repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
Eden-PHP/Block
Field.php
Field.wysiwyg
public function wysiwyg($name = null, $value = null) { Argument::i() ->test(1, 'string', 'null') ->test(2, 'scalar', 'null'); $field = Wysiwyg::i(); if(!is_null($name)) { $field->setName($name); } if(!is_null($value)) { $field->setValue($value); } return $field; }
php
public function wysiwyg($name = null, $value = null) { Argument::i() ->test(1, 'string', 'null') ->test(2, 'scalar', 'null'); $field = Wysiwyg::i(); if(!is_null($name)) { $field->setName($name); } if(!is_null($value)) { $field->setValue($value); } return $field; }
[ "public", "function", "wysiwyg", "(", "$", "name", "=", "null", ",", "$", "value", "=", "null", ")", "{", "Argument", "::", "i", "(", ")", "->", "test", "(", "1", ",", "'string'", ",", "'null'", ")", "->", "test", "(", "2", ",", "'scalar'", ",", "'null'", ")", ";", "$", "field", "=", "Wysiwyg", "::", "i", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "name", ")", ")", "{", "$", "field", "->", "setName", "(", "$", "name", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "$", "field", "->", "setValue", "(", "$", "value", ")", ";", "}", "return", "$", "field", ";", "}" ]
Returns a WYSIWYG field @param string|null @param scalar|null @return Eden\Block\Field\Wysiwyg
[ "Returns", "a", "WYSIWYG", "field" ]
681b9f01dd118612d0fced84d2f702167b52109b
https://github.com/Eden-PHP/Block/blob/681b9f01dd118612d0fced84d2f702167b52109b/Field.php#L582-L599
train
Innmind/Compose
src/Dependencies.php
Dependencies.exposed
public function exposed(): MapInterface { return $this->dependencies->reduce( new Map(Name::class, MapInterface::class), static function(Map $exposed, string $name, Dependency $dependency): Map { return $exposed->put( $dependency->name(), $dependency->exposed() ); } ); }
php
public function exposed(): MapInterface { return $this->dependencies->reduce( new Map(Name::class, MapInterface::class), static function(Map $exposed, string $name, Dependency $dependency): Map { return $exposed->put( $dependency->name(), $dependency->exposed() ); } ); }
[ "public", "function", "exposed", "(", ")", ":", "MapInterface", "{", "return", "$", "this", "->", "dependencies", "->", "reduce", "(", "new", "Map", "(", "Name", "::", "class", ",", "MapInterface", "::", "class", ")", ",", "static", "function", "(", "Map", "$", "exposed", ",", "string", "$", "name", ",", "Dependency", "$", "dependency", ")", ":", "Map", "{", "return", "$", "exposed", "->", "put", "(", "$", "dependency", "->", "name", "(", ")", ",", "$", "dependency", "->", "exposed", "(", ")", ")", ";", "}", ")", ";", "}" ]
Return the list of exposed services per dependency @return MapInterface<Name, MapInterface<Name, Constructor>>
[ "Return", "the", "list", "of", "exposed", "services", "per", "dependency" ]
1a833d7ba2f6248e9c472c00cd7aca041c1a2ba9
https://github.com/Innmind/Compose/blob/1a833d7ba2f6248e9c472c00cd7aca041c1a2ba9/src/Dependencies.php#L138-L149
train
wb-crowdfusion/crowdfusion
system/core/classes/nodedb/permissions/NodePermissions.php
NodePermissions.check
public function check($action, NodeRef &$nodeRef, &$newData = null, $isRead = false) { return $this->checkInternal($action, $nodeRef, $newData, false, $isRead); }
php
public function check($action, NodeRef &$nodeRef, &$newData = null, $isRead = false) { return $this->checkInternal($action, $nodeRef, $newData, false, $isRead); }
[ "public", "function", "check", "(", "$", "action", ",", "NodeRef", "&", "$", "nodeRef", ",", "&", "$", "newData", "=", "null", ",", "$", "isRead", "=", "false", ")", "{", "return", "$", "this", "->", "checkInternal", "(", "$", "action", ",", "$", "nodeRef", ",", "$", "newData", ",", "false", ",", "$", "isRead", ")", ";", "}" ]
Returns true if the user is permitted to access the node @param $action @param $nodeRef @param $newData @param $isRead @return unknown_type
[ "Returns", "true", "if", "the", "user", "is", "permitted", "to", "access", "the", "node" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/permissions/NodePermissions.php#L102-L105
train
wb-crowdfusion/crowdfusion
system/core/classes/nodedb/permissions/NodePermissions.php
NodePermissions.checkThrow
public function checkThrow($action, NodeRef &$nodeRef, &$newData = null, $isRead = false) { return $this->checkInternal($action, $nodeRef, $newData, true, $isRead); }
php
public function checkThrow($action, NodeRef &$nodeRef, &$newData = null, $isRead = false) { return $this->checkInternal($action, $nodeRef, $newData, true, $isRead); }
[ "public", "function", "checkThrow", "(", "$", "action", ",", "NodeRef", "&", "$", "nodeRef", ",", "&", "$", "newData", "=", "null", ",", "$", "isRead", "=", "false", ")", "{", "return", "$", "this", "->", "checkInternal", "(", "$", "action", ",", "$", "nodeRef", ",", "$", "newData", ",", "true", ",", "$", "isRead", ")", ";", "}" ]
Throws a PermissionsException if the user is unable to access the node, otherwise returns true @param $action @param $nodeRef @param $newData @param $isRead @return unknown_type
[ "Throws", "a", "PermissionsException", "if", "the", "user", "is", "unable", "to", "access", "the", "node", "otherwise", "returns", "true" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/permissions/NodePermissions.php#L116-L119
train
ekyna/MediaBundle
Twig/BrowserExtension.php
BrowserExtension.renderMediaThumb
public function renderMediaThumb(MediaInterface $media = null, array $controls = array()) { if (null !== $media) { $media->setThumb($this->thumbGenerator->generateThumbUrl($media)); } /*if (empty($controls)) { $controls = array( array('role' => 'edit', 'icon' => 'pencil'), //array('role' => 'delete', 'icon' => 'trash'), array('role' => 'download', 'icon' => 'download'), ); }*/ foreach ($controls as $control) { if (!(array_key_exists('role', $control) && array_key_exists('icon', $control))) { throw new \InvalidArgumentException('Controls must have "role" and "icon" defined.'); } } $data = '{}'; if ($media) { $context = SerializationContext::create()->setGroups(array('Manager')); $data = $this->serializer->serialize($media, 'json', $context); } return $this->thumbTemplate->render(array( 'media' => $media, 'data' => $data, 'controls' => $controls, 'selector' => false, )); }
php
public function renderMediaThumb(MediaInterface $media = null, array $controls = array()) { if (null !== $media) { $media->setThumb($this->thumbGenerator->generateThumbUrl($media)); } /*if (empty($controls)) { $controls = array( array('role' => 'edit', 'icon' => 'pencil'), //array('role' => 'delete', 'icon' => 'trash'), array('role' => 'download', 'icon' => 'download'), ); }*/ foreach ($controls as $control) { if (!(array_key_exists('role', $control) && array_key_exists('icon', $control))) { throw new \InvalidArgumentException('Controls must have "role" and "icon" defined.'); } } $data = '{}'; if ($media) { $context = SerializationContext::create()->setGroups(array('Manager')); $data = $this->serializer->serialize($media, 'json', $context); } return $this->thumbTemplate->render(array( 'media' => $media, 'data' => $data, 'controls' => $controls, 'selector' => false, )); }
[ "public", "function", "renderMediaThumb", "(", "MediaInterface", "$", "media", "=", "null", ",", "array", "$", "controls", "=", "array", "(", ")", ")", "{", "if", "(", "null", "!==", "$", "media", ")", "{", "$", "media", "->", "setThumb", "(", "$", "this", "->", "thumbGenerator", "->", "generateThumbUrl", "(", "$", "media", ")", ")", ";", "}", "/*if (empty($controls)) {\n $controls = array(\n array('role' => 'edit', 'icon' => 'pencil'),\n //array('role' => 'delete', 'icon' => 'trash'),\n array('role' => 'download', 'icon' => 'download'),\n );\n }*/", "foreach", "(", "$", "controls", "as", "$", "control", ")", "{", "if", "(", "!", "(", "array_key_exists", "(", "'role'", ",", "$", "control", ")", "&&", "array_key_exists", "(", "'icon'", ",", "$", "control", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Controls must have \"role\" and \"icon\" defined.'", ")", ";", "}", "}", "$", "data", "=", "'{}'", ";", "if", "(", "$", "media", ")", "{", "$", "context", "=", "SerializationContext", "::", "create", "(", ")", "->", "setGroups", "(", "array", "(", "'Manager'", ")", ")", ";", "$", "data", "=", "$", "this", "->", "serializer", "->", "serialize", "(", "$", "media", ",", "'json'", ",", "$", "context", ")", ";", "}", "return", "$", "this", "->", "thumbTemplate", "->", "render", "(", "array", "(", "'media'", "=>", "$", "media", ",", "'data'", "=>", "$", "data", ",", "'controls'", "=>", "$", "controls", ",", "'selector'", "=>", "false", ",", ")", ")", ";", "}" ]
Renders the media thumb. @param MediaInterface $media @param array $controls @return string
[ "Renders", "the", "media", "thumb", "." ]
512cf86c801a130a9f17eba8b48d646d23acdbab
https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Twig/BrowserExtension.php#L119-L149
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.build
public function build($configs) { foreach ($configs as $config) { $this->config = $config; $this->initVars(); $this->loadColumns(); $this->buildDataClasses(); $this->buildMapperClasses(); $this->generateClasses(); } return $this; }
php
public function build($configs) { foreach ($configs as $config) { $this->config = $config; $this->initVars(); $this->loadColumns(); $this->buildDataClasses(); $this->buildMapperClasses(); $this->generateClasses(); } return $this; }
[ "public", "function", "build", "(", "$", "configs", ")", "{", "foreach", "(", "$", "configs", "as", "$", "config", ")", "{", "$", "this", "->", "config", "=", "$", "config", ";", "$", "this", "->", "initVars", "(", ")", ";", "$", "this", "->", "loadColumns", "(", ")", ";", "$", "this", "->", "buildDataClasses", "(", ")", ";", "$", "this", "->", "buildMapperClasses", "(", ")", ";", "$", "this", "->", "generateClasses", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Build model classes. @param ConfigInterface[] $configs @return $this
[ "Build", "model", "classes", "." ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L119-L134
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.loadColumns
protected function loadColumns() { $statement = $this->db->query('SHOW COLUMNS FROM ' . $this->config->getDbTable()); $this->columns = array(); while (false !== ($column = $statement->fetchObject())) { $this->columns[] = new Column($column, $this->config->getDbPrefix()); } }
php
protected function loadColumns() { $statement = $this->db->query('SHOW COLUMNS FROM ' . $this->config->getDbTable()); $this->columns = array(); while (false !== ($column = $statement->fetchObject())) { $this->columns[] = new Column($column, $this->config->getDbPrefix()); } }
[ "protected", "function", "loadColumns", "(", ")", "{", "$", "statement", "=", "$", "this", "->", "db", "->", "query", "(", "'SHOW COLUMNS FROM '", ".", "$", "this", "->", "config", "->", "getDbTable", "(", ")", ")", ";", "$", "this", "->", "columns", "=", "array", "(", ")", ";", "while", "(", "false", "!==", "(", "$", "column", "=", "$", "statement", "->", "fetchObject", "(", ")", ")", ")", "{", "$", "this", "->", "columns", "[", "]", "=", "new", "Column", "(", "$", "column", ",", "$", "this", "->", "config", "->", "getDbPrefix", "(", ")", ")", ";", "}", "}" ]
Load columns data. @return void
[ "Load", "columns", "data", "." ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L156-L164
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.buildDataProperties
protected function buildDataProperties() { $properties = ''; $hasAutoincrement = false; foreach ($this->columns as $column) { $properties .= "\n" . $column->getProperty(); $hasAutoincrement |= $column->isAutoIncrement(); } if ($hasAutoincrement) { $properties = ' /** * @var bool $hasAutoIncrement If data has auto increment value. */ protected $hasAutoIncrement = true;' . $properties; } $this->vars['properties'] = $properties; }
php
protected function buildDataProperties() { $properties = ''; $hasAutoincrement = false; foreach ($this->columns as $column) { $properties .= "\n" . $column->getProperty(); $hasAutoincrement |= $column->isAutoIncrement(); } if ($hasAutoincrement) { $properties = ' /** * @var bool $hasAutoIncrement If data has auto increment value. */ protected $hasAutoIncrement = true;' . $properties; } $this->vars['properties'] = $properties; }
[ "protected", "function", "buildDataProperties", "(", ")", "{", "$", "properties", "=", "''", ";", "$", "hasAutoincrement", "=", "false", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", ")", "{", "$", "properties", ".=", "\"\\n\"", ".", "$", "column", "->", "getProperty", "(", ")", ";", "$", "hasAutoincrement", "|=", "$", "column", "->", "isAutoIncrement", "(", ")", ";", "}", "if", "(", "$", "hasAutoincrement", ")", "{", "$", "properties", "=", "'\n /**\n * @var bool $hasAutoIncrement If data has auto increment value.\n */\n protected $hasAutoIncrement = true;'", ".", "$", "properties", ";", "}", "$", "this", "->", "vars", "[", "'properties'", "]", "=", "$", "properties", ";", "}" ]
Build properties var @return void
[ "Build", "properties", "var" ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L192-L211
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.buildDataGetters
protected function buildDataGetters() { $getters = ''; foreach ($this->columns as $column) { $getters .= "\n" . $column->getGetter(); } $this->vars['getters'] = $getters; }
php
protected function buildDataGetters() { $getters = ''; foreach ($this->columns as $column) { $getters .= "\n" . $column->getGetter(); } $this->vars['getters'] = $getters; }
[ "protected", "function", "buildDataGetters", "(", ")", "{", "$", "getters", "=", "''", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", ")", "{", "$", "getters", ".=", "\"\\n\"", ".", "$", "column", "->", "getGetter", "(", ")", ";", "}", "$", "this", "->", "vars", "[", "'getters'", "]", "=", "$", "getters", ";", "}" ]
Build getters var @return void
[ "Build", "getters", "var" ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L218-L227
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.buildDataGetterCacheKey
protected function buildDataGetterCacheKey() { $keys = array(); foreach ($this->columns as $column) { if ($column->isPrimaryKey()) { $keys[] = '$this->' . $column->getMethodNameGet() . '()'; } } $key = "'" . $this->config->getCachePrefix() . "_data_' . " . implode(" . '_' . ", $keys); $this->vars['cache_key'] = ' /** * Get cache key * * @return string */ public function getCacheKey() { return ' . $key . '; }'; }
php
protected function buildDataGetterCacheKey() { $keys = array(); foreach ($this->columns as $column) { if ($column->isPrimaryKey()) { $keys[] = '$this->' . $column->getMethodNameGet() . '()'; } } $key = "'" . $this->config->getCachePrefix() . "_data_' . " . implode(" . '_' . ", $keys); $this->vars['cache_key'] = ' /** * Get cache key * * @return string */ public function getCacheKey() { return ' . $key . '; }'; }
[ "protected", "function", "buildDataGetterCacheKey", "(", ")", "{", "$", "keys", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", ")", "{", "if", "(", "$", "column", "->", "isPrimaryKey", "(", ")", ")", "{", "$", "keys", "[", "]", "=", "'$this->'", ".", "$", "column", "->", "getMethodNameGet", "(", ")", ".", "'()'", ";", "}", "}", "$", "key", "=", "\"'\"", ".", "$", "this", "->", "config", "->", "getCachePrefix", "(", ")", ".", "\"_data_' . \"", ".", "implode", "(", "\" . '_' . \"", ",", "$", "keys", ")", ";", "$", "this", "->", "vars", "[", "'cache_key'", "]", "=", "'\n /**\n * Get cache key\n *\n * @return string\n */\n public function getCacheKey()\n {\n return '", ".", "$", "key", ".", "';\n }'", ";", "}" ]
Build cache key method @return void
[ "Build", "cache", "key", "method" ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L234-L256
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.buildDataSetters
protected function buildDataSetters() { $setters = ''; foreach ($this->columns as $column) { $setters .= "\n" . $column->getSetter(); } $this->vars['setters'] = $setters; }
php
protected function buildDataSetters() { $setters = ''; foreach ($this->columns as $column) { $setters .= "\n" . $column->getSetter(); } $this->vars['setters'] = $setters; }
[ "protected", "function", "buildDataSetters", "(", ")", "{", "$", "setters", "=", "''", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", ")", "{", "$", "setters", ".=", "\"\\n\"", ".", "$", "column", "->", "getSetter", "(", ")", ";", "}", "$", "this", "->", "vars", "[", "'setters'", "]", "=", "$", "setters", ";", "}" ]
Build setters var @return void
[ "Build", "setters", "var" ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L263-L272
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.buildDataJoins
protected function buildDataJoins() { $joins = array('one' => array(), 'many' => array()); $joinsUse = array(); foreach ($this->config->getAllJoin() as $name => $join) { $config = $join['class']; if (!($config instanceof ConfigInterface)) { throw new \LogicException('Joined class is not an instance of ConfigInterface!'); } $class = $config->getClassname(); if ('one' === $join['type']) { $joinMethod = $this->buildDataJoinsOne($config, $join['keys']); } else { $joinMethod = $this->buildDataJoinsMany($config, $join['keys']); } $joins[$join['type']][] = $joinMethod; $joinsUse[$class] = 'use ' . $this->baseNamespace . 'Data\\' . $config->getNamespace() . '\\' . $class . ';'; $joinsUse[$class . 'Mapper'] = 'use ' . $this->baseNamespace . 'Mapper\\' . $config->getNamespace() . '\\' . $class . 'Mapper;'; } $this->vars['joins_use'] = implode("\n", $joinsUse); $this->vars['joins'] = implode("\n", $joins['one']) . "\n" . implode("\n", $joins['many']); }
php
protected function buildDataJoins() { $joins = array('one' => array(), 'many' => array()); $joinsUse = array(); foreach ($this->config->getAllJoin() as $name => $join) { $config = $join['class']; if (!($config instanceof ConfigInterface)) { throw new \LogicException('Joined class is not an instance of ConfigInterface!'); } $class = $config->getClassname(); if ('one' === $join['type']) { $joinMethod = $this->buildDataJoinsOne($config, $join['keys']); } else { $joinMethod = $this->buildDataJoinsMany($config, $join['keys']); } $joins[$join['type']][] = $joinMethod; $joinsUse[$class] = 'use ' . $this->baseNamespace . 'Data\\' . $config->getNamespace() . '\\' . $class . ';'; $joinsUse[$class . 'Mapper'] = 'use ' . $this->baseNamespace . 'Mapper\\' . $config->getNamespace() . '\\' . $class . 'Mapper;'; } $this->vars['joins_use'] = implode("\n", $joinsUse); $this->vars['joins'] = implode("\n", $joins['one']) . "\n" . implode("\n", $joins['many']); }
[ "protected", "function", "buildDataJoins", "(", ")", "{", "$", "joins", "=", "array", "(", "'one'", "=>", "array", "(", ")", ",", "'many'", "=>", "array", "(", ")", ")", ";", "$", "joinsUse", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "config", "->", "getAllJoin", "(", ")", "as", "$", "name", "=>", "$", "join", ")", "{", "$", "config", "=", "$", "join", "[", "'class'", "]", ";", "if", "(", "!", "(", "$", "config", "instanceof", "ConfigInterface", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "'Joined class is not an instance of ConfigInterface!'", ")", ";", "}", "$", "class", "=", "$", "config", "->", "getClassname", "(", ")", ";", "if", "(", "'one'", "===", "$", "join", "[", "'type'", "]", ")", "{", "$", "joinMethod", "=", "$", "this", "->", "buildDataJoinsOne", "(", "$", "config", ",", "$", "join", "[", "'keys'", "]", ")", ";", "}", "else", "{", "$", "joinMethod", "=", "$", "this", "->", "buildDataJoinsMany", "(", "$", "config", ",", "$", "join", "[", "'keys'", "]", ")", ";", "}", "$", "joins", "[", "$", "join", "[", "'type'", "]", "]", "[", "]", "=", "$", "joinMethod", ";", "$", "joinsUse", "[", "$", "class", "]", "=", "'use '", ".", "$", "this", "->", "baseNamespace", ".", "'Data\\\\'", ".", "$", "config", "->", "getNamespace", "(", ")", ".", "'\\\\'", ".", "$", "class", ".", "';'", ";", "$", "joinsUse", "[", "$", "class", ".", "'Mapper'", "]", "=", "'use '", ".", "$", "this", "->", "baseNamespace", ".", "'Mapper\\\\'", ".", "$", "config", "->", "getNamespace", "(", ")", ".", "'\\\\'", ".", "$", "class", ".", "'Mapper;'", ";", "}", "$", "this", "->", "vars", "[", "'joins_use'", "]", "=", "implode", "(", "\"\\n\"", ",", "$", "joinsUse", ")", ";", "$", "this", "->", "vars", "[", "'joins'", "]", "=", "implode", "(", "\"\\n\"", ",", "$", "joins", "[", "'one'", "]", ")", ".", "\"\\n\"", ".", "implode", "(", "\"\\n\"", ",", "$", "joins", "[", "'many'", "]", ")", ";", "}" ]
Build join getters @return void @throws \LogicException
[ "Build", "join", "getters" ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L280-L309
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.buildDataJoinsMany
protected function buildDataJoinsMany(ConfigInterface $config, array $joinKeys) { //~ Search for keys $keys = ''; $joinKeys = array_flip($joinKeys); foreach ($this->columns as $column) { if (!isset($joinKeys[$column->getName()])) { continue; } $keys .= ' $mapper->addWhere(\'' . $column->getName() . '\', $this->' . $column->getMethodNameGet() .'());'; } if (empty($keys)) { throw new \LogicException('Empty keys list for join all method !'); } $propertyCacheName = 'joinManyCache' . $config->getClassname(); $this->vars['properties'] .= ' /** * @var ' . $config->getClassname() . '[] $' . $propertyCacheName . ' */ protected $' . $propertyCacheName . ' = null;'; //~ Generate method return ' /** * Get list of ' . $config->getClassname() . ' data objects. * * @param bool $isForceReload * @return ' . $config->getClassname() . '[] */ public function getAll' . $config->getClassname() . '($isForceReload = false) { if ($isForceReload || null === $this->' . $propertyCacheName . ') { $mapper = new ' . $config->getClassname() . 'Mapper($this->dependencyContainer->getDatabase(\'' . $config->getDbConfig() . '\'));' . $keys . ' $this->' . $propertyCacheName . ' = $mapper->select(); } return $this->' . $propertyCacheName . '; } '; }
php
protected function buildDataJoinsMany(ConfigInterface $config, array $joinKeys) { //~ Search for keys $keys = ''; $joinKeys = array_flip($joinKeys); foreach ($this->columns as $column) { if (!isset($joinKeys[$column->getName()])) { continue; } $keys .= ' $mapper->addWhere(\'' . $column->getName() . '\', $this->' . $column->getMethodNameGet() .'());'; } if (empty($keys)) { throw new \LogicException('Empty keys list for join all method !'); } $propertyCacheName = 'joinManyCache' . $config->getClassname(); $this->vars['properties'] .= ' /** * @var ' . $config->getClassname() . '[] $' . $propertyCacheName . ' */ protected $' . $propertyCacheName . ' = null;'; //~ Generate method return ' /** * Get list of ' . $config->getClassname() . ' data objects. * * @param bool $isForceReload * @return ' . $config->getClassname() . '[] */ public function getAll' . $config->getClassname() . '($isForceReload = false) { if ($isForceReload || null === $this->' . $propertyCacheName . ') { $mapper = new ' . $config->getClassname() . 'Mapper($this->dependencyContainer->getDatabase(\'' . $config->getDbConfig() . '\'));' . $keys . ' $this->' . $propertyCacheName . ' = $mapper->select(); } return $this->' . $propertyCacheName . '; } '; }
[ "protected", "function", "buildDataJoinsMany", "(", "ConfigInterface", "$", "config", ",", "array", "$", "joinKeys", ")", "{", "//~ Search for keys", "$", "keys", "=", "''", ";", "$", "joinKeys", "=", "array_flip", "(", "$", "joinKeys", ")", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", ")", "{", "if", "(", "!", "isset", "(", "$", "joinKeys", "[", "$", "column", "->", "getName", "(", ")", "]", ")", ")", "{", "continue", ";", "}", "$", "keys", ".=", "'\n $mapper->addWhere(\\''", ".", "$", "column", "->", "getName", "(", ")", ".", "'\\', $this->'", ".", "$", "column", "->", "getMethodNameGet", "(", ")", ".", "'());'", ";", "}", "if", "(", "empty", "(", "$", "keys", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "'Empty keys list for join all method !'", ")", ";", "}", "$", "propertyCacheName", "=", "'joinManyCache'", ".", "$", "config", "->", "getClassname", "(", ")", ";", "$", "this", "->", "vars", "[", "'properties'", "]", ".=", "'\n\n /**\n * @var '", ".", "$", "config", "->", "getClassname", "(", ")", ".", "'[] $'", ".", "$", "propertyCacheName", ".", "'\n */\n protected $'", ".", "$", "propertyCacheName", ".", "' = null;'", ";", "//~ Generate method", "return", "'\n /**\n * Get list of '", ".", "$", "config", "->", "getClassname", "(", ")", ".", "' data objects.\n *\n * @param bool $isForceReload\n * @return '", ".", "$", "config", "->", "getClassname", "(", ")", ".", "'[]\n */\n public function getAll'", ".", "$", "config", "->", "getClassname", "(", ")", ".", "'($isForceReload = false)\n {\n if ($isForceReload || null === $this->'", ".", "$", "propertyCacheName", ".", "') {\n $mapper = new '", ".", "$", "config", "->", "getClassname", "(", ")", ".", "'Mapper($this->dependencyContainer->getDatabase(\\''", ".", "$", "config", "->", "getDbConfig", "(", ")", ".", "'\\'));'", ".", "$", "keys", ".", "'\n\n $this->'", ".", "$", "propertyCacheName", ".", "' = $mapper->select();\n }\n \n return $this->'", ".", "$", "propertyCacheName", ".", "';\n }\n'", ";", "}" ]
Build join many getters @param ConfigInterface $config @param array $joinKeys @return string @throws \LogicException
[ "Build", "join", "many", "getters" ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L374-L420
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.buildMapperFields
protected function buildMapperFields() { $fields = array(); $dataNamesMap = ''; foreach ($this->columns as $column) { $field = $column->getName(); $fields[] = " '" . $field . "'"; $dataNamesMap .= " '" . $field . "' => array( 'get' => '" . $column->getMethodNameGet() . "', 'set' => '" . $column->getMethodNameSet() . "', 'property' => '" . $column->getPropertyName() . "', ),"; } $this->vars['db_fields'] = implode(",\n", $fields); $this->vars['data_names_map'] = $dataNamesMap; }
php
protected function buildMapperFields() { $fields = array(); $dataNamesMap = ''; foreach ($this->columns as $column) { $field = $column->getName(); $fields[] = " '" . $field . "'"; $dataNamesMap .= " '" . $field . "' => array( 'get' => '" . $column->getMethodNameGet() . "', 'set' => '" . $column->getMethodNameSet() . "', 'property' => '" . $column->getPropertyName() . "', ),"; } $this->vars['db_fields'] = implode(",\n", $fields); $this->vars['data_names_map'] = $dataNamesMap; }
[ "protected", "function", "buildMapperFields", "(", ")", "{", "$", "fields", "=", "array", "(", ")", ";", "$", "dataNamesMap", "=", "''", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", ")", "{", "$", "field", "=", "$", "column", "->", "getName", "(", ")", ";", "$", "fields", "[", "]", "=", "\" '\"", ".", "$", "field", ".", "\"'\"", ";", "$", "dataNamesMap", ".=", "\"\n '\"", ".", "$", "field", ".", "\"' => array(\n 'get' => '\"", ".", "$", "column", "->", "getMethodNameGet", "(", ")", ".", "\"',\n 'set' => '\"", ".", "$", "column", "->", "getMethodNameSet", "(", ")", ".", "\"',\n 'property' => '\"", ".", "$", "column", "->", "getPropertyName", "(", ")", ".", "\"',\n ),\"", ";", "}", "$", "this", "->", "vars", "[", "'db_fields'", "]", "=", "implode", "(", "\",\\n\"", ",", "$", "fields", ")", ";", "$", "this", "->", "vars", "[", "'data_names_map'", "]", "=", "$", "dataNamesMap", ";", "}" ]
Build fields var @return void
[ "Build", "fields", "var" ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L456-L474
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.buildMapperPrimaryKeys
protected function buildMapperPrimaryKeys() { $fields = array(); foreach ($this->columns as $column) { if ($column->isPrimaryKey()) { $fields[] = " '" . $column->getName() . "'"; } } $this->vars['db_primary_keys'] = implode(",\n", $fields); }
php
protected function buildMapperPrimaryKeys() { $fields = array(); foreach ($this->columns as $column) { if ($column->isPrimaryKey()) { $fields[] = " '" . $column->getName() . "'"; } } $this->vars['db_primary_keys'] = implode(",\n", $fields); }
[ "protected", "function", "buildMapperPrimaryKeys", "(", ")", "{", "$", "fields", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", ")", "{", "if", "(", "$", "column", "->", "isPrimaryKey", "(", ")", ")", "{", "$", "fields", "[", "]", "=", "\" '\"", ".", "$", "column", "->", "getName", "(", ")", ".", "\"'\"", ";", "}", "}", "$", "this", "->", "vars", "[", "'db_primary_keys'", "]", "=", "implode", "(", "\",\\n\"", ",", "$", "fields", ")", ";", "}" ]
Build primary keys var @return void
[ "Build", "primary", "keys", "var" ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L481-L493
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.generateDataFileAbstract
protected function generateDataFileAbstract($dir) { $file = $dir . '/' . $this->config->getClassname() . 'Abstract.php'; if (!is_readable($file) && false === file_put_contents($file, '')) { throw new \RuntimeException('Cannot create empty class file: ' . $file); } $content = '<?php /** * Copyright (c) 2010-' . date('Y') . ' ' . $this->config->getAuthor() . ' * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ' . $this->baseNamespace . 'Data\\' . $this->config->getNamespace() . '\Abstracts; use Eureka\Component\Orm\DataMapper\DataAbstract; ' . $this->vars['joins_use'] . ' /** * /!\ AUTO GENERATED FILE. DO NOT EDIT THIS FILE. * THIS FILE IS OVERWRITTEN WHEN THE ORM SCRIPT GENERATOR IS RUN. * You can add you specific code in child class: ' . $this->config->getClassname() . ' * * @author ' . $this->config->getAuthor() . ' * @version ' . $this->config->getVersion() . ' */ abstract class ' . $this->config->getClassname() . 'Abstract extends DataAbstract {' . $this->vars['properties'] . ' ' . $this->vars['cache_key'] . ' ' . $this->vars['getters'] . ' ' . $this->vars['setters'] . ' ' . $this->vars['joins'] . '} '; if (false === file_put_contents($file, $content)) { throw new \RuntimeException('Unable to write file content! (file: ' . $file . ')'); } }
php
protected function generateDataFileAbstract($dir) { $file = $dir . '/' . $this->config->getClassname() . 'Abstract.php'; if (!is_readable($file) && false === file_put_contents($file, '')) { throw new \RuntimeException('Cannot create empty class file: ' . $file); } $content = '<?php /** * Copyright (c) 2010-' . date('Y') . ' ' . $this->config->getAuthor() . ' * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ' . $this->baseNamespace . 'Data\\' . $this->config->getNamespace() . '\Abstracts; use Eureka\Component\Orm\DataMapper\DataAbstract; ' . $this->vars['joins_use'] . ' /** * /!\ AUTO GENERATED FILE. DO NOT EDIT THIS FILE. * THIS FILE IS OVERWRITTEN WHEN THE ORM SCRIPT GENERATOR IS RUN. * You can add you specific code in child class: ' . $this->config->getClassname() . ' * * @author ' . $this->config->getAuthor() . ' * @version ' . $this->config->getVersion() . ' */ abstract class ' . $this->config->getClassname() . 'Abstract extends DataAbstract {' . $this->vars['properties'] . ' ' . $this->vars['cache_key'] . ' ' . $this->vars['getters'] . ' ' . $this->vars['setters'] . ' ' . $this->vars['joins'] . '} '; if (false === file_put_contents($file, $content)) { throw new \RuntimeException('Unable to write file content! (file: ' . $file . ')'); } }
[ "protected", "function", "generateDataFileAbstract", "(", "$", "dir", ")", "{", "$", "file", "=", "$", "dir", ".", "'/'", ".", "$", "this", "->", "config", "->", "getClassname", "(", ")", ".", "'Abstract.php'", ";", "if", "(", "!", "is_readable", "(", "$", "file", ")", "&&", "false", "===", "file_put_contents", "(", "$", "file", ",", "''", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot create empty class file: '", ".", "$", "file", ")", ";", "}", "$", "content", "=", "'<?php\n\n/**\n * Copyright (c) 2010-'", ".", "date", "(", "'Y'", ")", ".", "' '", ".", "$", "this", "->", "config", "->", "getAuthor", "(", ")", ".", "'\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nnamespace '", ".", "$", "this", "->", "baseNamespace", ".", "'Data\\\\'", ".", "$", "this", "->", "config", "->", "getNamespace", "(", ")", ".", "'\\Abstracts;\n\nuse Eureka\\Component\\Orm\\DataMapper\\DataAbstract;\n'", ".", "$", "this", "->", "vars", "[", "'joins_use'", "]", ".", "'\n\n/**\n * /!\\ AUTO GENERATED FILE. DO NOT EDIT THIS FILE.\n * THIS FILE IS OVERWRITTEN WHEN THE ORM SCRIPT GENERATOR IS RUN.\n * You can add you specific code in child class: '", ".", "$", "this", "->", "config", "->", "getClassname", "(", ")", ".", "'\n *\n * @author '", ".", "$", "this", "->", "config", "->", "getAuthor", "(", ")", ".", "'\n * @version '", ".", "$", "this", "->", "config", "->", "getVersion", "(", ")", ".", "'\n */\nabstract class '", ".", "$", "this", "->", "config", "->", "getClassname", "(", ")", ".", "'Abstract extends DataAbstract\n{'", ".", "$", "this", "->", "vars", "[", "'properties'", "]", ".", "'\n'", ".", "$", "this", "->", "vars", "[", "'cache_key'", "]", ".", "'\n'", ".", "$", "this", "->", "vars", "[", "'getters'", "]", ".", "'\n'", ".", "$", "this", "->", "vars", "[", "'setters'", "]", ".", "'\n'", ".", "$", "this", "->", "vars", "[", "'joins'", "]", ".", "'}\n'", ";", "if", "(", "false", "===", "file_put_contents", "(", "$", "file", ",", "$", "content", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Unable to write file content! (file: '", ".", "$", "file", ".", "')'", ")", ";", "}", "}" ]
Generate abstract file class. @param string $dir Directory for class @return void @throws \RuntimeException
[ "Generate", "abstract", "file", "class", "." ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L539-L579
train
eureka-framework/component-orm
src/Orm/Builder.php
Builder.generateDataFile
protected function generateDataFile($dir) { $file = $dir . '/' . $this->config->getClassname() . '.php'; if (file_exists($file)) { return; } if (!is_readable($file) && false === file_put_contents($file, '')) { throw new \RuntimeException('Cannot create empty class file: ' . $file); } $content = '<?php /** * Copyright (c) 2010-' . date('Y') . ' ' . $this->config->getAuthor() . ' * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ' . $this->baseNamespace . 'Data\\' . $this->config->getNamespace() . '; /** * DataMapper Data class for table "' . $this->config->getDbTable() . '" * * @author ' . $this->config->getAuthor() . ' * @version ' . $this->config->getVersion() . ' */ class ' . $this->config->getClassname() . ' extends Abstracts\\' . $this->config->getClassname() . 'Abstract { } '; if (false === file_put_contents($file, $content)) { throw new \RuntimeException('Unable to write file content! (file: ' . $file . ')'); } }
php
protected function generateDataFile($dir) { $file = $dir . '/' . $this->config->getClassname() . '.php'; if (file_exists($file)) { return; } if (!is_readable($file) && false === file_put_contents($file, '')) { throw new \RuntimeException('Cannot create empty class file: ' . $file); } $content = '<?php /** * Copyright (c) 2010-' . date('Y') . ' ' . $this->config->getAuthor() . ' * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ' . $this->baseNamespace . 'Data\\' . $this->config->getNamespace() . '; /** * DataMapper Data class for table "' . $this->config->getDbTable() . '" * * @author ' . $this->config->getAuthor() . ' * @version ' . $this->config->getVersion() . ' */ class ' . $this->config->getClassname() . ' extends Abstracts\\' . $this->config->getClassname() . 'Abstract { } '; if (false === file_put_contents($file, $content)) { throw new \RuntimeException('Unable to write file content! (file: ' . $file . ')'); } }
[ "protected", "function", "generateDataFile", "(", "$", "dir", ")", "{", "$", "file", "=", "$", "dir", ".", "'/'", ".", "$", "this", "->", "config", "->", "getClassname", "(", ")", ".", "'.php'", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "return", ";", "}", "if", "(", "!", "is_readable", "(", "$", "file", ")", "&&", "false", "===", "file_put_contents", "(", "$", "file", ",", "''", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot create empty class file: '", ".", "$", "file", ")", ";", "}", "$", "content", "=", "'<?php\n\n/**\n * Copyright (c) 2010-'", ".", "date", "(", "'Y'", ")", ".", "' '", ".", "$", "this", "->", "config", "->", "getAuthor", "(", ")", ".", "'\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nnamespace '", ".", "$", "this", "->", "baseNamespace", ".", "'Data\\\\'", ".", "$", "this", "->", "config", "->", "getNamespace", "(", ")", ".", "';\n\n/**\n * DataMapper Data class for table \"'", ".", "$", "this", "->", "config", "->", "getDbTable", "(", ")", ".", "'\"\n *\n * @author '", ".", "$", "this", "->", "config", "->", "getAuthor", "(", ")", ".", "'\n * @version '", ".", "$", "this", "->", "config", "->", "getVersion", "(", ")", ".", "'\n */\nclass '", ".", "$", "this", "->", "config", "->", "getClassname", "(", ")", ".", "' extends Abstracts\\\\'", ".", "$", "this", "->", "config", "->", "getClassname", "(", ")", ".", "'Abstract\n{\n}\n'", ";", "if", "(", "false", "===", "file_put_contents", "(", "$", "file", ",", "$", "content", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Unable to write file content! (file: '", ".", "$", "file", ".", "')'", ")", ";", "}", "}" ]
Generate child class if not already exists. @param string $dir Directory for class @return void @throws \RuntimeException
[ "Generate", "child", "class", "if", "not", "already", "exists", "." ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/Builder.php#L588-L624
train
ciims/ciims-modules-dashboard
controllers/ContentController.php
ContentController.actionSave
public function actionSave($id = NULL) { $asModel = NULL; if ($id == NULL) { $model = new Content; $model->savePrototype(Yii::app()->user->id); $this->redirect('/dashboard/content/save/id/' . $model->id); } else { $model = $this->loadModel($id); $asModel = ContentMetadata::model()->findByAttributes(array('content_id' => $model->id, 'key' => 'autosave')); if ($asModel != NULL) { $model->populate(CJSON::decode($asModel->value)); $model->autosavedata = true; } } $this->render('save', array( 'model' => $model )); }
php
public function actionSave($id = NULL) { $asModel = NULL; if ($id == NULL) { $model = new Content; $model->savePrototype(Yii::app()->user->id); $this->redirect('/dashboard/content/save/id/' . $model->id); } else { $model = $this->loadModel($id); $asModel = ContentMetadata::model()->findByAttributes(array('content_id' => $model->id, 'key' => 'autosave')); if ($asModel != NULL) { $model->populate(CJSON::decode($asModel->value)); $model->autosavedata = true; } } $this->render('save', array( 'model' => $model )); }
[ "public", "function", "actionSave", "(", "$", "id", "=", "NULL", ")", "{", "$", "asModel", "=", "NULL", ";", "if", "(", "$", "id", "==", "NULL", ")", "{", "$", "model", "=", "new", "Content", ";", "$", "model", "->", "savePrototype", "(", "Yii", "::", "app", "(", ")", "->", "user", "->", "id", ")", ";", "$", "this", "->", "redirect", "(", "'/dashboard/content/save/id/'", ".", "$", "model", "->", "id", ")", ";", "}", "else", "{", "$", "model", "=", "$", "this", "->", "loadModel", "(", "$", "id", ")", ";", "$", "asModel", "=", "ContentMetadata", "::", "model", "(", ")", "->", "findByAttributes", "(", "array", "(", "'content_id'", "=>", "$", "model", "->", "id", ",", "'key'", "=>", "'autosave'", ")", ")", ";", "if", "(", "$", "asModel", "!=", "NULL", ")", "{", "$", "model", "->", "populate", "(", "CJSON", "::", "decode", "(", "$", "asModel", "->", "value", ")", ")", ";", "$", "model", "->", "autosavedata", "=", "true", ";", "}", "}", "$", "this", "->", "render", "(", "'save'", ",", "array", "(", "'model'", "=>", "$", "model", ")", ")", ";", "}" ]
Rndering action for the entry @param int $id The content ID
[ "Rndering", "action", "for", "the", "entry" ]
94b89239e9ee34ac3b9c398e8d1ba67a08c68c11
https://github.com/ciims/ciims-modules-dashboard/blob/94b89239e9ee34ac3b9c398e8d1ba67a08c68c11/controllers/ContentController.php#L31-L56
train
jabernardo/lollipop-php
Library/TimeDate.php
TimeDate.longDateString
static function longDateString($date) { str_replace('now', date('m.d.y'), $date); if (!self::parsable($date)) return null; $r = self::fromString($date); return $r->format('M d, Y'); }
php
static function longDateString($date) { str_replace('now', date('m.d.y'), $date); if (!self::parsable($date)) return null; $r = self::fromString($date); return $r->format('M d, Y'); }
[ "static", "function", "longDateString", "(", "$", "date", ")", "{", "str_replace", "(", "'now'", ",", "date", "(", "'m.d.y'", ")", ",", "$", "date", ")", ";", "if", "(", "!", "self", "::", "parsable", "(", "$", "date", ")", ")", "return", "null", ";", "$", "r", "=", "self", "::", "fromString", "(", "$", "date", ")", ";", "return", "$", "r", "->", "format", "(", "'M d, Y'", ")", ";", "}" ]
Returns date in long date format @param string $date Date @return string Long Date @return string
[ "Returns", "date", "in", "long", "date", "format" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/TimeDate.php#L71-L79
train
jabernardo/lollipop-php
Library/TimeDate.php
TimeDate.shortDateString
static function shortDateString($date, $separator = '/') { str_replace('now', date('m.d.y'), $date); if (!self::parsable($date)) return null; $r = self::fromString($date); return $r->format('m' . $separator . 'd' . $separator . 'Y'); }
php
static function shortDateString($date, $separator = '/') { str_replace('now', date('m.d.y'), $date); if (!self::parsable($date)) return null; $r = self::fromString($date); return $r->format('m' . $separator . 'd' . $separator . 'Y'); }
[ "static", "function", "shortDateString", "(", "$", "date", ",", "$", "separator", "=", "'/'", ")", "{", "str_replace", "(", "'now'", ",", "date", "(", "'m.d.y'", ")", ",", "$", "date", ")", ";", "if", "(", "!", "self", "::", "parsable", "(", "$", "date", ")", ")", "return", "null", ";", "$", "r", "=", "self", "::", "fromString", "(", "$", "date", ")", ";", "return", "$", "r", "->", "format", "(", "'m'", ".", "$", "separator", ".", "'d'", ".", "$", "separator", ".", "'Y'", ")", ";", "}" ]
Returns date in short date format @param string $date Date @param string $separator Separator @return string
[ "Returns", "date", "in", "short", "date", "format" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/TimeDate.php#L90-L98
train
jabernardo/lollipop-php
Library/TimeDate.php
TimeDate.longTimeString
static function longTimeString($time) { str_replace('now', date('h:i:s t'), $time); if (!self::parsable($time)) return null; $r = self::fromString($time); return $r->format('h:i:s a'); }
php
static function longTimeString($time) { str_replace('now', date('h:i:s t'), $time); if (!self::parsable($time)) return null; $r = self::fromString($time); return $r->format('h:i:s a'); }
[ "static", "function", "longTimeString", "(", "$", "time", ")", "{", "str_replace", "(", "'now'", ",", "date", "(", "'h:i:s t'", ")", ",", "$", "time", ")", ";", "if", "(", "!", "self", "::", "parsable", "(", "$", "time", ")", ")", "return", "null", ";", "$", "r", "=", "self", "::", "fromString", "(", "$", "time", ")", ";", "return", "$", "r", "->", "format", "(", "'h:i:s a'", ")", ";", "}" ]
Returns time in long time format @param string $time Time @return string
[ "Returns", "time", "in", "long", "time", "format" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/TimeDate.php#L107-L115
train
Wedeto/HTTP
src/Accept.php
Accept.parseAccept
public static function parseAccept(string $accept, bool $is_lang) { // By default accept everything but prefer HTML if (empty($accept)) $accept = "text/html;q=1.0,*/*;q=0.9"; // Normalize locales when the intl extension is available $is_lang = $is_lang && class_exists('Locale', false); $accept = explode(",", $accept); $accepted = array(); foreach ($accept as $type) { if (preg_match("/^([^;]+);q=([\d.]+)$/", $type, $matches)) { $type = $matches[1]; $prio = (float)$matches[2]; } else $prio = 1.0; if ($is_lang) $type = \Locale::canonicalize($type); $accepted[$type] = $prio; } return $accepted; }
php
public static function parseAccept(string $accept, bool $is_lang) { // By default accept everything but prefer HTML if (empty($accept)) $accept = "text/html;q=1.0,*/*;q=0.9"; // Normalize locales when the intl extension is available $is_lang = $is_lang && class_exists('Locale', false); $accept = explode(",", $accept); $accepted = array(); foreach ($accept as $type) { if (preg_match("/^([^;]+);q=([\d.]+)$/", $type, $matches)) { $type = $matches[1]; $prio = (float)$matches[2]; } else $prio = 1.0; if ($is_lang) $type = \Locale::canonicalize($type); $accepted[$type] = $prio; } return $accepted; }
[ "public", "static", "function", "parseAccept", "(", "string", "$", "accept", ",", "bool", "$", "is_lang", ")", "{", "// By default accept everything but prefer HTML", "if", "(", "empty", "(", "$", "accept", ")", ")", "$", "accept", "=", "\"text/html;q=1.0,*/*;q=0.9\"", ";", "// Normalize locales when the intl extension is available", "$", "is_lang", "=", "$", "is_lang", "&&", "class_exists", "(", "'Locale'", ",", "false", ")", ";", "$", "accept", "=", "explode", "(", "\",\"", ",", "$", "accept", ")", ";", "$", "accepted", "=", "array", "(", ")", ";", "foreach", "(", "$", "accept", "as", "$", "type", ")", "{", "if", "(", "preg_match", "(", "\"/^([^;]+);q=([\\d.]+)$/\"", ",", "$", "type", ",", "$", "matches", ")", ")", "{", "$", "type", "=", "$", "matches", "[", "1", "]", ";", "$", "prio", "=", "(", "float", ")", "$", "matches", "[", "2", "]", ";", "}", "else", "$", "prio", "=", "1.0", ";", "if", "(", "$", "is_lang", ")", "$", "type", "=", "\\", "Locale", "::", "canonicalize", "(", "$", "type", ")", ";", "$", "accepted", "[", "$", "type", "]", "=", "$", "prio", ";", "}", "return", "$", "accepted", ";", "}" ]
Parse the HTTP Accept headers into an array of Type => Priority pairs. @param string $accept The accept header to parse @return The parsed accept list
[ "Parse", "the", "HTTP", "Accept", "headers", "into", "an", "array", "of", "Type", "=", ">", "Priority", "pairs", "." ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Accept.php#L78-L106
train
Wedeto/HTTP
src/Accept.php
Accept.accepts
public function accepts($type) { foreach ($this->accept as $accept_type => $priority) { if (strpos($accept_type, "*") !== false) { $regexp = "/" . str_replace("WC", ".*", preg_quote(str_replace("*", "WC", $accept_type), "/")) . "/i"; if (preg_match($regexp, $type)) return $priority; } elseif (strtolower($type) === strtolower($accept_type)) return $priority; } return 0; }
php
public function accepts($type) { foreach ($this->accept as $accept_type => $priority) { if (strpos($accept_type, "*") !== false) { $regexp = "/" . str_replace("WC", ".*", preg_quote(str_replace("*", "WC", $accept_type), "/")) . "/i"; if (preg_match($regexp, $type)) return $priority; } elseif (strtolower($type) === strtolower($accept_type)) return $priority; } return 0; }
[ "public", "function", "accepts", "(", "$", "type", ")", "{", "foreach", "(", "$", "this", "->", "accept", "as", "$", "accept_type", "=>", "$", "priority", ")", "{", "if", "(", "strpos", "(", "$", "accept_type", ",", "\"*\"", ")", "!==", "false", ")", "{", "$", "regexp", "=", "\"/\"", ".", "str_replace", "(", "\"WC\"", ",", "\".*\"", ",", "preg_quote", "(", "str_replace", "(", "\"*\"", ",", "\"WC\"", ",", "$", "accept_type", ")", ",", "\"/\"", ")", ")", ".", "\"/i\"", ";", "if", "(", "preg_match", "(", "$", "regexp", ",", "$", "type", ")", ")", "return", "$", "priority", ";", "}", "elseif", "(", "strtolower", "(", "$", "type", ")", "===", "strtolower", "(", "$", "accept_type", ")", ")", "return", "$", "priority", ";", "}", "return", "0", ";", "}" ]
Check if a specified response type is accepted by the client. When no types are specified, everything is accepted. @param string $type The type of the response that is to be checked @return float Returns 0 if the type is not accepted, and otherwise the priority
[ "Check", "if", "a", "specified", "response", "type", "is", "accepted", "by", "the", "client", ".", "When", "no", "types", "are", "specified", "everything", "is", "accepted", "." ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Accept.php#L115-L130
train
Wedeto/HTTP
src/Accept.php
Accept.compareTypes
public function compareTypes(string $l, string $r) { $lq = $this->accept[$l] ?? 0; $rq = $this->accept[$r] ?? 0; return $lq === $rq ? -1 : ($lq < $rq ? 1 : -1); }
php
public function compareTypes(string $l, string $r) { $lq = $this->accept[$l] ?? 0; $rq = $this->accept[$r] ?? 0; return $lq === $rq ? -1 : ($lq < $rq ? 1 : -1); }
[ "public", "function", "compareTypes", "(", "string", "$", "l", ",", "string", "$", "r", ")", "{", "$", "lq", "=", "$", "this", "->", "accept", "[", "$", "l", "]", "??", "0", ";", "$", "rq", "=", "$", "this", "->", "accept", "[", "$", "r", "]", "??", "0", ";", "return", "$", "lq", "===", "$", "rq", "?", "-", "1", ":", "(", "$", "lq", "<", "$", "rq", "?", "1", ":", "-", "1", ")", ";", "}" ]
Compare the types based on the priorty in the accept header. Aliases for common types are supported. @param string $l The left-hand side of the comparison. Should be a type @param string $r The right-hand side of the comparison. Should be a type
[ "Compare", "the", "types", "based", "on", "the", "priorty", "in", "the", "accept", "header", ".", "Aliases", "for", "common", "types", "are", "supported", "." ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Accept.php#L139-L145
train
Wedeto/HTTP
src/Accept.php
Accept.sortTypes
public function sortTypes(array &$types) { if (WF::is_numeric_array($types)) return usort($types, [$this, 'compareTypes']); return uksort($types, [$this, 'compareTypes']); }
php
public function sortTypes(array &$types) { if (WF::is_numeric_array($types)) return usort($types, [$this, 'compareTypes']); return uksort($types, [$this, 'compareTypes']); }
[ "public", "function", "sortTypes", "(", "array", "&", "$", "types", ")", "{", "if", "(", "WF", "::", "is_numeric_array", "(", "$", "types", ")", ")", "return", "usort", "(", "$", "types", ",", "[", "$", "this", ",", "'compareTypes'", "]", ")", ";", "return", "uksort", "(", "$", "types", ",", "[", "$", "this", ",", "'compareTypes'", "]", ")", ";", "}" ]
Sort a list by their accept priority @param array $types The list to sort. For arrays with numeric keys, the values are expected to be types. Otherwise, the keys are expected to be types. The array is passed by reference. @return bool True on success, false on failure
[ "Sort", "a", "list", "by", "their", "accept", "priority" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Accept.php#L155-L161
train
Wedeto/HTTP
src/Accept.php
Accept.getBestResponseType
public function getBestResponseType(array $types) { if (empty($types)) return ""; $this->sortTypes($types); $type = reset($types); return $this->accepts($type) ? current($types) : null; }
php
public function getBestResponseType(array $types) { if (empty($types)) return ""; $this->sortTypes($types); $type = reset($types); return $this->accepts($type) ? current($types) : null; }
[ "public", "function", "getBestResponseType", "(", "array", "$", "types", ")", "{", "if", "(", "empty", "(", "$", "types", ")", ")", "return", "\"\"", ";", "$", "this", "->", "sortTypes", "(", "$", "types", ")", ";", "$", "type", "=", "reset", "(", "$", "types", ")", ";", "return", "$", "this", "->", "accepts", "(", "$", "type", ")", "?", "current", "(", "$", "types", ")", ":", "null", ";", "}" ]
Select the best response type to return from a list of available types. @param array $types The types that the script is willing to return @return string The type preferred by the client
[ "Select", "the", "best", "response", "type", "to", "return", "from", "a", "list", "of", "available", "types", "." ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Accept.php#L169-L177
train
Wedeto/HTTP
src/Accept.php
Accept.chooseResponse
public function chooseResponse(array $types) { if (empty($types)) return null; $this->sortTypes($types); $first = reset($types); $type = key($types); return $this->accepts($type) ? $first : null; }
php
public function chooseResponse(array $types) { if (empty($types)) return null; $this->sortTypes($types); $first = reset($types); $type = key($types); return $this->accepts($type) ? $first : null; }
[ "public", "function", "chooseResponse", "(", "array", "$", "types", ")", "{", "if", "(", "empty", "(", "$", "types", ")", ")", "return", "null", ";", "$", "this", "->", "sortTypes", "(", "$", "types", ")", ";", "$", "first", "=", "reset", "(", "$", "types", ")", ";", "$", "type", "=", "key", "(", "$", "types", ")", ";", "return", "$", "this", "->", "accepts", "(", "$", "type", ")", "?", "$", "first", ":", "null", ";", "}" ]
Select the preferred reponse type based on a list of response types. The response types should be provided in preference of the script, if any. These are then matched with the accepted response types by the client, and the most preferred one is selected. If more than one type is equally desired by the client, the first one is selected. @param array $types The list of response types offered @return string The preferred response @see Wedeto\HTTP\Request::acept
[ "Select", "the", "preferred", "reponse", "type", "based", "on", "a", "list", "of", "response", "types", ".", "The", "response", "types", "should", "be", "provided", "in", "preference", "of", "the", "script", "if", "any", ".", "These", "are", "then", "matched", "with", "the", "accepted", "response", "types", "by", "the", "client", "and", "the", "most", "preferred", "one", "is", "selected", ".", "If", "more", "than", "one", "type", "is", "equally", "desired", "by", "the", "client", "the", "first", "one", "is", "selected", "." ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Accept.php#L190-L200
train
faizalpribadi/Cache
Driver/OpCache/FileCache.php
FileCache.setDirectory
public function setDirectory($directory) { if (!is_dir($directory) && !is_writable($directory)) { throw new FileCacheException( sprintf('The directory "%s" is not directory and not writable', $directory) ); } if (is_null($directory) && !$this->getFilesystem()->mkdir($directory, 0777, true)) { throw new FileCacheException( sprintf('The directory "%s" not be null and directory not be created') ); } $this->directory = realpath($directory); }
php
public function setDirectory($directory) { if (!is_dir($directory) && !is_writable($directory)) { throw new FileCacheException( sprintf('The directory "%s" is not directory and not writable', $directory) ); } if (is_null($directory) && !$this->getFilesystem()->mkdir($directory, 0777, true)) { throw new FileCacheException( sprintf('The directory "%s" not be null and directory not be created') ); } $this->directory = realpath($directory); }
[ "public", "function", "setDirectory", "(", "$", "directory", ")", "{", "if", "(", "!", "is_dir", "(", "$", "directory", ")", "&&", "!", "is_writable", "(", "$", "directory", ")", ")", "{", "throw", "new", "FileCacheException", "(", "sprintf", "(", "'The directory \"%s\" is not directory and not writable'", ",", "$", "directory", ")", ")", ";", "}", "if", "(", "is_null", "(", "$", "directory", ")", "&&", "!", "$", "this", "->", "getFilesystem", "(", ")", "->", "mkdir", "(", "$", "directory", ",", "0777", ",", "true", ")", ")", "{", "throw", "new", "FileCacheException", "(", "sprintf", "(", "'The directory \"%s\" not be null and directory not be created'", ")", ")", ";", "}", "$", "this", "->", "directory", "=", "realpath", "(", "$", "directory", ")", ";", "}" ]
Set the directory to store you're cache @param string|__DIR__ $directory @throws \Mozart\Library\Cache\Exception\FileCacheException
[ "Set", "the", "directory", "to", "store", "you", "re", "cache" ]
e62a4d71739e542ca6e7bac77f5cc522accef8cb
https://github.com/faizalpribadi/Cache/blob/e62a4d71739e542ca6e7bac77f5cc522accef8cb/Driver/OpCache/FileCache.php#L58-L73
train
BapCat/Remodel
src/GatewayQuery.php
GatewayQuery.insert
public function insert(array $values): bool { $this->coerceDataTypesToDatabase($values); return $this->builder->insert($values); }
php
public function insert(array $values): bool { $this->coerceDataTypesToDatabase($values); return $this->builder->insert($values); }
[ "public", "function", "insert", "(", "array", "$", "values", ")", ":", "bool", "{", "$", "this", "->", "coerceDataTypesToDatabase", "(", "$", "values", ")", ";", "return", "$", "this", "->", "builder", "->", "insert", "(", "$", "values", ")", ";", "}" ]
Insert a new record into the database @param mixed[] $values @return bool
[ "Insert", "a", "new", "record", "into", "the", "database" ]
80fcdec8bca22b88c5af9a0a93622c796cf3e7b1
https://github.com/BapCat/Remodel/blob/80fcdec8bca22b88c5af9a0a93622c796cf3e7b1/src/GatewayQuery.php#L96-L99
train
BapCat/Remodel
src/GatewayQuery.php
GatewayQuery.insertGetId
public function insertGetId(array $values): int { $this->coerceDataTypesToDatabase($values); return $this->builder->insertGetId($values); }
php
public function insertGetId(array $values): int { $this->coerceDataTypesToDatabase($values); return $this->builder->insertGetId($values); }
[ "public", "function", "insertGetId", "(", "array", "$", "values", ")", ":", "int", "{", "$", "this", "->", "coerceDataTypesToDatabase", "(", "$", "values", ")", ";", "return", "$", "this", "->", "builder", "->", "insertGetId", "(", "$", "values", ")", ";", "}" ]
Insert a new record and get the value of the primary key @param mixed[] $values @return int
[ "Insert", "a", "new", "record", "and", "get", "the", "value", "of", "the", "primary", "key" ]
80fcdec8bca22b88c5af9a0a93622c796cf3e7b1
https://github.com/BapCat/Remodel/blob/80fcdec8bca22b88c5af9a0a93622c796cf3e7b1/src/GatewayQuery.php#L108-L111
train
BapCat/Remodel
src/GatewayQuery.php
GatewayQuery.update
public function update(array $values): int { $this->coerceDataTypesToDatabase($values); return $this->builder->update($values); }
php
public function update(array $values): int { $this->coerceDataTypesToDatabase($values); return $this->builder->update($values); }
[ "public", "function", "update", "(", "array", "$", "values", ")", ":", "int", "{", "$", "this", "->", "coerceDataTypesToDatabase", "(", "$", "values", ")", ";", "return", "$", "this", "->", "builder", "->", "update", "(", "$", "values", ")", ";", "}" ]
Update a record in the database @param mixed[] $values @return int
[ "Update", "a", "record", "in", "the", "database" ]
80fcdec8bca22b88c5af9a0a93622c796cf3e7b1
https://github.com/BapCat/Remodel/blob/80fcdec8bca22b88c5af9a0a93622c796cf3e7b1/src/GatewayQuery.php#L120-L123
train
WellCommerce/AdminBundle
Provider/AdminMenuProvider.php
AdminMenuProvider.generateTree
protected function generateTree(Collection $collection, Collection $children) { $children->map(function (AdminMenuInterface $menuItem) use ($collection, &$tree) { $tree[] = [ 'routeName' => $menuItem->getRouteName(), 'cssClass' => $menuItem->getCssClass(), 'name' => $menuItem->getName(), 'children' => $this->generateTree($collection, $this->filterElements($collection, $menuItem)) ]; }); return $tree; }
php
protected function generateTree(Collection $collection, Collection $children) { $children->map(function (AdminMenuInterface $menuItem) use ($collection, &$tree) { $tree[] = [ 'routeName' => $menuItem->getRouteName(), 'cssClass' => $menuItem->getCssClass(), 'name' => $menuItem->getName(), 'children' => $this->generateTree($collection, $this->filterElements($collection, $menuItem)) ]; }); return $tree; }
[ "protected", "function", "generateTree", "(", "Collection", "$", "collection", ",", "Collection", "$", "children", ")", "{", "$", "children", "->", "map", "(", "function", "(", "AdminMenuInterface", "$", "menuItem", ")", "use", "(", "$", "collection", ",", "&", "$", "tree", ")", "{", "$", "tree", "[", "]", "=", "[", "'routeName'", "=>", "$", "menuItem", "->", "getRouteName", "(", ")", ",", "'cssClass'", "=>", "$", "menuItem", "->", "getCssClass", "(", ")", ",", "'name'", "=>", "$", "menuItem", "->", "getName", "(", ")", ",", "'children'", "=>", "$", "this", "->", "generateTree", "(", "$", "collection", ",", "$", "this", "->", "filterElements", "(", "$", "collection", ",", "$", "menuItem", ")", ")", "]", ";", "}", ")", ";", "return", "$", "tree", ";", "}" ]
Generates a tree for given children elements @param Collection $collection @param Collection $children @return array
[ "Generates", "a", "tree", "for", "given", "children", "elements" ]
5721f0b9a506023ed6beb6bdf79e4ccbbe546516
https://github.com/WellCommerce/AdminBundle/blob/5721f0b9a506023ed6beb6bdf79e4ccbbe546516/Provider/AdminMenuProvider.php#L87-L99
train
brunschgi/TerrificComposerBundle
EventListener/ToolbarListener.php
ToolbarListener.injectToolbar
protected function injectToolbar(Response $response, $params) { if (function_exists('mb_stripos')) { $posrFunction = 'mb_strripos'; $substrFunction = 'mb_substr'; } else { $posrFunction = 'strripos'; $substrFunction = 'substr'; } $content = $response->getContent(); if (false !== $pos = $posrFunction($content, '</body>')) { $toolbar = "\n".str_replace("\n", '', $this->templating->render( 'TerrificComposerBundle:Toolbar:toolbar.html.twig', $params ))."\n"; $content = $substrFunction($content, 0, $pos).$toolbar.$substrFunction($content, $pos); $response->setContent($content); } }
php
protected function injectToolbar(Response $response, $params) { if (function_exists('mb_stripos')) { $posrFunction = 'mb_strripos'; $substrFunction = 'mb_substr'; } else { $posrFunction = 'strripos'; $substrFunction = 'substr'; } $content = $response->getContent(); if (false !== $pos = $posrFunction($content, '</body>')) { $toolbar = "\n".str_replace("\n", '', $this->templating->render( 'TerrificComposerBundle:Toolbar:toolbar.html.twig', $params ))."\n"; $content = $substrFunction($content, 0, $pos).$toolbar.$substrFunction($content, $pos); $response->setContent($content); } }
[ "protected", "function", "injectToolbar", "(", "Response", "$", "response", ",", "$", "params", ")", "{", "if", "(", "function_exists", "(", "'mb_stripos'", ")", ")", "{", "$", "posrFunction", "=", "'mb_strripos'", ";", "$", "substrFunction", "=", "'mb_substr'", ";", "}", "else", "{", "$", "posrFunction", "=", "'strripos'", ";", "$", "substrFunction", "=", "'substr'", ";", "}", "$", "content", "=", "$", "response", "->", "getContent", "(", ")", ";", "if", "(", "false", "!==", "$", "pos", "=", "$", "posrFunction", "(", "$", "content", ",", "'</body>'", ")", ")", "{", "$", "toolbar", "=", "\"\\n\"", ".", "str_replace", "(", "\"\\n\"", ",", "''", ",", "$", "this", "->", "templating", "->", "render", "(", "'TerrificComposerBundle:Toolbar:toolbar.html.twig'", ",", "$", "params", ")", ")", ".", "\"\\n\"", ";", "$", "content", "=", "$", "substrFunction", "(", "$", "content", ",", "0", ",", "$", "pos", ")", ".", "$", "toolbar", ".", "$", "substrFunction", "(", "$", "content", ",", "$", "pos", ")", ";", "$", "response", "->", "setContent", "(", "$", "content", ")", ";", "}", "}" ]
Injects the Terrific Composer Toolbar into the given Response. @param Response $response A Response instance @param array $params The parameters
[ "Injects", "the", "Terrific", "Composer", "Toolbar", "into", "the", "given", "Response", "." ]
6eef4ace887c19ef166ab6654de385bc1ffbf5f1
https://github.com/brunschgi/TerrificComposerBundle/blob/6eef4ace887c19ef166ab6654de385bc1ffbf5f1/EventListener/ToolbarListener.php#L111-L130
train
tuanlq11/dbi18n
src/I18NBlueprint.php
I18NBlueprint.parseCommand
public function parseCommand($originCommand) { $mappings = [ 'create' => ['create'], 'drop' => ['drop', 'dropIfExists'], ]; foreach ($mappings as $key => $mapping) { if (in_array($originCommand, $mapping)) { return $key; } } return null; }
php
public function parseCommand($originCommand) { $mappings = [ 'create' => ['create'], 'drop' => ['drop', 'dropIfExists'], ]; foreach ($mappings as $key => $mapping) { if (in_array($originCommand, $mapping)) { return $key; } } return null; }
[ "public", "function", "parseCommand", "(", "$", "originCommand", ")", "{", "$", "mappings", "=", "[", "'create'", "=>", "[", "'create'", "]", ",", "'drop'", "=>", "[", "'drop'", ",", "'dropIfExists'", "]", ",", "]", ";", "foreach", "(", "$", "mappings", "as", "$", "key", "=>", "$", "mapping", ")", "{", "if", "(", "in_array", "(", "$", "originCommand", ",", "$", "mapping", ")", ")", "{", "return", "$", "key", ";", "}", "}", "return", "null", ";", "}" ]
Parse origin command to human command @param $originCommand @return int|null|string
[ "Parse", "origin", "command", "to", "human", "command" ]
56d01eceae043f2770e01b92e7bcc7e52a5047e7
https://github.com/tuanlq11/dbi18n/blob/56d01eceae043f2770e01b92e7bcc7e52a5047e7/src/I18NBlueprint.php#L26-L40
train
tuanlq11/dbi18n
src/I18NBlueprint.php
I18NBlueprint.primary
public function primary($columns, $name = null) { $this->addCachePrimary($columns); return parent::primary($columns, $name); }
php
public function primary($columns, $name = null) { $this->addCachePrimary($columns); return parent::primary($columns, $name); }
[ "public", "function", "primary", "(", "$", "columns", ",", "$", "name", "=", "null", ")", "{", "$", "this", "->", "addCachePrimary", "(", "$", "columns", ")", ";", "return", "parent", "::", "primary", "(", "$", "columns", ",", "$", "name", ")", ";", "}" ]
Store list primary to create i18n @param array|string $columns @param null $name @return \Illuminate\Support\Fluent
[ "Store", "list", "primary", "to", "create", "i18n" ]
56d01eceae043f2770e01b92e7bcc7e52a5047e7
https://github.com/tuanlq11/dbi18n/blob/56d01eceae043f2770e01b92e7bcc7e52a5047e7/src/I18NBlueprint.php#L80-L85
train
tuanlq11/dbi18n
src/I18NBlueprint.php
I18NBlueprint.build
public function build(Connection $connection, Grammar $grammar) { $command = $this->parseCommand($this->commands[0]->get('name')); $schema = $connection->getSchemaBuilder(); if ($command === "drop") { $schema->dropIfExists($this->getI18NTableName()); } parent::build($connection, $grammar); if ($command === "create") { $primary = $this->i18n_primary; $i18n_columns = $this->i18n_columns; $table_name = $this->table; $schema->create($this->getI18NTableName(), function (Blueprint $table) use ($table_name, $primary, $i18n_columns) { foreach ($primary as $name => $col) { $table->columns[] = $col; $table->foreign($col->get('name'))->references($col->get('name'))->on($table_name)->onDelete('cascade'); } foreach ($i18n_columns as $col) { $table->columns[] = $col; } $table->string($this->i18n_code_field, 10); $table->primary(array_merge(array_keys($primary), [$this->i18n_code_field])); }); } }
php
public function build(Connection $connection, Grammar $grammar) { $command = $this->parseCommand($this->commands[0]->get('name')); $schema = $connection->getSchemaBuilder(); if ($command === "drop") { $schema->dropIfExists($this->getI18NTableName()); } parent::build($connection, $grammar); if ($command === "create") { $primary = $this->i18n_primary; $i18n_columns = $this->i18n_columns; $table_name = $this->table; $schema->create($this->getI18NTableName(), function (Blueprint $table) use ($table_name, $primary, $i18n_columns) { foreach ($primary as $name => $col) { $table->columns[] = $col; $table->foreign($col->get('name'))->references($col->get('name'))->on($table_name)->onDelete('cascade'); } foreach ($i18n_columns as $col) { $table->columns[] = $col; } $table->string($this->i18n_code_field, 10); $table->primary(array_merge(array_keys($primary), [$this->i18n_code_field])); }); } }
[ "public", "function", "build", "(", "Connection", "$", "connection", ",", "Grammar", "$", "grammar", ")", "{", "$", "command", "=", "$", "this", "->", "parseCommand", "(", "$", "this", "->", "commands", "[", "0", "]", "->", "get", "(", "'name'", ")", ")", ";", "$", "schema", "=", "$", "connection", "->", "getSchemaBuilder", "(", ")", ";", "if", "(", "$", "command", "===", "\"drop\"", ")", "{", "$", "schema", "->", "dropIfExists", "(", "$", "this", "->", "getI18NTableName", "(", ")", ")", ";", "}", "parent", "::", "build", "(", "$", "connection", ",", "$", "grammar", ")", ";", "if", "(", "$", "command", "===", "\"create\"", ")", "{", "$", "primary", "=", "$", "this", "->", "i18n_primary", ";", "$", "i18n_columns", "=", "$", "this", "->", "i18n_columns", ";", "$", "table_name", "=", "$", "this", "->", "table", ";", "$", "schema", "->", "create", "(", "$", "this", "->", "getI18NTableName", "(", ")", ",", "function", "(", "Blueprint", "$", "table", ")", "use", "(", "$", "table_name", ",", "$", "primary", ",", "$", "i18n_columns", ")", "{", "foreach", "(", "$", "primary", "as", "$", "name", "=>", "$", "col", ")", "{", "$", "table", "->", "columns", "[", "]", "=", "$", "col", ";", "$", "table", "->", "foreign", "(", "$", "col", "->", "get", "(", "'name'", ")", ")", "->", "references", "(", "$", "col", "->", "get", "(", "'name'", ")", ")", "->", "on", "(", "$", "table_name", ")", "->", "onDelete", "(", "'cascade'", ")", ";", "}", "foreach", "(", "$", "i18n_columns", "as", "$", "col", ")", "{", "$", "table", "->", "columns", "[", "]", "=", "$", "col", ";", "}", "$", "table", "->", "string", "(", "$", "this", "->", "i18n_code_field", ",", "10", ")", ";", "$", "table", "->", "primary", "(", "array_merge", "(", "array_keys", "(", "$", "primary", ")", ",", "[", "$", "this", "->", "i18n_code_field", "]", ")", ")", ";", "}", ")", ";", "}", "}" ]
Overrride build function @param Connection $connection @param Grammar $grammar
[ "Overrride", "build", "function" ]
56d01eceae043f2770e01b92e7bcc7e52a5047e7
https://github.com/tuanlq11/dbi18n/blob/56d01eceae043f2770e01b92e7bcc7e52a5047e7/src/I18NBlueprint.php#L119-L149
train
tuanlq11/dbi18n
src/I18NBlueprint.php
I18NBlueprint.createColumn
protected function createColumn($name, $type, array $parameters = []) { $attributes = array_merge(compact('type', 'name'), $parameters); $column = new Fluent($attributes); return $column; }
php
protected function createColumn($name, $type, array $parameters = []) { $attributes = array_merge(compact('type', 'name'), $parameters); $column = new Fluent($attributes); return $column; }
[ "protected", "function", "createColumn", "(", "$", "name", ",", "$", "type", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "attributes", "=", "array_merge", "(", "compact", "(", "'type'", ",", "'name'", ")", ",", "$", "parameters", ")", ";", "$", "column", "=", "new", "Fluent", "(", "$", "attributes", ")", ";", "return", "$", "column", ";", "}" ]
Create column fluent @param $name @param $type @param array $parameters @return Fluent
[ "Create", "column", "fluent" ]
56d01eceae043f2770e01b92e7bcc7e52a5047e7
https://github.com/tuanlq11/dbi18n/blob/56d01eceae043f2770e01b92e7bcc7e52a5047e7/src/I18NBlueprint.php#L160-L167
train
tuanlq11/dbi18n
src/I18NBlueprint.php
I18NBlueprint.i18n_string
public function i18n_string($name, $length = 255) { $this->i18n_columns[] = $column = $this->createColumn($name, 'string', compact('length')); return $column; }
php
public function i18n_string($name, $length = 255) { $this->i18n_columns[] = $column = $this->createColumn($name, 'string', compact('length')); return $column; }
[ "public", "function", "i18n_string", "(", "$", "name", ",", "$", "length", "=", "255", ")", "{", "$", "this", "->", "i18n_columns", "[", "]", "=", "$", "column", "=", "$", "this", "->", "createColumn", "(", "$", "name", ",", "'string'", ",", "compact", "(", "'length'", ")", ")", ";", "return", "$", "column", ";", "}" ]
Add i18n string field @param $name @param int $length @return \Illuminate\Support\Fluent
[ "Add", "i18n", "string", "field" ]
56d01eceae043f2770e01b92e7bcc7e52a5047e7
https://github.com/tuanlq11/dbi18n/blob/56d01eceae043f2770e01b92e7bcc7e52a5047e7/src/I18NBlueprint.php#L205-L210
train
tuanlq11/dbi18n
src/I18NBlueprint.php
I18NBlueprint.i18n_char
public function i18n_char($name, $length = 255) { $this->i18n_columns[] = $column = $this->createColumn($name, 'char', compact('length')); return $column; }
php
public function i18n_char($name, $length = 255) { $this->i18n_columns[] = $column = $this->createColumn($name, 'char', compact('length')); return $column; }
[ "public", "function", "i18n_char", "(", "$", "name", ",", "$", "length", "=", "255", ")", "{", "$", "this", "->", "i18n_columns", "[", "]", "=", "$", "column", "=", "$", "this", "->", "createColumn", "(", "$", "name", ",", "'char'", ",", "compact", "(", "'length'", ")", ")", ";", "return", "$", "column", ";", "}" ]
Add i18n char field @param $name @param int $length @return \Illuminate\Support\Fluent
[ "Add", "i18n", "char", "field" ]
56d01eceae043f2770e01b92e7bcc7e52a5047e7
https://github.com/tuanlq11/dbi18n/blob/56d01eceae043f2770e01b92e7bcc7e52a5047e7/src/I18NBlueprint.php#L220-L225
train
OliverMonneke/pennePHP
src/Filesystem/File.php
File.setHandle
private function setHandle($mode) { $this->closeExistingHandle(); $this->handle = fopen($this->file, $mode); return $this->handle; }
php
private function setHandle($mode) { $this->closeExistingHandle(); $this->handle = fopen($this->file, $mode); return $this->handle; }
[ "private", "function", "setHandle", "(", "$", "mode", ")", "{", "$", "this", "->", "closeExistingHandle", "(", ")", ";", "$", "this", "->", "handle", "=", "fopen", "(", "$", "this", "->", "file", ",", "$", "mode", ")", ";", "return", "$", "this", "->", "handle", ";", "}" ]
Set file handle @param string $mode Mode for file opening @return resource
[ "Set", "file", "handle" ]
dd0de7944685a3f1947157e1254fc54b55ff9942
https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Filesystem/File.php#L54-L61
train
OliverMonneke/pennePHP
src/Filesystem/File.php
File.write
public function write($string, $append = true) { $mode = $this->getMode($append); $this->setHandle($mode); return fwrite($this->handle, $string); }
php
public function write($string, $append = true) { $mode = $this->getMode($append); $this->setHandle($mode); return fwrite($this->handle, $string); }
[ "public", "function", "write", "(", "$", "string", ",", "$", "append", "=", "true", ")", "{", "$", "mode", "=", "$", "this", "->", "getMode", "(", "$", "append", ")", ";", "$", "this", "->", "setHandle", "(", "$", "mode", ")", ";", "return", "fwrite", "(", "$", "this", "->", "handle", ",", "$", "string", ")", ";", "}" ]
Write a string into a file @param string $string The string to write @param bool $append Append to file @return int
[ "Write", "a", "string", "into", "a", "file" ]
dd0de7944685a3f1947157e1254fc54b55ff9942
https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Filesystem/File.php#L181-L187
train
OliverMonneke/pennePHP
src/Filesystem/File.php
File.read
public function read($length = 0, $asArray = false) { if ($asArray && Number::isZero($length)) { return file($this->file); } elseif (Number::isPositive($length)) { $this->setHandle('r'); return fread($this->handle, $length); } else { return Collection::implode($this->read(0, true), ''); } }
php
public function read($length = 0, $asArray = false) { if ($asArray && Number::isZero($length)) { return file($this->file); } elseif (Number::isPositive($length)) { $this->setHandle('r'); return fread($this->handle, $length); } else { return Collection::implode($this->read(0, true), ''); } }
[ "public", "function", "read", "(", "$", "length", "=", "0", ",", "$", "asArray", "=", "false", ")", "{", "if", "(", "$", "asArray", "&&", "Number", "::", "isZero", "(", "$", "length", ")", ")", "{", "return", "file", "(", "$", "this", "->", "file", ")", ";", "}", "elseif", "(", "Number", "::", "isPositive", "(", "$", "length", ")", ")", "{", "$", "this", "->", "setHandle", "(", "'r'", ")", ";", "return", "fread", "(", "$", "this", "->", "handle", ",", "$", "length", ")", ";", "}", "else", "{", "return", "Collection", "::", "implode", "(", "$", "this", "->", "read", "(", "0", ",", "true", ")", ",", "''", ")", ";", "}", "}" ]
Read content from file @param int $length Length of content to read @param bool $asArray Get as array @return array|string|bool
[ "Read", "content", "from", "file" ]
dd0de7944685a3f1947157e1254fc54b55ff9942
https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Filesystem/File.php#L209-L222
train
Krinkle/toollabs-base
src/Request.php
Request.getSessionData
public function getSessionData( $key ) { self::ensureSession(); if ( !isset( $_SESSION[ $key ] ) ) { return null; } return $_SESSION[$key]; }
php
public function getSessionData( $key ) { self::ensureSession(); if ( !isset( $_SESSION[ $key ] ) ) { return null; } return $_SESSION[$key]; }
[ "public", "function", "getSessionData", "(", "$", "key", ")", "{", "self", "::", "ensureSession", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "_SESSION", "[", "$", "key", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "_SESSION", "[", "$", "key", "]", ";", "}" ]
Get data from session @param string $key @return mixed
[ "Get", "data", "from", "session" ]
784150ca58f4b48cc89534fd6142c54b4f138cd2
https://github.com/Krinkle/toollabs-base/blob/784150ca58f4b48cc89534fd6142c54b4f138cd2/src/Request.php#L115-L121
train
Krinkle/toollabs-base
src/Request.php
Request.initHeaders
private function initHeaders() { if ( $this->headers !== null ) { return; } $apacheHeaders = function_exists( 'apache_request_headers' ) ? apache_request_headers() : false; if ( $apacheHeaders ) { foreach ( $apacheHeaders as $key => $val ) { $this->headers[strtoupper( $key )] = $val; } } else { foreach ( $_SERVER as $name => $value ) { if ( substr( $name, 0, 5 ) === 'HTTP_' ) { $name = str_replace( '_', '-', substr( $name, 5 ) ); $this->headers[$name] = $value; } elseif ( $name === 'CONTENT_LENGTH' ) { $this->headers['CONTENT-LENGTH'] = $value; } } } }
php
private function initHeaders() { if ( $this->headers !== null ) { return; } $apacheHeaders = function_exists( 'apache_request_headers' ) ? apache_request_headers() : false; if ( $apacheHeaders ) { foreach ( $apacheHeaders as $key => $val ) { $this->headers[strtoupper( $key )] = $val; } } else { foreach ( $_SERVER as $name => $value ) { if ( substr( $name, 0, 5 ) === 'HTTP_' ) { $name = str_replace( '_', '-', substr( $name, 5 ) ); $this->headers[$name] = $value; } elseif ( $name === 'CONTENT_LENGTH' ) { $this->headers['CONTENT-LENGTH'] = $value; } } } }
[ "private", "function", "initHeaders", "(", ")", "{", "if", "(", "$", "this", "->", "headers", "!==", "null", ")", "{", "return", ";", "}", "$", "apacheHeaders", "=", "function_exists", "(", "'apache_request_headers'", ")", "?", "apache_request_headers", "(", ")", ":", "false", ";", "if", "(", "$", "apacheHeaders", ")", "{", "foreach", "(", "$", "apacheHeaders", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "this", "->", "headers", "[", "strtoupper", "(", "$", "key", ")", "]", "=", "$", "val", ";", "}", "}", "else", "{", "foreach", "(", "$", "_SERVER", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "substr", "(", "$", "name", ",", "0", ",", "5", ")", "===", "'HTTP_'", ")", "{", "$", "name", "=", "str_replace", "(", "'_'", ",", "'-'", ",", "substr", "(", "$", "name", ",", "5", ")", ")", ";", "$", "this", "->", "headers", "[", "$", "name", "]", "=", "$", "value", ";", "}", "elseif", "(", "$", "name", "===", "'CONTENT_LENGTH'", ")", "{", "$", "this", "->", "headers", "[", "'CONTENT-LENGTH'", "]", "=", "$", "value", ";", "}", "}", "}", "}" ]
Initialise the header list
[ "Initialise", "the", "header", "list" ]
784150ca58f4b48cc89534fd6142c54b4f138cd2
https://github.com/Krinkle/toollabs-base/blob/784150ca58f4b48cc89534fd6142c54b4f138cd2/src/Request.php#L180-L200
train
Krinkle/toollabs-base
src/Request.php
Request.getHeader
public function getHeader( $name ) { $this->initHeaders(); $name = strtoupper( $name ); if ( !isset( $this->headers[$name] ) ) { return false; } return $this->headers[$name]; }
php
public function getHeader( $name ) { $this->initHeaders(); $name = strtoupper( $name ); if ( !isset( $this->headers[$name] ) ) { return false; } return $this->headers[$name]; }
[ "public", "function", "getHeader", "(", "$", "name", ")", "{", "$", "this", "->", "initHeaders", "(", ")", ";", "$", "name", "=", "strtoupper", "(", "$", "name", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "headers", "[", "$", "name", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "headers", "[", "$", "name", "]", ";", "}" ]
Get a request header, or false if it isn't set @param string $name Case-insensitive header name @return string|bool False on failure
[ "Get", "a", "request", "header", "or", "false", "if", "it", "isn", "t", "set" ]
784150ca58f4b48cc89534fd6142c54b4f138cd2
https://github.com/Krinkle/toollabs-base/blob/784150ca58f4b48cc89534fd6142c54b4f138cd2/src/Request.php#L218-L225
train
Krinkle/toollabs-base
src/Request.php
Request.tryLastModified
public function tryLastModified( $modifiedTime ) { $clientCache = $this->getHeader( 'If-Modified-Since' ); if ( $clientCache !== false ) { # IE sends sizes after the date like "Wed, 20 Aug 2003 06:51:19 GMT; length=5202" # which would break strtotime() parsing. $clientCache = preg_replace( '/;.*$/', '', $clientCache ); $clientCacheTime = @strtotime( $clientCache ); if ( $modifiedTime <= $clientCacheTime ) { header( 'Status: 304 Not Modified', true, 304 ); return true; } } return false; }
php
public function tryLastModified( $modifiedTime ) { $clientCache = $this->getHeader( 'If-Modified-Since' ); if ( $clientCache !== false ) { # IE sends sizes after the date like "Wed, 20 Aug 2003 06:51:19 GMT; length=5202" # which would break strtotime() parsing. $clientCache = preg_replace( '/;.*$/', '', $clientCache ); $clientCacheTime = @strtotime( $clientCache ); if ( $modifiedTime <= $clientCacheTime ) { header( 'Status: 304 Not Modified', true, 304 ); return true; } } return false; }
[ "public", "function", "tryLastModified", "(", "$", "modifiedTime", ")", "{", "$", "clientCache", "=", "$", "this", "->", "getHeader", "(", "'If-Modified-Since'", ")", ";", "if", "(", "$", "clientCache", "!==", "false", ")", "{", "# IE sends sizes after the date like \"Wed, 20 Aug 2003 06:51:19 GMT; length=5202\"", "# which would break strtotime() parsing.", "$", "clientCache", "=", "preg_replace", "(", "'/;.*$/'", ",", "''", ",", "$", "clientCache", ")", ";", "$", "clientCacheTime", "=", "@", "strtotime", "(", "$", "clientCache", ")", ";", "if", "(", "$", "modifiedTime", "<=", "$", "clientCacheTime", ")", "{", "header", "(", "'Status: 304 Not Modified'", ",", "true", ",", "304", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Respond with 304 Last Modified if appropiate @param int $modifiedTime @return bool True if 304 header was sent
[ "Respond", "with", "304", "Last", "Modified", "if", "appropiate" ]
784150ca58f4b48cc89534fd6142c54b4f138cd2
https://github.com/Krinkle/toollabs-base/blob/784150ca58f4b48cc89534fd6142c54b4f138cd2/src/Request.php#L233-L246
train
Wedeto/HTTP
src/URL.php
URL.parse
public static function parse(string $url, string $default_scheme = null) { if (substr($url, 0, 4) === "www." && !empty($default_scheme)) $url = $default_scheme . '://' . $url; elseif (substr($url, 0, 2) === '//' && !empty($_SERVER['REQUEST_SCHEME'])) $url = $_SERVER['REQUEST_SCHEME'] . '://' . substr($url, 2); $parts = parse_url($url); if ($parts === false) throw new URLException("Invalid URL: " . $url); $scheme = $parts['scheme'] ?? null; $username = $parts['user'] ?? null; $password = $parts['pass'] ?? null; $host = $parts['host'] ?? null; $port = $parts['port'] ?? null; $path = $parts['path'] ?? '/'; $query = $parts['query'] ?? null; $fragment = $parts['fragment'] ?? null; $query = self::parseQuery($query); // Scheme is case insensitive, to normalize to lowercase if ($scheme !== null) $scheme = strtolower($scheme); // Hostnames are case insensitive, to normalize to lowercase if ($host !== null) $host = strtolower($host); if (!empty($scheme) && !in_array($scheme, array('http', 'https', 'ftp'))) throw new URLException("Unsupported scheme: '" . $scheme . "'"); return array( 'scheme' => $scheme, 'username' => $username, 'password' => $password, 'host' => $host, 'port' => $port, 'path' => $path, 'query' => $query, 'fragment' => $fragment ); }
php
public static function parse(string $url, string $default_scheme = null) { if (substr($url, 0, 4) === "www." && !empty($default_scheme)) $url = $default_scheme . '://' . $url; elseif (substr($url, 0, 2) === '//' && !empty($_SERVER['REQUEST_SCHEME'])) $url = $_SERVER['REQUEST_SCHEME'] . '://' . substr($url, 2); $parts = parse_url($url); if ($parts === false) throw new URLException("Invalid URL: " . $url); $scheme = $parts['scheme'] ?? null; $username = $parts['user'] ?? null; $password = $parts['pass'] ?? null; $host = $parts['host'] ?? null; $port = $parts['port'] ?? null; $path = $parts['path'] ?? '/'; $query = $parts['query'] ?? null; $fragment = $parts['fragment'] ?? null; $query = self::parseQuery($query); // Scheme is case insensitive, to normalize to lowercase if ($scheme !== null) $scheme = strtolower($scheme); // Hostnames are case insensitive, to normalize to lowercase if ($host !== null) $host = strtolower($host); if (!empty($scheme) && !in_array($scheme, array('http', 'https', 'ftp'))) throw new URLException("Unsupported scheme: '" . $scheme . "'"); return array( 'scheme' => $scheme, 'username' => $username, 'password' => $password, 'host' => $host, 'port' => $port, 'path' => $path, 'query' => $query, 'fragment' => $fragment ); }
[ "public", "static", "function", "parse", "(", "string", "$", "url", ",", "string", "$", "default_scheme", "=", "null", ")", "{", "if", "(", "substr", "(", "$", "url", ",", "0", ",", "4", ")", "===", "\"www.\"", "&&", "!", "empty", "(", "$", "default_scheme", ")", ")", "$", "url", "=", "$", "default_scheme", ".", "'://'", ".", "$", "url", ";", "elseif", "(", "substr", "(", "$", "url", ",", "0", ",", "2", ")", "===", "'//'", "&&", "!", "empty", "(", "$", "_SERVER", "[", "'REQUEST_SCHEME'", "]", ")", ")", "$", "url", "=", "$", "_SERVER", "[", "'REQUEST_SCHEME'", "]", ".", "'://'", ".", "substr", "(", "$", "url", ",", "2", ")", ";", "$", "parts", "=", "parse_url", "(", "$", "url", ")", ";", "if", "(", "$", "parts", "===", "false", ")", "throw", "new", "URLException", "(", "\"Invalid URL: \"", ".", "$", "url", ")", ";", "$", "scheme", "=", "$", "parts", "[", "'scheme'", "]", "??", "null", ";", "$", "username", "=", "$", "parts", "[", "'user'", "]", "??", "null", ";", "$", "password", "=", "$", "parts", "[", "'pass'", "]", "??", "null", ";", "$", "host", "=", "$", "parts", "[", "'host'", "]", "??", "null", ";", "$", "port", "=", "$", "parts", "[", "'port'", "]", "??", "null", ";", "$", "path", "=", "$", "parts", "[", "'path'", "]", "??", "'/'", ";", "$", "query", "=", "$", "parts", "[", "'query'", "]", "??", "null", ";", "$", "fragment", "=", "$", "parts", "[", "'fragment'", "]", "??", "null", ";", "$", "query", "=", "self", "::", "parseQuery", "(", "$", "query", ")", ";", "// Scheme is case insensitive, to normalize to lowercase", "if", "(", "$", "scheme", "!==", "null", ")", "$", "scheme", "=", "strtolower", "(", "$", "scheme", ")", ";", "// Hostnames are case insensitive, to normalize to lowercase", "if", "(", "$", "host", "!==", "null", ")", "$", "host", "=", "strtolower", "(", "$", "host", ")", ";", "if", "(", "!", "empty", "(", "$", "scheme", ")", "&&", "!", "in_array", "(", "$", "scheme", ",", "array", "(", "'http'", ",", "'https'", ",", "'ftp'", ")", ")", ")", "throw", "new", "URLException", "(", "\"Unsupported scheme: '\"", ".", "$", "scheme", ".", "\"'\"", ")", ";", "return", "array", "(", "'scheme'", "=>", "$", "scheme", ",", "'username'", "=>", "$", "username", ",", "'password'", "=>", "$", "password", ",", "'host'", "=>", "$", "host", ",", "'port'", "=>", "$", "port", ",", "'path'", "=>", "$", "path", ",", "'query'", "=>", "$", "query", ",", "'fragment'", "=>", "$", "fragment", ")", ";", "}" ]
Parse a URL @param string $url The URL to parse @param string $default_scheme A default scheme to use when no scheme is used in the URL.
[ "Parse", "a", "URL" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/URL.php#L69-L113
train
Wedeto/HTTP
src/URL.php
URL.parseQuery
protected static function parseQuery($query) { if (is_array($query)) return $query; if (empty($query)) return null; if (!is_string($query)) throw new \InvalidArgumentException('Query must be associative array or string'); $query = ltrim($query, '?'); $query = str_replace('&amp;', '&', $query); $parts = explode('&', $query); $values = []; foreach ($parts as $part) { $subparts = explode('=', $part, 2); if (count($subparts) === 1) $values[$part] = '1'; else $values[$subparts[0]] = $subparts[1]; } return empty($values) ? null : $values; }
php
protected static function parseQuery($query) { if (is_array($query)) return $query; if (empty($query)) return null; if (!is_string($query)) throw new \InvalidArgumentException('Query must be associative array or string'); $query = ltrim($query, '?'); $query = str_replace('&amp;', '&', $query); $parts = explode('&', $query); $values = []; foreach ($parts as $part) { $subparts = explode('=', $part, 2); if (count($subparts) === 1) $values[$part] = '1'; else $values[$subparts[0]] = $subparts[1]; } return empty($values) ? null : $values; }
[ "protected", "static", "function", "parseQuery", "(", "$", "query", ")", "{", "if", "(", "is_array", "(", "$", "query", ")", ")", "return", "$", "query", ";", "if", "(", "empty", "(", "$", "query", ")", ")", "return", "null", ";", "if", "(", "!", "is_string", "(", "$", "query", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'Query must be associative array or string'", ")", ";", "$", "query", "=", "ltrim", "(", "$", "query", ",", "'?'", ")", ";", "$", "query", "=", "str_replace", "(", "'&amp;'", ",", "'&'", ",", "$", "query", ")", ";", "$", "parts", "=", "explode", "(", "'&'", ",", "$", "query", ")", ";", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "$", "subparts", "=", "explode", "(", "'='", ",", "$", "part", ",", "2", ")", ";", "if", "(", "count", "(", "$", "subparts", ")", "===", "1", ")", "$", "values", "[", "$", "part", "]", "=", "'1'", ";", "else", "$", "values", "[", "$", "subparts", "[", "0", "]", "]", "=", "$", "subparts", "[", "1", "]", ";", "}", "return", "empty", "(", "$", "values", ")", "?", "null", ":", "$", "values", ";", "}" ]
Parse a query string or array @param string|array $query The query to parse @return array The associative array of key/value pairs. If an array was passed in, it is returned as-is.
[ "Parse", "a", "query", "string", "or", "array" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/URL.php#L121-L146
train
Wedeto/HTTP
src/URL.php
URL.setPath
public function setPath(string $path) { $path = '/' . ltrim($path, '/'); $this->query = null; $this->fragment = null; if (preg_match('/^(.*?)(\\?([^#]*))?(#(.*))?$/u', $path, $matches)) { $path = $matches[1]; $this->query = !empty($matches[3]) ? $matches[3] : null; $this->fragment = !empty($matches[5]) ? $matches[5] : null; } $this->path = $path; return $this; }
php
public function setPath(string $path) { $path = '/' . ltrim($path, '/'); $this->query = null; $this->fragment = null; if (preg_match('/^(.*?)(\\?([^#]*))?(#(.*))?$/u', $path, $matches)) { $path = $matches[1]; $this->query = !empty($matches[3]) ? $matches[3] : null; $this->fragment = !empty($matches[5]) ? $matches[5] : null; } $this->path = $path; return $this; }
[ "public", "function", "setPath", "(", "string", "$", "path", ")", "{", "$", "path", "=", "'/'", ".", "ltrim", "(", "$", "path", ",", "'/'", ")", ";", "$", "this", "->", "query", "=", "null", ";", "$", "this", "->", "fragment", "=", "null", ";", "if", "(", "preg_match", "(", "'/^(.*?)(\\\\?([^#]*))?(#(.*))?$/u'", ",", "$", "path", ",", "$", "matches", ")", ")", "{", "$", "path", "=", "$", "matches", "[", "1", "]", ";", "$", "this", "->", "query", "=", "!", "empty", "(", "$", "matches", "[", "3", "]", ")", "?", "$", "matches", "[", "3", "]", ":", "null", ";", "$", "this", "->", "fragment", "=", "!", "empty", "(", "$", "matches", "[", "5", "]", ")", "?", "$", "matches", "[", "5", "]", ":", "null", ";", "}", "$", "this", "->", "path", "=", "$", "path", ";", "return", "$", "this", ";", "}" ]
Set the path of the URL. This will unset the currently set fragment and query and overwrite them with whatever is appended in the path. @param string $path The path to set. May include query and fragment @return URL Provides fluent interface
[ "Set", "the", "path", "of", "the", "URL", ".", "This", "will", "unset", "the", "currently", "set", "fragment", "and", "query", "and", "overwrite", "them", "with", "whatever", "is", "appended", "in", "the", "path", "." ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/URL.php#L154-L168
train
Wedeto/HTTP
src/URL.php
URL.toString
public function toString(bool $idn = false) { $o = ""; if (!empty($this->scheme)) $o .= $this->scheme . "://"; if (!empty($this->username) && !empty($this->password)) $o .= $this->username . ':' . $this->password . '@'; // Check for IDN $host = $this->host; if ($idn && preg_match('/[^\x20-\x7f]/', $host)) $host = \idn_to_ascii($host); $o .= $host; if (!empty($this->port)) { if (!( ($this->scheme === "http" && $this->port === 80) || ($this->scheme === "https" && $this->port === 443) || ($this->scheme === "ftp" && $this->port === 21) )) $o .= ":" . $this->port; } $o .= $this->path; $query = $this->getQuery(); if (!empty($query)) $o .= '?' . $query; if (!empty($this->fragment)) $o .= '#' . $this->fragment; return $o; }
php
public function toString(bool $idn = false) { $o = ""; if (!empty($this->scheme)) $o .= $this->scheme . "://"; if (!empty($this->username) && !empty($this->password)) $o .= $this->username . ':' . $this->password . '@'; // Check for IDN $host = $this->host; if ($idn && preg_match('/[^\x20-\x7f]/', $host)) $host = \idn_to_ascii($host); $o .= $host; if (!empty($this->port)) { if (!( ($this->scheme === "http" && $this->port === 80) || ($this->scheme === "https" && $this->port === 443) || ($this->scheme === "ftp" && $this->port === 21) )) $o .= ":" . $this->port; } $o .= $this->path; $query = $this->getQuery(); if (!empty($query)) $o .= '?' . $query; if (!empty($this->fragment)) $o .= '#' . $this->fragment; return $o; }
[ "public", "function", "toString", "(", "bool", "$", "idn", "=", "false", ")", "{", "$", "o", "=", "\"\"", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "scheme", ")", ")", "$", "o", ".=", "$", "this", "->", "scheme", ".", "\"://\"", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "username", ")", "&&", "!", "empty", "(", "$", "this", "->", "password", ")", ")", "$", "o", ".=", "$", "this", "->", "username", ".", "':'", ".", "$", "this", "->", "password", ".", "'@'", ";", "// Check for IDN", "$", "host", "=", "$", "this", "->", "host", ";", "if", "(", "$", "idn", "&&", "preg_match", "(", "'/[^\\x20-\\x7f]/'", ",", "$", "host", ")", ")", "$", "host", "=", "\\", "idn_to_ascii", "(", "$", "host", ")", ";", "$", "o", ".=", "$", "host", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "port", ")", ")", "{", "if", "(", "!", "(", "(", "$", "this", "->", "scheme", "===", "\"http\"", "&&", "$", "this", "->", "port", "===", "80", ")", "||", "(", "$", "this", "->", "scheme", "===", "\"https\"", "&&", "$", "this", "->", "port", "===", "443", ")", "||", "(", "$", "this", "->", "scheme", "===", "\"ftp\"", "&&", "$", "this", "->", "port", "===", "21", ")", ")", ")", "$", "o", ".=", "\":\"", ".", "$", "this", "->", "port", ";", "}", "$", "o", ".=", "$", "this", "->", "path", ";", "$", "query", "=", "$", "this", "->", "getQuery", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "query", ")", ")", "$", "o", ".=", "'?'", ".", "$", "query", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "fragment", ")", ")", "$", "o", ".=", "'#'", ".", "$", "this", "->", "fragment", ";", "return", "$", "o", ";", "}" ]
Convert a URL to a string. @param bool $idn Whether to allow IDN names or convert them to punycode. @return string A string representation of the URL
[ "Convert", "a", "URL", "to", "a", "string", "." ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/URL.php#L183-L218
train
Wedeto/HTTP
src/URL.php
URL.setHost
public function setHost(string $hostname) { if (($ppos = strrpos($hostname, ":")) !== false) { $this->port = substr($hostname, $ppos + 1); $hostname = substr($hostname, 0, $ppos); } if (substr($hostname, 0, 4) === "xn--") $hostname = \idn_to_utf8($hostname); $this->host = strtolower($hostname); return $this; }
php
public function setHost(string $hostname) { if (($ppos = strrpos($hostname, ":")) !== false) { $this->port = substr($hostname, $ppos + 1); $hostname = substr($hostname, 0, $ppos); } if (substr($hostname, 0, 4) === "xn--") $hostname = \idn_to_utf8($hostname); $this->host = strtolower($hostname); return $this; }
[ "public", "function", "setHost", "(", "string", "$", "hostname", ")", "{", "if", "(", "(", "$", "ppos", "=", "strrpos", "(", "$", "hostname", ",", "\":\"", ")", ")", "!==", "false", ")", "{", "$", "this", "->", "port", "=", "substr", "(", "$", "hostname", ",", "$", "ppos", "+", "1", ")", ";", "$", "hostname", "=", "substr", "(", "$", "hostname", ",", "0", ",", "$", "ppos", ")", ";", "}", "if", "(", "substr", "(", "$", "hostname", ",", "0", ",", "4", ")", "===", "\"xn--\"", ")", "$", "hostname", "=", "\\", "idn_to_utf8", "(", "$", "hostname", ")", ";", "$", "this", "->", "host", "=", "strtolower", "(", "$", "hostname", ")", ";", "return", "$", "this", ";", "}" ]
Set the host name of the URL @param string $hostname The hostname to set
[ "Set", "the", "host", "name", "of", "the", "URL" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/URL.php#L224-L237
train
Wedeto/HTTP
src/URL.php
URL.set
public function set(string $field, $value) { if ($value === null) $value = ""; switch ($field) { case "scheme": $this->scheme = strtolower($value); return $this; case "port": $value = empty($value) ? null : (int)$value; case "username": case "password": case "fragment": $this->$field = $value; return $this; case "query": $this->query = $this->parseQuery($value); return $this; case "path": $this->setPath($value); return $this; case "host": return $this->setHost($value); } throw new \OutOfRangeException($field); }
php
public function set(string $field, $value) { if ($value === null) $value = ""; switch ($field) { case "scheme": $this->scheme = strtolower($value); return $this; case "port": $value = empty($value) ? null : (int)$value; case "username": case "password": case "fragment": $this->$field = $value; return $this; case "query": $this->query = $this->parseQuery($value); return $this; case "path": $this->setPath($value); return $this; case "host": return $this->setHost($value); } throw new \OutOfRangeException($field); }
[ "public", "function", "set", "(", "string", "$", "field", ",", "$", "value", ")", "{", "if", "(", "$", "value", "===", "null", ")", "$", "value", "=", "\"\"", ";", "switch", "(", "$", "field", ")", "{", "case", "\"scheme\"", ":", "$", "this", "->", "scheme", "=", "strtolower", "(", "$", "value", ")", ";", "return", "$", "this", ";", "case", "\"port\"", ":", "$", "value", "=", "empty", "(", "$", "value", ")", "?", "null", ":", "(", "int", ")", "$", "value", ";", "case", "\"username\"", ":", "case", "\"password\"", ":", "case", "\"fragment\"", ":", "$", "this", "->", "$", "field", "=", "$", "value", ";", "return", "$", "this", ";", "case", "\"query\"", ":", "$", "this", "->", "query", "=", "$", "this", "->", "parseQuery", "(", "$", "value", ")", ";", "return", "$", "this", ";", "case", "\"path\"", ":", "$", "this", "->", "setPath", "(", "$", "value", ")", ";", "return", "$", "this", ";", "case", "\"host\"", ":", "return", "$", "this", "->", "setHost", "(", "$", "value", ")", ";", "}", "throw", "new", "\\", "OutOfRangeException", "(", "$", "field", ")", ";", "}" ]
Set a field to a new value @param string $field The field to set @param mixed $value The value to update @return URL Provides fluent interface
[ "Set", "a", "field", "to", "a", "new", "value" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/URL.php#L287-L314
train
Wedeto/HTTP
src/URL.php
URL.get
public function get(string $field) { if ($field === "secure") return $this->scheme === "https"; if ($field === "port" && $this->port === null) { if ($this->scheme === "http") return 80; if ($this->scheme === "https") return 443; if ($this->scheme === "ftp") return 21; } if ($field === "suffix") return $this->getSuffix(); if ($field === "query") return $this->getQuery(); if (property_exists($this, $field)) return $this->$field; throw new \OutOfRangeException($field); }
php
public function get(string $field) { if ($field === "secure") return $this->scheme === "https"; if ($field === "port" && $this->port === null) { if ($this->scheme === "http") return 80; if ($this->scheme === "https") return 443; if ($this->scheme === "ftp") return 21; } if ($field === "suffix") return $this->getSuffix(); if ($field === "query") return $this->getQuery(); if (property_exists($this, $field)) return $this->$field; throw new \OutOfRangeException($field); }
[ "public", "function", "get", "(", "string", "$", "field", ")", "{", "if", "(", "$", "field", "===", "\"secure\"", ")", "return", "$", "this", "->", "scheme", "===", "\"https\"", ";", "if", "(", "$", "field", "===", "\"port\"", "&&", "$", "this", "->", "port", "===", "null", ")", "{", "if", "(", "$", "this", "->", "scheme", "===", "\"http\"", ")", "return", "80", ";", "if", "(", "$", "this", "->", "scheme", "===", "\"https\"", ")", "return", "443", ";", "if", "(", "$", "this", "->", "scheme", "===", "\"ftp\"", ")", "return", "21", ";", "}", "if", "(", "$", "field", "===", "\"suffix\"", ")", "return", "$", "this", "->", "getSuffix", "(", ")", ";", "if", "(", "$", "field", "===", "\"query\"", ")", "return", "$", "this", "->", "getQuery", "(", ")", ";", "if", "(", "property_exists", "(", "$", "this", ",", "$", "field", ")", ")", "return", "$", "this", "->", "$", "field", ";", "throw", "new", "\\", "OutOfRangeException", "(", "$", "field", ")", ";", "}" ]
Get the value for a field @param string field The field to get @return string The value for the field
[ "Get", "the", "value", "for", "a", "field" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/URL.php#L321-L343
train
Wedeto/HTTP
src/URL.php
URL.setQueryVariable
public function setQueryVariable(string $key, string $value) { if (empty($value)) unset($this->query[$key]); else $this->query[$key] = $value; return $this; }
php
public function setQueryVariable(string $key, string $value) { if (empty($value)) unset($this->query[$key]); else $this->query[$key] = $value; return $this; }
[ "public", "function", "setQueryVariable", "(", "string", "$", "key", ",", "string", "$", "value", ")", "{", "if", "(", "empty", "(", "$", "value", ")", ")", "unset", "(", "$", "this", "->", "query", "[", "$", "key", "]", ")", ";", "else", "$", "this", "->", "query", "[", "$", "key", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Set or update a query variable @param string $key The name of the query parameter @param string $value The value for the parameter @return URL Provides fluent interface
[ "Set", "or", "update", "a", "query", "variable" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/URL.php#L391-L398
train
ReputationVIP/composer-assets-installer
src/AssetsInstaller.php
AssetsInstaller.getVendorPath
public function getVendorPath() { if (is_null($this->vendorPath)) { // We get the current package install path $installPath = $this->composer->getInstallationManager()->getInstallPath($this->package); // We get the name of the package in order to get its target path $targetDir = $this->package->getName(); // We remove this target path to isolate the vendor path only $this->vendorPath = explode($targetDir, $installPath)[0]; } return $this->vendorPath; }
php
public function getVendorPath() { if (is_null($this->vendorPath)) { // We get the current package install path $installPath = $this->composer->getInstallationManager()->getInstallPath($this->package); // We get the name of the package in order to get its target path $targetDir = $this->package->getName(); // We remove this target path to isolate the vendor path only $this->vendorPath = explode($targetDir, $installPath)[0]; } return $this->vendorPath; }
[ "public", "function", "getVendorPath", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "vendorPath", ")", ")", "{", "// We get the current package install path", "$", "installPath", "=", "$", "this", "->", "composer", "->", "getInstallationManager", "(", ")", "->", "getInstallPath", "(", "$", "this", "->", "package", ")", ";", "// We get the name of the package in order to get its target path", "$", "targetDir", "=", "$", "this", "->", "package", "->", "getName", "(", ")", ";", "// We remove this target path to isolate the vendor path only", "$", "this", "->", "vendorPath", "=", "explode", "(", "$", "targetDir", ",", "$", "installPath", ")", "[", "0", "]", ";", "}", "return", "$", "this", "->", "vendorPath", ";", "}" ]
Returns the vendor path of the current package @return string
[ "Returns", "the", "vendor", "path", "of", "the", "current", "package" ]
c8dea009795fe23dcd7f41d8b9a5bf4a970d842b
https://github.com/ReputationVIP/composer-assets-installer/blob/c8dea009795fe23dcd7f41d8b9a5bf4a970d842b/src/AssetsInstaller.php#L107-L118
train
ReputationVIP/composer-assets-installer
src/AssetsInstaller.php
AssetsInstaller.install
public function install() { // We get all the packages required $packages = $this->composer->getPackage()->getRequires(); /** @var Package\Link $package */ foreach ($packages as $package) { $this->packagesStatuses[$package->getTarget()] = array('extra' => null, 'dirs' => null); $this->installPackage($package); } return $this; }
php
public function install() { // We get all the packages required $packages = $this->composer->getPackage()->getRequires(); /** @var Package\Link $package */ foreach ($packages as $package) { $this->packagesStatuses[$package->getTarget()] = array('extra' => null, 'dirs' => null); $this->installPackage($package); } return $this; }
[ "public", "function", "install", "(", ")", "{", "// We get all the packages required", "$", "packages", "=", "$", "this", "->", "composer", "->", "getPackage", "(", ")", "->", "getRequires", "(", ")", ";", "/** @var Package\\Link $package */", "foreach", "(", "$", "packages", "as", "$", "package", ")", "{", "$", "this", "->", "packagesStatuses", "[", "$", "package", "->", "getTarget", "(", ")", "]", "=", "array", "(", "'extra'", "=>", "null", ",", "'dirs'", "=>", "null", ")", ";", "$", "this", "->", "installPackage", "(", "$", "package", ")", ";", "}", "return", "$", "this", ";", "}" ]
Installs all the assets directories of the dependency packages @return $this
[ "Installs", "all", "the", "assets", "directories", "of", "the", "dependency", "packages" ]
c8dea009795fe23dcd7f41d8b9a5bf4a970d842b
https://github.com/ReputationVIP/composer-assets-installer/blob/c8dea009795fe23dcd7f41d8b9a5bf4a970d842b/src/AssetsInstaller.php#L124-L134
train
ReputationVIP/composer-assets-installer
src/AssetsInstaller.php
AssetsInstaller.installPackage
public function installPackage($package) { // We read its composer file $jsonData = $this->getPackageJsonFile($package); // We get the package assets dirs $packagesAssetsDir = $this->getPackageAssetsDirs($jsonData); if (!is_null($packagesAssetsDir)) { $this->log($package->getTarget(), self::LOG_INFO, self::CODE_INSTALLING_PACKAGE); $this->packagesStatuses[$package->getTarget()]['extra'] = 1; foreach ($packagesAssetsDir as $namespace => $packageAssetsDir) { if (!isset($this->packagesStatuses[$package->getTarget()]['dirs'])) { $this->packagesStatuses[$package->getTarget()]['dirs'] = array(); } $this->packagesStatuses[$package->getTarget()]['dirs'][$namespace] = null; // We install each package directory $this->installPackageDir($package, $namespace, $packageAssetsDir); } } else { $this->log($package->getTarget(), self::LOG_INFO, self::CODE_NO_INSTALL); $this->packagesStatuses[$package->getTarget()]['extra'] = 0; } }
php
public function installPackage($package) { // We read its composer file $jsonData = $this->getPackageJsonFile($package); // We get the package assets dirs $packagesAssetsDir = $this->getPackageAssetsDirs($jsonData); if (!is_null($packagesAssetsDir)) { $this->log($package->getTarget(), self::LOG_INFO, self::CODE_INSTALLING_PACKAGE); $this->packagesStatuses[$package->getTarget()]['extra'] = 1; foreach ($packagesAssetsDir as $namespace => $packageAssetsDir) { if (!isset($this->packagesStatuses[$package->getTarget()]['dirs'])) { $this->packagesStatuses[$package->getTarget()]['dirs'] = array(); } $this->packagesStatuses[$package->getTarget()]['dirs'][$namespace] = null; // We install each package directory $this->installPackageDir($package, $namespace, $packageAssetsDir); } } else { $this->log($package->getTarget(), self::LOG_INFO, self::CODE_NO_INSTALL); $this->packagesStatuses[$package->getTarget()]['extra'] = 0; } }
[ "public", "function", "installPackage", "(", "$", "package", ")", "{", "// We read its composer file", "$", "jsonData", "=", "$", "this", "->", "getPackageJsonFile", "(", "$", "package", ")", ";", "// We get the package assets dirs", "$", "packagesAssetsDir", "=", "$", "this", "->", "getPackageAssetsDirs", "(", "$", "jsonData", ")", ";", "if", "(", "!", "is_null", "(", "$", "packagesAssetsDir", ")", ")", "{", "$", "this", "->", "log", "(", "$", "package", "->", "getTarget", "(", ")", ",", "self", "::", "LOG_INFO", ",", "self", "::", "CODE_INSTALLING_PACKAGE", ")", ";", "$", "this", "->", "packagesStatuses", "[", "$", "package", "->", "getTarget", "(", ")", "]", "[", "'extra'", "]", "=", "1", ";", "foreach", "(", "$", "packagesAssetsDir", "as", "$", "namespace", "=>", "$", "packageAssetsDir", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "packagesStatuses", "[", "$", "package", "->", "getTarget", "(", ")", "]", "[", "'dirs'", "]", ")", ")", "{", "$", "this", "->", "packagesStatuses", "[", "$", "package", "->", "getTarget", "(", ")", "]", "[", "'dirs'", "]", "=", "array", "(", ")", ";", "}", "$", "this", "->", "packagesStatuses", "[", "$", "package", "->", "getTarget", "(", ")", "]", "[", "'dirs'", "]", "[", "$", "namespace", "]", "=", "null", ";", "// We install each package directory", "$", "this", "->", "installPackageDir", "(", "$", "package", ",", "$", "namespace", ",", "$", "packageAssetsDir", ")", ";", "}", "}", "else", "{", "$", "this", "->", "log", "(", "$", "package", "->", "getTarget", "(", ")", ",", "self", "::", "LOG_INFO", ",", "self", "::", "CODE_NO_INSTALL", ")", ";", "$", "this", "->", "packagesStatuses", "[", "$", "package", "->", "getTarget", "(", ")", "]", "[", "'extra'", "]", "=", "0", ";", "}", "}" ]
Installs all the assets directories of the given package @param Package\Link $package
[ "Installs", "all", "the", "assets", "directories", "of", "the", "given", "package" ]
c8dea009795fe23dcd7f41d8b9a5bf4a970d842b
https://github.com/ReputationVIP/composer-assets-installer/blob/c8dea009795fe23dcd7f41d8b9a5bf4a970d842b/src/AssetsInstaller.php#L140-L161
train
ReputationVIP/composer-assets-installer
src/AssetsInstaller.php
AssetsInstaller.getPackageJsonFile
public function getPackageJsonFile($package) { // We get the project vendor path $vendorPath = $this->getVendorPath(); // We get the target dir of the iterated package $targetDir = $package->getTarget(); $jsonPath = $vendorPath . $targetDir . "/composer.json"; if (method_exists($package, 'getJsonFile')) { $jsonFile = $package->getJsonFile($jsonPath); } else { // @codeCoverageIgnoreStart $jsonFile = new JsonFile($jsonPath); // @codeCoverageIgnoreEnd } return $this->fs->exists($jsonPath) ? $jsonFile->read() : null; }
php
public function getPackageJsonFile($package) { // We get the project vendor path $vendorPath = $this->getVendorPath(); // We get the target dir of the iterated package $targetDir = $package->getTarget(); $jsonPath = $vendorPath . $targetDir . "/composer.json"; if (method_exists($package, 'getJsonFile')) { $jsonFile = $package->getJsonFile($jsonPath); } else { // @codeCoverageIgnoreStart $jsonFile = new JsonFile($jsonPath); // @codeCoverageIgnoreEnd } return $this->fs->exists($jsonPath) ? $jsonFile->read() : null; }
[ "public", "function", "getPackageJsonFile", "(", "$", "package", ")", "{", "// We get the project vendor path", "$", "vendorPath", "=", "$", "this", "->", "getVendorPath", "(", ")", ";", "// We get the target dir of the iterated package", "$", "targetDir", "=", "$", "package", "->", "getTarget", "(", ")", ";", "$", "jsonPath", "=", "$", "vendorPath", ".", "$", "targetDir", ".", "\"/composer.json\"", ";", "if", "(", "method_exists", "(", "$", "package", ",", "'getJsonFile'", ")", ")", "{", "$", "jsonFile", "=", "$", "package", "->", "getJsonFile", "(", "$", "jsonPath", ")", ";", "}", "else", "{", "// @codeCoverageIgnoreStart", "$", "jsonFile", "=", "new", "JsonFile", "(", "$", "jsonPath", ")", ";", "// @codeCoverageIgnoreEnd", "}", "return", "$", "this", "->", "fs", "->", "exists", "(", "$", "jsonPath", ")", "?", "$", "jsonFile", "->", "read", "(", ")", ":", "null", ";", "}" ]
Returns the Json file of the given Package @param Package\Link $package @return mixed
[ "Returns", "the", "Json", "file", "of", "the", "given", "Package" ]
c8dea009795fe23dcd7f41d8b9a5bf4a970d842b
https://github.com/ReputationVIP/composer-assets-installer/blob/c8dea009795fe23dcd7f41d8b9a5bf4a970d842b/src/AssetsInstaller.php#L168-L184
train
ReputationVIP/composer-assets-installer
src/AssetsInstaller.php
AssetsInstaller.getPackageAssetsDirs
public function getPackageAssetsDirs($jsonData) { $packagesAssetsDir = null; // If some assets were set on the package if (isset($jsonData["extra"][self::LABEL_ASSETS_DIR])) { // We get the assets-dir of this package $packagesAssetsDir = $jsonData["extra"][self::LABEL_ASSETS_DIR]; if (is_string($packagesAssetsDir)) { // If we get a string, it's the public shortcut so we uniform the return $packagesAssetsDir = array(self::LABEL_PUBLIC_DIR => $packagesAssetsDir); } } return $packagesAssetsDir; }
php
public function getPackageAssetsDirs($jsonData) { $packagesAssetsDir = null; // If some assets were set on the package if (isset($jsonData["extra"][self::LABEL_ASSETS_DIR])) { // We get the assets-dir of this package $packagesAssetsDir = $jsonData["extra"][self::LABEL_ASSETS_DIR]; if (is_string($packagesAssetsDir)) { // If we get a string, it's the public shortcut so we uniform the return $packagesAssetsDir = array(self::LABEL_PUBLIC_DIR => $packagesAssetsDir); } } return $packagesAssetsDir; }
[ "public", "function", "getPackageAssetsDirs", "(", "$", "jsonData", ")", "{", "$", "packagesAssetsDir", "=", "null", ";", "// If some assets were set on the package", "if", "(", "isset", "(", "$", "jsonData", "[", "\"extra\"", "]", "[", "self", "::", "LABEL_ASSETS_DIR", "]", ")", ")", "{", "// We get the assets-dir of this package", "$", "packagesAssetsDir", "=", "$", "jsonData", "[", "\"extra\"", "]", "[", "self", "::", "LABEL_ASSETS_DIR", "]", ";", "if", "(", "is_string", "(", "$", "packagesAssetsDir", ")", ")", "{", "// If we get a string, it's the public shortcut so we uniform the return", "$", "packagesAssetsDir", "=", "array", "(", "self", "::", "LABEL_PUBLIC_DIR", "=>", "$", "packagesAssetsDir", ")", ";", "}", "}", "return", "$", "packagesAssetsDir", ";", "}" ]
Returns all the assets directories contained in the given jsonData @param array $jsonData @return array|null
[ "Returns", "all", "the", "assets", "directories", "contained", "in", "the", "given", "jsonData" ]
c8dea009795fe23dcd7f41d8b9a5bf4a970d842b
https://github.com/ReputationVIP/composer-assets-installer/blob/c8dea009795fe23dcd7f41d8b9a5bf4a970d842b/src/AssetsInstaller.php#L191-L204
train
ReputationVIP/composer-assets-installer
src/AssetsInstaller.php
AssetsInstaller.installPackageDir
public function installPackageDir($package, $namespace, $packageAssetsDir) { $this->log($package->getTarget(), self::LOG_INFO, self::CODE_INSTALLING_DIR, array('namespace' => $namespace)); if (!isset($this->assetsDirectories[$namespace])) { $this->log($package->getTarget(), self::LOG_WARNING, self::CODE_NO_MATCHING_DIR, array('namespace' => $namespace)); $this->packagesStatuses[$package->getTarget()]['dirs'][$namespace]['status'] = 0; return; } $this->log($package->getTarget(), self::LOG_INFO, self::CODE_MATCHING_DIR, array('namespace' => $namespace)); // We get the project vendor path $vendorPath = $this->getVendorPath(); // We get the target dir of the iterated package $targetDir = $package->getTarget(); // We get the full path of the current assets directory $packagePath = $vendorPath . $targetDir . "/" . $packageAssetsDir; // We check if this path is a directory if ($this->directoryHandler->isDirectory($packagePath)) { $this->log($package->getTarget(), self::LOG_INFO, self::CODE_DIRECTORY, array('directory' => $this->assetsDirectories[$namespace])); $src = $packagePath; $dst = $vendorPath . "../" . $this->assetsDirectories[$namespace] . $targetDir; // We delete the remaining directory if any // In order to update it $this->directoryHandler->deleteDirectory($dst); // We finally copy the package assets-dir // Into the project assets-dir $this->directoryHandler->copyDirectory($src, $dst); $this->log($package->getTarget(), self::LOG_INFO, self::CODE_DIR_INSTALLED, array('destination' => $dst)); $this->packagesStatuses[$package->getTarget()]['dirs'][$namespace]['status'] = 1; } else { $this->log($package->getTarget(), self::LOG_ERROR, self::CODE_NOT_DIRECTORY, array('directory' => $this->assetsDirectories[$namespace])); $this->packagesStatuses[$package->getTarget()]['dirs'][$namespace]['status'] = 0; } }
php
public function installPackageDir($package, $namespace, $packageAssetsDir) { $this->log($package->getTarget(), self::LOG_INFO, self::CODE_INSTALLING_DIR, array('namespace' => $namespace)); if (!isset($this->assetsDirectories[$namespace])) { $this->log($package->getTarget(), self::LOG_WARNING, self::CODE_NO_MATCHING_DIR, array('namespace' => $namespace)); $this->packagesStatuses[$package->getTarget()]['dirs'][$namespace]['status'] = 0; return; } $this->log($package->getTarget(), self::LOG_INFO, self::CODE_MATCHING_DIR, array('namespace' => $namespace)); // We get the project vendor path $vendorPath = $this->getVendorPath(); // We get the target dir of the iterated package $targetDir = $package->getTarget(); // We get the full path of the current assets directory $packagePath = $vendorPath . $targetDir . "/" . $packageAssetsDir; // We check if this path is a directory if ($this->directoryHandler->isDirectory($packagePath)) { $this->log($package->getTarget(), self::LOG_INFO, self::CODE_DIRECTORY, array('directory' => $this->assetsDirectories[$namespace])); $src = $packagePath; $dst = $vendorPath . "../" . $this->assetsDirectories[$namespace] . $targetDir; // We delete the remaining directory if any // In order to update it $this->directoryHandler->deleteDirectory($dst); // We finally copy the package assets-dir // Into the project assets-dir $this->directoryHandler->copyDirectory($src, $dst); $this->log($package->getTarget(), self::LOG_INFO, self::CODE_DIR_INSTALLED, array('destination' => $dst)); $this->packagesStatuses[$package->getTarget()]['dirs'][$namespace]['status'] = 1; } else { $this->log($package->getTarget(), self::LOG_ERROR, self::CODE_NOT_DIRECTORY, array('directory' => $this->assetsDirectories[$namespace])); $this->packagesStatuses[$package->getTarget()]['dirs'][$namespace]['status'] = 0; } }
[ "public", "function", "installPackageDir", "(", "$", "package", ",", "$", "namespace", ",", "$", "packageAssetsDir", ")", "{", "$", "this", "->", "log", "(", "$", "package", "->", "getTarget", "(", ")", ",", "self", "::", "LOG_INFO", ",", "self", "::", "CODE_INSTALLING_DIR", ",", "array", "(", "'namespace'", "=>", "$", "namespace", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "assetsDirectories", "[", "$", "namespace", "]", ")", ")", "{", "$", "this", "->", "log", "(", "$", "package", "->", "getTarget", "(", ")", ",", "self", "::", "LOG_WARNING", ",", "self", "::", "CODE_NO_MATCHING_DIR", ",", "array", "(", "'namespace'", "=>", "$", "namespace", ")", ")", ";", "$", "this", "->", "packagesStatuses", "[", "$", "package", "->", "getTarget", "(", ")", "]", "[", "'dirs'", "]", "[", "$", "namespace", "]", "[", "'status'", "]", "=", "0", ";", "return", ";", "}", "$", "this", "->", "log", "(", "$", "package", "->", "getTarget", "(", ")", ",", "self", "::", "LOG_INFO", ",", "self", "::", "CODE_MATCHING_DIR", ",", "array", "(", "'namespace'", "=>", "$", "namespace", ")", ")", ";", "// We get the project vendor path", "$", "vendorPath", "=", "$", "this", "->", "getVendorPath", "(", ")", ";", "// We get the target dir of the iterated package", "$", "targetDir", "=", "$", "package", "->", "getTarget", "(", ")", ";", "// We get the full path of the current assets directory", "$", "packagePath", "=", "$", "vendorPath", ".", "$", "targetDir", ".", "\"/\"", ".", "$", "packageAssetsDir", ";", "// We check if this path is a directory", "if", "(", "$", "this", "->", "directoryHandler", "->", "isDirectory", "(", "$", "packagePath", ")", ")", "{", "$", "this", "->", "log", "(", "$", "package", "->", "getTarget", "(", ")", ",", "self", "::", "LOG_INFO", ",", "self", "::", "CODE_DIRECTORY", ",", "array", "(", "'directory'", "=>", "$", "this", "->", "assetsDirectories", "[", "$", "namespace", "]", ")", ")", ";", "$", "src", "=", "$", "packagePath", ";", "$", "dst", "=", "$", "vendorPath", ".", "\"../\"", ".", "$", "this", "->", "assetsDirectories", "[", "$", "namespace", "]", ".", "$", "targetDir", ";", "// We delete the remaining directory if any", "// In order to update it", "$", "this", "->", "directoryHandler", "->", "deleteDirectory", "(", "$", "dst", ")", ";", "// We finally copy the package assets-dir", "// Into the project assets-dir", "$", "this", "->", "directoryHandler", "->", "copyDirectory", "(", "$", "src", ",", "$", "dst", ")", ";", "$", "this", "->", "log", "(", "$", "package", "->", "getTarget", "(", ")", ",", "self", "::", "LOG_INFO", ",", "self", "::", "CODE_DIR_INSTALLED", ",", "array", "(", "'destination'", "=>", "$", "dst", ")", ")", ";", "$", "this", "->", "packagesStatuses", "[", "$", "package", "->", "getTarget", "(", ")", "]", "[", "'dirs'", "]", "[", "$", "namespace", "]", "[", "'status'", "]", "=", "1", ";", "}", "else", "{", "$", "this", "->", "log", "(", "$", "package", "->", "getTarget", "(", ")", ",", "self", "::", "LOG_ERROR", ",", "self", "::", "CODE_NOT_DIRECTORY", ",", "array", "(", "'directory'", "=>", "$", "this", "->", "assetsDirectories", "[", "$", "namespace", "]", ")", ")", ";", "$", "this", "->", "packagesStatuses", "[", "$", "package", "->", "getTarget", "(", ")", "]", "[", "'dirs'", "]", "[", "$", "namespace", "]", "[", "'status'", "]", "=", "0", ";", "}", "}" ]
Installs a specific directory from the given package @param Package\Link $package @param string $namespace @param string $packageAssetsDir
[ "Installs", "a", "specific", "directory", "from", "the", "given", "package" ]
c8dea009795fe23dcd7f41d8b9a5bf4a970d842b
https://github.com/ReputationVIP/composer-assets-installer/blob/c8dea009795fe23dcd7f41d8b9a5bf4a970d842b/src/AssetsInstaller.php#L212-L245
train
ebidtech/options-resolver
src/EBT/OptionsResolver/Model/OptionsResolver/OptionsResolver.php
OptionsResolver.setCast
public function setCast($option, $type) { /* Ensure the option exists: not very important, but ensures consistent behavior with underlying code. */ if (! $this->isDefined($option)) { throw new UndefinedOptionsException( sprintf( 'The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', $this->getDefinedOptions()) ) ); } /* Check if a closure was passed as argument. */ if ($type instanceof \Closure) { $refClosure = new \ReflectionFunction($type); /* The closure must have exactly one parameter, and it should be required. */ if (2 !== $refClosure->getNumberOfParameters() + $refClosure->getNumberOfRequiredParameters()) { throw new InvalidArgumentException( 'The given closure must define exactly one required parameter (the value to cast).' ); } $this->casts[$option] = $type; return $this; } /* Ensure that a valid type to cast to is given. */ if (! in_array($type, $this->validCastTypes)) { throw new InvalidArgumentException( sprintf( 'The type cast "%s" does not exist. Defined type casts are: "%s".', $type, implode('", "', $this->validCastTypes) ) ); } /* Add the type cast. */ $this->casts[$option] = $type; return $this; }
php
public function setCast($option, $type) { /* Ensure the option exists: not very important, but ensures consistent behavior with underlying code. */ if (! $this->isDefined($option)) { throw new UndefinedOptionsException( sprintf( 'The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', $this->getDefinedOptions()) ) ); } /* Check if a closure was passed as argument. */ if ($type instanceof \Closure) { $refClosure = new \ReflectionFunction($type); /* The closure must have exactly one parameter, and it should be required. */ if (2 !== $refClosure->getNumberOfParameters() + $refClosure->getNumberOfRequiredParameters()) { throw new InvalidArgumentException( 'The given closure must define exactly one required parameter (the value to cast).' ); } $this->casts[$option] = $type; return $this; } /* Ensure that a valid type to cast to is given. */ if (! in_array($type, $this->validCastTypes)) { throw new InvalidArgumentException( sprintf( 'The type cast "%s" does not exist. Defined type casts are: "%s".', $type, implode('", "', $this->validCastTypes) ) ); } /* Add the type cast. */ $this->casts[$option] = $type; return $this; }
[ "public", "function", "setCast", "(", "$", "option", ",", "$", "type", ")", "{", "/* Ensure the option exists: not very important, but ensures consistent behavior with underlying code. */", "if", "(", "!", "$", "this", "->", "isDefined", "(", "$", "option", ")", ")", "{", "throw", "new", "UndefinedOptionsException", "(", "sprintf", "(", "'The option \"%s\" does not exist. Defined options are: \"%s\".'", ",", "$", "option", ",", "implode", "(", "'\", \"'", ",", "$", "this", "->", "getDefinedOptions", "(", ")", ")", ")", ")", ";", "}", "/* Check if a closure was passed as argument. */", "if", "(", "$", "type", "instanceof", "\\", "Closure", ")", "{", "$", "refClosure", "=", "new", "\\", "ReflectionFunction", "(", "$", "type", ")", ";", "/* The closure must have exactly one parameter, and it should be required. */", "if", "(", "2", "!==", "$", "refClosure", "->", "getNumberOfParameters", "(", ")", "+", "$", "refClosure", "->", "getNumberOfRequiredParameters", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'The given closure must define exactly one required parameter (the value to cast).'", ")", ";", "}", "$", "this", "->", "casts", "[", "$", "option", "]", "=", "$", "type", ";", "return", "$", "this", ";", "}", "/* Ensure that a valid type to cast to is given. */", "if", "(", "!", "in_array", "(", "$", "type", ",", "$", "this", "->", "validCastTypes", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'The type cast \"%s\" does not exist. Defined type casts are: \"%s\".'", ",", "$", "type", ",", "implode", "(", "'\", \"'", ",", "$", "this", "->", "validCastTypes", ")", ")", ")", ";", "}", "/* Add the type cast. */", "$", "this", "->", "casts", "[", "$", "option", "]", "=", "$", "type", ";", "return", "$", "this", ";", "}" ]
Sets a cast for a specific option. The given option will be cast to the given type before any validation, if possible. @param string $option Option name. @param string|\Closure $type Type to cast the option to or a closure to be lazily evaluated. @return OptionsResolver Returns itself. @throws UndefinedOptionsException @throws InvalidArgumentException
[ "Sets", "a", "cast", "for", "a", "specific", "option", ".", "The", "given", "option", "will", "be", "cast", "to", "the", "given", "type", "before", "any", "validation", "if", "possible", "." ]
a5a3a81571c4ceaa94d674c3e60b22b5ee720d72
https://github.com/ebidtech/options-resolver/blob/a5a3a81571c4ceaa94d674c3e60b22b5ee720d72/src/EBT/OptionsResolver/Model/OptionsResolver/OptionsResolver.php#L115-L158
train
ebidtech/options-resolver
src/EBT/OptionsResolver/Model/OptionsResolver/OptionsResolver.php
OptionsResolver.clearUndefinedOptions
protected function clearUndefinedOptions(array $options, $allowUndefinedOptions) { if (! $allowUndefinedOptions) { return $options; } /* Find out undefined options by computing the difference between given and defined options. */ $undefinedOptions = array_diff( array_keys($options), $this->getDefinedOptions() ); /* Remove undefined options by computing the difference between given and undefined options. */ return array_diff_key( $options, array_flip($undefinedOptions) ); }
php
protected function clearUndefinedOptions(array $options, $allowUndefinedOptions) { if (! $allowUndefinedOptions) { return $options; } /* Find out undefined options by computing the difference between given and defined options. */ $undefinedOptions = array_diff( array_keys($options), $this->getDefinedOptions() ); /* Remove undefined options by computing the difference between given and undefined options. */ return array_diff_key( $options, array_flip($undefinedOptions) ); }
[ "protected", "function", "clearUndefinedOptions", "(", "array", "$", "options", ",", "$", "allowUndefinedOptions", ")", "{", "if", "(", "!", "$", "allowUndefinedOptions", ")", "{", "return", "$", "options", ";", "}", "/* Find out undefined options by computing the difference between given and defined options. */", "$", "undefinedOptions", "=", "array_diff", "(", "array_keys", "(", "$", "options", ")", ",", "$", "this", "->", "getDefinedOptions", "(", ")", ")", ";", "/* Remove undefined options by computing the difference between given and undefined options. */", "return", "array_diff_key", "(", "$", "options", ",", "array_flip", "(", "$", "undefinedOptions", ")", ")", ";", "}" ]
Clears undefined options before resolving, if the appropriate flag is set. @param array $options Map of option names to values. @param bool $allowUndefinedOptions If set to true undefined options will not raise an error. @return array Clean options.
[ "Clears", "undefined", "options", "before", "resolving", "if", "the", "appropriate", "flag", "is", "set", "." ]
a5a3a81571c4ceaa94d674c3e60b22b5ee720d72
https://github.com/ebidtech/options-resolver/blob/a5a3a81571c4ceaa94d674c3e60b22b5ee720d72/src/EBT/OptionsResolver/Model/OptionsResolver/OptionsResolver.php#L180-L199
train
ebidtech/options-resolver
src/EBT/OptionsResolver/Model/OptionsResolver/OptionsResolver.php
OptionsResolver.resolveCasts
protected function resolveCasts(array $options = []) { /* Create a copy of the options to work on. */ $castOptions = $options; /* Iterate every options and cast as needed. */ foreach ($options as $option => $value) { /* No cast was defined, continue. */ if (! isset($this->casts[$option])) { continue; } $type = $this->casts[$option]; $castOptions[$option] = ($type instanceof \Closure) ? $type($value) : $this->castToType($value, $type); } return $castOptions; }
php
protected function resolveCasts(array $options = []) { /* Create a copy of the options to work on. */ $castOptions = $options; /* Iterate every options and cast as needed. */ foreach ($options as $option => $value) { /* No cast was defined, continue. */ if (! isset($this->casts[$option])) { continue; } $type = $this->casts[$option]; $castOptions[$option] = ($type instanceof \Closure) ? $type($value) : $this->castToType($value, $type); } return $castOptions; }
[ "protected", "function", "resolveCasts", "(", "array", "$", "options", "=", "[", "]", ")", "{", "/* Create a copy of the options to work on. */", "$", "castOptions", "=", "$", "options", ";", "/* Iterate every options and cast as needed. */", "foreach", "(", "$", "options", "as", "$", "option", "=>", "$", "value", ")", "{", "/* No cast was defined, continue. */", "if", "(", "!", "isset", "(", "$", "this", "->", "casts", "[", "$", "option", "]", ")", ")", "{", "continue", ";", "}", "$", "type", "=", "$", "this", "->", "casts", "[", "$", "option", "]", ";", "$", "castOptions", "[", "$", "option", "]", "=", "(", "$", "type", "instanceof", "\\", "Closure", ")", "?", "$", "type", "(", "$", "value", ")", ":", "$", "this", "->", "castToType", "(", "$", "value", ",", "$", "type", ")", ";", "}", "return", "$", "castOptions", ";", "}" ]
Resolves a variable casts in the initial options. @param array $options Options to cast. @return array Options after applying the relevant casts.
[ "Resolves", "a", "variable", "casts", "in", "the", "initial", "options", "." ]
a5a3a81571c4ceaa94d674c3e60b22b5ee720d72
https://github.com/ebidtech/options-resolver/blob/a5a3a81571c4ceaa94d674c3e60b22b5ee720d72/src/EBT/OptionsResolver/Model/OptionsResolver/OptionsResolver.php#L208-L229
train
ebidtech/options-resolver
src/EBT/OptionsResolver/Model/OptionsResolver/OptionsResolver.php
OptionsResolver.castToType
protected function castToType($value, $type) { switch ($type) { case self::TYPE_CAST_INT: $newValue = filter_var($value, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); $value = (null === $newValue) ? $value : $newValue; break; case self::TYPE_CAST_BOOL: $newValue = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); $value = (null === $newValue) ? $value : $newValue; break; case self::TYPE_CAST_FLOAT: $newValue = filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE); $value = (null === $newValue) ? $value : $newValue; break; } return $value; }
php
protected function castToType($value, $type) { switch ($type) { case self::TYPE_CAST_INT: $newValue = filter_var($value, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); $value = (null === $newValue) ? $value : $newValue; break; case self::TYPE_CAST_BOOL: $newValue = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); $value = (null === $newValue) ? $value : $newValue; break; case self::TYPE_CAST_FLOAT: $newValue = filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE); $value = (null === $newValue) ? $value : $newValue; break; } return $value; }
[ "protected", "function", "castToType", "(", "$", "value", ",", "$", "type", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "self", "::", "TYPE_CAST_INT", ":", "$", "newValue", "=", "filter_var", "(", "$", "value", ",", "FILTER_VALIDATE_INT", ",", "FILTER_NULL_ON_FAILURE", ")", ";", "$", "value", "=", "(", "null", "===", "$", "newValue", ")", "?", "$", "value", ":", "$", "newValue", ";", "break", ";", "case", "self", "::", "TYPE_CAST_BOOL", ":", "$", "newValue", "=", "filter_var", "(", "$", "value", ",", "FILTER_VALIDATE_BOOLEAN", ",", "FILTER_NULL_ON_FAILURE", ")", ";", "$", "value", "=", "(", "null", "===", "$", "newValue", ")", "?", "$", "value", ":", "$", "newValue", ";", "break", ";", "case", "self", "::", "TYPE_CAST_FLOAT", ":", "$", "newValue", "=", "filter_var", "(", "$", "value", ",", "FILTER_VALIDATE_FLOAT", ",", "FILTER_NULL_ON_FAILURE", ")", ";", "$", "value", "=", "(", "null", "===", "$", "newValue", ")", "?", "$", "value", ":", "$", "newValue", ";", "break", ";", "}", "return", "$", "value", ";", "}" ]
Applies specific cast logic for each type. @param mixed $value Value to cast. @param string $type Type to cast to. @return mixed Cast value.
[ "Applies", "specific", "cast", "logic", "for", "each", "type", "." ]
a5a3a81571c4ceaa94d674c3e60b22b5ee720d72
https://github.com/ebidtech/options-resolver/blob/a5a3a81571c4ceaa94d674c3e60b22b5ee720d72/src/EBT/OptionsResolver/Model/OptionsResolver/OptionsResolver.php#L239-L257
train
stubbles/stubbles-reflect
src/main/php/annotation/Annotations.php
Annotations.add
public function add(Annotation $annotation) { if (!isset($this->types[$annotation->type()])) { $this->types[$annotation->type()] = [$annotation]; } else { $this->types[$annotation->type()][] = $annotation; } return $this; }
php
public function add(Annotation $annotation) { if (!isset($this->types[$annotation->type()])) { $this->types[$annotation->type()] = [$annotation]; } else { $this->types[$annotation->type()][] = $annotation; } return $this; }
[ "public", "function", "add", "(", "Annotation", "$", "annotation", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "types", "[", "$", "annotation", "->", "type", "(", ")", "]", ")", ")", "{", "$", "this", "->", "types", "[", "$", "annotation", "->", "type", "(", ")", "]", "=", "[", "$", "annotation", "]", ";", "}", "else", "{", "$", "this", "->", "types", "[", "$", "annotation", "->", "type", "(", ")", "]", "[", "]", "=", "$", "annotation", ";", "}", "return", "$", "this", ";", "}" ]
adds given annotation @internal only to be called by the parser @param \stubbles\reflect\annotation\Annotation $annotation
[ "adds", "given", "annotation" ]
ab48f9b8692293ef0d276b52619625dbb8869c97
https://github.com/stubbles/stubbles-reflect/blob/ab48f9b8692293ef0d276b52619625dbb8869c97/src/main/php/annotation/Annotations.php#L67-L76
train
stubbles/stubbles-reflect
src/main/php/annotation/Annotations.php
Annotations.firstNamed
public function firstNamed(string $type): Annotation { if ($this->contain($type)) { return $this->types[$type][0]; } throw new \ReflectionException('Can not find annotation ' . $type . ' for ' . $this->target); }
php
public function firstNamed(string $type): Annotation { if ($this->contain($type)) { return $this->types[$type][0]; } throw new \ReflectionException('Can not find annotation ' . $type . ' for ' . $this->target); }
[ "public", "function", "firstNamed", "(", "string", "$", "type", ")", ":", "Annotation", "{", "if", "(", "$", "this", "->", "contain", "(", "$", "type", ")", ")", "{", "return", "$", "this", "->", "types", "[", "$", "type", "]", "[", "0", "]", ";", "}", "throw", "new", "\\", "ReflectionException", "(", "'Can not find annotation '", ".", "$", "type", ".", "' for '", ".", "$", "this", "->", "target", ")", ";", "}" ]
returns first annotation with given type name If no such annotation exists a ReflectionException is thrown. @param string $type @return \stubbles\reflect\annotation\Annotation @throws \ReflectionException @since 5.3.0
[ "returns", "first", "annotation", "with", "given", "type", "name" ]
ab48f9b8692293ef0d276b52619625dbb8869c97
https://github.com/stubbles/stubbles-reflect/blob/ab48f9b8692293ef0d276b52619625dbb8869c97/src/main/php/annotation/Annotations.php#L110-L117
train
ivopetkov/html-server-components-bearframework-addon
classes/HTMLServerComponents.php
HTMLServerComponents.addAlias
public function addAlias(string $alias, string $original): self { $this->aliases[$alias] = $original; return $this; }
php
public function addAlias(string $alias, string $original): self { $this->aliases[$alias] = $original; return $this; }
[ "public", "function", "addAlias", "(", "string", "$", "alias", ",", "string", "$", "original", ")", ":", "self", "{", "$", "this", "->", "aliases", "[", "$", "alias", "]", "=", "$", "original", ";", "return", "$", "this", ";", "}" ]
Adds an alias @param string $alias The alias @param string $original The original source name @return IvoPetkov\BearFramework\Addons\HTMLServerComponents Instance of itself.
[ "Adds", "an", "alias" ]
c9a5f275d10f194b2216d733bfea612fd876a0b2
https://github.com/ivopetkov/html-server-components-bearframework-addon/blob/c9a5f275d10f194b2216d733bfea612fd876a0b2/classes/HTMLServerComponents.php#L51-L55
train
ivopetkov/html-server-components-bearframework-addon
classes/HTMLServerComponents.php
HTMLServerComponents.addTag
public function addTag(string $tagName, string $src): self { $this->tagNames[$tagName] = $src; return $this; }
php
public function addTag(string $tagName, string $src): self { $this->tagNames[$tagName] = $src; return $this; }
[ "public", "function", "addTag", "(", "string", "$", "tagName", ",", "string", "$", "src", ")", ":", "self", "{", "$", "this", "->", "tagNames", "[", "$", "tagName", "]", "=", "$", "src", ";", "return", "$", "this", ";", "}" ]
Defines a new tag @param string $tagName The alias @param string $src The original source name @return IvoPetkov\BearFramework\Addons\HTMLServerComponents Instance of itself.
[ "Defines", "a", "new", "tag" ]
c9a5f275d10f194b2216d733bfea612fd876a0b2
https://github.com/ivopetkov/html-server-components-bearframework-addon/blob/c9a5f275d10f194b2216d733bfea612fd876a0b2/classes/HTMLServerComponents.php#L64-L68
train
ivopetkov/html-server-components-bearframework-addon
classes/HTMLServerComponents.php
HTMLServerComponents.make
public function make() { if (self::$newComponentCache === null) { self::$newComponentCache = new \IvoPetkov\BearFramework\Addons\HTMLServerComponents\Internal\Component(); } return clone(self::$newComponentCache); }
php
public function make() { if (self::$newComponentCache === null) { self::$newComponentCache = new \IvoPetkov\BearFramework\Addons\HTMLServerComponents\Internal\Component(); } return clone(self::$newComponentCache); }
[ "public", "function", "make", "(", ")", "{", "if", "(", "self", "::", "$", "newComponentCache", "===", "null", ")", "{", "self", "::", "$", "newComponentCache", "=", "new", "\\", "IvoPetkov", "\\", "BearFramework", "\\", "Addons", "\\", "HTMLServerComponents", "\\", "Internal", "\\", "Component", "(", ")", ";", "}", "return", "clone", "(", "self", "::", "$", "newComponentCache", ")", ";", "}" ]
Creates new component and return it @return \IvoPetkov\BearFramework\Addons\HTMLServerComponents\Internal\Component
[ "Creates", "new", "component", "and", "return", "it" ]
c9a5f275d10f194b2216d733bfea612fd876a0b2
https://github.com/ivopetkov/html-server-components-bearframework-addon/blob/c9a5f275d10f194b2216d733bfea612fd876a0b2/classes/HTMLServerComponents.php#L114-L120
train
Orkestro/CountryBundle
Controller/Backend/CountryController.php
CountryController.createCreateForm
private function createCreateForm(Country $entity) { $form = $this->createForm(new CountryType($this->get('doctrine.orm.entity_manager')->getRepository('OrkestroLocaleBundle:Locale')), $entity, array( 'action' => $this->generateUrl('orkestro_backend_country_create'), 'method' => 'POST', )); $form->add('submit', 'submit', array('label' => 'Create')); return $form; }
php
private function createCreateForm(Country $entity) { $form = $this->createForm(new CountryType($this->get('doctrine.orm.entity_manager')->getRepository('OrkestroLocaleBundle:Locale')), $entity, array( 'action' => $this->generateUrl('orkestro_backend_country_create'), 'method' => 'POST', )); $form->add('submit', 'submit', array('label' => 'Create')); return $form; }
[ "private", "function", "createCreateForm", "(", "Country", "$", "entity", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "new", "CountryType", "(", "$", "this", "->", "get", "(", "'doctrine.orm.entity_manager'", ")", "->", "getRepository", "(", "'OrkestroLocaleBundle:Locale'", ")", ")", ",", "$", "entity", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'orkestro_backend_country_create'", ")", ",", "'method'", "=>", "'POST'", ",", ")", ")", ";", "$", "form", "->", "add", "(", "'submit'", ",", "'submit'", ",", "array", "(", "'label'", "=>", "'Create'", ")", ")", ";", "return", "$", "form", ";", "}" ]
Creates a form to create a Country entity. @param Country $entity The entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "create", "a", "Country", "entity", "." ]
fa4989b489791f156938062a0f197e10dc0b42ed
https://github.com/Orkestro/CountryBundle/blob/fa4989b489791f156938062a0f197e10dc0b42ed/Controller/Backend/CountryController.php#L74-L84
train
Orkestro/CountryBundle
Controller/Backend/CountryController.php
CountryController.newAction
public function newAction() { $entity = new Country(); $form = $this->createCreateForm($entity); return array( 'entity' => $entity, 'form' => $form->createView(), ); }
php
public function newAction() { $entity = new Country(); $form = $this->createCreateForm($entity); return array( 'entity' => $entity, 'form' => $form->createView(), ); }
[ "public", "function", "newAction", "(", ")", "{", "$", "entity", "=", "new", "Country", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createCreateForm", "(", "$", "entity", ")", ";", "return", "array", "(", "'entity'", "=>", "$", "entity", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Displays a form to create a new Country entity. @Route("/new", name="orkestro_backend_country_new") @Method("GET") @Template()
[ "Displays", "a", "form", "to", "create", "a", "new", "Country", "entity", "." ]
fa4989b489791f156938062a0f197e10dc0b42ed
https://github.com/Orkestro/CountryBundle/blob/fa4989b489791f156938062a0f197e10dc0b42ed/Controller/Backend/CountryController.php#L93-L102
train
Orkestro/CountryBundle
Controller/Backend/CountryController.php
CountryController.showAction
public function showAction($iso_code) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('OrkestroCountryBundle:Country')->findOneBy(array( 'isoCode' => $iso_code, )); if (!$entity) { throw $this->createNotFoundException('Unable to find Country entity.'); } $deleteForm = $this->createDeleteForm($iso_code); return array( 'entity' => $entity, 'delete_form' => $deleteForm->createView(), ); }
php
public function showAction($iso_code) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('OrkestroCountryBundle:Country')->findOneBy(array( 'isoCode' => $iso_code, )); if (!$entity) { throw $this->createNotFoundException('Unable to find Country entity.'); } $deleteForm = $this->createDeleteForm($iso_code); return array( 'entity' => $entity, 'delete_form' => $deleteForm->createView(), ); }
[ "public", "function", "showAction", "(", "$", "iso_code", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "entity", "=", "$", "em", "->", "getRepository", "(", "'OrkestroCountryBundle:Country'", ")", "->", "findOneBy", "(", "array", "(", "'isoCode'", "=>", "$", "iso_code", ",", ")", ")", ";", "if", "(", "!", "$", "entity", ")", "{", "throw", "$", "this", "->", "createNotFoundException", "(", "'Unable to find Country entity.'", ")", ";", "}", "$", "deleteForm", "=", "$", "this", "->", "createDeleteForm", "(", "$", "iso_code", ")", ";", "return", "array", "(", "'entity'", "=>", "$", "entity", ",", "'delete_form'", "=>", "$", "deleteForm", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Finds and displays a Country entity. @Route("/{iso_code}", name="orkestro_backend_country_show") @Method("GET") @Template()
[ "Finds", "and", "displays", "a", "Country", "entity", "." ]
fa4989b489791f156938062a0f197e10dc0b42ed
https://github.com/Orkestro/CountryBundle/blob/fa4989b489791f156938062a0f197e10dc0b42ed/Controller/Backend/CountryController.php#L111-L129
train
Orkestro/CountryBundle
Controller/Backend/CountryController.php
CountryController.editAction
public function editAction($iso_code) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('OrkestroCountryBundle:Country')->findOneBy(array( 'isoCode' => $iso_code, )); if (!$entity) { throw $this->createNotFoundException('Unable to find Country entity.'); } $editForm = $this->createEditForm($entity); $deleteForm = $this->createDeleteForm($iso_code); return array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), ); }
php
public function editAction($iso_code) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('OrkestroCountryBundle:Country')->findOneBy(array( 'isoCode' => $iso_code, )); if (!$entity) { throw $this->createNotFoundException('Unable to find Country entity.'); } $editForm = $this->createEditForm($entity); $deleteForm = $this->createDeleteForm($iso_code); return array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), ); }
[ "public", "function", "editAction", "(", "$", "iso_code", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "entity", "=", "$", "em", "->", "getRepository", "(", "'OrkestroCountryBundle:Country'", ")", "->", "findOneBy", "(", "array", "(", "'isoCode'", "=>", "$", "iso_code", ",", ")", ")", ";", "if", "(", "!", "$", "entity", ")", "{", "throw", "$", "this", "->", "createNotFoundException", "(", "'Unable to find Country entity.'", ")", ";", "}", "$", "editForm", "=", "$", "this", "->", "createEditForm", "(", "$", "entity", ")", ";", "$", "deleteForm", "=", "$", "this", "->", "createDeleteForm", "(", "$", "iso_code", ")", ";", "return", "array", "(", "'entity'", "=>", "$", "entity", ",", "'edit_form'", "=>", "$", "editForm", "->", "createView", "(", ")", ",", "'delete_form'", "=>", "$", "deleteForm", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Displays a form to edit an existing Country entity. @Route("/{iso_code}/edit", name="orkestro_backend_country_edit") @Method("GET") @Template()
[ "Displays", "a", "form", "to", "edit", "an", "existing", "Country", "entity", "." ]
fa4989b489791f156938062a0f197e10dc0b42ed
https://github.com/Orkestro/CountryBundle/blob/fa4989b489791f156938062a0f197e10dc0b42ed/Controller/Backend/CountryController.php#L138-L158
train
Orkestro/CountryBundle
Controller/Backend/CountryController.php
CountryController.createEditForm
private function createEditForm(Country $entity) { $form = $this->createForm(new CountryType($this->get('doctrine.orm.entity_manager')->getRepository('OrkestroLocaleBundle:Locale')), $entity, array( 'action' => $this->generateUrl('orkestro_backend_country_update', array('iso_code' => $entity->getIsoCode())), 'method' => 'PUT', )); $form->add('submit', 'submit', array('label' => 'Update')); return $form; }
php
private function createEditForm(Country $entity) { $form = $this->createForm(new CountryType($this->get('doctrine.orm.entity_manager')->getRepository('OrkestroLocaleBundle:Locale')), $entity, array( 'action' => $this->generateUrl('orkestro_backend_country_update', array('iso_code' => $entity->getIsoCode())), 'method' => 'PUT', )); $form->add('submit', 'submit', array('label' => 'Update')); return $form; }
[ "private", "function", "createEditForm", "(", "Country", "$", "entity", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "new", "CountryType", "(", "$", "this", "->", "get", "(", "'doctrine.orm.entity_manager'", ")", "->", "getRepository", "(", "'OrkestroLocaleBundle:Locale'", ")", ")", ",", "$", "entity", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'orkestro_backend_country_update'", ",", "array", "(", "'iso_code'", "=>", "$", "entity", "->", "getIsoCode", "(", ")", ")", ")", ",", "'method'", "=>", "'PUT'", ",", ")", ")", ";", "$", "form", "->", "add", "(", "'submit'", ",", "'submit'", ",", "array", "(", "'label'", "=>", "'Update'", ")", ")", ";", "return", "$", "form", ";", "}" ]
Creates a form to edit a Country entity. @param Country $entity The entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "edit", "a", "Country", "entity", "." ]
fa4989b489791f156938062a0f197e10dc0b42ed
https://github.com/Orkestro/CountryBundle/blob/fa4989b489791f156938062a0f197e10dc0b42ed/Controller/Backend/CountryController.php#L167-L177
train
Orkestro/CountryBundle
Controller/Backend/CountryController.php
CountryController.createDeleteForm
private function createDeleteForm($iso_code) { return $this->createFormBuilder() ->setAction($this->generateUrl('orkestro_backend_country_delete', array('iso_code' => $iso_code))) ->setMethod('DELETE') ->add('submit', 'submit', array('label' => 'Delete')) ->getForm() ; }
php
private function createDeleteForm($iso_code) { return $this->createFormBuilder() ->setAction($this->generateUrl('orkestro_backend_country_delete', array('iso_code' => $iso_code))) ->setMethod('DELETE') ->add('submit', 'submit', array('label' => 'Delete')) ->getForm() ; }
[ "private", "function", "createDeleteForm", "(", "$", "iso_code", ")", "{", "return", "$", "this", "->", "createFormBuilder", "(", ")", "->", "setAction", "(", "$", "this", "->", "generateUrl", "(", "'orkestro_backend_country_delete'", ",", "array", "(", "'iso_code'", "=>", "$", "iso_code", ")", ")", ")", "->", "setMethod", "(", "'DELETE'", ")", "->", "add", "(", "'submit'", ",", "'submit'", ",", "array", "(", "'label'", "=>", "'Delete'", ")", ")", "->", "getForm", "(", ")", ";", "}" ]
Creates a form to delete a Country entity by iso code. @param mixed $iso_code The entity iso code @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "delete", "a", "Country", "entity", "by", "iso", "code", "." ]
fa4989b489791f156938062a0f197e10dc0b42ed
https://github.com/Orkestro/CountryBundle/blob/fa4989b489791f156938062a0f197e10dc0b42ed/Controller/Backend/CountryController.php#L250-L258
train
Dhii/exception-helper-base
src/CreateOutOfBoundsExceptionCapableTrait.php
CreateOutOfBoundsExceptionCapableTrait._createOutOfBoundsException
protected function _createOutOfBoundsException( $message = null, $code = null, RootException $previous = null, $argument = null ) { return new OutOfBoundsException($message, $code, $previous, $argument); }
php
protected function _createOutOfBoundsException( $message = null, $code = null, RootException $previous = null, $argument = null ) { return new OutOfBoundsException($message, $code, $previous, $argument); }
[ "protected", "function", "_createOutOfBoundsException", "(", "$", "message", "=", "null", ",", "$", "code", "=", "null", ",", "RootException", "$", "previous", "=", "null", ",", "$", "argument", "=", "null", ")", "{", "return", "new", "OutOfBoundsException", "(", "$", "message", ",", "$", "code", ",", "$", "previous", ",", "$", "argument", ")", ";", "}" ]
Creates a new Dhii Out Of Bounds exception. @since [*next-version*] @param string|Stringable|int|float|bool|null $message The message, if any. @param int|float|string|Stringable|null $code The numeric error code, if any. @param RootException|null $previous The inner exception, if any. @param mixed|null $argument The value that is out of bounds, if any. @return OutOfBoundsException The new exception.
[ "Creates", "a", "new", "Dhii", "Out", "Of", "Bounds", "exception", "." ]
e97bfa6c0f79ea079e36b2f1d8f84d7566a3ccf5
https://github.com/Dhii/exception-helper-base/blob/e97bfa6c0f79ea079e36b2f1d8f84d7566a3ccf5/src/CreateOutOfBoundsExceptionCapableTrait.php#L27-L34
train
modulusphp/support
Arr.php
Arr.replace_key
public static function replace_key(array $array, $oldKey, $newKey) : array { $newArray = array(); foreach ($array as $key => $value) { if ($key == $oldKey) { $newArray = array_merge($newArray, [$newKey => $value]); } else { $newArray = array_merge($newArray, [$key => $value]); } } return $newArray; }
php
public static function replace_key(array $array, $oldKey, $newKey) : array { $newArray = array(); foreach ($array as $key => $value) { if ($key == $oldKey) { $newArray = array_merge($newArray, [$newKey => $value]); } else { $newArray = array_merge($newArray, [$key => $value]); } } return $newArray; }
[ "public", "static", "function", "replace_key", "(", "array", "$", "array", ",", "$", "oldKey", ",", "$", "newKey", ")", ":", "array", "{", "$", "newArray", "=", "array", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "==", "$", "oldKey", ")", "{", "$", "newArray", "=", "array_merge", "(", "$", "newArray", ",", "[", "$", "newKey", "=>", "$", "value", "]", ")", ";", "}", "else", "{", "$", "newArray", "=", "array_merge", "(", "$", "newArray", ",", "[", "$", "key", "=>", "$", "value", "]", ")", ";", "}", "}", "return", "$", "newArray", ";", "}" ]
Replace array key @param array $array @param mixed $oldKey @param mixed $newKey @return array $newArray
[ "Replace", "array", "key" ]
b5c5b48dcbeb379e6cd1f29159dc8cdacef3adab
https://github.com/modulusphp/support/blob/b5c5b48dcbeb379e6cd1f29159dc8cdacef3adab/Arr.php#L31-L44
train
SlaxWeb/Router
src/Route.php
Route.set
public function set(string $uri, int $method, callable $action, bool $default = false): self { if ((self::METHOD_ANY & $method) !== $method) { throw new Exception\InvalidMethodException( "Route does not contain a valid HTTP Method." ); } $this->uri = "~"; foreach (explode("|", $uri) as $uri) { $uri = trim($uri, "^$"); // add /? to every uri that does not already end with a /<quaantifier> $this->uri .= "^" . preg_replace("~/$|(?:(?<!/)[+*?]|[^+*?])\K$~", "/?", $uri) . "$|"; } $this->uri = rtrim($this->uri, "|") . "~"; $this->method = $method; $this->action = $action; $this->isDefault = $default; return $this; }
php
public function set(string $uri, int $method, callable $action, bool $default = false): self { if ((self::METHOD_ANY & $method) !== $method) { throw new Exception\InvalidMethodException( "Route does not contain a valid HTTP Method." ); } $this->uri = "~"; foreach (explode("|", $uri) as $uri) { $uri = trim($uri, "^$"); // add /? to every uri that does not already end with a /<quaantifier> $this->uri .= "^" . preg_replace("~/$|(?:(?<!/)[+*?]|[^+*?])\K$~", "/?", $uri) . "$|"; } $this->uri = rtrim($this->uri, "|") . "~"; $this->method = $method; $this->action = $action; $this->isDefault = $default; return $this; }
[ "public", "function", "set", "(", "string", "$", "uri", ",", "int", "$", "method", ",", "callable", "$", "action", ",", "bool", "$", "default", "=", "false", ")", ":", "self", "{", "if", "(", "(", "self", "::", "METHOD_ANY", "&", "$", "method", ")", "!==", "$", "method", ")", "{", "throw", "new", "Exception", "\\", "InvalidMethodException", "(", "\"Route does not contain a valid HTTP Method.\"", ")", ";", "}", "$", "this", "->", "uri", "=", "\"~\"", ";", "foreach", "(", "explode", "(", "\"|\"", ",", "$", "uri", ")", "as", "$", "uri", ")", "{", "$", "uri", "=", "trim", "(", "$", "uri", ",", "\"^$\"", ")", ";", "// add /? to every uri that does not already end with a /<quaantifier>", "$", "this", "->", "uri", ".=", "\"^\"", ".", "preg_replace", "(", "\"~/$|(?:(?<!/)[+*?]|[^+*?])\\K$~\"", ",", "\"/?\"", ",", "$", "uri", ")", ".", "\"$|\"", ";", "}", "$", "this", "->", "uri", "=", "rtrim", "(", "$", "this", "->", "uri", ",", "\"|\"", ")", ".", "\"~\"", ";", "$", "this", "->", "method", "=", "$", "method", ";", "$", "this", "->", "action", "=", "$", "action", ";", "$", "this", "->", "isDefault", "=", "$", "default", ";", "return", "$", "this", ";", "}" ]
Set Route data Sets the retrieved data to internal properties. Prior to setting, the method is checked, that it is valid, and raises an 'InvalidMethodException' on error. @param string $uri Request URI regex without delimiter @param int $method HTTP Request Method, accepts METHODO_* constant @param callable $action Route action @param bool $default Should the route be marked as default. Default bool(false) @return self
[ "Set", "Route", "data" ]
b4a25655710638c71787a8498d267a663ef2e819
https://github.com/SlaxWeb/Router/blob/b4a25655710638c71787a8498d267a663ef2e819/src/Route.php#L128-L148
train
SlaxWeb/Router
src/Route.php
Route.set404Route
public function set404Route(callable $action): self { $this->uri = "404RouteNotFound"; $this->method = self::METHOD_ANY; $this->action = $action; $this->is404 = true; return $this; }
php
public function set404Route(callable $action): self { $this->uri = "404RouteNotFound"; $this->method = self::METHOD_ANY; $this->action = $action; $this->is404 = true; return $this; }
[ "public", "function", "set404Route", "(", "callable", "$", "action", ")", ":", "self", "{", "$", "this", "->", "uri", "=", "\"404RouteNotFound\"", ";", "$", "this", "->", "method", "=", "self", "::", "METHOD_ANY", ";", "$", "this", "->", "action", "=", "$", "action", ";", "$", "this", "->", "is404", "=", "true", ";", "return", "$", "this", ";", "}" ]
Set 404 Route Sets the '404NoRouteFound' Route to its properties. This Route is used by the Dispatcher if it can not find a matching Route for its Request. @param callable $action Route action @return self
[ "Set", "404", "Route" ]
b4a25655710638c71787a8498d267a663ef2e819
https://github.com/SlaxWeb/Router/blob/b4a25655710638c71787a8498d267a663ef2e819/src/Route.php#L159-L167
train
codeblanche/Entity
src/Entity/Marshal/Typed.php
Typed.iterate
protected function iterate($value, PropertyDefinitionInterface $definition = null) { if (empty($value) || !is_array($value)) { return $value; } $type = $definition->getGenericType(); foreach ($value as $key => $item) { if (is_null($item)) { continue; } $value[$key] = $this->castValue($item, $type); } return $value; }
php
protected function iterate($value, PropertyDefinitionInterface $definition = null) { if (empty($value) || !is_array($value)) { return $value; } $type = $definition->getGenericType(); foreach ($value as $key => $item) { if (is_null($item)) { continue; } $value[$key] = $this->castValue($item, $type); } return $value; }
[ "protected", "function", "iterate", "(", "$", "value", ",", "PropertyDefinitionInterface", "$", "definition", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "value", ")", "||", "!", "is_array", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "$", "type", "=", "$", "definition", "->", "getGenericType", "(", ")", ";", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "is_null", "(", "$", "item", ")", ")", "{", "continue", ";", "}", "$", "value", "[", "$", "key", "]", "=", "$", "this", "->", "castValue", "(", "$", "item", ",", "$", "type", ")", ";", "}", "return", "$", "value", ";", "}" ]
Attempte to iterate the value and cast all child items to the require generic type. @param $value @param PropertyDefinitionInterface $definition @return array
[ "Attempte", "to", "iterate", "the", "value", "and", "cast", "all", "child", "items", "to", "the", "require", "generic", "type", "." ]
1d3839c09d7639ae8bbfc9d2721223202f3a5cdd
https://github.com/codeblanche/Entity/blob/1d3839c09d7639ae8bbfc9d2721223202f3a5cdd/src/Entity/Marshal/Typed.php#L106-L123
train
codeblanche/Entity
src/Entity/Marshal/Typed.php
Typed.castValue
protected function castValue($value, $type) { if (isset($this->scalarMap[$type])) { $cast = $this->castToScalar($value, $this->scalarMap[$type]); return $cast == $value ? $cast : $value; } if (is_null($value)) { return null; } if (!is_array($value) && $type === 'array') { return (array) $value; } if (!is_object($value) && $type === 'object') { return (object) $value; } return $this->castToClass($value, $this->resolveNamespace($type)); }
php
protected function castValue($value, $type) { if (isset($this->scalarMap[$type])) { $cast = $this->castToScalar($value, $this->scalarMap[$type]); return $cast == $value ? $cast : $value; } if (is_null($value)) { return null; } if (!is_array($value) && $type === 'array') { return (array) $value; } if (!is_object($value) && $type === 'object') { return (object) $value; } return $this->castToClass($value, $this->resolveNamespace($type)); }
[ "protected", "function", "castValue", "(", "$", "value", ",", "$", "type", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "scalarMap", "[", "$", "type", "]", ")", ")", "{", "$", "cast", "=", "$", "this", "->", "castToScalar", "(", "$", "value", ",", "$", "this", "->", "scalarMap", "[", "$", "type", "]", ")", ";", "return", "$", "cast", "==", "$", "value", "?", "$", "cast", ":", "$", "value", ";", "}", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "is_array", "(", "$", "value", ")", "&&", "$", "type", "===", "'array'", ")", "{", "return", "(", "array", ")", "$", "value", ";", "}", "if", "(", "!", "is_object", "(", "$", "value", ")", "&&", "$", "type", "===", "'object'", ")", "{", "return", "(", "object", ")", "$", "value", ";", "}", "return", "$", "this", "->", "castToClass", "(", "$", "value", ",", "$", "this", "->", "resolveNamespace", "(", "$", "type", ")", ")", ";", "}" ]
Cast a value to the desired type non-destructively. @param mixed $value @param string $type @return mixed Cast value
[ "Cast", "a", "value", "to", "the", "desired", "type", "non", "-", "destructively", "." ]
1d3839c09d7639ae8bbfc9d2721223202f3a5cdd
https://github.com/codeblanche/Entity/blob/1d3839c09d7639ae8bbfc9d2721223202f3a5cdd/src/Entity/Marshal/Typed.php#L133-L154
train
codeblanche/Entity
src/Entity/Marshal/Typed.php
Typed.castToScalar
protected function castToScalar($value, $type) { if ($type === 'integer') { return (integer) $value; } if ($type === 'boolean') { return (boolean) $value; } if ($type === 'float') { return (float) $value; } if ($type === 'string') { return (string) $value; } return $value; }
php
protected function castToScalar($value, $type) { if ($type === 'integer') { return (integer) $value; } if ($type === 'boolean') { return (boolean) $value; } if ($type === 'float') { return (float) $value; } if ($type === 'string') { return (string) $value; } return $value; }
[ "protected", "function", "castToScalar", "(", "$", "value", ",", "$", "type", ")", "{", "if", "(", "$", "type", "===", "'integer'", ")", "{", "return", "(", "integer", ")", "$", "value", ";", "}", "if", "(", "$", "type", "===", "'boolean'", ")", "{", "return", "(", "boolean", ")", "$", "value", ";", "}", "if", "(", "$", "type", "===", "'float'", ")", "{", "return", "(", "float", ")", "$", "value", ";", "}", "if", "(", "$", "type", "===", "'string'", ")", "{", "return", "(", "string", ")", "$", "value", ";", "}", "return", "$", "value", ";", "}" ]
Cast a value to the desired scalar type. Value remains unchanged if type is not scalar. @param mixed $value The value you went to cast @param string $type The type you want to cast to @return mixed
[ "Cast", "a", "value", "to", "the", "desired", "scalar", "type", ".", "Value", "remains", "unchanged", "if", "type", "is", "not", "scalar", "." ]
1d3839c09d7639ae8bbfc9d2721223202f3a5cdd
https://github.com/codeblanche/Entity/blob/1d3839c09d7639ae8bbfc9d2721223202f3a5cdd/src/Entity/Marshal/Typed.php#L164-L180
train
TiMESPLiNTER/tsFramework
src/ch/timesplinter/core/PluginManager.php
PluginManager.loadPlugins
public function loadPlugins($plugins) { foreach($plugins as $plugin) { $pluginClass = str_replace(':','\\',$plugin); $this->plugins[] = new $pluginClass($this->core); } }
php
public function loadPlugins($plugins) { foreach($plugins as $plugin) { $pluginClass = str_replace(':','\\',$plugin); $this->plugins[] = new $pluginClass($this->core); } }
[ "public", "function", "loadPlugins", "(", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "plugin", ")", "{", "$", "pluginClass", "=", "str_replace", "(", "':'", ",", "'\\\\'", ",", "$", "plugin", ")", ";", "$", "this", "->", "plugins", "[", "]", "=", "new", "$", "pluginClass", "(", "$", "this", "->", "core", ")", ";", "}", "}" ]
Load all plugins from an array @param array $plugins The array containing the plugins to load
[ "Load", "all", "plugins", "from", "an", "array" ]
b3b9fd98f6d456a9e571015877ecca203786fd0c
https://github.com/TiMESPLiNTER/tsFramework/blob/b3b9fd98f6d456a9e571015877ecca203786fd0c/src/ch/timesplinter/core/PluginManager.php#L28-L35
train
TiMESPLiNTER/tsFramework
src/ch/timesplinter/core/PluginManager.php
PluginManager.invokePluginHook
public function invokePluginHook($hookName) { $args = func_get_args(); array_shift($args); foreach($this->plugins as $plugin) { if(method_exists($plugin, $hookName) === false) continue; call_user_func_array(array($plugin, $hookName), $args); } }
php
public function invokePluginHook($hookName) { $args = func_get_args(); array_shift($args); foreach($this->plugins as $plugin) { if(method_exists($plugin, $hookName) === false) continue; call_user_func_array(array($plugin, $hookName), $args); } }
[ "public", "function", "invokePluginHook", "(", "$", "hookName", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "array_shift", "(", "$", "args", ")", ";", "foreach", "(", "$", "this", "->", "plugins", "as", "$", "plugin", ")", "{", "if", "(", "method_exists", "(", "$", "plugin", ",", "$", "hookName", ")", "===", "false", ")", "continue", ";", "call_user_func_array", "(", "array", "(", "$", "plugin", ",", "$", "hookName", ")", ",", "$", "args", ")", ";", "}", "}" ]
Invokes a specific plugin hook @param string $hookName The name of the hook to invoke @param mixed $parameter,... Parameters for the hook
[ "Invokes", "a", "specific", "plugin", "hook" ]
b3b9fd98f6d456a9e571015877ecca203786fd0c
https://github.com/TiMESPLiNTER/tsFramework/blob/b3b9fd98f6d456a9e571015877ecca203786fd0c/src/ch/timesplinter/core/PluginManager.php#L43-L54
train
Linkvalue-Interne/MajoraFrameworkExtraBundle
src/Majora/Framework/Model/LazyPropertiesTrait.php
LazyPropertiesTrait.load
protected function load($field) { if (!is_null($this->$field) || !$this->delegatesCollection || !$this->delegatesCollection->containsKey($key = strtolower($field)) ) { return $this->$field; } $loader = $this->delegatesCollection->get($key); $this->delegatesCollection->remove($key); return $this->$field = $loader($this); }
php
protected function load($field) { if (!is_null($this->$field) || !$this->delegatesCollection || !$this->delegatesCollection->containsKey($key = strtolower($field)) ) { return $this->$field; } $loader = $this->delegatesCollection->get($key); $this->delegatesCollection->remove($key); return $this->$field = $loader($this); }
[ "protected", "function", "load", "(", "$", "field", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "$", "field", ")", "||", "!", "$", "this", "->", "delegatesCollection", "||", "!", "$", "this", "->", "delegatesCollection", "->", "containsKey", "(", "$", "key", "=", "strtolower", "(", "$", "field", ")", ")", ")", "{", "return", "$", "this", "->", "$", "field", ";", "}", "$", "loader", "=", "$", "this", "->", "delegatesCollection", "->", "get", "(", "$", "key", ")", ";", "$", "this", "->", "delegatesCollection", "->", "remove", "(", "$", "key", ")", ";", "return", "$", "this", "->", "$", "field", "=", "$", "loader", "(", "$", "this", ")", ";", "}" ]
Load given field if able to, define his value and return it. @example public function getRelatedEntity() { return $this->load('relatedEntity'); } @param string $field @return mixed|null field value if retrieved
[ "Load", "given", "field", "if", "able", "to", "define", "his", "value", "and", "return", "it", "." ]
6f368380cfc39d27fafb0844e9a53b4d86d7c034
https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Model/LazyPropertiesTrait.php#L50-L63
train
eureka-framework/component-controller
src/Controller/Controller.php
Controller.setMetas
protected function setMetas($title = null, $description = null) { $meta = Config::getInstance()->get('Eureka\Global\Meta'); if ($title !== null) { $meta['title'] = strip_tags($title . ' - ' . $meta['title']); } if ($description !== null) { $meta['description'] = strip_tags($description); } Config::getInstance()->add('Eureka\Global\Meta', $meta); return $this; }
php
protected function setMetas($title = null, $description = null) { $meta = Config::getInstance()->get('Eureka\Global\Meta'); if ($title !== null) { $meta['title'] = strip_tags($title . ' - ' . $meta['title']); } if ($description !== null) { $meta['description'] = strip_tags($description); } Config::getInstance()->add('Eureka\Global\Meta', $meta); return $this; }
[ "protected", "function", "setMetas", "(", "$", "title", "=", "null", ",", "$", "description", "=", "null", ")", "{", "$", "meta", "=", "Config", "::", "getInstance", "(", ")", "->", "get", "(", "'Eureka\\Global\\Meta'", ")", ";", "if", "(", "$", "title", "!==", "null", ")", "{", "$", "meta", "[", "'title'", "]", "=", "strip_tags", "(", "$", "title", ".", "' - '", ".", "$", "meta", "[", "'title'", "]", ")", ";", "}", "if", "(", "$", "description", "!==", "null", ")", "{", "$", "meta", "[", "'description'", "]", "=", "strip_tags", "(", "$", "description", ")", ";", "}", "Config", "::", "getInstance", "(", ")", "->", "add", "(", "'Eureka\\Global\\Meta'", ",", "$", "meta", ")", ";", "return", "$", "this", ";", "}" ]
Override meta description with given description. @param string $description @return $this
[ "Override", "meta", "description", "with", "given", "description", "." ]
368efb6fb9eece4f7f69233e6190e1fdbb0ace2c
https://github.com/eureka-framework/component-controller/blob/368efb6fb9eece4f7f69233e6190e1fdbb0ace2c/src/Controller/Controller.php#L207-L222
train
stubbles/stubbles-peer
src/main/php/http/Http.php
Http.statusClassFor
public static function statusClassFor(int $statusCode): string { $class = substr((string) $statusCode, 0, 1); return self::$statusClass[$class] ?? self::STATUS_CLASS_UNKNOWN; }
php
public static function statusClassFor(int $statusCode): string { $class = substr((string) $statusCode, 0, 1); return self::$statusClass[$class] ?? self::STATUS_CLASS_UNKNOWN; }
[ "public", "static", "function", "statusClassFor", "(", "int", "$", "statusCode", ")", ":", "string", "{", "$", "class", "=", "substr", "(", "(", "string", ")", "$", "statusCode", ",", "0", ",", "1", ")", ";", "return", "self", "::", "$", "statusClass", "[", "$", "class", "]", "??", "self", "::", "STATUS_CLASS_UNKNOWN", ";", "}" ]
returns status class for given status code Returns null if given status code is empty. @api @param int $statusCode @return string @since 4.0.0
[ "returns", "status", "class", "for", "given", "status", "code" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/Http.php#L191-L195
train
stubbles/stubbles-peer
src/main/php/http/Http.php
Http.reasonPhraseFor
public static function reasonPhraseFor(int $statusCode): string { if (isset(self::$reasonPhrases[$statusCode])) { return self::$reasonPhrases[$statusCode]; } throw new \InvalidArgumentException( 'Invalid or unknown HTTP status code ' . $statusCode ); }
php
public static function reasonPhraseFor(int $statusCode): string { if (isset(self::$reasonPhrases[$statusCode])) { return self::$reasonPhrases[$statusCode]; } throw new \InvalidArgumentException( 'Invalid or unknown HTTP status code ' . $statusCode ); }
[ "public", "static", "function", "reasonPhraseFor", "(", "int", "$", "statusCode", ")", ":", "string", "{", "if", "(", "isset", "(", "self", "::", "$", "reasonPhrases", "[", "$", "statusCode", "]", ")", ")", "{", "return", "self", "::", "$", "reasonPhrases", "[", "$", "statusCode", "]", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid or unknown HTTP status code '", ".", "$", "statusCode", ")", ";", "}" ]
returns reason phrase for given status code @api @param int $statusCode @return string @throws \InvalidArgumentException @since 4.0.0
[ "returns", "reason", "phrase", "for", "given", "status", "code" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/Http.php#L218-L227
train
stubbles/stubbles-peer
src/main/php/http/Http.php
Http.lines
public static function lines(string ...$lines): string { $head = true; return join( '', array_map( function($line) use (&$head) { if (empty($line) && $head) { $head = false; return self::emptyLine(); } if ($head) { return self::line($line); } return $line; }, $lines ) ); }
php
public static function lines(string ...$lines): string { $head = true; return join( '', array_map( function($line) use (&$head) { if (empty($line) && $head) { $head = false; return self::emptyLine(); } if ($head) { return self::line($line); } return $line; }, $lines ) ); }
[ "public", "static", "function", "lines", "(", "string", "...", "$", "lines", ")", ":", "string", "{", "$", "head", "=", "true", ";", "return", "join", "(", "''", ",", "array_map", "(", "function", "(", "$", "line", ")", "use", "(", "&", "$", "head", ")", "{", "if", "(", "empty", "(", "$", "line", ")", "&&", "$", "head", ")", "{", "$", "head", "=", "false", ";", "return", "self", "::", "emptyLine", "(", ")", ";", "}", "if", "(", "$", "head", ")", "{", "return", "self", "::", "line", "(", "$", "line", ")", ";", "}", "return", "$", "line", ";", "}", ",", "$", "lines", ")", ")", ";", "}" ]
creates valid http lines from given input lines If the array contains an empty line all lines after this empty line are considered to belong to the body and will be returned as they are. @param string[] $lines @return string @since 4.0.0
[ "creates", "valid", "http", "lines", "from", "given", "input", "lines" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/Http.php#L250-L272
train
stubbles/stubbles-peer
src/main/php/http/Http.php
Http.isValidRfc
public static function isValidRfc(string $rfc): bool { return in_array($rfc, [self::RFC_2616, self::RFC_7230]); }
php
public static function isValidRfc(string $rfc): bool { return in_array($rfc, [self::RFC_2616, self::RFC_7230]); }
[ "public", "static", "function", "isValidRfc", "(", "string", "$", "rfc", ")", ":", "bool", "{", "return", "in_array", "(", "$", "rfc", ",", "[", "self", "::", "RFC_2616", ",", "self", "::", "RFC_7230", "]", ")", ";", "}" ]
checks if given RFC is a valid and known RFC @param string $rfc @return bool
[ "checks", "if", "given", "RFC", "is", "a", "valid", "and", "known", "RFC" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/Http.php#L290-L293
train
wb-crowdfusion/crowdfusion
system/core/classes/nodedb/model/Node.php
Node.toModel
public function toModel() { $nodeClass = $this->getElement()->NodeClass; if ($nodeClass === 'Node') { throw new LogicException('You must set a custom node in <node_class/> for element: ' . $this->getElement()->getSlug()); } else { throw new LogicException('You must create a toModel method in: ' . $nodeClass); } }
php
public function toModel() { $nodeClass = $this->getElement()->NodeClass; if ($nodeClass === 'Node') { throw new LogicException('You must set a custom node in <node_class/> for element: ' . $this->getElement()->getSlug()); } else { throw new LogicException('You must create a toModel method in: ' . $nodeClass); } }
[ "public", "function", "toModel", "(", ")", "{", "$", "nodeClass", "=", "$", "this", "->", "getElement", "(", ")", "->", "NodeClass", ";", "if", "(", "$", "nodeClass", "===", "'Node'", ")", "{", "throw", "new", "LogicException", "(", "'You must set a custom node in <node_class/> for element: '", ".", "$", "this", "->", "getElement", "(", ")", "->", "getSlug", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "LogicException", "(", "'You must create a toModel method in: '", ".", "$", "nodeClass", ")", ";", "}", "}" ]
You must implement a toModel method in a subclass of Node, defined in a plugin.xml or system.xml in order to have toModel functionality. @return mixed @throws LogicException
[ "You", "must", "implement", "a", "toModel", "method", "in", "a", "subclass", "of", "Node", "defined", "in", "a", "plugin", ".", "xml", "or", "system", ".", "xml", "in", "order", "to", "have", "toModel", "functionality", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/model/Node.php#L71-L79
train
wb-crowdfusion/crowdfusion
system/core/classes/nodedb/model/Node.php
Node.setNodeRef
public function setNodeRef($newNodeRef) { $this->fields['NodeRef'] = $newNodeRef; $this->fields['Slug'] = $newNodeRef->isFullyQualified()?$newNodeRef->getSlug():''; }
php
public function setNodeRef($newNodeRef) { $this->fields['NodeRef'] = $newNodeRef; $this->fields['Slug'] = $newNodeRef->isFullyQualified()?$newNodeRef->getSlug():''; }
[ "public", "function", "setNodeRef", "(", "$", "newNodeRef", ")", "{", "$", "this", "->", "fields", "[", "'NodeRef'", "]", "=", "$", "newNodeRef", ";", "$", "this", "->", "fields", "[", "'Slug'", "]", "=", "$", "newNodeRef", "->", "isFullyQualified", "(", ")", "?", "$", "newNodeRef", "->", "getSlug", "(", ")", ":", "''", ";", "}" ]
Changes our NodeRef @param NodeRef $newNodeRef
[ "Changes", "our", "NodeRef" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/model/Node.php#L96-L100
train
wb-crowdfusion/crowdfusion
system/core/classes/nodedb/model/Node.php
Node.setSlug
public function setSlug($slug) { if(empty($this->fields['Slug']) || empty($this->fields['OriginalSlug'])) { $this->fields['NodeRef'] = new NodeRef($this->getNodeRef()->getElement(), $slug); } $this->fields['Slug'] = $slug; }
php
public function setSlug($slug) { if(empty($this->fields['Slug']) || empty($this->fields['OriginalSlug'])) { $this->fields['NodeRef'] = new NodeRef($this->getNodeRef()->getElement(), $slug); } $this->fields['Slug'] = $slug; }
[ "public", "function", "setSlug", "(", "$", "slug", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "fields", "[", "'Slug'", "]", ")", "||", "empty", "(", "$", "this", "->", "fields", "[", "'OriginalSlug'", "]", ")", ")", "{", "$", "this", "->", "fields", "[", "'NodeRef'", "]", "=", "new", "NodeRef", "(", "$", "this", "->", "getNodeRef", "(", ")", "->", "getElement", "(", ")", ",", "$", "slug", ")", ";", "}", "$", "this", "->", "fields", "[", "'Slug'", "]", "=", "$", "slug", ";", "}" ]
Sets the Slug @param string $slug A valid @return void
[ "Sets", "the", "Slug" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/model/Node.php#L177-L185
train
wb-crowdfusion/crowdfusion
system/core/classes/nodedb/model/Node.php
Node.getNodePartials
public function getNodePartials() { if(!array_key_exists('NodePartials', $this->fields) || is_null($this->fields['NodePartials'])) $this->fields['NodePartials'] = new NodePartials(); return $this->fields['NodePartials']; }
php
public function getNodePartials() { if(!array_key_exists('NodePartials', $this->fields) || is_null($this->fields['NodePartials'])) $this->fields['NodePartials'] = new NodePartials(); return $this->fields['NodePartials']; }
[ "public", "function", "getNodePartials", "(", ")", "{", "if", "(", "!", "array_key_exists", "(", "'NodePartials'", ",", "$", "this", "->", "fields", ")", "||", "is_null", "(", "$", "this", "->", "fields", "[", "'NodePartials'", "]", ")", ")", "$", "this", "->", "fields", "[", "'NodePartials'", "]", "=", "new", "NodePartials", "(", ")", ";", "return", "$", "this", "->", "fields", "[", "'NodePartials'", "]", ";", "}" ]
Returns a reference to the partials for this node. @return NodePartials
[ "Returns", "a", "reference", "to", "the", "partials", "for", "this", "node", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/model/Node.php#L555-L561
train
jenskooij/cloudcontrol
src/cc/application/UrlMatcher.php
UrlMatcher.redirectMatching
public function redirectMatching(Request $request) { $redirects = $this->storage->getRedirects()->getRedirects(); $relativeUri = '/' . $request::$relativeUri; foreach ($redirects as $redirect) { if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) { $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri); if (substr($toUrl, 0, 1) == '/') { $toUrl = substr($toUrl, 1); } if ($redirect->type == '301') { header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $request::$subfolders . $toUrl); exit; } elseif ($redirect->type == '302') { header('Location: ' . $request::$subfolders . $toUrl, true, 302); exit; } else { throw new \Exception('Invalid redirect type.'); } } } }
php
public function redirectMatching(Request $request) { $redirects = $this->storage->getRedirects()->getRedirects(); $relativeUri = '/' . $request::$relativeUri; foreach ($redirects as $redirect) { if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) { $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri); if (substr($toUrl, 0, 1) == '/') { $toUrl = substr($toUrl, 1); } if ($redirect->type == '301') { header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $request::$subfolders . $toUrl); exit; } elseif ($redirect->type == '302') { header('Location: ' . $request::$subfolders . $toUrl, true, 302); exit; } else { throw new \Exception('Invalid redirect type.'); } } } }
[ "public", "function", "redirectMatching", "(", "Request", "$", "request", ")", "{", "$", "redirects", "=", "$", "this", "->", "storage", "->", "getRedirects", "(", ")", "->", "getRedirects", "(", ")", ";", "$", "relativeUri", "=", "'/'", ".", "$", "request", "::", "$", "relativeUri", ";", "foreach", "(", "$", "redirects", "as", "$", "redirect", ")", "{", "if", "(", "preg_match_all", "(", "$", "redirect", "->", "fromUrl", ",", "$", "relativeUri", ",", "$", "matches", ")", ")", "{", "$", "toUrl", "=", "preg_replace", "(", "$", "redirect", "->", "fromUrl", ",", "$", "redirect", "->", "toUrl", ",", "$", "relativeUri", ")", ";", "if", "(", "substr", "(", "$", "toUrl", ",", "0", ",", "1", ")", "==", "'/'", ")", "{", "$", "toUrl", "=", "substr", "(", "$", "toUrl", ",", "1", ")", ";", "}", "if", "(", "$", "redirect", "->", "type", "==", "'301'", ")", "{", "header", "(", "'HTTP/1.1 301 Moved Permanently'", ")", ";", "header", "(", "'Location: '", ".", "$", "request", "::", "$", "subfolders", ".", "$", "toUrl", ")", ";", "exit", ";", "}", "elseif", "(", "$", "redirect", "->", "type", "==", "'302'", ")", "{", "header", "(", "'Location: '", ".", "$", "request", "::", "$", "subfolders", ".", "$", "toUrl", ",", "true", ",", "302", ")", ";", "exit", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "'Invalid redirect type.'", ")", ";", "}", "}", "}", "}" ]
Loop through the redirects and see if a redirect needs to take place @param Request $request @throws \Exception
[ "Loop", "through", "the", "redirects", "and", "see", "if", "a", "redirect", "needs", "to", "take", "place" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/cc/application/UrlMatcher.php#L36-L59
train
jenskooij/cloudcontrol
src/cc/application/UrlMatcher.php
UrlMatcher.sitemapMatching
public function sitemapMatching($request) { $sitemap = $this->storage->getSitemap()->getSitemap(); $relativeUri = '/' . $request::$relativeUri; foreach ($sitemap as $sitemapItem) { if ($sitemapItem->regex) { $matches = array(); if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) { // Make a clone, so it doesnt add the matches to the original $matchedClone = clone $sitemapItem; $matchedClone->matches = $matches; $this->application->addMatchedSitemapItem($matchedClone); return; } } else { if ($sitemapItem->url == $relativeUri) { $this->application->addMatchedSitemapItem($sitemapItem); return; } } } }
php
public function sitemapMatching($request) { $sitemap = $this->storage->getSitemap()->getSitemap(); $relativeUri = '/' . $request::$relativeUri; foreach ($sitemap as $sitemapItem) { if ($sitemapItem->regex) { $matches = array(); if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) { // Make a clone, so it doesnt add the matches to the original $matchedClone = clone $sitemapItem; $matchedClone->matches = $matches; $this->application->addMatchedSitemapItem($matchedClone); return; } } else { if ($sitemapItem->url == $relativeUri) { $this->application->addMatchedSitemapItem($sitemapItem); return; } } } }
[ "public", "function", "sitemapMatching", "(", "$", "request", ")", "{", "$", "sitemap", "=", "$", "this", "->", "storage", "->", "getSitemap", "(", ")", "->", "getSitemap", "(", ")", ";", "$", "relativeUri", "=", "'/'", ".", "$", "request", "::", "$", "relativeUri", ";", "foreach", "(", "$", "sitemap", "as", "$", "sitemapItem", ")", "{", "if", "(", "$", "sitemapItem", "->", "regex", ")", "{", "$", "matches", "=", "array", "(", ")", ";", "if", "(", "preg_match_all", "(", "$", "sitemapItem", "->", "url", ",", "$", "relativeUri", ",", "$", "matches", ")", ")", "{", "// Make a clone, so it doesnt add the matches to the original", "$", "matchedClone", "=", "clone", "$", "sitemapItem", ";", "$", "matchedClone", "->", "matches", "=", "$", "matches", ";", "$", "this", "->", "application", "->", "addMatchedSitemapItem", "(", "$", "matchedClone", ")", ";", "return", ";", "}", "}", "else", "{", "if", "(", "$", "sitemapItem", "->", "url", "==", "$", "relativeUri", ")", "{", "$", "this", "->", "application", "->", "addMatchedSitemapItem", "(", "$", "sitemapItem", ")", ";", "return", ";", "}", "}", "}", "}" ]
Loop through sitemap items and see if one matches the requestUri. If it does, add it tot the matchedSitemapItems array @param Request $request
[ "Loop", "through", "sitemap", "items", "and", "see", "if", "one", "matches", "the", "requestUri", ".", "If", "it", "does", "add", "it", "tot", "the", "matchedSitemapItems", "array" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/cc/application/UrlMatcher.php#L67-L89
train
SCLInternet/SclRequestResponse
src/SclRequestResponse/Communicator/PersistentCommunicator.php
PersistentCommunicator.connect
public function connect($host, $port, $secure = true) { $this->socket->setBlocking(false); if (!$this->socket->connect($host, $port, $secure)) { throw new Exception\ConnectionFailedException( sprintf( '%s failed to %s:%d with error %s (%d).', $secure ? 'Secure connection' : 'Connection', $host, $port, $this->socket->connectionError(), $this->socket->connectionErrorNo() ) ); } }
php
public function connect($host, $port, $secure = true) { $this->socket->setBlocking(false); if (!$this->socket->connect($host, $port, $secure)) { throw new Exception\ConnectionFailedException( sprintf( '%s failed to %s:%d with error %s (%d).', $secure ? 'Secure connection' : 'Connection', $host, $port, $this->socket->connectionError(), $this->socket->connectionErrorNo() ) ); } }
[ "public", "function", "connect", "(", "$", "host", ",", "$", "port", ",", "$", "secure", "=", "true", ")", "{", "$", "this", "->", "socket", "->", "setBlocking", "(", "false", ")", ";", "if", "(", "!", "$", "this", "->", "socket", "->", "connect", "(", "$", "host", ",", "$", "port", ",", "$", "secure", ")", ")", "{", "throw", "new", "Exception", "\\", "ConnectionFailedException", "(", "sprintf", "(", "'%s failed to %s:%d with error %s (%d).'", ",", "$", "secure", "?", "'Secure connection'", ":", "'Connection'", ",", "$", "host", ",", "$", "port", ",", "$", "this", "->", "socket", "->", "connectionError", "(", ")", ",", "$", "this", "->", "socket", "->", "connectionErrorNo", "(", ")", ")", ")", ";", "}", "}" ]
Set up a connection to the server. @param string $host @param integer $port @param boolean $secure @return void
[ "Set", "up", "a", "connection", "to", "the", "server", "." ]
40e5e24288c70be6c7e4e54992069aba969f562c
https://github.com/SCLInternet/SclRequestResponse/blob/40e5e24288c70be6c7e4e54992069aba969f562c/src/SclRequestResponse/Communicator/PersistentCommunicator.php#L69-L85
train
SCLInternet/SclRequestResponse
src/SclRequestResponse/Communicator/PersistentCommunicator.php
PersistentCommunicator.read
protected function read() { $data = ''; // TODO Invesigate if a time out is required do { if ($this->socket->closed()) { throw new Exception\ConnectionDroppedException('The connection has been dropped.'); } $data .= $this->socket->read(); } while (!preg_match($this->responseEnding, $data)); return utf8_decode(substr($data, 4)); }
php
protected function read() { $data = ''; // TODO Invesigate if a time out is required do { if ($this->socket->closed()) { throw new Exception\ConnectionDroppedException('The connection has been dropped.'); } $data .= $this->socket->read(); } while (!preg_match($this->responseEnding, $data)); return utf8_decode(substr($data, 4)); }
[ "protected", "function", "read", "(", ")", "{", "$", "data", "=", "''", ";", "// TODO Invesigate if a time out is required", "do", "{", "if", "(", "$", "this", "->", "socket", "->", "closed", "(", ")", ")", "{", "throw", "new", "Exception", "\\", "ConnectionDroppedException", "(", "'The connection has been dropped.'", ")", ";", "}", "$", "data", ".=", "$", "this", "->", "socket", "->", "read", "(", ")", ";", "}", "while", "(", "!", "preg_match", "(", "$", "this", "->", "responseEnding", ",", "$", "data", ")", ")", ";", "return", "utf8_decode", "(", "substr", "(", "$", "data", ",", "4", ")", ")", ";", "}" ]
Retrieve a response from the server. @return string @throws ConnectionDroppedException @todo Always UTF8 decode?
[ "Retrieve", "a", "response", "from", "the", "server", "." ]
40e5e24288c70be6c7e4e54992069aba969f562c
https://github.com/SCLInternet/SclRequestResponse/blob/40e5e24288c70be6c7e4e54992069aba969f562c/src/SclRequestResponse/Communicator/PersistentCommunicator.php#L106-L120
train
SCLInternet/SclRequestResponse
src/SclRequestResponse/Communicator/PersistentCommunicator.php
PersistentCommunicator.getResponse
public function getResponse(RequestInterface $request) { $this->write($request->getPacket()); return $request->getResponse()->init($this->read()); }
php
public function getResponse(RequestInterface $request) { $this->write($request->getPacket()); return $request->getResponse()->init($this->read()); }
[ "public", "function", "getResponse", "(", "RequestInterface", "$", "request", ")", "{", "$", "this", "->", "write", "(", "$", "request", "->", "getPacket", "(", ")", ")", ";", "return", "$", "request", "->", "getResponse", "(", ")", "->", "init", "(", "$", "this", "->", "read", "(", ")", ")", ";", "}" ]
Send a request to the server and construct an appropriate response. @param RequestInterface $request @return ResponseInterface
[ "Send", "a", "request", "to", "the", "server", "and", "construct", "an", "appropriate", "response", "." ]
40e5e24288c70be6c7e4e54992069aba969f562c
https://github.com/SCLInternet/SclRequestResponse/blob/40e5e24288c70be6c7e4e54992069aba969f562c/src/SclRequestResponse/Communicator/PersistentCommunicator.php#L129-L134
train
congraphcms/core
Repositories/AbstractRepository.php
AbstractRepository.setTransactionMethod
public function setTransactionMethod($method) { // check if is array if (!is_array($this->transactionMethods)) { $this->transactionMethods = [$method]; return $this; } // check if method is already in array if (!in_array($method, $this->transactionMethods)) { $this->transactionMethods[] = $method; } return $this; }
php
public function setTransactionMethod($method) { // check if is array if (!is_array($this->transactionMethods)) { $this->transactionMethods = [$method]; return $this; } // check if method is already in array if (!in_array($method, $this->transactionMethods)) { $this->transactionMethods[] = $method; } return $this; }
[ "public", "function", "setTransactionMethod", "(", "$", "method", ")", "{", "// check if is array", "if", "(", "!", "is_array", "(", "$", "this", "->", "transactionMethods", ")", ")", "{", "$", "this", "->", "transactionMethods", "=", "[", "$", "method", "]", ";", "return", "$", "this", ";", "}", "// check if method is already in array", "if", "(", "!", "in_array", "(", "$", "method", ",", "$", "this", "->", "transactionMethods", ")", ")", "{", "$", "this", "->", "transactionMethods", "[", "]", "=", "$", "method", ";", "}", "return", "$", "this", ";", "}" ]
Set transaction method. @param string $method - method name @return $this
[ "Set", "transaction", "method", "." ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/AbstractRepository.php#L133-L148
train