repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
phossa/phossa-cache
src/Phossa/Cache/Driver/CompositeDriver.php
CompositeDriver.has
public function has(/*# string */ $key)/*# : int */ { // try front-end cache first $res = $this->frontHas($key); if ($res) { return $res; } // try backend cache return $this->backHas($key); }
php
public function has(/*# string */ $key)/*# : int */ { // try front-end cache first $res = $this->frontHas($key); if ($res) { return $res; } // try backend cache return $this->backHas($key); }
[ "public", "function", "has", "(", "/*# string */", "$", "key", ")", "/*# : int */", "{", "// try front-end cache first", "$", "res", "=", "$", "this", "->", "frontHas", "(", "$", "key", ")", ";", "if", "(", "$", "res", ")", "{", "return", "$", "res", ";", "}", "// try backend cache", "return", "$", "this", "->", "backHas", "(", "$", "key", ")", ";", "}" ]
Either end has is ok {inheritDoc}
[ "Either", "end", "has", "is", "ok" ]
ad86bee9c5c646fbae09f6f58a346b379d16276e
https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/CompositeDriver.php#L169-L179
train
phossa/phossa-cache
src/Phossa/Cache/Driver/CompositeDriver.php
CompositeDriver.clear
public function clear()/*# : bool */ { $ends = [ $this->front, $this->back ]; foreach ($ends as $end) { if (!$end->clear()) { return $this->falseAndSetError( $end->getError(), $end->getErrorCode() ); } } return $this->trueAndFlushError(); }
php
public function clear()/*# : bool */ { $ends = [ $this->front, $this->back ]; foreach ($ends as $end) { if (!$end->clear()) { return $this->falseAndSetError( $end->getError(), $end->getErrorCode() ); } } return $this->trueAndFlushError(); }
[ "public", "function", "clear", "(", ")", "/*# : bool */", "{", "$", "ends", "=", "[", "$", "this", "->", "front", ",", "$", "this", "->", "back", "]", ";", "foreach", "(", "$", "ends", "as", "$", "end", ")", "{", "if", "(", "!", "$", "end", "->", "clear", "(", ")", ")", "{", "return", "$", "this", "->", "falseAndSetError", "(", "$", "end", "->", "getError", "(", ")", ",", "$", "end", "->", "getErrorCode", "(", ")", ")", ";", "}", "}", "return", "$", "this", "->", "trueAndFlushError", "(", ")", ";", "}" ]
Need both ends clear ok {@inheritDoc}
[ "Need", "both", "ends", "clear", "ok" ]
ad86bee9c5c646fbae09f6f58a346b379d16276e
https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/CompositeDriver.php#L186-L198
train
phossa/phossa-cache
src/Phossa/Cache/Driver/CompositeDriver.php
CompositeDriver.delete
public function delete(/*# string */ $key)/*# : bool */ { $ends = [ $this->front, $this->back ]; foreach ($ends as $end) { if (!$end->delete($key)) { return $this->falseAndSetError( $end->getError(), $end->getErrorCode() ); } } return $this->trueAndFlushError(); }
php
public function delete(/*# string */ $key)/*# : bool */ { $ends = [ $this->front, $this->back ]; foreach ($ends as $end) { if (!$end->delete($key)) { return $this->falseAndSetError( $end->getError(), $end->getErrorCode() ); } } return $this->trueAndFlushError(); }
[ "public", "function", "delete", "(", "/*# string */", "$", "key", ")", "/*# : bool */", "{", "$", "ends", "=", "[", "$", "this", "->", "front", ",", "$", "this", "->", "back", "]", ";", "foreach", "(", "$", "ends", "as", "$", "end", ")", "{", "if", "(", "!", "$", "end", "->", "delete", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "falseAndSetError", "(", "$", "end", "->", "getError", "(", ")", ",", "$", "end", "->", "getErrorCode", "(", ")", ")", ";", "}", "}", "return", "$", "this", "->", "trueAndFlushError", "(", ")", ";", "}" ]
Need both ends delete ok {@inheritDoc}
[ "Need", "both", "ends", "delete", "ok" ]
ad86bee9c5c646fbae09f6f58a346b379d16276e
https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/CompositeDriver.php#L205-L217
train
phossa/phossa-cache
src/Phossa/Cache/Driver/CompositeDriver.php
CompositeDriver.commit
public function commit()/*# : bool */ { $ends = [ $this->front, $this->back ]; $res = false; foreach ($ends as $end) { // commit failed, set error if (!$end->commit()) { $this->setError( $end->getError(), $end->getErrorCode() ); // one commit is ok, then all ok } else { $res = true; } } return $res; }
php
public function commit()/*# : bool */ { $ends = [ $this->front, $this->back ]; $res = false; foreach ($ends as $end) { // commit failed, set error if (!$end->commit()) { $this->setError( $end->getError(), $end->getErrorCode() ); // one commit is ok, then all ok } else { $res = true; } } return $res; }
[ "public", "function", "commit", "(", ")", "/*# : bool */", "{", "$", "ends", "=", "[", "$", "this", "->", "front", ",", "$", "this", "->", "back", "]", ";", "$", "res", "=", "false", ";", "foreach", "(", "$", "ends", "as", "$", "end", ")", "{", "// commit failed, set error", "if", "(", "!", "$", "end", "->", "commit", "(", ")", ")", "{", "$", "this", "->", "setError", "(", "$", "end", "->", "getError", "(", ")", ",", "$", "end", "->", "getErrorCode", "(", ")", ")", ";", "// one commit is ok, then all ok", "}", "else", "{", "$", "res", "=", "true", ";", "}", "}", "return", "$", "res", ";", "}" ]
One end commit ok is ok {@inheritDoc}
[ "One", "end", "commit", "ok", "is", "ok" ]
ad86bee9c5c646fbae09f6f58a346b379d16276e
https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/CompositeDriver.php#L240-L260
train
phossa/phossa-cache
src/Phossa/Cache/Driver/CompositeDriver.php
CompositeDriver.purge
public function purge(/*# int */ $maxlife)/*# : bool */ { $ends = [ $this->front, $this->back ]; foreach ($ends as $end) { if (!$end->purge($maxlife)) { return $this->falseAndSetError( $end->getError(), $end->getErrorCode() ); } } return $this->trueAndFlushError(); }
php
public function purge(/*# int */ $maxlife)/*# : bool */ { $ends = [ $this->front, $this->back ]; foreach ($ends as $end) { if (!$end->purge($maxlife)) { return $this->falseAndSetError( $end->getError(), $end->getErrorCode() ); } } return $this->trueAndFlushError(); }
[ "public", "function", "purge", "(", "/*# int */", "$", "maxlife", ")", "/*# : bool */", "{", "$", "ends", "=", "[", "$", "this", "->", "front", ",", "$", "this", "->", "back", "]", ";", "foreach", "(", "$", "ends", "as", "$", "end", ")", "{", "if", "(", "!", "$", "end", "->", "purge", "(", "$", "maxlife", ")", ")", "{", "return", "$", "this", "->", "falseAndSetError", "(", "$", "end", "->", "getError", "(", ")", ",", "$", "end", "->", "getErrorCode", "(", ")", ")", ";", "}", "}", "return", "$", "this", "->", "trueAndFlushError", "(", ")", ";", "}" ]
Need both ends purge ok {@inheritDoc}
[ "Need", "both", "ends", "purge", "ok" ]
ad86bee9c5c646fbae09f6f58a346b379d16276e
https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/CompositeDriver.php#L267-L279
train
phossa/phossa-cache
src/Phossa/Cache/Driver/CompositeDriver.php
CompositeDriver.protectedSave
protected function protectedSave( CacheItemInterface $item, $function = 'save' )/*# : bool */ { // write to both ? $func = $this->tester; $both = $func($item); // if $both is true, write to front $res1 = false; if ($both) { if ($this->front->$function($item)) { $res1 = true; // ok } else { $this->setError( $this->front->getError(), $this->front->getErrorCode() ); } } // always write to backend $res2 = false; if ($this->back->$function($item)) { $res2 = true; // ok } else { $this->setError( $this->back->getError(), $this->back->getErrorCode() ); } return $res1 || $res2 ? true : false; }
php
protected function protectedSave( CacheItemInterface $item, $function = 'save' )/*# : bool */ { // write to both ? $func = $this->tester; $both = $func($item); // if $both is true, write to front $res1 = false; if ($both) { if ($this->front->$function($item)) { $res1 = true; // ok } else { $this->setError( $this->front->getError(), $this->front->getErrorCode() ); } } // always write to backend $res2 = false; if ($this->back->$function($item)) { $res2 = true; // ok } else { $this->setError( $this->back->getError(), $this->back->getErrorCode() ); } return $res1 || $res2 ? true : false; }
[ "protected", "function", "protectedSave", "(", "CacheItemInterface", "$", "item", ",", "$", "function", "=", "'save'", ")", "/*# : bool */", "{", "// write to both ?", "$", "func", "=", "$", "this", "->", "tester", ";", "$", "both", "=", "$", "func", "(", "$", "item", ")", ";", "// if $both is true, write to front", "$", "res1", "=", "false", ";", "if", "(", "$", "both", ")", "{", "if", "(", "$", "this", "->", "front", "->", "$", "function", "(", "$", "item", ")", ")", "{", "$", "res1", "=", "true", ";", "// ok", "}", "else", "{", "$", "this", "->", "setError", "(", "$", "this", "->", "front", "->", "getError", "(", ")", ",", "$", "this", "->", "front", "->", "getErrorCode", "(", ")", ")", ";", "}", "}", "// always write to backend", "$", "res2", "=", "false", ";", "if", "(", "$", "this", "->", "back", "->", "$", "function", "(", "$", "item", ")", ")", "{", "$", "res2", "=", "true", ";", "// ok", "}", "else", "{", "$", "this", "->", "setError", "(", "$", "this", "->", "back", "->", "getError", "(", ")", ",", "$", "this", "->", "back", "->", "getErrorCode", "(", ")", ")", ";", "}", "return", "$", "res1", "||", "$", "res2", "?", "true", ":", "false", ";", "}" ]
local save method, one end save ok is ok @param CacheItemInterface $item @param string $function save or saveDeferred @return bool @access protected
[ "local", "save", "method", "one", "end", "save", "ok", "is", "ok" ]
ad86bee9c5c646fbae09f6f58a346b379d16276e
https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/CompositeDriver.php#L299-L332
train
PascalKleindienst/simple-api-client
src/Model.php
Model.fill
private function fill($attributes) { // json if (is_string($attributes)) { $attributes = json_decode($attributes, true); } // check if attributes are valid if (!is_array($attributes)) { throw new \InvalidArgumentException('Attributes must be of type array or a valid json string'); } foreach ($attributes as $key => $value) { $this->setAttribute($key, $value); } }
php
private function fill($attributes) { // json if (is_string($attributes)) { $attributes = json_decode($attributes, true); } // check if attributes are valid if (!is_array($attributes)) { throw new \InvalidArgumentException('Attributes must be of type array or a valid json string'); } foreach ($attributes as $key => $value) { $this->setAttribute($key, $value); } }
[ "private", "function", "fill", "(", "$", "attributes", ")", "{", "// json", "if", "(", "is_string", "(", "$", "attributes", ")", ")", "{", "$", "attributes", "=", "json_decode", "(", "$", "attributes", ",", "true", ")", ";", "}", "// check if attributes are valid", "if", "(", "!", "is_array", "(", "$", "attributes", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Attributes must be of type array or a valid json string'", ")", ";", "}", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "setAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Fill the attributes @param string|array $attributes @return void
[ "Fill", "the", "attributes" ]
f4e20aa65bb9c340b8aff78acaede7dc62cd2105
https://github.com/PascalKleindienst/simple-api-client/blob/f4e20aa65bb9c340b8aff78acaede7dc62cd2105/src/Model.php#L35-L50
train
PascalKleindienst/simple-api-client
src/Model.php
Model.makeCollection
public function makeCollection(array $values, $class = null) { $collection = new Collection($values); if (!is_null($class) && class_exists($class)) { $model = new $class(); if ($model instanceof Model) { foreach ($collection as $key => $item) { $collection[$key] = $model->newInstance($item); } } } return $collection; }
php
public function makeCollection(array $values, $class = null) { $collection = new Collection($values); if (!is_null($class) && class_exists($class)) { $model = new $class(); if ($model instanceof Model) { foreach ($collection as $key => $item) { $collection[$key] = $model->newInstance($item); } } } return $collection; }
[ "public", "function", "makeCollection", "(", "array", "$", "values", ",", "$", "class", "=", "null", ")", "{", "$", "collection", "=", "new", "Collection", "(", "$", "values", ")", ";", "if", "(", "!", "is_null", "(", "$", "class", ")", "&&", "class_exists", "(", "$", "class", ")", ")", "{", "$", "model", "=", "new", "$", "class", "(", ")", ";", "if", "(", "$", "model", "instanceof", "Model", ")", "{", "foreach", "(", "$", "collection", "as", "$", "key", "=>", "$", "item", ")", "{", "$", "collection", "[", "$", "key", "]", "=", "$", "model", "->", "newInstance", "(", "$", "item", ")", ";", "}", "}", "}", "return", "$", "collection", ";", "}" ]
Transform an array of values into a collection of models @param array $values @param null $class @return \Illuminate\Support\Collection
[ "Transform", "an", "array", "of", "values", "into", "a", "collection", "of", "models" ]
f4e20aa65bb9c340b8aff78acaede7dc62cd2105
https://github.com/PascalKleindienst/simple-api-client/blob/f4e20aa65bb9c340b8aff78acaede7dc62cd2105/src/Model.php#L161-L176
train
MichaelRShelton/attribute-translator
src/Providers/AttributeTranslatorServiceProvider.php
AttributeTranslatorServiceProvider.registerService
public function registerService() { $this->app->bind('mrs.attributes.translator', function ($attributeMap = []) { return new AttributeTranslator($attributeMap); }); $this->app->alias('mrs.attributes.translator', 'attributes.translator'); $this->app->alias('mrs.attributes.translator', AttributeTranslatorInterface::class); }
php
public function registerService() { $this->app->bind('mrs.attributes.translator', function ($attributeMap = []) { return new AttributeTranslator($attributeMap); }); $this->app->alias('mrs.attributes.translator', 'attributes.translator'); $this->app->alias('mrs.attributes.translator', AttributeTranslatorInterface::class); }
[ "public", "function", "registerService", "(", ")", "{", "$", "this", "->", "app", "->", "bind", "(", "'mrs.attributes.translator'", ",", "function", "(", "$", "attributeMap", "=", "[", "]", ")", "{", "return", "new", "AttributeTranslator", "(", "$", "attributeMap", ")", ";", "}", ")", ";", "$", "this", "->", "app", "->", "alias", "(", "'mrs.attributes.translator'", ",", "'attributes.translator'", ")", ";", "$", "this", "->", "app", "->", "alias", "(", "'mrs.attributes.translator'", ",", "AttributeTranslatorInterface", "::", "class", ")", ";", "}" ]
Register services to the application container.
[ "Register", "services", "to", "the", "application", "container", "." ]
48a0ef01058647eeeeeeb8954f93b479bd713b82
https://github.com/MichaelRShelton/attribute-translator/blob/48a0ef01058647eeeeeeb8954f93b479bd713b82/src/Providers/AttributeTranslatorServiceProvider.php#L46-L53
train
Palmabit-IT/library
src/Palmabit/Library/ImportExport/CsvFileReader.php
CsvFileReader.readElement
public function readElement() { $csv_line_data = $this->spl_file_object->fgetcsv(); if($csv_line_data) { $csv_line_data[0] = $this->convertToUtf8($csv_line_data); if($this->isValidLine($csv_line_data)) { $csv_line = array_combine($this->columns_name, $csv_line_data); // we cast it to StdClass return (object)$csv_line; } } return false; }
php
public function readElement() { $csv_line_data = $this->spl_file_object->fgetcsv(); if($csv_line_data) { $csv_line_data[0] = $this->convertToUtf8($csv_line_data); if($this->isValidLine($csv_line_data)) { $csv_line = array_combine($this->columns_name, $csv_line_data); // we cast it to StdClass return (object)$csv_line; } } return false; }
[ "public", "function", "readElement", "(", ")", "{", "$", "csv_line_data", "=", "$", "this", "->", "spl_file_object", "->", "fgetcsv", "(", ")", ";", "if", "(", "$", "csv_line_data", ")", "{", "$", "csv_line_data", "[", "0", "]", "=", "$", "this", "->", "convertToUtf8", "(", "$", "csv_line_data", ")", ";", "if", "(", "$", "this", "->", "isValidLine", "(", "$", "csv_line_data", ")", ")", "{", "$", "csv_line", "=", "array_combine", "(", "$", "this", "->", "columns_name", ",", "$", "csv_line_data", ")", ";", "// we cast it to StdClass", "return", "(", "object", ")", "$", "csv_line", ";", "}", "}", "return", "false", ";", "}" ]
Reads a single element from the source then return a Object instance @return \StdClass|false object instance
[ "Reads", "a", "single", "element", "from", "the", "source", "then", "return", "a", "Object", "instance" ]
ec49a3c333eb4e94d9610a0f58d82c9ea1ade4b9
https://github.com/Palmabit-IT/library/blob/ec49a3c333eb4e94d9610a0f58d82c9ea1ade4b9/src/Palmabit/Library/ImportExport/CsvFileReader.php#L50-L65
train
Palmabit-IT/library
src/Palmabit/Library/ImportExport/CsvFileReader.php
CsvFileReader.readElements
public function readElements() { $iterator = new ArrayIterator; do { $object = $this->readElement(); if($object) $iterator->append($object); } while((boolean)$object); $this->objects = $iterator; return $this->objects; }
php
public function readElements() { $iterator = new ArrayIterator; do { $object = $this->readElement(); if($object) $iterator->append($object); } while((boolean)$object); $this->objects = $iterator; return $this->objects; }
[ "public", "function", "readElements", "(", ")", "{", "$", "iterator", "=", "new", "ArrayIterator", ";", "do", "{", "$", "object", "=", "$", "this", "->", "readElement", "(", ")", ";", "if", "(", "$", "object", ")", "$", "iterator", "->", "append", "(", "$", "object", ")", ";", "}", "while", "(", "(", "boolean", ")", "$", "object", ")", ";", "$", "this", "->", "objects", "=", "$", "iterator", ";", "return", "$", "this", "->", "objects", ";", "}" ]
Read all the objects from the source @return \ArrayIterator
[ "Read", "all", "the", "objects", "from", "the", "source" ]
ec49a3c333eb4e94d9610a0f58d82c9ea1ade4b9
https://github.com/Palmabit-IT/library/blob/ec49a3c333eb4e94d9610a0f58d82c9ea1ade4b9/src/Palmabit/Library/ImportExport/CsvFileReader.php#L81-L92
train
Aviogram/Common
src/Hydrator/ByConfigBuilder.php
ByConfigBuilder.addField
public function addField($fieldName, $getMethod, $setMethod, ByConfigBuilder $include = null, $formatter = null) { if (method_exists($this->getEntityPrototype(), $getMethod) === false) { throw new Exception\ConfigFailed(sprintf($this->exceptions[2], $getMethod, $this->entityClassName), 2); } if (method_exists($this->getEntityPrototype(), $setMethod) === false) { throw new Exception\ConfigFailed(sprintf($this->exceptions[2], $setMethod, $this->entityClassName), 2); } $this->mapping[$fieldName] = array( 'getter' => $getMethod, 'setter' => $setMethod, 'include' => $include, 'formatter' => $formatter, ); return $this; }
php
public function addField($fieldName, $getMethod, $setMethod, ByConfigBuilder $include = null, $formatter = null) { if (method_exists($this->getEntityPrototype(), $getMethod) === false) { throw new Exception\ConfigFailed(sprintf($this->exceptions[2], $getMethod, $this->entityClassName), 2); } if (method_exists($this->getEntityPrototype(), $setMethod) === false) { throw new Exception\ConfigFailed(sprintf($this->exceptions[2], $setMethod, $this->entityClassName), 2); } $this->mapping[$fieldName] = array( 'getter' => $getMethod, 'setter' => $setMethod, 'include' => $include, 'formatter' => $formatter, ); return $this; }
[ "public", "function", "addField", "(", "$", "fieldName", ",", "$", "getMethod", ",", "$", "setMethod", ",", "ByConfigBuilder", "$", "include", "=", "null", ",", "$", "formatter", "=", "null", ")", "{", "if", "(", "method_exists", "(", "$", "this", "->", "getEntityPrototype", "(", ")", ",", "$", "getMethod", ")", "===", "false", ")", "{", "throw", "new", "Exception", "\\", "ConfigFailed", "(", "sprintf", "(", "$", "this", "->", "exceptions", "[", "2", "]", ",", "$", "getMethod", ",", "$", "this", "->", "entityClassName", ")", ",", "2", ")", ";", "}", "if", "(", "method_exists", "(", "$", "this", "->", "getEntityPrototype", "(", ")", ",", "$", "setMethod", ")", "===", "false", ")", "{", "throw", "new", "Exception", "\\", "ConfigFailed", "(", "sprintf", "(", "$", "this", "->", "exceptions", "[", "2", "]", ",", "$", "setMethod", ",", "$", "this", "->", "entityClassName", ")", ",", "2", ")", ";", "}", "$", "this", "->", "mapping", "[", "$", "fieldName", "]", "=", "array", "(", "'getter'", "=>", "$", "getMethod", ",", "'setter'", "=>", "$", "setMethod", ",", "'include'", "=>", "$", "include", ",", "'formatter'", "=>", "$", "formatter", ",", ")", ";", "return", "$", "this", ";", "}" ]
Set a mapping @param string $fieldName @param string $getMethod @param string $setMethod @param ByConfigBuilder $include @param Closure $formatter @return $this
[ "Set", "a", "mapping" ]
bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5
https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/Hydrator/ByConfigBuilder.php#L91-L109
train
Aviogram/Common
src/Hydrator/ByConfigBuilder.php
ByConfigBuilder.isInclude
public function isInclude($fieldName) { if ($this->hasField($fieldName) === false) { return false; } $class = __CLASS__; return ($this->mapping[$fieldName]['include'] instanceof $class); }
php
public function isInclude($fieldName) { if ($this->hasField($fieldName) === false) { return false; } $class = __CLASS__; return ($this->mapping[$fieldName]['include'] instanceof $class); }
[ "public", "function", "isInclude", "(", "$", "fieldName", ")", "{", "if", "(", "$", "this", "->", "hasField", "(", "$", "fieldName", ")", "===", "false", ")", "{", "return", "false", ";", "}", "$", "class", "=", "__CLASS__", ";", "return", "(", "$", "this", "->", "mapping", "[", "$", "fieldName", "]", "[", "'include'", "]", "instanceof", "$", "class", ")", ";", "}" ]
Check if the given fieldName is an include @param string $fieldName @return bool TRUE on include | FALSE when field does not exists or field is not a include
[ "Check", "if", "the", "given", "fieldName", "is", "an", "include" ]
bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5
https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/Hydrator/ByConfigBuilder.php#L130-L139
train
Aviogram/Common
src/Hydrator/ByConfigBuilder.php
ByConfigBuilder.getSetter
public function getSetter($fieldName) { if ($this->hasField($fieldName) === false) { return false; } return $this->mapping[$fieldName]['setter']; }
php
public function getSetter($fieldName) { if ($this->hasField($fieldName) === false) { return false; } return $this->mapping[$fieldName]['setter']; }
[ "public", "function", "getSetter", "(", "$", "fieldName", ")", "{", "if", "(", "$", "this", "->", "hasField", "(", "$", "fieldName", ")", "===", "false", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "mapping", "[", "$", "fieldName", "]", "[", "'setter'", "]", ";", "}" ]
Return the setter name @param string $fieldName @return string | bool FALSE when field does not exists
[ "Return", "the", "setter", "name" ]
bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5
https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/Hydrator/ByConfigBuilder.php#L148-L155
train
Aviogram/Common
src/Hydrator/ByConfigBuilder.php
ByConfigBuilder.getGetter
public function getGetter($fieldName) { if ($this->hasField($fieldName) === false) { return false; } return $this->mapping[$fieldName]['getter']; }
php
public function getGetter($fieldName) { if ($this->hasField($fieldName) === false) { return false; } return $this->mapping[$fieldName]['getter']; }
[ "public", "function", "getGetter", "(", "$", "fieldName", ")", "{", "if", "(", "$", "this", "->", "hasField", "(", "$", "fieldName", ")", "===", "false", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "mapping", "[", "$", "fieldName", "]", "[", "'getter'", "]", ";", "}" ]
Return the getter name @param string $fieldName @return string | bool FALSE when field does not exists
[ "Return", "the", "getter", "name" ]
bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5
https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/Hydrator/ByConfigBuilder.php#L164-L171
train
Aviogram/Common
src/Hydrator/ByConfigBuilder.php
ByConfigBuilder.getInclude
public function getInclude($fieldName) { if ($this->isInclude($fieldName) === false) { return false; } return $this->mapping[$fieldName]['include']; }
php
public function getInclude($fieldName) { if ($this->isInclude($fieldName) === false) { return false; } return $this->mapping[$fieldName]['include']; }
[ "public", "function", "getInclude", "(", "$", "fieldName", ")", "{", "if", "(", "$", "this", "->", "isInclude", "(", "$", "fieldName", ")", "===", "false", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "mapping", "[", "$", "fieldName", "]", "[", "'include'", "]", ";", "}" ]
Get the include config @param string $fieldName @return ByConfigBuilder | bool FALSE when fieldName is not a include
[ "Get", "the", "include", "config" ]
bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5
https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/Hydrator/ByConfigBuilder.php#L180-L187
train
Aviogram/Common
src/Hydrator/ByConfigBuilder.php
ByConfigBuilder.setCatchAllSetter
public function setCatchAllSetter($setMethod) { if (method_exists($this->getEntityPrototype(), $setMethod) === false) { throw new Exception\ConfigFailed(sprintf($this->exceptions[2], $setMethod, $this->entityClassName), 2); } $this->catchAllSetter = $setMethod; return $this; }
php
public function setCatchAllSetter($setMethod) { if (method_exists($this->getEntityPrototype(), $setMethod) === false) { throw new Exception\ConfigFailed(sprintf($this->exceptions[2], $setMethod, $this->entityClassName), 2); } $this->catchAllSetter = $setMethod; return $this; }
[ "public", "function", "setCatchAllSetter", "(", "$", "setMethod", ")", "{", "if", "(", "method_exists", "(", "$", "this", "->", "getEntityPrototype", "(", ")", ",", "$", "setMethod", ")", "===", "false", ")", "{", "throw", "new", "Exception", "\\", "ConfigFailed", "(", "sprintf", "(", "$", "this", "->", "exceptions", "[", "2", "]", ",", "$", "setMethod", ",", "$", "this", "->", "entityClassName", ")", ",", "2", ")", ";", "}", "$", "this", "->", "catchAllSetter", "=", "$", "setMethod", ";", "return", "$", "this", ";", "}" ]
Sets an catchall Setter @param string $setMethod @return $this
[ "Sets", "an", "catchall", "Setter" ]
bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5
https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/Hydrator/ByConfigBuilder.php#L244-L253
train
ScaraMVC/Framework
src/Scara/Session/SessionInitializer.php
SessionInitializer.init
public static function init() { $c = new Configuration(); $cc = $c->from('app')->get('session'); if (strtolower($cc) == 'session') { return new Session(); } elseif (strtolower($cc) == 'file') { return new File(); } elseif (strtolower($cc) == 'cookie') { return new Cookie(); } else { throw new \Exception($cc.' is not a supported session type!'); } }
php
public static function init() { $c = new Configuration(); $cc = $c->from('app')->get('session'); if (strtolower($cc) == 'session') { return new Session(); } elseif (strtolower($cc) == 'file') { return new File(); } elseif (strtolower($cc) == 'cookie') { return new Cookie(); } else { throw new \Exception($cc.' is not a supported session type!'); } }
[ "public", "static", "function", "init", "(", ")", "{", "$", "c", "=", "new", "Configuration", "(", ")", ";", "$", "cc", "=", "$", "c", "->", "from", "(", "'app'", ")", "->", "get", "(", "'session'", ")", ";", "if", "(", "strtolower", "(", "$", "cc", ")", "==", "'session'", ")", "{", "return", "new", "Session", "(", ")", ";", "}", "elseif", "(", "strtolower", "(", "$", "cc", ")", "==", "'file'", ")", "{", "return", "new", "File", "(", ")", ";", "}", "elseif", "(", "strtolower", "(", "$", "cc", ")", "==", "'cookie'", ")", "{", "return", "new", "Cookie", "(", ")", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "$", "cc", ".", "' is not a supported session type!'", ")", ";", "}", "}" ]
Initializes session handler. @return mixed
[ "Initializes", "session", "handler", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Session/SessionInitializer.php#L17-L31
train
kambalabs/KmbPuppetDb
src/KmbPuppetDb/Service/Node.php
Node.getByName
public function getByName($name) { $response = $this->getPuppetDbClient()->send(new KmbPuppetDb\Request('/nodes/' . $name)); return $this->createNodeFromData($response->getData()); }
php
public function getByName($name) { $response = $this->getPuppetDbClient()->send(new KmbPuppetDb\Request('/nodes/' . $name)); return $this->createNodeFromData($response->getData()); }
[ "public", "function", "getByName", "(", "$", "name", ")", "{", "$", "response", "=", "$", "this", "->", "getPuppetDbClient", "(", ")", "->", "send", "(", "new", "KmbPuppetDb", "\\", "Request", "(", "'/nodes/'", ".", "$", "name", ")", ")", ";", "return", "$", "this", "->", "createNodeFromData", "(", "$", "response", "->", "getData", "(", ")", ")", ";", "}" ]
Retrieves a node by its name. @param string $name @return Model\NodeInterface @throws InvalidArgumentException
[ "Retrieves", "a", "node", "by", "its", "name", "." ]
df56a275cf00f4402cf121a2e99149168f1f8b2d
https://github.com/kambalabs/KmbPuppetDb/blob/df56a275cf00f4402cf121a2e99149168f1f8b2d/src/KmbPuppetDb/Service/Node.php#L59-L63
train
romm/configuration_object
Classes/Core/Service/CacheService.php
CacheService.registerInternalCache
public function registerInternalCache() { $cacheManager = $this->getCacheManager(); if (false === $cacheManager->hasCache(self::CACHE_IDENTIFIER)) { $cacheManager->setCacheConfigurations([self::CACHE_IDENTIFIER => $this->cacheOptions]); } }
php
public function registerInternalCache() { $cacheManager = $this->getCacheManager(); if (false === $cacheManager->hasCache(self::CACHE_IDENTIFIER)) { $cacheManager->setCacheConfigurations([self::CACHE_IDENTIFIER => $this->cacheOptions]); } }
[ "public", "function", "registerInternalCache", "(", ")", "{", "$", "cacheManager", "=", "$", "this", "->", "getCacheManager", "(", ")", ";", "if", "(", "false", "===", "$", "cacheManager", "->", "hasCache", "(", "self", "::", "CACHE_IDENTIFIER", ")", ")", "{", "$", "cacheManager", "->", "setCacheConfigurations", "(", "[", "self", "::", "CACHE_IDENTIFIER", "=>", "$", "this", "->", "cacheOptions", "]", ")", ";", "}", "}" ]
Function called from `ext_localconf` file which will register the internal cache earlier. @internal
[ "Function", "called", "from", "ext_localconf", "file", "which", "will", "register", "the", "internal", "cache", "earlier", "." ]
d3a40903386c2e0766bd8279337fe6da45cf5ce3
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Core/Service/CacheService.php#L50-L57
train
romm/configuration_object
Classes/Core/Service/CacheService.php
CacheService.registerDynamicCaches
public function registerDynamicCaches() { $dynamicCaches = $this->getCache()->getByTag(self::CACHE_TAG_DYNAMIC_CACHE); foreach ($dynamicCaches as $cacheData) { $identifier = $cacheData['identifier']; $options = $cacheData['options']; $this->registerCacheInternal($identifier, $options); } }
php
public function registerDynamicCaches() { $dynamicCaches = $this->getCache()->getByTag(self::CACHE_TAG_DYNAMIC_CACHE); foreach ($dynamicCaches as $cacheData) { $identifier = $cacheData['identifier']; $options = $cacheData['options']; $this->registerCacheInternal($identifier, $options); } }
[ "public", "function", "registerDynamicCaches", "(", ")", "{", "$", "dynamicCaches", "=", "$", "this", "->", "getCache", "(", ")", "->", "getByTag", "(", "self", "::", "CACHE_TAG_DYNAMIC_CACHE", ")", ";", "foreach", "(", "$", "dynamicCaches", "as", "$", "cacheData", ")", "{", "$", "identifier", "=", "$", "cacheData", "[", "'identifier'", "]", ";", "$", "options", "=", "$", "cacheData", "[", "'options'", "]", ";", "$", "this", "->", "registerCacheInternal", "(", "$", "identifier", ",", "$", "options", ")", ";", "}", "}" ]
This function will take care of initializing all caches that were defined previously by the `CacheService` which allows dynamic caches to be used for every configuration object type. @see \Romm\ConfigurationObject\Service\Items\Cache\CacheService::initialize() @internal
[ "This", "function", "will", "take", "care", "of", "initializing", "all", "caches", "that", "were", "defined", "previously", "by", "the", "CacheService", "which", "allows", "dynamic", "caches", "to", "be", "used", "for", "every", "configuration", "object", "type", "." ]
d3a40903386c2e0766bd8279337fe6da45cf5ce3
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Core/Service/CacheService.php#L67-L77
train
Wedeto/HTML
src/AssetManager.php
AssetManager.injectInstance
public static function injectInstance(Resolver $resolver) { $sub = $resolver->getResolver('assets'); return $sub !== null ? new static($sub) : null; }
php
public static function injectInstance(Resolver $resolver) { $sub = $resolver->getResolver('assets'); return $sub !== null ? new static($sub) : null; }
[ "public", "static", "function", "injectInstance", "(", "Resolver", "$", "resolver", ")", "{", "$", "sub", "=", "$", "resolver", "->", "getResolver", "(", "'assets'", ")", ";", "return", "$", "sub", "!==", "null", "?", "new", "static", "(", "$", "sub", ")", ":", "null", ";", "}" ]
Generate an instance for the injector
[ "Generate", "an", "instance", "for", "the", "injector" ]
9e725288098c42d0d2953a929faebe628ff4e389
https://github.com/Wedeto/HTML/blob/9e725288098c42d0d2953a929faebe628ff4e389/src/AssetManager.php#L96-L100
train
Wedeto/HTML
src/AssetManager.php
AssetManager.addScript
public function addScript(string $script, $depends = null) { $script = $this->stripSuffix($script, ".min", ".js"); $this->scripts[$script] = array("path" => $script, "depends" => $depends); return $this; }
php
public function addScript(string $script, $depends = null) { $script = $this->stripSuffix($script, ".min", ".js"); $this->scripts[$script] = array("path" => $script, "depends" => $depends); return $this; }
[ "public", "function", "addScript", "(", "string", "$", "script", ",", "$", "depends", "=", "null", ")", "{", "$", "script", "=", "$", "this", "->", "stripSuffix", "(", "$", "script", ",", "\".min\"", ",", "\".js\"", ")", ";", "$", "this", "->", "scripts", "[", "$", "script", "]", "=", "array", "(", "\"path\"", "=>", "$", "script", ",", "\"depends\"", "=>", "$", "depends", ")", ";", "return", "$", "this", ";", "}" ]
Add a javascript file to be loaded. This will strip the .min and .js suffixes and add them to the stack of included scripts. @param string $script The script to be loaded @return AssetManager Provides fluent interface
[ "Add", "a", "javascript", "file", "to", "be", "loaded", ".", "This", "will", "strip", "the", ".", "min", "and", ".", "js", "suffixes", "and", "add", "them", "to", "the", "stack", "of", "included", "scripts", "." ]
9e725288098c42d0d2953a929faebe628ff4e389
https://github.com/Wedeto/HTML/blob/9e725288098c42d0d2953a929faebe628ff4e389/src/AssetManager.php#L167-L172
train
Wedeto/HTML
src/AssetManager.php
AssetManager.addCSS
public function addCSS(string $stylesheet, $media = "screen") { $stylesheet = $this->stripSuffix($stylesheet, ".min", ".css"); $this->CSS[$stylesheet] = array("path" => $stylesheet, "media" => $media); return $this; }
php
public function addCSS(string $stylesheet, $media = "screen") { $stylesheet = $this->stripSuffix($stylesheet, ".min", ".css"); $this->CSS[$stylesheet] = array("path" => $stylesheet, "media" => $media); return $this; }
[ "public", "function", "addCSS", "(", "string", "$", "stylesheet", ",", "$", "media", "=", "\"screen\"", ")", "{", "$", "stylesheet", "=", "$", "this", "->", "stripSuffix", "(", "$", "stylesheet", ",", "\".min\"", ",", "\".css\"", ")", ";", "$", "this", "->", "CSS", "[", "$", "stylesheet", "]", "=", "array", "(", "\"path\"", "=>", "$", "stylesheet", ",", "\"media\"", "=>", "$", "media", ")", ";", "return", "$", "this", ";", "}" ]
Add a CSS stylesheet to be loaded. This will strip the .min and .css suffixes and add them to the stack of included stylesheets. @param string $style The style sheet to be loaded @return AssetManager Provides fluent interface
[ "Add", "a", "CSS", "stylesheet", "to", "be", "loaded", ".", "This", "will", "strip", "the", ".", "min", "and", ".", "css", "suffixes", "and", "add", "them", "to", "the", "stack", "of", "included", "stylesheets", "." ]
9e725288098c42d0d2953a929faebe628ff4e389
https://github.com/Wedeto/HTML/blob/9e725288098c42d0d2953a929faebe628ff4e389/src/AssetManager.php#L189-L194
train
Wedeto/HTML
src/AssetManager.php
AssetManager.addVariable
public function addVariable(string $name, $value) { // Convert value to something usable in the output if (WF::is_array_like($value)) { $value = WF::to_array($value); } elseif (is_subclass_of($value, JSONSerializable::class)) { $value = $value->jsonSerialize(); } elseif (!is_scalar($value)) { throw new InvalidArgumentException("Invalid value provided for JS variable $name"); } $this->inline_variables[$name] = $value; return $this; }
php
public function addVariable(string $name, $value) { // Convert value to something usable in the output if (WF::is_array_like($value)) { $value = WF::to_array($value); } elseif (is_subclass_of($value, JSONSerializable::class)) { $value = $value->jsonSerialize(); } elseif (!is_scalar($value)) { throw new InvalidArgumentException("Invalid value provided for JS variable $name"); } $this->inline_variables[$name] = $value; return $this; }
[ "public", "function", "addVariable", "(", "string", "$", "name", ",", "$", "value", ")", "{", "// Convert value to something usable in the output", "if", "(", "WF", "::", "is_array_like", "(", "$", "value", ")", ")", "{", "$", "value", "=", "WF", "::", "to_array", "(", "$", "value", ")", ";", "}", "elseif", "(", "is_subclass_of", "(", "$", "value", ",", "JSONSerializable", "::", "class", ")", ")", "{", "$", "value", "=", "$", "value", "->", "jsonSerialize", "(", ")", ";", "}", "elseif", "(", "!", "is_scalar", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Invalid value provided for JS variable $name\"", ")", ";", "}", "$", "this", "->", "inline_variables", "[", "$", "name", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Add a javascript variable to be added to the output document. A script will be generated to definie these variables on page load. @param string $name The name of the variable. Must be a valid javascript variable name. @param mixed The value to set. Should be scalar, array or JSONSerializable
[ "Add", "a", "javascript", "variable", "to", "be", "added", "to", "the", "output", "document", ".", "A", "script", "will", "be", "generated", "to", "definie", "these", "variables", "on", "page", "load", "." ]
9e725288098c42d0d2953a929faebe628ff4e389
https://github.com/Wedeto/HTML/blob/9e725288098c42d0d2953a929faebe628ff4e389/src/AssetManager.php#L231-L249
train
Wedeto/HTML
src/AssetManager.php
AssetManager.stripSuffix
protected function stripSuffix(string $path, string $suffix1, string $suffix2) { if (substr($path, -strlen($suffix2)) === $suffix2) $path = substr($path, 0, -strlen($suffix2)); if (substr($path, -strlen($suffix1)) === $suffix1) $path = substr($path, 0, -strlen($suffix1)); return $path; }
php
protected function stripSuffix(string $path, string $suffix1, string $suffix2) { if (substr($path, -strlen($suffix2)) === $suffix2) $path = substr($path, 0, -strlen($suffix2)); if (substr($path, -strlen($suffix1)) === $suffix1) $path = substr($path, 0, -strlen($suffix1)); return $path; }
[ "protected", "function", "stripSuffix", "(", "string", "$", "path", ",", "string", "$", "suffix1", ",", "string", "$", "suffix2", ")", "{", "if", "(", "substr", "(", "$", "path", ",", "-", "strlen", "(", "$", "suffix2", ")", ")", "===", "$", "suffix2", ")", "$", "path", "=", "substr", "(", "$", "path", ",", "0", ",", "-", "strlen", "(", "$", "suffix2", ")", ")", ";", "if", "(", "substr", "(", "$", "path", ",", "-", "strlen", "(", "$", "suffix1", ")", ")", "===", "$", "suffix1", ")", "$", "path", "=", "substr", "(", "$", "path", ",", "0", ",", "-", "strlen", "(", "$", "suffix1", ")", ")", ";", "return", "$", "path", ";", "}" ]
Remove the suffix from a file name, such as .min.css or .min.js @param string $path The file to strip @param string $suffix1 One suffix to strip. This one is stripped after the second, so it should come second-last. This probably should be .min @param string $suffix2 Another suffix to strip. This one is stripped from the right first, so it should come last in the file name. This probably should be .js or .css @return string The stripped file name.
[ "Remove", "the", "suffix", "from", "a", "file", "name", "such", "as", ".", "min", ".", "css", "or", ".", "min", ".", "js" ]
9e725288098c42d0d2953a929faebe628ff4e389
https://github.com/Wedeto/HTML/blob/9e725288098c42d0d2953a929faebe628ff4e389/src/AssetManager.php#L270-L277
train
Wedeto/HTML
src/AssetManager.php
AssetManager.executeHook
public function executeHook(Dictionary $params) { $responder = $params['responder'] ?? null; $mime = $params['mime'] ?? null; $result = empty($responder) ? null : $responder->getResult(); $response = empty($result) ? null : $result->getResponse(); if ($response instanceof HTTPError) $response = $response->getResponse(); if ($response instanceof StringResponse && $mime === "text/html") { $output = $response->getOutput($mime); $output = $this->replaceTokens($output); $response->setOutput($output, $mime); } }
php
public function executeHook(Dictionary $params) { $responder = $params['responder'] ?? null; $mime = $params['mime'] ?? null; $result = empty($responder) ? null : $responder->getResult(); $response = empty($result) ? null : $result->getResponse(); if ($response instanceof HTTPError) $response = $response->getResponse(); if ($response instanceof StringResponse && $mime === "text/html") { $output = $response->getOutput($mime); $output = $this->replaceTokens($output); $response->setOutput($output, $mime); } }
[ "public", "function", "executeHook", "(", "Dictionary", "$", "params", ")", "{", "$", "responder", "=", "$", "params", "[", "'responder'", "]", "??", "null", ";", "$", "mime", "=", "$", "params", "[", "'mime'", "]", "??", "null", ";", "$", "result", "=", "empty", "(", "$", "responder", ")", "?", "null", ":", "$", "responder", "->", "getResult", "(", ")", ";", "$", "response", "=", "empty", "(", "$", "result", ")", "?", "null", ":", "$", "result", "->", "getResponse", "(", ")", ";", "if", "(", "$", "response", "instanceof", "HTTPError", ")", "$", "response", "=", "$", "response", "->", "getResponse", "(", ")", ";", "if", "(", "$", "response", "instanceof", "StringResponse", "&&", "$", "mime", "===", "\"text/html\"", ")", "{", "$", "output", "=", "$", "response", "->", "getOutput", "(", "$", "mime", ")", ";", "$", "output", "=", "$", "this", "->", "replaceTokens", "(", "$", "output", ")", ";", "$", "response", "->", "setOutput", "(", "$", "output", ",", "$", "mime", ")", ";", "}", "}" ]
Execute the hook to replace the Javascript and CSS tokens in the HTTP Responder. This will be called by Wedeto\Util\Hook through Wedeto\HTTP. It can be called directly when you want to replace the content at a different time. @param Dictionary $params The parameters. Should contain a key 'response' and 'mime'. The res
[ "Execute", "the", "hook", "to", "replace", "the", "Javascript", "and", "CSS", "tokens", "in", "the", "HTTP", "Responder", ".", "This", "will", "be", "called", "by", "Wedeto", "\\", "Util", "\\", "Hook", "through", "Wedeto", "\\", "HTTP", ".", "It", "can", "be", "called", "directly", "when", "you", "want", "to", "replace", "the", "content", "at", "a", "different", "time", "." ]
9e725288098c42d0d2953a929faebe628ff4e389
https://github.com/Wedeto/HTML/blob/9e725288098c42d0d2953a929faebe628ff4e389/src/AssetManager.php#L529-L546
train
Ydle/HubBundle
Controller/RestRoomController.php
RestRoomController.getRoomsListAction
public function getRoomsListAction(ParamFetcher $paramFetcher) { $page = $paramFetcher->get('page'); $count = $paramFetcher->get('count'); $pager = $this->getRoomManager()->getPager($this->filterCriteria($paramFetcher), $page, $count); return $pager; }
php
public function getRoomsListAction(ParamFetcher $paramFetcher) { $page = $paramFetcher->get('page'); $count = $paramFetcher->get('count'); $pager = $this->getRoomManager()->getPager($this->filterCriteria($paramFetcher), $page, $count); return $pager; }
[ "public", "function", "getRoomsListAction", "(", "ParamFetcher", "$", "paramFetcher", ")", "{", "$", "page", "=", "$", "paramFetcher", "->", "get", "(", "'page'", ")", ";", "$", "count", "=", "$", "paramFetcher", "->", "get", "(", "'count'", ")", ";", "$", "pager", "=", "$", "this", "->", "getRoomManager", "(", ")", "->", "getPager", "(", "$", "this", "->", "filterCriteria", "(", "$", "paramFetcher", ")", ",", "$", "page", ",", "$", "count", ")", ";", "return", "$", "pager", ";", "}" ]
Retrieve the list of available rooms @QueryParam(name="page", requirements="\d+", default="0", description="Number of page") @QueryParam(name="count", requirements="\d+", default="0", description="Number of room by page") @param ParamFetcher $paramFetcher
[ "Retrieve", "the", "list", "of", "available", "rooms" ]
7fa423241246bcfd115f2ed3ad3997b4b63adb01
https://github.com/Ydle/HubBundle/blob/7fa423241246bcfd115f2ed3ad3997b4b63adb01/Controller/RestRoomController.php#L38-L46
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.query
public function query($statement, $params=array()) { if (!is_array($params)) { $params = array($params); } return $this->_link->query($statement, $params); }
php
public function query($statement, $params=array()) { if (!is_array($params)) { $params = array($params); } return $this->_link->query($statement, $params); }
[ "public", "function", "query", "(", "$", "statement", ",", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "params", ")", ")", "{", "$", "params", "=", "array", "(", "$", "params", ")", ";", "}", "return", "$", "this", "->", "_link", "->", "query", "(", "$", "statement", ",", "$", "params", ")", ";", "}" ]
Run database query and return complete result set This method is intended to be used internally by NADA. Application code should preferrably use methods from the underlying database abstraction layer. This method is intended for SELECT and similar commands that return a result set. The result is returned as a 2-dimensional array. The outer array is numeric and contains the rows. The rows are associative arrays with lowercase column identifiers as keys. @param string $statement SQL statement with optional placeholders @param mixed $params Single value or array of values to substitute for placeholders @return array Array of all rows @internal
[ "Run", "database", "query", "and", "return", "complete", "result", "set" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L196-L202
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.exec
public function exec($statement, $params=array()) { if (!is_array($params)) { $params = array($params); } return $this->_link->exec($statement, $params); }
php
public function exec($statement, $params=array()) { if (!is_array($params)) { $params = array($params); } return $this->_link->exec($statement, $params); }
[ "public", "function", "exec", "(", "$", "statement", ",", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "params", ")", ")", "{", "$", "params", "=", "array", "(", "$", "params", ")", ";", "}", "return", "$", "this", "->", "_link", "->", "exec", "(", "$", "statement", ",", "$", "params", ")", ";", "}" ]
Execute a database statement that does not return a result set This method is intended to be used internally by NADA. Application code should preferrably use methods from the underlying database abstraction layer. SQL commands like UPDATE, INSERT, DELETE, SET etc. don't return a result set. This method is intended for this type of commands. The return value is typically the number of affected rows. @param string $statement SQL statement with optional placeholders @param mixed $params Single value or array of values to substitute for placeholders @return integer Number of affected rows @internal
[ "Execute", "a", "database", "statement", "that", "does", "not", "return", "a", "result", "set" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L220-L226
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.prepareValue
public function prepareValue($value, $datatype) { if ($value === null) { return 'NULL'; } switch ($datatype) { case Column::TYPE_INTEGER: // Filter explicitly because some DBAL silently convert/truncate to integer $filtered = filter_var($value, FILTER_VALIDATE_INT); if ($filtered === false) { throw new \InvalidArgumentException('Not an integer: '. $value); } return $filtered; // No quotes necessary case Column::TYPE_FLOAT: case Column::TYPE_DECIMAL: // Filter explicitly because some DBAL silently convert/truncate to float $filtered = filter_var($value, FILTER_VALIDATE_FLOAT); if ($filtered === false) { throw new \InvalidArgumentException('Not a number: '. $value); } return $filtered; // No quotes necessary case Column::TYPE_BOOL: if (is_bool($value)) { // filter_var() does not work with real booleans $filtered = $value; } else { $filtered = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } if ($filtered === null) { throw new \InvalidArgumentException('Not a boolean: ' . $value); } return (integer)$filtered; // Convert to 0/1 for compatibility with emulated booleans case Column::TYPE_BLOB: // Handled differently across DBMS and abstraction layers - refuse by default. throw new \InvalidArgumentException('Cannot prepare BLOB values'); default: return $this->_link->quoteValue($value, $datatype); } }
php
public function prepareValue($value, $datatype) { if ($value === null) { return 'NULL'; } switch ($datatype) { case Column::TYPE_INTEGER: // Filter explicitly because some DBAL silently convert/truncate to integer $filtered = filter_var($value, FILTER_VALIDATE_INT); if ($filtered === false) { throw new \InvalidArgumentException('Not an integer: '. $value); } return $filtered; // No quotes necessary case Column::TYPE_FLOAT: case Column::TYPE_DECIMAL: // Filter explicitly because some DBAL silently convert/truncate to float $filtered = filter_var($value, FILTER_VALIDATE_FLOAT); if ($filtered === false) { throw new \InvalidArgumentException('Not a number: '. $value); } return $filtered; // No quotes necessary case Column::TYPE_BOOL: if (is_bool($value)) { // filter_var() does not work with real booleans $filtered = $value; } else { $filtered = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } if ($filtered === null) { throw new \InvalidArgumentException('Not a boolean: ' . $value); } return (integer)$filtered; // Convert to 0/1 for compatibility with emulated booleans case Column::TYPE_BLOB: // Handled differently across DBMS and abstraction layers - refuse by default. throw new \InvalidArgumentException('Cannot prepare BLOB values'); default: return $this->_link->quoteValue($value, $datatype); } }
[ "public", "function", "prepareValue", "(", "$", "value", ",", "$", "datatype", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "'NULL'", ";", "}", "switch", "(", "$", "datatype", ")", "{", "case", "Column", "::", "TYPE_INTEGER", ":", "// Filter explicitly because some DBAL silently convert/truncate to integer", "$", "filtered", "=", "filter_var", "(", "$", "value", ",", "FILTER_VALIDATE_INT", ")", ";", "if", "(", "$", "filtered", "===", "false", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Not an integer: '", ".", "$", "value", ")", ";", "}", "return", "$", "filtered", ";", "// No quotes necessary", "case", "Column", "::", "TYPE_FLOAT", ":", "case", "Column", "::", "TYPE_DECIMAL", ":", "// Filter explicitly because some DBAL silently convert/truncate to float", "$", "filtered", "=", "filter_var", "(", "$", "value", ",", "FILTER_VALIDATE_FLOAT", ")", ";", "if", "(", "$", "filtered", "===", "false", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Not a number: '", ".", "$", "value", ")", ";", "}", "return", "$", "filtered", ";", "// No quotes necessary", "case", "Column", "::", "TYPE_BOOL", ":", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "// filter_var() does not work with real booleans", "$", "filtered", "=", "$", "value", ";", "}", "else", "{", "$", "filtered", "=", "filter_var", "(", "$", "value", ",", "FILTER_VALIDATE_BOOLEAN", ",", "FILTER_NULL_ON_FAILURE", ")", ";", "}", "if", "(", "$", "filtered", "===", "null", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Not a boolean: '", ".", "$", "value", ")", ";", "}", "return", "(", "integer", ")", "$", "filtered", ";", "// Convert to 0/1 for compatibility with emulated booleans", "case", "Column", "::", "TYPE_BLOB", ":", "// Handled differently across DBMS and abstraction layers - refuse by default.", "throw", "new", "\\", "InvalidArgumentException", "(", "'Cannot prepare BLOB values'", ")", ";", "default", ":", "return", "$", "this", "->", "_link", "->", "quoteValue", "(", "$", "value", ",", "$", "datatype", ")", ";", "}", "}" ]
Prepare a literal value for insertion into an SQL statement @param mixed $value Value to prepare @param string $datatype The value's datatype @return string Value, processed, quoted and escaped if necessary
[ "Prepare", "a", "literal", "value", "for", "insertion", "into", "an", "SQL", "statement" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L464-L501
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.getName
public function getName() { if (!$this->_name) { $result = $this->query( 'select catalog_name from information_schema.information_schema_catalog_name' ); $this->_name = $result[0]['catalog_name']; } return $this->_name; }
php
public function getName() { if (!$this->_name) { $result = $this->query( 'select catalog_name from information_schema.information_schema_catalog_name' ); $this->_name = $result[0]['catalog_name']; } return $this->_name; }
[ "public", "function", "getName", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_name", ")", "{", "$", "result", "=", "$", "this", "->", "query", "(", "'select catalog_name from information_schema.information_schema_catalog_name'", ")", ";", "$", "this", "->", "_name", "=", "$", "result", "[", "0", "]", "[", "'catalog_name'", "]", ";", "}", "return", "$", "this", "->", "_name", ";", "}" ]
Return name of the database that the current connection points to @return string Database name
[ "Return", "name", "of", "the", "database", "that", "the", "current", "connection", "points", "to" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L535-L544
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.getTable
public function getTable($name) { if ($name != strtolower($name)) { throw new \DomainException('Table name must be lowercase: ' . $name); } if (!isset($this->_tables[$name])) { $class = 'Nada\Table\\' . $this->getDbmsSuffix(); $this->_tables[$name] = new $class($this, $name); } return $this->_tables[$name]; }
php
public function getTable($name) { if ($name != strtolower($name)) { throw new \DomainException('Table name must be lowercase: ' . $name); } if (!isset($this->_tables[$name])) { $class = 'Nada\Table\\' . $this->getDbmsSuffix(); $this->_tables[$name] = new $class($this, $name); } return $this->_tables[$name]; }
[ "public", "function", "getTable", "(", "$", "name", ")", "{", "if", "(", "$", "name", "!=", "strtolower", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "DomainException", "(", "'Table name must be lowercase: '", ".", "$", "name", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "_tables", "[", "$", "name", "]", ")", ")", "{", "$", "class", "=", "'Nada\\Table\\\\'", ".", "$", "this", "->", "getDbmsSuffix", "(", ")", ";", "$", "this", "->", "_tables", "[", "$", "name", "]", "=", "new", "$", "class", "(", "$", "this", ",", "$", "name", ")", ";", "}", "return", "$", "this", "->", "_tables", "[", "$", "name", "]", ";", "}" ]
Get access to a specific table The returned object provides access to the given table and its associated database objects (columns etc.). The result is cached internally, so that subsequent calls won't hurt performance. @param string $name Table name (lowercase). An exception gets thrown if the name does not exist. @return \Nada\Table\AbstractTable Table object @throws \DomainException if $name is not lowercase
[ "Get", "access", "to", "a", "specific", "table" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L556-L567
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.getTables
public function getTables() { if (!$this->_allTablesFetched) { // Fetch only once $tables = $this->getTableNames(); // Fetch missing tables foreach ($tables as $table) { $this->getTable($table); // Discard result, still available in cache } // Sort cache ksort($this->_tables); // Set flag for subsequent invocations $this->_allTablesFetched = true; } return $this->_tables; }
php
public function getTables() { if (!$this->_allTablesFetched) { // Fetch only once $tables = $this->getTableNames(); // Fetch missing tables foreach ($tables as $table) { $this->getTable($table); // Discard result, still available in cache } // Sort cache ksort($this->_tables); // Set flag for subsequent invocations $this->_allTablesFetched = true; } return $this->_tables; }
[ "public", "function", "getTables", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_allTablesFetched", ")", "{", "// Fetch only once", "$", "tables", "=", "$", "this", "->", "getTableNames", "(", ")", ";", "// Fetch missing tables", "foreach", "(", "$", "tables", "as", "$", "table", ")", "{", "$", "this", "->", "getTable", "(", "$", "table", ")", ";", "// Discard result, still available in cache", "}", "// Sort cache", "ksort", "(", "$", "this", "->", "_tables", ")", ";", "// Set flag for subsequent invocations", "$", "this", "->", "_allTablesFetched", "=", "true", ";", "}", "return", "$", "this", "->", "_tables", ";", "}" ]
Return all tables The result is cached internally, so that subsequent calls won't hurt performance. @return array Array with table names as keys and \Nada\Table\AbstractTable objects as values
[ "Return", "all", "tables" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L576-L590
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.getViewNames
public function getViewNames() { $names = $this->query( 'SELECT table_name FROM information_schema.tables WHERE table_schema=? AND table_type=?', array( $this->getTableSchema(), 'VIEW' ) ); // Flatten array foreach ($names as &$name) { $name = $name['table_name']; } return $names; }
php
public function getViewNames() { $names = $this->query( 'SELECT table_name FROM information_schema.tables WHERE table_schema=? AND table_type=?', array( $this->getTableSchema(), 'VIEW' ) ); // Flatten array foreach ($names as &$name) { $name = $name['table_name']; } return $names; }
[ "public", "function", "getViewNames", "(", ")", "{", "$", "names", "=", "$", "this", "->", "query", "(", "'SELECT table_name FROM information_schema.tables WHERE table_schema=? AND table_type=?'", ",", "array", "(", "$", "this", "->", "getTableSchema", "(", ")", ",", "'VIEW'", ")", ")", ";", "// Flatten array", "foreach", "(", "$", "names", "as", "&", "$", "name", ")", "{", "$", "name", "=", "$", "name", "[", "'table_name'", "]", ";", "}", "return", "$", "names", ";", "}" ]
Return list of all view names The default implementation queries information_schema. This can be overridden where information_schema is not available. @return array
[ "Return", "list", "of", "all", "view", "names" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L624-L638
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.getNativeDatatype
public function getNativeDatatype($type, $length=null, $cast=false) { switch ($type) { case Column::TYPE_INTEGER: if ($length === null) { $length = Column::DEFAULT_LENGTH_INTEGER; } switch ($length) { case 16: return 'SMALLINT'; case 32: return 'INTEGER'; case 64: return 'BIGINT'; default: throw new \DomainException("Invalid length for type $type: $length"); } case Column::TYPE_VARCHAR: if (!ctype_digit((string)$length) or $length < 1) { throw new \InvalidArgumentException('Invalid length: ' . $length); } return "VARCHAR($length)"; case Column::TYPE_TIMESTAMP: return 'TIMESTAMP'; case Column::TYPE_DATE: return 'DATE'; case Column::TYPE_BOOL: return 'BOOLEAN'; case Column::TYPE_BLOB: return 'BLOB'; case Column::TYPE_DECIMAL: if (!preg_match('/^([0-9]+),([0-9]+)$/', $length, $components)) { throw new \InvalidArgumentException('Invalid length: ' . $length); } $precision = (integer)$components[1]; $scale = (integer)$components[2]; if ($precision < $scale) { throw new \InvalidArgumentException('Invalid length: ' . $length); } return "NUMERIC($precision,$scale)"; case Column::TYPE_FLOAT: if ($length === null) { $length = Column::DEFAULT_LENGTH_FLOAT; } elseif (!ctype_digit((string)$length) or $length < 1) { throw new \InvalidArgumentException('Invalid length: ' . $length); } return "FLOAT($length)"; default: throw new \DomainException('Unsupported datatype: ' . $type); } }
php
public function getNativeDatatype($type, $length=null, $cast=false) { switch ($type) { case Column::TYPE_INTEGER: if ($length === null) { $length = Column::DEFAULT_LENGTH_INTEGER; } switch ($length) { case 16: return 'SMALLINT'; case 32: return 'INTEGER'; case 64: return 'BIGINT'; default: throw new \DomainException("Invalid length for type $type: $length"); } case Column::TYPE_VARCHAR: if (!ctype_digit((string)$length) or $length < 1) { throw new \InvalidArgumentException('Invalid length: ' . $length); } return "VARCHAR($length)"; case Column::TYPE_TIMESTAMP: return 'TIMESTAMP'; case Column::TYPE_DATE: return 'DATE'; case Column::TYPE_BOOL: return 'BOOLEAN'; case Column::TYPE_BLOB: return 'BLOB'; case Column::TYPE_DECIMAL: if (!preg_match('/^([0-9]+),([0-9]+)$/', $length, $components)) { throw new \InvalidArgumentException('Invalid length: ' . $length); } $precision = (integer)$components[1]; $scale = (integer)$components[2]; if ($precision < $scale) { throw new \InvalidArgumentException('Invalid length: ' . $length); } return "NUMERIC($precision,$scale)"; case Column::TYPE_FLOAT: if ($length === null) { $length = Column::DEFAULT_LENGTH_FLOAT; } elseif (!ctype_digit((string)$length) or $length < 1) { throw new \InvalidArgumentException('Invalid length: ' . $length); } return "FLOAT($length)"; default: throw new \DomainException('Unsupported datatype: ' . $type); } }
[ "public", "function", "getNativeDatatype", "(", "$", "type", ",", "$", "length", "=", "null", ",", "$", "cast", "=", "false", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "Column", "::", "TYPE_INTEGER", ":", "if", "(", "$", "length", "===", "null", ")", "{", "$", "length", "=", "Column", "::", "DEFAULT_LENGTH_INTEGER", ";", "}", "switch", "(", "$", "length", ")", "{", "case", "16", ":", "return", "'SMALLINT'", ";", "case", "32", ":", "return", "'INTEGER'", ";", "case", "64", ":", "return", "'BIGINT'", ";", "default", ":", "throw", "new", "\\", "DomainException", "(", "\"Invalid length for type $type: $length\"", ")", ";", "}", "case", "Column", "::", "TYPE_VARCHAR", ":", "if", "(", "!", "ctype_digit", "(", "(", "string", ")", "$", "length", ")", "or", "$", "length", "<", "1", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid length: '", ".", "$", "length", ")", ";", "}", "return", "\"VARCHAR($length)\"", ";", "case", "Column", "::", "TYPE_TIMESTAMP", ":", "return", "'TIMESTAMP'", ";", "case", "Column", "::", "TYPE_DATE", ":", "return", "'DATE'", ";", "case", "Column", "::", "TYPE_BOOL", ":", "return", "'BOOLEAN'", ";", "case", "Column", "::", "TYPE_BLOB", ":", "return", "'BLOB'", ";", "case", "Column", "::", "TYPE_DECIMAL", ":", "if", "(", "!", "preg_match", "(", "'/^([0-9]+),([0-9]+)$/'", ",", "$", "length", ",", "$", "components", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid length: '", ".", "$", "length", ")", ";", "}", "$", "precision", "=", "(", "integer", ")", "$", "components", "[", "1", "]", ";", "$", "scale", "=", "(", "integer", ")", "$", "components", "[", "2", "]", ";", "if", "(", "$", "precision", "<", "$", "scale", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid length: '", ".", "$", "length", ")", ";", "}", "return", "\"NUMERIC($precision,$scale)\"", ";", "case", "Column", "::", "TYPE_FLOAT", ":", "if", "(", "$", "length", "===", "null", ")", "{", "$", "length", "=", "Column", "::", "DEFAULT_LENGTH_FLOAT", ";", "}", "elseif", "(", "!", "ctype_digit", "(", "(", "string", ")", "$", "length", ")", "or", "$", "length", "<", "1", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid length: '", ".", "$", "length", ")", ";", "}", "return", "\"FLOAT($length)\"", ";", "default", ":", "throw", "new", "\\", "DomainException", "(", "'Unsupported datatype: '", ".", "$", "type", ")", ";", "}", "}" ]
Get DBMS-specific datatype for abstract NADA datatype @param string $type One of \Nada\Column\AbstractColumn's TYPE_* constants @param mixed $length Optional length modifier (default provided for some datatypes) @param bool $cast The result is used for a typecast operation. Some DBMS require different specifiers for casts. @return string SQL fragment representing the datatype @throws \DomainException if the datatype is not supported for the current DBMS @throws \InvalidArgumentException if $length is invalid
[ "Get", "DBMS", "-", "specific", "datatype", "for", "abstract", "NADA", "datatype" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L681-L731
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.createColumn
public function createColumn( $name, $type, $length=null, $notnull=false, $default=null, $autoIncrement=false, $comment=null ) { $column = $this->createColumnObject(); $column->constructNew($this, $name, $type, $length, $notnull, $default, $autoIncrement, $comment); return $column; }
php
public function createColumn( $name, $type, $length=null, $notnull=false, $default=null, $autoIncrement=false, $comment=null ) { $column = $this->createColumnObject(); $column->constructNew($this, $name, $type, $length, $notnull, $default, $autoIncrement, $comment); return $column; }
[ "public", "function", "createColumn", "(", "$", "name", ",", "$", "type", ",", "$", "length", "=", "null", ",", "$", "notnull", "=", "false", ",", "$", "default", "=", "null", ",", "$", "autoIncrement", "=", "false", ",", "$", "comment", "=", "null", ")", "{", "$", "column", "=", "$", "this", "->", "createColumnObject", "(", ")", ";", "$", "column", "->", "constructNew", "(", "$", "this", ",", "$", "name", ",", "$", "type", ",", "$", "length", ",", "$", "notnull", ",", "$", "default", ",", "$", "autoIncrement", ",", "$", "comment", ")", ";", "return", "$", "column", ";", "}" ]
Construct a new column Input is not validated at this point, i.e. this method always succeeds. Invalid input is detected once the column data is actually used. The returned object is not linked to a table. It should only be used for adding it to a table. It can be discarded afterwards. @param string $name Column name @param string $type Datatype @param mixed $length Optional length modifier @param bool $notnull NOT NULL constraint (default FALSE) @param mixed $default Default value (default NULL) @param bool $autoIncrement Auto increment property (default FALSE) @param string $comment Column comment (default: NULL) @return \Nada\Column\AbstractColumn Temporary column object
[ "Construct", "a", "new", "column" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L761-L774
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.createColumnFromArray
public function createColumnFromArray(array $data) { return $this->createColumn( $data['name'], $data['type'], $data['length'], !empty($data['notnull']), @$data['default'], !empty($data['autoincrement']), @$data['comment'] ); }
php
public function createColumnFromArray(array $data) { return $this->createColumn( $data['name'], $data['type'], $data['length'], !empty($data['notnull']), @$data['default'], !empty($data['autoincrement']), @$data['comment'] ); }
[ "public", "function", "createColumnFromArray", "(", "array", "$", "data", ")", "{", "return", "$", "this", "->", "createColumn", "(", "$", "data", "[", "'name'", "]", ",", "$", "data", "[", "'type'", "]", ",", "$", "data", "[", "'length'", "]", ",", "!", "empty", "(", "$", "data", "[", "'notnull'", "]", ")", ",", "@", "$", "data", "[", "'default'", "]", ",", "!", "empty", "(", "$", "data", "[", "'autoincrement'", "]", ")", ",", "@", "$", "data", "[", "'comment'", "]", ")", ";", "}" ]
Construct a new column with data from an array This is a wrapper around createColumn() which gets column data from an associative array. The "name", "type" and "length" elements must always be present. The "notnull" and "autoincrement" elements default to FALSE if not given. The "default" and "comment" elements default to NULL. @param array $data column data: name, type, length, notnull, default, autoincrement, comment @return \Nada\Column\AbstractColumn Temporary column object
[ "Construct", "a", "new", "column", "with", "data", "from", "an", "array" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L789-L800
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase.createTable
public function createTable($name, array $columns, $primaryKey=null) { $name = strtolower($name); if (strpos($name, 'sqlite_') === 0) { throw new \InvalidArgumentException('Created table name must not begin with sqlite_'); } if (empty($columns)) { throw new \InvalidArgumentException('No columns specified for new table'); } if ($primaryKey !== null and !is_array($primaryKey)) { $primaryKey = array($primaryKey); } $numAutoIncrement = 0; $autoPk = null; foreach ($columns as &$column) { if (is_array($column)) { $column = $this->createColumnFromArray($column); } if ($column->getAutoIncrement()) { $numAutoIncrement++; $autoPk = $column->getName(); } } unset($column); if ($numAutoIncrement > 1) { throw new \InvalidArgumentException( 'More than 1 autoincrement field specified, given: ' . $numAutoIncrement ); } if ($autoPk) { if ($primaryKey === null) { $primaryKey = array($autoPk); } elseif (count($primaryKey) != 1 or $autoPk != $primaryKey[0]) { throw new \InvalidArgumentException('Invalid primary key: ' . implode(',', $primaryKey)); } } if (!$primaryKey) { throw new \InvalidArgumentException('Missing primary key for table ' . $name); } if (in_array($name, $this->getTableNames())) { throw new \RuntimeException('Table already exists: ' . $name); } $colspecs = array(); foreach ($columns as $column) { $colspecs[] = $this->prepareIdentifier($column->getName()) . ' ' . $column->getDefinition(); } $sql = 'CREATE TABLE ' . $this->prepareIdentifier($name) . " (\n"; $sql .= implode(",\n", $colspecs); $sql .= $this->_getTablePkDeclaration($primaryKey, (bool) $numAutoIncrement); $sql .= "\n)"; $this->exec($sql); return $this->getTable($name); }
php
public function createTable($name, array $columns, $primaryKey=null) { $name = strtolower($name); if (strpos($name, 'sqlite_') === 0) { throw new \InvalidArgumentException('Created table name must not begin with sqlite_'); } if (empty($columns)) { throw new \InvalidArgumentException('No columns specified for new table'); } if ($primaryKey !== null and !is_array($primaryKey)) { $primaryKey = array($primaryKey); } $numAutoIncrement = 0; $autoPk = null; foreach ($columns as &$column) { if (is_array($column)) { $column = $this->createColumnFromArray($column); } if ($column->getAutoIncrement()) { $numAutoIncrement++; $autoPk = $column->getName(); } } unset($column); if ($numAutoIncrement > 1) { throw new \InvalidArgumentException( 'More than 1 autoincrement field specified, given: ' . $numAutoIncrement ); } if ($autoPk) { if ($primaryKey === null) { $primaryKey = array($autoPk); } elseif (count($primaryKey) != 1 or $autoPk != $primaryKey[0]) { throw new \InvalidArgumentException('Invalid primary key: ' . implode(',', $primaryKey)); } } if (!$primaryKey) { throw new \InvalidArgumentException('Missing primary key for table ' . $name); } if (in_array($name, $this->getTableNames())) { throw new \RuntimeException('Table already exists: ' . $name); } $colspecs = array(); foreach ($columns as $column) { $colspecs[] = $this->prepareIdentifier($column->getName()) . ' ' . $column->getDefinition(); } $sql = 'CREATE TABLE ' . $this->prepareIdentifier($name) . " (\n"; $sql .= implode(",\n", $colspecs); $sql .= $this->_getTablePkDeclaration($primaryKey, (bool) $numAutoIncrement); $sql .= "\n)"; $this->exec($sql); return $this->getTable($name); }
[ "public", "function", "createTable", "(", "$", "name", ",", "array", "$", "columns", ",", "$", "primaryKey", "=", "null", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "strpos", "(", "$", "name", ",", "'sqlite_'", ")", "===", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Created table name must not begin with sqlite_'", ")", ";", "}", "if", "(", "empty", "(", "$", "columns", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'No columns specified for new table'", ")", ";", "}", "if", "(", "$", "primaryKey", "!==", "null", "and", "!", "is_array", "(", "$", "primaryKey", ")", ")", "{", "$", "primaryKey", "=", "array", "(", "$", "primaryKey", ")", ";", "}", "$", "numAutoIncrement", "=", "0", ";", "$", "autoPk", "=", "null", ";", "foreach", "(", "$", "columns", "as", "&", "$", "column", ")", "{", "if", "(", "is_array", "(", "$", "column", ")", ")", "{", "$", "column", "=", "$", "this", "->", "createColumnFromArray", "(", "$", "column", ")", ";", "}", "if", "(", "$", "column", "->", "getAutoIncrement", "(", ")", ")", "{", "$", "numAutoIncrement", "++", ";", "$", "autoPk", "=", "$", "column", "->", "getName", "(", ")", ";", "}", "}", "unset", "(", "$", "column", ")", ";", "if", "(", "$", "numAutoIncrement", ">", "1", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'More than 1 autoincrement field specified, given: '", ".", "$", "numAutoIncrement", ")", ";", "}", "if", "(", "$", "autoPk", ")", "{", "if", "(", "$", "primaryKey", "===", "null", ")", "{", "$", "primaryKey", "=", "array", "(", "$", "autoPk", ")", ";", "}", "elseif", "(", "count", "(", "$", "primaryKey", ")", "!=", "1", "or", "$", "autoPk", "!=", "$", "primaryKey", "[", "0", "]", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid primary key: '", ".", "implode", "(", "','", ",", "$", "primaryKey", ")", ")", ";", "}", "}", "if", "(", "!", "$", "primaryKey", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Missing primary key for table '", ".", "$", "name", ")", ";", "}", "if", "(", "in_array", "(", "$", "name", ",", "$", "this", "->", "getTableNames", "(", ")", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Table already exists: '", ".", "$", "name", ")", ";", "}", "$", "colspecs", "=", "array", "(", ")", ";", "foreach", "(", "$", "columns", "as", "$", "column", ")", "{", "$", "colspecs", "[", "]", "=", "$", "this", "->", "prepareIdentifier", "(", "$", "column", "->", "getName", "(", ")", ")", ".", "' '", ".", "$", "column", "->", "getDefinition", "(", ")", ";", "}", "$", "sql", "=", "'CREATE TABLE '", ".", "$", "this", "->", "prepareIdentifier", "(", "$", "name", ")", ".", "\" (\\n\"", ";", "$", "sql", ".=", "implode", "(", "\",\\n\"", ",", "$", "colspecs", ")", ";", "$", "sql", ".=", "$", "this", "->", "_getTablePkDeclaration", "(", "$", "primaryKey", ",", "(", "bool", ")", "$", "numAutoIncrement", ")", ";", "$", "sql", ".=", "\"\\n)\"", ";", "$", "this", "->", "exec", "(", "$", "sql", ")", ";", "return", "$", "this", "->", "getTable", "(", "$", "name", ")", ";", "}" ]
Create a table Some constraints are checked before the creation is attempted: - There can be at most 1 autoincrement column. - If there is an autoincrement column, it must be the primary key. - Otherwise, $primaryKey must not be empty. - Table names must not begin with sqlite_. For maximum compatibility, this constraint is enforced for all DBMS, not only for SQLite. The $primaryKey value can be omitted for tables with an autoincrement column because the autoincrement column is automatically made the primary key. @param string $name Table name @param array $columns Array of column objects, created via createColumn(), or associative arrays @param string|array $primaryKey Primary key (column name or aray of column names) @return \Nada\Table\AbstractTable A representation of the created table @throws \InvalidArgumentException if $columns is empty or constraints are violated @throws \RuntimeException if the table already exists
[ "Create", "a", "table" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L824-L879
train
hschletz/NADA
src/Database/AbstractDatabase.php
AbstractDatabase._getTablePkDeclaration
protected function _getTablePkDeclaration(array $primaryKey, $autoIncrement) { foreach ($primaryKey as &$column) { $column = $this->prepareIdentifier($column); } return ",\nPRIMARY KEY (" . implode(', ', $primaryKey) . ')'; }
php
protected function _getTablePkDeclaration(array $primaryKey, $autoIncrement) { foreach ($primaryKey as &$column) { $column = $this->prepareIdentifier($column); } return ",\nPRIMARY KEY (" . implode(', ', $primaryKey) . ')'; }
[ "protected", "function", "_getTablePkDeclaration", "(", "array", "$", "primaryKey", ",", "$", "autoIncrement", ")", "{", "foreach", "(", "$", "primaryKey", "as", "&", "$", "column", ")", "{", "$", "column", "=", "$", "this", "->", "prepareIdentifier", "(", "$", "column", ")", ";", "}", "return", "\",\\nPRIMARY KEY (\"", ".", "implode", "(", "', '", ",", "$", "primaryKey", ")", ".", "')'", ";", "}" ]
Get the declaration for a table's primary key This is called by createTable() to get the PRIMARY KEY declaration to be inserted into a CREATE TABLE statement. The default implementation unconditionally returns ", PRIMARY KEY ($column[,$column...])". Other implementations may override this, depending on $autoIncrement. @param array $primaryKey Array of column names for PK @param bool $autoIncrement Whether the table has an autoincrement column @return string
[ "Get", "the", "declaration", "for", "a", "table", "s", "primary", "key" ]
4ead798354089fd360f917ce64dd1432d5650df0
https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Database/AbstractDatabase.php#L893-L899
train
geoffadams/bedrest-core
library/BedRest/Mapping/Driver/AbstractAnnotationDriver.php
AbstractAnnotationDriver.indexAnnotationsByType
protected function indexAnnotationsByType(array $annotations) { $indexed = array(); // if we are receiving annotations indexed by number, transform it to by class name if ($annotations && is_numeric(key($annotations))) { foreach ($annotations as $annotation) { $annotationType = get_class($annotation); if (isset($indexed[$annotationType]) && !is_array($indexed[$annotationType])) { $indexed[$annotationType] = array($indexed[$annotationType], $annotation); } elseif (isset($indexed[$annotationType])) { $indexed[$annotationType][] = $annotation; } else { $indexed[$annotationType] = $annotation; } } } return $indexed; }
php
protected function indexAnnotationsByType(array $annotations) { $indexed = array(); // if we are receiving annotations indexed by number, transform it to by class name if ($annotations && is_numeric(key($annotations))) { foreach ($annotations as $annotation) { $annotationType = get_class($annotation); if (isset($indexed[$annotationType]) && !is_array($indexed[$annotationType])) { $indexed[$annotationType] = array($indexed[$annotationType], $annotation); } elseif (isset($indexed[$annotationType])) { $indexed[$annotationType][] = $annotation; } else { $indexed[$annotationType] = $annotation; } } } return $indexed; }
[ "protected", "function", "indexAnnotationsByType", "(", "array", "$", "annotations", ")", "{", "$", "indexed", "=", "array", "(", ")", ";", "// if we are receiving annotations indexed by number, transform it to by class name", "if", "(", "$", "annotations", "&&", "is_numeric", "(", "key", "(", "$", "annotations", ")", ")", ")", "{", "foreach", "(", "$", "annotations", "as", "$", "annotation", ")", "{", "$", "annotationType", "=", "get_class", "(", "$", "annotation", ")", ";", "if", "(", "isset", "(", "$", "indexed", "[", "$", "annotationType", "]", ")", "&&", "!", "is_array", "(", "$", "indexed", "[", "$", "annotationType", "]", ")", ")", "{", "$", "indexed", "[", "$", "annotationType", "]", "=", "array", "(", "$", "indexed", "[", "$", "annotationType", "]", ",", "$", "annotation", ")", ";", "}", "elseif", "(", "isset", "(", "$", "indexed", "[", "$", "annotationType", "]", ")", ")", "{", "$", "indexed", "[", "$", "annotationType", "]", "[", "]", "=", "$", "annotation", ";", "}", "else", "{", "$", "indexed", "[", "$", "annotationType", "]", "=", "$", "annotation", ";", "}", "}", "}", "return", "$", "indexed", ";", "}" ]
Indexes a numerically-indexed array of annotation instances by their class names. @param array $annotations @return array
[ "Indexes", "a", "numerically", "-", "indexed", "array", "of", "annotation", "instances", "by", "their", "class", "names", "." ]
a77bf8b7492dfbfb720b201f7ec91a4f03417b5c
https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Mapping/Driver/AbstractAnnotationDriver.php#L56-L76
train
johnkrovitch/Sam
Filter/FilterBuilder.php
FilterBuilder.build
public function build(array $filterConfigurations) { $resolver = new OptionsResolver(); $filters = []; foreach ($filterConfigurations as $filterName => $filterConfiguration) { $resolver->clear(); if ($filterConfiguration === null) { $filterConfiguration = []; } $configuration = $this->getFilterConfiguration($filterName); $configuration->configureOptions($resolver); $configuration->setParameters($resolver->resolve($filterConfiguration)); $class = $this->mapping[$filterName]; /** @var FilterInterface $filter */ $filter = new $class( // filter's name $filterName, // filter's configuration $configuration, // event dispatcher $this->eventDispatcher ); $filter->checkRequirements(); $filters[$filterName] = $filter; } return $filters; }
php
public function build(array $filterConfigurations) { $resolver = new OptionsResolver(); $filters = []; foreach ($filterConfigurations as $filterName => $filterConfiguration) { $resolver->clear(); if ($filterConfiguration === null) { $filterConfiguration = []; } $configuration = $this->getFilterConfiguration($filterName); $configuration->configureOptions($resolver); $configuration->setParameters($resolver->resolve($filterConfiguration)); $class = $this->mapping[$filterName]; /** @var FilterInterface $filter */ $filter = new $class( // filter's name $filterName, // filter's configuration $configuration, // event dispatcher $this->eventDispatcher ); $filter->checkRequirements(); $filters[$filterName] = $filter; } return $filters; }
[ "public", "function", "build", "(", "array", "$", "filterConfigurations", ")", "{", "$", "resolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "filters", "=", "[", "]", ";", "foreach", "(", "$", "filterConfigurations", "as", "$", "filterName", "=>", "$", "filterConfiguration", ")", "{", "$", "resolver", "->", "clear", "(", ")", ";", "if", "(", "$", "filterConfiguration", "===", "null", ")", "{", "$", "filterConfiguration", "=", "[", "]", ";", "}", "$", "configuration", "=", "$", "this", "->", "getFilterConfiguration", "(", "$", "filterName", ")", ";", "$", "configuration", "->", "configureOptions", "(", "$", "resolver", ")", ";", "$", "configuration", "->", "setParameters", "(", "$", "resolver", "->", "resolve", "(", "$", "filterConfiguration", ")", ")", ";", "$", "class", "=", "$", "this", "->", "mapping", "[", "$", "filterName", "]", ";", "/** @var FilterInterface $filter */", "$", "filter", "=", "new", "$", "class", "(", "// filter's name", "$", "filterName", ",", "// filter's configuration", "$", "configuration", ",", "// event dispatcher", "$", "this", "->", "eventDispatcher", ")", ";", "$", "filter", "->", "checkRequirements", "(", ")", ";", "$", "filters", "[", "$", "filterName", "]", "=", "$", "filter", ";", "}", "return", "$", "filters", ";", "}" ]
Build the filter with the given configuration. @param array $filterConfigurations @return FilterInterface[] @throws Exception
[ "Build", "the", "filter", "with", "the", "given", "configuration", "." ]
fbd3770c11eecc0a6d8070f439f149062316f606
https://github.com/johnkrovitch/Sam/blob/fbd3770c11eecc0a6d8070f439f149062316f606/Filter/FilterBuilder.php#L54-L86
train
johnkrovitch/Sam
Filter/FilterBuilder.php
FilterBuilder.getFilterConfiguration
protected function getFilterConfiguration($filter) { if (!array_key_exists($filter, $this->mapping)) { throw new Exception($filter.' filter not found in assets mapping. Check your configuration'); } $class = $this->mapping[$filter].'Configuration'; if (!class_exists($class)) { throw new Exception($class.' filter configuration class not found'); } $configuration = new $class(); if (!($configuration instanceof ConfigurationInterface)) { throw new Exception(get_class($configuration).' should be an instance of '.ConfigurationInterface::class); } return $configuration; }
php
protected function getFilterConfiguration($filter) { if (!array_key_exists($filter, $this->mapping)) { throw new Exception($filter.' filter not found in assets mapping. Check your configuration'); } $class = $this->mapping[$filter].'Configuration'; if (!class_exists($class)) { throw new Exception($class.' filter configuration class not found'); } $configuration = new $class(); if (!($configuration instanceof ConfigurationInterface)) { throw new Exception(get_class($configuration).' should be an instance of '.ConfigurationInterface::class); } return $configuration; }
[ "protected", "function", "getFilterConfiguration", "(", "$", "filter", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "filter", ",", "$", "this", "->", "mapping", ")", ")", "{", "throw", "new", "Exception", "(", "$", "filter", ".", "' filter not found in assets mapping. Check your configuration'", ")", ";", "}", "$", "class", "=", "$", "this", "->", "mapping", "[", "$", "filter", "]", ".", "'Configuration'", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "Exception", "(", "$", "class", ".", "' filter configuration class not found'", ")", ";", "}", "$", "configuration", "=", "new", "$", "class", "(", ")", ";", "if", "(", "!", "(", "$", "configuration", "instanceof", "ConfigurationInterface", ")", ")", "{", "throw", "new", "Exception", "(", "get_class", "(", "$", "configuration", ")", ".", "' should be an instance of '", ".", "ConfigurationInterface", "::", "class", ")", ";", "}", "return", "$", "configuration", ";", "}" ]
Return filter configuration instance using the configured mapping. @param $filter @return ConfigurationInterface @throws Exception
[ "Return", "filter", "configuration", "instance", "using", "the", "configured", "mapping", "." ]
fbd3770c11eecc0a6d8070f439f149062316f606
https://github.com/johnkrovitch/Sam/blob/fbd3770c11eecc0a6d8070f439f149062316f606/Filter/FilterBuilder.php#L95-L112
train
codeinchq/psr7-responses
src/JsonResponse.php
JsonResponse.getDecodedJson
public function getDecodedJson():array { if (!($array = json_decode($this->json, true))) { throw new \RuntimeException("Unable to decode the response's JSON"); } return json_decode($this->json, true); }
php
public function getDecodedJson():array { if (!($array = json_decode($this->json, true))) { throw new \RuntimeException("Unable to decode the response's JSON"); } return json_decode($this->json, true); }
[ "public", "function", "getDecodedJson", "(", ")", ":", "array", "{", "if", "(", "!", "(", "$", "array", "=", "json_decode", "(", "$", "this", "->", "json", ",", "true", ")", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"Unable to decode the response's JSON\"", ")", ";", "}", "return", "json_decode", "(", "$", "this", "->", "json", ",", "true", ")", ";", "}" ]
Returns the decoded JSON string. @uses json_decode() @return array
[ "Returns", "the", "decoded", "JSON", "string", "." ]
d4bb6bc9b4219694e7c1f5ee9b40b75b22362fce
https://github.com/codeinchq/psr7-responses/blob/d4bb6bc9b4219694e7c1f5ee9b40b75b22362fce/src/JsonResponse.php#L113-L119
train
DreadLabs/VantomasWebsite
src/ThreatDefense/ReCaptchaResponse.php
ReCaptchaResponse.fromString
public static function fromString($string) { if (is_null($string) || empty($string) || !is_string($string)) { throw new \InvalidArgumentException('The given ReCaptcha response data is invalid.', 1452283305); } $value = (string) $string; $value = filter_var( $value, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | !FILTER_FLAG_ENCODE_LOW | !FILTER_FLAG_ENCODE_HIGH | FILTER_FLAG_NO_ENCODE_QUOTES ); $value = trim($value); return new static($value); }
php
public static function fromString($string) { if (is_null($string) || empty($string) || !is_string($string)) { throw new \InvalidArgumentException('The given ReCaptcha response data is invalid.', 1452283305); } $value = (string) $string; $value = filter_var( $value, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | !FILTER_FLAG_ENCODE_LOW | !FILTER_FLAG_ENCODE_HIGH | FILTER_FLAG_NO_ENCODE_QUOTES ); $value = trim($value); return new static($value); }
[ "public", "static", "function", "fromString", "(", "$", "string", ")", "{", "if", "(", "is_null", "(", "$", "string", ")", "||", "empty", "(", "$", "string", ")", "||", "!", "is_string", "(", "$", "string", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The given ReCaptcha response data is invalid.'", ",", "1452283305", ")", ";", "}", "$", "value", "=", "(", "string", ")", "$", "string", ";", "$", "value", "=", "filter_var", "(", "$", "value", ",", "FILTER_SANITIZE_STRING", ",", "FILTER_FLAG_STRIP_LOW", "|", "FILTER_FLAG_STRIP_HIGH", "|", "!", "FILTER_FLAG_ENCODE_LOW", "|", "!", "FILTER_FLAG_ENCODE_HIGH", "|", "FILTER_FLAG_NO_ENCODE_QUOTES", ")", ";", "$", "value", "=", "trim", "(", "$", "value", ")", ";", "return", "new", "static", "(", "$", "value", ")", ";", "}" ]
Creates the ReCaptchaResponse data object @param string $string The value @return self @throws \InvalidArgumentException
[ "Creates", "the", "ReCaptchaResponse", "data", "object" ]
7f85f2b45bdf5ed9fa9d320c805c416bf99cd668
https://github.com/DreadLabs/VantomasWebsite/blob/7f85f2b45bdf5ed9fa9d320c805c416bf99cd668/src/ThreatDefense/ReCaptchaResponse.php#L48-L69
train
buflix/SimpleCollection
src/SimpleCollection/Entity/AbstractEntity.php
AbstractEntity.toArray
public function toArray() { $aReturn = array(); foreach (get_object_vars($this) as $sKey => $mValue) { if (is_object($mValue) and true === method_exists($mValue, 'toArray')) { $aReturn[$sKey] = $mValue->toArray(); } else { $aReturn[$sKey] = $mValue; } } return $aReturn; }
php
public function toArray() { $aReturn = array(); foreach (get_object_vars($this) as $sKey => $mValue) { if (is_object($mValue) and true === method_exists($mValue, 'toArray')) { $aReturn[$sKey] = $mValue->toArray(); } else { $aReturn[$sKey] = $mValue; } } return $aReturn; }
[ "public", "function", "toArray", "(", ")", "{", "$", "aReturn", "=", "array", "(", ")", ";", "foreach", "(", "get_object_vars", "(", "$", "this", ")", "as", "$", "sKey", "=>", "$", "mValue", ")", "{", "if", "(", "is_object", "(", "$", "mValue", ")", "and", "true", "===", "method_exists", "(", "$", "mValue", ",", "'toArray'", ")", ")", "{", "$", "aReturn", "[", "$", "sKey", "]", "=", "$", "mValue", "->", "toArray", "(", ")", ";", "}", "else", "{", "$", "aReturn", "[", "$", "sKey", "]", "=", "$", "mValue", ";", "}", "}", "return", "$", "aReturn", ";", "}" ]
return this entity as array @see EntityInterface::toArray @return array
[ "return", "this", "entity", "as", "array" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/Entity/AbstractEntity.php#L19-L32
train
Vectrex/vxPHP
src/Form/FormElement/FormElementFactory.php
FormElementFactory.create
public static function create($type, $name, $value = null, array $attributes = [], array $options = [], $required = false, array $modifiers = [], array $validators = [], $validationErrorMessage = null) { $type = strtolower($type); if(is_array($value) && $type !== 'multipleselect') { $elem = self::createSingleElement($type, $name, null, $attributes, $options, $required, $modifiers, $validators, $validationErrorMessage); $elements = []; foreach($value as $k => $v) { $e = clone $elem; $e ->setName(sprintf('%s[%s]', $name, $k)) ->setValue($v) ; $elements[$k] = $e; } unset($elem); return $elements; } else { return self::createSingleElement($type, $name, $value, $attributes, $options, $required, $modifiers, $validators, $validationErrorMessage); } }
php
public static function create($type, $name, $value = null, array $attributes = [], array $options = [], $required = false, array $modifiers = [], array $validators = [], $validationErrorMessage = null) { $type = strtolower($type); if(is_array($value) && $type !== 'multipleselect') { $elem = self::createSingleElement($type, $name, null, $attributes, $options, $required, $modifiers, $validators, $validationErrorMessage); $elements = []; foreach($value as $k => $v) { $e = clone $elem; $e ->setName(sprintf('%s[%s]', $name, $k)) ->setValue($v) ; $elements[$k] = $e; } unset($elem); return $elements; } else { return self::createSingleElement($type, $name, $value, $attributes, $options, $required, $modifiers, $validators, $validationErrorMessage); } }
[ "public", "static", "function", "create", "(", "$", "type", ",", "$", "name", ",", "$", "value", "=", "null", ",", "array", "$", "attributes", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ",", "$", "required", "=", "false", ",", "array", "$", "modifiers", "=", "[", "]", ",", "array", "$", "validators", "=", "[", "]", ",", "$", "validationErrorMessage", "=", "null", ")", "{", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "if", "(", "is_array", "(", "$", "value", ")", "&&", "$", "type", "!==", "'multipleselect'", ")", "{", "$", "elem", "=", "self", "::", "createSingleElement", "(", "$", "type", ",", "$", "name", ",", "null", ",", "$", "attributes", ",", "$", "options", ",", "$", "required", ",", "$", "modifiers", ",", "$", "validators", ",", "$", "validationErrorMessage", ")", ";", "$", "elements", "=", "[", "]", ";", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "e", "=", "clone", "$", "elem", ";", "$", "e", "->", "setName", "(", "sprintf", "(", "'%s[%s]'", ",", "$", "name", ",", "$", "k", ")", ")", "->", "setValue", "(", "$", "v", ")", ";", "$", "elements", "[", "$", "k", "]", "=", "$", "e", ";", "}", "unset", "(", "$", "elem", ")", ";", "return", "$", "elements", ";", "}", "else", "{", "return", "self", "::", "createSingleElement", "(", "$", "type", ",", "$", "name", ",", "$", "value", ",", "$", "attributes", ",", "$", "options", ",", "$", "required", ",", "$", "modifiers", ",", "$", "validators", ",", "$", "validationErrorMessage", ")", ";", "}", "}" ]
create either single FormElement or array of FormElements @param string $type , type of element @param string $name , name of element @param mixed $value @param array $attributes @param array $options , array for initializing SelectOptionElements or RadioOptionElements @param boolean $required @param array $modifiers @param array $validators @param string $validationErrorMessage @return FormElement | FormElement[] @throws FormElementFactoryException
[ "create", "either", "single", "FormElement", "or", "array", "of", "FormElements" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Form/FormElement/FormElementFactory.php#L47-L72
train
Vectrex/vxPHP
src/Form/FormElement/FormElementFactory.php
FormElementFactory.createSingleElement
private static function createSingleElement($type, $name, $value, $attributes, $options, $required, $modifiers, $validators, $validationErrorMessage) { switch($type) { case 'input': $elem = new InputElement($name); break; case 'file': $elem = new FileInputElement($name); break; case 'password': $elem = new PasswordInputElement($name); break; case 'submit': $elem = new SubmitInputElement($name); break; case 'checkbox': $elem = new CheckboxElement($name); break; case 'textarea': $elem = new TextareaElement($name); break; case 'image': $elem = new ImageElement($name); break; case 'button': $elem = new ButtonElement($name); if(isset($attributes['type'])) { $elem->setType($attributes['type']); } break; case 'select': $elem = new SelectElement($name); $elem->createOptions($options); break; case 'radio': $elem = new RadioElement($name); $elem->createOptions($options); break; case 'multipleselect': $elem = new MultipleSelectElement($name); $elem->createOptions($options); break; default: throw new FormElementFactoryException(sprintf("Unknown form element '%s''", $type)); } $elem ->setAttributes($attributes) ->setRequired($required) ->setValidationErrorMessage($validationErrorMessage) ; foreach($modifiers as $modifier) { $elem->addModifier($modifier); } foreach($validators as $validator) { $elem->addValidator($validator); } $elem->setValue($value); return $elem; }
php
private static function createSingleElement($type, $name, $value, $attributes, $options, $required, $modifiers, $validators, $validationErrorMessage) { switch($type) { case 'input': $elem = new InputElement($name); break; case 'file': $elem = new FileInputElement($name); break; case 'password': $elem = new PasswordInputElement($name); break; case 'submit': $elem = new SubmitInputElement($name); break; case 'checkbox': $elem = new CheckboxElement($name); break; case 'textarea': $elem = new TextareaElement($name); break; case 'image': $elem = new ImageElement($name); break; case 'button': $elem = new ButtonElement($name); if(isset($attributes['type'])) { $elem->setType($attributes['type']); } break; case 'select': $elem = new SelectElement($name); $elem->createOptions($options); break; case 'radio': $elem = new RadioElement($name); $elem->createOptions($options); break; case 'multipleselect': $elem = new MultipleSelectElement($name); $elem->createOptions($options); break; default: throw new FormElementFactoryException(sprintf("Unknown form element '%s''", $type)); } $elem ->setAttributes($attributes) ->setRequired($required) ->setValidationErrorMessage($validationErrorMessage) ; foreach($modifiers as $modifier) { $elem->addModifier($modifier); } foreach($validators as $validator) { $elem->addValidator($validator); } $elem->setValue($value); return $elem; }
[ "private", "static", "function", "createSingleElement", "(", "$", "type", ",", "$", "name", ",", "$", "value", ",", "$", "attributes", ",", "$", "options", ",", "$", "required", ",", "$", "modifiers", ",", "$", "validators", ",", "$", "validationErrorMessage", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'input'", ":", "$", "elem", "=", "new", "InputElement", "(", "$", "name", ")", ";", "break", ";", "case", "'file'", ":", "$", "elem", "=", "new", "FileInputElement", "(", "$", "name", ")", ";", "break", ";", "case", "'password'", ":", "$", "elem", "=", "new", "PasswordInputElement", "(", "$", "name", ")", ";", "break", ";", "case", "'submit'", ":", "$", "elem", "=", "new", "SubmitInputElement", "(", "$", "name", ")", ";", "break", ";", "case", "'checkbox'", ":", "$", "elem", "=", "new", "CheckboxElement", "(", "$", "name", ")", ";", "break", ";", "case", "'textarea'", ":", "$", "elem", "=", "new", "TextareaElement", "(", "$", "name", ")", ";", "break", ";", "case", "'image'", ":", "$", "elem", "=", "new", "ImageElement", "(", "$", "name", ")", ";", "break", ";", "case", "'button'", ":", "$", "elem", "=", "new", "ButtonElement", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'type'", "]", ")", ")", "{", "$", "elem", "->", "setType", "(", "$", "attributes", "[", "'type'", "]", ")", ";", "}", "break", ";", "case", "'select'", ":", "$", "elem", "=", "new", "SelectElement", "(", "$", "name", ")", ";", "$", "elem", "->", "createOptions", "(", "$", "options", ")", ";", "break", ";", "case", "'radio'", ":", "$", "elem", "=", "new", "RadioElement", "(", "$", "name", ")", ";", "$", "elem", "->", "createOptions", "(", "$", "options", ")", ";", "break", ";", "case", "'multipleselect'", ":", "$", "elem", "=", "new", "MultipleSelectElement", "(", "$", "name", ")", ";", "$", "elem", "->", "createOptions", "(", "$", "options", ")", ";", "break", ";", "default", ":", "throw", "new", "FormElementFactoryException", "(", "sprintf", "(", "\"Unknown form element '%s''\"", ",", "$", "type", ")", ")", ";", "}", "$", "elem", "->", "setAttributes", "(", "$", "attributes", ")", "->", "setRequired", "(", "$", "required", ")", "->", "setValidationErrorMessage", "(", "$", "validationErrorMessage", ")", ";", "foreach", "(", "$", "modifiers", "as", "$", "modifier", ")", "{", "$", "elem", "->", "addModifier", "(", "$", "modifier", ")", ";", "}", "foreach", "(", "$", "validators", "as", "$", "validator", ")", "{", "$", "elem", "->", "addValidator", "(", "$", "validator", ")", ";", "}", "$", "elem", "->", "setValue", "(", "$", "value", ")", ";", "return", "$", "elem", ";", "}" ]
generate a single form element @param $type @param $name @param $value @param $attributes @param $options @param $required @param $modifiers @param $validators @param $validationErrorMessage @return ButtonElement|CheckboxElement|ImageElement|InputElement|PasswordInputElement|SubmitInputElement|TextareaElement @throws FormElementFactoryException
[ "generate", "a", "single", "form", "element" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Form/FormElement/FormElementFactory.php#L90-L164
train
anime-db/shikimori-related-items-widget-bundle
src/Controller/WidgetController.php
WidgetController.filter
protected function filter(array $list) { $tmp = []; foreach ($list as $item) { if ($item['anime']) { $tmp[] = $item; } } return $tmp; }
php
protected function filter(array $list) { $tmp = []; foreach ($list as $item) { if ($item['anime']) { $tmp[] = $item; } } return $tmp; }
[ "protected", "function", "filter", "(", "array", "$", "list", ")", "{", "$", "tmp", "=", "[", "]", ";", "foreach", "(", "$", "list", "as", "$", "item", ")", "{", "if", "(", "$", "item", "[", "'anime'", "]", ")", "{", "$", "tmp", "[", "]", "=", "$", "item", ";", "}", "}", "return", "$", "tmp", ";", "}" ]
Filter a list items @param array $list @return array
[ "Filter", "a", "list", "items" ]
ee77d08513efe0f099790ef899ba6080a11abdb3
https://github.com/anime-db/shikimori-related-items-widget-bundle/blob/ee77d08513efe0f099790ef899ba6080a11abdb3/src/Controller/WidgetController.php#L94-L103
train
fardus/CRUDBundle
Fardus/Bundle/CrudBundle/Controller/ApiController.php
ApiController.deleteAction
public function deleteAction($entity, $id) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($entity)->find($id); if (!$entity) { throw $this->createNotFoundException("Unable to find $entity entity."); } $em->remove($entity); $em->flush(); $this->get('session')->getFlashBag()->add( 'success', 'The Post has been removed.'); $content = json_encode(array( 'status' => 'deleted', )); $response = new Response($content, 200); return $response; }
php
public function deleteAction($entity, $id) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($entity)->find($id); if (!$entity) { throw $this->createNotFoundException("Unable to find $entity entity."); } $em->remove($entity); $em->flush(); $this->get('session')->getFlashBag()->add( 'success', 'The Post has been removed.'); $content = json_encode(array( 'status' => 'deleted', )); $response = new Response($content, 200); return $response; }
[ "public", "function", "deleteAction", "(", "$", "entity", ",", "$", "id", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "entity", "=", "$", "em", "->", "getRepository", "(", "$", "entity", ")", "->", "find", "(", "$", "id", ")", ";", "if", "(", "!", "$", "entity", ")", "{", "throw", "$", "this", "->", "createNotFoundException", "(", "\"Unable to find $entity entity.\"", ")", ";", "}", "$", "em", "->", "remove", "(", "$", "entity", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'success'", ",", "'The Post has been removed.'", ")", ";", "$", "content", "=", "json_encode", "(", "array", "(", "'status'", "=>", "'deleted'", ",", ")", ")", ";", "$", "response", "=", "new", "Response", "(", "$", "content", ",", "200", ")", ";", "return", "$", "response", ";", "}" ]
Delete any entity. @param string $entity @param int $id @return Response @throws NotFoundHttpException
[ "Delete", "any", "entity", "." ]
5d4180f2a1f30da0fc4cbb16a70f656e9e083c5c
https://github.com/fardus/CRUDBundle/blob/5d4180f2a1f30da0fc4cbb16a70f656e9e083c5c/Fardus/Bundle/CrudBundle/Controller/ApiController.php#L24-L46
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.FromFloat
public static function FromFloat( $value, $detail = true ) { if ( $value instanceof XPath2Item ) { $value = $value->getTypedValue(); } if ( $value instanceof DecimalValue ) return $value; if ( ( ! is_numeric( $value ) ) || is_infinite( $value ) || is_nan( $value ) ) { throw XPath2Exception::withErrorCodeAndParams( "FOCA0002", Resources::FOCA0002, array( $value, "Decimal" ) ); } $matched = preg_match( DecimalValue::Pattern, $detail ? sprintf( "%.018g", $value ) : $value, $matches ); if ( ! $matched ) { throw new \InvalidArgumentException( "The number '$value' cannot be parsed" ); } $sign = isset( $matches['sign'] ) && $matches['sign'] == '-' ? "-" : ""; $digits = isset( $matches['digits'] ) ? $matches['digits'] : "0"; $decimals = isset( $matches['decimals'] ) ? "." . $matches['decimals'] : ""; $exponent = isset( $matches['exponent'] ) ? $matches['exponent'] + 0 : false; $factor = str_pad( "1", abs( $exponent ) + 1, "0", STR_PAD_RIGHT ); $decimal = new DecimalValue( "$sign$digits$decimals" ); if ( $exponent ) { if ( $exponent > 0 ) { $result = $decimal->Mul( $factor ); } else if ( $exponent && $exponent < 0 ) { $result = $decimal->Div( $factor ); } $decimal = $result; } return $decimal; }
php
public static function FromFloat( $value, $detail = true ) { if ( $value instanceof XPath2Item ) { $value = $value->getTypedValue(); } if ( $value instanceof DecimalValue ) return $value; if ( ( ! is_numeric( $value ) ) || is_infinite( $value ) || is_nan( $value ) ) { throw XPath2Exception::withErrorCodeAndParams( "FOCA0002", Resources::FOCA0002, array( $value, "Decimal" ) ); } $matched = preg_match( DecimalValue::Pattern, $detail ? sprintf( "%.018g", $value ) : $value, $matches ); if ( ! $matched ) { throw new \InvalidArgumentException( "The number '$value' cannot be parsed" ); } $sign = isset( $matches['sign'] ) && $matches['sign'] == '-' ? "-" : ""; $digits = isset( $matches['digits'] ) ? $matches['digits'] : "0"; $decimals = isset( $matches['decimals'] ) ? "." . $matches['decimals'] : ""; $exponent = isset( $matches['exponent'] ) ? $matches['exponent'] + 0 : false; $factor = str_pad( "1", abs( $exponent ) + 1, "0", STR_PAD_RIGHT ); $decimal = new DecimalValue( "$sign$digits$decimals" ); if ( $exponent ) { if ( $exponent > 0 ) { $result = $decimal->Mul( $factor ); } else if ( $exponent && $exponent < 0 ) { $result = $decimal->Div( $factor ); } $decimal = $result; } return $decimal; }
[ "public", "static", "function", "FromFloat", "(", "$", "value", ",", "$", "detail", "=", "true", ")", "{", "if", "(", "$", "value", "instanceof", "XPath2Item", ")", "{", "$", "value", "=", "$", "value", "->", "getTypedValue", "(", ")", ";", "}", "if", "(", "$", "value", "instanceof", "DecimalValue", ")", "return", "$", "value", ";", "if", "(", "(", "!", "is_numeric", "(", "$", "value", ")", ")", "||", "is_infinite", "(", "$", "value", ")", "||", "is_nan", "(", "$", "value", ")", ")", "{", "throw", "XPath2Exception", "::", "withErrorCodeAndParams", "(", "\"FOCA0002\"", ",", "Resources", "::", "FOCA0002", ",", "array", "(", "$", "value", ",", "\"Decimal\"", ")", ")", ";", "}", "$", "matched", "=", "preg_match", "(", "DecimalValue", "::", "Pattern", ",", "$", "detail", "?", "sprintf", "(", "\"%.018g\"", ",", "$", "value", ")", ":", "$", "value", ",", "$", "matches", ")", ";", "if", "(", "!", "$", "matched", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The number '$value' cannot be parsed\"", ")", ";", "}", "$", "sign", "=", "isset", "(", "$", "matches", "[", "'sign'", "]", ")", "&&", "$", "matches", "[", "'sign'", "]", "==", "'-'", "?", "\"-\"", ":", "\"\"", ";", "$", "digits", "=", "isset", "(", "$", "matches", "[", "'digits'", "]", ")", "?", "$", "matches", "[", "'digits'", "]", ":", "\"0\"", ";", "$", "decimals", "=", "isset", "(", "$", "matches", "[", "'decimals'", "]", ")", "?", "\".\"", ".", "$", "matches", "[", "'decimals'", "]", ":", "\"\"", ";", "$", "exponent", "=", "isset", "(", "$", "matches", "[", "'exponent'", "]", ")", "?", "$", "matches", "[", "'exponent'", "]", "+", "0", ":", "false", ";", "$", "factor", "=", "str_pad", "(", "\"1\"", ",", "abs", "(", "$", "exponent", ")", "+", "1", ",", "\"0\"", ",", "STR_PAD_RIGHT", ")", ";", "$", "decimal", "=", "new", "DecimalValue", "(", "\"$sign$digits$decimals\"", ")", ";", "if", "(", "$", "exponent", ")", "{", "if", "(", "$", "exponent", ">", "0", ")", "{", "$", "result", "=", "$", "decimal", "->", "Mul", "(", "$", "factor", ")", ";", "}", "else", "if", "(", "$", "exponent", "&&", "$", "exponent", "<", "0", ")", "{", "$", "result", "=", "$", "decimal", "->", "Div", "(", "$", "factor", ")", ";", "}", "$", "decimal", "=", "$", "result", ";", "}", "return", "$", "decimal", ";", "}" ]
Creates an instance from a Float value @param float $value @param bool $detail (optional: default = true) Expand the number to the most digits
[ "Creates", "an", "instance", "from", "a", "Float", "value" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L159-L199
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.Compare
public function Compare( $number, $scale = false ) { if ( ! is_numeric( $number ) ) { if ( ! $number instanceof DecimalValue && ! $number instanceof Integer ) { return false; } $number = $number->getValue(); } if ( $scale === false ) { $scale = max( $this->getScale(), $this->scale( $number ) ); } return bccomp( $this->_value, $number, $scale ); }
php
public function Compare( $number, $scale = false ) { if ( ! is_numeric( $number ) ) { if ( ! $number instanceof DecimalValue && ! $number instanceof Integer ) { return false; } $number = $number->getValue(); } if ( $scale === false ) { $scale = max( $this->getScale(), $this->scale( $number ) ); } return bccomp( $this->_value, $number, $scale ); }
[ "public", "function", "Compare", "(", "$", "number", ",", "$", "scale", "=", "false", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "number", ")", ")", "{", "if", "(", "!", "$", "number", "instanceof", "DecimalValue", "&&", "!", "$", "number", "instanceof", "Integer", ")", "{", "return", "false", ";", "}", "$", "number", "=", "$", "number", "->", "getValue", "(", ")", ";", "}", "if", "(", "$", "scale", "===", "false", ")", "{", "$", "scale", "=", "max", "(", "$", "this", "->", "getScale", "(", ")", ",", "$", "this", "->", "scale", "(", "$", "number", ")", ")", ";", "}", "return", "bccomp", "(", "$", "this", "->", "_value", ",", "$", "number", ",", "$", "scale", ")", ";", "}" ]
Compares this number with another number @param string $number @param int $scale @return int 0 if the number is the same as this number, 1 if this number is larger than the supplied number, -1 otherwise.
[ "Compares", "this", "number", "with", "another", "number" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L253-L271
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.normalize
private function normalize( $number = null ) { if ( is_null( $number ) ) $number =& $this->_value; // Handle the case of -0 if ( $this->_value == "-0" ) $this->_value = "0"; if ( strpos( $this->_value, '.' ) === false ) return; $number = trim( $number ); $number = rtrim( $number, '0'); $number = rtrim( $number, '.'); if ( $number == "" || $number == "-" ) $number .= "0"; // The leading zero may be missing if ( substr( $number, 0, 1 ) == "." ) $number = "0" . $number; if ( substr( $number, 0, 2 ) == "-." ) $number = str_replace( "-.", "-0.", $number ); if ( substr( $number, 0, 2 ) == "+." ) $number = str_replace( "+.", "0.", $number ); return $number; }
php
private function normalize( $number = null ) { if ( is_null( $number ) ) $number =& $this->_value; // Handle the case of -0 if ( $this->_value == "-0" ) $this->_value = "0"; if ( strpos( $this->_value, '.' ) === false ) return; $number = trim( $number ); $number = rtrim( $number, '0'); $number = rtrim( $number, '.'); if ( $number == "" || $number == "-" ) $number .= "0"; // The leading zero may be missing if ( substr( $number, 0, 1 ) == "." ) $number = "0" . $number; if ( substr( $number, 0, 2 ) == "-." ) $number = str_replace( "-.", "-0.", $number ); if ( substr( $number, 0, 2 ) == "+." ) $number = str_replace( "+.", "0.", $number ); return $number; }
[ "private", "function", "normalize", "(", "$", "number", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "number", ")", ")", "$", "number", "=", "&", "$", "this", "->", "_value", ";", "// Handle the case of -0\r", "if", "(", "$", "this", "->", "_value", "==", "\"-0\"", ")", "$", "this", "->", "_value", "=", "\"0\"", ";", "if", "(", "strpos", "(", "$", "this", "->", "_value", ",", "'.'", ")", "===", "false", ")", "return", ";", "$", "number", "=", "trim", "(", "$", "number", ")", ";", "$", "number", "=", "rtrim", "(", "$", "number", ",", "'0'", ")", ";", "$", "number", "=", "rtrim", "(", "$", "number", ",", "'.'", ")", ";", "if", "(", "$", "number", "==", "\"\"", "||", "$", "number", "==", "\"-\"", ")", "$", "number", ".=", "\"0\"", ";", "// The leading zero may be missing\r", "if", "(", "substr", "(", "$", "number", ",", "0", ",", "1", ")", "==", "\".\"", ")", "$", "number", "=", "\"0\"", ".", "$", "number", ";", "if", "(", "substr", "(", "$", "number", ",", "0", ",", "2", ")", "==", "\"-.\"", ")", "$", "number", "=", "str_replace", "(", "\"-.\"", ",", "\"-0.\"", ",", "$", "number", ")", ";", "if", "(", "substr", "(", "$", "number", ",", "0", ",", "2", ")", "==", "\"+.\"", ")", "$", "number", "=", "str_replace", "(", "\"+.\"", ",", "\"0.\"", ",", "$", "number", ")", ";", "return", "$", "number", ";", "}" ]
Remove spaces and any trailing zeros @param string $number @return string
[ "Remove", "spaces", "and", "any", "trailing", "zeros" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L446-L466
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.getIsDecimal
public function getIsDecimal( $number = false ) { return strpos( $number === false ? $this->_value : $number, "." ) !== false && trim( substr( $number === false ? $this->_value : $number, strpos( $number === false ? $this->_value : $number, "." ) + 1 ), "0" ); }
php
public function getIsDecimal( $number = false ) { return strpos( $number === false ? $this->_value : $number, "." ) !== false && trim( substr( $number === false ? $this->_value : $number, strpos( $number === false ? $this->_value : $number, "." ) + 1 ), "0" ); }
[ "public", "function", "getIsDecimal", "(", "$", "number", "=", "false", ")", "{", "return", "strpos", "(", "$", "number", "===", "false", "?", "$", "this", "->", "_value", ":", "$", "number", ",", "\".\"", ")", "!==", "false", "&&", "trim", "(", "substr", "(", "$", "number", "===", "false", "?", "$", "this", "->", "_value", ":", "$", "number", ",", "strpos", "(", "$", "number", "===", "false", "?", "$", "this", "->", "_value", ":", "$", "number", ",", "\".\"", ")", "+", "1", ")", ",", "\"0\"", ")", ";", "}" ]
True if the number has a fractional part and it is not zero @param double $number @return bool
[ "True", "if", "the", "number", "has", "a", "fractional", "part", "and", "it", "is", "not", "zero" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L482-L486
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.getCeil
public function getCeil() { if ( $this->getIsDecimal() === false ) { return $this; } if ( $this->getIsNegative() === true ) { return new DecimalValue( bcadd( $this->_value, '0', 0 ) ); } return new DecimalValue( bcadd( $this->_value, '1', 0 ) ); // Add one and truncate }
php
public function getCeil() { if ( $this->getIsDecimal() === false ) { return $this; } if ( $this->getIsNegative() === true ) { return new DecimalValue( bcadd( $this->_value, '0', 0 ) ); } return new DecimalValue( bcadd( $this->_value, '1', 0 ) ); // Add one and truncate }
[ "public", "function", "getCeil", "(", ")", "{", "if", "(", "$", "this", "->", "getIsDecimal", "(", ")", "===", "false", ")", "{", "return", "$", "this", ";", "}", "if", "(", "$", "this", "->", "getIsNegative", "(", ")", "===", "true", ")", "{", "return", "new", "DecimalValue", "(", "bcadd", "(", "$", "this", "->", "_value", ",", "'0'", ",", "0", ")", ")", ";", "}", "return", "new", "DecimalValue", "(", "bcadd", "(", "$", "this", "->", "_value", ",", "'1'", ",", "0", ")", ")", ";", "// Add one and truncate\r", "}" ]
Get the ceiling value of the decimal number @return DecimalValue
[ "Get", "the", "ceiling", "value", "of", "the", "decimal", "number" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L501-L514
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.getFloor
public function getFloor( $scale = false ) { if ( $this->getIsDecimal() === false ) { return $this; } if ( $this->getIsNegative() === true ) { return new DecimalValue( bcadd( $this->_value, '-1', 0 ) ); // Subtract 1 and truncate } return new DecimalValue( bcadd( $this->_value, '0', 0 ) ); }
php
public function getFloor( $scale = false ) { if ( $this->getIsDecimal() === false ) { return $this; } if ( $this->getIsNegative() === true ) { return new DecimalValue( bcadd( $this->_value, '-1', 0 ) ); // Subtract 1 and truncate } return new DecimalValue( bcadd( $this->_value, '0', 0 ) ); }
[ "public", "function", "getFloor", "(", "$", "scale", "=", "false", ")", "{", "if", "(", "$", "this", "->", "getIsDecimal", "(", ")", "===", "false", ")", "{", "return", "$", "this", ";", "}", "if", "(", "$", "this", "->", "getIsNegative", "(", ")", "===", "true", ")", "{", "return", "new", "DecimalValue", "(", "bcadd", "(", "$", "this", "->", "_value", ",", "'-1'", ",", "0", ")", ")", ";", "// Subtract 1 and truncate\r", "}", "return", "new", "DecimalValue", "(", "bcadd", "(", "$", "this", "->", "_value", ",", "'0'", ",", "0", ")", ")", ";", "}" ]
Get the number that is one @param int $scale @return DecimalValue
[ "Get", "the", "number", "that", "is", "one" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L521-L534
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.roundDigit
private function roundDigit( $scale, $mode = PHP_ROUND_HALF_UP ) { if ( $this->getIsCloserToNext( $scale, $mode ) ) { return bcadd( $this->_value, $this->getIsNegative() ? -1 : 1, 0 ); } return bcadd( $this->_value, '0', 0 ); }
php
private function roundDigit( $scale, $mode = PHP_ROUND_HALF_UP ) { if ( $this->getIsCloserToNext( $scale, $mode ) ) { return bcadd( $this->_value, $this->getIsNegative() ? -1 : 1, 0 ); } return bcadd( $this->_value, '0', 0 ); }
[ "private", "function", "roundDigit", "(", "$", "scale", ",", "$", "mode", "=", "PHP_ROUND_HALF_UP", ")", "{", "if", "(", "$", "this", "->", "getIsCloserToNext", "(", "$", "scale", ",", "$", "mode", ")", ")", "{", "return", "bcadd", "(", "$", "this", "->", "_value", ",", "$", "this", "->", "getIsNegative", "(", ")", "?", "-", "1", ":", "1", ",", "0", ")", ";", "}", "return", "bcadd", "(", "$", "this", "->", "_value", ",", "'0'", ",", "0", ")", ";", "}" ]
Round the value to the required precision and using the required mode @param $scale The scale to use for rounding. The digit at this position will be rounded in the decimal part of the number will be rounded. @param int $mode PHP_ROUND_HALF_UP (default), PHP_ROUND_HALF_DOWN, PHP_ROUND_HALF_EVEN, PHP_ROUND_HALF_ODD @return string
[ "Round", "the", "value", "to", "the", "required", "precision", "and", "using", "the", "required", "mode" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L676-L684
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.getIntegerPart
public function getIntegerPart() { if ( ! $this->getIsDecimal() ) return $this->_value; return substr( $this->_value, 0, strpos( $this->_value, "." ) ); }
php
public function getIntegerPart() { if ( ! $this->getIsDecimal() ) return $this->_value; return substr( $this->_value, 0, strpos( $this->_value, "." ) ); }
[ "public", "function", "getIntegerPart", "(", ")", "{", "if", "(", "!", "$", "this", "->", "getIsDecimal", "(", ")", ")", "return", "$", "this", "->", "_value", ";", "return", "substr", "(", "$", "this", "->", "_value", ",", "0", ",", "strpos", "(", "$", "this", "->", "_value", ",", "\".\"", ")", ")", ";", "}" ]
Return the part of the number before the decimal point Does not taken into account the size of any fraction. @return string
[ "Return", "the", "part", "of", "the", "number", "before", "the", "decimal", "point", "Does", "not", "taken", "into", "account", "the", "size", "of", "any", "fraction", "." ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L712-L716
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.getDecimalIsHalf
public function getDecimalIsHalf( $scale = false ) { if ( ! $this->getIsDecimal() ) { return false; } if ( $scale === false ) $scale = $this->scale( $this->_value ); if ( $scale < 0 ) $scale = $scale = 0; $decimalPart = $this->getDecimalPart(); if ( $scale >= strlen( $decimalPart ) ) return false; // Get the portion of the decimal part affected by the scale value $decimalPart = substr( $decimalPart, $scale ); return strlen( $decimalPart ) == 1 && $decimalPart == "5"; }
php
public function getDecimalIsHalf( $scale = false ) { if ( ! $this->getIsDecimal() ) { return false; } if ( $scale === false ) $scale = $this->scale( $this->_value ); if ( $scale < 0 ) $scale = $scale = 0; $decimalPart = $this->getDecimalPart(); if ( $scale >= strlen( $decimalPart ) ) return false; // Get the portion of the decimal part affected by the scale value $decimalPart = substr( $decimalPart, $scale ); return strlen( $decimalPart ) == 1 && $decimalPart == "5"; }
[ "public", "function", "getDecimalIsHalf", "(", "$", "scale", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "getIsDecimal", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "scale", "===", "false", ")", "$", "scale", "=", "$", "this", "->", "scale", "(", "$", "this", "->", "_value", ")", ";", "if", "(", "$", "scale", "<", "0", ")", "$", "scale", "=", "$", "scale", "=", "0", ";", "$", "decimalPart", "=", "$", "this", "->", "getDecimalPart", "(", ")", ";", "if", "(", "$", "scale", ">=", "strlen", "(", "$", "decimalPart", ")", ")", "return", "false", ";", "// Get the portion of the decimal part affected by the scale value\r", "$", "decimalPart", "=", "substr", "(", "$", "decimalPart", ",", "$", "scale", ")", ";", "return", "strlen", "(", "$", "decimalPart", ")", "==", "1", "&&", "$", "decimalPart", "==", "\"5\"", ";", "}" ]
Test to see if the digit at scale + 1 is a 5 @param int $scale @return bool
[ "Test", "to", "see", "if", "the", "digit", "at", "scale", "+", "1", "is", "a", "5" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L723-L738
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.getIsDecimalEven
public function getIsDecimalEven( $precision = false ) { if ( ! $this->getIsDecimal() ) { return false; } if ( $precision === false ) $precision = $this->scale( $this->_value ); if ( $precision < 0 ) $precision = $precision = 0; $decimalPart = $this->getDecimalPart(); if ( $precision >= strlen( $decimalPart ) ) return false; // Get the portion of the decimal part affected by the scale value $decimalPart = substr( $decimalPart, $precision ); return $decimalPart[0] % 2 === 0; }
php
public function getIsDecimalEven( $precision = false ) { if ( ! $this->getIsDecimal() ) { return false; } if ( $precision === false ) $precision = $this->scale( $this->_value ); if ( $precision < 0 ) $precision = $precision = 0; $decimalPart = $this->getDecimalPart(); if ( $precision >= strlen( $decimalPart ) ) return false; // Get the portion of the decimal part affected by the scale value $decimalPart = substr( $decimalPart, $precision ); return $decimalPart[0] % 2 === 0; }
[ "public", "function", "getIsDecimalEven", "(", "$", "precision", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "getIsDecimal", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "precision", "===", "false", ")", "$", "precision", "=", "$", "this", "->", "scale", "(", "$", "this", "->", "_value", ")", ";", "if", "(", "$", "precision", "<", "0", ")", "$", "precision", "=", "$", "precision", "=", "0", ";", "$", "decimalPart", "=", "$", "this", "->", "getDecimalPart", "(", ")", ";", "if", "(", "$", "precision", ">=", "strlen", "(", "$", "decimalPart", ")", ")", "return", "false", ";", "// Get the portion of the decimal part affected by the scale value\r", "$", "decimalPart", "=", "substr", "(", "$", "decimalPart", ",", "$", "precision", ")", ";", "return", "$", "decimalPart", "[", "0", "]", "%", "2", "===", "0", ";", "}" ]
Returns true if the digit at the required level of precision is even @param string $precision @return bool
[ "Returns", "true", "if", "the", "digit", "at", "the", "required", "level", "of", "precision", "is", "even" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L764-L779
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.getIsCloserToNext
public function getIsCloserToNext( $precision = false, $mode = PHP_ROUND_HALF_UP ) { if ( ! $this->getIsDecimal() ) { return false; } if ( $precision === false ) $precision = $this->scale( $this->_value ); if ( $precision < 0 ) $precision = $precision = 0; $decimalPart = $this->getDecimalPart(); if ( $precision >= strlen( $decimalPart ) ) return false; // Get the portion of the decimal part affected by the scale value $decimalPart = substr( $decimalPart, $precision ); $result = bccomp( "0." . $decimalPart, "0.5", max( $this->scale( $decimalPart ), 1 ) ); return $mode == PHP_ROUND_HALF_DOWN ? $result == 1 : $result >= 0; }
php
public function getIsCloserToNext( $precision = false, $mode = PHP_ROUND_HALF_UP ) { if ( ! $this->getIsDecimal() ) { return false; } if ( $precision === false ) $precision = $this->scale( $this->_value ); if ( $precision < 0 ) $precision = $precision = 0; $decimalPart = $this->getDecimalPart(); if ( $precision >= strlen( $decimalPart ) ) return false; // Get the portion of the decimal part affected by the scale value $decimalPart = substr( $decimalPart, $precision ); $result = bccomp( "0." . $decimalPart, "0.5", max( $this->scale( $decimalPart ), 1 ) ); return $mode == PHP_ROUND_HALF_DOWN ? $result == 1 : $result >= 0; }
[ "public", "function", "getIsCloserToNext", "(", "$", "precision", "=", "false", ",", "$", "mode", "=", "PHP_ROUND_HALF_UP", ")", "{", "if", "(", "!", "$", "this", "->", "getIsDecimal", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "precision", "===", "false", ")", "$", "precision", "=", "$", "this", "->", "scale", "(", "$", "this", "->", "_value", ")", ";", "if", "(", "$", "precision", "<", "0", ")", "$", "precision", "=", "$", "precision", "=", "0", ";", "$", "decimalPart", "=", "$", "this", "->", "getDecimalPart", "(", ")", ";", "if", "(", "$", "precision", ">=", "strlen", "(", "$", "decimalPart", ")", ")", "return", "false", ";", "// Get the portion of the decimal part affected by the scale value\r", "$", "decimalPart", "=", "substr", "(", "$", "decimalPart", ",", "$", "precision", ")", ";", "$", "result", "=", "bccomp", "(", "\"0.\"", ".", "$", "decimalPart", ",", "\"0.5\"", ",", "max", "(", "$", "this", "->", "scale", "(", "$", "decimalPart", ")", ",", "1", ")", ")", ";", "return", "$", "mode", "==", "PHP_ROUND_HALF_DOWN", "?", "$", "result", "==", "1", ":", "$", "result", ">=", "0", ";", "}" ]
Returns true if the number at the scale position in the decimal part of the number is closer to the next power. @param int $precision @param int $mode PHP_ROUND_HALF_UP (default), PHP_ROUND_HALF_DOWN, PHP_ROUND_HALF_EVEN, PHP_ROUND_HALF_ODD @return bool
[ "Returns", "true", "if", "the", "number", "at", "the", "scale", "position", "in", "the", "decimal", "part", "of", "the", "number", "is", "closer", "to", "the", "next", "power", "." ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L787-L803
train
bseddon/XPath20
Value/DecimalValue.php
DecimalValue.dec2bin
private function dec2bin( $decimal ) { bcscale(0); $binary = ''; do { $binary = bcmod( $decimal, '2' ) . $binary; $decimal = bcdiv( $decimal, '2' ); } while ( bccomp( $decimal, '0' ) ); return( $binary ); }
php
private function dec2bin( $decimal ) { bcscale(0); $binary = ''; do { $binary = bcmod( $decimal, '2' ) . $binary; $decimal = bcdiv( $decimal, '2' ); } while ( bccomp( $decimal, '0' ) ); return( $binary ); }
[ "private", "function", "dec2bin", "(", "$", "decimal", ")", "{", "bcscale", "(", "0", ")", ";", "$", "binary", "=", "''", ";", "do", "{", "$", "binary", "=", "bcmod", "(", "$", "decimal", ",", "'2'", ")", ".", "$", "binary", ";", "$", "decimal", "=", "bcdiv", "(", "$", "decimal", ",", "'2'", ")", ";", "}", "while", "(", "bccomp", "(", "$", "decimal", ",", "'0'", ")", ")", ";", "return", "(", "$", "binary", ")", ";", "}" ]
Create a binary representation of the current value @param string $decimal The number to be converted @return string
[ "Create", "a", "binary", "representation", "of", "the", "current", "value" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DecimalValue.php#L989-L1000
train
naucon/Utility
src/CollectionAbstract.php
CollectionAbstract.getIterator
public function getIterator() { if (is_null($this->_iterator)) { $this->_iterator = new Iterator($this->_items); } return $this->_iterator; }
php
public function getIterator() { if (is_null($this->_iterator)) { $this->_iterator = new Iterator($this->_items); } return $this->_iterator; }
[ "public", "function", "getIterator", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_iterator", ")", ")", "{", "$", "this", "->", "_iterator", "=", "new", "Iterator", "(", "$", "this", "->", "_items", ")", ";", "}", "return", "$", "this", "->", "_iterator", ";", "}" ]
return a iterator @return IteratorInterface
[ "return", "a", "iterator" ]
d225bb5d09d82400917f710c9d502949a66442c4
https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/CollectionAbstract.php#L100-L106
train
naucon/Utility
src/CollectionAbstract.php
CollectionAbstract.remove
public function remove($element) { $index = $this->indexOf($element); if ($index !== false) { unset($this->_items[$index]); $this->_items = array_values($this->_items); $this->_iterator = null; return true; } return false; }
php
public function remove($element) { $index = $this->indexOf($element); if ($index !== false) { unset($this->_items[$index]); $this->_items = array_values($this->_items); $this->_iterator = null; return true; } return false; }
[ "public", "function", "remove", "(", "$", "element", ")", "{", "$", "index", "=", "$", "this", "->", "indexOf", "(", "$", "element", ")", ";", "if", "(", "$", "index", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "_items", "[", "$", "index", "]", ")", ";", "$", "this", "->", "_items", "=", "array_values", "(", "$", "this", "->", "_items", ")", ";", "$", "this", "->", "_iterator", "=", "null", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
remove a specified element from the collection @param mixed $element element @return bool
[ "remove", "a", "specified", "element", "from", "the", "collection" ]
d225bb5d09d82400917f710c9d502949a66442c4
https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/CollectionAbstract.php#L124-L135
train
fuelphp-storage/security
src/Filter/Base.php
Base.clean
public function clean($input) { // Nothing to escape for non-string scalars, or for already processed values if (is_bool($input) or is_int($input) or is_float($input) or $this->parent->isCleaned($input)) { return $input; } if (is_string($input)) { $input = $this->cleanString($input); } elseif (is_array($input) or ($input instanceof \Iterator and $input instanceof \ArrayAccess)) { $input = $this->cleanArray($input); } elseif ($input instanceof \Iterator or get_class($input) == 'stdClass') { $input = $this->cleanObject($input); } elseif (is_object($input)) { // Check if the object is whitelisted and just return when that's the case foreach ($this->parent->getConfig('whitelistedClasses', array()) as $class) { if (is_a($input, $class)) { return $input; } } // Throw exception when it wasn't whitelisted and can't be converted to String if (! method_exists($input, '__toString')) { throw new \RuntimeException('Object class "'.get_class($input).'" could not be converted to string or '. 'sanitized as ArrayAccess. Whitelist it in security.whitelisted_classes in [application]/config/security.php '. 'to allow it to be passed unchecked.'); } $input = $this->cleanString(strval($input)); } // mark this variable as cleaned $this->parent->isClean($input); return $input; }
php
public function clean($input) { // Nothing to escape for non-string scalars, or for already processed values if (is_bool($input) or is_int($input) or is_float($input) or $this->parent->isCleaned($input)) { return $input; } if (is_string($input)) { $input = $this->cleanString($input); } elseif (is_array($input) or ($input instanceof \Iterator and $input instanceof \ArrayAccess)) { $input = $this->cleanArray($input); } elseif ($input instanceof \Iterator or get_class($input) == 'stdClass') { $input = $this->cleanObject($input); } elseif (is_object($input)) { // Check if the object is whitelisted and just return when that's the case foreach ($this->parent->getConfig('whitelistedClasses', array()) as $class) { if (is_a($input, $class)) { return $input; } } // Throw exception when it wasn't whitelisted and can't be converted to String if (! method_exists($input, '__toString')) { throw new \RuntimeException('Object class "'.get_class($input).'" could not be converted to string or '. 'sanitized as ArrayAccess. Whitelist it in security.whitelisted_classes in [application]/config/security.php '. 'to allow it to be passed unchecked.'); } $input = $this->cleanString(strval($input)); } // mark this variable as cleaned $this->parent->isClean($input); return $input; }
[ "public", "function", "clean", "(", "$", "input", ")", "{", "// Nothing to escape for non-string scalars, or for already processed values", "if", "(", "is_bool", "(", "$", "input", ")", "or", "is_int", "(", "$", "input", ")", "or", "is_float", "(", "$", "input", ")", "or", "$", "this", "->", "parent", "->", "isCleaned", "(", "$", "input", ")", ")", "{", "return", "$", "input", ";", "}", "if", "(", "is_string", "(", "$", "input", ")", ")", "{", "$", "input", "=", "$", "this", "->", "cleanString", "(", "$", "input", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "input", ")", "or", "(", "$", "input", "instanceof", "\\", "Iterator", "and", "$", "input", "instanceof", "\\", "ArrayAccess", ")", ")", "{", "$", "input", "=", "$", "this", "->", "cleanArray", "(", "$", "input", ")", ";", "}", "elseif", "(", "$", "input", "instanceof", "\\", "Iterator", "or", "get_class", "(", "$", "input", ")", "==", "'stdClass'", ")", "{", "$", "input", "=", "$", "this", "->", "cleanObject", "(", "$", "input", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "input", ")", ")", "{", "// Check if the object is whitelisted and just return when that's the case", "foreach", "(", "$", "this", "->", "parent", "->", "getConfig", "(", "'whitelistedClasses'", ",", "array", "(", ")", ")", "as", "$", "class", ")", "{", "if", "(", "is_a", "(", "$", "input", ",", "$", "class", ")", ")", "{", "return", "$", "input", ";", "}", "}", "// Throw exception when it wasn't whitelisted and can't be converted to String", "if", "(", "!", "method_exists", "(", "$", "input", ",", "'__toString'", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Object class \"'", ".", "get_class", "(", "$", "input", ")", ".", "'\" could not be converted to string or '", ".", "'sanitized as ArrayAccess. Whitelist it in security.whitelisted_classes in [application]/config/security.php '", ".", "'to allow it to be passed unchecked.'", ")", ";", "}", "$", "input", "=", "$", "this", "->", "cleanString", "(", "strval", "(", "$", "input", ")", ")", ";", "}", "// mark this variable as cleaned", "$", "this", "->", "parent", "->", "isClean", "(", "$", "input", ")", ";", "return", "$", "input", ";", "}" ]
Cleans string, object or array @param mixed $input @return mixed @throws \RuntimeException if the variable passed can not be cleaned
[ "Cleans", "string", "object", "or", "array" ]
2cad42a8432bc9c9de46486623b71e105ff84b1b
https://github.com/fuelphp-storage/security/blob/2cad42a8432bc9c9de46486623b71e105ff84b1b/src/Filter/Base.php#L39-L88
train
fuelphp-storage/security
src/Filter/Base.php
Base.cleanArray
protected function cleanArray($input) { // add to the cleaned list when object if (is_object($input)) { $this->parent->isClean($input); } foreach ($input as $k => $v) { $input[$k] = $this->clean($v); } return $input; }
php
protected function cleanArray($input) { // add to the cleaned list when object if (is_object($input)) { $this->parent->isClean($input); } foreach ($input as $k => $v) { $input[$k] = $this->clean($v); } return $input; }
[ "protected", "function", "cleanArray", "(", "$", "input", ")", "{", "// add to the cleaned list when object", "if", "(", "is_object", "(", "$", "input", ")", ")", "{", "$", "this", "->", "parent", "->", "isClean", "(", "$", "input", ")", ";", "}", "foreach", "(", "$", "input", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "input", "[", "$", "k", "]", "=", "$", "this", "->", "clean", "(", "$", "v", ")", ";", "}", "return", "$", "input", ";", "}" ]
cleanArray base method @param string $input @return string
[ "cleanArray", "base", "method" ]
2cad42a8432bc9c9de46486623b71e105ff84b1b
https://github.com/fuelphp-storage/security/blob/2cad42a8432bc9c9de46486623b71e105ff84b1b/src/Filter/Base.php#L109-L123
train
fuelphp-storage/security
src/Filter/Base.php
Base.cleanObject
protected function cleanObject($input) { // add to the cleaned list $this->parent->isClean($input); foreach ($value as $k => $v) { $value->{$k} = $this->clean($v); } return $input; }
php
protected function cleanObject($input) { // add to the cleaned list $this->parent->isClean($input); foreach ($value as $k => $v) { $value->{$k} = $this->clean($v); } return $input; }
[ "protected", "function", "cleanObject", "(", "$", "input", ")", "{", "// add to the cleaned list", "$", "this", "->", "parent", "->", "isClean", "(", "$", "input", ")", ";", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "value", "->", "{", "$", "k", "}", "=", "$", "this", "->", "clean", "(", "$", "v", ")", ";", "}", "return", "$", "input", ";", "}" ]
cleanObject base method. Not defined as abstract become some filters might not implement cleaning objects @param object $input @return object
[ "cleanObject", "base", "method", ".", "Not", "defined", "as", "abstract", "become", "some", "filters", "might", "not", "implement", "cleaning", "objects" ]
2cad42a8432bc9c9de46486623b71e105ff84b1b
https://github.com/fuelphp-storage/security/blob/2cad42a8432bc9c9de46486623b71e105ff84b1b/src/Filter/Base.php#L132-L142
train
mullanaphy/variable
src/PHY/Variable/AVar.php
AVar.complete
public function complete() { $chain = $this->chain; $this->chaining = false; $this->chain = null; return $chain; }
php
public function complete() { $chain = $this->chain; $this->chaining = false; $this->chain = null; return $chain; }
[ "public", "function", "complete", "(", ")", "{", "$", "chain", "=", "$", "this", "->", "chain", ";", "$", "this", "->", "chaining", "=", "false", ";", "$", "this", "->", "chain", "=", "null", ";", "return", "$", "chain", ";", "}" ]
Complete a chain and return it's result. @return mixed
[ "Complete", "a", "chain", "and", "return", "it", "s", "result", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/AVar.php#L84-L90
train
mullanaphy/variable
src/PHY/Variable/AVar.php
AVar.update
public function update($value) { $this->validate($value); if ($this->chaining) { $this->chain = $value; } else { $this->current = $value; } return $this; }
php
public function update($value) { $this->validate($value); if ($this->chaining) { $this->chain = $value; } else { $this->current = $value; } return $this; }
[ "public", "function", "update", "(", "$", "value", ")", "{", "$", "this", "->", "validate", "(", "$", "value", ")", ";", "if", "(", "$", "this", "->", "chaining", ")", "{", "$", "this", "->", "chain", "=", "$", "value", ";", "}", "else", "{", "$", "this", "->", "current", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Update a value. @param mixed $value @return \PHY\Variable\AVar
[ "Update", "a", "value", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/AVar.php#L98-L107
train
mullanaphy/variable
src/PHY/Variable/AVar.php
AVar.reset
public function reset() { $this->current = $this->original; $this->chaining = false; $this->chain = null; return $this; }
php
public function reset() { $this->current = $this->original; $this->chaining = false; $this->chain = null; return $this; }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "current", "=", "$", "this", "->", "original", ";", "$", "this", "->", "chaining", "=", "false", ";", "$", "this", "->", "chain", "=", "null", ";", "return", "$", "this", ";", "}" ]
Reset the variable back to it's original value. @return \PHY\Variable\AVar
[ "Reset", "the", "variable", "back", "to", "it", "s", "original", "value", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/AVar.php#L157-L163
train
mullanaphy/variable
src/PHY/Variable/AVar.php
AVar.validate
public function validate($value) { if (!in_array(gettype($value), $this->types)) { throw new Exception('Type of value "'.gettype($value)."' is not compatible with ".get_class($this)); } }
php
public function validate($value) { if (!in_array(gettype($value), $this->types)) { throw new Exception('Type of value "'.gettype($value)."' is not compatible with ".get_class($this)); } }
[ "public", "function", "validate", "(", "$", "value", ")", "{", "if", "(", "!", "in_array", "(", "gettype", "(", "$", "value", ")", ",", "$", "this", "->", "types", ")", ")", "{", "throw", "new", "Exception", "(", "'Type of value \"'", ".", "gettype", "(", "$", "value", ")", ".", "\"' is not compatible with \"", ".", "get_class", "(", "$", "this", ")", ")", ";", "}", "}" ]
Validate a variables type to make sure our class can use it. @param string $value @throws Exception
[ "Validate", "a", "variables", "type", "to", "make", "sure", "our", "class", "can", "use", "it", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/AVar.php#L171-L176
train
OpenConext/Stepup-bundle
src/Value/GssfConfig.php
GssfConfig.getLoaMap
public function getLoaMap() { $loaMap = []; foreach ($this->config as $key => $config) { if (array_key_exists('loa', $config)) { $loaMap[$key] = $config['loa']; } } return $loaMap; }
php
public function getLoaMap() { $loaMap = []; foreach ($this->config as $key => $config) { if (array_key_exists('loa', $config)) { $loaMap[$key] = $config['loa']; } } return $loaMap; }
[ "public", "function", "getLoaMap", "(", ")", "{", "$", "loaMap", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "config", "as", "$", "key", "=>", "$", "config", ")", "{", "if", "(", "array_key_exists", "(", "'loa'", ",", "$", "config", ")", ")", "{", "$", "loaMap", "[", "$", "key", "]", "=", "$", "config", "[", "'loa'", "]", ";", "}", "}", "return", "$", "loaMap", ";", "}" ]
Flattens the config and returns key value pairs where the key is the SF type and the value is the LOA level
[ "Flattens", "the", "config", "and", "returns", "key", "value", "pairs", "where", "the", "key", "is", "the", "SF", "type", "and", "the", "value", "is", "the", "LOA", "level" ]
94178ddb421889df9e068109293a8da880793ed2
https://github.com/OpenConext/Stepup-bundle/blob/94178ddb421889df9e068109293a8da880793ed2/src/Value/GssfConfig.php#L48-L57
train
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Nested/Generators/ModelGenerator.php
ModelGenerator.create
public function create( $name, $path ) { $path = $this->getPath( $name, $path ); $stub = $this->getStub( 'model' ); $this->files->put( $path, $this->parseStub( $stub, [ 'table' => $this->tableize( $name ), 'class' => $this->classify( $name ) ] ) ); return $path; }
php
public function create( $name, $path ) { $path = $this->getPath( $name, $path ); $stub = $this->getStub( 'model' ); $this->files->put( $path, $this->parseStub( $stub, [ 'table' => $this->tableize( $name ), 'class' => $this->classify( $name ) ] ) ); return $path; }
[ "public", "function", "create", "(", "$", "name", ",", "$", "path", ")", "{", "$", "path", "=", "$", "this", "->", "getPath", "(", "$", "name", ",", "$", "path", ")", ";", "$", "stub", "=", "$", "this", "->", "getStub", "(", "'model'", ")", ";", "$", "this", "->", "files", "->", "put", "(", "$", "path", ",", "$", "this", "->", "parseStub", "(", "$", "stub", ",", "[", "'table'", "=>", "$", "this", "->", "tableize", "(", "$", "name", ")", ",", "'class'", "=>", "$", "this", "->", "classify", "(", "$", "name", ")", "]", ")", ")", ";", "return", "$", "path", ";", "}" ]
Create a new model at the given path. @param string $name @param string $path @return string
[ "Create", "a", "new", "model", "at", "the", "given", "path", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/Generators/ModelGenerator.php#L12-L24
train
ScaraMVC/Framework
src/Scara/Validation/Errors.php
Errors.get
public function get($key) { $res = $this->_errors[$key]; if (!is_array($res)) { return [$res]; } return $res; }
php
public function get($key) { $res = $this->_errors[$key]; if (!is_array($res)) { return [$res]; } return $res; }
[ "public", "function", "get", "(", "$", "key", ")", "{", "$", "res", "=", "$", "this", "->", "_errors", "[", "$", "key", "]", ";", "if", "(", "!", "is_array", "(", "$", "res", ")", ")", "{", "return", "[", "$", "res", "]", ";", "}", "return", "$", "res", ";", "}" ]
Gets a specific error. @param string $key - The error we're looking for @return string - The error message
[ "Gets", "a", "specific", "error", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Validation/Errors.php#L36-L44
train
ScaraMVC/Framework
src/Scara/Validation/Errors.php
Errors.first
public function first($key) { if ($this->has($key)) { $err = $this->_errors[$key]; if (is_array($err)) { for ($i = 0; $i < count($err); $i++) { if (!empty($err[$i])) { return $err[$i]; } } } else { return $err; } } return ''; // return empty string since no key found to prevent errors }
php
public function first($key) { if ($this->has($key)) { $err = $this->_errors[$key]; if (is_array($err)) { for ($i = 0; $i < count($err); $i++) { if (!empty($err[$i])) { return $err[$i]; } } } else { return $err; } } return ''; // return empty string since no key found to prevent errors }
[ "public", "function", "first", "(", "$", "key", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "$", "err", "=", "$", "this", "->", "_errors", "[", "$", "key", "]", ";", "if", "(", "is_array", "(", "$", "err", ")", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "err", ")", ";", "$", "i", "++", ")", "{", "if", "(", "!", "empty", "(", "$", "err", "[", "$", "i", "]", ")", ")", "{", "return", "$", "err", "[", "$", "i", "]", ";", "}", "}", "}", "else", "{", "return", "$", "err", ";", "}", "}", "return", "''", ";", "// return empty string since no key found to prevent errors", "}" ]
Gets the first message for a specific error. @param string $key - The error we're looking for @return string - The error message
[ "Gets", "the", "first", "message", "for", "a", "specific", "error", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Validation/Errors.php#L53-L69
train
ScaraMVC/Framework
src/Scara/Validation/Errors.php
Errors.add
public function add($data) { $ea = (array) $data; foreach ($ea as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { if (is_null($v)) { unset($value[$k]); } } $value = array_values($value); $ea[$key] = $value; } } $this->_errors = $ea; }
php
public function add($data) { $ea = (array) $data; foreach ($ea as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { if (is_null($v)) { unset($value[$k]); } } $value = array_values($value); $ea[$key] = $value; } } $this->_errors = $ea; }
[ "public", "function", "add", "(", "$", "data", ")", "{", "$", "ea", "=", "(", "array", ")", "$", "data", ";", "foreach", "(", "$", "ea", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "is_null", "(", "$", "v", ")", ")", "{", "unset", "(", "$", "value", "[", "$", "k", "]", ")", ";", "}", "}", "$", "value", "=", "array_values", "(", "$", "value", ")", ";", "$", "ea", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "$", "this", "->", "_errors", "=", "$", "ea", ";", "}" ]
Adds all error data. Also clears out any null values. @param array $data - The error data to load into
[ "Adds", "all", "error", "data", ".", "Also", "clears", "out", "any", "null", "values", "." ]
199b08b45fadf5dae14ac4732af03b36e15bbef2
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Validation/Errors.php#L76-L92
train
WellCommerce/LayoutBundle
Renderer/LayoutBoxRenderer.php
LayoutBoxRenderer.resolveControllerAction
private function resolveControllerAction(BoxControllerInterface $controller) { $currentAction = $this->routerHelper->getCurrentAction(); if ($this->routerHelper->hasControllerAction($controller, $currentAction)) { return $currentAction; } return 'indexAction'; }
php
private function resolveControllerAction(BoxControllerInterface $controller) { $currentAction = $this->routerHelper->getCurrentAction(); if ($this->routerHelper->hasControllerAction($controller, $currentAction)) { return $currentAction; } return 'indexAction'; }
[ "private", "function", "resolveControllerAction", "(", "BoxControllerInterface", "$", "controller", ")", "{", "$", "currentAction", "=", "$", "this", "->", "routerHelper", "->", "getCurrentAction", "(", ")", ";", "if", "(", "$", "this", "->", "routerHelper", "->", "hasControllerAction", "(", "$", "controller", ",", "$", "currentAction", ")", ")", "{", "return", "$", "currentAction", ";", "}", "return", "'indexAction'", ";", "}" ]
Resolves action which can be used in controller method call @param BoxControllerInterface $controller @return string
[ "Resolves", "action", "which", "can", "be", "used", "in", "controller", "method", "call" ]
470efd187d19827058f88317221cb875b4c9ced3
https://github.com/WellCommerce/LayoutBundle/blob/470efd187d19827058f88317221cb875b4c9ced3/Renderer/LayoutBoxRenderer.php#L111-L120
train
WellBloud/sovacore-core
src/model/FrontModule/repository/BaseRepository.php
BaseRepository.findPublishedItems
public function findPublishedItems( array $where, $orderBy = null, $limit = null ) { return $this->repository->findBy(array_merge($where, ['published' => true]), $orderBy, $limit); }
php
public function findPublishedItems( array $where, $orderBy = null, $limit = null ) { return $this->repository->findBy(array_merge($where, ['published' => true]), $orderBy, $limit); }
[ "public", "function", "findPublishedItems", "(", "array", "$", "where", ",", "$", "orderBy", "=", "null", ",", "$", "limit", "=", "null", ")", "{", "return", "$", "this", "->", "repository", "->", "findBy", "(", "array_merge", "(", "$", "where", ",", "[", "'published'", "=>", "true", "]", ")", ",", "$", "orderBy", ",", "$", "limit", ")", ";", "}" ]
Method which finds published items in the repository according to the where clause @param array $where @param array $orderBy @param int $limit @return array
[ "Method", "which", "finds", "published", "items", "in", "the", "repository", "according", "to", "the", "where", "clause" ]
1816a0d7cd3ec4a90d64e301fc2469d171ad217f
https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/FrontModule/repository/BaseRepository.php#L26-L33
train
agentmedia/phine-core
src/Core/Logic/Module/FrontendModule.php
FrontendModule.TemplateFile
public function TemplateFile() { if (!$this->AllowCustomTemplates() || !$this->content || !$this->content->GetTemplate()) { return $this->BuiltInTemplateFile(); } $file = Path::Combine(PathUtil::ModuleCustomTemplatesFolder($this), $this->content->GetTemplate()); return Path::AddExtension($file, 'phtml'); }
php
public function TemplateFile() { if (!$this->AllowCustomTemplates() || !$this->content || !$this->content->GetTemplate()) { return $this->BuiltInTemplateFile(); } $file = Path::Combine(PathUtil::ModuleCustomTemplatesFolder($this), $this->content->GetTemplate()); return Path::AddExtension($file, 'phtml'); }
[ "public", "function", "TemplateFile", "(", ")", "{", "if", "(", "!", "$", "this", "->", "AllowCustomTemplates", "(", ")", "||", "!", "$", "this", "->", "content", "||", "!", "$", "this", "->", "content", "->", "GetTemplate", "(", ")", ")", "{", "return", "$", "this", "->", "BuiltInTemplateFile", "(", ")", ";", "}", "$", "file", "=", "Path", "::", "Combine", "(", "PathUtil", "::", "ModuleCustomTemplatesFolder", "(", "$", "this", ")", ",", "$", "this", "->", "content", "->", "GetTemplate", "(", ")", ")", ";", "return", "Path", "::", "AddExtension", "(", "$", "file", ",", "'phtml'", ")", ";", "}" ]
The template file @return string
[ "The", "template", "file" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/FrontendModule.php#L47-L56
train
agentmedia/phine-core
src/Core/Logic/Module/FrontendModule.php
FrontendModule.SetTreeItem
public function SetTreeItem(IContentTreeProvider $tree, $item) { $this->tree = $tree; $this->item = $item; $this->content = $this->tree->ContentByItem($item); }
php
public function SetTreeItem(IContentTreeProvider $tree, $item) { $this->tree = $tree; $this->item = $item; $this->content = $this->tree->ContentByItem($item); }
[ "public", "function", "SetTreeItem", "(", "IContentTreeProvider", "$", "tree", ",", "$", "item", ")", "{", "$", "this", "->", "tree", "=", "$", "tree", ";", "$", "this", "->", "item", "=", "$", "item", ";", "$", "this", "->", "content", "=", "$", "this", "->", "tree", "->", "ContentByItem", "(", "$", "item", ")", ";", "}" ]
Sets tree and tree item @param IContentTreeProvider $tree @param mixed $item The tree item containing the render content
[ "Sets", "tree", "and", "tree", "item" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/FrontendModule.php#L81-L86
train
agentmedia/phine-core
src/Core/Logic/Module/FrontendModule.php
FrontendModule.BackendName
public function BackendName() { if ($this->ContentForm()) { $this->ContentForm()->ReadTranslations(); } return Trans($this->MyBundle() . '.' . $this->MyName() . '.BackendName'); }
php
public function BackendName() { if ($this->ContentForm()) { $this->ContentForm()->ReadTranslations(); } return Trans($this->MyBundle() . '.' . $this->MyName() . '.BackendName'); }
[ "public", "function", "BackendName", "(", ")", "{", "if", "(", "$", "this", "->", "ContentForm", "(", ")", ")", "{", "$", "this", "->", "ContentForm", "(", ")", "->", "ReadTranslations", "(", ")", ";", "}", "return", "Trans", "(", "$", "this", "->", "MyBundle", "(", ")", ".", "'.'", ".", "$", "this", "->", "MyName", "(", ")", ".", "'.BackendName'", ")", ";", "}" ]
Gets a display name for backend issues, can be overridden @return string The display name
[ "Gets", "a", "display", "name", "for", "backend", "issues", "can", "be", "overridden" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/FrontendModule.php#L92-L99
train
agentmedia/phine-core
src/Core/Logic/Module/FrontendModule.php
FrontendModule.BeforeInit
protected function BeforeInit() { //todo: check access rights $cacheFile = PathUtil::ContentCacheFile($this); $this->fileCacher = new FileCacher($cacheFile, $this->content->GetCacheLifetime()); if ($this->fileCacher->MustUseCache()) { $this->output = $this->fileCacher->GetFromCache(); return true; } return parent::BeforeInit(); }
php
protected function BeforeInit() { //todo: check access rights $cacheFile = PathUtil::ContentCacheFile($this); $this->fileCacher = new FileCacher($cacheFile, $this->content->GetCacheLifetime()); if ($this->fileCacher->MustUseCache()) { $this->output = $this->fileCacher->GetFromCache(); return true; } return parent::BeforeInit(); }
[ "protected", "function", "BeforeInit", "(", ")", "{", "//todo: check access rights", "$", "cacheFile", "=", "PathUtil", "::", "ContentCacheFile", "(", "$", "this", ")", ";", "$", "this", "->", "fileCacher", "=", "new", "FileCacher", "(", "$", "cacheFile", ",", "$", "this", "->", "content", "->", "GetCacheLifetime", "(", ")", ")", ";", "if", "(", "$", "this", "->", "fileCacher", "->", "MustUseCache", "(", ")", ")", "{", "$", "this", "->", "output", "=", "$", "this", "->", "fileCacher", "->", "GetFromCache", "(", ")", ";", "return", "true", ";", "}", "return", "parent", "::", "BeforeInit", "(", ")", ";", "}" ]
Gets cache content if necessary @return boolean
[ "Gets", "cache", "content", "if", "necessary" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/FrontendModule.php#L197-L208
train
agentmedia/phine-core
src/Core/Logic/Module/FrontendModule.php
FrontendModule.AfterGather
protected function AfterGather() { if ($this->fileCacher->MustStoreToCache()) { $this->fileCacher->StoreToCache($this->output); } parent::AfterGather(); }
php
protected function AfterGather() { if ($this->fileCacher->MustStoreToCache()) { $this->fileCacher->StoreToCache($this->output); } parent::AfterGather(); }
[ "protected", "function", "AfterGather", "(", ")", "{", "if", "(", "$", "this", "->", "fileCacher", "->", "MustStoreToCache", "(", ")", ")", "{", "$", "this", "->", "fileCacher", "->", "StoreToCache", "(", "$", "this", "->", "output", ")", ";", "}", "parent", "::", "AfterGather", "(", ")", ";", "}" ]
Stores to cache if necessary
[ "Stores", "to", "cache", "if", "necessary" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/FrontendModule.php#L212-L219
train
CalderaWP/caldera-interop
src/Collections/Attributes.php
Attributes.addAttribute
public function addAttribute(Attribute$attribute) : Attributes { $this->getItems();//max sure is array $this->attributes[$attribute->getName()] = $attribute; return $this; }
php
public function addAttribute(Attribute$attribute) : Attributes { $this->getItems();//max sure is array $this->attributes[$attribute->getName()] = $attribute; return $this; }
[ "public", "function", "addAttribute", "(", "Attribute", "$", "attribute", ")", ":", "Attributes", "{", "$", "this", "->", "getItems", "(", ")", ";", "//max sure is array", "$", "this", "->", "attributes", "[", "$", "attribute", "->", "getName", "(", ")", "]", "=", "$", "attribute", ";", "return", "$", "this", ";", "}" ]
Add attribute to collection @param Attribute $attribute @return Attributes
[ "Add", "attribute", "to", "collection" ]
d25c4bc930200b314fbd42d084080b5d85261c94
https://github.com/CalderaWP/caldera-interop/blob/d25c4bc930200b314fbd42d084080b5d85261c94/src/Collections/Attributes.php#L36-L41
train
PenoaksDev/Milky-Framework
src/Milky/Facades/Log.php
Log.log
public static function log( $level, $message, array $context = [] ) { return static::__do( __FUNCTION__, args_with_keys( func_get_args(), __CLASS__, __FUNCTION__ ) ); }
php
public static function log( $level, $message, array $context = [] ) { return static::__do( __FUNCTION__, args_with_keys( func_get_args(), __CLASS__, __FUNCTION__ ) ); }
[ "public", "static", "function", "log", "(", "$", "level", ",", "$", "message", ",", "array", "$", "context", "=", "[", "]", ")", "{", "return", "static", "::", "__do", "(", "__FUNCTION__", ",", "args_with_keys", "(", "func_get_args", "(", ")", ",", "__CLASS__", ",", "__FUNCTION__", ")", ")", ";", "}" ]
Logging a message to the logs. @param string $level @param string $message @param array $context
[ "Logging", "a", "message", "to", "the", "logs", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Facades/Log.php#L115-L118
train
internetofvoice/vsms-core
src/Controller/AbstractSkillController.php
AbstractSkillController.createAlexaRequest
protected function createAlexaRequest($request) { $this->voiceInterface = 'Alexa'; // Create AlexaRequest from HTTP request $this->alexaRequest = new AlexaRequest( $request->getBody()->getContents(), $this->askApplicationIds, $request->getHeaderLine('Signaturecertchainurl'), $request->getHeaderLine('Signature'), $this->settings['validateTimestamp'], $this->settings['validateCertificate'] ); // Update auto initialized translator as Alexa request might contain a locale if($this->alexaRequest->getRequest()->getLocale() && in_array('translator', $this->settings['auto_init'])) { $this->translator->chooseLocale($this->alexaRequest->getRequest()->getLocale()); } // Create new AlexaResponse $this->alexaResponse = new AlexaResponse; }
php
protected function createAlexaRequest($request) { $this->voiceInterface = 'Alexa'; // Create AlexaRequest from HTTP request $this->alexaRequest = new AlexaRequest( $request->getBody()->getContents(), $this->askApplicationIds, $request->getHeaderLine('Signaturecertchainurl'), $request->getHeaderLine('Signature'), $this->settings['validateTimestamp'], $this->settings['validateCertificate'] ); // Update auto initialized translator as Alexa request might contain a locale if($this->alexaRequest->getRequest()->getLocale() && in_array('translator', $this->settings['auto_init'])) { $this->translator->chooseLocale($this->alexaRequest->getRequest()->getLocale()); } // Create new AlexaResponse $this->alexaResponse = new AlexaResponse; }
[ "protected", "function", "createAlexaRequest", "(", "$", "request", ")", "{", "$", "this", "->", "voiceInterface", "=", "'Alexa'", ";", "// Create AlexaRequest from HTTP request", "$", "this", "->", "alexaRequest", "=", "new", "AlexaRequest", "(", "$", "request", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ",", "$", "this", "->", "askApplicationIds", ",", "$", "request", "->", "getHeaderLine", "(", "'Signaturecertchainurl'", ")", ",", "$", "request", "->", "getHeaderLine", "(", "'Signature'", ")", ",", "$", "this", "->", "settings", "[", "'validateTimestamp'", "]", ",", "$", "this", "->", "settings", "[", "'validateCertificate'", "]", ")", ";", "// Update auto initialized translator as Alexa request might contain a locale", "if", "(", "$", "this", "->", "alexaRequest", "->", "getRequest", "(", ")", "->", "getLocale", "(", ")", "&&", "in_array", "(", "'translator'", ",", "$", "this", "->", "settings", "[", "'auto_init'", "]", ")", ")", "{", "$", "this", "->", "translator", "->", "chooseLocale", "(", "$", "this", "->", "alexaRequest", "->", "getRequest", "(", ")", "->", "getLocale", "(", ")", ")", ";", "}", "// Create new AlexaResponse", "$", "this", "->", "alexaResponse", "=", "new", "AlexaResponse", ";", "}" ]
Create Alexa Request from Slim Request @param \Slim\Http\Request $request Slim request @access protected @author [email protected]
[ "Create", "Alexa", "Request", "from", "Slim", "Request" ]
bd1eb6ca90a55f4928c35b9f0742a5cc922298ef
https://github.com/internetofvoice/vsms-core/blob/bd1eb6ca90a55f4928c35b9f0742a5cc922298ef/src/Controller/AbstractSkillController.php#L60-L80
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php
GraphvizDumper.dump
public function dump(array $options = array()) { foreach (array('graph', 'node', 'edge', 'node.instance', 'node.definition', 'node.missing') as $key) { if (isset($options[$key])) { $this->options[$key] = array_merge($this->options[$key], $options[$key]); } } $this->nodes = $this->findNodes(); $this->edges = array(); foreach ($this->container->getDefinitions() as $id => $definition) { $this->edges[$id] = array_merge( $this->findEdges($id, $definition->getArguments(), true, ''), $this->findEdges($id, $definition->getProperties(), false, '') ); foreach ($definition->getMethodCalls() as $call) { $this->edges[$id] = array_merge( $this->edges[$id], $this->findEdges($id, $call[1], false, $call[0].'()') ); } } return $this->container->resolveEnvPlaceholders($this->startDot().$this->addNodes().$this->addEdges().$this->endDot(), '__ENV_%s__'); }
php
public function dump(array $options = array()) { foreach (array('graph', 'node', 'edge', 'node.instance', 'node.definition', 'node.missing') as $key) { if (isset($options[$key])) { $this->options[$key] = array_merge($this->options[$key], $options[$key]); } } $this->nodes = $this->findNodes(); $this->edges = array(); foreach ($this->container->getDefinitions() as $id => $definition) { $this->edges[$id] = array_merge( $this->findEdges($id, $definition->getArguments(), true, ''), $this->findEdges($id, $definition->getProperties(), false, '') ); foreach ($definition->getMethodCalls() as $call) { $this->edges[$id] = array_merge( $this->edges[$id], $this->findEdges($id, $call[1], false, $call[0].'()') ); } } return $this->container->resolveEnvPlaceholders($this->startDot().$this->addNodes().$this->addEdges().$this->endDot(), '__ENV_%s__'); }
[ "public", "function", "dump", "(", "array", "$", "options", "=", "array", "(", ")", ")", "{", "foreach", "(", "array", "(", "'graph'", ",", "'node'", ",", "'edge'", ",", "'node.instance'", ",", "'node.definition'", ",", "'node.missing'", ")", "as", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "options", "[", "$", "key", "]", "=", "array_merge", "(", "$", "this", "->", "options", "[", "$", "key", "]", ",", "$", "options", "[", "$", "key", "]", ")", ";", "}", "}", "$", "this", "->", "nodes", "=", "$", "this", "->", "findNodes", "(", ")", ";", "$", "this", "->", "edges", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "container", "->", "getDefinitions", "(", ")", "as", "$", "id", "=>", "$", "definition", ")", "{", "$", "this", "->", "edges", "[", "$", "id", "]", "=", "array_merge", "(", "$", "this", "->", "findEdges", "(", "$", "id", ",", "$", "definition", "->", "getArguments", "(", ")", ",", "true", ",", "''", ")", ",", "$", "this", "->", "findEdges", "(", "$", "id", ",", "$", "definition", "->", "getProperties", "(", ")", ",", "false", ",", "''", ")", ")", ";", "foreach", "(", "$", "definition", "->", "getMethodCalls", "(", ")", "as", "$", "call", ")", "{", "$", "this", "->", "edges", "[", "$", "id", "]", "=", "array_merge", "(", "$", "this", "->", "edges", "[", "$", "id", "]", ",", "$", "this", "->", "findEdges", "(", "$", "id", ",", "$", "call", "[", "1", "]", ",", "false", ",", "$", "call", "[", "0", "]", ".", "'()'", ")", ")", ";", "}", "}", "return", "$", "this", "->", "container", "->", "resolveEnvPlaceholders", "(", "$", "this", "->", "startDot", "(", ")", ".", "$", "this", "->", "addNodes", "(", ")", ".", "$", "this", "->", "addEdges", "(", ")", ".", "$", "this", "->", "endDot", "(", ")", ",", "'__ENV_%s__'", ")", ";", "}" ]
Dumps the service container as a graphviz graph. Available options: * graph: The default options for the whole graph * node: The default options for nodes * edge: The default options for edges * node.instance: The default options for services that are defined directly by object instances * node.definition: The default options for services that are defined via service definition instances * node.missing: The default options for missing services @return string The dot representation of the service container
[ "Dumps", "the", "service", "container", "as", "a", "graphviz", "graph", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php#L58-L84
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php
GraphvizDumper.startDot
private function startDot() { return sprintf("digraph sc {\n %s\n node [%s];\n edge [%s];\n\n", $this->addOptions($this->options['graph']), $this->addOptions($this->options['node']), $this->addOptions($this->options['edge']) ); }
php
private function startDot() { return sprintf("digraph sc {\n %s\n node [%s];\n edge [%s];\n\n", $this->addOptions($this->options['graph']), $this->addOptions($this->options['node']), $this->addOptions($this->options['edge']) ); }
[ "private", "function", "startDot", "(", ")", "{", "return", "sprintf", "(", "\"digraph sc {\\n %s\\n node [%s];\\n edge [%s];\\n\\n\"", ",", "$", "this", "->", "addOptions", "(", "$", "this", "->", "options", "[", "'graph'", "]", ")", ",", "$", "this", "->", "addOptions", "(", "$", "this", "->", "options", "[", "'node'", "]", ")", ",", "$", "this", "->", "addOptions", "(", "$", "this", "->", "options", "[", "'edge'", "]", ")", ")", ";", "}" ]
Returns the start dot. @return string The string representation of a start dot
[ "Returns", "the", "start", "dot", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php#L220-L227
train
gplcart/cli
controllers/commands/Status.php
Status.cmdStatusStatus
public function cmdStatusStatus() { $result = $this->report->getStatus(); $this->outputFormat($result); $this->outputFormatTableStatus($result); $this->output(); }
php
public function cmdStatusStatus() { $result = $this->report->getStatus(); $this->outputFormat($result); $this->outputFormatTableStatus($result); $this->output(); }
[ "public", "function", "cmdStatusStatus", "(", ")", "{", "$", "result", "=", "$", "this", "->", "report", "->", "getStatus", "(", ")", ";", "$", "this", "->", "outputFormat", "(", "$", "result", ")", ";", "$", "this", "->", "outputFormatTableStatus", "(", "$", "result", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "status" command
[ "Callback", "for", "status", "command" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Status.php#L40-L46
train
ekyna/Resource
Doctrine/ORM/Util/ResourceRepositoryTrait.php
ResourceRepositoryTrait.find
public function find($id) { return $this ->getQueryBuilder() ->andWhere($this->getAlias().'.id = '.intval($id)) ->getQuery() ->getOneOrNullResult() ; }
php
public function find($id) { return $this ->getQueryBuilder() ->andWhere($this->getAlias().'.id = '.intval($id)) ->getQuery() ->getOneOrNullResult() ; }
[ "public", "function", "find", "(", "$", "id", ")", "{", "return", "$", "this", "->", "getQueryBuilder", "(", ")", "->", "andWhere", "(", "$", "this", "->", "getAlias", "(", ")", ".", "'.id = '", ".", "intval", "(", "$", "id", ")", ")", "->", "getQuery", "(", ")", "->", "getOneOrNullResult", "(", ")", ";", "}" ]
Finds the resource by his ID. @param int $id @return null|object
[ "Finds", "the", "resource", "by", "his", "ID", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Doctrine/ORM/Util/ResourceRepositoryTrait.php#L44-L52
train
ekyna/Resource
Doctrine/ORM/Util/ResourceRepositoryTrait.php
ResourceRepositoryTrait.findBy
public function findBy(array $criteria, array $sorting = null, $limit = null, $offset = null) { $queryBuilder = $this->getCollectionQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); $this->applySorting($queryBuilder, (array) $sorting); if (null !== $limit) { $queryBuilder->setMaxResults($limit); } if (null !== $offset) { $queryBuilder->setFirstResult($offset); } $query = $queryBuilder->getQuery(); if (null !== $limit) { return $this->collectionResult($query); } return $query->getResult(); }
php
public function findBy(array $criteria, array $sorting = null, $limit = null, $offset = null) { $queryBuilder = $this->getCollectionQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); $this->applySorting($queryBuilder, (array) $sorting); if (null !== $limit) { $queryBuilder->setMaxResults($limit); } if (null !== $offset) { $queryBuilder->setFirstResult($offset); } $query = $queryBuilder->getQuery(); if (null !== $limit) { return $this->collectionResult($query); } return $query->getResult(); }
[ "public", "function", "findBy", "(", "array", "$", "criteria", ",", "array", "$", "sorting", "=", "null", ",", "$", "limit", "=", "null", ",", "$", "offset", "=", "null", ")", "{", "$", "queryBuilder", "=", "$", "this", "->", "getCollectionQueryBuilder", "(", ")", ";", "$", "this", "->", "applyCriteria", "(", "$", "queryBuilder", ",", "$", "criteria", ")", ";", "$", "this", "->", "applySorting", "(", "$", "queryBuilder", ",", "(", "array", ")", "$", "sorting", ")", ";", "if", "(", "null", "!==", "$", "limit", ")", "{", "$", "queryBuilder", "->", "setMaxResults", "(", "$", "limit", ")", ";", "}", "if", "(", "null", "!==", "$", "offset", ")", "{", "$", "queryBuilder", "->", "setFirstResult", "(", "$", "offset", ")", ";", "}", "$", "query", "=", "$", "queryBuilder", "->", "getQuery", "(", ")", ";", "if", "(", "null", "!==", "$", "limit", ")", "{", "return", "$", "this", "->", "collectionResult", "(", "$", "query", ")", ";", "}", "return", "$", "query", "->", "getResult", "(", ")", ";", "}" ]
Finds resources by criteria, sorting, limit and offset. @param array $criteria @param array $sorting @param int $limit @param int $offset @return array|\Doctrine\ORM\Tools\Pagination\Paginator
[ "Finds", "resources", "by", "criteria", "sorting", "limit", "and", "offset", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Doctrine/ORM/Util/ResourceRepositoryTrait.php#L97-L119
train
ekyna/Resource
Doctrine/ORM/Util/ResourceRepositoryTrait.php
ResourceRepositoryTrait.findRandomOneBy
public function findRandomOneBy(array $criteria) { $queryBuilder = $this->getQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); return $queryBuilder ->addSelect('RAND() as HIDDEN rand') ->orderBy('rand') ->setMaxResults(1) ->getQuery() ->getOneOrNullResult() ; }
php
public function findRandomOneBy(array $criteria) { $queryBuilder = $this->getQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); return $queryBuilder ->addSelect('RAND() as HIDDEN rand') ->orderBy('rand') ->setMaxResults(1) ->getQuery() ->getOneOrNullResult() ; }
[ "public", "function", "findRandomOneBy", "(", "array", "$", "criteria", ")", "{", "$", "queryBuilder", "=", "$", "this", "->", "getQueryBuilder", "(", ")", ";", "$", "this", "->", "applyCriteria", "(", "$", "queryBuilder", ",", "$", "criteria", ")", ";", "return", "$", "queryBuilder", "->", "addSelect", "(", "'RAND() as HIDDEN rand'", ")", "->", "orderBy", "(", "'rand'", ")", "->", "setMaxResults", "(", "1", ")", "->", "getQuery", "(", ")", "->", "getOneOrNullResult", "(", ")", ";", "}" ]
Finds a random resource by criteria. @param array $criteria @return null|object
[ "Finds", "a", "random", "resource", "by", "criteria", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Doctrine/ORM/Util/ResourceRepositoryTrait.php#L128-L141
train
ekyna/Resource
Doctrine/ORM/Util/ResourceRepositoryTrait.php
ResourceRepositoryTrait.findRandomBy
public function findRandomBy(array $criteria, $limit) { $limit = intval($limit); if ($limit <= 1) { throw new \InvalidArgumentException('Please use `findRandomOneBy()` for single result.'); } $queryBuilder = $this->getCollectionQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); $query = $queryBuilder ->addSelect('RAND() as HIDDEN rand') ->orderBy('rand') ->setMaxResults($limit) ->getQuery() ; return $this->collectionResult($query); }
php
public function findRandomBy(array $criteria, $limit) { $limit = intval($limit); if ($limit <= 1) { throw new \InvalidArgumentException('Please use `findRandomOneBy()` for single result.'); } $queryBuilder = $this->getCollectionQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); $query = $queryBuilder ->addSelect('RAND() as HIDDEN rand') ->orderBy('rand') ->setMaxResults($limit) ->getQuery() ; return $this->collectionResult($query); }
[ "public", "function", "findRandomBy", "(", "array", "$", "criteria", ",", "$", "limit", ")", "{", "$", "limit", "=", "intval", "(", "$", "limit", ")", ";", "if", "(", "$", "limit", "<=", "1", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Please use `findRandomOneBy()` for single result.'", ")", ";", "}", "$", "queryBuilder", "=", "$", "this", "->", "getCollectionQueryBuilder", "(", ")", ";", "$", "this", "->", "applyCriteria", "(", "$", "queryBuilder", ",", "$", "criteria", ")", ";", "$", "query", "=", "$", "queryBuilder", "->", "addSelect", "(", "'RAND() as HIDDEN rand'", ")", "->", "orderBy", "(", "'rand'", ")", "->", "setMaxResults", "(", "$", "limit", ")", "->", "getQuery", "(", ")", ";", "return", "$", "this", "->", "collectionResult", "(", "$", "query", ")", ";", "}" ]
Finds random resource by criteria and limit. @param array $criteria @param int $limit @return array|\Doctrine\ORM\Tools\Pagination\Paginator
[ "Finds", "random", "resource", "by", "criteria", "and", "limit", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Doctrine/ORM/Util/ResourceRepositoryTrait.php#L151-L170
train
ekyna/Resource
Doctrine/ORM/Util/ResourceRepositoryTrait.php
ResourceRepositoryTrait.createPager
public function createPager(array $criteria = [], array $sorting = []) { $queryBuilder = $this->getCollectionQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); $this->applySorting($queryBuilder, $sorting); return $this->getPager($queryBuilder); }
php
public function createPager(array $criteria = [], array $sorting = []) { $queryBuilder = $this->getCollectionQueryBuilder(); $this->applyCriteria($queryBuilder, $criteria); $this->applySorting($queryBuilder, $sorting); return $this->getPager($queryBuilder); }
[ "public", "function", "createPager", "(", "array", "$", "criteria", "=", "[", "]", ",", "array", "$", "sorting", "=", "[", "]", ")", "{", "$", "queryBuilder", "=", "$", "this", "->", "getCollectionQueryBuilder", "(", ")", ";", "$", "this", "->", "applyCriteria", "(", "$", "queryBuilder", ",", "$", "criteria", ")", ";", "$", "this", "->", "applySorting", "(", "$", "queryBuilder", ",", "$", "sorting", ")", ";", "return", "$", "this", "->", "getPager", "(", "$", "queryBuilder", ")", ";", "}" ]
Creates a pager. @param array $criteria @param array $sorting @return Pagerfanta
[ "Creates", "a", "pager", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Doctrine/ORM/Util/ResourceRepositoryTrait.php#L180-L188
train
ekyna/Resource
Doctrine/ORM/Util/ResourceRepositoryTrait.php
ResourceRepositoryTrait.applyCriteria
protected function applyCriteria(QueryBuilder $queryBuilder, array $criteria = []) { foreach ($criteria as $property => $value) { $name = $this->getPropertyName($property); if (null === $value) { $queryBuilder->andWhere($queryBuilder->expr()->isNull($name)); } elseif (is_array($value)) { $queryBuilder->andWhere($queryBuilder->expr()->in($name, $value)); } elseif ('' !== $value) { $parameter = str_replace('.', '_', $property); $queryBuilder ->andWhere($queryBuilder->expr()->eq($name, ':'.$parameter)) ->setParameter($parameter, $value) ; } } }
php
protected function applyCriteria(QueryBuilder $queryBuilder, array $criteria = []) { foreach ($criteria as $property => $value) { $name = $this->getPropertyName($property); if (null === $value) { $queryBuilder->andWhere($queryBuilder->expr()->isNull($name)); } elseif (is_array($value)) { $queryBuilder->andWhere($queryBuilder->expr()->in($name, $value)); } elseif ('' !== $value) { $parameter = str_replace('.', '_', $property); $queryBuilder ->andWhere($queryBuilder->expr()->eq($name, ':'.$parameter)) ->setParameter($parameter, $value) ; } } }
[ "protected", "function", "applyCriteria", "(", "QueryBuilder", "$", "queryBuilder", ",", "array", "$", "criteria", "=", "[", "]", ")", "{", "foreach", "(", "$", "criteria", "as", "$", "property", "=>", "$", "value", ")", "{", "$", "name", "=", "$", "this", "->", "getPropertyName", "(", "$", "property", ")", ";", "if", "(", "null", "===", "$", "value", ")", "{", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "isNull", "(", "$", "name", ")", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "in", "(", "$", "name", ",", "$", "value", ")", ")", ";", "}", "elseif", "(", "''", "!==", "$", "value", ")", "{", "$", "parameter", "=", "str_replace", "(", "'.'", ",", "'_'", ",", "$", "property", ")", ";", "$", "queryBuilder", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "$", "name", ",", "':'", ".", "$", "parameter", ")", ")", "->", "setParameter", "(", "$", "parameter", ",", "$", "value", ")", ";", "}", "}", "}" ]
Applies the criteria to the query builder. @param QueryBuilder $queryBuilder @param array $criteria
[ "Applies", "the", "criteria", "to", "the", "query", "builder", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Doctrine/ORM/Util/ResourceRepositoryTrait.php#L265-L281
train
ekyna/Resource
Doctrine/ORM/Util/ResourceRepositoryTrait.php
ResourceRepositoryTrait.getCachePrefix
public function getCachePrefix() { if ($this->cachePrefix) { return $this->cachePrefix; } $class = $this->getClassName(); if (!in_array(TaggedEntityInterface::class, class_implements($class))) { throw new \RuntimeException(sprintf( 'The entity %s does not implements %s, query should not be cached.', $class, TaggedEntityInterface::class )); } return $this->cachePrefix = call_user_func([$this->getClassName(), 'getEntityTagPrefix']); }
php
public function getCachePrefix() { if ($this->cachePrefix) { return $this->cachePrefix; } $class = $this->getClassName(); if (!in_array(TaggedEntityInterface::class, class_implements($class))) { throw new \RuntimeException(sprintf( 'The entity %s does not implements %s, query should not be cached.', $class, TaggedEntityInterface::class )); } return $this->cachePrefix = call_user_func([$this->getClassName(), 'getEntityTagPrefix']); }
[ "public", "function", "getCachePrefix", "(", ")", "{", "if", "(", "$", "this", "->", "cachePrefix", ")", "{", "return", "$", "this", "->", "cachePrefix", ";", "}", "$", "class", "=", "$", "this", "->", "getClassName", "(", ")", ";", "if", "(", "!", "in_array", "(", "TaggedEntityInterface", "::", "class", ",", "class_implements", "(", "$", "class", ")", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'The entity %s does not implements %s, query should not be cached.'", ",", "$", "class", ",", "TaggedEntityInterface", "::", "class", ")", ")", ";", "}", "return", "$", "this", "->", "cachePrefix", "=", "call_user_func", "(", "[", "$", "this", "->", "getClassName", "(", ")", ",", "'getEntityTagPrefix'", "]", ")", ";", "}" ]
Returns the cache prefix. @return string
[ "Returns", "the", "cache", "prefix", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Doctrine/ORM/Util/ResourceRepositoryTrait.php#L330-L346
train
itkg/core
src/Itkg/Core/Cache/Factory.php
Factory.create
public function create($adapterType, array $config) { if (!array_key_exists($adapterType, $this->adapters)) { throw new \InvalidArgumentException( sprintf('Cache Adapter\'s key %s does not exist', $adapterType) ); } /** * @fixme : Active this part & clean cache config */ if (!isset($config[$adapterType])) { throw new InvalidConfigurationException( sprintf('Config is not set for adapter %s', $adapterType) ); } return new $this->adapters[$adapterType]($config[$adapterType]); }
php
public function create($adapterType, array $config) { if (!array_key_exists($adapterType, $this->adapters)) { throw new \InvalidArgumentException( sprintf('Cache Adapter\'s key %s does not exist', $adapterType) ); } /** * @fixme : Active this part & clean cache config */ if (!isset($config[$adapterType])) { throw new InvalidConfigurationException( sprintf('Config is not set for adapter %s', $adapterType) ); } return new $this->adapters[$adapterType]($config[$adapterType]); }
[ "public", "function", "create", "(", "$", "adapterType", ",", "array", "$", "config", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "adapterType", ",", "$", "this", "->", "adapters", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Cache Adapter\\'s key %s does not exist'", ",", "$", "adapterType", ")", ")", ";", "}", "/**\n * @fixme : Active this part & clean cache config\n */", "if", "(", "!", "isset", "(", "$", "config", "[", "$", "adapterType", "]", ")", ")", "{", "throw", "new", "InvalidConfigurationException", "(", "sprintf", "(", "'Config is not set for adapter %s'", ",", "$", "adapterType", ")", ")", ";", "}", "return", "new", "$", "this", "->", "adapters", "[", "$", "adapterType", "]", "(", "$", "config", "[", "$", "adapterType", "]", ")", ";", "}" ]
Create an adapter @param string $adapterType @return AdapterInterface @throws \InvalidArgumentException
[ "Create", "an", "adapter" ]
e5e4efb05feb4d23b0df41f2b21fd095103e593b
https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Cache/Factory.php#L41-L59
train
Dhii/regex-abstract
src/QuoteRegexCapablePcreTrait.php
QuoteRegexCapablePcreTrait._quoteRegex
protected function _quoteRegex($string, $delimiter = null) { $string = $this->_normalizeString($string); $delimiter = is_null($delimiter) ? null : $this->_normalizeString($delimiter); return preg_quote($string, $delimiter); }
php
protected function _quoteRegex($string, $delimiter = null) { $string = $this->_normalizeString($string); $delimiter = is_null($delimiter) ? null : $this->_normalizeString($delimiter); return preg_quote($string, $delimiter); }
[ "protected", "function", "_quoteRegex", "(", "$", "string", ",", "$", "delimiter", "=", "null", ")", "{", "$", "string", "=", "$", "this", "->", "_normalizeString", "(", "$", "string", ")", ";", "$", "delimiter", "=", "is_null", "(", "$", "delimiter", ")", "?", "null", ":", "$", "this", "->", "_normalizeString", "(", "$", "delimiter", ")", ";", "return", "preg_quote", "(", "$", "string", ",", "$", "delimiter", ")", ";", "}" ]
Escapes special characters in a string such that it is interpreted literally by a PCRE parser. @since [*next-version*] @param string|Stringable $string The string to quote. @param string|Stringable|null $delimiter The delimiter that will be used in the expression, if any. If specified, this delimiter will be quoted too. @throws InvalidArgumentException If the string or the delimiter are invalid. @return string The quoted string.
[ "Escapes", "special", "characters", "in", "a", "string", "such", "that", "it", "is", "interpreted", "literally", "by", "a", "PCRE", "parser", "." ]
0751f9c91a6f86d5f901b6b7f3613dc80bb69a8a
https://github.com/Dhii/regex-abstract/blob/0751f9c91a6f86d5f901b6b7f3613dc80bb69a8a/src/QuoteRegexCapablePcreTrait.php#L28-L34
train
SahilDude89ss/PyntaxFramework
src/Pyntax/DAO/Bean/Column/Column.php
Column.getValueFromDefinition
protected function getValueFromDefinition($key) { return (isset($this->definition) && !empty($this->definition[$key])) ? $this->definition[$key] : false; }
php
protected function getValueFromDefinition($key) { return (isset($this->definition) && !empty($this->definition[$key])) ? $this->definition[$key] : false; }
[ "protected", "function", "getValueFromDefinition", "(", "$", "key", ")", "{", "return", "(", "isset", "(", "$", "this", "->", "definition", ")", "&&", "!", "empty", "(", "$", "this", "->", "definition", "[", "$", "key", "]", ")", ")", "?", "$", "this", "->", "definition", "[", "$", "key", "]", ":", "false", ";", "}" ]
This function returns the value of the key from the column definitions. @param $key @return bool|string
[ "This", "function", "returns", "the", "value", "of", "the", "key", "from", "the", "column", "definitions", "." ]
045cca87d24eb2b6405734966c64344e00224c7b
https://github.com/SahilDude89ss/PyntaxFramework/blob/045cca87d24eb2b6405734966c64344e00224c7b/src/Pyntax/DAO/Bean/Column/Column.php#L121-L124
train
Wedeto/Util
src/Cache/Item.php
Item.serialize
public function serialize() { return serialize([ 'key' => $this->key, 'value' => $this->value, 'expires' => $this->expires, 'hit' => $this->hit ]); }
php
public function serialize() { return serialize([ 'key' => $this->key, 'value' => $this->value, 'expires' => $this->expires, 'hit' => $this->hit ]); }
[ "public", "function", "serialize", "(", ")", "{", "return", "serialize", "(", "[", "'key'", "=>", "$", "this", "->", "key", ",", "'value'", "=>", "$", "this", "->", "value", ",", "'expires'", "=>", "$", "this", "->", "expires", ",", "'hit'", "=>", "$", "this", "->", "hit", "]", ")", ";", "}" ]
Serialize the item. Required for storing in the containing cache
[ "Serialize", "the", "item", ".", "Required", "for", "storing", "in", "the", "containing", "cache" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Item.php#L190-L198
train