repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
timostamm/url-builder
src/UrlQuery.php
UrlQuery.remove
public function remove($key) { $this->validateKey($key); if ($this->has($key)) { unset($this->params[$key]); return true; } else { return false; } }
php
public function remove($key) { $this->validateKey($key); if ($this->has($key)) { unset($this->params[$key]); return true; } else { return false; } }
[ "public", "function", "remove", "(", "$", "key", ")", "{", "$", "this", "->", "validateKey", "(", "$", "key", ")", ";", "if", "(", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "unset", "(", "$", "this", "->", "params", "[", "$", "key", "]", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Return all parameters with the given key. @param string $key @return boolean True if the parameter existed.
[ "Return", "all", "parameters", "with", "the", "given", "key", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlQuery.php#L81-L90
train
timostamm/url-builder
src/UrlQuery.php
UrlQuery.replace
public function replace(array $new) { foreach ($new as $key => $values) { $this->validateKey($key); if (! is_array($values)) { $values = $new[$key] = [ $values ]; } foreach ($values as $v) { $this->validateValue($v); } } foreach ($new as $key => $values) { $this->setArray($key, $values); } }
php
public function replace(array $new) { foreach ($new as $key => $values) { $this->validateKey($key); if (! is_array($values)) { $values = $new[$key] = [ $values ]; } foreach ($values as $v) { $this->validateValue($v); } } foreach ($new as $key => $values) { $this->setArray($key, $values); } }
[ "public", "function", "replace", "(", "array", "$", "new", ")", "{", "foreach", "(", "$", "new", "as", "$", "key", "=>", "$", "values", ")", "{", "$", "this", "->", "validateKey", "(", "$", "key", ")", ";", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "{", "$", "values", "=", "$", "new", "[", "$", "key", "]", "=", "[", "$", "values", "]", ";", "}", "foreach", "(", "$", "values", "as", "$", "v", ")", "{", "$", "this", "->", "validateValue", "(", "$", "v", ")", ";", "}", "}", "foreach", "(", "$", "new", "as", "$", "key", "=>", "$", "values", ")", "{", "$", "this", "->", "setArray", "(", "$", "key", ",", "$", "values", ")", ";", "}", "}" ]
Sets several new parameters, replacing the old values if already present. The provided array must be associative with the parameter keys as array keys and parameter values as array values. The array values may be either a string (to set a single parameter value) or an array (to set multiple parameter values). @param array $new
[ "Sets", "several", "new", "parameters", "replacing", "the", "old", "values", "if", "already", "present", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlQuery.php#L103-L119
train
timostamm/url-builder
src/UrlQuery.php
UrlQuery.getArray
public function getArray($key) { $this->validateKey($key); return $this->has($key) ? $this->params[$key] : []; }
php
public function getArray($key) { $this->validateKey($key); return $this->has($key) ? $this->params[$key] : []; }
[ "public", "function", "getArray", "(", "$", "key", ")", "{", "$", "this", "->", "validateKey", "(", "$", "key", ")", ";", "return", "$", "this", "->", "has", "(", "$", "key", ")", "?", "$", "this", "->", "params", "[", "$", "key", "]", ":", "[", "]", ";", "}" ]
Returns all values of the parameters with the given key. If no parameter with the given key exists, an empty array is returned. @param string $key @return array
[ "Returns", "all", "values", "of", "the", "parameters", "with", "the", "given", "key", ".", "If", "no", "parameter", "with", "the", "given", "key", "exists", "an", "empty", "array", "is", "returned", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlQuery.php#L140-L144
train
timostamm/url-builder
src/UrlQuery.php
UrlQuery.toArray
public function toArray($onlyFirst = false) { $r = []; foreach ($this->params as $key => $values) { $r[$key] = $onlyFirst ? $values[0] : $values; } return $r; }
php
public function toArray($onlyFirst = false) { $r = []; foreach ($this->params as $key => $values) { $r[$key] = $onlyFirst ? $values[0] : $values; } return $r; }
[ "public", "function", "toArray", "(", "$", "onlyFirst", "=", "false", ")", "{", "$", "r", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "params", "as", "$", "key", "=>", "$", "values", ")", "{", "$", "r", "[", "$", "key", "]", "=", "$", "onlyFirst", "?", "$", "values", "[", "0", "]", ":", "$", "values", ";", "}", "return", "$", "r", ";", "}" ]
Get all parameters as an associative array with the parameter keys as array keys. Returns either only the first values of the parameters, or all values of the parameters. @param boolean $onlyFirst @return array
[ "Get", "all", "parameters", "as", "an", "associative", "array", "with", "the", "parameter", "keys", "as", "array", "keys", ".", "Returns", "either", "only", "the", "first", "values", "of", "the", "parameters", "or", "all", "values", "of", "the", "parameters", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlQuery.php#L153-L160
train
timostamm/url-builder
src/UrlQuery.php
UrlQuery.count
public function count($key = null) { if (is_null($key)) { return count($this->params); } return count($this->getArray($key)); }
php
public function count($key = null) { if (is_null($key)) { return count($this->params); } return count($this->getArray($key)); }
[ "public", "function", "count", "(", "$", "key", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "return", "count", "(", "$", "this", "->", "params", ")", ";", "}", "return", "count", "(", "$", "this", "->", "getArray", "(", "$", "key", ")", ")", ";", "}" ]
Counts the parameters. Parameter keys that appear multiple times count as one array parameter. If the $key parameter is used, the number of values of this parameter are counted. @param string $key @return int
[ "Counts", "the", "parameters", ".", "Parameter", "keys", "that", "appear", "multiple", "times", "count", "as", "one", "array", "parameter", "." ]
9dec80635017415d83b7e6ef155e9324f4b27a00
https://github.com/timostamm/url-builder/blob/9dec80635017415d83b7e6ef155e9324f4b27a00/src/UrlQuery.php#L182-L188
train
lrezek/Arachnid
src/LRezek/Arachnid/Meta/Property.php
Property.isProperty
function isProperty() { //Get the annotation index $i = $this->getAnnotationIndex(self::PROPERTY); //If the property annotation is on here if($i >= 0) { //Set the format (Date, JSON, scalar, etc) $this->format = $this->annotations[$i]->format; //This is a property return true; } else { //Not a property return false; } }
php
function isProperty() { //Get the annotation index $i = $this->getAnnotationIndex(self::PROPERTY); //If the property annotation is on here if($i >= 0) { //Set the format (Date, JSON, scalar, etc) $this->format = $this->annotations[$i]->format; //This is a property return true; } else { //Not a property return false; } }
[ "function", "isProperty", "(", ")", "{", "//Get the annotation index", "$", "i", "=", "$", "this", "->", "getAnnotationIndex", "(", "self", "::", "PROPERTY", ")", ";", "//If the property annotation is on here", "if", "(", "$", "i", ">=", "0", ")", "{", "//Set the format (Date, JSON, scalar, etc)", "$", "this", "->", "format", "=", "$", "this", "->", "annotations", "[", "$", "i", "]", "->", "format", ";", "//This is a property", "return", "true", ";", "}", "else", "{", "//Not a property", "return", "false", ";", "}", "}" ]
Checks if this property is indeed a property. @return bool
[ "Checks", "if", "this", "property", "is", "indeed", "a", "property", "." ]
fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a
https://github.com/lrezek/Arachnid/blob/fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a/src/LRezek/Arachnid/Meta/Property.php#L112-L132
train
lrezek/Arachnid
src/LRezek/Arachnid/Meta/Property.php
Property.getValue
function getValue($entity) { $raw = $this->property->getValue($entity); switch ($this->format) { case 'scalar': return $raw; //Serialize classes and arrays before putting them in the DB case 'object': case 'array': return serialize($raw); //Json encode before putting into DB case 'json': return json_encode($raw); //Format the date correctly before putting in DB case 'date': if ($raw) { $value = clone $raw; $value->setTimezone(new \DateTimeZone('UTC')); return $value->format('Y-m-d H:i:s'); } else { return null; } } return null; }
php
function getValue($entity) { $raw = $this->property->getValue($entity); switch ($this->format) { case 'scalar': return $raw; //Serialize classes and arrays before putting them in the DB case 'object': case 'array': return serialize($raw); //Json encode before putting into DB case 'json': return json_encode($raw); //Format the date correctly before putting in DB case 'date': if ($raw) { $value = clone $raw; $value->setTimezone(new \DateTimeZone('UTC')); return $value->format('Y-m-d H:i:s'); } else { return null; } } return null; }
[ "function", "getValue", "(", "$", "entity", ")", "{", "$", "raw", "=", "$", "this", "->", "property", "->", "getValue", "(", "$", "entity", ")", ";", "switch", "(", "$", "this", "->", "format", ")", "{", "case", "'scalar'", ":", "return", "$", "raw", ";", "//Serialize classes and arrays before putting them in the DB", "case", "'object'", ":", "case", "'array'", ":", "return", "serialize", "(", "$", "raw", ")", ";", "//Json encode before putting into DB", "case", "'json'", ":", "return", "json_encode", "(", "$", "raw", ")", ";", "//Format the date correctly before putting in DB", "case", "'date'", ":", "if", "(", "$", "raw", ")", "{", "$", "value", "=", "clone", "$", "raw", ";", "$", "value", "->", "setTimezone", "(", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ")", ";", "return", "$", "value", "->", "format", "(", "'Y-m-d H:i:s'", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "return", "null", ";", "}" ]
Gets this property's value in the given entity. @param Relation|Node $entity The entity to get the value from. @return mixed The property value.
[ "Gets", "this", "property", "s", "value", "in", "the", "given", "entity", "." ]
fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a
https://github.com/lrezek/Arachnid/blob/fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a/src/LRezek/Arachnid/Meta/Property.php#L160-L195
train
lrezek/Arachnid
src/LRezek/Arachnid/Meta/Property.php
Property.setValue
function setValue($entity, $value) { switch ($this->format) { case 'scalar': $this->property->setValue($entity, $value); break; //Unserialize classes and arrays before putting them back in the entity. case 'object': case 'array': $this->property->setValue($entity, unserialize($value)); break; //Decode Json from DB back into a regular assoc array before putting it into the entity. case 'json': $this->property->setValue($entity, json_decode($value, true)); break; //Create a date time object out of the db stored date before putting it into the entity. case 'date': $date = null; if ($value) { $date = new \DateTime($value . ' UTC'); $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); } $this->property->setValue($entity, $date); break; } }
php
function setValue($entity, $value) { switch ($this->format) { case 'scalar': $this->property->setValue($entity, $value); break; //Unserialize classes and arrays before putting them back in the entity. case 'object': case 'array': $this->property->setValue($entity, unserialize($value)); break; //Decode Json from DB back into a regular assoc array before putting it into the entity. case 'json': $this->property->setValue($entity, json_decode($value, true)); break; //Create a date time object out of the db stored date before putting it into the entity. case 'date': $date = null; if ($value) { $date = new \DateTime($value . ' UTC'); $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); } $this->property->setValue($entity, $date); break; } }
[ "function", "setValue", "(", "$", "entity", ",", "$", "value", ")", "{", "switch", "(", "$", "this", "->", "format", ")", "{", "case", "'scalar'", ":", "$", "this", "->", "property", "->", "setValue", "(", "$", "entity", ",", "$", "value", ")", ";", "break", ";", "//Unserialize classes and arrays before putting them back in the entity.", "case", "'object'", ":", "case", "'array'", ":", "$", "this", "->", "property", "->", "setValue", "(", "$", "entity", ",", "unserialize", "(", "$", "value", ")", ")", ";", "break", ";", "//Decode Json from DB back into a regular assoc array before putting it into the entity.", "case", "'json'", ":", "$", "this", "->", "property", "->", "setValue", "(", "$", "entity", ",", "json_decode", "(", "$", "value", ",", "true", ")", ")", ";", "break", ";", "//Create a date time object out of the db stored date before putting it into the entity.", "case", "'date'", ":", "$", "date", "=", "null", ";", "if", "(", "$", "value", ")", "{", "$", "date", "=", "new", "\\", "DateTime", "(", "$", "value", ".", "' UTC'", ")", ";", "$", "date", "->", "setTimezone", "(", "new", "\\", "DateTimeZone", "(", "date_default_timezone_get", "(", ")", ")", ")", ";", "}", "$", "this", "->", "property", "->", "setValue", "(", "$", "entity", ",", "$", "date", ")", ";", "break", ";", "}", "}" ]
Sets this property's value in the given entity. @param Relation|Node $entity The entity to set the property of. @param mixed $value The value to set it to.
[ "Sets", "this", "property", "s", "value", "in", "the", "given", "entity", "." ]
fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a
https://github.com/lrezek/Arachnid/blob/fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a/src/LRezek/Arachnid/Meta/Property.php#L203-L233
train
lrezek/Arachnid
src/LRezek/Arachnid/Meta/Property.php
Property.matches
function matches($names) { //Check every argument supplied foreach (func_get_args() as $name) { //Check for any possible match if ( 0 === strcasecmp($name, $this->name) || 0 === strcasecmp($name, $this->property->getName()) || 0 === strcasecmp($name, Reflection::normalizeProperty($this->property->getName())) ) { return true; } } return false; }
php
function matches($names) { //Check every argument supplied foreach (func_get_args() as $name) { //Check for any possible match if ( 0 === strcasecmp($name, $this->name) || 0 === strcasecmp($name, $this->property->getName()) || 0 === strcasecmp($name, Reflection::normalizeProperty($this->property->getName())) ) { return true; } } return false; }
[ "function", "matches", "(", "$", "names", ")", "{", "//Check every argument supplied", "foreach", "(", "func_get_args", "(", ")", "as", "$", "name", ")", "{", "//Check for any possible match", "if", "(", "0", "===", "strcasecmp", "(", "$", "name", ",", "$", "this", "->", "name", ")", "||", "0", "===", "strcasecmp", "(", "$", "name", ",", "$", "this", "->", "property", "->", "getName", "(", ")", ")", "||", "0", "===", "strcasecmp", "(", "$", "name", ",", "Reflection", "::", "normalizeProperty", "(", "$", "this", "->", "property", "->", "getName", "(", ")", ")", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if a supplied name matches this property's name. @param mixed $names List of names to check. @return bool
[ "Checks", "if", "a", "supplied", "name", "matches", "this", "property", "s", "name", "." ]
fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a
https://github.com/lrezek/Arachnid/blob/fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a/src/LRezek/Arachnid/Meta/Property.php#L251-L268
train
lrezek/Arachnid
src/LRezek/Arachnid/Meta/Property.php
Property.validateAnnotations
private function validateAnnotations() { //Count annotations in the annotation namespace, ignore annotations not in our namespace $count = 0; foreach($this->annotations as $a) { //If you find the namespace in the class name, add to count if(strrpos(get_class($a), self::ANNOTATION_NAMESPACE) !== false) { $count++; } } switch($count) { //0 annotations, just ignore case 0: return; //1 Annotation, it can't be index. case 1: if($this->getAnnotationIndex(self::INDEX) < 0) { //It's not index, return. return; } throw new Exception("@Index cannot be the only annotation on {$this->name} in {$this->property->getDeclaringClass()->getName()}."); //2 Annotations, they have to be index and property. case 2: if( ($this->getAnnotationIndex(self::PROPERTY) >= 0) && ($this->getAnnotationIndex(self::INDEX) >= 0)) { //They are index and property, return return; } break; } //It didn't fall into any of the categories, must be invalid throw new Exception("Invalid annotation combination on {$this->name} in {$this->property->getDeclaringClass()->getName()}."); }
php
private function validateAnnotations() { //Count annotations in the annotation namespace, ignore annotations not in our namespace $count = 0; foreach($this->annotations as $a) { //If you find the namespace in the class name, add to count if(strrpos(get_class($a), self::ANNOTATION_NAMESPACE) !== false) { $count++; } } switch($count) { //0 annotations, just ignore case 0: return; //1 Annotation, it can't be index. case 1: if($this->getAnnotationIndex(self::INDEX) < 0) { //It's not index, return. return; } throw new Exception("@Index cannot be the only annotation on {$this->name} in {$this->property->getDeclaringClass()->getName()}."); //2 Annotations, they have to be index and property. case 2: if( ($this->getAnnotationIndex(self::PROPERTY) >= 0) && ($this->getAnnotationIndex(self::INDEX) >= 0)) { //They are index and property, return return; } break; } //It didn't fall into any of the categories, must be invalid throw new Exception("Invalid annotation combination on {$this->name} in {$this->property->getDeclaringClass()->getName()}."); }
[ "private", "function", "validateAnnotations", "(", ")", "{", "//Count annotations in the annotation namespace, ignore annotations not in our namespace", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "annotations", "as", "$", "a", ")", "{", "//If you find the namespace in the class name, add to count", "if", "(", "strrpos", "(", "get_class", "(", "$", "a", ")", ",", "self", "::", "ANNOTATION_NAMESPACE", ")", "!==", "false", ")", "{", "$", "count", "++", ";", "}", "}", "switch", "(", "$", "count", ")", "{", "//0 annotations, just ignore", "case", "0", ":", "return", ";", "//1 Annotation, it can't be index.", "case", "1", ":", "if", "(", "$", "this", "->", "getAnnotationIndex", "(", "self", "::", "INDEX", ")", "<", "0", ")", "{", "//It's not index, return.", "return", ";", "}", "throw", "new", "Exception", "(", "\"@Index cannot be the only annotation on {$this->name} in {$this->property->getDeclaringClass()->getName()}.\"", ")", ";", "//2 Annotations, they have to be index and property.", "case", "2", ":", "if", "(", "(", "$", "this", "->", "getAnnotationIndex", "(", "self", "::", "PROPERTY", ")", ">=", "0", ")", "&&", "(", "$", "this", "->", "getAnnotationIndex", "(", "self", "::", "INDEX", ")", ">=", "0", ")", ")", "{", "//They are index and property, return", "return", ";", "}", "break", ";", "}", "//It didn't fall into any of the categories, must be invalid", "throw", "new", "Exception", "(", "\"Invalid annotation combination on {$this->name} in {$this->property->getDeclaringClass()->getName()}.\"", ")", ";", "}" ]
Validates the annotation combination on a property. @throws Exception If the combination is invalid in some way.
[ "Validates", "the", "annotation", "combination", "on", "a", "property", "." ]
fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a
https://github.com/lrezek/Arachnid/blob/fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a/src/LRezek/Arachnid/Meta/Property.php#L285-L330
train
lrezek/Arachnid
src/LRezek/Arachnid/Meta/Property.php
Property.getAnnotationIndex
private function getAnnotationIndex($name) { for($i = 0; $i < count($this->annotations); $i++) { if($this->annotations[$i] instanceof $name) { return $i; } } return -1; }
php
private function getAnnotationIndex($name) { for($i = 0; $i < count($this->annotations); $i++) { if($this->annotations[$i] instanceof $name) { return $i; } } return -1; }
[ "private", "function", "getAnnotationIndex", "(", "$", "name", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "this", "->", "annotations", ")", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "annotations", "[", "$", "i", "]", "instanceof", "$", "name", ")", "{", "return", "$", "i", ";", "}", "}", "return", "-", "1", ";", "}" ]
Gets the index of a annotation with the value specified, or -1 if it's not in the annotations array. @param String $name The annotation class. @return int The index of the annotation in the annotations array().
[ "Gets", "the", "index", "of", "a", "annotation", "with", "the", "value", "specified", "or", "-", "1", "if", "it", "s", "not", "in", "the", "annotations", "array", "." ]
fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a
https://github.com/lrezek/Arachnid/blob/fbfc2c6f9d1dbfeef6f677813c12c570d5ea750a/src/LRezek/Arachnid/Meta/Property.php#L338-L349
train
PhoxPHP/Glider
src/Model/Uses/Record.php
Record.update
protected function update($keyValue=null, String $key, String $table, Array $properties=[]) { if (isset($properties[$key])) { unset($properties[$key]); } $this->queryBuilder()->where( $key, $keyValue )->update($table, $properties); }
php
protected function update($keyValue=null, String $key, String $table, Array $properties=[]) { if (isset($properties[$key])) { unset($properties[$key]); } $this->queryBuilder()->where( $key, $keyValue )->update($table, $properties); }
[ "protected", "function", "update", "(", "$", "keyValue", "=", "null", ",", "String", "$", "key", ",", "String", "$", "table", ",", "Array", "$", "properties", "=", "[", "]", ")", "{", "if", "(", "isset", "(", "$", "properties", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "properties", "[", "$", "key", "]", ")", ";", "}", "$", "this", "->", "queryBuilder", "(", ")", "->", "where", "(", "$", "key", ",", "$", "keyValue", ")", "->", "update", "(", "$", "table", ",", "$", "properties", ")", ";", "}" ]
Updates an existing record in the database table. @param $keyValue <Mixed> @param $key <String> @param $table <String> @param $properties <Array> @access protected @return <void>
[ "Updates", "an", "existing", "record", "in", "the", "database", "table", "." ]
17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042
https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Model/Uses/Record.php#L115-L125
train
bruno-barros/w.eloquent-framework
src/weloquent/Core/Globaljs/GlobalJs.php
GlobalJs.add
public function add($index, $data = null, $toAdmin = false) { if (!$this->has($index)) { $this->data = Arr::add($this->data, $index, $data); $this->metas = Arr::add($this->metas, $this->firstIndex($index), ['admin' => $toAdmin]); } return $this; }
php
public function add($index, $data = null, $toAdmin = false) { if (!$this->has($index)) { $this->data = Arr::add($this->data, $index, $data); $this->metas = Arr::add($this->metas, $this->firstIndex($index), ['admin' => $toAdmin]); } return $this; }
[ "public", "function", "add", "(", "$", "index", ",", "$", "data", "=", "null", ",", "$", "toAdmin", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "index", ")", ")", "{", "$", "this", "->", "data", "=", "Arr", "::", "add", "(", "$", "this", "->", "data", ",", "$", "index", ",", "$", "data", ")", ";", "$", "this", "->", "metas", "=", "Arr", "::", "add", "(", "$", "this", "->", "metas", ",", "$", "this", "->", "firstIndex", "(", "$", "index", ")", ",", "[", "'admin'", "=>", "$", "toAdmin", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Append new data @param string $index Unique identifier @param null $data @param bool $toAdmin If show on admin environment @return $this
[ "Append", "new", "data" ]
d252dcb1ba1b6b1cecf67877d7d6d3ba57ebedbd
https://github.com/bruno-barros/w.eloquent-framework/blob/d252dcb1ba1b6b1cecf67877d7d6d3ba57ebedbd/src/weloquent/Core/Globaljs/GlobalJs.php#L49-L59
train
bruno-barros/w.eloquent-framework
src/weloquent/Core/Globaljs/GlobalJs.php
GlobalJs.toJson
public function toJson($admin = false) { $data = $this->prepareDataToJson($admin); if (count($data) == 0) { return '{}'; } return json_encode($data); }
php
public function toJson($admin = false) { $data = $this->prepareDataToJson($admin); if (count($data) == 0) { return '{}'; } return json_encode($data); }
[ "public", "function", "toJson", "(", "$", "admin", "=", "false", ")", "{", "$", "data", "=", "$", "this", "->", "prepareDataToJson", "(", "$", "admin", ")", ";", "if", "(", "count", "(", "$", "data", ")", "==", "0", ")", "{", "return", "'{}'", ";", "}", "return", "json_encode", "(", "$", "data", ")", ";", "}" ]
Return the data as JSON @param bool $admin @return string|void
[ "Return", "the", "data", "as", "JSON" ]
d252dcb1ba1b6b1cecf67877d7d6d3ba57ebedbd
https://github.com/bruno-barros/w.eloquent-framework/blob/d252dcb1ba1b6b1cecf67877d7d6d3ba57ebedbd/src/weloquent/Core/Globaljs/GlobalJs.php#L128-L138
train
hummer2k/ConLayout
src/Layout/Layout.php
Layout.load
public function load() { if (false === $this->isLoaded) { $this->getEventManager()->trigger( __FUNCTION__ . '.pre', $this, [] ); $this->generate(); $this->injectBlocks(); $this->isLoaded = true; $this->getEventManager()->trigger( __FUNCTION__ . '.post', $this, [] ); } return $this; }
php
public function load() { if (false === $this->isLoaded) { $this->getEventManager()->trigger( __FUNCTION__ . '.pre', $this, [] ); $this->generate(); $this->injectBlocks(); $this->isLoaded = true; $this->getEventManager()->trigger( __FUNCTION__ . '.post', $this, [] ); } return $this; }
[ "public", "function", "load", "(", ")", "{", "if", "(", "false", "===", "$", "this", "->", "isLoaded", ")", "{", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "__FUNCTION__", ".", "'.pre'", ",", "$", "this", ",", "[", "]", ")", ";", "$", "this", "->", "generate", "(", ")", ";", "$", "this", "->", "injectBlocks", "(", ")", ";", "$", "this", "->", "isLoaded", "=", "true", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "__FUNCTION__", ".", "'.post'", ",", "$", "this", ",", "[", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
inject blocks into the root view model @return LayoutInterface
[ "inject", "blocks", "into", "the", "root", "view", "model" ]
15e472eaabc9b23ec6a5547524874e30d95e8d3e
https://github.com/hummer2k/ConLayout/blob/15e472eaabc9b23ec6a5547524874e30d95e8d3e/src/Layout/Layout.php#L97-L117
train
hummer2k/ConLayout
src/Layout/Layout.php
Layout.isAllowed
private function isAllowed($blockId, ModelInterface $block) { $result = $this->getEventManager()->trigger( __FUNCTION__, $this, [ 'block_id' => $blockId, 'block' => $block ] ); if ($result->stopped()) { return $result->last(); } return true; }
php
private function isAllowed($blockId, ModelInterface $block) { $result = $this->getEventManager()->trigger( __FUNCTION__, $this, [ 'block_id' => $blockId, 'block' => $block ] ); if ($result->stopped()) { return $result->last(); } return true; }
[ "private", "function", "isAllowed", "(", "$", "blockId", ",", "ModelInterface", "$", "block", ")", "{", "$", "result", "=", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "__FUNCTION__", ",", "$", "this", ",", "[", "'block_id'", "=>", "$", "blockId", ",", "'block'", "=>", "$", "block", "]", ")", ";", "if", "(", "$", "result", "->", "stopped", "(", ")", ")", "{", "return", "$", "result", "->", "last", "(", ")", ";", "}", "return", "true", ";", "}" ]
Determines whether a block should be allowed given certain parameters @param string $blockId @param ModelInterface $block @return bool
[ "Determines", "whether", "a", "block", "should", "be", "allowed", "given", "certain", "parameters" ]
15e472eaabc9b23ec6a5547524874e30d95e8d3e
https://github.com/hummer2k/ConLayout/blob/15e472eaabc9b23ec6a5547524874e30d95e8d3e/src/Layout/Layout.php#L175-L189
train
hummer2k/ConLayout
src/Layout/Layout.php
Layout.addBlock
public function addBlock($blockId, ModelInterface $block) { $this->blockPool->add($blockId, $block); return $this; }
php
public function addBlock($blockId, ModelInterface $block) { $this->blockPool->add($blockId, $block); return $this; }
[ "public", "function", "addBlock", "(", "$", "blockId", ",", "ModelInterface", "$", "block", ")", "{", "$", "this", "->", "blockPool", "->", "add", "(", "$", "blockId", ",", "$", "block", ")", ";", "return", "$", "this", ";", "}" ]
adds a block to the registry @param string $blockId @param ModelInterface $block @return LayoutInterface
[ "adds", "a", "block", "to", "the", "registry" ]
15e472eaabc9b23ec6a5547524874e30d95e8d3e
https://github.com/hummer2k/ConLayout/blob/15e472eaabc9b23ec6a5547524874e30d95e8d3e/src/Layout/Layout.php#L198-L202
train
oliwierptak/Everon1
src/Everon/Domain/Repository.php
Repository.prepareDataForEntity
protected function prepareDataForEntity(array $data) { /** * @var \Everon\DataMapper\Interfaces\Schema\Column $Column */ foreach ($this->getMapper()->getTable()->getColumns() as $name => $Column) { if (array_key_exists($name, $data) === false) { if ($Column->isPk()) { $data[$name] = null; } else if ($Column->isNullable() === false) { throw new Exception\Domain('Missing Entity data: "%s" for "%s"', [$name, $this->getMapper()->getTable()->getName()]); } $data[$name] = null; } $data[$name] = $Column->getColumnDataForEntity($data[$name]); } return $data; }
php
protected function prepareDataForEntity(array $data) { /** * @var \Everon\DataMapper\Interfaces\Schema\Column $Column */ foreach ($this->getMapper()->getTable()->getColumns() as $name => $Column) { if (array_key_exists($name, $data) === false) { if ($Column->isPk()) { $data[$name] = null; } else if ($Column->isNullable() === false) { throw new Exception\Domain('Missing Entity data: "%s" for "%s"', [$name, $this->getMapper()->getTable()->getName()]); } $data[$name] = null; } $data[$name] = $Column->getColumnDataForEntity($data[$name]); } return $data; }
[ "protected", "function", "prepareDataForEntity", "(", "array", "$", "data", ")", "{", "/**\n * @var \\Everon\\DataMapper\\Interfaces\\Schema\\Column $Column\n */", "foreach", "(", "$", "this", "->", "getMapper", "(", ")", "->", "getTable", "(", ")", "->", "getColumns", "(", ")", "as", "$", "name", "=>", "$", "Column", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "data", ")", "===", "false", ")", "{", "if", "(", "$", "Column", "->", "isPk", "(", ")", ")", "{", "$", "data", "[", "$", "name", "]", "=", "null", ";", "}", "else", "if", "(", "$", "Column", "->", "isNullable", "(", ")", "===", "false", ")", "{", "throw", "new", "Exception", "\\", "Domain", "(", "'Missing Entity data: \"%s\" for \"%s\"'", ",", "[", "$", "name", ",", "$", "this", "->", "getMapper", "(", ")", "->", "getTable", "(", ")", "->", "getName", "(", ")", "]", ")", ";", "}", "$", "data", "[", "$", "name", "]", "=", "null", ";", "}", "$", "data", "[", "$", "name", "]", "=", "$", "Column", "->", "getColumnDataForEntity", "(", "$", "data", "[", "$", "name", "]", ")", ";", "}", "return", "$", "data", ";", "}" ]
Makes sure data defined in the Entity is in proper format and all keys are set @param array $data @return array @throws \Everon\Exception\Domain
[ "Makes", "sure", "data", "defined", "in", "the", "Entity", "is", "in", "proper", "format", "and", "all", "keys", "are", "set" ]
ac93793d1fa517a8394db5f00062f1925dc218a3
https://github.com/oliwierptak/Everon1/blob/ac93793d1fa517a8394db5f00062f1925dc218a3/src/Everon/Domain/Repository.php#L62-L83
train
open-orchestra/open-orchestra-display-bundle
DisplayBundle/DisplayBlock/Strategies/SubMenuStrategy.php
SubMenuStrategy.getNodes
protected function getNodes(ReadBlockInterface $block) { $nodes = null; $nodeName = $block->getAttribute('nodeName'); $siteId = $this->currentSiteManager->getSiteId(); if (!is_null($nodeName)) { $nodes = $this->nodeRepository->getSubMenu($nodeName, $block->getAttribute('nbLevel'), $this->request->getLocale(), $siteId); $nodes = $this->getGrantedNodes($nodes); } return $nodes; }
php
protected function getNodes(ReadBlockInterface $block) { $nodes = null; $nodeName = $block->getAttribute('nodeName'); $siteId = $this->currentSiteManager->getSiteId(); if (!is_null($nodeName)) { $nodes = $this->nodeRepository->getSubMenu($nodeName, $block->getAttribute('nbLevel'), $this->request->getLocale(), $siteId); $nodes = $this->getGrantedNodes($nodes); } return $nodes; }
[ "protected", "function", "getNodes", "(", "ReadBlockInterface", "$", "block", ")", "{", "$", "nodes", "=", "null", ";", "$", "nodeName", "=", "$", "block", "->", "getAttribute", "(", "'nodeName'", ")", ";", "$", "siteId", "=", "$", "this", "->", "currentSiteManager", "->", "getSiteId", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "nodeName", ")", ")", "{", "$", "nodes", "=", "$", "this", "->", "nodeRepository", "->", "getSubMenu", "(", "$", "nodeName", ",", "$", "block", "->", "getAttribute", "(", "'nbLevel'", ")", ",", "$", "this", "->", "request", "->", "getLocale", "(", ")", ",", "$", "siteId", ")", ";", "$", "nodes", "=", "$", "this", "->", "getGrantedNodes", "(", "$", "nodes", ")", ";", "}", "return", "$", "nodes", ";", "}" ]
Get nodes to display @param ReadBlockInterface $block @return array
[ "Get", "nodes", "to", "display" ]
0e59e8686dac2d8408b57b63b975b4e5a1aa9472
https://github.com/open-orchestra/open-orchestra-display-bundle/blob/0e59e8686dac2d8408b57b63b975b4e5a1aa9472/DisplayBundle/DisplayBlock/Strategies/SubMenuStrategy.php#L103-L115
train
theloopyewe/ravelry-api.php
src/RavelryApi/ServiceClient.php
ServiceClient.defaultCommandFactory
public static function defaultCommandFactory(Description $description) { return function ( $name, array $args = [], GuzzleClientInterface $client ) use ($description) { $operation = null; if ($description->hasOperation($name)) { $operation = $description->getOperation($name); } else { $name = ucfirst($name); if ($description->hasOperation($name)) { $operation = $description->getOperation($name); } } if (!$operation) { return null; } // this is the only line which is patched $args += ($operation->getData('defaults') ?: []); return new Command($operation, $args, clone $client->getEmitter()); }; }
php
public static function defaultCommandFactory(Description $description) { return function ( $name, array $args = [], GuzzleClientInterface $client ) use ($description) { $operation = null; if ($description->hasOperation($name)) { $operation = $description->getOperation($name); } else { $name = ucfirst($name); if ($description->hasOperation($name)) { $operation = $description->getOperation($name); } } if (!$operation) { return null; } // this is the only line which is patched $args += ($operation->getData('defaults') ?: []); return new Command($operation, $args, clone $client->getEmitter()); }; }
[ "public", "static", "function", "defaultCommandFactory", "(", "Description", "$", "description", ")", "{", "return", "function", "(", "$", "name", ",", "array", "$", "args", "=", "[", "]", ",", "GuzzleClientInterface", "$", "client", ")", "use", "(", "$", "description", ")", "{", "$", "operation", "=", "null", ";", "if", "(", "$", "description", "->", "hasOperation", "(", "$", "name", ")", ")", "{", "$", "operation", "=", "$", "description", "->", "getOperation", "(", "$", "name", ")", ";", "}", "else", "{", "$", "name", "=", "ucfirst", "(", "$", "name", ")", ";", "if", "(", "$", "description", "->", "hasOperation", "(", "$", "name", ")", ")", "{", "$", "operation", "=", "$", "description", "->", "getOperation", "(", "$", "name", ")", ";", "}", "}", "if", "(", "!", "$", "operation", ")", "{", "return", "null", ";", "}", "// this is the only line which is patched", "$", "args", "+=", "(", "$", "operation", "->", "getData", "(", "'defaults'", ")", "?", ":", "[", "]", ")", ";", "return", "new", "Command", "(", "$", "operation", ",", "$", "args", ",", "clone", "$", "client", "->", "getEmitter", "(", ")", ")", ";", "}", ";", "}" ]
We're overriding this to support operation-specific requestion options. Currently this is for disabling `auth` on specific operations.
[ "We", "re", "overriding", "this", "to", "support", "operation", "-", "specific", "requestion", "options", ".", "Currently", "this", "is", "for", "disabling", "auth", "on", "specific", "operations", "." ]
4dacae056e15cf5fd4e236b79843d0736db1e885
https://github.com/theloopyewe/ravelry-api.php/blob/4dacae056e15cf5fd4e236b79843d0736db1e885/src/RavelryApi/ServiceClient.php#L20-L48
train
theloopyewe/ravelry-api.php
src/RavelryApi/ServiceClient.php
ServiceClient.processConfig
protected function processConfig(array $config) { $config['command_factory'] = self::defaultCommandFactory($this->getDescription()); // we'll add our own patched processor after this parent::processConfig( array_merge( $config, [ 'process' => false, ] ) ); if (!isset($config['process']) || $config['process'] === true) { $this->getEmitter()->attach( new ProcessResponse( isset($config['debug']) ? $config['debug'] : false, isset($config['response_locations']) ? $config['response_locations'] : [] ) ); } }
php
protected function processConfig(array $config) { $config['command_factory'] = self::defaultCommandFactory($this->getDescription()); // we'll add our own patched processor after this parent::processConfig( array_merge( $config, [ 'process' => false, ] ) ); if (!isset($config['process']) || $config['process'] === true) { $this->getEmitter()->attach( new ProcessResponse( isset($config['debug']) ? $config['debug'] : false, isset($config['response_locations']) ? $config['response_locations'] : [] ) ); } }
[ "protected", "function", "processConfig", "(", "array", "$", "config", ")", "{", "$", "config", "[", "'command_factory'", "]", "=", "self", "::", "defaultCommandFactory", "(", "$", "this", "->", "getDescription", "(", ")", ")", ";", "// we'll add our own patched processor after this", "parent", "::", "processConfig", "(", "array_merge", "(", "$", "config", ",", "[", "'process'", "=>", "false", ",", "]", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "config", "[", "'process'", "]", ")", "||", "$", "config", "[", "'process'", "]", "===", "true", ")", "{", "$", "this", "->", "getEmitter", "(", ")", "->", "attach", "(", "new", "ProcessResponse", "(", "isset", "(", "$", "config", "[", "'debug'", "]", ")", "?", "$", "config", "[", "'debug'", "]", ":", "false", ",", "isset", "(", "$", "config", "[", "'response_locations'", "]", ")", "?", "$", "config", "[", "'response_locations'", "]", ":", "[", "]", ")", ")", ";", "}", "}" ]
We're overriding this to use our command factory from above and to use custom objects for API results.
[ "We", "re", "overriding", "this", "to", "use", "our", "command", "factory", "from", "above", "and", "to", "use", "custom", "objects", "for", "API", "results", "." ]
4dacae056e15cf5fd4e236b79843d0736db1e885
https://github.com/theloopyewe/ravelry-api.php/blob/4dacae056e15cf5fd4e236b79843d0736db1e885/src/RavelryApi/ServiceClient.php#L54-L76
train
cyberspectrum/i18n-contao
src/Mapping/Terminal42ChangeLanguage/ArticleContentMap.php
ArticleContentMap.mapElements
private function mapElements(array $elements, array $mainElements, array &$map, array &$inverse): void { foreach ($elements as $index => $element) { $elementId = (int) $element['id']; if (!array_key_exists($index, $mainElements)) { $this->logger->warning( 'Content element {id} has no mapping in main. Element skipped.', [ 'id' => $elementId, 'msg_type' => 'article_content_no_main', ] ); continue; } $mainElement = $mainElements[$index]; $mainId = (int) $mainElement['id']; if ($element['type'] !== $mainElement['type']) { $this->logger->warning( 'Content element {id} has different type as element in main. Element skipped.', [ 'id' => $elementId, 'mainId' => $mainId, 'msg_type' => 'article_content_type_mismatch' ] ); continue; } $map[$elementId] = $mainId; $inverse[$mainId] = $elementId; } }
php
private function mapElements(array $elements, array $mainElements, array &$map, array &$inverse): void { foreach ($elements as $index => $element) { $elementId = (int) $element['id']; if (!array_key_exists($index, $mainElements)) { $this->logger->warning( 'Content element {id} has no mapping in main. Element skipped.', [ 'id' => $elementId, 'msg_type' => 'article_content_no_main', ] ); continue; } $mainElement = $mainElements[$index]; $mainId = (int) $mainElement['id']; if ($element['type'] !== $mainElement['type']) { $this->logger->warning( 'Content element {id} has different type as element in main. Element skipped.', [ 'id' => $elementId, 'mainId' => $mainId, 'msg_type' => 'article_content_type_mismatch' ] ); continue; } $map[$elementId] = $mainId; $inverse[$mainId] = $elementId; } }
[ "private", "function", "mapElements", "(", "array", "$", "elements", ",", "array", "$", "mainElements", ",", "array", "&", "$", "map", ",", "array", "&", "$", "inverse", ")", ":", "void", "{", "foreach", "(", "$", "elements", "as", "$", "index", "=>", "$", "element", ")", "{", "$", "elementId", "=", "(", "int", ")", "$", "element", "[", "'id'", "]", ";", "if", "(", "!", "array_key_exists", "(", "$", "index", ",", "$", "mainElements", ")", ")", "{", "$", "this", "->", "logger", "->", "warning", "(", "'Content element {id} has no mapping in main. Element skipped.'", ",", "[", "'id'", "=>", "$", "elementId", ",", "'msg_type'", "=>", "'article_content_no_main'", ",", "]", ")", ";", "continue", ";", "}", "$", "mainElement", "=", "$", "mainElements", "[", "$", "index", "]", ";", "$", "mainId", "=", "(", "int", ")", "$", "mainElement", "[", "'id'", "]", ";", "if", "(", "$", "element", "[", "'type'", "]", "!==", "$", "mainElement", "[", "'type'", "]", ")", "{", "$", "this", "->", "logger", "->", "warning", "(", "'Content element {id} has different type as element in main. Element skipped.'", ",", "[", "'id'", "=>", "$", "elementId", ",", "'mainId'", "=>", "$", "mainId", ",", "'msg_type'", "=>", "'article_content_type_mismatch'", "]", ")", ";", "continue", ";", "}", "$", "map", "[", "$", "elementId", "]", "=", "$", "mainId", ";", "$", "inverse", "[", "$", "mainId", "]", "=", "$", "elementId", ";", "}", "}" ]
Map the passed elements. @param array $elements The elements to map. @param array $mainElements The main elements. @param array $map The map to store elements to. @param array $inverse The inverse map. @return void
[ "Map", "the", "passed", "elements", "." ]
038cf6ea9c609a734d7476fba256bc4b0db236b7
https://github.com/cyberspectrum/i18n-contao/blob/038cf6ea9c609a734d7476fba256bc4b0db236b7/src/Mapping/Terminal42ChangeLanguage/ArticleContentMap.php#L91-L123
train
aryelgois/medools-router
src/Controller.php
Controller.authenticate
public function authenticate(string $auth) { if ($this->router === null) { return; } try { $response = $this->router->authenticate($auth, 'Basic'); if (!($response instanceof Response)) { $response = new Response; $response->status = HttpResponse::HTTP_NO_CONTENT; } $response->output(); } catch (RouterException $e) { $e->getResponse()->output(); } }
php
public function authenticate(string $auth) { if ($this->router === null) { return; } try { $response = $this->router->authenticate($auth, 'Basic'); if (!($response instanceof Response)) { $response = new Response; $response->status = HttpResponse::HTTP_NO_CONTENT; } $response->output(); } catch (RouterException $e) { $e->getResponse()->output(); } }
[ "public", "function", "authenticate", "(", "string", "$", "auth", ")", "{", "if", "(", "$", "this", "->", "router", "===", "null", ")", "{", "return", ";", "}", "try", "{", "$", "response", "=", "$", "this", "->", "router", "->", "authenticate", "(", "$", "auth", ",", "'Basic'", ")", ";", "if", "(", "!", "(", "$", "response", "instanceof", "Response", ")", ")", "{", "$", "response", "=", "new", "Response", ";", "$", "response", "->", "status", "=", "HttpResponse", "::", "HTTP_NO_CONTENT", ";", "}", "$", "response", "->", "output", "(", ")", ";", "}", "catch", "(", "RouterException", "$", "e", ")", "{", "$", "e", "->", "getResponse", "(", ")", "->", "output", "(", ")", ";", "}", "}" ]
Authenticates a Basic Authorization Header When successful, a JWT is sent. It must be used for Bearer Authentication with other routes If the authentication is disabled, a 204 response is sent @param string $auth Request Authorization Header
[ "Authenticates", "a", "Basic", "Authorization", "Header" ]
5d755f53b8099952d60cf15a0eb209af5fa3ca8a
https://github.com/aryelgois/medools-router/blob/5d755f53b8099952d60cf15a0eb209af5fa3ca8a/src/Controller.php#L72-L88
train
aryelgois/medools-router
src/Controller.php
Controller.run
public function run( string $method, string $uri, array $headers, string $body ) { if ($this->router === null) { return; } try { $response = $this->router->run($method, $uri, $headers, $body); if ($response !== null) { $response->output(); } } catch (RouterException $e) { $e->getResponse()->output(); } }
php
public function run( string $method, string $uri, array $headers, string $body ) { if ($this->router === null) { return; } try { $response = $this->router->run($method, $uri, $headers, $body); if ($response !== null) { $response->output(); } } catch (RouterException $e) { $e->getResponse()->output(); } }
[ "public", "function", "run", "(", "string", "$", "method", ",", "string", "$", "uri", ",", "array", "$", "headers", ",", "string", "$", "body", ")", "{", "if", "(", "$", "this", "->", "router", "===", "null", ")", "{", "return", ";", "}", "try", "{", "$", "response", "=", "$", "this", "->", "router", "->", "run", "(", "$", "method", ",", "$", "uri", ",", "$", "headers", ",", "$", "body", ")", ";", "if", "(", "$", "response", "!==", "null", ")", "{", "$", "response", "->", "output", "(", ")", ";", "}", "}", "catch", "(", "RouterException", "$", "e", ")", "{", "$", "e", "->", "getResponse", "(", ")", "->", "output", "(", ")", ";", "}", "}" ]
Runs the Router and outputs the Response @param string $method Requested HTTP method @param string $uri Requested URI @param array $headers Request Headers @param string $body Request Body
[ "Runs", "the", "Router", "and", "outputs", "the", "Response" ]
5d755f53b8099952d60cf15a0eb209af5fa3ca8a
https://github.com/aryelgois/medools-router/blob/5d755f53b8099952d60cf15a0eb209af5fa3ca8a/src/Controller.php#L98-L116
train
acacha/forge-publish
src/Console/Commands/PublishAssignment.php
PublishAssignment.createAssignment
protected function createAssignment() { $url = config('forge-publish.url') . config('forge-publish.store_assignment_uri'); try { $response = $this->http->post($url, [ 'form_params' => [ 'name' => $this->assignmentName, 'repository_uri' => $this->repository_uri, 'repository_type' => $this->repository_type, 'forge_site' => $this->forge_site, 'forge_server' => $this->forge_server ], 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest', 'Authorization' => 'Bearer ' . fp_env('ACACHA_FORGE_ACCESS_TOKEN') ] ]); } catch (\Exception $e) { $this->error('And error occurs connecting to the api url: ' . $url); $this->error('Status code: ' . $e->getResponse()->getStatusCode() . ' | Reason : ' . $e->getResponse()->getReasonPhrase()); return; } $assignment = json_decode((string) $response->getBody()); $this->addValueToEnv('ACACHA_FORGE_ASSIGNMENT', $assignment->id); return $assignment; }
php
protected function createAssignment() { $url = config('forge-publish.url') . config('forge-publish.store_assignment_uri'); try { $response = $this->http->post($url, [ 'form_params' => [ 'name' => $this->assignmentName, 'repository_uri' => $this->repository_uri, 'repository_type' => $this->repository_type, 'forge_site' => $this->forge_site, 'forge_server' => $this->forge_server ], 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest', 'Authorization' => 'Bearer ' . fp_env('ACACHA_FORGE_ACCESS_TOKEN') ] ]); } catch (\Exception $e) { $this->error('And error occurs connecting to the api url: ' . $url); $this->error('Status code: ' . $e->getResponse()->getStatusCode() . ' | Reason : ' . $e->getResponse()->getReasonPhrase()); return; } $assignment = json_decode((string) $response->getBody()); $this->addValueToEnv('ACACHA_FORGE_ASSIGNMENT', $assignment->id); return $assignment; }
[ "protected", "function", "createAssignment", "(", ")", "{", "$", "url", "=", "config", "(", "'forge-publish.url'", ")", ".", "config", "(", "'forge-publish.store_assignment_uri'", ")", ";", "try", "{", "$", "response", "=", "$", "this", "->", "http", "->", "post", "(", "$", "url", ",", "[", "'form_params'", "=>", "[", "'name'", "=>", "$", "this", "->", "assignmentName", ",", "'repository_uri'", "=>", "$", "this", "->", "repository_uri", ",", "'repository_type'", "=>", "$", "this", "->", "repository_type", ",", "'forge_site'", "=>", "$", "this", "->", "forge_site", ",", "'forge_server'", "=>", "$", "this", "->", "forge_server", "]", ",", "'headers'", "=>", "[", "'X-Requested-With'", "=>", "'XMLHttpRequest'", ",", "'Authorization'", "=>", "'Bearer '", ".", "fp_env", "(", "'ACACHA_FORGE_ACCESS_TOKEN'", ")", "]", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "error", "(", "'And error occurs connecting to the api url: '", ".", "$", "url", ")", ";", "$", "this", "->", "error", "(", "'Status code: '", ".", "$", "e", "->", "getResponse", "(", ")", "->", "getStatusCode", "(", ")", ".", "' | Reason : '", ".", "$", "e", "->", "getResponse", "(", ")", "->", "getReasonPhrase", "(", ")", ")", ";", "return", ";", "}", "$", "assignment", "=", "json_decode", "(", "(", "string", ")", "$", "response", "->", "getBody", "(", ")", ")", ";", "$", "this", "->", "addValueToEnv", "(", "'ACACHA_FORGE_ASSIGNMENT'", ",", "$", "assignment", "->", "id", ")", ";", "return", "$", "assignment", ";", "}" ]
Create assignment. @return array|mixed
[ "Create", "assignment", "." ]
010779e3d2297c763b82dc3fbde992edffb3a6c6
https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/PublishAssignment.php#L139-L164
train
PHPColibri/framework
Database/Concrete/MySQL/Connection.php
Connection.close
public function close() { if ( ! $this->link->close()) { throw new DbException('can\'t close database connection: ' . $this->link->error, $this->link->errno); } return true; }
php
public function close() { if ( ! $this->link->close()) { throw new DbException('can\'t close database connection: ' . $this->link->error, $this->link->errno); } return true; }
[ "public", "function", "close", "(", ")", "{", "if", "(", "!", "$", "this", "->", "link", "->", "close", "(", ")", ")", "{", "throw", "new", "DbException", "(", "'can\\'t close database connection: '", ".", "$", "this", "->", "link", "->", "error", ",", "$", "this", "->", "link", "->", "errno", ")", ";", "}", "return", "true", ";", "}" ]
Closes the connection. @return bool @throws \Colibri\Database\DbException
[ "Closes", "the", "connection", "." ]
7e5b77141da5e5e7c63afc83592671321ac52f36
https://github.com/PHPColibri/framework/blob/7e5b77141da5e5e7c63afc83592671321ac52f36/Database/Concrete/MySQL/Connection.php#L54-L61
train
SpoonX/SxBootstrap
src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php
FormColorPicker.assembleComponent
protected function assembleComponent($element) { $options = $this->getOptions(); $element = parent::__invoke($element); $component = sprintf( '<div style="padding: 0;" class="input-append color %s" data-color="%s" data-color-format="%s">%s', $options['class'], $options['color'], $options['format'], $element ) . sprintf( '<span class="add-on"><i style="background-color: %s;"></i></span></div>', $options['color'] ); return $component; }
php
protected function assembleComponent($element) { $options = $this->getOptions(); $element = parent::__invoke($element); $component = sprintf( '<div style="padding: 0;" class="input-append color %s" data-color="%s" data-color-format="%s">%s', $options['class'], $options['color'], $options['format'], $element ) . sprintf( '<span class="add-on"><i style="background-color: %s;"></i></span></div>', $options['color'] ); return $component; }
[ "protected", "function", "assembleComponent", "(", "$", "element", ")", "{", "$", "options", "=", "$", "this", "->", "getOptions", "(", ")", ";", "$", "element", "=", "parent", "::", "__invoke", "(", "$", "element", ")", ";", "$", "component", "=", "sprintf", "(", "'<div style=\"padding: 0;\" class=\"input-append color %s\" data-color=\"%s\" data-color-format=\"%s\">%s'", ",", "$", "options", "[", "'class'", "]", ",", "$", "options", "[", "'color'", "]", ",", "$", "options", "[", "'format'", "]", ",", "$", "element", ")", ".", "sprintf", "(", "'<span class=\"add-on\"><i style=\"background-color: %s;\"></i></span></div>'", ",", "$", "options", "[", "'color'", "]", ")", ";", "return", "$", "component", ";", "}" ]
Put together the colorpicker component. @param Zend\Form\Element $element
[ "Put", "together", "the", "colorpicker", "component", "." ]
768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6
https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php#L72-L88
train
SpoonX/SxBootstrap
src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php
FormColorPicker.prepareElement
protected function prepareElement($element) { $options = $this->getOptions(); $currClass = $element->getAttribute('class'); $class = $currClass . (null !== $currClass ? ' ' : '') . $options['class']; $element->setAttributes(array( 'class' => $class, 'data-color' => $options['color'], 'data-color-format' => $options['format'], )); return $element; }
php
protected function prepareElement($element) { $options = $this->getOptions(); $currClass = $element->getAttribute('class'); $class = $currClass . (null !== $currClass ? ' ' : '') . $options['class']; $element->setAttributes(array( 'class' => $class, 'data-color' => $options['color'], 'data-color-format' => $options['format'], )); return $element; }
[ "protected", "function", "prepareElement", "(", "$", "element", ")", "{", "$", "options", "=", "$", "this", "->", "getOptions", "(", ")", ";", "$", "currClass", "=", "$", "element", "->", "getAttribute", "(", "'class'", ")", ";", "$", "class", "=", "$", "currClass", ".", "(", "null", "!==", "$", "currClass", "?", "' '", ":", "''", ")", ".", "$", "options", "[", "'class'", "]", ";", "$", "element", "->", "setAttributes", "(", "array", "(", "'class'", "=>", "$", "class", ",", "'data-color'", "=>", "$", "options", "[", "'color'", "]", ",", "'data-color-format'", "=>", "$", "options", "[", "'format'", "]", ",", ")", ")", ";", "return", "$", "element", ";", "}" ]
Prepare the element by applying all changes to it required for the colorpicker. @param Zend\Form\Element\Element $element @return Zend\Form\View\Helper\FormInput
[ "Prepare", "the", "element", "by", "applying", "all", "changes", "to", "it", "required", "for", "the", "colorpicker", "." ]
768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6
https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php#L97-L110
train
SpoonX/SxBootstrap
src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php
FormColorPicker.setOptions
protected function setOptions($options) { $options = array_merge(array( 'format' => 'hex', 'invoke_inline' => false, 'include_dependencies' => false, 'as_component' => false, 'class' => 'colorpicker', ), $options); if (!in_array($options['format'], array('hex', 'rgb', 'rgba'))) { throw new Exception\InvalidArgumentException( 'Invalid format supplied. Allowed formats are "hex", "rgb" and "rgba".' ); } $defaultColors = array( 'hex' => '#fff', 'rgb' => 'rgb(255,255,255)', 'rgba' => 'rgba(255,255,255,1)', ); if (empty($options['color'])) { $options['color'] = $defaultColors[$options['format']]; } return $this->options = $options; }
php
protected function setOptions($options) { $options = array_merge(array( 'format' => 'hex', 'invoke_inline' => false, 'include_dependencies' => false, 'as_component' => false, 'class' => 'colorpicker', ), $options); if (!in_array($options['format'], array('hex', 'rgb', 'rgba'))) { throw new Exception\InvalidArgumentException( 'Invalid format supplied. Allowed formats are "hex", "rgb" and "rgba".' ); } $defaultColors = array( 'hex' => '#fff', 'rgb' => 'rgb(255,255,255)', 'rgba' => 'rgba(255,255,255,1)', ); if (empty($options['color'])) { $options['color'] = $defaultColors[$options['format']]; } return $this->options = $options; }
[ "protected", "function", "setOptions", "(", "$", "options", ")", "{", "$", "options", "=", "array_merge", "(", "array", "(", "'format'", "=>", "'hex'", ",", "'invoke_inline'", "=>", "false", ",", "'include_dependencies'", "=>", "false", ",", "'as_component'", "=>", "false", ",", "'class'", "=>", "'colorpicker'", ",", ")", ",", "$", "options", ")", ";", "if", "(", "!", "in_array", "(", "$", "options", "[", "'format'", "]", ",", "array", "(", "'hex'", ",", "'rgb'", ",", "'rgba'", ")", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "'Invalid format supplied. Allowed formats are \"hex\", \"rgb\" and \"rgba\".'", ")", ";", "}", "$", "defaultColors", "=", "array", "(", "'hex'", "=>", "'#fff'", ",", "'rgb'", "=>", "'rgb(255,255,255)'", ",", "'rgba'", "=>", "'rgba(255,255,255,1)'", ",", ")", ";", "if", "(", "empty", "(", "$", "options", "[", "'color'", "]", ")", ")", "{", "$", "options", "[", "'color'", "]", "=", "$", "defaultColors", "[", "$", "options", "[", "'format'", "]", "]", ";", "}", "return", "$", "this", "->", "options", "=", "$", "options", ";", "}" ]
Set the options for the colorpicker. @param array $options @return array The options. @throws Exception\InvalidArgumentException
[ "Set", "the", "options", "for", "the", "colorpicker", "." ]
768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6
https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php#L145-L172
train
SpoonX/SxBootstrap
src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php
FormColorPicker.includeDependencies
protected function includeDependencies() { $view = $this->getView(); $view->headScript()->appendFile($view->basePath() . '/js/bootstrap-colorpicker.js'); $view->headLink()->prependStylesheet($view->basePath() . '/css/colorpicker.css'); }
php
protected function includeDependencies() { $view = $this->getView(); $view->headScript()->appendFile($view->basePath() . '/js/bootstrap-colorpicker.js'); $view->headLink()->prependStylesheet($view->basePath() . '/css/colorpicker.css'); }
[ "protected", "function", "includeDependencies", "(", ")", "{", "$", "view", "=", "$", "this", "->", "getView", "(", ")", ";", "$", "view", "->", "headScript", "(", ")", "->", "appendFile", "(", "$", "view", "->", "basePath", "(", ")", ".", "'/js/bootstrap-colorpicker.js'", ")", ";", "$", "view", "->", "headLink", "(", ")", "->", "prependStylesheet", "(", "$", "view", "->", "basePath", "(", ")", ".", "'/css/colorpicker.css'", ")", ";", "}" ]
Include the colorpicker dependencies.
[ "Include", "the", "colorpicker", "dependencies", "." ]
768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6
https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php#L190-L195
train
antaresproject/translations
src/Processor/Publisher.php
Publisher.publish
public function publish($language) { $translations = $this->getTranslationGroups($language->translations); foreach ($translations as $area => $groups) { foreach ($groups as $group => $items) { if (!isset($this->hints[$group])) { continue; } $path = $this->getResourcePath($language->code, $area, $group); $this->publishTranslations($path, $items); } $this->putGitignore($area); } return true; }
php
public function publish($language) { $translations = $this->getTranslationGroups($language->translations); foreach ($translations as $area => $groups) { foreach ($groups as $group => $items) { if (!isset($this->hints[$group])) { continue; } $path = $this->getResourcePath($language->code, $area, $group); $this->publishTranslations($path, $items); } $this->putGitignore($area); } return true; }
[ "public", "function", "publish", "(", "$", "language", ")", "{", "$", "translations", "=", "$", "this", "->", "getTranslationGroups", "(", "$", "language", "->", "translations", ")", ";", "foreach", "(", "$", "translations", "as", "$", "area", "=>", "$", "groups", ")", "{", "foreach", "(", "$", "groups", "as", "$", "group", "=>", "$", "items", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "hints", "[", "$", "group", "]", ")", ")", "{", "continue", ";", "}", "$", "path", "=", "$", "this", "->", "getResourcePath", "(", "$", "language", "->", "code", ",", "$", "area", ",", "$", "group", ")", ";", "$", "this", "->", "publishTranslations", "(", "$", "path", ",", "$", "items", ")", ";", "}", "$", "this", "->", "putGitignore", "(", "$", "area", ")", ";", "}", "return", "true", ";", "}" ]
publish translations from database @param \Illuminate\Database\Eloquent\Model $language @return boolean
[ "publish", "translations", "from", "database" ]
63097aeb97f18c5aeeef7dcf15f0c67959951685
https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L65-L79
train
antaresproject/translations
src/Processor/Publisher.php
Publisher.putGitignore
protected function putGitignore($area) { $target = resource_path(implode(DIRECTORY_SEPARATOR, ['lang', $area, '.gitignore'])); if (!file_exists($target)) { return $this->filesystem->put($target, "*\n!.gitignore"); } return true; }
php
protected function putGitignore($area) { $target = resource_path(implode(DIRECTORY_SEPARATOR, ['lang', $area, '.gitignore'])); if (!file_exists($target)) { return $this->filesystem->put($target, "*\n!.gitignore"); } return true; }
[ "protected", "function", "putGitignore", "(", "$", "area", ")", "{", "$", "target", "=", "resource_path", "(", "implode", "(", "DIRECTORY_SEPARATOR", ",", "[", "'lang'", ",", "$", "area", ",", "'.gitignore'", "]", ")", ")", ";", "if", "(", "!", "file_exists", "(", "$", "target", ")", ")", "{", "return", "$", "this", "->", "filesystem", "->", "put", "(", "$", "target", ",", "\"*\\n!.gitignore\"", ")", ";", "}", "return", "true", ";", "}" ]
Puts gitignore file in lang directory @param String $area @return boolean
[ "Puts", "gitignore", "file", "in", "lang", "directory" ]
63097aeb97f18c5aeeef7dcf15f0c67959951685
https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L87-L94
train
antaresproject/translations
src/Processor/Publisher.php
Publisher.getResourcePath
protected function getResourcePath($locale, $area, $group) { $path = resource_path(implode(DIRECTORY_SEPARATOR, ['lang', $area, $group, $locale])); if ($this->filesystem->exists($path)) { $this->filesystem->cleanDirectory($path); } else { $this->filesystem->makeDirectory($path, 0755, true); } return $path; }
php
protected function getResourcePath($locale, $area, $group) { $path = resource_path(implode(DIRECTORY_SEPARATOR, ['lang', $area, $group, $locale])); if ($this->filesystem->exists($path)) { $this->filesystem->cleanDirectory($path); } else { $this->filesystem->makeDirectory($path, 0755, true); } return $path; }
[ "protected", "function", "getResourcePath", "(", "$", "locale", ",", "$", "area", ",", "$", "group", ")", "{", "$", "path", "=", "resource_path", "(", "implode", "(", "DIRECTORY_SEPARATOR", ",", "[", "'lang'", ",", "$", "area", ",", "$", "group", ",", "$", "locale", "]", ")", ")", ";", "if", "(", "$", "this", "->", "filesystem", "->", "exists", "(", "$", "path", ")", ")", "{", "$", "this", "->", "filesystem", "->", "cleanDirectory", "(", "$", "path", ")", ";", "}", "else", "{", "$", "this", "->", "filesystem", "->", "makeDirectory", "(", "$", "path", ",", "0755", ",", "true", ")", ";", "}", "return", "$", "path", ";", "}" ]
Gets resource path @param String $locale @param String $area @param String $group @return String
[ "Gets", "resource", "path" ]
63097aeb97f18c5aeeef7dcf15f0c67959951685
https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L104-L113
train
antaresproject/translations
src/Processor/Publisher.php
Publisher.publishTranslations
protected function publishTranslations($path, array $items) { foreach ($items as $filename => $translations) { $content = "<?php /** * Part of the Antares package. * * NOTICE OF LICENSE * * Licensed under the 3-clause BSD License. * * This source file is subject to the 3-clause BSD License that is * bundled with this package in the LICENSE file. * * @package Translations * @version 0.9.0 * @author Antares Team * @license BSD License (3-clause) * @copyright (c) 2017, Antares * @link http://antaresproject.io */ \n return\n\n " . var_export($translations, true) . ";\n"; file_put_contents($path . DIRECTORY_SEPARATOR . $filename . '.php', $content); } return true; }
php
protected function publishTranslations($path, array $items) { foreach ($items as $filename => $translations) { $content = "<?php /** * Part of the Antares package. * * NOTICE OF LICENSE * * Licensed under the 3-clause BSD License. * * This source file is subject to the 3-clause BSD License that is * bundled with this package in the LICENSE file. * * @package Translations * @version 0.9.0 * @author Antares Team * @license BSD License (3-clause) * @copyright (c) 2017, Antares * @link http://antaresproject.io */ \n return\n\n " . var_export($translations, true) . ";\n"; file_put_contents($path . DIRECTORY_SEPARATOR . $filename . '.php', $content); } return true; }
[ "protected", "function", "publishTranslations", "(", "$", "path", ",", "array", "$", "items", ")", "{", "foreach", "(", "$", "items", "as", "$", "filename", "=>", "$", "translations", ")", "{", "$", "content", "=", "\"<?php\n\n/**\n * Part of the Antares package.\n *\n * NOTICE OF LICENSE\n *\n * Licensed under the 3-clause BSD License.\n *\n * This source file is subject to the 3-clause BSD License that is\n * bundled with this package in the LICENSE file.\n *\n * @package Translations\n * @version 0.9.0\n * @author Antares Team\n * @license BSD License (3-clause)\n * @copyright (c) 2017, Antares\n * @link http://antaresproject.io\n */\n\n\\n return\\n\\n \"", ".", "var_export", "(", "$", "translations", ",", "true", ")", ".", "\";\\n\"", ";", "file_put_contents", "(", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "$", "filename", ".", "'.php'", ",", "$", "content", ")", ";", "}", "return", "true", ";", "}" ]
writing translations to files @param String $path @param array $items @return boolean
[ "writing", "translations", "to", "files" ]
63097aeb97f18c5aeeef7dcf15f0c67959951685
https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L122-L150
train
antaresproject/translations
src/Processor/Publisher.php
Publisher.getTranslationGroups
protected function getTranslationGroups(Collection $list) { $groups = []; foreach ($list as $model) { if (!isset($groups[$model->area][$model->group])) { $groups[$model->area][$model->group] = []; } $groups[$model->area][$model->group] = Arr::add($groups[$model->area][$model->group], $model->key, $model->value); } return $groups; }
php
protected function getTranslationGroups(Collection $list) { $groups = []; foreach ($list as $model) { if (!isset($groups[$model->area][$model->group])) { $groups[$model->area][$model->group] = []; } $groups[$model->area][$model->group] = Arr::add($groups[$model->area][$model->group], $model->key, $model->value); } return $groups; }
[ "protected", "function", "getTranslationGroups", "(", "Collection", "$", "list", ")", "{", "$", "groups", "=", "[", "]", ";", "foreach", "(", "$", "list", "as", "$", "model", ")", "{", "if", "(", "!", "isset", "(", "$", "groups", "[", "$", "model", "->", "area", "]", "[", "$", "model", "->", "group", "]", ")", ")", "{", "$", "groups", "[", "$", "model", "->", "area", "]", "[", "$", "model", "->", "group", "]", "=", "[", "]", ";", "}", "$", "groups", "[", "$", "model", "->", "area", "]", "[", "$", "model", "->", "group", "]", "=", "Arr", "::", "add", "(", "$", "groups", "[", "$", "model", "->", "area", "]", "[", "$", "model", "->", "group", "]", ",", "$", "model", "->", "key", ",", "$", "model", "->", "value", ")", ";", "}", "return", "$", "groups", ";", "}" ]
grouping translations by component name @param Collection $list @return array
[ "grouping", "translations", "by", "component", "name" ]
63097aeb97f18c5aeeef7dcf15f0c67959951685
https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L158-L168
train
factorio-item-browser/api-client
src/Service/EndpointService.php
EndpointService.getEndpointForRequest
public function getEndpointForRequest(RequestInterface $request): EndpointInterface { $requestClass = get_class($request); if (!isset($this->endpointsByRequestClass[$requestClass])) { throw new UnsupportedRequestException($requestClass); } return $this->endpointsByRequestClass[$requestClass]; }
php
public function getEndpointForRequest(RequestInterface $request): EndpointInterface { $requestClass = get_class($request); if (!isset($this->endpointsByRequestClass[$requestClass])) { throw new UnsupportedRequestException($requestClass); } return $this->endpointsByRequestClass[$requestClass]; }
[ "public", "function", "getEndpointForRequest", "(", "RequestInterface", "$", "request", ")", ":", "EndpointInterface", "{", "$", "requestClass", "=", "get_class", "(", "$", "request", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "endpointsByRequestClass", "[", "$", "requestClass", "]", ")", ")", "{", "throw", "new", "UnsupportedRequestException", "(", "$", "requestClass", ")", ";", "}", "return", "$", "this", "->", "endpointsByRequestClass", "[", "$", "requestClass", "]", ";", "}" ]
Returns the endpoint for the request. @param RequestInterface $request @return EndpointInterface @throws UnsupportedRequestException
[ "Returns", "the", "endpoint", "for", "the", "request", "." ]
ebda897483bd537c310a17ff868ca40c0568f728
https://github.com/factorio-item-browser/api-client/blob/ebda897483bd537c310a17ff868ca40c0568f728/src/Service/EndpointService.php#L42-L50
train
anklimsk/cakephp-console-installer
Console/Helper/WaitingShellHelper.php
WaitingShellHelper._getAnimateChar
protected function _getAnimateChar() { if ($this->_animateCharNum >= count($this->_animateChars)) { $this->_animateCharNum = 0; } return $this->_animateChars[$this->_animateCharNum++]; }
php
protected function _getAnimateChar() { if ($this->_animateCharNum >= count($this->_animateChars)) { $this->_animateCharNum = 0; } return $this->_animateChars[$this->_animateCharNum++]; }
[ "protected", "function", "_getAnimateChar", "(", ")", "{", "if", "(", "$", "this", "->", "_animateCharNum", ">=", "count", "(", "$", "this", "->", "_animateChars", ")", ")", "{", "$", "this", "->", "_animateCharNum", "=", "0", ";", "}", "return", "$", "this", "->", "_animateChars", "[", "$", "this", "->", "_animateCharNum", "++", "]", ";", "}" ]
Get char for animate @return string
[ "Get", "char", "for", "animate" ]
76136550e856ff4f8fd3634b77633f86510f63e9
https://github.com/anklimsk/cakephp-console-installer/blob/76136550e856ff4f8fd3634b77633f86510f63e9/Console/Helper/WaitingShellHelper.php#L58-L64
train
anklimsk/cakephp-console-installer
Console/Helper/WaitingShellHelper.php
WaitingShellHelper.animateMessage
public function animateMessage() { if (!$this->_showMessage) { $this->_showMessage = true; $this->_animateCharNum = 0; $msg = $this->_getWaitMsg(); $msg .= ' ' . $this->_getAnimateChar(); $this->_consoleOutput->write($msg, 0); } else { $msg = $this->_getAnimateChar(); $this->_consoleOutput->overwrite($msg, 0, mb_strlen($msg)); } }
php
public function animateMessage() { if (!$this->_showMessage) { $this->_showMessage = true; $this->_animateCharNum = 0; $msg = $this->_getWaitMsg(); $msg .= ' ' . $this->_getAnimateChar(); $this->_consoleOutput->write($msg, 0); } else { $msg = $this->_getAnimateChar(); $this->_consoleOutput->overwrite($msg, 0, mb_strlen($msg)); } }
[ "public", "function", "animateMessage", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_showMessage", ")", "{", "$", "this", "->", "_showMessage", "=", "true", ";", "$", "this", "->", "_animateCharNum", "=", "0", ";", "$", "msg", "=", "$", "this", "->", "_getWaitMsg", "(", ")", ";", "$", "msg", ".=", "' '", ".", "$", "this", "->", "_getAnimateChar", "(", ")", ";", "$", "this", "->", "_consoleOutput", "->", "write", "(", "$", "msg", ",", "0", ")", ";", "}", "else", "{", "$", "msg", "=", "$", "this", "->", "_getAnimateChar", "(", ")", ";", "$", "this", "->", "_consoleOutput", "->", "overwrite", "(", "$", "msg", ",", "0", ",", "mb_strlen", "(", "$", "msg", ")", ")", ";", "}", "}" ]
Print message 'Please wait...' and animate char on console @return void
[ "Print", "message", "Please", "wait", "...", "and", "animate", "char", "on", "console" ]
76136550e856ff4f8fd3634b77633f86510f63e9
https://github.com/anklimsk/cakephp-console-installer/blob/76136550e856ff4f8fd3634b77633f86510f63e9/Console/Helper/WaitingShellHelper.php#L82-L93
train
anklimsk/cakephp-console-installer
Console/Helper/WaitingShellHelper.php
WaitingShellHelper.hideMessage
public function hideMessage() { if (!$this->_showMessage) { return; } $msg = $this->_getWaitMsg(); $msg .= ' x'; $this->_consoleOutput->write(str_repeat("\x08", mb_strlen($msg)), 0); $this->_showMessage = false; }
php
public function hideMessage() { if (!$this->_showMessage) { return; } $msg = $this->_getWaitMsg(); $msg .= ' x'; $this->_consoleOutput->write(str_repeat("\x08", mb_strlen($msg)), 0); $this->_showMessage = false; }
[ "public", "function", "hideMessage", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_showMessage", ")", "{", "return", ";", "}", "$", "msg", "=", "$", "this", "->", "_getWaitMsg", "(", ")", ";", "$", "msg", ".=", "' x'", ";", "$", "this", "->", "_consoleOutput", "->", "write", "(", "str_repeat", "(", "\"\\x08\"", ",", "mb_strlen", "(", "$", "msg", ")", ")", ",", "0", ")", ";", "$", "this", "->", "_showMessage", "=", "false", ";", "}" ]
Hide message 'Please wait...' on console @return void
[ "Hide", "message", "Please", "wait", "...", "on", "console" ]
76136550e856ff4f8fd3634b77633f86510f63e9
https://github.com/anklimsk/cakephp-console-installer/blob/76136550e856ff4f8fd3634b77633f86510f63e9/Console/Helper/WaitingShellHelper.php#L100-L109
train
as3io/modlr
src/Models/Embeds/HasMany.php
HasMany.areDirty
public function areDirty() { if (true === parent::areDirty()) { return true; } foreach ($this->getOriginalAll() as $collection) { if (true === $collection->isDirty()) { return true; } } return false; }
php
public function areDirty() { if (true === parent::areDirty()) { return true; } foreach ($this->getOriginalAll() as $collection) { if (true === $collection->isDirty()) { return true; } } return false; }
[ "public", "function", "areDirty", "(", ")", "{", "if", "(", "true", "===", "parent", "::", "areDirty", "(", ")", ")", "{", "return", "true", ";", "}", "foreach", "(", "$", "this", "->", "getOriginalAll", "(", ")", "as", "$", "collection", ")", "{", "if", "(", "true", "===", "$", "collection", "->", "isDirty", "(", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Extended to also check for dirty states of has-many Collections. {@inheritDoc}
[ "Extended", "to", "also", "check", "for", "dirty", "states", "of", "has", "-", "many", "Collections", "." ]
7e684b88bb22a2e18397df9402075c6533084b16
https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Models/Embeds/HasMany.php#L20-L31
train
as3io/modlr
src/Models/Embeds/HasMany.php
HasMany.calculateChangeSet
public function calculateChangeSet() { $set = []; foreach ($this->getOriginalAll() as $key => $collection) { if (false === $collection->isDirty()) { continue; } $set[$key] = $collection->calculateChangeSet(); } return $set; }
php
public function calculateChangeSet() { $set = []; foreach ($this->getOriginalAll() as $key => $collection) { if (false === $collection->isDirty()) { continue; } $set[$key] = $collection->calculateChangeSet(); } return $set; }
[ "public", "function", "calculateChangeSet", "(", ")", "{", "$", "set", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getOriginalAll", "(", ")", "as", "$", "key", "=>", "$", "collection", ")", "{", "if", "(", "false", "===", "$", "collection", "->", "isDirty", "(", ")", ")", "{", "continue", ";", "}", "$", "set", "[", "$", "key", "]", "=", "$", "collection", "->", "calculateChangeSet", "(", ")", ";", "}", "return", "$", "set", ";", "}" ]
Overwritten to account for collection change sets. {@inheritDoc}
[ "Overwritten", "to", "account", "for", "collection", "change", "sets", "." ]
7e684b88bb22a2e18397df9402075c6533084b16
https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Models/Embeds/HasMany.php#L54-L64
train
YiMAproject/yimaWidgetator
src/yimaWidgetator/AbstractWidgetHelper.php
AbstractWidgetHelper.addWidget
function addWidget($region, $widget, $priority = 0) { if (!$this->rBoxContainer) { $sm = $this->getServiceLocator()->getServiceLocator(); $rBoxContainer = $sm->get('yimaWidgetator.Widgetizer.Container'); $this->rBoxContainer = $rBoxContainer; } $this->rBoxContainer->addWidget($region, $widget, $priority); return $this; }
php
function addWidget($region, $widget, $priority = 0) { if (!$this->rBoxContainer) { $sm = $this->getServiceLocator()->getServiceLocator(); $rBoxContainer = $sm->get('yimaWidgetator.Widgetizer.Container'); $this->rBoxContainer = $rBoxContainer; } $this->rBoxContainer->addWidget($region, $widget, $priority); return $this; }
[ "function", "addWidget", "(", "$", "region", ",", "$", "widget", ",", "$", "priority", "=", "0", ")", "{", "if", "(", "!", "$", "this", "->", "rBoxContainer", ")", "{", "$", "sm", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "getServiceLocator", "(", ")", ";", "$", "rBoxContainer", "=", "$", "sm", "->", "get", "(", "'yimaWidgetator.Widgetizer.Container'", ")", ";", "$", "this", "->", "rBoxContainer", "=", "$", "rBoxContainer", ";", "}", "$", "this", "->", "rBoxContainer", "->", "addWidget", "(", "$", "region", ",", "$", "widget", ",", "$", "priority", ")", ";", "return", "$", "this", ";", "}" ]
Add Widget To Region Box Container @param $region @param $widget @param int $priority @return $this
[ "Add", "Widget", "To", "Region", "Box", "Container" ]
332bc9318e6ceaec918147b30317da2f5b3d2636
https://github.com/YiMAproject/yimaWidgetator/blob/332bc9318e6ceaec918147b30317da2f5b3d2636/src/yimaWidgetator/AbstractWidgetHelper.php#L59-L71
train
YiMAproject/yimaWidgetator
src/yimaWidgetator/AbstractWidgetHelper.php
AbstractWidgetHelper.getWidgetManager
function getWidgetManager() { if (! $this->widgetManager) { $sm = $this->getServiceLocator()->getServiceLocator(); $widgetManager = $sm->get('yimaWidgetator.WidgetManager'); if (!($widgetManager instanceof WidgetManager) || !($widgetManager instanceof AbstractPluginManager) ) throw new \Exception(sprintf( 'WidgetManager must instance of WidgetManager or AbstractPluginManager, but "%s" given from \'yimaWidgetator.WidgetManager\'', is_object($widgetManager) ? get_class($widgetManager) : gettype($widgetManager) )); $this->widgetManager = $widgetManager; } return $this->widgetManager; }
php
function getWidgetManager() { if (! $this->widgetManager) { $sm = $this->getServiceLocator()->getServiceLocator(); $widgetManager = $sm->get('yimaWidgetator.WidgetManager'); if (!($widgetManager instanceof WidgetManager) || !($widgetManager instanceof AbstractPluginManager) ) throw new \Exception(sprintf( 'WidgetManager must instance of WidgetManager or AbstractPluginManager, but "%s" given from \'yimaWidgetator.WidgetManager\'', is_object($widgetManager) ? get_class($widgetManager) : gettype($widgetManager) )); $this->widgetManager = $widgetManager; } return $this->widgetManager; }
[ "function", "getWidgetManager", "(", ")", "{", "if", "(", "!", "$", "this", "->", "widgetManager", ")", "{", "$", "sm", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "getServiceLocator", "(", ")", ";", "$", "widgetManager", "=", "$", "sm", "->", "get", "(", "'yimaWidgetator.WidgetManager'", ")", ";", "if", "(", "!", "(", "$", "widgetManager", "instanceof", "WidgetManager", ")", "||", "!", "(", "$", "widgetManager", "instanceof", "AbstractPluginManager", ")", ")", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'WidgetManager must instance of WidgetManager or AbstractPluginManager, but \"%s\" given from \\'yimaWidgetator.WidgetManager\\''", ",", "is_object", "(", "$", "widgetManager", ")", "?", "get_class", "(", "$", "widgetManager", ")", ":", "gettype", "(", "$", "widgetManager", ")", ")", ")", ";", "$", "this", "->", "widgetManager", "=", "$", "widgetManager", ";", "}", "return", "$", "this", "->", "widgetManager", ";", "}" ]
Get Widget Manager @throws \Exception @return WidgetManager
[ "Get", "Widget", "Manager" ]
332bc9318e6ceaec918147b30317da2f5b3d2636
https://github.com/YiMAproject/yimaWidgetator/blob/332bc9318e6ceaec918147b30317da2f5b3d2636/src/yimaWidgetator/AbstractWidgetHelper.php#L79-L97
train
znframework/package-hypertext
Table.php
Table.cell
public function cell(Int $spacing, Int $padding) : Table { $this->attr['cellspacing'] = $spacing; $this->attr['cellpadding'] = $padding; return $this; }
php
public function cell(Int $spacing, Int $padding) : Table { $this->attr['cellspacing'] = $spacing; $this->attr['cellpadding'] = $padding; return $this; }
[ "public", "function", "cell", "(", "Int", "$", "spacing", ",", "Int", "$", "padding", ")", ":", "Table", "{", "$", "this", "->", "attr", "[", "'cellspacing'", "]", "=", "$", "spacing", ";", "$", "this", "->", "attr", "[", "'cellpadding'", "]", "=", "$", "padding", ";", "return", "$", "this", ";", "}" ]
Sets table cell @param int $spacing @param int $padding @return Table
[ "Sets", "table", "cell" ]
12bbc3bd47a2fae735f638a3e01cc82c1b9c9005
https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L74-L80
train
znframework/package-hypertext
Table.php
Table.border
public function border(Int $border, String $color = NULL) : Table { $this->attr['border'] = $border; if( ! empty($color) ) { $this->attr['bordercolor'] = $color; } return $this; }
php
public function border(Int $border, String $color = NULL) : Table { $this->attr['border'] = $border; if( ! empty($color) ) { $this->attr['bordercolor'] = $color; } return $this; }
[ "public", "function", "border", "(", "Int", "$", "border", ",", "String", "$", "color", "=", "NULL", ")", ":", "Table", "{", "$", "this", "->", "attr", "[", "'border'", "]", "=", "$", "border", ";", "if", "(", "!", "empty", "(", "$", "color", ")", ")", "{", "$", "this", "->", "attr", "[", "'bordercolor'", "]", "=", "$", "color", ";", "}", "return", "$", "this", ";", "}" ]
Sets table border @param int $border @param string $color = NULL @return Table
[ "Sets", "table", "border" ]
12bbc3bd47a2fae735f638a3e01cc82c1b9c9005
https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L90-L100
train
znframework/package-hypertext
Table.php
Table.size
public function size(Int $width, Int $height) : Table { $this->attr['width'] = $width; $this->attr['height'] = $height; return $this; }
php
public function size(Int $width, Int $height) : Table { $this->attr['width'] = $width; $this->attr['height'] = $height; return $this; }
[ "public", "function", "size", "(", "Int", "$", "width", ",", "Int", "$", "height", ")", ":", "Table", "{", "$", "this", "->", "attr", "[", "'width'", "]", "=", "$", "width", ";", "$", "this", "->", "attr", "[", "'height'", "]", "=", "$", "height", ";", "return", "$", "this", ";", "}" ]
Sets table size @param int $width @param int $height @return Table
[ "Sets", "table", "size" ]
12bbc3bd47a2fae735f638a3e01cc82c1b9c9005
https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L110-L116
train
znframework/package-hypertext
Table.php
Table.style
public function style(Array $attributes) : Table { $attribute = ''; foreach( $attributes as $key => $values ) { if( is_numeric($key) ) { $key = $values; } $attribute .= ' '.$key.':'.$values.';'; } $this->attr['style'] = $attribute; return $this; }
php
public function style(Array $attributes) : Table { $attribute = ''; foreach( $attributes as $key => $values ) { if( is_numeric($key) ) { $key = $values; } $attribute .= ' '.$key.':'.$values.';'; } $this->attr['style'] = $attribute; return $this; }
[ "public", "function", "style", "(", "Array", "$", "attributes", ")", ":", "Table", "{", "$", "attribute", "=", "''", ";", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "values", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "key", "=", "$", "values", ";", "}", "$", "attribute", ".=", "' '", ".", "$", "key", ".", "':'", ".", "$", "values", ".", "';'", ";", "}", "$", "this", "->", "attr", "[", "'style'", "]", "=", "$", "attribute", ";", "return", "$", "this", ";", "}" ]
Sets table style attribute @param array $attributes @return Table
[ "Sets", "table", "style", "attribute" ]
12bbc3bd47a2fae735f638a3e01cc82c1b9c9005
https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L125-L142
train
schpill/thin
src/Form.php
Form.buildLabel
public static function buildLabel($name, $label = '', $required = false) { $out = ''; if (!empty($label)) { $class = 'control-label'; $requiredLabel = '.req'; $requiredSuffix = '<span class="required"><i class="icon-asterisk"></i></span>'; $requiredPrefix = ''; $requiredClass = 'labelrequired'; if (false !== $required) { $label = $requiredPrefix . $label . $requiredSuffix; $class .= ' ' . $requiredClass; } $out .= static::label($name, $label, array('class' => $class)); } return $out; }
php
public static function buildLabel($name, $label = '', $required = false) { $out = ''; if (!empty($label)) { $class = 'control-label'; $requiredLabel = '.req'; $requiredSuffix = '<span class="required"><i class="icon-asterisk"></i></span>'; $requiredPrefix = ''; $requiredClass = 'labelrequired'; if (false !== $required) { $label = $requiredPrefix . $label . $requiredSuffix; $class .= ' ' . $requiredClass; } $out .= static::label($name, $label, array('class' => $class)); } return $out; }
[ "public", "static", "function", "buildLabel", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "required", "=", "false", ")", "{", "$", "out", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "label", ")", ")", "{", "$", "class", "=", "'control-label'", ";", "$", "requiredLabel", "=", "'.req'", ";", "$", "requiredSuffix", "=", "'<span class=\"required\"><i class=\"icon-asterisk\"></i></span>'", ";", "$", "requiredPrefix", "=", "''", ";", "$", "requiredClass", "=", "'labelrequired'", ";", "if", "(", "false", "!==", "$", "required", ")", "{", "$", "label", "=", "$", "requiredPrefix", ".", "$", "label", ".", "$", "requiredSuffix", ";", "$", "class", ".=", "' '", ".", "$", "requiredClass", ";", "}", "$", "out", ".=", "static", "::", "label", "(", "$", "name", ",", "$", "label", ",", "array", "(", "'class'", "=>", "$", "class", ")", ")", ";", "}", "return", "$", "out", ";", "}" ]
Builds the label html @param string $name The name of the html field @param string $label The label name @param boolean $required @return string
[ "Builds", "the", "label", "html" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Form.php#L122-L142
train
schpill/thin
src/Form.php
Form.buildWrapper
private static function buildWrapper($field, $name, $label = '', $checkbox = false, $required) { $getter = 'get' . Inflector::camelize($name); $error = null; $actual = Session::instance('ThinForm')->getActual(); if (null !== $actual) { $error = $actual->getErrors()->$getter(); } $class = 'control-group'; if (!empty(static::$controlGroupError) && !empty($error)) { $class .= ' ' . static::$controlGroupError; } $id = ' id="control-group-' . $name . '"'; $out = '<div class="' . $class . '"' . $id . '>'; $out .= static::buildLabel($name, $label, $required); $out .= '<div class="controls">' . PHP_EOL; $out .= ($checkbox === true) ? '<label class="checkbox">' : ''; $out .= $field; if (!empty($error)) { $out .= '<span class="help-inline">' . $error . '</span>'; } $out .= ($checkbox === true) ? '</label>' : ''; $out .= '</div>'; $out .= '</div>' . PHP_EOL; return $out; }
php
private static function buildWrapper($field, $name, $label = '', $checkbox = false, $required) { $getter = 'get' . Inflector::camelize($name); $error = null; $actual = Session::instance('ThinForm')->getActual(); if (null !== $actual) { $error = $actual->getErrors()->$getter(); } $class = 'control-group'; if (!empty(static::$controlGroupError) && !empty($error)) { $class .= ' ' . static::$controlGroupError; } $id = ' id="control-group-' . $name . '"'; $out = '<div class="' . $class . '"' . $id . '>'; $out .= static::buildLabel($name, $label, $required); $out .= '<div class="controls">' . PHP_EOL; $out .= ($checkbox === true) ? '<label class="checkbox">' : ''; $out .= $field; if (!empty($error)) { $out .= '<span class="help-inline">' . $error . '</span>'; } $out .= ($checkbox === true) ? '</label>' : ''; $out .= '</div>'; $out .= '</div>' . PHP_EOL; return $out; }
[ "private", "static", "function", "buildWrapper", "(", "$", "field", ",", "$", "name", ",", "$", "label", "=", "''", ",", "$", "checkbox", "=", "false", ",", "$", "required", ")", "{", "$", "getter", "=", "'get'", ".", "Inflector", "::", "camelize", "(", "$", "name", ")", ";", "$", "error", "=", "null", ";", "$", "actual", "=", "Session", "::", "instance", "(", "'ThinForm'", ")", "->", "getActual", "(", ")", ";", "if", "(", "null", "!==", "$", "actual", ")", "{", "$", "error", "=", "$", "actual", "->", "getErrors", "(", ")", "->", "$", "getter", "(", ")", ";", "}", "$", "class", "=", "'control-group'", ";", "if", "(", "!", "empty", "(", "static", "::", "$", "controlGroupError", ")", "&&", "!", "empty", "(", "$", "error", ")", ")", "{", "$", "class", ".=", "' '", ".", "static", "::", "$", "controlGroupError", ";", "}", "$", "id", "=", "' id=\"control-group-'", ".", "$", "name", ".", "'\"'", ";", "$", "out", "=", "'<div class=\"'", ".", "$", "class", ".", "'\"'", ".", "$", "id", ".", "'>'", ";", "$", "out", ".=", "static", "::", "buildLabel", "(", "$", "name", ",", "$", "label", ",", "$", "required", ")", ";", "$", "out", ".=", "'<div class=\"controls\">'", ".", "PHP_EOL", ";", "$", "out", ".=", "(", "$", "checkbox", "===", "true", ")", "?", "'<label class=\"checkbox\">'", ":", "''", ";", "$", "out", ".=", "$", "field", ";", "if", "(", "!", "empty", "(", "$", "error", ")", ")", "{", "$", "out", ".=", "'<span class=\"help-inline\">'", ".", "$", "error", ".", "'</span>'", ";", "}", "$", "out", ".=", "(", "$", "checkbox", "===", "true", ")", "?", "'</label>'", ":", "''", ";", "$", "out", ".=", "'</div>'", ";", "$", "out", ".=", "'</div>'", ".", "PHP_EOL", ";", "return", "$", "out", ";", "}" ]
Builds the Twitter Bootstrap control wrapper @param string $field The html for the field @param string $name The name of the field @param string $label The label name @param boolean $checkbox @return string
[ "Builds", "the", "Twitter", "Bootstrap", "control", "wrapper" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Form.php#L153-L185
train
jtallant/skimpy-engine
src/File/ContentFile.php
ContentFile.getDate
public function getDate() { if (false === $this->frontMatter->has('date')) { # Defaults to last modified return (new DateTime)->setTimestamp($this->file->getMTime()); } $date = $this->frontMatter->getDate(); if ($date instanceof DateTime) { return $date; } return (new DateTime)->setTimestamp($date); }
php
public function getDate() { if (false === $this->frontMatter->has('date')) { # Defaults to last modified return (new DateTime)->setTimestamp($this->file->getMTime()); } $date = $this->frontMatter->getDate(); if ($date instanceof DateTime) { return $date; } return (new DateTime)->setTimestamp($date); }
[ "public", "function", "getDate", "(", ")", "{", "if", "(", "false", "===", "$", "this", "->", "frontMatter", "->", "has", "(", "'date'", ")", ")", "{", "# Defaults to last modified", "return", "(", "new", "DateTime", ")", "->", "setTimestamp", "(", "$", "this", "->", "file", "->", "getMTime", "(", ")", ")", ";", "}", "$", "date", "=", "$", "this", "->", "frontMatter", "->", "getDate", "(", ")", ";", "if", "(", "$", "date", "instanceof", "DateTime", ")", "{", "return", "$", "date", ";", "}", "return", "(", "new", "DateTime", ")", "->", "setTimestamp", "(", "$", "date", ")", ";", "}" ]
Front matter date or filemtime @return DateTime
[ "Front", "matter", "date", "or", "filemtime" ]
2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2
https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/File/ContentFile.php#L108-L122
train
jtallant/skimpy-engine
src/File/ContentFile.php
ContentFile.getUri
public function getUri() { if ($this->isIndex()) { return $this->getUriPath(); } $path = $this->getUriPath().DIRECTORY_SEPARATOR.$this->getFilename(); return trim($path, DIRECTORY_SEPARATOR); }
php
public function getUri() { if ($this->isIndex()) { return $this->getUriPath(); } $path = $this->getUriPath().DIRECTORY_SEPARATOR.$this->getFilename(); return trim($path, DIRECTORY_SEPARATOR); }
[ "public", "function", "getUri", "(", ")", "{", "if", "(", "$", "this", "->", "isIndex", "(", ")", ")", "{", "return", "$", "this", "->", "getUriPath", "(", ")", ";", "}", "$", "path", "=", "$", "this", "->", "getUriPath", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "getFilename", "(", ")", ";", "return", "trim", "(", "$", "path", ",", "DIRECTORY_SEPARATOR", ")", ";", "}" ]
URI to the content based on directory path # Directory | URI ------------------------------------ foo/bar/baz.md | foo/bar/baz Files named index.md do not use the filename in the URI: index.md => / foo/index.md => foo/ foo/bar/index.md => foo/bar/index @return string
[ "URI", "to", "the", "content", "based", "on", "directory", "path" ]
2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2
https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/File/ContentFile.php#L188-L197
train
jtallant/skimpy-engine
src/File/ContentFile.php
ContentFile.getUriPath
protected function getUriPath() { $path = dirname($this->getPathFromContent()); $parts = explode(DIRECTORY_SEPARATOR, $path); $uriParts = array_filter($parts, function ($dirname) { return false === $this->isTopLevel(); }); return trim(implode(DIRECTORY_SEPARATOR, $uriParts), DIRECTORY_SEPARATOR); }
php
protected function getUriPath() { $path = dirname($this->getPathFromContent()); $parts = explode(DIRECTORY_SEPARATOR, $path); $uriParts = array_filter($parts, function ($dirname) { return false === $this->isTopLevel(); }); return trim(implode(DIRECTORY_SEPARATOR, $uriParts), DIRECTORY_SEPARATOR); }
[ "protected", "function", "getUriPath", "(", ")", "{", "$", "path", "=", "dirname", "(", "$", "this", "->", "getPathFromContent", "(", ")", ")", ";", "$", "parts", "=", "explode", "(", "DIRECTORY_SEPARATOR", ",", "$", "path", ")", ";", "$", "uriParts", "=", "array_filter", "(", "$", "parts", ",", "function", "(", "$", "dirname", ")", "{", "return", "false", "===", "$", "this", "->", "isTopLevel", "(", ")", ";", "}", ")", ";", "return", "trim", "(", "implode", "(", "DIRECTORY_SEPARATOR", ",", "$", "uriParts", ")", ",", "DIRECTORY_SEPARATOR", ")", ";", "}" ]
Returns the URI parts to the Entry up to but not including the slug, based on the file location. @return string
[ "Returns", "the", "URI", "parts", "to", "the", "Entry", "up", "to", "but", "not", "including", "the", "slug", "based", "on", "the", "file", "location", "." ]
2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2
https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/File/ContentFile.php#L257-L267
train
crisu83/yii-consoletools
commands/EnvironmentCommand.php
EnvironmentCommand.run
public function run($args) { if (!isset($args[0])) { $this->usageError('The environment id is not specified.'); } $id = $args[0]; $this->flush(); echo "\nCopying environment files... \n"; $environmentPath = $this->basePath . '/' . $this->environmentsDir . '/' . $id; if (!file_exists($environmentPath)) { throw new CException(sprintf("Failed to change environment. Unknown environment '%s'!", $id)); } $fileList = $this->buildFileList($environmentPath, $this->basePath); $this->copyFiles($fileList); echo "\nEnvironment successfully changed to '{$id}'.\n"; }
php
public function run($args) { if (!isset($args[0])) { $this->usageError('The environment id is not specified.'); } $id = $args[0]; $this->flush(); echo "\nCopying environment files... \n"; $environmentPath = $this->basePath . '/' . $this->environmentsDir . '/' . $id; if (!file_exists($environmentPath)) { throw new CException(sprintf("Failed to change environment. Unknown environment '%s'!", $id)); } $fileList = $this->buildFileList($environmentPath, $this->basePath); $this->copyFiles($fileList); echo "\nEnvironment successfully changed to '{$id}'.\n"; }
[ "public", "function", "run", "(", "$", "args", ")", "{", "if", "(", "!", "isset", "(", "$", "args", "[", "0", "]", ")", ")", "{", "$", "this", "->", "usageError", "(", "'The environment id is not specified.'", ")", ";", "}", "$", "id", "=", "$", "args", "[", "0", "]", ";", "$", "this", "->", "flush", "(", ")", ";", "echo", "\"\\nCopying environment files... \\n\"", ";", "$", "environmentPath", "=", "$", "this", "->", "basePath", ".", "'/'", ".", "$", "this", "->", "environmentsDir", ".", "'/'", ".", "$", "id", ";", "if", "(", "!", "file_exists", "(", "$", "environmentPath", ")", ")", "{", "throw", "new", "CException", "(", "sprintf", "(", "\"Failed to change environment. Unknown environment '%s'!\"", ",", "$", "id", ")", ")", ";", "}", "$", "fileList", "=", "$", "this", "->", "buildFileList", "(", "$", "environmentPath", ",", "$", "this", "->", "basePath", ")", ";", "$", "this", "->", "copyFiles", "(", "$", "fileList", ")", ";", "echo", "\"\\nEnvironment successfully changed to '{$id}'.\\n\"", ";", "}" ]
Changes the current environment. @param array $args the command-line arguments. @throws CException if the environment path does not exist.
[ "Changes", "the", "current", "environment", "." ]
53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc
https://github.com/crisu83/yii-consoletools/blob/53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc/commands/EnvironmentCommand.php#L44-L62
train
MovingImage24/VM6ApiClient
lib/ApiClient/AbstractApiClient.php
AbstractApiClient.getChannelList
private function getChannelList() { if (empty($this->channelList)) { $response = $this->makeRequest('GET', 'get_rubric_object_list.json', []); $this->channelList = $this->deserialize($response->getBody()->getContents(), ChannelList::class); } return $this->channelList; }
php
private function getChannelList() { if (empty($this->channelList)) { $response = $this->makeRequest('GET', 'get_rubric_object_list.json', []); $this->channelList = $this->deserialize($response->getBody()->getContents(), ChannelList::class); } return $this->channelList; }
[ "private", "function", "getChannelList", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "channelList", ")", ")", "{", "$", "response", "=", "$", "this", "->", "makeRequest", "(", "'GET'", ",", "'get_rubric_object_list.json'", ",", "[", "]", ")", ";", "$", "this", "->", "channelList", "=", "$", "this", "->", "deserialize", "(", "$", "response", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ",", "ChannelList", "::", "class", ")", ";", "}", "return", "$", "this", "->", "channelList", ";", "}" ]
Returns ChannelList containing all channels belonging to the video manager. @return ChannelList
[ "Returns", "ChannelList", "containing", "all", "channels", "belonging", "to", "the", "video", "manager", "." ]
84e6510fa0fb71cfbb42ea9f23775f681c266fac
https://github.com/MovingImage24/VM6ApiClient/blob/84e6510fa0fb71cfbb42ea9f23775f681c266fac/lib/ApiClient/AbstractApiClient.php#L49-L57
train
MovingImage24/VM6ApiClient
lib/ApiClient/AbstractApiClient.php
AbstractApiClient.getChannelIdsInclusiveSubChannels
private function getChannelIdsInclusiveSubChannels($channelIds) { $subChannelIds = []; foreach ($channelIds as $channelId) { $subChannels = $this->getChannelList()->getChildren($channelId); $subChannelIds = array_merge($subChannelIds, $subChannels->map(function (Channel $channel) { return $channel->getId(); })->toArray()); } return empty($subChannelIds) ? $channelIds : array_merge($channelIds, $this->getChannelIdsInclusiveSubChannels($subChannelIds)); }
php
private function getChannelIdsInclusiveSubChannels($channelIds) { $subChannelIds = []; foreach ($channelIds as $channelId) { $subChannels = $this->getChannelList()->getChildren($channelId); $subChannelIds = array_merge($subChannelIds, $subChannels->map(function (Channel $channel) { return $channel->getId(); })->toArray()); } return empty($subChannelIds) ? $channelIds : array_merge($channelIds, $this->getChannelIdsInclusiveSubChannels($subChannelIds)); }
[ "private", "function", "getChannelIdsInclusiveSubChannels", "(", "$", "channelIds", ")", "{", "$", "subChannelIds", "=", "[", "]", ";", "foreach", "(", "$", "channelIds", "as", "$", "channelId", ")", "{", "$", "subChannels", "=", "$", "this", "->", "getChannelList", "(", ")", "->", "getChildren", "(", "$", "channelId", ")", ";", "$", "subChannelIds", "=", "array_merge", "(", "$", "subChannelIds", ",", "$", "subChannels", "->", "map", "(", "function", "(", "Channel", "$", "channel", ")", "{", "return", "$", "channel", "->", "getId", "(", ")", ";", "}", ")", "->", "toArray", "(", ")", ")", ";", "}", "return", "empty", "(", "$", "subChannelIds", ")", "?", "$", "channelIds", ":", "array_merge", "(", "$", "channelIds", ",", "$", "this", "->", "getChannelIdsInclusiveSubChannels", "(", "$", "subChannelIds", ")", ")", ";", "}" ]
Returns an array containing all channel IDs inclusive sub channels. @param $channelIds @return array
[ "Returns", "an", "array", "containing", "all", "channel", "IDs", "inclusive", "sub", "channels", "." ]
84e6510fa0fb71cfbb42ea9f23775f681c266fac
https://github.com/MovingImage24/VM6ApiClient/blob/84e6510fa0fb71cfbb42ea9f23775f681c266fac/lib/ApiClient/AbstractApiClient.php#L74-L88
train
chilimatic/chilimatic-framework
lib/http/Request.php
Request.init
public function init($param) { if (empty($param)) return false; $this->header = ''; $param_list = new ParamList(); foreach ($param as $key => $value) { if (property_exists($this, $key)) $this->$key = $value; elseif (property_exists($param_list, strtolower(str_replace('-', '_', $key)))) { if (is_string($value)) { $this->header[] = new SingleParam($key, $value); } elseif (is_array($value)) { $this->header[] = new MultiParam($key, $value); } } } return true; }
php
public function init($param) { if (empty($param)) return false; $this->header = ''; $param_list = new ParamList(); foreach ($param as $key => $value) { if (property_exists($this, $key)) $this->$key = $value; elseif (property_exists($param_list, strtolower(str_replace('-', '_', $key)))) { if (is_string($value)) { $this->header[] = new SingleParam($key, $value); } elseif (is_array($value)) { $this->header[] = new MultiParam($key, $value); } } } return true; }
[ "public", "function", "init", "(", "$", "param", ")", "{", "if", "(", "empty", "(", "$", "param", ")", ")", "return", "false", ";", "$", "this", "->", "header", "=", "''", ";", "$", "param_list", "=", "new", "ParamList", "(", ")", ";", "foreach", "(", "$", "param", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "$", "key", ")", ")", "$", "this", "->", "$", "key", "=", "$", "value", ";", "elseif", "(", "property_exists", "(", "$", "param_list", ",", "strtolower", "(", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "key", ")", ")", ")", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "this", "->", "header", "[", "]", "=", "new", "SingleParam", "(", "$", "key", ",", "$", "value", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "this", "->", "header", "[", "]", "=", "new", "MultiParam", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}", "}", "return", "true", ";", "}" ]
set the parameters @param $param @return bool
[ "set", "the", "parameters" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/http/Request.php#L124-L146
train
acacha/forge-publish
src/Console/Commands/Traits/ItFetchesSites.php
ItFetchesSites.getSiteByName
protected function getSiteByName($sites, $site_name) { $site_found = collect($sites)->filter(function ($site) use ($site_name) { return $site->name === $site_name; })->first(); if ($site_found) { return $site_found; } return null; }
php
protected function getSiteByName($sites, $site_name) { $site_found = collect($sites)->filter(function ($site) use ($site_name) { return $site->name === $site_name; })->first(); if ($site_found) { return $site_found; } return null; }
[ "protected", "function", "getSiteByName", "(", "$", "sites", ",", "$", "site_name", ")", "{", "$", "site_found", "=", "collect", "(", "$", "sites", ")", "->", "filter", "(", "function", "(", "$", "site", ")", "use", "(", "$", "site_name", ")", "{", "return", "$", "site", "->", "name", "===", "$", "site_name", ";", "}", ")", "->", "first", "(", ")", ";", "if", "(", "$", "site_found", ")", "{", "return", "$", "site_found", ";", "}", "return", "null", ";", "}" ]
Get forge site from sites by name. @param $sites @param $site_id @return mixed
[ "Get", "forge", "site", "from", "sites", "by", "name", "." ]
010779e3d2297c763b82dc3fbde992edffb3a6c6
https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/Traits/ItFetchesSites.php#L40-L50
train
acacha/forge-publish
src/Console/Commands/Traits/ItFetchesSites.php
ItFetchesSites.getSite
protected function getSite($sites, $site_id) { $site_found = collect($sites)->filter(function ($site) use ($site_id) { return $site->id === $site_id; })->first(); if ($site_found) { return $site_found; } return null; }
php
protected function getSite($sites, $site_id) { $site_found = collect($sites)->filter(function ($site) use ($site_id) { return $site->id === $site_id; })->first(); if ($site_found) { return $site_found; } return null; }
[ "protected", "function", "getSite", "(", "$", "sites", ",", "$", "site_id", ")", "{", "$", "site_found", "=", "collect", "(", "$", "sites", ")", "->", "filter", "(", "function", "(", "$", "site", ")", "use", "(", "$", "site_id", ")", "{", "return", "$", "site", "->", "id", "===", "$", "site_id", ";", "}", ")", "->", "first", "(", ")", ";", "if", "(", "$", "site_found", ")", "{", "return", "$", "site_found", ";", "}", "return", "null", ";", "}" ]
Get forge site from sites. @param $sites @param $site_id @return mixed
[ "Get", "forge", "site", "from", "sites", "." ]
010779e3d2297c763b82dc3fbde992edffb3a6c6
https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/Traits/ItFetchesSites.php#L59-L69
train
acacha/forge-publish
src/Console/Commands/Traits/ItFetchesSites.php
ItFetchesSites.getSiteName
protected function getSiteName($sites, $site_id) { if ($site = $this->getSite($sites, $site_id)) { return $site->name; } return null; }
php
protected function getSiteName($sites, $site_id) { if ($site = $this->getSite($sites, $site_id)) { return $site->name; } return null; }
[ "protected", "function", "getSiteName", "(", "$", "sites", ",", "$", "site_id", ")", "{", "if", "(", "$", "site", "=", "$", "this", "->", "getSite", "(", "$", "sites", ",", "$", "site_id", ")", ")", "{", "return", "$", "site", "->", "name", ";", "}", "return", "null", ";", "}" ]
Get forge site name from site id. @param $sites @param $site_id @return mixed
[ "Get", "forge", "site", "name", "from", "site", "id", "." ]
010779e3d2297c763b82dc3fbde992edffb3a6c6
https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/Traits/ItFetchesSites.php#L78-L84
train
acacha/forge-publish
src/Console/Commands/Traits/ItFetchesSites.php
ItFetchesSites.getSiteId
protected function getSiteId($sites, $site_name) { if ($site = $this->getSiteByName($sites, $site_name)) { return $site->id; } return null; }
php
protected function getSiteId($sites, $site_name) { if ($site = $this->getSiteByName($sites, $site_name)) { return $site->id; } return null; }
[ "protected", "function", "getSiteId", "(", "$", "sites", ",", "$", "site_name", ")", "{", "if", "(", "$", "site", "=", "$", "this", "->", "getSiteByName", "(", "$", "sites", ",", "$", "site_name", ")", ")", "{", "return", "$", "site", "->", "id", ";", "}", "return", "null", ";", "}" ]
Get forge site id from site name. @param $sites @param $site_name @return mixed
[ "Get", "forge", "site", "id", "from", "site", "name", "." ]
010779e3d2297c763b82dc3fbde992edffb3a6c6
https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/Traits/ItFetchesSites.php#L93-L99
train
RadialCorp/magento-core
src/app/code/community/Radial/Core/Helper/Quote/Item.php
Radial_Core_Helper_Quote_Item.isItemInventoried
public function isItemInventoried(Mage_Sales_Model_Quote_Item $item) { // never consider a child product as inventoried, allow the parent deal // with inventory and let the child not need to worry about it as the parent // will be the item to keep track of qty being ordered. // Both checks needed as child items will not have a parent item id prior // to being saved and a parent item prior to being added to the parent (e.g. // immediately after being loaded from the DB). if ($item->getParentItemId() || $item->getParentItem()) { return false; } // when dealing with parent items, if any child of the product is managed // stock, consider the entire item as managed stock - allows for the parent // config product in the quote to deal with inventory while allowing child // products to not care individually if ($item->getHasChildren()) { foreach ($item->getChildren() as $childItem) { $childStock = $childItem->getProduct()->getStockItem(); if ($this->isManagedStock($childStock)) { // This Parent is inventoried. Child's ROM setting is 'No backorders', and Manage Stock check hasn't been manually overridden return true; } } // if none of the children were managed stock, the parent is not inventoried return false; } return $this->isManagedStock($item->getProduct()->getStockItem()); }
php
public function isItemInventoried(Mage_Sales_Model_Quote_Item $item) { // never consider a child product as inventoried, allow the parent deal // with inventory and let the child not need to worry about it as the parent // will be the item to keep track of qty being ordered. // Both checks needed as child items will not have a parent item id prior // to being saved and a parent item prior to being added to the parent (e.g. // immediately after being loaded from the DB). if ($item->getParentItemId() || $item->getParentItem()) { return false; } // when dealing with parent items, if any child of the product is managed // stock, consider the entire item as managed stock - allows for the parent // config product in the quote to deal with inventory while allowing child // products to not care individually if ($item->getHasChildren()) { foreach ($item->getChildren() as $childItem) { $childStock = $childItem->getProduct()->getStockItem(); if ($this->isManagedStock($childStock)) { // This Parent is inventoried. Child's ROM setting is 'No backorders', and Manage Stock check hasn't been manually overridden return true; } } // if none of the children were managed stock, the parent is not inventoried return false; } return $this->isManagedStock($item->getProduct()->getStockItem()); }
[ "public", "function", "isItemInventoried", "(", "Mage_Sales_Model_Quote_Item", "$", "item", ")", "{", "// never consider a child product as inventoried, allow the parent deal", "// with inventory and let the child not need to worry about it as the parent", "// will be the item to keep track of qty being ordered.", "// Both checks needed as child items will not have a parent item id prior", "// to being saved and a parent item prior to being added to the parent (e.g.", "// immediately after being loaded from the DB).", "if", "(", "$", "item", "->", "getParentItemId", "(", ")", "||", "$", "item", "->", "getParentItem", "(", ")", ")", "{", "return", "false", ";", "}", "// when dealing with parent items, if any child of the product is managed", "// stock, consider the entire item as managed stock - allows for the parent", "// config product in the quote to deal with inventory while allowing child", "// products to not care individually", "if", "(", "$", "item", "->", "getHasChildren", "(", ")", ")", "{", "foreach", "(", "$", "item", "->", "getChildren", "(", ")", "as", "$", "childItem", ")", "{", "$", "childStock", "=", "$", "childItem", "->", "getProduct", "(", ")", "->", "getStockItem", "(", ")", ";", "if", "(", "$", "this", "->", "isManagedStock", "(", "$", "childStock", ")", ")", "{", "// This Parent is inventoried. Child's ROM setting is 'No backorders', and Manage Stock check hasn't been manually overridden", "return", "true", ";", "}", "}", "// if none of the children were managed stock, the parent is not inventoried", "return", "false", ";", "}", "return", "$", "this", "->", "isManagedStock", "(", "$", "item", "->", "getProduct", "(", ")", "->", "getStockItem", "(", ")", ")", ";", "}" ]
Test if the item needs to have its quantity checked for available inventory. @param Mage_Sales_Model_Quote_Item $item The item to check @return bool True if inventory is managed, false if not
[ "Test", "if", "the", "item", "needs", "to", "have", "its", "quantity", "checked", "for", "available", "inventory", "." ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Helper/Quote/Item.php#L32-L59
train
RadialCorp/magento-core
src/app/code/community/Radial/Core/Helper/Quote/Item.php
Radial_Core_Helper_Quote_Item.isManagedStock
protected function isManagedStock(Mage_CatalogInventory_Model_Stock_Item $stock) { return ( ($this->_config->isBackorderable || (int) $stock->getBackorders() === Mage_CatalogInventory_Model_Stock::BACKORDERS_NO) && $stock->getManageStock() > 0 ); }
php
protected function isManagedStock(Mage_CatalogInventory_Model_Stock_Item $stock) { return ( ($this->_config->isBackorderable || (int) $stock->getBackorders() === Mage_CatalogInventory_Model_Stock::BACKORDERS_NO) && $stock->getManageStock() > 0 ); }
[ "protected", "function", "isManagedStock", "(", "Mage_CatalogInventory_Model_Stock_Item", "$", "stock", ")", "{", "return", "(", "(", "$", "this", "->", "_config", "->", "isBackorderable", "||", "(", "int", ")", "$", "stock", "->", "getBackorders", "(", ")", "===", "Mage_CatalogInventory_Model_Stock", "::", "BACKORDERS_NO", ")", "&&", "$", "stock", "->", "getManageStock", "(", ")", ">", "0", ")", ";", "}" ]
If the inventory configuration allow order item to be backorderable simply check if the Manage stock for the item is greater than zero. Otherwise, if the inventory configuration do not allow order items to be backorderable, then ensure the item is not backorder and has manage stock. @param Mage_CatalogInventory_Model_Stock_Item @return bool
[ "If", "the", "inventory", "configuration", "allow", "order", "item", "to", "be", "backorderable", "simply", "check", "if", "the", "Manage", "stock", "for", "the", "item", "is", "greater", "than", "zero", ".", "Otherwise", "if", "the", "inventory", "configuration", "do", "not", "allow", "order", "items", "to", "be", "backorderable", "then", "ensure", "the", "item", "is", "not", "backorder", "and", "has", "manage", "stock", "." ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Helper/Quote/Item.php#L70-L76
train
silvercommerce/contact-admin
src/model/Contact.php
Contact.getTagsList
public function getTagsList() { $return = ""; $tags = $this->Tags()->column("Title"); $this->extend("updateTagsList", $tags); return implode( $this->config()->list_seperator, $tags ); }
php
public function getTagsList() { $return = ""; $tags = $this->Tags()->column("Title"); $this->extend("updateTagsList", $tags); return implode( $this->config()->list_seperator, $tags ); }
[ "public", "function", "getTagsList", "(", ")", "{", "$", "return", "=", "\"\"", ";", "$", "tags", "=", "$", "this", "->", "Tags", "(", ")", "->", "column", "(", "\"Title\"", ")", ";", "$", "this", "->", "extend", "(", "\"updateTagsList\"", ",", "$", "tags", ")", ";", "return", "implode", "(", "$", "this", "->", "config", "(", ")", "->", "list_seperator", ",", "$", "tags", ")", ";", "}" ]
Generate as string of tag titles seperated by a comma @return string
[ "Generate", "as", "string", "of", "tag", "titles", "seperated", "by", "a", "comma" ]
32cbc2ef2589f93f9dd1796e5db2f11ad15d888c
https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/Contact.php#L243-L254
train
silvercommerce/contact-admin
src/model/Contact.php
Contact.getListsList
public function getListsList() { $return = ""; $list = $this->Lists()->column("Title"); $this->extend("updateListsList", $tags); return implode( $this->config()->list_seperator, $list ); }
php
public function getListsList() { $return = ""; $list = $this->Lists()->column("Title"); $this->extend("updateListsList", $tags); return implode( $this->config()->list_seperator, $list ); }
[ "public", "function", "getListsList", "(", ")", "{", "$", "return", "=", "\"\"", ";", "$", "list", "=", "$", "this", "->", "Lists", "(", ")", "->", "column", "(", "\"Title\"", ")", ";", "$", "this", "->", "extend", "(", "\"updateListsList\"", ",", "$", "tags", ")", ";", "return", "implode", "(", "$", "this", "->", "config", "(", ")", "->", "list_seperator", ",", "$", "list", ")", ";", "}" ]
Generate as string of list titles seperated by a comma @return string
[ "Generate", "as", "string", "of", "list", "titles", "seperated", "by", "a", "comma" ]
32cbc2ef2589f93f9dd1796e5db2f11ad15d888c
https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/Contact.php#L261-L272
train
silvercommerce/contact-admin
src/model/Contact.php
Contact.onBeforeDelete
public function onBeforeDelete() { parent::onBeforeDelete(); // Delete all locations attached to this order foreach ($this->Locations() as $item) { $item->delete(); } // Delete all notes attached to this order foreach ($this->Notes() as $item) { $item->delete(); } }
php
public function onBeforeDelete() { parent::onBeforeDelete(); // Delete all locations attached to this order foreach ($this->Locations() as $item) { $item->delete(); } // Delete all notes attached to this order foreach ($this->Notes() as $item) { $item->delete(); } }
[ "public", "function", "onBeforeDelete", "(", ")", "{", "parent", "::", "onBeforeDelete", "(", ")", ";", "// Delete all locations attached to this order", "foreach", "(", "$", "this", "->", "Locations", "(", ")", "as", "$", "item", ")", "{", "$", "item", "->", "delete", "(", ")", ";", "}", "// Delete all notes attached to this order", "foreach", "(", "$", "this", "->", "Notes", "(", ")", "as", "$", "item", ")", "{", "$", "item", "->", "delete", "(", ")", ";", "}", "}" ]
Cleanup DB on removal
[ "Cleanup", "DB", "on", "removal" ]
32cbc2ef2589f93f9dd1796e5db2f11ad15d888c
https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/Contact.php#L513-L526
train
nyeholt/silverstripe-performant
code/services/SiteDataService.php
SiteDataService.getPrivateNodes
protected function getPrivateNodes() { if (!Member::currentUserID()) { return array(); } $groups = Member::currentUser()->Groups()->column(); if (!count($groups)) { return $groups; } $fields = $this->queryFields(); $query = new SQLQuery($fields, '"'.$this->baseClass.'"'); $query = $query->setOrderBy($this->itemSort); $query->addWhere('"CanViewType" IN (\'OnlyTheseUsers\')'); if (Permission::check('ADMIN')) { // don't need to restrict the canView by anything } else { $query->addInnerJoin('SiteTree_ViewerGroups', '"SiteTree_ViewerGroups"."SiteTreeID" = "SiteTree"."ID"'); $query->addWhere('"SiteTree_ViewerGroups"."GroupID" IN (' . implode(',', $groups) . ')'); } $this->adjustPrivateNodeQuery($query); $this->adjustForVersioned($query); $sql = $query->sql(); $results = $query->execute(); return $results; }
php
protected function getPrivateNodes() { if (!Member::currentUserID()) { return array(); } $groups = Member::currentUser()->Groups()->column(); if (!count($groups)) { return $groups; } $fields = $this->queryFields(); $query = new SQLQuery($fields, '"'.$this->baseClass.'"'); $query = $query->setOrderBy($this->itemSort); $query->addWhere('"CanViewType" IN (\'OnlyTheseUsers\')'); if (Permission::check('ADMIN')) { // don't need to restrict the canView by anything } else { $query->addInnerJoin('SiteTree_ViewerGroups', '"SiteTree_ViewerGroups"."SiteTreeID" = "SiteTree"."ID"'); $query->addWhere('"SiteTree_ViewerGroups"."GroupID" IN (' . implode(',', $groups) . ')'); } $this->adjustPrivateNodeQuery($query); $this->adjustForVersioned($query); $sql = $query->sql(); $results = $query->execute(); return $results; }
[ "protected", "function", "getPrivateNodes", "(", ")", "{", "if", "(", "!", "Member", "::", "currentUserID", "(", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "groups", "=", "Member", "::", "currentUser", "(", ")", "->", "Groups", "(", ")", "->", "column", "(", ")", ";", "if", "(", "!", "count", "(", "$", "groups", ")", ")", "{", "return", "$", "groups", ";", "}", "$", "fields", "=", "$", "this", "->", "queryFields", "(", ")", ";", "$", "query", "=", "new", "SQLQuery", "(", "$", "fields", ",", "'\"'", ".", "$", "this", "->", "baseClass", ".", "'\"'", ")", ";", "$", "query", "=", "$", "query", "->", "setOrderBy", "(", "$", "this", "->", "itemSort", ")", ";", "$", "query", "->", "addWhere", "(", "'\"CanViewType\" IN (\\'OnlyTheseUsers\\')'", ")", ";", "if", "(", "Permission", "::", "check", "(", "'ADMIN'", ")", ")", "{", "// don't need to restrict the canView by anything", "}", "else", "{", "$", "query", "->", "addInnerJoin", "(", "'SiteTree_ViewerGroups'", ",", "'\"SiteTree_ViewerGroups\".\"SiteTreeID\" = \"SiteTree\".\"ID\"'", ")", ";", "$", "query", "->", "addWhere", "(", "'\"SiteTree_ViewerGroups\".\"GroupID\" IN ('", ".", "implode", "(", "','", ",", "$", "groups", ")", ".", "')'", ")", ";", "}", "$", "this", "->", "adjustPrivateNodeQuery", "(", "$", "query", ")", ";", "$", "this", "->", "adjustForVersioned", "(", "$", "query", ")", ";", "$", "sql", "=", "$", "query", "->", "sql", "(", ")", ";", "$", "results", "=", "$", "query", "->", "execute", "(", ")", ";", "return", "$", "results", ";", "}" ]
Get private nodes, assuming SilverStripe's default perm structure @return SS_Query
[ "Get", "private", "nodes", "assuming", "SilverStripe", "s", "default", "perm", "structure" ]
2c9d2570ddf4a43ced38487184da4de453a4863c
https://github.com/nyeholt/silverstripe-performant/blob/2c9d2570ddf4a43ced38487184da4de453a4863c/code/services/SiteDataService.php#L158-L185
train
nyeholt/silverstripe-performant
code/services/SiteDataService.php
SiteDataService.createMenuNode
public function createMenuNode($data) { $cls = $this->itemClass; $node = $cls::create($data, $this); $this->items[$node->ID] = $node; return $node; }
php
public function createMenuNode($data) { $cls = $this->itemClass; $node = $cls::create($data, $this); $this->items[$node->ID] = $node; return $node; }
[ "public", "function", "createMenuNode", "(", "$", "data", ")", "{", "$", "cls", "=", "$", "this", "->", "itemClass", ";", "$", "node", "=", "$", "cls", "::", "create", "(", "$", "data", ",", "$", "this", ")", ";", "$", "this", "->", "items", "[", "$", "node", "->", "ID", "]", "=", "$", "node", ";", "return", "$", "node", ";", "}" ]
Creates a menu item from an array of data @param array $data @returns MenuItem
[ "Creates", "a", "menu", "item", "from", "an", "array", "of", "data" ]
2c9d2570ddf4a43ced38487184da4de453a4863c
https://github.com/nyeholt/silverstripe-performant/blob/2c9d2570ddf4a43ced38487184da4de453a4863c/code/services/SiteDataService.php#L235-L240
train
airbornfoxx/commandcenter
src/Flyingfoxx/CommandCenter/MainCommandTranslator.php
MainCommandTranslator.toHandler
public function toHandler($command) { $class = get_class($command); $offset = ($this->positionAt('Command', $class)) ?: $this->positionAt('Request', $class); $handlerClass = substr_replace($class, 'Handler', $offset); if (!class_exists($handlerClass)) { $message = "Command handler [$handlerClass] does not exist."; throw new HandlerNotRegisteredException($message); } return $handlerClass; }
php
public function toHandler($command) { $class = get_class($command); $offset = ($this->positionAt('Command', $class)) ?: $this->positionAt('Request', $class); $handlerClass = substr_replace($class, 'Handler', $offset); if (!class_exists($handlerClass)) { $message = "Command handler [$handlerClass] does not exist."; throw new HandlerNotRegisteredException($message); } return $handlerClass; }
[ "public", "function", "toHandler", "(", "$", "command", ")", "{", "$", "class", "=", "get_class", "(", "$", "command", ")", ";", "$", "offset", "=", "(", "$", "this", "->", "positionAt", "(", "'Command'", ",", "$", "class", ")", ")", "?", ":", "$", "this", "->", "positionAt", "(", "'Request'", ",", "$", "class", ")", ";", "$", "handlerClass", "=", "substr_replace", "(", "$", "class", ",", "'Handler'", ",", "$", "offset", ")", ";", "if", "(", "!", "class_exists", "(", "$", "handlerClass", ")", ")", "{", "$", "message", "=", "\"Command handler [$handlerClass] does not exist.\"", ";", "throw", "new", "HandlerNotRegisteredException", "(", "$", "message", ")", ";", "}", "return", "$", "handlerClass", ";", "}" ]
Translate a command to its respective handler. @param $command @return mixed @throws HandlerNotRegisteredException
[ "Translate", "a", "command", "to", "its", "respective", "handler", "." ]
ee4f8d0981c69f8cd3410793988def4d809fdaa6
https://github.com/airbornfoxx/commandcenter/blob/ee4f8d0981c69f8cd3410793988def4d809fdaa6/src/Flyingfoxx/CommandCenter/MainCommandTranslator.php#L19-L31
train
airbornfoxx/commandcenter
src/Flyingfoxx/CommandCenter/MainCommandTranslator.php
MainCommandTranslator.toValidator
public function toValidator($command) { $class = get_class($command); $offset = ($this->positionAt('Command', $class)) ?: $this->positionAt('Request', $class); return substr_replace($class, 'Validator', $offset); }
php
public function toValidator($command) { $class = get_class($command); $offset = ($this->positionAt('Command', $class)) ?: $this->positionAt('Request', $class); return substr_replace($class, 'Validator', $offset); }
[ "public", "function", "toValidator", "(", "$", "command", ")", "{", "$", "class", "=", "get_class", "(", "$", "command", ")", ";", "$", "offset", "=", "(", "$", "this", "->", "positionAt", "(", "'Command'", ",", "$", "class", ")", ")", "?", ":", "$", "this", "->", "positionAt", "(", "'Request'", ",", "$", "class", ")", ";", "return", "substr_replace", "(", "$", "class", ",", "'Validator'", ",", "$", "offset", ")", ";", "}" ]
Translate a command to its respective validator. @param $command @return mixed
[ "Translate", "a", "command", "to", "its", "respective", "validator", "." ]
ee4f8d0981c69f8cd3410793988def4d809fdaa6
https://github.com/airbornfoxx/commandcenter/blob/ee4f8d0981c69f8cd3410793988def4d809fdaa6/src/Flyingfoxx/CommandCenter/MainCommandTranslator.php#L39-L45
train
antaresproject/translations
src/Http/Breadcrumb/Breadcrumb.php
Breadcrumb.onTranslationList
public function onTranslationList() { $this->breadcrumbs->register('translations', function($breadcrumbs) { $breadcrumbs->push('Translations', handles('antares::translations/index/' . area())); }); $this->shareOnView('translations'); }
php
public function onTranslationList() { $this->breadcrumbs->register('translations', function($breadcrumbs) { $breadcrumbs->push('Translations', handles('antares::translations/index/' . area())); }); $this->shareOnView('translations'); }
[ "public", "function", "onTranslationList", "(", ")", "{", "$", "this", "->", "breadcrumbs", "->", "register", "(", "'translations'", ",", "function", "(", "$", "breadcrumbs", ")", "{", "$", "breadcrumbs", "->", "push", "(", "'Translations'", ",", "handles", "(", "'antares::translations/index/'", ".", "area", "(", ")", ")", ")", ";", "}", ")", ";", "$", "this", "->", "shareOnView", "(", "'translations'", ")", ";", "}" ]
on translations list
[ "on", "translations", "list" ]
63097aeb97f18c5aeeef7dcf15f0c67959951685
https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Http/Breadcrumb/Breadcrumb.php#L33-L40
train
antaresproject/translations
src/Http/Breadcrumb/Breadcrumb.php
Breadcrumb.onLanguageAdd
public function onLanguageAdd() { $this->onTranslationList(); $this->breadcrumbs->register('languages', function($breadcrumbs) { $breadcrumbs->parent('translations'); $breadcrumbs->push('Languages', handles('antares::translations/languages/index')); }); $this->breadcrumbs->register('language-add', function($breadcrumbs) { $breadcrumbs->parent('languages'); $breadcrumbs->push('Language add'); }); $this->shareOnView('language-add'); }
php
public function onLanguageAdd() { $this->onTranslationList(); $this->breadcrumbs->register('languages', function($breadcrumbs) { $breadcrumbs->parent('translations'); $breadcrumbs->push('Languages', handles('antares::translations/languages/index')); }); $this->breadcrumbs->register('language-add', function($breadcrumbs) { $breadcrumbs->parent('languages'); $breadcrumbs->push('Language add'); }); $this->shareOnView('language-add'); }
[ "public", "function", "onLanguageAdd", "(", ")", "{", "$", "this", "->", "onTranslationList", "(", ")", ";", "$", "this", "->", "breadcrumbs", "->", "register", "(", "'languages'", ",", "function", "(", "$", "breadcrumbs", ")", "{", "$", "breadcrumbs", "->", "parent", "(", "'translations'", ")", ";", "$", "breadcrumbs", "->", "push", "(", "'Languages'", ",", "handles", "(", "'antares::translations/languages/index'", ")", ")", ";", "}", ")", ";", "$", "this", "->", "breadcrumbs", "->", "register", "(", "'language-add'", ",", "function", "(", "$", "breadcrumbs", ")", "{", "$", "breadcrumbs", "->", "parent", "(", "'languages'", ")", ";", "$", "breadcrumbs", "->", "push", "(", "'Language add'", ")", ";", "}", ")", ";", "$", "this", "->", "shareOnView", "(", "'language-add'", ")", ";", "}" ]
on language add
[ "on", "language", "add" ]
63097aeb97f18c5aeeef7dcf15f0c67959951685
https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Http/Breadcrumb/Breadcrumb.php#L45-L57
train
antaresproject/translations
src/Http/Breadcrumb/Breadcrumb.php
Breadcrumb.onImportTranslations
public function onImportTranslations() { $this->onTranslationList(); $this->breadcrumbs->register('translations-import', function($breadcrumbs) { $breadcrumbs->parent('translations'); $breadcrumbs->push('Import translations'); }); $this->shareOnView('translations-import'); }
php
public function onImportTranslations() { $this->onTranslationList(); $this->breadcrumbs->register('translations-import', function($breadcrumbs) { $breadcrumbs->parent('translations'); $breadcrumbs->push('Import translations'); }); $this->shareOnView('translations-import'); }
[ "public", "function", "onImportTranslations", "(", ")", "{", "$", "this", "->", "onTranslationList", "(", ")", ";", "$", "this", "->", "breadcrumbs", "->", "register", "(", "'translations-import'", ",", "function", "(", "$", "breadcrumbs", ")", "{", "$", "breadcrumbs", "->", "parent", "(", "'translations'", ")", ";", "$", "breadcrumbs", "->", "push", "(", "'Import translations'", ")", ";", "}", ")", ";", "$", "this", "->", "shareOnView", "(", "'translations-import'", ")", ";", "}" ]
on import translations
[ "on", "import", "translations" ]
63097aeb97f18c5aeeef7dcf15f0c67959951685
https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Http/Breadcrumb/Breadcrumb.php#L62-L70
train
antaresproject/translations
src/Http/Breadcrumb/Breadcrumb.php
Breadcrumb.onLanguagesList
public function onLanguagesList() { $this->breadcrumbs->register('translations', function($breadcrumbs) { $breadcrumbs->push('Translations', handles('antares::translations/index/' . area()), ['force_link' => true]); }); $this->shareOnView('translations'); }
php
public function onLanguagesList() { $this->breadcrumbs->register('translations', function($breadcrumbs) { $breadcrumbs->push('Translations', handles('antares::translations/index/' . area()), ['force_link' => true]); }); $this->shareOnView('translations'); }
[ "public", "function", "onLanguagesList", "(", ")", "{", "$", "this", "->", "breadcrumbs", "->", "register", "(", "'translations'", ",", "function", "(", "$", "breadcrumbs", ")", "{", "$", "breadcrumbs", "->", "push", "(", "'Translations'", ",", "handles", "(", "'antares::translations/index/'", ".", "area", "(", ")", ")", ",", "[", "'force_link'", "=>", "true", "]", ")", ";", "}", ")", ";", "$", "this", "->", "shareOnView", "(", "'translations'", ")", ";", "}" ]
On languages list
[ "On", "languages", "list" ]
63097aeb97f18c5aeeef7dcf15f0c67959951685
https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Http/Breadcrumb/Breadcrumb.php#L75-L82
train
WellCommerce/CatalogBundle
Controller/Admin/AttributeController.php
AttributeController.ajaxIndexAction
public function ajaxIndexAction(Request $request): Response { if (!$request->isXmlHttpRequest()) { return $this->redirectToAction('index'); } $attributeGroupId = (int)$request->request->get('id'); $attributeGroup = $this->getManager()->findAttributeGroup($attributeGroupId); return $this->jsonResponse([ 'attributes' => $this->getManager()->getRepository()->getAttributeSet($attributeGroup), ]); }
php
public function ajaxIndexAction(Request $request): Response { if (!$request->isXmlHttpRequest()) { return $this->redirectToAction('index'); } $attributeGroupId = (int)$request->request->get('id'); $attributeGroup = $this->getManager()->findAttributeGroup($attributeGroupId); return $this->jsonResponse([ 'attributes' => $this->getManager()->getRepository()->getAttributeSet($attributeGroup), ]); }
[ "public", "function", "ajaxIndexAction", "(", "Request", "$", "request", ")", ":", "Response", "{", "if", "(", "!", "$", "request", "->", "isXmlHttpRequest", "(", ")", ")", "{", "return", "$", "this", "->", "redirectToAction", "(", "'index'", ")", ";", "}", "$", "attributeGroupId", "=", "(", "int", ")", "$", "request", "->", "request", "->", "get", "(", "'id'", ")", ";", "$", "attributeGroup", "=", "$", "this", "->", "getManager", "(", ")", "->", "findAttributeGroup", "(", "$", "attributeGroupId", ")", ";", "return", "$", "this", "->", "jsonResponse", "(", "[", "'attributes'", "=>", "$", "this", "->", "getManager", "(", ")", "->", "getRepository", "(", ")", "->", "getAttributeSet", "(", "$", "attributeGroup", ")", ",", "]", ")", ";", "}" ]
Ajax action for listing attributes in variants editor @param Request $request @return Response
[ "Ajax", "action", "for", "listing", "attributes", "in", "variants", "editor" ]
b1809190298f6c6c04c472dbfd763c1ad0b68630
https://github.com/WellCommerce/CatalogBundle/blob/b1809190298f6c6c04c472dbfd763c1ad0b68630/Controller/Admin/AttributeController.php#L35-L47
train
WellCommerce/CatalogBundle
Controller/Admin/AttributeController.php
AttributeController.ajaxAddAction
public function ajaxAddAction(Request $request): Response { if (!$request->isXmlHttpRequest()) { return $this->redirectToAction('index'); } $attributeName = $request->request->get('name'); $attributeGroupId = (int)$request->request->get('set'); try { $attribute = $this->getManager()->createAttribute($attributeName, $attributeGroupId); return $this->jsonResponse([ 'id' => $attribute->getId(), ]); } catch (\Exception $e) { return $this->jsonResponse([ 'error' => $e->getMessage(), ]); } }
php
public function ajaxAddAction(Request $request): Response { if (!$request->isXmlHttpRequest()) { return $this->redirectToAction('index'); } $attributeName = $request->request->get('name'); $attributeGroupId = (int)$request->request->get('set'); try { $attribute = $this->getManager()->createAttribute($attributeName, $attributeGroupId); return $this->jsonResponse([ 'id' => $attribute->getId(), ]); } catch (\Exception $e) { return $this->jsonResponse([ 'error' => $e->getMessage(), ]); } }
[ "public", "function", "ajaxAddAction", "(", "Request", "$", "request", ")", ":", "Response", "{", "if", "(", "!", "$", "request", "->", "isXmlHttpRequest", "(", ")", ")", "{", "return", "$", "this", "->", "redirectToAction", "(", "'index'", ")", ";", "}", "$", "attributeName", "=", "$", "request", "->", "request", "->", "get", "(", "'name'", ")", ";", "$", "attributeGroupId", "=", "(", "int", ")", "$", "request", "->", "request", "->", "get", "(", "'set'", ")", ";", "try", "{", "$", "attribute", "=", "$", "this", "->", "getManager", "(", ")", "->", "createAttribute", "(", "$", "attributeName", ",", "$", "attributeGroupId", ")", ";", "return", "$", "this", "->", "jsonResponse", "(", "[", "'id'", "=>", "$", "attribute", "->", "getId", "(", ")", ",", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "$", "this", "->", "jsonResponse", "(", "[", "'error'", "=>", "$", "e", "->", "getMessage", "(", ")", ",", "]", ")", ";", "}", "}" ]
Adds new attribute value using ajax request @param Request $request @return Response
[ "Adds", "new", "attribute", "value", "using", "ajax", "request" ]
b1809190298f6c6c04c472dbfd763c1ad0b68630
https://github.com/WellCommerce/CatalogBundle/blob/b1809190298f6c6c04c472dbfd763c1ad0b68630/Controller/Admin/AttributeController.php#L56-L78
train
twistor/flysystem-memory-adapter
src/MemoryAdapter.php
MemoryAdapter.createFromPath
public static function createFromPath($path) { if (!is_dir($path) || !is_readable($path)) { throw new \LogicException(sprintf('%s does not exist or is not readable.', $path)); } return static::createFromFilesystem(new Filesystem(new Local($path))); }
php
public static function createFromPath($path) { if (!is_dir($path) || !is_readable($path)) { throw new \LogicException(sprintf('%s does not exist or is not readable.', $path)); } return static::createFromFilesystem(new Filesystem(new Local($path))); }
[ "public", "static", "function", "createFromPath", "(", "$", "path", ")", "{", "if", "(", "!", "is_dir", "(", "$", "path", ")", "||", "!", "is_readable", "(", "$", "path", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'%s does not exist or is not readable.'", ",", "$", "path", ")", ")", ";", "}", "return", "static", "::", "createFromFilesystem", "(", "new", "Filesystem", "(", "new", "Local", "(", "$", "path", ")", ")", ")", ";", "}" ]
Creates a Memory adapter from a filesystem folder. @param string $path The path to the folder. @return MemoryAdapter A new memory adapter.
[ "Creates", "a", "Memory", "adapter", "from", "a", "filesystem", "folder", "." ]
614f184d855135c1d55b1a579feabaf577de62b1
https://github.com/twistor/flysystem-memory-adapter/blob/614f184d855135c1d55b1a579feabaf577de62b1/src/MemoryAdapter.php#L37-L44
train
twistor/flysystem-memory-adapter
src/MemoryAdapter.php
MemoryAdapter.createFromFilesystem
public static function createFromFilesystem(FilesystemInterface $filesystem) { $filesystem->addPlugin(new ListWith()); $adapter = new static(); $config = new Config(); foreach ($filesystem->listWith(['timestamp', 'visibility'], '', true) as $meta) { if ($meta['type'] === 'dir') { $adapter->createDir($meta['path'], $config); continue; } $adapter->write($meta['path'], (string) $filesystem->read($meta['path']), $config); $adapter->setVisibility($meta['path'], $meta['visibility']); $adapter->setTimestamp($meta['path'], $meta['timestamp']); } return $adapter; }
php
public static function createFromFilesystem(FilesystemInterface $filesystem) { $filesystem->addPlugin(new ListWith()); $adapter = new static(); $config = new Config(); foreach ($filesystem->listWith(['timestamp', 'visibility'], '', true) as $meta) { if ($meta['type'] === 'dir') { $adapter->createDir($meta['path'], $config); continue; } $adapter->write($meta['path'], (string) $filesystem->read($meta['path']), $config); $adapter->setVisibility($meta['path'], $meta['visibility']); $adapter->setTimestamp($meta['path'], $meta['timestamp']); } return $adapter; }
[ "public", "static", "function", "createFromFilesystem", "(", "FilesystemInterface", "$", "filesystem", ")", "{", "$", "filesystem", "->", "addPlugin", "(", "new", "ListWith", "(", ")", ")", ";", "$", "adapter", "=", "new", "static", "(", ")", ";", "$", "config", "=", "new", "Config", "(", ")", ";", "foreach", "(", "$", "filesystem", "->", "listWith", "(", "[", "'timestamp'", ",", "'visibility'", "]", ",", "''", ",", "true", ")", "as", "$", "meta", ")", "{", "if", "(", "$", "meta", "[", "'type'", "]", "===", "'dir'", ")", "{", "$", "adapter", "->", "createDir", "(", "$", "meta", "[", "'path'", "]", ",", "$", "config", ")", ";", "continue", ";", "}", "$", "adapter", "->", "write", "(", "$", "meta", "[", "'path'", "]", ",", "(", "string", ")", "$", "filesystem", "->", "read", "(", "$", "meta", "[", "'path'", "]", ")", ",", "$", "config", ")", ";", "$", "adapter", "->", "setVisibility", "(", "$", "meta", "[", "'path'", "]", ",", "$", "meta", "[", "'visibility'", "]", ")", ";", "$", "adapter", "->", "setTimestamp", "(", "$", "meta", "[", "'path'", "]", ",", "$", "meta", "[", "'timestamp'", "]", ")", ";", "}", "return", "$", "adapter", ";", "}" ]
Creates a Memory adapter from a Flysystem filesystem. @param FilesystemInterface $filesystem The Flysystem filesystem. @return self A new memory adapter.
[ "Creates", "a", "Memory", "adapter", "from", "a", "Flysystem", "filesystem", "." ]
614f184d855135c1d55b1a579feabaf577de62b1
https://github.com/twistor/flysystem-memory-adapter/blob/614f184d855135c1d55b1a579feabaf577de62b1/src/MemoryAdapter.php#L53-L72
train
twistor/flysystem-memory-adapter
src/MemoryAdapter.php
MemoryAdapter.emptyDirectory
protected function emptyDirectory($directory) { foreach ($this->doListContents($directory, true) as $path) { $this->deletePath($path); } }
php
protected function emptyDirectory($directory) { foreach ($this->doListContents($directory, true) as $path) { $this->deletePath($path); } }
[ "protected", "function", "emptyDirectory", "(", "$", "directory", ")", "{", "foreach", "(", "$", "this", "->", "doListContents", "(", "$", "directory", ",", "true", ")", "as", "$", "path", ")", "{", "$", "this", "->", "deletePath", "(", "$", "path", ")", ";", "}", "}" ]
Empties a directory. @param string $directory
[ "Empties", "a", "directory", "." ]
614f184d855135c1d55b1a579feabaf577de62b1
https://github.com/twistor/flysystem-memory-adapter/blob/614f184d855135c1d55b1a579feabaf577de62b1/src/MemoryAdapter.php#L313-L318
train
twistor/flysystem-memory-adapter
src/MemoryAdapter.php
MemoryAdapter.ensureSubDirs
protected function ensureSubDirs($directory, Config $config = null) { $config = $config ?: new Config(); return $this->createDir(Util::dirname($directory), $config); }
php
protected function ensureSubDirs($directory, Config $config = null) { $config = $config ?: new Config(); return $this->createDir(Util::dirname($directory), $config); }
[ "protected", "function", "ensureSubDirs", "(", "$", "directory", ",", "Config", "$", "config", "=", "null", ")", "{", "$", "config", "=", "$", "config", "?", ":", "new", "Config", "(", ")", ";", "return", "$", "this", "->", "createDir", "(", "Util", "::", "dirname", "(", "$", "directory", ")", ",", "$", "config", ")", ";", "}" ]
Ensures that the sub-directories of a directory exist. @param string $directory The directory. @param Config|null $config Optionl configuration. @return bool True on success, false on failure.
[ "Ensures", "that", "the", "sub", "-", "directories", "of", "a", "directory", "exist", "." ]
614f184d855135c1d55b1a579feabaf577de62b1
https://github.com/twistor/flysystem-memory-adapter/blob/614f184d855135c1d55b1a579feabaf577de62b1/src/MemoryAdapter.php#L328-L333
train
twistor/flysystem-memory-adapter
src/MemoryAdapter.php
MemoryAdapter.getFileKeys
protected function getFileKeys($path, array $keys) { if (!$this->hasFile($path)) { return false; } return $this->getKeys($path, $keys); }
php
protected function getFileKeys($path, array $keys) { if (!$this->hasFile($path)) { return false; } return $this->getKeys($path, $keys); }
[ "protected", "function", "getFileKeys", "(", "$", "path", ",", "array", "$", "keys", ")", "{", "if", "(", "!", "$", "this", "->", "hasFile", "(", "$", "path", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "getKeys", "(", "$", "path", ",", "$", "keys", ")", ";", "}" ]
Returns the keys for a file. @param string $path @param array $keys @return array|false
[ "Returns", "the", "keys", "for", "a", "file", "." ]
614f184d855135c1d55b1a579feabaf577de62b1
https://github.com/twistor/flysystem-memory-adapter/blob/614f184d855135c1d55b1a579feabaf577de62b1/src/MemoryAdapter.php#L343-L350
train
twistor/flysystem-memory-adapter
src/MemoryAdapter.php
MemoryAdapter.getKeys
protected function getKeys($path, array $keys) { if (!$this->has($path)) { return false; } $return = []; foreach ($keys as $key) { if ($key === 'path') { $return[$key] = $path; continue; } $return[$key] = $this->storage[$path][$key]; } return $return; }
php
protected function getKeys($path, array $keys) { if (!$this->has($path)) { return false; } $return = []; foreach ($keys as $key) { if ($key === 'path') { $return[$key] = $path; continue; } $return[$key] = $this->storage[$path][$key]; } return $return; }
[ "protected", "function", "getKeys", "(", "$", "path", ",", "array", "$", "keys", ")", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "path", ")", ")", "{", "return", "false", ";", "}", "$", "return", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "$", "key", "===", "'path'", ")", "{", "$", "return", "[", "$", "key", "]", "=", "$", "path", ";", "continue", ";", "}", "$", "return", "[", "$", "key", "]", "=", "$", "this", "->", "storage", "[", "$", "path", "]", "[", "$", "key", "]", ";", "}", "return", "$", "return", ";", "}" ]
Returns the keys for a path. @param string $path @param array $keys @return array|false
[ "Returns", "the", "keys", "for", "a", "path", "." ]
614f184d855135c1d55b1a579feabaf577de62b1
https://github.com/twistor/flysystem-memory-adapter/blob/614f184d855135c1d55b1a579feabaf577de62b1/src/MemoryAdapter.php#L360-L377
train
ekyna/AdminBundle
Controller/Resource/SortableTrait.php
SortableTrait.moveUpAction
public function moveUpAction(Request $request) { $context = $this->loadContext($request); $resource = $context->getResource(); $this->isGranted('EDIT', $resource); $this->move($resource, -1); return $this->redirectToReferer($this->generateUrl( $this->config->getRoute('list'), $context->getIdentifiers() )); }
php
public function moveUpAction(Request $request) { $context = $this->loadContext($request); $resource = $context->getResource(); $this->isGranted('EDIT', $resource); $this->move($resource, -1); return $this->redirectToReferer($this->generateUrl( $this->config->getRoute('list'), $context->getIdentifiers() )); }
[ "public", "function", "moveUpAction", "(", "Request", "$", "request", ")", "{", "$", "context", "=", "$", "this", "->", "loadContext", "(", "$", "request", ")", ";", "$", "resource", "=", "$", "context", "->", "getResource", "(", ")", ";", "$", "this", "->", "isGranted", "(", "'EDIT'", ",", "$", "resource", ")", ";", "$", "this", "->", "move", "(", "$", "resource", ",", "-", "1", ")", ";", "return", "$", "this", "->", "redirectToReferer", "(", "$", "this", "->", "generateUrl", "(", "$", "this", "->", "config", "->", "getRoute", "(", "'list'", ")", ",", "$", "context", "->", "getIdentifiers", "(", ")", ")", ")", ";", "}" ]
Move up the resource. @param Request $request @return \Symfony\Component\HttpFoundation\Response
[ "Move", "up", "the", "resource", "." ]
3f58e253ae9cf651add7f3d587caec80eaea459a
https://github.com/ekyna/AdminBundle/blob/3f58e253ae9cf651add7f3d587caec80eaea459a/Controller/Resource/SortableTrait.php#L20-L34
train
ekyna/AdminBundle
Controller/Resource/SortableTrait.php
SortableTrait.move
protected function move($resource, $movement) { $resource->setPosition($resource->getPosition() + $movement); // TODO use ResourceManager $event = $this->getOperator()->update($resource); $event->toFlashes($this->getFlashBag()); }
php
protected function move($resource, $movement) { $resource->setPosition($resource->getPosition() + $movement); // TODO use ResourceManager $event = $this->getOperator()->update($resource); $event->toFlashes($this->getFlashBag()); }
[ "protected", "function", "move", "(", "$", "resource", ",", "$", "movement", ")", "{", "$", "resource", "->", "setPosition", "(", "$", "resource", "->", "getPosition", "(", ")", "+", "$", "movement", ")", ";", "// TODO use ResourceManager", "$", "event", "=", "$", "this", "->", "getOperator", "(", ")", "->", "update", "(", "$", "resource", ")", ";", "$", "event", "->", "toFlashes", "(", "$", "this", "->", "getFlashBag", "(", ")", ")", ";", "}" ]
Move the resource. @param $resource @param $movement
[ "Move", "the", "resource", "." ]
3f58e253ae9cf651add7f3d587caec80eaea459a
https://github.com/ekyna/AdminBundle/blob/3f58e253ae9cf651add7f3d587caec80eaea459a/Controller/Resource/SortableTrait.php#L64-L71
train
praxisnetau/silverware-navigation
src/Components/AnchorNavigation.php
AnchorNavigation.getAnchors
public function getAnchors() { $list = ArrayList::create(); if ($page = $this->getCurrentPage(Page::class)) { $html = HTMLValue::create($page->Content); $anchors = $html->query("//*[@id]"); foreach ($anchors as $anchor) { $list->push( ArrayData::create([ 'Link' => $page->Link(sprintf('#%s', $anchor->getAttribute('id'))), 'Text' => $anchor->textContent ]) ); } } return $list; }
php
public function getAnchors() { $list = ArrayList::create(); if ($page = $this->getCurrentPage(Page::class)) { $html = HTMLValue::create($page->Content); $anchors = $html->query("//*[@id]"); foreach ($anchors as $anchor) { $list->push( ArrayData::create([ 'Link' => $page->Link(sprintf('#%s', $anchor->getAttribute('id'))), 'Text' => $anchor->textContent ]) ); } } return $list; }
[ "public", "function", "getAnchors", "(", ")", "{", "$", "list", "=", "ArrayList", "::", "create", "(", ")", ";", "if", "(", "$", "page", "=", "$", "this", "->", "getCurrentPage", "(", "Page", "::", "class", ")", ")", "{", "$", "html", "=", "HTMLValue", "::", "create", "(", "$", "page", "->", "Content", ")", ";", "$", "anchors", "=", "$", "html", "->", "query", "(", "\"//*[@id]\"", ")", ";", "foreach", "(", "$", "anchors", "as", "$", "anchor", ")", "{", "$", "list", "->", "push", "(", "ArrayData", "::", "create", "(", "[", "'Link'", "=>", "$", "page", "->", "Link", "(", "sprintf", "(", "'#%s'", ",", "$", "anchor", "->", "getAttribute", "(", "'id'", ")", ")", ")", ",", "'Text'", "=>", "$", "anchor", "->", "textContent", "]", ")", ")", ";", "}", "}", "return", "$", "list", ";", "}" ]
Answers an array list of anchors identified within the current page content. @return ArrayList
[ "Answers", "an", "array", "list", "of", "anchors", "identified", "within", "the", "current", "page", "content", "." ]
04e6f3003c2871348d5bba7869d4fc273641627e
https://github.com/praxisnetau/silverware-navigation/blob/04e6f3003c2871348d5bba7869d4fc273641627e/src/Components/AnchorNavigation.php#L232-L256
train
phPoirot/Client-OAuth2
src/Assertion/AssertByInternalServer.php
AssertByInternalServer.assertToken
function assertToken($tokenStr) { if (false === $token = $this->_accessTokens->findByIdentifier((string) $tokenStr)) throw new exOAuthAccessDenied; $accessToken = new AccessTokenEntity( new HydrateGetters($token) ); return $accessToken; }
php
function assertToken($tokenStr) { if (false === $token = $this->_accessTokens->findByIdentifier((string) $tokenStr)) throw new exOAuthAccessDenied; $accessToken = new AccessTokenEntity( new HydrateGetters($token) ); return $accessToken; }
[ "function", "assertToken", "(", "$", "tokenStr", ")", "{", "if", "(", "false", "===", "$", "token", "=", "$", "this", "->", "_accessTokens", "->", "findByIdentifier", "(", "(", "string", ")", "$", "tokenStr", ")", ")", "throw", "new", "exOAuthAccessDenied", ";", "$", "accessToken", "=", "new", "AccessTokenEntity", "(", "new", "HydrateGetters", "(", "$", "token", ")", ")", ";", "return", "$", "accessToken", ";", "}" ]
Validate Authorize Token With OAuth Server note: implement grant extension http request @param string $tokenStr @return iAccessTokenEntity @throws exOAuthAccessDenied Access Denied
[ "Validate", "Authorize", "Token", "With", "OAuth", "Server" ]
8745fd54afbbb185669b9e38b1241ecc8ffc7268
https://github.com/phPoirot/Client-OAuth2/blob/8745fd54afbbb185669b9e38b1241ecc8ffc7268/src/Assertion/AssertByInternalServer.php#L42-L52
train
Etenil/assegai
src/assegai/modules/forms/fields/Field.php
Field.getType
function getType() { if($this->_type) { return $this->_type; } else { $myclass = get_class($this); return strtolower(substr($myclass, strrpos($myclass, '\\') + 1, -5)); } }
php
function getType() { if($this->_type) { return $this->_type; } else { $myclass = get_class($this); return strtolower(substr($myclass, strrpos($myclass, '\\') + 1, -5)); } }
[ "function", "getType", "(", ")", "{", "if", "(", "$", "this", "->", "_type", ")", "{", "return", "$", "this", "->", "_type", ";", "}", "else", "{", "$", "myclass", "=", "get_class", "(", "$", "this", ")", ";", "return", "strtolower", "(", "substr", "(", "$", "myclass", ",", "strrpos", "(", "$", "myclass", ",", "'\\\\'", ")", "+", "1", ",", "-", "5", ")", ")", ";", "}", "}" ]
This essentially returns the field's class name without the "Field" part.
[ "This", "essentially", "returns", "the", "field", "s", "class", "name", "without", "the", "Field", "part", "." ]
d43cce1a88f1c332f60dd0a4374b17764852af9e
https://github.com/Etenil/assegai/blob/d43cce1a88f1c332f60dd0a4374b17764852af9e/src/assegai/modules/forms/fields/Field.php#L111-L120
train
schpill/thin
src/Navigation/Page/Uri.php
Zend_Navigation_Page_Uri.setUri
public function setUri($uri) { if (null !== $uri && !is_string($uri)) { require_once 'Zend/Navigation/Exception.php'; throw new Zend_Navigation_Exception( 'Invalid argument: $uri must be a string or null'); } $this->_uri = $uri; return $this; }
php
public function setUri($uri) { if (null !== $uri && !is_string($uri)) { require_once 'Zend/Navigation/Exception.php'; throw new Zend_Navigation_Exception( 'Invalid argument: $uri must be a string or null'); } $this->_uri = $uri; return $this; }
[ "public", "function", "setUri", "(", "$", "uri", ")", "{", "if", "(", "null", "!==", "$", "uri", "&&", "!", "is_string", "(", "$", "uri", ")", ")", "{", "require_once", "'Zend/Navigation/Exception.php'", ";", "throw", "new", "Zend_Navigation_Exception", "(", "'Invalid argument: $uri must be a string or null'", ")", ";", "}", "$", "this", "->", "_uri", "=", "$", "uri", ";", "return", "$", "this", ";", "}" ]
Sets page URI @param string $uri page URI, must a string or null @return Zend_Navigation_Page_Uri fluent interface, returns self @throws Zend_Navigation_Exception if $uri is invalid
[ "Sets", "page", "URI" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Navigation/Page/Uri.php#L53-L63
train
Synapse-Cmf/synapse-cmf
src/Synapse/Page/Bundle/Action/Page/CreateAction.php
CreateAction.resolve
public function resolve() { $this->page ->setName($this->name) ->setOnline(!empty($this->online)) ->setTitle($this->title) ->setMeta(array('title' => $this->title)) ->setPath($this->getFullPath()) ; $this->assertEntityIsValid($this->page, array('Page', 'creation')); $this->fireEvent( PageEvents::PAGE_CREATED, new PageEvent($this->page, $this) ); return $this->page; }
php
public function resolve() { $this->page ->setName($this->name) ->setOnline(!empty($this->online)) ->setTitle($this->title) ->setMeta(array('title' => $this->title)) ->setPath($this->getFullPath()) ; $this->assertEntityIsValid($this->page, array('Page', 'creation')); $this->fireEvent( PageEvents::PAGE_CREATED, new PageEvent($this->page, $this) ); return $this->page; }
[ "public", "function", "resolve", "(", ")", "{", "$", "this", "->", "page", "->", "setName", "(", "$", "this", "->", "name", ")", "->", "setOnline", "(", "!", "empty", "(", "$", "this", "->", "online", ")", ")", "->", "setTitle", "(", "$", "this", "->", "title", ")", "->", "setMeta", "(", "array", "(", "'title'", "=>", "$", "this", "->", "title", ")", ")", "->", "setPath", "(", "$", "this", "->", "getFullPath", "(", ")", ")", ";", "$", "this", "->", "assertEntityIsValid", "(", "$", "this", "->", "page", ",", "array", "(", "'Page'", ",", "'creation'", ")", ")", ";", "$", "this", "->", "fireEvent", "(", "PageEvents", "::", "PAGE_CREATED", ",", "new", "PageEvent", "(", "$", "this", "->", "page", ",", "$", "this", ")", ")", ";", "return", "$", "this", "->", "page", ";", "}" ]
Page creation method. @return Page
[ "Page", "creation", "method", "." ]
d8122a4150a83d5607289724425cf35c56a5e880
https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Page/Bundle/Action/Page/CreateAction.php#L62-L80
train
Synapse-Cmf/synapse-cmf
src/Synapse/Page/Bundle/Action/Page/CreateAction.php
CreateAction.generateFullPath
protected function generateFullPath() { return $this->fullPath = $this->pathGenerator ->generatePath($this->page, $this->path ?: '') ; }
php
protected function generateFullPath() { return $this->fullPath = $this->pathGenerator ->generatePath($this->page, $this->path ?: '') ; }
[ "protected", "function", "generateFullPath", "(", ")", "{", "return", "$", "this", "->", "fullPath", "=", "$", "this", "->", "pathGenerator", "->", "generatePath", "(", "$", "this", "->", "page", ",", "$", "this", "->", "path", "?", ":", "''", ")", ";", "}" ]
Generate page full path. @return string
[ "Generate", "page", "full", "path", "." ]
d8122a4150a83d5607289724425cf35c56a5e880
https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Page/Bundle/Action/Page/CreateAction.php#L136-L141
train
RadialCorp/magento-core
src/app/code/community/Radial/Core/Model/Abstract/Send.php
EbayEnterprise_Order_Model_Abstract_Send._sendRequest
protected function _sendRequest() { $logger = $this->_logger; $logContext = $this->_logContext; $response = null; try { $response = $this->_api ->setRequestBody($this->_request) ->send() ->getResponseBody(); } catch (InvalidPayload $e) { $logMessage = "Invalid payload for {$this->_getPayloadName()}. See exception log for more details."; $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } catch (NetworkError $e) { $logMessage = "Caught a network error sending {$this->_getPayloadName()}. See exception log for more details."; $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } catch (UnsupportedOperation $e) { $logMessage = "{$this->_getPayloadName()} operation is unsupported in the current configuration. See exception log for more details."; $logger->critical($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } catch (UnsupportedHttpAction $e) { $logMessage = "{$this->_getPayloadName()} request is configured with an unsupported HTTP action. See exception log for more details."; $logger->critical($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } catch (Exception $e) { $logMessage = "Encountered unexpected exception sending {$this->_getPayloadName()}. See exception log for more details."; $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } return $response; }
php
protected function _sendRequest() { $logger = $this->_logger; $logContext = $this->_logContext; $response = null; try { $response = $this->_api ->setRequestBody($this->_request) ->send() ->getResponseBody(); } catch (InvalidPayload $e) { $logMessage = "Invalid payload for {$this->_getPayloadName()}. See exception log for more details."; $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } catch (NetworkError $e) { $logMessage = "Caught a network error sending {$this->_getPayloadName()}. See exception log for more details."; $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } catch (UnsupportedOperation $e) { $logMessage = "{$this->_getPayloadName()} operation is unsupported in the current configuration. See exception log for more details."; $logger->critical($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } catch (UnsupportedHttpAction $e) { $logMessage = "{$this->_getPayloadName()} request is configured with an unsupported HTTP action. See exception log for more details."; $logger->critical($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } catch (Exception $e) { $logMessage = "Encountered unexpected exception sending {$this->_getPayloadName()}. See exception log for more details."; $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e)); } return $response; }
[ "protected", "function", "_sendRequest", "(", ")", "{", "$", "logger", "=", "$", "this", "->", "_logger", ";", "$", "logContext", "=", "$", "this", "->", "_logContext", ";", "$", "response", "=", "null", ";", "try", "{", "$", "response", "=", "$", "this", "->", "_api", "->", "setRequestBody", "(", "$", "this", "->", "_request", ")", "->", "send", "(", ")", "->", "getResponseBody", "(", ")", ";", "}", "catch", "(", "InvalidPayload", "$", "e", ")", "{", "$", "logMessage", "=", "\"Invalid payload for {$this->_getPayloadName()}. See exception log for more details.\"", ";", "$", "logger", "->", "warning", "(", "$", "logMessage", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "'exception_message'", "=>", "$", "e", "->", "getMessage", "(", ")", "]", ")", ")", ";", "$", "logger", "->", "logException", "(", "$", "e", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "]", ",", "$", "e", ")", ")", ";", "}", "catch", "(", "NetworkError", "$", "e", ")", "{", "$", "logMessage", "=", "\"Caught a network error sending {$this->_getPayloadName()}. See exception log for more details.\"", ";", "$", "logger", "->", "warning", "(", "$", "logMessage", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "'exception_message'", "=>", "$", "e", "->", "getMessage", "(", ")", "]", ")", ")", ";", "$", "logger", "->", "logException", "(", "$", "e", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "]", ",", "$", "e", ")", ")", ";", "}", "catch", "(", "UnsupportedOperation", "$", "e", ")", "{", "$", "logMessage", "=", "\"{$this->_getPayloadName()} operation is unsupported in the current configuration. See exception log for more details.\"", ";", "$", "logger", "->", "critical", "(", "$", "logMessage", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "'exception_message'", "=>", "$", "e", "->", "getMessage", "(", ")", "]", ")", ")", ";", "$", "logger", "->", "logException", "(", "$", "e", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "]", ",", "$", "e", ")", ")", ";", "}", "catch", "(", "UnsupportedHttpAction", "$", "e", ")", "{", "$", "logMessage", "=", "\"{$this->_getPayloadName()} request is configured with an unsupported HTTP action. See exception log for more details.\"", ";", "$", "logger", "->", "critical", "(", "$", "logMessage", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "'exception_message'", "=>", "$", "e", "->", "getMessage", "(", ")", "]", ")", ")", ";", "$", "logger", "->", "logException", "(", "$", "e", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "]", ",", "$", "e", ")", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "logMessage", "=", "\"Encountered unexpected exception sending {$this->_getPayloadName()}. See exception log for more details.\"", ";", "$", "logger", "->", "warning", "(", "$", "logMessage", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "'exception_message'", "=>", "$", "e", "->", "getMessage", "(", ")", "]", ")", ")", ";", "$", "logger", "->", "logException", "(", "$", "e", ",", "$", "logContext", "->", "getMetaData", "(", "__CLASS__", ",", "[", "]", ",", "$", "e", ")", ")", ";", "}", "return", "$", "response", ";", "}" ]
Sending the payload request and returning the response. @return IPayload | null
[ "Sending", "the", "payload", "request", "and", "returning", "the", "response", "." ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Model/Abstract/Send.php#L119-L152
train
phavour/phavour
Phavour/Application.php
Application.setCacheAdapter
public function setCacheAdapter(AdapterAbstract $adapter) { if ($this->isSetup) { $e = new ApplicationIsAlreadySetupException('You cannot set the cache after calling setup()'); $this->error($e); } $this->cache = $adapter; }
php
public function setCacheAdapter(AdapterAbstract $adapter) { if ($this->isSetup) { $e = new ApplicationIsAlreadySetupException('You cannot set the cache after calling setup()'); $this->error($e); } $this->cache = $adapter; }
[ "public", "function", "setCacheAdapter", "(", "AdapterAbstract", "$", "adapter", ")", "{", "if", "(", "$", "this", "->", "isSetup", ")", "{", "$", "e", "=", "new", "ApplicationIsAlreadySetupException", "(", "'You cannot set the cache after calling setup()'", ")", ";", "$", "this", "->", "error", "(", "$", "e", ")", ";", "}", "$", "this", "->", "cache", "=", "$", "adapter", ";", "}" ]
Set an application level cache adapter. This adapter will be made available to all runnables @param AdapterAbstract $adapter
[ "Set", "an", "application", "level", "cache", "adapter", ".", "This", "adapter", "will", "be", "made", "available", "to", "all", "runnables" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Application.php#L134-L142
train
phavour/phavour
Phavour/Application.php
Application.setup
public function setup() { $this->request = new Request(); $this->response = new Response(); $this->env = new Environment(); $this->mode = $this->env->getMode(); if (!$this->env->isProduction() || $this->cache == null) { $this->cache = new AdapterNull(); } $this->loadPackages(); $this->loadConfig(); // @codeCoverageIgnoreStart if (array_key_exists('ini.set', $this->config)) { foreach ($this->config['ini.set'] as $iniName => $iniValue) { ini_set($iniName, $iniValue); } } // @codeCoverageIgnoreEnd $this->loadRoutes(); $this->isSetup = true; }
php
public function setup() { $this->request = new Request(); $this->response = new Response(); $this->env = new Environment(); $this->mode = $this->env->getMode(); if (!$this->env->isProduction() || $this->cache == null) { $this->cache = new AdapterNull(); } $this->loadPackages(); $this->loadConfig(); // @codeCoverageIgnoreStart if (array_key_exists('ini.set', $this->config)) { foreach ($this->config['ini.set'] as $iniName => $iniValue) { ini_set($iniName, $iniValue); } } // @codeCoverageIgnoreEnd $this->loadRoutes(); $this->isSetup = true; }
[ "public", "function", "setup", "(", ")", "{", "$", "this", "->", "request", "=", "new", "Request", "(", ")", ";", "$", "this", "->", "response", "=", "new", "Response", "(", ")", ";", "$", "this", "->", "env", "=", "new", "Environment", "(", ")", ";", "$", "this", "->", "mode", "=", "$", "this", "->", "env", "->", "getMode", "(", ")", ";", "if", "(", "!", "$", "this", "->", "env", "->", "isProduction", "(", ")", "||", "$", "this", "->", "cache", "==", "null", ")", "{", "$", "this", "->", "cache", "=", "new", "AdapterNull", "(", ")", ";", "}", "$", "this", "->", "loadPackages", "(", ")", ";", "$", "this", "->", "loadConfig", "(", ")", ";", "// @codeCoverageIgnoreStart", "if", "(", "array_key_exists", "(", "'ini.set'", ",", "$", "this", "->", "config", ")", ")", "{", "foreach", "(", "$", "this", "->", "config", "[", "'ini.set'", "]", "as", "$", "iniName", "=>", "$", "iniValue", ")", "{", "ini_set", "(", "$", "iniName", ",", "$", "iniValue", ")", ";", "}", "}", "// @codeCoverageIgnoreEnd", "$", "this", "->", "loadRoutes", "(", ")", ";", "$", "this", "->", "isSetup", "=", "true", ";", "}" ]
Setup the application, assigns all the packages, config, routes
[ "Setup", "the", "application", "assigns", "all", "the", "packages", "config", "routes" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Application.php#L148-L168
train
phavour/phavour
Phavour/Application.php
Application.loadPackages
private function loadPackages() { foreach ($this->packages as $package) { /** @var $package \Phavour\Package */ $this->packagesMetadata[$package->getPackageName()] = array( 'namespace' => $package->getNamespace(), 'route_path' => $package->getRoutePath(), 'config_path' => $package->getConfigPath(), 'package_path' => $package->getPackagePath(), 'package_name' => $package->getPackageName() ); } }
php
private function loadPackages() { foreach ($this->packages as $package) { /** @var $package \Phavour\Package */ $this->packagesMetadata[$package->getPackageName()] = array( 'namespace' => $package->getNamespace(), 'route_path' => $package->getRoutePath(), 'config_path' => $package->getConfigPath(), 'package_path' => $package->getPackagePath(), 'package_name' => $package->getPackageName() ); } }
[ "private", "function", "loadPackages", "(", ")", "{", "foreach", "(", "$", "this", "->", "packages", "as", "$", "package", ")", "{", "/** @var $package \\Phavour\\Package */", "$", "this", "->", "packagesMetadata", "[", "$", "package", "->", "getPackageName", "(", ")", "]", "=", "array", "(", "'namespace'", "=>", "$", "package", "->", "getNamespace", "(", ")", ",", "'route_path'", "=>", "$", "package", "->", "getRoutePath", "(", ")", ",", "'config_path'", "=>", "$", "package", "->", "getConfigPath", "(", ")", ",", "'package_path'", "=>", "$", "package", "->", "getPackagePath", "(", ")", ",", "'package_name'", "=>", "$", "package", "->", "getPackageName", "(", ")", ")", ";", "}", "}" ]
Load the package metadata from the given list
[ "Load", "the", "package", "metadata", "from", "the", "given", "list" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Application.php#L281-L293
train
phavour/phavour
Phavour/Application.php
Application.getRunnable
private function getRunnable($package, $class, $method, $className) { $view = $this->getViewFor($package, $class, $method); $instance = new $className($this->request, $this->response, $view, $this->env, $this->cache, $this->router, $this->config); /* @var $instance Runnable */ $instance->init(); return $instance; }
php
private function getRunnable($package, $class, $method, $className) { $view = $this->getViewFor($package, $class, $method); $instance = new $className($this->request, $this->response, $view, $this->env, $this->cache, $this->router, $this->config); /* @var $instance Runnable */ $instance->init(); return $instance; }
[ "private", "function", "getRunnable", "(", "$", "package", ",", "$", "class", ",", "$", "method", ",", "$", "className", ")", "{", "$", "view", "=", "$", "this", "->", "getViewFor", "(", "$", "package", ",", "$", "class", ",", "$", "method", ")", ";", "$", "instance", "=", "new", "$", "className", "(", "$", "this", "->", "request", ",", "$", "this", "->", "response", ",", "$", "view", ",", "$", "this", "->", "env", ",", "$", "this", "->", "cache", ",", "$", "this", "->", "router", ",", "$", "this", "->", "config", ")", ";", "/* @var $instance Runnable */", "$", "instance", "->", "init", "(", ")", ";", "return", "$", "instance", ";", "}" ]
Get the corresponding runnable for the given parameters @param string $package @param string $class @param string $method @param string $className @return \Phavour\Runnable
[ "Get", "the", "corresponding", "runnable", "for", "the", "given", "parameters" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Application.php#L526-L534
train
phavour/phavour
Phavour/Application.php
Application.getViewFor
private function getViewFor($package, $class, $method) { $view = new View($this, $package, $class, $method); $view->setRouter($this->router); $view->setConfig($this->config); return $view; }
php
private function getViewFor($package, $class, $method) { $view = new View($this, $package, $class, $method); $view->setRouter($this->router); $view->setConfig($this->config); return $view; }
[ "private", "function", "getViewFor", "(", "$", "package", ",", "$", "class", ",", "$", "method", ")", "{", "$", "view", "=", "new", "View", "(", "$", "this", ",", "$", "package", ",", "$", "class", ",", "$", "method", ")", ";", "$", "view", "->", "setRouter", "(", "$", "this", "->", "router", ")", ";", "$", "view", "->", "setConfig", "(", "$", "this", "->", "config", ")", ";", "return", "$", "view", ";", "}" ]
Retrieve an instance of View for a given package, class, method combination @param string $package @param string $class @param string $method @return \Phavour\Runnable\View
[ "Retrieve", "an", "instance", "of", "View", "for", "a", "given", "package", "class", "method", "combination" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Application.php#L543-L550
train
RadialCorp/magento-core
src/app/code/community/Radial/Core/Model/Api.php
Radial_Core_Model_Api.request
public function request( DOMDocument $doc, $xsdName, $uri, $timeout = self::DEFAULT_TIMEOUT, $adapter = self::DEFAULT_ADAPTER, Zend_Http_Client $client = null, $apiKey = null ) { if (!$apiKey) { $apiKey = Mage::helper('radial_core')->getConfigModel()->apiKey; } $xmlStr = $doc->C14N(); $logData = array_merge(['rom_request_body' => $xmlStr], $this->_logAppContext); $logMessage = 'Validating request.'; $this->_logger->debug($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); $this->schemaValidate($doc, $xsdName); $client = $this->_setupClient($client, $apiKey, $uri, $xmlStr, $adapter, $timeout); $logData = array_merge(['rom_request_url' => $uri], $this->_logAppContext); $logMessage = 'Sending request.'; $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); try { $response = $client->request(self::DEFAULT_METHOD); return $this->_processResponse($response, $uri); } catch (Zend_Http_Client_Exception $e) { return $this->_processException($e, $uri); } }
php
public function request( DOMDocument $doc, $xsdName, $uri, $timeout = self::DEFAULT_TIMEOUT, $adapter = self::DEFAULT_ADAPTER, Zend_Http_Client $client = null, $apiKey = null ) { if (!$apiKey) { $apiKey = Mage::helper('radial_core')->getConfigModel()->apiKey; } $xmlStr = $doc->C14N(); $logData = array_merge(['rom_request_body' => $xmlStr], $this->_logAppContext); $logMessage = 'Validating request.'; $this->_logger->debug($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); $this->schemaValidate($doc, $xsdName); $client = $this->_setupClient($client, $apiKey, $uri, $xmlStr, $adapter, $timeout); $logData = array_merge(['rom_request_url' => $uri], $this->_logAppContext); $logMessage = 'Sending request.'; $this->_logger->info($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); try { $response = $client->request(self::DEFAULT_METHOD); return $this->_processResponse($response, $uri); } catch (Zend_Http_Client_Exception $e) { return $this->_processException($e, $uri); } }
[ "public", "function", "request", "(", "DOMDocument", "$", "doc", ",", "$", "xsdName", ",", "$", "uri", ",", "$", "timeout", "=", "self", "::", "DEFAULT_TIMEOUT", ",", "$", "adapter", "=", "self", "::", "DEFAULT_ADAPTER", ",", "Zend_Http_Client", "$", "client", "=", "null", ",", "$", "apiKey", "=", "null", ")", "{", "if", "(", "!", "$", "apiKey", ")", "{", "$", "apiKey", "=", "Mage", "::", "helper", "(", "'radial_core'", ")", "->", "getConfigModel", "(", ")", "->", "apiKey", ";", "}", "$", "xmlStr", "=", "$", "doc", "->", "C14N", "(", ")", ";", "$", "logData", "=", "array_merge", "(", "[", "'rom_request_body'", "=>", "$", "xmlStr", "]", ",", "$", "this", "->", "_logAppContext", ")", ";", "$", "logMessage", "=", "'Validating request.'", ";", "$", "this", "->", "_logger", "->", "debug", "(", "$", "logMessage", ",", "$", "this", "->", "_context", "->", "getMetaData", "(", "__CLASS__", ",", "$", "logData", ")", ")", ";", "$", "this", "->", "schemaValidate", "(", "$", "doc", ",", "$", "xsdName", ")", ";", "$", "client", "=", "$", "this", "->", "_setupClient", "(", "$", "client", ",", "$", "apiKey", ",", "$", "uri", ",", "$", "xmlStr", ",", "$", "adapter", ",", "$", "timeout", ")", ";", "$", "logData", "=", "array_merge", "(", "[", "'rom_request_url'", "=>", "$", "uri", "]", ",", "$", "this", "->", "_logAppContext", ")", ";", "$", "logMessage", "=", "'Sending request.'", ";", "$", "this", "->", "_logger", "->", "info", "(", "$", "logMessage", ",", "$", "this", "->", "_context", "->", "getMetaData", "(", "__CLASS__", ",", "$", "logData", ")", ")", ";", "try", "{", "$", "response", "=", "$", "client", "->", "request", "(", "self", "::", "DEFAULT_METHOD", ")", ";", "return", "$", "this", "->", "_processResponse", "(", "$", "response", ",", "$", "uri", ")", ";", "}", "catch", "(", "Zend_Http_Client_Exception", "$", "e", ")", "{", "return", "$", "this", "->", "_processException", "(", "$", "e", ",", "$", "uri", ")", ";", "}", "}" ]
Call the API. @param DOMDocument $doc The document to send in the request body @param string $xsdName The basename of the xsd file to validate $doc (The dirname is in config.xml) @param string $uri The uri to send the request to @param int $timeout The amount of time in seconds after which the connection is terminated @param string $adapter The classname of a Zend_Http_Client_Adapter @param Zend_Http_Client $client @param string $apiKey Alternate API Key to use @return string The response from the server
[ "Call", "the", "API", "." ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Model/Api.php#L73-L102
train
RadialCorp/magento-core
src/app/code/community/Radial/Core/Model/Api.php
Radial_Core_Model_Api._processResponse
protected function _processResponse(Zend_Http_Response $response, $uri) { $this->_status = $response->getStatus(); $config = $this->_getHandlerConfig($this->_getHandlerKey($response)); $logMethod = isset($config['logger']) ? $config['logger'] : 'debug'; $logData = array_merge(['rom_request_url' => $uri], $this->_logAppContext); $this->_logger->$logMethod('Received response from.', $this->_context->getMetaData(__CLASS__, $logData)); $responseData = $logData; $responseData['rom_response_body'] = $response->asString(); $logMessage = 'Response data.'; $this->_logger->debug($logMessage, $this->_context->getMetaData(__CLASS__, $responseData)); if (!$response->getBody()) { $logMessage = "Received response with no body from {$uri} with status {$this->_status}."; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); } $callbackConfig = isset($config['callback']) ? $config['callback'] : array(); $callbackConfig['parameters'] = array($response); return Mage::helper('radial_core')->invokeCallBack($callbackConfig); }
php
protected function _processResponse(Zend_Http_Response $response, $uri) { $this->_status = $response->getStatus(); $config = $this->_getHandlerConfig($this->_getHandlerKey($response)); $logMethod = isset($config['logger']) ? $config['logger'] : 'debug'; $logData = array_merge(['rom_request_url' => $uri], $this->_logAppContext); $this->_logger->$logMethod('Received response from.', $this->_context->getMetaData(__CLASS__, $logData)); $responseData = $logData; $responseData['rom_response_body'] = $response->asString(); $logMessage = 'Response data.'; $this->_logger->debug($logMessage, $this->_context->getMetaData(__CLASS__, $responseData)); if (!$response->getBody()) { $logMessage = "Received response with no body from {$uri} with status {$this->_status}."; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); } $callbackConfig = isset($config['callback']) ? $config['callback'] : array(); $callbackConfig['parameters'] = array($response); return Mage::helper('radial_core')->invokeCallBack($callbackConfig); }
[ "protected", "function", "_processResponse", "(", "Zend_Http_Response", "$", "response", ",", "$", "uri", ")", "{", "$", "this", "->", "_status", "=", "$", "response", "->", "getStatus", "(", ")", ";", "$", "config", "=", "$", "this", "->", "_getHandlerConfig", "(", "$", "this", "->", "_getHandlerKey", "(", "$", "response", ")", ")", ";", "$", "logMethod", "=", "isset", "(", "$", "config", "[", "'logger'", "]", ")", "?", "$", "config", "[", "'logger'", "]", ":", "'debug'", ";", "$", "logData", "=", "array_merge", "(", "[", "'rom_request_url'", "=>", "$", "uri", "]", ",", "$", "this", "->", "_logAppContext", ")", ";", "$", "this", "->", "_logger", "->", "$", "logMethod", "(", "'Received response from.'", ",", "$", "this", "->", "_context", "->", "getMetaData", "(", "__CLASS__", ",", "$", "logData", ")", ")", ";", "$", "responseData", "=", "$", "logData", ";", "$", "responseData", "[", "'rom_response_body'", "]", "=", "$", "response", "->", "asString", "(", ")", ";", "$", "logMessage", "=", "'Response data.'", ";", "$", "this", "->", "_logger", "->", "debug", "(", "$", "logMessage", ",", "$", "this", "->", "_context", "->", "getMetaData", "(", "__CLASS__", ",", "$", "responseData", ")", ")", ";", "if", "(", "!", "$", "response", "->", "getBody", "(", ")", ")", "{", "$", "logMessage", "=", "\"Received response with no body from {$uri} with status {$this->_status}.\"", ";", "$", "this", "->", "_logger", "->", "warning", "(", "$", "logMessage", ",", "$", "this", "->", "_context", "->", "getMetaData", "(", "__CLASS__", ",", "$", "logData", ")", ")", ";", "}", "$", "callbackConfig", "=", "isset", "(", "$", "config", "[", "'callback'", "]", ")", "?", "$", "config", "[", "'callback'", "]", ":", "array", "(", ")", ";", "$", "callbackConfig", "[", "'parameters'", "]", "=", "array", "(", "$", "response", ")", ";", "return", "Mage", "::", "helper", "(", "'radial_core'", ")", "->", "invokeCallBack", "(", "$", "callbackConfig", ")", ";", "}" ]
log the response and return the result of the configured handler method. @param Zend_Http_Response $response @param string $uri @return string response body or empty
[ "log", "the", "response", "and", "return", "the", "result", "of", "the", "configured", "handler", "method", "." ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Model/Api.php#L136-L154
train
RadialCorp/magento-core
src/app/code/community/Radial/Core/Model/Api.php
Radial_Core_Model_Api.schemaValidate
public function schemaValidate(DOMDocument $doc, $xsdName) { $errors = array(); set_error_handler(function ($errno, $errstr) use (&$errors) { $errors[] = "'$errstr' [Errno $errno]"; }); $cfg = Mage::helper('radial_core')->getConfigModel(); $isValid = $doc->schemaValidate(Mage::getBaseDir() . DS . $cfg->apiXsdPath . DS . $xsdName); restore_error_handler(); if (!$isValid) { $msg = sprintf( "[ %s ] Schema validation failed, encountering the following errors:\n%s", __CLASS__, implode("\n", $errors) ); throw new Radial_Core_Exception_InvalidXml($msg); } return $this; }
php
public function schemaValidate(DOMDocument $doc, $xsdName) { $errors = array(); set_error_handler(function ($errno, $errstr) use (&$errors) { $errors[] = "'$errstr' [Errno $errno]"; }); $cfg = Mage::helper('radial_core')->getConfigModel(); $isValid = $doc->schemaValidate(Mage::getBaseDir() . DS . $cfg->apiXsdPath . DS . $xsdName); restore_error_handler(); if (!$isValid) { $msg = sprintf( "[ %s ] Schema validation failed, encountering the following errors:\n%s", __CLASS__, implode("\n", $errors) ); throw new Radial_Core_Exception_InvalidXml($msg); } return $this; }
[ "public", "function", "schemaValidate", "(", "DOMDocument", "$", "doc", ",", "$", "xsdName", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "set_error_handler", "(", "function", "(", "$", "errno", ",", "$", "errstr", ")", "use", "(", "&", "$", "errors", ")", "{", "$", "errors", "[", "]", "=", "\"'$errstr' [Errno $errno]\"", ";", "}", ")", ";", "$", "cfg", "=", "Mage", "::", "helper", "(", "'radial_core'", ")", "->", "getConfigModel", "(", ")", ";", "$", "isValid", "=", "$", "doc", "->", "schemaValidate", "(", "Mage", "::", "getBaseDir", "(", ")", ".", "DS", ".", "$", "cfg", "->", "apiXsdPath", ".", "DS", ".", "$", "xsdName", ")", ";", "restore_error_handler", "(", ")", ";", "if", "(", "!", "$", "isValid", ")", "{", "$", "msg", "=", "sprintf", "(", "\"[ %s ] Schema validation failed, encountering the following errors:\\n%s\"", ",", "__CLASS__", ",", "implode", "(", "\"\\n\"", ",", "$", "errors", ")", ")", ";", "throw", "new", "Radial_Core_Exception_InvalidXml", "(", "$", "msg", ")", ";", "}", "return", "$", "this", ";", "}" ]
Validates the DOM against a validation schema, which should be a full path to an xsd for this DOMDocument. @param DomDocument $doc The document to validate @param string $xsdName xsd file basename with which to validate the doc @throws Radial_Core_Exception_InvalidXml when the schema is invalid @return self
[ "Validates", "the", "DOM", "against", "a", "validation", "schema", "which", "should", "be", "a", "full", "path", "to", "an", "xsd", "for", "this", "DOMDocument", "." ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Model/Api.php#L171-L189
train
RadialCorp/magento-core
src/app/code/community/Radial/Core/Model/Api.php
Radial_Core_Model_Api._processException
protected function _processException(Zend_Http_Client_Exception $exception, $uri) { $this->_status = 0; $config = $this->_getHandlerConfig($this->_getHandlerKey()); $logMethod = isset($config['logger']) ? $config['logger'] : 'debug'; // the zend http client throws exceptions that are generic and make it impractical to // generate a message that is more representative of what went wrong. $logData = array_merge(['rom_request_url' => $uri], $this->_logAppContext); $logMessage = "Problem with request to {$uri}:\n{$exception->getMessage()}"; $this->_logger->$logMethod($logMessage, $this->_context->getMetaData(__CLASS__, $logData, $exception)); $callbackConfig = isset($config['callback']) ? $config['callback'] : array(); return Mage::helper('radial_core')->invokeCallBack($callbackConfig); }
php
protected function _processException(Zend_Http_Client_Exception $exception, $uri) { $this->_status = 0; $config = $this->_getHandlerConfig($this->_getHandlerKey()); $logMethod = isset($config['logger']) ? $config['logger'] : 'debug'; // the zend http client throws exceptions that are generic and make it impractical to // generate a message that is more representative of what went wrong. $logData = array_merge(['rom_request_url' => $uri], $this->_logAppContext); $logMessage = "Problem with request to {$uri}:\n{$exception->getMessage()}"; $this->_logger->$logMethod($logMessage, $this->_context->getMetaData(__CLASS__, $logData, $exception)); $callbackConfig = isset($config['callback']) ? $config['callback'] : array(); return Mage::helper('radial_core')->invokeCallBack($callbackConfig); }
[ "protected", "function", "_processException", "(", "Zend_Http_Client_Exception", "$", "exception", ",", "$", "uri", ")", "{", "$", "this", "->", "_status", "=", "0", ";", "$", "config", "=", "$", "this", "->", "_getHandlerConfig", "(", "$", "this", "->", "_getHandlerKey", "(", ")", ")", ";", "$", "logMethod", "=", "isset", "(", "$", "config", "[", "'logger'", "]", ")", "?", "$", "config", "[", "'logger'", "]", ":", "'debug'", ";", "// the zend http client throws exceptions that are generic and make it impractical to", "// generate a message that is more representative of what went wrong.", "$", "logData", "=", "array_merge", "(", "[", "'rom_request_url'", "=>", "$", "uri", "]", ",", "$", "this", "->", "_logAppContext", ")", ";", "$", "logMessage", "=", "\"Problem with request to {$uri}:\\n{$exception->getMessage()}\"", ";", "$", "this", "->", "_logger", "->", "$", "logMethod", "(", "$", "logMessage", ",", "$", "this", "->", "_context", "->", "getMetaData", "(", "__CLASS__", ",", "$", "logData", ",", "$", "exception", ")", ")", ";", "$", "callbackConfig", "=", "isset", "(", "$", "config", "[", "'callback'", "]", ")", "?", "$", "config", "[", "'callback'", "]", ":", "array", "(", ")", ";", "return", "Mage", "::", "helper", "(", "'radial_core'", ")", "->", "invokeCallBack", "(", "$", "callbackConfig", ")", ";", "}" ]
handle the exception thrown by the zend client and return the result of the configured handler. @param Zend_Http_Client_Exception $exception @param string $uri @return string
[ "handle", "the", "exception", "thrown", "by", "the", "zend", "client", "and", "return", "the", "result", "of", "the", "configured", "handler", "." ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Model/Api.php#L197-L209
train
RadialCorp/magento-core
src/app/code/community/Radial/Core/Model/Api.php
Radial_Core_Model_Api._getHandlerKey
protected function _getHandlerKey(Zend_Http_Response $response = null) { if ($response) { $code = $response->getStatus(); if ($response->isSuccessful() || $response->isRedirect()) { return 'success'; } elseif ($code < 500 && $code >= 400) { return 'client_error'; } elseif ($code >= 500) { return 'server_error'; } // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd return 'no_response'; }
php
protected function _getHandlerKey(Zend_Http_Response $response = null) { if ($response) { $code = $response->getStatus(); if ($response->isSuccessful() || $response->isRedirect()) { return 'success'; } elseif ($code < 500 && $code >= 400) { return 'client_error'; } elseif ($code >= 500) { return 'server_error'; } // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd return 'no_response'; }
[ "protected", "function", "_getHandlerKey", "(", "Zend_Http_Response", "$", "response", "=", "null", ")", "{", "if", "(", "$", "response", ")", "{", "$", "code", "=", "$", "response", "->", "getStatus", "(", ")", ";", "if", "(", "$", "response", "->", "isSuccessful", "(", ")", "||", "$", "response", "->", "isRedirect", "(", ")", ")", "{", "return", "'success'", ";", "}", "elseif", "(", "$", "code", "<", "500", "&&", "$", "code", ">=", "400", ")", "{", "return", "'client_error'", ";", "}", "elseif", "(", "$", "code", ">=", "500", ")", "{", "return", "'server_error'", ";", "}", "// @codeCoverageIgnoreStart", "}", "// @codeCoverageIgnoreEnd", "return", "'no_response'", ";", "}" ]
return a string that is a key to the handler config for the class of status codes. @param Zend_Http_Response $response @return string
[ "return", "a", "string", "that", "is", "a", "key", "to", "the", "handler", "config", "for", "the", "class", "of", "status", "codes", "." ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Model/Api.php#L239-L254
train