repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
sulu/SuluSalesShippingBundle
src/Sulu/Bundle/Sales/ShippingBundle/DataFixtures/ORM/LoadShippingStatus.php
LoadShippingStatus.load
public function load(ObjectManager $manager) { $statuses = array(); // force id = 1 $metadata = $manager->getClassMetaData(get_class(new ShippingStatus())); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE); // created $status = new ShippingStatus(); $status->setId(ShippingStatus::STATUS_CREATED); $this->createStatusTranslation($manager, $status, 'Created', 'en'); $this->createStatusTranslation($manager, $status, 'Erfasst', 'de'); $manager->persist($status); $statuses[ShippingStatus::STATUS_CREATED] = $status; // delivery note $status = new ShippingStatus(); $status->setId(ShippingStatus::STATUS_DELIVERY_NOTE); $this->createStatusTranslation($manager, $status, 'Delivery note created', 'en'); $this->createStatusTranslation($manager, $status, 'Lieferschein erstellt', 'de'); $manager->persist($status); $statuses[ShippingStatus::STATUS_DELIVERY_NOTE] = $status; // shipped $status = new ShippingStatus(); $status->setId(ShippingStatus::STATUS_SHIPPED); $this->createStatusTranslation($manager, $status, 'Shipped', 'en'); $this->createStatusTranslation($manager, $status, 'Versandt', 'de'); $manager->persist($status); $statuses[ShippingStatus::STATUS_SHIPPED] = $status; // canceled $status = new ShippingStatus(); $status->setId(ShippingStatus::STATUS_CANCELED); $this->createStatusTranslation($manager, $status, 'Canceled', 'en'); $this->createStatusTranslation($manager, $status, 'Storniert', 'de'); $manager->persist($status); $statuses[ShippingStatus::STATUS_CANCELED] = $status; $manager->flush(); return $statuses; }
php
public function load(ObjectManager $manager) { $statuses = array(); // force id = 1 $metadata = $manager->getClassMetaData(get_class(new ShippingStatus())); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE); // created $status = new ShippingStatus(); $status->setId(ShippingStatus::STATUS_CREATED); $this->createStatusTranslation($manager, $status, 'Created', 'en'); $this->createStatusTranslation($manager, $status, 'Erfasst', 'de'); $manager->persist($status); $statuses[ShippingStatus::STATUS_CREATED] = $status; // delivery note $status = new ShippingStatus(); $status->setId(ShippingStatus::STATUS_DELIVERY_NOTE); $this->createStatusTranslation($manager, $status, 'Delivery note created', 'en'); $this->createStatusTranslation($manager, $status, 'Lieferschein erstellt', 'de'); $manager->persist($status); $statuses[ShippingStatus::STATUS_DELIVERY_NOTE] = $status; // shipped $status = new ShippingStatus(); $status->setId(ShippingStatus::STATUS_SHIPPED); $this->createStatusTranslation($manager, $status, 'Shipped', 'en'); $this->createStatusTranslation($manager, $status, 'Versandt', 'de'); $manager->persist($status); $statuses[ShippingStatus::STATUS_SHIPPED] = $status; // canceled $status = new ShippingStatus(); $status->setId(ShippingStatus::STATUS_CANCELED); $this->createStatusTranslation($manager, $status, 'Canceled', 'en'); $this->createStatusTranslation($manager, $status, 'Storniert', 'de'); $manager->persist($status); $statuses[ShippingStatus::STATUS_CANCELED] = $status; $manager->flush(); return $statuses; }
[ "public", "function", "load", "(", "ObjectManager", "$", "manager", ")", "{", "$", "statuses", "=", "array", "(", ")", ";", "// force id = 1", "$", "metadata", "=", "$", "manager", "->", "getClassMetaData", "(", "get_class", "(", "new", "ShippingStatus", "(", ")", ")", ")", ";", "$", "metadata", "->", "setIdGeneratorType", "(", "\\", "Doctrine", "\\", "ORM", "\\", "Mapping", "\\", "ClassMetadata", "::", "GENERATOR_TYPE_NONE", ")", ";", "// created", "$", "status", "=", "new", "ShippingStatus", "(", ")", ";", "$", "status", "->", "setId", "(", "ShippingStatus", "::", "STATUS_CREATED", ")", ";", "$", "this", "->", "createStatusTranslation", "(", "$", "manager", ",", "$", "status", ",", "'Created'", ",", "'en'", ")", ";", "$", "this", "->", "createStatusTranslation", "(", "$", "manager", ",", "$", "status", ",", "'Erfasst'", ",", "'de'", ")", ";", "$", "manager", "->", "persist", "(", "$", "status", ")", ";", "$", "statuses", "[", "ShippingStatus", "::", "STATUS_CREATED", "]", "=", "$", "status", ";", "// delivery note", "$", "status", "=", "new", "ShippingStatus", "(", ")", ";", "$", "status", "->", "setId", "(", "ShippingStatus", "::", "STATUS_DELIVERY_NOTE", ")", ";", "$", "this", "->", "createStatusTranslation", "(", "$", "manager", ",", "$", "status", ",", "'Delivery note created'", ",", "'en'", ")", ";", "$", "this", "->", "createStatusTranslation", "(", "$", "manager", ",", "$", "status", ",", "'Lieferschein erstellt'", ",", "'de'", ")", ";", "$", "manager", "->", "persist", "(", "$", "status", ")", ";", "$", "statuses", "[", "ShippingStatus", "::", "STATUS_DELIVERY_NOTE", "]", "=", "$", "status", ";", "// shipped", "$", "status", "=", "new", "ShippingStatus", "(", ")", ";", "$", "status", "->", "setId", "(", "ShippingStatus", "::", "STATUS_SHIPPED", ")", ";", "$", "this", "->", "createStatusTranslation", "(", "$", "manager", ",", "$", "status", ",", "'Shipped'", ",", "'en'", ")", ";", "$", "this", "->", "createStatusTranslation", "(", "$", "manager", ",", "$", "status", ",", "'Versandt'", ",", "'de'", ")", ";", "$", "manager", "->", "persist", "(", "$", "status", ")", ";", "$", "statuses", "[", "ShippingStatus", "::", "STATUS_SHIPPED", "]", "=", "$", "status", ";", "// canceled", "$", "status", "=", "new", "ShippingStatus", "(", ")", ";", "$", "status", "->", "setId", "(", "ShippingStatus", "::", "STATUS_CANCELED", ")", ";", "$", "this", "->", "createStatusTranslation", "(", "$", "manager", ",", "$", "status", ",", "'Canceled'", ",", "'en'", ")", ";", "$", "this", "->", "createStatusTranslation", "(", "$", "manager", ",", "$", "status", ",", "'Storniert'", ",", "'de'", ")", ";", "$", "manager", "->", "persist", "(", "$", "status", ")", ";", "$", "statuses", "[", "ShippingStatus", "::", "STATUS_CANCELED", "]", "=", "$", "status", ";", "$", "manager", "->", "flush", "(", ")", ";", "return", "$", "statuses", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/ShippingBundle/DataFixtures/ORM/LoadShippingStatus.php#L24-L67
stubbles/stubbles-webapp-core
src/main/php/response/Cookie.php
Cookie.create
public static function create(string $name, string $value = null): self { return new self($name, $value); }
php
public static function create(string $name, string $value = null): self { return new self($name, $value); }
[ "public", "static", "function", "create", "(", "string", "$", "name", ",", "string", "$", "value", "=", "null", ")", ":", "self", "{", "return", "new", "self", "(", "$", "name", ",", "$", "value", ")", ";", "}" ]
creates the cookie @param string $name name of the cookie @param string $value value of the cookie @return \stubbles\webapp\response\Cookie
[ "creates", "the", "cookie" ]
train
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/response/Cookie.php#L86-L89
ellipsephp/container
src/Container.php
Container.serviceFactoryMap
private function serviceFactoryMap(array $providers): array { $wrap = function ($factory) { return [$factory]; }; return array_reduce($providers, function ($factories, ServiceProviderInterface $provider) use ($wrap) { return array_merge($factories, array_map($wrap, $provider->getFactories())); }, []); }
php
private function serviceFactoryMap(array $providers): array { $wrap = function ($factory) { return [$factory]; }; return array_reduce($providers, function ($factories, ServiceProviderInterface $provider) use ($wrap) { return array_merge($factories, array_map($wrap, $provider->getFactories())); }, []); }
[ "private", "function", "serviceFactoryMap", "(", "array", "$", "providers", ")", ":", "array", "{", "$", "wrap", "=", "function", "(", "$", "factory", ")", "{", "return", "[", "$", "factory", "]", ";", "}", ";", "return", "array_reduce", "(", "$", "providers", ",", "function", "(", "$", "factories", ",", "ServiceProviderInterface", "$", "provider", ")", "use", "(", "$", "wrap", ")", "{", "return", "array_merge", "(", "$", "factories", ",", "array_map", "(", "$", "wrap", ",", "$", "provider", "->", "getFactories", "(", ")", ")", ")", ";", "}", ",", "[", "]", ")", ";", "}" ]
Return a service factory map from the given service providers. @param array $providers @return array
[ "Return", "a", "service", "factory", "map", "from", "the", "given", "service", "providers", "." ]
train
https://github.com/ellipsephp/container/blob/ae0836b071fa1751f41b50fc33e3196fcbced6bf/src/Container.php#L89-L98
ellipsephp/container
src/Container.php
Container.serviceExtensionMap
private function serviceExtensionMap(array $providers): array { $wrap = function ($factory) { return [$factory]; }; return array_reduce($providers, function ($extensions, ServiceProviderInterface $provider) use ($wrap) { return array_merge_recursive($extensions, array_map($wrap, $provider->getExtensions())); }, []); }
php
private function serviceExtensionMap(array $providers): array { $wrap = function ($factory) { return [$factory]; }; return array_reduce($providers, function ($extensions, ServiceProviderInterface $provider) use ($wrap) { return array_merge_recursive($extensions, array_map($wrap, $provider->getExtensions())); }, []); }
[ "private", "function", "serviceExtensionMap", "(", "array", "$", "providers", ")", ":", "array", "{", "$", "wrap", "=", "function", "(", "$", "factory", ")", "{", "return", "[", "$", "factory", "]", ";", "}", ";", "return", "array_reduce", "(", "$", "providers", ",", "function", "(", "$", "extensions", ",", "ServiceProviderInterface", "$", "provider", ")", "use", "(", "$", "wrap", ")", "{", "return", "array_merge_recursive", "(", "$", "extensions", ",", "array_map", "(", "$", "wrap", ",", "$", "provider", "->", "getExtensions", "(", ")", ")", ")", ";", "}", ",", "[", "]", ")", ";", "}" ]
Return a service extension map from the given service providers. @param array $providers @return array
[ "Return", "a", "service", "extension", "map", "from", "the", "given", "service", "providers", "." ]
train
https://github.com/ellipsephp/container/blob/ae0836b071fa1751f41b50fc33e3196fcbced6bf/src/Container.php#L106-L115
tjbp/laravel-verify-emails
src/Auth/VerifyEmails/CanVerifyEmail.php
CanVerifyEmail.unverify
public function unverify() { VerifyEmail::sendVerificationLink($this, function (Message $message) { $message->subject($this->getVerifyEmailSubject()); }); $this->setVerified(false); }
php
public function unverify() { VerifyEmail::sendVerificationLink($this, function (Message $message) { $message->subject($this->getVerifyEmailSubject()); }); $this->setVerified(false); }
[ "public", "function", "unverify", "(", ")", "{", "VerifyEmail", "::", "sendVerificationLink", "(", "$", "this", ",", "function", "(", "Message", "$", "message", ")", "{", "$", "message", "->", "subject", "(", "$", "this", "->", "getVerifyEmailSubject", "(", ")", ")", ";", "}", ")", ";", "$", "this", "->", "setVerified", "(", "false", ")", ";", "}" ]
Unverify the user's email address. @return void
[ "Unverify", "the", "user", "s", "email", "address", "." ]
train
https://github.com/tjbp/laravel-verify-emails/blob/1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6/src/Auth/VerifyEmails/CanVerifyEmail.php#L66-L73
wpottier/WizadSettingsBundle
Parser/XmlFileLoader.php
XmlFileLoader.load
public function load($file) { $schema = array(); $path = $this->locator->locate($file); $xml = $this->parseFile($path); $document = $xml->documentElement; /** @var \DOMElement $setting */ $prefix = $document->hasAttribute('prefix') ? $document->getAttribute('prefix') . '.' : ''; foreach ($document->getElementsByTagName('parameter') as $node) { $this->parseParameter($node, $schema, $prefix); } return $schema; }
php
public function load($file) { $schema = array(); $path = $this->locator->locate($file); $xml = $this->parseFile($path); $document = $xml->documentElement; /** @var \DOMElement $setting */ $prefix = $document->hasAttribute('prefix') ? $document->getAttribute('prefix') . '.' : ''; foreach ($document->getElementsByTagName('parameter') as $node) { $this->parseParameter($node, $schema, $prefix); } return $schema; }
[ "public", "function", "load", "(", "$", "file", ")", "{", "$", "schema", "=", "array", "(", ")", ";", "$", "path", "=", "$", "this", "->", "locator", "->", "locate", "(", "$", "file", ")", ";", "$", "xml", "=", "$", "this", "->", "parseFile", "(", "$", "path", ")", ";", "$", "document", "=", "$", "xml", "->", "documentElement", ";", "/** @var \\DOMElement $setting */", "$", "prefix", "=", "$", "document", "->", "hasAttribute", "(", "'prefix'", ")", "?", "$", "document", "->", "getAttribute", "(", "'prefix'", ")", ".", "'.'", ":", "''", ";", "foreach", "(", "$", "document", "->", "getElementsByTagName", "(", "'parameter'", ")", "as", "$", "node", ")", "{", "$", "this", "->", "parseParameter", "(", "$", "node", ",", "$", "schema", ",", "$", "prefix", ")", ";", "}", "return", "$", "schema", ";", "}" ]
Loads an XML file. @param mixed $file The resource @return array
[ "Loads", "an", "XML", "file", "." ]
train
https://github.com/wpottier/WizadSettingsBundle/blob/92738c59d4da28d3a7376de854ce8505898159cb/Parser/XmlFileLoader.php#L57-L73
wpottier/WizadSettingsBundle
Parser/XmlFileLoader.php
XmlFileLoader.parseFile
protected function parseFile($file) { try { $dom = XmlUtils::loadFile($file, __DIR__ . static::SCHEME_PATH); } catch (\InvalidArgumentException $e) { throw new \InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e); } return $dom; }
php
protected function parseFile($file) { try { $dom = XmlUtils::loadFile($file, __DIR__ . static::SCHEME_PATH); } catch (\InvalidArgumentException $e) { throw new \InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e); } return $dom; }
[ "protected", "function", "parseFile", "(", "$", "file", ")", "{", "try", "{", "$", "dom", "=", "XmlUtils", "::", "loadFile", "(", "$", "file", ",", "__DIR__", ".", "static", "::", "SCHEME_PATH", ")", ";", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "e", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Unable to parse file \"%s\".'", ",", "$", "file", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "return", "$", "dom", ";", "}" ]
Parses a XML file. @param string $file Path to a file @return \DOMDocument @throws \InvalidArgumentException When loading of XML file returns error
[ "Parses", "a", "XML", "file", "." ]
train
https://github.com/wpottier/WizadSettingsBundle/blob/92738c59d4da28d3a7376de854ce8505898159cb/Parser/XmlFileLoader.php#L120-L129
yosmanyga/resource
src/Yosmanyga/Resource/Reader/Iterator/XmlFileReader.php
XmlFileReader.open
public function open(Resource $resource) { $file = $resource->getMetadata('file'); if (!is_file($file)) { throw new \InvalidArgumentException(sprintf('File "%s" not found.', $file)); } $this->xmlReader = new \XmlReader(); $this->xmlReader->open($file); // Try to move pointer to first node inside root tag try { while ($this->xmlReader->read()) { $name = $this->xmlReader->name; $depth = $this->xmlReader->depth; if (1 == $depth && !in_array($name, ['', '#text'])) { break; } } } catch (\Exception $e) { throw new \InvalidArgumentException($e->getMessage(), 0, $e); } }
php
public function open(Resource $resource) { $file = $resource->getMetadata('file'); if (!is_file($file)) { throw new \InvalidArgumentException(sprintf('File "%s" not found.', $file)); } $this->xmlReader = new \XmlReader(); $this->xmlReader->open($file); // Try to move pointer to first node inside root tag try { while ($this->xmlReader->read()) { $name = $this->xmlReader->name; $depth = $this->xmlReader->depth; if (1 == $depth && !in_array($name, ['', '#text'])) { break; } } } catch (\Exception $e) { throw new \InvalidArgumentException($e->getMessage(), 0, $e); } }
[ "public", "function", "open", "(", "Resource", "$", "resource", ")", "{", "$", "file", "=", "$", "resource", "->", "getMetadata", "(", "'file'", ")", ";", "if", "(", "!", "is_file", "(", "$", "file", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'File \"%s\" not found.'", ",", "$", "file", ")", ")", ";", "}", "$", "this", "->", "xmlReader", "=", "new", "\\", "XmlReader", "(", ")", ";", "$", "this", "->", "xmlReader", "->", "open", "(", "$", "file", ")", ";", "// Try to move pointer to first node inside root tag", "try", "{", "while", "(", "$", "this", "->", "xmlReader", "->", "read", "(", ")", ")", "{", "$", "name", "=", "$", "this", "->", "xmlReader", "->", "name", ";", "$", "depth", "=", "$", "this", "->", "xmlReader", "->", "depth", ";", "if", "(", "1", "==", "$", "depth", "&&", "!", "in_array", "(", "$", "name", ",", "[", "''", ",", "'#text'", "]", ")", ")", "{", "break", ";", "}", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "0", ",", "$", "e", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Reader/Iterator/XmlFileReader.php#L48-L71
yosmanyga/resource
src/Yosmanyga/Resource/Reader/Iterator/XmlFileReader.php
XmlFileReader.current
public function current() { if (!isset($this->xmlReader)) { throw new \RuntimeException('The resource needs to be open.'); } if (!$this->xmlReader->name) { return false; } /** @var \DOMElement $data */ $data = $this->xmlReader->expand(); $data = $this->xmlKit->convertDomElementToArray($data); return ['value' => $data]; }
php
public function current() { if (!isset($this->xmlReader)) { throw new \RuntimeException('The resource needs to be open.'); } if (!$this->xmlReader->name) { return false; } /** @var \DOMElement $data */ $data = $this->xmlReader->expand(); $data = $this->xmlKit->convertDomElementToArray($data); return ['value' => $data]; }
[ "public", "function", "current", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "xmlReader", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'The resource needs to be open.'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "xmlReader", "->", "name", ")", "{", "return", "false", ";", "}", "/** @var \\DOMElement $data */", "$", "data", "=", "$", "this", "->", "xmlReader", "->", "expand", "(", ")", ";", "$", "data", "=", "$", "this", "->", "xmlKit", "->", "convertDomElementToArray", "(", "$", "data", ")", ";", "return", "[", "'value'", "=>", "$", "data", "]", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Reader/Iterator/XmlFileReader.php#L76-L91
yosmanyga/resource
src/Yosmanyga/Resource/Reader/Iterator/XmlFileReader.php
XmlFileReader.next
public function next() { if (!isset($this->xmlReader)) { throw new \RuntimeException('The resource needs to be open.'); } while ($this->xmlReader->next()) { $name = $this->xmlReader->name; $depth = $this->xmlReader->depth; if (1 == $depth && !in_array($name, ['', '#text'])) { break; } } }
php
public function next() { if (!isset($this->xmlReader)) { throw new \RuntimeException('The resource needs to be open.'); } while ($this->xmlReader->next()) { $name = $this->xmlReader->name; $depth = $this->xmlReader->depth; if (1 == $depth && !in_array($name, ['', '#text'])) { break; } } }
[ "public", "function", "next", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "xmlReader", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'The resource needs to be open.'", ")", ";", "}", "while", "(", "$", "this", "->", "xmlReader", "->", "next", "(", ")", ")", "{", "$", "name", "=", "$", "this", "->", "xmlReader", "->", "name", ";", "$", "depth", "=", "$", "this", "->", "xmlReader", "->", "depth", ";", "if", "(", "1", "==", "$", "depth", "&&", "!", "in_array", "(", "$", "name", ",", "[", "''", ",", "'#text'", "]", ")", ")", "{", "break", ";", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Reader/Iterator/XmlFileReader.php#L96-L109
yosmanyga/resource
src/Yosmanyga/Resource/Reader/Iterator/XmlFileReader.php
XmlFileReader.close
public function close() { if (!isset($this->xmlReader)) { throw new \RuntimeException('The resource needs to be open.'); } $this->xmlReader->close(); unset($this->xmlReader); }
php
public function close() { if (!isset($this->xmlReader)) { throw new \RuntimeException('The resource needs to be open.'); } $this->xmlReader->close(); unset($this->xmlReader); }
[ "public", "function", "close", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "xmlReader", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'The resource needs to be open.'", ")", ";", "}", "$", "this", "->", "xmlReader", "->", "close", "(", ")", ";", "unset", "(", "$", "this", "->", "xmlReader", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Reader/Iterator/XmlFileReader.php#L114-L122
phramework/validate
src/AnyOf.php
AnyOf.validate
public function validate($value) { $return = new ValidateResult($value, false); //validator -> //return -> $successValidated = []; foreach ($this->{$this->anyOfProperty} as $validator) { $validatorReturn = $validator->validate($value); if ($validatorReturn->status) { //push to successValidated list $successValidated[] = (object)[ 'validator' => $validator, 'return' => $validatorReturn ]; } } if (( $this->requiredCountOfAnyOf === null && count($successValidated) > 0 ) || ( $this->requiredCountOfAnyOf !== null && count($successValidated) === $this->requiredCountOfAnyOf ) ) { //Use first in list $return = $successValidated[0]->return; return $this->validateCommon($value, $return); } //error $return->errorObject = new IncorrectParametersException([ [ 'type' => static::getType(), 'failure' => $this->anyOfProperty ] ]); unset($successValidated); return $return; }
php
public function validate($value) { $return = new ValidateResult($value, false); //validator -> //return -> $successValidated = []; foreach ($this->{$this->anyOfProperty} as $validator) { $validatorReturn = $validator->validate($value); if ($validatorReturn->status) { //push to successValidated list $successValidated[] = (object)[ 'validator' => $validator, 'return' => $validatorReturn ]; } } if (( $this->requiredCountOfAnyOf === null && count($successValidated) > 0 ) || ( $this->requiredCountOfAnyOf !== null && count($successValidated) === $this->requiredCountOfAnyOf ) ) { //Use first in list $return = $successValidated[0]->return; return $this->validateCommon($value, $return); } //error $return->errorObject = new IncorrectParametersException([ [ 'type' => static::getType(), 'failure' => $this->anyOfProperty ] ]); unset($successValidated); return $return; }
[ "public", "function", "validate", "(", "$", "value", ")", "{", "$", "return", "=", "new", "ValidateResult", "(", "$", "value", ",", "false", ")", ";", "//validator ->", "//return ->", "$", "successValidated", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "{", "$", "this", "->", "anyOfProperty", "}", "as", "$", "validator", ")", "{", "$", "validatorReturn", "=", "$", "validator", "->", "validate", "(", "$", "value", ")", ";", "if", "(", "$", "validatorReturn", "->", "status", ")", "{", "//push to successValidated list", "$", "successValidated", "[", "]", "=", "(", "object", ")", "[", "'validator'", "=>", "$", "validator", ",", "'return'", "=>", "$", "validatorReturn", "]", ";", "}", "}", "if", "(", "(", "$", "this", "->", "requiredCountOfAnyOf", "===", "null", "&&", "count", "(", "$", "successValidated", ")", ">", "0", ")", "||", "(", "$", "this", "->", "requiredCountOfAnyOf", "!==", "null", "&&", "count", "(", "$", "successValidated", ")", "===", "$", "this", "->", "requiredCountOfAnyOf", ")", ")", "{", "//Use first in list", "$", "return", "=", "$", "successValidated", "[", "0", "]", "->", "return", ";", "return", "$", "this", "->", "validateCommon", "(", "$", "value", ",", "$", "return", ")", ";", "}", "//error", "$", "return", "->", "errorObject", "=", "new", "IncorrectParametersException", "(", "[", "[", "'type'", "=>", "static", "::", "getType", "(", ")", ",", "'failure'", "=>", "$", "this", "->", "anyOfProperty", "]", "]", ")", ";", "unset", "(", "$", "successValidated", ")", ";", "return", "$", "return", ";", "}" ]
Validate value @see \Phramework\Validate\ValidateResult for ValidateResult object @param mixed $value Value to validate @return ValidateResult @uses $requiredCountOfAnyOf @uses $anyOfProperty
[ "Validate", "value" ]
train
https://github.com/phramework/validate/blob/22dd3c4e5f7a77a1a75d92f98444f3e4b7ce5cfc/src/AnyOf.php#L101-L144
czim/laravel-pxlcms
src/Models/Scopes/OnlyActiveScope.php
OnlyActiveScope.apply
public function apply(Builder $builder, Model $model) { $column = $model->getQualifiedActiveColumn(); $builder->where($column, true); $this->addWithInactive($builder); }
php
public function apply(Builder $builder, Model $model) { $column = $model->getQualifiedActiveColumn(); $builder->where($column, true); $this->addWithInactive($builder); }
[ "public", "function", "apply", "(", "Builder", "$", "builder", ",", "Model", "$", "model", ")", "{", "$", "column", "=", "$", "model", "->", "getQualifiedActiveColumn", "(", ")", ";", "$", "builder", "->", "where", "(", "$", "column", ",", "true", ")", ";", "$", "this", "->", "addWithInactive", "(", "$", "builder", ")", ";", "}" ]
Apply scope on the query @param \Illuminate\Database\Eloquent\Builder $builder @param \Illuminate\Database\Eloquent\Model $model
[ "Apply", "scope", "on", "the", "query" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Models/Scopes/OnlyActiveScope.php#L18-L25
czim/laravel-pxlcms
src/Models/Scopes/OnlyActiveScope.php
OnlyActiveScope.remove
public function remove(Builder $builder, Model $model) { $query = $builder->getQuery(); $column = $model->getQualifiedActiveColumn(); $bindingKey = 0; foreach ((array) $query->wheres as $key => $where) { if ($this->isActiveConstraint($where, $column)) { $this->removeWhere($query, $key); $this->removeBinding($query, $bindingKey); } if ( ! in_array($where['type'], ['Null', 'NotNull'])) { $bindingKey++; } } }
php
public function remove(Builder $builder, Model $model) { $query = $builder->getQuery(); $column = $model->getQualifiedActiveColumn(); $bindingKey = 0; foreach ((array) $query->wheres as $key => $where) { if ($this->isActiveConstraint($where, $column)) { $this->removeWhere($query, $key); $this->removeBinding($query, $bindingKey); } if ( ! in_array($where['type'], ['Null', 'NotNull'])) { $bindingKey++; } } }
[ "public", "function", "remove", "(", "Builder", "$", "builder", ",", "Model", "$", "model", ")", "{", "$", "query", "=", "$", "builder", "->", "getQuery", "(", ")", ";", "$", "column", "=", "$", "model", "->", "getQualifiedActiveColumn", "(", ")", ";", "$", "bindingKey", "=", "0", ";", "foreach", "(", "(", "array", ")", "$", "query", "->", "wheres", "as", "$", "key", "=>", "$", "where", ")", "{", "if", "(", "$", "this", "->", "isActiveConstraint", "(", "$", "where", ",", "$", "column", ")", ")", "{", "$", "this", "->", "removeWhere", "(", "$", "query", ",", "$", "key", ")", ";", "$", "this", "->", "removeBinding", "(", "$", "query", ",", "$", "bindingKey", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "where", "[", "'type'", "]", ",", "[", "'Null'", ",", "'NotNull'", "]", ")", ")", "{", "$", "bindingKey", "++", ";", "}", "}", "}" ]
Remove scope from the query @param \Illuminate\Database\Eloquent\Builder $builder @param \Illuminate\Database\Eloquent\Model $model
[ "Remove", "scope", "from", "the", "query" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Models/Scopes/OnlyActiveScope.php#L33-L51
czim/laravel-pxlcms
src/Models/Scopes/OnlyActiveScope.php
OnlyActiveScope.removeWhere
protected function removeWhere(BaseBuilder $query, $key) { unset($query->wheres[ $key ]); $query->wheres = array_values( $query->wheres ); }
php
protected function removeWhere(BaseBuilder $query, $key) { unset($query->wheres[ $key ]); $query->wheres = array_values( $query->wheres ); }
[ "protected", "function", "removeWhere", "(", "BaseBuilder", "$", "query", ",", "$", "key", ")", "{", "unset", "(", "$", "query", "->", "wheres", "[", "$", "key", "]", ")", ";", "$", "query", "->", "wheres", "=", "array_values", "(", "$", "query", "->", "wheres", ")", ";", "}" ]
Remove scope constraint from the query @param \Illuminate\Database\Query\Builder $query @param int $key
[ "Remove", "scope", "constraint", "from", "the", "query" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Models/Scopes/OnlyActiveScope.php#L59-L64
czim/laravel-pxlcms
src/Models/Scopes/OnlyActiveScope.php
OnlyActiveScope.removeBinding
protected function removeBinding(BaseBuilder $query, $key) { $bindings = $query->getRawBindings()['where']; unset($bindings[ $key ]); $query->setBindings($bindings); }
php
protected function removeBinding(BaseBuilder $query, $key) { $bindings = $query->getRawBindings()['where']; unset($bindings[ $key ]); $query->setBindings($bindings); }
[ "protected", "function", "removeBinding", "(", "BaseBuilder", "$", "query", ",", "$", "key", ")", "{", "$", "bindings", "=", "$", "query", "->", "getRawBindings", "(", ")", "[", "'where'", "]", ";", "unset", "(", "$", "bindings", "[", "$", "key", "]", ")", ";", "$", "query", "->", "setBindings", "(", "$", "bindings", ")", ";", "}" ]
Remove scope constraint from the query @param \Illuminate\Database\Query\Builder $query @param int $key
[ "Remove", "scope", "constraint", "from", "the", "query" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Models/Scopes/OnlyActiveScope.php#L72-L79
czim/laravel-pxlcms
src/Models/Scopes/OnlyActiveScope.php
OnlyActiveScope.addWithInactive
protected function addWithInactive(Builder $builder) { $builder->macro('withInactive', function (Builder $builder) { $this->remove($builder, $builder->getModel()); return $builder; }); }
php
protected function addWithInactive(Builder $builder) { $builder->macro('withInactive', function (Builder $builder) { $this->remove($builder, $builder->getModel()); return $builder; }); }
[ "protected", "function", "addWithInactive", "(", "Builder", "$", "builder", ")", "{", "$", "builder", "->", "macro", "(", "'withInactive'", ",", "function", "(", "Builder", "$", "builder", ")", "{", "$", "this", "->", "remove", "(", "$", "builder", ",", "$", "builder", "->", "getModel", "(", ")", ")", ";", "return", "$", "builder", ";", "}", ")", ";", "}" ]
Extend Builder with custom method @param \Illuminate\Database\Eloquent\Builder $builder
[ "Extend", "Builder", "with", "custom", "method" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Models/Scopes/OnlyActiveScope.php#L101-L108
axelitus/php-base
src/Flag.php
Flag.isOn
public static function isOn($value, $flag) { if (!Int::is($value)) { throw new \InvalidArgumentException("The \$value parameter must be of type int."); } if (!static::is($flag)) { throw new \InvalidArgumentException("The \$flag parameter must be of type int and a power of 2."); } return static::is($value & $flag); }
php
public static function isOn($value, $flag) { if (!Int::is($value)) { throw new \InvalidArgumentException("The \$value parameter must be of type int."); } if (!static::is($flag)) { throw new \InvalidArgumentException("The \$flag parameter must be of type int and a power of 2."); } return static::is($value & $flag); }
[ "public", "static", "function", "isOn", "(", "$", "value", ",", "$", "flag", ")", "{", "if", "(", "!", "Int", "::", "is", "(", "$", "value", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$value parameter must be of type int.\"", ")", ";", "}", "if", "(", "!", "static", "::", "is", "(", "$", "flag", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$flag parameter must be of type int and a power of 2.\"", ")", ";", "}", "return", "static", "::", "is", "(", "$", "value", "&", "$", "flag", ")", ";", "}" ]
Checks if a flag is set in a given value. @param int $value The value to test the flag on. @param int $flag The flag to be tested. @return bool Returns true if the flag is set in the value, false otherwise. @throws \InvalidArgumentException
[ "Checks", "if", "a", "flag", "is", "set", "in", "a", "given", "value", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Flag.php#L55-L66
axelitus/php-base
src/Flag.php
Flag.setOn
public static function setOn($value, $flag) { if (!Int::is($value)) { throw new \InvalidArgumentException("The \$value parameter must be of type int."); } if (is_array($flag)) { $ret = $value; foreach ($flag as $item) { $ret = static::setOn($ret, $item); } return $ret; } elseif (!static::is($flag)) { throw new \InvalidArgumentException("The \$flag parameter must be of type int and a power of 2."); } return ($value | $flag); }
php
public static function setOn($value, $flag) { if (!Int::is($value)) { throw new \InvalidArgumentException("The \$value parameter must be of type int."); } if (is_array($flag)) { $ret = $value; foreach ($flag as $item) { $ret = static::setOn($ret, $item); } return $ret; } elseif (!static::is($flag)) { throw new \InvalidArgumentException("The \$flag parameter must be of type int and a power of 2."); } return ($value | $flag); }
[ "public", "static", "function", "setOn", "(", "$", "value", ",", "$", "flag", ")", "{", "if", "(", "!", "Int", "::", "is", "(", "$", "value", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$value parameter must be of type int.\"", ")", ";", "}", "if", "(", "is_array", "(", "$", "flag", ")", ")", "{", "$", "ret", "=", "$", "value", ";", "foreach", "(", "$", "flag", "as", "$", "item", ")", "{", "$", "ret", "=", "static", "::", "setOn", "(", "$", "ret", ",", "$", "item", ")", ";", "}", "return", "$", "ret", ";", "}", "elseif", "(", "!", "static", "::", "is", "(", "$", "flag", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$flag parameter must be of type int and a power of 2.\"", ")", ";", "}", "return", "(", "$", "value", "|", "$", "flag", ")", ";", "}" ]
Sets a flag into a value. @param int $value The value to set the flag on. @param int|array $flag The flag(s) to be set. @return int Returns the value with the flag on. @throws \InvalidArgumentException
[ "Sets", "a", "flag", "into", "a", "value", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Flag.php#L95-L113
axelitus/php-base
src/Flag.php
Flag.getValues
public static function getValues($count) { if (!Int::is($count) || $count < 1) { throw new \InvalidArgumentException("The \$count parameter must be of type int and greater than zero."); } $ret = []; $flag = 1; for ($i = 0; $i < $count; $i++) { $ret[] = $flag; $flag <<= 1; } return $ret; }
php
public static function getValues($count) { if (!Int::is($count) || $count < 1) { throw new \InvalidArgumentException("The \$count parameter must be of type int and greater than zero."); } $ret = []; $flag = 1; for ($i = 0; $i < $count; $i++) { $ret[] = $flag; $flag <<= 1; } return $ret; }
[ "public", "static", "function", "getValues", "(", "$", "count", ")", "{", "if", "(", "!", "Int", "::", "is", "(", "$", "count", ")", "||", "$", "count", "<", "1", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$count parameter must be of type int and greater than zero.\"", ")", ";", "}", "$", "ret", "=", "[", "]", ";", "$", "flag", "=", "1", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "ret", "[", "]", "=", "$", "flag", ";", "$", "flag", "<<=", "1", ";", "}", "return", "$", "ret", ";", "}" ]
Gets an array with n consecutive flag values. @param int $count The number of flag values to return. @return array The array containing the n flag values. @throws \InvalidArgumentException
[ "Gets", "an", "array", "with", "n", "consecutive", "flag", "values", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Flag.php#L152-L166
axelitus/php-base
src/Flag.php
Flag.buildMask
public static function buildMask($flag1, $_ = null) { if (!static::is($flag1)) { throw new \InvalidArgumentException("The first parameter must be a flag."); } $mask = $flag1; $args = array_slice(func_get_args(), 1); foreach ($args as $flag) { if (!static::is($flag)) { throw new \InvalidArgumentException("All parameters must be flags."); } $mask = $mask | $flag; } return $mask; }
php
public static function buildMask($flag1, $_ = null) { if (!static::is($flag1)) { throw new \InvalidArgumentException("The first parameter must be a flag."); } $mask = $flag1; $args = array_slice(func_get_args(), 1); foreach ($args as $flag) { if (!static::is($flag)) { throw new \InvalidArgumentException("All parameters must be flags."); } $mask = $mask | $flag; } return $mask; }
[ "public", "static", "function", "buildMask", "(", "$", "flag1", ",", "$", "_", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "flag1", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The first parameter must be a flag.\"", ")", ";", "}", "$", "mask", "=", "$", "flag1", ";", "$", "args", "=", "array_slice", "(", "func_get_args", "(", ")", ",", "1", ")", ";", "foreach", "(", "$", "args", "as", "$", "flag", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "flag", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"All parameters must be flags.\"", ")", ";", "}", "$", "mask", "=", "$", "mask", "|", "$", "flag", ";", "}", "return", "$", "mask", ";", "}" ]
Builds a flag mask with the given flags. @param int $flag1 The first flag. @param int $_ More flags. @return int The mask containing all the flags given. @throws \InvalidArgumentException
[ "Builds", "a", "flag", "mask", "with", "the", "given", "flags", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Flag.php#L214-L231
axelitus/php-base
src/Flag.php
Flag.mask
public static function mask($value, $mask) { if (!Int::is($value) || !Int::is($mask)) { throw new \InvalidArgumentException("Both parameters must be integers."); } return ($value & $mask); }
php
public static function mask($value, $mask) { if (!Int::is($value) || !Int::is($mask)) { throw new \InvalidArgumentException("Both parameters must be integers."); } return ($value & $mask); }
[ "public", "static", "function", "mask", "(", "$", "value", ",", "$", "mask", ")", "{", "if", "(", "!", "Int", "::", "is", "(", "$", "value", ")", "||", "!", "Int", "::", "is", "(", "$", "mask", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Both parameters must be integers.\"", ")", ";", "}", "return", "(", "$", "value", "&", "$", "mask", ")", ";", "}" ]
Applies the mask to the given value and returns the masked result. @param int $value The value to apply the mask to. @param int $mask The mask to apply. @return int The masked value result. @throws \InvalidArgumentException
[ "Applies", "the", "mask", "to", "the", "given", "value", "and", "returns", "the", "masked", "result", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Flag.php#L242-L249
gbprod/elastica-provider-bundle
src/ElasticaProviderBundle/Provider/Registry.php
Registry.get
public function get($index = null, $type = null) { return array_filter( $this->entries, function($entry) use ($index, $type) { return $entry->match($index, $type); } ); }
php
public function get($index = null, $type = null) { return array_filter( $this->entries, function($entry) use ($index, $type) { return $entry->match($index, $type); } ); }
[ "public", "function", "get", "(", "$", "index", "=", "null", ",", "$", "type", "=", "null", ")", "{", "return", "array_filter", "(", "$", "this", "->", "entries", ",", "function", "(", "$", "entry", ")", "use", "(", "$", "index", ",", "$", "type", ")", "{", "return", "$", "entry", "->", "match", "(", "$", "index", ",", "$", "type", ")", ";", "}", ")", ";", "}" ]
Get entries for index and type @param string|null $index @param string|null $type @return array<ProviderEntry>
[ "Get", "entries", "for", "index", "and", "type" ]
train
https://github.com/gbprod/elastica-provider-bundle/blob/ee1e2ca78651d570b7400049bf81d8405fc744fc/src/ElasticaProviderBundle/Provider/Registry.php#L37-L45
php-ddd/command
src/Handler/AbstractCommandHandler.php
AbstractCommandHandler.handle
public function handle(CommandInterface $command) { if (!$this->supports(get_class($command))) { throw new InvalidArgumentException( sprintf( 'The command must be an instance of "%s". "%s" given.', $this->getSupportedCommandClassName(), get_class($command) ) ); } return $this->execute($command); }
php
public function handle(CommandInterface $command) { if (!$this->supports(get_class($command))) { throw new InvalidArgumentException( sprintf( 'The command must be an instance of "%s". "%s" given.', $this->getSupportedCommandClassName(), get_class($command) ) ); } return $this->execute($command); }
[ "public", "function", "handle", "(", "CommandInterface", "$", "command", ")", "{", "if", "(", "!", "$", "this", "->", "supports", "(", "get_class", "(", "$", "command", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'The command must be an instance of \"%s\". \"%s\" given.'", ",", "$", "this", "->", "getSupportedCommandClassName", "(", ")", ",", "get_class", "(", "$", "command", ")", ")", ")", ";", "}", "return", "$", "this", "->", "execute", "(", "$", "command", ")", ";", "}" ]
@param CommandInterface $command @return mixed @throws InvalidArgumentException
[ "@param", "CommandInterface", "$command" ]
train
https://github.com/php-ddd/command/blob/dbad1d35c8d740c29c3a28d34f4a787c2b14688a/src/Handler/AbstractCommandHandler.php#L31-L44
discophp/framework
core/classes/TemplateLoader.class.php
TemplateLoader.getFinalName
public function getFinalName($name){ try { return parent::findTemplate($name); } catch(\Twig_Error_Loader $e){ $exts = \App::config('TEMPLATE_EXTENSION'); if($exts){ if(!is_array($exts)){ $exts = Array($exts); }//if foreach($exts as $e){ try { return parent::findTemplate($name . $e); } catch(\Twig_Error_Loader $e){ } }//foreach }//if }//catch throw new \Twig_Error_Loader("Twig Error Loader Exception : Could name find template `{$name}`"); }
php
public function getFinalName($name){ try { return parent::findTemplate($name); } catch(\Twig_Error_Loader $e){ $exts = \App::config('TEMPLATE_EXTENSION'); if($exts){ if(!is_array($exts)){ $exts = Array($exts); }//if foreach($exts as $e){ try { return parent::findTemplate($name . $e); } catch(\Twig_Error_Loader $e){ } }//foreach }//if }//catch throw new \Twig_Error_Loader("Twig Error Loader Exception : Could name find template `{$name}`"); }
[ "public", "function", "getFinalName", "(", "$", "name", ")", "{", "try", "{", "return", "parent", "::", "findTemplate", "(", "$", "name", ")", ";", "}", "catch", "(", "\\", "Twig_Error_Loader", "$", "e", ")", "{", "$", "exts", "=", "\\", "App", "::", "config", "(", "'TEMPLATE_EXTENSION'", ")", ";", "if", "(", "$", "exts", ")", "{", "if", "(", "!", "is_array", "(", "$", "exts", ")", ")", "{", "$", "exts", "=", "Array", "(", "$", "exts", ")", ";", "}", "//if", "foreach", "(", "$", "exts", "as", "$", "e", ")", "{", "try", "{", "return", "parent", "::", "findTemplate", "(", "$", "name", ".", "$", "e", ")", ";", "}", "catch", "(", "\\", "Twig_Error_Loader", "$", "e", ")", "{", "}", "}", "//foreach", "}", "//if", "}", "//catch", "throw", "new", "\\", "Twig_Error_Loader", "(", "\"Twig Error Loader Exception : Could name find template `{$name}`\"", ")", ";", "}" ]
Get the final name where a template lives, regardless of whether it was called with an extension or not. @param string $name The template name. @return string The final template name. @throws \Twig_Error_Loader
[ "Get", "the", "final", "name", "where", "a", "template", "lives", "regardless", "of", "whether", "it", "was", "called", "with", "an", "extension", "or", "not", "." ]
train
https://github.com/discophp/framework/blob/40ff3ea5225810534195494dc6c21083da4d1356/core/classes/TemplateLoader.class.php#L20-L50
shawnsandy/ui-pages
src/PageKitServiceProvider.php
PageKitServiceProvider.boot
public function boot() { $this->loadViewsFrom(__DIR__ . '/resources/views/pagekit', 'page'); $this->publishes( [ __DIR__ . '/resources/views/pagekit' => resource_path('views/vendor/page'), ], 'pagekit-views' ); $this->publishes( [ __DIR__ . '/resources/views/pagekit' => resource_path('views/pagekit'), ], 'pagekit-theme' ); $this->publishes( [ __DIR__ . '/resources/views/pagekit' => resource_path('views/vendor/page') ], 'pagekit-enveditor' ); $this->publishes( [ __DIR__ . '/public/css/pagekit' => public_path('css/pagekit'), __DIR__ . '/public/css/fonts' => public_path('css/pagekit/fonts'), __DIR__ . '/public/img' => public_path('img'), __DIR__ . '/public/assets' => public_path('assets') ], 'pagekit-assets' ); $this->publishes( [__DIR__ . '/config/pagekit.php' => config_path('pagekit.php')], 'pagekit-config' ); if (!$this->app->runningInConsole()) : include_once __DIR__ . '/Helpers/helper.php'; endif; include_once __DIR__ . "/components/components.php"; $this->pageTheme(); $views = resource_path( "views/pagekit" ); $this->loadViewsFrom($views, 'pagekit'); }
php
public function boot() { $this->loadViewsFrom(__DIR__ . '/resources/views/pagekit', 'page'); $this->publishes( [ __DIR__ . '/resources/views/pagekit' => resource_path('views/vendor/page'), ], 'pagekit-views' ); $this->publishes( [ __DIR__ . '/resources/views/pagekit' => resource_path('views/pagekit'), ], 'pagekit-theme' ); $this->publishes( [ __DIR__ . '/resources/views/pagekit' => resource_path('views/vendor/page') ], 'pagekit-enveditor' ); $this->publishes( [ __DIR__ . '/public/css/pagekit' => public_path('css/pagekit'), __DIR__ . '/public/css/fonts' => public_path('css/pagekit/fonts'), __DIR__ . '/public/img' => public_path('img'), __DIR__ . '/public/assets' => public_path('assets') ], 'pagekit-assets' ); $this->publishes( [__DIR__ . '/config/pagekit.php' => config_path('pagekit.php')], 'pagekit-config' ); if (!$this->app->runningInConsole()) : include_once __DIR__ . '/Helpers/helper.php'; endif; include_once __DIR__ . "/components/components.php"; $this->pageTheme(); $views = resource_path( "views/pagekit" ); $this->loadViewsFrom($views, 'pagekit'); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "loadViewsFrom", "(", "__DIR__", ".", "'/resources/views/pagekit'", ",", "'page'", ")", ";", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/resources/views/pagekit'", "=>", "resource_path", "(", "'views/vendor/page'", ")", ",", "]", ",", "'pagekit-views'", ")", ";", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/resources/views/pagekit'", "=>", "resource_path", "(", "'views/pagekit'", ")", ",", "]", ",", "'pagekit-theme'", ")", ";", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/resources/views/pagekit'", "=>", "resource_path", "(", "'views/vendor/page'", ")", "]", ",", "'pagekit-enveditor'", ")", ";", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/public/css/pagekit'", "=>", "public_path", "(", "'css/pagekit'", ")", ",", "__DIR__", ".", "'/public/css/fonts'", "=>", "public_path", "(", "'css/pagekit/fonts'", ")", ",", "__DIR__", ".", "'/public/img'", "=>", "public_path", "(", "'img'", ")", ",", "__DIR__", ".", "'/public/assets'", "=>", "public_path", "(", "'assets'", ")", "]", ",", "'pagekit-assets'", ")", ";", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/config/pagekit.php'", "=>", "config_path", "(", "'pagekit.php'", ")", "]", ",", "'pagekit-config'", ")", ";", "if", "(", "!", "$", "this", "->", "app", "->", "runningInConsole", "(", ")", ")", ":", "include_once", "__DIR__", ".", "'/Helpers/helper.php'", ";", "endif", ";", "include_once", "__DIR__", ".", "\"/components/components.php\"", ";", "$", "this", "->", "pageTheme", "(", ")", ";", "$", "views", "=", "resource_path", "(", "\"views/pagekit\"", ")", ";", "$", "this", "->", "loadViewsFrom", "(", "$", "views", ",", "'pagekit'", ")", ";", "}" ]
Perform post-registration booting of services. @return null
[ "Perform", "post", "-", "registration", "booting", "of", "services", "." ]
train
https://github.com/shawnsandy/ui-pages/blob/11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8/src/PageKitServiceProvider.php#L17-L68
shawnsandy/ui-pages
src/PageKitServiceProvider.php
PageKitServiceProvider.register
public function register() { $this->mergeConfigFrom( __DIR__ . '/config/pagekit.php', 'pagekit' ); $this->app->bind( 'Breadcrumbs', function () { return new Breadcrumbs(); } ); $this->app->bind( 'MKD', function () { return new Markdown(); } ); $this->app->bind('Pages', function () { return new Page(); } ); }
php
public function register() { $this->mergeConfigFrom( __DIR__ . '/config/pagekit.php', 'pagekit' ); $this->app->bind( 'Breadcrumbs', function () { return new Breadcrumbs(); } ); $this->app->bind( 'MKD', function () { return new Markdown(); } ); $this->app->bind('Pages', function () { return new Page(); } ); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "mergeConfigFrom", "(", "__DIR__", ".", "'/config/pagekit.php'", ",", "'pagekit'", ")", ";", "$", "this", "->", "app", "->", "bind", "(", "'Breadcrumbs'", ",", "function", "(", ")", "{", "return", "new", "Breadcrumbs", "(", ")", ";", "}", ")", ";", "$", "this", "->", "app", "->", "bind", "(", "'MKD'", ",", "function", "(", ")", "{", "return", "new", "Markdown", "(", ")", ";", "}", ")", ";", "$", "this", "->", "app", "->", "bind", "(", "'Pages'", ",", "function", "(", ")", "{", "return", "new", "Page", "(", ")", ";", "}", ")", ";", "}" ]
Register any package services. @return null
[ "Register", "any", "package", "services", "." ]
train
https://github.com/shawnsandy/ui-pages/blob/11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8/src/PageKitServiceProvider.php#L76-L98
shawnsandy/ui-pages
src/PageKitServiceProvider.php
PageKitServiceProvider.pageTheme
public function pageTheme() { view()->composer("*", function ($view) { /* get the theme if set in config */ $theme = config("pagekit.theme", null); /* if not theme is set in the config */ /* check the theme folder if exist or use the theme in package*/ if (!$theme): if (view()->exists("theme.page.index")): $theme = "theme.page."; else : $theme = "page::"; endif; endif; view()->share('pageTheme', $theme); } ); }
php
public function pageTheme() { view()->composer("*", function ($view) { /* get the theme if set in config */ $theme = config("pagekit.theme", null); /* if not theme is set in the config */ /* check the theme folder if exist or use the theme in package*/ if (!$theme): if (view()->exists("theme.page.index")): $theme = "theme.page."; else : $theme = "page::"; endif; endif; view()->share('pageTheme', $theme); } ); }
[ "public", "function", "pageTheme", "(", ")", "{", "view", "(", ")", "->", "composer", "(", "\"*\"", ",", "function", "(", "$", "view", ")", "{", "/* get the theme if set in config */", "$", "theme", "=", "config", "(", "\"pagekit.theme\"", ",", "null", ")", ";", "/* if not theme is set in the config */", "/* check the theme folder if exist or use the theme in package*/", "if", "(", "!", "$", "theme", ")", ":", "if", "(", "view", "(", ")", "->", "exists", "(", "\"theme.page.index\"", ")", ")", ":", "$", "theme", "=", "\"theme.page.\"", ";", "else", ":", "$", "theme", "=", "\"page::\"", ";", "endif", ";", "endif", ";", "view", "(", ")", "->", "share", "(", "'pageTheme'", ",", "$", "theme", ")", ";", "}", ")", ";", "}" ]
get the default theme
[ "get", "the", "default", "theme" ]
train
https://github.com/shawnsandy/ui-pages/blob/11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8/src/PageKitServiceProvider.php#L105-L130
jasny/router
src/Router/Middleware/NotFound.php
NotFound.simpleResponse
protected function simpleResponse(ResponseInterface $response, $code) { $notFound = $response->withStatus($code); $notFound->getBody()->write('Not found'); return $notFound; }
php
protected function simpleResponse(ResponseInterface $response, $code) { $notFound = $response->withStatus($code); $notFound->getBody()->write('Not found'); return $notFound; }
[ "protected", "function", "simpleResponse", "(", "ResponseInterface", "$", "response", ",", "$", "code", ")", "{", "$", "notFound", "=", "$", "response", "->", "withStatus", "(", "$", "code", ")", ";", "$", "notFound", "->", "getBody", "(", ")", "->", "write", "(", "'Not found'", ")", ";", "return", "$", "notFound", ";", "}" ]
Simple response @param ResponseInterface $response @param int $code @return ResponseInterface
[ "Simple", "response" ]
train
https://github.com/jasny/router/blob/4c776665ba343150b442c21893946e3d54190896/src/Router/Middleware/NotFound.php#L107-L113
TypistTech/wp-option-store
src/ConstantStrategy.php
ConstantStrategy.get
public function get(string $optionName) { $constantName = $this->constantNameFor($optionName); if (! defined($constantName)) { return null; } return constant($constantName); }
php
public function get(string $optionName) { $constantName = $this->constantNameFor($optionName); if (! defined($constantName)) { return null; } return constant($constantName); }
[ "public", "function", "get", "(", "string", "$", "optionName", ")", "{", "$", "constantName", "=", "$", "this", "->", "constantNameFor", "(", "$", "optionName", ")", ";", "if", "(", "!", "defined", "(", "$", "constantName", ")", ")", "{", "return", "null", ";", "}", "return", "constant", "(", "$", "constantName", ")", ";", "}" ]
Option getter. @param string $optionName Name of option to retrieve. @return mixed|null Null if option not exists or its value is actually null.
[ "Option", "getter", "." ]
train
https://github.com/TypistTech/wp-option-store/blob/115ff7cb4b5f566c89c1294fe2b68c82d62cccc2/src/ConstantStrategy.php#L35-L44
phossa2/middleware
src/Middleware/Condition/PathPrefixCondition.php
PathPrefixCondition.evaluate
public function evaluate( RequestInterface $request, ResponseInterface $response )/*# : bool */ { foreach ($this->prefix as $pref) { if (0 === strpos($request->getUri()->getPath(), $pref)) { return true; } } return false; }
php
public function evaluate( RequestInterface $request, ResponseInterface $response )/*# : bool */ { foreach ($this->prefix as $pref) { if (0 === strpos($request->getUri()->getPath(), $pref)) { return true; } } return false; }
[ "public", "function", "evaluate", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "/*# : bool */", "{", "foreach", "(", "$", "this", "->", "prefix", "as", "$", "pref", ")", "{", "if", "(", "0", "===", "strpos", "(", "$", "request", "->", "getUri", "(", ")", "->", "getPath", "(", ")", ",", "$", "pref", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/phossa2/middleware/blob/518e97ae48077f2c11adcd3c2393830ed7ab7ce7/src/Middleware/Condition/PathPrefixCondition.php#L54-L64
pageon/SlackWebhookMonolog
src/Slack/Attachment/Attachment.php
Attachment.setAuthor
public function setAuthor(Author $author) { $this->attachment['author_name'] = $author; if ($author->hasIcon()) { $this->attachment['author_icon'] = $author->getIcon(); } if ($author->hasLink()) { $this->attachment['author_link'] = $author->getLink(); } return $this; }
php
public function setAuthor(Author $author) { $this->attachment['author_name'] = $author; if ($author->hasIcon()) { $this->attachment['author_icon'] = $author->getIcon(); } if ($author->hasLink()) { $this->attachment['author_link'] = $author->getLink(); } return $this; }
[ "public", "function", "setAuthor", "(", "Author", "$", "author", ")", "{", "$", "this", "->", "attachment", "[", "'author_name'", "]", "=", "$", "author", ";", "if", "(", "$", "author", "->", "hasIcon", "(", ")", ")", "{", "$", "this", "->", "attachment", "[", "'author_icon'", "]", "=", "$", "author", "->", "getIcon", "(", ")", ";", "}", "if", "(", "$", "author", "->", "hasLink", "(", ")", ")", "{", "$", "this", "->", "attachment", "[", "'author_link'", "]", "=", "$", "author", "->", "getLink", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
The author parameters will display a small section at the top of a message attachment. @param Author $author @return self
[ "The", "author", "parameters", "will", "display", "a", "small", "section", "at", "the", "top", "of", "a", "message", "attachment", "." ]
train
https://github.com/pageon/SlackWebhookMonolog/blob/6755060ddd6429620fd4c7decbb95f05463fc36b/src/Slack/Attachment/Attachment.php#L90-L103
pageon/SlackWebhookMonolog
src/Slack/Attachment/Attachment.php
Attachment.setTitle
public function setTitle(Title $title) { $this->attachment['title'] = $title; if ($title->hasLink()) { $this->attachment['title_link'] = $title->getLink(); } return $this; }
php
public function setTitle(Title $title) { $this->attachment['title'] = $title; if ($title->hasLink()) { $this->attachment['title_link'] = $title->getLink(); } return $this; }
[ "public", "function", "setTitle", "(", "Title", "$", "title", ")", "{", "$", "this", "->", "attachment", "[", "'title'", "]", "=", "$", "title", ";", "if", "(", "$", "title", "->", "hasLink", "(", ")", ")", "{", "$", "this", "->", "attachment", "[", "'title_link'", "]", "=", "$", "title", "->", "getLink", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
The title is displayed as larger, bold text near the top of a message attachment. @param Title $title @return self
[ "The", "title", "is", "displayed", "as", "larger", "bold", "text", "near", "the", "top", "of", "a", "message", "attachment", "." ]
train
https://github.com/pageon/SlackWebhookMonolog/blob/6755060ddd6429620fd4c7decbb95f05463fc36b/src/Slack/Attachment/Attachment.php#L112-L121
pageon/SlackWebhookMonolog
src/Slack/Attachment/Attachment.php
Attachment.addField
public function addField(Field $field) { if (!isset($this->attachment['fields'])) { $this->attachment['fields'] = []; } $this->attachment['fields'][] = $field; return $this; }
php
public function addField(Field $field) { if (!isset($this->attachment['fields'])) { $this->attachment['fields'] = []; } $this->attachment['fields'][] = $field; return $this; }
[ "public", "function", "addField", "(", "Field", "$", "field", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "attachment", "[", "'fields'", "]", ")", ")", "{", "$", "this", "->", "attachment", "[", "'fields'", "]", "=", "[", "]", ";", "}", "$", "this", "->", "attachment", "[", "'fields'", "]", "[", "]", "=", "$", "field", ";", "return", "$", "this", ";", "}" ]
Will be displayed in a table inside the message attachment. @param Field $field @return self
[ "Will", "be", "displayed", "in", "a", "table", "inside", "the", "message", "attachment", "." ]
train
https://github.com/pageon/SlackWebhookMonolog/blob/6755060ddd6429620fd4c7decbb95f05463fc36b/src/Slack/Attachment/Attachment.php#L130-L139
winzou/limonetik-php-api
src/APIClient.php
APIClient.PaymentOrderCreate
public function PaymentOrderCreate(array $params) { $request = new Request(); $request->setMethod('POST'); foreach (array('PaymentPageId', 'Amount', 'Currency', 'MerchantUrls') as $param) { if (!isset($params[$param])) { throw new InvalidArgumentException($param); } } $params['MerchantId'] = $this->options['merchantId']; $request->setContent(json_encode(array('PaymentOrder' => $params))); return $this->doRequest('PaymentOrder/Create', $request)->getContentJson(); }
php
public function PaymentOrderCreate(array $params) { $request = new Request(); $request->setMethod('POST'); foreach (array('PaymentPageId', 'Amount', 'Currency', 'MerchantUrls') as $param) { if (!isset($params[$param])) { throw new InvalidArgumentException($param); } } $params['MerchantId'] = $this->options['merchantId']; $request->setContent(json_encode(array('PaymentOrder' => $params))); return $this->doRequest('PaymentOrder/Create', $request)->getContentJson(); }
[ "public", "function", "PaymentOrderCreate", "(", "array", "$", "params", ")", "{", "$", "request", "=", "new", "Request", "(", ")", ";", "$", "request", "->", "setMethod", "(", "'POST'", ")", ";", "foreach", "(", "array", "(", "'PaymentPageId'", ",", "'Amount'", ",", "'Currency'", ",", "'MerchantUrls'", ")", "as", "$", "param", ")", "{", "if", "(", "!", "isset", "(", "$", "params", "[", "$", "param", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "$", "param", ")", ";", "}", "}", "$", "params", "[", "'MerchantId'", "]", "=", "$", "this", "->", "options", "[", "'merchantId'", "]", ";", "$", "request", "->", "setContent", "(", "json_encode", "(", "array", "(", "'PaymentOrder'", "=>", "$", "params", ")", ")", ")", ";", "return", "$", "this", "->", "doRequest", "(", "'PaymentOrder/Create'", ",", "$", "request", ")", "->", "getContentJson", "(", ")", ";", "}" ]
@param array $params @return array
[ "@param", "array", "$params" ]
train
https://github.com/winzou/limonetik-php-api/blob/4580dd455a446d2a78090ff932f65d6d54ab301c/src/APIClient.php#L91-L106
winzou/limonetik-php-api
src/APIClient.php
APIClient.PaymentOrderDetail
public function PaymentOrderDetail($paymentOrderId, array $addElements = array()) { $request = new Request(); $request->setMethod('GET'); if (null == $paymentOrderId) { throw new InvalidArgumentException('paymentOrderId'); } $qs = array('Id' => $paymentOrderId); if ($addElements) { $qs['AddElements'] = implode(',', $addElements); } return $this->doRequest('PaymentOrder/Detail', $request, $qs)->getContentJson(); }
php
public function PaymentOrderDetail($paymentOrderId, array $addElements = array()) { $request = new Request(); $request->setMethod('GET'); if (null == $paymentOrderId) { throw new InvalidArgumentException('paymentOrderId'); } $qs = array('Id' => $paymentOrderId); if ($addElements) { $qs['AddElements'] = implode(',', $addElements); } return $this->doRequest('PaymentOrder/Detail', $request, $qs)->getContentJson(); }
[ "public", "function", "PaymentOrderDetail", "(", "$", "paymentOrderId", ",", "array", "$", "addElements", "=", "array", "(", ")", ")", "{", "$", "request", "=", "new", "Request", "(", ")", ";", "$", "request", "->", "setMethod", "(", "'GET'", ")", ";", "if", "(", "null", "==", "$", "paymentOrderId", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'paymentOrderId'", ")", ";", "}", "$", "qs", "=", "array", "(", "'Id'", "=>", "$", "paymentOrderId", ")", ";", "if", "(", "$", "addElements", ")", "{", "$", "qs", "[", "'AddElements'", "]", "=", "implode", "(", "','", ",", "$", "addElements", ")", ";", "}", "return", "$", "this", "->", "doRequest", "(", "'PaymentOrder/Detail'", ",", "$", "request", ",", "$", "qs", ")", "->", "getContentJson", "(", ")", ";", "}" ]
@param int $paymentOrderId @param array $addElements @return array
[ "@param", "int", "$paymentOrderId", "@param", "array", "$addElements" ]
train
https://github.com/winzou/limonetik-php-api/blob/4580dd455a446d2a78090ff932f65d6d54ab301c/src/APIClient.php#L114-L130
winzou/limonetik-php-api
src/APIClient.php
APIClient.PaymentOrderDetailByMerchant
public function PaymentOrderDetailByMerchant($merchantOrderId, array $addElements = array()) { $request = new Request(); $request->setMethod('GET'); if (null == $merchantOrderId) { throw new InvalidArgumentException('merchantOrderId'); } $qs = array( 'MerchantOrderId' => $merchantOrderId, 'MerchantId' => $this->options['merchantId'] ); if ($addElements) { $qs['AddElements'] = implode(',', $addElements); } return $this->doRequest('PaymentOrder/Detail', $request, $qs)->getContentJson(); }
php
public function PaymentOrderDetailByMerchant($merchantOrderId, array $addElements = array()) { $request = new Request(); $request->setMethod('GET'); if (null == $merchantOrderId) { throw new InvalidArgumentException('merchantOrderId'); } $qs = array( 'MerchantOrderId' => $merchantOrderId, 'MerchantId' => $this->options['merchantId'] ); if ($addElements) { $qs['AddElements'] = implode(',', $addElements); } return $this->doRequest('PaymentOrder/Detail', $request, $qs)->getContentJson(); }
[ "public", "function", "PaymentOrderDetailByMerchant", "(", "$", "merchantOrderId", ",", "array", "$", "addElements", "=", "array", "(", ")", ")", "{", "$", "request", "=", "new", "Request", "(", ")", ";", "$", "request", "->", "setMethod", "(", "'GET'", ")", ";", "if", "(", "null", "==", "$", "merchantOrderId", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'merchantOrderId'", ")", ";", "}", "$", "qs", "=", "array", "(", "'MerchantOrderId'", "=>", "$", "merchantOrderId", ",", "'MerchantId'", "=>", "$", "this", "->", "options", "[", "'merchantId'", "]", ")", ";", "if", "(", "$", "addElements", ")", "{", "$", "qs", "[", "'AddElements'", "]", "=", "implode", "(", "','", ",", "$", "addElements", ")", ";", "}", "return", "$", "this", "->", "doRequest", "(", "'PaymentOrder/Detail'", ",", "$", "request", ",", "$", "qs", ")", "->", "getContentJson", "(", ")", ";", "}" ]
@param string $merchantOrderId @param array $addElements @return array
[ "@param", "string", "$merchantOrderId", "@param", "array", "$addElements" ]
train
https://github.com/winzou/limonetik-php-api/blob/4580dd455a446d2a78090ff932f65d6d54ab301c/src/APIClient.php#L138-L157
winzou/limonetik-php-api
src/APIClient.php
APIClient.PaymentOrderCancel
public function PaymentOrderCancel($paymentOrderId, $amount, $currency) { $request = new Request(); $request->setMethod('POST'); foreach (array('paymentOrderId', 'amount', 'currency') as $param) { if (null == $$param) { throw new InvalidArgumentException($param); } } $params = array( 'PaymentOrderId' => $paymentOrderId, 'CancelAmount' => $amount, 'Currency' => $currency ); $request->setContent(json_encode($params)); return $this->doRequest('PaymentOrder/Cancel', $request)->getContentJson(); }
php
public function PaymentOrderCancel($paymentOrderId, $amount, $currency) { $request = new Request(); $request->setMethod('POST'); foreach (array('paymentOrderId', 'amount', 'currency') as $param) { if (null == $$param) { throw new InvalidArgumentException($param); } } $params = array( 'PaymentOrderId' => $paymentOrderId, 'CancelAmount' => $amount, 'Currency' => $currency ); $request->setContent(json_encode($params)); return $this->doRequest('PaymentOrder/Cancel', $request)->getContentJson(); }
[ "public", "function", "PaymentOrderCancel", "(", "$", "paymentOrderId", ",", "$", "amount", ",", "$", "currency", ")", "{", "$", "request", "=", "new", "Request", "(", ")", ";", "$", "request", "->", "setMethod", "(", "'POST'", ")", ";", "foreach", "(", "array", "(", "'paymentOrderId'", ",", "'amount'", ",", "'currency'", ")", "as", "$", "param", ")", "{", "if", "(", "null", "==", "$", "$", "param", ")", "{", "throw", "new", "InvalidArgumentException", "(", "$", "param", ")", ";", "}", "}", "$", "params", "=", "array", "(", "'PaymentOrderId'", "=>", "$", "paymentOrderId", ",", "'CancelAmount'", "=>", "$", "amount", ",", "'Currency'", "=>", "$", "currency", ")", ";", "$", "request", "->", "setContent", "(", "json_encode", "(", "$", "params", ")", ")", ";", "return", "$", "this", "->", "doRequest", "(", "'PaymentOrder/Cancel'", ",", "$", "request", ")", "->", "getContentJson", "(", ")", ";", "}" ]
@param int $paymentOrderId @param float $amount @param string $currency @return array
[ "@param", "int", "$paymentOrderId", "@param", "float", "$amount", "@param", "string", "$currency" ]
train
https://github.com/winzou/limonetik-php-api/blob/4580dd455a446d2a78090ff932f65d6d54ab301c/src/APIClient.php#L166-L186
winzou/limonetik-php-api
src/APIClient.php
APIClient.EventDetail
public function EventDetail($eventId) { $request = new Request(); if (null == $eventId) { throw new InvalidArgumentException('eventId'); } return $this->doRequest('Event/Detail', $request, array('Id' => $eventId))->getContentJson(); }
php
public function EventDetail($eventId) { $request = new Request(); if (null == $eventId) { throw new InvalidArgumentException('eventId'); } return $this->doRequest('Event/Detail', $request, array('Id' => $eventId))->getContentJson(); }
[ "public", "function", "EventDetail", "(", "$", "eventId", ")", "{", "$", "request", "=", "new", "Request", "(", ")", ";", "if", "(", "null", "==", "$", "eventId", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'eventId'", ")", ";", "}", "return", "$", "this", "->", "doRequest", "(", "'Event/Detail'", ",", "$", "request", ",", "array", "(", "'Id'", "=>", "$", "eventId", ")", ")", "->", "getContentJson", "(", ")", ";", "}" ]
@param int $eventId @return array
[ "@param", "int", "$eventId" ]
train
https://github.com/winzou/limonetik-php-api/blob/4580dd455a446d2a78090ff932f65d6d54ab301c/src/APIClient.php#L251-L260
winzou/limonetik-php-api
src/APIClient.php
APIClient.doRequest
protected function doRequest($controller, Request $request, array $qs = array()) { $request->fromUrl($this->getApiEndpoint($controller).'?'.http_build_query($qs)); $request->addHeader('Authorization: Basic '.$this->options['key']); $request->addHeader('Accept: text/json'); $this->client->send($request, $response = new JsonResponse()); $content = $response->getContentJson(true); if (!in_array($content['ReturnCode'], array(self::EXECCODE_SUCCESS, self::EXECCODE_OPERATION_REFUSED))) { $e = new RequestException(print_r(array_merge($content, array('url' => $request->getUrl(), 'content' => $request->getContent())), true)); $e->setRequest($request); throw $e; } return $response; }
php
protected function doRequest($controller, Request $request, array $qs = array()) { $request->fromUrl($this->getApiEndpoint($controller).'?'.http_build_query($qs)); $request->addHeader('Authorization: Basic '.$this->options['key']); $request->addHeader('Accept: text/json'); $this->client->send($request, $response = new JsonResponse()); $content = $response->getContentJson(true); if (!in_array($content['ReturnCode'], array(self::EXECCODE_SUCCESS, self::EXECCODE_OPERATION_REFUSED))) { $e = new RequestException(print_r(array_merge($content, array('url' => $request->getUrl(), 'content' => $request->getContent())), true)); $e->setRequest($request); throw $e; } return $response; }
[ "protected", "function", "doRequest", "(", "$", "controller", ",", "Request", "$", "request", ",", "array", "$", "qs", "=", "array", "(", ")", ")", "{", "$", "request", "->", "fromUrl", "(", "$", "this", "->", "getApiEndpoint", "(", "$", "controller", ")", ".", "'?'", ".", "http_build_query", "(", "$", "qs", ")", ")", ";", "$", "request", "->", "addHeader", "(", "'Authorization: Basic '", ".", "$", "this", "->", "options", "[", "'key'", "]", ")", ";", "$", "request", "->", "addHeader", "(", "'Accept: text/json'", ")", ";", "$", "this", "->", "client", "->", "send", "(", "$", "request", ",", "$", "response", "=", "new", "JsonResponse", "(", ")", ")", ";", "$", "content", "=", "$", "response", "->", "getContentJson", "(", "true", ")", ";", "if", "(", "!", "in_array", "(", "$", "content", "[", "'ReturnCode'", "]", ",", "array", "(", "self", "::", "EXECCODE_SUCCESS", ",", "self", "::", "EXECCODE_OPERATION_REFUSED", ")", ")", ")", "{", "$", "e", "=", "new", "RequestException", "(", "print_r", "(", "array_merge", "(", "$", "content", ",", "array", "(", "'url'", "=>", "$", "request", "->", "getUrl", "(", ")", ",", "'content'", "=>", "$", "request", "->", "getContent", "(", ")", ")", ")", ",", "true", ")", ")", ";", "$", "e", "->", "setRequest", "(", "$", "request", ")", ";", "throw", "$", "e", ";", "}", "return", "$", "response", ";", "}" ]
@parem string $controller @param Request $request @param array $qs @throws RequestException @return JsonResponse
[ "@parem", "string", "$controller", "@param", "Request", "$request", "@param", "array", "$qs" ]
train
https://github.com/winzou/limonetik-php-api/blob/4580dd455a446d2a78090ff932f65d6d54ab301c/src/APIClient.php#L271-L288
winzou/limonetik-php-api
src/APIClient.php
APIClient.getApiEndpoint
protected function getApiEndpoint($controller) { $url = $this->options['sandbox'] ? self::URL_DEV : self::URL_PROD; return $url.'/'.self::VERSION.'/'.$controller; }
php
protected function getApiEndpoint($controller) { $url = $this->options['sandbox'] ? self::URL_DEV : self::URL_PROD; return $url.'/'.self::VERSION.'/'.$controller; }
[ "protected", "function", "getApiEndpoint", "(", "$", "controller", ")", "{", "$", "url", "=", "$", "this", "->", "options", "[", "'sandbox'", "]", "?", "self", "::", "URL_DEV", ":", "self", "::", "URL_PROD", ";", "return", "$", "url", ".", "'/'", ".", "self", "::", "VERSION", ".", "'/'", ".", "$", "controller", ";", "}" ]
@param string $controller @return string
[ "@param", "string", "$controller" ]
train
https://github.com/winzou/limonetik-php-api/blob/4580dd455a446d2a78090ff932f65d6d54ab301c/src/APIClient.php#L295-L300
blast-project/CoreBundle
src/Generator/ControllerGenerator.php
ControllerGenerator.generate
public function generate(BundleInterface $bundle, $controllerClassBasename) { $this->class = sprintf('%s\Controller\%s', $bundle->getNamespace(), $controllerClassBasename); $this->file = sprintf( '%s/Controller/%s.php', $bundle->getPath(), str_replace('\\', '/', $controllerClassBasename) ); $parts = explode('\\', $this->class); if (file_exists($this->file)) { throw new \RuntimeException(sprintf( 'Unable to generate the admin controller class "%s". The file "%s" already exists.', $this->class, realpath($this->file) )); } $this->renderFile('AdminController.php.twig', $this->file, array( 'classBasename' => array_pop($parts), 'namespace' => implode('\\', $parts), )); }
php
public function generate(BundleInterface $bundle, $controllerClassBasename) { $this->class = sprintf('%s\Controller\%s', $bundle->getNamespace(), $controllerClassBasename); $this->file = sprintf( '%s/Controller/%s.php', $bundle->getPath(), str_replace('\\', '/', $controllerClassBasename) ); $parts = explode('\\', $this->class); if (file_exists($this->file)) { throw new \RuntimeException(sprintf( 'Unable to generate the admin controller class "%s". The file "%s" already exists.', $this->class, realpath($this->file) )); } $this->renderFile('AdminController.php.twig', $this->file, array( 'classBasename' => array_pop($parts), 'namespace' => implode('\\', $parts), )); }
[ "public", "function", "generate", "(", "BundleInterface", "$", "bundle", ",", "$", "controllerClassBasename", ")", "{", "$", "this", "->", "class", "=", "sprintf", "(", "'%s\\Controller\\%s'", ",", "$", "bundle", "->", "getNamespace", "(", ")", ",", "$", "controllerClassBasename", ")", ";", "$", "this", "->", "file", "=", "sprintf", "(", "'%s/Controller/%s.php'", ",", "$", "bundle", "->", "getPath", "(", ")", ",", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "controllerClassBasename", ")", ")", ";", "$", "parts", "=", "explode", "(", "'\\\\'", ",", "$", "this", "->", "class", ")", ";", "if", "(", "file_exists", "(", "$", "this", "->", "file", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Unable to generate the admin controller class \"%s\". The file \"%s\" already exists.'", ",", "$", "this", "->", "class", ",", "realpath", "(", "$", "this", "->", "file", ")", ")", ")", ";", "}", "$", "this", "->", "renderFile", "(", "'AdminController.php.twig'", ",", "$", "this", "->", "file", ",", "array", "(", "'classBasename'", "=>", "array_pop", "(", "$", "parts", ")", ",", "'namespace'", "=>", "implode", "(", "'\\\\'", ",", "$", "parts", ")", ",", ")", ")", ";", "}" ]
@param BundleInterface $bundle @param string $controllerClassBasename @throws \RuntimeException
[ "@param", "BundleInterface", "$bundle", "@param", "string", "$controllerClassBasename" ]
train
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Generator/ControllerGenerator.php#L47-L69
gregorybesson/PlaygroundCore
src/Service/Image.php
Image.correctOrientation
public function correctOrientation() { try { $exif = exif_read_data($this->file); } catch (\Exception $e) { return $this; } if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 8: $this->image = imagerotate($this->image, 90, 0); break; case 3: $this->image = imagerotate($this->image, 180, 0); break; case 6: $this->image = imagerotate($this->image, -90, 0); break; } } return $this; }
php
public function correctOrientation() { try { $exif = exif_read_data($this->file); } catch (\Exception $e) { return $this; } if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 8: $this->image = imagerotate($this->image, 90, 0); break; case 3: $this->image = imagerotate($this->image, 180, 0); break; case 6: $this->image = imagerotate($this->image, -90, 0); break; } } return $this; }
[ "public", "function", "correctOrientation", "(", ")", "{", "try", "{", "$", "exif", "=", "exif_read_data", "(", "$", "this", "->", "file", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "$", "this", ";", "}", "if", "(", "!", "empty", "(", "$", "exif", "[", "'Orientation'", "]", ")", ")", "{", "switch", "(", "$", "exif", "[", "'Orientation'", "]", ")", "{", "case", "8", ":", "$", "this", "->", "image", "=", "imagerotate", "(", "$", "this", "->", "image", ",", "90", ",", "0", ")", ";", "break", ";", "case", "3", ":", "$", "this", "->", "image", "=", "imagerotate", "(", "$", "this", "->", "image", ",", "180", ",", "0", ")", ";", "break", ";", "case", "6", ":", "$", "this", "->", "image", "=", "imagerotate", "(", "$", "this", "->", "image", ",", "-", "90", ",", "0", ")", ";", "break", ";", "}", "}", "return", "$", "this", ";", "}" ]
Correct image orientation (if present in the medadata) use php_exif @return \PlaygroundCore\Service\Image
[ "Correct", "image", "orientation", "(", "if", "present", "in", "the", "medadata", ")", "use", "php_exif" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Service/Image.php#L65-L86
gregorybesson/PlaygroundCore
src/Service/Image.php
Image.save
public function save($path = null) { if (is_null($path)) { $path = $this->file; } imagejpeg($this->image, $path); return $this; }
php
public function save($path = null) { if (is_null($path)) { $path = $this->file; } imagejpeg($this->image, $path); return $this; }
[ "public", "function", "save", "(", "$", "path", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "path", ")", ")", "{", "$", "path", "=", "$", "this", "->", "file", ";", "}", "imagejpeg", "(", "$", "this", "->", "image", ",", "$", "path", ")", ";", "return", "$", "this", ";", "}" ]
save as jpeg @param string $path @return \PlaygroundCore\Service\Image
[ "save", "as", "jpeg" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Service/Image.php#L93-L100
bocharsky-bw/FileNamingResolver
src/NamingStrategy/HashNamingStrategy.php
HashNamingStrategy.provideName
public function provideName(FileInfo $srcFileInfo) { $string = $this->generateUniqueString(); $hash = hash($this->algorithm, $string); $dstFileInfo = $this->provideNameByHash($srcFileInfo, $hash); return $dstFileInfo; }
php
public function provideName(FileInfo $srcFileInfo) { $string = $this->generateUniqueString(); $hash = hash($this->algorithm, $string); $dstFileInfo = $this->provideNameByHash($srcFileInfo, $hash); return $dstFileInfo; }
[ "public", "function", "provideName", "(", "FileInfo", "$", "srcFileInfo", ")", "{", "$", "string", "=", "$", "this", "->", "generateUniqueString", "(", ")", ";", "$", "hash", "=", "hash", "(", "$", "this", "->", "algorithm", ",", "$", "string", ")", ";", "$", "dstFileInfo", "=", "$", "this", "->", "provideNameByHash", "(", "$", "srcFileInfo", ",", "$", "hash", ")", ";", "return", "$", "dstFileInfo", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bocharsky-bw/FileNamingResolver/blob/0a0fe86fee0e7acf1ab43a84c1abd51954ce2fbe/src/NamingStrategy/HashNamingStrategy.php#L15-L23
huasituo/hstcms
src/Libraries/Fields/Radio.php
Radio.input
public function input($cname, $name, $cfg, $value = NULL, $id = 0) { $cfg['option']['value'] = isset($cfg['option']['value']) ? $cfg['option']['value'] : ""; // 字段显示名称 $text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font>&nbsp;' : '').$cname; // 表单附加参数 $attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : ''; // 字段提示信息 $tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips']: ''; // 字段默认值 $value = $value ? $value : $cfg['option']['value']; $str = ''; // 表单选项 $options = isset($cfg['option']['list']) && $cfg['option']['list'] ? $cfg['option']['list'] : '';// 禁止修改 $disabled = !$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && $cfg['validate']['isedit'] ? 'disabled' : ''; if ($options) { $options = explode(PHP_EOL, str_replace(array(chr(13), chr(10)), PHP_EOL, $options)); $_i = 0; foreach ($options as $t) { if ($t) { $_i++; $n = $v = $selected = ''; list($n, $v) = explode('|', $t); $v = $v === NULL ? trim($n) : trim($v); $selected = $v == $value ? ' checked' : ''; if(!$selected && $_i == 1){ $selected = 'checked'; } $str.= '<input '.$disabled.' type="radio" name="'.$name.'" value="'.$v.'" '.$selected.' '.$attr.' />&nbsp;<label>'.$n.'</label>&nbsp;&nbsp;&nbsp;&nbsp;'; } } } return $this->input_format($name, $text, $str, $tips); }
php
public function input($cname, $name, $cfg, $value = NULL, $id = 0) { $cfg['option']['value'] = isset($cfg['option']['value']) ? $cfg['option']['value'] : ""; // 字段显示名称 $text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font>&nbsp;' : '').$cname; // 表单附加参数 $attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : ''; // 字段提示信息 $tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips']: ''; // 字段默认值 $value = $value ? $value : $cfg['option']['value']; $str = ''; // 表单选项 $options = isset($cfg['option']['list']) && $cfg['option']['list'] ? $cfg['option']['list'] : '';// 禁止修改 $disabled = !$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && $cfg['validate']['isedit'] ? 'disabled' : ''; if ($options) { $options = explode(PHP_EOL, str_replace(array(chr(13), chr(10)), PHP_EOL, $options)); $_i = 0; foreach ($options as $t) { if ($t) { $_i++; $n = $v = $selected = ''; list($n, $v) = explode('|', $t); $v = $v === NULL ? trim($n) : trim($v); $selected = $v == $value ? ' checked' : ''; if(!$selected && $_i == 1){ $selected = 'checked'; } $str.= '<input '.$disabled.' type="radio" name="'.$name.'" value="'.$v.'" '.$selected.' '.$attr.' />&nbsp;<label>'.$n.'</label>&nbsp;&nbsp;&nbsp;&nbsp;'; } } } return $this->input_format($name, $text, $str, $tips); }
[ "public", "function", "input", "(", "$", "cname", ",", "$", "name", ",", "$", "cfg", ",", "$", "value", "=", "NULL", ",", "$", "id", "=", "0", ")", "{", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", "=", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", ")", "?", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", ":", "\"\"", ";", "// 字段显示名称", "$", "text", "=", "(", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'required'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'required'", "]", "==", "1", "?", "'<font color=\"red\">*</font>&nbsp;'", ":", "''", ")", ".", "$", "cname", ";", "// 表单附加参数", "$", "attr", "=", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'formattr'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'formattr'", "]", "?", "$", "cfg", "[", "'validate'", "]", "[", "'formattr'", "]", ":", "''", ";", "// 字段提示信息", "$", "tips", "=", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'tips'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'tips'", "]", "?", "$", "cfg", "[", "'validate'", "]", "[", "'tips'", "]", ":", "''", ";", "// 字段默认值", "$", "value", "=", "$", "value", "?", "$", "value", ":", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", ";", "$", "str", "=", "''", ";", "// 表单选项", "$", "options", "=", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'list'", "]", ")", "&&", "$", "cfg", "[", "'option'", "]", "[", "'list'", "]", "?", "$", "cfg", "[", "'option'", "]", "[", "'list'", "]", ":", "''", ";", "// 禁止修改", "$", "disabled", "=", "!", "$", "this", "->", "isadmin", "&&", "$", "id", "&&", "$", "value", "&&", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'isedit'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'isedit'", "]", "?", "'disabled'", ":", "''", ";", "if", "(", "$", "options", ")", "{", "$", "options", "=", "explode", "(", "PHP_EOL", ",", "str_replace", "(", "array", "(", "chr", "(", "13", ")", ",", "chr", "(", "10", ")", ")", ",", "PHP_EOL", ",", "$", "options", ")", ")", ";", "$", "_i", "=", "0", ";", "foreach", "(", "$", "options", "as", "$", "t", ")", "{", "if", "(", "$", "t", ")", "{", "$", "_i", "++", ";", "$", "n", "=", "$", "v", "=", "$", "selected", "=", "''", ";", "list", "(", "$", "n", ",", "$", "v", ")", "=", "explode", "(", "'|'", ",", "$", "t", ")", ";", "$", "v", "=", "$", "v", "===", "NULL", "?", "trim", "(", "$", "n", ")", ":", "trim", "(", "$", "v", ")", ";", "$", "selected", "=", "$", "v", "==", "$", "value", "?", "' checked'", ":", "''", ";", "if", "(", "!", "$", "selected", "&&", "$", "_i", "==", "1", ")", "{", "$", "selected", "=", "'checked'", ";", "}", "$", "str", ".=", "'<input '", ".", "$", "disabled", ".", "' type=\"radio\" name=\"'", ".", "$", "name", ".", "'\" value=\"'", ".", "$", "v", ".", "'\" '", ".", "$", "selected", ".", "' '", ".", "$", "attr", ".", "' />&nbsp;<label>'", ".", "$", "n", ".", "'</label>&nbsp;&nbsp;&nbsp;&nbsp;'", ";", "}", "}", "}", "return", "$", "this", "->", "input_format", "(", "$", "name", ",", "$", "text", ",", "$", "str", ",", "$", "tips", ")", ";", "}" ]
字段表单输入 @param string $cname 字段别名 @param string $name 字段名称 @param array $cfg 字段配置 @param string $value 值 @return string
[ "字段表单输入" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Radio.php#L57-L90
huasituo/hstcms
src/Libraries/Fields/Radio.php
Radio.output_data
public function output_data($data, $field = []) { if(!isset($data[$field['fieldname']])) { return $data; } $value = $data[$field['fieldname']]; $data['_'.$field['fieldname']] = $value; if(!$value) { return $data; } $cfg = $field['setting']['option']; $options = @explode(PHP_EOL, str_replace(array(chr(13), chr(10)), PHP_EOL, $cfg['list'])); $_options = array(); foreach ($options as $key => $val) { $_value = @explode('|', $val); $_options[$_value[1]] = isset($_value[0]) ? $_value[0] : ''; } $data[$field['fieldname']] = $_options[$value]; return $data; }
php
public function output_data($data, $field = []) { if(!isset($data[$field['fieldname']])) { return $data; } $value = $data[$field['fieldname']]; $data['_'.$field['fieldname']] = $value; if(!$value) { return $data; } $cfg = $field['setting']['option']; $options = @explode(PHP_EOL, str_replace(array(chr(13), chr(10)), PHP_EOL, $cfg['list'])); $_options = array(); foreach ($options as $key => $val) { $_value = @explode('|', $val); $_options[$_value[1]] = isset($_value[0]) ? $_value[0] : ''; } $data[$field['fieldname']] = $_options[$value]; return $data; }
[ "public", "function", "output_data", "(", "$", "data", ",", "$", "field", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "$", "field", "[", "'fieldname'", "]", "]", ")", ")", "{", "return", "$", "data", ";", "}", "$", "value", "=", "$", "data", "[", "$", "field", "[", "'fieldname'", "]", "]", ";", "$", "data", "[", "'_'", ".", "$", "field", "[", "'fieldname'", "]", "]", "=", "$", "value", ";", "if", "(", "!", "$", "value", ")", "{", "return", "$", "data", ";", "}", "$", "cfg", "=", "$", "field", "[", "'setting'", "]", "[", "'option'", "]", ";", "$", "options", "=", "@", "explode", "(", "PHP_EOL", ",", "str_replace", "(", "array", "(", "chr", "(", "13", ")", ",", "chr", "(", "10", ")", ")", ",", "PHP_EOL", ",", "$", "cfg", "[", "'list'", "]", ")", ")", ";", "$", "_options", "=", "array", "(", ")", ";", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "_value", "=", "@", "explode", "(", "'|'", ",", "$", "val", ")", ";", "$", "_options", "[", "$", "_value", "[", "1", "]", "]", "=", "isset", "(", "$", "_value", "[", "0", "]", ")", "?", "$", "_value", "[", "0", "]", ":", "''", ";", "}", "$", "data", "[", "$", "field", "[", "'fieldname'", "]", "]", "=", "$", "_options", "[", "$", "value", "]", ";", "return", "$", "data", ";", "}" ]
字段输出
[ "字段输出" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Radio.php#L95-L114
jan-dolata/crude-crud
src/Engine/CrudeSetupTrait/InputType.php
InputType.setTypes
public function setTypes($attr, $type = null) { if (is_array($attr)) $this->inputType = array_merge($this->inputType, $attr); else $this->inputType[$attr] = $type; return $this; }
php
public function setTypes($attr, $type = null) { if (is_array($attr)) $this->inputType = array_merge($this->inputType, $attr); else $this->inputType[$attr] = $type; return $this; }
[ "public", "function", "setTypes", "(", "$", "attr", ",", "$", "type", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "attr", ")", ")", "$", "this", "->", "inputType", "=", "array_merge", "(", "$", "this", "->", "inputType", ",", "$", "attr", ")", ";", "else", "$", "this", "->", "inputType", "[", "$", "attr", "]", "=", "$", "type", ";", "return", "$", "this", ";", "}" ]
Sets the Input types. @param string|array $attr @param array $value @return self
[ "Sets", "the", "Input", "types", "." ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/CrudeSetupTrait/InputType.php#L34-L42
jan-dolata/crude-crud
src/Engine/CrudeSetupTrait/InputType.php
InputType.setTypesGroup
public function setTypesGroup($types, $attr = null) { if (! is_array($types)) $types = [$types => $attr]; foreach ($types as $type => $attrList) { if (! is_array($attrList)) $attrList = [$attrList]; foreach ($attrList as $attr) $this->inputType[$attr] = $type; } return $this; }
php
public function setTypesGroup($types, $attr = null) { if (! is_array($types)) $types = [$types => $attr]; foreach ($types as $type => $attrList) { if (! is_array($attrList)) $attrList = [$attrList]; foreach ($attrList as $attr) $this->inputType[$attr] = $type; } return $this; }
[ "public", "function", "setTypesGroup", "(", "$", "types", ",", "$", "attr", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "types", ")", ")", "$", "types", "=", "[", "$", "types", "=>", "$", "attr", "]", ";", "foreach", "(", "$", "types", "as", "$", "type", "=>", "$", "attrList", ")", "{", "if", "(", "!", "is_array", "(", "$", "attrList", ")", ")", "$", "attrList", "=", "[", "$", "attrList", "]", ";", "foreach", "(", "$", "attrList", "as", "$", "attr", ")", "$", "this", "->", "inputType", "[", "$", "attr", "]", "=", "$", "type", ";", "}", "return", "$", "this", ";", "}" ]
Set new or change input types @param string|array $types @param array $attr @return self
[ "Set", "new", "or", "change", "input", "types" ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/CrudeSetupTrait/InputType.php#L52-L66
itgalaxy/bin-wrapper
src/BinWrapper.php
BinWrapper.binCheck
private function binCheck($bin, $args = ['--help']) { $isExecutable = is_executable($bin); if (!$isExecutable) { throw new \Exception( 'Couldn\'t execute the ' . $bin . ' binary. Make sure it has the right permissions.' ); } exec($bin . ' ' . implode(' ', $args), $output, $returnVar); if ($returnVar !== 0) { return false; } return true; }
php
private function binCheck($bin, $args = ['--help']) { $isExecutable = is_executable($bin); if (!$isExecutable) { throw new \Exception( 'Couldn\'t execute the ' . $bin . ' binary. Make sure it has the right permissions.' ); } exec($bin . ' ' . implode(' ', $args), $output, $returnVar); if ($returnVar !== 0) { return false; } return true; }
[ "private", "function", "binCheck", "(", "$", "bin", ",", "$", "args", "=", "[", "'--help'", "]", ")", "{", "$", "isExecutable", "=", "is_executable", "(", "$", "bin", ")", ";", "if", "(", "!", "$", "isExecutable", ")", "{", "throw", "new", "\\", "Exception", "(", "'Couldn\\'t execute the '", ".", "$", "bin", ".", "' binary. Make sure it has the right permissions.'", ")", ";", "}", "exec", "(", "$", "bin", ".", "' '", ".", "implode", "(", "' '", ",", "$", "args", ")", ",", "$", "output", ",", "$", "returnVar", ")", ";", "if", "(", "$", "returnVar", "!==", "0", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Todo move to separatly repository
[ "Todo", "move", "to", "separatly", "repository" ]
train
https://github.com/itgalaxy/bin-wrapper/blob/f4217cb6a1ae5a2abea180255ba14ef264118d43/src/BinWrapper.php#L198-L215
hollodotme/TreeMDown
src/FileSystem/Tree.php
Tree.getLeafObject
public function getLeafObject( string $filepath ) : Leaf { $leafObject = new $this->leafObjectClass( $this->search, $filepath ); if ( $leafObject instanceof Leaf ) { return $leafObject; } throw new \RuntimeException( sprintf( '%s is not a subclass of %s\\Leaf', $this->leafObjectClass, __NAMESPACE__ ) ); }
php
public function getLeafObject( string $filepath ) : Leaf { $leafObject = new $this->leafObjectClass( $this->search, $filepath ); if ( $leafObject instanceof Leaf ) { return $leafObject; } throw new \RuntimeException( sprintf( '%s is not a subclass of %s\\Leaf', $this->leafObjectClass, __NAMESPACE__ ) ); }
[ "public", "function", "getLeafObject", "(", "string", "$", "filepath", ")", ":", "Leaf", "{", "$", "leafObject", "=", "new", "$", "this", "->", "leafObjectClass", "(", "$", "this", "->", "search", ",", "$", "filepath", ")", ";", "if", "(", "$", "leafObject", "instanceof", "Leaf", ")", "{", "return", "$", "leafObject", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'%s is not a subclass of %s\\\\Leaf'", ",", "$", "this", "->", "leafObjectClass", ",", "__NAMESPACE__", ")", ")", ";", "}" ]
Return a new leaf object @param string $filepath @throws \RuntimeException @return Leaf
[ "Return", "a", "new", "leaf", "object" ]
train
https://github.com/hollodotme/TreeMDown/blob/462c4118c70b68963e0176d540fc8502730ffe27/src/FileSystem/Tree.php#L197-L207
BugBuster1701/banner
classes/BannerImage.php
BannerImage.getBannerImageSize
public function getBannerImageSize($BannerImage,$BannerType) { switch ($BannerType) { case self::BANNER_TYPE_INTERN : return $this->getImageSizeInternal($BannerImage); break; case self::BANNER_TYPE_EXTERN : return $this->getImageSizeExternal($BannerImage); break; case self::BANNER_TYPE_TEXT : return false; break; default : return false; break; } }
php
public function getBannerImageSize($BannerImage,$BannerType) { switch ($BannerType) { case self::BANNER_TYPE_INTERN : return $this->getImageSizeInternal($BannerImage); break; case self::BANNER_TYPE_EXTERN : return $this->getImageSizeExternal($BannerImage); break; case self::BANNER_TYPE_TEXT : return false; break; default : return false; break; } }
[ "public", "function", "getBannerImageSize", "(", "$", "BannerImage", ",", "$", "BannerType", ")", "{", "switch", "(", "$", "BannerType", ")", "{", "case", "self", "::", "BANNER_TYPE_INTERN", ":", "return", "$", "this", "->", "getImageSizeInternal", "(", "$", "BannerImage", ")", ";", "break", ";", "case", "self", "::", "BANNER_TYPE_EXTERN", ":", "return", "$", "this", "->", "getImageSizeExternal", "(", "$", "BannerImage", ")", ";", "break", ";", "case", "self", "::", "BANNER_TYPE_TEXT", ":", "return", "false", ";", "break", ";", "default", ":", "return", "false", ";", "break", ";", "}", "}" ]
Get the size of an image @param string $BannerImage Image path/link @param string $BannerType intern,extern,text @return mixed $array / false
[ "Get", "the", "size", "of", "an", "image" ]
train
https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/BannerImage.php#L85-L102
BugBuster1701/banner
classes/BannerImage.php
BannerImage.getImageSizeInternal
protected function getImageSizeInternal($BannerImage) { try { $arrImageSize = getimagesize(TL_ROOT . '/' . $BannerImage); } catch (\Exception $e) { $arrImageSize = false; } if ($arrImageSize === false) { //Workaround for PHP without zlib on SWC files $arrImageSize = $this->getImageSizeCompressed($BannerImage); } ModuleBannerLog::writeLog(__METHOD__ , __LINE__ , 'Image Size: '. print_r($arrImageSize,true)); return $arrImageSize; }
php
protected function getImageSizeInternal($BannerImage) { try { $arrImageSize = getimagesize(TL_ROOT . '/' . $BannerImage); } catch (\Exception $e) { $arrImageSize = false; } if ($arrImageSize === false) { //Workaround for PHP without zlib on SWC files $arrImageSize = $this->getImageSizeCompressed($BannerImage); } ModuleBannerLog::writeLog(__METHOD__ , __LINE__ , 'Image Size: '. print_r($arrImageSize,true)); return $arrImageSize; }
[ "protected", "function", "getImageSizeInternal", "(", "$", "BannerImage", ")", "{", "try", "{", "$", "arrImageSize", "=", "getimagesize", "(", "TL_ROOT", ".", "'/'", ".", "$", "BannerImage", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "arrImageSize", "=", "false", ";", "}", "if", "(", "$", "arrImageSize", "===", "false", ")", "{", "//Workaround for PHP without zlib on SWC files", "$", "arrImageSize", "=", "$", "this", "->", "getImageSizeCompressed", "(", "$", "BannerImage", ")", ";", "}", "ModuleBannerLog", "::", "writeLog", "(", "__METHOD__", ",", "__LINE__", ",", "'Image Size: '", ".", "print_r", "(", "$", "arrImageSize", ",", "true", ")", ")", ";", "return", "$", "arrImageSize", ";", "}" ]
Get the size of an internal image @param string $BannerImage Image path @return mixed $array / false
[ "Get", "the", "size", "of", "an", "internal", "image" ]
train
https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/BannerImage.php#L110-L129
BugBuster1701/banner
classes/BannerImage.php
BannerImage.getImageSizeExternal
protected function getImageSizeExternal($BannerImage) { $token = md5(uniqid(rand(), true)); $tmpImage = 'system/tmp/mod_banner_fe_'.$token.'.tmp'; // HOOK: proxy module if ( \Config::get('useProxy') && in_array('proxy', \ModuleLoader::getActive()) ) { $objRequest = new \ProxyRequest(); } else { $objRequest = new \Request(); $objRequest->redirect = true; // #75: Unterstützung der redirects für externe Affiliat Banner $objRequest->rlimit = 5; // #75: Unterstützung der redirects für externe Affiliat Banner } $objRequest->send(html_entity_decode($BannerImage, ENT_NOQUOTES, 'UTF-8')); //old: Test auf chunked, nicht noetig solange Contao bei HTTP/1.0 bleibt try { $objFile = new \File($tmpImage); $objFile->write($objRequest->response); $objFile->close(); } // Temp directory not writeable catch (\Exception $e) { if ($e->getCode() == 0) { log_message('[getImageSizeExternal] tmpFile Problem: notWriteable', 'error.log'); } else { log_message('[getImageSizeExternal] tmpFile Problem: error', 'error.log'); } return false; } $objRequest=null; unset($objRequest); $arrImageSize = $this->getImageSizeInternal($tmpImage); if ($arrImageSize === false) //Workaround fuer PHP ohne zlib bei SWC Files { $arrImageSize = $this->getImageSizeCompressed($tmpImage); } $objFile->delete(); $objFile = null; unset($objFile); ModuleBannerLog::writeLog(__METHOD__ , __LINE__ , 'Image Size: '. print_r($arrImageSize,true)); return $arrImageSize; }
php
protected function getImageSizeExternal($BannerImage) { $token = md5(uniqid(rand(), true)); $tmpImage = 'system/tmp/mod_banner_fe_'.$token.'.tmp'; // HOOK: proxy module if ( \Config::get('useProxy') && in_array('proxy', \ModuleLoader::getActive()) ) { $objRequest = new \ProxyRequest(); } else { $objRequest = new \Request(); $objRequest->redirect = true; // #75: Unterstützung der redirects für externe Affiliat Banner $objRequest->rlimit = 5; // #75: Unterstützung der redirects für externe Affiliat Banner } $objRequest->send(html_entity_decode($BannerImage, ENT_NOQUOTES, 'UTF-8')); //old: Test auf chunked, nicht noetig solange Contao bei HTTP/1.0 bleibt try { $objFile = new \File($tmpImage); $objFile->write($objRequest->response); $objFile->close(); } // Temp directory not writeable catch (\Exception $e) { if ($e->getCode() == 0) { log_message('[getImageSizeExternal] tmpFile Problem: notWriteable', 'error.log'); } else { log_message('[getImageSizeExternal] tmpFile Problem: error', 'error.log'); } return false; } $objRequest=null; unset($objRequest); $arrImageSize = $this->getImageSizeInternal($tmpImage); if ($arrImageSize === false) //Workaround fuer PHP ohne zlib bei SWC Files { $arrImageSize = $this->getImageSizeCompressed($tmpImage); } $objFile->delete(); $objFile = null; unset($objFile); ModuleBannerLog::writeLog(__METHOD__ , __LINE__ , 'Image Size: '. print_r($arrImageSize,true)); return $arrImageSize; }
[ "protected", "function", "getImageSizeExternal", "(", "$", "BannerImage", ")", "{", "$", "token", "=", "md5", "(", "uniqid", "(", "rand", "(", ")", ",", "true", ")", ")", ";", "$", "tmpImage", "=", "'system/tmp/mod_banner_fe_'", ".", "$", "token", ".", "'.tmp'", ";", "// HOOK: proxy module", "if", "(", "\\", "Config", "::", "get", "(", "'useProxy'", ")", "&&", "in_array", "(", "'proxy'", ",", "\\", "ModuleLoader", "::", "getActive", "(", ")", ")", ")", "{", "$", "objRequest", "=", "new", "\\", "ProxyRequest", "(", ")", ";", "}", "else", "{", "$", "objRequest", "=", "new", "\\", "Request", "(", ")", ";", "$", "objRequest", "->", "redirect", "=", "true", ";", "// #75: Unterstützung der redirects für externe Affiliat Banner", "$", "objRequest", "->", "rlimit", "=", "5", ";", "// #75: Unterstützung der redirects für externe Affiliat Banner", "}", "$", "objRequest", "->", "send", "(", "html_entity_decode", "(", "$", "BannerImage", ",", "ENT_NOQUOTES", ",", "'UTF-8'", ")", ")", ";", "//old: Test auf chunked, nicht noetig solange Contao bei HTTP/1.0 bleibt", "try", "{", "$", "objFile", "=", "new", "\\", "File", "(", "$", "tmpImage", ")", ";", "$", "objFile", "->", "write", "(", "$", "objRequest", "->", "response", ")", ";", "$", "objFile", "->", "close", "(", ")", ";", "}", "// Temp directory not writeable", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "$", "e", "->", "getCode", "(", ")", "==", "0", ")", "{", "log_message", "(", "'[getImageSizeExternal] tmpFile Problem: notWriteable'", ",", "'error.log'", ")", ";", "}", "else", "{", "log_message", "(", "'[getImageSizeExternal] tmpFile Problem: error'", ",", "'error.log'", ")", ";", "}", "return", "false", ";", "}", "$", "objRequest", "=", "null", ";", "unset", "(", "$", "objRequest", ")", ";", "$", "arrImageSize", "=", "$", "this", "->", "getImageSizeInternal", "(", "$", "tmpImage", ")", ";", "if", "(", "$", "arrImageSize", "===", "false", ")", "//Workaround fuer PHP ohne zlib bei SWC Files ", "{", "$", "arrImageSize", "=", "$", "this", "->", "getImageSizeCompressed", "(", "$", "tmpImage", ")", ";", "}", "$", "objFile", "->", "delete", "(", ")", ";", "$", "objFile", "=", "null", ";", "unset", "(", "$", "objFile", ")", ";", "ModuleBannerLog", "::", "writeLog", "(", "__METHOD__", ",", "__LINE__", ",", "'Image Size: '", ".", "print_r", "(", "$", "arrImageSize", ",", "true", ")", ")", ";", "return", "$", "arrImageSize", ";", "}" ]
Get the size of an external image @param string $BannerImage Image link @return mixed $array / false
[ "Get", "the", "size", "of", "an", "external", "image" ]
train
https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/BannerImage.php#L137-L190
BugBuster1701/banner
classes/BannerImage.php
BannerImage.getImageSizeCompressed
protected function getImageSizeCompressed($BannerImage) { $arrImageSize = false; $res = $this->uncompressSwcData($BannerImage); if ($res) { // width,height $arrImageSize = array($res[0], $res[1], 13); // 13 = SWC } ModuleBannerLog::writeLog(__METHOD__ , __LINE__ , 'Image Size: '. print_r($arrImageSize,true)); return $arrImageSize; }
php
protected function getImageSizeCompressed($BannerImage) { $arrImageSize = false; $res = $this->uncompressSwcData($BannerImage); if ($res) { // width,height $arrImageSize = array($res[0], $res[1], 13); // 13 = SWC } ModuleBannerLog::writeLog(__METHOD__ , __LINE__ , 'Image Size: '. print_r($arrImageSize,true)); return $arrImageSize; }
[ "protected", "function", "getImageSizeCompressed", "(", "$", "BannerImage", ")", "{", "$", "arrImageSize", "=", "false", ";", "$", "res", "=", "$", "this", "->", "uncompressSwcData", "(", "$", "BannerImage", ")", ";", "if", "(", "$", "res", ")", "{", "// width,height", "$", "arrImageSize", "=", "array", "(", "$", "res", "[", "0", "]", ",", "$", "res", "[", "1", "]", ",", "13", ")", ";", "// 13 = SWC", "}", "ModuleBannerLog", "::", "writeLog", "(", "__METHOD__", ",", "__LINE__", ",", "'Image Size: '", ".", "print_r", "(", "$", "arrImageSize", ",", "true", ")", ")", ";", "return", "$", "arrImageSize", ";", "}" ]
getimagesize without zlib doesn't work workaround for this @param string $BannerImage Image @return mixed $array / false
[ "getimagesize", "without", "zlib", "doesn", "t", "work", "workaround", "for", "this" ]
train
https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/BannerImage.php#L199-L211
BugBuster1701/banner
classes/BannerImage.php
BannerImage.uncompressSwcData
private function uncompressSwcData($filename) { $size = 0; $width = 0; $height = 0; $file = @fopen(TL_ROOT . '/' . $filename,"rb"); if (!$file) { return false; } if ("CWS" != fread($file,3)) { return false; } // Version fread($file,1) ; for ($i=0;$i<4;$i++) { $t = ord(fread($file,1)); $size += ($t<<(8*$i)); } $buffer = gzuncompress(gzread($file,$size),$size); $buffer = substr($buffer,0,20); // first 20 Byte enough $b = ord(substr($buffer,0,1)); $buffer = substr($buffer,1); $cbyte = $b; $bits = $b>>3; $cval = ""; $cbyte &= 7; $cbyte<<= 5; $cbit = 2; // RECT for ($vals=0;$vals<4;$vals++) { $bitcount = 0; while ($bitcount<$bits) { if ($cbyte&128) { $cval .= "1"; } else { $cval .= "0"; } $cbyte<<=1; $cbyte &= 255; $cbit-- ; $bitcount++ ; if ($cbit<0) { $cbyte = ord(substr($buffer,0,1)); $buffer = substr($buffer,1); $cbit = 7; } } $c = 1; $val = 0; $tval = strrev($cval); $strlen = strlen($tval); for ($n=0; $n<$strlen; $n++) { $atom = substr($tval,$n,1); if ($atom=="1") $val+=$c; $c*=2; } // TWIPS to PIXELS $val/=20 ; switch ($vals) { case 0: // tmp value $width = $val; break; case 1: $width = $val - $width; break; case 2: // tmp value $height = $val; break; case 3: $height = $val - $height; break ; } $cval = ""; } fclose($file); $buffer =''; return array($width,$height); }
php
private function uncompressSwcData($filename) { $size = 0; $width = 0; $height = 0; $file = @fopen(TL_ROOT . '/' . $filename,"rb"); if (!$file) { return false; } if ("CWS" != fread($file,3)) { return false; } // Version fread($file,1) ; for ($i=0;$i<4;$i++) { $t = ord(fread($file,1)); $size += ($t<<(8*$i)); } $buffer = gzuncompress(gzread($file,$size),$size); $buffer = substr($buffer,0,20); // first 20 Byte enough $b = ord(substr($buffer,0,1)); $buffer = substr($buffer,1); $cbyte = $b; $bits = $b>>3; $cval = ""; $cbyte &= 7; $cbyte<<= 5; $cbit = 2; // RECT for ($vals=0;$vals<4;$vals++) { $bitcount = 0; while ($bitcount<$bits) { if ($cbyte&128) { $cval .= "1"; } else { $cval .= "0"; } $cbyte<<=1; $cbyte &= 255; $cbit-- ; $bitcount++ ; if ($cbit<0) { $cbyte = ord(substr($buffer,0,1)); $buffer = substr($buffer,1); $cbit = 7; } } $c = 1; $val = 0; $tval = strrev($cval); $strlen = strlen($tval); for ($n=0; $n<$strlen; $n++) { $atom = substr($tval,$n,1); if ($atom=="1") $val+=$c; $c*=2; } // TWIPS to PIXELS $val/=20 ; switch ($vals) { case 0: // tmp value $width = $val; break; case 1: $width = $val - $width; break; case 2: // tmp value $height = $val; break; case 3: $height = $val - $height; break ; } $cval = ""; } fclose($file); $buffer =''; return array($width,$height); }
[ "private", "function", "uncompressSwcData", "(", "$", "filename", ")", "{", "$", "size", "=", "0", ";", "$", "width", "=", "0", ";", "$", "height", "=", "0", ";", "$", "file", "=", "@", "fopen", "(", "TL_ROOT", ".", "'/'", ".", "$", "filename", ",", "\"rb\"", ")", ";", "if", "(", "!", "$", "file", ")", "{", "return", "false", ";", "}", "if", "(", "\"CWS\"", "!=", "fread", "(", "$", "file", ",", "3", ")", ")", "{", "return", "false", ";", "}", "// Version", "fread", "(", "$", "file", ",", "1", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "4", ";", "$", "i", "++", ")", "{", "$", "t", "=", "ord", "(", "fread", "(", "$", "file", ",", "1", ")", ")", ";", "$", "size", "+=", "(", "$", "t", "<<", "(", "8", "*", "$", "i", ")", ")", ";", "}", "$", "buffer", "=", "gzuncompress", "(", "gzread", "(", "$", "file", ",", "$", "size", ")", ",", "$", "size", ")", ";", "$", "buffer", "=", "substr", "(", "$", "buffer", ",", "0", ",", "20", ")", ";", "// first 20 Byte enough", "$", "b", "=", "ord", "(", "substr", "(", "$", "buffer", ",", "0", ",", "1", ")", ")", ";", "$", "buffer", "=", "substr", "(", "$", "buffer", ",", "1", ")", ";", "$", "cbyte", "=", "$", "b", ";", "$", "bits", "=", "$", "b", ">>", "3", ";", "$", "cval", "=", "\"\"", ";", "$", "cbyte", "&=", "7", ";", "$", "cbyte", "<<=", "5", ";", "$", "cbit", "=", "2", ";", "// RECT", "for", "(", "$", "vals", "=", "0", ";", "$", "vals", "<", "4", ";", "$", "vals", "++", ")", "{", "$", "bitcount", "=", "0", ";", "while", "(", "$", "bitcount", "<", "$", "bits", ")", "{", "if", "(", "$", "cbyte", "&", "128", ")", "{", "$", "cval", ".=", "\"1\"", ";", "}", "else", "{", "$", "cval", ".=", "\"0\"", ";", "}", "$", "cbyte", "<<=", "1", ";", "$", "cbyte", "&=", "255", ";", "$", "cbit", "--", ";", "$", "bitcount", "++", ";", "if", "(", "$", "cbit", "<", "0", ")", "{", "$", "cbyte", "=", "ord", "(", "substr", "(", "$", "buffer", ",", "0", ",", "1", ")", ")", ";", "$", "buffer", "=", "substr", "(", "$", "buffer", ",", "1", ")", ";", "$", "cbit", "=", "7", ";", "}", "}", "$", "c", "=", "1", ";", "$", "val", "=", "0", ";", "$", "tval", "=", "strrev", "(", "$", "cval", ")", ";", "$", "strlen", "=", "strlen", "(", "$", "tval", ")", ";", "for", "(", "$", "n", "=", "0", ";", "$", "n", "<", "$", "strlen", ";", "$", "n", "++", ")", "{", "$", "atom", "=", "substr", "(", "$", "tval", ",", "$", "n", ",", "1", ")", ";", "if", "(", "$", "atom", "==", "\"1\"", ")", "$", "val", "+=", "$", "c", ";", "$", "c", "*=", "2", ";", "}", "// TWIPS to PIXELS", "$", "val", "/=", "20", ";", "switch", "(", "$", "vals", ")", "{", "case", "0", ":", "// tmp value", "$", "width", "=", "$", "val", ";", "break", ";", "case", "1", ":", "$", "width", "=", "$", "val", "-", "$", "width", ";", "break", ";", "case", "2", ":", "// tmp value", "$", "height", "=", "$", "val", ";", "break", ";", "case", "3", ":", "$", "height", "=", "$", "val", "-", "$", "height", ";", "break", ";", "}", "$", "cval", "=", "\"\"", ";", "}", "fclose", "(", "$", "file", ")", ";", "$", "buffer", "=", "''", ";", "return", "array", "(", "$", "width", ",", "$", "height", ")", ";", "}" ]
Uncompress swc files (zip-like swf) @param string $filename @return boolean|array false|$width,$height
[ "Uncompress", "swc", "files", "(", "zip", "-", "like", "swf", ")" ]
train
https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/BannerImage.php#L219-L312
BugBuster1701/banner
classes/BannerImage.php
BannerImage.getBannerImageSizeNew
public function getBannerImageSizeNew($oldWidth,$oldHeight,$newWidth=0,$newHeight=0) { $Width = $oldWidth; //Default, and flash require this $Height = $oldHeight; //Default, and flash require this $oriSize = true; //Attribute for images without conversion if ($newWidth > 0 && $newHeight > 0) { $Width = $newWidth; $Height = $newHeight; $oriSize = false; } elseif ($newWidth > 0) { $Width = $newWidth; $Height = ceil($newWidth * $oldHeight / $oldWidth); $oriSize = false; } elseif ($newHeight > 0) { $Width = ceil($newHeight * $oldWidth / $oldHeight); $Height = $newHeight; $oriSize = false; } return array($Width,$Height,$oriSize); }
php
public function getBannerImageSizeNew($oldWidth,$oldHeight,$newWidth=0,$newHeight=0) { $Width = $oldWidth; //Default, and flash require this $Height = $oldHeight; //Default, and flash require this $oriSize = true; //Attribute for images without conversion if ($newWidth > 0 && $newHeight > 0) { $Width = $newWidth; $Height = $newHeight; $oriSize = false; } elseif ($newWidth > 0) { $Width = $newWidth; $Height = ceil($newWidth * $oldHeight / $oldWidth); $oriSize = false; } elseif ($newHeight > 0) { $Width = ceil($newHeight * $oldWidth / $oldHeight); $Height = $newHeight; $oriSize = false; } return array($Width,$Height,$oriSize); }
[ "public", "function", "getBannerImageSizeNew", "(", "$", "oldWidth", ",", "$", "oldHeight", ",", "$", "newWidth", "=", "0", ",", "$", "newHeight", "=", "0", ")", "{", "$", "Width", "=", "$", "oldWidth", ";", "//Default, and flash require this", "$", "Height", "=", "$", "oldHeight", ";", "//Default, and flash require this", "$", "oriSize", "=", "true", ";", "//Attribute for images without conversion", "if", "(", "$", "newWidth", ">", "0", "&&", "$", "newHeight", ">", "0", ")", "{", "$", "Width", "=", "$", "newWidth", ";", "$", "Height", "=", "$", "newHeight", ";", "$", "oriSize", "=", "false", ";", "}", "elseif", "(", "$", "newWidth", ">", "0", ")", "{", "$", "Width", "=", "$", "newWidth", ";", "$", "Height", "=", "ceil", "(", "$", "newWidth", "*", "$", "oldHeight", "/", "$", "oldWidth", ")", ";", "$", "oriSize", "=", "false", ";", "}", "elseif", "(", "$", "newHeight", ">", "0", ")", "{", "$", "Width", "=", "ceil", "(", "$", "newHeight", "*", "$", "oldWidth", "/", "$", "oldHeight", ")", ";", "$", "Height", "=", "$", "newHeight", ";", "$", "oriSize", "=", "false", ";", "}", "return", "array", "(", "$", "Width", ",", "$", "Height", ",", "$", "oriSize", ")", ";", "}" ]
Calculate the new size for witdh and height @param int $oldWidth ,mandatory @param int $oldHeight ,mandatory @param int $newWidth ,optional @param int $newHeight ,optional @return array $Width,$Height,$oriSize
[ "Calculate", "the", "new", "size", "for", "witdh", "and", "height" ]
train
https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/BannerImage.php#L323-L348
BugBuster1701/banner
classes/BannerImage.php
BannerImage.getCheckBannerImageSize
public function getCheckBannerImageSize($arrImageSize, $maxWidth, $maxHeight) { //$arrImageSize[0] Breite (max 250px in BE) //$arrImageSize[1] Hoehe (max 40px in BE) //$arrImageSize[2] Type if ($arrImageSize[0] > $arrImageSize[1]) // Breite > Hoehe = Landscape == { if ($arrImageSize[0] > $maxWidth) { //neue feste Breite $newImageSize = $this->getBannerImageSizeNew($arrImageSize[0],$arrImageSize[1], $maxWidth, 0); $intWidth = $newImageSize[0]; $intHeight = $newImageSize[1]; $oriSize = $newImageSize[2]; } else { $intWidth = $arrImageSize[0]; $intHeight = $arrImageSize[1]; $oriSize = true; // Merkmal fuer Bilder ohne Umrechnung } } else { // Hoehe >= Breite, ggf. Hoehe verkleinern if ($arrImageSize[1] > $maxWidth) // Hoehe > max Breite = Portrait || { // pruefen ob bei neuer Hoehe die Breite zu klein wird if (($maxWidth*$arrImageSize[0]/$arrImageSize[1]) < $maxHeight) { // Breite statt Hoehe setzen, Breite auf maximale Hoehe $newImageSize = $this->getBannerImageSizeNew($arrImageSize[0],$arrImageSize[1], $maxHeight, 0); $intWidth = $newImageSize[0]; $intHeight = $newImageSize[1]; $oriSize = $newImageSize[2]; } else { $newImageSize = $this->getBannerImageSizeNew($arrImageSize[0],$arrImageSize[1], 0, $maxHeight); $intWidth = $newImageSize[0]; $intHeight = $newImageSize[1]; $oriSize = $newImageSize[2]; } } else { $intWidth = $arrImageSize[0]; $intHeight = $arrImageSize[1]; $oriSize = true; // Merkmal fuer Bilder ohne Umrechnung } } return array($intWidth,$intHeight,$oriSize); }
php
public function getCheckBannerImageSize($arrImageSize, $maxWidth, $maxHeight) { //$arrImageSize[0] Breite (max 250px in BE) //$arrImageSize[1] Hoehe (max 40px in BE) //$arrImageSize[2] Type if ($arrImageSize[0] > $arrImageSize[1]) // Breite > Hoehe = Landscape == { if ($arrImageSize[0] > $maxWidth) { //neue feste Breite $newImageSize = $this->getBannerImageSizeNew($arrImageSize[0],$arrImageSize[1], $maxWidth, 0); $intWidth = $newImageSize[0]; $intHeight = $newImageSize[1]; $oriSize = $newImageSize[2]; } else { $intWidth = $arrImageSize[0]; $intHeight = $arrImageSize[1]; $oriSize = true; // Merkmal fuer Bilder ohne Umrechnung } } else { // Hoehe >= Breite, ggf. Hoehe verkleinern if ($arrImageSize[1] > $maxWidth) // Hoehe > max Breite = Portrait || { // pruefen ob bei neuer Hoehe die Breite zu klein wird if (($maxWidth*$arrImageSize[0]/$arrImageSize[1]) < $maxHeight) { // Breite statt Hoehe setzen, Breite auf maximale Hoehe $newImageSize = $this->getBannerImageSizeNew($arrImageSize[0],$arrImageSize[1], $maxHeight, 0); $intWidth = $newImageSize[0]; $intHeight = $newImageSize[1]; $oriSize = $newImageSize[2]; } else { $newImageSize = $this->getBannerImageSizeNew($arrImageSize[0],$arrImageSize[1], 0, $maxHeight); $intWidth = $newImageSize[0]; $intHeight = $newImageSize[1]; $oriSize = $newImageSize[2]; } } else { $intWidth = $arrImageSize[0]; $intHeight = $arrImageSize[1]; $oriSize = true; // Merkmal fuer Bilder ohne Umrechnung } } return array($intWidth,$intHeight,$oriSize); }
[ "public", "function", "getCheckBannerImageSize", "(", "$", "arrImageSize", ",", "$", "maxWidth", ",", "$", "maxHeight", ")", "{", "//$arrImageSize[0] Breite (max 250px in BE)", "//$arrImageSize[1] Hoehe (max 40px in BE)", "//$arrImageSize[2] Type", "if", "(", "$", "arrImageSize", "[", "0", "]", ">", "$", "arrImageSize", "[", "1", "]", ")", "// Breite > Hoehe = Landscape ==", "{", "if", "(", "$", "arrImageSize", "[", "0", "]", ">", "$", "maxWidth", ")", "{", "//neue feste Breite", "$", "newImageSize", "=", "$", "this", "->", "getBannerImageSizeNew", "(", "$", "arrImageSize", "[", "0", "]", ",", "$", "arrImageSize", "[", "1", "]", ",", "$", "maxWidth", ",", "0", ")", ";", "$", "intWidth", "=", "$", "newImageSize", "[", "0", "]", ";", "$", "intHeight", "=", "$", "newImageSize", "[", "1", "]", ";", "$", "oriSize", "=", "$", "newImageSize", "[", "2", "]", ";", "}", "else", "{", "$", "intWidth", "=", "$", "arrImageSize", "[", "0", "]", ";", "$", "intHeight", "=", "$", "arrImageSize", "[", "1", "]", ";", "$", "oriSize", "=", "true", ";", "// Merkmal fuer Bilder ohne Umrechnung", "}", "}", "else", "{", "// Hoehe >= Breite, ggf. Hoehe verkleinern", "if", "(", "$", "arrImageSize", "[", "1", "]", ">", "$", "maxWidth", ")", "// Hoehe > max Breite = Portrait ||", "{", "// pruefen ob bei neuer Hoehe die Breite zu klein wird", "if", "(", "(", "$", "maxWidth", "*", "$", "arrImageSize", "[", "0", "]", "/", "$", "arrImageSize", "[", "1", "]", ")", "<", "$", "maxHeight", ")", "{", "// Breite statt Hoehe setzen, Breite auf maximale Hoehe", "$", "newImageSize", "=", "$", "this", "->", "getBannerImageSizeNew", "(", "$", "arrImageSize", "[", "0", "]", ",", "$", "arrImageSize", "[", "1", "]", ",", "$", "maxHeight", ",", "0", ")", ";", "$", "intWidth", "=", "$", "newImageSize", "[", "0", "]", ";", "$", "intHeight", "=", "$", "newImageSize", "[", "1", "]", ";", "$", "oriSize", "=", "$", "newImageSize", "[", "2", "]", ";", "}", "else", "{", "$", "newImageSize", "=", "$", "this", "->", "getBannerImageSizeNew", "(", "$", "arrImageSize", "[", "0", "]", ",", "$", "arrImageSize", "[", "1", "]", ",", "0", ",", "$", "maxHeight", ")", ";", "$", "intWidth", "=", "$", "newImageSize", "[", "0", "]", ";", "$", "intHeight", "=", "$", "newImageSize", "[", "1", "]", ";", "$", "oriSize", "=", "$", "newImageSize", "[", "2", "]", ";", "}", "}", "else", "{", "$", "intWidth", "=", "$", "arrImageSize", "[", "0", "]", ";", "$", "intHeight", "=", "$", "arrImageSize", "[", "1", "]", ";", "$", "oriSize", "=", "true", ";", "// Merkmal fuer Bilder ohne Umrechnung", "}", "}", "return", "array", "(", "$", "intWidth", ",", "$", "intHeight", ",", "$", "oriSize", ")", ";", "}" ]
Calculate the new size if necessary by comparing with maxWidth and maxHeight @param array $arrImageSize @param int $maxWidth @param int $maxHeight @return array $Width,$Height,$oriSize
[ "Calculate", "the", "new", "size", "if", "necessary", "by", "comparing", "with", "maxWidth", "and", "maxHeight" ]
train
https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/BannerImage.php#L358-L408
BugBuster1701/banner
classes/BannerImage.php
BannerImage.getCheckBannerImageFallback
public function getCheckBannerImageFallback($BannerImage, $intWidth, $intHeight) { $fallback_content = false; $path_parts = pathinfo($BannerImage); if ( is_file(TL_ROOT . '/' . $path_parts['dirname'] . '/' . $path_parts['filename'].'.jpg') ) { $fallback_ext = '.jpg'; $fallback_content = true; } elseif ( is_file(TL_ROOT . '/' . $path_parts['dirname'] . '/' . $path_parts['filename'].'.png') ) { $fallback_ext = '.png'; $fallback_content = true; } elseif ( is_file(TL_ROOT . '/' . $path_parts['dirname'] . '/' . $path_parts['filename'].'.gif') ) { $fallback_ext = '.gif'; $fallback_content = true; } //if fallback image found, get image with size of flash size if ($fallback_content === true) { //Get Image with sizes of flash $src_fallback = \Image::get($this->urlEncode($path_parts['dirname'].'/'.$path_parts['filename'].$fallback_ext), $intWidth, $intHeight,'proportional'); return $src_fallback; } //no fallback image found return false; }
php
public function getCheckBannerImageFallback($BannerImage, $intWidth, $intHeight) { $fallback_content = false; $path_parts = pathinfo($BannerImage); if ( is_file(TL_ROOT . '/' . $path_parts['dirname'] . '/' . $path_parts['filename'].'.jpg') ) { $fallback_ext = '.jpg'; $fallback_content = true; } elseif ( is_file(TL_ROOT . '/' . $path_parts['dirname'] . '/' . $path_parts['filename'].'.png') ) { $fallback_ext = '.png'; $fallback_content = true; } elseif ( is_file(TL_ROOT . '/' . $path_parts['dirname'] . '/' . $path_parts['filename'].'.gif') ) { $fallback_ext = '.gif'; $fallback_content = true; } //if fallback image found, get image with size of flash size if ($fallback_content === true) { //Get Image with sizes of flash $src_fallback = \Image::get($this->urlEncode($path_parts['dirname'].'/'.$path_parts['filename'].$fallback_ext), $intWidth, $intHeight,'proportional'); return $src_fallback; } //no fallback image found return false; }
[ "public", "function", "getCheckBannerImageFallback", "(", "$", "BannerImage", ",", "$", "intWidth", ",", "$", "intHeight", ")", "{", "$", "fallback_content", "=", "false", ";", "$", "path_parts", "=", "pathinfo", "(", "$", "BannerImage", ")", ";", "if", "(", "is_file", "(", "TL_ROOT", ".", "'/'", ".", "$", "path_parts", "[", "'dirname'", "]", ".", "'/'", ".", "$", "path_parts", "[", "'filename'", "]", ".", "'.jpg'", ")", ")", "{", "$", "fallback_ext", "=", "'.jpg'", ";", "$", "fallback_content", "=", "true", ";", "}", "elseif", "(", "is_file", "(", "TL_ROOT", ".", "'/'", ".", "$", "path_parts", "[", "'dirname'", "]", ".", "'/'", ".", "$", "path_parts", "[", "'filename'", "]", ".", "'.png'", ")", ")", "{", "$", "fallback_ext", "=", "'.png'", ";", "$", "fallback_content", "=", "true", ";", "}", "elseif", "(", "is_file", "(", "TL_ROOT", ".", "'/'", ".", "$", "path_parts", "[", "'dirname'", "]", ".", "'/'", ".", "$", "path_parts", "[", "'filename'", "]", ".", "'.gif'", ")", ")", "{", "$", "fallback_ext", "=", "'.gif'", ";", "$", "fallback_content", "=", "true", ";", "}", "//if fallback image found, get image with size of flash size", "if", "(", "$", "fallback_content", "===", "true", ")", "{", "//Get Image with sizes of flash", "$", "src_fallback", "=", "\\", "Image", "::", "get", "(", "$", "this", "->", "urlEncode", "(", "$", "path_parts", "[", "'dirname'", "]", ".", "'/'", ".", "$", "path_parts", "[", "'filename'", "]", ".", "$", "fallback_ext", ")", ",", "$", "intWidth", ",", "$", "intHeight", ",", "'proportional'", ")", ";", "return", "$", "src_fallback", ";", "}", "//no fallback image found", "return", "false", ";", "}" ]
Search and get a flash fallback image path if exists @param string $BannerImage Image path (flash file) @param int $maxWidth Flash file width @param int $maxHeight Flash file height @return mixed $string/false Fallback image path / false
[ "Search", "and", "get", "a", "flash", "fallback", "image", "path", "if", "exists" ]
train
https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/BannerImage.php#L418-L448
gregorybesson/PlaygroundCore
src/View/Helper/AdCKEditor.php
AdCKEditor.adCKEditor
public function adCKEditor($name, $options = array()) { $CKEditor = new \PlaygroundCore\Service\CKEditor(); $CKEditor->returnOutput = true; /* * General module configurations */ if (isset($this->Config['BasePath'])) { $CKEditor->basePath = $this->Config['BasePath'].'/'; } if (isset($this->Config['Toolbar'])) { $CKEditor->config['toolbar'] = $this->Config['Toolbar']; } if (isset($this->Config['Width'])) { $CKEditor->config['width'] = $this->Config['Width']; } if (isset($this->Config['Height'])) { $CKEditor->config['height'] = $this->Config['Height']; } if (isset($this->Config['Language'])) { $CKEditor->config['language'] = $this->Config['Language']; } if (isset($this->Config['Color'])) { $CKEditor->config['uiColor'] = $this->Config['Color']; } if (isset($this->Config['stylesSet'])) { $CKEditor->config['stylesSet'] = $this->Config['stylesSet']; } if (isset($this->Config['contentsCss'])) { $CKEditor->config['contentsCss']= $this->Config['contentsCss']; } if (isset($this->Config['templates_files'])) { $CKEditor->config['templates_files'] = $this->Config['templates_files']; } // El Finder if (isset($this->Config['ElFinderBaseURL'])) { $CKEditor->config['filebrowserBrowseUrl'] = $this->Config['ElFinderBaseURL']; } if (isset($this->Config['ElFinderWindowWidth'])) { $CKEditor->config['filebrowserWindowWidth'] = $this->Config['ElFinderWindowWidth']; } if (isset($this->Config['ElFinderWindowHeight'])) { $CKEditor->config['filebrowserWindowHeight'] = $this->Config['ElFinderWindowHeight']; } /* * special confirmations in your form */ if (isset($options['BasePath'])) { $CKEditor->basePath = $options['BasePath'].'/'; } if (isset($options['Toolbar'])) { $CKEditor->config['toolbar'] = $options['Toolbar']; } if (isset($options['toolbar'])) { $CKEditor->config['toolbar'] = $options['toolbar']; } if (isset($options['Width'])) { $CKEditor->config['width'] = $options['Width']; } if (isset($options['Height'])) { $CKEditor->config['height'] = $options['Height']; } if (isset($options['Language'])) { $CKEditor->config['language'] = $options['Language']; } if (isset($options['Color'])) { $CKEditor->config['uiColor'] = $options['uiColor']; } if (isset($options['stylesSet'])) { $CKEditor->config['stylesSet'] = $options['stylesSet']; } if (isset($options['contentsCss'])) { $CKEditor->config['contentsCss'] = $options['contentsCss']; } if (isset($options['templates_files'])) { $CKEditor->config['templates_files'] = $options['templates_files']; } // El Finder if (isset($options['ElFinderBaseURL'])) { $CKEditor->config['filebrowserBrowseUrl'] = $options['ElFinderBaseURL']; } if (isset($options['ElFinderWindowWidth'])) { $CKEditor->config['filebrowserWindowWidth'] = $options['ElFinderWindowWidth']; } if (isset($options['ElFinderWindowHeight'])) { $CKEditor->config['filebrowserWindowHeight'] = $options['ElFinderWindowHeight']; } echo $CKEditor->replace($name); }
php
public function adCKEditor($name, $options = array()) { $CKEditor = new \PlaygroundCore\Service\CKEditor(); $CKEditor->returnOutput = true; /* * General module configurations */ if (isset($this->Config['BasePath'])) { $CKEditor->basePath = $this->Config['BasePath'].'/'; } if (isset($this->Config['Toolbar'])) { $CKEditor->config['toolbar'] = $this->Config['Toolbar']; } if (isset($this->Config['Width'])) { $CKEditor->config['width'] = $this->Config['Width']; } if (isset($this->Config['Height'])) { $CKEditor->config['height'] = $this->Config['Height']; } if (isset($this->Config['Language'])) { $CKEditor->config['language'] = $this->Config['Language']; } if (isset($this->Config['Color'])) { $CKEditor->config['uiColor'] = $this->Config['Color']; } if (isset($this->Config['stylesSet'])) { $CKEditor->config['stylesSet'] = $this->Config['stylesSet']; } if (isset($this->Config['contentsCss'])) { $CKEditor->config['contentsCss']= $this->Config['contentsCss']; } if (isset($this->Config['templates_files'])) { $CKEditor->config['templates_files'] = $this->Config['templates_files']; } // El Finder if (isset($this->Config['ElFinderBaseURL'])) { $CKEditor->config['filebrowserBrowseUrl'] = $this->Config['ElFinderBaseURL']; } if (isset($this->Config['ElFinderWindowWidth'])) { $CKEditor->config['filebrowserWindowWidth'] = $this->Config['ElFinderWindowWidth']; } if (isset($this->Config['ElFinderWindowHeight'])) { $CKEditor->config['filebrowserWindowHeight'] = $this->Config['ElFinderWindowHeight']; } /* * special confirmations in your form */ if (isset($options['BasePath'])) { $CKEditor->basePath = $options['BasePath'].'/'; } if (isset($options['Toolbar'])) { $CKEditor->config['toolbar'] = $options['Toolbar']; } if (isset($options['toolbar'])) { $CKEditor->config['toolbar'] = $options['toolbar']; } if (isset($options['Width'])) { $CKEditor->config['width'] = $options['Width']; } if (isset($options['Height'])) { $CKEditor->config['height'] = $options['Height']; } if (isset($options['Language'])) { $CKEditor->config['language'] = $options['Language']; } if (isset($options['Color'])) { $CKEditor->config['uiColor'] = $options['uiColor']; } if (isset($options['stylesSet'])) { $CKEditor->config['stylesSet'] = $options['stylesSet']; } if (isset($options['contentsCss'])) { $CKEditor->config['contentsCss'] = $options['contentsCss']; } if (isset($options['templates_files'])) { $CKEditor->config['templates_files'] = $options['templates_files']; } // El Finder if (isset($options['ElFinderBaseURL'])) { $CKEditor->config['filebrowserBrowseUrl'] = $options['ElFinderBaseURL']; } if (isset($options['ElFinderWindowWidth'])) { $CKEditor->config['filebrowserWindowWidth'] = $options['ElFinderWindowWidth']; } if (isset($options['ElFinderWindowHeight'])) { $CKEditor->config['filebrowserWindowHeight'] = $options['ElFinderWindowHeight']; } echo $CKEditor->replace($name); }
[ "public", "function", "adCKEditor", "(", "$", "name", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "CKEditor", "=", "new", "\\", "PlaygroundCore", "\\", "Service", "\\", "CKEditor", "(", ")", ";", "$", "CKEditor", "->", "returnOutput", "=", "true", ";", "/*\n * General module configurations\n */", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'BasePath'", "]", ")", ")", "{", "$", "CKEditor", "->", "basePath", "=", "$", "this", "->", "Config", "[", "'BasePath'", "]", ".", "'/'", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'Toolbar'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'toolbar'", "]", "=", "$", "this", "->", "Config", "[", "'Toolbar'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'Width'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'width'", "]", "=", "$", "this", "->", "Config", "[", "'Width'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'Height'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'height'", "]", "=", "$", "this", "->", "Config", "[", "'Height'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'Language'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'language'", "]", "=", "$", "this", "->", "Config", "[", "'Language'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'Color'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'uiColor'", "]", "=", "$", "this", "->", "Config", "[", "'Color'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'stylesSet'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'stylesSet'", "]", "=", "$", "this", "->", "Config", "[", "'stylesSet'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'contentsCss'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'contentsCss'", "]", "=", "$", "this", "->", "Config", "[", "'contentsCss'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'templates_files'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'templates_files'", "]", "=", "$", "this", "->", "Config", "[", "'templates_files'", "]", ";", "}", "// El Finder", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'ElFinderBaseURL'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'filebrowserBrowseUrl'", "]", "=", "$", "this", "->", "Config", "[", "'ElFinderBaseURL'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'ElFinderWindowWidth'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'filebrowserWindowWidth'", "]", "=", "$", "this", "->", "Config", "[", "'ElFinderWindowWidth'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "Config", "[", "'ElFinderWindowHeight'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'filebrowserWindowHeight'", "]", "=", "$", "this", "->", "Config", "[", "'ElFinderWindowHeight'", "]", ";", "}", "/*\n * special confirmations in your form\n */", "if", "(", "isset", "(", "$", "options", "[", "'BasePath'", "]", ")", ")", "{", "$", "CKEditor", "->", "basePath", "=", "$", "options", "[", "'BasePath'", "]", ".", "'/'", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'Toolbar'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'toolbar'", "]", "=", "$", "options", "[", "'Toolbar'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'toolbar'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'toolbar'", "]", "=", "$", "options", "[", "'toolbar'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'Width'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'width'", "]", "=", "$", "options", "[", "'Width'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'Height'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'height'", "]", "=", "$", "options", "[", "'Height'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'Language'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'language'", "]", "=", "$", "options", "[", "'Language'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'Color'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'uiColor'", "]", "=", "$", "options", "[", "'uiColor'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'stylesSet'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'stylesSet'", "]", "=", "$", "options", "[", "'stylesSet'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'contentsCss'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'contentsCss'", "]", "=", "$", "options", "[", "'contentsCss'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'templates_files'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'templates_files'", "]", "=", "$", "options", "[", "'templates_files'", "]", ";", "}", "// El Finder", "if", "(", "isset", "(", "$", "options", "[", "'ElFinderBaseURL'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'filebrowserBrowseUrl'", "]", "=", "$", "options", "[", "'ElFinderBaseURL'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'ElFinderWindowWidth'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'filebrowserWindowWidth'", "]", "=", "$", "options", "[", "'ElFinderWindowWidth'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'ElFinderWindowHeight'", "]", ")", ")", "{", "$", "CKEditor", "->", "config", "[", "'filebrowserWindowHeight'", "]", "=", "$", "options", "[", "'ElFinderWindowHeight'", "]", ";", "}", "echo", "$", "CKEditor", "->", "replace", "(", "$", "name", ")", ";", "}" ]
@param $name @param $options @return string
[ "@param", "$name", "@param", "$options" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/View/Helper/AdCKEditor.php#L40-L134
cabalphp/route
src/RouteCollection.php
RouteCollection.group
public function group($optionsOrMethod, $callback) { $collection = new RouteCollection($optionsOrMethod); $this->routes[] = $collection; $callback($collection); return $collection; }
php
public function group($optionsOrMethod, $callback) { $collection = new RouteCollection($optionsOrMethod); $this->routes[] = $collection; $callback($collection); return $collection; }
[ "public", "function", "group", "(", "$", "optionsOrMethod", ",", "$", "callback", ")", "{", "$", "collection", "=", "new", "RouteCollection", "(", "$", "optionsOrMethod", ")", ";", "$", "this", "->", "routes", "[", "]", "=", "$", "collection", ";", "$", "callback", "(", "$", "collection", ")", ";", "return", "$", "collection", ";", "}" ]
Undocumented function @param string|mixed $optionsOrMethod @param callable $callback @return \Cabal\Route\RouteCollection
[ "Undocumented", "function" ]
train
https://github.com/cabalphp/route/blob/13959fa0c3f6777cb9a9290c9b032dd514cd33b7/src/RouteCollection.php#L32-L38
cabalphp/route
src/RouteCollection.php
RouteCollection.map
public function map($optionsOrMethod, $path, $handler) { $route = new Route(); $route->map($optionsOrMethod, $path, $handler); $this->routes[] = $route; return $route; }
php
public function map($optionsOrMethod, $path, $handler) { $route = new Route(); $route->map($optionsOrMethod, $path, $handler); $this->routes[] = $route; return $route; }
[ "public", "function", "map", "(", "$", "optionsOrMethod", ",", "$", "path", ",", "$", "handler", ")", "{", "$", "route", "=", "new", "Route", "(", ")", ";", "$", "route", "->", "map", "(", "$", "optionsOrMethod", ",", "$", "path", ",", "$", "handler", ")", ";", "$", "this", "->", "routes", "[", "]", "=", "$", "route", ";", "return", "$", "route", ";", "}" ]
Undocumented function @param string $optionsOrMethod @param string|mixed $path @param string|mixed $handler @return \Cabal\Route\Route
[ "Undocumented", "function" ]
train
https://github.com/cabalphp/route/blob/13959fa0c3f6777cb9a9290c9b032dd514cd33b7/src/RouteCollection.php#L48-L54
geosocio/http-serializer-bundle
src/GeoSocioHttpSerializerBundle.php
GeoSocioHttpSerializerBundle.getContainerExtension
public function getContainerExtension() { if ($this->extension === null) { $extension = $this->createContainerExtension(); $this->extension = $extension ?? false; } return $this->extension ?? null; }
php
public function getContainerExtension() { if ($this->extension === null) { $extension = $this->createContainerExtension(); $this->extension = $extension ?? false; } return $this->extension ?? null; }
[ "public", "function", "getContainerExtension", "(", ")", "{", "if", "(", "$", "this", "->", "extension", "===", "null", ")", "{", "$", "extension", "=", "$", "this", "->", "createContainerExtension", "(", ")", ";", "$", "this", "->", "extension", "=", "$", "extension", "??", "false", ";", "}", "return", "$", "this", "->", "extension", "??", "null", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/geosocio/http-serializer-bundle/blob/2ceb24a148204b1f3b14083b202db7e5afff2099/src/GeoSocioHttpSerializerBundle.php#L14-L22
movoin/one-swoole
src/Swoole/Traits/HasSwoole.php
HasSwoole.createSwooleServer
protected function createSwooleServer(string $protocolName, array $config = []): self { switch ($protocolName) { // HTTP Server case Protocol::HTTP: $server = SwHttpServer::class; break; // WebSocket Server case Protocol::WEBSOCKET: $server = SwWebSocketServer::class; break; // TCP/UDP Server default: $server = SwServer::class; break; } // {{ 创建 Server $swoole = new $server( $config['host'], $config['port'], SWOOLE_PROCESS, SWOOLE_SOCK_TCP ); $swoole->set($config['swoole']); unset($server); $this->swoole = $this->bindSwooleEvents($swoole, $protocolName); unset($swoole); // }} return $this; }
php
protected function createSwooleServer(string $protocolName, array $config = []): self { switch ($protocolName) { // HTTP Server case Protocol::HTTP: $server = SwHttpServer::class; break; // WebSocket Server case Protocol::WEBSOCKET: $server = SwWebSocketServer::class; break; // TCP/UDP Server default: $server = SwServer::class; break; } // {{ 创建 Server $swoole = new $server( $config['host'], $config['port'], SWOOLE_PROCESS, SWOOLE_SOCK_TCP ); $swoole->set($config['swoole']); unset($server); $this->swoole = $this->bindSwooleEvents($swoole, $protocolName); unset($swoole); // }} return $this; }
[ "protected", "function", "createSwooleServer", "(", "string", "$", "protocolName", ",", "array", "$", "config", "=", "[", "]", ")", ":", "self", "{", "switch", "(", "$", "protocolName", ")", "{", "// HTTP Server", "case", "Protocol", "::", "HTTP", ":", "$", "server", "=", "SwHttpServer", "::", "class", ";", "break", ";", "// WebSocket Server", "case", "Protocol", "::", "WEBSOCKET", ":", "$", "server", "=", "SwWebSocketServer", "::", "class", ";", "break", ";", "// TCP/UDP Server", "default", ":", "$", "server", "=", "SwServer", "::", "class", ";", "break", ";", "}", "// {{ 创建 Server", "$", "swoole", "=", "new", "$", "server", "(", "$", "config", "[", "'host'", "]", ",", "$", "config", "[", "'port'", "]", ",", "SWOOLE_PROCESS", ",", "SWOOLE_SOCK_TCP", ")", ";", "$", "swoole", "->", "set", "(", "$", "config", "[", "'swoole'", "]", ")", ";", "unset", "(", "$", "server", ")", ";", "$", "this", "->", "swoole", "=", "$", "this", "->", "bindSwooleEvents", "(", "$", "swoole", ",", "$", "protocolName", ")", ";", "unset", "(", "$", "swoole", ")", ";", "// }}", "return", "$", "this", ";", "}" ]
创建 Swoole Server 实例 @param string $protocolName @param array $config @return self @throws \InvalidArgumentException
[ "创建", "Swoole", "Server", "实例" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Swoole/Traits/HasSwoole.php#L56-L91
movoin/one-swoole
src/Swoole/Traits/HasSwoole.php
HasSwoole.bindSwooleEvents
protected function bindSwooleEvents(SwServer $swoole, string $protocolName): SwServer { // {{ 初始化 Swoole Server 事件 $events = [ 'Start' => 'onMasterStart', 'Shutdown' => 'onMasterStop', 'ManagerStart' => 'onManagerStart', 'WorkerStart' => 'onWorkerStart', 'WorkerStop' => 'onWorkerStop', 'WorkerError' => 'onWorkerError', 'WorkerExit' => 'onWorkerExit', 'PipeMessage' => 'onPipeMessage', 'Connect' => 'onConnect', 'Close' => 'onClose', 'Receive' => 'onReceive', ]; array_walk($events, function ($handler, $event) use ($swoole) { $swoole->on($event, [$this, $handler]); }); unset($events); switch ($protocolName) { // HTTP Server case Protocol::HTTP: $swoole->on('Request', [$this, 'onRequest']); break; // UDP Server case Protocol::UDP: $swoole->on('Packet', [$this, 'onPacket']); break; // WebSocket Server case Protocol::WEBSOCKET: $swoole->on('Open', [$this, 'onOpen']); $swoole->on('HandShake', [$this, 'onHandShake']); $swoole->on('Message', [$this, 'onMessage']); break; } $tasks = isset($swoole->setting['task_worker_num']) ? (int) $swoole->setting['task_worker_num'] : 0; if ($tasks > 0) { $swoole->on('Task', [$this, 'onTask']); $swoole->on('Finish', [$this, 'onFinish']); } unset($tasks); // }} return $swoole; }
php
protected function bindSwooleEvents(SwServer $swoole, string $protocolName): SwServer { // {{ 初始化 Swoole Server 事件 $events = [ 'Start' => 'onMasterStart', 'Shutdown' => 'onMasterStop', 'ManagerStart' => 'onManagerStart', 'WorkerStart' => 'onWorkerStart', 'WorkerStop' => 'onWorkerStop', 'WorkerError' => 'onWorkerError', 'WorkerExit' => 'onWorkerExit', 'PipeMessage' => 'onPipeMessage', 'Connect' => 'onConnect', 'Close' => 'onClose', 'Receive' => 'onReceive', ]; array_walk($events, function ($handler, $event) use ($swoole) { $swoole->on($event, [$this, $handler]); }); unset($events); switch ($protocolName) { // HTTP Server case Protocol::HTTP: $swoole->on('Request', [$this, 'onRequest']); break; // UDP Server case Protocol::UDP: $swoole->on('Packet', [$this, 'onPacket']); break; // WebSocket Server case Protocol::WEBSOCKET: $swoole->on('Open', [$this, 'onOpen']); $swoole->on('HandShake', [$this, 'onHandShake']); $swoole->on('Message', [$this, 'onMessage']); break; } $tasks = isset($swoole->setting['task_worker_num']) ? (int) $swoole->setting['task_worker_num'] : 0; if ($tasks > 0) { $swoole->on('Task', [$this, 'onTask']); $swoole->on('Finish', [$this, 'onFinish']); } unset($tasks); // }} return $swoole; }
[ "protected", "function", "bindSwooleEvents", "(", "SwServer", "$", "swoole", ",", "string", "$", "protocolName", ")", ":", "SwServer", "{", "// {{ 初始化 Swoole Server 事件", "$", "events", "=", "[", "'Start'", "=>", "'onMasterStart'", ",", "'Shutdown'", "=>", "'onMasterStop'", ",", "'ManagerStart'", "=>", "'onManagerStart'", ",", "'WorkerStart'", "=>", "'onWorkerStart'", ",", "'WorkerStop'", "=>", "'onWorkerStop'", ",", "'WorkerError'", "=>", "'onWorkerError'", ",", "'WorkerExit'", "=>", "'onWorkerExit'", ",", "'PipeMessage'", "=>", "'onPipeMessage'", ",", "'Connect'", "=>", "'onConnect'", ",", "'Close'", "=>", "'onClose'", ",", "'Receive'", "=>", "'onReceive'", ",", "]", ";", "array_walk", "(", "$", "events", ",", "function", "(", "$", "handler", ",", "$", "event", ")", "use", "(", "$", "swoole", ")", "{", "$", "swoole", "->", "on", "(", "$", "event", ",", "[", "$", "this", ",", "$", "handler", "]", ")", ";", "}", ")", ";", "unset", "(", "$", "events", ")", ";", "switch", "(", "$", "protocolName", ")", "{", "// HTTP Server", "case", "Protocol", "::", "HTTP", ":", "$", "swoole", "->", "on", "(", "'Request'", ",", "[", "$", "this", ",", "'onRequest'", "]", ")", ";", "break", ";", "// UDP Server", "case", "Protocol", "::", "UDP", ":", "$", "swoole", "->", "on", "(", "'Packet'", ",", "[", "$", "this", ",", "'onPacket'", "]", ")", ";", "break", ";", "// WebSocket Server", "case", "Protocol", "::", "WEBSOCKET", ":", "$", "swoole", "->", "on", "(", "'Open'", ",", "[", "$", "this", ",", "'onOpen'", "]", ")", ";", "$", "swoole", "->", "on", "(", "'HandShake'", ",", "[", "$", "this", ",", "'onHandShake'", "]", ")", ";", "$", "swoole", "->", "on", "(", "'Message'", ",", "[", "$", "this", ",", "'onMessage'", "]", ")", ";", "break", ";", "}", "$", "tasks", "=", "isset", "(", "$", "swoole", "->", "setting", "[", "'task_worker_num'", "]", ")", "?", "(", "int", ")", "$", "swoole", "->", "setting", "[", "'task_worker_num'", "]", ":", "0", ";", "if", "(", "$", "tasks", ">", "0", ")", "{", "$", "swoole", "->", "on", "(", "'Task'", ",", "[", "$", "this", ",", "'onTask'", "]", ")", ";", "$", "swoole", "->", "on", "(", "'Finish'", ",", "[", "$", "this", ",", "'onFinish'", "]", ")", ";", "}", "unset", "(", "$", "tasks", ")", ";", "// }}", "return", "$", "swoole", ";", "}" ]
绑定 Swoole Server 事件 @param \Swoole\Server $swoole @param string $protocolName @return \Swoole\Server
[ "绑定", "Swoole", "Server", "事件" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Swoole/Traits/HasSwoole.php#L101-L156
phossa2/middleware
src/Middleware/Condition/MultipleCondition.php
MultipleCondition.evaluate
public function evaluate( RequestInterface $request, ResponseInterface $response )/*# : bool */ { foreach ($this->conditions as $cond) { if (is_callable($cond)) { $res = $cond($request, $response); } else { $res = $cond->evaluate($request, $response); } if (!$res) { return false; } } return true; }
php
public function evaluate( RequestInterface $request, ResponseInterface $response )/*# : bool */ { foreach ($this->conditions as $cond) { if (is_callable($cond)) { $res = $cond($request, $response); } else { $res = $cond->evaluate($request, $response); } if (!$res) { return false; } } return true; }
[ "public", "function", "evaluate", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "/*# : bool */", "{", "foreach", "(", "$", "this", "->", "conditions", "as", "$", "cond", ")", "{", "if", "(", "is_callable", "(", "$", "cond", ")", ")", "{", "$", "res", "=", "$", "cond", "(", "$", "request", ",", "$", "response", ")", ";", "}", "else", "{", "$", "res", "=", "$", "cond", "->", "evaluate", "(", "$", "request", ",", "$", "response", ")", ";", "}", "if", "(", "!", "$", "res", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/phossa2/middleware/blob/518e97ae48077f2c11adcd3c2393830ed7ab7ce7/src/Middleware/Condition/MultipleCondition.php#L54-L69
movoin/one-swoole
src/Run.php
Run.shell
public static function shell($sh, $cwd = null, int $timeout = 60, bool $async = false) { $process = new Process($sh, $cwd, null, null, $timeout); if ($async) { $process->start(); $process->wait(function ($type, $buffer) { if (Process::ERR === $type) { static::log('error', $buffer); } }); } else { $process->run(); if (! $process->isSuccessful()) { static::log('error', $process->getErrorOutput()); throw new ProcessFailedException($process); } return $process->getOutput(); } unset($process); }
php
public static function shell($sh, $cwd = null, int $timeout = 60, bool $async = false) { $process = new Process($sh, $cwd, null, null, $timeout); if ($async) { $process->start(); $process->wait(function ($type, $buffer) { if (Process::ERR === $type) { static::log('error', $buffer); } }); } else { $process->run(); if (! $process->isSuccessful()) { static::log('error', $process->getErrorOutput()); throw new ProcessFailedException($process); } return $process->getOutput(); } unset($process); }
[ "public", "static", "function", "shell", "(", "$", "sh", ",", "$", "cwd", "=", "null", ",", "int", "$", "timeout", "=", "60", ",", "bool", "$", "async", "=", "false", ")", "{", "$", "process", "=", "new", "Process", "(", "$", "sh", ",", "$", "cwd", ",", "null", ",", "null", ",", "$", "timeout", ")", ";", "if", "(", "$", "async", ")", "{", "$", "process", "->", "start", "(", ")", ";", "$", "process", "->", "wait", "(", "function", "(", "$", "type", ",", "$", "buffer", ")", "{", "if", "(", "Process", "::", "ERR", "===", "$", "type", ")", "{", "static", "::", "log", "(", "'error'", ",", "$", "buffer", ")", ";", "}", "}", ")", ";", "}", "else", "{", "$", "process", "->", "run", "(", ")", ";", "if", "(", "!", "$", "process", "->", "isSuccessful", "(", ")", ")", "{", "static", "::", "log", "(", "'error'", ",", "$", "process", "->", "getErrorOutput", "(", ")", ")", ";", "throw", "new", "ProcessFailedException", "(", "$", "process", ")", ";", "}", "return", "$", "process", "->", "getOutput", "(", ")", ";", "}", "unset", "(", "$", "process", ")", ";", "}" ]
运行 Shell @param array|string $sh @param string|null $cwd @param int $timeout @param bool $async @return mixed @throws \Symfony\Component\Process\Exception\ProcessFailedException
[ "运行", "Shell" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Run.php#L39-L62
movoin/one-swoole
src/Run.php
Run.log
private static function log(string $level, string $message, array $context = []) { if (static::$logger !== null) { static::$logger->$level($message, $context); } }
php
private static function log(string $level, string $message, array $context = []) { if (static::$logger !== null) { static::$logger->$level($message, $context); } }
[ "private", "static", "function", "log", "(", "string", "$", "level", ",", "string", "$", "message", ",", "array", "$", "context", "=", "[", "]", ")", "{", "if", "(", "static", "::", "$", "logger", "!==", "null", ")", "{", "static", "::", "$", "logger", "->", "$", "level", "(", "$", "message", ",", "$", "context", ")", ";", "}", "}" ]
写入日志 @param string $level @param string $message @param array $context
[ "写入日志" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Run.php#L81-L86
readdle/fqdb
src/Readdle/Database/FQDBProvider.php
FQDBProvider.defaultFQDB
public static function defaultFQDB() { if (self::$defaultFQDB) return self::$defaultFQDB; if (is_callable(self::$FQDBCreatorCallback)) return self::setDefaultFQDB(call_user_func(self::$FQDBCreatorCallback)); }
php
public static function defaultFQDB() { if (self::$defaultFQDB) return self::$defaultFQDB; if (is_callable(self::$FQDBCreatorCallback)) return self::setDefaultFQDB(call_user_func(self::$FQDBCreatorCallback)); }
[ "public", "static", "function", "defaultFQDB", "(", ")", "{", "if", "(", "self", "::", "$", "defaultFQDB", ")", "return", "self", "::", "$", "defaultFQDB", ";", "if", "(", "is_callable", "(", "self", "::", "$", "FQDBCreatorCallback", ")", ")", "return", "self", "::", "setDefaultFQDB", "(", "call_user_func", "(", "self", "::", "$", "FQDBCreatorCallback", ")", ")", ";", "}" ]
returns default FQDB @return \Readdle\Database\FQDB
[ "returns", "default", "FQDB" ]
train
https://github.com/readdle/fqdb/blob/4ef2e8f3343a7c8fbb309c243be502a160c42083/src/Readdle/Database/FQDBProvider.php#L128-L134
activecollab/databasestructure
src/Field/Scalar/Traits/LengthInterface/Implementation.php
Implementation.&
public function &length($length) { $length = (int) $length; if ($length < $this->getMinLength()) { throw new InvalidArgumentException("Min length is {$this->getMinLength()}"); } if ($length > $this->getMaxLength()) { throw new InvalidArgumentException("Max length is {$this->getMaxLength()}"); } $this->length = $length; return $this; }
php
public function &length($length) { $length = (int) $length; if ($length < $this->getMinLength()) { throw new InvalidArgumentException("Min length is {$this->getMinLength()}"); } if ($length > $this->getMaxLength()) { throw new InvalidArgumentException("Max length is {$this->getMaxLength()}"); } $this->length = $length; return $this; }
[ "public", "function", "&", "length", "(", "$", "length", ")", "{", "$", "length", "=", "(", "int", ")", "$", "length", ";", "if", "(", "$", "length", "<", "$", "this", "->", "getMinLength", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Min length is {$this->getMinLength()}\"", ")", ";", "}", "if", "(", "$", "length", ">", "$", "this", "->", "getMaxLength", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Max length is {$this->getMaxLength()}\"", ")", ";", "}", "$", "this", "->", "length", "=", "$", "length", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Field/Scalar/Traits/LengthInterface/Implementation.php#L34-L49
VDMi/Guzzle-oAuth
src/GuzzleOauth/Consumer/Google.php
Google.getUserEmail
public function getUserEmail($info = NULL) { if (empty($info)) { $info = $this->getUserInfo(); } $emails = $info->get('emails'); if (is_array($emails) && count($emails)) { $email = reset($emails); return $email['value']; } }
php
public function getUserEmail($info = NULL) { if (empty($info)) { $info = $this->getUserInfo(); } $emails = $info->get('emails'); if (is_array($emails) && count($emails)) { $email = reset($emails); return $email['value']; } }
[ "public", "function", "getUserEmail", "(", "$", "info", "=", "NULL", ")", "{", "if", "(", "empty", "(", "$", "info", ")", ")", "{", "$", "info", "=", "$", "this", "->", "getUserInfo", "(", ")", ";", "}", "$", "emails", "=", "$", "info", "->", "get", "(", "'emails'", ")", ";", "if", "(", "is_array", "(", "$", "emails", ")", "&&", "count", "(", "$", "emails", ")", ")", "{", "$", "email", "=", "reset", "(", "$", "emails", ")", ";", "return", "$", "email", "[", "'value'", "]", ";", "}", "}" ]
Google can return an array of emails. We only give back the first one, since we request one e-mail address
[ "Google", "can", "return", "an", "array", "of", "emails", ".", "We", "only", "give", "back", "the", "first", "one", "since", "we", "request", "one", "e", "-", "mail", "address" ]
train
https://github.com/VDMi/Guzzle-oAuth/blob/e2b2561e4e402e13ba605082bf768b29942f90cb/src/GuzzleOauth/Consumer/Google.php#L13-L22
gdbots/pbjx-bundle-php
src/PbjxTokenSigner.php
PbjxTokenSigner.addKey
public function addKey(string $kid, string $secret): void { $this->keys[$kid] = $secret; }
php
public function addKey(string $kid, string $secret): void { $this->keys[$kid] = $secret; }
[ "public", "function", "addKey", "(", "string", "$", "kid", ",", "string", "$", "secret", ")", ":", "void", "{", "$", "this", "->", "keys", "[", "$", "kid", "]", "=", "$", "secret", ";", "}" ]
Adds a signing key (will overwrite existing kid if present). @param string $kid @param string $secret
[ "Adds", "a", "signing", "key", "(", "will", "overwrite", "existing", "kid", "if", "present", ")", "." ]
train
https://github.com/gdbots/pbjx-bundle-php/blob/f3c0088583879fc92f13247a0752634bd8696eac/src/PbjxTokenSigner.php#L47-L50
gdbots/pbjx-bundle-php
src/PbjxTokenSigner.php
PbjxTokenSigner.sign
public function sign(string $content, string $aud, ?string $kid = null): PbjxToken { $kid = $kid ?: $this->defaultKid; return PbjxToken::create($content, $aud, $kid, $this->getSecret($kid)); }
php
public function sign(string $content, string $aud, ?string $kid = null): PbjxToken { $kid = $kid ?: $this->defaultKid; return PbjxToken::create($content, $aud, $kid, $this->getSecret($kid)); }
[ "public", "function", "sign", "(", "string", "$", "content", ",", "string", "$", "aud", ",", "?", "string", "$", "kid", "=", "null", ")", ":", "PbjxToken", "{", "$", "kid", "=", "$", "kid", "?", ":", "$", "this", "->", "defaultKid", ";", "return", "PbjxToken", "::", "create", "(", "$", "content", ",", "$", "aud", ",", "$", "kid", ",", "$", "this", "->", "getSecret", "(", "$", "kid", ")", ")", ";", "}" ]
Creates a new signed token for the provided content. @param string $content Pbjx content that is being signed @param string $aud Pbjx endpoint this token will be sent to @param string $kid Key ID to use to sign the token. @return PbjxToken
[ "Creates", "a", "new", "signed", "token", "for", "the", "provided", "content", "." ]
train
https://github.com/gdbots/pbjx-bundle-php/blob/f3c0088583879fc92f13247a0752634bd8696eac/src/PbjxTokenSigner.php#L71-L75
gdbots/pbjx-bundle-php
src/PbjxTokenSigner.php
PbjxTokenSigner.validate
public function validate(string $content, string $aud, string $token): void { $actualToken = PbjxToken::fromString($token); $expectedToken = PbjxToken::create( $content, $aud, $actualToken->getKid(), $this->getSecret($actualToken->getKid()), [ 'exp' => $actualToken->getExp(), 'iat' => $actualToken->getIat(), ] ); if (!$actualToken->equals($expectedToken)) { throw new \InvalidArgumentException('PbjxTokens do not match.', Code::INVALID_ARGUMENT); } }
php
public function validate(string $content, string $aud, string $token): void { $actualToken = PbjxToken::fromString($token); $expectedToken = PbjxToken::create( $content, $aud, $actualToken->getKid(), $this->getSecret($actualToken->getKid()), [ 'exp' => $actualToken->getExp(), 'iat' => $actualToken->getIat(), ] ); if (!$actualToken->equals($expectedToken)) { throw new \InvalidArgumentException('PbjxTokens do not match.', Code::INVALID_ARGUMENT); } }
[ "public", "function", "validate", "(", "string", "$", "content", ",", "string", "$", "aud", ",", "string", "$", "token", ")", ":", "void", "{", "$", "actualToken", "=", "PbjxToken", "::", "fromString", "(", "$", "token", ")", ";", "$", "expectedToken", "=", "PbjxToken", "::", "create", "(", "$", "content", ",", "$", "aud", ",", "$", "actualToken", "->", "getKid", "(", ")", ",", "$", "this", "->", "getSecret", "(", "$", "actualToken", "->", "getKid", "(", ")", ")", ",", "[", "'exp'", "=>", "$", "actualToken", "->", "getExp", "(", ")", ",", "'iat'", "=>", "$", "actualToken", "->", "getIat", "(", ")", ",", "]", ")", ";", "if", "(", "!", "$", "actualToken", "->", "equals", "(", "$", "expectedToken", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'PbjxTokens do not match.'", ",", "Code", "::", "INVALID_ARGUMENT", ")", ";", "}", "}" ]
Validates that the provided token is valid and okay to use and also creates a new token with the same secret and content and compares our result to the provided token to determine if they are an exact match. If no exception is thrown the token is valid. @param string $content Pbjx content that has been signed @param string $aud Pbjx endpoint this token was sent to @param string $token The token string (typically from header x-pbjx-token) @throws \Throwable
[ "Validates", "that", "the", "provided", "token", "is", "valid", "and", "okay", "to", "use", "and", "also", "creates", "a", "new", "token", "with", "the", "same", "secret", "and", "content", "and", "compares", "our", "result", "to", "the", "provided", "token", "to", "determine", "if", "they", "are", "an", "exact", "match", "." ]
train
https://github.com/gdbots/pbjx-bundle-php/blob/f3c0088583879fc92f13247a0752634bd8696eac/src/PbjxTokenSigner.php#L91-L108
gdbots/pbjx-bundle-php
src/PbjxTokenSigner.php
PbjxTokenSigner.getSecret
private function getSecret(string $kid): string { $secret = $this->keys[$kid] ?? null; if (null !== $secret) { return $secret; } throw new \InvalidArgumentException('PbjxTokenSigner given unknown kid.', Code::INVALID_ARGUMENT); }
php
private function getSecret(string $kid): string { $secret = $this->keys[$kid] ?? null; if (null !== $secret) { return $secret; } throw new \InvalidArgumentException('PbjxTokenSigner given unknown kid.', Code::INVALID_ARGUMENT); }
[ "private", "function", "getSecret", "(", "string", "$", "kid", ")", ":", "string", "{", "$", "secret", "=", "$", "this", "->", "keys", "[", "$", "kid", "]", "??", "null", ";", "if", "(", "null", "!==", "$", "secret", ")", "{", "return", "$", "secret", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'PbjxTokenSigner given unknown kid.'", ",", "Code", "::", "INVALID_ARGUMENT", ")", ";", "}" ]
@param string $kid @return string @throws \InvalidArgumentException
[ "@param", "string", "$kid" ]
train
https://github.com/gdbots/pbjx-bundle-php/blob/f3c0088583879fc92f13247a0752634bd8696eac/src/PbjxTokenSigner.php#L117-L125
axelitus/php-base
src/Str.php
Str.compare
public static function compare($str1, $str2, $caseInsensitive = false) { return ($caseInsensitive) ? strcasecmp($str1, $str2) : strcmp($str1, $str2); }
php
public static function compare($str1, $str2, $caseInsensitive = false) { return ($caseInsensitive) ? strcasecmp($str1, $str2) : strcmp($str1, $str2); }
[ "public", "static", "function", "compare", "(", "$", "str1", ",", "$", "str2", ",", "$", "caseInsensitive", "=", "false", ")", "{", "return", "(", "$", "caseInsensitive", ")", "?", "strcasecmp", "(", "$", "str1", ",", "$", "str2", ")", ":", "strcmp", "(", "$", "str1", ",", "$", "str2", ")", ";", "}" ]
Compares two strings. @param string $str1 The first string. @param string $str2 The second string. @param bool $caseInsensitive Whether the comparison should be case sensitive or case insensitive. @return int Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Compares", "two", "strings", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L147-L150
axelitus/php-base
src/Str.php
Str.contains
public static function contains($input, $search, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING) { return (static::pos($input, $search, $caseInsensitive, $encoding) !== false); }
php
public static function contains($input, $search, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING) { return (static::pos($input, $search, $caseInsensitive, $encoding) !== false); }
[ "public", "static", "function", "contains", "(", "$", "input", ",", "$", "search", ",", "$", "caseInsensitive", "=", "false", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "return", "(", "static", "::", "pos", "(", "$", "input", ",", "$", "search", ",", "$", "caseInsensitive", ",", "$", "encoding", ")", "!==", "false", ")", ";", "}" ]
Verifies if a string contains a substring. The $encoding parameter is used to determine the encoding and thus the proper method. @param string $input The input string to compare to @param string $search The substring to compare the ending to @param bool $caseInsensitive Whether the comparison is case-sensitive @param string $encoding The encoding of the input string @return bool Whether the input string contains the substring @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Verifies", "if", "a", "string", "contains", "a", "substring", ".", "The", "$encoding", "parameter", "is", "used", "to", "determine", "the", "encoding", "and", "thus", "the", "proper", "method", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L179-L182
axelitus/php-base
src/Str.php
Str.beginsWith
public static function beginsWith($input, $search, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING) { $substr = static::sub($input, 0, static::length($search), $encoding); return (static::compare($substr, $search, $caseInsensitive) === 0); }
php
public static function beginsWith($input, $search, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING) { $substr = static::sub($input, 0, static::length($search), $encoding); return (static::compare($substr, $search, $caseInsensitive) === 0); }
[ "public", "static", "function", "beginsWith", "(", "$", "input", ",", "$", "search", ",", "$", "caseInsensitive", "=", "false", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "$", "substr", "=", "static", "::", "sub", "(", "$", "input", ",", "0", ",", "static", "::", "length", "(", "$", "search", ")", ",", "$", "encoding", ")", ";", "return", "(", "static", "::", "compare", "(", "$", "substr", ",", "$", "search", ",", "$", "caseInsensitive", ")", "===", "0", ")", ";", "}" ]
Verifies if a string begins with a substring. Uses the multibyte function if available with the given encoding $encoding. The comparison is case-sensitive by default. @param string $input The input string to compare to. @param string $search The substring to compare the beginning to. @param bool $caseInsensitive Whether the comparison is case-sensitive. @param string $encoding The encoding of the input string. @return bool Returns true if the input string begins with the given search string. @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Verifies", "if", "a", "string", "begins", "with", "a", "substring", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L198-L203
axelitus/php-base
src/Str.php
Str.endsWith
public static function endsWith($input, $search, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING) { if (($length = static::length($search, $encoding)) == 0) { return true; } $substr = static::sub($input, -$length, $length, $encoding); return (static::compare($substr, $search, $caseInsensitive) === 0); }
php
public static function endsWith($input, $search, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING) { if (($length = static::length($search, $encoding)) == 0) { return true; } $substr = static::sub($input, -$length, $length, $encoding); return (static::compare($substr, $search, $caseInsensitive) === 0); }
[ "public", "static", "function", "endsWith", "(", "$", "input", ",", "$", "search", ",", "$", "caseInsensitive", "=", "false", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "if", "(", "(", "$", "length", "=", "static", "::", "length", "(", "$", "search", ",", "$", "encoding", ")", ")", "==", "0", ")", "{", "return", "true", ";", "}", "$", "substr", "=", "static", "::", "sub", "(", "$", "input", ",", "-", "$", "length", ",", "$", "length", ",", "$", "encoding", ")", ";", "return", "(", "static", "::", "compare", "(", "$", "substr", ",", "$", "search", ",", "$", "caseInsensitive", ")", "===", "0", ")", ";", "}" ]
Verifies if a string ends with a substring. Uses the multibyte function if available with the given encoding $encoding. The comparison is case-sensitive by default. @param string $input The input string to compare to. @param string $search The substring to compare the ending to. @param bool $caseInsensitive Whether the comparison is case-sensitive. @param string $encoding The encoding of the input string. @return bool Returns true if the $input string ends with the given $search string. @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Verifies", "if", "a", "string", "ends", "with", "a", "substring", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L219-L228
axelitus/php-base
src/Str.php
Str.isOneOf
public static function isOneOf($input, array $values, $caseInsensitive = false, $returnIndex = false) { if (is_null($input)) { return false; } foreach ($values as $index => $str) { if (static::equals($input, $str, $caseInsensitive)) { return ($returnIndex) ? $index : true; } } return false; }
php
public static function isOneOf($input, array $values, $caseInsensitive = false, $returnIndex = false) { if (is_null($input)) { return false; } foreach ($values as $index => $str) { if (static::equals($input, $str, $caseInsensitive)) { return ($returnIndex) ? $index : true; } } return false; }
[ "public", "static", "function", "isOneOf", "(", "$", "input", ",", "array", "$", "values", ",", "$", "caseInsensitive", "=", "false", ",", "$", "returnIndex", "=", "false", ")", "{", "if", "(", "is_null", "(", "$", "input", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "values", "as", "$", "index", "=>", "$", "str", ")", "{", "if", "(", "static", "::", "equals", "(", "$", "input", ",", "$", "str", ",", "$", "caseInsensitive", ")", ")", "{", "return", "(", "$", "returnIndex", ")", "?", "$", "index", ":", "true", ";", "}", "}", "return", "false", ";", "}" ]
Verifies if the input string is one of the values of the given array. Verifies if the input string is one of the values of the given array. Each of the values of the array is matched against the input string. The index of the value that matched can be returned instead of the default bool value. The comparison can be case sensitive or case insensitive. @param string $input The input string @param array $values The string|PrimitiveString array to look for the input string @param bool $caseInsensitive Whether the comparison is case-sensitive @param bool $returnIndex Whether to return the matched array's item instead @return bool|int Whether the input string was found in the array or the item's index if found @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Verifies", "if", "the", "input", "string", "is", "one", "of", "the", "values", "of", "the", "given", "array", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L246-L259
axelitus/php-base
src/Str.php
Str.match
public static function match($input, $pattern, array &$matches = null, $flags = 0, $offset = 0) { return preg_match($pattern, $input, $matches, $flags, $offset); }
php
public static function match($input, $pattern, array &$matches = null, $flags = 0, $offset = 0) { return preg_match($pattern, $input, $matches, $flags, $offset); }
[ "public", "static", "function", "match", "(", "$", "input", ",", "$", "pattern", ",", "array", "&", "$", "matches", "=", "null", ",", "$", "flags", "=", "0", ",", "$", "offset", "=", "0", ")", "{", "return", "preg_match", "(", "$", "pattern", ",", "$", "input", ",", "$", "matches", ",", "$", "flags", ",", "$", "offset", ")", ";", "}" ]
Searches the input string for a match to the regular expression given in pattern. @param string $input The input string. @param string $pattern The pattern to search for, as a string. @param array $matches If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on. @param int $flags The flag modifiers. @param int $offset The offset from which to start the search (in bytes). @return int Returns 1 if the pattern matches the input string, 0 if it does not, or false if an error occurred. @see http://php.net/manual/en/function.preg-match.php
[ "Searches", "the", "input", "string", "for", "a", "match", "to", "the", "regular", "expression", "given", "in", "pattern", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L276-L279
axelitus/php-base
src/Str.php
Str.length
public static function length($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strlen') ? mb_strlen($input, $encoding) : strlen($input); }
php
public static function length($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strlen') ? mb_strlen($input, $encoding) : strlen($input); }
[ "public", "static", "function", "length", "(", "$", "input", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "return", "function_exists", "(", "'mb_strlen'", ")", "?", "mb_strlen", "(", "$", "input", ",", "$", "encoding", ")", ":", "strlen", "(", "$", "input", ")", ";", "}" ]
Gets the length of the given string. Uses the multibyte function if available with the given encoding $encoding. @author FuelPHP (http://fuelphp.com) @param string $input The input string. @param string $encoding The encoding of the input string for multibyte functions. @return int Returns the length of the string.
[ "Gets", "the", "length", "of", "the", "given", "string", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L297-L300
axelitus/php-base
src/Str.php
Str.sub
public static function sub($input, $start, $length = null, $encoding = self::DEFAULT_ENCODING) { // sub input functions don't parse null correctly $length = is_null($length) ? (function_exists('mb_substr') ? mb_strlen($input, $encoding) : strlen($input)) - $start : $length; return function_exists('mb_substr') ? mb_substr($input, $start, $length, $encoding) : substr($input, $start, $length); }
php
public static function sub($input, $start, $length = null, $encoding = self::DEFAULT_ENCODING) { // sub input functions don't parse null correctly $length = is_null($length) ? (function_exists('mb_substr') ? mb_strlen($input, $encoding) : strlen($input)) - $start : $length; return function_exists('mb_substr') ? mb_substr($input, $start, $length, $encoding) : substr($input, $start, $length); }
[ "public", "static", "function", "sub", "(", "$", "input", ",", "$", "start", ",", "$", "length", "=", "null", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "// sub input functions don't parse null correctly", "$", "length", "=", "is_null", "(", "$", "length", ")", "?", "(", "function_exists", "(", "'mb_substr'", ")", "?", "mb_strlen", "(", "$", "input", ",", "$", "encoding", ")", ":", "strlen", "(", "$", "input", ")", ")", "-", "$", "start", ":", "$", "length", ";", "return", "function_exists", "(", "'mb_substr'", ")", "?", "mb_substr", "(", "$", "input", ",", "$", "start", ",", "$", "length", ",", "$", "encoding", ")", ":", "substr", "(", "$", "input", ",", "$", "start", ",", "$", "length", ")", ";", "}" ]
Returns the portion of string specified by the $start and $length parameters. USes the multibyte function if available with the given encoding $encoding and falls back to substr. @author FuelPHP (http://fuelphp.com) @param string $input The input string. @param int $start The start index from where to begin extracting. @param int $length The length of the extracted substring. @param string $encoding The encoding of the $input string for multibyte functions. @throws \InvalidArgumentException @return string Returns the extracted substring or false on failure.
[ "Returns", "the", "portion", "of", "string", "specified", "by", "the", "$start", "and", "$length", "parameters", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L321-L334
axelitus/php-base
src/Str.php
Str.pos
public static function pos($input, $search, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING) { if ($caseInsensitive) { return function_exists('mb_stripos') ? mb_stripos($input, $search, 0, $encoding) : (stripos($input, $search) !== false ? true : false); } return function_exists('mb_strpos') ? mb_strpos($input, $search, 0, $encoding) : (strpos($input, $search) !== false ? true : false); }
php
public static function pos($input, $search, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING) { if ($caseInsensitive) { return function_exists('mb_stripos') ? mb_stripos($input, $search, 0, $encoding) : (stripos($input, $search) !== false ? true : false); } return function_exists('mb_strpos') ? mb_strpos($input, $search, 0, $encoding) : (strpos($input, $search) !== false ? true : false); }
[ "public", "static", "function", "pos", "(", "$", "input", ",", "$", "search", ",", "$", "caseInsensitive", "=", "false", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "if", "(", "$", "caseInsensitive", ")", "{", "return", "function_exists", "(", "'mb_stripos'", ")", "?", "mb_stripos", "(", "$", "input", ",", "$", "search", ",", "0", ",", "$", "encoding", ")", ":", "(", "stripos", "(", "$", "input", ",", "$", "search", ")", "!==", "false", "?", "true", ":", "false", ")", ";", "}", "return", "function_exists", "(", "'mb_strpos'", ")", "?", "mb_strpos", "(", "$", "input", ",", "$", "search", ",", "0", ",", "$", "encoding", ")", ":", "(", "strpos", "(", "$", "input", ",", "$", "search", ")", "!==", "false", "?", "true", ":", "false", ")", ";", "}" ]
Finds the position of the first occurrence of a substring in a string. The $encoding parameter is used to determine the encoding and thus the proper method to be used. @param string $input The input string to compare to @param string $search The substring to compare the ending to @param bool $caseInsensitive Whether the comparison is case-sensitive @param string $encoding The encoding of the input string @return int|false Returns the numeric position of the first occurrence of the searched string in the input string. If it is not found, it returns false. @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Finds", "the", "position", "of", "the", "first", "occurrence", "of", "a", "substring", "in", "a", "string", ".", "The", "$encoding", "parameter", "is", "used", "to", "determine", "the", "encoding", "and", "thus", "the", "proper", "method", "to", "be", "used", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L350-L361
axelitus/php-base
src/Str.php
Str.replace
public static function replace( $input, $search, $replace, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING, &$count = null ) { return function_exists('mb_strlen') ? static::mbStrReplaceCaller($search, $replace, $input, $caseInsensitive, $encoding, $count) : (($caseInsensitive) ? (str_ireplace($search, $replace, $input, $count)) // @codeCoverageIgnore // excluded as reaching this line is environment dependent. : (str_replace($search, $replace, $input, $count))); }
php
public static function replace( $input, $search, $replace, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING, &$count = null ) { return function_exists('mb_strlen') ? static::mbStrReplaceCaller($search, $replace, $input, $caseInsensitive, $encoding, $count) : (($caseInsensitive) ? (str_ireplace($search, $replace, $input, $count)) // @codeCoverageIgnore // excluded as reaching this line is environment dependent. : (str_replace($search, $replace, $input, $count))); }
[ "public", "static", "function", "replace", "(", "$", "input", ",", "$", "search", ",", "$", "replace", ",", "$", "caseInsensitive", "=", "false", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ",", "&", "$", "count", "=", "null", ")", "{", "return", "function_exists", "(", "'mb_strlen'", ")", "?", "static", "::", "mbStrReplaceCaller", "(", "$", "search", ",", "$", "replace", ",", "$", "input", ",", "$", "caseInsensitive", ",", "$", "encoding", ",", "$", "count", ")", ":", "(", "(", "$", "caseInsensitive", ")", "?", "(", "str_ireplace", "(", "$", "search", ",", "$", "replace", ",", "$", "input", ",", "$", "count", ")", ")", "// @codeCoverageIgnore", "// excluded as reaching this line is environment dependent.", ":", "(", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "input", ",", "$", "count", ")", ")", ")", ";", "}" ]
Replaces a substring inside a string. @param string $input The input string @param string $search The substring to be replaced @param string $replace The substring replacement @param bool $caseInsensitive Whether the comparison should be case sensitive @param string $encoding The encoding of the input string @param int $count If passed, this will be set to the number of replacements performed. @return string The string with the substring replaced @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Replaces", "a", "substring", "inside", "a", "string", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L380-L394
axelitus/php-base
src/Str.php
Str.mbStrReplaceCaller
protected static function mbStrReplaceCaller( $search, $replace, $subject, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING, &$count = null ) { if (is_array($subject)) { $result = []; foreach ($subject as $item) { $result[] = static::mbStrReplaceCaller($search, $replace, $item, $caseInsensitive, $encoding, $count); } return $result; } if (!is_array($search)) { return static::mbStrReplaceInternal($search, $replace, $subject, $caseInsensitive, $encoding, $count); } $replaceIsArray = is_array($replace); foreach ($search as $key => $value) { $subject = static::mbStrReplaceInternal( $value, ($replaceIsArray ? $replace[$key] : $replace), $subject, $caseInsensitive, $encoding, $count ); } return $subject; }
php
protected static function mbStrReplaceCaller( $search, $replace, $subject, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING, &$count = null ) { if (is_array($subject)) { $result = []; foreach ($subject as $item) { $result[] = static::mbStrReplaceCaller($search, $replace, $item, $caseInsensitive, $encoding, $count); } return $result; } if (!is_array($search)) { return static::mbStrReplaceInternal($search, $replace, $subject, $caseInsensitive, $encoding, $count); } $replaceIsArray = is_array($replace); foreach ($search as $key => $value) { $subject = static::mbStrReplaceInternal( $value, ($replaceIsArray ? $replace[$key] : $replace), $subject, $caseInsensitive, $encoding, $count ); } return $subject; }
[ "protected", "static", "function", "mbStrReplaceCaller", "(", "$", "search", ",", "$", "replace", ",", "$", "subject", ",", "$", "caseInsensitive", "=", "false", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ",", "&", "$", "count", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "subject", ")", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "subject", "as", "$", "item", ")", "{", "$", "result", "[", "]", "=", "static", "::", "mbStrReplaceCaller", "(", "$", "search", ",", "$", "replace", ",", "$", "item", ",", "$", "caseInsensitive", ",", "$", "encoding", ",", "$", "count", ")", ";", "}", "return", "$", "result", ";", "}", "if", "(", "!", "is_array", "(", "$", "search", ")", ")", "{", "return", "static", "::", "mbStrReplaceInternal", "(", "$", "search", ",", "$", "replace", ",", "$", "subject", ",", "$", "caseInsensitive", ",", "$", "encoding", ",", "$", "count", ")", ";", "}", "$", "replaceIsArray", "=", "is_array", "(", "$", "replace", ")", ";", "foreach", "(", "$", "search", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "subject", "=", "static", "::", "mbStrReplaceInternal", "(", "$", "value", ",", "(", "$", "replaceIsArray", "?", "$", "replace", "[", "$", "key", "]", ":", "$", "replace", ")", ",", "$", "subject", ",", "$", "caseInsensitive", ",", "$", "encoding", ",", "$", "count", ")", ";", "}", "return", "$", "subject", ";", "}" ]
Replaces a substring inside a string with multi-byte support @param string|array $search @param string|array $replace @param string|array $subject @param bool $caseInsensitive @param string $encoding @param int $count @return array|string @see https://github.com/faceleg/php-mb_str_replace @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Replaces", "a", "substring", "inside", "a", "string", "with", "multi", "-", "byte", "support" ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L410-L444
axelitus/php-base
src/Str.php
Str.mbStrReplaceInternal
protected static function mbStrReplaceInternal( $search, $replace, $subject, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING, &$count = null ) { $searchLength = mb_strlen($search, $encoding); $subjectLength = mb_strlen($subject, $encoding); $offset = 0; $result = ''; while ($offset < $subjectLength) { $match = $caseInsensitive ? mb_stripos($subject, $search, $offset, $encoding) : mb_strpos($subject, $search, $offset, $encoding); if ($match === false) { if ($offset === 0) { // No match was ever found, just return the subject. return $subject; } // Append the final portion of the subject to the replaced. $result .= mb_substr($subject, $offset, $subjectLength - $offset, $encoding); break; } if ($count !== null) { $count++; } $result .= mb_substr($subject, $offset, $match - $offset, $encoding); $result .= $replace; $offset = $match + $searchLength; } return $result; }
php
protected static function mbStrReplaceInternal( $search, $replace, $subject, $caseInsensitive = false, $encoding = self::DEFAULT_ENCODING, &$count = null ) { $searchLength = mb_strlen($search, $encoding); $subjectLength = mb_strlen($subject, $encoding); $offset = 0; $result = ''; while ($offset < $subjectLength) { $match = $caseInsensitive ? mb_stripos($subject, $search, $offset, $encoding) : mb_strpos($subject, $search, $offset, $encoding); if ($match === false) { if ($offset === 0) { // No match was ever found, just return the subject. return $subject; } // Append the final portion of the subject to the replaced. $result .= mb_substr($subject, $offset, $subjectLength - $offset, $encoding); break; } if ($count !== null) { $count++; } $result .= mb_substr($subject, $offset, $match - $offset, $encoding); $result .= $replace; $offset = $match + $searchLength; } return $result; }
[ "protected", "static", "function", "mbStrReplaceInternal", "(", "$", "search", ",", "$", "replace", ",", "$", "subject", ",", "$", "caseInsensitive", "=", "false", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ",", "&", "$", "count", "=", "null", ")", "{", "$", "searchLength", "=", "mb_strlen", "(", "$", "search", ",", "$", "encoding", ")", ";", "$", "subjectLength", "=", "mb_strlen", "(", "$", "subject", ",", "$", "encoding", ")", ";", "$", "offset", "=", "0", ";", "$", "result", "=", "''", ";", "while", "(", "$", "offset", "<", "$", "subjectLength", ")", "{", "$", "match", "=", "$", "caseInsensitive", "?", "mb_stripos", "(", "$", "subject", ",", "$", "search", ",", "$", "offset", ",", "$", "encoding", ")", ":", "mb_strpos", "(", "$", "subject", ",", "$", "search", ",", "$", "offset", ",", "$", "encoding", ")", ";", "if", "(", "$", "match", "===", "false", ")", "{", "if", "(", "$", "offset", "===", "0", ")", "{", "// No match was ever found, just return the subject.", "return", "$", "subject", ";", "}", "// Append the final portion of the subject to the replaced.", "$", "result", ".=", "mb_substr", "(", "$", "subject", ",", "$", "offset", ",", "$", "subjectLength", "-", "$", "offset", ",", "$", "encoding", ")", ";", "break", ";", "}", "if", "(", "$", "count", "!==", "null", ")", "{", "$", "count", "++", ";", "}", "$", "result", ".=", "mb_substr", "(", "$", "subject", ",", "$", "offset", ",", "$", "match", "-", "$", "offset", ",", "$", "encoding", ")", ";", "$", "result", ".=", "$", "replace", ";", "$", "offset", "=", "$", "match", "+", "$", "searchLength", ";", "}", "return", "$", "result", ";", "}" ]
Implementation of mb_str_replace. Do not call directly. @param string|array $search @param string|array $replace @param string|array $subject @param bool $caseInsensitive @param string $encoding @param int $count @return string @see https://github.com/faceleg/php-mb_str_replace @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Implementation", "of", "mb_str_replace", ".", "Do", "not", "call", "directly", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L460-L495
axelitus/php-base
src/Str.php
Str.truncate
public static function truncate($input, $limit, $continuation = '...', $isHtml = false) { $offset = 0; $tags = []; if ($isHtml) { $input = static::truncateHtml($input, $limit, $offset, $tags); } $newString = static::sub($input, 0, $limit = min(static::length($input), $limit + $offset)); $newString .= (static::length($input) > $limit ? $continuation : ''); $newString .= count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : ''; return $newString; }
php
public static function truncate($input, $limit, $continuation = '...', $isHtml = false) { $offset = 0; $tags = []; if ($isHtml) { $input = static::truncateHtml($input, $limit, $offset, $tags); } $newString = static::sub($input, 0, $limit = min(static::length($input), $limit + $offset)); $newString .= (static::length($input) > $limit ? $continuation : ''); $newString .= count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : ''; return $newString; }
[ "public", "static", "function", "truncate", "(", "$", "input", ",", "$", "limit", ",", "$", "continuation", "=", "'...'", ",", "$", "isHtml", "=", "false", ")", "{", "$", "offset", "=", "0", ";", "$", "tags", "=", "[", "]", ";", "if", "(", "$", "isHtml", ")", "{", "$", "input", "=", "static", "::", "truncateHtml", "(", "$", "input", ",", "$", "limit", ",", "$", "offset", ",", "$", "tags", ")", ";", "}", "$", "newString", "=", "static", "::", "sub", "(", "$", "input", ",", "0", ",", "$", "limit", "=", "min", "(", "static", "::", "length", "(", "$", "input", ")", ",", "$", "limit", "+", "$", "offset", ")", ")", ";", "$", "newString", ".=", "(", "static", "::", "length", "(", "$", "input", ")", ">", "$", "limit", "?", "$", "continuation", ":", "''", ")", ";", "$", "newString", ".=", "count", "(", "$", "tags", "=", "array_reverse", "(", "$", "tags", ")", ")", "?", "'</'", ".", "implode", "(", "'></'", ",", "$", "tags", ")", ".", "'>'", ":", "''", ";", "return", "$", "newString", ";", "}" ]
Truncates a string to the given length. Truncates a string to the given length. It will optionally preserve HTML tags if $is_html is set to true. @author FuelPHP (http://fuelphp.com) @param string $input The string to truncate. @param int $limit The number of characters to truncate to. @param string $continuation The string to use to denote it was truncated @param bool $isHtml Whether the string has HTML @return string The truncated string @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Truncates", "a", "string", "to", "the", "given", "length", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L512-L525
axelitus/php-base
src/Str.php
Str.truncateHtml
protected static function truncateHtml($input, &$limit, &$offset, &$tags) { static::truncateSpecialChars($input, $limit); // Handle all the html tags. preg_match_all('/<[^>]+>([^<]*)/', $input, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); if (is_array($matches) || $matches instanceof \Traversable) { foreach ($matches as $match) { if ($match[0][1] - $offset >= $limit) { break; } $tag = static::sub(strtok($match[0][0], " \t\n\r\0\x0B>"), 1); if ($tag[0] != '/') { $tags[] = $tag; } elseif (end($tags) == static::sub($tag, 1)) { array_pop($tags); } $offset += $match[1][1] - $match[0][1]; } } return $input; }
php
protected static function truncateHtml($input, &$limit, &$offset, &$tags) { static::truncateSpecialChars($input, $limit); // Handle all the html tags. preg_match_all('/<[^>]+>([^<]*)/', $input, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); if (is_array($matches) || $matches instanceof \Traversable) { foreach ($matches as $match) { if ($match[0][1] - $offset >= $limit) { break; } $tag = static::sub(strtok($match[0][0], " \t\n\r\0\x0B>"), 1); if ($tag[0] != '/') { $tags[] = $tag; } elseif (end($tags) == static::sub($tag, 1)) { array_pop($tags); } $offset += $match[1][1] - $match[0][1]; } } return $input; }
[ "protected", "static", "function", "truncateHtml", "(", "$", "input", ",", "&", "$", "limit", ",", "&", "$", "offset", ",", "&", "$", "tags", ")", "{", "static", "::", "truncateSpecialChars", "(", "$", "input", ",", "$", "limit", ")", ";", "// Handle all the html tags.", "preg_match_all", "(", "'/<[^>]+>([^<]*)/'", ",", "$", "input", ",", "$", "matches", ",", "PREG_OFFSET_CAPTURE", "|", "PREG_SET_ORDER", ")", ";", "if", "(", "is_array", "(", "$", "matches", ")", "||", "$", "matches", "instanceof", "\\", "Traversable", ")", "{", "foreach", "(", "$", "matches", "as", "$", "match", ")", "{", "if", "(", "$", "match", "[", "0", "]", "[", "1", "]", "-", "$", "offset", ">=", "$", "limit", ")", "{", "break", ";", "}", "$", "tag", "=", "static", "::", "sub", "(", "strtok", "(", "$", "match", "[", "0", "]", "[", "0", "]", ",", "\" \\t\\n\\r\\0\\x0B>\"", ")", ",", "1", ")", ";", "if", "(", "$", "tag", "[", "0", "]", "!=", "'/'", ")", "{", "$", "tags", "[", "]", "=", "$", "tag", ";", "}", "elseif", "(", "end", "(", "$", "tags", ")", "==", "static", "::", "sub", "(", "$", "tag", ",", "1", ")", ")", "{", "array_pop", "(", "$", "tags", ")", ";", "}", "$", "offset", "+=", "$", "match", "[", "1", "]", "[", "1", "]", "-", "$", "match", "[", "0", "]", "[", "1", "]", ";", "}", "}", "return", "$", "input", ";", "}" ]
Handles the strip of tags in the {@link truncate} function. @param string $input The input string. @param int $limit The number of characters to truncate to. @param int $offset The offset. @param array $tags The stripped tags. @return string Returns the stripped string to reassemble.
[ "Handles", "the", "strip", "of", "tags", "in", "the", "{", "@link", "truncate", "}", "function", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L537-L561
axelitus/php-base
src/Str.php
Str.truncateSpecialChars
protected static function truncateSpecialChars($input, &$limit) { // Handle special characters. preg_match_all('/&[a-z]+;/i', strip_tags($input), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); if (is_array($matches) || $matches instanceof \Traversable) { foreach ($matches as $match) { if ($match[0][1] >= $limit) { break; } $limit += (static::length($match[0][0]) - 1); } } }
php
protected static function truncateSpecialChars($input, &$limit) { // Handle special characters. preg_match_all('/&[a-z]+;/i', strip_tags($input), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); if (is_array($matches) || $matches instanceof \Traversable) { foreach ($matches as $match) { if ($match[0][1] >= $limit) { break; } $limit += (static::length($match[0][0]) - 1); } } }
[ "protected", "static", "function", "truncateSpecialChars", "(", "$", "input", ",", "&", "$", "limit", ")", "{", "// Handle special characters.", "preg_match_all", "(", "'/&[a-z]+;/i'", ",", "strip_tags", "(", "$", "input", ")", ",", "$", "matches", ",", "PREG_OFFSET_CAPTURE", "|", "PREG_SET_ORDER", ")", ";", "if", "(", "is_array", "(", "$", "matches", ")", "||", "$", "matches", "instanceof", "\\", "Traversable", ")", "{", "foreach", "(", "$", "matches", "as", "$", "match", ")", "{", "if", "(", "$", "match", "[", "0", "]", "[", "1", "]", ">=", "$", "limit", ")", "{", "break", ";", "}", "$", "limit", "+=", "(", "static", "::", "length", "(", "$", "match", "[", "0", "]", "[", "0", "]", ")", "-", "1", ")", ";", "}", "}", "}" ]
Handles the special characters while stripping html tags in the {@link truncateHtml} function. @param string $input The input string. @param int $limit The number of characters to truncate to.
[ "Handles", "the", "special", "characters", "while", "stripping", "html", "tags", "in", "the", "{", "@link", "truncateHtml", "}", "function", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L569-L581
axelitus/php-base
src/Str.php
Str.lower
public static function lower($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strtolower') ? mb_strtolower($input, $encoding) : strtolower($input); }
php
public static function lower($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strtolower') ? mb_strtolower($input, $encoding) : strtolower($input); }
[ "public", "static", "function", "lower", "(", "$", "input", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "return", "function_exists", "(", "'mb_strtolower'", ")", "?", "mb_strtolower", "(", "$", "input", ",", "$", "encoding", ")", ":", "strtolower", "(", "$", "input", ")", ";", "}" ]
Returns a lowercased string. Returns a lowercased string. The $encoding parameter is used to determine the input string encoding and thus use the proper method. The functions uses mb_strtolower if present and falls back to strtolower. @author FuelPHP (http://fuelphp.com) @param string $input The input string @param string $encoding The encoding of the input string @return string The lowercased string
[ "Returns", "a", "lowercased", "string", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L600-L605
axelitus/php-base
src/Str.php
Str.upper
public static function upper($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strtoupper') ? mb_strtoupper($input, $encoding) : strtoupper($input); }
php
public static function upper($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strtoupper') ? mb_strtoupper($input, $encoding) : strtoupper($input); }
[ "public", "static", "function", "upper", "(", "$", "input", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "return", "function_exists", "(", "'mb_strtoupper'", ")", "?", "mb_strtoupper", "(", "$", "input", ",", "$", "encoding", ")", ":", "strtoupper", "(", "$", "input", ")", ";", "}" ]
Returns an uppercased string. Returns an uppercased string. The $encoding parameter is used to determine the input string encoding and thus use the proper method. The functions uses mb_strtoupper if present and falls back to strtoupper. @author FuelPHP (http://fuelphp.com) @param string $input The input string @param string $encoding The encoding of the input string @return string The uppercased string
[ "Returns", "an", "uppercased", "string", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L620-L625
axelitus/php-base
src/Str.php
Str.lcfirst
public static function lcfirst($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strtolower') ? mb_strtolower(mb_substr($input, 0, 1, $encoding), $encoding) . mb_substr($input, 1, mb_strlen($input, $encoding), $encoding) : lcfirst($input); }
php
public static function lcfirst($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strtolower') ? mb_strtolower(mb_substr($input, 0, 1, $encoding), $encoding) . mb_substr($input, 1, mb_strlen($input, $encoding), $encoding) : lcfirst($input); }
[ "public", "static", "function", "lcfirst", "(", "$", "input", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "return", "function_exists", "(", "'mb_strtolower'", ")", "?", "mb_strtolower", "(", "mb_substr", "(", "$", "input", ",", "0", ",", "1", ",", "$", "encoding", ")", ",", "$", "encoding", ")", ".", "mb_substr", "(", "$", "input", ",", "1", ",", "mb_strlen", "(", "$", "input", ",", "$", "encoding", ")", ",", "$", "encoding", ")", ":", "lcfirst", "(", "$", "input", ")", ";", "}" ]
Returns a string with the first char as lowercase. Returns a string with the first char as lowercase. The other characters in the string are left untouched. The $encoding parameter is used to determine the input string encoding and thus use the proper method. The function uses mb_strtolower, mb_mb_substr and mb_strlen if present and falls back to lcfirst. @author FuelPHP (http://fuelphp.com) @param string $input The input string @param string $encoding The encoding of the input string @return string The string with the first char lowercased
[ "Returns", "a", "string", "with", "the", "first", "char", "as", "lowercase", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L641-L647
axelitus/php-base
src/Str.php
Str.ucfirst
public static function ucfirst($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strtoupper') ? mb_strtoupper(mb_substr($input, 0, 1, $encoding), $encoding) . mb_substr($input, 1, mb_strlen($input, $encoding), $encoding) : ucfirst($input); }
php
public static function ucfirst($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_strtoupper') ? mb_strtoupper(mb_substr($input, 0, 1, $encoding), $encoding) . mb_substr($input, 1, mb_strlen($input, $encoding), $encoding) : ucfirst($input); }
[ "public", "static", "function", "ucfirst", "(", "$", "input", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "return", "function_exists", "(", "'mb_strtoupper'", ")", "?", "mb_strtoupper", "(", "mb_substr", "(", "$", "input", ",", "0", ",", "1", ",", "$", "encoding", ")", ",", "$", "encoding", ")", ".", "mb_substr", "(", "$", "input", ",", "1", ",", "mb_strlen", "(", "$", "input", ",", "$", "encoding", ")", ",", "$", "encoding", ")", ":", "ucfirst", "(", "$", "input", ")", ";", "}" ]
Returns a string with the first char as uppercase. Returns a string with the first char as uppercase. The other characters in the string are left untouched. The $encoding parameter is used to determine the input string encoding and thus use the proper method. The function uses mb_strtoupper, mb_mb_substr and mb_strlen if present and falls back to ucfirst. @author FuelPHP (http://fuelphp.com) @param string $input The input string @param string $encoding The encoding of the input string @return string The string with the first char uppercased
[ "Returns", "a", "string", "with", "the", "first", "char", "as", "uppercase", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L663-L669
axelitus/php-base
src/Str.php
Str.ucwords
public static function ucwords($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_convert_case') ? mb_convert_case($input, MB_CASE_TITLE, $encoding) : ucwords(strtolower($input)); }
php
public static function ucwords($input, $encoding = self::DEFAULT_ENCODING) { return function_exists('mb_convert_case') ? mb_convert_case($input, MB_CASE_TITLE, $encoding) : ucwords(strtolower($input)); }
[ "public", "static", "function", "ucwords", "(", "$", "input", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "return", "function_exists", "(", "'mb_convert_case'", ")", "?", "mb_convert_case", "(", "$", "input", ",", "MB_CASE_TITLE", ",", "$", "encoding", ")", ":", "ucwords", "(", "strtolower", "(", "$", "input", ")", ")", ";", "}" ]
Returns a string with the words capitalized. Returns a string with the words capitalized. The $encoding parameter is used to determine the input string encoding and thus use the proper method. The function uses mb_convert_case if present and falls back to ucwords. The ucwords function normally does not lowercase the input string first, this function does. @author FuelPHP (http://fuelphp.com) @param string $input The input string @param string $encoding The encoding of the input string @return string The string with the words capitalized
[ "Returns", "a", "string", "with", "the", "words", "capitalized", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L685-L690
axelitus/php-base
src/Str.php
Str.studly
public static function studly($input, array $separators = ['_'], $encoding = self::DEFAULT_ENCODING) { $studly = $input; if (!empty($separators)) { $studly = preg_replace_callback( static::studlyBuildPattern($separators), function ($matches) { return strtoupper($matches[2]); }, strval($input) ); $words = explode(' ', $studly); foreach ($words as &$word) { $word = static::ucfirst($word, $encoding); } $studly = implode(' ', $words); } return $studly; }
php
public static function studly($input, array $separators = ['_'], $encoding = self::DEFAULT_ENCODING) { $studly = $input; if (!empty($separators)) { $studly = preg_replace_callback( static::studlyBuildPattern($separators), function ($matches) { return strtoupper($matches[2]); }, strval($input) ); $words = explode(' ', $studly); foreach ($words as &$word) { $word = static::ucfirst($word, $encoding); } $studly = implode(' ', $words); } return $studly; }
[ "public", "static", "function", "studly", "(", "$", "input", ",", "array", "$", "separators", "=", "[", "'_'", "]", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "$", "studly", "=", "$", "input", ";", "if", "(", "!", "empty", "(", "$", "separators", ")", ")", "{", "$", "studly", "=", "preg_replace_callback", "(", "static", "::", "studlyBuildPattern", "(", "$", "separators", ")", ",", "function", "(", "$", "matches", ")", "{", "return", "strtoupper", "(", "$", "matches", "[", "2", "]", ")", ";", "}", ",", "strval", "(", "$", "input", ")", ")", ";", "$", "words", "=", "explode", "(", "' '", ",", "$", "studly", ")", ";", "foreach", "(", "$", "words", "as", "&", "$", "word", ")", "{", "$", "word", "=", "static", "::", "ucfirst", "(", "$", "word", ",", "$", "encoding", ")", ";", "}", "$", "studly", "=", "implode", "(", "' '", ",", "$", "words", ")", ";", "}", "return", "$", "studly", ";", "}" ]
Converts a char(s)-separated string into studly caps. Converts a char(s)-separated string into studly caps. The string can be split using one or more separators (being them a single char or a string). The $encoding parameter is used to determine the input string encoding and thus use the proper method. When the space char is not used as a separator, each word is converted to studly caps on its own, otherwise the result will be a single studly-caps-cased string. @param string $input The input string @param array $separators An array containing separators to split the input string @param string $encoding The encoding of the input string @return string The studly-caps-cased string
[ "Converts", "a", "char", "(", "s", ")", "-", "separated", "string", "into", "studly", "caps", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L711-L731
axelitus/php-base
src/Str.php
Str.studlyBuildPattern
protected static function studlyBuildPattern(array $separators) { $pattern = ''; foreach ($separators as $separator) { $pattern .= '|' . preg_quote($separator); } $pattern = '/(^' . $pattern . ')(.)/'; return $pattern; }
php
protected static function studlyBuildPattern(array $separators) { $pattern = ''; foreach ($separators as $separator) { $pattern .= '|' . preg_quote($separator); } $pattern = '/(^' . $pattern . ')(.)/'; return $pattern; }
[ "protected", "static", "function", "studlyBuildPattern", "(", "array", "$", "separators", ")", "{", "$", "pattern", "=", "''", ";", "foreach", "(", "$", "separators", "as", "$", "separator", ")", "{", "$", "pattern", ".=", "'|'", ".", "preg_quote", "(", "$", "separator", ")", ";", "}", "$", "pattern", "=", "'/(^'", ".", "$", "pattern", ".", "')(.)/'", ";", "return", "$", "pattern", ";", "}" ]
Builds the studly patter with the given separators. @param array $separators The array of separators to use. @return string Returns the built studly pattern.
[ "Builds", "the", "studly", "patter", "with", "the", "given", "separators", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L740-L749
axelitus/php-base
src/Str.php
Str.camel
public static function camel($input, array $separators = ['_'], $encoding = self::DEFAULT_ENCODING) { $camel = static::studly($input, $separators, $encoding); $words = explode(' ', $camel); foreach ($words as &$word) { $word = static::lcfirst($word, $encoding); } $camel = implode(' ', $words); return $camel; }
php
public static function camel($input, array $separators = ['_'], $encoding = self::DEFAULT_ENCODING) { $camel = static::studly($input, $separators, $encoding); $words = explode(' ', $camel); foreach ($words as &$word) { $word = static::lcfirst($word, $encoding); } $camel = implode(' ', $words); return $camel; }
[ "public", "static", "function", "camel", "(", "$", "input", ",", "array", "$", "separators", "=", "[", "'_'", "]", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "$", "camel", "=", "static", "::", "studly", "(", "$", "input", ",", "$", "separators", ",", "$", "encoding", ")", ";", "$", "words", "=", "explode", "(", "' '", ",", "$", "camel", ")", ";", "foreach", "(", "$", "words", "as", "&", "$", "word", ")", "{", "$", "word", "=", "static", "::", "lcfirst", "(", "$", "word", ",", "$", "encoding", ")", ";", "}", "$", "camel", "=", "implode", "(", "' '", ",", "$", "words", ")", ";", "return", "$", "camel", ";", "}" ]
Converts a char(s)-separated string into camel case. Converts a char(s)-separated string into camel case. The string can be split using one or more separators (being them a single char or a string). The $encoding parameter is used to determine the input string encoding and thus use the proper method. When the space char is not used as a separator, each word is converted to camel case on its own, otherwise the result will be a single camel-cased string. @param string $input The input string @param array $separators An array containing separators to split the input string @param string $encoding The encoding of the input string @return string The camel-cased string
[ "Converts", "a", "char", "(", "s", ")", "-", "separated", "string", "into", "camel", "case", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L766-L776
axelitus/php-base
src/Str.php
Str.separated
public static function separated($input, $separator = '_', $transform = null, $encoding = self::DEFAULT_ENCODING) { if (!is_string($separator) || $separator == '') { throw new \InvalidArgumentException("The \$separator parameter must be a non-empty string."); } $separated = preg_replace_callback( '/(^.[^A-Z]+$)|(^.+?(?=[A-Z]))|( +)(.+?)(?=[A-Z])|([A-Z]+(?=$|[A-Z][a-z])|[A-Z]?[a-z]+)/', function ($matches) use ($separator, $transform, $encoding) { $transformed = trim($matches[0]); $countMatches = count($matches); $transformed = (($countMatches == 5) ? $matches[3] : '') . $transformed; $transformed = (($countMatches == 6) ? $separator : '') . $transformed; return $transformed; }, $input ); // Run transform to the separated string $separated = static::separatedTransform($separated, $transform, $encoding); return $separated; }
php
public static function separated($input, $separator = '_', $transform = null, $encoding = self::DEFAULT_ENCODING) { if (!is_string($separator) || $separator == '') { throw new \InvalidArgumentException("The \$separator parameter must be a non-empty string."); } $separated = preg_replace_callback( '/(^.[^A-Z]+$)|(^.+?(?=[A-Z]))|( +)(.+?)(?=[A-Z])|([A-Z]+(?=$|[A-Z][a-z])|[A-Z]?[a-z]+)/', function ($matches) use ($separator, $transform, $encoding) { $transformed = trim($matches[0]); $countMatches = count($matches); $transformed = (($countMatches == 5) ? $matches[3] : '') . $transformed; $transformed = (($countMatches == 6) ? $separator : '') . $transformed; return $transformed; }, $input ); // Run transform to the separated string $separated = static::separatedTransform($separated, $transform, $encoding); return $separated; }
[ "public", "static", "function", "separated", "(", "$", "input", ",", "$", "separator", "=", "'_'", ",", "$", "transform", "=", "null", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "if", "(", "!", "is_string", "(", "$", "separator", ")", "||", "$", "separator", "==", "''", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$separator parameter must be a non-empty string.\"", ")", ";", "}", "$", "separated", "=", "preg_replace_callback", "(", "'/(^.[^A-Z]+$)|(^.+?(?=[A-Z]))|( +)(.+?)(?=[A-Z])|([A-Z]+(?=$|[A-Z][a-z])|[A-Z]?[a-z]+)/'", ",", "function", "(", "$", "matches", ")", "use", "(", "$", "separator", ",", "$", "transform", ",", "$", "encoding", ")", "{", "$", "transformed", "=", "trim", "(", "$", "matches", "[", "0", "]", ")", ";", "$", "countMatches", "=", "count", "(", "$", "matches", ")", ";", "$", "transformed", "=", "(", "(", "$", "countMatches", "==", "5", ")", "?", "$", "matches", "[", "3", "]", ":", "''", ")", ".", "$", "transformed", ";", "$", "transformed", "=", "(", "(", "$", "countMatches", "==", "6", ")", "?", "$", "separator", ":", "''", ")", ".", "$", "transformed", ";", "return", "$", "transformed", ";", "}", ",", "$", "input", ")", ";", "// Run transform to the separated string", "$", "separated", "=", "static", "::", "separatedTransform", "(", "$", "separated", ",", "$", "transform", ",", "$", "encoding", ")", ";", "return", "$", "separated", ";", "}" ]
Converts a studly-caps-cased or camel-cased string into a char(s)-separated string using a given separator. Converts a studly-caps-cased or camel-cased string into a char(s)-separated string using a given separator. Additionally it can run one of the following transformation in every separated word (words are split by a space): 'lower', 'upper', 'lcfirst', 'ucfirst', 'ucwords' by using the $transform parameter (other values will be ignored and no transformation will be made thus returning the separated words unmodified). @param string $input The input string @param string $separator The separator to be used @param null|string $transform The transformation to be run for each word @param string $encoding The encoding of the input string @return string The char(s)-separated string @throws \InvalidArgumentException
[ "Converts", "a", "studly", "-", "caps", "-", "cased", "or", "camel", "-", "cased", "string", "into", "a", "char", "(", "s", ")", "-", "separated", "string", "using", "a", "given", "separator", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L794-L817
axelitus/php-base
src/Str.php
Str.separatedTransform
protected static function separatedTransform($input, $transform, $encoding = self::DEFAULT_ENCODING) { // Do lcfirst, ucfirst and ucwords transformations if (static::isOneOf($transform, ['lower', 'upper', 'lcfirst', 'ucfirst', 'ucwords'])) { $words = explode(' ', $input); Traverser::run( $words, function (&$word) use ($transform, $encoding) { // Simulate ucwords behaviour as mb_convert_case splits the word by the dash // and we want the space to be the only word separator. $word = ($transform == 'ucwords') ? static::ucfirst(static::lower($word, $encoding), $encoding) : call_user_func_array('static::' . $transform, [$word, $encoding]); } ); $input = implode(' ', $words); } return $input; }
php
protected static function separatedTransform($input, $transform, $encoding = self::DEFAULT_ENCODING) { // Do lcfirst, ucfirst and ucwords transformations if (static::isOneOf($transform, ['lower', 'upper', 'lcfirst', 'ucfirst', 'ucwords'])) { $words = explode(' ', $input); Traverser::run( $words, function (&$word) use ($transform, $encoding) { // Simulate ucwords behaviour as mb_convert_case splits the word by the dash // and we want the space to be the only word separator. $word = ($transform == 'ucwords') ? static::ucfirst(static::lower($word, $encoding), $encoding) : call_user_func_array('static::' . $transform, [$word, $encoding]); } ); $input = implode(' ', $words); } return $input; }
[ "protected", "static", "function", "separatedTransform", "(", "$", "input", ",", "$", "transform", ",", "$", "encoding", "=", "self", "::", "DEFAULT_ENCODING", ")", "{", "// Do lcfirst, ucfirst and ucwords transformations", "if", "(", "static", "::", "isOneOf", "(", "$", "transform", ",", "[", "'lower'", ",", "'upper'", ",", "'lcfirst'", ",", "'ucfirst'", ",", "'ucwords'", "]", ")", ")", "{", "$", "words", "=", "explode", "(", "' '", ",", "$", "input", ")", ";", "Traverser", "::", "run", "(", "$", "words", ",", "function", "(", "&", "$", "word", ")", "use", "(", "$", "transform", ",", "$", "encoding", ")", "{", "// Simulate ucwords behaviour as mb_convert_case splits the word by the dash", "// and we want the space to be the only word separator.", "$", "word", "=", "(", "$", "transform", "==", "'ucwords'", ")", "?", "static", "::", "ucfirst", "(", "static", "::", "lower", "(", "$", "word", ",", "$", "encoding", ")", ",", "$", "encoding", ")", ":", "call_user_func_array", "(", "'static::'", ".", "$", "transform", ",", "[", "$", "word", ",", "$", "encoding", "]", ")", ";", "}", ")", ";", "$", "input", "=", "implode", "(", "' '", ",", "$", "words", ")", ";", "}", "return", "$", "input", ";", "}" ]
Runs the transformation for the {@link separated} function. @param string $input The string to apply the transformation to. @param string $transform The transformation to apply (options:'lcfirst', 'ucfirst', 'ucwords'). @param string $encoding The encoding of the input string. @return string The transformed input string (or the input string as is).
[ "Runs", "the", "transformation", "for", "the", "{", "@link", "separated", "}", "function", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L828-L847