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
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
229,300
slickframework/slick
src/Slick/Di/Resolver/ObjectResolver.php
ObjectResolver._getMethodParameters
protected function _getMethodParameters( MethodInjection $method = null, ReflectionMethod $methodReflection = null, array $parameters = [] ) { $args = []; if ($methodReflection) { foreach ($methodReflection->getParameters() as $index => $parameter) { if (array_key_exists($parameter->getName(), $parameters)) { $value = $parameters[$parameter->getName()]; } elseif ($method && $method->hasParameter($index)) { $value = $method->getParameter($index); } else { // If the parameter is optional and wasn't specified, // we take its default value if ($parameter->isOptional()) { $args[] = $this->_getParameterDefaultValue( $parameter, $methodReflection ); continue; } throw new DefinitionException(sprintf( "The parameter '%s' of %s::%s has no value defined " . "or guessable", $parameter->getName(), $methodReflection->getDeclaringClass()->getName(), $methodReflection->getName() )); } if ($value instanceof ObjectDefinition\EntryReference) { $args[] = $this->_container->get($value->getName()); } else { $args[] = $value; } } } return $args; }
php
protected function _getMethodParameters( MethodInjection $method = null, ReflectionMethod $methodReflection = null, array $parameters = [] ) { $args = []; if ($methodReflection) { foreach ($methodReflection->getParameters() as $index => $parameter) { if (array_key_exists($parameter->getName(), $parameters)) { $value = $parameters[$parameter->getName()]; } elseif ($method && $method->hasParameter($index)) { $value = $method->getParameter($index); } else { // If the parameter is optional and wasn't specified, // we take its default value if ($parameter->isOptional()) { $args[] = $this->_getParameterDefaultValue( $parameter, $methodReflection ); continue; } throw new DefinitionException(sprintf( "The parameter '%s' of %s::%s has no value defined " . "or guessable", $parameter->getName(), $methodReflection->getDeclaringClass()->getName(), $methodReflection->getName() )); } if ($value instanceof ObjectDefinition\EntryReference) { $args[] = $this->_container->get($value->getName()); } else { $args[] = $value; } } } return $args; }
[ "protected", "function", "_getMethodParameters", "(", "MethodInjection", "$", "method", "=", "null", ",", "ReflectionMethod", "$", "methodReflection", "=", "null", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "args", "=", "[", "]", ";", "if", "(", "$", "methodReflection", ")", "{", "foreach", "(", "$", "methodReflection", "->", "getParameters", "(", ")", "as", "$", "index", "=>", "$", "parameter", ")", "{", "if", "(", "array_key_exists", "(", "$", "parameter", "->", "getName", "(", ")", ",", "$", "parameters", ")", ")", "{", "$", "value", "=", "$", "parameters", "[", "$", "parameter", "->", "getName", "(", ")", "]", ";", "}", "elseif", "(", "$", "method", "&&", "$", "method", "->", "hasParameter", "(", "$", "index", ")", ")", "{", "$", "value", "=", "$", "method", "->", "getParameter", "(", "$", "index", ")", ";", "}", "else", "{", "// If the parameter is optional and wasn't specified,", "// we take its default value", "if", "(", "$", "parameter", "->", "isOptional", "(", ")", ")", "{", "$", "args", "[", "]", "=", "$", "this", "->", "_getParameterDefaultValue", "(", "$", "parameter", ",", "$", "methodReflection", ")", ";", "continue", ";", "}", "throw", "new", "DefinitionException", "(", "sprintf", "(", "\"The parameter '%s' of %s::%s has no value defined \"", ".", "\"or guessable\"", ",", "$", "parameter", "->", "getName", "(", ")", ",", "$", "methodReflection", "->", "getDeclaringClass", "(", ")", "->", "getName", "(", ")", ",", "$", "methodReflection", "->", "getName", "(", ")", ")", ")", ";", "}", "if", "(", "$", "value", "instanceof", "ObjectDefinition", "\\", "EntryReference", ")", "{", "$", "args", "[", "]", "=", "$", "this", "->", "_container", "->", "get", "(", "$", "value", "->", "getName", "(", ")", ")", ";", "}", "else", "{", "$", "args", "[", "]", "=", "$", "value", ";", "}", "}", "}", "return", "$", "args", ";", "}" ]
Returns the parameters for the provided method @param MethodInjection $method @param ReflectionMethod $methodReflection @param array $parameters @throws DefinitionException Parameter has no value and cannot be guessed @return array
[ "Returns", "the", "parameters", "for", "the", "provided", "method" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Di/Resolver/ObjectResolver.php#L121-L161
229,301
slickframework/slick
src/Slick/Di/Resolver/ObjectResolver.php
ObjectResolver._getParameterDefaultValue
protected function _getParameterDefaultValue( ReflectionParameter $reflectionParameter, ReflectionMethod $reflectionMethod ) { try { return $reflectionParameter->getDefaultValue(); } catch (ReflectionException $e) { throw new DefinitionException(sprintf( "The parameter '%s' of %s::%s has no type defined or " . "guessable. It has a default value, but the default value " . "can't be read through Reflection because it is a " . "PHP internal class.", $reflectionParameter->getName(), $reflectionMethod->getDeclaringClass()->getName(), $reflectionMethod->getName() )); } }
php
protected function _getParameterDefaultValue( ReflectionParameter $reflectionParameter, ReflectionMethod $reflectionMethod ) { try { return $reflectionParameter->getDefaultValue(); } catch (ReflectionException $e) { throw new DefinitionException(sprintf( "The parameter '%s' of %s::%s has no type defined or " . "guessable. It has a default value, but the default value " . "can't be read through Reflection because it is a " . "PHP internal class.", $reflectionParameter->getName(), $reflectionMethod->getDeclaringClass()->getName(), $reflectionMethod->getName() )); } }
[ "protected", "function", "_getParameterDefaultValue", "(", "ReflectionParameter", "$", "reflectionParameter", ",", "ReflectionMethod", "$", "reflectionMethod", ")", "{", "try", "{", "return", "$", "reflectionParameter", "->", "getDefaultValue", "(", ")", ";", "}", "catch", "(", "ReflectionException", "$", "e", ")", "{", "throw", "new", "DefinitionException", "(", "sprintf", "(", "\"The parameter '%s' of %s::%s has no type defined or \"", ".", "\"guessable. It has a default value, but the default value \"", ".", "\"can't be read through Reflection because it is a \"", ".", "\"PHP internal class.\"", ",", "$", "reflectionParameter", "->", "getName", "(", ")", ",", "$", "reflectionMethod", "->", "getDeclaringClass", "(", ")", "->", "getName", "(", ")", ",", "$", "reflectionMethod", "->", "getName", "(", ")", ")", ")", ";", "}", "}" ]
Returns the default value of a function parameter. @param ReflectionParameter $reflectionParameter @param ReflectionMethod $reflectionMethod @throws DefinitionException Can't get default values from PHP internal classes and methods. @return mixed @codeCoverageIgnore
[ "Returns", "the", "default", "value", "of", "a", "function", "parameter", "." ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Di/Resolver/ObjectResolver.php#L174-L191
229,302
slickframework/slick
src/Slick/Di/Resolver/ObjectResolver.php
ObjectResolver._injectMethodsAndProperties
protected function _injectMethodsAndProperties( DefinitionInterface $definition, $instance) { $classReflection = new ReflectionClass($instance); /** @var ObjectDefinition $definition */ // Property injections foreach ($definition->getProperties() as $property) { $this->_propertyInjection($instance, $property, $classReflection); } // Method injections foreach ($definition->getMethods() as $method) { $this->_methodInjection($instance, $method, $classReflection); } }
php
protected function _injectMethodsAndProperties( DefinitionInterface $definition, $instance) { $classReflection = new ReflectionClass($instance); /** @var ObjectDefinition $definition */ // Property injections foreach ($definition->getProperties() as $property) { $this->_propertyInjection($instance, $property, $classReflection); } // Method injections foreach ($definition->getMethods() as $method) { $this->_methodInjection($instance, $method, $classReflection); } }
[ "protected", "function", "_injectMethodsAndProperties", "(", "DefinitionInterface", "$", "definition", ",", "$", "instance", ")", "{", "$", "classReflection", "=", "new", "ReflectionClass", "(", "$", "instance", ")", ";", "/** @var ObjectDefinition $definition */", "// Property injections", "foreach", "(", "$", "definition", "->", "getProperties", "(", ")", "as", "$", "property", ")", "{", "$", "this", "->", "_propertyInjection", "(", "$", "instance", ",", "$", "property", ",", "$", "classReflection", ")", ";", "}", "// Method injections", "foreach", "(", "$", "definition", "->", "getMethods", "(", ")", "as", "$", "method", ")", "{", "$", "this", "->", "_methodInjection", "(", "$", "instance", ",", "$", "method", ",", "$", "classReflection", ")", ";", "}", "}" ]
Inject properties and methods on the provided instance @param DefinitionInterface $definition @param object $instance
[ "Inject", "properties", "and", "methods", "on", "the", "provided", "instance" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Di/Resolver/ObjectResolver.php#L199-L216
229,303
slickframework/slick
src/Slick/Di/Resolver/ObjectResolver.php
ObjectResolver._propertyInjection
protected function _propertyInjection( $instance, PropertyInjection $property, ReflectionClass $classReflection) { // lets try to confirm it not prefixed by convention $public = trim($property->getPropertyName(), '_'); $notPublic = "_{$public}"; $propertyName = $classReflection->hasProperty($notPublic) ? $notPublic : $public; $propertyReflection = $classReflection->getProperty($propertyName); $value = $property->getValue(); if ($value instanceof ObjectDefinition\EntryReference) { $value = $this->_container->get($value->getName()); } if (!$propertyReflection->isPublic()) { $propertyReflection->setAccessible(true); } $propertyReflection->setValue($instance, $value); }
php
protected function _propertyInjection( $instance, PropertyInjection $property, ReflectionClass $classReflection) { // lets try to confirm it not prefixed by convention $public = trim($property->getPropertyName(), '_'); $notPublic = "_{$public}"; $propertyName = $classReflection->hasProperty($notPublic) ? $notPublic : $public; $propertyReflection = $classReflection->getProperty($propertyName); $value = $property->getValue(); if ($value instanceof ObjectDefinition\EntryReference) { $value = $this->_container->get($value->getName()); } if (!$propertyReflection->isPublic()) { $propertyReflection->setAccessible(true); } $propertyReflection->setValue($instance, $value); }
[ "protected", "function", "_propertyInjection", "(", "$", "instance", ",", "PropertyInjection", "$", "property", ",", "ReflectionClass", "$", "classReflection", ")", "{", "// lets try to confirm it not prefixed by convention", "$", "public", "=", "trim", "(", "$", "property", "->", "getPropertyName", "(", ")", ",", "'_'", ")", ";", "$", "notPublic", "=", "\"_{$public}\"", ";", "$", "propertyName", "=", "$", "classReflection", "->", "hasProperty", "(", "$", "notPublic", ")", "?", "$", "notPublic", ":", "$", "public", ";", "$", "propertyReflection", "=", "$", "classReflection", "->", "getProperty", "(", "$", "propertyName", ")", ";", "$", "value", "=", "$", "property", "->", "getValue", "(", ")", ";", "if", "(", "$", "value", "instanceof", "ObjectDefinition", "\\", "EntryReference", ")", "{", "$", "value", "=", "$", "this", "->", "_container", "->", "get", "(", "$", "value", "->", "getName", "(", ")", ")", ";", "}", "if", "(", "!", "$", "propertyReflection", "->", "isPublic", "(", ")", ")", "{", "$", "propertyReflection", "->", "setAccessible", "(", "true", ")", ";", "}", "$", "propertyReflection", "->", "setValue", "(", "$", "instance", ",", "$", "value", ")", ";", "}" ]
Injects property value @param Object $instance @param PropertyInjection $property @param ReflectionClass $classReflection @throws DependencyException When an error occurs retrieving the value from dependency container
[ "Injects", "property", "value" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Di/Resolver/ObjectResolver.php#L244-L265
229,304
lekoala/silverstripe-form-extras
code/fields/AccountingField.php
AccountingField.format
public static function format($value, $precision = null, $locale = null) { if ($precision === null) { $precision = self::$default_precision; } if ($locale) { $currentLocale = self::$_locale; self::$_locale = $locale; } if (is_array($value)) { foreach ($value as &$val) { $val = self::format($val, $precision); } return $value; } if (self::$_locale !== i18n::get_locale()) { self::initVariables(); } if (self::$_decimals === null) { self::initVariables(); } $rawValue = self::unformat($value); $formattedValue = number_format( $rawValue, $precision, self::$_decimals, self::$_thousands ); if ($locale) { self::$_locale = $currentLocale; } return $formattedValue; }
php
public static function format($value, $precision = null, $locale = null) { if ($precision === null) { $precision = self::$default_precision; } if ($locale) { $currentLocale = self::$_locale; self::$_locale = $locale; } if (is_array($value)) { foreach ($value as &$val) { $val = self::format($val, $precision); } return $value; } if (self::$_locale !== i18n::get_locale()) { self::initVariables(); } if (self::$_decimals === null) { self::initVariables(); } $rawValue = self::unformat($value); $formattedValue = number_format( $rawValue, $precision, self::$_decimals, self::$_thousands ); if ($locale) { self::$_locale = $currentLocale; } return $formattedValue; }
[ "public", "static", "function", "format", "(", "$", "value", ",", "$", "precision", "=", "null", ",", "$", "locale", "=", "null", ")", "{", "if", "(", "$", "precision", "===", "null", ")", "{", "$", "precision", "=", "self", "::", "$", "default_precision", ";", "}", "if", "(", "$", "locale", ")", "{", "$", "currentLocale", "=", "self", "::", "$", "_locale", ";", "self", "::", "$", "_locale", "=", "$", "locale", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "&", "$", "val", ")", "{", "$", "val", "=", "self", "::", "format", "(", "$", "val", ",", "$", "precision", ")", ";", "}", "return", "$", "value", ";", "}", "if", "(", "self", "::", "$", "_locale", "!==", "i18n", "::", "get_locale", "(", ")", ")", "{", "self", "::", "initVariables", "(", ")", ";", "}", "if", "(", "self", "::", "$", "_decimals", "===", "null", ")", "{", "self", "::", "initVariables", "(", ")", ";", "}", "$", "rawValue", "=", "self", "::", "unformat", "(", "$", "value", ")", ";", "$", "formattedValue", "=", "number_format", "(", "$", "rawValue", ",", "$", "precision", ",", "self", "::", "$", "_decimals", ",", "self", "::", "$", "_thousands", ")", ";", "if", "(", "$", "locale", ")", "{", "self", "::", "$", "_locale", "=", "$", "currentLocale", ";", "}", "return", "$", "formattedValue", ";", "}" ]
Format a value as a number @param string $value @param int $precision @return string
[ "Format", "a", "value", "as", "a", "number" ]
e0c1200792af8e6cea916e1999c73cf8408c6dd2
https://github.com/lekoala/silverstripe-form-extras/blob/e0c1200792af8e6cea916e1999c73cf8408c6dd2/code/fields/AccountingField.php#L78-L115
229,305
lekoala/silverstripe-form-extras
code/fields/AccountingField.php
AccountingField.unformat
public static function unformat($value) { if (is_array($value)) { foreach ($value as &$val) { $val = self::unformat($val); } return $value; } if (!$value) { $value = 0; } $neg = false; if (strpos($value, '-') === 0) { $neg = true; } $cleanString = preg_replace('/([^0-9\.,])/i', '', $value); $onlyNumbersString = preg_replace('/([^0-9])/i', '', $value); $separatorsCountToBeErased = strlen($cleanString) - strlen($onlyNumbersString) - 1; $stringWithCommaOrDot = preg_replace( '/([,\.])/', '', $cleanString, $separatorsCountToBeErased ); $removedThousendSeparator = preg_replace( '/(\.|,)(?=[0-9]{3,}$)/', '', $stringWithCommaOrDot ); $value = str_replace(',', '.', $removedThousendSeparator); if ($neg) { $value = -1 * abs($value); } return $value; }
php
public static function unformat($value) { if (is_array($value)) { foreach ($value as &$val) { $val = self::unformat($val); } return $value; } if (!$value) { $value = 0; } $neg = false; if (strpos($value, '-') === 0) { $neg = true; } $cleanString = preg_replace('/([^0-9\.,])/i', '', $value); $onlyNumbersString = preg_replace('/([^0-9])/i', '', $value); $separatorsCountToBeErased = strlen($cleanString) - strlen($onlyNumbersString) - 1; $stringWithCommaOrDot = preg_replace( '/([,\.])/', '', $cleanString, $separatorsCountToBeErased ); $removedThousendSeparator = preg_replace( '/(\.|,)(?=[0-9]{3,}$)/', '', $stringWithCommaOrDot ); $value = str_replace(',', '.', $removedThousendSeparator); if ($neg) { $value = -1 * abs($value); } return $value; }
[ "public", "static", "function", "unformat", "(", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "&", "$", "val", ")", "{", "$", "val", "=", "self", "::", "unformat", "(", "$", "val", ")", ";", "}", "return", "$", "value", ";", "}", "if", "(", "!", "$", "value", ")", "{", "$", "value", "=", "0", ";", "}", "$", "neg", "=", "false", ";", "if", "(", "strpos", "(", "$", "value", ",", "'-'", ")", "===", "0", ")", "{", "$", "neg", "=", "true", ";", "}", "$", "cleanString", "=", "preg_replace", "(", "'/([^0-9\\.,])/i'", ",", "''", ",", "$", "value", ")", ";", "$", "onlyNumbersString", "=", "preg_replace", "(", "'/([^0-9])/i'", ",", "''", ",", "$", "value", ")", ";", "$", "separatorsCountToBeErased", "=", "strlen", "(", "$", "cleanString", ")", "-", "strlen", "(", "$", "onlyNumbersString", ")", "-", "1", ";", "$", "stringWithCommaOrDot", "=", "preg_replace", "(", "'/([,\\.])/'", ",", "''", ",", "$", "cleanString", ",", "$", "separatorsCountToBeErased", ")", ";", "$", "removedThousendSeparator", "=", "preg_replace", "(", "'/(\\.|,)(?=[0-9]{3,}$)/'", ",", "''", ",", "$", "stringWithCommaOrDot", ")", ";", "$", "value", "=", "str_replace", "(", "','", ",", "'.'", ",", "$", "removedThousendSeparator", ")", ";", "if", "(", "$", "neg", ")", "{", "$", "value", "=", "-", "1", "*", "abs", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Similar implementation than accounting.js unformat method @param string $value
[ "Similar", "implementation", "than", "accounting", ".", "js", "unformat", "method" ]
e0c1200792af8e6cea916e1999c73cf8408c6dd2
https://github.com/lekoala/silverstripe-form-extras/blob/e0c1200792af8e6cea916e1999c73cf8408c6dd2/code/fields/AccountingField.php#L121-L162
229,306
cornernote/yii-audit-module
audit/components/AuditFieldBehavior.php
AuditFieldBehavior.getDbAttribute
public function getDbAttribute($attribute, $default = null) { return isset($this->_dbAttributes[$attribute]) ? $this->_dbAttributes[$attribute] : $default; }
php
public function getDbAttribute($attribute, $default = null) { return isset($this->_dbAttributes[$attribute]) ? $this->_dbAttributes[$attribute] : $default; }
[ "public", "function", "getDbAttribute", "(", "$", "attribute", ",", "$", "default", "=", "null", ")", "{", "return", "isset", "(", "$", "this", "->", "_dbAttributes", "[", "$", "attribute", "]", ")", "?", "$", "this", "->", "_dbAttributes", "[", "$", "attribute", "]", ":", "$", "default", ";", "}" ]
Gets an attribute, as it is in the database @param $attribute @param $default @return mixed
[ "Gets", "an", "attribute", "as", "it", "is", "in", "the", "database" ]
07362f79741b5343d22bb9bb516d840072a097d4
https://github.com/cornernote/yii-audit-module/blob/07362f79741b5343d22bb9bb516d840072a097d4/audit/components/AuditFieldBehavior.php#L83-L86
229,307
cornernote/yii-audit-module
audit/components/AuditFieldBehavior.php
AuditFieldBehavior.changed
public function changed($field = null) { if ($this->owner->isNewRecord) return false; if ($field) return $this->getDbAttribute($field) != $this->owner->getAttribute($field); foreach ($this->owner->getAttributes() as $k => $v) if ($this->getDbAttribute($k) != $v) return true; return false; }
php
public function changed($field = null) { if ($this->owner->isNewRecord) return false; if ($field) return $this->getDbAttribute($field) != $this->owner->getAttribute($field); foreach ($this->owner->getAttributes() as $k => $v) if ($this->getDbAttribute($k) != $v) return true; return false; }
[ "public", "function", "changed", "(", "$", "field", "=", "null", ")", "{", "if", "(", "$", "this", "->", "owner", "->", "isNewRecord", ")", "return", "false", ";", "if", "(", "$", "field", ")", "return", "$", "this", "->", "getDbAttribute", "(", "$", "field", ")", "!=", "$", "this", "->", "owner", "->", "getAttribute", "(", "$", "field", ")", ";", "foreach", "(", "$", "this", "->", "owner", "->", "getAttributes", "(", ")", "as", "$", "k", "=>", "$", "v", ")", "if", "(", "$", "this", "->", "getDbAttribute", "(", "$", "k", ")", "!=", "$", "v", ")", "return", "true", ";", "return", "false", ";", "}" ]
Check if any fields have changed @param string $field @return bool|string|array
[ "Check", "if", "any", "fields", "have", "changed" ]
07362f79741b5343d22bb9bb516d840072a097d4
https://github.com/cornernote/yii-audit-module/blob/07362f79741b5343d22bb9bb516d840072a097d4/audit/components/AuditFieldBehavior.php#L94-L104
229,308
cornernote/yii-audit-module
audit/components/AuditFieldBehavior.php
AuditFieldBehavior.afterFind
public function afterFind($event) { $this->_dbAttributes = $this->owner->getAttributes(); parent::afterFind($event); }
php
public function afterFind($event) { $this->_dbAttributes = $this->owner->getAttributes(); parent::afterFind($event); }
[ "public", "function", "afterFind", "(", "$", "event", ")", "{", "$", "this", "->", "_dbAttributes", "=", "$", "this", "->", "owner", "->", "getAttributes", "(", ")", ";", "parent", "::", "afterFind", "(", "$", "event", ")", ";", "}" ]
Actions to be performed after the model is loaded
[ "Actions", "to", "be", "performed", "after", "the", "model", "is", "loaded" ]
07362f79741b5343d22bb9bb516d840072a097d4
https://github.com/cornernote/yii-audit-module/blob/07362f79741b5343d22bb9bb516d840072a097d4/audit/components/AuditFieldBehavior.php#L109-L113
229,309
cornernote/yii-audit-module
audit/components/AuditFieldBehavior.php
AuditFieldBehavior.afterSave
public function afterSave($event) { if (!$this->enableAuditField) { parent::afterSave($event); return; } $date = time(); $newAttributes = $this->owner->attributes; $oldAttributes = $this->_dbAttributes; $auditModels = $this->getAuditModels(); $auditRequestId = $this->getAuditRequestId(); $auditFields = array(); $userId = Yii::app()->user && Yii::app()->user->id ? Yii::app()->user->id : 0; // insert if ($this->owner->isNewRecord) { foreach ($newAttributes as $name => $new) { if (in_array($name, $this->ignoreFields['insert'])) continue; // prepare the values $new = trim($new); if (!$new) continue; // prepare the logs foreach ($auditModels as $auditModel) { if (isset($auditModel['ignoreFields']) && in_array($name, $auditModel['ignoreFields'])) continue; $auditFields[] = array( 'old_value' => '', 'new_value' => $new, 'action' => 'INSERT', 'model_name' => $auditModel['model_name'], 'model_id' => $auditModel['model_id'], 'field' => $auditModel['prefix'] . $name, 'created' => $date, 'user_id' => $userId, 'audit_request_id' => $auditRequestId, ); } } } // update else { // compare old and new foreach ($newAttributes as $name => $new) { if (in_array($name, $this->ignoreFields['update'])) continue; // prepare the values $old = !empty($oldAttributes) ? trim($oldAttributes[$name]) : ''; $new = trim($new); if (in_array($old, $this->ignoreValues)) $old = ''; if (in_array($new, $this->ignoreValues)) $new = ''; if ($new == $old) continue; // prepare the logs foreach ($auditModels as $auditModel) { if (isset($auditModel['ignoreFields']) && in_array($name, $auditModel['ignoreFields'])) continue; $auditFields[] = array( 'old_value' => $old, 'new_value' => $new, 'action' => 'UPDATE', 'model_name' => $auditModel['model_name'], 'model_id' => $auditModel['model_id'], 'field' => $auditModel['prefix'] . $name, 'created' => $date, 'user_id' => $userId, 'audit_request_id' => $auditRequestId, ); } } } // insert the audit_field records $this->addAuditFields($auditFields); // set the dbAttributes to the new values $this->_dbAttributes = $this->owner->attributes; parent::afterSave($event); }
php
public function afterSave($event) { if (!$this->enableAuditField) { parent::afterSave($event); return; } $date = time(); $newAttributes = $this->owner->attributes; $oldAttributes = $this->_dbAttributes; $auditModels = $this->getAuditModels(); $auditRequestId = $this->getAuditRequestId(); $auditFields = array(); $userId = Yii::app()->user && Yii::app()->user->id ? Yii::app()->user->id : 0; // insert if ($this->owner->isNewRecord) { foreach ($newAttributes as $name => $new) { if (in_array($name, $this->ignoreFields['insert'])) continue; // prepare the values $new = trim($new); if (!$new) continue; // prepare the logs foreach ($auditModels as $auditModel) { if (isset($auditModel['ignoreFields']) && in_array($name, $auditModel['ignoreFields'])) continue; $auditFields[] = array( 'old_value' => '', 'new_value' => $new, 'action' => 'INSERT', 'model_name' => $auditModel['model_name'], 'model_id' => $auditModel['model_id'], 'field' => $auditModel['prefix'] . $name, 'created' => $date, 'user_id' => $userId, 'audit_request_id' => $auditRequestId, ); } } } // update else { // compare old and new foreach ($newAttributes as $name => $new) { if (in_array($name, $this->ignoreFields['update'])) continue; // prepare the values $old = !empty($oldAttributes) ? trim($oldAttributes[$name]) : ''; $new = trim($new); if (in_array($old, $this->ignoreValues)) $old = ''; if (in_array($new, $this->ignoreValues)) $new = ''; if ($new == $old) continue; // prepare the logs foreach ($auditModels as $auditModel) { if (isset($auditModel['ignoreFields']) && in_array($name, $auditModel['ignoreFields'])) continue; $auditFields[] = array( 'old_value' => $old, 'new_value' => $new, 'action' => 'UPDATE', 'model_name' => $auditModel['model_name'], 'model_id' => $auditModel['model_id'], 'field' => $auditModel['prefix'] . $name, 'created' => $date, 'user_id' => $userId, 'audit_request_id' => $auditRequestId, ); } } } // insert the audit_field records $this->addAuditFields($auditFields); // set the dbAttributes to the new values $this->_dbAttributes = $this->owner->attributes; parent::afterSave($event); }
[ "public", "function", "afterSave", "(", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "enableAuditField", ")", "{", "parent", "::", "afterSave", "(", "$", "event", ")", ";", "return", ";", "}", "$", "date", "=", "time", "(", ")", ";", "$", "newAttributes", "=", "$", "this", "->", "owner", "->", "attributes", ";", "$", "oldAttributes", "=", "$", "this", "->", "_dbAttributes", ";", "$", "auditModels", "=", "$", "this", "->", "getAuditModels", "(", ")", ";", "$", "auditRequestId", "=", "$", "this", "->", "getAuditRequestId", "(", ")", ";", "$", "auditFields", "=", "array", "(", ")", ";", "$", "userId", "=", "Yii", "::", "app", "(", ")", "->", "user", "&&", "Yii", "::", "app", "(", ")", "->", "user", "->", "id", "?", "Yii", "::", "app", "(", ")", "->", "user", "->", "id", ":", "0", ";", "// insert", "if", "(", "$", "this", "->", "owner", "->", "isNewRecord", ")", "{", "foreach", "(", "$", "newAttributes", "as", "$", "name", "=>", "$", "new", ")", "{", "if", "(", "in_array", "(", "$", "name", ",", "$", "this", "->", "ignoreFields", "[", "'insert'", "]", ")", ")", "continue", ";", "// prepare the values", "$", "new", "=", "trim", "(", "$", "new", ")", ";", "if", "(", "!", "$", "new", ")", "continue", ";", "// prepare the logs", "foreach", "(", "$", "auditModels", "as", "$", "auditModel", ")", "{", "if", "(", "isset", "(", "$", "auditModel", "[", "'ignoreFields'", "]", ")", "&&", "in_array", "(", "$", "name", ",", "$", "auditModel", "[", "'ignoreFields'", "]", ")", ")", "continue", ";", "$", "auditFields", "[", "]", "=", "array", "(", "'old_value'", "=>", "''", ",", "'new_value'", "=>", "$", "new", ",", "'action'", "=>", "'INSERT'", ",", "'model_name'", "=>", "$", "auditModel", "[", "'model_name'", "]", ",", "'model_id'", "=>", "$", "auditModel", "[", "'model_id'", "]", ",", "'field'", "=>", "$", "auditModel", "[", "'prefix'", "]", ".", "$", "name", ",", "'created'", "=>", "$", "date", ",", "'user_id'", "=>", "$", "userId", ",", "'audit_request_id'", "=>", "$", "auditRequestId", ",", ")", ";", "}", "}", "}", "// update", "else", "{", "// compare old and new", "foreach", "(", "$", "newAttributes", "as", "$", "name", "=>", "$", "new", ")", "{", "if", "(", "in_array", "(", "$", "name", ",", "$", "this", "->", "ignoreFields", "[", "'update'", "]", ")", ")", "continue", ";", "// prepare the values", "$", "old", "=", "!", "empty", "(", "$", "oldAttributes", ")", "?", "trim", "(", "$", "oldAttributes", "[", "$", "name", "]", ")", ":", "''", ";", "$", "new", "=", "trim", "(", "$", "new", ")", ";", "if", "(", "in_array", "(", "$", "old", ",", "$", "this", "->", "ignoreValues", ")", ")", "$", "old", "=", "''", ";", "if", "(", "in_array", "(", "$", "new", ",", "$", "this", "->", "ignoreValues", ")", ")", "$", "new", "=", "''", ";", "if", "(", "$", "new", "==", "$", "old", ")", "continue", ";", "// prepare the logs", "foreach", "(", "$", "auditModels", "as", "$", "auditModel", ")", "{", "if", "(", "isset", "(", "$", "auditModel", "[", "'ignoreFields'", "]", ")", "&&", "in_array", "(", "$", "name", ",", "$", "auditModel", "[", "'ignoreFields'", "]", ")", ")", "continue", ";", "$", "auditFields", "[", "]", "=", "array", "(", "'old_value'", "=>", "$", "old", ",", "'new_value'", "=>", "$", "new", ",", "'action'", "=>", "'UPDATE'", ",", "'model_name'", "=>", "$", "auditModel", "[", "'model_name'", "]", ",", "'model_id'", "=>", "$", "auditModel", "[", "'model_id'", "]", ",", "'field'", "=>", "$", "auditModel", "[", "'prefix'", "]", ".", "$", "name", ",", "'created'", "=>", "$", "date", ",", "'user_id'", "=>", "$", "userId", ",", "'audit_request_id'", "=>", "$", "auditRequestId", ",", ")", ";", "}", "}", "}", "// insert the audit_field records", "$", "this", "->", "addAuditFields", "(", "$", "auditFields", ")", ";", "// set the dbAttributes to the new values", "$", "this", "->", "_dbAttributes", "=", "$", "this", "->", "owner", "->", "attributes", ";", "parent", "::", "afterSave", "(", "$", "event", ")", ";", "}" ]
Find changes to the model and save them as AuditField records Do not call this method directly, it will be called after the model is saved. @param CModelEvent $event
[ "Find", "changes", "to", "the", "model", "and", "save", "them", "as", "AuditField", "records", "Do", "not", "call", "this", "method", "directly", "it", "will", "be", "called", "after", "the", "model", "is", "saved", "." ]
07362f79741b5343d22bb9bb516d840072a097d4
https://github.com/cornernote/yii-audit-module/blob/07362f79741b5343d22bb9bb516d840072a097d4/audit/components/AuditFieldBehavior.php#L120-L200
229,310
cornernote/yii-audit-module
audit/components/AuditFieldBehavior.php
AuditFieldBehavior.afterDelete
public function afterDelete($event) { if (!$this->enableAuditField) { parent::afterDelete($event); return; } $date = time(); $auditModels = $this->getAuditModels(); $auditRequestId = $this->getAuditRequestId(); $userId = Yii::app()->user && Yii::app()->user->id ? Yii::app()->user->id : 0; $auditFields = array(); // prepare the logs $pk = $this->getModelPrimaryKeyString($this->auditModel); foreach ($auditModels as $auditModel) { $prefix = isset($auditModel['prefix']) ? $auditModel['prefix'] . '.' . $pk : ''; $auditFields[] = array( 'old_value' => '', 'new_value' => '', 'action' => 'DELETE', 'model_name' => $auditModel['model_name'], 'model_id' => $auditModel['model_id'], 'field' => $prefix . '*', 'created' => $date, 'user_id' => $userId, 'audit_request_id' => $auditRequestId, ); } // insert the audit_field records $this->addAuditFields($auditFields); parent::afterDelete($event); }
php
public function afterDelete($event) { if (!$this->enableAuditField) { parent::afterDelete($event); return; } $date = time(); $auditModels = $this->getAuditModels(); $auditRequestId = $this->getAuditRequestId(); $userId = Yii::app()->user && Yii::app()->user->id ? Yii::app()->user->id : 0; $auditFields = array(); // prepare the logs $pk = $this->getModelPrimaryKeyString($this->auditModel); foreach ($auditModels as $auditModel) { $prefix = isset($auditModel['prefix']) ? $auditModel['prefix'] . '.' . $pk : ''; $auditFields[] = array( 'old_value' => '', 'new_value' => '', 'action' => 'DELETE', 'model_name' => $auditModel['model_name'], 'model_id' => $auditModel['model_id'], 'field' => $prefix . '*', 'created' => $date, 'user_id' => $userId, 'audit_request_id' => $auditRequestId, ); } // insert the audit_field records $this->addAuditFields($auditFields); parent::afterDelete($event); }
[ "public", "function", "afterDelete", "(", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "enableAuditField", ")", "{", "parent", "::", "afterDelete", "(", "$", "event", ")", ";", "return", ";", "}", "$", "date", "=", "time", "(", ")", ";", "$", "auditModels", "=", "$", "this", "->", "getAuditModels", "(", ")", ";", "$", "auditRequestId", "=", "$", "this", "->", "getAuditRequestId", "(", ")", ";", "$", "userId", "=", "Yii", "::", "app", "(", ")", "->", "user", "&&", "Yii", "::", "app", "(", ")", "->", "user", "->", "id", "?", "Yii", "::", "app", "(", ")", "->", "user", "->", "id", ":", "0", ";", "$", "auditFields", "=", "array", "(", ")", ";", "// prepare the logs", "$", "pk", "=", "$", "this", "->", "getModelPrimaryKeyString", "(", "$", "this", "->", "auditModel", ")", ";", "foreach", "(", "$", "auditModels", "as", "$", "auditModel", ")", "{", "$", "prefix", "=", "isset", "(", "$", "auditModel", "[", "'prefix'", "]", ")", "?", "$", "auditModel", "[", "'prefix'", "]", ".", "'.'", ".", "$", "pk", ":", "''", ";", "$", "auditFields", "[", "]", "=", "array", "(", "'old_value'", "=>", "''", ",", "'new_value'", "=>", "''", ",", "'action'", "=>", "'DELETE'", ",", "'model_name'", "=>", "$", "auditModel", "[", "'model_name'", "]", ",", "'model_id'", "=>", "$", "auditModel", "[", "'model_id'", "]", ",", "'field'", "=>", "$", "prefix", ".", "'*'", ",", "'created'", "=>", "$", "date", ",", "'user_id'", "=>", "$", "userId", ",", "'audit_request_id'", "=>", "$", "auditRequestId", ",", ")", ";", "}", "// insert the audit_field records", "$", "this", "->", "addAuditFields", "(", "$", "auditFields", ")", ";", "parent", "::", "afterDelete", "(", "$", "event", ")", ";", "}" ]
Find changes to the model and save them as AuditField records. Do not call this method directly, it will be called after the model is deleted. @param CModelEvent $event
[ "Find", "changes", "to", "the", "model", "and", "save", "them", "as", "AuditField", "records", ".", "Do", "not", "call", "this", "method", "directly", "it", "will", "be", "called", "after", "the", "model", "is", "deleted", "." ]
07362f79741b5343d22bb9bb516d840072a097d4
https://github.com/cornernote/yii-audit-module/blob/07362f79741b5343d22bb9bb516d840072a097d4/audit/components/AuditFieldBehavior.php#L207-L241
229,311
cornernote/yii-audit-module
audit/components/AuditFieldBehavior.php
AuditFieldBehavior.getAuditModels
protected function getAuditModels() { $auditModels = array(); // get log models if ($this->auditModel) { $auditModels[] = array( 'model_name' => $this->auditModelName ? $this->auditModelName : get_class($this->auditModel), 'model_id' => $this->getModelPrimaryKeyString($this->auditModel), 'prefix' => $this->getModelFieldPrefix($this->auditModel), ); } // also log to additionalAuditModels foreach ($this->additionalAuditModels as $model => $fk_field) { $auditModels[] = array( 'model_name' => $model, 'model_id' => $this->owner->$fk_field, 'prefix' => get_class($this->owner) . '.', 'ignoreFields' => array($fk_field), ); } return $auditModels; }
php
protected function getAuditModels() { $auditModels = array(); // get log models if ($this->auditModel) { $auditModels[] = array( 'model_name' => $this->auditModelName ? $this->auditModelName : get_class($this->auditModel), 'model_id' => $this->getModelPrimaryKeyString($this->auditModel), 'prefix' => $this->getModelFieldPrefix($this->auditModel), ); } // also log to additionalAuditModels foreach ($this->additionalAuditModels as $model => $fk_field) { $auditModels[] = array( 'model_name' => $model, 'model_id' => $this->owner->$fk_field, 'prefix' => get_class($this->owner) . '.', 'ignoreFields' => array($fk_field), ); } return $auditModels; }
[ "protected", "function", "getAuditModels", "(", ")", "{", "$", "auditModels", "=", "array", "(", ")", ";", "// get log models", "if", "(", "$", "this", "->", "auditModel", ")", "{", "$", "auditModels", "[", "]", "=", "array", "(", "'model_name'", "=>", "$", "this", "->", "auditModelName", "?", "$", "this", "->", "auditModelName", ":", "get_class", "(", "$", "this", "->", "auditModel", ")", ",", "'model_id'", "=>", "$", "this", "->", "getModelPrimaryKeyString", "(", "$", "this", "->", "auditModel", ")", ",", "'prefix'", "=>", "$", "this", "->", "getModelFieldPrefix", "(", "$", "this", "->", "auditModel", ")", ",", ")", ";", "}", "// also log to additionalAuditModels", "foreach", "(", "$", "this", "->", "additionalAuditModels", "as", "$", "model", "=>", "$", "fk_field", ")", "{", "$", "auditModels", "[", "]", "=", "array", "(", "'model_name'", "=>", "$", "model", ",", "'model_id'", "=>", "$", "this", "->", "owner", "->", "$", "fk_field", ",", "'prefix'", "=>", "get_class", "(", "$", "this", "->", "owner", ")", ".", "'.'", ",", "'ignoreFields'", "=>", "array", "(", "$", "fk_field", ")", ",", ")", ";", "}", "return", "$", "auditModels", ";", "}" ]
Gets additional models to be used in the model and model_id fields. @return array @see additionalAuditModels
[ "Gets", "additional", "models", "to", "be", "used", "in", "the", "model", "and", "model_id", "fields", "." ]
07362f79741b5343d22bb9bb516d840072a097d4
https://github.com/cornernote/yii-audit-module/blob/07362f79741b5343d22bb9bb516d840072a097d4/audit/components/AuditFieldBehavior.php#L288-L312
229,312
cornernote/yii-audit-module
audit/components/AuditFieldBehavior.php
AuditFieldBehavior.getModelFieldPrefix
protected function getModelFieldPrefix($model) { return (get_class($this->owner) != get_class($model)) ? get_class($this->owner) . '.' : ''; }
php
protected function getModelFieldPrefix($model) { return (get_class($this->owner) != get_class($model)) ? get_class($this->owner) . '.' : ''; }
[ "protected", "function", "getModelFieldPrefix", "(", "$", "model", ")", "{", "return", "(", "get_class", "(", "$", "this", "->", "owner", ")", "!=", "get_class", "(", "$", "model", ")", ")", "?", "get_class", "(", "$", "this", "->", "owner", ")", ".", "'.'", ":", "''", ";", "}" ]
If the model is not the same as the owner then prefix the field so we know the model. @param $model CActiveRecord @return string
[ "If", "the", "model", "is", "not", "the", "same", "as", "the", "owner", "then", "prefix", "the", "field", "so", "we", "know", "the", "model", "." ]
07362f79741b5343d22bb9bb516d840072a097d4
https://github.com/cornernote/yii-audit-module/blob/07362f79741b5343d22bb9bb516d840072a097d4/audit/components/AuditFieldBehavior.php#L319-L322
229,313
cornernote/yii-audit-module
audit/components/AuditFieldBehavior.php
AuditFieldBehavior.getModelPrimaryKeyString
protected function getModelPrimaryKeyString($model) { return is_array($model->getPrimaryKey()) ? implode('-', $model->getPrimaryKey()) : $model->getPrimaryKey(); }
php
protected function getModelPrimaryKeyString($model) { return is_array($model->getPrimaryKey()) ? implode('-', $model->getPrimaryKey()) : $model->getPrimaryKey(); }
[ "protected", "function", "getModelPrimaryKeyString", "(", "$", "model", ")", "{", "return", "is_array", "(", "$", "model", "->", "getPrimaryKey", "(", ")", ")", "?", "implode", "(", "'-'", ",", "$", "model", "->", "getPrimaryKey", "(", ")", ")", ":", "$", "model", "->", "getPrimaryKey", "(", ")", ";", "}" ]
Returns Primary Key as a string @param $model CActiveRecord @return string
[ "Returns", "Primary", "Key", "as", "a", "string" ]
07362f79741b5343d22bb9bb516d840072a097d4
https://github.com/cornernote/yii-audit-module/blob/07362f79741b5343d22bb9bb516d840072a097d4/audit/components/AuditFieldBehavior.php#L329-L332
229,314
mbilbille/jpnforphp
src/JpnForPhp/Converter/Converter.php
Converter.toWesternYear
public static function toWesternYear($year) { if (Analyzer::hasKanji($year)) { $key = 'kanji'; $eraName = Helper::extractKanji($year); $eraName = $eraName[0]; $eraValue = (int)Helper::subString($year, Analyzer::length($eraName), Analyzer::length($year)); } elseif (Analyzer::hasHiragana($year)) { $key = 'kana'; $eraName = Helper::extractHiragana($year); $eraName = $eraName[0]; $eraValue = (int)Helper::subString($year, Analyzer::length($eraName), Analyzer::length($year)); } else { $key = 'romaji'; $year = ucfirst(mb_strtolower($year, 'UTF-8')); // Change case to match `$mapEras` $parts = explode(' ', $year); $eraName = $parts[0]; $eraValue = (int)$parts[1]; } if (empty($eraName) || empty($eraValue)) { throw new Exception('Invalid year ' . $year); } $max = count(self::$mapEras); $westernYears = array(); for ($i = 0; $i < $max; $i++) { $era = self::$mapEras[$i]; $overflown = false; if ($era[$key] == $eraName) { $eraStart = $era['year']; $westernYear = $eraStart + $eraValue - 1; if ($i < $max - 1) { $nextEra = self::$mapEras[$i + 1]; $nextEraYear = $nextEra['year']; if ($westernYear > $nextEraYear) { $overflown = true; } } $westernYears[] = array('value' => $westernYear, 'overflown' => $overflown); } } $results = array(); foreach ($westernYears as $westernYear) { if (!$westernYear['overflown']) { $results[] = $westernYear['value']; } } if (empty($results)) { throw new Exception('Year ' . $year . ' is invalid'); } elseif (count($results) == 1) { return $results[0]; } else { return $results; } }
php
public static function toWesternYear($year) { if (Analyzer::hasKanji($year)) { $key = 'kanji'; $eraName = Helper::extractKanji($year); $eraName = $eraName[0]; $eraValue = (int)Helper::subString($year, Analyzer::length($eraName), Analyzer::length($year)); } elseif (Analyzer::hasHiragana($year)) { $key = 'kana'; $eraName = Helper::extractHiragana($year); $eraName = $eraName[0]; $eraValue = (int)Helper::subString($year, Analyzer::length($eraName), Analyzer::length($year)); } else { $key = 'romaji'; $year = ucfirst(mb_strtolower($year, 'UTF-8')); // Change case to match `$mapEras` $parts = explode(' ', $year); $eraName = $parts[0]; $eraValue = (int)$parts[1]; } if (empty($eraName) || empty($eraValue)) { throw new Exception('Invalid year ' . $year); } $max = count(self::$mapEras); $westernYears = array(); for ($i = 0; $i < $max; $i++) { $era = self::$mapEras[$i]; $overflown = false; if ($era[$key] == $eraName) { $eraStart = $era['year']; $westernYear = $eraStart + $eraValue - 1; if ($i < $max - 1) { $nextEra = self::$mapEras[$i + 1]; $nextEraYear = $nextEra['year']; if ($westernYear > $nextEraYear) { $overflown = true; } } $westernYears[] = array('value' => $westernYear, 'overflown' => $overflown); } } $results = array(); foreach ($westernYears as $westernYear) { if (!$westernYear['overflown']) { $results[] = $westernYear['value']; } } if (empty($results)) { throw new Exception('Year ' . $year . ' is invalid'); } elseif (count($results) == 1) { return $results[0]; } else { return $results; } }
[ "public", "static", "function", "toWesternYear", "(", "$", "year", ")", "{", "if", "(", "Analyzer", "::", "hasKanji", "(", "$", "year", ")", ")", "{", "$", "key", "=", "'kanji'", ";", "$", "eraName", "=", "Helper", "::", "extractKanji", "(", "$", "year", ")", ";", "$", "eraName", "=", "$", "eraName", "[", "0", "]", ";", "$", "eraValue", "=", "(", "int", ")", "Helper", "::", "subString", "(", "$", "year", ",", "Analyzer", "::", "length", "(", "$", "eraName", ")", ",", "Analyzer", "::", "length", "(", "$", "year", ")", ")", ";", "}", "elseif", "(", "Analyzer", "::", "hasHiragana", "(", "$", "year", ")", ")", "{", "$", "key", "=", "'kana'", ";", "$", "eraName", "=", "Helper", "::", "extractHiragana", "(", "$", "year", ")", ";", "$", "eraName", "=", "$", "eraName", "[", "0", "]", ";", "$", "eraValue", "=", "(", "int", ")", "Helper", "::", "subString", "(", "$", "year", ",", "Analyzer", "::", "length", "(", "$", "eraName", ")", ",", "Analyzer", "::", "length", "(", "$", "year", ")", ")", ";", "}", "else", "{", "$", "key", "=", "'romaji'", ";", "$", "year", "=", "ucfirst", "(", "mb_strtolower", "(", "$", "year", ",", "'UTF-8'", ")", ")", ";", "// Change case to match `$mapEras`", "$", "parts", "=", "explode", "(", "' '", ",", "$", "year", ")", ";", "$", "eraName", "=", "$", "parts", "[", "0", "]", ";", "$", "eraValue", "=", "(", "int", ")", "$", "parts", "[", "1", "]", ";", "}", "if", "(", "empty", "(", "$", "eraName", ")", "||", "empty", "(", "$", "eraValue", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid year '", ".", "$", "year", ")", ";", "}", "$", "max", "=", "count", "(", "self", "::", "$", "mapEras", ")", ";", "$", "westernYears", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "max", ";", "$", "i", "++", ")", "{", "$", "era", "=", "self", "::", "$", "mapEras", "[", "$", "i", "]", ";", "$", "overflown", "=", "false", ";", "if", "(", "$", "era", "[", "$", "key", "]", "==", "$", "eraName", ")", "{", "$", "eraStart", "=", "$", "era", "[", "'year'", "]", ";", "$", "westernYear", "=", "$", "eraStart", "+", "$", "eraValue", "-", "1", ";", "if", "(", "$", "i", "<", "$", "max", "-", "1", ")", "{", "$", "nextEra", "=", "self", "::", "$", "mapEras", "[", "$", "i", "+", "1", "]", ";", "$", "nextEraYear", "=", "$", "nextEra", "[", "'year'", "]", ";", "if", "(", "$", "westernYear", ">", "$", "nextEraYear", ")", "{", "$", "overflown", "=", "true", ";", "}", "}", "$", "westernYears", "[", "]", "=", "array", "(", "'value'", "=>", "$", "westernYear", ",", "'overflown'", "=>", "$", "overflown", ")", ";", "}", "}", "$", "results", "=", "array", "(", ")", ";", "foreach", "(", "$", "westernYears", "as", "$", "westernYear", ")", "{", "if", "(", "!", "$", "westernYear", "[", "'overflown'", "]", ")", "{", "$", "results", "[", "]", "=", "$", "westernYear", "[", "'value'", "]", ";", "}", "}", "if", "(", "empty", "(", "$", "results", ")", ")", "{", "throw", "new", "Exception", "(", "'Year '", ".", "$", "year", ".", "' is invalid'", ")", ";", "}", "elseif", "(", "count", "(", "$", "results", ")", "==", "1", ")", "{", "return", "$", "results", "[", "0", "]", ";", "}", "else", "{", "return", "$", "results", ";", "}", "}" ]
Converts a year in Japanese format into Western format. @param $year : kanji or hiragana era name followed by digits, or era name in romaji, space and digit. I.e. : 明治33, めいじ33, Meiji 33 @return string|array : The year(s) in Western format. @throws Exception
[ "Converts", "a", "year", "in", "Japanese", "format", "into", "Western", "format", "." ]
5623468503cc2941f4656b0ee1a58b939d263453
https://github.com/mbilbille/jpnforphp/blob/5623468503cc2941f4656b0ee1a58b939d263453/src/JpnForPhp/Converter/Converter.php#L497-L551
229,315
slickframework/slick
src/Slick/Configuration/Driver/Ini.php
Ini._load
protected function _load() { $file = new File($this->_file, "r"); $data = @parse_ini_string($file->read(), true); if ($data === false) { throw new Exception\ParserErrorException( "Error parsing configuration file {$this->_file}" ); } $this->_data = $data; }
php
protected function _load() { $file = new File($this->_file, "r"); $data = @parse_ini_string($file->read(), true); if ($data === false) { throw new Exception\ParserErrorException( "Error parsing configuration file {$this->_file}" ); } $this->_data = $data; }
[ "protected", "function", "_load", "(", ")", "{", "$", "file", "=", "new", "File", "(", "$", "this", "->", "_file", ",", "\"r\"", ")", ";", "$", "data", "=", "@", "parse_ini_string", "(", "$", "file", "->", "read", "(", ")", ",", "true", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "throw", "new", "Exception", "\\", "ParserErrorException", "(", "\"Error parsing configuration file {$this->_file}\"", ")", ";", "}", "$", "this", "->", "_data", "=", "$", "data", ";", "}" ]
Loads the data into this configuration driver
[ "Loads", "the", "data", "into", "this", "configuration", "driver" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Configuration/Driver/Ini.php#L29-L40
229,316
tooleks/php-avg-color-picker
src/Gd/Image.php
Image.assertResource
protected function assertResource($resource) { if (!is_resource($resource) || get_resource_type($resource) !== 'gd') { throw new InvalidArgumentException('Invalid resource type.'); } $width = imagesx($resource); $height = imagesy($resource); if ($width < 1 || $height < 1) { throw new InvalidImageDimensionException( sprintf('The resource image dimensions should be at least 1x1px. The resource image with %sx%spx dimensions given.', $width, $height) ); } }
php
protected function assertResource($resource) { if (!is_resource($resource) || get_resource_type($resource) !== 'gd') { throw new InvalidArgumentException('Invalid resource type.'); } $width = imagesx($resource); $height = imagesy($resource); if ($width < 1 || $height < 1) { throw new InvalidImageDimensionException( sprintf('The resource image dimensions should be at least 1x1px. The resource image with %sx%spx dimensions given.', $width, $height) ); } }
[ "protected", "function", "assertResource", "(", "$", "resource", ")", "{", "if", "(", "!", "is_resource", "(", "$", "resource", ")", "||", "get_resource_type", "(", "$", "resource", ")", "!==", "'gd'", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid resource type.'", ")", ";", "}", "$", "width", "=", "imagesx", "(", "$", "resource", ")", ";", "$", "height", "=", "imagesy", "(", "$", "resource", ")", ";", "if", "(", "$", "width", "<", "1", "||", "$", "height", "<", "1", ")", "{", "throw", "new", "InvalidImageDimensionException", "(", "sprintf", "(", "'The resource image dimensions should be at least 1x1px. The resource image with %sx%spx dimensions given.'", ",", "$", "width", ",", "$", "height", ")", ")", ";", "}", "}" ]
Assert an image resource. @param $resource
[ "Assert", "an", "image", "resource", "." ]
64e2042def3f0450e04a812dd3dcd8e7236a7fd8
https://github.com/tooleks/php-avg-color-picker/blob/64e2042def3f0450e04a812dd3dcd8e7236a7fd8/src/Gd/Image.php#L59-L72
229,317
tooleks/php-avg-color-picker
src/Gd/Image.php
Image.createFromPath
public static function createFromPath(string $path) { $createFunctions = [ 'image/png' => 'imagecreatefrompng', 'image/jpeg' => 'imagecreatefromjpeg', 'image/gif' => 'imagecreatefromgif', ]; $mimeType = mime_content_type($path); if (!array_key_exists($mimeType, $createFunctions)) { throw new InvalidMimeTypeException(sprintf('The "%s" mime type is not supported.', $mimeType)); } $resource = $createFunctions[$mimeType]($path); return new static($resource); }
php
public static function createFromPath(string $path) { $createFunctions = [ 'image/png' => 'imagecreatefrompng', 'image/jpeg' => 'imagecreatefromjpeg', 'image/gif' => 'imagecreatefromgif', ]; $mimeType = mime_content_type($path); if (!array_key_exists($mimeType, $createFunctions)) { throw new InvalidMimeTypeException(sprintf('The "%s" mime type is not supported.', $mimeType)); } $resource = $createFunctions[$mimeType]($path); return new static($resource); }
[ "public", "static", "function", "createFromPath", "(", "string", "$", "path", ")", "{", "$", "createFunctions", "=", "[", "'image/png'", "=>", "'imagecreatefrompng'", ",", "'image/jpeg'", "=>", "'imagecreatefromjpeg'", ",", "'image/gif'", "=>", "'imagecreatefromgif'", ",", "]", ";", "$", "mimeType", "=", "mime_content_type", "(", "$", "path", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "mimeType", ",", "$", "createFunctions", ")", ")", "{", "throw", "new", "InvalidMimeTypeException", "(", "sprintf", "(", "'The \"%s\" mime type is not supported.'", ",", "$", "mimeType", ")", ")", ";", "}", "$", "resource", "=", "$", "createFunctions", "[", "$", "mimeType", "]", "(", "$", "path", ")", ";", "return", "new", "static", "(", "$", "resource", ")", ";", "}" ]
Create an image from the path. @param string $path @return $this
[ "Create", "an", "image", "from", "the", "path", "." ]
64e2042def3f0450e04a812dd3dcd8e7236a7fd8
https://github.com/tooleks/php-avg-color-picker/blob/64e2042def3f0450e04a812dd3dcd8e7236a7fd8/src/Gd/Image.php#L91-L108
229,318
gbv/jskos-php
src/Resource.php
Resource.guessClassFromTypes
public static function guessClassFromTypes(array $types) { if (count($types)) { foreach (Resource::CLASSES as $class) { $class = "JSKOS\\$class"; foreach ($class::TYPES as $uri) { if (in_array($uri, $types)) { return $class; } } } } }
php
public static function guessClassFromTypes(array $types) { if (count($types)) { foreach (Resource::CLASSES as $class) { $class = "JSKOS\\$class"; foreach ($class::TYPES as $uri) { if (in_array($uri, $types)) { return $class; } } } } }
[ "public", "static", "function", "guessClassFromTypes", "(", "array", "$", "types", ")", "{", "if", "(", "count", "(", "$", "types", ")", ")", "{", "foreach", "(", "Resource", "::", "CLASSES", "as", "$", "class", ")", "{", "$", "class", "=", "\"JSKOS\\\\$class\"", ";", "foreach", "(", "$", "class", "::", "TYPES", "as", "$", "uri", ")", "{", "if", "(", "in_array", "(", "$", "uri", ",", "$", "types", ")", ")", "{", "return", "$", "class", ";", "}", "}", "}", "}", "}" ]
Guess subclass from list of type URIs.
[ "Guess", "subclass", "from", "list", "of", "type", "URIs", "." ]
b558b3bdbced9c6c0671dbeeebcdfcee2c72e405
https://github.com/gbv/jskos-php/blob/b558b3bdbced9c6c0671dbeeebcdfcee2c72e405/src/Resource.php#L85-L97
229,319
slickframework/slick
src/Slick/Database/Sql/Dialect/Sqlite/CreateTableSqlTemplate.php
CreateTableSqlTemplate._getUniqueConstraint
protected function _getUniqueConstraint(Constraint\Unique $constraint) { $this->_afterCreate[] = sprintf( 'CREATE UNIQUE INDEX %s ON %s(%s)', $constraint->getName(), $this->_sql->getTable(), $constraint->getColumn() ); return null; }
php
protected function _getUniqueConstraint(Constraint\Unique $constraint) { $this->_afterCreate[] = sprintf( 'CREATE UNIQUE INDEX %s ON %s(%s)', $constraint->getName(), $this->_sql->getTable(), $constraint->getColumn() ); return null; }
[ "protected", "function", "_getUniqueConstraint", "(", "Constraint", "\\", "Unique", "$", "constraint", ")", "{", "$", "this", "->", "_afterCreate", "[", "]", "=", "sprintf", "(", "'CREATE UNIQUE INDEX %s ON %s(%s)'", ",", "$", "constraint", "->", "getName", "(", ")", ",", "$", "this", "->", "_sql", "->", "getTable", "(", ")", ",", "$", "constraint", "->", "getColumn", "(", ")", ")", ";", "return", "null", ";", "}" ]
Parse a Unique constraint to its SQL representation @param Constraint\Unique $constraint @return null|string
[ "Parse", "a", "Unique", "constraint", "to", "its", "SQL", "representation" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Sql/Dialect/Sqlite/CreateTableSqlTemplate.php#L210-L219
229,320
lekoala/silverstripe-form-extras
code/FormExtra.php
FormExtra.err
protected function err($msg, $url = null) { $this->saveDataInSession(); return $this->msg($msg, self::MSG_BAD, $url); }
php
protected function err($msg, $url = null) { $this->saveDataInSession(); return $this->msg($msg, self::MSG_BAD, $url); }
[ "protected", "function", "err", "(", "$", "msg", ",", "$", "url", "=", "null", ")", "{", "$", "this", "->", "saveDataInSession", "(", ")", ";", "return", "$", "this", "->", "msg", "(", "$", "msg", ",", "self", "::", "MSG_BAD", ",", "$", "url", ")", ";", "}" ]
Shortcut for an error @param string $msg @param string $url @return SS_HTTPResponse
[ "Shortcut", "for", "an", "error" ]
e0c1200792af8e6cea916e1999c73cf8408c6dd2
https://github.com/lekoala/silverstripe-form-extras/blob/e0c1200792af8e6cea916e1999c73cf8408c6dd2/code/FormExtra.php#L153-L157
229,321
lekoala/silverstripe-form-extras
code/FormExtra.php
FormExtra.success
protected function success($msg, $url = null) { return $this->msg($msg, self::MSG_GOOD, $url); }
php
protected function success($msg, $url = null) { return $this->msg($msg, self::MSG_GOOD, $url); }
[ "protected", "function", "success", "(", "$", "msg", ",", "$", "url", "=", "null", ")", "{", "return", "$", "this", "->", "msg", "(", "$", "msg", ",", "self", "::", "MSG_GOOD", ",", "$", "url", ")", ";", "}" ]
Shortcut for a success @param string $msg @param string $url @return SS_HTTPResponse
[ "Shortcut", "for", "a", "success" ]
e0c1200792af8e6cea916e1999c73cf8408c6dd2
https://github.com/lekoala/silverstripe-form-extras/blob/e0c1200792af8e6cea916e1999c73cf8408c6dd2/code/FormExtra.php#L166-L169
229,322
lekoala/silverstripe-form-extras
code/FormExtra.php
FormExtra.msg
protected function msg($msg, $type, $url = null) { $this->sessionMessage($msg, $type); if ($url) { return $this->Controller()->redirect($url); } return $this->Controller()->redirectBack(); }
php
protected function msg($msg, $type, $url = null) { $this->sessionMessage($msg, $type); if ($url) { return $this->Controller()->redirect($url); } return $this->Controller()->redirectBack(); }
[ "protected", "function", "msg", "(", "$", "msg", ",", "$", "type", ",", "$", "url", "=", "null", ")", "{", "$", "this", "->", "sessionMessage", "(", "$", "msg", ",", "$", "type", ")", ";", "if", "(", "$", "url", ")", "{", "return", "$", "this", "->", "Controller", "(", ")", "->", "redirect", "(", "$", "url", ")", ";", "}", "return", "$", "this", "->", "Controller", "(", ")", "->", "redirectBack", "(", ")", ";", "}" ]
Return a response with a message for your form @param string $msg @param string $type good,bad,notice,warning @param string $url @return SS_HTTPResponse
[ "Return", "a", "response", "with", "a", "message", "for", "your", "form" ]
e0c1200792af8e6cea916e1999c73cf8408c6dd2
https://github.com/lekoala/silverstripe-form-extras/blob/e0c1200792af8e6cea916e1999c73cf8408c6dd2/code/FormExtra.php#L179-L186
229,323
inc2734/wp-breadcrumbs
src/Contract/Controller/Controller.php
Controller.set_ancestors
protected function set_ancestors( $object_id, $object_type ) { $ancestors = get_ancestors( $object_id, $object_type ); krsort( $ancestors ); if ( 'page' === $object_type ) { foreach ( $ancestors as $ancestor_id ) { $this->set( get_the_title( $ancestor_id ), get_permalink( $ancestor_id ) ); } } else { foreach ( $ancestors as $ancestor_id ) { $ancestor = get_term( $ancestor_id, $object_type ); $this->set( $ancestor->name, get_term_link( $ancestor ) ); } } }
php
protected function set_ancestors( $object_id, $object_type ) { $ancestors = get_ancestors( $object_id, $object_type ); krsort( $ancestors ); if ( 'page' === $object_type ) { foreach ( $ancestors as $ancestor_id ) { $this->set( get_the_title( $ancestor_id ), get_permalink( $ancestor_id ) ); } } else { foreach ( $ancestors as $ancestor_id ) { $ancestor = get_term( $ancestor_id, $object_type ); $this->set( $ancestor->name, get_term_link( $ancestor ) ); } } }
[ "protected", "function", "set_ancestors", "(", "$", "object_id", ",", "$", "object_type", ")", "{", "$", "ancestors", "=", "get_ancestors", "(", "$", "object_id", ",", "$", "object_type", ")", ";", "krsort", "(", "$", "ancestors", ")", ";", "if", "(", "'page'", "===", "$", "object_type", ")", "{", "foreach", "(", "$", "ancestors", "as", "$", "ancestor_id", ")", "{", "$", "this", "->", "set", "(", "get_the_title", "(", "$", "ancestor_id", ")", ",", "get_permalink", "(", "$", "ancestor_id", ")", ")", ";", "}", "}", "else", "{", "foreach", "(", "$", "ancestors", "as", "$", "ancestor_id", ")", "{", "$", "ancestor", "=", "get_term", "(", "$", "ancestor_id", ",", "$", "object_type", ")", ";", "$", "this", "->", "set", "(", "$", "ancestor", "->", "name", ",", "get_term_link", "(", "$", "ancestor", ")", ")", ";", "}", "}", "}" ]
Set the ancestors of the specified page or taxonomy @param int $object_id Post ID or Term ID @param string $object_type
[ "Set", "the", "ancestors", "of", "the", "specified", "page", "or", "taxonomy" ]
fb904467f5ab3ec18c17c7420d1cbd98248367d8
https://github.com/inc2734/wp-breadcrumbs/blob/fb904467f5ab3ec18c17c7420d1cbd98248367d8/src/Contract/Controller/Controller.php#L54-L67
229,324
inc2734/wp-breadcrumbs
src/Contract/Controller/Controller.php
Controller.get_post_type
protected function get_post_type() { global $wp_query; $post_type = get_post_type(); if ( $post_type ) { return $post_type; } if ( isset( $wp_query->query['post_type'] ) ) { return $wp_query->query['post_type']; } return $post_type; }
php
protected function get_post_type() { global $wp_query; $post_type = get_post_type(); if ( $post_type ) { return $post_type; } if ( isset( $wp_query->query['post_type'] ) ) { return $wp_query->query['post_type']; } return $post_type; }
[ "protected", "function", "get_post_type", "(", ")", "{", "global", "$", "wp_query", ";", "$", "post_type", "=", "get_post_type", "(", ")", ";", "if", "(", "$", "post_type", ")", "{", "return", "$", "post_type", ";", "}", "if", "(", "isset", "(", "$", "wp_query", "->", "query", "[", "'post_type'", "]", ")", ")", "{", "return", "$", "wp_query", "->", "query", "[", "'post_type'", "]", ";", "}", "return", "$", "post_type", ";", "}" ]
Return the current post type @return string
[ "Return", "the", "current", "post", "type" ]
fb904467f5ab3ec18c17c7420d1cbd98248367d8
https://github.com/inc2734/wp-breadcrumbs/blob/fb904467f5ab3ec18c17c7420d1cbd98248367d8/src/Contract/Controller/Controller.php#L96-L110
229,325
slickframework/slick
src/Slick/Mvc/Router/RouteInfo.php
RouteInfo.setConfiguration
public function setConfiguration(DriverInterface $driver) { $this->_configuration = $driver; $this->_namespace = null; $this->_action = null; $this->_controller = null; return $this; }
php
public function setConfiguration(DriverInterface $driver) { $this->_configuration = $driver; $this->_namespace = null; $this->_action = null; $this->_controller = null; return $this; }
[ "public", "function", "setConfiguration", "(", "DriverInterface", "$", "driver", ")", "{", "$", "this", "->", "_configuration", "=", "$", "driver", ";", "$", "this", "->", "_namespace", "=", "null", ";", "$", "this", "->", "_action", "=", "null", ";", "$", "this", "->", "_controller", "=", "null", ";", "return", "$", "this", ";", "}" ]
Sets configuration driver @param DriverInterface $driver @return self
[ "Sets", "configuration", "driver" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Router/RouteInfo.php#L109-L116
229,326
slickframework/slick
src/Slick/Mvc/Router/RouteInfo.php
RouteInfo.getController
public function getController() { if (is_null($this->_controller)) { $controller = $this->getConfiguration() ->get('router.controller', 'pages'); if (isset($this->_params['controller'])) { $controller = $this->_params['controller']; } $this->_controllerName = $controller; $this->_controller = trim( "{$this->namespace}\\". ucfirst($controller), '\\' ); } return $this->_controller; }
php
public function getController() { if (is_null($this->_controller)) { $controller = $this->getConfiguration() ->get('router.controller', 'pages'); if (isset($this->_params['controller'])) { $controller = $this->_params['controller']; } $this->_controllerName = $controller; $this->_controller = trim( "{$this->namespace}\\". ucfirst($controller), '\\' ); } return $this->_controller; }
[ "public", "function", "getController", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_controller", ")", ")", "{", "$", "controller", "=", "$", "this", "->", "getConfiguration", "(", ")", "->", "get", "(", "'router.controller'", ",", "'pages'", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_params", "[", "'controller'", "]", ")", ")", "{", "$", "controller", "=", "$", "this", "->", "_params", "[", "'controller'", "]", ";", "}", "$", "this", "->", "_controllerName", "=", "$", "controller", ";", "$", "this", "->", "_controller", "=", "trim", "(", "\"{$this->namespace}\\\\\"", ".", "ucfirst", "(", "$", "controller", ")", ",", "'\\\\'", ")", ";", "}", "return", "$", "this", "->", "_controller", ";", "}" ]
Returns controller class name @return string
[ "Returns", "controller", "class", "name" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Router/RouteInfo.php#L123-L138
229,327
slickframework/slick
src/Slick/Mvc/Router/RouteInfo.php
RouteInfo.getNamespace
public function getNamespace() { if (is_null($this->_namespace)) { $namespace = $this->getConfiguration() ->get('router.namespace', 'Controllers'); if (isset($this->_params['namespace'])) { $namespace = $this->_params['namespace']; } $this->_namespace = trim($namespace, '\\'); } return $this->_namespace; }
php
public function getNamespace() { if (is_null($this->_namespace)) { $namespace = $this->getConfiguration() ->get('router.namespace', 'Controllers'); if (isset($this->_params['namespace'])) { $namespace = $this->_params['namespace']; } $this->_namespace = trim($namespace, '\\'); } return $this->_namespace; }
[ "public", "function", "getNamespace", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_namespace", ")", ")", "{", "$", "namespace", "=", "$", "this", "->", "getConfiguration", "(", ")", "->", "get", "(", "'router.namespace'", ",", "'Controllers'", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_params", "[", "'namespace'", "]", ")", ")", "{", "$", "namespace", "=", "$", "this", "->", "_params", "[", "'namespace'", "]", ";", "}", "$", "this", "->", "_namespace", "=", "trim", "(", "$", "namespace", ",", "'\\\\'", ")", ";", "}", "return", "$", "this", "->", "_namespace", ";", "}" ]
Returns the namespace for controller class @return string
[ "Returns", "the", "namespace", "for", "controller", "class" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Router/RouteInfo.php#L145-L156
229,328
slickframework/slick
src/Slick/Mvc/Router/RouteInfo.php
RouteInfo.getArguments
public function getArguments() { if (empty($this->_arguments)) { $base = []; if (isset($this->_params['trailing'])) { $base = explode('/', $this->_params['trailing']); } $names = ['controller', 'action', 'namespace', 'trailing']; foreach ($this->_params as $key => $value) { if (in_array($key, $names)) { continue; } $this->_arguments[$key] = $value; } $this->_arguments = array_merge($this->_arguments, $base); } return $this->_arguments; }
php
public function getArguments() { if (empty($this->_arguments)) { $base = []; if (isset($this->_params['trailing'])) { $base = explode('/', $this->_params['trailing']); } $names = ['controller', 'action', 'namespace', 'trailing']; foreach ($this->_params as $key => $value) { if (in_array($key, $names)) { continue; } $this->_arguments[$key] = $value; } $this->_arguments = array_merge($this->_arguments, $base); } return $this->_arguments; }
[ "public", "function", "getArguments", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_arguments", ")", ")", "{", "$", "base", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "_params", "[", "'trailing'", "]", ")", ")", "{", "$", "base", "=", "explode", "(", "'/'", ",", "$", "this", "->", "_params", "[", "'trailing'", "]", ")", ";", "}", "$", "names", "=", "[", "'controller'", ",", "'action'", ",", "'namespace'", ",", "'trailing'", "]", ";", "foreach", "(", "$", "this", "->", "_params", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "names", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "_arguments", "[", "$", "key", "]", "=", "$", "value", ";", "}", "$", "this", "->", "_arguments", "=", "array_merge", "(", "$", "this", "->", "_arguments", ",", "$", "base", ")", ";", "}", "return", "$", "this", "->", "_arguments", ";", "}" ]
Returns the list of arguments passed in the URL @return array
[ "Returns", "the", "list", "of", "arguments", "passed", "in", "the", "URL" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Router/RouteInfo.php#L181-L199
229,329
slickframework/slick
src/Slick/Mvc/Router/RouteInfo.php
RouteInfo.setTarget
public function setTarget($target) { if (is_array($target)) { $this->_params = array_merge($this->_params, $target); } $this->_target = $target; }
php
public function setTarget($target) { if (is_array($target)) { $this->_params = array_merge($this->_params, $target); } $this->_target = $target; }
[ "public", "function", "setTarget", "(", "$", "target", ")", "{", "if", "(", "is_array", "(", "$", "target", ")", ")", "{", "$", "this", "->", "_params", "=", "array_merge", "(", "$", "this", "->", "_params", ",", "$", "target", ")", ";", "}", "$", "this", "->", "_target", "=", "$", "target", ";", "}" ]
Sets target data @param $target
[ "Sets", "target", "data" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Router/RouteInfo.php#L221-L227
229,330
cornernote/yii-audit-module
audit/models/AuditLog.php
AuditLog.formatProfileMessage
public function formatProfileMessage($message) { $sqlStart = strpos($message, '(') + 1; $sqlEnd = strrpos($message, ')'); $sqlLength = $sqlEnd - $sqlStart; $message = substr($message, $sqlStart, $sqlLength); $message = strtr($message, array( ' FROM ' => "\nFROM ", ' VALUES ' => "\nVALUES ", ' WHERE ' => "\nWHERE ", ' ORDER BY ' => "\nORDER BY ", ' GROUP BY ' => "\nGROUP BY ", ' LIMIT ' => "\nLIMIT ", ' AND ' => "\n\tAND ", ', ' => ",\n\t ", )); if (strpos($message, '. Bound with ') !== false) { list($query, $params) = explode('. Bound with ', $message); $binds = array(); $matchResult = preg_match_all("/(?<key>[a-z0-9\.\_\-\:]+)=(?<value>[\d\.e\-\+]+|''|'.+?(?<!\\\)')/ims", $params, $paramsMatched, PREG_SET_ORDER); if ($matchResult) { foreach ($paramsMatched as $paramsMatch) if (isset($paramsMatch['key'], $paramsMatch['value'])) $binds[':' . trim($paramsMatch['key'], ': ')] = trim($paramsMatch['value']); } $message = strtr($query, $binds); } return strip_tags($this->getTextHighlighter()->highlight($message), '<div>,<span>'); }
php
public function formatProfileMessage($message) { $sqlStart = strpos($message, '(') + 1; $sqlEnd = strrpos($message, ')'); $sqlLength = $sqlEnd - $sqlStart; $message = substr($message, $sqlStart, $sqlLength); $message = strtr($message, array( ' FROM ' => "\nFROM ", ' VALUES ' => "\nVALUES ", ' WHERE ' => "\nWHERE ", ' ORDER BY ' => "\nORDER BY ", ' GROUP BY ' => "\nGROUP BY ", ' LIMIT ' => "\nLIMIT ", ' AND ' => "\n\tAND ", ', ' => ",\n\t ", )); if (strpos($message, '. Bound with ') !== false) { list($query, $params) = explode('. Bound with ', $message); $binds = array(); $matchResult = preg_match_all("/(?<key>[a-z0-9\.\_\-\:]+)=(?<value>[\d\.e\-\+]+|''|'.+?(?<!\\\)')/ims", $params, $paramsMatched, PREG_SET_ORDER); if ($matchResult) { foreach ($paramsMatched as $paramsMatch) if (isset($paramsMatch['key'], $paramsMatch['value'])) $binds[':' . trim($paramsMatch['key'], ': ')] = trim($paramsMatch['value']); } $message = strtr($query, $binds); } return strip_tags($this->getTextHighlighter()->highlight($message), '<div>,<span>'); }
[ "public", "function", "formatProfileMessage", "(", "$", "message", ")", "{", "$", "sqlStart", "=", "strpos", "(", "$", "message", ",", "'('", ")", "+", "1", ";", "$", "sqlEnd", "=", "strrpos", "(", "$", "message", ",", "')'", ")", ";", "$", "sqlLength", "=", "$", "sqlEnd", "-", "$", "sqlStart", ";", "$", "message", "=", "substr", "(", "$", "message", ",", "$", "sqlStart", ",", "$", "sqlLength", ")", ";", "$", "message", "=", "strtr", "(", "$", "message", ",", "array", "(", "' FROM '", "=>", "\"\\nFROM \"", ",", "' VALUES '", "=>", "\"\\nVALUES \"", ",", "' WHERE '", "=>", "\"\\nWHERE \"", ",", "' ORDER BY '", "=>", "\"\\nORDER BY \"", ",", "' GROUP BY '", "=>", "\"\\nGROUP BY \"", ",", "' LIMIT '", "=>", "\"\\nLIMIT \"", ",", "' AND '", "=>", "\"\\n\\tAND \"", ",", "', '", "=>", "\",\\n\\t \"", ",", ")", ")", ";", "if", "(", "strpos", "(", "$", "message", ",", "'. Bound with '", ")", "!==", "false", ")", "{", "list", "(", "$", "query", ",", "$", "params", ")", "=", "explode", "(", "'. Bound with '", ",", "$", "message", ")", ";", "$", "binds", "=", "array", "(", ")", ";", "$", "matchResult", "=", "preg_match_all", "(", "\"/(?<key>[a-z0-9\\.\\_\\-\\:]+)=(?<value>[\\d\\.e\\-\\+]+|''|'.+?(?<!\\\\\\)')/ims\"", ",", "$", "params", ",", "$", "paramsMatched", ",", "PREG_SET_ORDER", ")", ";", "if", "(", "$", "matchResult", ")", "{", "foreach", "(", "$", "paramsMatched", "as", "$", "paramsMatch", ")", "if", "(", "isset", "(", "$", "paramsMatch", "[", "'key'", "]", ",", "$", "paramsMatch", "[", "'value'", "]", ")", ")", "$", "binds", "[", "':'", ".", "trim", "(", "$", "paramsMatch", "[", "'key'", "]", ",", "': '", ")", "]", "=", "trim", "(", "$", "paramsMatch", "[", "'value'", "]", ")", ";", "}", "$", "message", "=", "strtr", "(", "$", "query", ",", "$", "binds", ")", ";", "}", "return", "strip_tags", "(", "$", "this", "->", "getTextHighlighter", "(", ")", "->", "highlight", "(", "$", "message", ")", ",", "'<div>,<span>'", ")", ";", "}" ]
Format profile message @param string $message @return string
[ "Format", "profile", "message" ]
07362f79741b5343d22bb9bb516d840072a097d4
https://github.com/cornernote/yii-audit-module/blob/07362f79741b5343d22bb9bb516d840072a097d4/audit/models/AuditLog.php#L132-L160
229,331
slickframework/slick
src/Slick/Orm/Entity.php
Entity.getTableName
public function getTableName() { if (is_null($this->_tableName)) { $parts = explode('\\', $this->getClassName()); $name = end($parts); $this->_tableName = Text::plural(strtolower($name)); } return $this->_tableName; }
php
public function getTableName() { if (is_null($this->_tableName)) { $parts = explode('\\', $this->getClassName()); $name = end($parts); $this->_tableName = Text::plural(strtolower($name)); } return $this->_tableName; }
[ "public", "function", "getTableName", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_tableName", ")", ")", "{", "$", "parts", "=", "explode", "(", "'\\\\'", ",", "$", "this", "->", "getClassName", "(", ")", ")", ";", "$", "name", "=", "end", "(", "$", "parts", ")", ";", "$", "this", "->", "_tableName", "=", "Text", "::", "plural", "(", "strtolower", "(", "$", "name", ")", ")", ";", "}", "return", "$", "this", "->", "_tableName", ";", "}" ]
Returns entity table name. If no name was give it returns the plural of the entity class name @return string
[ "Returns", "entity", "table", "name", ".", "If", "no", "name", "was", "give", "it", "returns", "the", "plural", "of", "the", "entity", "class", "name" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Entity.php#L52-L60
229,332
slickframework/slick
src/Slick/Orm/Entity.php
Entity.get
public static function get($id) { /** @var Entity $entity */ $entity = new static(); Manager::getInstance()->get($entity)->refreshRelations(); $className = $entity->getClassName(); $sql = Sql::createSql($entity->getAdapter()) ->select($entity->getTableName()) ->where( [ "{$entity->getTableName()}.{$entity->_primaryKey} = :id" => [ ':id' => $id ] ] ); $events = $entity->getEventManager(); $event = new Select([ 'sqlQuery' => $sql, 'params' => compact('id'), 'action' => Select::GET, 'singleItem' => true ]); $events->trigger(Select::BEFORE_SELECT, $entity, $event); $row = $event->sqlQuery->first(); if ($row) { $event->data = $row; $events->trigger(Select::AFTER_SELECT, $entity, $event); $object = new $className($event->data); return $object; } return null; }
php
public static function get($id) { /** @var Entity $entity */ $entity = new static(); Manager::getInstance()->get($entity)->refreshRelations(); $className = $entity->getClassName(); $sql = Sql::createSql($entity->getAdapter()) ->select($entity->getTableName()) ->where( [ "{$entity->getTableName()}.{$entity->_primaryKey} = :id" => [ ':id' => $id ] ] ); $events = $entity->getEventManager(); $event = new Select([ 'sqlQuery' => $sql, 'params' => compact('id'), 'action' => Select::GET, 'singleItem' => true ]); $events->trigger(Select::BEFORE_SELECT, $entity, $event); $row = $event->sqlQuery->first(); if ($row) { $event->data = $row; $events->trigger(Select::AFTER_SELECT, $entity, $event); $object = new $className($event->data); return $object; } return null; }
[ "public", "static", "function", "get", "(", "$", "id", ")", "{", "/** @var Entity $entity */", "$", "entity", "=", "new", "static", "(", ")", ";", "Manager", "::", "getInstance", "(", ")", "->", "get", "(", "$", "entity", ")", "->", "refreshRelations", "(", ")", ";", "$", "className", "=", "$", "entity", "->", "getClassName", "(", ")", ";", "$", "sql", "=", "Sql", "::", "createSql", "(", "$", "entity", "->", "getAdapter", "(", ")", ")", "->", "select", "(", "$", "entity", "->", "getTableName", "(", ")", ")", "->", "where", "(", "[", "\"{$entity->getTableName()}.{$entity->_primaryKey} = :id\"", "=>", "[", "':id'", "=>", "$", "id", "]", "]", ")", ";", "$", "events", "=", "$", "entity", "->", "getEventManager", "(", ")", ";", "$", "event", "=", "new", "Select", "(", "[", "'sqlQuery'", "=>", "$", "sql", ",", "'params'", "=>", "compact", "(", "'id'", ")", ",", "'action'", "=>", "Select", "::", "GET", ",", "'singleItem'", "=>", "true", "]", ")", ";", "$", "events", "->", "trigger", "(", "Select", "::", "BEFORE_SELECT", ",", "$", "entity", ",", "$", "event", ")", ";", "$", "row", "=", "$", "event", "->", "sqlQuery", "->", "first", "(", ")", ";", "if", "(", "$", "row", ")", "{", "$", "event", "->", "data", "=", "$", "row", ";", "$", "events", "->", "trigger", "(", "Select", "::", "AFTER_SELECT", ",", "$", "entity", ",", "$", "event", ")", ";", "$", "object", "=", "new", "$", "className", "(", "$", "event", "->", "data", ")", ";", "return", "$", "object", ";", "}", "return", "null", ";", "}" ]
Gets the record with the provided primary key @param string|integer $id The primary key value @return null|self
[ "Gets", "the", "record", "with", "the", "provided", "primary", "key" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Entity.php#L69-L102
229,333
slickframework/slick
src/Slick/Orm/Entity.php
Entity.find
public static function find($fields = '*') { $entity = new static(); if ($fields == '*') { $fields = $entity->getTableName() .'.*'; } Entity\Manager::getInstance()->get($entity)->refreshRelations(); $select = new \Slick\Orm\Sql\Select($entity, $fields); return $select; }
php
public static function find($fields = '*') { $entity = new static(); if ($fields == '*') { $fields = $entity->getTableName() .'.*'; } Entity\Manager::getInstance()->get($entity)->refreshRelations(); $select = new \Slick\Orm\Sql\Select($entity, $fields); return $select; }
[ "public", "static", "function", "find", "(", "$", "fields", "=", "'*'", ")", "{", "$", "entity", "=", "new", "static", "(", ")", ";", "if", "(", "$", "fields", "==", "'*'", ")", "{", "$", "fields", "=", "$", "entity", "->", "getTableName", "(", ")", ".", "'.*'", ";", "}", "Entity", "\\", "Manager", "::", "getInstance", "(", ")", "->", "get", "(", "$", "entity", ")", "->", "refreshRelations", "(", ")", ";", "$", "select", "=", "new", "\\", "Slick", "\\", "Orm", "\\", "Sql", "\\", "Select", "(", "$", "entity", ",", "$", "fields", ")", ";", "return", "$", "select", ";", "}" ]
Starts a select query on this model. Fields can be specified otherwise all fields are selected @param string|array $fields The list of fields to be selected. @return \Slick\Orm\Sql\Select
[ "Starts", "a", "select", "query", "on", "this", "model", ".", "Fields", "can", "be", "specified", "otherwise", "all", "fields", "are", "selected" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Entity.php#L112-L121
229,334
slickframework/slick
src/Slick/Orm/Entity.php
Entity.save
public function save(array $data = []) { Manager::getInstance()->get($this)->refreshRelations(); $action = Save::INSERT; $pmk = $this->primaryKey; if ($this->$pmk || isset($data[$pmk])) { $action = Save::UPDATE; } if ($action == Save::UPDATE) { return $this->_update($data); } return $this->_insert($data); }
php
public function save(array $data = []) { Manager::getInstance()->get($this)->refreshRelations(); $action = Save::INSERT; $pmk = $this->primaryKey; if ($this->$pmk || isset($data[$pmk])) { $action = Save::UPDATE; } if ($action == Save::UPDATE) { return $this->_update($data); } return $this->_insert($data); }
[ "public", "function", "save", "(", "array", "$", "data", "=", "[", "]", ")", "{", "Manager", "::", "getInstance", "(", ")", "->", "get", "(", "$", "this", ")", "->", "refreshRelations", "(", ")", ";", "$", "action", "=", "Save", "::", "INSERT", ";", "$", "pmk", "=", "$", "this", "->", "primaryKey", ";", "if", "(", "$", "this", "->", "$", "pmk", "||", "isset", "(", "$", "data", "[", "$", "pmk", "]", ")", ")", "{", "$", "action", "=", "Save", "::", "UPDATE", ";", "}", "if", "(", "$", "action", "==", "Save", "::", "UPDATE", ")", "{", "return", "$", "this", "->", "_update", "(", "$", "data", ")", ";", "}", "return", "$", "this", "->", "_insert", "(", "$", "data", ")", ";", "}" ]
Saves the entity data or the provided data If no data is provided the save action will check all properties marked with @column annotation and crates a key/value pair array with those properties and its values. If the data is provided only the values in that associative array will be used except that if you don't set the primary key value and the entity has this property set it will be added to the data being saved. If data being saved has the primary key with value (by setting this property or entering the key/value in data) an update will be performed on database. In the opposite an insert will be done. @param array $data @return bool True if data was saved, false otherwise
[ "Saves", "the", "entity", "data", "or", "the", "provided", "data" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Entity.php#L140-L154
229,335
slickframework/slick
src/Slick/Orm/Entity.php
Entity.delete
public function delete() { Manager::getInstance()->get($this)->refreshRelations(); $pmk = $this->getPrimaryKey(); $sql = Sql::createSql($this->getAdapter()) ->delete($this->getTableName()) ->where(["{$pmk} = :id" => [':id' => $this->$pmk]]); $event = new Delete([ 'primaryKey' => $this->$pmk, 'abort' => false ]); $this->getEventManager()->trigger(Delete::BEFORE_DELETE, $this, $event); if ($event->abort) { return false; } $result = $sql->execute(); $this->getEventManager()->trigger(Delete::AFTER_DELETE, $event); return $result > 0; }
php
public function delete() { Manager::getInstance()->get($this)->refreshRelations(); $pmk = $this->getPrimaryKey(); $sql = Sql::createSql($this->getAdapter()) ->delete($this->getTableName()) ->where(["{$pmk} = :id" => [':id' => $this->$pmk]]); $event = new Delete([ 'primaryKey' => $this->$pmk, 'abort' => false ]); $this->getEventManager()->trigger(Delete::BEFORE_DELETE, $this, $event); if ($event->abort) { return false; } $result = $sql->execute(); $this->getEventManager()->trigger(Delete::AFTER_DELETE, $event); return $result > 0; }
[ "public", "function", "delete", "(", ")", "{", "Manager", "::", "getInstance", "(", ")", "->", "get", "(", "$", "this", ")", "->", "refreshRelations", "(", ")", ";", "$", "pmk", "=", "$", "this", "->", "getPrimaryKey", "(", ")", ";", "$", "sql", "=", "Sql", "::", "createSql", "(", "$", "this", "->", "getAdapter", "(", ")", ")", "->", "delete", "(", "$", "this", "->", "getTableName", "(", ")", ")", "->", "where", "(", "[", "\"{$pmk} = :id\"", "=>", "[", "':id'", "=>", "$", "this", "->", "$", "pmk", "]", "]", ")", ";", "$", "event", "=", "new", "Delete", "(", "[", "'primaryKey'", "=>", "$", "this", "->", "$", "pmk", ",", "'abort'", "=>", "false", "]", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "Delete", "::", "BEFORE_DELETE", ",", "$", "this", ",", "$", "event", ")", ";", "if", "(", "$", "event", "->", "abort", ")", "{", "return", "false", ";", "}", "$", "result", "=", "$", "sql", "->", "execute", "(", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "Delete", "::", "AFTER_DELETE", ",", "$", "event", ")", ";", "return", "$", "result", ">", "0", ";", "}" ]
Deletes current record from @return bool
[ "Deletes", "current", "record", "from" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Entity.php#L161-L180
229,336
slickframework/slick
src/Slick/Orm/Entity.php
Entity._insert
protected function _insert(array $data) { $data = $this->_setData($data); $sql = Sql::createSql($this->getAdapter())->insert($this->getTableName()); $event = new Save([ 'action' => Save::INSERT, 'data' => $data, 'abort' => false ]); $this->getEventManager()->trigger(Save::BEFORE_SAVE, $this, $event); if ($event->abort) { return false; } $result = $sql->set($event->data)->execute(); if ($result > 0) { $pmk = $this->getPrimaryKey(); $this->$pmk = $this->getAdapter()->getLastInsertId(); $this->getEventManager()->trigger(Save::AFTER_SAVE, $this, $event); } return $result > 0; }
php
protected function _insert(array $data) { $data = $this->_setData($data); $sql = Sql::createSql($this->getAdapter())->insert($this->getTableName()); $event = new Save([ 'action' => Save::INSERT, 'data' => $data, 'abort' => false ]); $this->getEventManager()->trigger(Save::BEFORE_SAVE, $this, $event); if ($event->abort) { return false; } $result = $sql->set($event->data)->execute(); if ($result > 0) { $pmk = $this->getPrimaryKey(); $this->$pmk = $this->getAdapter()->getLastInsertId(); $this->getEventManager()->trigger(Save::AFTER_SAVE, $this, $event); } return $result > 0; }
[ "protected", "function", "_insert", "(", "array", "$", "data", ")", "{", "$", "data", "=", "$", "this", "->", "_setData", "(", "$", "data", ")", ";", "$", "sql", "=", "Sql", "::", "createSql", "(", "$", "this", "->", "getAdapter", "(", ")", ")", "->", "insert", "(", "$", "this", "->", "getTableName", "(", ")", ")", ";", "$", "event", "=", "new", "Save", "(", "[", "'action'", "=>", "Save", "::", "INSERT", ",", "'data'", "=>", "$", "data", ",", "'abort'", "=>", "false", "]", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "Save", "::", "BEFORE_SAVE", ",", "$", "this", ",", "$", "event", ")", ";", "if", "(", "$", "event", "->", "abort", ")", "{", "return", "false", ";", "}", "$", "result", "=", "$", "sql", "->", "set", "(", "$", "event", "->", "data", ")", "->", "execute", "(", ")", ";", "if", "(", "$", "result", ">", "0", ")", "{", "$", "pmk", "=", "$", "this", "->", "getPrimaryKey", "(", ")", ";", "$", "this", "->", "$", "pmk", "=", "$", "this", "->", "getAdapter", "(", ")", "->", "getLastInsertId", "(", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "Save", "::", "AFTER_SAVE", ",", "$", "this", ",", "$", "event", ")", ";", "}", "return", "$", "result", ">", "0", ";", "}" ]
Inserts a new record in the database @param array $data @return bool
[ "Inserts", "a", "new", "record", "in", "the", "database" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Entity.php#L188-L209
229,337
slickframework/slick
src/Slick/Orm/Entity.php
Entity._update
protected function _update(array $data) { $data = $this->_setData($data); $pmk = $this->getPrimaryKey(); unset($data[$pmk]); $sql = Sql::createSql($this->getAdapter())->update($this->getTableName()); $event = new Save([ 'action' => Save::UPDATE, 'data' => $data, 'abort' => false ]); $this->getEventManager()->trigger(Save::BEFORE_SAVE, $this, $event); if ($event->abort) { return false; } $sql->set($event->data) ->where(["{$pmk} = :id" => [':id' => $this->$pmk]]) ->execute(); $this->getEventManager()->trigger(Save::AFTER_SAVE, $this, $event); return true; }
php
protected function _update(array $data) { $data = $this->_setData($data); $pmk = $this->getPrimaryKey(); unset($data[$pmk]); $sql = Sql::createSql($this->getAdapter())->update($this->getTableName()); $event = new Save([ 'action' => Save::UPDATE, 'data' => $data, 'abort' => false ]); $this->getEventManager()->trigger(Save::BEFORE_SAVE, $this, $event); if ($event->abort) { return false; } $sql->set($event->data) ->where(["{$pmk} = :id" => [':id' => $this->$pmk]]) ->execute(); $this->getEventManager()->trigger(Save::AFTER_SAVE, $this, $event); return true; }
[ "protected", "function", "_update", "(", "array", "$", "data", ")", "{", "$", "data", "=", "$", "this", "->", "_setData", "(", "$", "data", ")", ";", "$", "pmk", "=", "$", "this", "->", "getPrimaryKey", "(", ")", ";", "unset", "(", "$", "data", "[", "$", "pmk", "]", ")", ";", "$", "sql", "=", "Sql", "::", "createSql", "(", "$", "this", "->", "getAdapter", "(", ")", ")", "->", "update", "(", "$", "this", "->", "getTableName", "(", ")", ")", ";", "$", "event", "=", "new", "Save", "(", "[", "'action'", "=>", "Save", "::", "UPDATE", ",", "'data'", "=>", "$", "data", ",", "'abort'", "=>", "false", "]", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "Save", "::", "BEFORE_SAVE", ",", "$", "this", ",", "$", "event", ")", ";", "if", "(", "$", "event", "->", "abort", ")", "{", "return", "false", ";", "}", "$", "sql", "->", "set", "(", "$", "event", "->", "data", ")", "->", "where", "(", "[", "\"{$pmk} = :id\"", "=>", "[", "':id'", "=>", "$", "this", "->", "$", "pmk", "]", "]", ")", "->", "execute", "(", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "Save", "::", "AFTER_SAVE", ",", "$", "this", ",", "$", "event", ")", ";", "return", "true", ";", "}" ]
Updated current entity or data @param array $data @return bool
[ "Updated", "current", "entity", "or", "data" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Entity.php#L217-L237
229,338
slickframework/slick
src/Slick/Orm/Entity.php
Entity._setData
protected function _setData(array $data) { $pmk = $this->getPrimaryKey(); if (!empty($data)) { if (!isset($data[$pmk]) && !is_null($this->$pmk)) { $data[$pmk] = $this->$pmk; } return $data; } $columns = Manager::getInstance()->get($this)->getColumns(); foreach (array_keys($columns) as $property) { $key = trim($property, '_'); if ($key == $pmk && !$this->$pmk) { continue; } $data[$key] = $this->$property; } return $data; }
php
protected function _setData(array $data) { $pmk = $this->getPrimaryKey(); if (!empty($data)) { if (!isset($data[$pmk]) && !is_null($this->$pmk)) { $data[$pmk] = $this->$pmk; } return $data; } $columns = Manager::getInstance()->get($this)->getColumns(); foreach (array_keys($columns) as $property) { $key = trim($property, '_'); if ($key == $pmk && !$this->$pmk) { continue; } $data[$key] = $this->$property; } return $data; }
[ "protected", "function", "_setData", "(", "array", "$", "data", ")", "{", "$", "pmk", "=", "$", "this", "->", "getPrimaryKey", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "$", "pmk", "]", ")", "&&", "!", "is_null", "(", "$", "this", "->", "$", "pmk", ")", ")", "{", "$", "data", "[", "$", "pmk", "]", "=", "$", "this", "->", "$", "pmk", ";", "}", "return", "$", "data", ";", "}", "$", "columns", "=", "Manager", "::", "getInstance", "(", ")", "->", "get", "(", "$", "this", ")", "->", "getColumns", "(", ")", ";", "foreach", "(", "array_keys", "(", "$", "columns", ")", "as", "$", "property", ")", "{", "$", "key", "=", "trim", "(", "$", "property", ",", "'_'", ")", ";", "if", "(", "$", "key", "==", "$", "pmk", "&&", "!", "$", "this", "->", "$", "pmk", ")", "{", "continue", ";", "}", "$", "data", "[", "$", "key", "]", "=", "$", "this", "->", "$", "property", ";", "}", "return", "$", "data", ";", "}" ]
Sets the data to be saved @param array $data @return array
[ "Sets", "the", "data", "to", "be", "saved" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Entity.php#L245-L264
229,339
slickframework/slick
src/Slick/Orm/Entity.php
Entity.asArray
public function asArray() { $data = []; $columns = Manager::getInstance()->get($this)->getColumns(); foreach(array_keys($columns) as $field) { $data[trim($field, '_')] = $this->$field; } $relations = Manager::getInstance()->get($this)->getRelations(); foreach(array_keys($relations) as $field) { if ($this->$field instanceof Entity) { $data[trim($field, '_')] = $this->$field->asArray(); } elseif ($this->$field instanceof RecordList) { $values = []; /** @var Entity $entity */ foreach ($this->$field as $entity) { $values[] = $entity->asArray(); } $data[trim($field, '_')] = $values; } else { $data[trim($field, '_')] = $this->$field; } } return $data; }
php
public function asArray() { $data = []; $columns = Manager::getInstance()->get($this)->getColumns(); foreach(array_keys($columns) as $field) { $data[trim($field, '_')] = $this->$field; } $relations = Manager::getInstance()->get($this)->getRelations(); foreach(array_keys($relations) as $field) { if ($this->$field instanceof Entity) { $data[trim($field, '_')] = $this->$field->asArray(); } elseif ($this->$field instanceof RecordList) { $values = []; /** @var Entity $entity */ foreach ($this->$field as $entity) { $values[] = $entity->asArray(); } $data[trim($field, '_')] = $values; } else { $data[trim($field, '_')] = $this->$field; } } return $data; }
[ "public", "function", "asArray", "(", ")", "{", "$", "data", "=", "[", "]", ";", "$", "columns", "=", "Manager", "::", "getInstance", "(", ")", "->", "get", "(", "$", "this", ")", "->", "getColumns", "(", ")", ";", "foreach", "(", "array_keys", "(", "$", "columns", ")", "as", "$", "field", ")", "{", "$", "data", "[", "trim", "(", "$", "field", ",", "'_'", ")", "]", "=", "$", "this", "->", "$", "field", ";", "}", "$", "relations", "=", "Manager", "::", "getInstance", "(", ")", "->", "get", "(", "$", "this", ")", "->", "getRelations", "(", ")", ";", "foreach", "(", "array_keys", "(", "$", "relations", ")", "as", "$", "field", ")", "{", "if", "(", "$", "this", "->", "$", "field", "instanceof", "Entity", ")", "{", "$", "data", "[", "trim", "(", "$", "field", ",", "'_'", ")", "]", "=", "$", "this", "->", "$", "field", "->", "asArray", "(", ")", ";", "}", "elseif", "(", "$", "this", "->", "$", "field", "instanceof", "RecordList", ")", "{", "$", "values", "=", "[", "]", ";", "/** @var Entity $entity */", "foreach", "(", "$", "this", "->", "$", "field", "as", "$", "entity", ")", "{", "$", "values", "[", "]", "=", "$", "entity", "->", "asArray", "(", ")", ";", "}", "$", "data", "[", "trim", "(", "$", "field", ",", "'_'", ")", "]", "=", "$", "values", ";", "}", "else", "{", "$", "data", "[", "trim", "(", "$", "field", ",", "'_'", ")", "]", "=", "$", "this", "->", "$", "field", ";", "}", "}", "return", "$", "data", ";", "}" ]
Recursively returns this entity as an array. Used in json and serialization processes. @return array
[ "Recursively", "returns", "this", "entity", "as", "an", "array", ".", "Used", "in", "json", "and", "serialization", "processes", "." ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Entity.php#L272-L296
229,340
jacobstr/matura
lib/Console/Output/Printer.php
Printer.renderEvent
public function renderEvent(Event $event) { $parts = array_map('ucfirst', array_filter(preg_split('/_|\./', $event->name))); $name = 'on'.implode($parts); if (is_callable(array($this, $name))) { return call_user_func(array($this, $name), $event); } else { return null; } }
php
public function renderEvent(Event $event) { $parts = array_map('ucfirst', array_filter(preg_split('/_|\./', $event->name))); $name = 'on'.implode($parts); if (is_callable(array($this, $name))) { return call_user_func(array($this, $name), $event); } else { return null; } }
[ "public", "function", "renderEvent", "(", "Event", "$", "event", ")", "{", "$", "parts", "=", "array_map", "(", "'ucfirst'", ",", "array_filter", "(", "preg_split", "(", "'/_|\\./'", ",", "$", "event", "->", "name", ")", ")", ")", ";", "$", "name", "=", "'on'", ".", "implode", "(", "$", "parts", ")", ";", "if", "(", "is_callable", "(", "array", "(", "$", "this", ",", "$", "name", ")", ")", ")", "{", "return", "call_user_func", "(", "array", "(", "$", "this", ",", "$", "name", ")", ",", "$", "event", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Conducts our 'event_group.action' => 'onEventGroupAction delegation'
[ "Conducts", "our", "event_group", ".", "action", "=", ">", "onEventGroupAction", "delegation" ]
393e0f3676f502454cc6823cac8ce9cef2ea7bff
https://github.com/jacobstr/matura/blob/393e0f3676f502454cc6823cac8ce9cef2ea7bff/lib/Console/Output/Printer.php#L199-L209
229,341
mbilbille/jpnforphp
src/JpnForPhp/Transliterator/Transliterator.php
Transliterator.transliterate
public function transliterate($str, $system = null) { if(is_null($system)) { $system = $this->system; } if(is_null($system)) { throw new RuntimeException("Transliteration system is not defined"); } return $system->transliterate($str); }
php
public function transliterate($str, $system = null) { if(is_null($system)) { $system = $this->system; } if(is_null($system)) { throw new RuntimeException("Transliteration system is not defined"); } return $system->transliterate($str); }
[ "public", "function", "transliterate", "(", "$", "str", ",", "$", "system", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "system", ")", ")", "{", "$", "system", "=", "$", "this", "->", "system", ";", "}", "if", "(", "is_null", "(", "$", "system", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Transliteration system is not defined\"", ")", ";", "}", "return", "$", "system", "->", "transliterate", "(", "$", "str", ")", ";", "}" ]
Transliterate a string from an alphabet into another alphabet. @param string $str The string to be converted. @param System $system (Optional) Override default transliteration system. @return string Converted string.
[ "Transliterate", "a", "string", "from", "an", "alphabet", "into", "another", "alphabet", "." ]
5623468503cc2941f4656b0ee1a58b939d263453
https://github.com/mbilbille/jpnforphp/blob/5623468503cc2941f4656b0ee1a58b939d263453/src/JpnForPhp/Transliterator/Transliterator.php#L41-L49
229,342
slickframework/slick
src/Slick/Di/Definition/Helper/ObjectDefinitionHelper.php
ObjectDefinitionHelper.getDefinition
public function getDefinition($entryName) { $definition = new ObjectDefinition($entryName, $this->_className); $definition ->setMethods($this->_methods) ->setProperties($this->_properties) ->setScope($this->_scope); if ($this->_constructor) { $definition->setConstructor($this->_constructor); } return $definition; }
php
public function getDefinition($entryName) { $definition = new ObjectDefinition($entryName, $this->_className); $definition ->setMethods($this->_methods) ->setProperties($this->_properties) ->setScope($this->_scope); if ($this->_constructor) { $definition->setConstructor($this->_constructor); } return $definition; }
[ "public", "function", "getDefinition", "(", "$", "entryName", ")", "{", "$", "definition", "=", "new", "ObjectDefinition", "(", "$", "entryName", ",", "$", "this", "->", "_className", ")", ";", "$", "definition", "->", "setMethods", "(", "$", "this", "->", "_methods", ")", "->", "setProperties", "(", "$", "this", "->", "_properties", ")", "->", "setScope", "(", "$", "this", "->", "_scope", ")", ";", "if", "(", "$", "this", "->", "_constructor", ")", "{", "$", "definition", "->", "setConstructor", "(", "$", "this", "->", "_constructor", ")", ";", "}", "return", "$", "definition", ";", "}" ]
Returns an object definition @param string $entryName Container entry name @return \Slick\Di\DefinitionInterface
[ "Returns", "an", "object", "definition" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Di/Definition/Helper/ObjectDefinitionHelper.php#L73-L84
229,343
slickframework/slick
src/Slick/Di/Definition/Helper/ObjectDefinitionHelper.php
ObjectDefinitionHelper.method
public function method($name, array $parameters = []) { $this->_methods[$name] = new MethodInjection($name, $parameters); return $this; }
php
public function method($name, array $parameters = []) { $this->_methods[$name] = new MethodInjection($name, $parameters); return $this; }
[ "public", "function", "method", "(", "$", "name", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "this", "->", "_methods", "[", "$", "name", "]", "=", "new", "MethodInjection", "(", "$", "name", ",", "$", "parameters", ")", ";", "return", "$", "this", ";", "}" ]
Defines a method injection @param string $name @param array $parameters @return ObjectDefinitionHelper
[ "Defines", "a", "method", "injection" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Di/Definition/Helper/ObjectDefinitionHelper.php#L107-L111
229,344
slickframework/slick
src/Slick/Di/Definition/Helper/ObjectDefinitionHelper.php
ObjectDefinitionHelper.property
public function property($name, $value) { $this->_properties[$name] = new PropertyInjection($name, $value); return $this; }
php
public function property($name, $value) { $this->_properties[$name] = new PropertyInjection($name, $value); return $this; }
[ "public", "function", "property", "(", "$", "name", ",", "$", "value", ")", "{", "$", "this", "->", "_properties", "[", "$", "name", "]", "=", "new", "PropertyInjection", "(", "$", "name", ",", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Defines a property injection @param string $name @param mixed $value @return ObjectDefinitionHelper
[ "Defines", "a", "property", "injection" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Di/Definition/Helper/ObjectDefinitionHelper.php#L121-L125
229,345
jacobstr/matura
lib/Runners/SuiteRunner.php
SuiteRunner.run
public function run() { $this->emit( 'suite.start', array( 'suite' => $this->suite, 'result_set' => $this->result_set ) ); $result = $this->captureAround(array($this, 'runGroup'), $this->suite, $this->suite); $this->emit( 'suite.complete', array( 'suite' => $this->suite, 'result' => $result, 'result_set' => $this->result_set ) ); if ($result->isFailure()) { $this->result_set->addResult($result); } }
php
public function run() { $this->emit( 'suite.start', array( 'suite' => $this->suite, 'result_set' => $this->result_set ) ); $result = $this->captureAround(array($this, 'runGroup'), $this->suite, $this->suite); $this->emit( 'suite.complete', array( 'suite' => $this->suite, 'result' => $result, 'result_set' => $this->result_set ) ); if ($result->isFailure()) { $this->result_set->addResult($result); } }
[ "public", "function", "run", "(", ")", "{", "$", "this", "->", "emit", "(", "'suite.start'", ",", "array", "(", "'suite'", "=>", "$", "this", "->", "suite", ",", "'result_set'", "=>", "$", "this", "->", "result_set", ")", ")", ";", "$", "result", "=", "$", "this", "->", "captureAround", "(", "array", "(", "$", "this", ",", "'runGroup'", ")", ",", "$", "this", "->", "suite", ",", "$", "this", "->", "suite", ")", ";", "$", "this", "->", "emit", "(", "'suite.complete'", ",", "array", "(", "'suite'", "=>", "$", "this", "->", "suite", ",", "'result'", "=>", "$", "result", ",", "'result_set'", "=>", "$", "this", "->", "result_set", ")", ")", ";", "if", "(", "$", "result", "->", "isFailure", "(", ")", ")", "{", "$", "this", "->", "result_set", "->", "addResult", "(", "$", "result", ")", ";", "}", "}" ]
Runs the Suite from start to finish.
[ "Runs", "the", "Suite", "from", "start", "to", "finish", "." ]
393e0f3676f502454cc6823cac8ce9cef2ea7bff
https://github.com/jacobstr/matura/blob/393e0f3676f502454cc6823cac8ce9cef2ea7bff/lib/Runners/SuiteRunner.php#L51-L75
229,346
jacobstr/matura
lib/Runners/SuiteRunner.php
SuiteRunner.isFiltered
protected function isFiltered(Block $block) { // Skip filtering on implicit Suite block. if ($block instanceof Suite) { return false; } $options = &$this->options; $isFiltered = function ($block) use (&$options) { $filtered = false; if ($options['grep']) { $filtered = $filtered || preg_match($options['grep'], $block->path(0)) === 0; } if ($options['except']) { $filtered = $filtered || preg_match($options['except'], $block->path(0)) === 1; } return $filtered; }; // Code smell. Consider moving this responsibility to the blocks. if ($block instanceof TestMethod) { return $isFiltered($block); } else { foreach ($block->tests() as $test) { if ($isFiltered($test) === false) { return false; } } foreach ($block->describes() as $describe) { if ($this->isFiltered($describe) === false) { return false; } } return true; } }
php
protected function isFiltered(Block $block) { // Skip filtering on implicit Suite block. if ($block instanceof Suite) { return false; } $options = &$this->options; $isFiltered = function ($block) use (&$options) { $filtered = false; if ($options['grep']) { $filtered = $filtered || preg_match($options['grep'], $block->path(0)) === 0; } if ($options['except']) { $filtered = $filtered || preg_match($options['except'], $block->path(0)) === 1; } return $filtered; }; // Code smell. Consider moving this responsibility to the blocks. if ($block instanceof TestMethod) { return $isFiltered($block); } else { foreach ($block->tests() as $test) { if ($isFiltered($test) === false) { return false; } } foreach ($block->describes() as $describe) { if ($this->isFiltered($describe) === false) { return false; } } return true; } }
[ "protected", "function", "isFiltered", "(", "Block", "$", "block", ")", "{", "// Skip filtering on implicit Suite block.", "if", "(", "$", "block", "instanceof", "Suite", ")", "{", "return", "false", ";", "}", "$", "options", "=", "&", "$", "this", "->", "options", ";", "$", "isFiltered", "=", "function", "(", "$", "block", ")", "use", "(", "&", "$", "options", ")", "{", "$", "filtered", "=", "false", ";", "if", "(", "$", "options", "[", "'grep'", "]", ")", "{", "$", "filtered", "=", "$", "filtered", "||", "preg_match", "(", "$", "options", "[", "'grep'", "]", ",", "$", "block", "->", "path", "(", "0", ")", ")", "===", "0", ";", "}", "if", "(", "$", "options", "[", "'except'", "]", ")", "{", "$", "filtered", "=", "$", "filtered", "||", "preg_match", "(", "$", "options", "[", "'except'", "]", ",", "$", "block", "->", "path", "(", "0", ")", ")", "===", "1", ";", "}", "return", "$", "filtered", ";", "}", ";", "// Code smell. Consider moving this responsibility to the blocks.", "if", "(", "$", "block", "instanceof", "TestMethod", ")", "{", "return", "$", "isFiltered", "(", "$", "block", ")", ";", "}", "else", "{", "foreach", "(", "$", "block", "->", "tests", "(", ")", "as", "$", "test", ")", "{", "if", "(", "$", "isFiltered", "(", "$", "test", ")", "===", "false", ")", "{", "return", "false", ";", "}", "}", "foreach", "(", "$", "block", "->", "describes", "(", ")", "as", "$", "describe", ")", "{", "if", "(", "$", "this", "->", "isFiltered", "(", "$", "describe", ")", "===", "false", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "}" ]
Checks if the block or any of it's descendants match our grep filter or do not match our except filter. Descendants are checked in order to retain a test even it's parent block path does not match.
[ "Checks", "if", "the", "block", "or", "any", "of", "it", "s", "descendants", "match", "our", "grep", "filter", "or", "do", "not", "match", "our", "except", "filter", "." ]
393e0f3676f502454cc6823cac8ce9cef2ea7bff
https://github.com/jacobstr/matura/blob/393e0f3676f502454cc6823cac8ce9cef2ea7bff/lib/Runners/SuiteRunner.php#L207-L248
229,347
Danzabar/phalcon-cli
src/Format/Colors.php
Colors.getForeground
public function getForeground($name) { if (array_key_exists($name, $this->foreground)) { return $this->foreground[$name]; } return false; }
php
public function getForeground($name) { if (array_key_exists($name, $this->foreground)) { return $this->foreground[$name]; } return false; }
[ "public", "function", "getForeground", "(", "$", "name", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "foreground", ")", ")", "{", "return", "$", "this", "->", "foreground", "[", "$", "name", "]", ";", "}", "return", "false", ";", "}" ]
Gets a foreground color code by its name @return void
[ "Gets", "a", "foreground", "color", "code", "by", "its", "name" ]
0d6293d5d899158705f8e3a31886d176e595ee38
https://github.com/Danzabar/phalcon-cli/blob/0d6293d5d899158705f8e3a31886d176e595ee38/src/Format/Colors.php#L46-L53
229,348
Danzabar/phalcon-cli
src/Format/Colors.php
Colors.getBackground
public function getBackground($name) { if (array_key_exists($name, $this->background)) { return $this->background[$name]; } return false; }
php
public function getBackground($name) { if (array_key_exists($name, $this->background)) { return $this->background[$name]; } return false; }
[ "public", "function", "getBackground", "(", "$", "name", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "background", ")", ")", "{", "return", "$", "this", "->", "background", "[", "$", "name", "]", ";", "}", "return", "false", ";", "}" ]
Gets a background color code by its name @return void
[ "Gets", "a", "background", "color", "code", "by", "its", "name" ]
0d6293d5d899158705f8e3a31886d176e595ee38
https://github.com/Danzabar/phalcon-cli/blob/0d6293d5d899158705f8e3a31886d176e595ee38/src/Format/Colors.php#L60-L67
229,349
PrestaShop/decimal
src/Operation/Division.php
Division.compute
public function compute(DecimalNumber $a, DecimalNumber $b, $precision = self::DEFAULT_PRECISION) { if (function_exists('bcdiv')) { return $this->computeUsingBcMath($a, $b, $precision); } return $this->computeWithoutBcMath($a, $b, $precision); }
php
public function compute(DecimalNumber $a, DecimalNumber $b, $precision = self::DEFAULT_PRECISION) { if (function_exists('bcdiv')) { return $this->computeUsingBcMath($a, $b, $precision); } return $this->computeWithoutBcMath($a, $b, $precision); }
[ "public", "function", "compute", "(", "DecimalNumber", "$", "a", ",", "DecimalNumber", "$", "b", ",", "$", "precision", "=", "self", "::", "DEFAULT_PRECISION", ")", "{", "if", "(", "function_exists", "(", "'bcdiv'", ")", ")", "{", "return", "$", "this", "->", "computeUsingBcMath", "(", "$", "a", ",", "$", "b", ",", "$", "precision", ")", ";", "}", "return", "$", "this", "->", "computeWithoutBcMath", "(", "$", "a", ",", "$", "b", ",", "$", "precision", ")", ";", "}" ]
Performs the division. A target maximum precision is required in order to handle potential infinite number of decimals (e.g. 1/3 = 0.3333333...). If the division yields more decimal positions than the requested precision, the remaining decimals are truncated, with **no rounding**. @param DecimalNumber $a Dividend @param DecimalNumber $b Divisor @param int $precision Maximum decimal precision @return DecimalNumber Result of the division @throws DivisionByZeroException
[ "Performs", "the", "division", "." ]
42e9bc8c2ec533dc2a247f9321b8f3ed55c5341f
https://github.com/PrestaShop/decimal/blob/42e9bc8c2ec533dc2a247f9321b8f3ed55c5341f/src/Operation/Division.php#L37-L44
229,350
PrestaShop/decimal
src/Operation/Division.php
Division.computeUsingBcMath
public function computeUsingBcMath(DecimalNumber $a, DecimalNumber $b, $precision = self::DEFAULT_PRECISION) { if ((string) $b === '0') { throw new DivisionByZeroException(); } return new DecimalNumber((string) bcdiv($a, $b, $precision)); }
php
public function computeUsingBcMath(DecimalNumber $a, DecimalNumber $b, $precision = self::DEFAULT_PRECISION) { if ((string) $b === '0') { throw new DivisionByZeroException(); } return new DecimalNumber((string) bcdiv($a, $b, $precision)); }
[ "public", "function", "computeUsingBcMath", "(", "DecimalNumber", "$", "a", ",", "DecimalNumber", "$", "b", ",", "$", "precision", "=", "self", "::", "DEFAULT_PRECISION", ")", "{", "if", "(", "(", "string", ")", "$", "b", "===", "'0'", ")", "{", "throw", "new", "DivisionByZeroException", "(", ")", ";", "}", "return", "new", "DecimalNumber", "(", "(", "string", ")", "bcdiv", "(", "$", "a", ",", "$", "b", ",", "$", "precision", ")", ")", ";", "}" ]
Performs the division using BC Math @param DecimalNumber $a Dividend @param DecimalNumber $b Divisor @param int $precision Maximum decimal precision @return DecimalNumber Result of the division @throws DivisionByZeroException
[ "Performs", "the", "division", "using", "BC", "Math" ]
42e9bc8c2ec533dc2a247f9321b8f3ed55c5341f
https://github.com/PrestaShop/decimal/blob/42e9bc8c2ec533dc2a247f9321b8f3ed55c5341f/src/Operation/Division.php#L56-L63
229,351
PrestaShop/decimal
src/Operation/Division.php
Division.computeWithoutBcMath
public function computeWithoutBcMath(DecimalNumber $a, DecimalNumber $b, $precision = self::DEFAULT_PRECISION) { $bString = (string) $b; if ('0' === $bString) { throw new DivisionByZeroException(); } $aString = (string) $a; // 0 as dividend always yields 0 if ('0' === $aString) { return $a; } // 1 as divisor always yields the dividend if ('1' === $bString) { return $a; } // -1 as divisor always yields the the inverted dividend if ('-1' === $bString) { return $a->invert(); } // if dividend and divisor are equal, the result is always 1 if ($a->equals($b)) { return new DecimalNumber('1'); } $aPrecision = $a->getPrecision(); $bPrecision = $b->getPrecision(); $maxPrecision = max($aPrecision, $bPrecision); if ($maxPrecision > 0) { // make $a and $b integers by multiplying both by 10^(maximum number of decimals) $a = $a->toMagnitude($maxPrecision); $b = $b->toMagnitude($maxPrecision); } $result = $this->integerDivision($a, $b, max($precision, $aPrecision)); return $result; }
php
public function computeWithoutBcMath(DecimalNumber $a, DecimalNumber $b, $precision = self::DEFAULT_PRECISION) { $bString = (string) $b; if ('0' === $bString) { throw new DivisionByZeroException(); } $aString = (string) $a; // 0 as dividend always yields 0 if ('0' === $aString) { return $a; } // 1 as divisor always yields the dividend if ('1' === $bString) { return $a; } // -1 as divisor always yields the the inverted dividend if ('-1' === $bString) { return $a->invert(); } // if dividend and divisor are equal, the result is always 1 if ($a->equals($b)) { return new DecimalNumber('1'); } $aPrecision = $a->getPrecision(); $bPrecision = $b->getPrecision(); $maxPrecision = max($aPrecision, $bPrecision); if ($maxPrecision > 0) { // make $a and $b integers by multiplying both by 10^(maximum number of decimals) $a = $a->toMagnitude($maxPrecision); $b = $b->toMagnitude($maxPrecision); } $result = $this->integerDivision($a, $b, max($precision, $aPrecision)); return $result; }
[ "public", "function", "computeWithoutBcMath", "(", "DecimalNumber", "$", "a", ",", "DecimalNumber", "$", "b", ",", "$", "precision", "=", "self", "::", "DEFAULT_PRECISION", ")", "{", "$", "bString", "=", "(", "string", ")", "$", "b", ";", "if", "(", "'0'", "===", "$", "bString", ")", "{", "throw", "new", "DivisionByZeroException", "(", ")", ";", "}", "$", "aString", "=", "(", "string", ")", "$", "a", ";", "// 0 as dividend always yields 0", "if", "(", "'0'", "===", "$", "aString", ")", "{", "return", "$", "a", ";", "}", "// 1 as divisor always yields the dividend", "if", "(", "'1'", "===", "$", "bString", ")", "{", "return", "$", "a", ";", "}", "// -1 as divisor always yields the the inverted dividend", "if", "(", "'-1'", "===", "$", "bString", ")", "{", "return", "$", "a", "->", "invert", "(", ")", ";", "}", "// if dividend and divisor are equal, the result is always 1", "if", "(", "$", "a", "->", "equals", "(", "$", "b", ")", ")", "{", "return", "new", "DecimalNumber", "(", "'1'", ")", ";", "}", "$", "aPrecision", "=", "$", "a", "->", "getPrecision", "(", ")", ";", "$", "bPrecision", "=", "$", "b", "->", "getPrecision", "(", ")", ";", "$", "maxPrecision", "=", "max", "(", "$", "aPrecision", ",", "$", "bPrecision", ")", ";", "if", "(", "$", "maxPrecision", ">", "0", ")", "{", "// make $a and $b integers by multiplying both by 10^(maximum number of decimals)", "$", "a", "=", "$", "a", "->", "toMagnitude", "(", "$", "maxPrecision", ")", ";", "$", "b", "=", "$", "b", "->", "toMagnitude", "(", "$", "maxPrecision", ")", ";", "}", "$", "result", "=", "$", "this", "->", "integerDivision", "(", "$", "a", ",", "$", "b", ",", "max", "(", "$", "precision", ",", "$", "aPrecision", ")", ")", ";", "return", "$", "result", ";", "}" ]
Performs the division without BC Math @param DecimalNumber $a Dividend @param DecimalNumber $b Divisor @param int $precision Maximum decimal precision @return DecimalNumber Result of the division @throws DivisionByZeroException
[ "Performs", "the", "division", "without", "BC", "Math" ]
42e9bc8c2ec533dc2a247f9321b8f3ed55c5341f
https://github.com/PrestaShop/decimal/blob/42e9bc8c2ec533dc2a247f9321b8f3ed55c5341f/src/Operation/Division.php#L75-L118
229,352
PrestaShop/decimal
src/Operation/Division.php
Division.integerDivision
private function integerDivision(DecimalNumber $a, DecimalNumber $b, $precision) { $dividend = $a->getCoefficient(); $divisor = new DecimalNumber($b->getCoefficient()); $dividendLength = strlen($dividend); $result = ''; $exponent = 0; $currentSequence = ''; for ($i = 0; $i < $dividendLength; $i++) { // append digits until we get a number big enough to divide $currentSequence .= $dividend[$i]; if ($currentSequence < $divisor) { if (!empty($result)) { $result .= '0'; } } else { // subtract divisor as many times as we can $remainder = new DecimalNumber($currentSequence); $multiple = 0; do { $multiple++; $remainder = $remainder->minus($divisor); } while ($remainder->isGreaterOrEqualThan($divisor)); $result .= (string) $multiple; // reset sequence to the reminder $currentSequence = (string) $remainder; } // add up to $precision decimals if ($currentSequence > 0 && $i === $dividendLength - 1 && $precision > 0) { // "borrow" up to $precision digits --$precision; $dividend .= '0'; $dividendLength++; $exponent++; } } $sign = ($a->isNegative() xor $b->isNegative()) ? '-' : ''; return new DecimalNumber($sign . $result, $exponent); }
php
private function integerDivision(DecimalNumber $a, DecimalNumber $b, $precision) { $dividend = $a->getCoefficient(); $divisor = new DecimalNumber($b->getCoefficient()); $dividendLength = strlen($dividend); $result = ''; $exponent = 0; $currentSequence = ''; for ($i = 0; $i < $dividendLength; $i++) { // append digits until we get a number big enough to divide $currentSequence .= $dividend[$i]; if ($currentSequence < $divisor) { if (!empty($result)) { $result .= '0'; } } else { // subtract divisor as many times as we can $remainder = new DecimalNumber($currentSequence); $multiple = 0; do { $multiple++; $remainder = $remainder->minus($divisor); } while ($remainder->isGreaterOrEqualThan($divisor)); $result .= (string) $multiple; // reset sequence to the reminder $currentSequence = (string) $remainder; } // add up to $precision decimals if ($currentSequence > 0 && $i === $dividendLength - 1 && $precision > 0) { // "borrow" up to $precision digits --$precision; $dividend .= '0'; $dividendLength++; $exponent++; } } $sign = ($a->isNegative() xor $b->isNegative()) ? '-' : ''; return new DecimalNumber($sign . $result, $exponent); }
[ "private", "function", "integerDivision", "(", "DecimalNumber", "$", "a", ",", "DecimalNumber", "$", "b", ",", "$", "precision", ")", "{", "$", "dividend", "=", "$", "a", "->", "getCoefficient", "(", ")", ";", "$", "divisor", "=", "new", "DecimalNumber", "(", "$", "b", "->", "getCoefficient", "(", ")", ")", ";", "$", "dividendLength", "=", "strlen", "(", "$", "dividend", ")", ";", "$", "result", "=", "''", ";", "$", "exponent", "=", "0", ";", "$", "currentSequence", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "dividendLength", ";", "$", "i", "++", ")", "{", "// append digits until we get a number big enough to divide", "$", "currentSequence", ".=", "$", "dividend", "[", "$", "i", "]", ";", "if", "(", "$", "currentSequence", "<", "$", "divisor", ")", "{", "if", "(", "!", "empty", "(", "$", "result", ")", ")", "{", "$", "result", ".=", "'0'", ";", "}", "}", "else", "{", "// subtract divisor as many times as we can", "$", "remainder", "=", "new", "DecimalNumber", "(", "$", "currentSequence", ")", ";", "$", "multiple", "=", "0", ";", "do", "{", "$", "multiple", "++", ";", "$", "remainder", "=", "$", "remainder", "->", "minus", "(", "$", "divisor", ")", ";", "}", "while", "(", "$", "remainder", "->", "isGreaterOrEqualThan", "(", "$", "divisor", ")", ")", ";", "$", "result", ".=", "(", "string", ")", "$", "multiple", ";", "// reset sequence to the reminder", "$", "currentSequence", "=", "(", "string", ")", "$", "remainder", ";", "}", "// add up to $precision decimals", "if", "(", "$", "currentSequence", ">", "0", "&&", "$", "i", "===", "$", "dividendLength", "-", "1", "&&", "$", "precision", ">", "0", ")", "{", "// \"borrow\" up to $precision digits", "--", "$", "precision", ";", "$", "dividend", ".=", "'0'", ";", "$", "dividendLength", "++", ";", "$", "exponent", "++", ";", "}", "}", "$", "sign", "=", "(", "$", "a", "->", "isNegative", "(", ")", "xor", "$", "b", "->", "isNegative", "(", ")", ")", "?", "'-'", ":", "''", ";", "return", "new", "DecimalNumber", "(", "$", "sign", ".", "$", "result", ",", "$", "exponent", ")", ";", "}" ]
Computes the division between two integer DecimalNumbers @param DecimalNumber $a Dividend @param DecimalNumber $b Divisor @param int $precision Maximum number of decimals to try @return DecimalNumber
[ "Computes", "the", "division", "between", "two", "integer", "DecimalNumbers" ]
42e9bc8c2ec533dc2a247f9321b8f3ed55c5341f
https://github.com/PrestaShop/decimal/blob/42e9bc8c2ec533dc2a247f9321b8f3ed55c5341f/src/Operation/Division.php#L129-L174
229,353
laravelcity/laravel-categories
src/Models/Categories.php
Categories.categoryExist
function categoryExist($title){ if(self::where('title',$title)->where('model_type',$this->modelType)->first()) return true; return false; }
php
function categoryExist($title){ if(self::where('title',$title)->where('model_type',$this->modelType)->first()) return true; return false; }
[ "function", "categoryExist", "(", "$", "title", ")", "{", "if", "(", "self", "::", "where", "(", "'title'", ",", "$", "title", ")", "->", "where", "(", "'model_type'", ",", "$", "this", "->", "modelType", ")", "->", "first", "(", ")", ")", "return", "true", ";", "return", "false", ";", "}" ]
check category exist @param $title => string @return bool
[ "check", "category", "exist" ]
b5c1baf8cbb51377fef090fc9ddaa0946bf42a68
https://github.com/laravelcity/laravel-categories/blob/b5c1baf8cbb51377fef090fc9ddaa0946bf42a68/src/Models/Categories.php#L56-L61
229,354
laravelcity/laravel-categories
src/Models/Categories.php
Categories.child
function child($depth=null){ if($depth==null) return self::where('parent',$this->attributes['id'])->get(); else return self::where('parent',$this->attributes['id'])->where('depth',$depth)->get(); }
php
function child($depth=null){ if($depth==null) return self::where('parent',$this->attributes['id'])->get(); else return self::where('parent',$this->attributes['id'])->where('depth',$depth)->get(); }
[ "function", "child", "(", "$", "depth", "=", "null", ")", "{", "if", "(", "$", "depth", "==", "null", ")", "return", "self", "::", "where", "(", "'parent'", ",", "$", "this", "->", "attributes", "[", "'id'", "]", ")", "->", "get", "(", ")", ";", "else", "return", "self", "::", "where", "(", "'parent'", ",", "$", "this", "->", "attributes", "[", "'id'", "]", ")", "->", "where", "(", "'depth'", ",", "$", "depth", ")", "->", "get", "(", ")", ";", "}" ]
get category child with depth @params $depth @return Collection
[ "get", "category", "child", "with", "depth" ]
b5c1baf8cbb51377fef090fc9ddaa0946bf42a68
https://github.com/laravelcity/laravel-categories/blob/b5c1baf8cbb51377fef090fc9ddaa0946bf42a68/src/Models/Categories.php#L68-L73
229,355
laravelcity/laravel-categories
src/Models/Categories.php
Categories.getCategory
function getCategory($id){ if(is_numeric($id)) $model=self::where('id',$id)->select(); else $model=self::where('slug',$id)->select(); $model->where('model_type',$this->modelType); return $model->first(); }
php
function getCategory($id){ if(is_numeric($id)) $model=self::where('id',$id)->select(); else $model=self::where('slug',$id)->select(); $model->where('model_type',$this->modelType); return $model->first(); }
[ "function", "getCategory", "(", "$", "id", ")", "{", "if", "(", "is_numeric", "(", "$", "id", ")", ")", "$", "model", "=", "self", "::", "where", "(", "'id'", ",", "$", "id", ")", "->", "select", "(", ")", ";", "else", "$", "model", "=", "self", "::", "where", "(", "'slug'", ",", "$", "id", ")", "->", "select", "(", ")", ";", "$", "model", "->", "where", "(", "'model_type'", ",", "$", "this", "->", "modelType", ")", ";", "return", "$", "model", "->", "first", "(", ")", ";", "}" ]
get category with id @param $id @param $type @return Categories
[ "get", "category", "with", "id" ]
b5c1baf8cbb51377fef090fc9ddaa0946bf42a68
https://github.com/laravelcity/laravel-categories/blob/b5c1baf8cbb51377fef090fc9ddaa0946bf42a68/src/Models/Categories.php#L97-L106
229,356
slickframework/slick
src/Slick/Database/Sql/Select.php
Select.join
public function join( $table, $on, $fields = ['*'], $alias = null, $type = Join::JOIN_LEFT) { $join = new Join($table, $on, $fields, $type); if (!is_null($alias)) { $join->setAlias($alias); } $this->_joins[] = $join; return $this; }
php
public function join( $table, $on, $fields = ['*'], $alias = null, $type = Join::JOIN_LEFT) { $join = new Join($table, $on, $fields, $type); if (!is_null($alias)) { $join->setAlias($alias); } $this->_joins[] = $join; return $this; }
[ "public", "function", "join", "(", "$", "table", ",", "$", "on", ",", "$", "fields", "=", "[", "'*'", "]", ",", "$", "alias", "=", "null", ",", "$", "type", "=", "Join", "::", "JOIN_LEFT", ")", "{", "$", "join", "=", "new", "Join", "(", "$", "table", ",", "$", "on", ",", "$", "fields", ",", "$", "type", ")", ";", "if", "(", "!", "is_null", "(", "$", "alias", ")", ")", "{", "$", "join", "->", "setAlias", "(", "$", "alias", ")", ";", "}", "$", "this", "->", "_joins", "[", "]", "=", "$", "join", ";", "return", "$", "this", ";", "}" ]
Adds a join table to the select query If fields is null it will not set any field to the select field list. if it is a string it will be passed to the select field list as it is. If you pass a list of field names they will be prefixed with the alias if is set or the table name, to avoid the ambiguous fields name @param string $table @param string $on @param string|null|string[] $fields @param string $alias @param string $type @return Select
[ "Adds", "a", "join", "table", "to", "the", "select", "query" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Sql/Select.php#L194-L203
229,357
slickframework/slick
src/Slick/Database/Sql/Select.php
Select.limit
public function limit($rows, $offset = 0) { $this->_limit = $rows; $this->_offset = $offset; return $this; }
php
public function limit($rows, $offset = 0) { $this->_limit = $rows; $this->_offset = $offset; return $this; }
[ "public", "function", "limit", "(", "$", "rows", ",", "$", "offset", "=", "0", ")", "{", "$", "this", "->", "_limit", "=", "$", "rows", ";", "$", "this", "->", "_offset", "=", "$", "offset", ";", "return", "$", "this", ";", "}" ]
Sets query limit and offset @param int $rows @param int $offset @return Select
[ "Sets", "query", "limit", "and", "offset" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Sql/Select.php#L226-L231
229,358
mjacobus/php-query-builder
lib/PO/QueryBuilder/Statements/ConditionalStatement.php
ConditionalStatement.innerJoin
public function innerJoin($join, $on = null) { $this->getJoins()->innerJoin($join, $on); return $this; }
php
public function innerJoin($join, $on = null) { $this->getJoins()->innerJoin($join, $on); return $this; }
[ "public", "function", "innerJoin", "(", "$", "join", ",", "$", "on", "=", "null", ")", "{", "$", "this", "->", "getJoins", "(", ")", "->", "innerJoin", "(", "$", "join", ",", "$", "on", ")", ";", "return", "$", "this", ";", "}" ]
Adds INNER JOIN to the query @param string $join @param string $on @return self
[ "Adds", "INNER", "JOIN", "to", "the", "query" ]
eb7a90ae3bc433659306807535b39f12ce4dfd9f
https://github.com/mjacobus/php-query-builder/blob/eb7a90ae3bc433659306807535b39f12ce4dfd9f/lib/PO/QueryBuilder/Statements/ConditionalStatement.php#L106-L111
229,359
mjacobus/php-query-builder
lib/PO/QueryBuilder/Statements/ConditionalStatement.php
ConditionalStatement.leftJoin
public function leftJoin($join, $on = null) { $this->getJoins()->leftJoin($join, $on); return $this; }
php
public function leftJoin($join, $on = null) { $this->getJoins()->leftJoin($join, $on); return $this; }
[ "public", "function", "leftJoin", "(", "$", "join", ",", "$", "on", "=", "null", ")", "{", "$", "this", "->", "getJoins", "(", ")", "->", "leftJoin", "(", "$", "join", ",", "$", "on", ")", ";", "return", "$", "this", ";", "}" ]
Adds LEFT JOIN to the query @param string $join @param string $on @return self
[ "Adds", "LEFT", "JOIN", "to", "the", "query" ]
eb7a90ae3bc433659306807535b39f12ce4dfd9f
https://github.com/mjacobus/php-query-builder/blob/eb7a90ae3bc433659306807535b39f12ce4dfd9f/lib/PO/QueryBuilder/Statements/ConditionalStatement.php#L120-L125
229,360
mjacobus/php-query-builder
lib/PO/QueryBuilder/Statements/ConditionalStatement.php
ConditionalStatement.where
public function where($conditions, $value = null, $operator = '=') { if (is_array($conditions)) { $this->getWhere()->addConditions($conditions); } else { $this->getWhere()->addCondition($conditions, $value, $operator); } return $this; }
php
public function where($conditions, $value = null, $operator = '=') { if (is_array($conditions)) { $this->getWhere()->addConditions($conditions); } else { $this->getWhere()->addCondition($conditions, $value, $operator); } return $this; }
[ "public", "function", "where", "(", "$", "conditions", ",", "$", "value", "=", "null", ",", "$", "operator", "=", "'='", ")", "{", "if", "(", "is_array", "(", "$", "conditions", ")", ")", "{", "$", "this", "->", "getWhere", "(", ")", "->", "addConditions", "(", "$", "conditions", ")", ";", "}", "else", "{", "$", "this", "->", "getWhere", "(", ")", "->", "addCondition", "(", "$", "conditions", ",", "$", "value", ",", "$", "operator", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add conditions I.E. $this->where('a = 1') ->where('a', 'b') ->where('a', 'x', '!=') ->where(array( 'foo' => 'bar', 'foobar' => 'foo' )); @param array|string $conditions @param string $value @param string $operator @return PO\QueryBuilder
[ "Add", "conditions", "I", ".", "E", "." ]
eb7a90ae3bc433659306807535b39f12ce4dfd9f
https://github.com/mjacobus/php-query-builder/blob/eb7a90ae3bc433659306807535b39f12ce4dfd9f/lib/PO/QueryBuilder/Statements/ConditionalStatement.php#L144-L153
229,361
mjacobus/php-query-builder
lib/PO/QueryBuilder/Statements/ConditionalStatement.php
ConditionalStatement.limit
public function limit($limit, $offset = null) { if ($offset) { $this->getLimit()->setParams(array($limit, $offset)); } else { $this->getLimit()->setParams(array($limit)); } return $this; }
php
public function limit($limit, $offset = null) { if ($offset) { $this->getLimit()->setParams(array($limit, $offset)); } else { $this->getLimit()->setParams(array($limit)); } return $this; }
[ "public", "function", "limit", "(", "$", "limit", ",", "$", "offset", "=", "null", ")", "{", "if", "(", "$", "offset", ")", "{", "$", "this", "->", "getLimit", "(", ")", "->", "setParams", "(", "array", "(", "$", "limit", ",", "$", "offset", ")", ")", ";", "}", "else", "{", "$", "this", "->", "getLimit", "(", ")", "->", "setParams", "(", "array", "(", "$", "limit", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add limit I.E. @param int $limit @param int $offset @return self
[ "Add", "limit", "I", ".", "E", "." ]
eb7a90ae3bc433659306807535b39f12ce4dfd9f
https://github.com/mjacobus/php-query-builder/blob/eb7a90ae3bc433659306807535b39f12ce4dfd9f/lib/PO/QueryBuilder/Statements/ConditionalStatement.php#L179-L188
229,362
slickframework/slick
src/Slick/Database/Sql/WhereMethods.php
WhereMethods.getWhereStatement
public function getWhereStatement() { if (empty($this->where)) { return false; } $this->where[0]['operation'] = null; $str = ''; foreach ($this->where as $clause) { $str .= trim("{$clause['operation']} {$clause['condition']}"); $str .= " "; } return trim($str); }
php
public function getWhereStatement() { if (empty($this->where)) { return false; } $this->where[0]['operation'] = null; $str = ''; foreach ($this->where as $clause) { $str .= trim("{$clause['operation']} {$clause['condition']}"); $str .= " "; } return trim($str); }
[ "public", "function", "getWhereStatement", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "where", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "where", "[", "0", "]", "[", "'operation'", "]", "=", "null", ";", "$", "str", "=", "''", ";", "foreach", "(", "$", "this", "->", "where", "as", "$", "clause", ")", "{", "$", "str", ".=", "trim", "(", "\"{$clause['operation']} {$clause['condition']}\"", ")", ";", "$", "str", ".=", "\" \"", ";", "}", "return", "trim", "(", "$", "str", ")", ";", "}" ]
Returns the where statement for sql @return bool|string
[ "Returns", "the", "where", "statement", "for", "sql" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Sql/WhereMethods.php#L130-L143
229,363
slickframework/slick
src/Slick/Database/Query/Sql/Dialect/Standard/Select.php
Select.getStatement
public function getStatement() { return $this->_fixBlanks( trim( str_replace( array( '<fields>', '<joinFields>', '<tableName>', '<joins>', '<where>', '<groupBy>', '<orderBy>', '<limit>' ), array( $this->getFields(), $this->getJoinFields(), $this->_sql->getTableName(), $this->getJoins(), $this->getWhere(), $this->getGroupBy(), $this->getOrderBy(), $this->getLimit() ), $this->_select ) ) ); }
php
public function getStatement() { return $this->_fixBlanks( trim( str_replace( array( '<fields>', '<joinFields>', '<tableName>', '<joins>', '<where>', '<groupBy>', '<orderBy>', '<limit>' ), array( $this->getFields(), $this->getJoinFields(), $this->_sql->getTableName(), $this->getJoins(), $this->getWhere(), $this->getGroupBy(), $this->getOrderBy(), $this->getLimit() ), $this->_select ) ) ); }
[ "public", "function", "getStatement", "(", ")", "{", "return", "$", "this", "->", "_fixBlanks", "(", "trim", "(", "str_replace", "(", "array", "(", "'<fields>'", ",", "'<joinFields>'", ",", "'<tableName>'", ",", "'<joins>'", ",", "'<where>'", ",", "'<groupBy>'", ",", "'<orderBy>'", ",", "'<limit>'", ")", ",", "array", "(", "$", "this", "->", "getFields", "(", ")", ",", "$", "this", "->", "getJoinFields", "(", ")", ",", "$", "this", "->", "_sql", "->", "getTableName", "(", ")", ",", "$", "this", "->", "getJoins", "(", ")", ",", "$", "this", "->", "getWhere", "(", ")", ",", "$", "this", "->", "getGroupBy", "(", ")", ",", "$", "this", "->", "getOrderBy", "(", ")", ",", "$", "this", "->", "getLimit", "(", ")", ")", ",", "$", "this", "->", "_select", ")", ")", ")", ";", "}" ]
Returns the SQL query string for current Select SQL Object @return String The SQL query string
[ "Returns", "the", "SQL", "query", "string", "for", "current", "Select", "SQL", "Object" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Query/Sql/Dialect/Standard/Select.php#L48-L72
229,364
slickframework/slick
src/Slick/Database/Query/Sql/Dialect/Standard/Select.php
Select.getFields
public function getFields() { $joins = $this->_sql->getJoins(); $fields = $this->_sql->getFields(); if (!is_array($fields)) { return $fields; } if (count($joins) > 0 && $this->_sql->prefixTableName) { $table = $this->_sql->getTableName(); foreach ($fields as $key => $field) { $fields[$key] = "{$table}.{$field}"; } } return implode(', ', $fields); }
php
public function getFields() { $joins = $this->_sql->getJoins(); $fields = $this->_sql->getFields(); if (!is_array($fields)) { return $fields; } if (count($joins) > 0 && $this->_sql->prefixTableName) { $table = $this->_sql->getTableName(); foreach ($fields as $key => $field) { $fields[$key] = "{$table}.{$field}"; } } return implode(', ', $fields); }
[ "public", "function", "getFields", "(", ")", "{", "$", "joins", "=", "$", "this", "->", "_sql", "->", "getJoins", "(", ")", ";", "$", "fields", "=", "$", "this", "->", "_sql", "->", "getFields", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "fields", ")", ")", "{", "return", "$", "fields", ";", "}", "if", "(", "count", "(", "$", "joins", ")", ">", "0", "&&", "$", "this", "->", "_sql", "->", "prefixTableName", ")", "{", "$", "table", "=", "$", "this", "->", "_sql", "->", "getTableName", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "key", "=>", "$", "field", ")", "{", "$", "fields", "[", "$", "key", "]", "=", "\"{$table}.{$field}\"", ";", "}", "}", "return", "implode", "(", "', '", ",", "$", "fields", ")", ";", "}" ]
Returns the field list from Select object @return string The field list
[ "Returns", "the", "field", "list", "from", "Select", "object" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Query/Sql/Dialect/Standard/Select.php#L79-L96
229,365
slickframework/slick
src/Slick/Database/Query/Sql/Dialect/Standard/Select.php
Select.getJoinFields
public function getJoinFields() { $fields = null; $tmpFields = array(); $joins = $this->_sql->getJoins(); if (count($joins) > 0) { foreach ($joins as $join) { $tmpJoin = array(); foreach ($join['fields'] as $field) { $tmpJoin[] = "{$join['table']}.{$field}"; } $str = implode(', ', $tmpJoin); if (strlen($str) > 1) { $tmpFields[] = implode(', ', $tmpJoin); } } $fields = ', '. implode(', ', $tmpFields); if (trim($fields) == ',') $fields = null; } return $fields; }
php
public function getJoinFields() { $fields = null; $tmpFields = array(); $joins = $this->_sql->getJoins(); if (count($joins) > 0) { foreach ($joins as $join) { $tmpJoin = array(); foreach ($join['fields'] as $field) { $tmpJoin[] = "{$join['table']}.{$field}"; } $str = implode(', ', $tmpJoin); if (strlen($str) > 1) { $tmpFields[] = implode(', ', $tmpJoin); } } $fields = ', '. implode(', ', $tmpFields); if (trim($fields) == ',') $fields = null; } return $fields; }
[ "public", "function", "getJoinFields", "(", ")", "{", "$", "fields", "=", "null", ";", "$", "tmpFields", "=", "array", "(", ")", ";", "$", "joins", "=", "$", "this", "->", "_sql", "->", "getJoins", "(", ")", ";", "if", "(", "count", "(", "$", "joins", ")", ">", "0", ")", "{", "foreach", "(", "$", "joins", "as", "$", "join", ")", "{", "$", "tmpJoin", "=", "array", "(", ")", ";", "foreach", "(", "$", "join", "[", "'fields'", "]", "as", "$", "field", ")", "{", "$", "tmpJoin", "[", "]", "=", "\"{$join['table']}.{$field}\"", ";", "}", "$", "str", "=", "implode", "(", "', '", ",", "$", "tmpJoin", ")", ";", "if", "(", "strlen", "(", "$", "str", ")", ">", "1", ")", "{", "$", "tmpFields", "[", "]", "=", "implode", "(", "', '", ",", "$", "tmpJoin", ")", ";", "}", "}", "$", "fields", "=", "', '", ".", "implode", "(", "', '", ",", "$", "tmpFields", ")", ";", "if", "(", "trim", "(", "$", "fields", ")", "==", "','", ")", "$", "fields", "=", "null", ";", "}", "return", "$", "fields", ";", "}" ]
Returns the join fields for this query @return string The comma seperated field names
[ "Returns", "the", "join", "fields", "for", "this", "query" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Query/Sql/Dialect/Standard/Select.php#L103-L126
229,366
slickframework/slick
src/Slick/Database/Query/Sql/Dialect/Standard/Select.php
Select.getJoins
public function getJoins() { $template = "%s JOIN %s ON %s"; $joinsStr = null; $joins = $this->_sql->getJoins(); $tmpJoin = array(); if (count($joins) > 0) { foreach ($joins as $join) { $tmpJoin[] = sprintf( $template, $join['type'], $join['table'], $join['onClause'] ); } $joinsStr = implode(PHP_EOL, $tmpJoin); } return $joinsStr; }
php
public function getJoins() { $template = "%s JOIN %s ON %s"; $joinsStr = null; $joins = $this->_sql->getJoins(); $tmpJoin = array(); if (count($joins) > 0) { foreach ($joins as $join) { $tmpJoin[] = sprintf( $template, $join['type'], $join['table'], $join['onClause'] ); } $joinsStr = implode(PHP_EOL, $tmpJoin); } return $joinsStr; }
[ "public", "function", "getJoins", "(", ")", "{", "$", "template", "=", "\"%s JOIN %s ON %s\"", ";", "$", "joinsStr", "=", "null", ";", "$", "joins", "=", "$", "this", "->", "_sql", "->", "getJoins", "(", ")", ";", "$", "tmpJoin", "=", "array", "(", ")", ";", "if", "(", "count", "(", "$", "joins", ")", ">", "0", ")", "{", "foreach", "(", "$", "joins", "as", "$", "join", ")", "{", "$", "tmpJoin", "[", "]", "=", "sprintf", "(", "$", "template", ",", "$", "join", "[", "'type'", "]", ",", "$", "join", "[", "'table'", "]", ",", "$", "join", "[", "'onClause'", "]", ")", ";", "}", "$", "joinsStr", "=", "implode", "(", "PHP_EOL", ",", "$", "tmpJoin", ")", ";", "}", "return", "$", "joinsStr", ";", "}" ]
Returns the JOIN clauses for this query @return string The join clauses string
[ "Returns", "the", "JOIN", "clauses", "for", "this", "query" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Query/Sql/Dialect/Standard/Select.php#L133-L153
229,367
slickframework/slick
src/Slick/Database/Query/Sql/Dialect/Standard/Select.php
Select.getWhere
public function getWhere() { $template = "WHERE %s"; $where = null; if (count($this->_sql->conditions->predicates) > 0) { $where = trim( sprintf($template, $this->_sql->conditions->toString()) ); } return $where; }
php
public function getWhere() { $template = "WHERE %s"; $where = null; if (count($this->_sql->conditions->predicates) > 0) { $where = trim( sprintf($template, $this->_sql->conditions->toString()) ); } return $where; }
[ "public", "function", "getWhere", "(", ")", "{", "$", "template", "=", "\"WHERE %s\"", ";", "$", "where", "=", "null", ";", "if", "(", "count", "(", "$", "this", "->", "_sql", "->", "conditions", "->", "predicates", ")", ">", "0", ")", "{", "$", "where", "=", "trim", "(", "sprintf", "(", "$", "template", ",", "$", "this", "->", "_sql", "->", "conditions", "->", "toString", "(", ")", ")", ")", ";", "}", "return", "$", "where", ";", "}" ]
Returns the WHERE clause for this query @return string The where clause string
[ "Returns", "the", "WHERE", "clause", "for", "this", "query" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Query/Sql/Dialect/Standard/Select.php#L160-L171
229,368
slickframework/slick
src/Slick/Database/Query/Sql/Dialect/Standard/Select.php
Select.getOrderBy
public function getOrderBy() { $template = "ORDER BY %s"; $orderBy = null; if (!is_null($this->_sql->orderBy)) { $orderBy = trim(sprintf($template, $this->_sql->getOrderBy())); } return $orderBy; }
php
public function getOrderBy() { $template = "ORDER BY %s"; $orderBy = null; if (!is_null($this->_sql->orderBy)) { $orderBy = trim(sprintf($template, $this->_sql->getOrderBy())); } return $orderBy; }
[ "public", "function", "getOrderBy", "(", ")", "{", "$", "template", "=", "\"ORDER BY %s\"", ";", "$", "orderBy", "=", "null", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "_sql", "->", "orderBy", ")", ")", "{", "$", "orderBy", "=", "trim", "(", "sprintf", "(", "$", "template", ",", "$", "this", "->", "_sql", "->", "getOrderBy", "(", ")", ")", ")", ";", "}", "return", "$", "orderBy", ";", "}" ]
Returns the order by clause for this query @return string The order by clause string
[ "Returns", "the", "order", "by", "clause", "for", "this", "query" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Query/Sql/Dialect/Standard/Select.php#L178-L186
229,369
slickframework/slick
src/Slick/Database/Query/Sql/Dialect/Standard/Select.php
Select.getGroupBy
public function getGroupBy() { $template = "GROUP BY %s"; $groupBy = null; if (!is_null($this->_sql->groupBy)) { $groupBy = trim(sprintf($template, $this->_sql->getGroupBy())); } return $groupBy; }
php
public function getGroupBy() { $template = "GROUP BY %s"; $groupBy = null; if (!is_null($this->_sql->groupBy)) { $groupBy = trim(sprintf($template, $this->_sql->getGroupBy())); } return $groupBy; }
[ "public", "function", "getGroupBy", "(", ")", "{", "$", "template", "=", "\"GROUP BY %s\"", ";", "$", "groupBy", "=", "null", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "_sql", "->", "groupBy", ")", ")", "{", "$", "groupBy", "=", "trim", "(", "sprintf", "(", "$", "template", ",", "$", "this", "->", "_sql", "->", "getGroupBy", "(", ")", ")", ")", ";", "}", "return", "$", "groupBy", ";", "}" ]
Returns the group by clause for this query @return string The group by clause string
[ "Returns", "the", "group", "by", "clause", "for", "this", "query" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Query/Sql/Dialect/Standard/Select.php#L193-L201
229,370
slickframework/slick
src/Slick/Database/Query/Sql/Dialect/Standard/Select.php
Select._fixBlanks
protected function _fixBlanks($str) { $lines = explode(PHP_EOL, $str); $clean = array(); foreach ($lines as $line) { if (trim($line) != "") { $clean[] = $line; } } return implode(PHP_EOL, $clean); }
php
protected function _fixBlanks($str) { $lines = explode(PHP_EOL, $str); $clean = array(); foreach ($lines as $line) { if (trim($line) != "") { $clean[] = $line; } } return implode(PHP_EOL, $clean); }
[ "protected", "function", "_fixBlanks", "(", "$", "str", ")", "{", "$", "lines", "=", "explode", "(", "PHP_EOL", ",", "$", "str", ")", ";", "$", "clean", "=", "array", "(", ")", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "if", "(", "trim", "(", "$", "line", ")", "!=", "\"\"", ")", "{", "$", "clean", "[", "]", "=", "$", "line", ";", "}", "}", "return", "implode", "(", "PHP_EOL", ",", "$", "clean", ")", ";", "}" ]
Removes the blank lines in the query string @param string $str The query string to fix @return string The fixed query string.
[ "Removes", "the", "blank", "lines", "in", "the", "query", "string" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Database/Query/Sql/Dialect/Standard/Select.php#L227-L238
229,371
lcobucci/content-negotiation-middleware
src/UnformattedResponse.php
UnformattedResponse.withAttribute
public function withAttribute(string $name, $value): self { return new self( $this->decoratedResponse, $this->unformattedContent, [$name => $value] + $this->attributes ); }
php
public function withAttribute(string $name, $value): self { return new self( $this->decoratedResponse, $this->unformattedContent, [$name => $value] + $this->attributes ); }
[ "public", "function", "withAttribute", "(", "string", "$", "name", ",", "$", "value", ")", ":", "self", "{", "return", "new", "self", "(", "$", "this", "->", "decoratedResponse", ",", "$", "this", "->", "unformattedContent", ",", "[", "$", "name", "=>", "$", "value", "]", "+", "$", "this", "->", "attributes", ")", ";", "}" ]
Returns an instance with the specified attribute @param mixed $value
[ "Returns", "an", "instance", "with", "the", "specified", "attribute" ]
fdbe268786af4c59bbf82de92eab87a69855715b
https://github.com/lcobucci/content-negotiation-middleware/blob/fdbe268786af4c59bbf82de92eab87a69855715b/src/UnformattedResponse.php#L189-L196
229,372
slickframework/slick
src/Slick/Form/InputFilter/Input.php
Input.isValid
public function isValid() { $filtered = $this->getValue(); $valid = $this->getValidatorChain()->isValid($filtered); $this->_messages = $this->getValidatorChain()->getMessages(); return $valid; }
php
public function isValid() { $filtered = $this->getValue(); $valid = $this->getValidatorChain()->isValid($filtered); $this->_messages = $this->getValidatorChain()->getMessages(); return $valid; }
[ "public", "function", "isValid", "(", ")", "{", "$", "filtered", "=", "$", "this", "->", "getValue", "(", ")", ";", "$", "valid", "=", "$", "this", "->", "getValidatorChain", "(", ")", "->", "isValid", "(", "$", "filtered", ")", ";", "$", "this", "->", "_messages", "=", "$", "this", "->", "getValidatorChain", "(", ")", "->", "getMessages", "(", ")", ";", "return", "$", "valid", ";", "}" ]
Returns true if and only if the values passes all chain validation @return boolean
[ "Returns", "true", "if", "and", "only", "if", "the", "values", "passes", "all", "chain", "validation" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Form/InputFilter/Input.php#L123-L129
229,373
slickframework/slick
src/Slick/Form/InputFilter/Input.php
Input.getValue
public function getValue() { if (is_null($this->_filtered)) { $this->_filtered = $this->getFilterChain()->filter($this->_value); } return $this->_filtered; }
php
public function getValue() { if (is_null($this->_filtered)) { $this->_filtered = $this->getFilterChain()->filter($this->_value); } return $this->_filtered; }
[ "public", "function", "getValue", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_filtered", ")", ")", "{", "$", "this", "->", "_filtered", "=", "$", "this", "->", "getFilterChain", "(", ")", "->", "filter", "(", "$", "this", "->", "_value", ")", ";", "}", "return", "$", "this", "->", "_filtered", ";", "}" ]
Retrieves the input value @return mixed
[ "Retrieves", "the", "input", "value" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Form/InputFilter/Input.php#L150-L156
229,374
slickframework/slick
src/Slick/Orm/Relation/HasMany.php
HasMany.onDelete
public function onDelete(Delete $event) { if ($this->isDependent()) { $class = $this->getRelatedEntity(); /** @var Entity $entity */ $entity = new $class(); $fkField = $this->getForeignKey(); $pmk = $event->getTarget()->getPrimaryKey(); $sql = Sql::createSql($entity->getAdapter()) ->delete($entity->getTableName()) ->where( ["{$fkField} = :id" => [':id' => $event->getTarget()->$pmk]] ); $sql->execute(); } }
php
public function onDelete(Delete $event) { if ($this->isDependent()) { $class = $this->getRelatedEntity(); /** @var Entity $entity */ $entity = new $class(); $fkField = $this->getForeignKey(); $pmk = $event->getTarget()->getPrimaryKey(); $sql = Sql::createSql($entity->getAdapter()) ->delete($entity->getTableName()) ->where( ["{$fkField} = :id" => [':id' => $event->getTarget()->$pmk]] ); $sql->execute(); } }
[ "public", "function", "onDelete", "(", "Delete", "$", "event", ")", "{", "if", "(", "$", "this", "->", "isDependent", "(", ")", ")", "{", "$", "class", "=", "$", "this", "->", "getRelatedEntity", "(", ")", ";", "/** @var Entity $entity */", "$", "entity", "=", "new", "$", "class", "(", ")", ";", "$", "fkField", "=", "$", "this", "->", "getForeignKey", "(", ")", ";", "$", "pmk", "=", "$", "event", "->", "getTarget", "(", ")", "->", "getPrimaryKey", "(", ")", ";", "$", "sql", "=", "Sql", "::", "createSql", "(", "$", "entity", "->", "getAdapter", "(", ")", ")", "->", "delete", "(", "$", "entity", "->", "getTableName", "(", ")", ")", "->", "where", "(", "[", "\"{$fkField} = :id\"", "=>", "[", "':id'", "=>", "$", "event", "->", "getTarget", "(", ")", "->", "$", "pmk", "]", "]", ")", ";", "$", "sql", "->", "execute", "(", ")", ";", "}", "}" ]
Runs before delete on entity event and deletes the children records on related entity. @param Delete $event
[ "Runs", "before", "delete", "on", "entity", "event", "and", "deletes", "the", "children", "records", "on", "related", "entity", "." ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Orm/Relation/HasMany.php#L102-L118
229,375
letyii/yii2-rbac-mongodb
MongodbManager.php
MongodbManager.init
public function init() { parent::init(); $this->db = Instance::ensure($this->db, Connection::className()); $this->db->getCollection($this->itemTable)->createIndex(['name' => 1], ['unique' => true]); $this->db->getCollection($this->ruleTable)->createIndex(['name' => 1], ['unique' => true]); }
php
public function init() { parent::init(); $this->db = Instance::ensure($this->db, Connection::className()); $this->db->getCollection($this->itemTable)->createIndex(['name' => 1], ['unique' => true]); $this->db->getCollection($this->ruleTable)->createIndex(['name' => 1], ['unique' => true]); }
[ "public", "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "$", "this", "->", "db", "=", "Instance", "::", "ensure", "(", "$", "this", "->", "db", ",", "Connection", "::", "className", "(", ")", ")", ";", "$", "this", "->", "db", "->", "getCollection", "(", "$", "this", "->", "itemTable", ")", "->", "createIndex", "(", "[", "'name'", "=>", "1", "]", ",", "[", "'unique'", "=>", "true", "]", ")", ";", "$", "this", "->", "db", "->", "getCollection", "(", "$", "this", "->", "ruleTable", ")", "->", "createIndex", "(", "[", "'name'", "=>", "1", "]", ",", "[", "'unique'", "=>", "true", "]", ")", ";", "}" ]
Initializes the application component. This method overrides the parent implementation by establishing the database connection.
[ "Initializes", "the", "application", "component", ".", "This", "method", "overrides", "the", "parent", "implementation", "by", "establishing", "the", "database", "connection", "." ]
a268f1018eae2a3ec473afd31a8f91f54cfacc08
https://github.com/letyii/yii2-rbac-mongodb/blob/a268f1018eae2a3ec473afd31a8f91f54cfacc08/MongodbManager.php#L64-L69
229,376
letyii/yii2-rbac-mongodb
MongodbManager.php
MongodbManager.getRoleAssigments
public function getRoleAssigments($roleName) { $query = (new Query)->from($this->assignmentTable) ->where(['item_name' => $roleName]); $assignments = []; foreach ($query->all($this->db) as $row) { $assignments[$row['user_id']] = new Assignment([ 'userId' => $row['user_id'], 'roleName' => $row['item_name'], 'createdAt' => $row['created_at'], ]); } return $assignments; }
php
public function getRoleAssigments($roleName) { $query = (new Query)->from($this->assignmentTable) ->where(['item_name' => $roleName]); $assignments = []; foreach ($query->all($this->db) as $row) { $assignments[$row['user_id']] = new Assignment([ 'userId' => $row['user_id'], 'roleName' => $row['item_name'], 'createdAt' => $row['created_at'], ]); } return $assignments; }
[ "public", "function", "getRoleAssigments", "(", "$", "roleName", ")", "{", "$", "query", "=", "(", "new", "Query", ")", "->", "from", "(", "$", "this", "->", "assignmentTable", ")", "->", "where", "(", "[", "'item_name'", "=>", "$", "roleName", "]", ")", ";", "$", "assignments", "=", "[", "]", ";", "foreach", "(", "$", "query", "->", "all", "(", "$", "this", "->", "db", ")", "as", "$", "row", ")", "{", "$", "assignments", "[", "$", "row", "[", "'user_id'", "]", "]", "=", "new", "Assignment", "(", "[", "'userId'", "=>", "$", "row", "[", "'user_id'", "]", ",", "'roleName'", "=>", "$", "row", "[", "'item_name'", "]", ",", "'createdAt'", "=>", "$", "row", "[", "'created_at'", "]", ",", "]", ")", ";", "}", "return", "$", "assignments", ";", "}" ]
Return all user assigment information for the specified role @param string $roleName the role name @return The assignment information. An empty array will be returned if there is no user assigned to the role.
[ "Return", "all", "user", "assigment", "information", "for", "the", "specified", "role" ]
a268f1018eae2a3ec473afd31a8f91f54cfacc08
https://github.com/letyii/yii2-rbac-mongodb/blob/a268f1018eae2a3ec473afd31a8f91f54cfacc08/MongodbManager.php#L498-L512
229,377
letyii/yii2-rbac-mongodb
MongodbManager.php
MongodbManager.buildTreeRole
public function buildTreeRole($item = NULL, $roleList = []) { $tree = []; $allParents = []; if (empty($roleList)) $roleList = $this->getRoles(); if ($item == NULL) { // Get all children $childRoles = []; $query = (new Query)->select(['child']) ->from($this->itemChildTable) ->where([]); foreach ($query->all($this->db) as $key => $value) { $childRoles[] = $value['child']; } // Get all roles $query = (new Query)->select(['name']) ->from($this->itemTable) ->where(['type' => 1]); foreach ($query->all($this->db) as $key => $value) { if (!in_array($value['name'], $childRoles)) $allParents[] = $value; } } if (!empty($allParents)) { foreach ($allParents as $parent) { $tree[$parent['name']] = [ 'title' => $roleList[$parent['name']]->description, 'items' => $this->buildTreeRole($parent['name'], $roleList), ]; } } else { // Get $childs = (new Query)->select(['child']) ->from($this->itemChildTable) ->where(['parent' => $item]) ->all($this->db); // lấy ra name của các role gán vào mảng mới. $checkRole = []; foreach ($roleList as $v) { $checkRole[] = $v->name; } foreach ($childs as $child) { // Nếu item là permission thì bỏ qua. if (!in_array($child['child'], $checkRole)) continue; $tree[$child['child']] = [ 'title' => $roleList[$child['child']]->description, 'items' => $this->buildTreeRole($child['child'], $roleList), ]; } } return $tree; }
php
public function buildTreeRole($item = NULL, $roleList = []) { $tree = []; $allParents = []; if (empty($roleList)) $roleList = $this->getRoles(); if ($item == NULL) { // Get all children $childRoles = []; $query = (new Query)->select(['child']) ->from($this->itemChildTable) ->where([]); foreach ($query->all($this->db) as $key => $value) { $childRoles[] = $value['child']; } // Get all roles $query = (new Query)->select(['name']) ->from($this->itemTable) ->where(['type' => 1]); foreach ($query->all($this->db) as $key => $value) { if (!in_array($value['name'], $childRoles)) $allParents[] = $value; } } if (!empty($allParents)) { foreach ($allParents as $parent) { $tree[$parent['name']] = [ 'title' => $roleList[$parent['name']]->description, 'items' => $this->buildTreeRole($parent['name'], $roleList), ]; } } else { // Get $childs = (new Query)->select(['child']) ->from($this->itemChildTable) ->where(['parent' => $item]) ->all($this->db); // lấy ra name của các role gán vào mảng mới. $checkRole = []; foreach ($roleList as $v) { $checkRole[] = $v->name; } foreach ($childs as $child) { // Nếu item là permission thì bỏ qua. if (!in_array($child['child'], $checkRole)) continue; $tree[$child['child']] = [ 'title' => $roleList[$child['child']]->description, 'items' => $this->buildTreeRole($child['child'], $roleList), ]; } } return $tree; }
[ "public", "function", "buildTreeRole", "(", "$", "item", "=", "NULL", ",", "$", "roleList", "=", "[", "]", ")", "{", "$", "tree", "=", "[", "]", ";", "$", "allParents", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "roleList", ")", ")", "$", "roleList", "=", "$", "this", "->", "getRoles", "(", ")", ";", "if", "(", "$", "item", "==", "NULL", ")", "{", "// Get all children\r", "$", "childRoles", "=", "[", "]", ";", "$", "query", "=", "(", "new", "Query", ")", "->", "select", "(", "[", "'child'", "]", ")", "->", "from", "(", "$", "this", "->", "itemChildTable", ")", "->", "where", "(", "[", "]", ")", ";", "foreach", "(", "$", "query", "->", "all", "(", "$", "this", "->", "db", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "childRoles", "[", "]", "=", "$", "value", "[", "'child'", "]", ";", "}", "// Get all roles\r", "$", "query", "=", "(", "new", "Query", ")", "->", "select", "(", "[", "'name'", "]", ")", "->", "from", "(", "$", "this", "->", "itemTable", ")", "->", "where", "(", "[", "'type'", "=>", "1", "]", ")", ";", "foreach", "(", "$", "query", "->", "all", "(", "$", "this", "->", "db", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "in_array", "(", "$", "value", "[", "'name'", "]", ",", "$", "childRoles", ")", ")", "$", "allParents", "[", "]", "=", "$", "value", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "allParents", ")", ")", "{", "foreach", "(", "$", "allParents", "as", "$", "parent", ")", "{", "$", "tree", "[", "$", "parent", "[", "'name'", "]", "]", "=", "[", "'title'", "=>", "$", "roleList", "[", "$", "parent", "[", "'name'", "]", "]", "->", "description", ",", "'items'", "=>", "$", "this", "->", "buildTreeRole", "(", "$", "parent", "[", "'name'", "]", ",", "$", "roleList", ")", ",", "]", ";", "}", "}", "else", "{", "// Get\r", "$", "childs", "=", "(", "new", "Query", ")", "->", "select", "(", "[", "'child'", "]", ")", "->", "from", "(", "$", "this", "->", "itemChildTable", ")", "->", "where", "(", "[", "'parent'", "=>", "$", "item", "]", ")", "->", "all", "(", "$", "this", "->", "db", ")", ";", "// lấy ra name của các role gán vào mảng mới.\r", "$", "checkRole", "=", "[", "]", ";", "foreach", "(", "$", "roleList", "as", "$", "v", ")", "{", "$", "checkRole", "[", "]", "=", "$", "v", "->", "name", ";", "}", "foreach", "(", "$", "childs", "as", "$", "child", ")", "{", "// Nếu item là permission thì bỏ qua.\r", "if", "(", "!", "in_array", "(", "$", "child", "[", "'child'", "]", ",", "$", "checkRole", ")", ")", "continue", ";", "$", "tree", "[", "$", "child", "[", "'child'", "]", "]", "=", "[", "'title'", "=>", "$", "roleList", "[", "$", "child", "[", "'child'", "]", "]", "->", "description", ",", "'items'", "=>", "$", "this", "->", "buildTreeRole", "(", "$", "child", "[", "'child'", "]", ",", "$", "roleList", ")", ",", "]", ";", "}", "}", "return", "$", "tree", ";", "}" ]
Build tree from item table @param string $item @param integer $level @return array
[ "Build", "tree", "from", "item", "table" ]
a268f1018eae2a3ec473afd31a8f91f54cfacc08
https://github.com/letyii/yii2-rbac-mongodb/blob/a268f1018eae2a3ec473afd31a8f91f54cfacc08/MongodbManager.php#L776-L832
229,378
mjacobus/php-query-builder
lib/PO/QueryBuilder/Clauses/WhereClause.php
WhereClause.addConditions
public function addConditions(array $conditions = array()) { foreach ($conditions as $key => $condition) { if (is_array($condition)) { call_user_func_array(array($this, 'addCondition'), $condition); } elseif (!$this->getBuilder()->getHelper()->isNumber($key)) { call_user_func_array(array($this, 'addCondition'), array($key, $condition)); } else { $this->addCondition($condition); } } return $this; }
php
public function addConditions(array $conditions = array()) { foreach ($conditions as $key => $condition) { if (is_array($condition)) { call_user_func_array(array($this, 'addCondition'), $condition); } elseif (!$this->getBuilder()->getHelper()->isNumber($key)) { call_user_func_array(array($this, 'addCondition'), array($key, $condition)); } else { $this->addCondition($condition); } } return $this; }
[ "public", "function", "addConditions", "(", "array", "$", "conditions", "=", "array", "(", ")", ")", "{", "foreach", "(", "$", "conditions", "as", "$", "key", "=>", "$", "condition", ")", "{", "if", "(", "is_array", "(", "$", "condition", ")", ")", "{", "call_user_func_array", "(", "array", "(", "$", "this", ",", "'addCondition'", ")", ",", "$", "condition", ")", ";", "}", "elseif", "(", "!", "$", "this", "->", "getBuilder", "(", ")", "->", "getHelper", "(", ")", "->", "isNumber", "(", "$", "key", ")", ")", "{", "call_user_func_array", "(", "array", "(", "$", "this", ",", "'addCondition'", ")", ",", "array", "(", "$", "key", ",", "$", "condition", ")", ")", ";", "}", "else", "{", "$", "this", "->", "addCondition", "(", "$", "condition", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Add contitions to the statement I.E. $this->o->addConditions(array( 'a = "b"', array('x', 1), array('x', '1', '!=') )); @param array $conditions @return PO\QueryBuilder\Clauses\WhereClause
[ "Add", "contitions", "to", "the", "statement", "I", ".", "E", "." ]
eb7a90ae3bc433659306807535b39f12ce4dfd9f
https://github.com/mjacobus/php-query-builder/blob/eb7a90ae3bc433659306807535b39f12ce4dfd9f/lib/PO/QueryBuilder/Clauses/WhereClause.php#L51-L64
229,379
silverstripe/silverstripe-mobile
code/MobileSiteControllerExtension.php
MobileSiteControllerExtension.onAfterInit
public function onAfterInit() { self::$is_mobile = false; $config = SiteConfig::current_site_config(); $request = $this->owner->getRequest(); // If we've accessed the homepage as /home/, then we redirect to / and don't want to double redirect here if ($this->owner->redirectedTo()) { return; } // Enforce the site (cookie expires in 1 day) $fullSite = $request->getVar('fullSite'); if(is_numeric($fullSite)) { $fullSiteCookie = (int)$fullSite; Cookie::set('fullSite', $fullSiteCookie); // use the host of the desktop version of the site to set cross-(sub)domain cookie $domain = $config->FullSiteDomainNormalized; if (!empty($domain)) { Cookie::set('fullSite', $fullSite, self::$cookie_expire_time, null, '.' . parse_url($domain, PHP_URL_HOST)); } else { // otherwise just use a normal cookie with the default domain Cookie::set('fullSite', $fullSite, self::$cookie_expire_time); } } else { $fullSiteCookie = Cookie::get('fullSite'); } if(is_numeric($fullSiteCookie)) { // Full site requested if($fullSiteCookie) { if($this->onMobileDomain() && $config->MobileSiteType == 'RedirectToDomain') { return $this->owner->redirect($config->FullSiteDomainNormalized, 301); } return; } // Mobile site requested else { if(!$this->onMobileDomain() && $config->MobileSiteType == 'RedirectToDomain') { return $this->owner->redirect($config->MobileDomainNormalized, 301); } Config::inst()->update('SSViewer', 'theme', $config->MobileTheme); self::$is_mobile = true; return; } } // If the user requested the mobile domain, set the right theme if($this->onMobileDomain()) { Config::inst()->update('SSViewer', 'theme', $config->MobileTheme); self::$is_mobile = true; } // User just wants to see a theme, but no redirect occurs if(MobileBrowserDetector::is_mobile() && $config->MobileSiteType == 'MobileThemeOnly') { Config::inst()->update('SSViewer', 'theme', $config->MobileTheme); self::$is_mobile = true; } // If on a mobile device, but not on the mobile domain and has been setup for redirection if(!$this->onMobileDomain() && MobileBrowserDetector::is_mobile() && $config->MobileSiteType == 'RedirectToDomain') { return $this->owner->redirect($config->MobileDomainNormalized, 301); } }
php
public function onAfterInit() { self::$is_mobile = false; $config = SiteConfig::current_site_config(); $request = $this->owner->getRequest(); // If we've accessed the homepage as /home/, then we redirect to / and don't want to double redirect here if ($this->owner->redirectedTo()) { return; } // Enforce the site (cookie expires in 1 day) $fullSite = $request->getVar('fullSite'); if(is_numeric($fullSite)) { $fullSiteCookie = (int)$fullSite; Cookie::set('fullSite', $fullSiteCookie); // use the host of the desktop version of the site to set cross-(sub)domain cookie $domain = $config->FullSiteDomainNormalized; if (!empty($domain)) { Cookie::set('fullSite', $fullSite, self::$cookie_expire_time, null, '.' . parse_url($domain, PHP_URL_HOST)); } else { // otherwise just use a normal cookie with the default domain Cookie::set('fullSite', $fullSite, self::$cookie_expire_time); } } else { $fullSiteCookie = Cookie::get('fullSite'); } if(is_numeric($fullSiteCookie)) { // Full site requested if($fullSiteCookie) { if($this->onMobileDomain() && $config->MobileSiteType == 'RedirectToDomain') { return $this->owner->redirect($config->FullSiteDomainNormalized, 301); } return; } // Mobile site requested else { if(!$this->onMobileDomain() && $config->MobileSiteType == 'RedirectToDomain') { return $this->owner->redirect($config->MobileDomainNormalized, 301); } Config::inst()->update('SSViewer', 'theme', $config->MobileTheme); self::$is_mobile = true; return; } } // If the user requested the mobile domain, set the right theme if($this->onMobileDomain()) { Config::inst()->update('SSViewer', 'theme', $config->MobileTheme); self::$is_mobile = true; } // User just wants to see a theme, but no redirect occurs if(MobileBrowserDetector::is_mobile() && $config->MobileSiteType == 'MobileThemeOnly') { Config::inst()->update('SSViewer', 'theme', $config->MobileTheme); self::$is_mobile = true; } // If on a mobile device, but not on the mobile domain and has been setup for redirection if(!$this->onMobileDomain() && MobileBrowserDetector::is_mobile() && $config->MobileSiteType == 'RedirectToDomain') { return $this->owner->redirect($config->MobileDomainNormalized, 301); } }
[ "public", "function", "onAfterInit", "(", ")", "{", "self", "::", "$", "is_mobile", "=", "false", ";", "$", "config", "=", "SiteConfig", "::", "current_site_config", "(", ")", ";", "$", "request", "=", "$", "this", "->", "owner", "->", "getRequest", "(", ")", ";", "// If we've accessed the homepage as /home/, then we redirect to / and don't want to double redirect here", "if", "(", "$", "this", "->", "owner", "->", "redirectedTo", "(", ")", ")", "{", "return", ";", "}", "// Enforce the site (cookie expires in 1 day)", "$", "fullSite", "=", "$", "request", "->", "getVar", "(", "'fullSite'", ")", ";", "if", "(", "is_numeric", "(", "$", "fullSite", ")", ")", "{", "$", "fullSiteCookie", "=", "(", "int", ")", "$", "fullSite", ";", "Cookie", "::", "set", "(", "'fullSite'", ",", "$", "fullSiteCookie", ")", ";", "// use the host of the desktop version of the site to set cross-(sub)domain cookie", "$", "domain", "=", "$", "config", "->", "FullSiteDomainNormalized", ";", "if", "(", "!", "empty", "(", "$", "domain", ")", ")", "{", "Cookie", "::", "set", "(", "'fullSite'", ",", "$", "fullSite", ",", "self", "::", "$", "cookie_expire_time", ",", "null", ",", "'.'", ".", "parse_url", "(", "$", "domain", ",", "PHP_URL_HOST", ")", ")", ";", "}", "else", "{", "// otherwise just use a normal cookie with the default domain", "Cookie", "::", "set", "(", "'fullSite'", ",", "$", "fullSite", ",", "self", "::", "$", "cookie_expire_time", ")", ";", "}", "}", "else", "{", "$", "fullSiteCookie", "=", "Cookie", "::", "get", "(", "'fullSite'", ")", ";", "}", "if", "(", "is_numeric", "(", "$", "fullSiteCookie", ")", ")", "{", "// Full site requested", "if", "(", "$", "fullSiteCookie", ")", "{", "if", "(", "$", "this", "->", "onMobileDomain", "(", ")", "&&", "$", "config", "->", "MobileSiteType", "==", "'RedirectToDomain'", ")", "{", "return", "$", "this", "->", "owner", "->", "redirect", "(", "$", "config", "->", "FullSiteDomainNormalized", ",", "301", ")", ";", "}", "return", ";", "}", "// Mobile site requested", "else", "{", "if", "(", "!", "$", "this", "->", "onMobileDomain", "(", ")", "&&", "$", "config", "->", "MobileSiteType", "==", "'RedirectToDomain'", ")", "{", "return", "$", "this", "->", "owner", "->", "redirect", "(", "$", "config", "->", "MobileDomainNormalized", ",", "301", ")", ";", "}", "Config", "::", "inst", "(", ")", "->", "update", "(", "'SSViewer'", ",", "'theme'", ",", "$", "config", "->", "MobileTheme", ")", ";", "self", "::", "$", "is_mobile", "=", "true", ";", "return", ";", "}", "}", "// If the user requested the mobile domain, set the right theme", "if", "(", "$", "this", "->", "onMobileDomain", "(", ")", ")", "{", "Config", "::", "inst", "(", ")", "->", "update", "(", "'SSViewer'", ",", "'theme'", ",", "$", "config", "->", "MobileTheme", ")", ";", "self", "::", "$", "is_mobile", "=", "true", ";", "}", "// User just wants to see a theme, but no redirect occurs", "if", "(", "MobileBrowserDetector", "::", "is_mobile", "(", ")", "&&", "$", "config", "->", "MobileSiteType", "==", "'MobileThemeOnly'", ")", "{", "Config", "::", "inst", "(", ")", "->", "update", "(", "'SSViewer'", ",", "'theme'", ",", "$", "config", "->", "MobileTheme", ")", ";", "self", "::", "$", "is_mobile", "=", "true", ";", "}", "// If on a mobile device, but not on the mobile domain and has been setup for redirection", "if", "(", "!", "$", "this", "->", "onMobileDomain", "(", ")", "&&", "MobileBrowserDetector", "::", "is_mobile", "(", ")", "&&", "$", "config", "->", "MobileSiteType", "==", "'RedirectToDomain'", ")", "{", "return", "$", "this", "->", "owner", "->", "redirect", "(", "$", "config", "->", "MobileDomainNormalized", ",", "301", ")", ";", "}", "}" ]
Override the default behavior to ensure that if this is a mobile device or if they are on the configured mobile domain then they receive the mobile site.
[ "Override", "the", "default", "behavior", "to", "ensure", "that", "if", "this", "is", "a", "mobile", "device", "or", "if", "they", "are", "on", "the", "configured", "mobile", "domain", "then", "they", "receive", "the", "mobile", "site", "." ]
27822812aa7d178e4e9d1e7e1b63c2836b4deb21
https://github.com/silverstripe/silverstripe-mobile/blob/27822812aa7d178e4e9d1e7e1b63c2836b4deb21/code/MobileSiteControllerExtension.php#L26-L93
229,380
silverstripe/silverstripe-mobile
code/MobileSiteControllerExtension.php
MobileSiteControllerExtension.requestedMobileSite
public function requestedMobileSite() { $config = SiteConfig::current_site_config(); if ($config->MobileSiteType == 'Disabled') return false; $request = $this->owner->getRequest(); $fullSite = $request->getVar('fullSite'); if (is_numeric($fullSite)) { return ($fullSite == 0); } $fullSiteCookie = Cookie::get('fullSite'); if (is_numeric($fullSiteCookie)) { return ($fullSiteCookie == 0); } return MobileBrowserDetector::is_mobile(); }
php
public function requestedMobileSite() { $config = SiteConfig::current_site_config(); if ($config->MobileSiteType == 'Disabled') return false; $request = $this->owner->getRequest(); $fullSite = $request->getVar('fullSite'); if (is_numeric($fullSite)) { return ($fullSite == 0); } $fullSiteCookie = Cookie::get('fullSite'); if (is_numeric($fullSiteCookie)) { return ($fullSiteCookie == 0); } return MobileBrowserDetector::is_mobile(); }
[ "public", "function", "requestedMobileSite", "(", ")", "{", "$", "config", "=", "SiteConfig", "::", "current_site_config", "(", ")", ";", "if", "(", "$", "config", "->", "MobileSiteType", "==", "'Disabled'", ")", "return", "false", ";", "$", "request", "=", "$", "this", "->", "owner", "->", "getRequest", "(", ")", ";", "$", "fullSite", "=", "$", "request", "->", "getVar", "(", "'fullSite'", ")", ";", "if", "(", "is_numeric", "(", "$", "fullSite", ")", ")", "{", "return", "(", "$", "fullSite", "==", "0", ")", ";", "}", "$", "fullSiteCookie", "=", "Cookie", "::", "get", "(", "'fullSite'", ")", ";", "if", "(", "is_numeric", "(", "$", "fullSiteCookie", ")", ")", "{", "return", "(", "$", "fullSiteCookie", "==", "0", ")", ";", "}", "return", "MobileBrowserDetector", "::", "is_mobile", "(", ")", ";", "}" ]
Return whether the user is requesting the mobile site - either by query string or by saved cookie. Falls back to browser detection for first time visitors @return boolean
[ "Return", "whether", "the", "user", "is", "requesting", "the", "mobile", "site", "-", "either", "by", "query", "string", "or", "by", "saved", "cookie", ".", "Falls", "back", "to", "browser", "detection", "for", "first", "time", "visitors" ]
27822812aa7d178e4e9d1e7e1b63c2836b4deb21
https://github.com/silverstripe/silverstripe-mobile/blob/27822812aa7d178e4e9d1e7e1b63c2836b4deb21/code/MobileSiteControllerExtension.php#L111-L127
229,381
slickframework/slick
src/Slick/Version/Version.php
Version.compare
public static function compare($version) { $version = strtolower($version); $version = preg_replace('/(\d)pr(\d?)/', '$1a$2', $version); return version_compare($version, strtolower(static::VERSION)); }
php
public static function compare($version) { $version = strtolower($version); $version = preg_replace('/(\d)pr(\d?)/', '$1a$2', $version); return version_compare($version, strtolower(static::VERSION)); }
[ "public", "static", "function", "compare", "(", "$", "version", ")", "{", "$", "version", "=", "strtolower", "(", "$", "version", ")", ";", "$", "version", "=", "preg_replace", "(", "'/(\\d)pr(\\d?)/'", ",", "'$1a$2'", ",", "$", "version", ")", ";", "return", "version_compare", "(", "$", "version", ",", "strtolower", "(", "static", "::", "VERSION", ")", ")", ";", "}" ]
Compare the provided version with current Slick version @param string $version @return int -1 if the $version is older, 0 if they are the same, and +1 if $version is newer.
[ "Compare", "the", "provided", "version", "with", "current", "Slick", "version" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Version/Version.php#L43-L48
229,382
emgag/flysystem-hash
src/HashPlugin.php
HashPlugin.handle
public function handle($path, $algo = 'sha256') { if (!in_array($algo, hash_algos())) { throw new \InvalidArgumentException('Hash algorithm ' . $algo . ' is not supported'); } $stream = $this->filesystem->readStream($path); if ($stream === false) { return false; } $hc = hash_init($algo); hash_update_stream($hc, $stream); return hash_final($hc); }
php
public function handle($path, $algo = 'sha256') { if (!in_array($algo, hash_algos())) { throw new \InvalidArgumentException('Hash algorithm ' . $algo . ' is not supported'); } $stream = $this->filesystem->readStream($path); if ($stream === false) { return false; } $hc = hash_init($algo); hash_update_stream($hc, $stream); return hash_final($hc); }
[ "public", "function", "handle", "(", "$", "path", ",", "$", "algo", "=", "'sha256'", ")", "{", "if", "(", "!", "in_array", "(", "$", "algo", ",", "hash_algos", "(", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Hash algorithm '", ".", "$", "algo", ".", "' is not supported'", ")", ";", "}", "$", "stream", "=", "$", "this", "->", "filesystem", "->", "readStream", "(", "$", "path", ")", ";", "if", "(", "$", "stream", "===", "false", ")", "{", "return", "false", ";", "}", "$", "hc", "=", "hash_init", "(", "$", "algo", ")", ";", "hash_update_stream", "(", "$", "hc", ",", "$", "stream", ")", ";", "return", "hash_final", "(", "$", "hc", ")", ";", "}" ]
Returns hash value of given path using supplied hash algorithm @param string $path @param string $algo any algorithm supported by hash() @return string|bool @see http://php.net/hash
[ "Returns", "hash", "value", "of", "given", "path", "using", "supplied", "hash", "algorithm" ]
88763a3cb2605e2f9ad61debc34b41a1f41126d1
https://github.com/emgag/flysystem-hash/blob/88763a3cb2605e2f9ad61debc34b41a1f41126d1/src/HashPlugin.php#L29-L45
229,383
odan/database
src/Database/Schema.php
Schema.setDatabase
public function setDatabase(string $dbName): bool { $this->db->exec('USE ' . $this->quoter->quoteName($dbName) . ';'); return true; }
php
public function setDatabase(string $dbName): bool { $this->db->exec('USE ' . $this->quoter->quoteName($dbName) . ';'); return true; }
[ "public", "function", "setDatabase", "(", "string", "$", "dbName", ")", ":", "bool", "{", "$", "this", "->", "db", "->", "exec", "(", "'USE '", ".", "$", "this", "->", "quoter", "->", "quoteName", "(", "$", "dbName", ")", ".", "';'", ")", ";", "return", "true", ";", "}" ]
Switch database. @param string $dbName @return bool
[ "Switch", "database", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L40-L45
229,384
odan/database
src/Database/Schema.php
Schema.getDatabases
public function getDatabases(string $like = null): array { $sql = 'SHOW DATABASES;'; if ($like !== null) { $sql = sprintf('SHOW DATABASES WHERE `database` LIKE %s;', $this->quoter->quoteValue($like)); } return $this->db->queryValues($sql, 'Database'); }
php
public function getDatabases(string $like = null): array { $sql = 'SHOW DATABASES;'; if ($like !== null) { $sql = sprintf('SHOW DATABASES WHERE `database` LIKE %s;', $this->quoter->quoteValue($like)); } return $this->db->queryValues($sql, 'Database'); }
[ "public", "function", "getDatabases", "(", "string", "$", "like", "=", "null", ")", ":", "array", "{", "$", "sql", "=", "'SHOW DATABASES;'", ";", "if", "(", "$", "like", "!==", "null", ")", "{", "$", "sql", "=", "sprintf", "(", "'SHOW DATABASES WHERE `database` LIKE %s;'", ",", "$", "this", "->", "quoter", "->", "quoteValue", "(", "$", "like", ")", ")", ";", "}", "return", "$", "this", "->", "db", "->", "queryValues", "(", "$", "sql", ",", "'Database'", ")", ";", "}" ]
Returns all databases. @param string|null $like (optional) e.g. 'information%schema'; @return array
[ "Returns", "all", "databases", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L83-L91
229,385
odan/database
src/Database/Schema.php
Schema.createDatabase
public function createDatabase( string $dbName, string $characterSet = 'utf8mb4', string $collate = 'utf8mb4_unicode_ci' ): bool { $sql = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s;'; $sql = vsprintf($sql, [ $this->quoter->quoteName($dbName), $this->quoter->quoteValue($characterSet), $this->quoter->quoteValue($collate), ]); return $this->db->exec($sql); }
php
public function createDatabase( string $dbName, string $characterSet = 'utf8mb4', string $collate = 'utf8mb4_unicode_ci' ): bool { $sql = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s;'; $sql = vsprintf($sql, [ $this->quoter->quoteName($dbName), $this->quoter->quoteValue($characterSet), $this->quoter->quoteValue($collate), ]); return $this->db->exec($sql); }
[ "public", "function", "createDatabase", "(", "string", "$", "dbName", ",", "string", "$", "characterSet", "=", "'utf8mb4'", ",", "string", "$", "collate", "=", "'utf8mb4_unicode_ci'", ")", ":", "bool", "{", "$", "sql", "=", "'CREATE DATABASE %s CHARACTER SET %s COLLATE %s;'", ";", "$", "sql", "=", "vsprintf", "(", "$", "sql", ",", "[", "$", "this", "->", "quoter", "->", "quoteName", "(", "$", "dbName", ")", ",", "$", "this", "->", "quoter", "->", "quoteValue", "(", "$", "characterSet", ")", ",", "$", "this", "->", "quoter", "->", "quoteValue", "(", "$", "collate", ")", ",", "]", ")", ";", "return", "$", "this", "->", "db", "->", "exec", "(", "$", "sql", ")", ";", "}" ]
Create a database. @param string $dbName The database name @param string $characterSet @param string $collate @return bool Success
[ "Create", "a", "database", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L102-L115
229,386
odan/database
src/Database/Schema.php
Schema.useDatabase
public function useDatabase(string $dbName): bool { $sql = sprintf('USE %s;', $this->quoter->quoteName($dbName)); $result = $this->db->exec($sql); return (bool)$result; }
php
public function useDatabase(string $dbName): bool { $sql = sprintf('USE %s;', $this->quoter->quoteName($dbName)); $result = $this->db->exec($sql); return (bool)$result; }
[ "public", "function", "useDatabase", "(", "string", "$", "dbName", ")", ":", "bool", "{", "$", "sql", "=", "sprintf", "(", "'USE %s;'", ",", "$", "this", "->", "quoter", "->", "quoteName", "(", "$", "dbName", ")", ")", ";", "$", "result", "=", "$", "this", "->", "db", "->", "exec", "(", "$", "sql", ")", ";", "return", "(", "bool", ")", "$", "result", ";", "}" ]
Change the database. @param string $dbName The database name @return bool Success
[ "Change", "the", "database", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L124-L130
229,387
odan/database
src/Database/Schema.php
Schema.getTables
public function getTables($like = null): array { if ($like === null) { $sql = 'SELECT table_name FROM information_schema.tables WHERE table_schema = database()'; } else { $sql = sprintf('SELECT table_name FROM information_schema.tables WHERE table_schema = database() AND table_name LIKE %s;', $this->quoter->quoteValue($like)); } return $this->db->queryValues($sql, 'table_name'); }
php
public function getTables($like = null): array { if ($like === null) { $sql = 'SELECT table_name FROM information_schema.tables WHERE table_schema = database()'; } else { $sql = sprintf('SELECT table_name FROM information_schema.tables WHERE table_schema = database() AND table_name LIKE %s;', $this->quoter->quoteValue($like)); } return $this->db->queryValues($sql, 'table_name'); }
[ "public", "function", "getTables", "(", "$", "like", "=", "null", ")", ":", "array", "{", "if", "(", "$", "like", "===", "null", ")", "{", "$", "sql", "=", "'SELECT table_name\n FROM information_schema.tables\n WHERE table_schema = database()'", ";", "}", "else", "{", "$", "sql", "=", "sprintf", "(", "'SELECT table_name\n FROM information_schema.tables\n WHERE table_schema = database()\n AND table_name LIKE %s;'", ",", "$", "this", "->", "quoter", "->", "quoteValue", "(", "$", "like", ")", ")", ";", "}", "return", "$", "this", "->", "db", "->", "queryValues", "(", "$", "sql", ",", "'table_name'", ")", ";", "}" ]
Return all Tables from Database. @param string $like (optional) e.g. 'information%' @return array
[ "Return", "all", "Tables", "from", "Database", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L139-L153
229,388
odan/database
src/Database/Schema.php
Schema.existTable
public function existTable(string $tableName): bool { [$dbName, $tableName] = $this->parseTableName($tableName); $sql = 'SELECT table_name FROM information_schema.tables WHERE table_schema = %s AND table_name = %s;'; $sql = sprintf($sql, $dbName, $tableName); $row = $this->db->query($sql)->fetch(PDO::FETCH_ASSOC); return isset($row['table_name']); }
php
public function existTable(string $tableName): bool { [$dbName, $tableName] = $this->parseTableName($tableName); $sql = 'SELECT table_name FROM information_schema.tables WHERE table_schema = %s AND table_name = %s;'; $sql = sprintf($sql, $dbName, $tableName); $row = $this->db->query($sql)->fetch(PDO::FETCH_ASSOC); return isset($row['table_name']); }
[ "public", "function", "existTable", "(", "string", "$", "tableName", ")", ":", "bool", "{", "[", "$", "dbName", ",", "$", "tableName", "]", "=", "$", "this", "->", "parseTableName", "(", "$", "tableName", ")", ";", "$", "sql", "=", "'SELECT table_name\n FROM information_schema.tables\n WHERE table_schema = %s\n AND table_name = %s;'", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "dbName", ",", "$", "tableName", ")", ";", "$", "row", "=", "$", "this", "->", "db", "->", "query", "(", "$", "sql", ")", "->", "fetch", "(", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "isset", "(", "$", "row", "[", "'table_name'", "]", ")", ";", "}" ]
Check if table exist. @param string $tableName @return bool
[ "Check", "if", "table", "exist", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L162-L175
229,389
odan/database
src/Database/Schema.php
Schema.parseTableName
protected function parseTableName(string $tableName): array { $dbName = 'database()'; if (strpos($tableName, '.') !== false) { $parts = explode('.', $tableName); $dbName = $this->quoter->quoteValue($parts[0]); $tableName = $this->quoter->quoteValue($parts[1]); } else { $tableName = $this->quoter->quoteValue($tableName); } return [$dbName, $tableName]; }
php
protected function parseTableName(string $tableName): array { $dbName = 'database()'; if (strpos($tableName, '.') !== false) { $parts = explode('.', $tableName); $dbName = $this->quoter->quoteValue($parts[0]); $tableName = $this->quoter->quoteValue($parts[1]); } else { $tableName = $this->quoter->quoteValue($tableName); } return [$dbName, $tableName]; }
[ "protected", "function", "parseTableName", "(", "string", "$", "tableName", ")", ":", "array", "{", "$", "dbName", "=", "'database()'", ";", "if", "(", "strpos", "(", "$", "tableName", ",", "'.'", ")", "!==", "false", ")", "{", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "tableName", ")", ";", "$", "dbName", "=", "$", "this", "->", "quoter", "->", "quoteValue", "(", "$", "parts", "[", "0", "]", ")", ";", "$", "tableName", "=", "$", "this", "->", "quoter", "->", "quoteValue", "(", "$", "parts", "[", "1", "]", ")", ";", "}", "else", "{", "$", "tableName", "=", "$", "this", "->", "quoter", "->", "quoteValue", "(", "$", "tableName", ")", ";", "}", "return", "[", "$", "dbName", ",", "$", "tableName", "]", ";", "}" ]
Split table into dbname and table name. @param string $tableName table @return array
[ "Split", "table", "into", "dbname", "and", "table", "name", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L184-L196
229,390
odan/database
src/Database/Schema.php
Schema.dropTable
public function dropTable(string $tableName): bool { $this->db->exec(sprintf('DROP TABLE IF EXISTS %s;', $this->quoter->quoteName($tableName))); return true; }
php
public function dropTable(string $tableName): bool { $this->db->exec(sprintf('DROP TABLE IF EXISTS %s;', $this->quoter->quoteName($tableName))); return true; }
[ "public", "function", "dropTable", "(", "string", "$", "tableName", ")", ":", "bool", "{", "$", "this", "->", "db", "->", "exec", "(", "sprintf", "(", "'DROP TABLE IF EXISTS %s;'", ",", "$", "this", "->", "quoter", "->", "quoteName", "(", "$", "tableName", ")", ")", ")", ";", "return", "true", ";", "}" ]
Delete a table. @param string $tableName @return bool Success
[ "Delete", "a", "table", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L205-L210
229,391
odan/database
src/Database/Schema.php
Schema.clearTable
public function clearTable(string $tableName): bool { $delete = new DeleteQuery($this->db); return $delete->from($tableName)->execute(); }
php
public function clearTable(string $tableName): bool { $delete = new DeleteQuery($this->db); return $delete->from($tableName)->execute(); }
[ "public", "function", "clearTable", "(", "string", "$", "tableName", ")", ":", "bool", "{", "$", "delete", "=", "new", "DeleteQuery", "(", "$", "this", "->", "db", ")", ";", "return", "$", "delete", "->", "from", "(", "$", "tableName", ")", "->", "execute", "(", ")", ";", "}" ]
Clear table content. Delete all rows. @param string $tableName @return bool Success @deprecated Use DeleteQuery instead
[ "Clear", "table", "content", ".", "Delete", "all", "rows", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L221-L226
229,392
odan/database
src/Database/Schema.php
Schema.renameTable
public function renameTable(string $from, string $to): bool { $from = $this->quoter->quoteName($from); $to = $this->quoter->quoteName($to); $this->db->exec(sprintf('RENAME TABLE %s TO %s;', $from, $to)); return true; }
php
public function renameTable(string $from, string $to): bool { $from = $this->quoter->quoteName($from); $to = $this->quoter->quoteName($to); $this->db->exec(sprintf('RENAME TABLE %s TO %s;', $from, $to)); return true; }
[ "public", "function", "renameTable", "(", "string", "$", "from", ",", "string", "$", "to", ")", ":", "bool", "{", "$", "from", "=", "$", "this", "->", "quoter", "->", "quoteName", "(", "$", "from", ")", ";", "$", "to", "=", "$", "this", "->", "quoter", "->", "quoteName", "(", "$", "to", ")", ";", "$", "this", "->", "db", "->", "exec", "(", "sprintf", "(", "'RENAME TABLE %s TO %s;'", ",", "$", "from", ",", "$", "to", ")", ")", ";", "return", "true", ";", "}" ]
Rename table. @param string $from Old table name @param string $to New table name @return bool Success
[ "Rename", "table", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L251-L258
229,393
odan/database
src/Database/Schema.php
Schema.copyTable
public function copyTable(string $tableNameSource, string $tableNameDestination): bool { $tableNameSource = $this->quoter->quoteName($tableNameSource); $tableNameDestination = $this->quoter->quoteName($tableNameDestination); $this->db->exec(sprintf('CREATE TABLE %s LIKE %s;', $tableNameDestination, $tableNameSource)); return true; }
php
public function copyTable(string $tableNameSource, string $tableNameDestination): bool { $tableNameSource = $this->quoter->quoteName($tableNameSource); $tableNameDestination = $this->quoter->quoteName($tableNameDestination); $this->db->exec(sprintf('CREATE TABLE %s LIKE %s;', $tableNameDestination, $tableNameSource)); return true; }
[ "public", "function", "copyTable", "(", "string", "$", "tableNameSource", ",", "string", "$", "tableNameDestination", ")", ":", "bool", "{", "$", "tableNameSource", "=", "$", "this", "->", "quoter", "->", "quoteName", "(", "$", "tableNameSource", ")", ";", "$", "tableNameDestination", "=", "$", "this", "->", "quoter", "->", "quoteName", "(", "$", "tableNameDestination", ")", ";", "$", "this", "->", "db", "->", "exec", "(", "sprintf", "(", "'CREATE TABLE %s LIKE %s;'", ",", "$", "tableNameDestination", ",", "$", "tableNameSource", ")", ")", ";", "return", "true", ";", "}" ]
Copy an existing table to a new table. @param string $tableNameSource source table name @param string $tableNameDestination new table name @return bool Success
[ "Copy", "an", "existing", "table", "to", "a", "new", "table", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L268-L275
229,394
odan/database
src/Database/Schema.php
Schema.getColumnNames
public function getColumnNames(string $tableName): array { $result = []; foreach ($this->getColumns($tableName) as $value) { $field = $value['column_name']; $result[$field] = $field; } return $result; }
php
public function getColumnNames(string $tableName): array { $result = []; foreach ($this->getColumns($tableName) as $value) { $field = $value['column_name']; $result[$field] = $field; } return $result; }
[ "public", "function", "getColumnNames", "(", "string", "$", "tableName", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getColumns", "(", "$", "tableName", ")", "as", "$", "value", ")", "{", "$", "field", "=", "$", "value", "[", "'column_name'", "]", ";", "$", "result", "[", "$", "field", "]", "=", "$", "field", ";", "}", "return", "$", "result", ";", "}" ]
Returns the column names of a table as an array. @param string $tableName @return array
[ "Returns", "the", "column", "names", "of", "a", "table", "as", "an", "array", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L284-L293
229,395
odan/database
src/Database/Schema.php
Schema.getColumns
public function getColumns(string $tableName): array { $sql = 'SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_scale, character_set_name, collation_name, column_type, column_key, extra, `privileges`, column_comment FROM information_schema.columns WHERE table_schema = %s AND table_name = %s;'; [$dbName, $tableName] = $this->parseTableName($tableName); $sql = sprintf($sql, $dbName, $tableName); $result = $this->db->query($sql)->fetchAll(PDO::FETCH_ASSOC); return $result ?: []; }
php
public function getColumns(string $tableName): array { $sql = 'SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_scale, character_set_name, collation_name, column_type, column_key, extra, `privileges`, column_comment FROM information_schema.columns WHERE table_schema = %s AND table_name = %s;'; [$dbName, $tableName] = $this->parseTableName($tableName); $sql = sprintf($sql, $dbName, $tableName); $result = $this->db->query($sql)->fetchAll(PDO::FETCH_ASSOC); return $result ?: []; }
[ "public", "function", "getColumns", "(", "string", "$", "tableName", ")", ":", "array", "{", "$", "sql", "=", "'SELECT\n column_name,\n column_default,\n is_nullable,\n data_type,\n character_maximum_length,\n character_octet_length,\n numeric_precision,\n numeric_scale,\n character_set_name,\n collation_name,\n column_type,\n column_key,\n extra,\n `privileges`,\n column_comment\n FROM information_schema.columns\n WHERE table_schema = %s\n AND table_name = %s;'", ";", "[", "$", "dbName", ",", "$", "tableName", "]", "=", "$", "this", "->", "parseTableName", "(", "$", "tableName", ")", ";", "$", "sql", "=", "sprintf", "(", "$", "sql", ",", "$", "dbName", ",", "$", "tableName", ")", ";", "$", "result", "=", "$", "this", "->", "db", "->", "query", "(", "$", "sql", ")", "->", "fetchAll", "(", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "$", "result", "?", ":", "[", "]", ";", "}" ]
Returns all columns in a table. @param string $tableName @return array
[ "Returns", "all", "columns", "in", "a", "table", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L302-L330
229,396
odan/database
src/Database/Schema.php
Schema.compareTableSchema
public function compareTableSchema(string $tableName1, string $tableName2): bool { $schema1 = $this->getTableSchemaId($tableName1); $schema2 = $this->getTableSchemaId($tableName2); return $schema1 === $schema2; }
php
public function compareTableSchema(string $tableName1, string $tableName2): bool { $schema1 = $this->getTableSchemaId($tableName1); $schema2 = $this->getTableSchemaId($tableName2); return $schema1 === $schema2; }
[ "public", "function", "compareTableSchema", "(", "string", "$", "tableName1", ",", "string", "$", "tableName2", ")", ":", "bool", "{", "$", "schema1", "=", "$", "this", "->", "getTableSchemaId", "(", "$", "tableName1", ")", ";", "$", "schema2", "=", "$", "this", "->", "getTableSchemaId", "(", "$", "tableName2", ")", ";", "return", "$", "schema1", "===", "$", "schema2", ";", "}" ]
Compare two tables and returns true if the table schema match. @param string $tableName1 @param string $tableName2 @return bool Status
[ "Compare", "two", "tables", "and", "returns", "true", "if", "the", "table", "schema", "match", "." ]
e514fb45ab72718a77b34ed2c44906f5159e8278
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Schema.php#L340-L346
229,397
cgsmith/zf1-recaptcha-2
src/Cgsmith/Validate/Recaptcha.php
Recaptcha.isValid
public function isValid($value, $context = null) { $frontController = \Zend_Controller_Front::getInstance(); $request = $frontController->getRequest(); $value = $request->getParam('g-recaptcha-response'); if (empty($value)) { $this->_error(self::CAPTCHA_EMPTY); return false; } $this->_value = $value; if (!$this->_verify($value)) { $this->_error(self::INVALID_CAPTCHA); return false; } return true; }
php
public function isValid($value, $context = null) { $frontController = \Zend_Controller_Front::getInstance(); $request = $frontController->getRequest(); $value = $request->getParam('g-recaptcha-response'); if (empty($value)) { $this->_error(self::CAPTCHA_EMPTY); return false; } $this->_value = $value; if (!$this->_verify($value)) { $this->_error(self::INVALID_CAPTCHA); return false; } return true; }
[ "public", "function", "isValid", "(", "$", "value", ",", "$", "context", "=", "null", ")", "{", "$", "frontController", "=", "\\", "Zend_Controller_Front", "::", "getInstance", "(", ")", ";", "$", "request", "=", "$", "frontController", "->", "getRequest", "(", ")", ";", "$", "value", "=", "$", "request", "->", "getParam", "(", "'g-recaptcha-response'", ")", ";", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "$", "this", "->", "_error", "(", "self", "::", "CAPTCHA_EMPTY", ")", ";", "return", "false", ";", "}", "$", "this", "->", "_value", "=", "$", "value", ";", "if", "(", "!", "$", "this", "->", "_verify", "(", "$", "value", ")", ")", "{", "$", "this", "->", "_error", "(", "self", "::", "INVALID_CAPTCHA", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Validate our form's element @param mixed $value @param null $context @return bool
[ "Validate", "our", "form", "s", "element" ]
fa2ab15df2dd27943e9ea61a7790c3566d78b19a
https://github.com/cgsmith/zf1-recaptcha-2/blob/fa2ab15df2dd27943e9ea61a7790c3566d78b19a/src/Cgsmith/Validate/Recaptcha.php#L54-L70
229,398
cgsmith/zf1-recaptcha-2
src/Cgsmith/Validate/Recaptcha.php
Recaptcha._verify
protected function _verify($value) { $queryString = http_build_query([ 'secret' => $this->_secretKey, 'response' => $value, 'remoteIp' => $_SERVER['REMOTE_ADDR'] ]); /** * PHP 5.6.0 changed the way you specify the peer name for SSL context options. * Using "CN_name" will still work, but it will raise deprecated errors. */ $peerKey = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; $context = stream_context_create([ 'http' => [ 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => self::POST_METHOD, 'content' => $queryString, 'verify_peer' => true, $peerKey => self::PEER_KEY ] ]); $jsonObject = json_decode(file_get_contents(self::SITE_VERIFY_URL, false, $context)); return $jsonObject->success; }
php
protected function _verify($value) { $queryString = http_build_query([ 'secret' => $this->_secretKey, 'response' => $value, 'remoteIp' => $_SERVER['REMOTE_ADDR'] ]); /** * PHP 5.6.0 changed the way you specify the peer name for SSL context options. * Using "CN_name" will still work, but it will raise deprecated errors. */ $peerKey = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; $context = stream_context_create([ 'http' => [ 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => self::POST_METHOD, 'content' => $queryString, 'verify_peer' => true, $peerKey => self::PEER_KEY ] ]); $jsonObject = json_decode(file_get_contents(self::SITE_VERIFY_URL, false, $context)); return $jsonObject->success; }
[ "protected", "function", "_verify", "(", "$", "value", ")", "{", "$", "queryString", "=", "http_build_query", "(", "[", "'secret'", "=>", "$", "this", "->", "_secretKey", ",", "'response'", "=>", "$", "value", ",", "'remoteIp'", "=>", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", "]", ")", ";", "/**\n * PHP 5.6.0 changed the way you specify the peer name for SSL context options.\n * Using \"CN_name\" will still work, but it will raise deprecated errors.\n */", "$", "peerKey", "=", "version_compare", "(", "PHP_VERSION", ",", "'5.6.0'", ",", "'<'", ")", "?", "'CN_name'", ":", "'peer_name'", ";", "$", "context", "=", "stream_context_create", "(", "[", "'http'", "=>", "[", "'header'", "=>", "\"Content-type: application/x-www-form-urlencoded\\r\\n\"", ",", "'method'", "=>", "self", "::", "POST_METHOD", ",", "'content'", "=>", "$", "queryString", ",", "'verify_peer'", "=>", "true", ",", "$", "peerKey", "=>", "self", "::", "PEER_KEY", "]", "]", ")", ";", "$", "jsonObject", "=", "json_decode", "(", "file_get_contents", "(", "self", "::", "SITE_VERIFY_URL", ",", "false", ",", "$", "context", ")", ")", ";", "return", "$", "jsonObject", "->", "success", ";", "}" ]
Calls the reCAPTCHA siteverify API to verify whether the user passes the captcha test. @param mixed $value @return boolean @link https://github.com/google/recaptcha
[ "Calls", "the", "reCAPTCHA", "siteverify", "API", "to", "verify", "whether", "the", "user", "passes", "the", "captcha", "test", "." ]
fa2ab15df2dd27943e9ea61a7790c3566d78b19a
https://github.com/cgsmith/zf1-recaptcha-2/blob/fa2ab15df2dd27943e9ea61a7790c3566d78b19a/src/Cgsmith/Validate/Recaptcha.php#L80-L104
229,399
chadicus/marvel-api-client
src/Entities/Comic.php
Comic.findAll
final public static function findAll(Api\Client $client, array $criteria = []) : Api\Collection { $filters = [ 'format' => [ [ 'in', [ 'comic', 'hardcover', 'trade paperback', 'magazine', 'digest', 'graphic novel', 'digital comic', 'infinite comic', ] ], ], 'formatType' => [['in', ['comic', 'collection']]], 'noVariants' => [['bool'], ['bool-convert']], 'dateDescriptor' => [['in', ['lastWeek', 'thisWeek', 'nextWeek', 'thisMonth']]], 'fromDate' => [['date', true]], 'toDate' => [['date', true]], 'hasDigitalIssue' => [['bool'], ['bool-convert']], 'modifiedSince' => [['date', true], ['date-format', 'c']], 'creators' => [['ofScalars', [['uint']]], ['implode', ',']], 'characters' => [['ofScalars', [['uint']]], ['implode', ',']], 'series' => [['ofScalars', [['uint']]], ['implode', ',']], 'events' => [['ofScalars', [['uint']]], ['implode', ',']], 'stories' => [['ofScalars', [['uint']]], ['implode', ',']], 'sharedAppearances' => [['ofScalars', [['uint']]], ['implode', ',']], 'collaborators' => [['ofScalars', [['uint']]], ['implode', ',']], 'orderBy' => [ [ 'in', [ 'focDate', 'onsaleDate', 'title', 'issueNumber', 'modified', '-focDate', '-onsaleDate', '-title', '-issueNumber', '-modified', ], ] ], ]; list($success, $filteredCriteria, $error) = Api\Filterer::filter($filters, $criteria); Util::ensure(true, $success, $error); $toDate = Util\Arrays::get($filteredCriteria, 'toDate'); $fromDate = Util\Arrays::get($filteredCriteria, 'fromDate'); if ($toDate !== null && $fromDate !== null) { unset($filteredCriteria['toDate'], $filteredCriteria['fromDate']); $filteredCriteria['dateRange'] = "{$fromDate->format('c')},{$toDate->format('c')}"; } return new Api\Collection($client, self::API_RESOURCE, $filteredCriteria); }
php
final public static function findAll(Api\Client $client, array $criteria = []) : Api\Collection { $filters = [ 'format' => [ [ 'in', [ 'comic', 'hardcover', 'trade paperback', 'magazine', 'digest', 'graphic novel', 'digital comic', 'infinite comic', ] ], ], 'formatType' => [['in', ['comic', 'collection']]], 'noVariants' => [['bool'], ['bool-convert']], 'dateDescriptor' => [['in', ['lastWeek', 'thisWeek', 'nextWeek', 'thisMonth']]], 'fromDate' => [['date', true]], 'toDate' => [['date', true]], 'hasDigitalIssue' => [['bool'], ['bool-convert']], 'modifiedSince' => [['date', true], ['date-format', 'c']], 'creators' => [['ofScalars', [['uint']]], ['implode', ',']], 'characters' => [['ofScalars', [['uint']]], ['implode', ',']], 'series' => [['ofScalars', [['uint']]], ['implode', ',']], 'events' => [['ofScalars', [['uint']]], ['implode', ',']], 'stories' => [['ofScalars', [['uint']]], ['implode', ',']], 'sharedAppearances' => [['ofScalars', [['uint']]], ['implode', ',']], 'collaborators' => [['ofScalars', [['uint']]], ['implode', ',']], 'orderBy' => [ [ 'in', [ 'focDate', 'onsaleDate', 'title', 'issueNumber', 'modified', '-focDate', '-onsaleDate', '-title', '-issueNumber', '-modified', ], ] ], ]; list($success, $filteredCriteria, $error) = Api\Filterer::filter($filters, $criteria); Util::ensure(true, $success, $error); $toDate = Util\Arrays::get($filteredCriteria, 'toDate'); $fromDate = Util\Arrays::get($filteredCriteria, 'fromDate'); if ($toDate !== null && $fromDate !== null) { unset($filteredCriteria['toDate'], $filteredCriteria['fromDate']); $filteredCriteria['dateRange'] = "{$fromDate->format('c')},{$toDate->format('c')}"; } return new Api\Collection($client, self::API_RESOURCE, $filteredCriteria); }
[ "final", "public", "static", "function", "findAll", "(", "Api", "\\", "Client", "$", "client", ",", "array", "$", "criteria", "=", "[", "]", ")", ":", "Api", "\\", "Collection", "{", "$", "filters", "=", "[", "'format'", "=>", "[", "[", "'in'", ",", "[", "'comic'", ",", "'hardcover'", ",", "'trade paperback'", ",", "'magazine'", ",", "'digest'", ",", "'graphic novel'", ",", "'digital comic'", ",", "'infinite comic'", ",", "]", "]", ",", "]", ",", "'formatType'", "=>", "[", "[", "'in'", ",", "[", "'comic'", ",", "'collection'", "]", "]", "]", ",", "'noVariants'", "=>", "[", "[", "'bool'", "]", ",", "[", "'bool-convert'", "]", "]", ",", "'dateDescriptor'", "=>", "[", "[", "'in'", ",", "[", "'lastWeek'", ",", "'thisWeek'", ",", "'nextWeek'", ",", "'thisMonth'", "]", "]", "]", ",", "'fromDate'", "=>", "[", "[", "'date'", ",", "true", "]", "]", ",", "'toDate'", "=>", "[", "[", "'date'", ",", "true", "]", "]", ",", "'hasDigitalIssue'", "=>", "[", "[", "'bool'", "]", ",", "[", "'bool-convert'", "]", "]", ",", "'modifiedSince'", "=>", "[", "[", "'date'", ",", "true", "]", ",", "[", "'date-format'", ",", "'c'", "]", "]", ",", "'creators'", "=>", "[", "[", "'ofScalars'", ",", "[", "[", "'uint'", "]", "]", "]", ",", "[", "'implode'", ",", "','", "]", "]", ",", "'characters'", "=>", "[", "[", "'ofScalars'", ",", "[", "[", "'uint'", "]", "]", "]", ",", "[", "'implode'", ",", "','", "]", "]", ",", "'series'", "=>", "[", "[", "'ofScalars'", ",", "[", "[", "'uint'", "]", "]", "]", ",", "[", "'implode'", ",", "','", "]", "]", ",", "'events'", "=>", "[", "[", "'ofScalars'", ",", "[", "[", "'uint'", "]", "]", "]", ",", "[", "'implode'", ",", "','", "]", "]", ",", "'stories'", "=>", "[", "[", "'ofScalars'", ",", "[", "[", "'uint'", "]", "]", "]", ",", "[", "'implode'", ",", "','", "]", "]", ",", "'sharedAppearances'", "=>", "[", "[", "'ofScalars'", ",", "[", "[", "'uint'", "]", "]", "]", ",", "[", "'implode'", ",", "','", "]", "]", ",", "'collaborators'", "=>", "[", "[", "'ofScalars'", ",", "[", "[", "'uint'", "]", "]", "]", ",", "[", "'implode'", ",", "','", "]", "]", ",", "'orderBy'", "=>", "[", "[", "'in'", ",", "[", "'focDate'", ",", "'onsaleDate'", ",", "'title'", ",", "'issueNumber'", ",", "'modified'", ",", "'-focDate'", ",", "'-onsaleDate'", ",", "'-title'", ",", "'-issueNumber'", ",", "'-modified'", ",", "]", ",", "]", "]", ",", "]", ";", "list", "(", "$", "success", ",", "$", "filteredCriteria", ",", "$", "error", ")", "=", "Api", "\\", "Filterer", "::", "filter", "(", "$", "filters", ",", "$", "criteria", ")", ";", "Util", "::", "ensure", "(", "true", ",", "$", "success", ",", "$", "error", ")", ";", "$", "toDate", "=", "Util", "\\", "Arrays", "::", "get", "(", "$", "filteredCriteria", ",", "'toDate'", ")", ";", "$", "fromDate", "=", "Util", "\\", "Arrays", "::", "get", "(", "$", "filteredCriteria", ",", "'fromDate'", ")", ";", "if", "(", "$", "toDate", "!==", "null", "&&", "$", "fromDate", "!==", "null", ")", "{", "unset", "(", "$", "filteredCriteria", "[", "'toDate'", "]", ",", "$", "filteredCriteria", "[", "'fromDate'", "]", ")", ";", "$", "filteredCriteria", "[", "'dateRange'", "]", "=", "\"{$fromDate->format('c')},{$toDate->format('c')}\"", ";", "}", "return", "new", "Api", "\\", "Collection", "(", "$", "client", ",", "self", "::", "API_RESOURCE", ",", "$", "filteredCriteria", ")", ";", "}" ]
Returns a collection containing all Comics which match the given criteria. @param Api\Client $client The API Client. @param array $criteria The criteria for searching. @return Api\Collection
[ "Returns", "a", "collection", "containing", "all", "Comics", "which", "match", "the", "given", "criteria", "." ]
a27729f070c0a3f14b2d2df3a3961590e2d59cb2
https://github.com/chadicus/marvel-api-client/blob/a27729f070c0a3f14b2d2df3a3961590e2d59cb2/src/Entities/Comic.php#L103-L151