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
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
expectation-php/expect
src/matcher/ToBeAnInstanceOf.php
ToBeAnInstanceOf.reportNegativeFailed
public function reportNegativeFailed(FailedMessage $message) { $message->appendText('Expected ') ->appendText($this->className) ->appendText(' not to be an instance of ') ->appendText($this->expected) ->appendText("\n\n") ->appendText(' expected not: ') ->appendText($this->expected) ->appendText("\n") ->appendText(' got: ') ->appendText($this->className); }
php
public function reportNegativeFailed(FailedMessage $message) { $message->appendText('Expected ') ->appendText($this->className) ->appendText(' not to be an instance of ') ->appendText($this->expected) ->appendText("\n\n") ->appendText(' expected not: ') ->appendText($this->expected) ->appendText("\n") ->appendText(' got: ') ->appendText($this->className); }
[ "public", "function", "reportNegativeFailed", "(", "FailedMessage", "$", "message", ")", "{", "$", "message", "->", "appendText", "(", "'Expected '", ")", "->", "appendText", "(", "$", "this", "->", "className", ")", "->", "appendText", "(", "' not to be an instance of '", ")", "->", "appendText", "(", "$", "this", "->", "expected", ")", "->", "appendText", "(", "\"\\n\\n\"", ")", "->", "appendText", "(", "' expected not: '", ")", "->", "appendText", "(", "$", "this", "->", "expected", ")", "->", "appendText", "(", "\"\\n\"", ")", "->", "appendText", "(", "' got: '", ")", "->", "appendText", "(", "$", "this", "->", "className", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/matcher/ToBeAnInstanceOf.php#L93-L105
ShaoZeMing/laravel-merchant
src/Grid/Exporters/AbstractExporter.php
AbstractExporter.withScope
public function withScope($scope) { if ($scope == Grid\Exporter::SCOPE_ALL) { return $this; } list($scope, $args) = explode(':', $scope); if ($scope == Grid\Exporter::SCOPE_CURRENT_PAGE) { $this->grid->model()->usePaginate(true); } if ($scope == Grid\Exporter::SCOPE_SELECTED_ROWS) { $selected = explode(',', $args); $this->grid->model()->whereIn($this->grid->getKeyName(), $selected); } return $this; }
php
public function withScope($scope) { if ($scope == Grid\Exporter::SCOPE_ALL) { return $this; } list($scope, $args) = explode(':', $scope); if ($scope == Grid\Exporter::SCOPE_CURRENT_PAGE) { $this->grid->model()->usePaginate(true); } if ($scope == Grid\Exporter::SCOPE_SELECTED_ROWS) { $selected = explode(',', $args); $this->grid->model()->whereIn($this->grid->getKeyName(), $selected); } return $this; }
[ "public", "function", "withScope", "(", "$", "scope", ")", "{", "if", "(", "$", "scope", "==", "Grid", "\\", "Exporter", "::", "SCOPE_ALL", ")", "{", "return", "$", "this", ";", "}", "list", "(", "$", "scope", ",", "$", "args", ")", "=", "explode", "(", "':'", ",", "$", "scope", ")", ";", "if", "(", "$", "scope", "==", "Grid", "\\", "Exporter", "::", "SCOPE_CURRENT_PAGE", ")", "{", "$", "this", "->", "grid", "->", "model", "(", ")", "->", "usePaginate", "(", "true", ")", ";", "}", "if", "(", "$", "scope", "==", "Grid", "\\", "Exporter", "::", "SCOPE_SELECTED_ROWS", ")", "{", "$", "selected", "=", "explode", "(", "','", ",", "$", "args", ")", ";", "$", "this", "->", "grid", "->", "model", "(", ")", "->", "whereIn", "(", "$", "this", "->", "grid", "->", "getKeyName", "(", ")", ",", "$", "selected", ")", ";", "}", "return", "$", "this", ";", "}" ]
Export data with scope. @param string $scope @return $this
[ "Export", "data", "with", "scope", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Grid/Exporters/AbstractExporter.php#L78-L96
nguyenanhung/security
src/Encryption/AES.php
AES.encrypt
public function encrypt($plainText = '') { $cipher = new \phpseclib\Crypt\AES(); // could use AES::MODE_CBC // keys are null-padded to the closest valid size // longer than the longest key and it's truncated $cipher->setKeyLength($this->keyLength); $cipher->setKey($this->key); // $cipher->setPassword($this->key, 'pbkdf2', 'sha1', 'phpseclib/salt', 1000, 256 / 8); // the IV defaults to all-NULLs if not explicitly defined //$cipher->setIV('7014a0eb6d1611151a286c0ff4f2238f92c120d6'); return base64_encode($cipher->encrypt($plainText)); }
php
public function encrypt($plainText = '') { $cipher = new \phpseclib\Crypt\AES(); // could use AES::MODE_CBC // keys are null-padded to the closest valid size // longer than the longest key and it's truncated $cipher->setKeyLength($this->keyLength); $cipher->setKey($this->key); // $cipher->setPassword($this->key, 'pbkdf2', 'sha1', 'phpseclib/salt', 1000, 256 / 8); // the IV defaults to all-NULLs if not explicitly defined //$cipher->setIV('7014a0eb6d1611151a286c0ff4f2238f92c120d6'); return base64_encode($cipher->encrypt($plainText)); }
[ "public", "function", "encrypt", "(", "$", "plainText", "=", "''", ")", "{", "$", "cipher", "=", "new", "\\", "phpseclib", "\\", "Crypt", "\\", "AES", "(", ")", ";", "// could use AES::MODE_CBC", "// keys are null-padded to the closest valid size", "// longer than the longest key and it's truncated", "$", "cipher", "->", "setKeyLength", "(", "$", "this", "->", "keyLength", ")", ";", "$", "cipher", "->", "setKey", "(", "$", "this", "->", "key", ")", ";", "// $cipher->setPassword($this->key, 'pbkdf2', 'sha1', 'phpseclib/salt', 1000, 256 / 8);", "// the IV defaults to all-NULLs if not explicitly defined", "//$cipher->setIV('7014a0eb6d1611151a286c0ff4f2238f92c120d6');", "return", "base64_encode", "(", "$", "cipher", "->", "encrypt", "(", "$", "plainText", ")", ")", ";", "}" ]
Function encrypt @author: 713uk13m <[email protected]> @time : 2018-12-03 16:36 @param string $plainText @return string
[ "Function", "encrypt" ]
train
https://github.com/nguyenanhung/security/blob/a2c9bac66d3c2dad6d668ba6c2bd82ed04bffbd6/src/Encryption/AES.php#L103-L116
nguyenanhung/security
src/Encryption/AES.php
AES.decrypt
public function decrypt($cipherText = '') { $cipher = new \phpseclib\Crypt\AES(); // could use AES::MODE_CBC // keys are null-padded to the closest valid size // longer than the longest key and it's truncated $cipher->setKeyLength($this->keyLength); $cipher->setKey($this->key); // $cipher->setPassword($this->key, 'pbkdf2', 'sha1', 'phpseclib/salt', 1000, 256 / 8); // the IV defaults to all-NULLs if not explicitly defined //$cipher->setIV('7014a0eb6d1611151a286c0ff4f2238f92c120d6'); return $cipher->decrypt(base64_decode($cipherText)); }
php
public function decrypt($cipherText = '') { $cipher = new \phpseclib\Crypt\AES(); // could use AES::MODE_CBC // keys are null-padded to the closest valid size // longer than the longest key and it's truncated $cipher->setKeyLength($this->keyLength); $cipher->setKey($this->key); // $cipher->setPassword($this->key, 'pbkdf2', 'sha1', 'phpseclib/salt', 1000, 256 / 8); // the IV defaults to all-NULLs if not explicitly defined //$cipher->setIV('7014a0eb6d1611151a286c0ff4f2238f92c120d6'); return $cipher->decrypt(base64_decode($cipherText)); }
[ "public", "function", "decrypt", "(", "$", "cipherText", "=", "''", ")", "{", "$", "cipher", "=", "new", "\\", "phpseclib", "\\", "Crypt", "\\", "AES", "(", ")", ";", "// could use AES::MODE_CBC", "// keys are null-padded to the closest valid size", "// longer than the longest key and it's truncated", "$", "cipher", "->", "setKeyLength", "(", "$", "this", "->", "keyLength", ")", ";", "$", "cipher", "->", "setKey", "(", "$", "this", "->", "key", ")", ";", "// $cipher->setPassword($this->key, 'pbkdf2', 'sha1', 'phpseclib/salt', 1000, 256 / 8);", "// the IV defaults to all-NULLs if not explicitly defined", "//$cipher->setIV('7014a0eb6d1611151a286c0ff4f2238f92c120d6');", "return", "$", "cipher", "->", "decrypt", "(", "base64_decode", "(", "$", "cipherText", ")", ")", ";", "}" ]
Function decrypt @author: 713uk13m <[email protected]> @time : 2018-12-03 16:35 @param string $cipherText @return string
[ "Function", "decrypt" ]
train
https://github.com/nguyenanhung/security/blob/a2c9bac66d3c2dad6d668ba6c2bd82ed04bffbd6/src/Encryption/AES.php#L128-L141
php-lug/lug
src/Component/Translation/Repository/Doctrine/ORM/TranslatableRepositoryFactory.php
TranslatableRepositoryFactory.createResourceRepository
protected function createResourceRepository( $class, EntityManagerInterface $entityManager, ClassMetadata $metadata, ResourceInterface $resource = null ) { if ($resource !== null && is_a($class, TranslatableRepository::class, true)) { return new $class($entityManager, $metadata, $resource, $this->getLocaleContext()); } return parent::createResourceRepository($class, $entityManager, $metadata, $resource); }
php
protected function createResourceRepository( $class, EntityManagerInterface $entityManager, ClassMetadata $metadata, ResourceInterface $resource = null ) { if ($resource !== null && is_a($class, TranslatableRepository::class, true)) { return new $class($entityManager, $metadata, $resource, $this->getLocaleContext()); } return parent::createResourceRepository($class, $entityManager, $metadata, $resource); }
[ "protected", "function", "createResourceRepository", "(", "$", "class", ",", "EntityManagerInterface", "$", "entityManager", ",", "ClassMetadata", "$", "metadata", ",", "ResourceInterface", "$", "resource", "=", "null", ")", "{", "if", "(", "$", "resource", "!==", "null", "&&", "is_a", "(", "$", "class", ",", "TranslatableRepository", "::", "class", ",", "true", ")", ")", "{", "return", "new", "$", "class", "(", "$", "entityManager", ",", "$", "metadata", ",", "$", "resource", ",", "$", "this", "->", "getLocaleContext", "(", ")", ")", ";", "}", "return", "parent", "::", "createResourceRepository", "(", "$", "class", ",", "$", "entityManager", ",", "$", "metadata", ",", "$", "resource", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Translation/Repository/Doctrine/ORM/TranslatableRepositoryFactory.php#L44-L55
ZayconFoods/whatcounts
src/ZayconWhatCounts/SubscriberList.php
SubscriberList.setSentFlag
public function setSentFlag($sent_flag) { $this->sent_flag = ($sent_flag == 1 || $sent_flag == 'Y' || $sent_flag === TRUE) ? TRUE : FALSE; return $this; }
php
public function setSentFlag($sent_flag) { $this->sent_flag = ($sent_flag == 1 || $sent_flag == 'Y' || $sent_flag === TRUE) ? TRUE : FALSE; return $this; }
[ "public", "function", "setSentFlag", "(", "$", "sent_flag", ")", "{", "$", "this", "->", "sent_flag", "=", "(", "$", "sent_flag", "==", "1", "||", "$", "sent_flag", "==", "'Y'", "||", "$", "sent_flag", "===", "TRUE", ")", "?", "TRUE", ":", "FALSE", ";", "return", "$", "this", ";", "}" ]
@param mixed $sent_flag @return SubscriberList
[ "@param", "mixed", "$sent_flag" ]
train
https://github.com/ZayconFoods/whatcounts/blob/ff18491fc152571a72e4b558f8102f4fbb9bb7fd/src/ZayconWhatCounts/SubscriberList.php#L93-L98
caffeinated/beverage
src/Traits/NamespacedPackageTrait.php
NamespacedPackageTrait.isValidPackageName
protected function isValidPackageName($packageName) { if (! preg_match($this->getNamespacedPackageRegex(), $packageName, $matches) or count($matches) !== 3) { return false; } return true; }
php
protected function isValidPackageName($packageName) { if (! preg_match($this->getNamespacedPackageRegex(), $packageName, $matches) or count($matches) !== 3) { return false; } return true; }
[ "protected", "function", "isValidPackageName", "(", "$", "packageName", ")", "{", "if", "(", "!", "preg_match", "(", "$", "this", "->", "getNamespacedPackageRegex", "(", ")", ",", "$", "packageName", ",", "$", "matches", ")", "or", "count", "(", "$", "matches", ")", "!==", "3", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks if the given $packageName is valid @param $packageName @return bool
[ "Checks", "if", "the", "given", "$packageName", "is", "valid" ]
train
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Traits/NamespacedPackageTrait.php#L38-L45
NuclearCMS/Hierarchy
src/Repositories/NodeTypeRepository.php
NodeTypeRepository.create
public function create(array $attributes) { $model = $this->getModelName(); $nodeType = $model::create($attributes); $this->builderService->buildTable( $nodeType->getName(), $nodeType->getKey() ); return $nodeType; }
php
public function create(array $attributes) { $model = $this->getModelName(); $nodeType = $model::create($attributes); $this->builderService->buildTable( $nodeType->getName(), $nodeType->getKey() ); return $nodeType; }
[ "public", "function", "create", "(", "array", "$", "attributes", ")", "{", "$", "model", "=", "$", "this", "->", "getModelName", "(", ")", ";", "$", "nodeType", "=", "$", "model", "::", "create", "(", "$", "attributes", ")", ";", "$", "this", "->", "builderService", "->", "buildTable", "(", "$", "nodeType", "->", "getName", "(", ")", ",", "$", "nodeType", "->", "getKey", "(", ")", ")", ";", "return", "$", "nodeType", ";", "}" ]
Creates a node type @param array $attributes @return NodeTypeContract
[ "Creates", "a", "node", "type" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Repositories/NodeTypeRepository.php#L14-L26
NuclearCMS/Hierarchy
src/Repositories/NodeTypeRepository.php
NodeTypeRepository.destroy
public function destroy($id) { $model = $this->getModelName(); $nodeType = $model::findOrFail($id); $this->builderService->destroyTable( $nodeType->getName(), $nodeType->getFieldKeys(), $nodeType->getKey() ); $nodeType->delete(); return $nodeType; }
php
public function destroy($id) { $model = $this->getModelName(); $nodeType = $model::findOrFail($id); $this->builderService->destroyTable( $nodeType->getName(), $nodeType->getFieldKeys(), $nodeType->getKey() ); $nodeType->delete(); return $nodeType; }
[ "public", "function", "destroy", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "getModelName", "(", ")", ";", "$", "nodeType", "=", "$", "model", "::", "findOrFail", "(", "$", "id", ")", ";", "$", "this", "->", "builderService", "->", "destroyTable", "(", "$", "nodeType", "->", "getName", "(", ")", ",", "$", "nodeType", "->", "getFieldKeys", "(", ")", ",", "$", "nodeType", "->", "getKey", "(", ")", ")", ";", "$", "nodeType", "->", "delete", "(", ")", ";", "return", "$", "nodeType", ";", "}" ]
Destroys a node type @param int $id @return NodeTypeContract
[ "Destroys", "a", "node", "type" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Repositories/NodeTypeRepository.php#L34-L49
NuclearCMS/Hierarchy
src/Repositories/NodeTypeRepository.php
NodeTypeRepository.getNodeTypesByIds
public function getNodeTypesByIds($ids) { if (empty($ids)) { return null; } if (is_string($ids)) { $ids = json_decode($ids, true); } if (is_array($ids) && ! empty($ids)) { $model = $this->getModelName(); $placeholders = implode(',', array_fill(0, count($ids), '?')); $nodeTypes = $model::whereIn('id', $ids) ->orderByRaw('field(id,' . $placeholders . ')', $ids) ->get(); return (count($nodeTypes) > 0) ? $nodeTypes : null; } return null; }
php
public function getNodeTypesByIds($ids) { if (empty($ids)) { return null; } if (is_string($ids)) { $ids = json_decode($ids, true); } if (is_array($ids) && ! empty($ids)) { $model = $this->getModelName(); $placeholders = implode(',', array_fill(0, count($ids), '?')); $nodeTypes = $model::whereIn('id', $ids) ->orderByRaw('field(id,' . $placeholders . ')', $ids) ->get(); return (count($nodeTypes) > 0) ? $nodeTypes : null; } return null; }
[ "public", "function", "getNodeTypesByIds", "(", "$", "ids", ")", "{", "if", "(", "empty", "(", "$", "ids", ")", ")", "{", "return", "null", ";", "}", "if", "(", "is_string", "(", "$", "ids", ")", ")", "{", "$", "ids", "=", "json_decode", "(", "$", "ids", ",", "true", ")", ";", "}", "if", "(", "is_array", "(", "$", "ids", ")", "&&", "!", "empty", "(", "$", "ids", ")", ")", "{", "$", "model", "=", "$", "this", "->", "getModelName", "(", ")", ";", "$", "placeholders", "=", "implode", "(", "','", ",", "array_fill", "(", "0", ",", "count", "(", "$", "ids", ")", ",", "'?'", ")", ")", ";", "$", "nodeTypes", "=", "$", "model", "::", "whereIn", "(", "'id'", ",", "$", "ids", ")", "->", "orderByRaw", "(", "'field(id,'", ".", "$", "placeholders", ".", "')'", ",", "$", "ids", ")", "->", "get", "(", ")", ";", "return", "(", "count", "(", "$", "nodeTypes", ")", ">", "0", ")", "?", "$", "nodeTypes", ":", "null", ";", "}", "return", "null", ";", "}" ]
Returns node types by ids @param array|string $ids @return Collection
[ "Returns", "node", "types", "by", "ids" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Repositories/NodeTypeRepository.php#L57-L83
Danzabar/config-builder
src/Data/Extensions/YamlTranslator.php
YamlTranslator.validate
public function validate() { try { Yaml\Yaml::parse($this->data); } catch(\Exception $e) { return false; } return true; }
php
public function validate() { try { Yaml\Yaml::parse($this->data); } catch(\Exception $e) { return false; } return true; }
[ "public", "function", "validate", "(", ")", "{", "try", "{", "Yaml", "\\", "Yaml", "::", "parse", "(", "$", "this", "->", "data", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Validates a Yaml string @return Boolean @author Dan Cox
[ "Validates", "a", "Yaml", "string" ]
train
https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Data/Extensions/YamlTranslator.php#L65-L77
CupOfTea696/WordPress-Composer
src/EventSubscriber.php
EventSubscriber.getSubscribedEvents
public static function getSubscribedEvents() { return [ ScriptEvents::PRE_INSTALL_CMD => 'configureComposerJson', ScriptEvents::PRE_UPDATE_CMD => 'configureComposerJson', PackageEvents::PRE_PACKAGE_INSTALL => 'setWordPressInstallDirectory', PackageEvents::POST_PACKAGE_INSTALL => ['cleanWordPressInstallation', 'activateWordPressPlugin'], PackageEvents::POST_PACKAGE_UPDATE => 'cleanWordPressInstallation', PackageEvents::PRE_PACKAGE_UNINSTALL => ['deactivateWordPressPlugin', 'uninstallWordPressPlugin'], ]; }
php
public static function getSubscribedEvents() { return [ ScriptEvents::PRE_INSTALL_CMD => 'configureComposerJson', ScriptEvents::PRE_UPDATE_CMD => 'configureComposerJson', PackageEvents::PRE_PACKAGE_INSTALL => 'setWordPressInstallDirectory', PackageEvents::POST_PACKAGE_INSTALL => ['cleanWordPressInstallation', 'activateWordPressPlugin'], PackageEvents::POST_PACKAGE_UPDATE => 'cleanWordPressInstallation', PackageEvents::PRE_PACKAGE_UNINSTALL => ['deactivateWordPressPlugin', 'uninstallWordPressPlugin'], ]; }
[ "public", "static", "function", "getSubscribedEvents", "(", ")", "{", "return", "[", "ScriptEvents", "::", "PRE_INSTALL_CMD", "=>", "'configureComposerJson'", ",", "ScriptEvents", "::", "PRE_UPDATE_CMD", "=>", "'configureComposerJson'", ",", "PackageEvents", "::", "PRE_PACKAGE_INSTALL", "=>", "'setWordPressInstallDirectory'", ",", "PackageEvents", "::", "POST_PACKAGE_INSTALL", "=>", "[", "'cleanWordPressInstallation'", ",", "'activateWordPressPlugin'", "]", ",", "PackageEvents", "::", "POST_PACKAGE_UPDATE", "=>", "'cleanWordPressInstallation'", ",", "PackageEvents", "::", "PRE_PACKAGE_UNINSTALL", "=>", "[", "'deactivateWordPressPlugin'", ",", "'uninstallWordPressPlugin'", "]", ",", "]", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/EventSubscriber.php#L42-L52
CupOfTea696/WordPress-Composer
src/EventSubscriber.php
EventSubscriber.configureComposerJson
public function configureComposerJson(Event $event) { static::$plugin->getInstanceOf(ComposerConfigurator::class)->configure($event->getComposer(), $event->getIO()); }
php
public function configureComposerJson(Event $event) { static::$plugin->getInstanceOf(ComposerConfigurator::class)->configure($event->getComposer(), $event->getIO()); }
[ "public", "function", "configureComposerJson", "(", "Event", "$", "event", ")", "{", "static", "::", "$", "plugin", "->", "getInstanceOf", "(", "ComposerConfigurator", "::", "class", ")", "->", "configure", "(", "$", "event", "->", "getComposer", "(", ")", ",", "$", "event", "->", "getIO", "(", ")", ")", ";", "}" ]
Configure the composer sonfiguration file. @param \Composer\EventDispatcher\Event $event @return void
[ "Configure", "the", "composer", "sonfiguration", "file", "." ]
train
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/EventSubscriber.php#L85-L88
CupOfTea696/WordPress-Composer
src/EventSubscriber.php
EventSubscriber.setWordPressInstallDirectory
public function setWordPressInstallDirectory(PackageEvent $event) { if ($this->getPackageName($event) != 'johnpbloch/wordpress') { return; } $composer = $event->getComposer(); $rootPkg = $composer->getPackage(); if (! $rootPkg) { return; } $extra = $rootPkg->getExtra(); if (isset($extra['wordpress-install-dir']) && $extra['wordpress-install-dir']) { return; } $extra['wordpress-install-dir'] = static::$plugin->getPublicDirectory() . '/wp'; $rootPkg->setExtra($extra); $composer->setPackage($rootPkg); }
php
public function setWordPressInstallDirectory(PackageEvent $event) { if ($this->getPackageName($event) != 'johnpbloch/wordpress') { return; } $composer = $event->getComposer(); $rootPkg = $composer->getPackage(); if (! $rootPkg) { return; } $extra = $rootPkg->getExtra(); if (isset($extra['wordpress-install-dir']) && $extra['wordpress-install-dir']) { return; } $extra['wordpress-install-dir'] = static::$plugin->getPublicDirectory() . '/wp'; $rootPkg->setExtra($extra); $composer->setPackage($rootPkg); }
[ "public", "function", "setWordPressInstallDirectory", "(", "PackageEvent", "$", "event", ")", "{", "if", "(", "$", "this", "->", "getPackageName", "(", "$", "event", ")", "!=", "'johnpbloch/wordpress'", ")", "{", "return", ";", "}", "$", "composer", "=", "$", "event", "->", "getComposer", "(", ")", ";", "$", "rootPkg", "=", "$", "composer", "->", "getPackage", "(", ")", ";", "if", "(", "!", "$", "rootPkg", ")", "{", "return", ";", "}", "$", "extra", "=", "$", "rootPkg", "->", "getExtra", "(", ")", ";", "if", "(", "isset", "(", "$", "extra", "[", "'wordpress-install-dir'", "]", ")", "&&", "$", "extra", "[", "'wordpress-install-dir'", "]", ")", "{", "return", ";", "}", "$", "extra", "[", "'wordpress-install-dir'", "]", "=", "static", "::", "$", "plugin", "->", "getPublicDirectory", "(", ")", ".", "'/wp'", ";", "$", "rootPkg", "->", "setExtra", "(", "$", "extra", ")", ";", "$", "composer", "->", "setPackage", "(", "$", "rootPkg", ")", ";", "}" ]
Set the WordPress installation directory. @param \Composer\EventDispatcher\Event $event @return void
[ "Set", "the", "WordPress", "installation", "directory", "." ]
train
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/EventSubscriber.php#L96-L119
CupOfTea696/WordPress-Composer
src/EventSubscriber.php
EventSubscriber.cleanWordPressInstallation
public function cleanWordPressInstallation(PackageEvent $event) { if ($this->getPackageName($event) != 'johnpbloch/wordpress') { return; } static::$plugin->getInstanceOf(WordPressInstallationCleaner::class)->clean($event->getComposer(), $event->getIO()); }
php
public function cleanWordPressInstallation(PackageEvent $event) { if ($this->getPackageName($event) != 'johnpbloch/wordpress') { return; } static::$plugin->getInstanceOf(WordPressInstallationCleaner::class)->clean($event->getComposer(), $event->getIO()); }
[ "public", "function", "cleanWordPressInstallation", "(", "PackageEvent", "$", "event", ")", "{", "if", "(", "$", "this", "->", "getPackageName", "(", "$", "event", ")", "!=", "'johnpbloch/wordpress'", ")", "{", "return", ";", "}", "static", "::", "$", "plugin", "->", "getInstanceOf", "(", "WordPressInstallationCleaner", "::", "class", ")", "->", "clean", "(", "$", "event", "->", "getComposer", "(", ")", ",", "$", "event", "->", "getIO", "(", ")", ")", ";", "}" ]
Clean the WordPress installation. @param \Composer\Installer\PackageEvent $event @return void
[ "Clean", "the", "WordPress", "installation", "." ]
train
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/EventSubscriber.php#L127-L134
CupOfTea696/WordPress-Composer
src/EventSubscriber.php
EventSubscriber.activateWordPressPlugin
public function activateWordPressPlugin(PackageEvent $event) { if (! $this->isWordPressPlugin($this->getPackage($event))) { return; } static::$plugin->getInstanceOf(PluginInteractor::class)->activate( $event->getComposer(), $event->getIO(), preg_replace('/^wpackagist-plugin\//', '', $this->getPackageName($event)) ); }
php
public function activateWordPressPlugin(PackageEvent $event) { if (! $this->isWordPressPlugin($this->getPackage($event))) { return; } static::$plugin->getInstanceOf(PluginInteractor::class)->activate( $event->getComposer(), $event->getIO(), preg_replace('/^wpackagist-plugin\//', '', $this->getPackageName($event)) ); }
[ "public", "function", "activateWordPressPlugin", "(", "PackageEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "isWordPressPlugin", "(", "$", "this", "->", "getPackage", "(", "$", "event", ")", ")", ")", "{", "return", ";", "}", "static", "::", "$", "plugin", "->", "getInstanceOf", "(", "PluginInteractor", "::", "class", ")", "->", "activate", "(", "$", "event", "->", "getComposer", "(", ")", ",", "$", "event", "->", "getIO", "(", ")", ",", "preg_replace", "(", "'/^wpackagist-plugin\\//'", ",", "''", ",", "$", "this", "->", "getPackageName", "(", "$", "event", ")", ")", ")", ";", "}" ]
Activate a WordPress plugin. @param \Composer\Installer\PackageEvent $event @return void
[ "Activate", "a", "WordPress", "plugin", "." ]
train
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/EventSubscriber.php#L142-L153
CupOfTea696/WordPress-Composer
src/EventSubscriber.php
EventSubscriber.deactivateWordPressPlugin
public function deactivateWordPressPlugin(PackageEvent $event) { if (! $this->isWordPressPlugin($this->getPackage($event))) { return; } static::$plugin->getInstanceOf(PluginInteractor::class)->deactivate( $event->getComposer(), $event->getIO(), preg_replace('/^wpackagist-plugin\//', '', $this->getPackageName($event)) ); }
php
public function deactivateWordPressPlugin(PackageEvent $event) { if (! $this->isWordPressPlugin($this->getPackage($event))) { return; } static::$plugin->getInstanceOf(PluginInteractor::class)->deactivate( $event->getComposer(), $event->getIO(), preg_replace('/^wpackagist-plugin\//', '', $this->getPackageName($event)) ); }
[ "public", "function", "deactivateWordPressPlugin", "(", "PackageEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "isWordPressPlugin", "(", "$", "this", "->", "getPackage", "(", "$", "event", ")", ")", ")", "{", "return", ";", "}", "static", "::", "$", "plugin", "->", "getInstanceOf", "(", "PluginInteractor", "::", "class", ")", "->", "deactivate", "(", "$", "event", "->", "getComposer", "(", ")", ",", "$", "event", "->", "getIO", "(", ")", ",", "preg_replace", "(", "'/^wpackagist-plugin\\//'", ",", "''", ",", "$", "this", "->", "getPackageName", "(", "$", "event", ")", ")", ")", ";", "}" ]
Deactivate a WordPress plugin. @param \Composer\Installer\PackageEvent $event @return void
[ "Deactivate", "a", "WordPress", "plugin", "." ]
train
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/EventSubscriber.php#L161-L172
CupOfTea696/WordPress-Composer
src/EventSubscriber.php
EventSubscriber.uninstallWordPressPlugin
public function uninstallWordPressPlugin(PackageEvent $event) { if (! $this->isWordPressPlugin($this->getPackage($event))) { return; } static::$plugin->getInstanceOf(PluginInteractor::class)->uninstall( $event->getComposer(), $event->getIO(), preg_replace('/^wpackagist-plugin\//', '', $this->getPackageName($event)) ); }
php
public function uninstallWordPressPlugin(PackageEvent $event) { if (! $this->isWordPressPlugin($this->getPackage($event))) { return; } static::$plugin->getInstanceOf(PluginInteractor::class)->uninstall( $event->getComposer(), $event->getIO(), preg_replace('/^wpackagist-plugin\//', '', $this->getPackageName($event)) ); }
[ "public", "function", "uninstallWordPressPlugin", "(", "PackageEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "isWordPressPlugin", "(", "$", "this", "->", "getPackage", "(", "$", "event", ")", ")", ")", "{", "return", ";", "}", "static", "::", "$", "plugin", "->", "getInstanceOf", "(", "PluginInteractor", "::", "class", ")", "->", "uninstall", "(", "$", "event", "->", "getComposer", "(", ")", ",", "$", "event", "->", "getIO", "(", ")", ",", "preg_replace", "(", "'/^wpackagist-plugin\\//'", ",", "''", ",", "$", "this", "->", "getPackageName", "(", "$", "event", ")", ")", ")", ";", "}" ]
Uninstall a WordPress plugin. @param \Composer\Installer\PackageEvent $event @return void
[ "Uninstall", "a", "WordPress", "plugin", "." ]
train
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/EventSubscriber.php#L180-L191
CupOfTea696/WordPress-Composer
src/EventSubscriber.php
EventSubscriber.getPackage
protected function getPackage(PackageEvent $event) { $operation = $event->getOperation(); if (method_exists($operation, 'getPackage')) { return $operation->getPackage(); } return $operation->getTargetPackage(); }
php
protected function getPackage(PackageEvent $event) { $operation = $event->getOperation(); if (method_exists($operation, 'getPackage')) { return $operation->getPackage(); } return $operation->getTargetPackage(); }
[ "protected", "function", "getPackage", "(", "PackageEvent", "$", "event", ")", "{", "$", "operation", "=", "$", "event", "->", "getOperation", "(", ")", ";", "if", "(", "method_exists", "(", "$", "operation", ",", "'getPackage'", ")", ")", "{", "return", "$", "operation", "->", "getPackage", "(", ")", ";", "}", "return", "$", "operation", "->", "getTargetPackage", "(", ")", ";", "}" ]
Get the PackageInterface from a PackageEvent. @param \Composer\Installer\PackageEvent $event @return \Composer\Package\PackageInterface
[ "Get", "the", "PackageInterface", "from", "a", "PackageEvent", "." ]
train
https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/EventSubscriber.php#L199-L208
novaway/open-graph
src/Metadata/Driver/AnnotationDriver.php
AnnotationDriver.loadMetadataForClass
public function loadMetadataForClass(\ReflectionClass $class) { $classMetadata = new ClassMetadata($class->name); $classMetadata->fileResources[] = $class->getFileName(); foreach ($this->reader->getClassAnnotations($class) as $annotation) { if ($annotation instanceof NamespaceNode) { $classMetadata->addGraphNamespace($annotation); } if ($annotation instanceof GraphNode) { $classMetadata->addGraphMetadata($annotation, new MetadataValue($annotation->value)); } } foreach ($class->getProperties() as $property) { foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { if ($annotation instanceof GraphNode) { $classMetadata->addGraphMetadata($annotation, new PropertyMetadata($class->name, $property->name)); } } } foreach ($class->getMethods() as $method) { foreach ($this->reader->getMethodAnnotations($method) as $annotation) { if ($annotation instanceof GraphNode) { $classMetadata->addGraphMetadata($annotation, new MethodMetadata($class->name, $method->name)); } } } return $classMetadata; }
php
public function loadMetadataForClass(\ReflectionClass $class) { $classMetadata = new ClassMetadata($class->name); $classMetadata->fileResources[] = $class->getFileName(); foreach ($this->reader->getClassAnnotations($class) as $annotation) { if ($annotation instanceof NamespaceNode) { $classMetadata->addGraphNamespace($annotation); } if ($annotation instanceof GraphNode) { $classMetadata->addGraphMetadata($annotation, new MetadataValue($annotation->value)); } } foreach ($class->getProperties() as $property) { foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { if ($annotation instanceof GraphNode) { $classMetadata->addGraphMetadata($annotation, new PropertyMetadata($class->name, $property->name)); } } } foreach ($class->getMethods() as $method) { foreach ($this->reader->getMethodAnnotations($method) as $annotation) { if ($annotation instanceof GraphNode) { $classMetadata->addGraphMetadata($annotation, new MethodMetadata($class->name, $method->name)); } } } return $classMetadata; }
[ "public", "function", "loadMetadataForClass", "(", "\\", "ReflectionClass", "$", "class", ")", "{", "$", "classMetadata", "=", "new", "ClassMetadata", "(", "$", "class", "->", "name", ")", ";", "$", "classMetadata", "->", "fileResources", "[", "]", "=", "$", "class", "->", "getFileName", "(", ")", ";", "foreach", "(", "$", "this", "->", "reader", "->", "getClassAnnotations", "(", "$", "class", ")", "as", "$", "annotation", ")", "{", "if", "(", "$", "annotation", "instanceof", "NamespaceNode", ")", "{", "$", "classMetadata", "->", "addGraphNamespace", "(", "$", "annotation", ")", ";", "}", "if", "(", "$", "annotation", "instanceof", "GraphNode", ")", "{", "$", "classMetadata", "->", "addGraphMetadata", "(", "$", "annotation", ",", "new", "MetadataValue", "(", "$", "annotation", "->", "value", ")", ")", ";", "}", "}", "foreach", "(", "$", "class", "->", "getProperties", "(", ")", "as", "$", "property", ")", "{", "foreach", "(", "$", "this", "->", "reader", "->", "getPropertyAnnotations", "(", "$", "property", ")", "as", "$", "annotation", ")", "{", "if", "(", "$", "annotation", "instanceof", "GraphNode", ")", "{", "$", "classMetadata", "->", "addGraphMetadata", "(", "$", "annotation", ",", "new", "PropertyMetadata", "(", "$", "class", "->", "name", ",", "$", "property", "->", "name", ")", ")", ";", "}", "}", "}", "foreach", "(", "$", "class", "->", "getMethods", "(", ")", "as", "$", "method", ")", "{", "foreach", "(", "$", "this", "->", "reader", "->", "getMethodAnnotations", "(", "$", "method", ")", "as", "$", "annotation", ")", "{", "if", "(", "$", "annotation", "instanceof", "GraphNode", ")", "{", "$", "classMetadata", "->", "addGraphMetadata", "(", "$", "annotation", ",", "new", "MethodMetadata", "(", "$", "class", "->", "name", ",", "$", "method", "->", "name", ")", ")", ";", "}", "}", "}", "return", "$", "classMetadata", ";", "}" ]
Load metadata class @param \ReflectionClass $class @return ClassMetadata
[ "Load", "metadata", "class" ]
train
https://github.com/novaway/open-graph/blob/19817bee4b91cf26ca3fe44883ad58b32328e464/src/Metadata/Driver/AnnotationDriver.php#L36-L68
heidelpay/PhpDoc
src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php
ElementsIndexBuilder.getIndexKey
protected function getIndexKey($element) { $key = $element->getFullyQualifiedStructuralElementName(); // properties should have an additional $ before the property name if ($element instanceof PropertyInterface) { list($fqcn, $propertyName) = explode('::', $key); $key = $fqcn . '::$' . $propertyName; } return $key; }
php
protected function getIndexKey($element) { $key = $element->getFullyQualifiedStructuralElementName(); // properties should have an additional $ before the property name if ($element instanceof PropertyInterface) { list($fqcn, $propertyName) = explode('::', $key); $key = $fqcn . '::$' . $propertyName; } return $key; }
[ "protected", "function", "getIndexKey", "(", "$", "element", ")", "{", "$", "key", "=", "$", "element", "->", "getFullyQualifiedStructuralElementName", "(", ")", ";", "// properties should have an additional $ before the property name", "if", "(", "$", "element", "instanceof", "PropertyInterface", ")", "{", "list", "(", "$", "fqcn", ",", "$", "propertyName", ")", "=", "explode", "(", "'::'", ",", "$", "key", ")", ";", "$", "key", "=", "$", "fqcn", ".", "'::$'", ".", "$", "propertyName", ";", "}", "return", "$", "key", ";", "}" ]
Retrieves a key for the index for the provided element. @param DescriptorAbstract $element @return string
[ "Retrieves", "a", "key", "for", "the", "index", "for", "the", "provided", "element", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php#L146-L157
heidelpay/PhpDoc
src/phpDocumentor/Partials/Collection.php
Collection.set
public function set($index, $item) { $this->offsetSet($index, $this->parser->text($item)); }
php
public function set($index, $item) { $this->offsetSet($index, $this->parser->text($item)); }
[ "public", "function", "set", "(", "$", "index", ",", "$", "item", ")", "{", "$", "this", "->", "offsetSet", "(", "$", "index", ",", "$", "this", "->", "parser", "->", "text", "(", "$", "item", ")", ")", ";", "}" ]
Sets a new object onto the collection or clear it using null. @param string|integer $index An index value to recognize this item with. @param string $item The item to store, generally a Descriptor but may be something else. @return void
[ "Sets", "a", "new", "object", "onto", "the", "collection", "or", "clear", "it", "using", "null", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Partials/Collection.php#L42-L45
chrismou/phergie-irc-plugin-react-google
src/Provider/GoogleSearchCount.php
GoogleSearchCount.getSuccessLines
public function getSuccessLines(Event $event, $apiResponse) { $json = json_decode($apiResponse); $json = $json->responseData; $messages = []; $messages[] = sprintf( "%s results [ %s ]", (isset($json->cursor->estimatedResultCount)) ? $json->cursor->estimatedResultCount : "0", $json->cursor->moreResultsUrl ); return $messages; }
php
public function getSuccessLines(Event $event, $apiResponse) { $json = json_decode($apiResponse); $json = $json->responseData; $messages = []; $messages[] = sprintf( "%s results [ %s ]", (isset($json->cursor->estimatedResultCount)) ? $json->cursor->estimatedResultCount : "0", $json->cursor->moreResultsUrl ); return $messages; }
[ "public", "function", "getSuccessLines", "(", "Event", "$", "event", ",", "$", "apiResponse", ")", "{", "$", "json", "=", "json_decode", "(", "$", "apiResponse", ")", ";", "$", "json", "=", "$", "json", "->", "responseData", ";", "$", "messages", "=", "[", "]", ";", "$", "messages", "[", "]", "=", "sprintf", "(", "\"%s results [ %s ]\"", ",", "(", "isset", "(", "$", "json", "->", "cursor", "->", "estimatedResultCount", ")", ")", "?", "$", "json", "->", "cursor", "->", "estimatedResultCount", ":", "\"0\"", ",", "$", "json", "->", "cursor", "->", "moreResultsUrl", ")", ";", "return", "$", "messages", ";", "}" ]
Process the response (when the request is successful) @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event @param string $apiResponse @return array
[ "Process", "the", "response", "(", "when", "the", "request", "is", "successful", ")" ]
train
https://github.com/chrismou/phergie-irc-plugin-react-google/blob/4492bf1e25826a9cf7187afee0ec35deddefaf6f/src/Provider/GoogleSearchCount.php#L31-L45
superjimpupcake/Pupcake
src/Pupcake/Event.php
Event.register
public function register() { $this->helper_callbacks = array(); $arguments= func_get_args(); if(count($arguments) > 0){ foreach($arguments as $argument){ if($argument instanceof Plugin){ //this is a plugin object $callback = $argument->getEventHelperCallback($this->getName()); if(is_callable($callback)){ $this->helper_callbacks[] = $callback; } } else if(is_callable($argument)){ //this is a closure $this->helper_callbacks[] = $argument; } } } return $this; //return the event object reference to allow chainable calls }
php
public function register() { $this->helper_callbacks = array(); $arguments= func_get_args(); if(count($arguments) > 0){ foreach($arguments as $argument){ if($argument instanceof Plugin){ //this is a plugin object $callback = $argument->getEventHelperCallback($this->getName()); if(is_callable($callback)){ $this->helper_callbacks[] = $callback; } } else if(is_callable($argument)){ //this is a closure $this->helper_callbacks[] = $argument; } } } return $this; //return the event object reference to allow chainable calls }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "helper_callbacks", "=", "array", "(", ")", ";", "$", "arguments", "=", "func_get_args", "(", ")", ";", "if", "(", "count", "(", "$", "arguments", ")", ">", "0", ")", "{", "foreach", "(", "$", "arguments", "as", "$", "argument", ")", "{", "if", "(", "$", "argument", "instanceof", "Plugin", ")", "{", "//this is a plugin object", "$", "callback", "=", "$", "argument", "->", "getEventHelperCallback", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "if", "(", "is_callable", "(", "$", "callback", ")", ")", "{", "$", "this", "->", "helper_callbacks", "[", "]", "=", "$", "callback", ";", "}", "}", "else", "if", "(", "is_callable", "(", "$", "argument", ")", ")", "{", "//this is a closure", "$", "this", "->", "helper_callbacks", "[", "]", "=", "$", "argument", ";", "}", "}", "}", "return", "$", "this", ";", "//return the event object reference to allow chainable calls", "}" ]
register an array of plugins objects and allow the plugins to join the process of handling this event
[ "register", "an", "array", "of", "plugins", "objects", "and", "allow", "the", "plugins", "to", "join", "the", "process", "of", "handling", "this", "event" ]
train
https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Event.php#L76-L95
superjimpupcake/Pupcake
src/Pupcake/Event.php
Event.start
public function start() { $result = array(); if(count($this->helper_callbacks) > 0){ foreach($this->helper_callbacks as $callback){ $return_value = call_user_func_array($callback, array($this)); $result[] = $return_value; } } return $result; }
php
public function start() { $result = array(); if(count($this->helper_callbacks) > 0){ foreach($this->helper_callbacks as $callback){ $return_value = call_user_func_array($callback, array($this)); $result[] = $return_value; } } return $result; }
[ "public", "function", "start", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "if", "(", "count", "(", "$", "this", "->", "helper_callbacks", ")", ">", "0", ")", "{", "foreach", "(", "$", "this", "->", "helper_callbacks", "as", "$", "callback", ")", "{", "$", "return_value", "=", "call_user_func_array", "(", "$", "callback", ",", "array", "(", "$", "this", ")", ")", ";", "$", "result", "[", "]", "=", "$", "return_value", ";", "}", "}", "return", "$", "result", ";", "}" ]
start this event
[ "start", "this", "event" ]
train
https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Event.php#L118-L128
prooph/link-dashboard
src/Service/Factory/DashboardProviderFactory.php
DashboardProviderFactory.createService
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('config'); $controllerLoader = $serviceLocator->get('ControllerLoader'); /** @var $systemConfig ProcessingConfig */ $systemConfig = $serviceLocator->get('prooph.link.system_config'); if ($serviceLocator->has('prooph.link.dashboard.widget_blacklist')) { $blacklist = $serviceLocator->get('prooph.link.dashboard.widget_blacklist'); if (! $blacklist instanceof WidgetBlacklist) { throw new \RuntimeException("Widget blacklist should implement " . WidgetBlacklist::class . ". Got " . (is_object($blacklist))? get_class($blacklist) : gettype($blacklist)); } } $controllers = []; $sortArr = []; if ($systemConfig->isConfigured()) { foreach ($config['prooph.link.dashboard'] as $widgetName => $widgetConfig) { if (isset($blacklist)) { if ($blacklist->isWidgetOnList($widgetName)) { continue; } } if (! array_key_exists('controller', $widgetConfig)) { throw new \RuntimeException('controller key missing in widget config: ' . $widgetName); } $sortArr[$widgetName] = (isset($widgetConfig['order']))? (int)$widgetConfig['order'] : 0; } asort($sortArr); } else { $sortArr['system_config_widget'] = 1; } foreach ($sortArr as $widgetName => $order) { $controller = $controllerLoader->get($config['prooph.link.dashboard'][$widgetName]['controller']); $controller->setWidgetConfig(new WidgetConfig($config['prooph.link.dashboard'][$widgetName])); $controllers[] = $controller; } return new DashboardProvider($controllers); }
php
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('config'); $controllerLoader = $serviceLocator->get('ControllerLoader'); /** @var $systemConfig ProcessingConfig */ $systemConfig = $serviceLocator->get('prooph.link.system_config'); if ($serviceLocator->has('prooph.link.dashboard.widget_blacklist')) { $blacklist = $serviceLocator->get('prooph.link.dashboard.widget_blacklist'); if (! $blacklist instanceof WidgetBlacklist) { throw new \RuntimeException("Widget blacklist should implement " . WidgetBlacklist::class . ". Got " . (is_object($blacklist))? get_class($blacklist) : gettype($blacklist)); } } $controllers = []; $sortArr = []; if ($systemConfig->isConfigured()) { foreach ($config['prooph.link.dashboard'] as $widgetName => $widgetConfig) { if (isset($blacklist)) { if ($blacklist->isWidgetOnList($widgetName)) { continue; } } if (! array_key_exists('controller', $widgetConfig)) { throw new \RuntimeException('controller key missing in widget config: ' . $widgetName); } $sortArr[$widgetName] = (isset($widgetConfig['order']))? (int)$widgetConfig['order'] : 0; } asort($sortArr); } else { $sortArr['system_config_widget'] = 1; } foreach ($sortArr as $widgetName => $order) { $controller = $controllerLoader->get($config['prooph.link.dashboard'][$widgetName]['controller']); $controller->setWidgetConfig(new WidgetConfig($config['prooph.link.dashboard'][$widgetName])); $controllers[] = $controller; } return new DashboardProvider($controllers); }
[ "public", "function", "createService", "(", "ServiceLocatorInterface", "$", "serviceLocator", ")", "{", "$", "config", "=", "$", "serviceLocator", "->", "get", "(", "'config'", ")", ";", "$", "controllerLoader", "=", "$", "serviceLocator", "->", "get", "(", "'ControllerLoader'", ")", ";", "/** @var $systemConfig ProcessingConfig */", "$", "systemConfig", "=", "$", "serviceLocator", "->", "get", "(", "'prooph.link.system_config'", ")", ";", "if", "(", "$", "serviceLocator", "->", "has", "(", "'prooph.link.dashboard.widget_blacklist'", ")", ")", "{", "$", "blacklist", "=", "$", "serviceLocator", "->", "get", "(", "'prooph.link.dashboard.widget_blacklist'", ")", ";", "if", "(", "!", "$", "blacklist", "instanceof", "WidgetBlacklist", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"Widget blacklist should implement \"", ".", "WidgetBlacklist", "::", "class", ".", "\". Got \"", ".", "(", "is_object", "(", "$", "blacklist", ")", ")", "?", "get_class", "(", "$", "blacklist", ")", ":", "gettype", "(", "$", "blacklist", ")", ")", ";", "}", "}", "$", "controllers", "=", "[", "]", ";", "$", "sortArr", "=", "[", "]", ";", "if", "(", "$", "systemConfig", "->", "isConfigured", "(", ")", ")", "{", "foreach", "(", "$", "config", "[", "'prooph.link.dashboard'", "]", "as", "$", "widgetName", "=>", "$", "widgetConfig", ")", "{", "if", "(", "isset", "(", "$", "blacklist", ")", ")", "{", "if", "(", "$", "blacklist", "->", "isWidgetOnList", "(", "$", "widgetName", ")", ")", "{", "continue", ";", "}", "}", "if", "(", "!", "array_key_exists", "(", "'controller'", ",", "$", "widgetConfig", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'controller key missing in widget config: '", ".", "$", "widgetName", ")", ";", "}", "$", "sortArr", "[", "$", "widgetName", "]", "=", "(", "isset", "(", "$", "widgetConfig", "[", "'order'", "]", ")", ")", "?", "(", "int", ")", "$", "widgetConfig", "[", "'order'", "]", ":", "0", ";", "}", "asort", "(", "$", "sortArr", ")", ";", "}", "else", "{", "$", "sortArr", "[", "'system_config_widget'", "]", "=", "1", ";", "}", "foreach", "(", "$", "sortArr", "as", "$", "widgetName", "=>", "$", "order", ")", "{", "$", "controller", "=", "$", "controllerLoader", "->", "get", "(", "$", "config", "[", "'prooph.link.dashboard'", "]", "[", "$", "widgetName", "]", "[", "'controller'", "]", ")", ";", "$", "controller", "->", "setWidgetConfig", "(", "new", "WidgetConfig", "(", "$", "config", "[", "'prooph.link.dashboard'", "]", "[", "$", "widgetName", "]", ")", ")", ";", "$", "controllers", "[", "]", "=", "$", "controller", ";", "}", "return", "new", "DashboardProvider", "(", "$", "controllers", ")", ";", "}" ]
Create service @param ServiceLocatorInterface $serviceLocator @throws \RuntimeException @return DashboardProvider
[ "Create", "service" ]
train
https://github.com/prooph/link-dashboard/blob/6b1806c65552aa03092c63abae45c269cdc8b6bf/src/Service/Factory/DashboardProviderFactory.php#L30-L84
oroinc/OroLayoutComponent
BlockViewCache.php
BlockViewCache.save
public function save(ContextInterface $context, BlockView $rootView) { $hash = $context->getHash(); $serialized = $this->serializer->serialize($rootView, JsonEncoder::FORMAT); $this->cache->save($hash, $serialized); }
php
public function save(ContextInterface $context, BlockView $rootView) { $hash = $context->getHash(); $serialized = $this->serializer->serialize($rootView, JsonEncoder::FORMAT); $this->cache->save($hash, $serialized); }
[ "public", "function", "save", "(", "ContextInterface", "$", "context", ",", "BlockView", "$", "rootView", ")", "{", "$", "hash", "=", "$", "context", "->", "getHash", "(", ")", ";", "$", "serialized", "=", "$", "this", "->", "serializer", "->", "serialize", "(", "$", "rootView", ",", "JsonEncoder", "::", "FORMAT", ")", ";", "$", "this", "->", "cache", "->", "save", "(", "$", "hash", ",", "$", "serialized", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockViewCache.php#L34-L41
oroinc/OroLayoutComponent
BlockViewCache.php
BlockViewCache.fetch
public function fetch(ContextInterface $context) { $hash = $context->getHash(); if ($this->cache->contains($hash)) { $cached = $this->cache->fetch($hash); return $this->serializer->deserialize($cached, BlockView::class, JsonEncoder::FORMAT); } else { return null; } }
php
public function fetch(ContextInterface $context) { $hash = $context->getHash(); if ($this->cache->contains($hash)) { $cached = $this->cache->fetch($hash); return $this->serializer->deserialize($cached, BlockView::class, JsonEncoder::FORMAT); } else { return null; } }
[ "public", "function", "fetch", "(", "ContextInterface", "$", "context", ")", "{", "$", "hash", "=", "$", "context", "->", "getHash", "(", ")", ";", "if", "(", "$", "this", "->", "cache", "->", "contains", "(", "$", "hash", ")", ")", "{", "$", "cached", "=", "$", "this", "->", "cache", "->", "fetch", "(", "$", "hash", ")", ";", "return", "$", "this", "->", "serializer", "->", "deserialize", "(", "$", "cached", ",", "BlockView", "::", "class", ",", "JsonEncoder", "::", "FORMAT", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/BlockViewCache.php#L46-L57
eloquent/cosmos
src/Eloquent/Cosmos/ClassNameResolver.php
ClassNameResolver.resolve
public function resolve(ClassName $className) { if ($className->isAbsolute()) { return $className; } elseif ($className->isShortName()) { $usedClass = $this->usedClass($className); if (null !== $usedClass) { return $usedClass; } } if (null !== $this->namespaceName()) { return $this->namespaceName()->join($className); } return $className->toAbsolute(); }
php
public function resolve(ClassName $className) { if ($className->isAbsolute()) { return $className; } elseif ($className->isShortName()) { $usedClass = $this->usedClass($className); if (null !== $usedClass) { return $usedClass; } } if (null !== $this->namespaceName()) { return $this->namespaceName()->join($className); } return $className->toAbsolute(); }
[ "public", "function", "resolve", "(", "ClassName", "$", "className", ")", "{", "if", "(", "$", "className", "->", "isAbsolute", "(", ")", ")", "{", "return", "$", "className", ";", "}", "elseif", "(", "$", "className", "->", "isShortName", "(", ")", ")", "{", "$", "usedClass", "=", "$", "this", "->", "usedClass", "(", "$", "className", ")", ";", "if", "(", "null", "!==", "$", "usedClass", ")", "{", "return", "$", "usedClass", ";", "}", "}", "if", "(", "null", "!==", "$", "this", "->", "namespaceName", "(", ")", ")", "{", "return", "$", "this", "->", "namespaceName", "(", ")", "->", "join", "(", "$", "className", ")", ";", "}", "return", "$", "className", "->", "toAbsolute", "(", ")", ";", "}" ]
@param ClassName $className @return ClassName
[ "@param", "ClassName", "$className" ]
train
https://github.com/eloquent/cosmos/blob/0226b7aa39c629cdbb41bde759adff59d932d16d/src/Eloquent/Cosmos/ClassNameResolver.php#L68-L84
eloquent/cosmos
src/Eloquent/Cosmos/ClassNameResolver.php
ClassNameResolver.shorten
public function shorten(ClassName $className) { if (!$className->isAbsolute()) { return $className; } foreach ($this->usedClasses() as $tuple) { list($usedClass, $as) = $tuple; if ($this->comparator()->equals($usedClass, $className)) { return $as; } } if ( null !== $this->namespaceName() && $this->namespaceName()->hasDescendant($className) ) { return $className->stripNamespace($this->namespaceName()); } return $className; }
php
public function shorten(ClassName $className) { if (!$className->isAbsolute()) { return $className; } foreach ($this->usedClasses() as $tuple) { list($usedClass, $as) = $tuple; if ($this->comparator()->equals($usedClass, $className)) { return $as; } } if ( null !== $this->namespaceName() && $this->namespaceName()->hasDescendant($className) ) { return $className->stripNamespace($this->namespaceName()); } return $className; }
[ "public", "function", "shorten", "(", "ClassName", "$", "className", ")", "{", "if", "(", "!", "$", "className", "->", "isAbsolute", "(", ")", ")", "{", "return", "$", "className", ";", "}", "foreach", "(", "$", "this", "->", "usedClasses", "(", ")", "as", "$", "tuple", ")", "{", "list", "(", "$", "usedClass", ",", "$", "as", ")", "=", "$", "tuple", ";", "if", "(", "$", "this", "->", "comparator", "(", ")", "->", "equals", "(", "$", "usedClass", ",", "$", "className", ")", ")", "{", "return", "$", "as", ";", "}", "}", "if", "(", "null", "!==", "$", "this", "->", "namespaceName", "(", ")", "&&", "$", "this", "->", "namespaceName", "(", ")", "->", "hasDescendant", "(", "$", "className", ")", ")", "{", "return", "$", "className", "->", "stripNamespace", "(", "$", "this", "->", "namespaceName", "(", ")", ")", ";", "}", "return", "$", "className", ";", "}" ]
@param ClassName $className @return ClassName
[ "@param", "ClassName", "$className" ]
train
https://github.com/eloquent/cosmos/blob/0226b7aa39c629cdbb41bde759adff59d932d16d/src/Eloquent/Cosmos/ClassNameResolver.php#L91-L112
eloquent/cosmos
src/Eloquent/Cosmos/ClassNameResolver.php
ClassNameResolver.normalizeUsedClasses
protected function normalizeUsedClasses(array $usedClasses) { $normalized = array(); foreach ($usedClasses as $tuple) { $tuple[0] = $tuple[0]->toAbsolute(); if (array_key_exists(1, $tuple)) { if (!$tuple[1]->isShortName()) { throw new Exception\InvalidUsedClassAliasException($tuple[1]); } $normalized[] = $tuple; } else { $normalized[] = array($tuple[0], $tuple[0]->shortName()); } } return $normalized; }
php
protected function normalizeUsedClasses(array $usedClasses) { $normalized = array(); foreach ($usedClasses as $tuple) { $tuple[0] = $tuple[0]->toAbsolute(); if (array_key_exists(1, $tuple)) { if (!$tuple[1]->isShortName()) { throw new Exception\InvalidUsedClassAliasException($tuple[1]); } $normalized[] = $tuple; } else { $normalized[] = array($tuple[0], $tuple[0]->shortName()); } } return $normalized; }
[ "protected", "function", "normalizeUsedClasses", "(", "array", "$", "usedClasses", ")", "{", "$", "normalized", "=", "array", "(", ")", ";", "foreach", "(", "$", "usedClasses", "as", "$", "tuple", ")", "{", "$", "tuple", "[", "0", "]", "=", "$", "tuple", "[", "0", "]", "->", "toAbsolute", "(", ")", ";", "if", "(", "array_key_exists", "(", "1", ",", "$", "tuple", ")", ")", "{", "if", "(", "!", "$", "tuple", "[", "1", "]", "->", "isShortName", "(", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidUsedClassAliasException", "(", "$", "tuple", "[", "1", "]", ")", ";", "}", "$", "normalized", "[", "]", "=", "$", "tuple", ";", "}", "else", "{", "$", "normalized", "[", "]", "=", "array", "(", "$", "tuple", "[", "0", "]", ",", "$", "tuple", "[", "0", "]", "->", "shortName", "(", ")", ")", ";", "}", "}", "return", "$", "normalized", ";", "}" ]
@param array<array<ClassName>> $usedClasses @return array<tuple<ClassName,ClassName>>
[ "@param", "array<array<ClassName", ">>", "$usedClasses" ]
train
https://github.com/eloquent/cosmos/blob/0226b7aa39c629cdbb41bde759adff59d932d16d/src/Eloquent/Cosmos/ClassNameResolver.php#L119-L137
eloquent/cosmos
src/Eloquent/Cosmos/ClassNameResolver.php
ClassNameResolver.usedClass
protected function usedClass(ClassName $className) { foreach ($this->usedClasses() as $tuple) { list($usedClass, $as) = $tuple; if ($this->comparator()->equals($as, $className)) { return $usedClass; } } return null; }
php
protected function usedClass(ClassName $className) { foreach ($this->usedClasses() as $tuple) { list($usedClass, $as) = $tuple; if ($this->comparator()->equals($as, $className)) { return $usedClass; } } return null; }
[ "protected", "function", "usedClass", "(", "ClassName", "$", "className", ")", "{", "foreach", "(", "$", "this", "->", "usedClasses", "(", ")", "as", "$", "tuple", ")", "{", "list", "(", "$", "usedClass", ",", "$", "as", ")", "=", "$", "tuple", ";", "if", "(", "$", "this", "->", "comparator", "(", ")", "->", "equals", "(", "$", "as", ",", "$", "className", ")", ")", "{", "return", "$", "usedClass", ";", "}", "}", "return", "null", ";", "}" ]
@param ClassName $className @return ClassName|null
[ "@param", "ClassName", "$className" ]
train
https://github.com/eloquent/cosmos/blob/0226b7aa39c629cdbb41bde759adff59d932d16d/src/Eloquent/Cosmos/ClassNameResolver.php#L144-L154
xiewulong/yii2-fileupload
oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php
CurlMulti.throwMultiException
protected function throwMultiException(array $exceptions, array $successful) { $multiException = new MultiTransferException('Errors during multi transfer'); while ($e = array_shift($exceptions)) { $multiException->add($e['exception']); $multiException->addFailedRequest($e['request']); } // Add successful requests foreach ($successful as $request) { if (!$multiException->containsRequest($request)) { $multiException->addSuccessfulRequest($request); } } throw $multiException; }
php
protected function throwMultiException(array $exceptions, array $successful) { $multiException = new MultiTransferException('Errors during multi transfer'); while ($e = array_shift($exceptions)) { $multiException->add($e['exception']); $multiException->addFailedRequest($e['request']); } // Add successful requests foreach ($successful as $request) { if (!$multiException->containsRequest($request)) { $multiException->addSuccessfulRequest($request); } } throw $multiException; }
[ "protected", "function", "throwMultiException", "(", "array", "$", "exceptions", ",", "array", "$", "successful", ")", "{", "$", "multiException", "=", "new", "MultiTransferException", "(", "'Errors during multi transfer'", ")", ";", "while", "(", "$", "e", "=", "array_shift", "(", "$", "exceptions", ")", ")", "{", "$", "multiException", "->", "add", "(", "$", "e", "[", "'exception'", "]", ")", ";", "$", "multiException", "->", "addFailedRequest", "(", "$", "e", "[", "'request'", "]", ")", ";", "}", "// Add successful requests", "foreach", "(", "$", "successful", "as", "$", "request", ")", "{", "if", "(", "!", "$", "multiException", "->", "containsRequest", "(", "$", "request", ")", ")", "{", "$", "multiException", "->", "addSuccessfulRequest", "(", "$", "request", ")", ";", "}", "}", "throw", "$", "multiException", ";", "}" ]
Build and throw a MultiTransferException @param array $exceptions Exceptions encountered @param array $successful Successful requests @throws MultiTransferException
[ "Build", "and", "throw", "a", "MultiTransferException" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php#L128-L145
xiewulong/yii2-fileupload
oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php
CurlMulti.beforeSend
protected function beforeSend(RequestInterface $request) { try { $state = $request->setState(RequestInterface::STATE_TRANSFER); if ($state == RequestInterface::STATE_TRANSFER) { // Add the request curl handle to the multi handle $this->checkCurlResult(curl_multi_add_handle($this->multiHandle, $this->createCurlHandle($request)->getHandle())); } else { // Requests might decide they don't need to be sent just before transfer (e.g. CachePlugin) $this->remove($request); if ($state == RequestInterface::STATE_COMPLETE) { $this->successful[] = $request; } } } catch (\Exception $e) { // Queue the exception to be thrown when sent $this->removeErroredRequest($request, $e); } }
php
protected function beforeSend(RequestInterface $request) { try { $state = $request->setState(RequestInterface::STATE_TRANSFER); if ($state == RequestInterface::STATE_TRANSFER) { // Add the request curl handle to the multi handle $this->checkCurlResult(curl_multi_add_handle($this->multiHandle, $this->createCurlHandle($request)->getHandle())); } else { // Requests might decide they don't need to be sent just before transfer (e.g. CachePlugin) $this->remove($request); if ($state == RequestInterface::STATE_COMPLETE) { $this->successful[] = $request; } } } catch (\Exception $e) { // Queue the exception to be thrown when sent $this->removeErroredRequest($request, $e); } }
[ "protected", "function", "beforeSend", "(", "RequestInterface", "$", "request", ")", "{", "try", "{", "$", "state", "=", "$", "request", "->", "setState", "(", "RequestInterface", "::", "STATE_TRANSFER", ")", ";", "if", "(", "$", "state", "==", "RequestInterface", "::", "STATE_TRANSFER", ")", "{", "// Add the request curl handle to the multi handle", "$", "this", "->", "checkCurlResult", "(", "curl_multi_add_handle", "(", "$", "this", "->", "multiHandle", ",", "$", "this", "->", "createCurlHandle", "(", "$", "request", ")", "->", "getHandle", "(", ")", ")", ")", ";", "}", "else", "{", "// Requests might decide they don't need to be sent just before transfer (e.g. CachePlugin)", "$", "this", "->", "remove", "(", "$", "request", ")", ";", "if", "(", "$", "state", "==", "RequestInterface", "::", "STATE_COMPLETE", ")", "{", "$", "this", "->", "successful", "[", "]", "=", "$", "request", ";", "}", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// Queue the exception to be thrown when sent", "$", "this", "->", "removeErroredRequest", "(", "$", "request", ",", "$", "e", ")", ";", "}", "}" ]
Prepare for sending @param RequestInterface $request Request to prepare @throws \Exception on error preparing the request
[ "Prepare", "for", "sending" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php#L153-L171
xiewulong/yii2-fileupload
oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php
CurlMulti.perform
protected function perform() { if (!$this->requests) { return; } // Initialize the handles with a very quick select timeout $active = $mrc = null; $this->executeHandles($active, $mrc, 0.001); $event = new Event(array('curl_multi' => $this)); $this->processMessages(); while ($this->requests) { // Notify each request as polling $blocking = $total = 0; foreach ($this->requests as $request) { ++$total; $event['request'] = $request; $request->getEventDispatcher()->dispatch(self::POLLING_REQUEST, $event); // The blocking variable just has to be non-falsey to block the loop if ($request->getParams()->hasKey(self::BLOCKING)) { ++$blocking; } } if ($blocking == $total) { // Sleep to prevent eating CPU because no requests are actually pending a select call usleep(500); } else { do { $this->executeHandles($active, $mrc, 1); } while ($active); } $this->processMessages(); } }
php
protected function perform() { if (!$this->requests) { return; } // Initialize the handles with a very quick select timeout $active = $mrc = null; $this->executeHandles($active, $mrc, 0.001); $event = new Event(array('curl_multi' => $this)); $this->processMessages(); while ($this->requests) { // Notify each request as polling $blocking = $total = 0; foreach ($this->requests as $request) { ++$total; $event['request'] = $request; $request->getEventDispatcher()->dispatch(self::POLLING_REQUEST, $event); // The blocking variable just has to be non-falsey to block the loop if ($request->getParams()->hasKey(self::BLOCKING)) { ++$blocking; } } if ($blocking == $total) { // Sleep to prevent eating CPU because no requests are actually pending a select call usleep(500); } else { do { $this->executeHandles($active, $mrc, 1); } while ($active); } $this->processMessages(); } }
[ "protected", "function", "perform", "(", ")", "{", "if", "(", "!", "$", "this", "->", "requests", ")", "{", "return", ";", "}", "// Initialize the handles with a very quick select timeout", "$", "active", "=", "$", "mrc", "=", "null", ";", "$", "this", "->", "executeHandles", "(", "$", "active", ",", "$", "mrc", ",", "0.001", ")", ";", "$", "event", "=", "new", "Event", "(", "array", "(", "'curl_multi'", "=>", "$", "this", ")", ")", ";", "$", "this", "->", "processMessages", "(", ")", ";", "while", "(", "$", "this", "->", "requests", ")", "{", "// Notify each request as polling", "$", "blocking", "=", "$", "total", "=", "0", ";", "foreach", "(", "$", "this", "->", "requests", "as", "$", "request", ")", "{", "++", "$", "total", ";", "$", "event", "[", "'request'", "]", "=", "$", "request", ";", "$", "request", "->", "getEventDispatcher", "(", ")", "->", "dispatch", "(", "self", "::", "POLLING_REQUEST", ",", "$", "event", ")", ";", "// The blocking variable just has to be non-falsey to block the loop", "if", "(", "$", "request", "->", "getParams", "(", ")", "->", "hasKey", "(", "self", "::", "BLOCKING", ")", ")", "{", "++", "$", "blocking", ";", "}", "}", "if", "(", "$", "blocking", "==", "$", "total", ")", "{", "// Sleep to prevent eating CPU because no requests are actually pending a select call", "usleep", "(", "500", ")", ";", "}", "else", "{", "do", "{", "$", "this", "->", "executeHandles", "(", "$", "active", ",", "$", "mrc", ",", "1", ")", ";", "}", "while", "(", "$", "active", ")", ";", "}", "$", "this", "->", "processMessages", "(", ")", ";", "}", "}" ]
Get the data from the multi handle
[ "Get", "the", "data", "from", "the", "multi", "handle" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php#L192-L228
xiewulong/yii2-fileupload
oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php
CurlMulti.executeHandles
private function executeHandles(&$active, &$mrc, $timeout = 1) { do { $mrc = curl_multi_exec($this->multiHandle, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM && $active); $this->checkCurlResult($mrc); // @codeCoverageIgnoreStart // Select the curl handles until there is any activity on any of the open file descriptors // See https://github.com/php/php-src/blob/master/ext/curl/multi.c#L170 if ($active && $mrc == CURLM_OK && curl_multi_select($this->multiHandle, $timeout) == -1) { // Perform a usleep if a previously executed select returned -1 // @see https://bugs.php.net/bug.php?id=61141 usleep(100); } // @codeCoverageIgnoreEnd }
php
private function executeHandles(&$active, &$mrc, $timeout = 1) { do { $mrc = curl_multi_exec($this->multiHandle, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM && $active); $this->checkCurlResult($mrc); // @codeCoverageIgnoreStart // Select the curl handles until there is any activity on any of the open file descriptors // See https://github.com/php/php-src/blob/master/ext/curl/multi.c#L170 if ($active && $mrc == CURLM_OK && curl_multi_select($this->multiHandle, $timeout) == -1) { // Perform a usleep if a previously executed select returned -1 // @see https://bugs.php.net/bug.php?id=61141 usleep(100); } // @codeCoverageIgnoreEnd }
[ "private", "function", "executeHandles", "(", "&", "$", "active", ",", "&", "$", "mrc", ",", "$", "timeout", "=", "1", ")", "{", "do", "{", "$", "mrc", "=", "curl_multi_exec", "(", "$", "this", "->", "multiHandle", ",", "$", "active", ")", ";", "}", "while", "(", "$", "mrc", "==", "CURLM_CALL_MULTI_PERFORM", "&&", "$", "active", ")", ";", "$", "this", "->", "checkCurlResult", "(", "$", "mrc", ")", ";", "// @codeCoverageIgnoreStart", "// Select the curl handles until there is any activity on any of the open file descriptors", "// See https://github.com/php/php-src/blob/master/ext/curl/multi.c#L170", "if", "(", "$", "active", "&&", "$", "mrc", "==", "CURLM_OK", "&&", "curl_multi_select", "(", "$", "this", "->", "multiHandle", ",", "$", "timeout", ")", "==", "-", "1", ")", "{", "// Perform a usleep if a previously executed select returned -1", "// @see https://bugs.php.net/bug.php?id=61141", "usleep", "(", "100", ")", ";", "}", "// @codeCoverageIgnoreEnd", "}" ]
Execute and select curl handles until there is activity @param int $active Active value to update @param int $mrc Multi result value to update @param int $timeout Select timeout in seconds
[ "Execute", "and", "select", "curl", "handles", "until", "there", "is", "activity" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php#L257-L273
xiewulong/yii2-fileupload
oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php
CurlMulti.removeErroredRequest
protected function removeErroredRequest(RequestInterface $request, \Exception $e = null, $buffer = true) { if ($buffer) { $this->exceptions[] = array('request' => $request, 'exception' => $e); } $this->remove($request); $this->dispatch(self::MULTI_EXCEPTION, array('exception' => $e, 'all_exceptions' => $this->exceptions)); }
php
protected function removeErroredRequest(RequestInterface $request, \Exception $e = null, $buffer = true) { if ($buffer) { $this->exceptions[] = array('request' => $request, 'exception' => $e); } $this->remove($request); $this->dispatch(self::MULTI_EXCEPTION, array('exception' => $e, 'all_exceptions' => $this->exceptions)); }
[ "protected", "function", "removeErroredRequest", "(", "RequestInterface", "$", "request", ",", "\\", "Exception", "$", "e", "=", "null", ",", "$", "buffer", "=", "true", ")", "{", "if", "(", "$", "buffer", ")", "{", "$", "this", "->", "exceptions", "[", "]", "=", "array", "(", "'request'", "=>", "$", "request", ",", "'exception'", "=>", "$", "e", ")", ";", "}", "$", "this", "->", "remove", "(", "$", "request", ")", ";", "$", "this", "->", "dispatch", "(", "self", "::", "MULTI_EXCEPTION", ",", "array", "(", "'exception'", "=>", "$", "e", ",", "'all_exceptions'", "=>", "$", "this", "->", "exceptions", ")", ")", ";", "}" ]
Remove a request that encountered an exception @param RequestInterface $request Request to remove @param \Exception $e Exception encountered @param bool $buffer Set to false to not buffer the exception
[ "Remove", "a", "request", "that", "encountered", "an", "exception" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php#L282-L290
xiewulong/yii2-fileupload
oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php
CurlMulti.processResponse
protected function processResponse(RequestInterface $request, CurlHandle $handle, array $curl) { // Set the transfer stats on the response $handle->updateRequestFromTransfer($request); // Check if a cURL exception occurred, and if so, notify things $curlException = $this->isCurlException($request, $handle, $curl); // Always remove completed curl handles. They can be added back again // via events if needed (e.g. ExponentialBackoffPlugin) $this->removeHandle($request); if (!$curlException) { $state = $request->setState(RequestInterface::STATE_COMPLETE, array('handle' => $handle)); // Only remove the request if it wasn't resent as a result of the state change if ($state != RequestInterface::STATE_TRANSFER) { $this->remove($request); } } else { // Set the state of the request to an error $state = $request->setState(RequestInterface::STATE_ERROR, array('exception' => $curlException)); // Allow things to ignore the error if possible if ($state != RequestInterface::STATE_TRANSFER) { $this->remove($request); } // The error was not handled, so fail if ($state == RequestInterface::STATE_ERROR) { /** @var CurlException $curlException */ throw $curlException; } } }
php
protected function processResponse(RequestInterface $request, CurlHandle $handle, array $curl) { // Set the transfer stats on the response $handle->updateRequestFromTransfer($request); // Check if a cURL exception occurred, and if so, notify things $curlException = $this->isCurlException($request, $handle, $curl); // Always remove completed curl handles. They can be added back again // via events if needed (e.g. ExponentialBackoffPlugin) $this->removeHandle($request); if (!$curlException) { $state = $request->setState(RequestInterface::STATE_COMPLETE, array('handle' => $handle)); // Only remove the request if it wasn't resent as a result of the state change if ($state != RequestInterface::STATE_TRANSFER) { $this->remove($request); } } else { // Set the state of the request to an error $state = $request->setState(RequestInterface::STATE_ERROR, array('exception' => $curlException)); // Allow things to ignore the error if possible if ($state != RequestInterface::STATE_TRANSFER) { $this->remove($request); } // The error was not handled, so fail if ($state == RequestInterface::STATE_ERROR) { /** @var CurlException $curlException */ throw $curlException; } } }
[ "protected", "function", "processResponse", "(", "RequestInterface", "$", "request", ",", "CurlHandle", "$", "handle", ",", "array", "$", "curl", ")", "{", "// Set the transfer stats on the response", "$", "handle", "->", "updateRequestFromTransfer", "(", "$", "request", ")", ";", "// Check if a cURL exception occurred, and if so, notify things", "$", "curlException", "=", "$", "this", "->", "isCurlException", "(", "$", "request", ",", "$", "handle", ",", "$", "curl", ")", ";", "// Always remove completed curl handles. They can be added back again", "// via events if needed (e.g. ExponentialBackoffPlugin)", "$", "this", "->", "removeHandle", "(", "$", "request", ")", ";", "if", "(", "!", "$", "curlException", ")", "{", "$", "state", "=", "$", "request", "->", "setState", "(", "RequestInterface", "::", "STATE_COMPLETE", ",", "array", "(", "'handle'", "=>", "$", "handle", ")", ")", ";", "// Only remove the request if it wasn't resent as a result of the state change", "if", "(", "$", "state", "!=", "RequestInterface", "::", "STATE_TRANSFER", ")", "{", "$", "this", "->", "remove", "(", "$", "request", ")", ";", "}", "}", "else", "{", "// Set the state of the request to an error", "$", "state", "=", "$", "request", "->", "setState", "(", "RequestInterface", "::", "STATE_ERROR", ",", "array", "(", "'exception'", "=>", "$", "curlException", ")", ")", ";", "// Allow things to ignore the error if possible", "if", "(", "$", "state", "!=", "RequestInterface", "::", "STATE_TRANSFER", ")", "{", "$", "this", "->", "remove", "(", "$", "request", ")", ";", "}", "// The error was not handled, so fail", "if", "(", "$", "state", "==", "RequestInterface", "::", "STATE_ERROR", ")", "{", "/** @var CurlException $curlException */", "throw", "$", "curlException", ";", "}", "}", "}" ]
Check for errors and fix headers of a request based on a curl response @param RequestInterface $request Request to process @param CurlHandle $handle Curl handle object @param array $curl Array returned from curl_multi_info_read @throws CurlException on Curl error
[ "Check", "for", "errors", "and", "fix", "headers", "of", "a", "request", "based", "on", "a", "curl", "response" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php#L301-L331
xiewulong/yii2-fileupload
oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php
CurlMulti.removeHandle
protected function removeHandle(RequestInterface $request) { if (isset($this->handles[$request])) { $handle = $this->handles[$request]; unset($this->handles[$request]); unset($this->resourceHash[(int) $handle->getHandle()]); curl_multi_remove_handle($this->multiHandle, $handle->getHandle()); $handle->close(); } }
php
protected function removeHandle(RequestInterface $request) { if (isset($this->handles[$request])) { $handle = $this->handles[$request]; unset($this->handles[$request]); unset($this->resourceHash[(int) $handle->getHandle()]); curl_multi_remove_handle($this->multiHandle, $handle->getHandle()); $handle->close(); } }
[ "protected", "function", "removeHandle", "(", "RequestInterface", "$", "request", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "handles", "[", "$", "request", "]", ")", ")", "{", "$", "handle", "=", "$", "this", "->", "handles", "[", "$", "request", "]", ";", "unset", "(", "$", "this", "->", "handles", "[", "$", "request", "]", ")", ";", "unset", "(", "$", "this", "->", "resourceHash", "[", "(", "int", ")", "$", "handle", "->", "getHandle", "(", ")", "]", ")", ";", "curl_multi_remove_handle", "(", "$", "this", "->", "multiHandle", ",", "$", "handle", "->", "getHandle", "(", ")", ")", ";", "$", "handle", "->", "close", "(", ")", ";", "}", "}" ]
Remove a curl handle from the curl multi object @param RequestInterface $request Request that owns the handle
[ "Remove", "a", "curl", "handle", "from", "the", "curl", "multi", "object" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Curl/CurlMulti.php#L338-L347
heidelpay/PhpDoc
src/phpDocumentor/Transformer/Command/Project/TransformCommand.php
TransformCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { /** @var ConfigurationHelper $configurationHelper */ $configurationHelper = $this->getHelper('phpdocumentor_configuration'); $progress = $this->getProgressBar($input); if (! $progress) { $this->connectOutputToEvents($output); } // initialize transformer $transformer = $this->getTransformer(); $target = (string) $configurationHelper->getOption($input, 'target', 'transformer/target'); $fileSystem = new Filesystem(); if (! $fileSystem->isAbsolutePath($target)) { $target = getcwd() . DIRECTORY_SEPARATOR . $target; } $transformer->setTarget($target); $source = realpath($configurationHelper->getOption($input, 'source', 'parser/target')); if (!file_exists($source) || !is_dir($source)) { throw new \Exception('Invalid source location provided, a path to an existing folder was expected'); } $this->getCache()->getOptions()->setCacheDir($source); $projectDescriptor = $this->getBuilder()->getProjectDescriptor(); $mapper = new ProjectDescriptorMapper($this->getCache()); $output->writeTimedLog('Load cache', array($mapper, 'populate'), array($projectDescriptor)); foreach ($this->getTemplates($input) as $template) { $output->writeTimedLog( 'Preparing template "'. $template .'"', array($transformer->getTemplates(), 'load'), array($template, $transformer) ); } $output->writeTimedLog( 'Preparing ' . count($transformer->getTemplates()->getTransformations()) . ' transformations', array($this, 'loadTransformations'), array($transformer) ); if ($progress) { $progress->start($output, count($transformer->getTemplates()->getTransformations())); } /** @var CompilerPassInterface $pass */ foreach ($this->compiler as $pass) { $output->writeTimedLog($pass->getDescription(), array($pass, 'execute'), array($projectDescriptor)); } if ($progress) { $progress->finish(); } return 0; }
php
protected function execute(InputInterface $input, OutputInterface $output) { /** @var ConfigurationHelper $configurationHelper */ $configurationHelper = $this->getHelper('phpdocumentor_configuration'); $progress = $this->getProgressBar($input); if (! $progress) { $this->connectOutputToEvents($output); } // initialize transformer $transformer = $this->getTransformer(); $target = (string) $configurationHelper->getOption($input, 'target', 'transformer/target'); $fileSystem = new Filesystem(); if (! $fileSystem->isAbsolutePath($target)) { $target = getcwd() . DIRECTORY_SEPARATOR . $target; } $transformer->setTarget($target); $source = realpath($configurationHelper->getOption($input, 'source', 'parser/target')); if (!file_exists($source) || !is_dir($source)) { throw new \Exception('Invalid source location provided, a path to an existing folder was expected'); } $this->getCache()->getOptions()->setCacheDir($source); $projectDescriptor = $this->getBuilder()->getProjectDescriptor(); $mapper = new ProjectDescriptorMapper($this->getCache()); $output->writeTimedLog('Load cache', array($mapper, 'populate'), array($projectDescriptor)); foreach ($this->getTemplates($input) as $template) { $output->writeTimedLog( 'Preparing template "'. $template .'"', array($transformer->getTemplates(), 'load'), array($template, $transformer) ); } $output->writeTimedLog( 'Preparing ' . count($transformer->getTemplates()->getTransformations()) . ' transformations', array($this, 'loadTransformations'), array($transformer) ); if ($progress) { $progress->start($output, count($transformer->getTemplates()->getTransformations())); } /** @var CompilerPassInterface $pass */ foreach ($this->compiler as $pass) { $output->writeTimedLog($pass->getDescription(), array($pass, 'execute'), array($projectDescriptor)); } if ($progress) { $progress->finish(); } return 0; }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "/** @var ConfigurationHelper $configurationHelper */", "$", "configurationHelper", "=", "$", "this", "->", "getHelper", "(", "'phpdocumentor_configuration'", ")", ";", "$", "progress", "=", "$", "this", "->", "getProgressBar", "(", "$", "input", ")", ";", "if", "(", "!", "$", "progress", ")", "{", "$", "this", "->", "connectOutputToEvents", "(", "$", "output", ")", ";", "}", "// initialize transformer", "$", "transformer", "=", "$", "this", "->", "getTransformer", "(", ")", ";", "$", "target", "=", "(", "string", ")", "$", "configurationHelper", "->", "getOption", "(", "$", "input", ",", "'target'", ",", "'transformer/target'", ")", ";", "$", "fileSystem", "=", "new", "Filesystem", "(", ")", ";", "if", "(", "!", "$", "fileSystem", "->", "isAbsolutePath", "(", "$", "target", ")", ")", "{", "$", "target", "=", "getcwd", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "target", ";", "}", "$", "transformer", "->", "setTarget", "(", "$", "target", ")", ";", "$", "source", "=", "realpath", "(", "$", "configurationHelper", "->", "getOption", "(", "$", "input", ",", "'source'", ",", "'parser/target'", ")", ")", ";", "if", "(", "!", "file_exists", "(", "$", "source", ")", "||", "!", "is_dir", "(", "$", "source", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Invalid source location provided, a path to an existing folder was expected'", ")", ";", "}", "$", "this", "->", "getCache", "(", ")", "->", "getOptions", "(", ")", "->", "setCacheDir", "(", "$", "source", ")", ";", "$", "projectDescriptor", "=", "$", "this", "->", "getBuilder", "(", ")", "->", "getProjectDescriptor", "(", ")", ";", "$", "mapper", "=", "new", "ProjectDescriptorMapper", "(", "$", "this", "->", "getCache", "(", ")", ")", ";", "$", "output", "->", "writeTimedLog", "(", "'Load cache'", ",", "array", "(", "$", "mapper", ",", "'populate'", ")", ",", "array", "(", "$", "projectDescriptor", ")", ")", ";", "foreach", "(", "$", "this", "->", "getTemplates", "(", "$", "input", ")", "as", "$", "template", ")", "{", "$", "output", "->", "writeTimedLog", "(", "'Preparing template \"'", ".", "$", "template", ".", "'\"'", ",", "array", "(", "$", "transformer", "->", "getTemplates", "(", ")", ",", "'load'", ")", ",", "array", "(", "$", "template", ",", "$", "transformer", ")", ")", ";", "}", "$", "output", "->", "writeTimedLog", "(", "'Preparing '", ".", "count", "(", "$", "transformer", "->", "getTemplates", "(", ")", "->", "getTransformations", "(", ")", ")", ".", "' transformations'", ",", "array", "(", "$", "this", ",", "'loadTransformations'", ")", ",", "array", "(", "$", "transformer", ")", ")", ";", "if", "(", "$", "progress", ")", "{", "$", "progress", "->", "start", "(", "$", "output", ",", "count", "(", "$", "transformer", "->", "getTemplates", "(", ")", "->", "getTransformations", "(", ")", ")", ")", ";", "}", "/** @var CompilerPassInterface $pass */", "foreach", "(", "$", "this", "->", "compiler", "as", "$", "pass", ")", "{", "$", "output", "->", "writeTimedLog", "(", "$", "pass", "->", "getDescription", "(", ")", ",", "array", "(", "$", "pass", ",", "'execute'", ")", ",", "array", "(", "$", "projectDescriptor", ")", ")", ";", "}", "if", "(", "$", "progress", ")", "{", "$", "progress", "->", "finish", "(", ")", ";", "}", "return", "0", ";", "}" ]
Executes the business logic involved with this command. @param InputInterface $input @param OutputInterface $output @throws \Exception if the provided source is not an existing file or a folder. @return int
[ "Executes", "the", "business", "logic", "involved", "with", "this", "command", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php#L156-L214
heidelpay/PhpDoc
src/phpDocumentor/Transformer/Command/Project/TransformCommand.php
TransformCommand.getTemplates
protected function getTemplates(InputInterface $input) { /** @var ConfigurationHelper $configurationHelper */ $configurationHelper = $this->getHelper('phpdocumentor_configuration'); $templates = $input->getOption('template'); if (!$templates) { /** @var Template[] $templatesFromConfig */ $templatesFromConfig = $configurationHelper->getConfigValueFromPath('transformations/templates'); foreach ($templatesFromConfig as $template) { $templates[] = $template->getName(); } } if (!$templates) { $templates = array('clean'); } return $templates; }
php
protected function getTemplates(InputInterface $input) { /** @var ConfigurationHelper $configurationHelper */ $configurationHelper = $this->getHelper('phpdocumentor_configuration'); $templates = $input->getOption('template'); if (!$templates) { /** @var Template[] $templatesFromConfig */ $templatesFromConfig = $configurationHelper->getConfigValueFromPath('transformations/templates'); foreach ($templatesFromConfig as $template) { $templates[] = $template->getName(); } } if (!$templates) { $templates = array('clean'); } return $templates; }
[ "protected", "function", "getTemplates", "(", "InputInterface", "$", "input", ")", "{", "/** @var ConfigurationHelper $configurationHelper */", "$", "configurationHelper", "=", "$", "this", "->", "getHelper", "(", "'phpdocumentor_configuration'", ")", ";", "$", "templates", "=", "$", "input", "->", "getOption", "(", "'template'", ")", ";", "if", "(", "!", "$", "templates", ")", "{", "/** @var Template[] $templatesFromConfig */", "$", "templatesFromConfig", "=", "$", "configurationHelper", "->", "getConfigValueFromPath", "(", "'transformations/templates'", ")", ";", "foreach", "(", "$", "templatesFromConfig", "as", "$", "template", ")", "{", "$", "templates", "[", "]", "=", "$", "template", "->", "getName", "(", ")", ";", "}", "}", "if", "(", "!", "$", "templates", ")", "{", "$", "templates", "=", "array", "(", "'clean'", ")", ";", "}", "return", "$", "templates", ";", "}" ]
Retrieves the templates to be used by analyzing the options and the configuration. @param InputInterface $input @return string[]
[ "Retrieves", "the", "templates", "to", "be", "used", "by", "analyzing", "the", "options", "and", "the", "configuration", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php#L233-L252
heidelpay/PhpDoc
src/phpDocumentor/Transformer/Command/Project/TransformCommand.php
TransformCommand.loadTransformations
public function loadTransformations(Transformer $transformer) { /** @var ConfigurationHelper $configurationHelper */ $configurationHelper = $this->getHelper('phpdocumentor_configuration'); $received = array(); $transformations = $configurationHelper->getConfigValueFromPath('transformations/transformations'); if (is_array($transformations)) { if (isset($transformations['writer'])) { $received[] = $this->createTransformation($transformations); } else { foreach ($transformations as $transformation) { if (is_array($transformation)) { $received[] = $this->createTransformation($transformations); } } } } $this->appendReceivedTransformations($transformer, $received); }
php
public function loadTransformations(Transformer $transformer) { /** @var ConfigurationHelper $configurationHelper */ $configurationHelper = $this->getHelper('phpdocumentor_configuration'); $received = array(); $transformations = $configurationHelper->getConfigValueFromPath('transformations/transformations'); if (is_array($transformations)) { if (isset($transformations['writer'])) { $received[] = $this->createTransformation($transformations); } else { foreach ($transformations as $transformation) { if (is_array($transformation)) { $received[] = $this->createTransformation($transformations); } } } } $this->appendReceivedTransformations($transformer, $received); }
[ "public", "function", "loadTransformations", "(", "Transformer", "$", "transformer", ")", "{", "/** @var ConfigurationHelper $configurationHelper */", "$", "configurationHelper", "=", "$", "this", "->", "getHelper", "(", "'phpdocumentor_configuration'", ")", ";", "$", "received", "=", "array", "(", ")", ";", "$", "transformations", "=", "$", "configurationHelper", "->", "getConfigValueFromPath", "(", "'transformations/transformations'", ")", ";", "if", "(", "is_array", "(", "$", "transformations", ")", ")", "{", "if", "(", "isset", "(", "$", "transformations", "[", "'writer'", "]", ")", ")", "{", "$", "received", "[", "]", "=", "$", "this", "->", "createTransformation", "(", "$", "transformations", ")", ";", "}", "else", "{", "foreach", "(", "$", "transformations", "as", "$", "transformation", ")", "{", "if", "(", "is_array", "(", "$", "transformation", ")", ")", "{", "$", "received", "[", "]", "=", "$", "this", "->", "createTransformation", "(", "$", "transformations", ")", ";", "}", "}", "}", "}", "$", "this", "->", "appendReceivedTransformations", "(", "$", "transformer", ",", "$", "received", ")", ";", "}" ]
Load custom defined transformations. @param Transformer $transformer @todo this is an ugly implementation done for speed of development, should be refactored @return void
[ "Load", "custom", "defined", "transformations", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php#L263-L283
heidelpay/PhpDoc
src/phpDocumentor/Transformer/Command/Project/TransformCommand.php
TransformCommand.createTransformation
protected function createTransformation(array $transformations) { return new Transformation( isset($transformations['query']) ? $transformations['query'] : '', $transformations['writer'], isset($transformations['source']) ? $transformations['source'] : '', isset($transformations['artifact']) ? $transformations['artifact'] : '' ); }
php
protected function createTransformation(array $transformations) { return new Transformation( isset($transformations['query']) ? $transformations['query'] : '', $transformations['writer'], isset($transformations['source']) ? $transformations['source'] : '', isset($transformations['artifact']) ? $transformations['artifact'] : '' ); }
[ "protected", "function", "createTransformation", "(", "array", "$", "transformations", ")", "{", "return", "new", "Transformation", "(", "isset", "(", "$", "transformations", "[", "'query'", "]", ")", "?", "$", "transformations", "[", "'query'", "]", ":", "''", ",", "$", "transformations", "[", "'writer'", "]", ",", "isset", "(", "$", "transformations", "[", "'source'", "]", ")", "?", "$", "transformations", "[", "'source'", "]", ":", "''", ",", "isset", "(", "$", "transformations", "[", "'artifact'", "]", ")", "?", "$", "transformations", "[", "'artifact'", "]", ":", "''", ")", ";", "}" ]
Create Transformation instance. @param array $transformations @return \phpDocumentor\Transformer\Transformation
[ "Create", "Transformation", "instance", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php#L292-L300
heidelpay/PhpDoc
src/phpDocumentor/Transformer/Command/Project/TransformCommand.php
TransformCommand.appendReceivedTransformations
protected function appendReceivedTransformations(Transformer $transformer, $received) { if (!empty($received)) { $template = new Template('__'); foreach ($received as $transformation) { $template[] = $transformation; } $transformer->getTemplates()->append($template); } }
php
protected function appendReceivedTransformations(Transformer $transformer, $received) { if (!empty($received)) { $template = new Template('__'); foreach ($received as $transformation) { $template[] = $transformation; } $transformer->getTemplates()->append($template); } }
[ "protected", "function", "appendReceivedTransformations", "(", "Transformer", "$", "transformer", ",", "$", "received", ")", "{", "if", "(", "!", "empty", "(", "$", "received", ")", ")", "{", "$", "template", "=", "new", "Template", "(", "'__'", ")", ";", "foreach", "(", "$", "received", "as", "$", "transformation", ")", "{", "$", "template", "[", "]", "=", "$", "transformation", ";", "}", "$", "transformer", "->", "getTemplates", "(", ")", "->", "append", "(", "$", "template", ")", ";", "}", "}" ]
Append received transformations. @param Transformer $transformer @param array $received @return void
[ "Append", "received", "transformations", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php#L310-L319
heidelpay/PhpDoc
src/phpDocumentor/Transformer/Command/Project/TransformCommand.php
TransformCommand.getProgressBar
protected function getProgressBar(InputInterface $input) { $progress = parent::getProgressBar($input); if (!$progress) { return null; } /** @var Dispatcher $eventDispatcher */ $eventDispatcher = $this->getService('event_dispatcher'); $eventDispatcher->addListener( 'transformer.transformation.post', function () use ($progress) { $progress->advance(); } ); return $progress; }
php
protected function getProgressBar(InputInterface $input) { $progress = parent::getProgressBar($input); if (!$progress) { return null; } /** @var Dispatcher $eventDispatcher */ $eventDispatcher = $this->getService('event_dispatcher'); $eventDispatcher->addListener( 'transformer.transformation.post', function () use ($progress) { $progress->advance(); } ); return $progress; }
[ "protected", "function", "getProgressBar", "(", "InputInterface", "$", "input", ")", "{", "$", "progress", "=", "parent", "::", "getProgressBar", "(", "$", "input", ")", ";", "if", "(", "!", "$", "progress", ")", "{", "return", "null", ";", "}", "/** @var Dispatcher $eventDispatcher */", "$", "eventDispatcher", "=", "$", "this", "->", "getService", "(", "'event_dispatcher'", ")", ";", "$", "eventDispatcher", "->", "addListener", "(", "'transformer.transformation.post'", ",", "function", "(", ")", "use", "(", "$", "progress", ")", "{", "$", "progress", "->", "advance", "(", ")", ";", "}", ")", ";", "return", "$", "progress", ";", "}" ]
Adds the transformer.transformation.post event to advance the progressbar. @param InputInterface $input @return HelperInterface|null
[ "Adds", "the", "transformer", ".", "transformation", ".", "post", "event", "to", "advance", "the", "progressbar", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php#L328-L345
heidelpay/PhpDoc
src/phpDocumentor/Transformer/Command/Project/TransformCommand.php
TransformCommand.connectOutputToEvents
private function connectOutputToEvents(OutputInterface $output) { $this->getHelper('phpdocumentor_logger')->connectOutputToLogging($output, $this); Dispatcher::getInstance()->addListener( Transformer::EVENT_PRE_TRANSFORM, function (PreTransformEvent $event) use ($output) { $transformations = $event->getSubject()->getTemplates()->getTransformations(); $output->writeln(sprintf("\nApplying %d transformations", count($transformations))); } ); Dispatcher::getInstance()->addListener( Transformer::EVENT_PRE_INITIALIZATION, function (WriterInitializationEvent $event) use ($output) { $output->writeln(' Initialize writer "' . get_class($event->getWriter()) . '"'); } ); Dispatcher::getInstance()->addListener( Transformer::EVENT_PRE_TRANSFORMATION, function (PreTransformationEvent $event) use ($output) { $output->writeln( ' Execute transformation using writer "' . $event->getTransformation()->getWriter() . '"' ); } ); }
php
private function connectOutputToEvents(OutputInterface $output) { $this->getHelper('phpdocumentor_logger')->connectOutputToLogging($output, $this); Dispatcher::getInstance()->addListener( Transformer::EVENT_PRE_TRANSFORM, function (PreTransformEvent $event) use ($output) { $transformations = $event->getSubject()->getTemplates()->getTransformations(); $output->writeln(sprintf("\nApplying %d transformations", count($transformations))); } ); Dispatcher::getInstance()->addListener( Transformer::EVENT_PRE_INITIALIZATION, function (WriterInitializationEvent $event) use ($output) { $output->writeln(' Initialize writer "' . get_class($event->getWriter()) . '"'); } ); Dispatcher::getInstance()->addListener( Transformer::EVENT_PRE_TRANSFORMATION, function (PreTransformationEvent $event) use ($output) { $output->writeln( ' Execute transformation using writer "' . $event->getTransformation()->getWriter() . '"' ); } ); }
[ "private", "function", "connectOutputToEvents", "(", "OutputInterface", "$", "output", ")", "{", "$", "this", "->", "getHelper", "(", "'phpdocumentor_logger'", ")", "->", "connectOutputToLogging", "(", "$", "output", ",", "$", "this", ")", ";", "Dispatcher", "::", "getInstance", "(", ")", "->", "addListener", "(", "Transformer", "::", "EVENT_PRE_TRANSFORM", ",", "function", "(", "PreTransformEvent", "$", "event", ")", "use", "(", "$", "output", ")", "{", "$", "transformations", "=", "$", "event", "->", "getSubject", "(", ")", "->", "getTemplates", "(", ")", "->", "getTransformations", "(", ")", ";", "$", "output", "->", "writeln", "(", "sprintf", "(", "\"\\nApplying %d transformations\"", ",", "count", "(", "$", "transformations", ")", ")", ")", ";", "}", ")", ";", "Dispatcher", "::", "getInstance", "(", ")", "->", "addListener", "(", "Transformer", "::", "EVENT_PRE_INITIALIZATION", ",", "function", "(", "WriterInitializationEvent", "$", "event", ")", "use", "(", "$", "output", ")", "{", "$", "output", "->", "writeln", "(", "' Initialize writer \"'", ".", "get_class", "(", "$", "event", "->", "getWriter", "(", ")", ")", ".", "'\"'", ")", ";", "}", ")", ";", "Dispatcher", "::", "getInstance", "(", ")", "->", "addListener", "(", "Transformer", "::", "EVENT_PRE_TRANSFORMATION", ",", "function", "(", "PreTransformationEvent", "$", "event", ")", "use", "(", "$", "output", ")", "{", "$", "output", "->", "writeln", "(", "' Execute transformation using writer \"'", ".", "$", "event", "->", "getTransformation", "(", ")", "->", "getWriter", "(", ")", ".", "'\"'", ")", ";", "}", ")", ";", "}" ]
Connect a series of output messages to various events to display progress. @param OutputInterface $output @return void
[ "Connect", "a", "series", "of", "output", "messages", "to", "various", "events", "to", "display", "progress", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Command/Project/TransformCommand.php#L354-L379
caffeinated/beverage
src/Filesystem.php
Filesystem.rsearch
public function rsearch($folder, $pattern) { $dir = new RecursiveDirectoryIterator($folder); $iterator = new RecursiveIteratorIterator($dir); $files = new RegexIterator($iterator, $pattern, RegexIterator::GET_MATCH); $fileList = []; foreach ($files as $file) { $fileList = array_merge($fileList, $file); } return $fileList; }
php
public function rsearch($folder, $pattern) { $dir = new RecursiveDirectoryIterator($folder); $iterator = new RecursiveIteratorIterator($dir); $files = new RegexIterator($iterator, $pattern, RegexIterator::GET_MATCH); $fileList = []; foreach ($files as $file) { $fileList = array_merge($fileList, $file); } return $fileList; }
[ "public", "function", "rsearch", "(", "$", "folder", ",", "$", "pattern", ")", "{", "$", "dir", "=", "new", "RecursiveDirectoryIterator", "(", "$", "folder", ")", ";", "$", "iterator", "=", "new", "RecursiveIteratorIterator", "(", "$", "dir", ")", ";", "$", "files", "=", "new", "RegexIterator", "(", "$", "iterator", ",", "$", "pattern", ",", "RegexIterator", "::", "GET_MATCH", ")", ";", "$", "fileList", "=", "[", "]", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "fileList", "=", "array_merge", "(", "$", "fileList", ",", "$", "file", ")", ";", "}", "return", "$", "fileList", ";", "}" ]
Search the given folder recursively for files using a regular expression pattern. @param string $folder @param string $pattern @return array
[ "Search", "the", "given", "folder", "recursively", "for", "files", "using", "a", "regular", "expression", "pattern", "." ]
train
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Filesystem.php#L66-L78
php-lug/lug
src/Component/Grid/Column/Type/NumberType.php
NumberType.render
public function render($data, array $options) { $number = $this->getValue($data, $options); if ($number === null) { return; } if (!is_numeric($number)) { throw new InvalidTypeException(sprintf( 'The "%s" %s column type expects a numeric value, got "%s".', $options['column']->getName(), $this->getName(), is_object($number) ? get_class($number) : gettype($number) )); } return $this->formatter->format($number, $options); }
php
public function render($data, array $options) { $number = $this->getValue($data, $options); if ($number === null) { return; } if (!is_numeric($number)) { throw new InvalidTypeException(sprintf( 'The "%s" %s column type expects a numeric value, got "%s".', $options['column']->getName(), $this->getName(), is_object($number) ? get_class($number) : gettype($number) )); } return $this->formatter->format($number, $options); }
[ "public", "function", "render", "(", "$", "data", ",", "array", "$", "options", ")", "{", "$", "number", "=", "$", "this", "->", "getValue", "(", "$", "data", ",", "$", "options", ")", ";", "if", "(", "$", "number", "===", "null", ")", "{", "return", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "number", ")", ")", "{", "throw", "new", "InvalidTypeException", "(", "sprintf", "(", "'The \"%s\" %s column type expects a numeric value, got \"%s\".'", ",", "$", "options", "[", "'column'", "]", "->", "getName", "(", ")", ",", "$", "this", "->", "getName", "(", ")", ",", "is_object", "(", "$", "number", ")", "?", "get_class", "(", "$", "number", ")", ":", "gettype", "(", "$", "number", ")", ")", ")", ";", "}", "return", "$", "this", "->", "formatter", "->", "format", "(", "$", "number", ",", "$", "options", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/NumberType.php#L69-L87
php-lug/lug
src/Component/Grid/Column/Type/NumberType.php
NumberType.configureOptions
public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); $resolver ->setDefaults([ 'scale' => $this->scale, 'rounding' => $this->rounding, 'grouping' => $this->grouping, ]) ->setAllowedTypes('scale', 'integer') ->setAllowedTypes('grouping', 'boolean') ->setAllowedValues('rounding', [ \NumberFormatter::ROUND_FLOOR, \NumberFormatter::ROUND_DOWN, \NumberFormatter::ROUND_HALFDOWN, \NumberFormatter::ROUND_HALFEVEN, \NumberFormatter::ROUND_HALFUP, \NumberFormatter::ROUND_UP, \NumberFormatter::ROUND_CEILING, ]); }
php
public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); $resolver ->setDefaults([ 'scale' => $this->scale, 'rounding' => $this->rounding, 'grouping' => $this->grouping, ]) ->setAllowedTypes('scale', 'integer') ->setAllowedTypes('grouping', 'boolean') ->setAllowedValues('rounding', [ \NumberFormatter::ROUND_FLOOR, \NumberFormatter::ROUND_DOWN, \NumberFormatter::ROUND_HALFDOWN, \NumberFormatter::ROUND_HALFEVEN, \NumberFormatter::ROUND_HALFUP, \NumberFormatter::ROUND_UP, \NumberFormatter::ROUND_CEILING, ]); }
[ "public", "function", "configureOptions", "(", "OptionsResolver", "$", "resolver", ")", "{", "parent", "::", "configureOptions", "(", "$", "resolver", ")", ";", "$", "resolver", "->", "setDefaults", "(", "[", "'scale'", "=>", "$", "this", "->", "scale", ",", "'rounding'", "=>", "$", "this", "->", "rounding", ",", "'grouping'", "=>", "$", "this", "->", "grouping", ",", "]", ")", "->", "setAllowedTypes", "(", "'scale'", ",", "'integer'", ")", "->", "setAllowedTypes", "(", "'grouping'", ",", "'boolean'", ")", "->", "setAllowedValues", "(", "'rounding'", ",", "[", "\\", "NumberFormatter", "::", "ROUND_FLOOR", ",", "\\", "NumberFormatter", "::", "ROUND_DOWN", ",", "\\", "NumberFormatter", "::", "ROUND_HALFDOWN", ",", "\\", "NumberFormatter", "::", "ROUND_HALFEVEN", ",", "\\", "NumberFormatter", "::", "ROUND_HALFUP", ",", "\\", "NumberFormatter", "::", "ROUND_UP", ",", "\\", "NumberFormatter", "::", "ROUND_CEILING", ",", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/NumberType.php#L92-L113
tystuyfzand/flysystem-seaweedfs
src/Seaweed.php
Seaweed.write
public function write($path, $contents, Config $config) { try { $mapping = $this->mapper->get($path); $file = null; if ($mapping) { $volume = $this->client->lookup($mapping['fid']); $file = new \stdClass(); $file->url = $volume->url; $file->fid = $mapping['fid']; } $file = $this->client->upload($contents, basename($path), $file); if (!$file) { return false; } $this->mapper->store($path, $file->fid, mimetype_from_filename($path), $file->size); return $file->toArray(); } catch (SeaweedFSException $e) { return false; } }
php
public function write($path, $contents, Config $config) { try { $mapping = $this->mapper->get($path); $file = null; if ($mapping) { $volume = $this->client->lookup($mapping['fid']); $file = new \stdClass(); $file->url = $volume->url; $file->fid = $mapping['fid']; } $file = $this->client->upload($contents, basename($path), $file); if (!$file) { return false; } $this->mapper->store($path, $file->fid, mimetype_from_filename($path), $file->size); return $file->toArray(); } catch (SeaweedFSException $e) { return false; } }
[ "public", "function", "write", "(", "$", "path", ",", "$", "contents", ",", "Config", "$", "config", ")", "{", "try", "{", "$", "mapping", "=", "$", "this", "->", "mapper", "->", "get", "(", "$", "path", ")", ";", "$", "file", "=", "null", ";", "if", "(", "$", "mapping", ")", "{", "$", "volume", "=", "$", "this", "->", "client", "->", "lookup", "(", "$", "mapping", "[", "'fid'", "]", ")", ";", "$", "file", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "file", "->", "url", "=", "$", "volume", "->", "url", ";", "$", "file", "->", "fid", "=", "$", "mapping", "[", "'fid'", "]", ";", "}", "$", "file", "=", "$", "this", "->", "client", "->", "upload", "(", "$", "contents", ",", "basename", "(", "$", "path", ")", ",", "$", "file", ")", ";", "if", "(", "!", "$", "file", ")", "{", "return", "false", ";", "}", "$", "this", "->", "mapper", "->", "store", "(", "$", "path", ",", "$", "file", "->", "fid", ",", "mimetype_from_filename", "(", "$", "path", ")", ",", "$", "file", "->", "size", ")", ";", "return", "$", "file", "->", "toArray", "(", ")", ";", "}", "catch", "(", "SeaweedFSException", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Write a new file. @param string $path @param string $contents @param Config $config Config object @return array|false false on failure file meta data on success
[ "Write", "a", "new", "file", "." ]
train
https://github.com/tystuyfzand/flysystem-seaweedfs/blob/992334ba1d8e26fe6bbb9e33feedbf66b4872613/src/Seaweed.php#L48-L74
tystuyfzand/flysystem-seaweedfs
src/Seaweed.php
Seaweed.delete
public function delete($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } try { $this->client->delete($mapping['fid']); $this->mapper->remove($path); return true; } catch (SeaweedFSException $e) { return false; } }
php
public function delete($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } try { $this->client->delete($mapping['fid']); $this->mapper->remove($path); return true; } catch (SeaweedFSException $e) { return false; } }
[ "public", "function", "delete", "(", "$", "path", ")", "{", "$", "mapping", "=", "$", "this", "->", "mapper", "->", "get", "(", "$", "path", ")", ";", "if", "(", "!", "$", "mapping", ")", "{", "return", "false", ";", "}", "try", "{", "$", "this", "->", "client", "->", "delete", "(", "$", "mapping", "[", "'fid'", "]", ")", ";", "$", "this", "->", "mapper", "->", "remove", "(", "$", "path", ")", ";", "return", "true", ";", "}", "catch", "(", "SeaweedFSException", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Delete a file. @param string $path @return bool
[ "Delete", "a", "file", "." ]
train
https://github.com/tystuyfzand/flysystem-seaweedfs/blob/992334ba1d8e26fe6bbb9e33feedbf66b4872613/src/Seaweed.php#L146-L161
tystuyfzand/flysystem-seaweedfs
src/Seaweed.php
Seaweed.has
public function has($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } return $this->client->has($mapping['fid']); }
php
public function has($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } return $this->client->has($mapping['fid']); }
[ "public", "function", "has", "(", "$", "path", ")", "{", "$", "mapping", "=", "$", "this", "->", "mapper", "->", "get", "(", "$", "path", ")", ";", "if", "(", "!", "$", "mapping", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "client", "->", "has", "(", "$", "mapping", "[", "'fid'", "]", ")", ";", "}" ]
Check whether a file exists. @param string $path @return array|bool|null
[ "Check", "whether", "a", "file", "exists", "." ]
train
https://github.com/tystuyfzand/flysystem-seaweedfs/blob/992334ba1d8e26fe6bbb9e33feedbf66b4872613/src/Seaweed.php#L193-L201
tystuyfzand/flysystem-seaweedfs
src/Seaweed.php
Seaweed.read
public function read($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } try { $file = $this->client->get($mapping['fid']); if (!$file) { return false; } return [ 'contents' => stream_get_contents($file) ]; } catch (SeaweedFSException $e) { return false; } }
php
public function read($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } try { $file = $this->client->get($mapping['fid']); if (!$file) { return false; } return [ 'contents' => stream_get_contents($file) ]; } catch (SeaweedFSException $e) { return false; } }
[ "public", "function", "read", "(", "$", "path", ")", "{", "$", "mapping", "=", "$", "this", "->", "mapper", "->", "get", "(", "$", "path", ")", ";", "if", "(", "!", "$", "mapping", ")", "{", "return", "false", ";", "}", "try", "{", "$", "file", "=", "$", "this", "->", "client", "->", "get", "(", "$", "mapping", "[", "'fid'", "]", ")", ";", "if", "(", "!", "$", "file", ")", "{", "return", "false", ";", "}", "return", "[", "'contents'", "=>", "stream_get_contents", "(", "$", "file", ")", "]", ";", "}", "catch", "(", "SeaweedFSException", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Read a file. @param string $path @return array|false
[ "Read", "a", "file", "." ]
train
https://github.com/tystuyfzand/flysystem-seaweedfs/blob/992334ba1d8e26fe6bbb9e33feedbf66b4872613/src/Seaweed.php#L210-L230
tystuyfzand/flysystem-seaweedfs
src/Seaweed.php
Seaweed.readStream
public function readStream($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } try { $file = $this->client->get($mapping['fid']); if (!$file) { return false; } return [ 'stream' => $file ]; } catch (SeaweedFSException $e) { return false; } }
php
public function readStream($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } try { $file = $this->client->get($mapping['fid']); if (!$file) { return false; } return [ 'stream' => $file ]; } catch (SeaweedFSException $e) { return false; } }
[ "public", "function", "readStream", "(", "$", "path", ")", "{", "$", "mapping", "=", "$", "this", "->", "mapper", "->", "get", "(", "$", "path", ")", ";", "if", "(", "!", "$", "mapping", ")", "{", "return", "false", ";", "}", "try", "{", "$", "file", "=", "$", "this", "->", "client", "->", "get", "(", "$", "mapping", "[", "'fid'", "]", ")", ";", "if", "(", "!", "$", "file", ")", "{", "return", "false", ";", "}", "return", "[", "'stream'", "=>", "$", "file", "]", ";", "}", "catch", "(", "SeaweedFSException", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Read a file as a stream. @param string $path @return array|false
[ "Read", "a", "file", "as", "a", "stream", "." ]
train
https://github.com/tystuyfzand/flysystem-seaweedfs/blob/992334ba1d8e26fe6bbb9e33feedbf66b4872613/src/Seaweed.php#L239-L259
tystuyfzand/flysystem-seaweedfs
src/Seaweed.php
Seaweed.getUrl
public function getUrl($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } try { $volume = $this->client->lookup($mapping['fid']); return $this->client->buildVolumeUrl($volume->getPublicUrl(), $mapping['fid']); } catch (SeaweedFSException $e) { return false; } }
php
public function getUrl($path) { $mapping = $this->mapper->get($path); if (!$mapping) { return false; } try { $volume = $this->client->lookup($mapping['fid']); return $this->client->buildVolumeUrl($volume->getPublicUrl(), $mapping['fid']); } catch (SeaweedFSException $e) { return false; } }
[ "public", "function", "getUrl", "(", "$", "path", ")", "{", "$", "mapping", "=", "$", "this", "->", "mapper", "->", "get", "(", "$", "path", ")", ";", "if", "(", "!", "$", "mapping", ")", "{", "return", "false", ";", "}", "try", "{", "$", "volume", "=", "$", "this", "->", "client", "->", "lookup", "(", "$", "mapping", "[", "'fid'", "]", ")", ";", "return", "$", "this", "->", "client", "->", "buildVolumeUrl", "(", "$", "volume", "->", "getPublicUrl", "(", ")", ",", "$", "mapping", "[", "'fid'", "]", ")", ";", "}", "catch", "(", "SeaweedFSException", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Get the public URL of a path. @param $path @return string|bool
[ "Get", "the", "public", "URL", "of", "a", "path", "." ]
train
https://github.com/tystuyfzand/flysystem-seaweedfs/blob/992334ba1d8e26fe6bbb9e33feedbf66b4872613/src/Seaweed.php#L325-L339
mothership-ec/composer
src/Composer/Util/SpdxLicense.php
SpdxLicense.getLicenseByIdentifier
public function getLicenseByIdentifier($identifier) { if (!isset($this->licenses[$identifier])) { return; } $license = $this->licenses[$identifier]; // add URL for the license text (it's not included in the json) $license[2] = 'http://spdx.org/licenses/' . $identifier . '#licenseText'; return $license; }
php
public function getLicenseByIdentifier($identifier) { if (!isset($this->licenses[$identifier])) { return; } $license = $this->licenses[$identifier]; // add URL for the license text (it's not included in the json) $license[2] = 'http://spdx.org/licenses/' . $identifier . '#licenseText'; return $license; }
[ "public", "function", "getLicenseByIdentifier", "(", "$", "identifier", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "licenses", "[", "$", "identifier", "]", ")", ")", "{", "return", ";", "}", "$", "license", "=", "$", "this", "->", "licenses", "[", "$", "identifier", "]", ";", "// add URL for the license text (it's not included in the json)", "$", "license", "[", "2", "]", "=", "'http://spdx.org/licenses/'", ".", "$", "identifier", ".", "'#licenseText'", ";", "return", "$", "license", ";", "}" ]
Returns license metadata by license identifier. @param string $identifier @return array|null
[ "Returns", "license", "metadata", "by", "license", "identifier", "." ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Util/SpdxLicense.php#L54-L66
mothership-ec/composer
src/Composer/Util/SpdxLicense.php
SpdxLicense.getIdentifierByName
public function getIdentifierByName($name) { foreach ($this->licenses as $identifier => $licenseData) { if ($licenseData[0] === $name) { // key 0 = fullname return $identifier; } } }
php
public function getIdentifierByName($name) { foreach ($this->licenses as $identifier => $licenseData) { if ($licenseData[0] === $name) { // key 0 = fullname return $identifier; } } }
[ "public", "function", "getIdentifierByName", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "licenses", "as", "$", "identifier", "=>", "$", "licenseData", ")", "{", "if", "(", "$", "licenseData", "[", "0", "]", "===", "$", "name", ")", "{", "// key 0 = fullname", "return", "$", "identifier", ";", "}", "}", "}" ]
Returns the short identifier of a license by full name. @param string $identifier @return string
[ "Returns", "the", "short", "identifier", "of", "a", "license", "by", "full", "name", "." ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Util/SpdxLicense.php#L75-L82
mothership-ec/composer
src/Composer/Util/SpdxLicense.php
SpdxLicense.isValidLicenseString
private function isValidLicenseString($license) { $tokens = array( 'po' => '\(', 'pc' => '\)', 'op' => '(?:or|and)', 'lix' => '(?:NONE|NOASSERTION)', 'lir' => 'LicenseRef-\d+', 'lic' => '[-+_.a-zA-Z0-9]{3,}', 'ws' => '\s+', '_' => '.', ); $next = function () use ($license, $tokens) { static $offset = 0; if ($offset >= strlen($license)) { return null; } foreach ($tokens as $name => $token) { if (false === $r = preg_match('{' . $token . '}', $license, $matches, PREG_OFFSET_CAPTURE, $offset)) { throw new \RuntimeException('Pattern for token %s failed (regex error).', $name); } if ($r === 0) { continue; } if ($matches[0][1] !== $offset) { continue; } $offset += strlen($matches[0][0]); return array($name, $matches[0][0]); } throw new \RuntimeException('At least the last pattern needs to match, but it did not (dot-match-all is missing?).'); }; $open = 0; $require = 1; $lastop = null; while (list($token, $string) = $next()) { switch ($token) { case 'po': if ($open || !$require) { return false; } $open = 1; break; case 'pc': if ($open !== 1 || $require || !$lastop) { return false; } $open = 2; break; case 'op': if ($require || !$open) { return false; } $lastop || $lastop = $string; if ($lastop !== $string) { return false; } $require = 1; break; case 'lix': if ($open) { return false; } goto lir; case 'lic': if (!$this->isValidLicenseIdentifier($string)) { return false; } // Fall-through intended case 'lir': lir: if (!$require) { return false; } $require = 0; break; case 'ws': break; case '_': return false; default: throw new \RuntimeException(sprintf('Unparsed token: %s.', print_r($token, true))); } } return !($open % 2 || $require); }
php
private function isValidLicenseString($license) { $tokens = array( 'po' => '\(', 'pc' => '\)', 'op' => '(?:or|and)', 'lix' => '(?:NONE|NOASSERTION)', 'lir' => 'LicenseRef-\d+', 'lic' => '[-+_.a-zA-Z0-9]{3,}', 'ws' => '\s+', '_' => '.', ); $next = function () use ($license, $tokens) { static $offset = 0; if ($offset >= strlen($license)) { return null; } foreach ($tokens as $name => $token) { if (false === $r = preg_match('{' . $token . '}', $license, $matches, PREG_OFFSET_CAPTURE, $offset)) { throw new \RuntimeException('Pattern for token %s failed (regex error).', $name); } if ($r === 0) { continue; } if ($matches[0][1] !== $offset) { continue; } $offset += strlen($matches[0][0]); return array($name, $matches[0][0]); } throw new \RuntimeException('At least the last pattern needs to match, but it did not (dot-match-all is missing?).'); }; $open = 0; $require = 1; $lastop = null; while (list($token, $string) = $next()) { switch ($token) { case 'po': if ($open || !$require) { return false; } $open = 1; break; case 'pc': if ($open !== 1 || $require || !$lastop) { return false; } $open = 2; break; case 'op': if ($require || !$open) { return false; } $lastop || $lastop = $string; if ($lastop !== $string) { return false; } $require = 1; break; case 'lix': if ($open) { return false; } goto lir; case 'lic': if (!$this->isValidLicenseIdentifier($string)) { return false; } // Fall-through intended case 'lir': lir: if (!$require) { return false; } $require = 0; break; case 'ws': break; case '_': return false; default: throw new \RuntimeException(sprintf('Unparsed token: %s.', print_r($token, true))); } } return !($open % 2 || $require); }
[ "private", "function", "isValidLicenseString", "(", "$", "license", ")", "{", "$", "tokens", "=", "array", "(", "'po'", "=>", "'\\('", ",", "'pc'", "=>", "'\\)'", ",", "'op'", "=>", "'(?:or|and)'", ",", "'lix'", "=>", "'(?:NONE|NOASSERTION)'", ",", "'lir'", "=>", "'LicenseRef-\\d+'", ",", "'lic'", "=>", "'[-+_.a-zA-Z0-9]{3,}'", ",", "'ws'", "=>", "'\\s+'", ",", "'_'", "=>", "'.'", ",", ")", ";", "$", "next", "=", "function", "(", ")", "use", "(", "$", "license", ",", "$", "tokens", ")", "{", "static", "$", "offset", "=", "0", ";", "if", "(", "$", "offset", ">=", "strlen", "(", "$", "license", ")", ")", "{", "return", "null", ";", "}", "foreach", "(", "$", "tokens", "as", "$", "name", "=>", "$", "token", ")", "{", "if", "(", "false", "===", "$", "r", "=", "preg_match", "(", "'{'", ".", "$", "token", ".", "'}'", ",", "$", "license", ",", "$", "matches", ",", "PREG_OFFSET_CAPTURE", ",", "$", "offset", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Pattern for token %s failed (regex error).'", ",", "$", "name", ")", ";", "}", "if", "(", "$", "r", "===", "0", ")", "{", "continue", ";", "}", "if", "(", "$", "matches", "[", "0", "]", "[", "1", "]", "!==", "$", "offset", ")", "{", "continue", ";", "}", "$", "offset", "+=", "strlen", "(", "$", "matches", "[", "0", "]", "[", "0", "]", ")", ";", "return", "array", "(", "$", "name", ",", "$", "matches", "[", "0", "]", "[", "0", "]", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "'At least the last pattern needs to match, but it did not (dot-match-all is missing?).'", ")", ";", "}", ";", "$", "open", "=", "0", ";", "$", "require", "=", "1", ";", "$", "lastop", "=", "null", ";", "while", "(", "list", "(", "$", "token", ",", "$", "string", ")", "=", "$", "next", "(", ")", ")", "{", "switch", "(", "$", "token", ")", "{", "case", "'po'", ":", "if", "(", "$", "open", "||", "!", "$", "require", ")", "{", "return", "false", ";", "}", "$", "open", "=", "1", ";", "break", ";", "case", "'pc'", ":", "if", "(", "$", "open", "!==", "1", "||", "$", "require", "||", "!", "$", "lastop", ")", "{", "return", "false", ";", "}", "$", "open", "=", "2", ";", "break", ";", "case", "'op'", ":", "if", "(", "$", "require", "||", "!", "$", "open", ")", "{", "return", "false", ";", "}", "$", "lastop", "||", "$", "lastop", "=", "$", "string", ";", "if", "(", "$", "lastop", "!==", "$", "string", ")", "{", "return", "false", ";", "}", "$", "require", "=", "1", ";", "break", ";", "case", "'lix'", ":", "if", "(", "$", "open", ")", "{", "return", "false", ";", "}", "goto", "lir", ";", "case", "'lic'", ":", "if", "(", "!", "$", "this", "->", "isValidLicenseIdentifier", "(", "$", "string", ")", ")", "{", "return", "false", ";", "}", "// Fall-through intended", "case", "'lir'", ":", "lir", ":", "if", "(", "!", "$", "require", ")", "{", "return", "false", ";", "}", "$", "require", "=", "0", ";", "break", ";", "case", "'ws'", ":", "break", ";", "case", "'_'", ":", "return", "false", ";", "default", ":", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Unparsed token: %s.'", ",", "print_r", "(", "$", "token", ",", "true", ")", ")", ")", ";", "}", "}", "return", "!", "(", "$", "open", "%", "2", "||", "$", "require", ")", ";", "}" ]
@param string $license @return bool @throws \RuntimeException
[ "@param", "string", "$license" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Util/SpdxLicense.php#L139-L232
andromeda-framework/doctrine
src/Doctrine/Tracy/SqlDumper.php
SqlDumper.dump
public static function dump(string $query, array $params = []) { [$query, $params] = Doctrine\DBAL\SQLParserUtils::expandListParameters($query, $params, []); $parts = explode('?', $query); $output = []; while ($parts && $params) { $output[] = array_shift($parts); $output[] = self::formatParameter(array_shift($params)); } return self::highlightQuery(implode('', array_merge($output, $parts ? : [], $params ? : []))); }
php
public static function dump(string $query, array $params = []) { [$query, $params] = Doctrine\DBAL\SQLParserUtils::expandListParameters($query, $params, []); $parts = explode('?', $query); $output = []; while ($parts && $params) { $output[] = array_shift($parts); $output[] = self::formatParameter(array_shift($params)); } return self::highlightQuery(implode('', array_merge($output, $parts ? : [], $params ? : []))); }
[ "public", "static", "function", "dump", "(", "string", "$", "query", ",", "array", "$", "params", "=", "[", "]", ")", "{", "[", "$", "query", ",", "$", "params", "]", "=", "Doctrine", "\\", "DBAL", "\\", "SQLParserUtils", "::", "expandListParameters", "(", "$", "query", ",", "$", "params", ",", "[", "]", ")", ";", "$", "parts", "=", "explode", "(", "'?'", ",", "$", "query", ")", ";", "$", "output", "=", "[", "]", ";", "while", "(", "$", "parts", "&&", "$", "params", ")", "{", "$", "output", "[", "]", "=", "array_shift", "(", "$", "parts", ")", ";", "$", "output", "[", "]", "=", "self", "::", "formatParameter", "(", "array_shift", "(", "$", "params", ")", ")", ";", "}", "return", "self", "::", "highlightQuery", "(", "implode", "(", "''", ",", "array_merge", "(", "$", "output", ",", "$", "parts", "?", ":", "[", "]", ",", "$", "params", "?", ":", "[", "]", ")", ")", ")", ";", "}" ]
@param string $query @param array $params @return string
[ "@param", "string", "$query", "@param", "array", "$params" ]
train
https://github.com/andromeda-framework/doctrine/blob/46924d91c09e0b9fbe5764518cbad70e467ffad4/src/Doctrine/Tracy/SqlDumper.php#L40-L53
andromeda-framework/doctrine
src/Doctrine/Tracy/SqlDumper.php
SqlDumper.highlightQuery
public static function highlightQuery($sql) { static $keywords1 = 'SELECT|(?:ON\s+DUPLICATE\s+KEY)?UPDATE|INSERT(?:\s+INTO)?|REPLACE(?:\s+INTO)?|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|' . 'LIMIT|OFFSET|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN|TRUNCATE'; static $keywords2 = 'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|[RI]?LIKE|REGEXP|TRUE|FALSE|WITH|INSTANCE\s+OF'; // insert new lines $sql = " $sql "; $sql = preg_replace("#(?<=[\\s,(])($keywords1)(?=[\\s,)])#i", "\n\$1", $sql); // reduce spaces $sql = preg_replace('#[ \t]{2,}#', ' ', $sql); $sql = wordwrap($sql, 100); $sql = preg_replace('#([ \t]*\r?\n){2,}#', "\n", $sql); // syntax highlight $sql = htmlspecialchars($sql, ENT_IGNORE, 'UTF-8'); $sql = preg_replace_callback("#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is", function ($matches) { if (!empty($matches[1])) { // comment return '<em style="color:gray">' . $matches[1] . '</em>'; } elseif (!empty($matches[2])) { // error return '<strong style="color:red">' . $matches[2] . '</strong>'; } elseif (!empty($matches[3])) { // most important keywords return '<strong style="color:blue">' . $matches[3] . '</strong>'; } elseif (!empty($matches[4])) { // other keywords return '<strong style="color:green">' . $matches[4] . '</strong>'; } }, $sql); return '<pre class="dump">' . trim($sql) . "</pre>\n"; }
php
public static function highlightQuery($sql) { static $keywords1 = 'SELECT|(?:ON\s+DUPLICATE\s+KEY)?UPDATE|INSERT(?:\s+INTO)?|REPLACE(?:\s+INTO)?|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|' . 'LIMIT|OFFSET|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN|TRUNCATE'; static $keywords2 = 'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|[RI]?LIKE|REGEXP|TRUE|FALSE|WITH|INSTANCE\s+OF'; // insert new lines $sql = " $sql "; $sql = preg_replace("#(?<=[\\s,(])($keywords1)(?=[\\s,)])#i", "\n\$1", $sql); // reduce spaces $sql = preg_replace('#[ \t]{2,}#', ' ', $sql); $sql = wordwrap($sql, 100); $sql = preg_replace('#([ \t]*\r?\n){2,}#', "\n", $sql); // syntax highlight $sql = htmlspecialchars($sql, ENT_IGNORE, 'UTF-8'); $sql = preg_replace_callback("#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is", function ($matches) { if (!empty($matches[1])) { // comment return '<em style="color:gray">' . $matches[1] . '</em>'; } elseif (!empty($matches[2])) { // error return '<strong style="color:red">' . $matches[2] . '</strong>'; } elseif (!empty($matches[3])) { // most important keywords return '<strong style="color:blue">' . $matches[3] . '</strong>'; } elseif (!empty($matches[4])) { // other keywords return '<strong style="color:green">' . $matches[4] . '</strong>'; } }, $sql); return '<pre class="dump">' . trim($sql) . "</pre>\n"; }
[ "public", "static", "function", "highlightQuery", "(", "$", "sql", ")", "{", "static", "$", "keywords1", "=", "'SELECT|(?:ON\\s+DUPLICATE\\s+KEY)?UPDATE|INSERT(?:\\s+INTO)?|REPLACE(?:\\s+INTO)?|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\\s+BY|ORDER\\s+BY|'", ".", "'LIMIT|OFFSET|SET|VALUES|LEFT\\s+JOIN|INNER\\s+JOIN|TRUNCATE'", ";", "static", "$", "keywords2", "=", "'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|[RI]?LIKE|REGEXP|TRUE|FALSE|WITH|INSTANCE\\s+OF'", ";", "// insert new lines", "$", "sql", "=", "\" $sql \"", ";", "$", "sql", "=", "preg_replace", "(", "\"#(?<=[\\\\s,(])($keywords1)(?=[\\\\s,)])#i\"", ",", "\"\\n\\$1\"", ",", "$", "sql", ")", ";", "// reduce spaces", "$", "sql", "=", "preg_replace", "(", "'#[ \\t]{2,}#'", ",", "' '", ",", "$", "sql", ")", ";", "$", "sql", "=", "wordwrap", "(", "$", "sql", ",", "100", ")", ";", "$", "sql", "=", "preg_replace", "(", "'#([ \\t]*\\r?\\n){2,}#'", ",", "\"\\n\"", ",", "$", "sql", ")", ";", "// syntax highlight", "$", "sql", "=", "htmlspecialchars", "(", "$", "sql", ",", "ENT_IGNORE", ",", "'UTF-8'", ")", ";", "$", "sql", "=", "preg_replace_callback", "(", "\"#(/\\\\*.+?\\\\*/)|(\\\\*\\\\*.+?\\\\*\\\\*)|(?<=[\\\\s,(])($keywords1)(?=[\\\\s,)])|(?<=[\\\\s,(=])($keywords2)(?=[\\\\s,)=])#is\"", ",", "function", "(", "$", "matches", ")", "{", "if", "(", "!", "empty", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "// comment", "return", "'<em style=\"color:gray\">'", ".", "$", "matches", "[", "1", "]", ".", "'</em>'", ";", "}", "elseif", "(", "!", "empty", "(", "$", "matches", "[", "2", "]", ")", ")", "{", "// error", "return", "'<strong style=\"color:red\">'", ".", "$", "matches", "[", "2", "]", ".", "'</strong>'", ";", "}", "elseif", "(", "!", "empty", "(", "$", "matches", "[", "3", "]", ")", ")", "{", "// most important keywords", "return", "'<strong style=\"color:blue\">'", ".", "$", "matches", "[", "3", "]", ".", "'</strong>'", ";", "}", "elseif", "(", "!", "empty", "(", "$", "matches", "[", "4", "]", ")", ")", "{", "// other keywords", "return", "'<strong style=\"color:green\">'", ".", "$", "matches", "[", "4", "]", ".", "'</strong>'", ";", "}", "}", ",", "$", "sql", ")", ";", "return", "'<pre class=\"dump\">'", ".", "trim", "(", "$", "sql", ")", ".", "\"</pre>\\n\"", ";", "}" ]
Returns syntax highlighted SQL command. @link https://github.com/nette/database/blob/667143b2d5b940f78c8dc9212f95b1bbc033c6a3/src/Database/Helpers.php#L75-L138 @author David Grudl @param string $sql @return string
[ "Returns", "syntax", "highlighted", "SQL", "command", "." ]
train
https://github.com/andromeda-framework/doctrine/blob/46924d91c09e0b9fbe5764518cbad70e467ffad4/src/Doctrine/Tracy/SqlDumper.php#L66-L100
andromeda-framework/doctrine
src/Doctrine/Tracy/SqlDumper.php
SqlDumper.formatParameter
private static function formatParameter($param): string { if (is_int($param) || is_float($param)) { return (string) $param; } elseif (is_string($param)) { return "'" . addslashes($param) . "'"; } elseif (is_null($param)) { return "NULL"; } elseif (is_bool($param)) { return $param ? "TRUE" : "FALSE"; } elseif (is_array($param)) { $formatted = []; foreach ($param as $value) { $formatted[] = self::formatParameter($value); } return implode(', ', $formatted); } elseif ($param instanceof \Datetime) { return "'" . $param->format('Y-m-d H:i:s') . "'"; } elseif (is_object($param)) { return get_class($param) . (method_exists($param, 'getId') ? '(' . $param->getId() . ')' : ''); } else { return @"'$param'"; // @ - conversion of something to string } }
php
private static function formatParameter($param): string { if (is_int($param) || is_float($param)) { return (string) $param; } elseif (is_string($param)) { return "'" . addslashes($param) . "'"; } elseif (is_null($param)) { return "NULL"; } elseif (is_bool($param)) { return $param ? "TRUE" : "FALSE"; } elseif (is_array($param)) { $formatted = []; foreach ($param as $value) { $formatted[] = self::formatParameter($value); } return implode(', ', $formatted); } elseif ($param instanceof \Datetime) { return "'" . $param->format('Y-m-d H:i:s') . "'"; } elseif (is_object($param)) { return get_class($param) . (method_exists($param, 'getId') ? '(' . $param->getId() . ')' : ''); } else { return @"'$param'"; // @ - conversion of something to string } }
[ "private", "static", "function", "formatParameter", "(", "$", "param", ")", ":", "string", "{", "if", "(", "is_int", "(", "$", "param", ")", "||", "is_float", "(", "$", "param", ")", ")", "{", "return", "(", "string", ")", "$", "param", ";", "}", "elseif", "(", "is_string", "(", "$", "param", ")", ")", "{", "return", "\"'\"", ".", "addslashes", "(", "$", "param", ")", ".", "\"'\"", ";", "}", "elseif", "(", "is_null", "(", "$", "param", ")", ")", "{", "return", "\"NULL\"", ";", "}", "elseif", "(", "is_bool", "(", "$", "param", ")", ")", "{", "return", "$", "param", "?", "\"TRUE\"", ":", "\"FALSE\"", ";", "}", "elseif", "(", "is_array", "(", "$", "param", ")", ")", "{", "$", "formatted", "=", "[", "]", ";", "foreach", "(", "$", "param", "as", "$", "value", ")", "{", "$", "formatted", "[", "]", "=", "self", "::", "formatParameter", "(", "$", "value", ")", ";", "}", "return", "implode", "(", "', '", ",", "$", "formatted", ")", ";", "}", "elseif", "(", "$", "param", "instanceof", "\\", "Datetime", ")", "{", "return", "\"'\"", ".", "$", "param", "->", "format", "(", "'Y-m-d H:i:s'", ")", ".", "\"'\"", ";", "}", "elseif", "(", "is_object", "(", "$", "param", ")", ")", "{", "return", "get_class", "(", "$", "param", ")", ".", "(", "method_exists", "(", "$", "param", ",", "'getId'", ")", "?", "'('", ".", "$", "param", "->", "getId", "(", ")", ".", "')'", ":", "''", ")", ";", "}", "else", "{", "return", "@", "\"'$param'\"", ";", "// @ - conversion of something to string", "}", "}" ]
@param mixed $param @return string
[ "@param", "mixed", "$param" ]
train
https://github.com/andromeda-framework/doctrine/blob/46924d91c09e0b9fbe5764518cbad70e467ffad4/src/Doctrine/Tracy/SqlDumper.php#L108-L138
antaresproject/notifications
src/Listener/NotificationsListener.php
NotificationsListener.listen
public function listen() { $notifications = $this->repository->findSendable()->toArray(); foreach ($notifications as $notification) { $this->listenNotificationsEvents($notification); } }
php
public function listen() { $notifications = $this->repository->findSendable()->toArray(); foreach ($notifications as $notification) { $this->listenNotificationsEvents($notification); } }
[ "public", "function", "listen", "(", ")", "{", "$", "notifications", "=", "$", "this", "->", "repository", "->", "findSendable", "(", ")", "->", "toArray", "(", ")", ";", "foreach", "(", "$", "notifications", "as", "$", "notification", ")", "{", "$", "this", "->", "listenNotificationsEvents", "(", "$", "notification", ")", ";", "}", "}" ]
Listening for notifications
[ "Listening", "for", "notifications" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Listener/NotificationsListener.php#L62-L69
antaresproject/notifications
src/Listener/NotificationsListener.php
NotificationsListener.listenNotificationsEvents
protected function listenNotificationsEvents(array $notification) { $events = Arr::get($notification, 'event'); if($events === null && isset($notification['classname'])) { $events = app()->make($notification['classname'])->getEvents(); } foreach ((array) $events as $event) { $this->runNotificationListener($event, $notification); } }
php
protected function listenNotificationsEvents(array $notification) { $events = Arr::get($notification, 'event'); if($events === null && isset($notification['classname'])) { $events = app()->make($notification['classname'])->getEvents(); } foreach ((array) $events as $event) { $this->runNotificationListener($event, $notification); } }
[ "protected", "function", "listenNotificationsEvents", "(", "array", "$", "notification", ")", "{", "$", "events", "=", "Arr", "::", "get", "(", "$", "notification", ",", "'event'", ")", ";", "if", "(", "$", "events", "===", "null", "&&", "isset", "(", "$", "notification", "[", "'classname'", "]", ")", ")", "{", "$", "events", "=", "app", "(", ")", "->", "make", "(", "$", "notification", "[", "'classname'", "]", ")", "->", "getEvents", "(", ")", ";", "}", "foreach", "(", "(", "array", ")", "$", "events", "as", "$", "event", ")", "{", "$", "this", "->", "runNotificationListener", "(", "$", "event", ",", "$", "notification", ")", ";", "}", "}" ]
Runs notification events. @param array $notification
[ "Runs", "notification", "events", "." ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Listener/NotificationsListener.php#L76-L87
antaresproject/notifications
src/Listener/NotificationsListener.php
NotificationsListener.runNotificationListener
protected function runNotificationListener(string $event, array $notification) { app('events')->listen($event, function(array $variables = null, array $recipients = null) use($notification) { $this->eventDispatcher->run($notification, $variables, $recipients); }); }
php
protected function runNotificationListener(string $event, array $notification) { app('events')->listen($event, function(array $variables = null, array $recipients = null) use($notification) { $this->eventDispatcher->run($notification, $variables, $recipients); }); }
[ "protected", "function", "runNotificationListener", "(", "string", "$", "event", ",", "array", "$", "notification", ")", "{", "app", "(", "'events'", ")", "->", "listen", "(", "$", "event", ",", "function", "(", "array", "$", "variables", "=", "null", ",", "array", "$", "recipients", "=", "null", ")", "use", "(", "$", "notification", ")", "{", "$", "this", "->", "eventDispatcher", "->", "run", "(", "$", "notification", ",", "$", "variables", ",", "$", "recipients", ")", ";", "}", ")", ";", "}" ]
Runs notification listener. @param string $event @param array $notification
[ "Runs", "notification", "listener", "." ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Listener/NotificationsListener.php#L95-L100
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Helper/Char.php
Char.fromHex
public static function fromHex($hex) { if(strlen($hex) != 2) { throw new Exception("given parameter '" . $hex . "' is not a valid hexadecimal number"); } return new self(chr(hexdec($hex))); }
php
public static function fromHex($hex) { if(strlen($hex) != 2) { throw new Exception("given parameter '" . $hex . "' is not a valid hexadecimal number"); } return new self(chr(hexdec($hex))); }
[ "public", "static", "function", "fromHex", "(", "$", "hex", ")", "{", "if", "(", "strlen", "(", "$", "hex", ")", "!=", "2", ")", "{", "throw", "new", "Exception", "(", "\"given parameter '\"", ".", "$", "hex", ".", "\"' is not a valid hexadecimal number\"", ")", ";", "}", "return", "new", "self", "(", "chr", "(", "hexdec", "(", "$", "hex", ")", ")", ")", ";", "}" ]
Returns the Char based on a given hex value. @param string $hex @throws Exception @return Char
[ "Returns", "the", "Char", "based", "on", "a", "given", "hex", "value", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Helper/Char.php#L231-L239
technote-space/wordpress-plugin-base
src/classes/models/lib/filter.php
Filter.initialize
protected function initialize() { foreach ( $this->apply_filters( 'filter', $this->app->config->load( 'filter' ) ) as $class => $tags ) { $this->register_class_filter( $class, $tags ); } }
php
protected function initialize() { foreach ( $this->apply_filters( 'filter', $this->app->config->load( 'filter' ) ) as $class => $tags ) { $this->register_class_filter( $class, $tags ); } }
[ "protected", "function", "initialize", "(", ")", "{", "foreach", "(", "$", "this", "->", "apply_filters", "(", "'filter'", ",", "$", "this", "->", "app", "->", "config", "->", "load", "(", "'filter'", ")", ")", "as", "$", "class", "=>", "$", "tags", ")", "{", "$", "this", "->", "register_class_filter", "(", "$", "class", ",", "$", "tags", ")", ";", "}", "}" ]
initialize @since 2.4.2 Improved: change timing to load filter target instance
[ "initialize" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/filter.php#L37-L41
technote-space/wordpress-plugin-base
src/classes/models/lib/filter.php
Filter.get_target_app
private function get_target_app( $class ) { if ( ! isset( $this->_target_app[ $class ] ) ) { $app = false; if ( strpos( $class, '->' ) !== false ) { $app = $this->app; $exploded = explode( '->', $class ); foreach ( $exploded as $property ) { if ( isset( $app->$property ) ) { $app = $app->$property; } else { $app = false; break; } } } else { if ( isset( $this->app->$class ) ) { $app = $this->app->$class; } } if ( false === $app ) { if ( class_exists( $class ) && is_subclass_of( $class, '\Technote\Interfaces\Singleton' ) ) { try { /** @var \Technote\Interfaces\Singleton $class */ $app = $class::get_instance( $this->app ); } catch ( \Exception $e ) { } } } $this->_target_app[ $class ] = $app; } return $this->_target_app[ $class ]; }
php
private function get_target_app( $class ) { if ( ! isset( $this->_target_app[ $class ] ) ) { $app = false; if ( strpos( $class, '->' ) !== false ) { $app = $this->app; $exploded = explode( '->', $class ); foreach ( $exploded as $property ) { if ( isset( $app->$property ) ) { $app = $app->$property; } else { $app = false; break; } } } else { if ( isset( $this->app->$class ) ) { $app = $this->app->$class; } } if ( false === $app ) { if ( class_exists( $class ) && is_subclass_of( $class, '\Technote\Interfaces\Singleton' ) ) { try { /** @var \Technote\Interfaces\Singleton $class */ $app = $class::get_instance( $this->app ); } catch ( \Exception $e ) { } } } $this->_target_app[ $class ] = $app; } return $this->_target_app[ $class ]; }
[ "private", "function", "get_target_app", "(", "$", "class", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_target_app", "[", "$", "class", "]", ")", ")", "{", "$", "app", "=", "false", ";", "if", "(", "strpos", "(", "$", "class", ",", "'->'", ")", "!==", "false", ")", "{", "$", "app", "=", "$", "this", "->", "app", ";", "$", "exploded", "=", "explode", "(", "'->'", ",", "$", "class", ")", ";", "foreach", "(", "$", "exploded", "as", "$", "property", ")", "{", "if", "(", "isset", "(", "$", "app", "->", "$", "property", ")", ")", "{", "$", "app", "=", "$", "app", "->", "$", "property", ";", "}", "else", "{", "$", "app", "=", "false", ";", "break", ";", "}", "}", "}", "else", "{", "if", "(", "isset", "(", "$", "this", "->", "app", "->", "$", "class", ")", ")", "{", "$", "app", "=", "$", "this", "->", "app", "->", "$", "class", ";", "}", "}", "if", "(", "false", "===", "$", "app", ")", "{", "if", "(", "class_exists", "(", "$", "class", ")", "&&", "is_subclass_of", "(", "$", "class", ",", "'\\Technote\\Interfaces\\Singleton'", ")", ")", "{", "try", "{", "/** @var \\Technote\\Interfaces\\Singleton $class */", "$", "app", "=", "$", "class", "::", "get_instance", "(", "$", "this", "->", "app", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "}", "}", "$", "this", "->", "_target_app", "[", "$", "class", "]", "=", "$", "app", ";", "}", "return", "$", "this", "->", "_target_app", "[", "$", "class", "]", ";", "}" ]
@since 2.4.2 @param string $class @return false|\Technote|\Technote\Interfaces\Singleton
[ "@since", "2", ".", "4", ".", "2" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/filter.php#L88-L120
technote-space/wordpress-plugin-base
src/classes/models/lib/filter.php
Filter.get_filter_params
private function get_filter_params( $params ) { $priority = 10; $accepted_args = 100; if ( is_array( $params ) ) { if ( count( $params ) >= 1 ) { $priority = $params[0]; } if ( count( $params ) >= 2 ) { $accepted_args = $params[1]; } } return [ $priority, $accepted_args ]; }
php
private function get_filter_params( $params ) { $priority = 10; $accepted_args = 100; if ( is_array( $params ) ) { if ( count( $params ) >= 1 ) { $priority = $params[0]; } if ( count( $params ) >= 2 ) { $accepted_args = $params[1]; } } return [ $priority, $accepted_args ]; }
[ "private", "function", "get_filter_params", "(", "$", "params", ")", "{", "$", "priority", "=", "10", ";", "$", "accepted_args", "=", "100", ";", "if", "(", "is_array", "(", "$", "params", ")", ")", "{", "if", "(", "count", "(", "$", "params", ")", ">=", "1", ")", "{", "$", "priority", "=", "$", "params", "[", "0", "]", ";", "}", "if", "(", "count", "(", "$", "params", ")", ">=", "2", ")", "{", "$", "accepted_args", "=", "$", "params", "[", "1", "]", ";", "}", "}", "return", "[", "$", "priority", ",", "$", "accepted_args", "]", ";", "}" ]
@since 2.4.2 @param array $params @return array
[ "@since", "2", ".", "4", ".", "2" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/filter.php#L129-L142
technote-space/wordpress-plugin-base
src/classes/models/lib/filter.php
Filter.call_filter_callback
private function call_filter_callback( $class, $method, $args ) { $result = empty( $args ) ? null : reset( $args ); $app = $this->get_target_app( $class ); if ( empty( $app ) ) { return $result; } if ( $app->is_filter_callable( $method ) ) { return $app->filter_callback( $method, $args ); } return $result; }
php
private function call_filter_callback( $class, $method, $args ) { $result = empty( $args ) ? null : reset( $args ); $app = $this->get_target_app( $class ); if ( empty( $app ) ) { return $result; } if ( $app->is_filter_callable( $method ) ) { return $app->filter_callback( $method, $args ); } return $result; }
[ "private", "function", "call_filter_callback", "(", "$", "class", ",", "$", "method", ",", "$", "args", ")", "{", "$", "result", "=", "empty", "(", "$", "args", ")", "?", "null", ":", "reset", "(", "$", "args", ")", ";", "$", "app", "=", "$", "this", "->", "get_target_app", "(", "$", "class", ")", ";", "if", "(", "empty", "(", "$", "app", ")", ")", "{", "return", "$", "result", ";", "}", "if", "(", "$", "app", "->", "is_filter_callable", "(", "$", "method", ")", ")", "{", "return", "$", "app", "->", "filter_callback", "(", "$", "method", ",", "$", "args", ")", ";", "}", "return", "$", "result", ";", "}" ]
@since 2.4.2 @param string $class @param string $method @param array $args @return mixed
[ "@since", "2", ".", "4", ".", "2" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/filter.php#L153-L165
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.discoverFields
public function discoverFields() { if (!empty($this->fields)) { return; // Already configured. } $sm = $this->db()->getSchemaManager(); $columns = $sm->listTableColumns($this->table); foreach ($columns as $column) { $this->fields[$column->getName()] = array( 'name' => $column->getName(), 'type' => $column->getType(), ); } try { $this->fks = $sm->listTableForeignKeys($this->table); } catch (\DBALException $e) { //Platform does not support foreign keys. $this->fks = array(); } }
php
public function discoverFields() { if (!empty($this->fields)) { return; // Already configured. } $sm = $this->db()->getSchemaManager(); $columns = $sm->listTableColumns($this->table); foreach ($columns as $column) { $this->fields[$column->getName()] = array( 'name' => $column->getName(), 'type' => $column->getType(), ); } try { $this->fks = $sm->listTableForeignKeys($this->table); } catch (\DBALException $e) { //Platform does not support foreign keys. $this->fks = array(); } }
[ "public", "function", "discoverFields", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "fields", ")", ")", "{", "return", ";", "// Already configured.", "}", "$", "sm", "=", "$", "this", "->", "db", "(", ")", "->", "getSchemaManager", "(", ")", ";", "$", "columns", "=", "$", "sm", "->", "listTableColumns", "(", "$", "this", "->", "table", ")", ";", "foreach", "(", "$", "columns", "as", "$", "column", ")", "{", "$", "this", "->", "fields", "[", "$", "column", "->", "getName", "(", ")", "]", "=", "array", "(", "'name'", "=>", "$", "column", "->", "getName", "(", ")", ",", "'type'", "=>", "$", "column", "->", "getType", "(", ")", ",", ")", ";", "}", "try", "{", "$", "this", "->", "fks", "=", "$", "sm", "->", "listTableForeignKeys", "(", "$", "this", "->", "table", ")", ";", "}", "catch", "(", "\\", "DBALException", "$", "e", ")", "{", "//Platform does not support foreign keys.", "$", "this", "->", "fks", "=", "array", "(", ")", ";", "}", "}" ]
Gets info of the fields from the table.
[ "Gets", "info", "of", "the", "fields", "from", "the", "table", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L25-L45
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.setField
public function setField($name, $value) { if (isset($this->fields[$name])) { $this->isDirty = TRUE; return $this->record[$name] = $value; } throw new \Exception('Not a valid Field for Set ' . $name); }
php
public function setField($name, $value) { if (isset($this->fields[$name])) { $this->isDirty = TRUE; return $this->record[$name] = $value; } throw new \Exception('Not a valid Field for Set ' . $name); }
[ "public", "function", "setField", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "fields", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "isDirty", "=", "TRUE", ";", "return", "$", "this", "->", "record", "[", "$", "name", "]", "=", "$", "value", ";", "}", "throw", "new", "\\", "Exception", "(", "'Not a valid Field for Set '", ".", "$", "name", ")", ";", "}" ]
Sets a field to the record. @param $name @param $value @return mixed @throws \Exception
[ "Sets", "a", "field", "to", "the", "record", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L88-L95
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.getField
public function getField($name) { if (isset($this->fields[$name])) { return $this->record[$name]; } if (isset($this->fetchedRecord[$name])) { return $this->fetchedRecord[$name]; } throw new \Exception('Not a valid Field for Get ' . $name); }
php
public function getField($name) { if (isset($this->fields[$name])) { return $this->record[$name]; } if (isset($this->fetchedRecord[$name])) { return $this->fetchedRecord[$name]; } throw new \Exception('Not a valid Field for Get ' . $name); }
[ "public", "function", "getField", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "fields", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "record", "[", "$", "name", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "fetchedRecord", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "fetchedRecord", "[", "$", "name", "]", ";", "}", "throw", "new", "\\", "Exception", "(", "'Not a valid Field for Get '", ".", "$", "name", ")", ";", "}" ]
Gets a Field from Record. If the field is not in record will check in fetchedRecord, fetched record may have some fields from the last query that you will need, like related records. @param $name @return mixed @throws \Exception
[ "Gets", "a", "Field", "from", "Record", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L107-L117
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.insert
public function insert() { $this->db()->insert($this->table, $this->record); $id = $this->db()->lastInsertId(); $this->record[$this->id_name] = $id; $this->isDirty = FALSE; return $this; }
php
public function insert() { $this->db()->insert($this->table, $this->record); $id = $this->db()->lastInsertId(); $this->record[$this->id_name] = $id; $this->isDirty = FALSE; return $this; }
[ "public", "function", "insert", "(", ")", "{", "$", "this", "->", "db", "(", ")", "->", "insert", "(", "$", "this", "->", "table", ",", "$", "this", "->", "record", ")", ";", "$", "id", "=", "$", "this", "->", "db", "(", ")", "->", "lastInsertId", "(", ")", ";", "$", "this", "->", "record", "[", "$", "this", "->", "id_name", "]", "=", "$", "id", ";", "$", "this", "->", "isDirty", "=", "FALSE", ";", "return", "$", "this", ";", "}" ]
Inserts the record. @return $this
[ "Inserts", "the", "record", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L124-L131
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.update
public function update() { $this->db()->update($this->table, $this->record, $this->identifier()); $this->isDirty = FALSE; return $this; }
php
public function update() { $this->db()->update($this->table, $this->record, $this->identifier()); $this->isDirty = FALSE; return $this; }
[ "public", "function", "update", "(", ")", "{", "$", "this", "->", "db", "(", ")", "->", "update", "(", "$", "this", "->", "table", ",", "$", "this", "->", "record", ",", "$", "this", "->", "identifier", "(", ")", ")", ";", "$", "this", "->", "isDirty", "=", "FALSE", ";", "return", "$", "this", ";", "}" ]
Updates the record. @return $this
[ "Updates", "the", "record", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L138-L143
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.delete
public function delete() { if ($this->isNew()) { throw new \Exception('ID is not setted for Delete'); } $this->db()->delete($this->table, $this->identifier()); $this->isDeleted = TRUE; return $this; }
php
public function delete() { if ($this->isNew()) { throw new \Exception('ID is not setted for Delete'); } $this->db()->delete($this->table, $this->identifier()); $this->isDeleted = TRUE; return $this; }
[ "public", "function", "delete", "(", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'ID is not setted for Delete'", ")", ";", "}", "$", "this", "->", "db", "(", ")", "->", "delete", "(", "$", "this", "->", "table", ",", "$", "this", "->", "identifier", "(", ")", ")", ";", "$", "this", "->", "isDeleted", "=", "TRUE", ";", "return", "$", "this", ";", "}" ]
Deletes the record. @return $this @throws \Exception
[ "Deletes", "the", "record", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L168-L177
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.identifier
public function identifier() { if (empty($this->record[$this->id_name])) { return FALSE; } return array($this->id_name => $this->record[$this->id_name]); }
php
public function identifier() { if (empty($this->record[$this->id_name])) { return FALSE; } return array($this->id_name => $this->record[$this->id_name]); }
[ "public", "function", "identifier", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "record", "[", "$", "this", "->", "id_name", "]", ")", ")", "{", "return", "FALSE", ";", "}", "return", "array", "(", "$", "this", "->", "id_name", "=>", "$", "this", "->", "record", "[", "$", "this", "->", "id_name", "]", ")", ";", "}" ]
Provides the Id in array format column-value. False if is a new object. @return array|bool
[ "Provides", "the", "Id", "in", "array", "format", "column", "-", "value", ".", "False", "if", "is", "a", "new", "object", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L207-L213
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.getId
public function getId() { if (empty($this->record[$this->id_name])) { return FALSE; } return $this->record[$this->id_name]; }
php
public function getId() { if (empty($this->record[$this->id_name])) { return FALSE; } return $this->record[$this->id_name]; }
[ "public", "function", "getId", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "record", "[", "$", "this", "->", "id_name", "]", ")", ")", "{", "return", "FALSE", ";", "}", "return", "$", "this", "->", "record", "[", "$", "this", "->", "id_name", "]", ";", "}" ]
Gets the ID value or false. @return mixed ID Value or false.
[ "Gets", "the", "ID", "value", "or", "false", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L220-L226
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.setRecord
public function setRecord($record) { $this->resetObject(); $newRecord = array(); foreach ($this->fields as $field_name => $field) { if (!empty($record[$field_name])) { $newRecord[$field_name] = $record[$field_name]; } else { $newRecord[$field_name] = ''; //Adds the field but with empty string. } } $this->record = $newRecord; $this->fetchedRecord = $record; return $this; }
php
public function setRecord($record) { $this->resetObject(); $newRecord = array(); foreach ($this->fields as $field_name => $field) { if (!empty($record[$field_name])) { $newRecord[$field_name] = $record[$field_name]; } else { $newRecord[$field_name] = ''; //Adds the field but with empty string. } } $this->record = $newRecord; $this->fetchedRecord = $record; return $this; }
[ "public", "function", "setRecord", "(", "$", "record", ")", "{", "$", "this", "->", "resetObject", "(", ")", ";", "$", "newRecord", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "field_name", "=>", "$", "field", ")", "{", "if", "(", "!", "empty", "(", "$", "record", "[", "$", "field_name", "]", ")", ")", "{", "$", "newRecord", "[", "$", "field_name", "]", "=", "$", "record", "[", "$", "field_name", "]", ";", "}", "else", "{", "$", "newRecord", "[", "$", "field_name", "]", "=", "''", ";", "//Adds the field but with empty string.", "}", "}", "$", "this", "->", "record", "=", "$", "newRecord", ";", "$", "this", "->", "fetchedRecord", "=", "$", "record", ";", "return", "$", "this", ";", "}" ]
Sets the internal record with a new record. @param $record @return \Towel\Model\BaseModel
[ "Sets", "the", "internal", "record", "with", "a", "new", "record", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L244-L259
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.mergeRecord
public function mergeRecord($record) { if ($this->isNew()) { throw new \Exception('Can not merge, is new'); } foreach ($this->fields as $field_name => $field) { if (!empty($record[$field_name])) { $this->record[$field_name] = $record[$field_name]; } $this->isDirty = TRUE; } return $this; }
php
public function mergeRecord($record) { if ($this->isNew()) { throw new \Exception('Can not merge, is new'); } foreach ($this->fields as $field_name => $field) { if (!empty($record[$field_name])) { $this->record[$field_name] = $record[$field_name]; } $this->isDirty = TRUE; } return $this; }
[ "public", "function", "mergeRecord", "(", "$", "record", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Can not merge, is new'", ")", ";", "}", "foreach", "(", "$", "this", "->", "fields", "as", "$", "field_name", "=>", "$", "field", ")", "{", "if", "(", "!", "empty", "(", "$", "record", "[", "$", "field_name", "]", ")", ")", "{", "$", "this", "->", "record", "[", "$", "field_name", "]", "=", "$", "record", "[", "$", "field_name", "]", ";", "}", "$", "this", "->", "isDirty", "=", "TRUE", ";", "}", "return", "$", "this", ";", "}" ]
Update partial values of the record and keep the current non modified values. @param $record @return $this @throws \Exception
[ "Update", "partial", "values", "of", "the", "record", "and", "keep", "the", "current", "non", "modified", "values", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L270-L282
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.fetchOne
public function fetchOne($sql, $params = array()) { $result = $this->db()->fetchAssoc($sql, $params); if (!empty($result)) { $this->setRecord($result); return $this; } return FALSE; }
php
public function fetchOne($sql, $params = array()) { $result = $this->db()->fetchAssoc($sql, $params); if (!empty($result)) { $this->setRecord($result); return $this; } return FALSE; }
[ "public", "function", "fetchOne", "(", "$", "sql", ",", "$", "params", "=", "array", "(", ")", ")", "{", "$", "result", "=", "$", "this", "->", "db", "(", ")", "->", "fetchAssoc", "(", "$", "sql", ",", "$", "params", ")", ";", "if", "(", "!", "empty", "(", "$", "result", ")", ")", "{", "$", "this", "->", "setRecord", "(", "$", "result", ")", ";", "return", "$", "this", ";", "}", "return", "FALSE", ";", "}" ]
Fetchs one record with the given query. If success sets the record in the current object and return $this. If fails return false. @param $sql @param $params @return The current instance with the record setted internally.
[ "Fetchs", "one", "record", "with", "the", "given", "query", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L304-L314
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.findByFieldWithoutFetch
public function findByFieldWithoutFetch($field_name, $value, $operator = '=') { $query = $this->db()->createQueryBuilder(); $query->select('t.*') ->from($this->table, 't') ->where("$field_name $operator ?") ->setParameter(0, $value); return $query->execute(); }
php
public function findByFieldWithoutFetch($field_name, $value, $operator = '=') { $query = $this->db()->createQueryBuilder(); $query->select('t.*') ->from($this->table, 't') ->where("$field_name $operator ?") ->setParameter(0, $value); return $query->execute(); }
[ "public", "function", "findByFieldWithoutFetch", "(", "$", "field_name", ",", "$", "value", ",", "$", "operator", "=", "'='", ")", "{", "$", "query", "=", "$", "this", "->", "db", "(", ")", "->", "createQueryBuilder", "(", ")", ";", "$", "query", "->", "select", "(", "'t.*'", ")", "->", "from", "(", "$", "this", "->", "table", ",", "'t'", ")", "->", "where", "(", "\"$field_name $operator ?\"", ")", "->", "setParameter", "(", "0", ",", "$", "value", ")", ";", "return", "$", "query", "->", "execute", "(", ")", ";", "}" ]
Finds into table by any given field. @param $field_name @param $value @param $operator : A valid SQL operator for the comparison =, >, <, LIKE, IN, NOT IN. By default = @return PDOStatement : PDOStatement with results.
[ "Finds", "into", "table", "by", "any", "given", "field", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L363-L371
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.findByField
public function findByField($field_name, $value, $operator = '=') { $results = $this->findByFieldWithoutFetch($field_name, $value, $operator); $return = $this->hydrate($results); return $return; }
php
public function findByField($field_name, $value, $operator = '=') { $results = $this->findByFieldWithoutFetch($field_name, $value, $operator); $return = $this->hydrate($results); return $return; }
[ "public", "function", "findByField", "(", "$", "field_name", ",", "$", "value", ",", "$", "operator", "=", "'='", ")", "{", "$", "results", "=", "$", "this", "->", "findByFieldWithoutFetch", "(", "$", "field_name", ",", "$", "value", ",", "$", "operator", ")", ";", "$", "return", "=", "$", "this", "->", "hydrate", "(", "$", "results", ")", ";", "return", "$", "return", ";", "}" ]
Finds into table by any given field. @param $field_name @param $value @param $operator : A valid SQL operator for the comparison =, >, <, LIKE, IN, NOT IN. By default = @return Array of Model Objects .
[ "Finds", "into", "table", "by", "any", "given", "field", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L383-L388
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.hydrate
public function hydrate(PDOStatement $results) { if (method_exists($this, 'preHydrate')) { $results = $this->preHydrate($results); } $return = array(); if ($results) { $arrayResults = $results->fetchAll(); foreach ($arrayResults as $arrayResult) { $className = get_class($this); $object = new $className(); $return[$arrayResult[$this->id_name]] = $object->setRecord($arrayResult); } } if (method_exists($this, 'postHydrate')) { $return = $this->preHydrate($return); } return $return; }
php
public function hydrate(PDOStatement $results) { if (method_exists($this, 'preHydrate')) { $results = $this->preHydrate($results); } $return = array(); if ($results) { $arrayResults = $results->fetchAll(); foreach ($arrayResults as $arrayResult) { $className = get_class($this); $object = new $className(); $return[$arrayResult[$this->id_name]] = $object->setRecord($arrayResult); } } if (method_exists($this, 'postHydrate')) { $return = $this->preHydrate($return); } return $return; }
[ "public", "function", "hydrate", "(", "PDOStatement", "$", "results", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "'preHydrate'", ")", ")", "{", "$", "results", "=", "$", "this", "->", "preHydrate", "(", "$", "results", ")", ";", "}", "$", "return", "=", "array", "(", ")", ";", "if", "(", "$", "results", ")", "{", "$", "arrayResults", "=", "$", "results", "->", "fetchAll", "(", ")", ";", "foreach", "(", "$", "arrayResults", "as", "$", "arrayResult", ")", "{", "$", "className", "=", "get_class", "(", "$", "this", ")", ";", "$", "object", "=", "new", "$", "className", "(", ")", ";", "$", "return", "[", "$", "arrayResult", "[", "$", "this", "->", "id_name", "]", "]", "=", "$", "object", "->", "setRecord", "(", "$", "arrayResult", ")", ";", "}", "}", "if", "(", "method_exists", "(", "$", "this", ",", "'postHydrate'", ")", ")", "{", "$", "return", "=", "$", "this", "->", "preHydrate", "(", "$", "return", ")", ";", "}", "return", "$", "return", ";", "}" ]
Default Hydrate. Use preHydrate and postHydrate methods to change the default behavior. You can override this method too if you need. @param PDOStatement $results @return Array of Model Objects
[ "Default", "Hydrate", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L400-L422
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.findRelatedModel
public function findRelatedModel($modelName, $field, $id = NULL) { $relatedModel = $this->getInstance($modelName); if ($this->isNew() && $id === NULL) { throw new \Exception('No id for related'); } if ($id === NULL) { $id = $this->getField($field); } $result = $relatedModel->findById($id); return $result; }
php
public function findRelatedModel($modelName, $field, $id = NULL) { $relatedModel = $this->getInstance($modelName); if ($this->isNew() && $id === NULL) { throw new \Exception('No id for related'); } if ($id === NULL) { $id = $this->getField($field); } $result = $relatedModel->findById($id); return $result; }
[ "public", "function", "findRelatedModel", "(", "$", "modelName", ",", "$", "field", ",", "$", "id", "=", "NULL", ")", "{", "$", "relatedModel", "=", "$", "this", "->", "getInstance", "(", "$", "modelName", ")", ";", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "$", "id", "===", "NULL", ")", "{", "throw", "new", "\\", "Exception", "(", "'No id for related'", ")", ";", "}", "if", "(", "$", "id", "===", "NULL", ")", "{", "$", "id", "=", "$", "this", "->", "getField", "(", "$", "field", ")", ";", "}", "$", "result", "=", "$", "relatedModel", "->", "findById", "(", "$", "id", ")", ";", "return", "$", "result", ";", "}" ]
Finds a related model instance by the given field name and the id value. Use it in a 1 to N relation, with an object instance of the N side to the get 1 related model. @param $modelName : The related model name. @param $field : The field that must be used to relate. @param $id : Optional, the ID the related model, if is not given the value of the field in the executor object will be used. @throws \Exception : if a invalid model is given. @return Related Instance.
[ "Finds", "a", "related", "model", "instance", "by", "the", "given", "field", "name", "and", "the", "id", "value", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L437-L451
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.findRelatedModels
public function findRelatedModels($modelName, $field, $id = NULL) { $relatedModel = $this->getInstance($modelName); if ($this->isNew() && $id === NULL) { throw new \Exception('No id for related'); } if ($id === NULL) { $id = $this->getId(); } $result = $relatedModel->findByField($field, $id); return $result; }
php
public function findRelatedModels($modelName, $field, $id = NULL) { $relatedModel = $this->getInstance($modelName); if ($this->isNew() && $id === NULL) { throw new \Exception('No id for related'); } if ($id === NULL) { $id = $this->getId(); } $result = $relatedModel->findByField($field, $id); return $result; }
[ "public", "function", "findRelatedModels", "(", "$", "modelName", ",", "$", "field", ",", "$", "id", "=", "NULL", ")", "{", "$", "relatedModel", "=", "$", "this", "->", "getInstance", "(", "$", "modelName", ")", ";", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "$", "id", "===", "NULL", ")", "{", "throw", "new", "\\", "Exception", "(", "'No id for related'", ")", ";", "}", "if", "(", "$", "id", "===", "NULL", ")", "{", "$", "id", "=", "$", "this", "->", "getId", "(", ")", ";", "}", "$", "result", "=", "$", "relatedModel", "->", "findByField", "(", "$", "field", ",", "$", "id", ")", ";", "return", "$", "result", ";", "}" ]
Finds related models instances using the field name and the id value. Use it in a 1 to N relation, with an object instance of the 1 side to the get N related models. @param $modelName : The related model name. @param $field : The field that must be used to relate. @param $id : Optional, the ID the related model, if is not given the value of the field in the executor object will be used. @throws \Exception : if a invalid model is given. @return Related Instance.
[ "Finds", "related", "models", "instances", "using", "the", "field", "name", "and", "the", "id", "value", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L466-L480
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.plain
static public function plain($objects) { $data = array(); foreach ($objects as $object) { $data[] = $object->getRecord(); } return $data; }
php
static public function plain($objects) { $data = array(); foreach ($objects as $object) { $data[] = $object->getRecord(); } return $data; }
[ "static", "public", "function", "plain", "(", "$", "objects", ")", "{", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "objects", "as", "$", "object", ")", "{", "$", "data", "[", "]", "=", "$", "object", "->", "getRecord", "(", ")", ";", "}", "return", "$", "data", ";", "}" ]
Convert the array of objects into a plain array. @param $objects @return array
[ "Convert", "the", "array", "of", "objects", "into", "a", "plain", "array", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L516-L523
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.createQuery
public function createQuery() { $query = $this->db()->createQueryBuilder(); $query->select('t.*') ->from($this->table, 't'); return $query; }
php
public function createQuery() { $query = $this->db()->createQueryBuilder(); $query->select('t.*') ->from($this->table, 't'); return $query; }
[ "public", "function", "createQuery", "(", ")", "{", "$", "query", "=", "$", "this", "->", "db", "(", ")", "->", "createQueryBuilder", "(", ")", ";", "$", "query", "->", "select", "(", "'t.*'", ")", "->", "from", "(", "$", "this", "->", "table", ",", "'t'", ")", ";", "return", "$", "query", ";", "}" ]
Creates a QueryBuilder with the table selected. @return \Doctrine\DBAL\Query\QueryBuilder
[ "Creates", "a", "QueryBuilder", "with", "the", "table", "selected", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L530-L536
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.findAllPaged
public function findAllPaged($page = 0, $limit = 20) { $results = $this->findAllWithoutFetchPaged($page, $limit); $return = $this->hydrate($results); return $return; }
php
public function findAllPaged($page = 0, $limit = 20) { $results = $this->findAllWithoutFetchPaged($page, $limit); $return = $this->hydrate($results); return $return; }
[ "public", "function", "findAllPaged", "(", "$", "page", "=", "0", ",", "$", "limit", "=", "20", ")", "{", "$", "results", "=", "$", "this", "->", "findAllWithoutFetchPaged", "(", "$", "page", ",", "$", "limit", ")", ";", "$", "return", "=", "$", "this", "->", "hydrate", "(", "$", "results", ")", ";", "return", "$", "return", ";", "}" ]
Finds all records of a table paged. @param int $page @param int $limit @return mixed : Array with results.
[ "Finds", "all", "records", "of", "a", "table", "paged", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L556-L561
42mate/towel
src/Towel/Model/BaseModel.php
BaseModel.findAllWithoutFetchPaged
public function findAllWithoutFetchPaged($page = 0, $limit = 20) { $offset = $page * $limit; $results = $this->createQuery() ->setFirstResult($offset) ->setMaxResults($limit) ->execute(); return $results; }
php
public function findAllWithoutFetchPaged($page = 0, $limit = 20) { $offset = $page * $limit; $results = $this->createQuery() ->setFirstResult($offset) ->setMaxResults($limit) ->execute(); return $results; }
[ "public", "function", "findAllWithoutFetchPaged", "(", "$", "page", "=", "0", ",", "$", "limit", "=", "20", ")", "{", "$", "offset", "=", "$", "page", "*", "$", "limit", ";", "$", "results", "=", "$", "this", "->", "createQuery", "(", ")", "->", "setFirstResult", "(", "$", "offset", ")", "->", "setMaxResults", "(", "$", "limit", ")", "->", "execute", "(", ")", ";", "return", "$", "results", ";", "}" ]
Finds all records of a table. @param int $page @param int $limit @return mixed : PDOStatement with results.
[ "Finds", "all", "records", "of", "a", "table", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Model/BaseModel.php#L572-L579
edhelas/sasl2
src/SASL2/SASL2.php
SASL2.factory
function factory($type) { $classname = 'SASL2\Auth\\'; switch (strtolower($type)) { case 'anonymous': $classname .= 'Anonymous'; break; case 'login': $classname .= 'Login'; break; case 'plain': $classname .= 'Plain'; break; case 'external': $classname .= 'External'; break; case 'crammd5': // $msg = 'Deprecated mechanism name. Use IANA-registered name: CRAM-MD5.'; // trigger_error($msg, E_USER_DEPRECATED); case 'cram-md5': $classname .= 'CramMD5'; break; case 'digestmd5': // $msg = 'Deprecated mechanism name. Use IANA-registered name: DIGEST-MD5.'; // trigger_error($msg, E_USER_DEPRECATED); case 'digest-md5': // $msg = 'DIGEST-MD5 is a deprecated SASL mechanism as per RFC-6331. Using it could be a security risk.'; // trigger_error($msg, E_USER_NOTICE); $classname .= 'DigestMD5'; break; default: $scram = '/^SCRAM-(.{1,9})$/i'; if (preg_match($scram, $type, $matches)) { $hash = $matches[1]; $classname .= 'SCRAM'; $parameter = $hash; break; } throw new InvalidArgumentException('Invalid SASL mechanism type'); break; } if (isset($parameter)) { $obj = new $classname($parameter); } else { $obj = new $classname(); } return $obj; }
php
function factory($type) { $classname = 'SASL2\Auth\\'; switch (strtolower($type)) { case 'anonymous': $classname .= 'Anonymous'; break; case 'login': $classname .= 'Login'; break; case 'plain': $classname .= 'Plain'; break; case 'external': $classname .= 'External'; break; case 'crammd5': // $msg = 'Deprecated mechanism name. Use IANA-registered name: CRAM-MD5.'; // trigger_error($msg, E_USER_DEPRECATED); case 'cram-md5': $classname .= 'CramMD5'; break; case 'digestmd5': // $msg = 'Deprecated mechanism name. Use IANA-registered name: DIGEST-MD5.'; // trigger_error($msg, E_USER_DEPRECATED); case 'digest-md5': // $msg = 'DIGEST-MD5 is a deprecated SASL mechanism as per RFC-6331. Using it could be a security risk.'; // trigger_error($msg, E_USER_NOTICE); $classname .= 'DigestMD5'; break; default: $scram = '/^SCRAM-(.{1,9})$/i'; if (preg_match($scram, $type, $matches)) { $hash = $matches[1]; $classname .= 'SCRAM'; $parameter = $hash; break; } throw new InvalidArgumentException('Invalid SASL mechanism type'); break; } if (isset($parameter)) { $obj = new $classname($parameter); } else { $obj = new $classname(); } return $obj; }
[ "function", "factory", "(", "$", "type", ")", "{", "$", "classname", "=", "'SASL2\\Auth\\\\'", ";", "switch", "(", "strtolower", "(", "$", "type", ")", ")", "{", "case", "'anonymous'", ":", "$", "classname", ".=", "'Anonymous'", ";", "break", ";", "case", "'login'", ":", "$", "classname", ".=", "'Login'", ";", "break", ";", "case", "'plain'", ":", "$", "classname", ".=", "'Plain'", ";", "break", ";", "case", "'external'", ":", "$", "classname", ".=", "'External'", ";", "break", ";", "case", "'crammd5'", ":", "// $msg = 'Deprecated mechanism name. Use IANA-registered name: CRAM-MD5.';", "// trigger_error($msg, E_USER_DEPRECATED);", "case", "'cram-md5'", ":", "$", "classname", ".=", "'CramMD5'", ";", "break", ";", "case", "'digestmd5'", ":", "// $msg = 'Deprecated mechanism name. Use IANA-registered name: DIGEST-MD5.';", "// trigger_error($msg, E_USER_DEPRECATED);", "case", "'digest-md5'", ":", "// $msg = 'DIGEST-MD5 is a deprecated SASL mechanism as per RFC-6331. Using it could be a security risk.';", "// trigger_error($msg, E_USER_NOTICE);", "$", "classname", ".=", "'DigestMD5'", ";", "break", ";", "default", ":", "$", "scram", "=", "'/^SCRAM-(.{1,9})$/i'", ";", "if", "(", "preg_match", "(", "$", "scram", ",", "$", "type", ",", "$", "matches", ")", ")", "{", "$", "hash", "=", "$", "matches", "[", "1", "]", ";", "$", "classname", ".=", "'SCRAM'", ";", "$", "parameter", "=", "$", "hash", ";", "break", ";", "}", "throw", "new", "InvalidArgumentException", "(", "'Invalid SASL mechanism type'", ")", ";", "break", ";", "}", "if", "(", "isset", "(", "$", "parameter", ")", ")", "{", "$", "obj", "=", "new", "$", "classname", "(", "$", "parameter", ")", ";", "}", "else", "{", "$", "obj", "=", "new", "$", "classname", "(", ")", ";", "}", "return", "$", "obj", ";", "}" ]
Factory class. Returns an object of the request type. @param string $type One of: Anonymous Plain CramMD5 DigestMD5 SCRAM-* (any mechanism of the SCRAM family) Types are not case sensitive
[ "Factory", "class", ".", "Returns", "an", "object", "of", "the", "request", "type", "." ]
train
https://github.com/edhelas/sasl2/blob/b9c7cecb1ebb6086262304b901bbc71dff435504/src/SASL2/SASL2.php#L69-L125
ShaoZeMing/laravel-merchant
src/Form.php
Form.redirectAfterUpdate
protected function redirectAfterUpdate() { merchant_toastr(trans('merchant.update_succeeded')); $url = Input::get(Builder::PREVIOUS_URL_KEY) ?: $this->resource(-1); return redirect($url); }
php
protected function redirectAfterUpdate() { merchant_toastr(trans('merchant.update_succeeded')); $url = Input::get(Builder::PREVIOUS_URL_KEY) ?: $this->resource(-1); return redirect($url); }
[ "protected", "function", "redirectAfterUpdate", "(", ")", "{", "merchant_toastr", "(", "trans", "(", "'merchant.update_succeeded'", ")", ")", ";", "$", "url", "=", "Input", "::", "get", "(", "Builder", "::", "PREVIOUS_URL_KEY", ")", "?", ":", "$", "this", "->", "resource", "(", "-", "1", ")", ";", "return", "redirect", "(", "$", "url", ")", ";", "}" ]
Get RedirectResponse after update. @return \Illuminate\Http\RedirectResponse
[ "Get", "RedirectResponse", "after", "update", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Form.php#L559-L566
ShaoZeMing/laravel-merchant
src/Form.php
Form.updateRelation
protected function updateRelation($relationsData) { foreach ($relationsData as $name => $values) { if (!method_exists($this->model, $name)) { continue; } $relation = $this->model->$name(); $oneToOneRelation = $relation instanceof \Illuminate\Database\Eloquent\Relations\HasOne || $relation instanceof \Illuminate\Database\Eloquent\Relations\MorphOne; $prepared = $this->prepareUpdate([$name => $values], $oneToOneRelation); if (empty($prepared)) { continue; } switch (get_class($relation)) { case \Illuminate\Database\Eloquent\Relations\BelongsToMany::class: case \Illuminate\Database\Eloquent\Relations\MorphToMany::class: if (isset($prepared[$name])) { $relation->sync($prepared[$name]); } break; case \Illuminate\Database\Eloquent\Relations\HasOne::class: $related = $this->model->$name; // if related is empty if (is_null($related)) { $related = $relation->getRelated(); $related->{$relation->getForeignKeyName()} = $this->model->{$this->model->getKeyName()}; } foreach ($prepared[$name] as $column => $value) { $related->setAttribute($column, $value); } $related->save(); break; case \Illuminate\Database\Eloquent\Relations\MorphOne::class: $related = $this->model->$name; if (is_null($related)) { $related = $relation->make(); } foreach ($prepared[$name] as $column => $value) { $related->setAttribute($column, $value); } $related->save(); break; case \Illuminate\Database\Eloquent\Relations\HasMany::class: case \Illuminate\Database\Eloquent\Relations\MorphMany::class: foreach ($prepared[$name] as $related) { $relation = $this->model()->$name(); $keyName = $relation->getRelated()->getKeyName(); $instance = $relation->findOrNew(array_get($related, $keyName)); if ($related[static::REMOVE_FLAG_NAME] == 1) { $instance->delete(); continue; } array_forget($related, static::REMOVE_FLAG_NAME); $instance->fill($related); $instance->save(); } break; } } }
php
protected function updateRelation($relationsData) { foreach ($relationsData as $name => $values) { if (!method_exists($this->model, $name)) { continue; } $relation = $this->model->$name(); $oneToOneRelation = $relation instanceof \Illuminate\Database\Eloquent\Relations\HasOne || $relation instanceof \Illuminate\Database\Eloquent\Relations\MorphOne; $prepared = $this->prepareUpdate([$name => $values], $oneToOneRelation); if (empty($prepared)) { continue; } switch (get_class($relation)) { case \Illuminate\Database\Eloquent\Relations\BelongsToMany::class: case \Illuminate\Database\Eloquent\Relations\MorphToMany::class: if (isset($prepared[$name])) { $relation->sync($prepared[$name]); } break; case \Illuminate\Database\Eloquent\Relations\HasOne::class: $related = $this->model->$name; // if related is empty if (is_null($related)) { $related = $relation->getRelated(); $related->{$relation->getForeignKeyName()} = $this->model->{$this->model->getKeyName()}; } foreach ($prepared[$name] as $column => $value) { $related->setAttribute($column, $value); } $related->save(); break; case \Illuminate\Database\Eloquent\Relations\MorphOne::class: $related = $this->model->$name; if (is_null($related)) { $related = $relation->make(); } foreach ($prepared[$name] as $column => $value) { $related->setAttribute($column, $value); } $related->save(); break; case \Illuminate\Database\Eloquent\Relations\HasMany::class: case \Illuminate\Database\Eloquent\Relations\MorphMany::class: foreach ($prepared[$name] as $related) { $relation = $this->model()->$name(); $keyName = $relation->getRelated()->getKeyName(); $instance = $relation->findOrNew(array_get($related, $keyName)); if ($related[static::REMOVE_FLAG_NAME] == 1) { $instance->delete(); continue; } array_forget($related, static::REMOVE_FLAG_NAME); $instance->fill($related); $instance->save(); } break; } } }
[ "protected", "function", "updateRelation", "(", "$", "relationsData", ")", "{", "foreach", "(", "$", "relationsData", "as", "$", "name", "=>", "$", "values", ")", "{", "if", "(", "!", "method_exists", "(", "$", "this", "->", "model", ",", "$", "name", ")", ")", "{", "continue", ";", "}", "$", "relation", "=", "$", "this", "->", "model", "->", "$", "name", "(", ")", ";", "$", "oneToOneRelation", "=", "$", "relation", "instanceof", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "HasOne", "||", "$", "relation", "instanceof", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "MorphOne", ";", "$", "prepared", "=", "$", "this", "->", "prepareUpdate", "(", "[", "$", "name", "=>", "$", "values", "]", ",", "$", "oneToOneRelation", ")", ";", "if", "(", "empty", "(", "$", "prepared", ")", ")", "{", "continue", ";", "}", "switch", "(", "get_class", "(", "$", "relation", ")", ")", "{", "case", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "BelongsToMany", "::", "class", ":", "case", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "MorphToMany", "::", "class", ":", "if", "(", "isset", "(", "$", "prepared", "[", "$", "name", "]", ")", ")", "{", "$", "relation", "->", "sync", "(", "$", "prepared", "[", "$", "name", "]", ")", ";", "}", "break", ";", "case", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "HasOne", "::", "class", ":", "$", "related", "=", "$", "this", "->", "model", "->", "$", "name", ";", "// if related is empty", "if", "(", "is_null", "(", "$", "related", ")", ")", "{", "$", "related", "=", "$", "relation", "->", "getRelated", "(", ")", ";", "$", "related", "->", "{", "$", "relation", "->", "getForeignKeyName", "(", ")", "}", "=", "$", "this", "->", "model", "->", "{", "$", "this", "->", "model", "->", "getKeyName", "(", ")", "}", ";", "}", "foreach", "(", "$", "prepared", "[", "$", "name", "]", "as", "$", "column", "=>", "$", "value", ")", "{", "$", "related", "->", "setAttribute", "(", "$", "column", ",", "$", "value", ")", ";", "}", "$", "related", "->", "save", "(", ")", ";", "break", ";", "case", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "MorphOne", "::", "class", ":", "$", "related", "=", "$", "this", "->", "model", "->", "$", "name", ";", "if", "(", "is_null", "(", "$", "related", ")", ")", "{", "$", "related", "=", "$", "relation", "->", "make", "(", ")", ";", "}", "foreach", "(", "$", "prepared", "[", "$", "name", "]", "as", "$", "column", "=>", "$", "value", ")", "{", "$", "related", "->", "setAttribute", "(", "$", "column", ",", "$", "value", ")", ";", "}", "$", "related", "->", "save", "(", ")", ";", "break", ";", "case", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "HasMany", "::", "class", ":", "case", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "MorphMany", "::", "class", ":", "foreach", "(", "$", "prepared", "[", "$", "name", "]", "as", "$", "related", ")", "{", "$", "relation", "=", "$", "this", "->", "model", "(", ")", "->", "$", "name", "(", ")", ";", "$", "keyName", "=", "$", "relation", "->", "getRelated", "(", ")", "->", "getKeyName", "(", ")", ";", "$", "instance", "=", "$", "relation", "->", "findOrNew", "(", "array_get", "(", "$", "related", ",", "$", "keyName", ")", ")", ";", "if", "(", "$", "related", "[", "static", "::", "REMOVE_FLAG_NAME", "]", "==", "1", ")", "{", "$", "instance", "->", "delete", "(", ")", ";", "continue", ";", "}", "array_forget", "(", "$", "related", ",", "static", "::", "REMOVE_FLAG_NAME", ")", ";", "$", "instance", "->", "fill", "(", "$", "related", ")", ";", "$", "instance", "->", "save", "(", ")", ";", "}", "break", ";", "}", "}", "}" ]
Update relation data. @param array $relationsData @return void
[ "Update", "relation", "data", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Form.php#L635-L712
ShaoZeMing/laravel-merchant
src/Form.php
Form.registerBuiltinFields
public static function registerBuiltinFields() { $map = [ 'button' => \ShaoZeMing\Merchant\Form\Field\Button::class, 'checkbox' => \ShaoZeMing\Merchant\Form\Field\Checkbox::class, 'color' => \ShaoZeMing\Merchant\Form\Field\Color::class, 'currency' => \ShaoZeMing\Merchant\Form\Field\Currency::class, 'date' => \ShaoZeMing\Merchant\Form\Field\Date::class, 'dateRange' => \ShaoZeMing\Merchant\Form\Field\DateRange::class, 'datetime' => \ShaoZeMing\Merchant\Form\Field\Datetime::class, 'dateTimeRange' => \ShaoZeMing\Merchant\Form\Field\DatetimeRange::class, 'datetimeRange' => \ShaoZeMing\Merchant\Form\Field\DatetimeRange::class, 'decimal' => \ShaoZeMing\Merchant\Form\Field\Decimal::class, 'display' => \ShaoZeMing\Merchant\Form\Field\Display::class, 'divider' => \ShaoZeMing\Merchant\Form\Field\Divide::class, 'divide' => \ShaoZeMing\Merchant\Form\Field\Divide::class, 'embeds' => \ShaoZeMing\Merchant\Form\Field\Embeds::class, 'editor' => \ShaoZeMing\Merchant\Form\Field\Editor::class, 'email' => \ShaoZeMing\Merchant\Form\Field\Email::class, 'file' => \ShaoZeMing\Merchant\Form\Field\File::class, 'hasMany' => \ShaoZeMing\Merchant\Form\Field\HasMany::class, 'hidden' => \ShaoZeMing\Merchant\Form\Field\Hidden::class, 'id' => \ShaoZeMing\Merchant\Form\Field\Id::class, 'image' => \ShaoZeMing\Merchant\Form\Field\Image::class, 'ip' => \ShaoZeMing\Merchant\Form\Field\Ip::class, 'map' => \ShaoZeMing\Merchant\Form\Field\Map::class, 'mobile' => \ShaoZeMing\Merchant\Form\Field\Mobile::class, 'month' => \ShaoZeMing\Merchant\Form\Field\Month::class, 'multipleSelect' => \ShaoZeMing\Merchant\Form\Field\MultipleSelect::class, 'number' => \ShaoZeMing\Merchant\Form\Field\Number::class, 'password' => \ShaoZeMing\Merchant\Form\Field\Password::class, 'radio' => \ShaoZeMing\Merchant\Form\Field\Radio::class, 'rate' => \ShaoZeMing\Merchant\Form\Field\Rate::class, 'select' => \ShaoZeMing\Merchant\Form\Field\Select::class, 'slider' => \ShaoZeMing\Merchant\Form\Field\Slider::class, 'switch' => \ShaoZeMing\Merchant\Form\Field\SwitchField::class, 'text' => \ShaoZeMing\Merchant\Form\Field\Text::class, 'textarea' => \ShaoZeMing\Merchant\Form\Field\Textarea::class, 'time' => \ShaoZeMing\Merchant\Form\Field\Time::class, 'timeRange' => \ShaoZeMing\Merchant\Form\Field\TimeRange::class, 'url' => \ShaoZeMing\Merchant\Form\Field\Url::class, 'year' => \ShaoZeMing\Merchant\Form\Field\Year::class, 'html' => \ShaoZeMing\Merchant\Form\Field\Html::class, 'tags' => \ShaoZeMing\Merchant\Form\Field\Tags::class, 'icon' => \ShaoZeMing\Merchant\Form\Field\Icon::class, 'multipleFile' => \ShaoZeMing\Merchant\Form\Field\MultipleFile::class, 'multipleImage' => \ShaoZeMing\Merchant\Form\Field\MultipleImage::class, 'captcha' => \ShaoZeMing\Merchant\Form\Field\Captcha::class, 'listbox' => \ShaoZeMing\Merchant\Form\Field\Listbox::class, ]; foreach ($map as $abstract => $class) { static::extend($abstract, $class); } }
php
public static function registerBuiltinFields() { $map = [ 'button' => \ShaoZeMing\Merchant\Form\Field\Button::class, 'checkbox' => \ShaoZeMing\Merchant\Form\Field\Checkbox::class, 'color' => \ShaoZeMing\Merchant\Form\Field\Color::class, 'currency' => \ShaoZeMing\Merchant\Form\Field\Currency::class, 'date' => \ShaoZeMing\Merchant\Form\Field\Date::class, 'dateRange' => \ShaoZeMing\Merchant\Form\Field\DateRange::class, 'datetime' => \ShaoZeMing\Merchant\Form\Field\Datetime::class, 'dateTimeRange' => \ShaoZeMing\Merchant\Form\Field\DatetimeRange::class, 'datetimeRange' => \ShaoZeMing\Merchant\Form\Field\DatetimeRange::class, 'decimal' => \ShaoZeMing\Merchant\Form\Field\Decimal::class, 'display' => \ShaoZeMing\Merchant\Form\Field\Display::class, 'divider' => \ShaoZeMing\Merchant\Form\Field\Divide::class, 'divide' => \ShaoZeMing\Merchant\Form\Field\Divide::class, 'embeds' => \ShaoZeMing\Merchant\Form\Field\Embeds::class, 'editor' => \ShaoZeMing\Merchant\Form\Field\Editor::class, 'email' => \ShaoZeMing\Merchant\Form\Field\Email::class, 'file' => \ShaoZeMing\Merchant\Form\Field\File::class, 'hasMany' => \ShaoZeMing\Merchant\Form\Field\HasMany::class, 'hidden' => \ShaoZeMing\Merchant\Form\Field\Hidden::class, 'id' => \ShaoZeMing\Merchant\Form\Field\Id::class, 'image' => \ShaoZeMing\Merchant\Form\Field\Image::class, 'ip' => \ShaoZeMing\Merchant\Form\Field\Ip::class, 'map' => \ShaoZeMing\Merchant\Form\Field\Map::class, 'mobile' => \ShaoZeMing\Merchant\Form\Field\Mobile::class, 'month' => \ShaoZeMing\Merchant\Form\Field\Month::class, 'multipleSelect' => \ShaoZeMing\Merchant\Form\Field\MultipleSelect::class, 'number' => \ShaoZeMing\Merchant\Form\Field\Number::class, 'password' => \ShaoZeMing\Merchant\Form\Field\Password::class, 'radio' => \ShaoZeMing\Merchant\Form\Field\Radio::class, 'rate' => \ShaoZeMing\Merchant\Form\Field\Rate::class, 'select' => \ShaoZeMing\Merchant\Form\Field\Select::class, 'slider' => \ShaoZeMing\Merchant\Form\Field\Slider::class, 'switch' => \ShaoZeMing\Merchant\Form\Field\SwitchField::class, 'text' => \ShaoZeMing\Merchant\Form\Field\Text::class, 'textarea' => \ShaoZeMing\Merchant\Form\Field\Textarea::class, 'time' => \ShaoZeMing\Merchant\Form\Field\Time::class, 'timeRange' => \ShaoZeMing\Merchant\Form\Field\TimeRange::class, 'url' => \ShaoZeMing\Merchant\Form\Field\Url::class, 'year' => \ShaoZeMing\Merchant\Form\Field\Year::class, 'html' => \ShaoZeMing\Merchant\Form\Field\Html::class, 'tags' => \ShaoZeMing\Merchant\Form\Field\Tags::class, 'icon' => \ShaoZeMing\Merchant\Form\Field\Icon::class, 'multipleFile' => \ShaoZeMing\Merchant\Form\Field\MultipleFile::class, 'multipleImage' => \ShaoZeMing\Merchant\Form\Field\MultipleImage::class, 'captcha' => \ShaoZeMing\Merchant\Form\Field\Captcha::class, 'listbox' => \ShaoZeMing\Merchant\Form\Field\Listbox::class, ]; foreach ($map as $abstract => $class) { static::extend($abstract, $class); } }
[ "public", "static", "function", "registerBuiltinFields", "(", ")", "{", "$", "map", "=", "[", "'button'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Button", "::", "class", ",", "'checkbox'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Checkbox", "::", "class", ",", "'color'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Color", "::", "class", ",", "'currency'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Currency", "::", "class", ",", "'date'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Date", "::", "class", ",", "'dateRange'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "DateRange", "::", "class", ",", "'datetime'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Datetime", "::", "class", ",", "'dateTimeRange'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "DatetimeRange", "::", "class", ",", "'datetimeRange'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "DatetimeRange", "::", "class", ",", "'decimal'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Decimal", "::", "class", ",", "'display'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Display", "::", "class", ",", "'divider'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Divide", "::", "class", ",", "'divide'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Divide", "::", "class", ",", "'embeds'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Embeds", "::", "class", ",", "'editor'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Editor", "::", "class", ",", "'email'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Email", "::", "class", ",", "'file'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "File", "::", "class", ",", "'hasMany'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "HasMany", "::", "class", ",", "'hidden'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Hidden", "::", "class", ",", "'id'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Id", "::", "class", ",", "'image'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Image", "::", "class", ",", "'ip'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Ip", "::", "class", ",", "'map'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Map", "::", "class", ",", "'mobile'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Mobile", "::", "class", ",", "'month'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Month", "::", "class", ",", "'multipleSelect'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "MultipleSelect", "::", "class", ",", "'number'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Number", "::", "class", ",", "'password'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Password", "::", "class", ",", "'radio'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Radio", "::", "class", ",", "'rate'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Rate", "::", "class", ",", "'select'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Select", "::", "class", ",", "'slider'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Slider", "::", "class", ",", "'switch'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "SwitchField", "::", "class", ",", "'text'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Text", "::", "class", ",", "'textarea'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Textarea", "::", "class", ",", "'time'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Time", "::", "class", ",", "'timeRange'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "TimeRange", "::", "class", ",", "'url'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Url", "::", "class", ",", "'year'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Year", "::", "class", ",", "'html'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Html", "::", "class", ",", "'tags'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Tags", "::", "class", ",", "'icon'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Icon", "::", "class", ",", "'multipleFile'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "MultipleFile", "::", "class", ",", "'multipleImage'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "MultipleImage", "::", "class", ",", "'captcha'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Captcha", "::", "class", ",", "'listbox'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "\\", "Field", "\\", "Listbox", "::", "class", ",", "]", ";", "foreach", "(", "$", "map", "as", "$", "abstract", "=>", "$", "class", ")", "{", "static", "::", "extend", "(", "$", "abstract", ",", "$", "class", ")", ";", "}", "}" ]
Register builtin fields. @return void
[ "Register", "builtin", "fields", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Form.php#L1198-L1252
Humanized/yii2-location
controllers/AdminController.php
AdminController.actionIndex
public function actionIndex() { $model = new Location(); if ($model->load(\Yii::$app->request->post()) && $model->save()) { $model = new Location(); //reset model } $searchModel = new LocationSearch(['pagination' => TRUE]); $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'model' => $model, ]); }
php
public function actionIndex() { $model = new Location(); if ($model->load(\Yii::$app->request->post()) && $model->save()) { $model = new Location(); //reset model } $searchModel = new LocationSearch(['pagination' => TRUE]); $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'model' => $model, ]); }
[ "public", "function", "actionIndex", "(", ")", "{", "$", "model", "=", "new", "Location", "(", ")", ";", "if", "(", "$", "model", "->", "load", "(", "\\", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", "&&", "$", "model", "->", "save", "(", ")", ")", "{", "$", "model", "=", "new", "Location", "(", ")", ";", "//reset model", "}", "$", "searchModel", "=", "new", "LocationSearch", "(", "[", "'pagination'", "=>", "TRUE", "]", ")", ";", "$", "dataProvider", "=", "$", "searchModel", "->", "search", "(", "\\", "Yii", "::", "$", "app", "->", "request", "->", "queryParams", ")", ";", "return", "$", "this", "->", "render", "(", "'index'", ",", "[", "'searchModel'", "=>", "$", "searchModel", ",", "'dataProvider'", "=>", "$", "dataProvider", ",", "'model'", "=>", "$", "model", ",", "]", ")", ";", "}" ]
Lists all Location models. @return mixed
[ "Lists", "all", "Location", "models", "." ]
train
https://github.com/Humanized/yii2-location/blob/48ac12ceab741fc4c82ac8e979415a11bf9175f2/controllers/AdminController.php#L38-L53
raideer/twitch-api
src/Resources/Resource.php
Resource.resolveOptions
public function resolveOptions($options, $defaults, $required = [], $allowedTypes = []) { $resolver = new OptionsResolver(); $resolver->setDefaults($defaults); if (!empty($required)) { $resolver->setRequired($required); } if (!empty($allowedTypes)) { foreach ($allowedTypes as $type => $value) { $resolver->setAllowedValues($type, $value); } } return $resolver->resolve($options); }
php
public function resolveOptions($options, $defaults, $required = [], $allowedTypes = []) { $resolver = new OptionsResolver(); $resolver->setDefaults($defaults); if (!empty($required)) { $resolver->setRequired($required); } if (!empty($allowedTypes)) { foreach ($allowedTypes as $type => $value) { $resolver->setAllowedValues($type, $value); } } return $resolver->resolve($options); }
[ "public", "function", "resolveOptions", "(", "$", "options", ",", "$", "defaults", ",", "$", "required", "=", "[", "]", ",", "$", "allowedTypes", "=", "[", "]", ")", "{", "$", "resolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "resolver", "->", "setDefaults", "(", "$", "defaults", ")", ";", "if", "(", "!", "empty", "(", "$", "required", ")", ")", "{", "$", "resolver", "->", "setRequired", "(", "$", "required", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "allowedTypes", ")", ")", "{", "foreach", "(", "$", "allowedTypes", "as", "$", "type", "=>", "$", "value", ")", "{", "$", "resolver", "->", "setAllowedValues", "(", "$", "type", ",", "$", "value", ")", ";", "}", "}", "return", "$", "resolver", "->", "resolve", "(", "$", "options", ")", ";", "}" ]
Helper function for resolving parameters. @param array $options Passed params @param array $defaults Default values @param array $required Required fields @param array $allowedTypes Allowed field values @return array
[ "Helper", "function", "for", "resolving", "parameters", "." ]
train
https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Resource.php#L45-L61
php-lug/lug
src/Bundle/GridBundle/Form/Type/Filter/NumberFilterType.php
NumberFilterType.buildForm
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add($builder->create('type', ChoiceType::class, [ 'choices' => array_combine( array_map(function ($choice) use ($options) { return $options['label_prefix'].'.type.'.$choice; }, $choices = NumberType::getTypes()), $choices ), 'choices_as_values' => true, 'xml_http_request_trigger' => true, ]) ->addEventSubscriber($this->numberFilterSubscriber)); }
php
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add($builder->create('type', ChoiceType::class, [ 'choices' => array_combine( array_map(function ($choice) use ($options) { return $options['label_prefix'].'.type.'.$choice; }, $choices = NumberType::getTypes()), $choices ), 'choices_as_values' => true, 'xml_http_request_trigger' => true, ]) ->addEventSubscriber($this->numberFilterSubscriber)); }
[ "public", "function", "buildForm", "(", "FormBuilderInterface", "$", "builder", ",", "array", "$", "options", ")", "{", "$", "builder", "->", "add", "(", "$", "builder", "->", "create", "(", "'type'", ",", "ChoiceType", "::", "class", ",", "[", "'choices'", "=>", "array_combine", "(", "array_map", "(", "function", "(", "$", "choice", ")", "use", "(", "$", "options", ")", "{", "return", "$", "options", "[", "'label_prefix'", "]", ".", "'.type.'", ".", "$", "choice", ";", "}", ",", "$", "choices", "=", "NumberType", "::", "getTypes", "(", ")", ")", ",", "$", "choices", ")", ",", "'choices_as_values'", "=>", "true", ",", "'xml_http_request_trigger'", "=>", "true", ",", "]", ")", "->", "addEventSubscriber", "(", "$", "this", "->", "numberFilterSubscriber", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Form/Type/Filter/NumberFilterType.php#L40-L54
gpupo/common-schema
src/ORM/Entity/Trading/Order/Shipping/Shipping.php
Shipping.setSeller
public function setSeller(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Seller $seller = null) { $this->seller = $seller; return $this; }
php
public function setSeller(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Seller $seller = null) { $this->seller = $seller; return $this; }
[ "public", "function", "setSeller", "(", "\\", "Gpupo", "\\", "CommonSchema", "\\", "ORM", "\\", "Entity", "\\", "Trading", "\\", "Order", "\\", "Shipping", "\\", "Seller", "$", "seller", "=", "null", ")", "{", "$", "this", "->", "seller", "=", "$", "seller", ";", "return", "$", "this", ";", "}" ]
Set seller. @param null|\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Seller $seller @return Shipping
[ "Set", "seller", "." ]
train
https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Trading/Order/Shipping/Shipping.php#L685-L690
gpupo/common-schema
src/ORM/Entity/Trading/Order/Shipping/Shipping.php
Shipping.addProduct
public function addProduct(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Product\Product $product) { $this->products[] = $product; return $this; }
php
public function addProduct(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Product\Product $product) { $this->products[] = $product; return $this; }
[ "public", "function", "addProduct", "(", "\\", "Gpupo", "\\", "CommonSchema", "\\", "ORM", "\\", "Entity", "\\", "Trading", "\\", "Order", "\\", "Shipping", "\\", "Product", "\\", "Product", "$", "product", ")", "{", "$", "this", "->", "products", "[", "]", "=", "$", "product", ";", "return", "$", "this", ";", "}" ]
Add product. @param \Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Product\Product $product @return Shipping
[ "Add", "product", "." ]
train
https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Trading/Order/Shipping/Shipping.php#L709-L714
gpupo/common-schema
src/ORM/Entity/Trading/Order/Shipping/Shipping.php
Shipping.removeProduct
public function removeProduct(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Product\Product $product) { return $this->products->removeElement($product); }
php
public function removeProduct(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Product\Product $product) { return $this->products->removeElement($product); }
[ "public", "function", "removeProduct", "(", "\\", "Gpupo", "\\", "CommonSchema", "\\", "ORM", "\\", "Entity", "\\", "Trading", "\\", "Order", "\\", "Shipping", "\\", "Product", "\\", "Product", "$", "product", ")", "{", "return", "$", "this", "->", "products", "->", "removeElement", "(", "$", "product", ")", ";", "}" ]
Remove product. @param \Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Product\Product $product @return bool TRUE if this collection contained the specified element, FALSE otherwise
[ "Remove", "product", "." ]
train
https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Trading/Order/Shipping/Shipping.php#L723-L726
gpupo/common-schema
src/ORM/Entity/Trading/Order/Shipping/Shipping.php
Shipping.addTransport
public function addTransport(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Transport\Transport $transport) { $this->transports[] = $transport; return $this; }
php
public function addTransport(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Transport\Transport $transport) { $this->transports[] = $transport; return $this; }
[ "public", "function", "addTransport", "(", "\\", "Gpupo", "\\", "CommonSchema", "\\", "ORM", "\\", "Entity", "\\", "Trading", "\\", "Order", "\\", "Shipping", "\\", "Transport", "\\", "Transport", "$", "transport", ")", "{", "$", "this", "->", "transports", "[", "]", "=", "$", "transport", ";", "return", "$", "this", ";", "}" ]
Add transport. @param \Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Transport\Transport $transport @return Shipping
[ "Add", "transport", "." ]
train
https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Trading/Order/Shipping/Shipping.php#L745-L750