sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function handle() { $extension = $this->argument('extension'); if (empty($extension) || !array_has(Admin::$extensions, $extension)) { $extension = $this->choice('Please choose a extension to import', array_keys(Admin::$extensions)); } $className = array_get(Admin...
Execute the console command.
entailment
public function getInMethod(string $method): array { if (isset($this->methodIndex[$method])) { return $this->methodIndex[$method]; } return []; }
@param string $method @return Tombstone[]
entailment
public static function fromHeader(string $string) { /* : ?self */ $parts = \array_map("trim", \explode(";", $string)); $nameValue = \explode("=", \array_shift($parts), 2); if (\count($nameValue) !== 2) { return null; } list($name, $value) = $nameValue; ...
Parses a cookie from a 'set-cookie' header. @param string $string Valid 'set-cookie' header line. @return self|null Returns a `ResponseCookie` instance on success and `null` on failure.
entailment
public function fire() { // Assets Assets::withChain([ new Location($this->token), new Names($this->token), ])->dispatch($this->token)->onQueue($this->queue); // Bookmarks Bookmarks::withChain([ new Folders($this->token), ])->dispatch($this->...
Fires the command. @return mixed|void
entailment
public function all() { $params = []; foreach ($this->methodRequirements as $key => $config) { $params[$key] = $this->get($key); } return $params; }
Fetches all required parameters from the current Request body. @return array
entailment
public function get($name) { if (!$paramConfig = $this->methodRequirements[$name]) { return; } $config = new Credential($name, $paramConfig); if (true === $config->required && !($this->getRequest()->request->has($name))) { throw new BadRequestUserException( ...
Fetches a given parameter from the current Request body. @param string $name The parameter key @return mixed The parameter value
entailment
private function validateParam(Credential $config, $param) { $name = $config->name; if (null === $requirements = $config->requirements) { return; } foreach ($requirements as $constraint) { if (is_scalar($constraint)) { $constraint = new Regex...
Handle requirements validation. @param Param $param @throws BadRequestUserException If the param is not valid @return Param
entailment
private function formatError($key, $invalidValue, $errorMessage) { return sprintf( false === $invalidValue ? 'Request parameter %s must be set' : "Request parameter %s value '%s' violated a requirement (%s)", $key, $invalidValue, $error...
{@inheritdoc}
entailment
private function getRequest() { if ($this->requestStack instanceof Request) { $request = $this->requestStack; } elseif ($this->requestStack instanceof RequestStack) { $request = $this->requestStack->getCurrentRequest(); } if ($request !== null) { ...
@throws \RuntimeException @return Request
entailment
protected function configureProperties(OptionsResolver $resolver) { $this->configureProcessProperties($resolver); $this->configureStartControlProperties($resolver); $this->configureStopControlProperties($resolver); $resolver ->setDefined('user') ->setAllowedT...
{@inheritdoc}
entailment
private function configureProcessProperties(OptionsResolver $resolver) { $resolver ->setRequired('command') ->setAllowedTypes('command', 'string'); $resolver ->setDefined('process_name') ->setAllowedTypes('process_name', 'string'); $resolver-...
Configures process related properties. @param OptionsResolver $resolver
entailment
private function configureStartControlProperties(OptionsResolver $resolver) { $resolver->setDefined('autostart') ->setAllowedTypes('autostart', 'bool'); $resolver ->setDefined('autorestart') ->setAllowedTypes('autorestart', ['bool', 'string']) ->setAl...
Configures start control related properties. @param OptionsResolver $resolver
entailment
private function configureStopControlProperties(OptionsResolver $resolver) { $resolver->setDefined('exitcodes'); $this->configureArrayProperty('exitcodes', $resolver); $resolver ->setDefined('stopsignal') ->setAllowedTypes('stopsignal', 'string') ->setAll...
Configures stop control related properties. @param OptionsResolver $resolver
entailment
private function configureLogProperties(OptionsResolver $resolver) { $resolver->setDefined('redirect_stderr') ->setAllowedTypes('redirect_stderr', 'bool'); $this->configureStdoutLogProperties($resolver); $this->configureStderrLogProperties($resolver); }
Configures log related properties. @param OptionsResolver $resolver
entailment
private function configureStdoutLogProperties(OptionsResolver $resolver) { $resolver ->setDefined('stdout_logfile') ->setAllowedTypes('stdout_logfile', 'string'); $resolver->setDefined('stdout_logfile_maxbytes'); $this->configureByteProperty('stdout_logfile_maxbytes'...
Configures stdout log related properties. @param OptionsResolver $resolver
entailment
private function configureStderrLogProperties(OptionsResolver $resolver) { $resolver ->setDefined('stderr_logfile') ->setAllowedTypes('stderr_logfile', 'string'); $resolver->setDefined('stderr_logfile_maxbytes'); $this->configureByteProperty('stderr_logfile_maxbytes'...
Configures stderr log related properties. @param OptionsResolver $resolver
entailment
protected function convertToResource($data) { return Holding::make($this->client, $this->bib, $data->holding_id) ->init($data); }
Convert a data element to a resource object. @param $data @return Holding
entailment
public static function fromHeader(string $string): array { $cookies = \explode(";", $string); $result = []; try { foreach ($cookies as $cookie) { $parts = \explode('=', $cookie, 2); if (2 !== \count($parts)) { return []; ...
Parses the cookies from a 'cookie' header. Note: Parsing is aborted if there's an invalid value and no cookies are returned. @param string $string Valid 'cookie' header line. @return RequestCookie[]
entailment
protected function configureProperties(OptionsResolver $resolver) { $resolver ->setRequired('files') ->setAllowedTypes('files', ['string', 'array']) ->setNormalizer('files', function (Options $options, $value) { return is_string($value) ? $value : implode(...
{@inheritdoc}
entailment
public function withExpiry(\DateTimeInterface $date): self { $new = clone $this; if ($date instanceof \DateTimeImmutable) { $new->expiry = $date; } elseif ($date instanceof \DateTime) { $new->expiry = \DateTimeImmutable::createFromMutable($date); } else { ...
Applies the given expiry to the cookie. @param \DateTimeInterface $date @return self Cloned instance with the specified operation applied. @see self::withMaxAge() @see self::withoutExpiry() @link https://tools.ietf.org/html/rfc6265#section-5.2.1
entailment
public function getSize() { if (!$this->stream) { return null; } $stats = fstat($this->stream); if (isset($stats['size'])) { return $stats['size']; } return null; }
Get the size of the stream if known. @return int|null Returns the size in bytes if known, or null if unknown.
entailment
public function tell() { if (!$this->stream) { throw new RuntimeException('No stream'); } $position = ftell($this->stream); if (!$position) { throw new RuntimeException('Cannot get current position'); } return $position; }
Returns the current position of the file read/write pointer @return int Position of the file pointer @throws \RuntimeException on error.
entailment
public function rewind() { if (!$this->stream) { throw new RuntimeException("No stream attached"); } if (!$this->isSeekable() || rewind($this->stream) === false) { throw new RuntimeException('Could not rewind stream'); } }
Seek to the beginning of the stream. If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0). @see seek() @link http://www.php.net/manual/en/function.fseek.php @throws \RuntimeException on failure.
entailment
public function isWritable() { if ($this->stream) { $meta = $this->getMetadata(); $writableModes = ['r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'c', 'c+']; foreach ($writableModes as $mode) { if (strpos($meta['mode'], $mode) === 0) { return ...
Returns whether or not the stream is writable. @return bool
entailment
public function isReadable() { if ($this->stream) { $meta = $this->getMetadata(); $readableModes = ['r', 'r+', 'w+', 'a+', 'x+', 'c+']; foreach ($readableModes as $mode) { if (strpos($meta['mode'], $mode) === 0) { return true; ...
Returns whether or not the stream is readable. @return bool
entailment
public function getContents() { if (!$this->stream) { throw new RuntimeException("No stream attached"); } if (!$this->isReadable() || ($contents = stream_get_contents($this->stream)) === false) { throw new RuntimeException('Could not get contents of stream'); ...
Returns the remaining contents in a string @return string @throws \RuntimeException if unable to read or an error occurs while reading.
entailment
protected function configureProperties(OptionsResolver $resolver) { $resolver ->setDefined('serverurl') ->setAllowedTypes('serverurl', 'string'); $resolver ->setDefined('username') ->setAllowedTypes('username', 'string'); $resolver ...
{@inheritdoc}
entailment
protected function convertToResource($data) { return Library::make($this->client, $data->code) ->init($data); }
Convert a data element to a resource object. @param $data @return Library
entailment
public function addField($name, array $attributes) { //Argument 1 must be a string Argument::i()->test(1, 'string'); $this->addFields[$name] = $attributes; return $this; }
Adds a field in the table @param *string $name Column name @param *array $attributes Column attributes @return Eden\Mysql\Alter
entailment
public function changeField($name, array $attributes) { //Argument 1 must be a string Argument::i()->test(1, 'string'); $this->changeFields[$name] = $attributes; return $this; }
Changes attributes of the table given the field name @param *string $name Column name @param *array $attributes Column attributes @return Eden\Mysql\Alter
entailment
public function getSEOScoreTips() { $score_criteria_tips = array( 'pagesubject_defined' => _t('SEO.SEOScoreTipPageSubjectDefined', 'Page subject is not defined for page'), 'pagesubject_in_title' => _t('SEO.SEOScoreTipPageSubjectInTitle', 'Page subject is not in the title of this page'),...
getSEOScoreTips. Get array of tips translated in current locale @param none @return array $score_criteria_tips Associative array with translated tips
entailment
public function updateCMSFields(FieldList $fields) { // exclude SEO tab from some pages $excluded = Config::inst()->get(self::class, 'excluded_page_types'); if ($excluded) { if (in_array($this->owner->getClassName(), $excluded)) { return; } } ...
updateCMSFields. Update Silverstripe CMS Fields for SEO Module @param FieldList @return none
entailment
public function getHTMLStars() { $treshold_score = $this->seo_score - 2 < 0 ? 0 : $this->seo_score - 2; $num_stars = intval(ceil($treshold_score) / 2); $num_nostars = 5 - $num_stars; $html = '<div id="fivestar-widget">'; for ($i = 1; $i <= $num_stars; $i++) { $...
getHTMLStars. Get html of stars rating in CMS, maximum score is 12 threshold 2 @param none @return String $html
entailment
public function MetaTags(&$tags) { $siteConfig = SiteConfig::current_site_config(); // facebook OpenGraph /* $tags .= '<meta property="og:locale" content="' . i18n::get_locale() . '" />' . "\n"; $tags .= '<meta property="og:title" content="' . $this->owner->Title . '" />' . "\n...
/* MetaTags Hooks into MetaTags SiteTree method and adds MetaTags for Sharing of this page on Social Media (Facebook / Google+)
entailment
public function getSEOScoreCalculation() { $this->score_criteria['pagesubject_defined'] = $this->checkPageSubjectDefined(); $this->score_criteria['pagesubject_in_title'] = $this->checkPageSubjectInTitle(); $this->score_criteria['pagesubject_in_firstparagraph'] = $this->che...
getSEOScoreCalculation. Do SEO score calculation and set class Array score_criteria 12 corresponding assoc values Also set class Integer seo_score with score 0-12 based on values which are true in score_criteria array Do SEO score calculation and set class Array score_criteria 11 corresponding assoc values Also set cla...
entailment
public function setSEOScoreTipsUL() { $tips = $this->getSEOScoreTips(); $this->seo_score_tips = '<ul id="seo_score_tips">'; foreach ($this->score_criteria as $index => $crit) { if (!$crit) { $this->seo_score_tips .= '<li>' . $tips[$index] . '</li>'; } ...
setSEOScoreTipsUL. Set SEO Score tips ul > li for SEO tips literal field, based on score_criteria @param none @return none, set class string seo_score_tips with tips html
entailment
private function createDOMDocumentFromHTML($html = null) { if ($html != null) { libxml_use_internal_errors(true); $dom = new DOMDocument; $dom->loadHTML($html); libxml_clear_errors(); libxml_use_internal_errors(false); return $dom; ...
checkContentHasSubtitles. check if page Content has a h2's in it @param HTMLText $html String @return DOMDocument Object
entailment
public function checkPageSubjectInImageAltTags() { $html = $this->getPageContent(); // for newly created page if ($html == '') { return false; } $dom = $this->createDOMDocumentFromHTML($html); $images = $dom->getElementsByTagName('img'); foreach($...
checkPageSubjectInImageAlt. Checks if image alt tags contain page subject @param none @return boolean
entailment
private function checkImageAltTags() { $html = $this->getPageContent(); // for newly created page if ($html == '') { return false; } $dom = $this->createDOMDocumentFromHTML($html); $images = $dom->getElementsByTagName('img'); $imagesWithAltTags = ...
checkImageAltTags. Checks if images in content have alt tags @param none @return boolean
entailment
private function checkImageTitleTags() { $html = $this->getPageContent(); // for newly created page if ($html == '') { return false; } $dom = $this->createDOMDocumentFromHTML($html); $images = $dom->getElementsByTagName('img'); $imagesWithTitleTag...
checkImageTitleTags. Checks if images in content have title tags @param none @return boolean
entailment
public function checkPageSubjectInTitle() { if ($this->checkPageSubjectDefined()) { if (preg_match('/' . preg_quote($this->owner->SEOPageSubject, '/') . '/i', $this->owner->MetaTitle)) { return true; } elseif (preg_match('/' . preg_quote($this->owner->SEOPageSubject, '/')...
checkPageSubjectInTitle. Checks if defined PageSubject is present in the Page Title @param none @return boolean
entailment
public function checkPageSubjectInContent() { if ($this->checkPageSubjectDefined()) { if (preg_match('/' . preg_quote($this->owner->SEOPageSubject, '/') . '/i', $this->getPageContent())) { return true; } else { return false; } ...
checkPageSubjectInContent. Checks if defined PageSubject is present in the Page Content @param none @return boolean
entailment
public function checkPageSubjectInFirstParagraph() { if ($this->checkPageSubjectDefined()) { $first_paragraph = $this->owner->dbObject('Content')->FirstParagraph(); if (trim($first_paragraph != '')) { if (preg_match('/' . preg_quote($this->owner->SEOPageSubject, '/') . '...
checkPageSubjectInFirstParagraph. Checks if defined PageSubject is present in the Page Content's First Paragraph @param none @return boolean
entailment
public function checkPageSubjectInUrl() { if ($this->checkPageSubjectDefined()) { $url_segment = $this->owner->URLSegment; $pagesubject_url_segment = $this->owner->generateURLSegment($this->owner->SEOPageSubject); if (preg_match('/' . preg_quote($pagesubject_url...
checkPageSubjectInUrl. Checks if defined PageSubject is present in the Page URLSegment @param none @return boolean
entailment
public function checkPageSubjectInMetaDescription() { if ($this->checkPageSubjectDefined()) { if (preg_match('/' . preg_quote($this->owner->SEOPageSubject, '/') . '/i', $this->owner->MetaDescription)) { return true; } else { return false; ...
checkPageSubjectInMetaDescription. Checks if defined PageSubject is present in the Page MetaDescription @param none @return boolean
entailment
private function checkPageTitleLength() { $site_title_length = strlen($this->owner->getSiteConfig()->Title); // 3 is length of divider, this could all be done better ... return (($this->getNumCharsTitle() + 3 + $site_title_length) >= 40) ? true : false; }
checkPageTitleLength. check if length of Title and SiteConfig.Title has a minimal of 40 chars @param none @return boolean
entailment
private function checkPageHasImages() { $html = $this->getPageContent(); // for newly created page if ($html == '') { return false; } $dom = $this->createDOMDocumentFromHTML($html); $elements = $dom->getElementsByTagName('img'); return ($elements->...
checkPageHasImages. check if page Content has a img's in it @param none @return boolean
entailment
public function getPageContent() { $response = Director::test($this->owner->Link()); if (!$response->isError()) { return $response->getBody(); } return ''; }
getPageContent function to get html content of page which SEO score is based on (we use the same info as gets back from $Layout in template)
entailment
public static function fromSruRecord(SruRecord $record, Client $client = null) { $record->data->registerXPathNamespace('marc', 'http://www.loc.gov/MARC21/slim'); $mmsId = $record->data->text('.//marc:controlfield[@tag="001"]'); return (new self($client, $mmsId)) ->setMarcRecord(...
Initialize from SRU record without having to fetch the Bib record. @param SruRecord $record @param Client|null $client @return Bib
entailment
public function save() { // If initialized from an SRU record, we need to fetch the // remaining parts of the Bib record. $this->init(); // Inject the MARC record $marcXml = new QuiteSimpleXMLElement($this->_marc->toXML('UTF-8', false, false)); $this->data->first('re...
Save the MARC record.
entailment
public function getNzMmsId() { // If initialized from an SRU record, we need to fetch the // remaining parts of the Bib record. $this->init(); $nz_mms_id = $this->data->text("linked_record_id[@type='NZ']"); if (!$nz_mms_id) { throw new NoLinkedNetworkZoneRecordEx...
Get the MMS ID of the linked record in network zone.
entailment
protected function configureProperties(OptionsResolver $resolver) { $resolver->setRequired('programs'); $this->configureArrayProperty('programs', $resolver); $resolver->setDefined('priority') ->setAllowedTypes('priority', 'int'); }
{@inheritdoc}
entailment
public function load(Configuration $configuration = null) { try { $ini = $this->getParser()->parse($this->string); } catch (ParserException $e) { throw new LoaderException('Cannot parse INI', 0, $e); } return $this->parseSections($ini, $configuration); }
{@inheritdoc}
entailment
public function handle() { $offline = $this->option('offline'); if ($offline) $this->info('Checking Local Versions Only'); else $this->info('Checking Local and Github Versions. Please wait...'); $client = $this->client; $base_url = $this->base_url; ...
Execute the console command.
entailment
public function valid() { if (!isset($this->resources[$this->position])) { $this->fetchBatch(); } return isset($this->resources[$this->position]); }
Checks if current position is valid. @link http://php.net/manual/en/iterator.valid.php @return bool
entailment
public function run() { for ($i = 1; $i <= $this->maxRetry; $i++) { try { return call_user_func_array($this->process, $this->args); } catch (\Exception $e) { if (in_array(get_class($e), $this->allowedExceptions)) { throw $e; ...
@return mixed @throws YoloException @throws \Exception
entailment
public function tryUntil($callback) { try { return call_user_func_array($this->process, $this->args); } catch (\Exception $e) { if (in_array(get_class($e), $this->allowedExceptions)) { throw $e; } } $this->logger->warning(sprintf('...
@param $callback @return mixed|null @throws \Exception
entailment
public function setProperty($key, $value) { $properties = $this->properties; $properties[$key] = $value; $this->setProperties($properties); }
{@inheritdoc}
entailment
protected function configureArrayProperty($property, OptionsResolver $resolver) { $resolver ->setAllowedTypes($property, ['array', 'string']) ->setNormalizer($property, function (Options $options, $value) { return is_array($value) ? $value : explode(',', str_replace('...
Configures an array property for OptionsResolver. @param string $property @param OptionsResolver $resolver
entailment
protected function configureEnvironmentProperty(OptionsResolver $resolver) { $resolver ->setDefined('environment') ->setAllowedTypes('environment', ['array', 'string']) ->setNormalizer('environment', function (Options $options, $value) { if (is_array($valu...
Configures an environment property for OptionsResolver. @param OptionsResolver $resolver
entailment
protected function configureByteProperty($property, OptionsResolver $resolver) { $resolver ->setAllowedTypes($property, 'byte') ->setNormalizer($property, function (Options $options, $value) { return is_numeric($value) ? intval($value) : $value; }); }
Configures a byte property for OptionsResolver. @param string $property @param OptionsResolver $resolver
entailment
public function handle() { Map::dispatch(); Structures::withChain([new Stations])->dispatch(); Affiliation::withChain([new Names])->dispatch(); Alliances::withChain([new Members])->dispatch(); Prices::dispatch(); PublicCorporationHistory::dispatch(); PublicIn...
Execute the console command.
entailment
protected function buildUrl($url, $query = []) { $url = explode('?', $url, 2); if (count($url) == 2) { parse_str($url[1], $query0); $query = array_merge($query0, $query); } $query['apikey'] = $this->key; $url = $url[0]; if (strpos($url, $this...
Extend an URL with query string parameters and return an UriInterface object. @param string $url @param array $query @return UriInterface
entailment
public function request(RequestInterface $request, $attempt = 1) { if (!$this->key) { throw new AlmaClientException('No API key defined for ' . $this->zone); } try { return $this->http->sendRequest($request); } catch (HttpException $e) { // Thrown...
Make a synchronous HTTP request and return a PSR7 response if successful. In the case of intermittent errors (connection problem, 429 or 5XX error), the request is attempted a maximum of {$this->maxAttempts} times with a sleep of {$this->sleepTimeOnRetry} between each attempt to avoid hammering the server. @param Requ...
entailment
public function get($url, $query = [], $contentType = 'application/json') { $url = $this->buildUrl($url, $query); $request = $this->requestFactory->createRequest('GET', $url) ->withHeader('Accept', $contentType); $response = $this->request($request); return strval($resp...
Make a GET request. @param string $url @param array $query @param string $contentType @return string The response body
entailment
public function getJSON($url, $query = []) { $responseBody = $this->get($url, $query, 'application/json'); return json_decode($responseBody); }
Make a GET request, accepting JSON. @param string $url @param array $query @return \stdClass JSON response as an object.
entailment
public function getXML($url, $query = []) { $responseBody = $this->get($url, $query, 'application/xml'); return new QuiteSimpleXMLElement($responseBody); }
Make a GET request, accepting XML. @param string $url @param array $query @return QuiteSimpleXMLElement
entailment
public function putJSON($url, $data) { $responseBody = $this->put($url, json_encode($data), 'application/json'); return json_decode($responseBody); }
Make a PUT request, sending JSON data. @param string $url @param $data @return \stdClass
entailment
public function putXML($url, $data) { $responseBody = $this->put($url, $data, 'application/xml'); return new QuiteSimpleXMLElement($responseBody); }
Make a PUT request, sending XML data. @param string $url @param $data @return QuiteSimpleXMLElement
entailment
public function post($url, $data, $contentType = 'application/json') { $uri = $this->buildUrl($url); $request = $this->requestFactory->createRequest('POST', $uri); if (!is_null($contentType)) { $request = $request->withHeader('Content-Type', $contentType); $request =...
Make a POST request. @param string $url @param $data @param string $contentType @return string The response body
entailment
public function postJSON($url, $data = null) { $responseBody = $this->post($url, json_encode($data), 'application/json'); return json_decode($responseBody); }
Make a POST request, sending JSON data. @param string $url @param $data @return \stdClass
entailment
public function postXML($url, $data = null) { $responseBody = $this->post($url, $data, 'application/xml'); return new QuiteSimpleXMLElement($responseBody); }
Make a POST request, sending XML data. @param string $url @param $data @return QuiteSimpleXMLElement
entailment
public function getRedirectLocation($url, $query = []) { $url = $this->buildUrl($url, $query); $request = $this->requestFactory->createRequest('GET', $url); try { $response = $this->request($request); } catch (ResourceNotFound $e) { return; } ...
Get the redirect target location of an URL, or null if not a redirect. @param string $url @param array $query @return string|null
entailment
protected function parseClientError(HttpException $exception) { $contentType = explode(';', $exception->getResponse()->getHeaderLine('Content-Type'))[0]; $responseBody = (string) $exception->getResponse()->getBody(); switch ($contentType) { case 'application/json': ...
Generate a client exception. @param HttpException $exception @return RequestFailed
entailment
public function write(Configuration $configuration) { $ini = $this->getRenderer()->render($configuration->toArray()); if (false === $result = $this->filesystem->put($this->file, $ini)) { throw new WriterException(sprintf('Cannot write configuration into file %s', $this->file)); ...
{@inheritdoc}
entailment
public function ping($timeout = 1) { if ($socket = @fsockopen($this->protocol . '://' . $this->host, $this->port, $errCode, $errStr, $timeout)) { fclose($socket); return true; } return false; }
@param int $timeout @return array|bool
entailment
protected function setHeaders(array $headers) { // Ensure this is an atomic operation, either all headers are set or none. $before = $this->headers; try { foreach ($headers as $name => $value) { $this->setHeader($name, $value); } } catch (\Thr...
Sets the headers from the given array. @param string[]|string[][] $headers
entailment
protected function setHeader(string $name, $value) { \assert($this->isNameValid($name), "Invalid header name"); if (\is_array($value)) { if (!$value) { $this->removeHeader($name); return; } $value = \array_values(\array_map("strva...
Sets the named header to the given value. @param string $name @param string|string[] $value @throws \Error If the header name or value is invalid.
entailment
protected function addHeader(string $name, $value) { \assert($this->isNameValid($name), "Invalid header name"); if (\is_array($value)) { if (!$value) { return; } $value = \array_values(\array_map("strval", $value)); } else { $...
Adds the value to the named header, or creates the header with the given value if it did not exist. @param string $name @param string|string[] $value @throws \Error If the header name or value is invalid.
entailment
private function isValueValid(array $values): bool { foreach ($values as $value) { if (\preg_match("/[^\t\r\n\x20-\x7e\x80-\xfe]|\r\n/", $value)) { return false; } } return true; }
Determines if the given value is a valid header value. @param string[] $values @return bool @throws \Error If the given value cannot be converted to a string and is not an array of values that can be converted to strings.
entailment
public static function parseHeaders(string $rawHeaders): array { // Ensure that the last line also ends with a newline, this is important. \assert(\substr($rawHeaders, -2) === "\r\n", "Argument 1 must end with CRLF"); /** @var array[] $matches */ $count = \preg_match_all(self::HEADE...
Parses headers according to RFC 7230 and 2616. Allows empty header values, as HTTP/1.0 allows that. @param string $rawHeaders @return array Associative array mapping header names to arrays of values. @throws InvalidHeaderException If invalid headers have been passed.
entailment
public static function formatHeaders(array $headers): string { $buffer = ""; $lines = 0; foreach ($headers as $name => $values) { // PHP casts integer-like keys to integers $name = (string) $name; // Ignore any HTTP/2 pseudo headers if ($nam...
Format headers in to their on-the-wire format. Headers are always validated syntactically. This protects against response splitting and header injection attacks. @param array $headers Headers in a format as returned by {@see parseHeaders()}. @return string Formatted headers. @throws InvalidHeaderException If header...
entailment
protected function loadRoutes(): RouteCollection { $builder = $this->getRouteCollectionBuilder(); if (\is_callable($this->routeCallback)) { call_user_func($this->routeCallback, $builder); } return $builder->build(); }
Returns routes for request handling. @return RouteCollection
entailment
public function handle(Request $request): Response { try { $matcher = $this->getUrlMatcher($request); $parameters = $matcher->match($request->getPathInfo()); if (empty($parameters['_controller'])) { throw new InvalidRouteException('Route requires a _cont...
Handles HTTP request and returns response. @param Request $request @return Response
entailment
protected function getControllerParameters(Request $request, array $parameters): array { $result = [$request]; foreach ($parameters as $key => $value) { if (strpos($key, '_') !== 0) { $result[$key] = $value; } } return $result; }
Returns arguments for controller callback. @param Request $request @param array $parameters @return array
entailment
public function match(string $pattern, $callback, array $requirements = [], array $methods = []) { $route = new Route( $pattern, // path array('_controller' => $callback), // default values $requirements, // requirements array(), // options '', // ...
Maps a pattern to a callable. You can optionally specify HTTP methods that should be matched. @param string $pattern Matched route pattern @param callable $callback Callback that returns the response when matched @param array $requirements @param array $methods @return $this
entailment
public function get(string $pattern, $callback, array $requirements = []) { return $this->match($pattern, $callback, $requirements, [Request::METHOD_GET, Request::METHOD_HEAD]); }
Maps a GET request to a callable. @param string $pattern @param callable $callback @param array $requirements @return $this
entailment
public function post(string $pattern, $callback, array $requirements = []) { return $this->match($pattern, $callback, $requirements, [Request::METHOD_POST]); }
Maps a POST request to a callable. @param string $pattern @param callable $callback @param array $requirements @return $this
entailment
public function put(string $pattern, $callback, array $requirements = []) { return $this->match($pattern, $callback, $requirements, [Request::METHOD_PUT]); }
Maps a PUT request to a callable. @param string $pattern @param callable $callback @param array $requirements @return $this
entailment
public function delete(string $pattern, $callback, array $requirements = []) { return $this->match($pattern, $callback, $requirements, [Request::METHOD_DELETE]); }
Maps a DELETE request to a callable. @param string $pattern @param $callback @param array $requirements @return $this
entailment
public function options(string $pattern, $callback, array $requirements = []) { return $this->match($pattern, $callback, $requirements, [Request::METHOD_OPTIONS]); }
Maps an OPTIONS request to a callable. @param string $pattern @param $callback @param array $requirements @return $this
entailment
public function patch(string $pattern, $callback, array $requirements = []) { return $this->match($pattern, $callback, $requirements, [Request::METHOD_PATCH]); }
Maps a PATCH request to a callable. @param string $pattern @param $callback @param array $requirements @return $this
entailment
public function compare(\DateInterval $first, \DateInterval $second) { if ($this->safe) { $this->safecheck($first); $this->safecheck($second); } if ($first->y > $second->y) { return 1; } if ($first->y < $second->y) { return -1...
COmpare the two date intervals. If the first contains a larger timespan we return 1, if the second contains more we return -1 and when they are equals we return 0. @param \DateInterval $first @param \DateInterval $second @return int
entailment
protected function buildClass($name) { $stub = parent::buildClass($name); $this->replaceEndpoint($stub, $this->argument('endpoint')); if (! is_null($this->option('esi-version'))) $this->replaceVersion($stub, $this->option('esi-version')); if (! is_null($this->option('...
Build the class with the given name. @param string $name @return string
entailment
protected function replaceEndpoint(string &$stub, string $endpoint) { if (strlen($endpoint) > 0) $stub = str_replace('/dummy/endpoint/', $endpoint, $stub); return $this; }
Replace the endpoint for the given stub. @param string $stub @param string $endpoint @return $this
entailment
protected function replaceVersion(string &$stub, string $version) { if (strlen($version) > 0) $stub = str_replace('v1', $version, $stub); return $this; }
Replace the endpoint version for the given stub. @param string $stub @param string $version @return $this
entailment
protected function replaceScope(string &$stub, string $scope) { if (strlen($scope) > 0) $stub = str_replace("'public'", "'$scope'", $stub); return $this; }
Replace the scope for the given stub. @param string $stub @param string $scope @return $this
entailment
protected function execute(InputInterface $input, OutputInterface $output) { $this->io = new SymfonyStyle($input, $output); $fs = new FileSystem(); $this->io->title('RCHJWTUserBundle - Generate SSL Keys'); $rootDir = $this->getContainer()->getParameter('kernel.root_dir'); $...
{@inheritdoc}
entailment
protected function generatePrivateKey($path, $passphrase) { if ($passphrase) { $processArgs = sprintf('genrsa -out %s/private.pem -aes256 -passout pass:%s 4096', $path, $passphrase); } else { $processArgs = sprintf('genrsa -out %s/private.pem 4096', $path); } ...
Generate a RSA private key. @param string $path @param string $passphrase @param OutputInterface $output @throws ProcessFailedException
entailment
protected function generatePublicKey($path, $passphrase) { $processArgs = sprintf('rsa -pubout -in %s/private.pem -out %s/public.pem -passin pass:%s', $path, $path, $passphrase); $this->generateKey($processArgs); }
Generate a RSA public key. @param string $path @param string $passphrase @param OutputInterface $output
entailment