id
int32
0
241k
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
4,100
Sowapps/orpheus-entitydescriptor
src/EntityDescriptor/EntityDescriptor.php
EntityDescriptor.load
public static function load($name, $class=null) { $descriptorPath = ENTITY_DESCRIPTOR_CONFIG_PATH.$name; $cache = new FSCache(self::DESCRIPTORCLASS, $name, filemtime(YAML::getFilePath($descriptorPath))); // Comment when editing class and entity field types $descriptor = null; try { if( !defined('ENTITY_ALWAYS_RELOAD') && $cache->get($descriptor) && isset($descriptor->version) && $descriptor->version==self::VERSION ) { return $descriptor; } } catch( Exception $e ) { // If file is corrupted (version mismatch ?) $cache->reset(); } // Unable to get from cache, building new one $conf = YAML::build($descriptorPath, true); if( empty($conf->fields) ) { throw new \Exception('Descriptor file for "'.$name.'" is corrupted, empty or not found, there is no field.'); } // Build descriptor // Parse Config file // Fields $fields = array(); if( !empty($conf->parent) ) { if( !is_array($conf->parent) ) { $conf->parent = array($conf->parent); } foreach( $conf->parent as $p ) { $p = static::load($p); if( !empty($p) ) { $fields = array_merge($fields, $p->getFields()); } } } $IDField = $class ? $class::getIDField() : self::IDFIELD; $fields[$IDField] = FieldDescriptor::buildIDField($IDField); foreach( $conf->fields as $fieldName => $fieldInfos ) { $fields[$fieldName] = FieldDescriptor::parseType($fieldName, $fieldInfos); } // Indexes $indexes = array(); if( !empty($conf->indexes) ) { foreach( $conf->indexes as $index ) { $iType = static::parseType(null, $index); $indexes[] = (object) array('name'=>$iType->default, 'type'=>strtoupper($iType->type), 'fields'=>$iType->args); } } // Save cache output $descriptor = new EntityDescriptor($name, $fields, $indexes, $class); if( !empty($conf->flags) ) { if( in_array(self::FLAG_ABSTRACT, $conf->flags) ) { $descriptor->setAbstract(true); } } // debug('Entity load('.$name.')', $fields); $cache->set($descriptor); return $descriptor; }
php
public static function load($name, $class=null) { $descriptorPath = ENTITY_DESCRIPTOR_CONFIG_PATH.$name; $cache = new FSCache(self::DESCRIPTORCLASS, $name, filemtime(YAML::getFilePath($descriptorPath))); // Comment when editing class and entity field types $descriptor = null; try { if( !defined('ENTITY_ALWAYS_RELOAD') && $cache->get($descriptor) && isset($descriptor->version) && $descriptor->version==self::VERSION ) { return $descriptor; } } catch( Exception $e ) { // If file is corrupted (version mismatch ?) $cache->reset(); } // Unable to get from cache, building new one $conf = YAML::build($descriptorPath, true); if( empty($conf->fields) ) { throw new \Exception('Descriptor file for "'.$name.'" is corrupted, empty or not found, there is no field.'); } // Build descriptor // Parse Config file // Fields $fields = array(); if( !empty($conf->parent) ) { if( !is_array($conf->parent) ) { $conf->parent = array($conf->parent); } foreach( $conf->parent as $p ) { $p = static::load($p); if( !empty($p) ) { $fields = array_merge($fields, $p->getFields()); } } } $IDField = $class ? $class::getIDField() : self::IDFIELD; $fields[$IDField] = FieldDescriptor::buildIDField($IDField); foreach( $conf->fields as $fieldName => $fieldInfos ) { $fields[$fieldName] = FieldDescriptor::parseType($fieldName, $fieldInfos); } // Indexes $indexes = array(); if( !empty($conf->indexes) ) { foreach( $conf->indexes as $index ) { $iType = static::parseType(null, $index); $indexes[] = (object) array('name'=>$iType->default, 'type'=>strtoupper($iType->type), 'fields'=>$iType->args); } } // Save cache output $descriptor = new EntityDescriptor($name, $fields, $indexes, $class); if( !empty($conf->flags) ) { if( in_array(self::FLAG_ABSTRACT, $conf->flags) ) { $descriptor->setAbstract(true); } } // debug('Entity load('.$name.')', $fields); $cache->set($descriptor); return $descriptor; }
[ "public", "static", "function", "load", "(", "$", "name", ",", "$", "class", "=", "null", ")", "{", "$", "descriptorPath", "=", "ENTITY_DESCRIPTOR_CONFIG_PATH", ".", "$", "name", ";", "$", "cache", "=", "new", "FSCache", "(", "self", "::", "DESCRIPTORCLASS", ",", "$", "name", ",", "filemtime", "(", "YAML", "::", "getFilePath", "(", "$", "descriptorPath", ")", ")", ")", ";", "// Comment when editing class and entity field types", "$", "descriptor", "=", "null", ";", "try", "{", "if", "(", "!", "defined", "(", "'ENTITY_ALWAYS_RELOAD'", ")", "&&", "$", "cache", "->", "get", "(", "$", "descriptor", ")", "&&", "isset", "(", "$", "descriptor", "->", "version", ")", "&&", "$", "descriptor", "->", "version", "==", "self", "::", "VERSION", ")", "{", "return", "$", "descriptor", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// If file is corrupted (version mismatch ?)", "$", "cache", "->", "reset", "(", ")", ";", "}", "// Unable to get from cache, building new one", "$", "conf", "=", "YAML", "::", "build", "(", "$", "descriptorPath", ",", "true", ")", ";", "if", "(", "empty", "(", "$", "conf", "->", "fields", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Descriptor file for \"'", ".", "$", "name", ".", "'\" is corrupted, empty or not found, there is no field.'", ")", ";", "}", "// Build descriptor", "// Parse Config file", "// Fields", "$", "fields", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "conf", "->", "parent", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "conf", "->", "parent", ")", ")", "{", "$", "conf", "->", "parent", "=", "array", "(", "$", "conf", "->", "parent", ")", ";", "}", "foreach", "(", "$", "conf", "->", "parent", "as", "$", "p", ")", "{", "$", "p", "=", "static", "::", "load", "(", "$", "p", ")", ";", "if", "(", "!", "empty", "(", "$", "p", ")", ")", "{", "$", "fields", "=", "array_merge", "(", "$", "fields", ",", "$", "p", "->", "getFields", "(", ")", ")", ";", "}", "}", "}", "$", "IDField", "=", "$", "class", "?", "$", "class", "::", "getIDField", "(", ")", ":", "self", "::", "IDFIELD", ";", "$", "fields", "[", "$", "IDField", "]", "=", "FieldDescriptor", "::", "buildIDField", "(", "$", "IDField", ")", ";", "foreach", "(", "$", "conf", "->", "fields", "as", "$", "fieldName", "=>", "$", "fieldInfos", ")", "{", "$", "fields", "[", "$", "fieldName", "]", "=", "FieldDescriptor", "::", "parseType", "(", "$", "fieldName", ",", "$", "fieldInfos", ")", ";", "}", "// Indexes", "$", "indexes", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "conf", "->", "indexes", ")", ")", "{", "foreach", "(", "$", "conf", "->", "indexes", "as", "$", "index", ")", "{", "$", "iType", "=", "static", "::", "parseType", "(", "null", ",", "$", "index", ")", ";", "$", "indexes", "[", "]", "=", "(", "object", ")", "array", "(", "'name'", "=>", "$", "iType", "->", "default", ",", "'type'", "=>", "strtoupper", "(", "$", "iType", "->", "type", ")", ",", "'fields'", "=>", "$", "iType", "->", "args", ")", ";", "}", "}", "// Save cache output", "$", "descriptor", "=", "new", "EntityDescriptor", "(", "$", "name", ",", "$", "fields", ",", "$", "indexes", ",", "$", "class", ")", ";", "if", "(", "!", "empty", "(", "$", "conf", "->", "flags", ")", ")", "{", "if", "(", "in_array", "(", "self", "::", "FLAG_ABSTRACT", ",", "$", "conf", "->", "flags", ")", ")", "{", "$", "descriptor", "->", "setAbstract", "(", "true", ")", ";", "}", "}", "// \t\tdebug('Entity load('.$name.')', $fields);", "$", "cache", "->", "set", "(", "$", "descriptor", ")", ";", "return", "$", "descriptor", ";", "}" ]
Load an entity descriptor from configuraiton file @param string $name @param string $class @throws Exception @return EntityDescriptor
[ "Load", "an", "entity", "descriptor", "from", "configuraiton", "file" ]
b9cc04c42e7955b11f37a70ee7cd2a518f5983b2
https://github.com/Sowapps/orpheus-entitydescriptor/blob/b9cc04c42e7955b11f37a70ee7cd2a518f5983b2/src/EntityDescriptor/EntityDescriptor.php#L111-L173
4,101
Sowapps/orpheus-entitydescriptor
src/EntityDescriptor/EntityDescriptor.php
EntityDescriptor.validateFieldValue
public function validateFieldValue($fieldName, &$value, $input=array(), $ref=null) { if( !isset($this->fields[$fieldName]) ) { throw new InvalidFieldException('unknownField', $fieldName, $value, null, $this->name); } $field = $this->getField($fieldName); if( !$field->writable ) { throw new InvalidFieldException('readOnlyField', $fieldName, $value, null, $this->name); } $TYPE = $field->getType(); $TYPE->preFormat($field, $value, $input, $ref); if( $value === NULL || ($value==='' && $TYPE->emptyIsNull($field)) ) { $value = null; if( isset($field->default) ) { // Look for default value $value = $field->getDefault(); } else if( !$field->nullable ) { // Reject null value throw new InvalidFieldException('requiredField', $fieldName, $value, null, $this->name); } // We will format valid null value later (in formatter) return; } // TYPE Validator - Use inheritance, mandatory in super class try { $TYPE->validate($field, $value, $input, $ref); // Field Validator - Could be undefined if( !empty($field->validator) ) { call_user_func_array($field->validator, array($field, &$value, $input, &$ref)); } } catch( FE $e ) { throw new InvalidFieldException($e->getMessage(), $fieldName, $value, $field->type, $this->name, $field->args); } // TYPE Formatter - Use inheritance, mandatory in super class $TYPE->format($field, $value); // Field Formatter - Could be undefined }
php
public function validateFieldValue($fieldName, &$value, $input=array(), $ref=null) { if( !isset($this->fields[$fieldName]) ) { throw new InvalidFieldException('unknownField', $fieldName, $value, null, $this->name); } $field = $this->getField($fieldName); if( !$field->writable ) { throw new InvalidFieldException('readOnlyField', $fieldName, $value, null, $this->name); } $TYPE = $field->getType(); $TYPE->preFormat($field, $value, $input, $ref); if( $value === NULL || ($value==='' && $TYPE->emptyIsNull($field)) ) { $value = null; if( isset($field->default) ) { // Look for default value $value = $field->getDefault(); } else if( !$field->nullable ) { // Reject null value throw new InvalidFieldException('requiredField', $fieldName, $value, null, $this->name); } // We will format valid null value later (in formatter) return; } // TYPE Validator - Use inheritance, mandatory in super class try { $TYPE->validate($field, $value, $input, $ref); // Field Validator - Could be undefined if( !empty($field->validator) ) { call_user_func_array($field->validator, array($field, &$value, $input, &$ref)); } } catch( FE $e ) { throw new InvalidFieldException($e->getMessage(), $fieldName, $value, $field->type, $this->name, $field->args); } // TYPE Formatter - Use inheritance, mandatory in super class $TYPE->format($field, $value); // Field Formatter - Could be undefined }
[ "public", "function", "validateFieldValue", "(", "$", "fieldName", ",", "&", "$", "value", ",", "$", "input", "=", "array", "(", ")", ",", "$", "ref", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "fields", "[", "$", "fieldName", "]", ")", ")", "{", "throw", "new", "InvalidFieldException", "(", "'unknownField'", ",", "$", "fieldName", ",", "$", "value", ",", "null", ",", "$", "this", "->", "name", ")", ";", "}", "$", "field", "=", "$", "this", "->", "getField", "(", "$", "fieldName", ")", ";", "if", "(", "!", "$", "field", "->", "writable", ")", "{", "throw", "new", "InvalidFieldException", "(", "'readOnlyField'", ",", "$", "fieldName", ",", "$", "value", ",", "null", ",", "$", "this", "->", "name", ")", ";", "}", "$", "TYPE", "=", "$", "field", "->", "getType", "(", ")", ";", "$", "TYPE", "->", "preFormat", "(", "$", "field", ",", "$", "value", ",", "$", "input", ",", "$", "ref", ")", ";", "if", "(", "$", "value", "===", "NULL", "||", "(", "$", "value", "===", "''", "&&", "$", "TYPE", "->", "emptyIsNull", "(", "$", "field", ")", ")", ")", "{", "$", "value", "=", "null", ";", "if", "(", "isset", "(", "$", "field", "->", "default", ")", ")", "{", "// Look for default value", "$", "value", "=", "$", "field", "->", "getDefault", "(", ")", ";", "}", "else", "if", "(", "!", "$", "field", "->", "nullable", ")", "{", "// Reject null value ", "throw", "new", "InvalidFieldException", "(", "'requiredField'", ",", "$", "fieldName", ",", "$", "value", ",", "null", ",", "$", "this", "->", "name", ")", ";", "}", "// We will format valid null value later (in formatter)", "return", ";", "}", "// TYPE Validator - Use inheritance, mandatory in super class", "try", "{", "$", "TYPE", "->", "validate", "(", "$", "field", ",", "$", "value", ",", "$", "input", ",", "$", "ref", ")", ";", "// Field Validator - Could be undefined", "if", "(", "!", "empty", "(", "$", "field", "->", "validator", ")", ")", "{", "call_user_func_array", "(", "$", "field", "->", "validator", ",", "array", "(", "$", "field", ",", "&", "$", "value", ",", "$", "input", ",", "&", "$", "ref", ")", ")", ";", "}", "}", "catch", "(", "FE", "$", "e", ")", "{", "throw", "new", "InvalidFieldException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "fieldName", ",", "$", "value", ",", "$", "field", "->", "type", ",", "$", "this", "->", "name", ",", "$", "field", "->", "args", ")", ";", "}", "// TYPE Formatter - Use inheritance, mandatory in super class", "$", "TYPE", "->", "format", "(", "$", "field", ",", "$", "value", ")", ";", "// Field Formatter - Could be undefined", "}" ]
Validate a value for a specified field, an exception is thrown if the value is invalid @param string $fieldName The field to use @param mixed $value input|output value to validate for this field @param $input string[] @param PermanentEntity $ref @throws InvalidFieldException
[ "Validate", "a", "value", "for", "a", "specified", "field", "an", "exception", "is", "thrown", "if", "the", "value", "is", "invalid" ]
b9cc04c42e7955b11f37a70ee7cd2a518f5983b2
https://github.com/Sowapps/orpheus-entitydescriptor/blob/b9cc04c42e7955b11f37a70ee7cd2a518f5983b2/src/EntityDescriptor/EntityDescriptor.php#L266-L306
4,102
Sowapps/orpheus-entitydescriptor
src/EntityDescriptor/EntityDescriptor.php
EntityDescriptor.getType
public static function getType($name, &$type=null) { if( !isset(static::$types[$name]) ) { throw new Exception('unknownType_'.$name); } $type = &static::$types[$name]; return $type; }
php
public static function getType($name, &$type=null) { if( !isset(static::$types[$name]) ) { throw new Exception('unknownType_'.$name); } $type = &static::$types[$name]; return $type; }
[ "public", "static", "function", "getType", "(", "$", "name", ",", "&", "$", "type", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "types", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "Exception", "(", "'unknownType_'", ".", "$", "name", ")", ";", "}", "$", "type", "=", "&", "static", "::", "$", "types", "[", "$", "name", "]", ";", "return", "$", "type", ";", "}" ]
Get a type by name @param string $name Name of the type to get @param string $type Output parameter for type @throws Exception @return TypeDescriptor
[ "Get", "a", "type", "by", "name" ]
b9cc04c42e7955b11f37a70ee7cd2a518f5983b2
https://github.com/Sowapps/orpheus-entitydescriptor/blob/b9cc04c42e7955b11f37a70ee7cd2a518f5983b2/src/EntityDescriptor/EntityDescriptor.php#L385-L391
4,103
Sowapps/orpheus-entitydescriptor
src/EntityDescriptor/EntityDescriptor.php
EntityDescriptor.parseType
public static function parseType($fieldName, $desc) { $result = array('type'=>null, 'args'=>array(), 'default'=>null, 'flags'=>array()); $matches = null; if( !preg_match('#([^\(\[=]+)(?:\(([^\)]*)\))?(?:\[([^\]]*)\])?(?:=([^\[]*))?#', $desc, $matches) ) { throw new Exception('failToParseType'); } $result['type'] = trim($matches[1]); $result['args'] = !empty($matches[2]) ? preg_split('#\s*,\s*#', $matches[2]) : array(); $result['flags'] = !empty($matches[3]) ? preg_split('#\s#', $matches[3], -1, PREG_SPLIT_NO_EMPTY) : array(); if( isset($matches[4]) ) { $result['default'] = $matches[4]; if( $result['default']==='true' ) { $result['default'] = true; } else if( $result['default']==='false' ) { $result['default'] = false; } else { $len = strlen($result['default']); if( $len && $result['default'][$len-1]==')' ) { $result['default'] = static::parseType($fieldName, $result['default']); } } } return (object) $result; }
php
public static function parseType($fieldName, $desc) { $result = array('type'=>null, 'args'=>array(), 'default'=>null, 'flags'=>array()); $matches = null; if( !preg_match('#([^\(\[=]+)(?:\(([^\)]*)\))?(?:\[([^\]]*)\])?(?:=([^\[]*))?#', $desc, $matches) ) { throw new Exception('failToParseType'); } $result['type'] = trim($matches[1]); $result['args'] = !empty($matches[2]) ? preg_split('#\s*,\s*#', $matches[2]) : array(); $result['flags'] = !empty($matches[3]) ? preg_split('#\s#', $matches[3], -1, PREG_SPLIT_NO_EMPTY) : array(); if( isset($matches[4]) ) { $result['default'] = $matches[4]; if( $result['default']==='true' ) { $result['default'] = true; } else if( $result['default']==='false' ) { $result['default'] = false; } else { $len = strlen($result['default']); if( $len && $result['default'][$len-1]==')' ) { $result['default'] = static::parseType($fieldName, $result['default']); } } } return (object) $result; }
[ "public", "static", "function", "parseType", "(", "$", "fieldName", ",", "$", "desc", ")", "{", "$", "result", "=", "array", "(", "'type'", "=>", "null", ",", "'args'", "=>", "array", "(", ")", ",", "'default'", "=>", "null", ",", "'flags'", "=>", "array", "(", ")", ")", ";", "$", "matches", "=", "null", ";", "if", "(", "!", "preg_match", "(", "'#([^\\(\\[=]+)(?:\\(([^\\)]*)\\))?(?:\\[([^\\]]*)\\])?(?:=([^\\[]*))?#'", ",", "$", "desc", ",", "$", "matches", ")", ")", "{", "throw", "new", "Exception", "(", "'failToParseType'", ")", ";", "}", "$", "result", "[", "'type'", "]", "=", "trim", "(", "$", "matches", "[", "1", "]", ")", ";", "$", "result", "[", "'args'", "]", "=", "!", "empty", "(", "$", "matches", "[", "2", "]", ")", "?", "preg_split", "(", "'#\\s*,\\s*#'", ",", "$", "matches", "[", "2", "]", ")", ":", "array", "(", ")", ";", "$", "result", "[", "'flags'", "]", "=", "!", "empty", "(", "$", "matches", "[", "3", "]", ")", "?", "preg_split", "(", "'#\\s#'", ",", "$", "matches", "[", "3", "]", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", ":", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "matches", "[", "4", "]", ")", ")", "{", "$", "result", "[", "'default'", "]", "=", "$", "matches", "[", "4", "]", ";", "if", "(", "$", "result", "[", "'default'", "]", "===", "'true'", ")", "{", "$", "result", "[", "'default'", "]", "=", "true", ";", "}", "else", "if", "(", "$", "result", "[", "'default'", "]", "===", "'false'", ")", "{", "$", "result", "[", "'default'", "]", "=", "false", ";", "}", "else", "{", "$", "len", "=", "strlen", "(", "$", "result", "[", "'default'", "]", ")", ";", "if", "(", "$", "len", "&&", "$", "result", "[", "'default'", "]", "[", "$", "len", "-", "1", "]", "==", "')'", ")", "{", "$", "result", "[", "'default'", "]", "=", "static", "::", "parseType", "(", "$", "fieldName", ",", "$", "result", "[", "'default'", "]", ")", ";", "}", "}", "}", "return", "(", "object", ")", "$", "result", ";", "}" ]
parse type from configuration string @param string $fieldName @param string $desc @throws Exception @return StdClass
[ "parse", "type", "from", "configuration", "string" ]
b9cc04c42e7955b11f37a70ee7cd2a518f5983b2
https://github.com/Sowapps/orpheus-entitydescriptor/blob/b9cc04c42e7955b11f37a70ee7cd2a518f5983b2/src/EntityDescriptor/EntityDescriptor.php#L401-L425
4,104
n0m4dz/laracasa
Zend/Gdata/Books/VolumeQuery.php
Zend_Gdata_Books_VolumeQuery.setMinViewability
public function setMinViewability($value = null) { switch ($value) { case 'full_view': $this->_params['min-viewability'] = 'full'; break; case 'partial_view': $this->_params['min-viewability'] = 'partial'; break; case null: unset($this->_params['min-viewability']); break; } return $this; }
php
public function setMinViewability($value = null) { switch ($value) { case 'full_view': $this->_params['min-viewability'] = 'full'; break; case 'partial_view': $this->_params['min-viewability'] = 'partial'; break; case null: unset($this->_params['min-viewability']); break; } return $this; }
[ "public", "function", "setMinViewability", "(", "$", "value", "=", "null", ")", "{", "switch", "(", "$", "value", ")", "{", "case", "'full_view'", ":", "$", "this", "->", "_params", "[", "'min-viewability'", "]", "=", "'full'", ";", "break", ";", "case", "'partial_view'", ":", "$", "this", "->", "_params", "[", "'min-viewability'", "]", "=", "'partial'", ";", "break", ";", "case", "null", ":", "unset", "(", "$", "this", "->", "_params", "[", "'min-viewability'", "]", ")", ";", "break", ";", "}", "return", "$", "this", ";", "}" ]
Sets the minimum level of viewability of volumes to return in the search results @param string|null $value The minimum viewability - 'full' or 'partial' @return Zend_Gdata_Books_VolumeQuery Provides a fluent interface
[ "Sets", "the", "minimum", "level", "of", "viewability", "of", "volumes", "to", "return", "in", "the", "search", "results" ]
6141f0c16c7d4453275e3b74be5041f336085c91
https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Books/VolumeQuery.php#L63-L77
4,105
n0m4dz/laracasa
Zend/Gdata/Books/VolumeQuery.php
Zend_Gdata_Books_VolumeQuery.getQueryUrl
public function getQueryUrl() { if (isset($this->_url)) { $url = $this->_url; } else { $url = Zend_Gdata_Books::VOLUME_FEED_URI; } if ($this->getCategory() !== null) { $url .= '/-/' . $this->getCategory(); } $url = $url . $this->getQueryString(); return $url; }
php
public function getQueryUrl() { if (isset($this->_url)) { $url = $this->_url; } else { $url = Zend_Gdata_Books::VOLUME_FEED_URI; } if ($this->getCategory() !== null) { $url .= '/-/' . $this->getCategory(); } $url = $url . $this->getQueryString(); return $url; }
[ "public", "function", "getQueryUrl", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_url", ")", ")", "{", "$", "url", "=", "$", "this", "->", "_url", ";", "}", "else", "{", "$", "url", "=", "Zend_Gdata_Books", "::", "VOLUME_FEED_URI", ";", "}", "if", "(", "$", "this", "->", "getCategory", "(", ")", "!==", "null", ")", "{", "$", "url", ".=", "'/-/'", ".", "$", "this", "->", "getCategory", "(", ")", ";", "}", "$", "url", "=", "$", "url", ".", "$", "this", "->", "getQueryString", "(", ")", ";", "return", "$", "url", ";", "}" ]
Returns the generated full query URL @return string The URL
[ "Returns", "the", "generated", "full", "query", "URL" ]
6141f0c16c7d4453275e3b74be5041f336085c91
https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Books/VolumeQuery.php#L98-L110
4,106
dflydev/dflydev-github-gist-twig-extension
src/Dflydev/Twig/Extension/GitHubGist/GistTwigExtension.php
GistTwigExtension.gist
public function gist($id, $file = null) { if ($this->cache()->exists($id)) { $gist = $this->cache()->get($id); } else { $gist = $this->transport()->fetchGist($id); $this->cache()->set($id, $gist); } $files = array(); foreach ($gist['files'] as $name => $fileInfo) { if ($file === null) { $files[$name] = $fileInfo; } else { if ($file == $name) { $files[$name] = $fileInfo; break; } } } if (!count($files)) { return ''; } $urlExtra = $file ? '?file='.$file : ''; $output = ''; $output .= '<script src="https://gist.github.com/'.$id.'.js'.$urlExtra.'"></script>'; $output .= '<noscript>'; foreach ($files as $name => $fileInfo) { $language = strtolower($fileInfo['language']); $output .= '<pre><code class="language-'.$language.' '.$language.'">'; $output .= htmlentities($fileInfo['content']); $output .= '</code></pre>'; } $output .= '</noscript>'; return $output; }
php
public function gist($id, $file = null) { if ($this->cache()->exists($id)) { $gist = $this->cache()->get($id); } else { $gist = $this->transport()->fetchGist($id); $this->cache()->set($id, $gist); } $files = array(); foreach ($gist['files'] as $name => $fileInfo) { if ($file === null) { $files[$name] = $fileInfo; } else { if ($file == $name) { $files[$name] = $fileInfo; break; } } } if (!count($files)) { return ''; } $urlExtra = $file ? '?file='.$file : ''; $output = ''; $output .= '<script src="https://gist.github.com/'.$id.'.js'.$urlExtra.'"></script>'; $output .= '<noscript>'; foreach ($files as $name => $fileInfo) { $language = strtolower($fileInfo['language']); $output .= '<pre><code class="language-'.$language.' '.$language.'">'; $output .= htmlentities($fileInfo['content']); $output .= '</code></pre>'; } $output .= '</noscript>'; return $output; }
[ "public", "function", "gist", "(", "$", "id", ",", "$", "file", "=", "null", ")", "{", "if", "(", "$", "this", "->", "cache", "(", ")", "->", "exists", "(", "$", "id", ")", ")", "{", "$", "gist", "=", "$", "this", "->", "cache", "(", ")", "->", "get", "(", "$", "id", ")", ";", "}", "else", "{", "$", "gist", "=", "$", "this", "->", "transport", "(", ")", "->", "fetchGist", "(", "$", "id", ")", ";", "$", "this", "->", "cache", "(", ")", "->", "set", "(", "$", "id", ",", "$", "gist", ")", ";", "}", "$", "files", "=", "array", "(", ")", ";", "foreach", "(", "$", "gist", "[", "'files'", "]", "as", "$", "name", "=>", "$", "fileInfo", ")", "{", "if", "(", "$", "file", "===", "null", ")", "{", "$", "files", "[", "$", "name", "]", "=", "$", "fileInfo", ";", "}", "else", "{", "if", "(", "$", "file", "==", "$", "name", ")", "{", "$", "files", "[", "$", "name", "]", "=", "$", "fileInfo", ";", "break", ";", "}", "}", "}", "if", "(", "!", "count", "(", "$", "files", ")", ")", "{", "return", "''", ";", "}", "$", "urlExtra", "=", "$", "file", "?", "'?file='", ".", "$", "file", ":", "''", ";", "$", "output", "=", "''", ";", "$", "output", ".=", "'<script src=\"https://gist.github.com/'", ".", "$", "id", ".", "'.js'", ".", "$", "urlExtra", ".", "'\"></script>'", ";", "$", "output", ".=", "'<noscript>'", ";", "foreach", "(", "$", "files", "as", "$", "name", "=>", "$", "fileInfo", ")", "{", "$", "language", "=", "strtolower", "(", "$", "fileInfo", "[", "'language'", "]", ")", ";", "$", "output", ".=", "'<pre><code class=\"language-'", ".", "$", "language", ".", "' '", ".", "$", "language", ".", "'\">'", ";", "$", "output", ".=", "htmlentities", "(", "$", "fileInfo", "[", "'content'", "]", ")", ";", "$", "output", ".=", "'</code></pre>'", ";", "}", "$", "output", ".=", "'</noscript>'", ";", "return", "$", "output", ";", "}" ]
Get the HTML content for a GitHub Gist @param string $id ID @param string $file File @return string
[ "Get", "the", "HTML", "content", "for", "a", "GitHub", "Gist" ]
c324152707397472bed8548ca98cee6c12f215f0
https://github.com/dflydev/dflydev-github-gist-twig-extension/blob/c324152707397472bed8548ca98cee6c12f215f0/src/Dflydev/Twig/Extension/GitHubGist/GistTwigExtension.php#L78-L115
4,107
protobile/framework
src/Protobile/Framework/Runnable.php
Runnable.run
public function run() { $this->container->get('app')->run( $this->container->get('app.input'), $this->container->get('app.output') ); }
php
public function run() { $this->container->get('app')->run( $this->container->get('app.input'), $this->container->get('app.output') ); }
[ "public", "function", "run", "(", ")", "{", "$", "this", "->", "container", "->", "get", "(", "'app'", ")", "->", "run", "(", "$", "this", "->", "container", "->", "get", "(", "'app.input'", ")", ",", "$", "this", "->", "container", "->", "get", "(", "'app.output'", ")", ")", ";", "}" ]
Execute CLI application.
[ "Execute", "CLI", "application", "." ]
e5accea7330b86dcdf11ebd08e8e0ed47e2a914f
https://github.com/protobile/framework/blob/e5accea7330b86dcdf11ebd08e8e0ed47e2a914f/src/Protobile/Framework/Runnable.php#L35-L41
4,108
Puzzlout/FrameworkMvcLegacy
src/UC/ScriptControl.php
ScriptControl.GenerateOutput
private function GenerateOutput($source) { array_push($this->Attributes, HtmlAttribute::Instanciate(HtmlAttributeConstants::Src, $source)); $this->HtmlOutput = '<script type="application/javascript" {0}></script>'; HtmlControlBuildHelper::Init()->GenerateAttributes($this); }
php
private function GenerateOutput($source) { array_push($this->Attributes, HtmlAttribute::Instanciate(HtmlAttributeConstants::Src, $source)); $this->HtmlOutput = '<script type="application/javascript" {0}></script>'; HtmlControlBuildHelper::Init()->GenerateAttributes($this); }
[ "private", "function", "GenerateOutput", "(", "$", "source", ")", "{", "array_push", "(", "$", "this", "->", "Attributes", ",", "HtmlAttribute", "::", "Instanciate", "(", "HtmlAttributeConstants", "::", "Src", ",", "$", "source", ")", ")", ";", "$", "this", "->", "HtmlOutput", "=", "'<script type=\"application/javascript\" {0}></script>'", ";", "HtmlControlBuildHelper", "::", "Init", "(", ")", "->", "GenerateAttributes", "(", "$", "this", ")", ";", "}" ]
Generates a script html tag to include a script in the DOM @param string $source The source to load as a script.
[ "Generates", "a", "script", "html", "tag", "to", "include", "a", "script", "in", "the", "DOM" ]
14e0fc5b16978cbd209f552ee9c649f66a0dfc6e
https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/UC/ScriptControl.php#L56-L60
4,109
FKSE/php-utils
lib/FKSE/Process/ProcessPool.php
ProcessPool.start
public function start() { foreach ($this->processes as $process) { //start process $process->start(); //update status array $this->updateStatus(); while ($this->runningProcesses() >= $this->concurrent) { usleep(self::SLEEP_INTERVAL); //update status $this->updateStatus(); } } //wait until all processes are finished $this->wait(); }
php
public function start() { foreach ($this->processes as $process) { //start process $process->start(); //update status array $this->updateStatus(); while ($this->runningProcesses() >= $this->concurrent) { usleep(self::SLEEP_INTERVAL); //update status $this->updateStatus(); } } //wait until all processes are finished $this->wait(); }
[ "public", "function", "start", "(", ")", "{", "foreach", "(", "$", "this", "->", "processes", "as", "$", "process", ")", "{", "//start process", "$", "process", "->", "start", "(", ")", ";", "//update status array", "$", "this", "->", "updateStatus", "(", ")", ";", "while", "(", "$", "this", "->", "runningProcesses", "(", ")", ">=", "$", "this", "->", "concurrent", ")", "{", "usleep", "(", "self", "::", "SLEEP_INTERVAL", ")", ";", "//update status", "$", "this", "->", "updateStatus", "(", ")", ";", "}", "}", "//wait until all processes are finished", "$", "this", "->", "wait", "(", ")", ";", "}" ]
Start the processes in the pool
[ "Start", "the", "processes", "in", "the", "pool" ]
d13c5c49cf9f48658d2cabd18357257185474ff2
https://github.com/FKSE/php-utils/blob/d13c5c49cf9f48658d2cabd18357257185474ff2/lib/FKSE/Process/ProcessPool.php#L90-L107
4,110
FKSE/php-utils
lib/FKSE/Process/ProcessPool.php
ProcessPool.runningProcesses
protected function runningProcesses() { $count = 0; foreach ($this->processes as $process) { if ($process->isRunning()) { $count++; } } return $count; }
php
protected function runningProcesses() { $count = 0; foreach ($this->processes as $process) { if ($process->isRunning()) { $count++; } } return $count; }
[ "protected", "function", "runningProcesses", "(", ")", "{", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "processes", "as", "$", "process", ")", "{", "if", "(", "$", "process", "->", "isRunning", "(", ")", ")", "{", "$", "count", "++", ";", "}", "}", "return", "$", "count", ";", "}" ]
Counts the number of running processes in the pool @return int The number of currently running processes
[ "Counts", "the", "number", "of", "running", "processes", "in", "the", "pool" ]
d13c5c49cf9f48658d2cabd18357257185474ff2
https://github.com/FKSE/php-utils/blob/d13c5c49cf9f48658d2cabd18357257185474ff2/lib/FKSE/Process/ProcessPool.php#L126-L136
4,111
FKSE/php-utils
lib/FKSE/Process/ProcessPool.php
ProcessPool.updateStatus
protected function updateStatus($alwaysNotify = false) { //save current $this->previousStatus = $this->status; //clear status $this->status = []; foreach ($this->processes as $process) { $this->status[] = $process->getStatus(); } //notify if something has changed if ($this->previousStatus != $this->status || $alwaysNotify) { if (is_callable($this->updateCallback)) { call_user_func($this->updateCallback, $this->status); } } }
php
protected function updateStatus($alwaysNotify = false) { //save current $this->previousStatus = $this->status; //clear status $this->status = []; foreach ($this->processes as $process) { $this->status[] = $process->getStatus(); } //notify if something has changed if ($this->previousStatus != $this->status || $alwaysNotify) { if (is_callable($this->updateCallback)) { call_user_func($this->updateCallback, $this->status); } } }
[ "protected", "function", "updateStatus", "(", "$", "alwaysNotify", "=", "false", ")", "{", "//save current", "$", "this", "->", "previousStatus", "=", "$", "this", "->", "status", ";", "//clear status", "$", "this", "->", "status", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "processes", "as", "$", "process", ")", "{", "$", "this", "->", "status", "[", "]", "=", "$", "process", "->", "getStatus", "(", ")", ";", "}", "//notify if something has changed", "if", "(", "$", "this", "->", "previousStatus", "!=", "$", "this", "->", "status", "||", "$", "alwaysNotify", ")", "{", "if", "(", "is_callable", "(", "$", "this", "->", "updateCallback", ")", ")", "{", "call_user_func", "(", "$", "this", "->", "updateCallback", ",", "$", "this", "->", "status", ")", ";", "}", "}", "}" ]
Updates the status of all processes @param bool $alwaysNotify
[ "Updates", "the", "status", "of", "all", "processes" ]
d13c5c49cf9f48658d2cabd18357257185474ff2
https://github.com/FKSE/php-utils/blob/d13c5c49cf9f48658d2cabd18357257185474ff2/lib/FKSE/Process/ProcessPool.php#L143-L159
4,112
inceddy/everest-http
src/Everest/Http/Cookie.php
Cookie.validateName
private static function validateName(string $name) : string { if (empty($name) || preg_match("/[=,; \t\r\n\013\014]/", $name)) { throw new \InvalidArgumentException(sprintf('Invalid name \'%s\'.', $name)); } return $name; }
php
private static function validateName(string $name) : string { if (empty($name) || preg_match("/[=,; \t\r\n\013\014]/", $name)) { throw new \InvalidArgumentException(sprintf('Invalid name \'%s\'.', $name)); } return $name; }
[ "private", "static", "function", "validateName", "(", "string", "$", "name", ")", ":", "string", "{", "if", "(", "empty", "(", "$", "name", ")", "||", "preg_match", "(", "\"/[=,; \\t\\r\\n\\013\\014]/\"", ",", "$", "name", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid name \\'%s\\'.'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "name", ";", "}" ]
Validates the name and returns it @param string $name The name to validate @return string
[ "Validates", "the", "name", "and", "returns", "it" ]
b0f6cbb6723aa96213d28c35b52e03833113be0e
https://github.com/inceddy/everest-http/blob/b0f6cbb6723aa96213d28c35b52e03833113be0e/src/Everest/Http/Cookie.php#L83-L90
4,113
inceddy/everest-http
src/Everest/Http/Cookie.php
Cookie.validateExpires
private static function validateExpires($expires) : int { if (is_numeric($expires)) { return (int)$expires; } // Add intervals to current type if ($expires instanceof \DateInterval) { $now = new \DateTime('now'); return (int)$now->add($expires)->format('U'); } if ($expires instanceof \DateTimeInterface) { return (int)$expires->format('U'); } $expires = strtotime($expires); if (false === $expires || -1 === $expires) { throw new \InvalidArgumentException('The expiration time is not valid.'); } return $expires; }
php
private static function validateExpires($expires) : int { if (is_numeric($expires)) { return (int)$expires; } // Add intervals to current type if ($expires instanceof \DateInterval) { $now = new \DateTime('now'); return (int)$now->add($expires)->format('U'); } if ($expires instanceof \DateTimeInterface) { return (int)$expires->format('U'); } $expires = strtotime($expires); if (false === $expires || -1 === $expires) { throw new \InvalidArgumentException('The expiration time is not valid.'); } return $expires; }
[ "private", "static", "function", "validateExpires", "(", "$", "expires", ")", ":", "int", "{", "if", "(", "is_numeric", "(", "$", "expires", ")", ")", "{", "return", "(", "int", ")", "$", "expires", ";", "}", "// Add intervals to current type", "if", "(", "$", "expires", "instanceof", "\\", "DateInterval", ")", "{", "$", "now", "=", "new", "\\", "DateTime", "(", "'now'", ")", ";", "return", "(", "int", ")", "$", "now", "->", "add", "(", "$", "expires", ")", "->", "format", "(", "'U'", ")", ";", "}", "if", "(", "$", "expires", "instanceof", "\\", "DateTimeInterface", ")", "{", "return", "(", "int", ")", "$", "expires", "->", "format", "(", "'U'", ")", ";", "}", "$", "expires", "=", "strtotime", "(", "$", "expires", ")", ";", "if", "(", "false", "===", "$", "expires", "||", "-", "1", "===", "$", "expires", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The expiration time is not valid.'", ")", ";", "}", "return", "$", "expires", ";", "}" ]
Convert expiration time to a Unix timestamp @param mixed $expire @return int
[ "Convert", "expiration", "time", "to", "a", "Unix", "timestamp" ]
b0f6cbb6723aa96213d28c35b52e03833113be0e
https://github.com/inceddy/everest-http/blob/b0f6cbb6723aa96213d28c35b52e03833113be0e/src/Everest/Http/Cookie.php#L99-L122
4,114
inceddy/everest-http
src/Everest/Http/Cookie.php
Cookie.toHeaderLine
public function toHeaderLine() : string { $cookie = sprintf('%s=%s', $this->name, urlencode($this->value)); if ($this->expires !== 0) { $cookie .= sprintf('; expires=%s', gmdate('D, d-M-Y H:i:s T', $this->expires)); } if (!empty($this->path)) { $cookie .= sprintf('; path=%s', $this->path); } if (!empty($this->domain)) { $cookie .= sprintf('; domain=%s', $this->domain); } if (!empty($this->secure)) { $cookie .= '; secure'; } if (!empty($this->httpOnly)) { $cookie .= '; httponly'; } return $cookie; }
php
public function toHeaderLine() : string { $cookie = sprintf('%s=%s', $this->name, urlencode($this->value)); if ($this->expires !== 0) { $cookie .= sprintf('; expires=%s', gmdate('D, d-M-Y H:i:s T', $this->expires)); } if (!empty($this->path)) { $cookie .= sprintf('; path=%s', $this->path); } if (!empty($this->domain)) { $cookie .= sprintf('; domain=%s', $this->domain); } if (!empty($this->secure)) { $cookie .= '; secure'; } if (!empty($this->httpOnly)) { $cookie .= '; httponly'; } return $cookie; }
[ "public", "function", "toHeaderLine", "(", ")", ":", "string", "{", "$", "cookie", "=", "sprintf", "(", "'%s=%s'", ",", "$", "this", "->", "name", ",", "urlencode", "(", "$", "this", "->", "value", ")", ")", ";", "if", "(", "$", "this", "->", "expires", "!==", "0", ")", "{", "$", "cookie", ".=", "sprintf", "(", "'; expires=%s'", ",", "gmdate", "(", "'D, d-M-Y H:i:s T'", ",", "$", "this", "->", "expires", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "path", ")", ")", "{", "$", "cookie", ".=", "sprintf", "(", "'; path=%s'", ",", "$", "this", "->", "path", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "domain", ")", ")", "{", "$", "cookie", ".=", "sprintf", "(", "'; domain=%s'", ",", "$", "this", "->", "domain", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "secure", ")", ")", "{", "$", "cookie", ".=", "'; secure'", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "httpOnly", ")", ")", "{", "$", "cookie", ".=", "'; httponly'", ";", "}", "return", "$", "cookie", ";", "}" ]
Returns headerline from this cookie @return string
[ "Returns", "headerline", "from", "this", "cookie" ]
b0f6cbb6723aa96213d28c35b52e03833113be0e
https://github.com/inceddy/everest-http/blob/b0f6cbb6723aa96213d28c35b52e03833113be0e/src/Everest/Http/Cookie.php#L248-L273
4,115
novuso/common
src/Domain/Model/AggregateRoot.php
AggregateRoot.extractRecordedEvents
public function extractRecordedEvents() { $eventCollection = $this->eventCollection(); $eventStream = $eventCollection->stream(); $eventCollection->commit(); $this->committedVersion = $eventCollection->committedSequence(); return $eventStream; }
php
public function extractRecordedEvents() { $eventCollection = $this->eventCollection(); $eventStream = $eventCollection->stream(); $eventCollection->commit(); $this->committedVersion = $eventCollection->committedSequence(); return $eventStream; }
[ "public", "function", "extractRecordedEvents", "(", ")", "{", "$", "eventCollection", "=", "$", "this", "->", "eventCollection", "(", ")", ";", "$", "eventStream", "=", "$", "eventCollection", "->", "stream", "(", ")", ";", "$", "eventCollection", "->", "commit", "(", ")", ";", "$", "this", "->", "committedVersion", "=", "$", "eventCollection", "->", "committedSequence", "(", ")", ";", "return", "$", "eventStream", ";", "}" ]
Removes and returns recorded events @return Traversable|EventRecord[]
[ "Removes", "and", "returns", "recorded", "events" ]
7d0e5a4f4c79c9622e068efc8b7c70815c460863
https://github.com/novuso/common/blob/7d0e5a4f4c79c9622e068efc8b7c70815c460863/src/Domain/Model/AggregateRoot.php#L71-L79
4,116
novuso/common
src/Domain/Model/AggregateRoot.php
AggregateRoot.committedVersion
public function committedVersion(): ?int { if ($this->committedVersion === null) { $this->committedVersion = $this->eventCollection()->committedSequence(); } return $this->committedVersion; }
php
public function committedVersion(): ?int { if ($this->committedVersion === null) { $this->committedVersion = $this->eventCollection()->committedSequence(); } return $this->committedVersion; }
[ "public", "function", "committedVersion", "(", ")", ":", "?", "int", "{", "if", "(", "$", "this", "->", "committedVersion", "===", "null", ")", "{", "$", "this", "->", "committedVersion", "=", "$", "this", "->", "eventCollection", "(", ")", "->", "committedSequence", "(", ")", ";", "}", "return", "$", "this", "->", "committedVersion", ";", "}" ]
Retrieves the committed version @return int|null
[ "Retrieves", "the", "committed", "version" ]
7d0e5a4f4c79c9622e068efc8b7c70815c460863
https://github.com/novuso/common/blob/7d0e5a4f4c79c9622e068efc8b7c70815c460863/src/Domain/Model/AggregateRoot.php#L86-L93
4,117
novuso/common
src/Domain/Model/AggregateRoot.php
AggregateRoot.initializeCommittedVersion
protected function initializeCommittedVersion(int $committedVersion): void { if (!$this->eventCollection()->isEmpty()) { $message = 'Cannot initialize version after recording events'; throw new OperationException($message); } $this->eventCollection()->initializeSequence($committedVersion); }
php
protected function initializeCommittedVersion(int $committedVersion): void { if (!$this->eventCollection()->isEmpty()) { $message = 'Cannot initialize version after recording events'; throw new OperationException($message); } $this->eventCollection()->initializeSequence($committedVersion); }
[ "protected", "function", "initializeCommittedVersion", "(", "int", "$", "committedVersion", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "eventCollection", "(", ")", "->", "isEmpty", "(", ")", ")", "{", "$", "message", "=", "'Cannot initialize version after recording events'", ";", "throw", "new", "OperationException", "(", "$", "message", ")", ";", "}", "$", "this", "->", "eventCollection", "(", ")", "->", "initializeSequence", "(", "$", "committedVersion", ")", ";", "}" ]
Initializes the committed version @param int $committedVersion the initial version @return void @throws OperationException When called with recorded events
[ "Initializes", "the", "committed", "version" ]
7d0e5a4f4c79c9622e068efc8b7c70815c460863
https://github.com/novuso/common/blob/7d0e5a4f4c79c9622e068efc8b7c70815c460863/src/Domain/Model/AggregateRoot.php#L104-L112
4,118
novuso/common
src/Domain/Model/AggregateRoot.php
AggregateRoot.eventCollection
protected function eventCollection(): EventCollection { if ($this->eventCollection === null) { $this->eventCollection = new EventCollection($this->id(), Type::create($this)); } return $this->eventCollection; }
php
protected function eventCollection(): EventCollection { if ($this->eventCollection === null) { $this->eventCollection = new EventCollection($this->id(), Type::create($this)); } return $this->eventCollection; }
[ "protected", "function", "eventCollection", "(", ")", ":", "EventCollection", "{", "if", "(", "$", "this", "->", "eventCollection", "===", "null", ")", "{", "$", "this", "->", "eventCollection", "=", "new", "EventCollection", "(", "$", "this", "->", "id", "(", ")", ",", "Type", "::", "create", "(", "$", "this", ")", ")", ";", "}", "return", "$", "this", "->", "eventCollection", ";", "}" ]
Retrieves the event collection @return EventCollection
[ "Retrieves", "the", "event", "collection" ]
7d0e5a4f4c79c9622e068efc8b7c70815c460863
https://github.com/novuso/common/blob/7d0e5a4f4c79c9622e068efc8b7c70815c460863/src/Domain/Model/AggregateRoot.php#L119-L126
4,119
webforge-labs/webforge-utils
src/php/Webforge/Common/StringUtil.php
StringUtil.endsWith
public static function endsWith($string, $suffix) { return (mb_strrpos($string,$suffix) === mb_strlen($string) - mb_strlen($suffix)); }
php
public static function endsWith($string, $suffix) { return (mb_strrpos($string,$suffix) === mb_strlen($string) - mb_strlen($suffix)); }
[ "public", "static", "function", "endsWith", "(", "$", "string", ",", "$", "suffix", ")", "{", "return", "(", "mb_strrpos", "(", "$", "string", ",", "$", "suffix", ")", "===", "mb_strlen", "(", "$", "string", ")", "-", "mb_strlen", "(", "$", "suffix", ")", ")", ";", "}" ]
Does string end with suffix? @param string $string @param string $suffix
[ "Does", "string", "end", "with", "suffix?" ]
a476eeec046c22ad91794b0ab9fe15a1d3f92bfc
https://github.com/webforge-labs/webforge-utils/blob/a476eeec046c22ad91794b0ab9fe15a1d3f92bfc/src/php/Webforge/Common/StringUtil.php#L31-L33
4,120
webforge-labs/webforge-utils
src/php/Webforge/Common/StringUtil.php
StringUtil.lineNumbers
public static function lineNumbers($code, $eol = "\n", $begin = 1) { $cut = FALSE; if (!static::endsWith($code, $eol)) { $code .= $eol; $cut = -mb_strlen($eol); } $lines = mb_substr_count($code, $eol); $padWhite = mb_strlen((string) $lines); // darstellung der größten zeilen-nummer als string $cnt = $begin; $linedCode = Preg::replace_callback($code, '/(.*?)'.$eol.'/', function ($match) use (&$cnt, $padWhite) { return sprintf('%s %s', StringUtil::padRight((string) $cnt++, $padWhite,' '), $match[0]); } ); if ($cut !== FALSE) { return mb_substr($linedCode, 0, $cut); } else { return $linedCode; } }
php
public static function lineNumbers($code, $eol = "\n", $begin = 1) { $cut = FALSE; if (!static::endsWith($code, $eol)) { $code .= $eol; $cut = -mb_strlen($eol); } $lines = mb_substr_count($code, $eol); $padWhite = mb_strlen((string) $lines); // darstellung der größten zeilen-nummer als string $cnt = $begin; $linedCode = Preg::replace_callback($code, '/(.*?)'.$eol.'/', function ($match) use (&$cnt, $padWhite) { return sprintf('%s %s', StringUtil::padRight((string) $cnt++, $padWhite,' '), $match[0]); } ); if ($cut !== FALSE) { return mb_substr($linedCode, 0, $cut); } else { return $linedCode; } }
[ "public", "static", "function", "lineNumbers", "(", "$", "code", ",", "$", "eol", "=", "\"\\n\"", ",", "$", "begin", "=", "1", ")", "{", "$", "cut", "=", "FALSE", ";", "if", "(", "!", "static", "::", "endsWith", "(", "$", "code", ",", "$", "eol", ")", ")", "{", "$", "code", ".=", "$", "eol", ";", "$", "cut", "=", "-", "mb_strlen", "(", "$", "eol", ")", ";", "}", "$", "lines", "=", "mb_substr_count", "(", "$", "code", ",", "$", "eol", ")", ";", "$", "padWhite", "=", "mb_strlen", "(", "(", "string", ")", "$", "lines", ")", ";", "// darstellung der größten zeilen-nummer als string", "$", "cnt", "=", "$", "begin", ";", "$", "linedCode", "=", "Preg", "::", "replace_callback", "(", "$", "code", ",", "'/(.*?)'", ".", "$", "eol", ".", "'/'", ",", "function", "(", "$", "match", ")", "use", "(", "&", "$", "cnt", ",", "$", "padWhite", ")", "{", "return", "sprintf", "(", "'%s %s'", ",", "StringUtil", "::", "padRight", "(", "(", "string", ")", "$", "cnt", "++", ",", "$", "padWhite", ",", "' '", ")", ",", "$", "match", "[", "0", "]", ")", ";", "}", ")", ";", "if", "(", "$", "cut", "!==", "FALSE", ")", "{", "return", "mb_substr", "(", "$", "linedCode", ",", "0", ",", "$", "cut", ")", ";", "}", "else", "{", "return", "$", "linedCode", ";", "}", "}" ]
Number the lines in the string @param string $code @param string $eol the eol from $code @param int $begin the number of the first line found @return string
[ "Number", "the", "lines", "in", "the", "string" ]
a476eeec046c22ad91794b0ab9fe15a1d3f92bfc
https://github.com/webforge-labs/webforge-utils/blob/a476eeec046c22ad91794b0ab9fe15a1d3f92bfc/src/php/Webforge/Common/StringUtil.php#L74-L94
4,121
webforge-labs/webforge-utils
src/php/Webforge/Common/StringUtil.php
StringUtil.random
public static function random($length) { if ($length <= 0) return ''; $str = ''; for ($i = 0; $i < $length; $i++) { $rand = rand(0, 35); if ($rand >= 10) $str .= chr(ord('a') + $rand-10); // a - z else $str .= chr(ord('0') + $rand); // 0 - 9 } return $str; }
php
public static function random($length) { if ($length <= 0) return ''; $str = ''; for ($i = 0; $i < $length; $i++) { $rand = rand(0, 35); if ($rand >= 10) $str .= chr(ord('a') + $rand-10); // a - z else $str .= chr(ord('0') + $rand); // 0 - 9 } return $str; }
[ "public", "static", "function", "random", "(", "$", "length", ")", "{", "if", "(", "$", "length", "<=", "0", ")", "return", "''", ";", "$", "str", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "rand", "=", "rand", "(", "0", ",", "35", ")", ";", "if", "(", "$", "rand", ">=", "10", ")", "$", "str", ".=", "chr", "(", "ord", "(", "'a'", ")", "+", "$", "rand", "-", "10", ")", ";", "// a - z", "else", "$", "str", ".=", "chr", "(", "ord", "(", "'0'", ")", "+", "$", "rand", ")", ";", "// 0 - 9", "}", "return", "$", "str", ";", "}" ]
Generates a Random string from specific length the range of chars [a-z0-9] is used @return string
[ "Generates", "a", "Random", "string", "from", "specific", "length" ]
a476eeec046c22ad91794b0ab9fe15a1d3f92bfc
https://github.com/webforge-labs/webforge-utils/blob/a476eeec046c22ad91794b0ab9fe15a1d3f92bfc/src/php/Webforge/Common/StringUtil.php#L134-L146
4,122
Briareos/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.getFieldsInQuery
public function getFieldsInQuery() { $query = isset($this->query['query']) ? $this->query['query'] : array(); $sort = isset($this->query['sort']) ? $this->query['sort'] : array(); $extractor = new FieldExtractor($query, $sort); return $extractor->getFields(); }
php
public function getFieldsInQuery() { $query = isset($this->query['query']) ? $this->query['query'] : array(); $sort = isset($this->query['sort']) ? $this->query['sort'] : array(); $extractor = new FieldExtractor($query, $sort); return $extractor->getFields(); }
[ "public", "function", "getFieldsInQuery", "(", ")", "{", "$", "query", "=", "isset", "(", "$", "this", "->", "query", "[", "'query'", "]", ")", "?", "$", "this", "->", "query", "[", "'query'", "]", ":", "array", "(", ")", ";", "$", "sort", "=", "isset", "(", "$", "this", "->", "query", "[", "'sort'", "]", ")", "?", "$", "this", "->", "query", "[", "'sort'", "]", ":", "array", "(", ")", ";", "$", "extractor", "=", "new", "FieldExtractor", "(", "$", "query", ",", "$", "sort", ")", ";", "return", "$", "extractor", "->", "getFields", "(", ")", ";", "}" ]
Gets the fields involved in this query. @return array $fields An array of fields names used in this query.
[ "Gets", "the", "fields", "involved", "in", "this", "query", "." ]
29e28bed9a265efd7d05473b0a909fb7c83f76e0
https://github.com/Briareos/mongodb-odm/blob/29e28bed9a265efd7d05473b0a909fb7c83f76e0/lib/Doctrine/ODM/MongoDB/Query/Query.php#L172-L179
4,123
Briareos/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.isIndexed
public function isIndexed() { $fields = $this->getFieldsInQuery(); foreach ($fields as $field) { if ( ! $this->collection->isFieldIndexed($field)) { return false; } } return true; }
php
public function isIndexed() { $fields = $this->getFieldsInQuery(); foreach ($fields as $field) { if ( ! $this->collection->isFieldIndexed($field)) { return false; } } return true; }
[ "public", "function", "isIndexed", "(", ")", "{", "$", "fields", "=", "$", "this", "->", "getFieldsInQuery", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "!", "$", "this", "->", "collection", "->", "isFieldIndexed", "(", "$", "field", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check if this query is indexed. @return bool
[ "Check", "if", "this", "query", "is", "indexed", "." ]
29e28bed9a265efd7d05473b0a909fb7c83f76e0
https://github.com/Briareos/mongodb-odm/blob/29e28bed9a265efd7d05473b0a909fb7c83f76e0/lib/Doctrine/ODM/MongoDB/Query/Query.php#L186-L195
4,124
Briareos/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.getUnindexedFields
public function getUnindexedFields() { $unindexedFields = array(); $fields = $this->getFieldsInQuery(); foreach ($fields as $field) { if ( ! $this->collection->isFieldIndexed($field)) { $unindexedFields[] = $field; } } return $unindexedFields; }
php
public function getUnindexedFields() { $unindexedFields = array(); $fields = $this->getFieldsInQuery(); foreach ($fields as $field) { if ( ! $this->collection->isFieldIndexed($field)) { $unindexedFields[] = $field; } } return $unindexedFields; }
[ "public", "function", "getUnindexedFields", "(", ")", "{", "$", "unindexedFields", "=", "array", "(", ")", ";", "$", "fields", "=", "$", "this", "->", "getFieldsInQuery", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "!", "$", "this", "->", "collection", "->", "isFieldIndexed", "(", "$", "field", ")", ")", "{", "$", "unindexedFields", "[", "]", "=", "$", "field", ";", "}", "}", "return", "$", "unindexedFields", ";", "}" ]
Gets an array of the unindexed fields in this query. @return array
[ "Gets", "an", "array", "of", "the", "unindexed", "fields", "in", "this", "query", "." ]
29e28bed9a265efd7d05473b0a909fb7c83f76e0
https://github.com/Briareos/mongodb-odm/blob/29e28bed9a265efd7d05473b0a909fb7c83f76e0/lib/Doctrine/ODM/MongoDB/Query/Query.php#L202-L212
4,125
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.hasAction
public function hasAction($controller, $action = null) { if ($action === null) { list($controller, $action) = explode('.', $controller); } return in_array("{$controller}.{$action}", $this->action_names); }
php
public function hasAction($controller, $action = null) { if ($action === null) { list($controller, $action) = explode('.', $controller); } return in_array("{$controller}.{$action}", $this->action_names); }
[ "public", "function", "hasAction", "(", "$", "controller", ",", "$", "action", "=", "null", ")", "{", "if", "(", "$", "action", "===", "null", ")", "{", "list", "(", "$", "controller", ",", "$", "action", ")", "=", "explode", "(", "'.'", ",", "$", "controller", ")", ";", "}", "return", "in_array", "(", "\"{$controller}.{$action}\"", ",", "$", "this", "->", "action_names", ")", ";", "}" ]
has action ? @param string $controller @param string $action @return boolean
[ "has", "action", "?" ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L111-L117
4,126
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.getCurrentAction
public function getCurrentAction() { if (! isset($this->actions[$this->position])) return null; $define = $this->actions[$this->position]; if ($define['controller']) return $define; $controller = $this->getController($define['controller_name']); $define['controller'] = $controller; $this->actions[$this->position] = $define; return $define; }
php
public function getCurrentAction() { if (! isset($this->actions[$this->position])) return null; $define = $this->actions[$this->position]; if ($define['controller']) return $define; $controller = $this->getController($define['controller_name']); $define['controller'] = $controller; $this->actions[$this->position] = $define; return $define; }
[ "public", "function", "getCurrentAction", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "actions", "[", "$", "this", "->", "position", "]", ")", ")", "return", "null", ";", "$", "define", "=", "$", "this", "->", "actions", "[", "$", "this", "->", "position", "]", ";", "if", "(", "$", "define", "[", "'controller'", "]", ")", "return", "$", "define", ";", "$", "controller", "=", "$", "this", "->", "getController", "(", "$", "define", "[", "'controller_name'", "]", ")", ";", "$", "define", "[", "'controller'", "]", "=", "$", "controller", ";", "$", "this", "->", "actions", "[", "$", "this", "->", "position", "]", "=", "$", "define", ";", "return", "$", "define", ";", "}" ]
Get current action instance. @return array controller:Controller, action:string
[ "Get", "current", "action", "instance", "." ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L125-L138
4,127
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.getCurrentActionName
public function getCurrentActionName() { return isset($this->action_names[$this->position]) ? $this->action_names[$this->position] : null; }
php
public function getCurrentActionName() { return isset($this->action_names[$this->position]) ? $this->action_names[$this->position] : null; }
[ "public", "function", "getCurrentActionName", "(", ")", "{", "return", "isset", "(", "$", "this", "->", "action_names", "[", "$", "this", "->", "position", "]", ")", "?", "$", "this", "->", "action_names", "[", "$", "this", "->", "position", "]", ":", "null", ";", "}" ]
get current action name @return string
[ "get", "current", "action", "name" ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L145-L148
4,128
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.getController
public function getController($name) { $names = explode('_', $name); array_unshift($names, 'Controller'); foreach ($this->application->config('controller.namespaces') as $ns) { $class = $ns . '\\' . join('\\', array_map('ucfirst', $names)) . 'Controller'; if (class_exists($class)) { $controller = new $class(); $controller->setContainer($this->getContainer()); $this->getContainer()->injectDependency($controller); $controller->setName($name); return $controller; } } // not found. throw new NotFoundException(); }
php
public function getController($name) { $names = explode('_', $name); array_unshift($names, 'Controller'); foreach ($this->application->config('controller.namespaces') as $ns) { $class = $ns . '\\' . join('\\', array_map('ucfirst', $names)) . 'Controller'; if (class_exists($class)) { $controller = new $class(); $controller->setContainer($this->getContainer()); $this->getContainer()->injectDependency($controller); $controller->setName($name); return $controller; } } // not found. throw new NotFoundException(); }
[ "public", "function", "getController", "(", "$", "name", ")", "{", "$", "names", "=", "explode", "(", "'_'", ",", "$", "name", ")", ";", "array_unshift", "(", "$", "names", ",", "'Controller'", ")", ";", "foreach", "(", "$", "this", "->", "application", "->", "config", "(", "'controller.namespaces'", ")", "as", "$", "ns", ")", "{", "$", "class", "=", "$", "ns", ".", "'\\\\'", ".", "join", "(", "'\\\\'", ",", "array_map", "(", "'ucfirst'", ",", "$", "names", ")", ")", ".", "'Controller'", ";", "if", "(", "class_exists", "(", "$", "class", ")", ")", "{", "$", "controller", "=", "new", "$", "class", "(", ")", ";", "$", "controller", "->", "setContainer", "(", "$", "this", "->", "getContainer", "(", ")", ")", ";", "$", "this", "->", "getContainer", "(", ")", "->", "injectDependency", "(", "$", "controller", ")", ";", "$", "controller", "->", "setName", "(", "$", "name", ")", ";", "return", "$", "controller", ";", "}", "}", "// not found.", "throw", "new", "NotFoundException", "(", ")", ";", "}" ]
cteate and return controller. @access public @return Controller
[ "cteate", "and", "return", "controller", "." ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L157-L175
4,129
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.existsController
public function existsController($name, $action = null) { $names = explode('_', $name); array_unshift($names, 'Controller'); $base = join(DS, array_map('ucfirst', $names)) . 'Controller.php'; $file = $this->loader->findFirst($base); if ($file) { $class = $file->getClassName(); if (! $action && class_exists($class)) return true; $action = $this->actionNameStrategy($action); if (method_exists($class, $action)) return true; } return false; }
php
public function existsController($name, $action = null) { $names = explode('_', $name); array_unshift($names, 'Controller'); $base = join(DS, array_map('ucfirst', $names)) . 'Controller.php'; $file = $this->loader->findFirst($base); if ($file) { $class = $file->getClassName(); if (! $action && class_exists($class)) return true; $action = $this->actionNameStrategy($action); if (method_exists($class, $action)) return true; } return false; }
[ "public", "function", "existsController", "(", "$", "name", ",", "$", "action", "=", "null", ")", "{", "$", "names", "=", "explode", "(", "'_'", ",", "$", "name", ")", ";", "array_unshift", "(", "$", "names", ",", "'Controller'", ")", ";", "$", "base", "=", "join", "(", "DS", ",", "array_map", "(", "'ucfirst'", ",", "$", "names", ")", ")", ".", "'Controller.php'", ";", "$", "file", "=", "$", "this", "->", "loader", "->", "findFirst", "(", "$", "base", ")", ";", "if", "(", "$", "file", ")", "{", "$", "class", "=", "$", "file", "->", "getClassName", "(", ")", ";", "if", "(", "!", "$", "action", "&&", "class_exists", "(", "$", "class", ")", ")", "return", "true", ";", "$", "action", "=", "$", "this", "->", "actionNameStrategy", "(", "$", "action", ")", ";", "if", "(", "method_exists", "(", "$", "class", ",", "$", "action", ")", ")", "return", "true", ";", "}", "return", "false", ";", "}" ]
has controller ? @param string $name @param string $action @return boolean
[ "has", "controller", "?" ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L185-L201
4,130
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.getErrorListByName
public function getErrorListByName($controller, $action = null) { $position = $this->getPositionByName($controller, $action); if (is_integer($position)) { if (! isset($this->errors[$position])) $this->errors[$position] = new ErrorList(); return $this->errors[$position]; } }
php
public function getErrorListByName($controller, $action = null) { $position = $this->getPositionByName($controller, $action); if (is_integer($position)) { if (! isset($this->errors[$position])) $this->errors[$position] = new ErrorList(); return $this->errors[$position]; } }
[ "public", "function", "getErrorListByName", "(", "$", "controller", ",", "$", "action", "=", "null", ")", "{", "$", "position", "=", "$", "this", "->", "getPositionByName", "(", "$", "controller", ",", "$", "action", ")", ";", "if", "(", "is_integer", "(", "$", "position", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "errors", "[", "$", "position", "]", ")", ")", "$", "this", "->", "errors", "[", "$", "position", "]", "=", "new", "ErrorList", "(", ")", ";", "return", "$", "this", "->", "errors", "[", "$", "position", "]", ";", "}", "}" ]
get error list by name @param string $controller @param string $action @return Samurai\Samurai\Component\Core\ErrorList
[ "get", "error", "list", "by", "name" ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L223-L230
4,131
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.getErrorLists
public function getErrorLists() { $names = array_values($this->action_names); $errors = []; foreach ($names as $name) { $errors[$name] = $this->getErrorListByName($name); } return $errors; }
php
public function getErrorLists() { $names = array_values($this->action_names); $errors = []; foreach ($names as $name) { $errors[$name] = $this->getErrorListByName($name); } return $errors; }
[ "public", "function", "getErrorLists", "(", ")", "{", "$", "names", "=", "array_values", "(", "$", "this", "->", "action_names", ")", ";", "$", "errors", "=", "[", "]", ";", "foreach", "(", "$", "names", "as", "$", "name", ")", "{", "$", "errors", "[", "$", "name", "]", "=", "$", "this", "->", "getErrorListByName", "(", "$", "name", ")", ";", "}", "return", "$", "errors", ";", "}" ]
get error lists @return array
[ "get", "error", "lists" ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L248-L256
4,132
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.getPositionByName
public function getPositionByName($controller, $action = null) { if ($action === null) { list($controller, $action) = explode('.', $controller); } return array_search("{$controller}.{$action}", $this->action_names); }
php
public function getPositionByName($controller, $action = null) { if ($action === null) { list($controller, $action) = explode('.', $controller); } return array_search("{$controller}.{$action}", $this->action_names); }
[ "public", "function", "getPositionByName", "(", "$", "controller", ",", "$", "action", "=", "null", ")", "{", "if", "(", "$", "action", "===", "null", ")", "{", "list", "(", "$", "controller", ",", "$", "action", ")", "=", "explode", "(", "'.'", ",", "$", "controller", ")", ";", "}", "return", "array_search", "(", "\"{$controller}.{$action}\"", ",", "$", "this", "->", "action_names", ")", ";", "}" ]
get position by name @param string $controller @param string $action @return int
[ "get", "position", "by", "name" ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L266-L272
4,133
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.controllerClassNameStrategy
public function controllerClassNameStrategy($name) { $names = explode('_', $name); $names = array_map('ucfirst', $names); return join('\\', $names) . 'Controller'; }
php
public function controllerClassNameStrategy($name) { $names = explode('_', $name); $names = array_map('ucfirst', $names); return join('\\', $names) . 'Controller'; }
[ "public", "function", "controllerClassNameStrategy", "(", "$", "name", ")", "{", "$", "names", "=", "explode", "(", "'_'", ",", "$", "name", ")", ";", "$", "names", "=", "array_map", "(", "'ucfirst'", ",", "$", "names", ")", ";", "return", "join", "(", "'\\\\'", ",", "$", "names", ")", ".", "'Controller'", ";", "}" ]
controller class name strategy @param string $name @return string
[ "controller", "class", "name", "strategy" ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L281-L286
4,134
samurai-fw/samurai
src/Samurai/Component/Core/ActionChain.php
ActionChain.actionNameStrategy
public function actionNameStrategy($name) { $names = explode('_', $name); $names = array_map('ucfirst', $names); return lcfirst(join('', $names)) . 'Action'; }
php
public function actionNameStrategy($name) { $names = explode('_', $name); $names = array_map('ucfirst', $names); return lcfirst(join('', $names)) . 'Action'; }
[ "public", "function", "actionNameStrategy", "(", "$", "name", ")", "{", "$", "names", "=", "explode", "(", "'_'", ",", "$", "name", ")", ";", "$", "names", "=", "array_map", "(", "'ucfirst'", ",", "$", "names", ")", ";", "return", "lcfirst", "(", "join", "(", "''", ",", "$", "names", ")", ")", ".", "'Action'", ";", "}" ]
action name strategy @param string $name @return string
[ "action", "name", "strategy" ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Core/ActionChain.php#L295-L300
4,135
osflab/session
AppSession.php
AppSession.checkStarted
protected function checkStarted(): bool { if (!$this->started) { $this->started = self::sessionStart(); } if (isset($_SESSION[$this->namespace]) && !is_array($_SESSION[$this->namespace])) { $_SESSION[$this->namespace] = []; } return (bool) $this->started; }
php
protected function checkStarted(): bool { if (!$this->started) { $this->started = self::sessionStart(); } if (isset($_SESSION[$this->namespace]) && !is_array($_SESSION[$this->namespace])) { $_SESSION[$this->namespace] = []; } return (bool) $this->started; }
[ "protected", "function", "checkStarted", "(", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "started", ")", "{", "$", "this", "->", "started", "=", "self", "::", "sessionStart", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "_SESSION", "[", "$", "this", "->", "namespace", "]", ")", "&&", "!", "is_array", "(", "$", "_SESSION", "[", "$", "this", "->", "namespace", "]", ")", ")", "{", "$", "_SESSION", "[", "$", "this", "->", "namespace", "]", "=", "[", "]", ";", "}", "return", "(", "bool", ")", "$", "this", "->", "started", ";", "}" ]
Check if session started, if not start it @return bool
[ "Check", "if", "session", "started", "if", "not", "start", "it" ]
d4a0d28a8ed3e43edcc335aee084da21b2bd6402
https://github.com/osflab/session/blob/d4a0d28a8ed3e43edcc335aee084da21b2bd6402/AppSession.php#L40-L49
4,136
phlexible/phlexible
src/Phlexible/Bundle/UserBundle/Entity/User.php
User.addProperties
public function addProperties($properties) { foreach ($properties as $key => $value) { $this->setProperty($key, $value); } return $this; }
php
public function addProperties($properties) { foreach ($properties as $key => $value) { $this->setProperty($key, $value); } return $this; }
[ "public", "function", "addProperties", "(", "$", "properties", ")", "{", "foreach", "(", "$", "properties", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "setProperty", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add properties. @param array $properties @return $this
[ "Add", "properties", "." ]
132f24924c9bb0dbb6c1ea84db0a463f97fa3893
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/UserBundle/Entity/User.php#L309-L316
4,137
headzoo/core
src/Headzoo/Core/Obj.php
Obj.getNamespaceName
public function getNamespaceName() { $caller = get_called_class(); $parts = explode('\\', $caller); array_pop($parts); return join('\\', $parts); }
php
public function getNamespaceName() { $caller = get_called_class(); $parts = explode('\\', $caller); array_pop($parts); return join('\\', $parts); }
[ "public", "function", "getNamespaceName", "(", ")", "{", "$", "caller", "=", "get_called_class", "(", ")", ";", "$", "parts", "=", "explode", "(", "'\\\\'", ",", "$", "caller", ")", ";", "array_pop", "(", "$", "parts", ")", ";", "return", "join", "(", "'\\\\'", ",", "$", "parts", ")", ";", "}" ]
Returns the name of the class namespace The namespace will not have a leading forward-slash, eg "Headzoo\Core" instead of "\Headzoo\Core". An empty string is returned when the class is in the global namespace. @return string
[ "Returns", "the", "name", "of", "the", "class", "namespace" ]
1e574813e197aa827b3e952f8caa81be31a8b5b5
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Obj.php#L28-L35
4,138
headzoo/core
src/Headzoo/Core/Obj.php
Obj.toss
protected static function toss(/** @noinspection PhpUnusedParameterInspection */ $exception, $message, $code = 0) { $args = array_values(get_defined_vars()); foreach(func_get_args() as $i => $value) { $args[$i] = $value; } list($exception, $message, $code) = array_splice($args, 0, 3); $exception = self::getNamespaceName() . "\\Exceptions\\{$exception}"; if (strpos($exception, 'Headzoo\Core\\') === 0 && substr($exception, -9) != "Exception") { $exception .= "Exception"; } if (!is_int($code)) { array_unshift($args, $code); $code = 0; } $placeholders = array_merge($args, [ "me" => get_called_class(), "exception" => $exception, "code" => $code, "date" => date("Y-m-d H:i:s") ]); $message = self::interpolate($message, $placeholders); throw new $exception( $message, $code ); }
php
protected static function toss(/** @noinspection PhpUnusedParameterInspection */ $exception, $message, $code = 0) { $args = array_values(get_defined_vars()); foreach(func_get_args() as $i => $value) { $args[$i] = $value; } list($exception, $message, $code) = array_splice($args, 0, 3); $exception = self::getNamespaceName() . "\\Exceptions\\{$exception}"; if (strpos($exception, 'Headzoo\Core\\') === 0 && substr($exception, -9) != "Exception") { $exception .= "Exception"; } if (!is_int($code)) { array_unshift($args, $code); $code = 0; } $placeholders = array_merge($args, [ "me" => get_called_class(), "exception" => $exception, "code" => $code, "date" => date("Y-m-d H:i:s") ]); $message = self::interpolate($message, $placeholders); throw new $exception( $message, $code ); }
[ "protected", "static", "function", "toss", "(", "/** @noinspection PhpUnusedParameterInspection */", "$", "exception", ",", "$", "message", ",", "$", "code", "=", "0", ")", "{", "$", "args", "=", "array_values", "(", "get_defined_vars", "(", ")", ")", ";", "foreach", "(", "func_get_args", "(", ")", "as", "$", "i", "=>", "$", "value", ")", "{", "$", "args", "[", "$", "i", "]", "=", "$", "value", ";", "}", "list", "(", "$", "exception", ",", "$", "message", ",", "$", "code", ")", "=", "array_splice", "(", "$", "args", ",", "0", ",", "3", ")", ";", "$", "exception", "=", "self", "::", "getNamespaceName", "(", ")", ".", "\"\\\\Exceptions\\\\{$exception}\"", ";", "if", "(", "strpos", "(", "$", "exception", ",", "'Headzoo\\Core\\\\'", ")", "===", "0", "&&", "substr", "(", "$", "exception", ",", "-", "9", ")", "!=", "\"Exception\"", ")", "{", "$", "exception", ".=", "\"Exception\"", ";", "}", "if", "(", "!", "is_int", "(", "$", "code", ")", ")", "{", "array_unshift", "(", "$", "args", ",", "$", "code", ")", ";", "$", "code", "=", "0", ";", "}", "$", "placeholders", "=", "array_merge", "(", "$", "args", ",", "[", "\"me\"", "=>", "get_called_class", "(", ")", ",", "\"exception\"", "=>", "$", "exception", ",", "\"code\"", "=>", "$", "code", ",", "\"date\"", "=>", "date", "(", "\"Y-m-d H:i:s\"", ")", "]", ")", ";", "$", "message", "=", "self", "::", "interpolate", "(", "$", "message", ",", "$", "placeholders", ")", ";", "throw", "new", "$", "exception", "(", "$", "message", ",", "$", "code", ")", ";", "}" ]
Throws an exception from the calling class namespace Examples: ```php // If the calling class namespace is Headzoo\Core this call will throw an // instance of Headzoo\Core\Exceptions\InvalidArgumentException with the // given message. $this->toss("InvalidArgumentException", "There was an error."); // Additional context arguments may be passed to the method which will be interpolated // into the message. The interpolater looks for numerically indexed place holders, // eg {0}, {1}, etc, which map to the extra arguments. This means the context arguments // may be given in any order. $this->toss("RuntimeException", "The {0} system broke.", "database"); // The context interpolater has a few built-in place holders. The "{me}" place holder // will be replaced with the name of the class which threw the exception. Additional // context arguments are inserted into the message per their index. $this->toss("RuntimeException", "The {me} class reported a {0} error.", "serious"); // When the first argument after the message is an integer, it will be used as the // exception code. This call will throw an instance of // Headzoo\Core\Exceptions\RuntimeException with the message "There was an error", // and the error code 43. $this->toss("RuntimeException", "There was an error.", 43); // This call is giving an exception code, and context arguments for interpolation. // Remember when the first argument after the message is an integer, it's treated as // the error code. When you need a number to be interpolated into the message, cast // it to a string. $this->toss("RuntimeException", "There was a {0} error", 43, "database"); // For exceptions in the Headzoo\Core namespace, the word "Exception" in the name // of the exception is optional. $this->toss("InvalidArgument", "There was an error."); $this->toss("Runtime", "The {0} system broke.", "database"); ``` The built in place holders: {me} - The name of the class throwing the exception {exception} - The name of the exception being thrown {code} - The exception code {date} - The date the exception was thrown @param string $exception The name of the exception to throw @param string $message The error message @param int $code The error code, defaults to 0 @param ... $args One or more context arguments to interpolate into the message
[ "Throws", "an", "exception", "from", "the", "calling", "class", "namespace" ]
1e574813e197aa827b3e952f8caa81be31a8b5b5
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Obj.php#L87-L115
4,139
CatLabInteractive/Neuron
src/Neuron/DB/Query.php
Query.select
public static function select ( $table, array $data = array(), array $where = array(), $order = array(), $limit = null ) { $query = 'SELECT '; $values = array (); if (count ($data) > 0) { foreach ($data as $v) { $query .= $v . ', '; } $query = substr ($query, 0, -2) . ' '; } else { $query .= '* '; } $query .= 'FROM ' . self::escapeTableName($table) . ' '; $query .= self::processWhere ($where, $values); // Order if (count ($order) > 0) { $query .= " ORDER BY "; foreach ($order as $v) { $query .= $v . ", "; } $query = substr ($query, 0, -2); } // Limit if ($limit) { $query .= " LIMIT " . $limit; } $query = new self($query); $query->bindValues($values); return $query; }
php
public static function select ( $table, array $data = array(), array $where = array(), $order = array(), $limit = null ) { $query = 'SELECT '; $values = array (); if (count ($data) > 0) { foreach ($data as $v) { $query .= $v . ', '; } $query = substr ($query, 0, -2) . ' '; } else { $query .= '* '; } $query .= 'FROM ' . self::escapeTableName($table) . ' '; $query .= self::processWhere ($where, $values); // Order if (count ($order) > 0) { $query .= " ORDER BY "; foreach ($order as $v) { $query .= $v . ", "; } $query = substr ($query, 0, -2); } // Limit if ($limit) { $query .= " LIMIT " . $limit; } $query = new self($query); $query->bindValues($values); return $query; }
[ "public", "static", "function", "select", "(", "$", "table", ",", "array", "$", "data", "=", "array", "(", ")", ",", "array", "$", "where", "=", "array", "(", ")", ",", "$", "order", "=", "array", "(", ")", ",", "$", "limit", "=", "null", ")", "{", "$", "query", "=", "'SELECT '", ";", "$", "values", "=", "array", "(", ")", ";", "if", "(", "count", "(", "$", "data", ")", ">", "0", ")", "{", "foreach", "(", "$", "data", "as", "$", "v", ")", "{", "$", "query", ".=", "$", "v", ".", "', '", ";", "}", "$", "query", "=", "substr", "(", "$", "query", ",", "0", ",", "-", "2", ")", ".", "' '", ";", "}", "else", "{", "$", "query", ".=", "'* '", ";", "}", "$", "query", ".=", "'FROM '", ".", "self", "::", "escapeTableName", "(", "$", "table", ")", ".", "' '", ";", "$", "query", ".=", "self", "::", "processWhere", "(", "$", "where", ",", "$", "values", ")", ";", "// Order", "if", "(", "count", "(", "$", "order", ")", ">", "0", ")", "{", "$", "query", ".=", "\" ORDER BY \"", ";", "foreach", "(", "$", "order", "as", "$", "v", ")", "{", "$", "query", ".=", "$", "v", ".", "\", \"", ";", "}", "$", "query", "=", "substr", "(", "$", "query", ",", "0", ",", "-", "2", ")", ";", "}", "// Limit", "if", "(", "$", "limit", ")", "{", "$", "query", ".=", "\" LIMIT \"", ".", "$", "limit", ";", "}", "$", "query", "=", "new", "self", "(", "$", "query", ")", ";", "$", "query", "->", "bindValues", "(", "$", "values", ")", ";", "return", "$", "query", ";", "}" ]
Select data from a message @param $table @param array $data : array of column names [ column1, column2 ] @param array $where : a 2 dimensional array with syntax: { column_name : [ value, type, nullOnEmpty ]} @param array $order @param null $limit @return Query
[ "Select", "data", "from", "a", "message" ]
67dca5349891e23b31a96dcdead893b9491a1b8b
https://github.com/CatLabInteractive/Neuron/blob/67dca5349891e23b31a96dcdead893b9491a1b8b/src/Neuron/DB/Query.php#L191-L231
4,140
silverorange/Net_Notifier
Net/Notifier/Sender.php
Net_Notifier_Sender.send
public function send($action, array $data = array()) { $message = array('action' => $action); if (count($data) > 0) { $message['data'] = $data; } $message = json_encode($message); $this->connect(); $this->connection->writeText($message); $this->disconnect(); return $this; }
php
public function send($action, array $data = array()) { $message = array('action' => $action); if (count($data) > 0) { $message['data'] = $data; } $message = json_encode($message); $this->connect(); $this->connection->writeText($message); $this->disconnect(); return $this; }
[ "public", "function", "send", "(", "$", "action", ",", "array", "$", "data", "=", "array", "(", ")", ")", "{", "$", "message", "=", "array", "(", "'action'", "=>", "$", "action", ")", ";", "if", "(", "count", "(", "$", "data", ")", ">", "0", ")", "{", "$", "message", "[", "'data'", "]", "=", "$", "data", ";", "}", "$", "message", "=", "json_encode", "(", "$", "message", ")", ";", "$", "this", "->", "connect", "(", ")", ";", "$", "this", "->", "connection", "->", "writeText", "(", "$", "message", ")", ";", "$", "this", "->", "disconnect", "(", ")", ";", "return", "$", "this", ";", "}" ]
Connects to the WebSocket server, sends a text message and disconnects @param string $action the notification action. @param array $data optional. The notification data. @return Net_Notifier_Sender the current object, for fluent interface. @throws Net_Notifier_ClientException if there is an error connecting to the notification server or sending the message.
[ "Connects", "to", "the", "WebSocket", "server", "sends", "a", "text", "message", "and", "disconnects" ]
b446e27cd1bebd58ba89243cde1272c5d281d3fb
https://github.com/silverorange/Net_Notifier/blob/b446e27cd1bebd58ba89243cde1272c5d281d3fb/Net/Notifier/Sender.php#L59-L74
4,141
flowcode/roble
src/flowcode/roble/form/BaseForm.php
BaseForm.isValid
public function isValid() { $valid = TRUE; foreach ($this->fields as $key => $field) { // required if ($field->getOption("required") && $field->getValue() == "") { $this->errors[$key] = "Requerido"; $valid = FALSE; } // custom validators if (isset($this->validators[$key])) { foreach ($this->validators[$key] as $validator) { $validator->validate($field); if (!$validator->isValid()) { $this->errors[$key] = $validator->getMessage(); $valid = FALSE; } } } } return $valid; }
php
public function isValid() { $valid = TRUE; foreach ($this->fields as $key => $field) { // required if ($field->getOption("required") && $field->getValue() == "") { $this->errors[$key] = "Requerido"; $valid = FALSE; } // custom validators if (isset($this->validators[$key])) { foreach ($this->validators[$key] as $validator) { $validator->validate($field); if (!$validator->isValid()) { $this->errors[$key] = $validator->getMessage(); $valid = FALSE; } } } } return $valid; }
[ "public", "function", "isValid", "(", ")", "{", "$", "valid", "=", "TRUE", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "key", "=>", "$", "field", ")", "{", "// required", "if", "(", "$", "field", "->", "getOption", "(", "\"required\"", ")", "&&", "$", "field", "->", "getValue", "(", ")", "==", "\"\"", ")", "{", "$", "this", "->", "errors", "[", "$", "key", "]", "=", "\"Requerido\"", ";", "$", "valid", "=", "FALSE", ";", "}", "// custom validators", "if", "(", "isset", "(", "$", "this", "->", "validators", "[", "$", "key", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "validators", "[", "$", "key", "]", "as", "$", "validator", ")", "{", "$", "validator", "->", "validate", "(", "$", "field", ")", ";", "if", "(", "!", "$", "validator", "->", "isValid", "(", ")", ")", "{", "$", "this", "->", "errors", "[", "$", "key", "]", "=", "$", "validator", "->", "getMessage", "(", ")", ";", "$", "valid", "=", "FALSE", ";", "}", "}", "}", "}", "return", "$", "valid", ";", "}" ]
Verify each field with its correspondant validator, if exist. @return boolean
[ "Verify", "each", "field", "with", "its", "correspondant", "validator", "if", "exist", "." ]
f9a58309168b0143a5ed9fadad4cc29451766c26
https://github.com/flowcode/roble/blob/f9a58309168b0143a5ed9fadad4cc29451766c26/src/flowcode/roble/form/BaseForm.php#L67-L91
4,142
flowcode/roble
src/flowcode/roble/form/BaseForm.php
BaseForm.bind
public function bind($array) { foreach ($array as $fieldname => $value) { if ($this->getField($fieldname) != "") $this->getField($fieldname)->setValue($value); } }
php
public function bind($array) { foreach ($array as $fieldname => $value) { if ($this->getField($fieldname) != "") $this->getField($fieldname)->setValue($value); } }
[ "public", "function", "bind", "(", "$", "array", ")", "{", "foreach", "(", "$", "array", "as", "$", "fieldname", "=>", "$", "value", ")", "{", "if", "(", "$", "this", "->", "getField", "(", "$", "fieldname", ")", "!=", "\"\"", ")", "$", "this", "->", "getField", "(", "$", "fieldname", ")", "->", "setValue", "(", "$", "value", ")", ";", "}", "}" ]
Bind each array value with the form field. @param type $array
[ "Bind", "each", "array", "value", "with", "the", "form", "field", "." ]
f9a58309168b0143a5ed9fadad4cc29451766c26
https://github.com/flowcode/roble/blob/f9a58309168b0143a5ed9fadad4cc29451766c26/src/flowcode/roble/form/BaseForm.php#L97-L102
4,143
Stratadox/HydrationMapper
src/Instruction/Relation/Relationship.php
Relationship.keyOr
protected function keyOr(string $property): string { return $this->key ? $this->key->find() : $property; }
php
protected function keyOr(string $property): string { return $this->key ? $this->key->find() : $property; }
[ "protected", "function", "keyOr", "(", "string", "$", "property", ")", ":", "string", "{", "return", "$", "this", "->", "key", "?", "$", "this", "->", "key", "->", "find", "(", ")", ":", "$", "property", ";", "}" ]
Returns the key if one was provided, defaulting to the property name. @param string $property The property name to use as fallback. @return string The key to use as offset for the input data.
[ "Returns", "the", "key", "if", "one", "was", "provided", "defaulting", "to", "the", "property", "name", "." ]
d9bf1f10b7626312e0a2466a2ef255ec972acb41
https://github.com/Stratadox/HydrationMapper/blob/d9bf1f10b7626312e0a2466a2ef255ec972acb41/src/Instruction/Relation/Relationship.php#L133-L136
4,144
Stratadox/HydrationMapper
src/Instruction/Relation/Relationship.php
Relationship.hydrator
protected function hydrator(): Hydrates { if (isset($this->decisionKey)) { return $this->choiceHydrator(); } $mapped = Mapper::forThe($this->class); foreach ($this->properties as $property => $instruction) { $mapped = $mapped->property($property, $instruction); } return $mapped->finish(); }
php
protected function hydrator(): Hydrates { if (isset($this->decisionKey)) { return $this->choiceHydrator(); } $mapped = Mapper::forThe($this->class); foreach ($this->properties as $property => $instruction) { $mapped = $mapped->property($property, $instruction); } return $mapped->finish(); }
[ "protected", "function", "hydrator", "(", ")", ":", "Hydrates", "{", "if", "(", "isset", "(", "$", "this", "->", "decisionKey", ")", ")", "{", "return", "$", "this", "->", "choiceHydrator", "(", ")", ";", "}", "$", "mapped", "=", "Mapper", "::", "forThe", "(", "$", "this", "->", "class", ")", ";", "foreach", "(", "$", "this", "->", "properties", "as", "$", "property", "=>", "$", "instruction", ")", "{", "$", "mapped", "=", "$", "mapped", "->", "property", "(", "$", "property", ",", "$", "instruction", ")", ";", "}", "return", "$", "mapped", "->", "finish", "(", ")", ";", "}" ]
Produces a mapped hydrator according to the relationship configuration. @return Hydrates The hydrator for the relationship mapping. @throws InvalidMapperConfiguration
[ "Produces", "a", "mapped", "hydrator", "according", "to", "the", "relationship", "configuration", "." ]
d9bf1f10b7626312e0a2466a2ef255ec972acb41
https://github.com/Stratadox/HydrationMapper/blob/d9bf1f10b7626312e0a2466a2ef255ec972acb41/src/Instruction/Relation/Relationship.php#L144-L154
4,145
Stratadox/HydrationMapper
src/Instruction/Relation/Relationship.php
Relationship.choiceHydrator
private function choiceHydrator(): Hydrates { assert(isset($this->decisionKey)); return OneOfTheseHydrators::decideBasedOnThe( $this->decisionKey, array_map(function (RepresentsChoice $choice): Hydrates { return $choice->finish(); }, $this->choices) ); }
php
private function choiceHydrator(): Hydrates { assert(isset($this->decisionKey)); return OneOfTheseHydrators::decideBasedOnThe( $this->decisionKey, array_map(function (RepresentsChoice $choice): Hydrates { return $choice->finish(); }, $this->choices) ); }
[ "private", "function", "choiceHydrator", "(", ")", ":", "Hydrates", "{", "assert", "(", "isset", "(", "$", "this", "->", "decisionKey", ")", ")", ";", "return", "OneOfTheseHydrators", "::", "decideBasedOnThe", "(", "$", "this", "->", "decisionKey", ",", "array_map", "(", "function", "(", "RepresentsChoice", "$", "choice", ")", ":", "Hydrates", "{", "return", "$", "choice", "->", "finish", "(", ")", ";", "}", ",", "$", "this", "->", "choices", ")", ")", ";", "}" ]
Produces a multiple-choice hydrator. @return Hydrates The adapter that selects the hydrator. @throws InvalidMapperConfiguration
[ "Produces", "a", "multiple", "-", "choice", "hydrator", "." ]
d9bf1f10b7626312e0a2466a2ef255ec972acb41
https://github.com/Stratadox/HydrationMapper/blob/d9bf1f10b7626312e0a2466a2ef255ec972acb41/src/Instruction/Relation/Relationship.php#L170-L179
4,146
razielsd/webdriverlib
WebDriver/WebDriver/Object/Frame.php
WebDriver_Object_Frame.focus
public function focus($frameId=null) { if ($frameId instanceof WebDriver_Element) { $frameId = $frameId->getReference(); } $params = [ 'id' => $frameId ]; $command = $this->driver->factoryCommand( 'frame', WebDriver_Command::METHOD_POST, $params ); return $this->driver->curl($command)['value']; }
php
public function focus($frameId=null) { if ($frameId instanceof WebDriver_Element) { $frameId = $frameId->getReference(); } $params = [ 'id' => $frameId ]; $command = $this->driver->factoryCommand( 'frame', WebDriver_Command::METHOD_POST, $params ); return $this->driver->curl($command)['value']; }
[ "public", "function", "focus", "(", "$", "frameId", "=", "null", ")", "{", "if", "(", "$", "frameId", "instanceof", "WebDriver_Element", ")", "{", "$", "frameId", "=", "$", "frameId", "->", "getReference", "(", ")", ";", "}", "$", "params", "=", "[", "'id'", "=>", "$", "frameId", "]", ";", "$", "command", "=", "$", "this", "->", "driver", "->", "factoryCommand", "(", "'frame'", ",", "WebDriver_Command", "::", "METHOD_POST", ",", "$", "params", ")", ";", "return", "$", "this", "->", "driver", "->", "curl", "(", "$", "command", ")", "[", "'value'", "]", ";", "}" ]
Change focus to another frame on the page. If the frame id is null, the server should switch to the page's default content.
[ "Change", "focus", "to", "another", "frame", "on", "the", "page", ".", "If", "the", "frame", "id", "is", "null", "the", "server", "should", "switch", "to", "the", "page", "s", "default", "content", "." ]
e498afc36a8cdeab5b6ca95016420557baf32f36
https://github.com/razielsd/webdriverlib/blob/e498afc36a8cdeab5b6ca95016420557baf32f36/WebDriver/WebDriver/Object/Frame.php#L9-L23
4,147
razielsd/webdriverlib
WebDriver/WebDriver/Object/Frame.php
WebDriver_Object_Frame.parent
public function parent() { $command = $this->driver->factoryCommand( 'frame/parent', WebDriver_Command::METHOD_POST ); return $this->driver->curl($command)['value']; }
php
public function parent() { $command = $this->driver->factoryCommand( 'frame/parent', WebDriver_Command::METHOD_POST ); return $this->driver->curl($command)['value']; }
[ "public", "function", "parent", "(", ")", "{", "$", "command", "=", "$", "this", "->", "driver", "->", "factoryCommand", "(", "'frame/parent'", ",", "WebDriver_Command", "::", "METHOD_POST", ")", ";", "return", "$", "this", "->", "driver", "->", "curl", "(", "$", "command", ")", "[", "'value'", "]", ";", "}" ]
Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged.
[ "Change", "focus", "to", "the", "parent", "context", ".", "If", "the", "current", "context", "is", "the", "top", "level", "browsing", "context", "the", "context", "remains", "unchanged", "." ]
e498afc36a8cdeab5b6ca95016420557baf32f36
https://github.com/razielsd/webdriverlib/blob/e498afc36a8cdeab5b6ca95016420557baf32f36/WebDriver/WebDriver/Object/Frame.php#L30-L38
4,148
tekkla/core-security
Core/Security/Token/SessionToken.php
SessionToken.generate
public function generate(): string { $this->token = hash('sha256', $this->generateRandomToken()); $this->session[$this->name] = $this->token; return $this->token; }
php
public function generate(): string { $this->token = hash('sha256', $this->generateRandomToken()); $this->session[$this->name] = $this->token; return $this->token; }
[ "public", "function", "generate", "(", ")", ":", "string", "{", "$", "this", "->", "token", "=", "hash", "(", "'sha256'", ",", "$", "this", "->", "generateRandomToken", "(", ")", ")", ";", "$", "this", "->", "session", "[", "$", "this", "->", "name", "]", "=", "$", "this", "->", "token", ";", "return", "$", "this", "->", "token", ";", "}" ]
Generates a token, stores it in the set session reference and returns the token The token gets stored in $_SESSION['Core']['Security']['session.token'] by default. @return string
[ "Generates", "a", "token", "stores", "it", "in", "the", "set", "session", "reference", "and", "returns", "the", "token" ]
66a09ca63a2f5a2239ea7537d2d6bdaa89b0a582
https://github.com/tekkla/core-security/blob/66a09ca63a2f5a2239ea7537d2d6bdaa89b0a582/Core/Security/Token/SessionToken.php#L94-L100
4,149
xobotyi/vxn
src/Vxn/Helper/Str.php
Str.HashFromInt
public static function HashFromInt($num, int $seed = 5421087) :string { $scrambled = (324863748635 * $num + $seed) % 2654348974297586158321; $res = ''; while ($scrambled) { $res = self::BASE62_POOL[$scrambled % self::BASE62_BASE] . $res; $scrambled = intdiv($scrambled, self::BASE62_BASE); } $res = str_repeat('0', 12 - strlen($res)) . $res; return $res; }
php
public static function HashFromInt($num, int $seed = 5421087) :string { $scrambled = (324863748635 * $num + $seed) % 2654348974297586158321; $res = ''; while ($scrambled) { $res = self::BASE62_POOL[$scrambled % self::BASE62_BASE] . $res; $scrambled = intdiv($scrambled, self::BASE62_BASE); } $res = str_repeat('0', 12 - strlen($res)) . $res; return $res; }
[ "public", "static", "function", "HashFromInt", "(", "$", "num", ",", "int", "$", "seed", "=", "5421087", ")", ":", "string", "{", "$", "scrambled", "=", "(", "324863748635", "*", "$", "num", "+", "$", "seed", ")", "%", "2654348974297586158321", ";", "$", "res", "=", "''", ";", "while", "(", "$", "scrambled", ")", "{", "$", "res", "=", "self", "::", "BASE62_POOL", "[", "$", "scrambled", "%", "self", "::", "BASE62_BASE", "]", ".", "$", "res", ";", "$", "scrambled", "=", "intdiv", "(", "$", "scrambled", ",", "self", "::", "BASE62_BASE", ")", ";", "}", "$", "res", "=", "str_repeat", "(", "'0'", ",", "12", "-", "strlen", "(", "$", "res", ")", ")", ".", "$", "res", ";", "return", "$", "res", ";", "}" ]
Pseudo-random string generator can provide 62^12 unique strings Generated string has length of 12, "z" char uses to fill generated char to 12 chars length @param int|float $num @param int $seed @return string
[ "Pseudo", "-", "random", "string", "generator", "can", "provide", "62^12", "unique", "strings", "Generated", "string", "has", "length", "of", "12", "z", "char", "uses", "to", "fill", "generated", "char", "to", "12", "chars", "length" ]
a6a8edb620ddfd10e3347eceaccce1e00763aff7
https://github.com/xobotyi/vxn/blob/a6a8edb620ddfd10e3347eceaccce1e00763aff7/src/Vxn/Helper/Str.php#L53-L67
4,150
Holdlang/annotationscanner
src/AnnotationScanner.php
AnnotationScanner.startScan
public function startScan() { //First we get all the files we need form the directories $this->scanPaths(); //Then we get the the annotations from the corresponding namespace and class name $annotations = $this->scanFileListForAnnotations(); //Converting to collections $annotations = collect($annotations)->mapWithKeys( function ($annotations, $className) { return [$className => $annotations]; } ); $this->setAnnotations($annotations); }
php
public function startScan() { //First we get all the files we need form the directories $this->scanPaths(); //Then we get the the annotations from the corresponding namespace and class name $annotations = $this->scanFileListForAnnotations(); //Converting to collections $annotations = collect($annotations)->mapWithKeys( function ($annotations, $className) { return [$className => $annotations]; } ); $this->setAnnotations($annotations); }
[ "public", "function", "startScan", "(", ")", "{", "//First we get all the files we need form the directories", "$", "this", "->", "scanPaths", "(", ")", ";", "//Then we get the the annotations from the corresponding namespace and class name", "$", "annotations", "=", "$", "this", "->", "scanFileListForAnnotations", "(", ")", ";", "//Converting to collections", "$", "annotations", "=", "collect", "(", "$", "annotations", ")", "->", "mapWithKeys", "(", "function", "(", "$", "annotations", ",", "$", "className", ")", "{", "return", "[", "$", "className", "=>", "$", "annotations", "]", ";", "}", ")", ";", "$", "this", "->", "setAnnotations", "(", "$", "annotations", ")", ";", "}" ]
Public method for starting the annotation scanner @return void
[ "Public", "method", "for", "starting", "the", "annotation", "scanner" ]
7420b8ae1ab4d8bf9e76a448ea3ea749d6a934c6
https://github.com/Holdlang/annotationscanner/blob/7420b8ae1ab4d8bf9e76a448ea3ea749d6a934c6/src/AnnotationScanner.php#L88-L102
4,151
Holdlang/annotationscanner
src/AnnotationScanner.php
AnnotationScanner.scanPaths
private function scanPaths() { foreach (Finder::create()->files()->in($this->pathsToScan)->name('*.' . $this->fileExtension) as $file) { $this->fileList->push($file->getRealPath()); } }
php
private function scanPaths() { foreach (Finder::create()->files()->in($this->pathsToScan)->name('*.' . $this->fileExtension) as $file) { $this->fileList->push($file->getRealPath()); } }
[ "private", "function", "scanPaths", "(", ")", "{", "foreach", "(", "Finder", "::", "create", "(", ")", "->", "files", "(", ")", "->", "in", "(", "$", "this", "->", "pathsToScan", ")", "->", "name", "(", "'*.'", ".", "$", "this", "->", "fileExtension", ")", "as", "$", "file", ")", "{", "$", "this", "->", "fileList", "->", "push", "(", "$", "file", "->", "getRealPath", "(", ")", ")", ";", "}", "}" ]
We create a Finder instance and check for files recursively in the given directories @return void
[ "We", "create", "a", "Finder", "instance", "and", "check", "for", "files", "recursively", "in", "the", "given", "directories" ]
7420b8ae1ab4d8bf9e76a448ea3ea749d6a934c6
https://github.com/Holdlang/annotationscanner/blob/7420b8ae1ab4d8bf9e76a448ea3ea749d6a934c6/src/AnnotationScanner.php#L109-L114
4,152
Holdlang/annotationscanner
src/AnnotationScanner.php
AnnotationScanner.scanFileListForAnnotations
private function scanFileListForAnnotations() { $annotations = []; foreach ($this->getFileList() as $file) { $this->classListByFiles[$file] = ClassInformationFromFile::getClassesFromFile($file)[0]; $annotations[$this->classListByFiles[$file]] = $this->scanClassForAnnotations( $this->classListByFiles[$file] ); } return $annotations; }
php
private function scanFileListForAnnotations() { $annotations = []; foreach ($this->getFileList() as $file) { $this->classListByFiles[$file] = ClassInformationFromFile::getClassesFromFile($file)[0]; $annotations[$this->classListByFiles[$file]] = $this->scanClassForAnnotations( $this->classListByFiles[$file] ); } return $annotations; }
[ "private", "function", "scanFileListForAnnotations", "(", ")", "{", "$", "annotations", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getFileList", "(", ")", "as", "$", "file", ")", "{", "$", "this", "->", "classListByFiles", "[", "$", "file", "]", "=", "ClassInformationFromFile", "::", "getClassesFromFile", "(", "$", "file", ")", "[", "0", "]", ";", "$", "annotations", "[", "$", "this", "->", "classListByFiles", "[", "$", "file", "]", "]", "=", "$", "this", "->", "scanClassForAnnotations", "(", "$", "this", "->", "classListByFiles", "[", "$", "file", "]", ")", ";", "}", "return", "$", "annotations", ";", "}" ]
Collect necessary Namespaces and Class names form the files and do call the annotation scanner on them. @return array
[ "Collect", "necessary", "Namespaces", "and", "Class", "names", "form", "the", "files", "and", "do", "call", "the", "annotation", "scanner", "on", "them", "." ]
7420b8ae1ab4d8bf9e76a448ea3ea749d6a934c6
https://github.com/Holdlang/annotationscanner/blob/7420b8ae1ab4d8bf9e76a448ea3ea749d6a934c6/src/AnnotationScanner.php#L121-L131
4,153
webriq/core
module/User/src/Grid/User/Model/Paragraph/Structure/Login.php
Login.getDisplay
public function getDisplay() { $display = $this->getServiceLocator() ->get( 'Config' ) [ 'modules' ] [ 'Grid\User' ] [ 'display' ]; if ( null !== $this->displayRegisterLink ) { $display['registerLink'] = (bool) $this->displayRegisterLink; } if ( null !== $this->displayPasswordRequestLink ) { $display['passwordRequestLink'] = (bool) $this->displayPasswordRequestLink; } if ( null !== $this->displayLoginWithLink ) { $display['loginWithLink'] = (bool) $this->displayLoginWithLink; } return $display; }
php
public function getDisplay() { $display = $this->getServiceLocator() ->get( 'Config' ) [ 'modules' ] [ 'Grid\User' ] [ 'display' ]; if ( null !== $this->displayRegisterLink ) { $display['registerLink'] = (bool) $this->displayRegisterLink; } if ( null !== $this->displayPasswordRequestLink ) { $display['passwordRequestLink'] = (bool) $this->displayPasswordRequestLink; } if ( null !== $this->displayLoginWithLink ) { $display['loginWithLink'] = (bool) $this->displayLoginWithLink; } return $display; }
[ "public", "function", "getDisplay", "(", ")", "{", "$", "display", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'Config'", ")", "[", "'modules'", "]", "[", "'Grid\\User'", "]", "[", "'display'", "]", ";", "if", "(", "null", "!==", "$", "this", "->", "displayRegisterLink", ")", "{", "$", "display", "[", "'registerLink'", "]", "=", "(", "bool", ")", "$", "this", "->", "displayRegisterLink", ";", "}", "if", "(", "null", "!==", "$", "this", "->", "displayPasswordRequestLink", ")", "{", "$", "display", "[", "'passwordRequestLink'", "]", "=", "(", "bool", ")", "$", "this", "->", "displayPasswordRequestLink", ";", "}", "if", "(", "null", "!==", "$", "this", "->", "displayLoginWithLink", ")", "{", "$", "display", "[", "'loginWithLink'", "]", "=", "(", "bool", ")", "$", "this", "->", "displayLoginWithLink", ";", "}", "return", "$", "display", ";", "}" ]
Get displayable links @return array
[ "Get", "displayable", "links" ]
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/User/src/Grid/User/Model/Paragraph/Structure/Login.php#L125-L149
4,154
samurai-fw/samurai
src/Samurai/Component/FileSystem/Iterator/SimpleListIterator.php
SimpleListIterator.reverse
public function reverse() { $iterator = new self(); foreach (array_reverse($this->list) as $file) { $iterator->add($file); } return $iterator; }
php
public function reverse() { $iterator = new self(); foreach (array_reverse($this->list) as $file) { $iterator->add($file); } return $iterator; }
[ "public", "function", "reverse", "(", ")", "{", "$", "iterator", "=", "new", "self", "(", ")", ";", "foreach", "(", "array_reverse", "(", "$", "this", "->", "list", ")", "as", "$", "file", ")", "{", "$", "iterator", "->", "add", "(", "$", "file", ")", ";", "}", "return", "$", "iterator", ";", "}" ]
get reversed elements. @access public @return Samurai\Samurai\Component\FileSystem\Iterator\SimpleListIterator
[ "get", "reversed", "elements", "." ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/FileSystem/Iterator/SimpleListIterator.php#L123-L130
4,155
atelierspierrot/library
src/Library/ServiceContainer/ServiceContainer.php
ServiceContainer.init
public function init( array $initial_services = array(), array $services_providers = array(), array $services_protected = array() ) { // object can only be initialized once if (!is_object($this->_services)) { $this->_services = new Collection(); $this->_services_protected = new Collection(); $this->_services_providers = new Collection(); if (!empty($initial_services)) { foreach ($initial_services as $_name=>$_service) { $this->setService($_name, $_service); } } if (!empty($services_providers)) { foreach ($services_providers as $_name=>$_provider) { $this->setProvider($_name, $_provider); } } if (!empty($services_protected)) { foreach ($services_protected as $_name) { $this->setProtected($_name); } } } return $this; }
php
public function init( array $initial_services = array(), array $services_providers = array(), array $services_protected = array() ) { // object can only be initialized once if (!is_object($this->_services)) { $this->_services = new Collection(); $this->_services_protected = new Collection(); $this->_services_providers = new Collection(); if (!empty($initial_services)) { foreach ($initial_services as $_name=>$_service) { $this->setService($_name, $_service); } } if (!empty($services_providers)) { foreach ($services_providers as $_name=>$_provider) { $this->setProvider($_name, $_provider); } } if (!empty($services_protected)) { foreach ($services_protected as $_name) { $this->setProtected($_name); } } } return $this; }
[ "public", "function", "init", "(", "array", "$", "initial_services", "=", "array", "(", ")", ",", "array", "$", "services_providers", "=", "array", "(", ")", ",", "array", "$", "services_protected", "=", "array", "(", ")", ")", "{", "// object can only be initialized once", "if", "(", "!", "is_object", "(", "$", "this", "->", "_services", ")", ")", "{", "$", "this", "->", "_services", "=", "new", "Collection", "(", ")", ";", "$", "this", "->", "_services_protected", "=", "new", "Collection", "(", ")", ";", "$", "this", "->", "_services_providers", "=", "new", "Collection", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "initial_services", ")", ")", "{", "foreach", "(", "$", "initial_services", "as", "$", "_name", "=>", "$", "_service", ")", "{", "$", "this", "->", "setService", "(", "$", "_name", ",", "$", "_service", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "services_providers", ")", ")", "{", "foreach", "(", "$", "services_providers", "as", "$", "_name", "=>", "$", "_provider", ")", "{", "$", "this", "->", "setProvider", "(", "$", "_name", ",", "$", "_provider", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "services_protected", ")", ")", "{", "foreach", "(", "$", "services_protected", "as", "$", "_name", ")", "{", "$", "this", "->", "setProtected", "(", "$", "_name", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Initialize the service container system @param array $initial_services @param array $services_providers @param array $services_protected @return $this
[ "Initialize", "the", "service", "container", "system" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/ServiceContainer/ServiceContainer.php#L73-L100
4,156
atelierspierrot/library
src/Library/ServiceContainer/ServiceContainer.php
ServiceContainer.getProvider
public function getProvider($name) { return $this->hasProvider($name) ? $this->_services_providers->offsetGet($name) : null; }
php
public function getProvider($name) { return $this->hasProvider($name) ? $this->_services_providers->offsetGet($name) : null; }
[ "public", "function", "getProvider", "(", "$", "name", ")", "{", "return", "$", "this", "->", "hasProvider", "(", "$", "name", ")", "?", "$", "this", "->", "_services_providers", "->", "offsetGet", "(", "$", "name", ")", ":", "null", ";", "}" ]
Get a service constructor if it exists @param string $name @return mixed
[ "Get", "a", "service", "constructor", "if", "it", "exists" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/ServiceContainer/ServiceContainer.php#L126-L130
4,157
atelierspierrot/library
src/Library/ServiceContainer/ServiceContainer.php
ServiceContainer.isProtected
public function isProtected($name) { return (bool) ( $this->_services_protected->offsetExists($name) && $this->_services_protected->offsetGet($name)===true ); }
php
public function isProtected($name) { return (bool) ( $this->_services_protected->offsetExists($name) && $this->_services_protected->offsetGet($name)===true ); }
[ "public", "function", "isProtected", "(", "$", "name", ")", "{", "return", "(", "bool", ")", "(", "$", "this", "->", "_services_protected", "->", "offsetExists", "(", "$", "name", ")", "&&", "$", "this", "->", "_services_protected", "->", "offsetGet", "(", "$", "name", ")", "===", "true", ")", ";", "}" ]
Test if a service is protected @param string $name @return bool
[ "Test", "if", "a", "service", "is", "protected" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/ServiceContainer/ServiceContainer.php#L161-L167
4,158
atelierspierrot/library
src/Library/ServiceContainer/ServiceContainer.php
ServiceContainer.unsetService
public function unsetService($name) { if ($this->hasService($name)) { if (!$this->isProtected($name)) { if ($this->hasProvider($name)) { $data = $this->getProvider($name); if (is_object($data) && CodeHelper::implementsInterface($data, 'Library\ServiceContainer\ServiceProviderInterface')) { $data->terminate($this); } } $this->_services->offsetUnset($name); } else { throw new ErrorException( sprintf('Cannot unset protected service "%s"!', $name) ); } } return $this; }
php
public function unsetService($name) { if ($this->hasService($name)) { if (!$this->isProtected($name)) { if ($this->hasProvider($name)) { $data = $this->getProvider($name); if (is_object($data) && CodeHelper::implementsInterface($data, 'Library\ServiceContainer\ServiceProviderInterface')) { $data->terminate($this); } } $this->_services->offsetUnset($name); } else { throw new ErrorException( sprintf('Cannot unset protected service "%s"!', $name) ); } } return $this; }
[ "public", "function", "unsetService", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "hasService", "(", "$", "name", ")", ")", "{", "if", "(", "!", "$", "this", "->", "isProtected", "(", "$", "name", ")", ")", "{", "if", "(", "$", "this", "->", "hasProvider", "(", "$", "name", ")", ")", "{", "$", "data", "=", "$", "this", "->", "getProvider", "(", "$", "name", ")", ";", "if", "(", "is_object", "(", "$", "data", ")", "&&", "CodeHelper", "::", "implementsInterface", "(", "$", "data", ",", "'Library\\ServiceContainer\\ServiceProviderInterface'", ")", ")", "{", "$", "data", "->", "terminate", "(", "$", "this", ")", ";", "}", "}", "$", "this", "->", "_services", "->", "offsetUnset", "(", "$", "name", ")", ";", "}", "else", "{", "throw", "new", "ErrorException", "(", "sprintf", "(", "'Cannot unset protected service \"%s\"!'", ",", "$", "name", ")", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Unset a service if it is not protected @param string $name @return mixed @throws \ErrorException
[ "Unset", "a", "service", "if", "it", "is", "not", "protected" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/ServiceContainer/ServiceContainer.php#L239-L257
4,159
atelierspierrot/library
src/Library/ServiceContainer/ServiceContainer.php
ServiceContainer._constructService
protected function _constructService($name, array $arguments = array()) { if ($this->hasProvider($name)) { $data = $this->getProvider($name); if (is_object($data) && CodeHelper::implementsInterface($data, 'Library\ServiceContainer\ServiceProviderInterface')) { $data->boot($this); $this->setService($name, $data); } elseif (is_callable($data) || ($data instanceof \Closure)) { try { $item = call_user_func_array( $data, array($this, $name, $arguments) ); $this->setService($name, $item); } catch (\Exception $e) { throw new ErrorException( sprintf('An error occurred while trying to create a "%s" service!', $name), 0, 1, __FILE__, __LINE__, $e ); } } elseif (is_array($data)) { $this->setService( $name, $data[1], isset($data[2]) ? $data[2] : false ); } else { throw new ErrorException( sprintf('A "%s" service constructor must be a valid callback!', $name) ); } } }
php
protected function _constructService($name, array $arguments = array()) { if ($this->hasProvider($name)) { $data = $this->getProvider($name); if (is_object($data) && CodeHelper::implementsInterface($data, 'Library\ServiceContainer\ServiceProviderInterface')) { $data->boot($this); $this->setService($name, $data); } elseif (is_callable($data) || ($data instanceof \Closure)) { try { $item = call_user_func_array( $data, array($this, $name, $arguments) ); $this->setService($name, $item); } catch (\Exception $e) { throw new ErrorException( sprintf('An error occurred while trying to create a "%s" service!', $name), 0, 1, __FILE__, __LINE__, $e ); } } elseif (is_array($data)) { $this->setService( $name, $data[1], isset($data[2]) ? $data[2] : false ); } else { throw new ErrorException( sprintf('A "%s" service constructor must be a valid callback!', $name) ); } } }
[ "protected", "function", "_constructService", "(", "$", "name", ",", "array", "$", "arguments", "=", "array", "(", ")", ")", "{", "if", "(", "$", "this", "->", "hasProvider", "(", "$", "name", ")", ")", "{", "$", "data", "=", "$", "this", "->", "getProvider", "(", "$", "name", ")", ";", "if", "(", "is_object", "(", "$", "data", ")", "&&", "CodeHelper", "::", "implementsInterface", "(", "$", "data", ",", "'Library\\ServiceContainer\\ServiceProviderInterface'", ")", ")", "{", "$", "data", "->", "boot", "(", "$", "this", ")", ";", "$", "this", "->", "setService", "(", "$", "name", ",", "$", "data", ")", ";", "}", "elseif", "(", "is_callable", "(", "$", "data", ")", "||", "(", "$", "data", "instanceof", "\\", "Closure", ")", ")", "{", "try", "{", "$", "item", "=", "call_user_func_array", "(", "$", "data", ",", "array", "(", "$", "this", ",", "$", "name", ",", "$", "arguments", ")", ")", ";", "$", "this", "->", "setService", "(", "$", "name", ",", "$", "item", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "ErrorException", "(", "sprintf", "(", "'An error occurred while trying to create a \"%s\" service!'", ",", "$", "name", ")", ",", "0", ",", "1", ",", "__FILE__", ",", "__LINE__", ",", "$", "e", ")", ";", "}", "}", "elseif", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "this", "->", "setService", "(", "$", "name", ",", "$", "data", "[", "1", "]", ",", "isset", "(", "$", "data", "[", "2", "]", ")", "?", "$", "data", "[", "2", "]", ":", "false", ")", ";", "}", "else", "{", "throw", "new", "ErrorException", "(", "sprintf", "(", "'A \"%s\" service constructor must be a valid callback!'", ",", "$", "name", ")", ")", ";", "}", "}", "}" ]
Construct a service based on its `constructor` item and references it @param string $name @param array $arguments @return void @throws ErrorException
[ "Construct", "a", "service", "based", "on", "its", "constructor", "item", "and", "references", "it" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/ServiceContainer/ServiceContainer.php#L281-L312
4,160
pletfix/core
src/Services/PDOs/Schemas/SQLiteSchema.php
SQLiteSchema.extractFieldType
private function extractFieldType($spec) { if (!preg_match('/(\w+)(?:\s*\(\s*([0-9]+)(?:\,\s*([0-9]+))?\s*\))?(?:\s*(\w+))?/s', strtoupper($spec), $match)) { return [null, null, null, null]; } $dbType = isset($match[1]) ? $match[1] : null; $size = isset($match[2]) && $match[2] != '' ? (int)$match[2] : null; $scale = isset($match[3]) && $match[2] != '' ? (int)$match[3] : null; $unsigned = isset($match[4]) && $match[4] == 'UNSIGNED'; return [$dbType, $size, $scale, $unsigned]; }
php
private function extractFieldType($spec) { if (!preg_match('/(\w+)(?:\s*\(\s*([0-9]+)(?:\,\s*([0-9]+))?\s*\))?(?:\s*(\w+))?/s', strtoupper($spec), $match)) { return [null, null, null, null]; } $dbType = isset($match[1]) ? $match[1] : null; $size = isset($match[2]) && $match[2] != '' ? (int)$match[2] : null; $scale = isset($match[3]) && $match[2] != '' ? (int)$match[3] : null; $unsigned = isset($match[4]) && $match[4] == 'UNSIGNED'; return [$dbType, $size, $scale, $unsigned]; }
[ "private", "function", "extractFieldType", "(", "$", "spec", ")", "{", "if", "(", "!", "preg_match", "(", "'/(\\w+)(?:\\s*\\(\\s*([0-9]+)(?:\\,\\s*([0-9]+))?\\s*\\))?(?:\\s*(\\w+))?/s'", ",", "strtoupper", "(", "$", "spec", ")", ",", "$", "match", ")", ")", "{", "return", "[", "null", ",", "null", ",", "null", ",", "null", "]", ";", "}", "$", "dbType", "=", "isset", "(", "$", "match", "[", "1", "]", ")", "?", "$", "match", "[", "1", "]", ":", "null", ";", "$", "size", "=", "isset", "(", "$", "match", "[", "2", "]", ")", "&&", "$", "match", "[", "2", "]", "!=", "''", "?", "(", "int", ")", "$", "match", "[", "2", "]", ":", "null", ";", "$", "scale", "=", "isset", "(", "$", "match", "[", "3", "]", ")", "&&", "$", "match", "[", "2", "]", "!=", "''", "?", "(", "int", ")", "$", "match", "[", "3", "]", ":", "null", ";", "$", "unsigned", "=", "isset", "(", "$", "match", "[", "4", "]", ")", "&&", "$", "match", "[", "4", "]", "==", "'UNSIGNED'", ";", "return", "[", "$", "dbType", ",", "$", "size", ",", "$", "scale", ",", "$", "unsigned", "]", ";", "}" ]
Extract a given database field type into field type, size, scale and unsigned flag. This function could be used by columns(). @param string $spec The database field specification; for example, "VARCHAR(255)" or "NUMERIC(10,2) UNSIGNED". @return array
[ "Extract", "a", "given", "database", "field", "type", "into", "field", "type", "size", "scale", "and", "unsigned", "flag", "." ]
974945500f278eb6c1779832e08bbfca1007a7b3
https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Services/PDOs/Schemas/SQLiteSchema.php#L186-L198
4,161
ForceLabsDev/framework
src/DependencyInjection/ServiceContainer.php
ServiceContainer.bind
public function bind($name, \Closure $type) { $name = '\\'.ltrim($name, '\\'); $this->bindings[$name] = $type; }
php
public function bind($name, \Closure $type) { $name = '\\'.ltrim($name, '\\'); $this->bindings[$name] = $type; }
[ "public", "function", "bind", "(", "$", "name", ",", "\\", "Closure", "$", "type", ")", "{", "$", "name", "=", "'\\\\'", ".", "ltrim", "(", "$", "name", ",", "'\\\\'", ")", ";", "$", "this", "->", "bindings", "[", "$", "name", "]", "=", "$", "type", ";", "}" ]
Adds a new service class. @param string $name The full qualified class name of the service including namespace @param \Closure $type This Closure has to return the service class object
[ "Adds", "a", "new", "service", "class", "." ]
e2288582432857771e85c9859acd6d32e5f2f9b7
https://github.com/ForceLabsDev/framework/blob/e2288582432857771e85c9859acd6d32e5f2f9b7/src/DependencyInjection/ServiceContainer.php#L21-L25
4,162
ForceLabsDev/framework
src/DependencyInjection/ServiceContainer.php
ServiceContainer.resolveParameter
private function resolveParameter(\ReflectionParameter $param, array $args) { $className = $param->getClass(); if ($className !== null) { return $this->make($className->getName()); } elseif (isset($args[$param->getName()])) { return $args[$param->getName()]; } elseif ($param->isOptional()) { return $param->getDefaultValue(); } else { throw new ClassResolvingException('Cannot resolve Parameter #'.$param->getPosition()." '".$param->getName()."'"); } }
php
private function resolveParameter(\ReflectionParameter $param, array $args) { $className = $param->getClass(); if ($className !== null) { return $this->make($className->getName()); } elseif (isset($args[$param->getName()])) { return $args[$param->getName()]; } elseif ($param->isOptional()) { return $param->getDefaultValue(); } else { throw new ClassResolvingException('Cannot resolve Parameter #'.$param->getPosition()." '".$param->getName()."'"); } }
[ "private", "function", "resolveParameter", "(", "\\", "ReflectionParameter", "$", "param", ",", "array", "$", "args", ")", "{", "$", "className", "=", "$", "param", "->", "getClass", "(", ")", ";", "if", "(", "$", "className", "!==", "null", ")", "{", "return", "$", "this", "->", "make", "(", "$", "className", "->", "getName", "(", ")", ")", ";", "}", "elseif", "(", "isset", "(", "$", "args", "[", "$", "param", "->", "getName", "(", ")", "]", ")", ")", "{", "return", "$", "args", "[", "$", "param", "->", "getName", "(", ")", "]", ";", "}", "elseif", "(", "$", "param", "->", "isOptional", "(", ")", ")", "{", "return", "$", "param", "->", "getDefaultValue", "(", ")", ";", "}", "else", "{", "throw", "new", "ClassResolvingException", "(", "'Cannot resolve Parameter #'", ".", "$", "param", "->", "getPosition", "(", ")", ".", "\" '\"", ".", "$", "param", "->", "getName", "(", ")", ".", "\"'\"", ")", ";", "}", "}" ]
Resolves a ReflectionParameter. @param \ReflectionParameter $param @param array $args @return mixed|object @throws \Exception
[ "Resolves", "a", "ReflectionParameter", "." ]
e2288582432857771e85c9859acd6d32e5f2f9b7
https://github.com/ForceLabsDev/framework/blob/e2288582432857771e85c9859acd6d32e5f2f9b7/src/DependencyInjection/ServiceContainer.php#L110-L122
4,163
bishopb/vanilla
library/core/class.factory.php
Gdn_Factory.Factory
public function Factory($Alias, $Args = NULL) { //if (!$this->Exists($Alias)) if (!array_key_exists($Alias, $this->_Objects)) return NULL; $Def = &$this->_Objects[$Alias]; $ClassName = $Def['ClassName']; // Make sure the class has beeen included. if (!class_exists($ClassName)) { $Path = $Def['Path']; if (substr($Path, 0, 1) == '~') { // Replace the beginning of the path with the root of the application. $Path = PATH_ROOT . substr($Path, 1); $Def['Path'] = $Path; } if (file_exists($Path)) require_once($Path); } if (!class_exists($ClassName, FALSE)) { throw new Exception(sprintf('Class %s not found while trying to get an object for %s. Check the path %s.', $ClassName, $Alias, $Def['Path'])); } // Create the object differently depending on the type. $Result = NULL; $FactoryType = $Def['FactoryType']; $FactorySupplimentData = isset($Def[$FactoryType]) ? $Def[$FactoryType] : NULL; switch($FactoryType) { case Gdn::FactoryInstance: // Instantiate a new instance of the class. $Result = $this->_InstantiateObject($Alias, $ClassName, $Args); break; case Gdn::FactoryPrototype: $Prototype = $FactorySupplimentData; $Result = clone $Prototype; break; case Gdn::FactorySingleton: $SingletonDef = $FactorySupplimentData; if(is_array($SingletonDef)) { // The singleton has arguments for instantiation. $Singleton = NULL; $Args = $SingletonDef; } else { $Singleton = $SingletonDef; } if(is_null($Singleton)) { // Lazy create the singleton instance. $Singleton = $this->_InstantiateObject($Alias, $ClassName, $Args); $Def[$FactoryType] = $Singleton; } $Result = $Def[$FactoryType]; break; case Gdn::FactoryRealSingleton: $RealSingletonDef = $FactorySupplimentData; // Not yet stored as an object... need to instantiate if (!is_object($RealSingletonDef)) { $RealSingleton = NULL; } else { $RealSingleton = $RealSingletonDef; } if (is_null($RealSingleton)) { // Lazy create the singleton instance. $RealSingleton = call_user_func_array(array($ClassName,$RealSingletonDef), $Args); $this->_SetDependancies($Alias, $RealSingleton); $Def[$FactoryType] = $RealSingleton; } $Result = $Def[$FactoryType]; break; default: /** @todo Throw an exception. */ throw new Exception(); break; } return $Result; }
php
public function Factory($Alias, $Args = NULL) { //if (!$this->Exists($Alias)) if (!array_key_exists($Alias, $this->_Objects)) return NULL; $Def = &$this->_Objects[$Alias]; $ClassName = $Def['ClassName']; // Make sure the class has beeen included. if (!class_exists($ClassName)) { $Path = $Def['Path']; if (substr($Path, 0, 1) == '~') { // Replace the beginning of the path with the root of the application. $Path = PATH_ROOT . substr($Path, 1); $Def['Path'] = $Path; } if (file_exists($Path)) require_once($Path); } if (!class_exists($ClassName, FALSE)) { throw new Exception(sprintf('Class %s not found while trying to get an object for %s. Check the path %s.', $ClassName, $Alias, $Def['Path'])); } // Create the object differently depending on the type. $Result = NULL; $FactoryType = $Def['FactoryType']; $FactorySupplimentData = isset($Def[$FactoryType]) ? $Def[$FactoryType] : NULL; switch($FactoryType) { case Gdn::FactoryInstance: // Instantiate a new instance of the class. $Result = $this->_InstantiateObject($Alias, $ClassName, $Args); break; case Gdn::FactoryPrototype: $Prototype = $FactorySupplimentData; $Result = clone $Prototype; break; case Gdn::FactorySingleton: $SingletonDef = $FactorySupplimentData; if(is_array($SingletonDef)) { // The singleton has arguments for instantiation. $Singleton = NULL; $Args = $SingletonDef; } else { $Singleton = $SingletonDef; } if(is_null($Singleton)) { // Lazy create the singleton instance. $Singleton = $this->_InstantiateObject($Alias, $ClassName, $Args); $Def[$FactoryType] = $Singleton; } $Result = $Def[$FactoryType]; break; case Gdn::FactoryRealSingleton: $RealSingletonDef = $FactorySupplimentData; // Not yet stored as an object... need to instantiate if (!is_object($RealSingletonDef)) { $RealSingleton = NULL; } else { $RealSingleton = $RealSingletonDef; } if (is_null($RealSingleton)) { // Lazy create the singleton instance. $RealSingleton = call_user_func_array(array($ClassName,$RealSingletonDef), $Args); $this->_SetDependancies($Alias, $RealSingleton); $Def[$FactoryType] = $RealSingleton; } $Result = $Def[$FactoryType]; break; default: /** @todo Throw an exception. */ throw new Exception(); break; } return $Result; }
[ "public", "function", "Factory", "(", "$", "Alias", ",", "$", "Args", "=", "NULL", ")", "{", "//if (!$this->Exists($Alias))", "if", "(", "!", "array_key_exists", "(", "$", "Alias", ",", "$", "this", "->", "_Objects", ")", ")", "return", "NULL", ";", "$", "Def", "=", "&", "$", "this", "->", "_Objects", "[", "$", "Alias", "]", ";", "$", "ClassName", "=", "$", "Def", "[", "'ClassName'", "]", ";", "// Make sure the class has beeen included.", "if", "(", "!", "class_exists", "(", "$", "ClassName", ")", ")", "{", "$", "Path", "=", "$", "Def", "[", "'Path'", "]", ";", "if", "(", "substr", "(", "$", "Path", ",", "0", ",", "1", ")", "==", "'~'", ")", "{", "// Replace the beginning of the path with the root of the application.", "$", "Path", "=", "PATH_ROOT", ".", "substr", "(", "$", "Path", ",", "1", ")", ";", "$", "Def", "[", "'Path'", "]", "=", "$", "Path", ";", "}", "if", "(", "file_exists", "(", "$", "Path", ")", ")", "require_once", "(", "$", "Path", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "ClassName", ",", "FALSE", ")", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'Class %s not found while trying to get an object for %s. Check the path %s.'", ",", "$", "ClassName", ",", "$", "Alias", ",", "$", "Def", "[", "'Path'", "]", ")", ")", ";", "}", "// Create the object differently depending on the type.", "$", "Result", "=", "NULL", ";", "$", "FactoryType", "=", "$", "Def", "[", "'FactoryType'", "]", ";", "$", "FactorySupplimentData", "=", "isset", "(", "$", "Def", "[", "$", "FactoryType", "]", ")", "?", "$", "Def", "[", "$", "FactoryType", "]", ":", "NULL", ";", "switch", "(", "$", "FactoryType", ")", "{", "case", "Gdn", "::", "FactoryInstance", ":", "// Instantiate a new instance of the class.", "$", "Result", "=", "$", "this", "->", "_InstantiateObject", "(", "$", "Alias", ",", "$", "ClassName", ",", "$", "Args", ")", ";", "break", ";", "case", "Gdn", "::", "FactoryPrototype", ":", "$", "Prototype", "=", "$", "FactorySupplimentData", ";", "$", "Result", "=", "clone", "$", "Prototype", ";", "break", ";", "case", "Gdn", "::", "FactorySingleton", ":", "$", "SingletonDef", "=", "$", "FactorySupplimentData", ";", "if", "(", "is_array", "(", "$", "SingletonDef", ")", ")", "{", "// The singleton has arguments for instantiation.", "$", "Singleton", "=", "NULL", ";", "$", "Args", "=", "$", "SingletonDef", ";", "}", "else", "{", "$", "Singleton", "=", "$", "SingletonDef", ";", "}", "if", "(", "is_null", "(", "$", "Singleton", ")", ")", "{", "// Lazy create the singleton instance.", "$", "Singleton", "=", "$", "this", "->", "_InstantiateObject", "(", "$", "Alias", ",", "$", "ClassName", ",", "$", "Args", ")", ";", "$", "Def", "[", "$", "FactoryType", "]", "=", "$", "Singleton", ";", "}", "$", "Result", "=", "$", "Def", "[", "$", "FactoryType", "]", ";", "break", ";", "case", "Gdn", "::", "FactoryRealSingleton", ":", "$", "RealSingletonDef", "=", "$", "FactorySupplimentData", ";", "// Not yet stored as an object... need to instantiate", "if", "(", "!", "is_object", "(", "$", "RealSingletonDef", ")", ")", "{", "$", "RealSingleton", "=", "NULL", ";", "}", "else", "{", "$", "RealSingleton", "=", "$", "RealSingletonDef", ";", "}", "if", "(", "is_null", "(", "$", "RealSingleton", ")", ")", "{", "// Lazy create the singleton instance.", "$", "RealSingleton", "=", "call_user_func_array", "(", "array", "(", "$", "ClassName", ",", "$", "RealSingletonDef", ")", ",", "$", "Args", ")", ";", "$", "this", "->", "_SetDependancies", "(", "$", "Alias", ",", "$", "RealSingleton", ")", ";", "$", "Def", "[", "$", "FactoryType", "]", "=", "$", "RealSingleton", ";", "}", "$", "Result", "=", "$", "Def", "[", "$", "FactoryType", "]", ";", "break", ";", "default", ":", "/** @todo Throw an exception. */", "throw", "new", "Exception", "(", ")", ";", "break", ";", "}", "return", "$", "Result", ";", "}" ]
Creates an object with mapped to the name. @param $Alias The class code of the object to create. @param $Args The arguments to pass to the constructor of the object.
[ "Creates", "an", "object", "with", "mapped", "to", "the", "name", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.factory.php#L45-L124
4,164
bishopb/vanilla
library/core/class.factory.php
Gdn_Factory.InstallDependency
public function InstallDependency($Alias, $PropertyName, $SourceAlias) { if(!array_key_exists($Alias, $this->_Dependencies)) { $this->_Dependencies[$Alias] = array($PropertyName => $SourceAlias); } else { $this->_Dependencies[$Alias][$PropertyName] = $SourceAlias; } }
php
public function InstallDependency($Alias, $PropertyName, $SourceAlias) { if(!array_key_exists($Alias, $this->_Dependencies)) { $this->_Dependencies[$Alias] = array($PropertyName => $SourceAlias); } else { $this->_Dependencies[$Alias][$PropertyName] = $SourceAlias; } }
[ "public", "function", "InstallDependency", "(", "$", "Alias", ",", "$", "PropertyName", ",", "$", "SourceAlias", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "Alias", ",", "$", "this", "->", "_Dependencies", ")", ")", "{", "$", "this", "->", "_Dependencies", "[", "$", "Alias", "]", "=", "array", "(", "$", "PropertyName", "=>", "$", "SourceAlias", ")", ";", "}", "else", "{", "$", "this", "->", "_Dependencies", "[", "$", "Alias", "]", "[", "$", "PropertyName", "]", "=", "$", "SourceAlias", ";", "}", "}" ]
Install a dependency for the factory. This method provides support for simple dependency injection. When an object with dependencies is created then the factory will call inline{@link Gdn_Factory::Factory()} for each dependency and set the object properties before returning it. Those dependencies can also have their own dependencies which will all be set when the object is returned. @param string $Alias The alias of the class that will have the dependency. @param string $PropertyName The name of the property on the class that will have the dependency. @param string $SourceAlias The alias of the class that will provide the value of the property when objects are instantiated.
[ "Install", "a", "dependency", "for", "the", "factory", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.factory.php#L183-L189
4,165
bishopb/vanilla
library/core/class.factory.php
Gdn_Factory._InstantiateObject
protected function _InstantiateObject($Alias, $ClassName, $Args = NULL) { if(is_null($Args)) $Args = array(); $Result = NULL; // Instantiate the object with the correct arguments. // This odd looking case statement is purely for speed optimization. switch(count($Args)) { case 0: $Result = new $ClassName; break; case 1: $Result = new $ClassName($Args[0]); break; case 2: $Result = new $ClassName($Args[0], $Args[1]); break; case 3: $Result = new $ClassName($Args[0], $Args[1], $Args[2]); break; case 4: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3]); break; case 5: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4]); break; case 6: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5]); break; case 7: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6]); break; case 8: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7]); break; default: throw new Exception(); } $this->_SetDependancies($Alias, $Result); return $Result; }
php
protected function _InstantiateObject($Alias, $ClassName, $Args = NULL) { if(is_null($Args)) $Args = array(); $Result = NULL; // Instantiate the object with the correct arguments. // This odd looking case statement is purely for speed optimization. switch(count($Args)) { case 0: $Result = new $ClassName; break; case 1: $Result = new $ClassName($Args[0]); break; case 2: $Result = new $ClassName($Args[0], $Args[1]); break; case 3: $Result = new $ClassName($Args[0], $Args[1], $Args[2]); break; case 4: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3]); break; case 5: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4]); break; case 6: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5]); break; case 7: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6]); break; case 8: $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7]); break; default: throw new Exception(); } $this->_SetDependancies($Alias, $Result); return $Result; }
[ "protected", "function", "_InstantiateObject", "(", "$", "Alias", ",", "$", "ClassName", ",", "$", "Args", "=", "NULL", ")", "{", "if", "(", "is_null", "(", "$", "Args", ")", ")", "$", "Args", "=", "array", "(", ")", ";", "$", "Result", "=", "NULL", ";", "// Instantiate the object with the correct arguments.", "// This odd looking case statement is purely for speed optimization.", "switch", "(", "count", "(", "$", "Args", ")", ")", "{", "case", "0", ":", "$", "Result", "=", "new", "$", "ClassName", ";", "break", ";", "case", "1", ":", "$", "Result", "=", "new", "$", "ClassName", "(", "$", "Args", "[", "0", "]", ")", ";", "break", ";", "case", "2", ":", "$", "Result", "=", "new", "$", "ClassName", "(", "$", "Args", "[", "0", "]", ",", "$", "Args", "[", "1", "]", ")", ";", "break", ";", "case", "3", ":", "$", "Result", "=", "new", "$", "ClassName", "(", "$", "Args", "[", "0", "]", ",", "$", "Args", "[", "1", "]", ",", "$", "Args", "[", "2", "]", ")", ";", "break", ";", "case", "4", ":", "$", "Result", "=", "new", "$", "ClassName", "(", "$", "Args", "[", "0", "]", ",", "$", "Args", "[", "1", "]", ",", "$", "Args", "[", "2", "]", ",", "$", "Args", "[", "3", "]", ")", ";", "break", ";", "case", "5", ":", "$", "Result", "=", "new", "$", "ClassName", "(", "$", "Args", "[", "0", "]", ",", "$", "Args", "[", "1", "]", ",", "$", "Args", "[", "2", "]", ",", "$", "Args", "[", "3", "]", ",", "$", "Args", "[", "4", "]", ")", ";", "break", ";", "case", "6", ":", "$", "Result", "=", "new", "$", "ClassName", "(", "$", "Args", "[", "0", "]", ",", "$", "Args", "[", "1", "]", ",", "$", "Args", "[", "2", "]", ",", "$", "Args", "[", "3", "]", ",", "$", "Args", "[", "4", "]", ",", "$", "Args", "[", "5", "]", ")", ";", "break", ";", "case", "7", ":", "$", "Result", "=", "new", "$", "ClassName", "(", "$", "Args", "[", "0", "]", ",", "$", "Args", "[", "1", "]", ",", "$", "Args", "[", "2", "]", ",", "$", "Args", "[", "3", "]", ",", "$", "Args", "[", "4", "]", ",", "$", "Args", "[", "5", "]", ",", "$", "Args", "[", "6", "]", ")", ";", "break", ";", "case", "8", ":", "$", "Result", "=", "new", "$", "ClassName", "(", "$", "Args", "[", "0", "]", ",", "$", "Args", "[", "1", "]", ",", "$", "Args", "[", "2", "]", ",", "$", "Args", "[", "3", "]", ",", "$", "Args", "[", "4", "]", ",", "$", "Args", "[", "5", "]", ",", "$", "Args", "[", "6", "]", ",", "$", "Args", "[", "7", "]", ")", ";", "break", ";", "default", ":", "throw", "new", "Exception", "(", ")", ";", "}", "$", "this", "->", "_SetDependancies", "(", "$", "Alias", ",", "$", "Result", ")", ";", "return", "$", "Result", ";", "}" ]
Instantiate a new object. @param string $ClassName The name of the class to instantiate. @param array $Args The arguments to pass to the constructor. Note: This function currently only supports a maximum of 8 arguments.
[ "Instantiate", "a", "new", "object", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.factory.php#L198-L229
4,166
bishopb/vanilla
library/core/class.factory.php
Gdn_Factory.Cleanup
public function Cleanup() { foreach ($this->_Objects as $FactoryInstanceName => &$FactoryInstance) { if (!is_array($FactoryInstance)) continue; $FactoryType = $FactoryInstance['FactoryType']; if (!array_key_exists($FactoryType, $FactoryInstance)) continue; $FactoryObject = &$FactoryInstance[$FactoryType]; if (method_exists($FactoryObject, 'Cleanup')) $FactoryObject->Cleanup(); unset($FactoryInstance); } }
php
public function Cleanup() { foreach ($this->_Objects as $FactoryInstanceName => &$FactoryInstance) { if (!is_array($FactoryInstance)) continue; $FactoryType = $FactoryInstance['FactoryType']; if (!array_key_exists($FactoryType, $FactoryInstance)) continue; $FactoryObject = &$FactoryInstance[$FactoryType]; if (method_exists($FactoryObject, 'Cleanup')) $FactoryObject->Cleanup(); unset($FactoryInstance); } }
[ "public", "function", "Cleanup", "(", ")", "{", "foreach", "(", "$", "this", "->", "_Objects", "as", "$", "FactoryInstanceName", "=>", "&", "$", "FactoryInstance", ")", "{", "if", "(", "!", "is_array", "(", "$", "FactoryInstance", ")", ")", "continue", ";", "$", "FactoryType", "=", "$", "FactoryInstance", "[", "'FactoryType'", "]", ";", "if", "(", "!", "array_key_exists", "(", "$", "FactoryType", ",", "$", "FactoryInstance", ")", ")", "continue", ";", "$", "FactoryObject", "=", "&", "$", "FactoryInstance", "[", "$", "FactoryType", "]", ";", "if", "(", "method_exists", "(", "$", "FactoryObject", ",", "'Cleanup'", ")", ")", "$", "FactoryObject", "->", "Cleanup", "(", ")", ";", "unset", "(", "$", "FactoryInstance", ")", ";", "}", "}" ]
Clean up the factory's objects Also calls 'Cleanup' on compatible instances.
[ "Clean", "up", "the", "factory", "s", "objects" ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.factory.php#L257-L270
4,167
bishopb/vanilla
library/core/class.factory.php
Gdn_Factory.UninstallDependency
public function UninstallDependency($Alias, $PropertyName = NULL) { if(array_key_exists($Alias, $this->_Dependencies)) { if(is_null($PropertyName)) unset($this->_Dependencies[$Alias]); elseif(array_key_exists($PropertyName, $this->_Dependencies[$Alias])) unset($this->_Dependencies[$Alias][$PropertyName]); } }
php
public function UninstallDependency($Alias, $PropertyName = NULL) { if(array_key_exists($Alias, $this->_Dependencies)) { if(is_null($PropertyName)) unset($this->_Dependencies[$Alias]); elseif(array_key_exists($PropertyName, $this->_Dependencies[$Alias])) unset($this->_Dependencies[$Alias][$PropertyName]); } }
[ "public", "function", "UninstallDependency", "(", "$", "Alias", ",", "$", "PropertyName", "=", "NULL", ")", "{", "if", "(", "array_key_exists", "(", "$", "Alias", ",", "$", "this", "->", "_Dependencies", ")", ")", "{", "if", "(", "is_null", "(", "$", "PropertyName", ")", ")", "unset", "(", "$", "this", "->", "_Dependencies", "[", "$", "Alias", "]", ")", ";", "elseif", "(", "array_key_exists", "(", "$", "PropertyName", ",", "$", "this", "->", "_Dependencies", "[", "$", "Alias", "]", ")", ")", "unset", "(", "$", "this", "->", "_Dependencies", "[", "$", "Alias", "]", "[", "$", "PropertyName", "]", ")", ";", "}", "}" ]
Uninstall a dependency definition. @param string $Alias The object alias to uninstall the dependency for. @param string $PropertyName The name of the property dependency to uninstall. Note: If $PropertyName is null then all of the dependencies will be uninstalled for $Alias.
[ "Uninstall", "a", "dependency", "definition", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.factory.php#L279-L286
4,168
jakew/cases
src/Phrase.php
Phrase.getCamelCase
public function getCamelCase(bool $upperCamelCase = true, int $acronymMaxLength = null): string { $phrase = ''; // Combine letters to make sure acronym max length is preserved. foreach ($this->words as $word) { if (!$upperCamelCase) { $phrase .= $word->getCapitalCase(); $upperCamelCase = true; continue; } $phrase .= $word->getCapitalCase(); } return $phrase; }
php
public function getCamelCase(bool $upperCamelCase = true, int $acronymMaxLength = null): string { $phrase = ''; // Combine letters to make sure acronym max length is preserved. foreach ($this->words as $word) { if (!$upperCamelCase) { $phrase .= $word->getCapitalCase(); $upperCamelCase = true; continue; } $phrase .= $word->getCapitalCase(); } return $phrase; }
[ "public", "function", "getCamelCase", "(", "bool", "$", "upperCamelCase", "=", "true", ",", "int", "$", "acronymMaxLength", "=", "null", ")", ":", "string", "{", "$", "phrase", "=", "''", ";", "// Combine letters to make sure acronym max length is preserved.", "foreach", "(", "$", "this", "->", "words", "as", "$", "word", ")", "{", "if", "(", "!", "$", "upperCamelCase", ")", "{", "$", "phrase", ".=", "$", "word", "->", "getCapitalCase", "(", ")", ";", "$", "upperCamelCase", "=", "true", ";", "continue", ";", "}", "$", "phrase", ".=", "$", "word", "->", "getCapitalCase", "(", ")", ";", "}", "return", "$", "phrase", ";", "}" ]
Returns the phrase as camel case. @TODO: Finish acroynm length system. @param bool $upperCamelCase True if the first _word_ should be capitalized. @param int|null $acronymMaxLength If set, acronyms will be all capitalized up to a specific length. @return string The camel cased version of the phrase.
[ "Returns", "the", "phrase", "as", "camel", "case", "." ]
949bd1933c8dceac5543e9758daf11d93b2bb69e
https://github.com/jakew/cases/blob/949bd1933c8dceac5543e9758daf11d93b2bb69e/src/Phrase.php#L44-L61
4,169
jakew/cases
src/Phrase.php
Phrase.getSnakeCase
public function getSnakeCase(string $glue = '-') { $words = []; foreach ($this->words as $word) { $words[] = $word->getLowerCase(); } return implode($glue, $words); }
php
public function getSnakeCase(string $glue = '-') { $words = []; foreach ($this->words as $word) { $words[] = $word->getLowerCase(); } return implode($glue, $words); }
[ "public", "function", "getSnakeCase", "(", "string", "$", "glue", "=", "'-'", ")", "{", "$", "words", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "words", "as", "$", "word", ")", "{", "$", "words", "[", "]", "=", "$", "word", "->", "getLowerCase", "(", ")", ";", "}", "return", "implode", "(", "$", "glue", ",", "$", "words", ")", ";", "}" ]
Returns the snake case version with the glue provided. @param string $glue The glue between words. Common examples would be '-', '_' and ' '. @return string The snake case version of the phrase.
[ "Returns", "the", "snake", "case", "version", "with", "the", "glue", "provided", "." ]
949bd1933c8dceac5543e9758daf11d93b2bb69e
https://github.com/jakew/cases/blob/949bd1933c8dceac5543e9758daf11d93b2bb69e/src/Phrase.php#L69-L78
4,170
jakew/cases
src/Phrase.php
Phrase.decode
public static function decode( string $phrase, string $concatenationType = self::CONCATENATION_TYPE_ALL, string $glue = null ) { if ($concatenationType == self::CONCATENATION_TYPE_CAPITALIZATION || $concatenationType == self::CONCATENATION_TYPE_ALL) { $phrase = preg_split('/(?=[A-Z])/', $phrase); } else { $phrase = [$phrase]; } if ($concatenationType == self::CONCATENATION_TYPE_GLUE || $concatenationType == self::CONCATENATION_TYPE_ALL) { $newWords = []; foreach ($phrase as $i) { array_push($newWords, ...self::unglue($i, $glue)); } $phrase = $newWords; } $phrase = array_filter($phrase); foreach ($phrase as &$word) { $word = Dictionary::getInstance()->getWord($word); } return new self(...$phrase); }
php
public static function decode( string $phrase, string $concatenationType = self::CONCATENATION_TYPE_ALL, string $glue = null ) { if ($concatenationType == self::CONCATENATION_TYPE_CAPITALIZATION || $concatenationType == self::CONCATENATION_TYPE_ALL) { $phrase = preg_split('/(?=[A-Z])/', $phrase); } else { $phrase = [$phrase]; } if ($concatenationType == self::CONCATENATION_TYPE_GLUE || $concatenationType == self::CONCATENATION_TYPE_ALL) { $newWords = []; foreach ($phrase as $i) { array_push($newWords, ...self::unglue($i, $glue)); } $phrase = $newWords; } $phrase = array_filter($phrase); foreach ($phrase as &$word) { $word = Dictionary::getInstance()->getWord($word); } return new self(...$phrase); }
[ "public", "static", "function", "decode", "(", "string", "$", "phrase", ",", "string", "$", "concatenationType", "=", "self", "::", "CONCATENATION_TYPE_ALL", ",", "string", "$", "glue", "=", "null", ")", "{", "if", "(", "$", "concatenationType", "==", "self", "::", "CONCATENATION_TYPE_CAPITALIZATION", "||", "$", "concatenationType", "==", "self", "::", "CONCATENATION_TYPE_ALL", ")", "{", "$", "phrase", "=", "preg_split", "(", "'/(?=[A-Z])/'", ",", "$", "phrase", ")", ";", "}", "else", "{", "$", "phrase", "=", "[", "$", "phrase", "]", ";", "}", "if", "(", "$", "concatenationType", "==", "self", "::", "CONCATENATION_TYPE_GLUE", "||", "$", "concatenationType", "==", "self", "::", "CONCATENATION_TYPE_ALL", ")", "{", "$", "newWords", "=", "[", "]", ";", "foreach", "(", "$", "phrase", "as", "$", "i", ")", "{", "array_push", "(", "$", "newWords", ",", "...", "self", "::", "unglue", "(", "$", "i", ",", "$", "glue", ")", ")", ";", "}", "$", "phrase", "=", "$", "newWords", ";", "}", "$", "phrase", "=", "array_filter", "(", "$", "phrase", ")", ";", "foreach", "(", "$", "phrase", "as", "&", "$", "word", ")", "{", "$", "word", "=", "Dictionary", "::", "getInstance", "(", ")", "->", "getWord", "(", "$", "word", ")", ";", "}", "return", "new", "self", "(", "...", "$", "phrase", ")", ";", "}" ]
Given a phrase as a string, and a few options, break it down into individual Word objects and create a Phrase with them. @param string $phrase The phrase we are starting with. @param string $concatenationType The type of the concatenation. @param string|null $glue The glue we should use specifically. This can be a list of chars (except /). @return Phrase The resulting object, created with the words we separated.
[ "Given", "a", "phrase", "as", "a", "string", "and", "a", "few", "options", "break", "it", "down", "into", "individual", "Word", "objects", "and", "create", "a", "Phrase", "with", "them", "." ]
949bd1933c8dceac5543e9758daf11d93b2bb69e
https://github.com/jakew/cases/blob/949bd1933c8dceac5543e9758daf11d93b2bb69e/src/Phrase.php#L99-L129
4,171
jakew/cases
src/Phrase.php
Phrase.unglue
protected static function unglue(string $string, string $glue = null): array { $glue = ($glue === null) ? '-_ ' : $glue; return preg_split("/[" . $glue . "]+/", $string); }
php
protected static function unglue(string $string, string $glue = null): array { $glue = ($glue === null) ? '-_ ' : $glue; return preg_split("/[" . $glue . "]+/", $string); }
[ "protected", "static", "function", "unglue", "(", "string", "$", "string", ",", "string", "$", "glue", "=", "null", ")", ":", "array", "{", "$", "glue", "=", "(", "$", "glue", "===", "null", ")", "?", "'-_ '", ":", "$", "glue", ";", "return", "preg_split", "(", "\"/[\"", ".", "$", "glue", ".", "\"]+/\"", ",", "$", "string", ")", ";", "}" ]
Given one or more characters as glue, separate a string into an array of strings. @param string $string The string we are separating. @param string|null $glue The characters that are combining the string. @return string[] The segments of the string after being separated.
[ "Given", "one", "or", "more", "characters", "as", "glue", "separate", "a", "string", "into", "an", "array", "of", "strings", "." ]
949bd1933c8dceac5543e9758daf11d93b2bb69e
https://github.com/jakew/cases/blob/949bd1933c8dceac5543e9758daf11d93b2bb69e/src/Phrase.php#L138-L142
4,172
jakew/cases
src/Phrase.php
Phrase.decodeSnakeCase
public static function decodeSnakeCase(string $phrase, string $glue = '-') { return self::decode($phrase, self::CONCATENATION_TYPE_GLUE, $glue); }
php
public static function decodeSnakeCase(string $phrase, string $glue = '-') { return self::decode($phrase, self::CONCATENATION_TYPE_GLUE, $glue); }
[ "public", "static", "function", "decodeSnakeCase", "(", "string", "$", "phrase", ",", "string", "$", "glue", "=", "'-'", ")", "{", "return", "self", "::", "decode", "(", "$", "phrase", ",", "self", "::", "CONCATENATION_TYPE_GLUE", ",", "$", "glue", ")", ";", "}" ]
Convenience method to separate snake cased words. @param string $phrase The snake cased string. @param string $glue The character(s) to separate by. @return Phrase The object with each word, ready to be converted.
[ "Convenience", "method", "to", "separate", "snake", "cased", "words", "." ]
949bd1933c8dceac5543e9758daf11d93b2bb69e
https://github.com/jakew/cases/blob/949bd1933c8dceac5543e9758daf11d93b2bb69e/src/Phrase.php#L162-L165
4,173
devbr/database
Config/Devbr/Database.php
Database.get
static function get($alias = null) { if ($alias === null) { return static::$config[static::$default]; } if (isset(static::$config[$alias])) { return static::$config[$alias]; } else { return false; } }
php
static function get($alias = null) { if ($alias === null) { return static::$config[static::$default]; } if (isset(static::$config[$alias])) { return static::$config[$alias]; } else { return false; } }
[ "static", "function", "get", "(", "$", "alias", "=", "null", ")", "{", "if", "(", "$", "alias", "===", "null", ")", "{", "return", "static", "::", "$", "config", "[", "static", "::", "$", "default", "]", ";", "}", "if", "(", "isset", "(", "static", "::", "$", "config", "[", "$", "alias", "]", ")", ")", "{", "return", "static", "::", "$", "config", "[", "$", "alias", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Get Database configurations @param string $alias Database config name @return bool|array Array (or false) of the configurations
[ "Get", "Database", "configurations" ]
09269a39be6dd70d68cc3e6ffa18c23a09205238
https://github.com/devbr/database/blob/09269a39be6dd70d68cc3e6ffa18c23a09205238/Config/Devbr/Database.php#L55-L65
4,174
dpeuscher/DpZFExtensions
src/DpZFExtensions/Validator/TExchangeState.php
TExchangeState.exchangeArray
public function exchangeArray(array $state) { if ($this instanceof IValueObject && $this->isExchanged()) throw new Exception("Cannot change ValueObjects. Create new object instead"); if ($this instanceof IValidatorAware && !is_null($this->getValidator()) && !$this->getValidator()->isValid($state)) { $stateRep = array(); foreach ($state as $key => $val) $stateRep[] = $key.' => '. (is_object($val)?'[Object]':(is_resource($val)?'[Resource]':var_export($val,true))); throw new InvalidStateException("ExchangeArray called with an invalid state: ". var_export($this->getValidator()->getMessages(),true)."\n\n(".implode(',',$stateRep).')'); } $toSet = $this->getStateVarsWithAll(); foreach ($this->getStateVO() as $voIndex) if (isset($state[$voIndex])) { $vo = $state[$voIndex]; if ($vo instanceof IExchangeState) $state = array_merge($state,$vo->getArrayCopy()); } foreach ($toSet as $var) { if (isset($state[$var])) { $value = $state[$var]; if ($this instanceof IValueObject && $value instanceof IFreezable) $value->freeze(); // @TODO Add fields of ValueObjects to motherObject $this->{self::_privatizeField($var)} = $value; } else $this->{self::_privatizeField($var)} = null; } if ($this instanceof IValueObject) $this->markExchanged(); }
php
public function exchangeArray(array $state) { if ($this instanceof IValueObject && $this->isExchanged()) throw new Exception("Cannot change ValueObjects. Create new object instead"); if ($this instanceof IValidatorAware && !is_null($this->getValidator()) && !$this->getValidator()->isValid($state)) { $stateRep = array(); foreach ($state as $key => $val) $stateRep[] = $key.' => '. (is_object($val)?'[Object]':(is_resource($val)?'[Resource]':var_export($val,true))); throw new InvalidStateException("ExchangeArray called with an invalid state: ". var_export($this->getValidator()->getMessages(),true)."\n\n(".implode(',',$stateRep).')'); } $toSet = $this->getStateVarsWithAll(); foreach ($this->getStateVO() as $voIndex) if (isset($state[$voIndex])) { $vo = $state[$voIndex]; if ($vo instanceof IExchangeState) $state = array_merge($state,$vo->getArrayCopy()); } foreach ($toSet as $var) { if (isset($state[$var])) { $value = $state[$var]; if ($this instanceof IValueObject && $value instanceof IFreezable) $value->freeze(); // @TODO Add fields of ValueObjects to motherObject $this->{self::_privatizeField($var)} = $value; } else $this->{self::_privatizeField($var)} = null; } if ($this instanceof IValueObject) $this->markExchanged(); }
[ "public", "function", "exchangeArray", "(", "array", "$", "state", ")", "{", "if", "(", "$", "this", "instanceof", "IValueObject", "&&", "$", "this", "->", "isExchanged", "(", ")", ")", "throw", "new", "Exception", "(", "\"Cannot change ValueObjects. Create new object instead\"", ")", ";", "if", "(", "$", "this", "instanceof", "IValidatorAware", "&&", "!", "is_null", "(", "$", "this", "->", "getValidator", "(", ")", ")", "&&", "!", "$", "this", "->", "getValidator", "(", ")", "->", "isValid", "(", "$", "state", ")", ")", "{", "$", "stateRep", "=", "array", "(", ")", ";", "foreach", "(", "$", "state", "as", "$", "key", "=>", "$", "val", ")", "$", "stateRep", "[", "]", "=", "$", "key", ".", "' => '", ".", "(", "is_object", "(", "$", "val", ")", "?", "'[Object]'", ":", "(", "is_resource", "(", "$", "val", ")", "?", "'[Resource]'", ":", "var_export", "(", "$", "val", ",", "true", ")", ")", ")", ";", "throw", "new", "InvalidStateException", "(", "\"ExchangeArray called with an invalid state: \"", ".", "var_export", "(", "$", "this", "->", "getValidator", "(", ")", "->", "getMessages", "(", ")", ",", "true", ")", ".", "\"\\n\\n(\"", ".", "implode", "(", "','", ",", "$", "stateRep", ")", ".", "')'", ")", ";", "}", "$", "toSet", "=", "$", "this", "->", "getStateVarsWithAll", "(", ")", ";", "foreach", "(", "$", "this", "->", "getStateVO", "(", ")", "as", "$", "voIndex", ")", "if", "(", "isset", "(", "$", "state", "[", "$", "voIndex", "]", ")", ")", "{", "$", "vo", "=", "$", "state", "[", "$", "voIndex", "]", ";", "if", "(", "$", "vo", "instanceof", "IExchangeState", ")", "$", "state", "=", "array_merge", "(", "$", "state", ",", "$", "vo", "->", "getArrayCopy", "(", ")", ")", ";", "}", "foreach", "(", "$", "toSet", "as", "$", "var", ")", "{", "if", "(", "isset", "(", "$", "state", "[", "$", "var", "]", ")", ")", "{", "$", "value", "=", "$", "state", "[", "$", "var", "]", ";", "if", "(", "$", "this", "instanceof", "IValueObject", "&&", "$", "value", "instanceof", "IFreezable", ")", "$", "value", "->", "freeze", "(", ")", ";", "// @TODO Add fields of ValueObjects to motherObject", "$", "this", "->", "{", "self", "::", "_privatizeField", "(", "$", "var", ")", "}", "=", "$", "value", ";", "}", "else", "$", "this", "->", "{", "self", "::", "_privatizeField", "(", "$", "var", ")", "}", "=", "null", ";", "}", "if", "(", "$", "this", "instanceof", "IValueObject", ")", "$", "this", "->", "markExchanged", "(", ")", ";", "}" ]
Implements a state into an entity @param $state array @throws InvalidStateException if the state is not valid @throws \Exception
[ "Implements", "a", "state", "into", "an", "entity" ]
e0194daca449601a58f5b2fc019dbdbd1a1b1b89
https://github.com/dpeuscher/DpZFExtensions/blob/e0194daca449601a58f5b2fc019dbdbd1a1b1b89/src/DpZFExtensions/Validator/TExchangeState.php#L76-L108
4,175
veridu/idos-sdk-php
src/idOS/Auth/UserToken.php
UserToken.getToken
public function getToken() : string { if (($this->token === null) || ($this->token->isExpired())) { $jwtBuilder = new Builder(); $jwtBuilder->set('iss', $this->credentialPublicKey); $jwtBuilder->set('sub', $this->userName); $this->token = $jwtBuilder ->sign(new Sha256(), $this->credentialPrivateKey) ->getToken(); } return (string) $this->token; }
php
public function getToken() : string { if (($this->token === null) || ($this->token->isExpired())) { $jwtBuilder = new Builder(); $jwtBuilder->set('iss', $this->credentialPublicKey); $jwtBuilder->set('sub', $this->userName); $this->token = $jwtBuilder ->sign(new Sha256(), $this->credentialPrivateKey) ->getToken(); } return (string) $this->token; }
[ "public", "function", "getToken", "(", ")", ":", "string", "{", "if", "(", "(", "$", "this", "->", "token", "===", "null", ")", "||", "(", "$", "this", "->", "token", "->", "isExpired", "(", ")", ")", ")", "{", "$", "jwtBuilder", "=", "new", "Builder", "(", ")", ";", "$", "jwtBuilder", "->", "set", "(", "'iss'", ",", "$", "this", "->", "credentialPublicKey", ")", ";", "$", "jwtBuilder", "->", "set", "(", "'sub'", ",", "$", "this", "->", "userName", ")", ";", "$", "this", "->", "token", "=", "$", "jwtBuilder", "->", "sign", "(", "new", "Sha256", "(", ")", ",", "$", "this", "->", "credentialPrivateKey", ")", "->", "getToken", "(", ")", ";", "}", "return", "(", "string", ")", "$", "this", "->", "token", ";", "}" ]
Generates the User Token and returns it. @return string userToken
[ "Generates", "the", "User", "Token", "and", "returns", "it", "." ]
e56757bed10404756f2f0485a4b7f55794192008
https://github.com/veridu/idos-sdk-php/blob/e56757bed10404756f2f0485a4b7f55794192008/src/idOS/Auth/UserToken.php#L50-L62
4,176
ntentan/utils
src/Text.php
Text.camelize
public static function camelize($string, $separator = '_') : string { if(is_array($separator)) { $separator = "(\\" . implode("|\\", $separator) . ")"; } else { $separator = '\\' . $separator; } return preg_replace_callback( "/{$separator}[a-zA-Z]/", function ($matches) { return strtoupper($matches[0][1]); }, strtolower($string) ); }
php
public static function camelize($string, $separator = '_') : string { if(is_array($separator)) { $separator = "(\\" . implode("|\\", $separator) . ")"; } else { $separator = '\\' . $separator; } return preg_replace_callback( "/{$separator}[a-zA-Z]/", function ($matches) { return strtoupper($matches[0][1]); }, strtolower($string) ); }
[ "public", "static", "function", "camelize", "(", "$", "string", ",", "$", "separator", "=", "'_'", ")", ":", "string", "{", "if", "(", "is_array", "(", "$", "separator", ")", ")", "{", "$", "separator", "=", "\"(\\\\\"", ".", "implode", "(", "\"|\\\\\"", ",", "$", "separator", ")", ".", "\")\"", ";", "}", "else", "{", "$", "separator", "=", "'\\\\'", ".", "$", "separator", ";", "}", "return", "preg_replace_callback", "(", "\"/{$separator}[a-zA-Z]/\"", ",", "function", "(", "$", "matches", ")", "{", "return", "strtoupper", "(", "$", "matches", "[", "0", "]", "[", "1", "]", ")", ";", "}", ",", "strtolower", "(", "$", "string", ")", ")", ";", "}" ]
Converts text separated by a specified separator to camel case. This function converts the entire text into lower case before performing the camel case conversion. Due to this the first character would be lowercased. @param string $string The text to be converted. @param string $separator The separator to consider for camel casing @return string
[ "Converts", "text", "separated", "by", "a", "specified", "separator", "to", "camel", "case", ".", "This", "function", "converts", "the", "entire", "text", "into", "lower", "case", "before", "performing", "the", "camel", "case", "conversion", ".", "Due", "to", "this", "the", "first", "character", "would", "be", "lowercased", "." ]
151f3582ee6007ea77a38d2b6c590289331e19a1
https://github.com/ntentan/utils/blob/151f3582ee6007ea77a38d2b6c590289331e19a1/src/Text.php#L121-L139
4,177
ntentan/utils
src/Text.php
Text.deCamelize
public static function deCamelize($string, $separator = '_') : string { return preg_replace_callback( "/[A-Z][a-z]/", function ($matches) use($separator) { return $separator . strtolower($matches[0]); }, lcfirst($string) ); }
php
public static function deCamelize($string, $separator = '_') : string { return preg_replace_callback( "/[A-Z][a-z]/", function ($matches) use($separator) { return $separator . strtolower($matches[0]); }, lcfirst($string) ); }
[ "public", "static", "function", "deCamelize", "(", "$", "string", ",", "$", "separator", "=", "'_'", ")", ":", "string", "{", "return", "preg_replace_callback", "(", "\"/[A-Z][a-z]/\"", ",", "function", "(", "$", "matches", ")", "use", "(", "$", "separator", ")", "{", "return", "$", "separator", ".", "strtolower", "(", "$", "matches", "[", "0", "]", ")", ";", "}", ",", "lcfirst", "(", "$", "string", ")", ")", ";", "}" ]
Converts camel case text into regular text separated with an arbitrary separator. By default the seperator is an underscore. A space can also be used as the seperator in cases where the conversion is to an English sentence. @param string $string The text to be converted. @param string $separator The separator to be used. @return string
[ "Converts", "camel", "case", "text", "into", "regular", "text", "separated", "with", "an", "arbitrary", "separator", ".", "By", "default", "the", "seperator", "is", "an", "underscore", ".", "A", "space", "can", "also", "be", "used", "as", "the", "seperator", "in", "cases", "where", "the", "conversion", "is", "to", "an", "English", "sentence", "." ]
151f3582ee6007ea77a38d2b6c590289331e19a1
https://github.com/ntentan/utils/blob/151f3582ee6007ea77a38d2b6c590289331e19a1/src/Text.php#L164-L174
4,178
ntentan/utils
src/Text.php
Text.runInflection
private static function runInflection($text, $rules) { if(in_array($text, self::$noPlurals)) { return $text; } foreach($rules as $rule) { if(preg_match($rule[0], $text, $matches)) { return substr($text, 0, strlen($text) - strlen($matches['remove'] ?? '')) . $rule[1]; } } }
php
private static function runInflection($text, $rules) { if(in_array($text, self::$noPlurals)) { return $text; } foreach($rules as $rule) { if(preg_match($rule[0], $text, $matches)) { return substr($text, 0, strlen($text) - strlen($matches['remove'] ?? '')) . $rule[1]; } } }
[ "private", "static", "function", "runInflection", "(", "$", "text", ",", "$", "rules", ")", "{", "if", "(", "in_array", "(", "$", "text", ",", "self", "::", "$", "noPlurals", ")", ")", "{", "return", "$", "text", ";", "}", "foreach", "(", "$", "rules", "as", "$", "rule", ")", "{", "if", "(", "preg_match", "(", "$", "rule", "[", "0", "]", ",", "$", "text", ",", "$", "matches", ")", ")", "{", "return", "substr", "(", "$", "text", ",", "0", ",", "strlen", "(", "$", "text", ")", "-", "strlen", "(", "$", "matches", "[", "'remove'", "]", "??", "''", ")", ")", ".", "$", "rule", "[", "1", "]", ";", "}", "}", "}" ]
Run through the rules and generate a text transformation. @param string $text @param array $rules @return string|null
[ "Run", "through", "the", "rules", "and", "generate", "a", "text", "transformation", "." ]
151f3582ee6007ea77a38d2b6c590289331e19a1
https://github.com/ntentan/utils/blob/151f3582ee6007ea77a38d2b6c590289331e19a1/src/Text.php#L183-L193
4,179
laasti/symfony-translation-provider
src/TranslatorAwareTrait.php
TranslatorAwareTrait.setTranslator
public function setTranslator(\Symfony\Component\Translation\Translator $translator) { $this->translator = $translator; return $this->translator; }
php
public function setTranslator(\Symfony\Component\Translation\Translator $translator) { $this->translator = $translator; return $this->translator; }
[ "public", "function", "setTranslator", "(", "\\", "Symfony", "\\", "Component", "\\", "Translation", "\\", "Translator", "$", "translator", ")", "{", "$", "this", "->", "translator", "=", "$", "translator", ";", "return", "$", "this", "->", "translator", ";", "}" ]
Set translator instance @param \Symfony\Component\Translation\Translator $translator @return \Symfony\Component\Translation\Translator
[ "Set", "translator", "instance" ]
8e1acac57edbb754f8cbb1b5f9fd9d96799ea710
https://github.com/laasti/symfony-translation-provider/blob/8e1acac57edbb754f8cbb1b5f9fd9d96799ea710/src/TranslatorAwareTrait.php#L18-L22
4,180
laasti/symfony-translation-provider
src/TranslatorAwareTrait.php
TranslatorAwareTrait.trans
public function trans($id, $params = [], $domain = null, $locale = null) { return $this->getTranslator()->trans($id, $params, $domain, $locale); }
php
public function trans($id, $params = [], $domain = null, $locale = null) { return $this->getTranslator()->trans($id, $params, $domain, $locale); }
[ "public", "function", "trans", "(", "$", "id", ",", "$", "params", "=", "[", "]", ",", "$", "domain", "=", "null", ",", "$", "locale", "=", "null", ")", "{", "return", "$", "this", "->", "getTranslator", "(", ")", "->", "trans", "(", "$", "id", ",", "$", "params", ",", "$", "domain", ",", "$", "locale", ")", ";", "}" ]
Translate the id using the translator @param string $id The message id @param array params An array of parameters for the message @param string|null $domain The domain for the message @param string|null $locale The locale @return string The translated string
[ "Translate", "the", "id", "using", "the", "translator" ]
8e1acac57edbb754f8cbb1b5f9fd9d96799ea710
https://github.com/laasti/symfony-translation-provider/blob/8e1acac57edbb754f8cbb1b5f9fd9d96799ea710/src/TranslatorAwareTrait.php#L42-L45
4,181
shopery/view
src/Factory/RegistryViewFactory.php
RegistryViewFactory.createView
public function createView($object) { if (!is_object($object)) { return null; } foreach ($this->registry as $className => $viewFactory) { if ($object instanceof $className) { return $viewFactory->createView($object); } } }
php
public function createView($object) { if (!is_object($object)) { return null; } foreach ($this->registry as $className => $viewFactory) { if ($object instanceof $className) { return $viewFactory->createView($object); } } }
[ "public", "function", "createView", "(", "$", "object", ")", "{", "if", "(", "!", "is_object", "(", "$", "object", ")", ")", "{", "return", "null", ";", "}", "foreach", "(", "$", "this", "->", "registry", "as", "$", "className", "=>", "$", "viewFactory", ")", "{", "if", "(", "$", "object", "instanceof", "$", "className", ")", "{", "return", "$", "viewFactory", "->", "createView", "(", "$", "object", ")", ";", "}", "}", "}" ]
Create a view for the object, looking for a suitable factory @param $object @return View
[ "Create", "a", "view", "for", "the", "object", "looking", "for", "a", "suitable", "factory" ]
cc38154a2b649ec99e7eb13f79b99cdf143bd4af
https://github.com/shopery/view/blob/cc38154a2b649ec99e7eb13f79b99cdf143bd4af/src/Factory/RegistryViewFactory.php#L59-L71
4,182
Gelembjuk/locale
src/Gelembjuk/Locale/Utils.php
Utils.getAllGrupsWithMisses
public function getAllGrupsWithMisses($deflocale,$includingmissedindef = true) { $result = array(); $translate = $this->getTranslateObject(); $translate->setLocale($deflocale); $defgroups = $translate->getAllGroups(); $usedlanguages = $this->getUsedLanguages(); foreach ($usedlanguages as $lang => $langdata) { foreach ($defgroups as $group) { $difference = $this->getDifference($group,$lang,$deflocale); if ($difference['missedcount'] > 0) { if (!is_array($result[$lang])) { $result[$lang] = array(); } $result[$lang][$group] = $difference['missedcount']; } } } return $result; }
php
public function getAllGrupsWithMisses($deflocale,$includingmissedindef = true) { $result = array(); $translate = $this->getTranslateObject(); $translate->setLocale($deflocale); $defgroups = $translate->getAllGroups(); $usedlanguages = $this->getUsedLanguages(); foreach ($usedlanguages as $lang => $langdata) { foreach ($defgroups as $group) { $difference = $this->getDifference($group,$lang,$deflocale); if ($difference['missedcount'] > 0) { if (!is_array($result[$lang])) { $result[$lang] = array(); } $result[$lang][$group] = $difference['missedcount']; } } } return $result; }
[ "public", "function", "getAllGrupsWithMisses", "(", "$", "deflocale", ",", "$", "includingmissedindef", "=", "true", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "translate", "=", "$", "this", "->", "getTranslateObject", "(", ")", ";", "$", "translate", "->", "setLocale", "(", "$", "deflocale", ")", ";", "$", "defgroups", "=", "$", "translate", "->", "getAllGroups", "(", ")", ";", "$", "usedlanguages", "=", "$", "this", "->", "getUsedLanguages", "(", ")", ";", "foreach", "(", "$", "usedlanguages", "as", "$", "lang", "=>", "$", "langdata", ")", "{", "foreach", "(", "$", "defgroups", "as", "$", "group", ")", "{", "$", "difference", "=", "$", "this", "->", "getDifference", "(", "$", "group", ",", "$", "lang", ",", "$", "deflocale", ")", ";", "if", "(", "$", "difference", "[", "'missedcount'", "]", ">", "0", ")", "{", "if", "(", "!", "is_array", "(", "$", "result", "[", "$", "lang", "]", ")", ")", "{", "$", "result", "[", "$", "lang", "]", "=", "array", "(", ")", ";", "}", "$", "result", "[", "$", "lang", "]", "[", "$", "group", "]", "=", "$", "difference", "[", "'missedcount'", "]", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Returns all groups-locale associations where are some data missed comparing to def locale @param string $deflocale Default locale to use as a base for comparing @param bool $includingmissedindef Defines if to check what is present in other locales and missed in def locale
[ "Returns", "all", "groups", "-", "locale", "associations", "where", "are", "some", "data", "missed", "comparing", "to", "def", "locale" ]
4d59f6518bf765c3653f3d2583e6e262ff8bfb29
https://github.com/Gelembjuk/locale/blob/4d59f6518bf765c3653f3d2583e6e262ff8bfb29/src/Gelembjuk/Locale/Utils.php#L32-L57
4,183
Gelembjuk/locale
src/Gelembjuk/Locale/Utils.php
Utils.getDifference
public function getDifference($group,$locale,$deflocale) { $translate = $this->getTranslateObject(); $translate->setLocale($deflocale); $allkeys = $translate->getAllKeysForGroup($group); $translate->setLocale($locale); $result['groupmissed'] = false; try { $keys = $translate->getAllKeysForGroup($group); } catch (\Exception $e) { $result['groupmissed'] = true; $keys = array(); } $result['missed'] = array_values(array_diff($allkeys,$keys)); $result['extra'] = array_values(array_diff($keys,$allkeys)); $result['missedcount'] = count($result['missed']); $result['extracount'] = count($result['extra']); $result['total'] = $result['missedcount']+$result['extracount']; return $result; }
php
public function getDifference($group,$locale,$deflocale) { $translate = $this->getTranslateObject(); $translate->setLocale($deflocale); $allkeys = $translate->getAllKeysForGroup($group); $translate->setLocale($locale); $result['groupmissed'] = false; try { $keys = $translate->getAllKeysForGroup($group); } catch (\Exception $e) { $result['groupmissed'] = true; $keys = array(); } $result['missed'] = array_values(array_diff($allkeys,$keys)); $result['extra'] = array_values(array_diff($keys,$allkeys)); $result['missedcount'] = count($result['missed']); $result['extracount'] = count($result['extra']); $result['total'] = $result['missedcount']+$result['extracount']; return $result; }
[ "public", "function", "getDifference", "(", "$", "group", ",", "$", "locale", ",", "$", "deflocale", ")", "{", "$", "translate", "=", "$", "this", "->", "getTranslateObject", "(", ")", ";", "$", "translate", "->", "setLocale", "(", "$", "deflocale", ")", ";", "$", "allkeys", "=", "$", "translate", "->", "getAllKeysForGroup", "(", "$", "group", ")", ";", "$", "translate", "->", "setLocale", "(", "$", "locale", ")", ";", "$", "result", "[", "'groupmissed'", "]", "=", "false", ";", "try", "{", "$", "keys", "=", "$", "translate", "->", "getAllKeysForGroup", "(", "$", "group", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "result", "[", "'groupmissed'", "]", "=", "true", ";", "$", "keys", "=", "array", "(", ")", ";", "}", "$", "result", "[", "'missed'", "]", "=", "array_values", "(", "array_diff", "(", "$", "allkeys", ",", "$", "keys", ")", ")", ";", "$", "result", "[", "'extra'", "]", "=", "array_values", "(", "array_diff", "(", "$", "keys", ",", "$", "allkeys", ")", ")", ";", "$", "result", "[", "'missedcount'", "]", "=", "count", "(", "$", "result", "[", "'missed'", "]", ")", ";", "$", "result", "[", "'extracount'", "]", "=", "count", "(", "$", "result", "[", "'extra'", "]", ")", ";", "$", "result", "[", "'total'", "]", "=", "$", "result", "[", "'missedcount'", "]", "+", "$", "result", "[", "'extracount'", "]", ";", "return", "$", "result", ";", "}" ]
Returns information about difference between same group file in different locales an be used to find what is missed in secondary languages files @param string $group Translation group @param string $locale Locale to compare to default locale @param string $deflocale Default locale to use as a base for comparing @return array
[ "Returns", "information", "about", "difference", "between", "same", "group", "file", "in", "different", "locales", "an", "be", "used", "to", "find", "what", "is", "missed", "in", "secondary", "languages", "files" ]
4d59f6518bf765c3653f3d2583e6e262ff8bfb29
https://github.com/Gelembjuk/locale/blob/4d59f6518bf765c3653f3d2583e6e262ff8bfb29/src/Gelembjuk/Locale/Utils.php#L68-L94
4,184
Gelembjuk/locale
src/Gelembjuk/Locale/Utils.php
Utils.getMissedKeysTemplate
public function getMissedKeysTemplate($group,$locale,$deflocale,$mode = 'empty',$returntype = 'text', $textlinesplitter = "\n") { $translate = $this->getTranslateObject(true); $translate->setLocale($deflocale); $difference = $this->getDifference($group,$locale,$deflocale); $fixtextlines = array(); foreach ($difference['missed'] as $key) { $line = $key.' = '; if ($mode == 'empty') { $line .= '#'; } $defvalue = $translate->getText($key,$group); $line .= $defvalue; if ($returntype == 'hash') { $fixtextlines[$key] = $defvalue; } else { $fixtextlines[] = $line; } } if ($returntype == 'lines' || $returntype == 'hash') { return $fixtextline; } return implode($textlinesplitter,$fixtextlines); }
php
public function getMissedKeysTemplate($group,$locale,$deflocale,$mode = 'empty',$returntype = 'text', $textlinesplitter = "\n") { $translate = $this->getTranslateObject(true); $translate->setLocale($deflocale); $difference = $this->getDifference($group,$locale,$deflocale); $fixtextlines = array(); foreach ($difference['missed'] as $key) { $line = $key.' = '; if ($mode == 'empty') { $line .= '#'; } $defvalue = $translate->getText($key,$group); $line .= $defvalue; if ($returntype == 'hash') { $fixtextlines[$key] = $defvalue; } else { $fixtextlines[] = $line; } } if ($returntype == 'lines' || $returntype == 'hash') { return $fixtextline; } return implode($textlinesplitter,$fixtextlines); }
[ "public", "function", "getMissedKeysTemplate", "(", "$", "group", ",", "$", "locale", ",", "$", "deflocale", ",", "$", "mode", "=", "'empty'", ",", "$", "returntype", "=", "'text'", ",", "$", "textlinesplitter", "=", "\"\\n\"", ")", "{", "$", "translate", "=", "$", "this", "->", "getTranslateObject", "(", "true", ")", ";", "$", "translate", "->", "setLocale", "(", "$", "deflocale", ")", ";", "$", "difference", "=", "$", "this", "->", "getDifference", "(", "$", "group", ",", "$", "locale", ",", "$", "deflocale", ")", ";", "$", "fixtextlines", "=", "array", "(", ")", ";", "foreach", "(", "$", "difference", "[", "'missed'", "]", "as", "$", "key", ")", "{", "$", "line", "=", "$", "key", ".", "' = '", ";", "if", "(", "$", "mode", "==", "'empty'", ")", "{", "$", "line", ".=", "'#'", ";", "}", "$", "defvalue", "=", "$", "translate", "->", "getText", "(", "$", "key", ",", "$", "group", ")", ";", "$", "line", ".=", "$", "defvalue", ";", "if", "(", "$", "returntype", "==", "'hash'", ")", "{", "$", "fixtextlines", "[", "$", "key", "]", "=", "$", "defvalue", ";", "}", "else", "{", "$", "fixtextlines", "[", "]", "=", "$", "line", ";", "}", "}", "if", "(", "$", "returntype", "==", "'lines'", "||", "$", "returntype", "==", "'hash'", ")", "{", "return", "$", "fixtextline", ";", "}", "return", "implode", "(", "$", "textlinesplitter", ",", "$", "fixtextlines", ")", ";", "}" ]
Returns text of array of lines to add toa secondary locale group to correct it @param string $group Translation group @param string $locale Locale to compare to default locale @param string $deflocale Default locale to use as a base for comparing @param string $mode `empty` or `default`. If empty then generated keys are empty and deflocale value is added as comment @return array|string
[ "Returns", "text", "of", "array", "of", "lines", "to", "add", "toa", "secondary", "locale", "group", "to", "correct", "it" ]
4d59f6518bf765c3653f3d2583e6e262ff8bfb29
https://github.com/Gelembjuk/locale/blob/4d59f6518bf765c3653f3d2583e6e262ff8bfb29/src/Gelembjuk/Locale/Utils.php#L105-L133
4,185
Gelembjuk/locale
src/Gelembjuk/Locale/Utils.php
Utils.fixMissedKeysFromTemplate
public function fixMissedKeysFromTemplate($group,$locale,$deflocale,$mode = 'empty',$textlinesplitter = "\n") { $text = $this->getMissedKeysTemplate($group,$locale,$deflocale,$mode,'text', $textlinesplitter); $translate = $this->getTranslateObject(); $groupfile = $translate->getGroupFile($group,$locale); $groupfilecontents = ''; if (file_exists($groupfile)) { $groupfilecontents = @file_get_contents($groupfile); } $groupfilecontents .= $textlinesplitter . $text; file_put_contents($groupfile,$groupfilecontents); return true; }
php
public function fixMissedKeysFromTemplate($group,$locale,$deflocale,$mode = 'empty',$textlinesplitter = "\n") { $text = $this->getMissedKeysTemplate($group,$locale,$deflocale,$mode,'text', $textlinesplitter); $translate = $this->getTranslateObject(); $groupfile = $translate->getGroupFile($group,$locale); $groupfilecontents = ''; if (file_exists($groupfile)) { $groupfilecontents = @file_get_contents($groupfile); } $groupfilecontents .= $textlinesplitter . $text; file_put_contents($groupfile,$groupfilecontents); return true; }
[ "public", "function", "fixMissedKeysFromTemplate", "(", "$", "group", ",", "$", "locale", ",", "$", "deflocale", ",", "$", "mode", "=", "'empty'", ",", "$", "textlinesplitter", "=", "\"\\n\"", ")", "{", "$", "text", "=", "$", "this", "->", "getMissedKeysTemplate", "(", "$", "group", ",", "$", "locale", ",", "$", "deflocale", ",", "$", "mode", ",", "'text'", ",", "$", "textlinesplitter", ")", ";", "$", "translate", "=", "$", "this", "->", "getTranslateObject", "(", ")", ";", "$", "groupfile", "=", "$", "translate", "->", "getGroupFile", "(", "$", "group", ",", "$", "locale", ")", ";", "$", "groupfilecontents", "=", "''", ";", "if", "(", "file_exists", "(", "$", "groupfile", ")", ")", "{", "$", "groupfilecontents", "=", "@", "file_get_contents", "(", "$", "groupfile", ")", ";", "}", "$", "groupfilecontents", ".=", "$", "textlinesplitter", ".", "$", "text", ";", "file_put_contents", "(", "$", "groupfile", ",", "$", "groupfilecontents", ")", ";", "return", "true", ";", "}" ]
Fixes a group by adding all missed keys with empty values or def locale values @param string $group Translation group @param string $locale Locale to compare to default locale @param string $deflocale Default locale to use as a base for comparing @param string $mode `empty` or `default`. If empty then generated keys are empty and deflocale value is added as comment @return bool
[ "Fixes", "a", "group", "by", "adding", "all", "missed", "keys", "with", "empty", "values", "or", "def", "locale", "values" ]
4d59f6518bf765c3653f3d2583e6e262ff8bfb29
https://github.com/Gelembjuk/locale/blob/4d59f6518bf765c3653f3d2583e6e262ff8bfb29/src/Gelembjuk/Locale/Utils.php#L144-L162
4,186
Gelembjuk/locale
src/Gelembjuk/Locale/Utils.php
Utils.getEmptyKeysWithDefValues
public function getEmptyKeysWithDefValues($group,$locale,$deflocale,$skipfiles = true) { $translate = $this->getTranslateObject(true); $translate->setLocale($deflocale); $allkeys = $translate->getAllKeysForGroup($group); $alltranslates = $translate->getDataForGroup($group); $translate->setLocale($locale); try { $keys = $translate->getAllKeysForGroup($group); $translates = $translate->getDataForGroup($group); } catch (\Exception $e) { $keys = array(); $translates = array(); } $missed = array_values(array_diff($allkeys,$keys)); $result = array(); foreach ($translates as $key => $value) { if ($value == '') { $missed[] = $key; } } foreach ($missed as $key) { $result[$key] = $alltranslates[$key]; if ($result[$key] == '') { $result[$key] = '*'; } elseif (strpos($result[$key],'file:') === 0 && $skipfiles) { unset($result[$key]); } } return $result; }
php
public function getEmptyKeysWithDefValues($group,$locale,$deflocale,$skipfiles = true) { $translate = $this->getTranslateObject(true); $translate->setLocale($deflocale); $allkeys = $translate->getAllKeysForGroup($group); $alltranslates = $translate->getDataForGroup($group); $translate->setLocale($locale); try { $keys = $translate->getAllKeysForGroup($group); $translates = $translate->getDataForGroup($group); } catch (\Exception $e) { $keys = array(); $translates = array(); } $missed = array_values(array_diff($allkeys,$keys)); $result = array(); foreach ($translates as $key => $value) { if ($value == '') { $missed[] = $key; } } foreach ($missed as $key) { $result[$key] = $alltranslates[$key]; if ($result[$key] == '') { $result[$key] = '*'; } elseif (strpos($result[$key],'file:') === 0 && $skipfiles) { unset($result[$key]); } } return $result; }
[ "public", "function", "getEmptyKeysWithDefValues", "(", "$", "group", ",", "$", "locale", ",", "$", "deflocale", ",", "$", "skipfiles", "=", "true", ")", "{", "$", "translate", "=", "$", "this", "->", "getTranslateObject", "(", "true", ")", ";", "$", "translate", "->", "setLocale", "(", "$", "deflocale", ")", ";", "$", "allkeys", "=", "$", "translate", "->", "getAllKeysForGroup", "(", "$", "group", ")", ";", "$", "alltranslates", "=", "$", "translate", "->", "getDataForGroup", "(", "$", "group", ")", ";", "$", "translate", "->", "setLocale", "(", "$", "locale", ")", ";", "try", "{", "$", "keys", "=", "$", "translate", "->", "getAllKeysForGroup", "(", "$", "group", ")", ";", "$", "translates", "=", "$", "translate", "->", "getDataForGroup", "(", "$", "group", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "keys", "=", "array", "(", ")", ";", "$", "translates", "=", "array", "(", ")", ";", "}", "$", "missed", "=", "array_values", "(", "array_diff", "(", "$", "allkeys", ",", "$", "keys", ")", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "translates", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "==", "''", ")", "{", "$", "missed", "[", "]", "=", "$", "key", ";", "}", "}", "foreach", "(", "$", "missed", "as", "$", "key", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "alltranslates", "[", "$", "key", "]", ";", "if", "(", "$", "result", "[", "$", "key", "]", "==", "''", ")", "{", "$", "result", "[", "$", "key", "]", "=", "'*'", ";", "}", "elseif", "(", "strpos", "(", "$", "result", "[", "$", "key", "]", ",", "'file:'", ")", "===", "0", "&&", "$", "skipfiles", ")", "{", "unset", "(", "$", "result", "[", "$", "key", "]", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns all empty keys from a group and associated values from def locale group @param string $group Translation group @param string $locale Locale to compare to default locale @param string $deflocale Default locale to use as a base for comparing @param bool $skipfiles If to skip keys pointing to files with a text @return array|string
[ "Returns", "all", "empty", "keys", "from", "a", "group", "and", "associated", "values", "from", "def", "locale", "group" ]
4d59f6518bf765c3653f3d2583e6e262ff8bfb29
https://github.com/Gelembjuk/locale/blob/4d59f6518bf765c3653f3d2583e6e262ff8bfb29/src/Gelembjuk/Locale/Utils.php#L173-L211
4,187
Gelembjuk/locale
src/Gelembjuk/Locale/Utils.php
Utils.fixMissedKeysFromList
public function fixMissedKeysFromList($lines,$group,$locale,$deflocale,$skipfiles = true, $textlinesplitter = "\n") { $list = $this->getEmptyKeysWithDefValues($group,$locale,$deflocale,$skipfiles); if (count($list) != count($lines)) { throw new \Exception(sprintf('Wrong count of input lines. %d vs %d',count($list),count($lines))); } $translate = $this->getTranslateObject(true); $translate->setLocale($locale); try { $translates = $translate->getDataForGroup($group); } catch (\Exception $e) { $translates = array(); } // assign new values and keys foreach ($list as $key => $value) { $value = array_shift($lines); $translates[$key] = $value; } $groupfile = $translate->getGroupFile($group,$locale); array_walk($translates, function(&$value, $key) { $value = "$key = $value"; }); $groupfilecontents .= implode($textlinesplitter,$translates).$textlinesplitter; file_put_contents($groupfile,$groupfilecontents); return true; }
php
public function fixMissedKeysFromList($lines,$group,$locale,$deflocale,$skipfiles = true, $textlinesplitter = "\n") { $list = $this->getEmptyKeysWithDefValues($group,$locale,$deflocale,$skipfiles); if (count($list) != count($lines)) { throw new \Exception(sprintf('Wrong count of input lines. %d vs %d',count($list),count($lines))); } $translate = $this->getTranslateObject(true); $translate->setLocale($locale); try { $translates = $translate->getDataForGroup($group); } catch (\Exception $e) { $translates = array(); } // assign new values and keys foreach ($list as $key => $value) { $value = array_shift($lines); $translates[$key] = $value; } $groupfile = $translate->getGroupFile($group,$locale); array_walk($translates, function(&$value, $key) { $value = "$key = $value"; }); $groupfilecontents .= implode($textlinesplitter,$translates).$textlinesplitter; file_put_contents($groupfile,$groupfilecontents); return true; }
[ "public", "function", "fixMissedKeysFromList", "(", "$", "lines", ",", "$", "group", ",", "$", "locale", ",", "$", "deflocale", ",", "$", "skipfiles", "=", "true", ",", "$", "textlinesplitter", "=", "\"\\n\"", ")", "{", "$", "list", "=", "$", "this", "->", "getEmptyKeysWithDefValues", "(", "$", "group", ",", "$", "locale", ",", "$", "deflocale", ",", "$", "skipfiles", ")", ";", "if", "(", "count", "(", "$", "list", ")", "!=", "count", "(", "$", "lines", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Wrong count of input lines. %d vs %d'", ",", "count", "(", "$", "list", ")", ",", "count", "(", "$", "lines", ")", ")", ")", ";", "}", "$", "translate", "=", "$", "this", "->", "getTranslateObject", "(", "true", ")", ";", "$", "translate", "->", "setLocale", "(", "$", "locale", ")", ";", "try", "{", "$", "translates", "=", "$", "translate", "->", "getDataForGroup", "(", "$", "group", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "translates", "=", "array", "(", ")", ";", "}", "// assign new values and keys", "foreach", "(", "$", "list", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "value", "=", "array_shift", "(", "$", "lines", ")", ";", "$", "translates", "[", "$", "key", "]", "=", "$", "value", ";", "}", "$", "groupfile", "=", "$", "translate", "->", "getGroupFile", "(", "$", "group", ",", "$", "locale", ")", ";", "array_walk", "(", "$", "translates", ",", "function", "(", "&", "$", "value", ",", "$", "key", ")", "{", "$", "value", "=", "\"$key = $value\"", ";", "}", ")", ";", "$", "groupfilecontents", ".=", "implode", "(", "$", "textlinesplitter", ",", "$", "translates", ")", ".", "$", "textlinesplitter", ";", "file_put_contents", "(", "$", "groupfile", ",", "$", "groupfilecontents", ")", ";", "return", "true", ";", "}" ]
Receives a group of values as a list and assigns to missed keys in a group of locale. It can be used to quick translate of values as text file with a value per line. @param string $group Translation group @param string $locale Locale to compare to default locale @param string $deflocale Default locale to use as a base for comparing @param bool $skipfiles If to skip keys pointing to files with a text @return bool
[ "Receives", "a", "group", "of", "values", "as", "a", "list", "and", "assigns", "to", "missed", "keys", "in", "a", "group", "of", "locale", ".", "It", "can", "be", "used", "to", "quick", "translate", "of", "values", "as", "text", "file", "with", "a", "value", "per", "line", "." ]
4d59f6518bf765c3653f3d2583e6e262ff8bfb29
https://github.com/Gelembjuk/locale/blob/4d59f6518bf765c3653f3d2583e6e262ff8bfb29/src/Gelembjuk/Locale/Utils.php#L223-L255
4,188
rinvex/obsolete-taggable
src/Tag.php
Tag.setNameAttribute
public function setNameAttribute($value) { $this->attributes['name'] = json_encode(! is_array($value) ? [app()->getLocale() => $value] : $value); }
php
public function setNameAttribute($value) { $this->attributes['name'] = json_encode(! is_array($value) ? [app()->getLocale() => $value] : $value); }
[ "public", "function", "setNameAttribute", "(", "$", "value", ")", "{", "$", "this", "->", "attributes", "[", "'name'", "]", "=", "json_encode", "(", "!", "is_array", "(", "$", "value", ")", "?", "[", "app", "(", ")", "->", "getLocale", "(", ")", "=>", "$", "value", "]", ":", "$", "value", ")", ";", "}" ]
Set the translatable name attribute. @param string $value @return void
[ "Set", "the", "translatable", "name", "attribute", "." ]
661ae32b70e0721db9e20438eb2ff4f1d2308005
https://github.com/rinvex/obsolete-taggable/blob/661ae32b70e0721db9e20438eb2ff4f1d2308005/src/Tag.php#L163-L166
4,189
rinvex/obsolete-taggable
src/Tag.php
Tag.setDescriptionAttribute
public function setDescriptionAttribute($value) { $this->attributes['description'] = ! empty($value) ? json_encode(! is_array($value) ? [app()->getLocale() => $value] : $value) : null; }
php
public function setDescriptionAttribute($value) { $this->attributes['description'] = ! empty($value) ? json_encode(! is_array($value) ? [app()->getLocale() => $value] : $value) : null; }
[ "public", "function", "setDescriptionAttribute", "(", "$", "value", ")", "{", "$", "this", "->", "attributes", "[", "'description'", "]", "=", "!", "empty", "(", "$", "value", ")", "?", "json_encode", "(", "!", "is_array", "(", "$", "value", ")", "?", "[", "app", "(", ")", "->", "getLocale", "(", ")", "=>", "$", "value", "]", ":", "$", "value", ")", ":", "null", ";", "}" ]
Set the translatable description attribute. @param string $value @return void
[ "Set", "the", "translatable", "description", "attribute", "." ]
661ae32b70e0721db9e20438eb2ff4f1d2308005
https://github.com/rinvex/obsolete-taggable/blob/661ae32b70e0721db9e20438eb2ff4f1d2308005/src/Tag.php#L175-L178
4,190
rinvex/obsolete-taggable
src/Tag.php
Tag.scopeWithGroup
public function scopeWithGroup(Builder $query, string $group = null): Builder { return $group ? $query->where('group', $group) : $query; }
php
public function scopeWithGroup(Builder $query, string $group = null): Builder { return $group ? $query->where('group', $group) : $query; }
[ "public", "function", "scopeWithGroup", "(", "Builder", "$", "query", ",", "string", "$", "group", "=", "null", ")", ":", "Builder", "{", "return", "$", "group", "?", "$", "query", "->", "where", "(", "'group'", ",", "$", "group", ")", ":", "$", "query", ";", "}" ]
Scope tags by given group. @param \Illuminate\Database\Eloquent\Builder $query @param string|null $group @return \Illuminate\Database\Eloquent\Builder
[ "Scope", "tags", "by", "given", "group", "." ]
661ae32b70e0721db9e20438eb2ff4f1d2308005
https://github.com/rinvex/obsolete-taggable/blob/661ae32b70e0721db9e20438eb2ff4f1d2308005/src/Tag.php#L213-L216
4,191
rinvex/obsolete-taggable
src/Tag.php
Tag.findManyByNameOrCreate
public static function findManyByNameOrCreate(array $tags, string $group = null, string $locale = null): Collection { // Expects array of tag names return collect($tags)->map(function ($tag) use ($group, $locale) { return static::findByNameOrCreate($tag, $group, $locale); }); }
php
public static function findManyByNameOrCreate(array $tags, string $group = null, string $locale = null): Collection { // Expects array of tag names return collect($tags)->map(function ($tag) use ($group, $locale) { return static::findByNameOrCreate($tag, $group, $locale); }); }
[ "public", "static", "function", "findManyByNameOrCreate", "(", "array", "$", "tags", ",", "string", "$", "group", "=", "null", ",", "string", "$", "locale", "=", "null", ")", ":", "Collection", "{", "// Expects array of tag names", "return", "collect", "(", "$", "tags", ")", "->", "map", "(", "function", "(", "$", "tag", ")", "use", "(", "$", "group", ",", "$", "locale", ")", "{", "return", "static", "::", "findByNameOrCreate", "(", "$", "tag", ",", "$", "group", ",", "$", "locale", ")", ";", "}", ")", ";", "}" ]
Find many tags by name or create if not exists. @param array $tags @param string|null $group @param string|null $locale @return \Illuminate\Support\Collection
[ "Find", "many", "tags", "by", "name", "or", "create", "if", "not", "exists", "." ]
661ae32b70e0721db9e20438eb2ff4f1d2308005
https://github.com/rinvex/obsolete-taggable/blob/661ae32b70e0721db9e20438eb2ff4f1d2308005/src/Tag.php#L227-L233
4,192
rinvex/obsolete-taggable
src/Tag.php
Tag.findByNameOrCreate
public static function findByNameOrCreate(string $name, string $locale = null, string $group = null): Tag { $locale = $locale ?? app()->getLocale(); return static::findByName($name, $locale) ?: static::createByName($name, $locale, $group); }
php
public static function findByNameOrCreate(string $name, string $locale = null, string $group = null): Tag { $locale = $locale ?? app()->getLocale(); return static::findByName($name, $locale) ?: static::createByName($name, $locale, $group); }
[ "public", "static", "function", "findByNameOrCreate", "(", "string", "$", "name", ",", "string", "$", "locale", "=", "null", ",", "string", "$", "group", "=", "null", ")", ":", "Tag", "{", "$", "locale", "=", "$", "locale", "??", "app", "(", ")", "->", "getLocale", "(", ")", ";", "return", "static", "::", "findByName", "(", "$", "name", ",", "$", "locale", ")", "?", ":", "static", "::", "createByName", "(", "$", "name", ",", "$", "locale", ",", "$", "group", ")", ";", "}" ]
Find tag by attribute or create if not exists. @param mixed $name @param string|null $locale @param string|null $group @return static
[ "Find", "tag", "by", "attribute", "or", "create", "if", "not", "exists", "." ]
661ae32b70e0721db9e20438eb2ff4f1d2308005
https://github.com/rinvex/obsolete-taggable/blob/661ae32b70e0721db9e20438eb2ff4f1d2308005/src/Tag.php#L244-L249
4,193
affinitidev/silex-config
Source/ConfigCompiler.php
ConfigCompiler.compile
public function compile() { $loader = $this->loaderFactory->newInstance(); $cache = $this->cacheFactory->produce(); if(true === $cache->expired()) { $config = $this->loadConfig($loader); $cache->write($config); } else { $config = $cache->get(); } return $config; }
php
public function compile() { $loader = $this->loaderFactory->newInstance(); $cache = $this->cacheFactory->produce(); if(true === $cache->expired()) { $config = $this->loadConfig($loader); $cache->write($config); } else { $config = $cache->get(); } return $config; }
[ "public", "function", "compile", "(", ")", "{", "$", "loader", "=", "$", "this", "->", "loaderFactory", "->", "newInstance", "(", ")", ";", "$", "cache", "=", "$", "this", "->", "cacheFactory", "->", "produce", "(", ")", ";", "if", "(", "true", "===", "$", "cache", "->", "expired", "(", ")", ")", "{", "$", "config", "=", "$", "this", "->", "loadConfig", "(", "$", "loader", ")", ";", "$", "cache", "->", "write", "(", "$", "config", ")", ";", "}", "else", "{", "$", "config", "=", "$", "cache", "->", "get", "(", ")", ";", "}", "return", "$", "config", ";", "}" ]
Builds the configuration tree out of all of the App configuration definitions. @return array Array of configuration values.
[ "Builds", "the", "configuration", "tree", "out", "of", "all", "of", "the", "App", "configuration", "definitions", "." ]
6c9cd170b26a6d30f31334ccfaca203304ad8f72
https://github.com/affinitidev/silex-config/blob/6c9cd170b26a6d30f31334ccfaca203304ad8f72/Source/ConfigCompiler.php#L67-L80
4,194
fiedsch/datamanagement
src/Fiedsch/Data/File/Writer.php
Writer.printLine
public function printLine($line) { if (!$this->handle) { throw new \RuntimeException('can not write to file: invalid file handle'); } fwrite($this->handle, $line . "\n"); ++$this->lineNumber; }
php
public function printLine($line) { if (!$this->handle) { throw new \RuntimeException('can not write to file: invalid file handle'); } fwrite($this->handle, $line . "\n"); ++$this->lineNumber; }
[ "public", "function", "printLine", "(", "$", "line", ")", "{", "if", "(", "!", "$", "this", "->", "handle", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'can not write to file: invalid file handle'", ")", ";", "}", "fwrite", "(", "$", "this", "->", "handle", ",", "$", "line", ".", "\"\\n\"", ")", ";", "++", "$", "this", "->", "lineNumber", ";", "}" ]
Write to the file. @param string|null the line to be written to the file or null to write an empty line to the file. Note that a newline char is automatically appended!
[ "Write", "to", "the", "file", "." ]
06e8000399d46e83f848944b73afecabf619f52b
https://github.com/fiedsch/datamanagement/blob/06e8000399d46e83f848944b73afecabf619f52b/src/Fiedsch/Data/File/Writer.php#L57-L64
4,195
roydejong/Enlighten
lib/Http/FileUpload.php
FileUpload.setTemporaryPath
public function setTemporaryPath($temporaryPath) { $this->temporaryPath = $temporaryPath; if (!$this->didMove) { $this->currentPath = $temporaryPath; $this->fileSize = 0; if (file_exists($this->currentPath)) { $this->fileSize = filesize($temporaryPath); } } return $this; }
php
public function setTemporaryPath($temporaryPath) { $this->temporaryPath = $temporaryPath; if (!$this->didMove) { $this->currentPath = $temporaryPath; $this->fileSize = 0; if (file_exists($this->currentPath)) { $this->fileSize = filesize($temporaryPath); } } return $this; }
[ "public", "function", "setTemporaryPath", "(", "$", "temporaryPath", ")", "{", "$", "this", "->", "temporaryPath", "=", "$", "temporaryPath", ";", "if", "(", "!", "$", "this", "->", "didMove", ")", "{", "$", "this", "->", "currentPath", "=", "$", "temporaryPath", ";", "$", "this", "->", "fileSize", "=", "0", ";", "if", "(", "file_exists", "(", "$", "this", "->", "currentPath", ")", ")", "{", "$", "this", "->", "fileSize", "=", "filesize", "(", "$", "temporaryPath", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Sets the path to local temporary file that was created to hold this file upload. @param string $temporaryPath @return $this
[ "Sets", "the", "path", "to", "local", "temporary", "file", "that", "was", "created", "to", "hold", "this", "file", "upload", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Http/FileUpload.php#L137-L151
4,196
roydejong/Enlighten
lib/Http/FileUpload.php
FileUpload.getErrorMessage
public function getErrorMessage() { switch ($this->error) { case UPLOAD_ERR_OK: return 'File uploaded successfully.'; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: return 'The uploaded file exceeds the maximum file size.'; case UPLOAD_ERR_NO_FILE: return 'No file was uploaded.'; case UPLOAD_ERR_PARTIAL: return 'The file was only partially uploaded.'; case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_CANT_WRITE: return 'Could not create temporary file.'; case UPLOAD_ERR_EXTENSION: return 'The upload was blocked.'; } return 'An unknown error occured.'; }
php
public function getErrorMessage() { switch ($this->error) { case UPLOAD_ERR_OK: return 'File uploaded successfully.'; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: return 'The uploaded file exceeds the maximum file size.'; case UPLOAD_ERR_NO_FILE: return 'No file was uploaded.'; case UPLOAD_ERR_PARTIAL: return 'The file was only partially uploaded.'; case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_CANT_WRITE: return 'Could not create temporary file.'; case UPLOAD_ERR_EXTENSION: return 'The upload was blocked.'; } return 'An unknown error occured.'; }
[ "public", "function", "getErrorMessage", "(", ")", "{", "switch", "(", "$", "this", "->", "error", ")", "{", "case", "UPLOAD_ERR_OK", ":", "return", "'File uploaded successfully.'", ";", "case", "UPLOAD_ERR_INI_SIZE", ":", "case", "UPLOAD_ERR_FORM_SIZE", ":", "return", "'The uploaded file exceeds the maximum file size.'", ";", "case", "UPLOAD_ERR_NO_FILE", ":", "return", "'No file was uploaded.'", ";", "case", "UPLOAD_ERR_PARTIAL", ":", "return", "'The file was only partially uploaded.'", ";", "case", "UPLOAD_ERR_NO_TMP_DIR", ":", "case", "UPLOAD_ERR_CANT_WRITE", ":", "return", "'Could not create temporary file.'", ";", "case", "UPLOAD_ERR_EXTENSION", ":", "return", "'The upload was blocked.'", ";", "}", "return", "'An unknown error occured.'", ";", "}" ]
Gets a description of the upload error that has occurred. @return string
[ "Gets", "a", "description", "of", "the", "upload", "error", "that", "has", "occurred", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Http/FileUpload.php#L203-L223
4,197
roydejong/Enlighten
lib/Http/FileUpload.php
FileUpload.saveTo
public function saveTo($targetPath) { if ($this->hasError()) { // We cannot process a file that has errored (empty, incomplete, blocked, ...) return false; } if ($this->getFileSize() <= 0) { // We cannot process empty source files return false; } if (!$this->didMove) { $moveOk = move_uploaded_file($this->getTemporaryPath(), $targetPath); } else { $moveOk = copy($this->getCurrentPath(), $targetPath); } if ($moveOk) { $this->didMove = true; $this->currentPath = $targetPath; } return $moveOk; }
php
public function saveTo($targetPath) { if ($this->hasError()) { // We cannot process a file that has errored (empty, incomplete, blocked, ...) return false; } if ($this->getFileSize() <= 0) { // We cannot process empty source files return false; } if (!$this->didMove) { $moveOk = move_uploaded_file($this->getTemporaryPath(), $targetPath); } else { $moveOk = copy($this->getCurrentPath(), $targetPath); } if ($moveOk) { $this->didMove = true; $this->currentPath = $targetPath; } return $moveOk; }
[ "public", "function", "saveTo", "(", "$", "targetPath", ")", "{", "if", "(", "$", "this", "->", "hasError", "(", ")", ")", "{", "// We cannot process a file that has errored (empty, incomplete, blocked, ...)", "return", "false", ";", "}", "if", "(", "$", "this", "->", "getFileSize", "(", ")", "<=", "0", ")", "{", "// We cannot process empty source files", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "didMove", ")", "{", "$", "moveOk", "=", "move_uploaded_file", "(", "$", "this", "->", "getTemporaryPath", "(", ")", ",", "$", "targetPath", ")", ";", "}", "else", "{", "$", "moveOk", "=", "copy", "(", "$", "this", "->", "getCurrentPath", "(", ")", ",", "$", "targetPath", ")", ";", "}", "if", "(", "$", "moveOk", ")", "{", "$", "this", "->", "didMove", "=", "true", ";", "$", "this", "->", "currentPath", "=", "$", "targetPath", ";", "}", "return", "$", "moveOk", ";", "}" ]
Moves the temporary file to a given location, or copies the previously moved file to a new location. If the destination file already exists, it will be overwritten. The temporary file will be deleted. @param string $targetPath The path to move the file to. @return bool Returns true on success.
[ "Moves", "the", "temporary", "file", "to", "a", "given", "location", "or", "copies", "the", "previously", "moved", "file", "to", "a", "new", "location", ".", "If", "the", "destination", "file", "already", "exists", "it", "will", "be", "overwritten", ".", "The", "temporary", "file", "will", "be", "deleted", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Http/FileUpload.php#L265-L289
4,198
rozaverta/cmf
core/Database/Manager.php
Manager.table
public static function table( $table, $connection = null ) { return self::getInstance()->getConnection($connection)->table($table); }
php
public static function table( $table, $connection = null ) { return self::getInstance()->getConnection($connection)->table($table); }
[ "public", "static", "function", "table", "(", "$", "table", ",", "$", "connection", "=", "null", ")", "{", "return", "self", "::", "getInstance", "(", ")", "->", "getConnection", "(", "$", "connection", ")", "->", "table", "(", "$", "table", ")", ";", "}" ]
Get a fluent query builder instance. @param string $table @param string $connection @return \EApp\Database\Query\Builder
[ "Get", "a", "fluent", "query", "builder", "instance", "." ]
95ed38362e397d1c700ee255f7200234ef98d356
https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Database/Manager.php#L137-L140
4,199
theluckyteam/php-jira
src/jira/Provider/IssueLinksProvider.php
IssueLinksProvider.build
public function build() { $issue = $this->root; $this->issues[$issue->getKey()] = $issue; $unreceivedIssues = array_diff_key($this->issues, $this->populatedIssueKeys); while (count($unreceivedIssues) > 0 && $this->depth < $this->maxDepth) { $unpopulatedIssueKeys = []; foreach ($unreceivedIssues as $issue) { /** @var Issue $issue */ $this->populatedIssueKeys[$issue->getKey()] = 1; foreach ($issue->getLinks() as $issueLink) { $unpopulatedIssueKey = IssueLinkHelper::getLinkedIssueKey($issueLink); if ($unpopulatedIssueKey) { $unpopulatedIssueKeys[$unpopulatedIssueKey] = $unpopulatedIssueKey; } } } $notProcessedIssueKeys = []; foreach ($unpopulatedIssueKeys as $issueKey) { if (!array_key_exists($issueKey, $this->issues)) { $notProcessedIssueKeys[] = $issueKey; } } if ($notProcessedIssueKeys) { $issues = $this->getIssuesFromRepositoryByKeys($notProcessedIssueKeys); foreach ($issues as $issue) { if (!array_key_exists($issue->getKey(), $this->issues)) { $this->issues[$issue->getKey()] = $issue; } } } $unreceivedIssues = array_diff_key($this->issues, $this->populatedIssueKeys); $this->depth++; } }
php
public function build() { $issue = $this->root; $this->issues[$issue->getKey()] = $issue; $unreceivedIssues = array_diff_key($this->issues, $this->populatedIssueKeys); while (count($unreceivedIssues) > 0 && $this->depth < $this->maxDepth) { $unpopulatedIssueKeys = []; foreach ($unreceivedIssues as $issue) { /** @var Issue $issue */ $this->populatedIssueKeys[$issue->getKey()] = 1; foreach ($issue->getLinks() as $issueLink) { $unpopulatedIssueKey = IssueLinkHelper::getLinkedIssueKey($issueLink); if ($unpopulatedIssueKey) { $unpopulatedIssueKeys[$unpopulatedIssueKey] = $unpopulatedIssueKey; } } } $notProcessedIssueKeys = []; foreach ($unpopulatedIssueKeys as $issueKey) { if (!array_key_exists($issueKey, $this->issues)) { $notProcessedIssueKeys[] = $issueKey; } } if ($notProcessedIssueKeys) { $issues = $this->getIssuesFromRepositoryByKeys($notProcessedIssueKeys); foreach ($issues as $issue) { if (!array_key_exists($issue->getKey(), $this->issues)) { $this->issues[$issue->getKey()] = $issue; } } } $unreceivedIssues = array_diff_key($this->issues, $this->populatedIssueKeys); $this->depth++; } }
[ "public", "function", "build", "(", ")", "{", "$", "issue", "=", "$", "this", "->", "root", ";", "$", "this", "->", "issues", "[", "$", "issue", "->", "getKey", "(", ")", "]", "=", "$", "issue", ";", "$", "unreceivedIssues", "=", "array_diff_key", "(", "$", "this", "->", "issues", ",", "$", "this", "->", "populatedIssueKeys", ")", ";", "while", "(", "count", "(", "$", "unreceivedIssues", ")", ">", "0", "&&", "$", "this", "->", "depth", "<", "$", "this", "->", "maxDepth", ")", "{", "$", "unpopulatedIssueKeys", "=", "[", "]", ";", "foreach", "(", "$", "unreceivedIssues", "as", "$", "issue", ")", "{", "/** @var Issue $issue */", "$", "this", "->", "populatedIssueKeys", "[", "$", "issue", "->", "getKey", "(", ")", "]", "=", "1", ";", "foreach", "(", "$", "issue", "->", "getLinks", "(", ")", "as", "$", "issueLink", ")", "{", "$", "unpopulatedIssueKey", "=", "IssueLinkHelper", "::", "getLinkedIssueKey", "(", "$", "issueLink", ")", ";", "if", "(", "$", "unpopulatedIssueKey", ")", "{", "$", "unpopulatedIssueKeys", "[", "$", "unpopulatedIssueKey", "]", "=", "$", "unpopulatedIssueKey", ";", "}", "}", "}", "$", "notProcessedIssueKeys", "=", "[", "]", ";", "foreach", "(", "$", "unpopulatedIssueKeys", "as", "$", "issueKey", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "issueKey", ",", "$", "this", "->", "issues", ")", ")", "{", "$", "notProcessedIssueKeys", "[", "]", "=", "$", "issueKey", ";", "}", "}", "if", "(", "$", "notProcessedIssueKeys", ")", "{", "$", "issues", "=", "$", "this", "->", "getIssuesFromRepositoryByKeys", "(", "$", "notProcessedIssueKeys", ")", ";", "foreach", "(", "$", "issues", "as", "$", "issue", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "issue", "->", "getKey", "(", ")", ",", "$", "this", "->", "issues", ")", ")", "{", "$", "this", "->", "issues", "[", "$", "issue", "->", "getKey", "(", ")", "]", "=", "$", "issue", ";", "}", "}", "}", "$", "unreceivedIssues", "=", "array_diff_key", "(", "$", "this", "->", "issues", ",", "$", "this", "->", "populatedIssueKeys", ")", ";", "$", "this", "->", "depth", "++", ";", "}", "}" ]
Builds issue tree
[ "Builds", "issue", "tree" ]
5a50ab4fc57dd77239f1b7e9c87738318c258c38
https://github.com/theluckyteam/php-jira/blob/5a50ab4fc57dd77239f1b7e9c87738318c258c38/src/jira/Provider/IssueLinksProvider.php#L71-L110