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
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.whereFirst
public function whereFirst($where) { $where = LambdaUtils::toConditionCallable($where); foreach($this as $record) { if(call_user_func($where, $record)) { return $record; } } throw new \OutOfBoundsException(); }
php
public function whereFirst($where) { $where = LambdaUtils::toConditionCallable($where); foreach($this as $record) { if(call_user_func($where, $record)) { return $record; } } throw new \OutOfBoundsException(); }
[ "public", "function", "whereFirst", "(", "$", "where", ")", "{", "$", "where", "=", "LambdaUtils", "::", "toConditionCallable", "(", "$", "where", ")", ";", "foreach", "(", "$", "this", "as", "$", "record", ")", "{", "if", "(", "call_user_func", "(", "$", "where", ",", "$", "record", ")", ")", "{", "return", "$", "record", ";", "}", "}", "throw", "new", "\\", "OutOfBoundsException", "(", ")", ";", "}" ]
Get first item matching to callable @param callable|array $where @return mixed @throws \OutOfBoundsException
[ "Get", "first", "item", "matching", "to", "callable" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L638-L649
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.whereFirstOrDefault
public function whereFirstOrDefault($where, $default=null) { $where = LambdaUtils::toConditionCallable($where); foreach($this as $record) { if(call_user_func($where, $record)) { return $record; } } return $default; }
php
public function whereFirstOrDefault($where, $default=null) { $where = LambdaUtils::toConditionCallable($where); foreach($this as $record) { if(call_user_func($where, $record)) { return $record; } } return $default; }
[ "public", "function", "whereFirstOrDefault", "(", "$", "where", ",", "$", "default", "=", "null", ")", "{", "$", "where", "=", "LambdaUtils", "::", "toConditionCallable", "(", "$", "where", ")", ";", "foreach", "(", "$", "this", "as", "$", "record", ")", "{", "if", "(", "call_user_func", "(", "$", "where", ",", "$", "record", ")", ")", "{", "return", "$", "record", ";", "}", "}", "return", "$", "default", ";", "}" ]
Get first item matching to callable or default @param callable|array $where @param mixed $default @return mixed
[ "Get", "first", "item", "matching", "to", "callable", "or", "default" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L657-L668
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.groupBy
public function groupBy($group=null) { $group = LambdaUtils::toSelectCallable($group); $result = new ObjectArray(array()); if($this instanceof ObjectArray) { $result = $this->newInstance(); } foreach($this as $record) { $key = call_user_func($group, $record); $data = array(); if($this->__converter instanceof IListConverter) { $data = $this->newConverterInstance(); } $newitemtype = new ArrayList($data); $result->get($key, $newitemtype, true)->add($record); } return $result; }
php
public function groupBy($group=null) { $group = LambdaUtils::toSelectCallable($group); $result = new ObjectArray(array()); if($this instanceof ObjectArray) { $result = $this->newInstance(); } foreach($this as $record) { $key = call_user_func($group, $record); $data = array(); if($this->__converter instanceof IListConverter) { $data = $this->newConverterInstance(); } $newitemtype = new ArrayList($data); $result->get($key, $newitemtype, true)->add($record); } return $result; }
[ "public", "function", "groupBy", "(", "$", "group", "=", "null", ")", "{", "$", "group", "=", "LambdaUtils", "::", "toSelectCallable", "(", "$", "group", ")", ";", "$", "result", "=", "new", "ObjectArray", "(", "array", "(", ")", ")", ";", "if", "(", "$", "this", "instanceof", "ObjectArray", ")", "{", "$", "result", "=", "$", "this", "->", "newInstance", "(", ")", ";", "}", "foreach", "(", "$", "this", "as", "$", "record", ")", "{", "$", "key", "=", "call_user_func", "(", "$", "group", ",", "$", "record", ")", ";", "$", "data", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "__converter", "instanceof", "IListConverter", ")", "{", "$", "data", "=", "$", "this", "->", "newConverterInstance", "(", ")", ";", "}", "$", "newitemtype", "=", "new", "ArrayList", "(", "$", "data", ")", ";", "$", "result", "->", "get", "(", "$", "key", ",", "$", "newitemtype", ",", "true", ")", "->", "add", "(", "$", "record", ")", ";", "}", "return", "$", "result", ";", "}" ]
Group fields by condition @param callable|string|null $group @return \PerrysLambda\ArrayBase
[ "Group", "fields", "by", "condition" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L675-L700
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.distinct
public function distinct($distinct=null) { $distinct = LambdaUtils::toSelectCallable($distinct); $keys = array(); $collection = $this->newInstance(); foreach($this as $record) { $value = call_user_func($distinct, $record); $hash = md5(json_encode($value)); if(!isset($keys[$hash])) { $keys[$hash]=true; $collection->add($record); } } return $collection; }
php
public function distinct($distinct=null) { $distinct = LambdaUtils::toSelectCallable($distinct); $keys = array(); $collection = $this->newInstance(); foreach($this as $record) { $value = call_user_func($distinct, $record); $hash = md5(json_encode($value)); if(!isset($keys[$hash])) { $keys[$hash]=true; $collection->add($record); } } return $collection; }
[ "public", "function", "distinct", "(", "$", "distinct", "=", "null", ")", "{", "$", "distinct", "=", "LambdaUtils", "::", "toSelectCallable", "(", "$", "distinct", ")", ";", "$", "keys", "=", "array", "(", ")", ";", "$", "collection", "=", "$", "this", "->", "newInstance", "(", ")", ";", "foreach", "(", "$", "this", "as", "$", "record", ")", "{", "$", "value", "=", "call_user_func", "(", "$", "distinct", ",", "$", "record", ")", ";", "$", "hash", "=", "md5", "(", "json_encode", "(", "$", "value", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "keys", "[", "$", "hash", "]", ")", ")", "{", "$", "keys", "[", "$", "hash", "]", "=", "true", ";", "$", "collection", "->", "add", "(", "$", "record", ")", ";", "}", "}", "return", "$", "collection", ";", "}" ]
filter duplicate field by condition @param callable|string|null $distinct @return \PerrysLambda\ArrayBase
[ "filter", "duplicate", "field", "by", "condition" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L707-L724
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.intersect
public function intersect(ArrayBase $comparedata) { $cmpvalue = function($v1, $v2) { return $v1==$v2 ? 0 : ($v1>$v2 ? 1 : -1); }; $collection = $this->newInstance(); $temp = array_uintersect($this->getData(), $comparedata->getData(), $cmpvalue); $collection->setData($temp); unset($temp); return $collection; }
php
public function intersect(ArrayBase $comparedata) { $cmpvalue = function($v1, $v2) { return $v1==$v2 ? 0 : ($v1>$v2 ? 1 : -1); }; $collection = $this->newInstance(); $temp = array_uintersect($this->getData(), $comparedata->getData(), $cmpvalue); $collection->setData($temp); unset($temp); return $collection; }
[ "public", "function", "intersect", "(", "ArrayBase", "$", "comparedata", ")", "{", "$", "cmpvalue", "=", "function", "(", "$", "v1", ",", "$", "v2", ")", "{", "return", "$", "v1", "==", "$", "v2", "?", "0", ":", "(", "$", "v1", ">", "$", "v2", "?", "1", ":", "-", "1", ")", ";", "}", ";", "$", "collection", "=", "$", "this", "->", "newInstance", "(", ")", ";", "$", "temp", "=", "array_uintersect", "(", "$", "this", "->", "getData", "(", ")", ",", "$", "comparedata", "->", "getData", "(", ")", ",", "$", "cmpvalue", ")", ";", "$", "collection", "->", "setData", "(", "$", "temp", ")", ";", "unset", "(", "$", "temp", ")", ";", "return", "$", "collection", ";", "}" ]
Intersection to another object @param \PerrysLambda\ArrayBase $comparedata @return \PerrysLambda\ArrayBase
[ "Intersection", "to", "another", "object" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L731-L741
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.except
public function except(ArrayBase $comparedata) { $cmpvalue = function($v1, $v2) { return $v1==$v2 ? 0 : ($v1>$v2 ? 1 : -1); }; $collection = $this->newInstance(); $temp1 = array_udiff($this->getData(), $comparedata->getData(), $cmpvalue); $temp2 = array_udiff($comparedata->getData(), $this->getData(), $cmpvalue); $temp = array_merge($temp1, $temp2); unset($temp1, $temp2); $collection->setData($temp); unset($temp); return $collection; }
php
public function except(ArrayBase $comparedata) { $cmpvalue = function($v1, $v2) { return $v1==$v2 ? 0 : ($v1>$v2 ? 1 : -1); }; $collection = $this->newInstance(); $temp1 = array_udiff($this->getData(), $comparedata->getData(), $cmpvalue); $temp2 = array_udiff($comparedata->getData(), $this->getData(), $cmpvalue); $temp = array_merge($temp1, $temp2); unset($temp1, $temp2); $collection->setData($temp); unset($temp); return $collection; }
[ "public", "function", "except", "(", "ArrayBase", "$", "comparedata", ")", "{", "$", "cmpvalue", "=", "function", "(", "$", "v1", ",", "$", "v2", ")", "{", "return", "$", "v1", "==", "$", "v2", "?", "0", ":", "(", "$", "v1", ">", "$", "v2", "?", "1", ":", "-", "1", ")", ";", "}", ";", "$", "collection", "=", "$", "this", "->", "newInstance", "(", ")", ";", "$", "temp1", "=", "array_udiff", "(", "$", "this", "->", "getData", "(", ")", ",", "$", "comparedata", "->", "getData", "(", ")", ",", "$", "cmpvalue", ")", ";", "$", "temp2", "=", "array_udiff", "(", "$", "comparedata", "->", "getData", "(", ")", ",", "$", "this", "->", "getData", "(", ")", ",", "$", "cmpvalue", ")", ";", "$", "temp", "=", "array_merge", "(", "$", "temp1", ",", "$", "temp2", ")", ";", "unset", "(", "$", "temp1", ",", "$", "temp2", ")", ";", "$", "collection", "->", "setData", "(", "$", "temp", ")", ";", "unset", "(", "$", "temp", ")", ";", "return", "$", "collection", ";", "}" ]
Difference to another object @param \PerrysLambda\ArrayBase $comparedata @return \PerrysLambda\ArrayBase
[ "Difference", "to", "another", "object" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L748-L761
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.all
public function all($where) { $where = LambdaUtils::toConditionCallable($where); foreach($this as $record) { if(!call_user_func($where, $record)) { return false; } } return true; }
php
public function all($where) { $where = LambdaUtils::toConditionCallable($where); foreach($this as $record) { if(!call_user_func($where, $record)) { return false; } } return true; }
[ "public", "function", "all", "(", "$", "where", ")", "{", "$", "where", "=", "LambdaUtils", "::", "toConditionCallable", "(", "$", "where", ")", ";", "foreach", "(", "$", "this", "as", "$", "record", ")", "{", "if", "(", "!", "call_user_func", "(", "$", "where", ",", "$", "record", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check for all fields by condition @param callable|array $where @return bool
[ "Check", "for", "all", "fields", "by", "condition" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L786-L797
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.selectMany
public function selectMany($select=null) { $select = LambdaUtils::toSelectCallable($select); $result = array(); foreach($this as $key => $record) { $temp = call_user_func($select, $record, $key); if(is_array($temp) || $temp instanceof \Iterator) { foreach($temp as $tempitem) { $result[] = $tempitem; } } else { $result[] = $temp; } } return new ArrayList($result); }
php
public function selectMany($select=null) { $select = LambdaUtils::toSelectCallable($select); $result = array(); foreach($this as $key => $record) { $temp = call_user_func($select, $record, $key); if(is_array($temp) || $temp instanceof \Iterator) { foreach($temp as $tempitem) { $result[] = $tempitem; } } else { $result[] = $temp; } } return new ArrayList($result); }
[ "public", "function", "selectMany", "(", "$", "select", "=", "null", ")", "{", "$", "select", "=", "LambdaUtils", "::", "toSelectCallable", "(", "$", "select", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "as", "$", "key", "=>", "$", "record", ")", "{", "$", "temp", "=", "call_user_func", "(", "$", "select", ",", "$", "record", ",", "$", "key", ")", ";", "if", "(", "is_array", "(", "$", "temp", ")", "||", "$", "temp", "instanceof", "\\", "Iterator", ")", "{", "foreach", "(", "$", "temp", "as", "$", "tempitem", ")", "{", "$", "result", "[", "]", "=", "$", "tempitem", ";", "}", "}", "else", "{", "$", "result", "[", "]", "=", "$", "temp", ";", "}", "}", "return", "new", "ArrayList", "(", "$", "result", ")", ";", "}" ]
Select a field and merge all arrays into one @param callable|string|null $select @return \PerrysLambda\ArrayList
[ "Select", "a", "field", "and", "merge", "all", "arrays", "into", "one" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L821-L842
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.each
public function each(callable $each) { foreach($this->__data as $key => &$record) { call_user_func_array($each, array(&$record, $key)); } unset($record); return $this; }
php
public function each(callable $each) { foreach($this->__data as $key => &$record) { call_user_func_array($each, array(&$record, $key)); } unset($record); return $this; }
[ "public", "function", "each", "(", "callable", "$", "each", ")", "{", "foreach", "(", "$", "this", "->", "__data", "as", "$", "key", "=>", "&", "$", "record", ")", "{", "call_user_func_array", "(", "$", "each", ",", "array", "(", "&", "$", "record", ",", "$", "key", ")", ")", ";", "}", "unset", "(", "$", "record", ")", ";", "return", "$", "this", ";", "}" ]
Iterate all fields @param callable $each @return \PerrysLambda\ArrayList
[ "Iterate", "all", "fields" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L849-L857
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.sum
public function sum($sum=null) { $sum = LambdaUtils::toSelectCallable($sum); $temp = $this->select($sum)->toArray(); return array_sum($temp); }
php
public function sum($sum=null) { $sum = LambdaUtils::toSelectCallable($sum); $temp = $this->select($sum)->toArray(); return array_sum($temp); }
[ "public", "function", "sum", "(", "$", "sum", "=", "null", ")", "{", "$", "sum", "=", "LambdaUtils", "::", "toSelectCallable", "(", "$", "sum", ")", ";", "$", "temp", "=", "$", "this", "->", "select", "(", "$", "sum", ")", "->", "toArray", "(", ")", ";", "return", "array_sum", "(", "$", "temp", ")", ";", "}" ]
Calculates the sum of values from given expression @param callable|string|null $sum @return numeric
[ "Calculates", "the", "sum", "of", "values", "from", "given", "expression" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L864-L869
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.min
public function min($min=null) { $min = LambdaUtils::toSelectCallable($min); $temp = $this->select($min)->toArray(); return min($temp); }
php
public function min($min=null) { $min = LambdaUtils::toSelectCallable($min); $temp = $this->select($min)->toArray(); return min($temp); }
[ "public", "function", "min", "(", "$", "min", "=", "null", ")", "{", "$", "min", "=", "LambdaUtils", "::", "toSelectCallable", "(", "$", "min", ")", ";", "$", "temp", "=", "$", "this", "->", "select", "(", "$", "min", ")", "->", "toArray", "(", ")", ";", "return", "min", "(", "$", "temp", ")", ";", "}" ]
Find the lowest value from given expression @param callable|string|null $min @return numeric
[ "Find", "the", "lowest", "value", "from", "given", "expression" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L876-L881
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.max
public function max($max=null) { $max = LambdaUtils::toSelectCallable($max); $temp = $this->select($max)->toArray(); return max($temp); }
php
public function max($max=null) { $max = LambdaUtils::toSelectCallable($max); $temp = $this->select($max)->toArray(); return max($temp); }
[ "public", "function", "max", "(", "$", "max", "=", "null", ")", "{", "$", "max", "=", "LambdaUtils", "::", "toSelectCallable", "(", "$", "max", ")", ";", "$", "temp", "=", "$", "this", "->", "select", "(", "$", "max", ")", "->", "toArray", "(", ")", ";", "return", "max", "(", "$", "temp", ")", ";", "}" ]
Find the biggest value from given expression @param callable|string|null $max @return numeric
[ "Find", "the", "biggest", "value", "from", "given", "expression" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L888-L893
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.avg
public function avg($avg=null) { $avg = LambdaUtils::toSelectCallable($avg); return ($this->sum($avg)/$this->length()); }
php
public function avg($avg=null) { $avg = LambdaUtils::toSelectCallable($avg); return ($this->sum($avg)/$this->length()); }
[ "public", "function", "avg", "(", "$", "avg", "=", "null", ")", "{", "$", "avg", "=", "LambdaUtils", "::", "toSelectCallable", "(", "$", "avg", ")", ";", "return", "(", "$", "this", "->", "sum", "(", "$", "avg", ")", "/", "$", "this", "->", "length", "(", ")", ")", ";", "}" ]
Find the average of the values from given expression @param callable|string|null $avg @return numeric
[ "Find", "the", "average", "of", "the", "values", "from", "given", "expression" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L900-L904
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.joinString
public function joinString($join=null, $glue=", ") { $join = LambdaUtils::toSelectCallable($join); $temp = $this->select($join)->toArray(); return implode($glue, $temp); }
php
public function joinString($join=null, $glue=", ") { $join = LambdaUtils::toSelectCallable($join); $temp = $this->select($join)->toArray(); return implode($glue, $temp); }
[ "public", "function", "joinString", "(", "$", "join", "=", "null", ",", "$", "glue", "=", "\", \"", ")", "{", "$", "join", "=", "LambdaUtils", "::", "toSelectCallable", "(", "$", "join", ")", ";", "$", "temp", "=", "$", "this", "->", "select", "(", "$", "join", ")", "->", "toArray", "(", ")", ";", "return", "implode", "(", "$", "glue", ",", "$", "temp", ")", ";", "}" ]
Join values from expression to one string @param callable|string|null $join @param string $glue @return string
[ "Join", "values", "from", "expression", "to", "one", "string" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L912-L917
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.take
public function take($length) { if(!is_int($length)) { throw new \InvalidArgumentException(); } if($length>=0 && $length>$this->length()) { $length = $this->length(); } elseif($length<0 && $length<(0-$this->length())) { $length = 0-$this->length(); } $temp = $this->newInstance(); if($length>=0) { $temp->setData(array_slice($this->getData(), 0, $length)); } else { $temp->setData(array_slice($this->getData(), $length)); } return $temp; }
php
public function take($length) { if(!is_int($length)) { throw new \InvalidArgumentException(); } if($length>=0 && $length>$this->length()) { $length = $this->length(); } elseif($length<0 && $length<(0-$this->length())) { $length = 0-$this->length(); } $temp = $this->newInstance(); if($length>=0) { $temp->setData(array_slice($this->getData(), 0, $length)); } else { $temp->setData(array_slice($this->getData(), $length)); } return $temp; }
[ "public", "function", "take", "(", "$", "length", ")", "{", "if", "(", "!", "is_int", "(", "$", "length", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "if", "(", "$", "length", ">=", "0", "&&", "$", "length", ">", "$", "this", "->", "length", "(", ")", ")", "{", "$", "length", "=", "$", "this", "->", "length", "(", ")", ";", "}", "elseif", "(", "$", "length", "<", "0", "&&", "$", "length", "<", "(", "0", "-", "$", "this", "->", "length", "(", ")", ")", ")", "{", "$", "length", "=", "0", "-", "$", "this", "->", "length", "(", ")", ";", "}", "$", "temp", "=", "$", "this", "->", "newInstance", "(", ")", ";", "if", "(", "$", "length", ">=", "0", ")", "{", "$", "temp", "->", "setData", "(", "array_slice", "(", "$", "this", "->", "getData", "(", ")", ",", "0", ",", "$", "length", ")", ")", ";", "}", "else", "{", "$", "temp", "->", "setData", "(", "array_slice", "(", "$", "this", "->", "getData", "(", ")", ",", "$", "length", ")", ")", ";", "}", "return", "$", "temp", ";", "}" ]
Take first x fields @param int $length @return \PerrysLambda\ArrayList
[ "Take", "first", "x", "fields" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L1010-L1038
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.skip
public function skip($offset) { if(!is_int($offset)) { throw new \InvalidArgumentException(); } if($offset<0 || $offset>=$this->length()) { throw new \OutOfBoundsException(); } $temp = $this->newInstance(); $temp->setData(array_slice($this->getData(), $offset)); return $temp; }
php
public function skip($offset) { if(!is_int($offset)) { throw new \InvalidArgumentException(); } if($offset<0 || $offset>=$this->length()) { throw new \OutOfBoundsException(); } $temp = $this->newInstance(); $temp->setData(array_slice($this->getData(), $offset)); return $temp; }
[ "public", "function", "skip", "(", "$", "offset", ")", "{", "if", "(", "!", "is_int", "(", "$", "offset", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "if", "(", "$", "offset", "<", "0", "||", "$", "offset", ">=", "$", "this", "->", "length", "(", ")", ")", "{", "throw", "new", "\\", "OutOfBoundsException", "(", ")", ";", "}", "$", "temp", "=", "$", "this", "->", "newInstance", "(", ")", ";", "$", "temp", "->", "setData", "(", "array_slice", "(", "$", "this", "->", "getData", "(", ")", ",", "$", "offset", ")", ")", ";", "return", "$", "temp", ";", "}" ]
Skip x fields @param type $offset @return \PerrysLambda\ArrayList
[ "Skip", "x", "fields" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L1045-L1060
train
CrunchPHP/fastcgi
src/Client/Client.php
Client.newRequest
public function newRequest(RequestParametersInterface $parameters = null, ReaderInterface $stdin = null) { return new Request(Role::responder(), $this->nextRequestId++, true, $parameters, $stdin); }
php
public function newRequest(RequestParametersInterface $parameters = null, ReaderInterface $stdin = null) { return new Request(Role::responder(), $this->nextRequestId++, true, $parameters, $stdin); }
[ "public", "function", "newRequest", "(", "RequestParametersInterface", "$", "parameters", "=", "null", ",", "ReaderInterface", "$", "stdin", "=", "null", ")", "{", "return", "new", "Request", "(", "Role", "::", "responder", "(", ")", ",", "$", "this", "->", "nextRequestId", "++", ",", "true", ",", "$", "parameters", ",", "$", "stdin", ")", ";", "}" ]
Creates a new responder request. Although you can create a Request instance manually it is highly recommended to use this factory method, because only this one ensures, that the request uses a previously unused request id. @param RequestParametersInterface|null $parameters @param ReaderInterface|null $stdin @return RequestInterface
[ "Creates", "a", "new", "responder", "request", "." ]
102437193e67e5a841ec5a897549ec345788d1bd
https://github.com/CrunchPHP/fastcgi/blob/102437193e67e5a841ec5a897549ec345788d1bd/src/Client/Client.php#L60-L63
train
dmt-software/auth-middleware
src/Authorization/ApiToken.php
ApiToken.handle
public function handle(RequestInterface $request): RequestInterface { if ($this->token === '' || $this->key === '') { throw new AuthorizationException('Could not create api token, missing or empty arguments'); } return $request->withHeader($this->key, $this->token); }
php
public function handle(RequestInterface $request): RequestInterface { if ($this->token === '' || $this->key === '') { throw new AuthorizationException('Could not create api token, missing or empty arguments'); } return $request->withHeader($this->key, $this->token); }
[ "public", "function", "handle", "(", "RequestInterface", "$", "request", ")", ":", "RequestInterface", "{", "if", "(", "$", "this", "->", "token", "===", "''", "||", "$", "this", "->", "key", "===", "''", ")", "{", "throw", "new", "AuthorizationException", "(", "'Could not create api token, missing or empty arguments'", ")", ";", "}", "return", "$", "request", "->", "withHeader", "(", "$", "this", "->", "key", ",", "$", "this", "->", "token", ")", ";", "}" ]
Get a request with the headers associated with the authorization. @param RequestInterface $request @return RequestInterface
[ "Get", "a", "request", "with", "the", "headers", "associated", "with", "the", "authorization", "." ]
7a4633224944567c1e2ce63189f40a69acf221a6
https://github.com/dmt-software/auth-middleware/blob/7a4633224944567c1e2ce63189f40a69acf221a6/src/Authorization/ApiToken.php#L49-L55
train
net-tools/core
src/Helpers/SecureRequestHelper.php
SecureRequestHelper.getCSRFCookie
public function getCSRFCookie() { $cookie = $this->_browserInterface->getCookie($this->_csrf_cookiename); if ( !$cookie ) throw new SecureRequestHelper\CSRFException('CSRF cookie has not been initialized'); return $cookie; }
php
public function getCSRFCookie() { $cookie = $this->_browserInterface->getCookie($this->_csrf_cookiename); if ( !$cookie ) throw new SecureRequestHelper\CSRFException('CSRF cookie has not been initialized'); return $cookie; }
[ "public", "function", "getCSRFCookie", "(", ")", "{", "$", "cookie", "=", "$", "this", "->", "_browserInterface", "->", "getCookie", "(", "$", "this", "->", "_csrf_cookiename", ")", ";", "if", "(", "!", "$", "cookie", ")", "throw", "new", "SecureRequestHelper", "\\", "CSRFException", "(", "'CSRF cookie has not been initialized'", ")", ";", "return", "$", "cookie", ";", "}" ]
Get CSRF cookie value @return string @throws SecureRequestHelper\CSRFException Thrown if the CSRF layer has not been initialized
[ "Get", "CSRF", "cookie", "value" ]
51446641cee22c0cf53d2b409c76cc8bd1a187e7
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/SecureRequestHelper.php#L77-L84
train
fridge-project/dbal
src/Fridge/DBAL/Driver/Statement/MysqliStatement.php
MysqliStatement.getMappedType
private static function getMappedType($type) { if (!isset(self::$mappedTypes[$type])) { throw MysqliException::mappedTypeDoesNotExist($type); } return self::$mappedTypes[$type]; }
php
private static function getMappedType($type) { if (!isset(self::$mappedTypes[$type])) { throw MysqliException::mappedTypeDoesNotExist($type); } return self::$mappedTypes[$type]; }
[ "private", "static", "function", "getMappedType", "(", "$", "type", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "mappedTypes", "[", "$", "type", "]", ")", ")", "{", "throw", "MysqliException", "::", "mappedTypeDoesNotExist", "(", "$", "type", ")", ";", "}", "return", "self", "::", "$", "mappedTypes", "[", "$", "type", "]", ";", "}" ]
Gets the mapped type. @param integer $type The type (\PDO::PARAM_*). @throws \Fridge\DBAL\Exception\MysqliException If the mapped type does not exist. @return string The mapped type.
[ "Gets", "the", "mapped", "type", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/MysqliStatement.php#L302-L309
train
fridge-project/dbal
src/Fridge/DBAL/Driver/Statement/MysqliStatement.php
MysqliStatement.bindValues
private function bindValues(array $values) { $this->bindedParameters = array(); $this->bindedTypes = array(); $this->bindedValues = array(); foreach ($values as $parameter => $value) { if (is_int($parameter)) { $parameter++; } $this->bindValue($parameter, $value); } }
php
private function bindValues(array $values) { $this->bindedParameters = array(); $this->bindedTypes = array(); $this->bindedValues = array(); foreach ($values as $parameter => $value) { if (is_int($parameter)) { $parameter++; } $this->bindValue($parameter, $value); } }
[ "private", "function", "bindValues", "(", "array", "$", "values", ")", "{", "$", "this", "->", "bindedParameters", "=", "array", "(", ")", ";", "$", "this", "->", "bindedTypes", "=", "array", "(", ")", ";", "$", "this", "->", "bindedValues", "=", "array", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "parameter", "=>", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "parameter", ")", ")", "{", "$", "parameter", "++", ";", "}", "$", "this", "->", "bindValue", "(", "$", "parameter", ",", "$", "value", ")", ";", "}", "}" ]
Binds values on the statement. @param array $values Associative array describing parameter => value pairs.
[ "Binds", "values", "on", "the", "statement", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/MysqliStatement.php#L316-L329
train
fridge-project/dbal
src/Fridge/DBAL/Driver/Statement/MysqliStatement.php
MysqliStatement.bindParameters
private function bindParameters() { $bindedParameterReferences = array(implode('', $this->bindedTypes)); $lobParameters = array(); $null = null; foreach ($this->bindedParameters as $key => &$parameter) { if (isset($this->bindedTypes[$key - 1]) && ($this->bindedTypes[$key - 1] === self::$mappedTypes[\PDO::PARAM_LOB])) { $lobParameters[$key - 1] = $parameter; $bindedParameterReferences[$key] = &$null; } else { $bindedParameterReferences[$key] = &$parameter; } } call_user_func_array(array($this->mysqliStatement, 'bind_param'), $bindedParameterReferences); foreach ($lobParameters as $key => $lobParameter) { rewind($lobParameter); while (!feof($lobParameter)) { $this->mysqliStatement->send_long_data( $key, fread($lobParameter, $this->connection->getMaxAllowedPacket()) ); } } }
php
private function bindParameters() { $bindedParameterReferences = array(implode('', $this->bindedTypes)); $lobParameters = array(); $null = null; foreach ($this->bindedParameters as $key => &$parameter) { if (isset($this->bindedTypes[$key - 1]) && ($this->bindedTypes[$key - 1] === self::$mappedTypes[\PDO::PARAM_LOB])) { $lobParameters[$key - 1] = $parameter; $bindedParameterReferences[$key] = &$null; } else { $bindedParameterReferences[$key] = &$parameter; } } call_user_func_array(array($this->mysqliStatement, 'bind_param'), $bindedParameterReferences); foreach ($lobParameters as $key => $lobParameter) { rewind($lobParameter); while (!feof($lobParameter)) { $this->mysqliStatement->send_long_data( $key, fread($lobParameter, $this->connection->getMaxAllowedPacket()) ); } } }
[ "private", "function", "bindParameters", "(", ")", "{", "$", "bindedParameterReferences", "=", "array", "(", "implode", "(", "''", ",", "$", "this", "->", "bindedTypes", ")", ")", ";", "$", "lobParameters", "=", "array", "(", ")", ";", "$", "null", "=", "null", ";", "foreach", "(", "$", "this", "->", "bindedParameters", "as", "$", "key", "=>", "&", "$", "parameter", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "bindedTypes", "[", "$", "key", "-", "1", "]", ")", "&&", "(", "$", "this", "->", "bindedTypes", "[", "$", "key", "-", "1", "]", "===", "self", "::", "$", "mappedTypes", "[", "\\", "PDO", "::", "PARAM_LOB", "]", ")", ")", "{", "$", "lobParameters", "[", "$", "key", "-", "1", "]", "=", "$", "parameter", ";", "$", "bindedParameterReferences", "[", "$", "key", "]", "=", "&", "$", "null", ";", "}", "else", "{", "$", "bindedParameterReferences", "[", "$", "key", "]", "=", "&", "$", "parameter", ";", "}", "}", "call_user_func_array", "(", "array", "(", "$", "this", "->", "mysqliStatement", ",", "'bind_param'", ")", ",", "$", "bindedParameterReferences", ")", ";", "foreach", "(", "$", "lobParameters", "as", "$", "key", "=>", "$", "lobParameter", ")", "{", "rewind", "(", "$", "lobParameter", ")", ";", "while", "(", "!", "feof", "(", "$", "lobParameter", ")", ")", "{", "$", "this", "->", "mysqliStatement", "->", "send_long_data", "(", "$", "key", ",", "fread", "(", "$", "lobParameter", ",", "$", "this", "->", "connection", "->", "getMaxAllowedPacket", "(", ")", ")", ")", ";", "}", "}", "}" ]
Binds the parameters on the driver statement.
[ "Binds", "the", "parameters", "on", "the", "driver", "statement", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/MysqliStatement.php#L334-L362
train
fridge-project/dbal
src/Fridge/DBAL/Driver/Statement/MysqliStatement.php
MysqliStatement.bindResultFields
private function bindResultFields() { $resultMetadata = $this->mysqliStatement->result_metadata(); if ($resultMetadata !== false) { $this->resultFields = array(); foreach ($resultMetadata->fetch_fields() as $field) { $this->resultFields[] = $field->name; } $resultMetadata->free(); } }
php
private function bindResultFields() { $resultMetadata = $this->mysqliStatement->result_metadata(); if ($resultMetadata !== false) { $this->resultFields = array(); foreach ($resultMetadata->fetch_fields() as $field) { $this->resultFields[] = $field->name; } $resultMetadata->free(); } }
[ "private", "function", "bindResultFields", "(", ")", "{", "$", "resultMetadata", "=", "$", "this", "->", "mysqliStatement", "->", "result_metadata", "(", ")", ";", "if", "(", "$", "resultMetadata", "!==", "false", ")", "{", "$", "this", "->", "resultFields", "=", "array", "(", ")", ";", "foreach", "(", "$", "resultMetadata", "->", "fetch_fields", "(", ")", "as", "$", "field", ")", "{", "$", "this", "->", "resultFields", "[", "]", "=", "$", "field", "->", "name", ";", "}", "$", "resultMetadata", "->", "free", "(", ")", ";", "}", "}" ]
Binds the driver result fields.
[ "Binds", "the", "driver", "result", "fields", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/MysqliStatement.php#L367-L380
train
fridge-project/dbal
src/Fridge/DBAL/Driver/Statement/MysqliStatement.php
MysqliStatement.bindResult
private function bindResult() { $this->result = array_fill(0, count($this->resultFields), null); $resultReferences = array(); foreach ($this->result as $key => &$result) { $resultReferences[$key] = &$result; } call_user_func_array(array($this->mysqliStatement, 'bind_result'), $resultReferences); $this->result = $resultReferences; }
php
private function bindResult() { $this->result = array_fill(0, count($this->resultFields), null); $resultReferences = array(); foreach ($this->result as $key => &$result) { $resultReferences[$key] = &$result; } call_user_func_array(array($this->mysqliStatement, 'bind_result'), $resultReferences); $this->result = $resultReferences; }
[ "private", "function", "bindResult", "(", ")", "{", "$", "this", "->", "result", "=", "array_fill", "(", "0", ",", "count", "(", "$", "this", "->", "resultFields", ")", ",", "null", ")", ";", "$", "resultReferences", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "result", "as", "$", "key", "=>", "&", "$", "result", ")", "{", "$", "resultReferences", "[", "$", "key", "]", "=", "&", "$", "result", ";", "}", "call_user_func_array", "(", "array", "(", "$", "this", "->", "mysqliStatement", ",", "'bind_result'", ")", ",", "$", "resultReferences", ")", ";", "$", "this", "->", "result", "=", "$", "resultReferences", ";", "}" ]
Binds the driver statement result.
[ "Binds", "the", "driver", "statement", "result", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/MysqliStatement.php#L385-L397
train
kambalabs/KmbDomain
src/KmbDomain/Service/GroupFactory.php
GroupFactory.createFromImportedData
public function createFromImportedData($data) { $group = new Group($data['name'], $data['include_pattern'], $data['exclude_pattern']); if (isset($data['type'])) { $group->setType($data['type']); } $group->setOrdering($data['ordering']); foreach ($data['classes'] as $className => $classData) { $group->addClass($this->getGroupClassFactory()->createFromImportedData($className, $classData)); } return $group; }
php
public function createFromImportedData($data) { $group = new Group($data['name'], $data['include_pattern'], $data['exclude_pattern']); if (isset($data['type'])) { $group->setType($data['type']); } $group->setOrdering($data['ordering']); foreach ($data['classes'] as $className => $classData) { $group->addClass($this->getGroupClassFactory()->createFromImportedData($className, $classData)); } return $group; }
[ "public", "function", "createFromImportedData", "(", "$", "data", ")", "{", "$", "group", "=", "new", "Group", "(", "$", "data", "[", "'name'", "]", ",", "$", "data", "[", "'include_pattern'", "]", ",", "$", "data", "[", "'exclude_pattern'", "]", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'type'", "]", ")", ")", "{", "$", "group", "->", "setType", "(", "$", "data", "[", "'type'", "]", ")", ";", "}", "$", "group", "->", "setOrdering", "(", "$", "data", "[", "'ordering'", "]", ")", ";", "foreach", "(", "$", "data", "[", "'classes'", "]", "as", "$", "className", "=>", "$", "classData", ")", "{", "$", "group", "->", "addClass", "(", "$", "this", "->", "getGroupClassFactory", "(", ")", "->", "createFromImportedData", "(", "$", "className", ",", "$", "classData", ")", ")", ";", "}", "return", "$", "group", ";", "}" ]
Create Group instance from imported data. @param array $data @return Group
[ "Create", "Group", "instance", "from", "imported", "data", "." ]
b1631bd936c6c6798076b51dfaebd706e1bdc8c2
https://github.com/kambalabs/KmbDomain/blob/b1631bd936c6c6798076b51dfaebd706e1bdc8c2/src/KmbDomain/Service/GroupFactory.php#L36-L47
train
Saritasa/php-eloquent-custom
src/Models/User.php
User.getRules
public function getRules() { $rules = [ static::FIRST_NAME => "required|max:100", static::LAST_NAME => "required|max:100", static::EMAIL => "required|max:100|email|unique:users,email,{$this->id},id", ]; if (!$this->id) { $rules[static::PWD_FIELD] = 'required|min:' . config('app.model.user.password.min', 6) . '|max:' . config('app.model.user.password.max', 20); } return $rules; }
php
public function getRules() { $rules = [ static::FIRST_NAME => "required|max:100", static::LAST_NAME => "required|max:100", static::EMAIL => "required|max:100|email|unique:users,email,{$this->id},id", ]; if (!$this->id) { $rules[static::PWD_FIELD] = 'required|min:' . config('app.model.user.password.min', 6) . '|max:' . config('app.model.user.password.max', 20); } return $rules; }
[ "public", "function", "getRules", "(", ")", "{", "$", "rules", "=", "[", "static", "::", "FIRST_NAME", "=>", "\"required|max:100\"", ",", "static", "::", "LAST_NAME", "=>", "\"required|max:100\"", ",", "static", "::", "EMAIL", "=>", "\"required|max:100|email|unique:users,email,{$this->id},id\"", ",", "]", ";", "if", "(", "!", "$", "this", "->", "id", ")", "{", "$", "rules", "[", "static", "::", "PWD_FIELD", "]", "=", "'required|min:'", ".", "config", "(", "'app.model.user.password.min'", ",", "6", ")", ".", "'|max:'", ".", "config", "(", "'app.model.user.password.max'", ",", "20", ")", ";", "}", "return", "$", "rules", ";", "}" ]
Return array of rules for model validation @deprecated Declare rules in Form Request: https://laravel.com/docs/5.5/validation#form-request-validation @return array
[ "Return", "array", "of", "rules", "for", "model", "validation" ]
54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a
https://github.com/Saritasa/php-eloquent-custom/blob/54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a/src/Models/User.php#L161-L173
train
anime-db/catalog-bundle
src/Event/Listener/Entity/Downloader.php
Downloader.renameFile
protected function renameFile(EntityInterface $entity, $target) { if ($entity->getFilename() && strpos($entity->getFilename(), 'tmp') !== false) { $filename = $entity->getFilename(); $entity->setFilename($target.pathinfo($filename, PATHINFO_BASENAME)); $root = $this->root.$entity->getDownloadPath().'/'; $this->fs->copy($root.$filename, $root.$entity->getFilename(), true); } }
php
protected function renameFile(EntityInterface $entity, $target) { if ($entity->getFilename() && strpos($entity->getFilename(), 'tmp') !== false) { $filename = $entity->getFilename(); $entity->setFilename($target.pathinfo($filename, PATHINFO_BASENAME)); $root = $this->root.$entity->getDownloadPath().'/'; $this->fs->copy($root.$filename, $root.$entity->getFilename(), true); } }
[ "protected", "function", "renameFile", "(", "EntityInterface", "$", "entity", ",", "$", "target", ")", "{", "if", "(", "$", "entity", "->", "getFilename", "(", ")", "&&", "strpos", "(", "$", "entity", "->", "getFilename", "(", ")", ",", "'tmp'", ")", "!==", "false", ")", "{", "$", "filename", "=", "$", "entity", "->", "getFilename", "(", ")", ";", "$", "entity", "->", "setFilename", "(", "$", "target", ".", "pathinfo", "(", "$", "filename", ",", "PATHINFO_BASENAME", ")", ")", ";", "$", "root", "=", "$", "this", "->", "root", ".", "$", "entity", "->", "getDownloadPath", "(", ")", ".", "'/'", ";", "$", "this", "->", "fs", "->", "copy", "(", "$", "root", ".", "$", "filename", ",", "$", "root", ".", "$", "entity", "->", "getFilename", "(", ")", ",", "true", ")", ";", "}", "}" ]
Rename file, if it in the temp folder. @param EntityInterface $entity @param string $target
[ "Rename", "file", "if", "it", "in", "the", "temp", "folder", "." ]
631b6f92a654e91bee84f46218c52cf42bdb8606
https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Event/Listener/Entity/Downloader.php#L64-L72
train
stevenliebregt/crispysystem
src/CrispySystem.php
CrispySystem.handle
private function handle(Request $request) : Response { $router = $this->getInstance(Router::class); if ($router->match($request->getPathInfo(), $request->getMethod())) { // A match has been found /** @var Route $match */ $match = $router->getMatch(); // Check if the handler is a closure or not $handler = $match->getHandler(); if (is_object($handler) && $handler instanceof \Closure) { try { $content = $this->resolveClosure($handler); } catch (\Exception $e) { if (DEVELOPMENT) { showPlainError('Something went wrong while resolving a closure, details below:', false); pr($e); exit; } return $this->respond(500); } } else { $controller = substr($handler, 0, stripos($handler, '.')); $method = substr($handler, (stripos($handler, '.') + 1)); try { $instance = $this->getInstance($controller); if (method_exists($instance, 'setCrispySystem')) { $instance->setCrispySystem($this); } $content = $this->resolveMethod($instance, $method, $match->getParameters()); } catch (\Exception $e) { if (DEVELOPMENT) { showPlainError('Something went wrong while resolving a controller, details below:', false); pr($e); exit; } return $this->respond(500); } } return $this->respond(200, $content); } // No match found return $this->respond(404); }
php
private function handle(Request $request) : Response { $router = $this->getInstance(Router::class); if ($router->match($request->getPathInfo(), $request->getMethod())) { // A match has been found /** @var Route $match */ $match = $router->getMatch(); // Check if the handler is a closure or not $handler = $match->getHandler(); if (is_object($handler) && $handler instanceof \Closure) { try { $content = $this->resolveClosure($handler); } catch (\Exception $e) { if (DEVELOPMENT) { showPlainError('Something went wrong while resolving a closure, details below:', false); pr($e); exit; } return $this->respond(500); } } else { $controller = substr($handler, 0, stripos($handler, '.')); $method = substr($handler, (stripos($handler, '.') + 1)); try { $instance = $this->getInstance($controller); if (method_exists($instance, 'setCrispySystem')) { $instance->setCrispySystem($this); } $content = $this->resolveMethod($instance, $method, $match->getParameters()); } catch (\Exception $e) { if (DEVELOPMENT) { showPlainError('Something went wrong while resolving a controller, details below:', false); pr($e); exit; } return $this->respond(500); } } return $this->respond(200, $content); } // No match found return $this->respond(404); }
[ "private", "function", "handle", "(", "Request", "$", "request", ")", ":", "Response", "{", "$", "router", "=", "$", "this", "->", "getInstance", "(", "Router", "::", "class", ")", ";", "if", "(", "$", "router", "->", "match", "(", "$", "request", "->", "getPathInfo", "(", ")", ",", "$", "request", "->", "getMethod", "(", ")", ")", ")", "{", "// A match has been found", "/** @var Route $match */", "$", "match", "=", "$", "router", "->", "getMatch", "(", ")", ";", "// Check if the handler is a closure or not", "$", "handler", "=", "$", "match", "->", "getHandler", "(", ")", ";", "if", "(", "is_object", "(", "$", "handler", ")", "&&", "$", "handler", "instanceof", "\\", "Closure", ")", "{", "try", "{", "$", "content", "=", "$", "this", "->", "resolveClosure", "(", "$", "handler", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "DEVELOPMENT", ")", "{", "showPlainError", "(", "'Something went wrong while resolving a closure, details below:'", ",", "false", ")", ";", "pr", "(", "$", "e", ")", ";", "exit", ";", "}", "return", "$", "this", "->", "respond", "(", "500", ")", ";", "}", "}", "else", "{", "$", "controller", "=", "substr", "(", "$", "handler", ",", "0", ",", "stripos", "(", "$", "handler", ",", "'.'", ")", ")", ";", "$", "method", "=", "substr", "(", "$", "handler", ",", "(", "stripos", "(", "$", "handler", ",", "'.'", ")", "+", "1", ")", ")", ";", "try", "{", "$", "instance", "=", "$", "this", "->", "getInstance", "(", "$", "controller", ")", ";", "if", "(", "method_exists", "(", "$", "instance", ",", "'setCrispySystem'", ")", ")", "{", "$", "instance", "->", "setCrispySystem", "(", "$", "this", ")", ";", "}", "$", "content", "=", "$", "this", "->", "resolveMethod", "(", "$", "instance", ",", "$", "method", ",", "$", "match", "->", "getParameters", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "DEVELOPMENT", ")", "{", "showPlainError", "(", "'Something went wrong while resolving a controller, details below:'", ",", "false", ")", ";", "pr", "(", "$", "e", ")", ";", "exit", ";", "}", "return", "$", "this", "->", "respond", "(", "500", ")", ";", "}", "}", "return", "$", "this", "->", "respond", "(", "200", ",", "$", "content", ")", ";", "}", "// No match found", "return", "$", "this", "->", "respond", "(", "404", ")", ";", "}" ]
Turn a request into a response @param Request $request @return Response @since 1.0.0
[ "Turn", "a", "request", "into", "a", "response" ]
06547dae100dae1023a93ec903f2d2abacce9aec
https://github.com/stevenliebregt/crispysystem/blob/06547dae100dae1023a93ec903f2d2abacce9aec/src/CrispySystem.php#L75-L124
train
agentmedia/phine-core
src/Core/Logic/Tree/ContentTreeUtil.php
ContentTreeUtil.FirstChildOf
static function FirstChildOf (Content $content) { $provider = self::GetTreeProvider($content); if (!$provider) { return null; } $item = $provider->ItemByContent($content); return $provider->ContentByItem($provider->FirstChildOf($item)); }
php
static function FirstChildOf (Content $content) { $provider = self::GetTreeProvider($content); if (!$provider) { return null; } $item = $provider->ItemByContent($content); return $provider->ContentByItem($provider->FirstChildOf($item)); }
[ "static", "function", "FirstChildOf", "(", "Content", "$", "content", ")", "{", "$", "provider", "=", "self", "::", "GetTreeProvider", "(", "$", "content", ")", ";", "if", "(", "!", "$", "provider", ")", "{", "return", "null", ";", "}", "$", "item", "=", "$", "provider", "->", "ItemByContent", "(", "$", "content", ")", ";", "return", "$", "provider", "->", "ContentByItem", "(", "$", "provider", "->", "FirstChildOf", "(", "$", "item", ")", ")", ";", "}" ]
Returns the first child of the content @param Content $content The parent content @return Content Returns the first child in the tree
[ "Returns", "the", "first", "child", "of", "the", "content" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Tree/ContentTreeUtil.php#L54-L63
train
PhoxPHP/Console
src/Command.php
Command.hasCommand
public static function hasCommand(String $label) : Bool { return (isset(Command::$commands[$label])) ? true : false; }
php
public static function hasCommand(String $label) : Bool { return (isset(Command::$commands[$label])) ? true : false; }
[ "public", "static", "function", "hasCommand", "(", "String", "$", "label", ")", ":", "Bool", "{", "return", "(", "isset", "(", "Command", "::", "$", "commands", "[", "$", "label", "]", ")", ")", "?", "true", ":", "false", ";", "}" ]
Checks if a command is registered. @param $command <String> @access public @static @return <Boolean>
[ "Checks", "if", "a", "command", "is", "registered", "." ]
fee1238cfdb3592964bb5d5a2336e70b8ffd20e9
https://github.com/PhoxPHP/Console/blob/fee1238cfdb3592964bb5d5a2336e70b8ffd20e9/src/Command.php#L66-L69
train
PhoxPHP/Console
src/Command.php
Command.watchOutput
public function watchOutput() { $arguments = $_SERVER['argv']; unset($arguments[0]); $argumentsCount = $_SERVER['argc'] - 1; $arguments = array_values($arguments); if ($argumentsCount > 0) { $commandId = $arguments[0]; if (!Command::hasCommand($commandId)) { return $this->env->sendOutput(sprintf('[%s] is not a valid runnable id', $commandId), 'red'); } $command = Command::getCommandById($commandId); $runnableCmds = $command->runnableCommands(); if (isset($arguments[1])) { if (!isset($runnableCmds[$arguments[1]])) { return $this->error(sprintf('Command %s is an invalid command', $arguments[1]), 'red'); } unset($arguments[0]); } $arguments = array_values($arguments); if (count($arguments) > 0 && isset($runnableCmds[$arguments[0]])) { // Check number of arguments passed to command and validate. $commandArgumentLength = $runnableCmds[$arguments[0]]; // validate command with infinite arguments. if ($commandArgumentLength == ':i' && (count($arguments) - 1) == 0) { return $this->error(sprintf('[%s] command requires at least one argument', $arguments[0]), 'red'); } // validate command with no arguments. if ($commandArgumentLength == ':none' && (count($arguments) - 1) > 0) { return $this->error(sprintf('[%s] command may not accept any argument', $arguments[0]), 'red'); } if (is_integer($commandArgumentLength) && (count($arguments) - 1) > $commandArgumentLength) { $this->error(sprintf('[%s] command requires exactly [%d] argument(s)', $arguments[0], $commandArgumentLength)); } } return $command->run($arguments, $argumentsCount); } }
php
public function watchOutput() { $arguments = $_SERVER['argv']; unset($arguments[0]); $argumentsCount = $_SERVER['argc'] - 1; $arguments = array_values($arguments); if ($argumentsCount > 0) { $commandId = $arguments[0]; if (!Command::hasCommand($commandId)) { return $this->env->sendOutput(sprintf('[%s] is not a valid runnable id', $commandId), 'red'); } $command = Command::getCommandById($commandId); $runnableCmds = $command->runnableCommands(); if (isset($arguments[1])) { if (!isset($runnableCmds[$arguments[1]])) { return $this->error(sprintf('Command %s is an invalid command', $arguments[1]), 'red'); } unset($arguments[0]); } $arguments = array_values($arguments); if (count($arguments) > 0 && isset($runnableCmds[$arguments[0]])) { // Check number of arguments passed to command and validate. $commandArgumentLength = $runnableCmds[$arguments[0]]; // validate command with infinite arguments. if ($commandArgumentLength == ':i' && (count($arguments) - 1) == 0) { return $this->error(sprintf('[%s] command requires at least one argument', $arguments[0]), 'red'); } // validate command with no arguments. if ($commandArgumentLength == ':none' && (count($arguments) - 1) > 0) { return $this->error(sprintf('[%s] command may not accept any argument', $arguments[0]), 'red'); } if (is_integer($commandArgumentLength) && (count($arguments) - 1) > $commandArgumentLength) { $this->error(sprintf('[%s] command requires exactly [%d] argument(s)', $arguments[0], $commandArgumentLength)); } } return $command->run($arguments, $argumentsCount); } }
[ "public", "function", "watchOutput", "(", ")", "{", "$", "arguments", "=", "$", "_SERVER", "[", "'argv'", "]", ";", "unset", "(", "$", "arguments", "[", "0", "]", ")", ";", "$", "argumentsCount", "=", "$", "_SERVER", "[", "'argc'", "]", "-", "1", ";", "$", "arguments", "=", "array_values", "(", "$", "arguments", ")", ";", "if", "(", "$", "argumentsCount", ">", "0", ")", "{", "$", "commandId", "=", "$", "arguments", "[", "0", "]", ";", "if", "(", "!", "Command", "::", "hasCommand", "(", "$", "commandId", ")", ")", "{", "return", "$", "this", "->", "env", "->", "sendOutput", "(", "sprintf", "(", "'[%s] is not a valid runnable id'", ",", "$", "commandId", ")", ",", "'red'", ")", ";", "}", "$", "command", "=", "Command", "::", "getCommandById", "(", "$", "commandId", ")", ";", "$", "runnableCmds", "=", "$", "command", "->", "runnableCommands", "(", ")", ";", "if", "(", "isset", "(", "$", "arguments", "[", "1", "]", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "runnableCmds", "[", "$", "arguments", "[", "1", "]", "]", ")", ")", "{", "return", "$", "this", "->", "error", "(", "sprintf", "(", "'Command %s is an invalid command'", ",", "$", "arguments", "[", "1", "]", ")", ",", "'red'", ")", ";", "}", "unset", "(", "$", "arguments", "[", "0", "]", ")", ";", "}", "$", "arguments", "=", "array_values", "(", "$", "arguments", ")", ";", "if", "(", "count", "(", "$", "arguments", ")", ">", "0", "&&", "isset", "(", "$", "runnableCmds", "[", "$", "arguments", "[", "0", "]", "]", ")", ")", "{", "// Check number of arguments passed to command and validate.", "$", "commandArgumentLength", "=", "$", "runnableCmds", "[", "$", "arguments", "[", "0", "]", "]", ";", "// validate command with infinite arguments.", "if", "(", "$", "commandArgumentLength", "==", "':i'", "&&", "(", "count", "(", "$", "arguments", ")", "-", "1", ")", "==", "0", ")", "{", "return", "$", "this", "->", "error", "(", "sprintf", "(", "'[%s] command requires at least one argument'", ",", "$", "arguments", "[", "0", "]", ")", ",", "'red'", ")", ";", "}", "// validate command with no arguments.", "if", "(", "$", "commandArgumentLength", "==", "':none'", "&&", "(", "count", "(", "$", "arguments", ")", "-", "1", ")", ">", "0", ")", "{", "return", "$", "this", "->", "error", "(", "sprintf", "(", "'[%s] command may not accept any argument'", ",", "$", "arguments", "[", "0", "]", ")", ",", "'red'", ")", ";", "}", "if", "(", "is_integer", "(", "$", "commandArgumentLength", ")", "&&", "(", "count", "(", "$", "arguments", ")", "-", "1", ")", ">", "$", "commandArgumentLength", ")", "{", "$", "this", "->", "error", "(", "sprintf", "(", "'[%s] command requires exactly [%d] argument(s)'", ",", "$", "arguments", "[", "0", "]", ",", "$", "commandArgumentLength", ")", ")", ";", "}", "}", "return", "$", "command", "->", "run", "(", "$", "arguments", ",", "$", "argumentsCount", ")", ";", "}", "}" ]
Processes called command and returns it's output. @access public @return <void>
[ "Processes", "called", "command", "and", "returns", "it", "s", "output", "." ]
fee1238cfdb3592964bb5d5a2336e70b8ffd20e9
https://github.com/PhoxPHP/Console/blob/fee1238cfdb3592964bb5d5a2336e70b8ffd20e9/src/Command.php#L139-L187
train
PhoxPHP/Console
src/Command.php
Command.question
public function question(String $question) { $this->env->sendOutput($question); return $this->env->getOutputOption(); }
php
public function question(String $question) { $this->env->sendOutput($question); return $this->env->getOutputOption(); }
[ "public", "function", "question", "(", "String", "$", "question", ")", "{", "$", "this", "->", "env", "->", "sendOutput", "(", "$", "question", ")", ";", "return", "$", "this", "->", "env", "->", "getOutputOption", "(", ")", ";", "}" ]
Sends output to user as a question and returns response. @param $question <String> @access public @return <String>
[ "Sends", "output", "to", "user", "as", "a", "question", "and", "returns", "response", "." ]
fee1238cfdb3592964bb5d5a2336e70b8ffd20e9
https://github.com/PhoxPHP/Console/blob/fee1238cfdb3592964bb5d5a2336e70b8ffd20e9/src/Command.php#L196-L200
train
dmj/PicaRecord
src/HAB/Pica/Record/NestedRecord.php
NestedRecord.sort
public function sort () { parent::sort(); Helper::mapMethod($this->_records, 'sort'); usort($this->_records, array($this, 'compareRecords')); }
php
public function sort () { parent::sort(); Helper::mapMethod($this->_records, 'sort'); usort($this->_records, array($this, 'compareRecords')); }
[ "public", "function", "sort", "(", ")", "{", "parent", "::", "sort", "(", ")", ";", "Helper", "::", "mapMethod", "(", "$", "this", "->", "_records", ",", "'sort'", ")", ";", "usort", "(", "$", "this", "->", "_records", ",", "array", "(", "$", "this", ",", "'compareRecords'", ")", ")", ";", "}" ]
Sort fields and contained records. The sort() is propagated down to all contained records. In addition the nested records are sorted themselves using the implementing class' compareNestedRecords() function. @see Record::sort() @see NestedRecord::compareNestedRecords() @return void
[ "Sort", "fields", "and", "contained", "records", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/NestedRecord.php#L74-L79
train
dmj/PicaRecord
src/HAB/Pica/Record/NestedRecord.php
NestedRecord.isEmpty
public function isEmpty () { return parent::isEmpty() && Helper::every($this->_records, function (Record $record) { return $record->isEmpty(); }); }
php
public function isEmpty () { return parent::isEmpty() && Helper::every($this->_records, function (Record $record) { return $record->isEmpty(); }); }
[ "public", "function", "isEmpty", "(", ")", "{", "return", "parent", "::", "isEmpty", "(", ")", "&&", "Helper", "::", "every", "(", "$", "this", "->", "_records", ",", "function", "(", "Record", "$", "record", ")", "{", "return", "$", "record", "->", "isEmpty", "(", ")", ";", "}", ")", ";", "}" ]
Return true if the record is empty. A nested record is empty iff it contains no fields and no non-empty contained record. @return boolean
[ "Return", "true", "if", "the", "record", "is", "empty", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/NestedRecord.php#L89-L92
train
dmj/PicaRecord
src/HAB/Pica/Record/NestedRecord.php
NestedRecord.addRecord
protected function addRecord (Record $record) { if ($this->containsRecord($record)) { throw new InvalidArgumentException("{$this} already contains {$record}"); } $this->_records []= $record; }
php
protected function addRecord (Record $record) { if ($this->containsRecord($record)) { throw new InvalidArgumentException("{$this} already contains {$record}"); } $this->_records []= $record; }
[ "protected", "function", "addRecord", "(", "Record", "$", "record", ")", "{", "if", "(", "$", "this", "->", "containsRecord", "(", "$", "record", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"{$this} already contains {$record}\"", ")", ";", "}", "$", "this", "->", "_records", "[", "]", "=", "$", "record", ";", "}" ]
Add a record as a contained record. @throws InvalidArgumentException Record already contains the record @param Record $record Record to add @return void
[ "Add", "a", "record", "as", "a", "contained", "record", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/NestedRecord.php#L145-L151
train
dmj/PicaRecord
src/HAB/Pica/Record/NestedRecord.php
NestedRecord.removeRecord
protected function removeRecord (Record $record) { $index = array_search($record, $this->_records, true); if ($index === false) { throw new InvalidArgumentException("{$this} does not contain {$record}"); } unset($this->_records[$index]); }
php
protected function removeRecord (Record $record) { $index = array_search($record, $this->_records, true); if ($index === false) { throw new InvalidArgumentException("{$this} does not contain {$record}"); } unset($this->_records[$index]); }
[ "protected", "function", "removeRecord", "(", "Record", "$", "record", ")", "{", "$", "index", "=", "array_search", "(", "$", "record", ",", "$", "this", "->", "_records", ",", "true", ")", ";", "if", "(", "$", "index", "===", "false", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"{$this} does not contain {$record}\"", ")", ";", "}", "unset", "(", "$", "this", "->", "_records", "[", "$", "index", "]", ")", ";", "}" ]
Remove a contained record. @throws InvalidArgumentException Record does not contain the record @param Record $record Record to remove @return void
[ "Remove", "a", "contained", "record", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/NestedRecord.php#L161-L168
train
helsingborg-stad/better-post-UI
source/php/Components/Author.php
Author.alwaysShowAuthorMetabox
public function alwaysShowAuthorMetabox($hidden, $screen) { if ($screen->post_type != 'page') { return $hidden; } $hidden = array_filter($hidden, function ($item) { return $item != 'authordiv'; }); return $hidden; }
php
public function alwaysShowAuthorMetabox($hidden, $screen) { if ($screen->post_type != 'page') { return $hidden; } $hidden = array_filter($hidden, function ($item) { return $item != 'authordiv'; }); return $hidden; }
[ "public", "function", "alwaysShowAuthorMetabox", "(", "$", "hidden", ",", "$", "screen", ")", "{", "if", "(", "$", "screen", "->", "post_type", "!=", "'page'", ")", "{", "return", "$", "hidden", ";", "}", "$", "hidden", "=", "array_filter", "(", "$", "hidden", ",", "function", "(", "$", "item", ")", "{", "return", "$", "item", "!=", "'authordiv'", ";", "}", ")", ";", "return", "$", "hidden", ";", "}" ]
Display the author metabox by default @param array $hidden Hidden metaboxes before @param array $screen Screen args @return array Hidden metaboxes after
[ "Display", "the", "author", "metabox", "by", "default" ]
0454e8d6f42787244d02f0e976825ed8dca579f0
https://github.com/helsingborg-stad/better-post-UI/blob/0454e8d6f42787244d02f0e976825ed8dca579f0/source/php/Components/Author.php#L133-L144
train
kapitchi/KapitchiEntity
src/KapitchiEntity/Controller/EntityController.php
EntityController.getIndexUrl
public function getIndexUrl(array $params = array(), array $options = array()) { return $this->url()->fromRoute($this->getEvent()->getRouteMatch()->getMatchedRouteName(), array_merge(array('action' => 'index'), $params), $options ); }
php
public function getIndexUrl(array $params = array(), array $options = array()) { return $this->url()->fromRoute($this->getEvent()->getRouteMatch()->getMatchedRouteName(), array_merge(array('action' => 'index'), $params), $options ); }
[ "public", "function", "getIndexUrl", "(", "array", "$", "params", "=", "array", "(", ")", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "url", "(", ")", "->", "fromRoute", "(", "$", "this", "->", "getEvent", "(", ")", "->", "getRouteMatch", "(", ")", "->", "getMatchedRouteName", "(", ")", ",", "array_merge", "(", "array", "(", "'action'", "=>", "'index'", ")", ",", "$", "params", ")", ",", "$", "options", ")", ";", "}" ]
Default implementation of this method returns entity index URL using matched route name and setting action = 'index' If you have different routes set overwrite this method in your concrete controller
[ "Default", "implementation", "of", "this", "method", "returns", "entity", "index", "URL", "using", "matched", "route", "name", "and", "setting", "action", "=", "index", "If", "you", "have", "different", "routes", "set", "overwrite", "this", "method", "in", "your", "concrete", "controller" ]
69deaeb41d9133422a20ad6f64f0743d66cea8fd
https://github.com/kapitchi/KapitchiEntity/blob/69deaeb41d9133422a20ad6f64f0743d66cea8fd/src/KapitchiEntity/Controller/EntityController.php#L75-L81
train
kapitchi/KapitchiEntity
src/KapitchiEntity/Controller/EntityController.php
EntityController.setEventManager
public function setEventManager(EventManagerInterface $events) { $events->setIdentifiers(array( 'Zend\Stdlib\DispatchableInterface', 'Zend\Mvc\Controller\AbstractController', 'Zend\Mvc\Controller\AbstractActionController', __CLASS__, get_called_class(), $this->eventIdentifier, substr(get_called_class(), 0, strpos(get_called_class(), '\\')) )); $this->events = $events; $this->attachDefaultListeners(); return $this; }
php
public function setEventManager(EventManagerInterface $events) { $events->setIdentifiers(array( 'Zend\Stdlib\DispatchableInterface', 'Zend\Mvc\Controller\AbstractController', 'Zend\Mvc\Controller\AbstractActionController', __CLASS__, get_called_class(), $this->eventIdentifier, substr(get_called_class(), 0, strpos(get_called_class(), '\\')) )); $this->events = $events; $this->attachDefaultListeners(); return $this; }
[ "public", "function", "setEventManager", "(", "EventManagerInterface", "$", "events", ")", "{", "$", "events", "->", "setIdentifiers", "(", "array", "(", "'Zend\\Stdlib\\DispatchableInterface'", ",", "'Zend\\Mvc\\Controller\\AbstractController'", ",", "'Zend\\Mvc\\Controller\\AbstractActionController'", ",", "__CLASS__", ",", "get_called_class", "(", ")", ",", "$", "this", "->", "eventIdentifier", ",", "substr", "(", "get_called_class", "(", ")", ",", "0", ",", "strpos", "(", "get_called_class", "(", ")", ",", "'\\\\'", ")", ")", ")", ")", ";", "$", "this", "->", "events", "=", "$", "events", ";", "$", "this", "->", "attachDefaultListeners", "(", ")", ";", "return", "$", "this", ";", "}" ]
Adds all subclass identifiers @author Matus Zeman <[email protected]> @param EventManagerInterface $events @return AbstractController
[ "Adds", "all", "subclass", "identifiers" ]
69deaeb41d9133422a20ad6f64f0743d66cea8fd
https://github.com/kapitchi/KapitchiEntity/blob/69deaeb41d9133422a20ad6f64f0743d66cea8fd/src/KapitchiEntity/Controller/EntityController.php#L392-L408
train
siriusSupreme/sirius-broadcast
src/BroadcastManager.php
BroadcastManager.queue
public function queue($event) { $connection = $event instanceof ShouldBroadcastNow ? 'sync' : null; if (is_null($connection) && isset($event->connection)) { $connection = $event->connection; } $queue = null; if (method_exists($event, 'broadcastQueue')) { $queue = $event->broadcastQueue(); } elseif (isset($event->broadcastQueue)) { $queue = $event->broadcastQueue; } elseif (isset($event->queue)) { $queue = $event->queue; } $this->container->make('queue')->connection($connection)->pushOn( $queue, new BroadcastEvent(clone $event) ); }
php
public function queue($event) { $connection = $event instanceof ShouldBroadcastNow ? 'sync' : null; if (is_null($connection) && isset($event->connection)) { $connection = $event->connection; } $queue = null; if (method_exists($event, 'broadcastQueue')) { $queue = $event->broadcastQueue(); } elseif (isset($event->broadcastQueue)) { $queue = $event->broadcastQueue; } elseif (isset($event->queue)) { $queue = $event->queue; } $this->container->make('queue')->connection($connection)->pushOn( $queue, new BroadcastEvent(clone $event) ); }
[ "public", "function", "queue", "(", "$", "event", ")", "{", "$", "connection", "=", "$", "event", "instanceof", "ShouldBroadcastNow", "?", "'sync'", ":", "null", ";", "if", "(", "is_null", "(", "$", "connection", ")", "&&", "isset", "(", "$", "event", "->", "connection", ")", ")", "{", "$", "connection", "=", "$", "event", "->", "connection", ";", "}", "$", "queue", "=", "null", ";", "if", "(", "method_exists", "(", "$", "event", ",", "'broadcastQueue'", ")", ")", "{", "$", "queue", "=", "$", "event", "->", "broadcastQueue", "(", ")", ";", "}", "elseif", "(", "isset", "(", "$", "event", "->", "broadcastQueue", ")", ")", "{", "$", "queue", "=", "$", "event", "->", "broadcastQueue", ";", "}", "elseif", "(", "isset", "(", "$", "event", "->", "queue", ")", ")", "{", "$", "queue", "=", "$", "event", "->", "queue", ";", "}", "$", "this", "->", "container", "->", "make", "(", "'queue'", ")", "->", "connection", "(", "$", "connection", ")", "->", "pushOn", "(", "$", "queue", ",", "new", "BroadcastEvent", "(", "clone", "$", "event", ")", ")", ";", "}" ]
Queue the given event for broadcast. @param mixed $event @return void
[ "Queue", "the", "given", "event", "for", "broadcast", "." ]
d98f47973631dbb2da0296fd7066d1a70e9b30f7
https://github.com/siriusSupreme/sirius-broadcast/blob/d98f47973631dbb2da0296fd7066d1a70e9b30f7/src/BroadcastManager.php#L138-L159
train
zenodorus-tools/strings
src/Strings.php
Strings.safe
public static function safe(string $string, string $regex = self::SAFE) { if (preg_match($regex, $string)) : return $string; else : return false; endif; }
php
public static function safe(string $string, string $regex = self::SAFE) { if (preg_match($regex, $string)) : return $string; else : return false; endif; }
[ "public", "static", "function", "safe", "(", "string", "$", "string", ",", "string", "$", "regex", "=", "self", "::", "SAFE", ")", "{", "if", "(", "preg_match", "(", "$", "regex", ",", "$", "string", ")", ")", ":", "return", "$", "string", ";", "else", ":", "return", "false", ";", "endif", ";", "}" ]
Determine if a string contains any "bad" characters. It works by checking for the presence of ONLY "good" characters; not the presense of "bad" characters, which should make it more difficult to trick. @param string $string The string to check. @param string $regex (optional) Regex defining "safe" characters. @return string|bool Return $string if save, bool false if not.
[ "Determine", "if", "a", "string", "contains", "any", "bad", "characters", "." ]
5c98702ed2e3078169a3f2d4f12500cf630e5e6b
https://github.com/zenodorus-tools/strings/blob/5c98702ed2e3078169a3f2d4f12500cf630e5e6b/src/Strings.php#L19-L26
train
zenodorus-tools/strings
src/Strings.php
Strings.clean
public static function clean(string $string, string $replace = "", string $regex = self::CLEAN) { if ($replace === null) : $replace = ""; endif; if ($regex === null) : $regex = self::CLEAN; endif; return preg_replace($regex, $replace, $string); }
php
public static function clean(string $string, string $replace = "", string $regex = self::CLEAN) { if ($replace === null) : $replace = ""; endif; if ($regex === null) : $regex = self::CLEAN; endif; return preg_replace($regex, $replace, $string); }
[ "public", "static", "function", "clean", "(", "string", "$", "string", ",", "string", "$", "replace", "=", "\"\"", ",", "string", "$", "regex", "=", "self", "::", "CLEAN", ")", "{", "if", "(", "$", "replace", "===", "null", ")", ":", "$", "replace", "=", "\"\"", ";", "endif", ";", "if", "(", "$", "regex", "===", "null", ")", ":", "$", "regex", "=", "self", "::", "CLEAN", ";", "endif", ";", "return", "preg_replace", "(", "$", "regex", ",", "$", "replace", ",", "$", "string", ")", ";", "}" ]
Clean a string by removing any characters we don't want. @param string $string The string we're cleaning. @param string $replace What to replace "bad" characters with. @param string $regex (optional) The regex determing "good" characters. @return string
[ "Clean", "a", "string", "by", "removing", "any", "characters", "we", "don", "t", "want", "." ]
5c98702ed2e3078169a3f2d4f12500cf630e5e6b
https://github.com/zenodorus-tools/strings/blob/5c98702ed2e3078169a3f2d4f12500cf630e5e6b/src/Strings.php#L36-L46
train
zenodorus-tools/strings
src/Strings.php
Strings.replaceFirst
public static function replaceFirst(string $search, string $replace, string $subject) { $pos = strpos($subject, $search); if ($pos !== false) { return substr_replace($subject, $replace, $pos, strlen($search)); } return $subject; }
php
public static function replaceFirst(string $search, string $replace, string $subject) { $pos = strpos($subject, $search); if ($pos !== false) { return substr_replace($subject, $replace, $pos, strlen($search)); } return $subject; }
[ "public", "static", "function", "replaceFirst", "(", "string", "$", "search", ",", "string", "$", "replace", ",", "string", "$", "subject", ")", "{", "$", "pos", "=", "strpos", "(", "$", "subject", ",", "$", "search", ")", ";", "if", "(", "$", "pos", "!==", "false", ")", "{", "return", "substr_replace", "(", "$", "subject", ",", "$", "replace", ",", "$", "pos", ",", "strlen", "(", "$", "search", ")", ")", ";", "}", "return", "$", "subject", ";", "}" ]
Replace the first instance of a string in another string, if it exists. @param string $search The string being to be replaced. @param string $replace The string to replace $search with. @param string $subject The string that is being searched for $search. @return string If $search doesn't exist, this returns $subject unmodified.
[ "Replace", "the", "first", "instance", "of", "a", "string", "in", "another", "string", "if", "it", "exists", "." ]
5c98702ed2e3078169a3f2d4f12500cf630e5e6b
https://github.com/zenodorus-tools/strings/blob/5c98702ed2e3078169a3f2d4f12500cf630e5e6b/src/Strings.php#L57-L64
train
zenodorus-tools/strings
src/Strings.php
Strings.addNew
public static function addNew(string $add, string $existing, string $concatenateWith = ' ') { if (!strpos($existing, $add)) : return sprintf("%s%s%s", $existing, $concatenateWith, $add); endif; return $existing; }
php
public static function addNew(string $add, string $existing, string $concatenateWith = ' ') { if (!strpos($existing, $add)) : return sprintf("%s%s%s", $existing, $concatenateWith, $add); endif; return $existing; }
[ "public", "static", "function", "addNew", "(", "string", "$", "add", ",", "string", "$", "existing", ",", "string", "$", "concatenateWith", "=", "' '", ")", "{", "if", "(", "!", "strpos", "(", "$", "existing", ",", "$", "add", ")", ")", ":", "return", "sprintf", "(", "\"%s%s%s\"", ",", "$", "existing", ",", "$", "concatenateWith", ",", "$", "add", ")", ";", "endif", ";", "return", "$", "existing", ";", "}" ]
Concatenates a string to another string, if it isn't already a substring of it. @param string $add The string to be added. @param string $existing The existing string. @param string $concatenateWith (option) String to concatenate with. Defaults to ' '. @return string Returns concatenated string (if $add isn't a substring) and original string (if $add is a substring).
[ "Concatenates", "a", "string", "to", "another", "string", "if", "it", "isn", "t", "already", "a", "substring", "of", "it", "." ]
5c98702ed2e3078169a3f2d4f12500cf630e5e6b
https://github.com/zenodorus-tools/strings/blob/5c98702ed2e3078169a3f2d4f12500cf630e5e6b/src/Strings.php#L76-L83
train
Wedeto/DB
src/Query/LimitClause.php
LimitClause.toSQL
public function toSQL(Parameters $params, bool $inner_clause) { return "LIMIT " . $params->getDriver()->toSQL($params, $this->getLimit()); }
php
public function toSQL(Parameters $params, bool $inner_clause) { return "LIMIT " . $params->getDriver()->toSQL($params, $this->getLimit()); }
[ "public", "function", "toSQL", "(", "Parameters", "$", "params", ",", "bool", "$", "inner_clause", ")", "{", "return", "\"LIMIT \"", ".", "$", "params", "->", "getDriver", "(", ")", "->", "toSQL", "(", "$", "params", ",", "$", "this", "->", "getLimit", "(", ")", ")", ";", "}" ]
Write a LIMIT clause to SQL query syntax @param Parameters $params The query parameters: tables and placeholder values @param bool $inner_caluse Unused @return string The generated SQL
[ "Write", "a", "LIMIT", "clause", "to", "SQL", "query", "syntax" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/LimitClause.php#L60-L63
train
eureka-framework/component-template
src/Template/Pattern/PatternCollection.php
PatternCollection.add
public function add(PatternInterface $pattern) { $this->collection[$this->length] = $pattern; $this->length++; return $this; }
php
public function add(PatternInterface $pattern) { $this->collection[$this->length] = $pattern; $this->length++; return $this; }
[ "public", "function", "add", "(", "PatternInterface", "$", "pattern", ")", "{", "$", "this", "->", "collection", "[", "$", "this", "->", "length", "]", "=", "$", "pattern", ";", "$", "this", "->", "length", "++", ";", "return", "$", "this", ";", "}" ]
Add pattern object to the collection. @param PatternInterface $pattern @return self
[ "Add", "pattern", "object", "to", "the", "collection", "." ]
42e9b3954b79892ba340ba7ca909f03ee99c36fe
https://github.com/eureka-framework/component-template/blob/42e9b3954b79892ba340ba7ca909f03ee99c36fe/src/Template/Pattern/PatternCollection.php#L48-L54
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Exception/ODMException.php
ODMException.conversionFailedInvalidType
static public function conversionFailedInvalidType($value, $toType, array $possibleTypes) { $actualType = is_object($value) ? get_class($value) : gettype($value); if (is_scalar($value)) { return new self(sprintf( "Could not convert PHP value '%s' of type '%s' to type '%s'. Expected one of the following types: %s", $value, $actualType, $toType, implode(', ', $possibleTypes) )); } return new self(sprintf( "Could not convert PHP value of type '%s' to type '%s'. Expected one of the following types: %s", $actualType, $toType, implode(', ', $possibleTypes) )); }
php
static public function conversionFailedInvalidType($value, $toType, array $possibleTypes) { $actualType = is_object($value) ? get_class($value) : gettype($value); if (is_scalar($value)) { return new self(sprintf( "Could not convert PHP value '%s' of type '%s' to type '%s'. Expected one of the following types: %s", $value, $actualType, $toType, implode(', ', $possibleTypes) )); } return new self(sprintf( "Could not convert PHP value of type '%s' to type '%s'. Expected one of the following types: %s", $actualType, $toType, implode(', ', $possibleTypes) )); }
[ "static", "public", "function", "conversionFailedInvalidType", "(", "$", "value", ",", "$", "toType", ",", "array", "$", "possibleTypes", ")", "{", "$", "actualType", "=", "is_object", "(", "$", "value", ")", "?", "get_class", "(", "$", "value", ")", ":", "gettype", "(", "$", "value", ")", ";", "if", "(", "is_scalar", "(", "$", "value", ")", ")", "{", "return", "new", "self", "(", "sprintf", "(", "\"Could not convert PHP value '%s' of type '%s' to type '%s'. Expected one of the following types: %s\"", ",", "$", "value", ",", "$", "actualType", ",", "$", "toType", ",", "implode", "(", "', '", ",", "$", "possibleTypes", ")", ")", ")", ";", "}", "return", "new", "self", "(", "sprintf", "(", "\"Could not convert PHP value of type '%s' to type '%s'. Expected one of the following types: %s\"", ",", "$", "actualType", ",", "$", "toType", ",", "implode", "(", "', '", ",", "$", "possibleTypes", ")", ")", ")", ";", "}" ]
Thrown when the PHP value passed to the type converter was not of the expected type. @param mixed $value @param string $toType @param string[] $possibleTypes @return ODMException
[ "Thrown", "when", "the", "PHP", "value", "passed", "to", "the", "type", "converter", "was", "not", "of", "the", "expected", "type", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Exception/ODMException.php#L95-L115
train
phata/widgetfy
src/Utils/Dimension.php
Dimension.toAttr
public function toAttr($prefix='', $suffix='') { $attrs = array(); if ($this->width !== FALSE) { $attrs[] = 'width="'.addslashes($this->width).'"'; } if ($this->height !== FALSE) { $attrs[] = 'height="'.addslashes($this->height).'"'; } return $prefix.implode(' ', $attrs).$suffix; }
php
public function toAttr($prefix='', $suffix='') { $attrs = array(); if ($this->width !== FALSE) { $attrs[] = 'width="'.addslashes($this->width).'"'; } if ($this->height !== FALSE) { $attrs[] = 'height="'.addslashes($this->height).'"'; } return $prefix.implode(' ', $attrs).$suffix; }
[ "public", "function", "toAttr", "(", "$", "prefix", "=", "''", ",", "$", "suffix", "=", "''", ")", "{", "$", "attrs", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "width", "!==", "FALSE", ")", "{", "$", "attrs", "[", "]", "=", "'width=\"'", ".", "addslashes", "(", "$", "this", "->", "width", ")", ".", "'\"'", ";", "}", "if", "(", "$", "this", "->", "height", "!==", "FALSE", ")", "{", "$", "attrs", "[", "]", "=", "'height=\"'", ".", "addslashes", "(", "$", "this", "->", "height", ")", ".", "'\"'", ";", "}", "return", "$", "prefix", ".", "implode", "(", "' '", ",", "$", "attrs", ")", ".", "$", "suffix", ";", "}" ]
translate the current dimension data to attribute width="xxx" height="yyy" @return string HTML/XML attribute width and height
[ "translate", "the", "current", "dimension", "data", "to", "attribute", "width", "=", "xxx", "height", "=", "yyy" ]
00102c35ec5267b42c627f1e34b8e64a7dd3590c
https://github.com/phata/widgetfy/blob/00102c35ec5267b42c627f1e34b8e64a7dd3590c/src/Utils/Dimension.php#L309-L318
train
ddrv-test/firmapi-core
src/Core.php
Core.init
public function init($configArrayOrPathToConfig) { $config = include(dirname(__DIR__).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'default.php'); if (is_array($configArrayOrPathToConfig)) { $config = array_replace_recursive($config,$configArrayOrPathToConfig); } if (is_string($configArrayOrPathToConfig) && is_readable($configArrayOrPathToConfig)) { $config = array_replace_recursive($config,(array)include($configArrayOrPathToConfig)); } $this->config = $config; $this->connect = new Connection(); foreach ($this->config['connections'] as $connectionName=>$connectionConfig) { if (!isset($connectionConfig['type'])) continue; $method = 'set'.ucfirst($connectionConfig['type']); if (method_exists($this->connect,$method)) { $this->connect->$method($connectionName,$connectionConfig); } } $this->api = new Api(); return $this; }
php
public function init($configArrayOrPathToConfig) { $config = include(dirname(__DIR__).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'default.php'); if (is_array($configArrayOrPathToConfig)) { $config = array_replace_recursive($config,$configArrayOrPathToConfig); } if (is_string($configArrayOrPathToConfig) && is_readable($configArrayOrPathToConfig)) { $config = array_replace_recursive($config,(array)include($configArrayOrPathToConfig)); } $this->config = $config; $this->connect = new Connection(); foreach ($this->config['connections'] as $connectionName=>$connectionConfig) { if (!isset($connectionConfig['type'])) continue; $method = 'set'.ucfirst($connectionConfig['type']); if (method_exists($this->connect,$method)) { $this->connect->$method($connectionName,$connectionConfig); } } $this->api = new Api(); return $this; }
[ "public", "function", "init", "(", "$", "configArrayOrPathToConfig", ")", "{", "$", "config", "=", "include", "(", "dirname", "(", "__DIR__", ")", ".", "DIRECTORY_SEPARATOR", ".", "'config'", ".", "DIRECTORY_SEPARATOR", ".", "'default.php'", ")", ";", "if", "(", "is_array", "(", "$", "configArrayOrPathToConfig", ")", ")", "{", "$", "config", "=", "array_replace_recursive", "(", "$", "config", ",", "$", "configArrayOrPathToConfig", ")", ";", "}", "if", "(", "is_string", "(", "$", "configArrayOrPathToConfig", ")", "&&", "is_readable", "(", "$", "configArrayOrPathToConfig", ")", ")", "{", "$", "config", "=", "array_replace_recursive", "(", "$", "config", ",", "(", "array", ")", "include", "(", "$", "configArrayOrPathToConfig", ")", ")", ";", "}", "$", "this", "->", "config", "=", "$", "config", ";", "$", "this", "->", "connect", "=", "new", "Connection", "(", ")", ";", "foreach", "(", "$", "this", "->", "config", "[", "'connections'", "]", "as", "$", "connectionName", "=>", "$", "connectionConfig", ")", "{", "if", "(", "!", "isset", "(", "$", "connectionConfig", "[", "'type'", "]", ")", ")", "continue", ";", "$", "method", "=", "'set'", ".", "ucfirst", "(", "$", "connectionConfig", "[", "'type'", "]", ")", ";", "if", "(", "method_exists", "(", "$", "this", "->", "connect", ",", "$", "method", ")", ")", "{", "$", "this", "->", "connect", "->", "$", "method", "(", "$", "connectionName", ",", "$", "connectionConfig", ")", ";", "}", "}", "$", "this", "->", "api", "=", "new", "Api", "(", ")", ";", "return", "$", "this", ";", "}" ]
Init application with config @param array|string $configArrayOrPathToConfig @return $this
[ "Init", "application", "with", "config" ]
8f8843f0fb134568e7764cabd5039e15c579976d
https://github.com/ddrv-test/firmapi-core/blob/8f8843f0fb134568e7764cabd5039e15c579976d/src/Core.php#L111-L131
train
ddrv-test/firmapi-core
src/Core.php
Core.getAllowedMethods
public function getAllowedMethods($token) { $token = (string)$token; $array = (isset($this->config['tokens'][$token]))?$this->config['tokens'][$token]:array(); $allowed = array_merge_recursive( $this->config['tokens']['*'], $array ); $allowed = array_change_key_case($allowed); array_walk_recursive($allowed,function(&$value,$key){$value=mb_strtolower($value);}); return $allowed; }
php
public function getAllowedMethods($token) { $token = (string)$token; $array = (isset($this->config['tokens'][$token]))?$this->config['tokens'][$token]:array(); $allowed = array_merge_recursive( $this->config['tokens']['*'], $array ); $allowed = array_change_key_case($allowed); array_walk_recursive($allowed,function(&$value,$key){$value=mb_strtolower($value);}); return $allowed; }
[ "public", "function", "getAllowedMethods", "(", "$", "token", ")", "{", "$", "token", "=", "(", "string", ")", "$", "token", ";", "$", "array", "=", "(", "isset", "(", "$", "this", "->", "config", "[", "'tokens'", "]", "[", "$", "token", "]", ")", ")", "?", "$", "this", "->", "config", "[", "'tokens'", "]", "[", "$", "token", "]", ":", "array", "(", ")", ";", "$", "allowed", "=", "array_merge_recursive", "(", "$", "this", "->", "config", "[", "'tokens'", "]", "[", "'*'", "]", ",", "$", "array", ")", ";", "$", "allowed", "=", "array_change_key_case", "(", "$", "allowed", ")", ";", "array_walk_recursive", "(", "$", "allowed", ",", "function", "(", "&", "$", "value", ",", "$", "key", ")", "{", "$", "value", "=", "mb_strtolower", "(", "$", "value", ")", ";", "}", ")", ";", "return", "$", "allowed", ";", "}" ]
Return Allowed methods for token @param string $token @return array
[ "Return", "Allowed", "methods", "for", "token" ]
8f8843f0fb134568e7764cabd5039e15c579976d
https://github.com/ddrv-test/firmapi-core/blob/8f8843f0fb134568e7764cabd5039e15c579976d/src/Core.php#L139-L149
train
ddrv-test/firmapi-core
src/Core.php
Core.isAllow
public function isAllow($object,$method,$token) { $allowed = $this->getAllowedMethods($token); $object = mb_strtolower($object); $method = mb_strtolower($method); $allow = false; if ( (isset($allowed[$object]) && in_array($method,$allowed[$object])) || (isset($allowed[$object]) && in_array('*',$allowed[$object])) || (isset($allowed['*']) && in_array($method,$allowed['*'])) || (isset($allowed['*']) && in_array('*',$allowed['*'])) ) { $allow = true; }; return $allow; }
php
public function isAllow($object,$method,$token) { $allowed = $this->getAllowedMethods($token); $object = mb_strtolower($object); $method = mb_strtolower($method); $allow = false; if ( (isset($allowed[$object]) && in_array($method,$allowed[$object])) || (isset($allowed[$object]) && in_array('*',$allowed[$object])) || (isset($allowed['*']) && in_array($method,$allowed['*'])) || (isset($allowed['*']) && in_array('*',$allowed['*'])) ) { $allow = true; }; return $allow; }
[ "public", "function", "isAllow", "(", "$", "object", ",", "$", "method", ",", "$", "token", ")", "{", "$", "allowed", "=", "$", "this", "->", "getAllowedMethods", "(", "$", "token", ")", ";", "$", "object", "=", "mb_strtolower", "(", "$", "object", ")", ";", "$", "method", "=", "mb_strtolower", "(", "$", "method", ")", ";", "$", "allow", "=", "false", ";", "if", "(", "(", "isset", "(", "$", "allowed", "[", "$", "object", "]", ")", "&&", "in_array", "(", "$", "method", ",", "$", "allowed", "[", "$", "object", "]", ")", ")", "||", "(", "isset", "(", "$", "allowed", "[", "$", "object", "]", ")", "&&", "in_array", "(", "'*'", ",", "$", "allowed", "[", "$", "object", "]", ")", ")", "||", "(", "isset", "(", "$", "allowed", "[", "'*'", "]", ")", "&&", "in_array", "(", "$", "method", ",", "$", "allowed", "[", "'*'", "]", ")", ")", "||", "(", "isset", "(", "$", "allowed", "[", "'*'", "]", ")", "&&", "in_array", "(", "'*'", ",", "$", "allowed", "[", "'*'", "]", ")", ")", ")", "{", "$", "allow", "=", "true", ";", "}", ";", "return", "$", "allow", ";", "}" ]
Check for method allow @param string $object @param string $method @param string $token @return true
[ "Check", "for", "method", "allow" ]
8f8843f0fb134568e7764cabd5039e15c579976d
https://github.com/ddrv-test/firmapi-core/blob/8f8843f0fb134568e7764cabd5039e15c579976d/src/Core.php#L159-L175
train
ddrv-test/firmapi-core
src/Core.php
Core.getRepository
public function getRepository($repositoryName) { $repositoryName = (string)$repositoryName; if(!isset($this->config['repositories'][$repositoryName]['class'])) return false; $className = $this->config['repositories'][$repositoryName]['class']; if (!class_exists($className)) { return false; } $connectionName = isset($this->config['repositories'][$repositoryName]['connection'])?$this->config['repositories'][$repositoryName]['connection']:null; return new $className($connectionName); }
php
public function getRepository($repositoryName) { $repositoryName = (string)$repositoryName; if(!isset($this->config['repositories'][$repositoryName]['class'])) return false; $className = $this->config['repositories'][$repositoryName]['class']; if (!class_exists($className)) { return false; } $connectionName = isset($this->config['repositories'][$repositoryName]['connection'])?$this->config['repositories'][$repositoryName]['connection']:null; return new $className($connectionName); }
[ "public", "function", "getRepository", "(", "$", "repositoryName", ")", "{", "$", "repositoryName", "=", "(", "string", ")", "$", "repositoryName", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "'repositories'", "]", "[", "$", "repositoryName", "]", "[", "'class'", "]", ")", ")", "return", "false", ";", "$", "className", "=", "$", "this", "->", "config", "[", "'repositories'", "]", "[", "$", "repositoryName", "]", "[", "'class'", "]", ";", "if", "(", "!", "class_exists", "(", "$", "className", ")", ")", "{", "return", "false", ";", "}", "$", "connectionName", "=", "isset", "(", "$", "this", "->", "config", "[", "'repositories'", "]", "[", "$", "repositoryName", "]", "[", "'connection'", "]", ")", "?", "$", "this", "->", "config", "[", "'repositories'", "]", "[", "$", "repositoryName", "]", "[", "'connection'", "]", ":", "null", ";", "return", "new", "$", "className", "(", "$", "connectionName", ")", ";", "}" ]
Return repository object @param string $repositoryName @return mixed
[ "Return", "repository", "object" ]
8f8843f0fb134568e7764cabd5039e15c579976d
https://github.com/ddrv-test/firmapi-core/blob/8f8843f0fb134568e7764cabd5039e15c579976d/src/Core.php#L209-L219
train
Stinger-Soft/PhpCommons
src/StingerSoft/PhpCommons/String/Utils.php
Utils.startsWith
public static function startsWith($haystack, $needle) { if($needle === null && $haystack === null) return false; if($needle === null && $haystack !== null) return true; return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false; }
php
public static function startsWith($haystack, $needle) { if($needle === null && $haystack === null) return false; if($needle === null && $haystack !== null) return true; return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false; }
[ "public", "static", "function", "startsWith", "(", "$", "haystack", ",", "$", "needle", ")", "{", "if", "(", "$", "needle", "===", "null", "&&", "$", "haystack", "===", "null", ")", "return", "false", ";", "if", "(", "$", "needle", "===", "null", "&&", "$", "haystack", "!==", "null", ")", "return", "true", ";", "return", "$", "needle", "===", "\"\"", "||", "strrpos", "(", "$", "haystack", ",", "$", "needle", ",", "-", "strlen", "(", "$", "haystack", ")", ")", "!==", "false", ";", "}" ]
Checks if the haystack starts with needle @param string $haystack @param string $needle @return boolean
[ "Checks", "if", "the", "haystack", "starts", "with", "needle" ]
e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b
https://github.com/Stinger-Soft/PhpCommons/blob/e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b/src/StingerSoft/PhpCommons/String/Utils.php#L26-L32
train
Stinger-Soft/PhpCommons
src/StingerSoft/PhpCommons/String/Utils.php
Utils.endsWith
public static function endsWith($haystack, $needle) { if($needle === null && $haystack === null) return true; if($needle === null && $haystack !== null) return true; return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false); }
php
public static function endsWith($haystack, $needle) { if($needle === null && $haystack === null) return true; if($needle === null && $haystack !== null) return true; return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false); }
[ "public", "static", "function", "endsWith", "(", "$", "haystack", ",", "$", "needle", ")", "{", "if", "(", "$", "needle", "===", "null", "&&", "$", "haystack", "===", "null", ")", "return", "true", ";", "if", "(", "$", "needle", "===", "null", "&&", "$", "haystack", "!==", "null", ")", "return", "true", ";", "return", "$", "needle", "===", "\"\"", "||", "(", "(", "$", "temp", "=", "strlen", "(", "$", "haystack", ")", "-", "strlen", "(", "$", "needle", ")", ")", ">=", "0", "&&", "strpos", "(", "$", "haystack", ",", "$", "needle", ",", "$", "temp", ")", "!==", "false", ")", ";", "}" ]
Checks if the haystack ends with needle @param string $haystack @param string $needle @return boolean
[ "Checks", "if", "the", "haystack", "ends", "with", "needle" ]
e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b
https://github.com/Stinger-Soft/PhpCommons/blob/e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b/src/StingerSoft/PhpCommons/String/Utils.php#L41-L47
train
Stinger-Soft/PhpCommons
src/StingerSoft/PhpCommons/String/Utils.php
Utils.excerpt
public static function excerpt($text, $phrase, $radius = 100, $ending = "...") { $phrases = is_array($phrase) ? $phrase : array( $phrase ); $phraseLen = strlen(implode(' ', $phrases)); if($radius < $phraseLen) { $radius = $phraseLen; } foreach($phrases as $phrase) { $pos = strpos(strtolower($text), strtolower($phrase)); if($pos > -1) break; } $startPos = 0; if($pos > $radius) { $startPos = $pos - $radius; } $textLen = strlen($text); $endPos = $pos + $phraseLen + $radius; if($endPos >= $textLen) { $endPos = $textLen; } $excerpt = substr($text, $startPos, $endPos - $startPos); if($startPos != 0) { $excerpt = substr_replace($excerpt, $ending, 0, $phraseLen); } if($endPos != $textLen) { $excerpt = substr_replace($excerpt, $ending, -$phraseLen); } return $excerpt; }
php
public static function excerpt($text, $phrase, $radius = 100, $ending = "...") { $phrases = is_array($phrase) ? $phrase : array( $phrase ); $phraseLen = strlen(implode(' ', $phrases)); if($radius < $phraseLen) { $radius = $phraseLen; } foreach($phrases as $phrase) { $pos = strpos(strtolower($text), strtolower($phrase)); if($pos > -1) break; } $startPos = 0; if($pos > $radius) { $startPos = $pos - $radius; } $textLen = strlen($text); $endPos = $pos + $phraseLen + $radius; if($endPos >= $textLen) { $endPos = $textLen; } $excerpt = substr($text, $startPos, $endPos - $startPos); if($startPos != 0) { $excerpt = substr_replace($excerpt, $ending, 0, $phraseLen); } if($endPos != $textLen) { $excerpt = substr_replace($excerpt, $ending, -$phraseLen); } return $excerpt; }
[ "public", "static", "function", "excerpt", "(", "$", "text", ",", "$", "phrase", ",", "$", "radius", "=", "100", ",", "$", "ending", "=", "\"...\"", ")", "{", "$", "phrases", "=", "is_array", "(", "$", "phrase", ")", "?", "$", "phrase", ":", "array", "(", "$", "phrase", ")", ";", "$", "phraseLen", "=", "strlen", "(", "implode", "(", "' '", ",", "$", "phrases", ")", ")", ";", "if", "(", "$", "radius", "<", "$", "phraseLen", ")", "{", "$", "radius", "=", "$", "phraseLen", ";", "}", "foreach", "(", "$", "phrases", "as", "$", "phrase", ")", "{", "$", "pos", "=", "strpos", "(", "strtolower", "(", "$", "text", ")", ",", "strtolower", "(", "$", "phrase", ")", ")", ";", "if", "(", "$", "pos", ">", "-", "1", ")", "break", ";", "}", "$", "startPos", "=", "0", ";", "if", "(", "$", "pos", ">", "$", "radius", ")", "{", "$", "startPos", "=", "$", "pos", "-", "$", "radius", ";", "}", "$", "textLen", "=", "strlen", "(", "$", "text", ")", ";", "$", "endPos", "=", "$", "pos", "+", "$", "phraseLen", "+", "$", "radius", ";", "if", "(", "$", "endPos", ">=", "$", "textLen", ")", "{", "$", "endPos", "=", "$", "textLen", ";", "}", "$", "excerpt", "=", "substr", "(", "$", "text", ",", "$", "startPos", ",", "$", "endPos", "-", "$", "startPos", ")", ";", "if", "(", "$", "startPos", "!=", "0", ")", "{", "$", "excerpt", "=", "substr_replace", "(", "$", "excerpt", ",", "$", "ending", ",", "0", ",", "$", "phraseLen", ")", ";", "}", "if", "(", "$", "endPos", "!=", "$", "textLen", ")", "{", "$", "excerpt", "=", "substr_replace", "(", "$", "excerpt", ",", "$", "ending", ",", "-", "$", "phraseLen", ")", ";", "}", "return", "$", "excerpt", ";", "}" ]
Creates an excerpt from the given text based on the passed phrase @see http://stackoverflow.com/a/1404151 @param string $text The text to extract the excerpt from @param string|array $phrase The phrases to search for. @param number $radius The radius in characters to be included in the excerpt @param string $ending The string that should be appended after the excerpt @return string The created excerpt
[ "Creates", "an", "excerpt", "from", "the", "given", "text", "based", "on", "the", "passed", "phrase" ]
e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b
https://github.com/Stinger-Soft/PhpCommons/blob/e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b/src/StingerSoft/PhpCommons/String/Utils.php#L117-L155
train
Stinger-Soft/PhpCommons
src/StingerSoft/PhpCommons/String/Utils.php
Utils.hashCode
public static function hashCode($string) { // Code from https://stackoverflow.com/a/40688976/3918483 $hash = 0; if(!is_string($string)) { return $hash; } $len = mb_strlen($string, 'UTF-8'); if($len === 0) { return $hash; } for($i = 0; $i < $len; $i++) { $c = mb_substr($string, $i, 1, 'UTF-8'); $cc = unpack('V', iconv('UTF-8', 'UCS-4LE', $c))[1]; $hash = (($hash << 5) - $hash) + $cc; $hash &= $hash; // 16bit > 32bit } return $hash; }
php
public static function hashCode($string) { // Code from https://stackoverflow.com/a/40688976/3918483 $hash = 0; if(!is_string($string)) { return $hash; } $len = mb_strlen($string, 'UTF-8'); if($len === 0) { return $hash; } for($i = 0; $i < $len; $i++) { $c = mb_substr($string, $i, 1, 'UTF-8'); $cc = unpack('V', iconv('UTF-8', 'UCS-4LE', $c))[1]; $hash = (($hash << 5) - $hash) + $cc; $hash &= $hash; // 16bit > 32bit } return $hash; }
[ "public", "static", "function", "hashCode", "(", "$", "string", ")", "{", "// Code from https://stackoverflow.com/a/40688976/3918483", "$", "hash", "=", "0", ";", "if", "(", "!", "is_string", "(", "$", "string", ")", ")", "{", "return", "$", "hash", ";", "}", "$", "len", "=", "mb_strlen", "(", "$", "string", ",", "'UTF-8'", ")", ";", "if", "(", "$", "len", "===", "0", ")", "{", "return", "$", "hash", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "$", "c", "=", "mb_substr", "(", "$", "string", ",", "$", "i", ",", "1", ",", "'UTF-8'", ")", ";", "$", "cc", "=", "unpack", "(", "'V'", ",", "iconv", "(", "'UTF-8'", ",", "'UCS-4LE'", ",", "$", "c", ")", ")", "[", "1", "]", ";", "$", "hash", "=", "(", "(", "$", "hash", "<<", "5", ")", "-", "$", "hash", ")", "+", "$", "cc", ";", "$", "hash", "&=", "$", "hash", ";", "// 16bit > 32bit", "}", "return", "$", "hash", ";", "}" ]
Get an integer based hash code of the given string. @param string $string the string to be hashed @return int the hash code of the given string
[ "Get", "an", "integer", "based", "hash", "code", "of", "the", "given", "string", "." ]
e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b
https://github.com/Stinger-Soft/PhpCommons/blob/e1d7e2bb7b384fb9182903d3b6138aa3bbd05d9b/src/StingerSoft/PhpCommons/String/Utils.php#L199-L217
train
nemundo/core
src/Text/TextConvert.php
TextConvert.removeHtmlTag
static function removeHtmlTag($text) { $text = htmlspecialchars_decode($text); $text = html_entity_decode($text); $text = strip_tags($text); return $text; }
php
static function removeHtmlTag($text) { $text = htmlspecialchars_decode($text); $text = html_entity_decode($text); $text = strip_tags($text); return $text; }
[ "static", "function", "removeHtmlTag", "(", "$", "text", ")", "{", "$", "text", "=", "htmlspecialchars_decode", "(", "$", "text", ")", ";", "$", "text", "=", "html_entity_decode", "(", "$", "text", ")", ";", "$", "text", "=", "strip_tags", "(", "$", "text", ")", ";", "return", "$", "text", ";", "}" ]
Entfernt Html Tags und Umlaute @param $text @return string
[ "Entfernt", "Html", "Tags", "und", "Umlaute" ]
5ca14889fdfb9155b52fedb364b34502d14e21ed
https://github.com/nemundo/core/blob/5ca14889fdfb9155b52fedb364b34502d14e21ed/src/Text/TextConvert.php#L132-L140
train
dittertp/Puzzle
src/Puzzle/Serializer/DefaultSerializer.php
DefaultSerializer.serialize
public function serialize($data) { if (is_string($data) === true) { return $data; } else { $data = json_encode($data); if ($data === '[]') { return '{}'; } else { return $data; } } }
php
public function serialize($data) { if (is_string($data) === true) { return $data; } else { $data = json_encode($data); if ($data === '[]') { return '{}'; } else { return $data; } } }
[ "public", "function", "serialize", "(", "$", "data", ")", "{", "if", "(", "is_string", "(", "$", "data", ")", "===", "true", ")", "{", "return", "$", "data", ";", "}", "else", "{", "$", "data", "=", "json_encode", "(", "$", "data", ")", ";", "if", "(", "$", "data", "===", "'[]'", ")", "{", "return", "'{}'", ";", "}", "else", "{", "return", "$", "data", ";", "}", "}", "}" ]
Serialize assoc array into JSON string @param string|array $data Assoc array to encode into JSON @return string
[ "Serialize", "assoc", "array", "into", "JSON", "string" ]
cb3dfd64b0df8610c054dbb43b242fbf2cf668a0
https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Serializer/DefaultSerializer.php#L46-L60
train
dittertp/Puzzle
src/Puzzle/Serializer/DefaultSerializer.php
DefaultSerializer.deserialize
public function deserialize($data) { $result = json_decode($data, true); if ($result === null) { return $data; } return $result; }
php
public function deserialize($data) { $result = json_decode($data, true); if ($result === null) { return $data; } return $result; }
[ "public", "function", "deserialize", "(", "$", "data", ")", "{", "$", "result", "=", "json_decode", "(", "$", "data", ",", "true", ")", ";", "if", "(", "$", "result", "===", "null", ")", "{", "return", "$", "data", ";", "}", "return", "$", "result", ";", "}" ]
Deserialize JSON into an assoc array @param string $data JSON encoded string @return mixed
[ "Deserialize", "JSON", "into", "an", "assoc", "array" ]
cb3dfd64b0df8610c054dbb43b242fbf2cf668a0
https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Serializer/DefaultSerializer.php#L69-L76
train
Thruio/ActiveRecord
src/DatabaseLayer/Sql/GenericSql.php
GenericSql.process
public function process(DatabaseLayer\VirtualQuery $thing) { switch ($thing->getOperation()) { case 'Insert': //Create return $this->processInsert($thing); case 'Select': //Read return $this->processSelect($thing); case 'Update': //Update return $this->processUpdate($thing); case 'Delete': //Delete return $this->processDelete($thing); case 'Passthru': //Delete return $this->processPassthru($thing); default: throw new Exception("Operation {$thing->getOperation()} not supported"); } }
php
public function process(DatabaseLayer\VirtualQuery $thing) { switch ($thing->getOperation()) { case 'Insert': //Create return $this->processInsert($thing); case 'Select': //Read return $this->processSelect($thing); case 'Update': //Update return $this->processUpdate($thing); case 'Delete': //Delete return $this->processDelete($thing); case 'Passthru': //Delete return $this->processPassthru($thing); default: throw new Exception("Operation {$thing->getOperation()} not supported"); } }
[ "public", "function", "process", "(", "DatabaseLayer", "\\", "VirtualQuery", "$", "thing", ")", "{", "switch", "(", "$", "thing", "->", "getOperation", "(", ")", ")", "{", "case", "'Insert'", ":", "//Create", "return", "$", "this", "->", "processInsert", "(", "$", "thing", ")", ";", "case", "'Select'", ":", "//Read", "return", "$", "this", "->", "processSelect", "(", "$", "thing", ")", ";", "case", "'Update'", ":", "//Update", "return", "$", "this", "->", "processUpdate", "(", "$", "thing", ")", ";", "case", "'Delete'", ":", "//Delete", "return", "$", "this", "->", "processDelete", "(", "$", "thing", ")", ";", "case", "'Passthru'", ":", "//Delete", "return", "$", "this", "->", "processPassthru", "(", "$", "thing", ")", ";", "default", ":", "throw", "new", "Exception", "(", "\"Operation {$thing->getOperation()} not supported\"", ")", ";", "}", "}" ]
Turn a VirtualQuery into a SQL statement @param \Thru\ActiveRecord\DatabaseLayer\VirtualQuery $thing @return array|boolean @throws Exception
[ "Turn", "a", "VirtualQuery", "into", "a", "SQL", "statement" ]
90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461
https://github.com/Thruio/ActiveRecord/blob/90b0f838cd0e0fb7f3b56a0c38632ff08b3c3461/src/DatabaseLayer/Sql/GenericSql.php#L18-L39
train
devlabmtl/haven-web
Repository/PostRepository.php
PostRepository.findLastCreatedOnline
public function findLastCreatedOnline($qt) { $query_builder = $this->getBaseBuilder(); $this->FilterByTranslationStatus($query_builder, PostTranslation::STATUS_PUBLISHED); $query_builder // ->orderBy("p.created_at", "ASC") ->setMaxResults($qt); return $query_builder; }
php
public function findLastCreatedOnline($qt) { $query_builder = $this->getBaseBuilder(); $this->FilterByTranslationStatus($query_builder, PostTranslation::STATUS_PUBLISHED); $query_builder // ->orderBy("p.created_at", "ASC") ->setMaxResults($qt); return $query_builder; }
[ "public", "function", "findLastCreatedOnline", "(", "$", "qt", ")", "{", "$", "query_builder", "=", "$", "this", "->", "getBaseBuilder", "(", ")", ";", "$", "this", "->", "FilterByTranslationStatus", "(", "$", "query_builder", ",", "PostTranslation", "::", "STATUS_PUBLISHED", ")", ";", "$", "query_builder", "// ->orderBy(\"p.created_at\", \"ASC\")", "->", "setMaxResults", "(", "$", "qt", ")", ";", "return", "$", "query_builder", ";", "}" ]
Return a query for last crated post. @param boolean $return_qb @param \Doctrine\ORM\QueryBuilder $query_builder @return type
[ "Return", "a", "query", "for", "last", "crated", "post", "." ]
0d091bc5a8bda4c78c07a11be3525b88781b993a
https://github.com/devlabmtl/haven-web/blob/0d091bc5a8bda4c78c07a11be3525b88781b993a/Repository/PostRepository.php#L37-L46
train
ContaoDMS/dms-FileTypeSets
system/modules/DocumentManagementSystemFileTypeSets/classes/DmsFileTypeSetsModificator.php
DmsFileTypeSetsModificator.addFileTypeSetsToCategory
public function addFileTypeSetsToCategory(\Category $category, $dbResultCategory) { $arrFileTypesOfSets = array(); $arrFileTypeSetIds = deserialize($dbResultCategory->file_type_sets); if (!empty($arrFileTypeSetIds)) { foreach($arrFileTypeSetIds as $arrFileTypeSetId) { $arrFileTypesOfSets = array_merge($arrFileTypesOfSets, explode(",", $this->arrPublishedFileTypeSets[$arrFileTypeSetId])); } } $arrFileTypes = \DmsUtils::getUniqueFileTypes($category->fileTypes, $arrFileTypesOfSets); $category->fileTypes = implode(",", $arrFileTypes); return $category; }
php
public function addFileTypeSetsToCategory(\Category $category, $dbResultCategory) { $arrFileTypesOfSets = array(); $arrFileTypeSetIds = deserialize($dbResultCategory->file_type_sets); if (!empty($arrFileTypeSetIds)) { foreach($arrFileTypeSetIds as $arrFileTypeSetId) { $arrFileTypesOfSets = array_merge($arrFileTypesOfSets, explode(",", $this->arrPublishedFileTypeSets[$arrFileTypeSetId])); } } $arrFileTypes = \DmsUtils::getUniqueFileTypes($category->fileTypes, $arrFileTypesOfSets); $category->fileTypes = implode(",", $arrFileTypes); return $category; }
[ "public", "function", "addFileTypeSetsToCategory", "(", "\\", "Category", "$", "category", ",", "$", "dbResultCategory", ")", "{", "$", "arrFileTypesOfSets", "=", "array", "(", ")", ";", "$", "arrFileTypeSetIds", "=", "deserialize", "(", "$", "dbResultCategory", "->", "file_type_sets", ")", ";", "if", "(", "!", "empty", "(", "$", "arrFileTypeSetIds", ")", ")", "{", "foreach", "(", "$", "arrFileTypeSetIds", "as", "$", "arrFileTypeSetId", ")", "{", "$", "arrFileTypesOfSets", "=", "array_merge", "(", "$", "arrFileTypesOfSets", ",", "explode", "(", "\",\"", ",", "$", "this", "->", "arrPublishedFileTypeSets", "[", "$", "arrFileTypeSetId", "]", ")", ")", ";", "}", "}", "$", "arrFileTypes", "=", "\\", "DmsUtils", "::", "getUniqueFileTypes", "(", "$", "category", "->", "fileTypes", ",", "$", "arrFileTypesOfSets", ")", ";", "$", "category", "->", "fileTypes", "=", "implode", "(", "\",\"", ",", "$", "arrFileTypes", ")", ";", "return", "$", "category", ";", "}" ]
Modify loaded categories.
[ "Modify", "loaded", "categories", "." ]
7a88a5d5d3e9e0cbfab442944d4199ec135f67b6
https://github.com/ContaoDMS/dms-FileTypeSets/blob/7a88a5d5d3e9e0cbfab442944d4199ec135f67b6/system/modules/DocumentManagementSystemFileTypeSets/classes/DmsFileTypeSetsModificator.php#L88-L105
train
geoffadams/bedrest-core
library/BedRest/Rest/Request/Request.php
Request.setMethod
public function setMethod($method = null) { if ($method === null) { $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null; } $this->method = $method; }
php
public function setMethod($method = null) { if ($method === null) { $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null; } $this->method = $method; }
[ "public", "function", "setMethod", "(", "$", "method", "=", "null", ")", "{", "if", "(", "$", "method", "===", "null", ")", "{", "$", "method", "=", "isset", "(", "$", "_SERVER", "[", "'REQUEST_METHOD'", "]", ")", "?", "$", "_SERVER", "[", "'REQUEST_METHOD'", "]", ":", "null", ";", "}", "$", "this", "->", "method", "=", "$", "method", ";", "}" ]
Sets the HTTP method of the request. If the provided value is null, it is automatically detected from the environment. @param string $method
[ "Sets", "the", "HTTP", "method", "of", "the", "request", ".", "If", "the", "provided", "value", "is", "null", "it", "is", "automatically", "detected", "from", "the", "environment", "." ]
a77bf8b7492dfbfb720b201f7ec91a4f03417b5c
https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Rest/Request/Request.php#L111-L118
train
geoffadams/bedrest-core
library/BedRest/Rest/Request/Request.php
Request.getParameter
public function getParameter($parameter, $default = null) { if (!isset($this->parameters[$parameter])) { return $default; } return $this->parameters[$parameter]; }
php
public function getParameter($parameter, $default = null) { if (!isset($this->parameters[$parameter])) { return $default; } return $this->parameters[$parameter]; }
[ "public", "function", "getParameter", "(", "$", "parameter", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "parameters", "[", "$", "parameter", "]", ")", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "parameters", "[", "$", "parameter", "]", ";", "}" ]
Returns the value of a single query string parameter. @param string $parameter @param mixed $default @return mixed
[ "Returns", "the", "value", "of", "a", "single", "query", "string", "parameter", "." ]
a77bf8b7492dfbfb720b201f7ec91a4f03417b5c
https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Rest/Request/Request.php#L153-L160
train
geoffadams/bedrest-core
library/BedRest/Rest/Request/Request.php
Request.setContentType
public function setContentType($contentType = null) { if ($contentType === null) { $contentType = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : null; } $this->contentType = $contentType; }
php
public function setContentType($contentType = null) { if ($contentType === null) { $contentType = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : null; } $this->contentType = $contentType; }
[ "public", "function", "setContentType", "(", "$", "contentType", "=", "null", ")", "{", "if", "(", "$", "contentType", "===", "null", ")", "{", "$", "contentType", "=", "isset", "(", "$", "_SERVER", "[", "'CONTENT_TYPE'", "]", ")", "?", "$", "_SERVER", "[", "'CONTENT_TYPE'", "]", ":", "null", ";", "}", "$", "this", "->", "contentType", "=", "$", "contentType", ";", "}" ]
Sets the content type of the request content. If the provided value is null, it is automatically detected from the environment. @param string $contentType
[ "Sets", "the", "content", "type", "of", "the", "request", "content", ".", "If", "the", "provided", "value", "is", "null", "it", "is", "automatically", "detected", "from", "the", "environment", "." ]
a77bf8b7492dfbfb720b201f7ec91a4f03417b5c
https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Rest/Request/Request.php#L195-L202
train
squareproton/Bond
src/Bond/Exception/BadTypeException.php
BadTypeException.getVarForDisplay
public function getVarForDisplay() { if( is_object( $this->var ) ) { $output = "object ". get_class( $this->var ); } elseif( is_string( $this->var ) or is_array( $this->var ) ) { $type = is_string( $this->var ) ? 'string' : 'array'; $working = json_encode($this->var); $length = strlen( $working ); if( $length > 50 ) { $output = sprintf( "%s %s ... %s chars ommited", $type, substr( $working, 0, 40 ), $length - 40 ); } else { $output = "{$type} {$working}"; } } elseif( is_null( $this->var ) ) { $output = "NULL"; } elseif( is_bool( $this->var ) ) { $output = $this->var ? "TRUE" : "FALSE"; } elseif( is_int( $this->var ) ) { $output = "int {$this->var}"; } elseif( is_float( $this->var ) ) { $output = "float {$this->var}"; } elseif( is_resource( $this->var ) ) { $output = "resource `" .get_resource_type( $this->var ) . "`"; } else { $output = print_r( $this->var, true ); } return $output; }
php
public function getVarForDisplay() { if( is_object( $this->var ) ) { $output = "object ". get_class( $this->var ); } elseif( is_string( $this->var ) or is_array( $this->var ) ) { $type = is_string( $this->var ) ? 'string' : 'array'; $working = json_encode($this->var); $length = strlen( $working ); if( $length > 50 ) { $output = sprintf( "%s %s ... %s chars ommited", $type, substr( $working, 0, 40 ), $length - 40 ); } else { $output = "{$type} {$working}"; } } elseif( is_null( $this->var ) ) { $output = "NULL"; } elseif( is_bool( $this->var ) ) { $output = $this->var ? "TRUE" : "FALSE"; } elseif( is_int( $this->var ) ) { $output = "int {$this->var}"; } elseif( is_float( $this->var ) ) { $output = "float {$this->var}"; } elseif( is_resource( $this->var ) ) { $output = "resource `" .get_resource_type( $this->var ) . "`"; } else { $output = print_r( $this->var, true ); } return $output; }
[ "public", "function", "getVarForDisplay", "(", ")", "{", "if", "(", "is_object", "(", "$", "this", "->", "var", ")", ")", "{", "$", "output", "=", "\"object \"", ".", "get_class", "(", "$", "this", "->", "var", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "this", "->", "var", ")", "or", "is_array", "(", "$", "this", "->", "var", ")", ")", "{", "$", "type", "=", "is_string", "(", "$", "this", "->", "var", ")", "?", "'string'", ":", "'array'", ";", "$", "working", "=", "json_encode", "(", "$", "this", "->", "var", ")", ";", "$", "length", "=", "strlen", "(", "$", "working", ")", ";", "if", "(", "$", "length", ">", "50", ")", "{", "$", "output", "=", "sprintf", "(", "\"%s %s ... %s chars ommited\"", ",", "$", "type", ",", "substr", "(", "$", "working", ",", "0", ",", "40", ")", ",", "$", "length", "-", "40", ")", ";", "}", "else", "{", "$", "output", "=", "\"{$type} {$working}\"", ";", "}", "}", "elseif", "(", "is_null", "(", "$", "this", "->", "var", ")", ")", "{", "$", "output", "=", "\"NULL\"", ";", "}", "elseif", "(", "is_bool", "(", "$", "this", "->", "var", ")", ")", "{", "$", "output", "=", "$", "this", "->", "var", "?", "\"TRUE\"", ":", "\"FALSE\"", ";", "}", "elseif", "(", "is_int", "(", "$", "this", "->", "var", ")", ")", "{", "$", "output", "=", "\"int {$this->var}\"", ";", "}", "elseif", "(", "is_float", "(", "$", "this", "->", "var", ")", ")", "{", "$", "output", "=", "\"float {$this->var}\"", ";", "}", "elseif", "(", "is_resource", "(", "$", "this", "->", "var", ")", ")", "{", "$", "output", "=", "\"resource `\"", ".", "get_resource_type", "(", "$", "this", "->", "var", ")", ".", "\"`\"", ";", "}", "else", "{", "$", "output", "=", "print_r", "(", "$", "this", "->", "var", ",", "true", ")", ";", "}", "return", "$", "output", ";", "}" ]
Get a human readable representation of the passed varibale @return string
[ "Get", "a", "human", "readable", "representation", "of", "the", "passed", "varibale" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Exception/BadTypeException.php#L45-L80
train
ezra-obiwale/dSCore
src/Form/AValidator.php
AValidator.addFilters
final public function addFilters($elementName, array $filters) { $this->elements[$elementName]->filters->add($filters); return $this; }
php
final public function addFilters($elementName, array $filters) { $this->elements[$elementName]->filters->add($filters); return $this; }
[ "final", "public", "function", "addFilters", "(", "$", "elementName", ",", "array", "$", "filters", ")", "{", "$", "this", "->", "elements", "[", "$", "elementName", "]", "->", "filters", "->", "add", "(", "$", "filters", ")", ";", "return", "$", "this", ";", "}" ]
Add filters to specified element @param string $elementName @param array $filters @return \DScribe\Form\AValidator
[ "Add", "filters", "to", "specified", "element" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/AValidator.php#L50-L53
train
ezra-obiwale/dSCore
src/Form/AValidator.php
AValidator.validate
private function validate() { $filterer = new Filterer(); $valid = true; foreach ($this->elements as $element) { if (!$element->validate($filterer, $this->data)) $valid = false; $this->data[$element->name] = ($element->type === 'fieldset') ? $element->options->value->getData(true) : $element->data; } $this->valid = $valid; return $valid; }
php
private function validate() { $filterer = new Filterer(); $valid = true; foreach ($this->elements as $element) { if (!$element->validate($filterer, $this->data)) $valid = false; $this->data[$element->name] = ($element->type === 'fieldset') ? $element->options->value->getData(true) : $element->data; } $this->valid = $valid; return $valid; }
[ "private", "function", "validate", "(", ")", "{", "$", "filterer", "=", "new", "Filterer", "(", ")", ";", "$", "valid", "=", "true", ";", "foreach", "(", "$", "this", "->", "elements", "as", "$", "element", ")", "{", "if", "(", "!", "$", "element", "->", "validate", "(", "$", "filterer", ",", "$", "this", "->", "data", ")", ")", "$", "valid", "=", "false", ";", "$", "this", "->", "data", "[", "$", "element", "->", "name", "]", "=", "(", "$", "element", "->", "type", "===", "'fieldset'", ")", "?", "$", "element", "->", "options", "->", "value", "->", "getData", "(", "true", ")", ":", "$", "element", "->", "data", ";", "}", "$", "this", "->", "valid", "=", "$", "valid", ";", "return", "$", "valid", ";", "}" ]
Validates the data @return boolean
[ "Validates", "the", "data" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/AValidator.php#L59-L70
train
rollerworks/search-core
SearchConditionBuilder.php
SearchConditionBuilder.group
public function group(string $logical = ValuesGroup::GROUP_LOGICAL_AND): self { $builder = new self($logical, $this->fieldSet, $this); $this->valuesGroup->addGroup($builder->getGroup()); return $builder; }
php
public function group(string $logical = ValuesGroup::GROUP_LOGICAL_AND): self { $builder = new self($logical, $this->fieldSet, $this); $this->valuesGroup->addGroup($builder->getGroup()); return $builder; }
[ "public", "function", "group", "(", "string", "$", "logical", "=", "ValuesGroup", "::", "GROUP_LOGICAL_AND", ")", ":", "self", "{", "$", "builder", "=", "new", "self", "(", "$", "logical", ",", "$", "this", "->", "fieldSet", ",", "$", "this", ")", ";", "$", "this", "->", "valuesGroup", "->", "addGroup", "(", "$", "builder", "->", "getGroup", "(", ")", ")", ";", "return", "$", "builder", ";", "}" ]
Create a new ValuesGroup and returns the object instance. Afterwards the group can be expended with fields or subgroups: ``` ->group() ->field('name') ->... ->end() // return back to the ValuesGroup. ->end() // return back to the parent ValuesGroup ``` @param string $logical eg. one of the following ValuesGroup class constants value: GROUP_LOGICAL_OR or GROUP_LOGICAL_AND
[ "Create", "a", "new", "ValuesGroup", "and", "returns", "the", "object", "instance", "." ]
6b5671b8c4d6298906ded768261b0a59845140fb
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/SearchConditionBuilder.php#L59-L65
train
rollerworks/search-core
SearchConditionBuilder.php
SearchConditionBuilder.getSearchCondition
public function getSearchCondition(): SearchCondition { if ($this->parent) { return $this->parent->getSearchCondition(); } // This the root of the condition so now traverse back up the hierarchy. // We need to re-create the condition using actual objects. $rootValuesGroup = new ValuesGroup($this->valuesGroup->getGroupLogical()); $this->normalizeValueGroup($this->valuesGroup, $rootValuesGroup); return new SearchCondition($this->fieldSet, $rootValuesGroup); }
php
public function getSearchCondition(): SearchCondition { if ($this->parent) { return $this->parent->getSearchCondition(); } // This the root of the condition so now traverse back up the hierarchy. // We need to re-create the condition using actual objects. $rootValuesGroup = new ValuesGroup($this->valuesGroup->getGroupLogical()); $this->normalizeValueGroup($this->valuesGroup, $rootValuesGroup); return new SearchCondition($this->fieldSet, $rootValuesGroup); }
[ "public", "function", "getSearchCondition", "(", ")", ":", "SearchCondition", "{", "if", "(", "$", "this", "->", "parent", ")", "{", "return", "$", "this", "->", "parent", "->", "getSearchCondition", "(", ")", ";", "}", "// This the root of the condition so now traverse back up the hierarchy.", "// We need to re-create the condition using actual objects.", "$", "rootValuesGroup", "=", "new", "ValuesGroup", "(", "$", "this", "->", "valuesGroup", "->", "getGroupLogical", "(", ")", ")", ";", "$", "this", "->", "normalizeValueGroup", "(", "$", "this", "->", "valuesGroup", ",", "$", "rootValuesGroup", ")", ";", "return", "new", "SearchCondition", "(", "$", "this", "->", "fieldSet", ",", "$", "rootValuesGroup", ")", ";", "}" ]
Build the SearchCondition object using the groups and fields.
[ "Build", "the", "SearchCondition", "object", "using", "the", "groups", "and", "fields", "." ]
6b5671b8c4d6298906ded768261b0a59845140fb
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/SearchConditionBuilder.php#L113-L125
train
SCLInternet/SclZfGenericMapper
src/SclZfGenericMapper/CommonMapperMethodsTrait.php
CommonMapperMethodsTrait.create
public function create() { $entityClass = $this->getEntityName(); $reflection = new \ReflectionClass($entityClass); if ($reflection->isAbstract()) { throw RuntimeException::createAbstract($entityClass); } return new $entityClass(); }
php
public function create() { $entityClass = $this->getEntityName(); $reflection = new \ReflectionClass($entityClass); if ($reflection->isAbstract()) { throw RuntimeException::createAbstract($entityClass); } return new $entityClass(); }
[ "public", "function", "create", "(", ")", "{", "$", "entityClass", "=", "$", "this", "->", "getEntityName", "(", ")", ";", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "entityClass", ")", ";", "if", "(", "$", "reflection", "->", "isAbstract", "(", ")", ")", "{", "throw", "RuntimeException", "::", "createAbstract", "(", "$", "entityClass", ")", ";", "}", "return", "new", "$", "entityClass", "(", ")", ";", "}" ]
Creates an instance of the entity. @return object @throws RuntimeException If prototype has not yet been set.
[ "Creates", "an", "instance", "of", "the", "entity", "." ]
c61c61546bfbc07e9c9a4b425e8e02fd7182d80b
https://github.com/SCLInternet/SclZfGenericMapper/blob/c61c61546bfbc07e9c9a4b425e8e02fd7182d80b/src/SclZfGenericMapper/CommonMapperMethodsTrait.php#L35-L46
train
SCLInternet/SclZfGenericMapper
src/SclZfGenericMapper/CommonMapperMethodsTrait.php
CommonMapperMethodsTrait.singleEntity
protected function singleEntity($entity) { if (empty($entity)) { return null; } $singleEntity = $entity; if (is_array($entity)) { if (count($entity) > 1) { throw RuntimeException::multipleResultsFound(); } $singleEntity = reset($entity); } $entityClass = $this->getEntityName(); if (!$singleEntity instanceof $entityClass) { throw InvalidArgumentException::invalidEntityType( $this->getEntityName(), $singleEntity ); } return $singleEntity; }
php
protected function singleEntity($entity) { if (empty($entity)) { return null; } $singleEntity = $entity; if (is_array($entity)) { if (count($entity) > 1) { throw RuntimeException::multipleResultsFound(); } $singleEntity = reset($entity); } $entityClass = $this->getEntityName(); if (!$singleEntity instanceof $entityClass) { throw InvalidArgumentException::invalidEntityType( $this->getEntityName(), $singleEntity ); } return $singleEntity; }
[ "protected", "function", "singleEntity", "(", "$", "entity", ")", "{", "if", "(", "empty", "(", "$", "entity", ")", ")", "{", "return", "null", ";", "}", "$", "singleEntity", "=", "$", "entity", ";", "if", "(", "is_array", "(", "$", "entity", ")", ")", "{", "if", "(", "count", "(", "$", "entity", ")", ">", "1", ")", "{", "throw", "RuntimeException", "::", "multipleResultsFound", "(", ")", ";", "}", "$", "singleEntity", "=", "reset", "(", "$", "entity", ")", ";", "}", "$", "entityClass", "=", "$", "this", "->", "getEntityName", "(", ")", ";", "if", "(", "!", "$", "singleEntity", "instanceof", "$", "entityClass", ")", "{", "throw", "InvalidArgumentException", "::", "invalidEntityType", "(", "$", "this", "->", "getEntityName", "(", ")", ",", "$", "singleEntity", ")", ";", "}", "return", "$", "singleEntity", ";", "}" ]
Makes sure a result contains a single result. @param array|null|object entity @return object|null @throws RuntimeException If mulitple entities are found in the array. @throws InvalidArgumentException If the object is not an entity.
[ "Makes", "sure", "a", "result", "contains", "a", "single", "result", "." ]
c61c61546bfbc07e9c9a4b425e8e02fd7182d80b
https://github.com/SCLInternet/SclZfGenericMapper/blob/c61c61546bfbc07e9c9a4b425e8e02fd7182d80b/src/SclZfGenericMapper/CommonMapperMethodsTrait.php#L74-L100
train
SCLInternet/SclZfGenericMapper
src/SclZfGenericMapper/CommonMapperMethodsTrait.php
CommonMapperMethodsTrait.checkIsEntity
public function checkIsEntity($object) { if (!$object instanceof $this->entityName) { throw InvalidArgumentException::invalidEntityType( $this->getEntityName(), $object ); } }
php
public function checkIsEntity($object) { if (!$object instanceof $this->entityName) { throw InvalidArgumentException::invalidEntityType( $this->getEntityName(), $object ); } }
[ "public", "function", "checkIsEntity", "(", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "$", "this", "->", "entityName", ")", "{", "throw", "InvalidArgumentException", "::", "invalidEntityType", "(", "$", "this", "->", "getEntityName", "(", ")", ",", "$", "object", ")", ";", "}", "}" ]
Checks the given entity is an instance of the entity this mapper works with. @param mixed $object @return void @throws InvalidArgumentException If $object is not an entity.
[ "Checks", "the", "given", "entity", "is", "an", "instance", "of", "the", "entity", "this", "mapper", "works", "with", "." ]
c61c61546bfbc07e9c9a4b425e8e02fd7182d80b
https://github.com/SCLInternet/SclZfGenericMapper/blob/c61c61546bfbc07e9c9a4b425e8e02fd7182d80b/src/SclZfGenericMapper/CommonMapperMethodsTrait.php#L111-L119
train
SCLInternet/SclZfGenericMapper
src/SclZfGenericMapper/CommonMapperMethodsTrait.php
CommonMapperMethodsTrait.setPrototype
protected function setPrototype($prototype) { if ($this->entityName) { throw RuntimeException::setPrototypeCalledAgain(); } $this->entityName = is_object($prototype) ? get_class($prototype) : $prototype; }
php
protected function setPrototype($prototype) { if ($this->entityName) { throw RuntimeException::setPrototypeCalledAgain(); } $this->entityName = is_object($prototype) ? get_class($prototype) : $prototype; }
[ "protected", "function", "setPrototype", "(", "$", "prototype", ")", "{", "if", "(", "$", "this", "->", "entityName", ")", "{", "throw", "RuntimeException", "::", "setPrototypeCalledAgain", "(", ")", ";", "}", "$", "this", "->", "entityName", "=", "is_object", "(", "$", "prototype", ")", "?", "get_class", "(", "$", "prototype", ")", ":", "$", "prototype", ";", "}" ]
Setup the prototype of the entity this mapper works with. @param object $prototype
[ "Setup", "the", "prototype", "of", "the", "entity", "this", "mapper", "works", "with", "." ]
c61c61546bfbc07e9c9a4b425e8e02fd7182d80b
https://github.com/SCLInternet/SclZfGenericMapper/blob/c61c61546bfbc07e9c9a4b425e8e02fd7182d80b/src/SclZfGenericMapper/CommonMapperMethodsTrait.php#L126-L135
train
maikealame/auto-where
src/Where.php
Where.havingComplete
public static function havingComplete($array){ $c = 0; $r = ""; if( is_array( $array ) ) foreach($array as $k => $v){ if($c) $r .= " AND "; if (strpos($v, ":") !== false){ // number range [0] e [1] $vArray = explode(":",$v); if($vArray[0] <= $vArray[1]) $r .="(" .$k ." BETWEEN ".$vArray[0]." AND ".$vArray[1].")"; }else{ if (strpos($v, ">") !== false){ // number [0] bigger than [1] $v = str_replace(">", "", $v); $r .= $k ." >".$v.""; }else if (strpos($v, "<") !== false){ // number [1] bigger than [0] $v = str_replace("<", "", $v); $r .= $k ." <".$v.""; }else{ // number only $r .= $k ." = ".$v.""; } } $c++; } return empty($r) ? "1=1" : $r; }
php
public static function havingComplete($array){ $c = 0; $r = ""; if( is_array( $array ) ) foreach($array as $k => $v){ if($c) $r .= " AND "; if (strpos($v, ":") !== false){ // number range [0] e [1] $vArray = explode(":",$v); if($vArray[0] <= $vArray[1]) $r .="(" .$k ." BETWEEN ".$vArray[0]." AND ".$vArray[1].")"; }else{ if (strpos($v, ">") !== false){ // number [0] bigger than [1] $v = str_replace(">", "", $v); $r .= $k ." >".$v.""; }else if (strpos($v, "<") !== false){ // number [1] bigger than [0] $v = str_replace("<", "", $v); $r .= $k ." <".$v.""; }else{ // number only $r .= $k ." = ".$v.""; } } $c++; } return empty($r) ? "1=1" : $r; }
[ "public", "static", "function", "havingComplete", "(", "$", "array", ")", "{", "$", "c", "=", "0", ";", "$", "r", "=", "\"\"", ";", "if", "(", "is_array", "(", "$", "array", ")", ")", "foreach", "(", "$", "array", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "c", ")", "$", "r", ".=", "\" AND \"", ";", "if", "(", "strpos", "(", "$", "v", ",", "\":\"", ")", "!==", "false", ")", "{", "// number range [0] e [1]", "$", "vArray", "=", "explode", "(", "\":\"", ",", "$", "v", ")", ";", "if", "(", "$", "vArray", "[", "0", "]", "<=", "$", "vArray", "[", "1", "]", ")", "$", "r", ".=", "\"(\"", ".", "$", "k", ".", "\" BETWEEN \"", ".", "$", "vArray", "[", "0", "]", ".", "\" AND \"", ".", "$", "vArray", "[", "1", "]", ".", "\")\"", ";", "}", "else", "{", "if", "(", "strpos", "(", "$", "v", ",", "\">\"", ")", "!==", "false", ")", "{", "// number [0] bigger than [1]", "$", "v", "=", "str_replace", "(", "\">\"", ",", "\"\"", ",", "$", "v", ")", ";", "$", "r", ".=", "$", "k", ".", "\" >\"", ".", "$", "v", ".", "\"\"", ";", "}", "else", "if", "(", "strpos", "(", "$", "v", ",", "\"<\"", ")", "!==", "false", ")", "{", "// number [1] bigger than [0]", "$", "v", "=", "str_replace", "(", "\"<\"", ",", "\"\"", ",", "$", "v", ")", ";", "$", "r", ".=", "$", "k", ".", "\" <\"", ".", "$", "v", ".", "\"\"", ";", "}", "else", "{", "// number only", "$", "r", ".=", "$", "k", ".", "\" = \"", ".", "$", "v", ".", "\"\"", ";", "}", "}", "$", "c", "++", ";", "}", "return", "empty", "(", "$", "r", ")", "?", "\"1=1\"", ":", "$", "r", ";", "}" ]
not in use, needs improves and tests
[ "not", "in", "use", "needs", "improves", "and", "tests" ]
663542a11b1ee6222b8868ea91639f01ee69ff80
https://github.com/maikealame/auto-where/blob/663542a11b1ee6222b8868ea91639f01ee69ff80/src/Where.php#L461-L487
train
maikealame/auto-where
src/Where.php
Where.parseDate
public static function parseDate($date, $format){ if( $format == "d/m/Y" ) return self::parseDate1($date, $format); if( $format == "Y-m-d" ) return self::parseDate2($date, $format); return null; }
php
public static function parseDate($date, $format){ if( $format == "d/m/Y" ) return self::parseDate1($date, $format); if( $format == "Y-m-d" ) return self::parseDate2($date, $format); return null; }
[ "public", "static", "function", "parseDate", "(", "$", "date", ",", "$", "format", ")", "{", "if", "(", "$", "format", "==", "\"d/m/Y\"", ")", "return", "self", "::", "parseDate1", "(", "$", "date", ",", "$", "format", ")", ";", "if", "(", "$", "format", "==", "\"Y-m-d\"", ")", "return", "self", "::", "parseDate2", "(", "$", "date", ",", "$", "format", ")", ";", "return", "null", ";", "}" ]
Helps for data manipulation
[ "Helps", "for", "data", "manipulation" ]
663542a11b1ee6222b8868ea91639f01ee69ff80
https://github.com/maikealame/auto-where/blob/663542a11b1ee6222b8868ea91639f01ee69ff80/src/Where.php#L495-L499
train
agentmedia/phine-core
src/Core/Modules/Backend/ModuleLockForm.php
ModuleLockForm.Bundles
protected function Bundles() { $bundles = PathUtil::Bundles(); $result = array(); foreach ($bundles as $bundle) { if (count($this->Modules($bundle)) > 0) { $result[] = $bundle; } } return $result; }
php
protected function Bundles() { $bundles = PathUtil::Bundles(); $result = array(); foreach ($bundles as $bundle) { if (count($this->Modules($bundle)) > 0) { $result[] = $bundle; } } return $result; }
[ "protected", "function", "Bundles", "(", ")", "{", "$", "bundles", "=", "PathUtil", "::", "Bundles", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "bundles", "as", "$", "bundle", ")", "{", "if", "(", "count", "(", "$", "this", "->", "Modules", "(", "$", "bundle", ")", ")", ">", "0", ")", "{", "$", "result", "[", "]", "=", "$", "bundle", ";", "}", "}", "return", "$", "result", ";", "}" ]
Gets all bundles containing backend modules @return string[] Returns all bundle names
[ "Gets", "all", "bundles", "containing", "backend", "modules" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/ModuleLockForm.php#L92-L104
train
agentmedia/phine-core
src/Core/Modules/Backend/ModuleLockForm.php
ModuleLockForm.Modules
protected function Modules($bundle) { $modules = PathUtil::BackendModules($bundle); $result = array(); foreach ($modules as $module) { $instance = ClassFinder::CreateBackendModule(ClassFinder::CalcModuleType($bundle, $module)); if ($instance instanceof BackendModule) { $result[] = $module; } } return $result; }
php
protected function Modules($bundle) { $modules = PathUtil::BackendModules($bundle); $result = array(); foreach ($modules as $module) { $instance = ClassFinder::CreateBackendModule(ClassFinder::CalcModuleType($bundle, $module)); if ($instance instanceof BackendModule) { $result[] = $module; } } return $result; }
[ "protected", "function", "Modules", "(", "$", "bundle", ")", "{", "$", "modules", "=", "PathUtil", "::", "BackendModules", "(", "$", "bundle", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "modules", "as", "$", "module", ")", "{", "$", "instance", "=", "ClassFinder", "::", "CreateBackendModule", "(", "ClassFinder", "::", "CalcModuleType", "(", "$", "bundle", ",", "$", "module", ")", ")", ";", "if", "(", "$", "instance", "instanceof", "BackendModule", ")", "{", "$", "result", "[", "]", "=", "$", "module", ";", "}", "}", "return", "$", "result", ";", "}" ]
Gets all backend module names for a bundle @param string $bundle The bundle name @return string Returns the module names
[ "Gets", "all", "backend", "module", "names", "for", "a", "bundle" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/ModuleLockForm.php#L111-L124
train
agentmedia/phine-core
src/Core/Modules/Backend/ModuleLockForm.php
ModuleLockForm.HasLock
private function HasLock($bundle, $module = '') { $sql = Access::SqlBuilder(); $tblModLock = ModuleLock::Schema()->Table(); $where = $sql->Equals($tblModLock->Field('Bundle'), $sql->Value($bundle)) ->And_($sql->Equals($tblModLock->Field('Module'), $sql->Value($module))) ->And_($sql->Equals($tblModLock->Field('UserGroup'), $sql->Value($this->group->GetID()))); return ModuleLock::Schema()->Count(false, $where) > 0; }
php
private function HasLock($bundle, $module = '') { $sql = Access::SqlBuilder(); $tblModLock = ModuleLock::Schema()->Table(); $where = $sql->Equals($tblModLock->Field('Bundle'), $sql->Value($bundle)) ->And_($sql->Equals($tblModLock->Field('Module'), $sql->Value($module))) ->And_($sql->Equals($tblModLock->Field('UserGroup'), $sql->Value($this->group->GetID()))); return ModuleLock::Schema()->Count(false, $where) > 0; }
[ "private", "function", "HasLock", "(", "$", "bundle", ",", "$", "module", "=", "''", ")", "{", "$", "sql", "=", "Access", "::", "SqlBuilder", "(", ")", ";", "$", "tblModLock", "=", "ModuleLock", "::", "Schema", "(", ")", "->", "Table", "(", ")", ";", "$", "where", "=", "$", "sql", "->", "Equals", "(", "$", "tblModLock", "->", "Field", "(", "'Bundle'", ")", ",", "$", "sql", "->", "Value", "(", "$", "bundle", ")", ")", "->", "And_", "(", "$", "sql", "->", "Equals", "(", "$", "tblModLock", "->", "Field", "(", "'Module'", ")", ",", "$", "sql", "->", "Value", "(", "$", "module", ")", ")", ")", "->", "And_", "(", "$", "sql", "->", "Equals", "(", "$", "tblModLock", "->", "Field", "(", "'UserGroup'", ")", ",", "$", "sql", "->", "Value", "(", "$", "this", "->", "group", "->", "GetID", "(", ")", ")", ")", ")", ";", "return", "ModuleLock", "::", "Schema", "(", ")", "->", "Count", "(", "false", ",", "$", "where", ")", ">", "0", ";", "}" ]
True if a lock with given bundle and module are set @param string $bundle The bundle name @param string $module The module name @return boolean Returns true if the lock is set
[ "True", "if", "a", "lock", "with", "given", "bundle", "and", "module", "are", "set" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/ModuleLockForm.php#L186-L196
train
prolic/HumusMvc
src/HumusMvc/Controller/Action/Helper/ViewRenderer.php
ViewRenderer.initView
public function initView($path = null, $prefix = null, array $options = array()) { $this->setView($this->getServiceLocator()->get('View')); parent::initView($path, $prefix, $options); }
php
public function initView($path = null, $prefix = null, array $options = array()) { $this->setView($this->getServiceLocator()->get('View')); parent::initView($path, $prefix, $options); }
[ "public", "function", "initView", "(", "$", "path", "=", "null", ",", "$", "prefix", "=", "null", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "setView", "(", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'View'", ")", ")", ";", "parent", "::", "initView", "(", "$", "path", ",", "$", "prefix", ",", "$", "options", ")", ";", "}" ]
Initialize the view object $options may contain the following keys: - neverRender - flag dis/enabling postDispatch() autorender (affects all subsequent calls) - noController - flag indicating whether or not to look for view scripts in subdirectories named after the controller - noRender - flag indicating whether or not to autorender postDispatch() - responseSegment - which named response segment to render a view script to - scriptAction - what action script to render - viewBasePathSpec - specification to use for determining view base path - viewScriptPathSpec - specification to use for determining view script paths - viewScriptPathNoControllerSpec - specification to use for determining view script paths when noController flag is set - viewSuffix - what view script filename suffix to use @param string $path @param string $prefix @param array $options @throws Zend_Controller_Action_Exception @return void
[ "Initialize", "the", "view", "object" ]
09e8c6422d84b57745cc643047e10761be2a21a7
https://github.com/prolic/HumusMvc/blob/09e8c6422d84b57745cc643047e10761be2a21a7/src/HumusMvc/Controller/Action/Helper/ViewRenderer.php#L74-L78
train
nochso/ORM2
src/QueryBuilder.php
QueryBuilder.getSQL
private function getSQL() { $sql = $this->getTypeSQL() . $this->getWhereSQL() . $this->getOrderSQL() . $this->getLimitSQL() . $this->getOffsetSQL(); return $sql; }
php
private function getSQL() { $sql = $this->getTypeSQL() . $this->getWhereSQL() . $this->getOrderSQL() . $this->getLimitSQL() . $this->getOffsetSQL(); return $sql; }
[ "private", "function", "getSQL", "(", ")", "{", "$", "sql", "=", "$", "this", "->", "getTypeSQL", "(", ")", ".", "$", "this", "->", "getWhereSQL", "(", ")", ".", "$", "this", "->", "getOrderSQL", "(", ")", ".", "$", "this", "->", "getLimitSQL", "(", ")", ".", "$", "this", "->", "getOffsetSQL", "(", ")", ";", "return", "$", "sql", ";", "}" ]
Private functions to help build the SQL statement named parameter bindings
[ "Private", "functions", "to", "help", "build", "the", "SQL", "statement", "named", "parameter", "bindings" ]
89f9a5c61ad5f575fbdd52990171b52d54f8bfbc
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/QueryBuilder.php#L121-L129
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Partition.php
Wrapper_FS_Partition.commit
public function commit() { if (!is_null($this->_changes)) { $this->_commit($this->_changes); $this->_changes = null; } }
php
public function commit() { if (!is_null($this->_changes)) { $this->_commit($this->_changes); $this->_changes = null; } }
[ "public", "function", "commit", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "_changes", ")", ")", "{", "$", "this", "->", "_commit", "(", "$", "this", "->", "_changes", ")", ";", "$", "this", "->", "_changes", "=", "null", ";", "}", "}" ]
Commit changes to real FS @return null
[ "Commit", "changes", "to", "real", "FS" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Partition.php#L464-L471
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Partition.php
Wrapper_FS_Partition._commit
private function _commit(Wrapper_FS_Changes $changes, $path = "") { $root = $this->getRoot(); $rootpath = $root->path(); if ($path) { $path .= "/"; } $own = $changes->own(); foreach ($own as $filename => $vEntity) { $filepath = $path . $filename; $rPath = $rootpath . "/" . $filepath; /* @var $vEntity Entity_Abstract|Entity_Virtual_Interface */ $vExists = $vEntity->file_exists(); $rDeleted = false; $rEntity = $vEntity; do { $rEntity = $rEntity->getRealEntity(); $rDeleted = $rDeleted || !$rEntity->file_exists(); } while ($rEntity instanceof Entity_Virtual_Interface); /* @var $rEntity Entity */ $rExists = $rEntity->file_exists(); if ($rExists && !$vExists) { $rDeleted = true; } if (!$vExists && !$rExists) { continue; } elseif ($rDeleted) { if ($rExists) { $this->_files->delete($rPath); } if ($vExists) { $this->_copyChanges($filepath); } } else { /* @var $vEntity Entity_Virtual */ if ($vEntity->is_file()) { unlink($rPath); copy($vEntity->path(), $rPath); } } } $subtrees = $changes->sublists(); foreach ($subtrees as $filename => $tree) { /* @var $tree Wrapper_FS_Changes */ if (!isset($own[$filename])) { $this->_commit($tree, $path . $filename); } } }
php
private function _commit(Wrapper_FS_Changes $changes, $path = "") { $root = $this->getRoot(); $rootpath = $root->path(); if ($path) { $path .= "/"; } $own = $changes->own(); foreach ($own as $filename => $vEntity) { $filepath = $path . $filename; $rPath = $rootpath . "/" . $filepath; /* @var $vEntity Entity_Abstract|Entity_Virtual_Interface */ $vExists = $vEntity->file_exists(); $rDeleted = false; $rEntity = $vEntity; do { $rEntity = $rEntity->getRealEntity(); $rDeleted = $rDeleted || !$rEntity->file_exists(); } while ($rEntity instanceof Entity_Virtual_Interface); /* @var $rEntity Entity */ $rExists = $rEntity->file_exists(); if ($rExists && !$vExists) { $rDeleted = true; } if (!$vExists && !$rExists) { continue; } elseif ($rDeleted) { if ($rExists) { $this->_files->delete($rPath); } if ($vExists) { $this->_copyChanges($filepath); } } else { /* @var $vEntity Entity_Virtual */ if ($vEntity->is_file()) { unlink($rPath); copy($vEntity->path(), $rPath); } } } $subtrees = $changes->sublists(); foreach ($subtrees as $filename => $tree) { /* @var $tree Wrapper_FS_Changes */ if (!isset($own[$filename])) { $this->_commit($tree, $path . $filename); } } }
[ "private", "function", "_commit", "(", "Wrapper_FS_Changes", "$", "changes", ",", "$", "path", "=", "\"\"", ")", "{", "$", "root", "=", "$", "this", "->", "getRoot", "(", ")", ";", "$", "rootpath", "=", "$", "root", "->", "path", "(", ")", ";", "if", "(", "$", "path", ")", "{", "$", "path", ".=", "\"/\"", ";", "}", "$", "own", "=", "$", "changes", "->", "own", "(", ")", ";", "foreach", "(", "$", "own", "as", "$", "filename", "=>", "$", "vEntity", ")", "{", "$", "filepath", "=", "$", "path", ".", "$", "filename", ";", "$", "rPath", "=", "$", "rootpath", ".", "\"/\"", ".", "$", "filepath", ";", "/* @var $vEntity Entity_Abstract|Entity_Virtual_Interface */", "$", "vExists", "=", "$", "vEntity", "->", "file_exists", "(", ")", ";", "$", "rDeleted", "=", "false", ";", "$", "rEntity", "=", "$", "vEntity", ";", "do", "{", "$", "rEntity", "=", "$", "rEntity", "->", "getRealEntity", "(", ")", ";", "$", "rDeleted", "=", "$", "rDeleted", "||", "!", "$", "rEntity", "->", "file_exists", "(", ")", ";", "}", "while", "(", "$", "rEntity", "instanceof", "Entity_Virtual_Interface", ")", ";", "/* @var $rEntity Entity */", "$", "rExists", "=", "$", "rEntity", "->", "file_exists", "(", ")", ";", "if", "(", "$", "rExists", "&&", "!", "$", "vExists", ")", "{", "$", "rDeleted", "=", "true", ";", "}", "if", "(", "!", "$", "vExists", "&&", "!", "$", "rExists", ")", "{", "continue", ";", "}", "elseif", "(", "$", "rDeleted", ")", "{", "if", "(", "$", "rExists", ")", "{", "$", "this", "->", "_files", "->", "delete", "(", "$", "rPath", ")", ";", "}", "if", "(", "$", "vExists", ")", "{", "$", "this", "->", "_copyChanges", "(", "$", "filepath", ")", ";", "}", "}", "else", "{", "/* @var $vEntity Entity_Virtual */", "if", "(", "$", "vEntity", "->", "is_file", "(", ")", ")", "{", "unlink", "(", "$", "rPath", ")", ";", "copy", "(", "$", "vEntity", "->", "path", "(", ")", ",", "$", "rPath", ")", ";", "}", "}", "}", "$", "subtrees", "=", "$", "changes", "->", "sublists", "(", ")", ";", "foreach", "(", "$", "subtrees", "as", "$", "filename", "=>", "$", "tree", ")", "{", "/* @var $tree Wrapper_FS_Changes */", "if", "(", "!", "isset", "(", "$", "own", "[", "$", "filename", "]", ")", ")", "{", "$", "this", "->", "_commit", "(", "$", "tree", ",", "$", "path", ".", "$", "filename", ")", ";", "}", "}", "}" ]
Commit changes into real FS Если удалено и не существовало с самого начала - ничего не делаем Иначе если когда-то не существовало - удаляем всё RДерево - Если сейчас существует, то - переносим всё VДерево Иначе если это файл, то - удаляем RФайл - копируем VФайл на место RФайла По всем subtree - сделать тоже самое, если не было собственных изменений @param Wrapper_FS_Changes $changes Changes in FS @param string $path Path to commit @return null
[ "Commit", "changes", "into", "real", "FS" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Partition.php#L494-L549
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Partition.php
Wrapper_FS_Partition._copyChanges
private function _copyChanges($path) { $entity = $this->getEntity($path); $source = $entity->path(); $root = $this->getRoot()->path(); $destination = $root . "/" . $path; if ($entity->is_file()) { copy($source, $destination); } else { $mode = fileperms($source); mkdir($destination, $mode); $list = $this->getList($path); foreach ($list as $file) { /* @var $file Entity_Interface */ $this->_copyChanges($path . "/" . $file->basename()); } } }
php
private function _copyChanges($path) { $entity = $this->getEntity($path); $source = $entity->path(); $root = $this->getRoot()->path(); $destination = $root . "/" . $path; if ($entity->is_file()) { copy($source, $destination); } else { $mode = fileperms($source); mkdir($destination, $mode); $list = $this->getList($path); foreach ($list as $file) { /* @var $file Entity_Interface */ $this->_copyChanges($path . "/" . $file->basename()); } } }
[ "private", "function", "_copyChanges", "(", "$", "path", ")", "{", "$", "entity", "=", "$", "this", "->", "getEntity", "(", "$", "path", ")", ";", "$", "source", "=", "$", "entity", "->", "path", "(", ")", ";", "$", "root", "=", "$", "this", "->", "getRoot", "(", ")", "->", "path", "(", ")", ";", "$", "destination", "=", "$", "root", ".", "\"/\"", ".", "$", "path", ";", "if", "(", "$", "entity", "->", "is_file", "(", ")", ")", "{", "copy", "(", "$", "source", ",", "$", "destination", ")", ";", "}", "else", "{", "$", "mode", "=", "fileperms", "(", "$", "source", ")", ";", "mkdir", "(", "$", "destination", ",", "$", "mode", ")", ";", "$", "list", "=", "$", "this", "->", "getList", "(", "$", "path", ")", ";", "foreach", "(", "$", "list", "as", "$", "file", ")", "{", "/* @var $file Entity_Interface */", "$", "this", "->", "_copyChanges", "(", "$", "path", ".", "\"/\"", ".", "$", "file", "->", "basename", "(", ")", ")", ";", "}", "}", "}" ]
Copy new virtual files to real fs @param string $path Path @return null
[ "Copy", "new", "virtual", "files", "to", "real", "fs" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Partition.php#L558-L578
train
locomotivemtl/charcoal-config
src/Charcoal/Config/SeparatorAwareTrait.php
SeparatorAwareTrait.setSeparator
final public function setSeparator($separator) { if (!is_string($separator)) { throw new InvalidArgumentException( 'Separator must be a string' ); } if (strlen($separator) > 1) { throw new InvalidArgumentException( 'Separator must be one-character, or empty' ); } $this->separator = $separator; return $this; }
php
final public function setSeparator($separator) { if (!is_string($separator)) { throw new InvalidArgumentException( 'Separator must be a string' ); } if (strlen($separator) > 1) { throw new InvalidArgumentException( 'Separator must be one-character, or empty' ); } $this->separator = $separator; return $this; }
[ "final", "public", "function", "setSeparator", "(", "$", "separator", ")", "{", "if", "(", "!", "is_string", "(", "$", "separator", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Separator must be a string'", ")", ";", "}", "if", "(", "strlen", "(", "$", "separator", ")", ">", "1", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Separator must be one-character, or empty'", ")", ";", "}", "$", "this", "->", "separator", "=", "$", "separator", ";", "return", "$", "this", ";", "}" ]
Sets the token for traversing a data-tree. @param string $separator The single-character token to delimit nested data. If the token is an empty string, data-tree traversal is disabled. @throws InvalidArgumentException If the $separator is invalid. @return self
[ "Sets", "the", "token", "for", "traversing", "a", "data", "-", "tree", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/SeparatorAwareTrait.php#L31-L47
train
locomotivemtl/charcoal-config
src/Charcoal/Config/SeparatorAwareTrait.php
SeparatorAwareTrait.hasWithSeparator
final protected function hasWithSeparator($key) { $structure = $this; $splitKeys = explode($this->separator, $key); foreach ($splitKeys as $key) { if (!isset($structure[$key])) { return false; } if (!is_array($structure[$key])) { return true; } $structure = $structure[$key]; } return true; }
php
final protected function hasWithSeparator($key) { $structure = $this; $splitKeys = explode($this->separator, $key); foreach ($splitKeys as $key) { if (!isset($structure[$key])) { return false; } if (!is_array($structure[$key])) { return true; } $structure = $structure[$key]; } return true; }
[ "final", "protected", "function", "hasWithSeparator", "(", "$", "key", ")", "{", "$", "structure", "=", "$", "this", ";", "$", "splitKeys", "=", "explode", "(", "$", "this", "->", "separator", ",", "$", "key", ")", ";", "foreach", "(", "$", "splitKeys", "as", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "structure", "[", "$", "key", "]", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "is_array", "(", "$", "structure", "[", "$", "key", "]", ")", ")", "{", "return", "true", ";", "}", "$", "structure", "=", "$", "structure", "[", "$", "key", "]", ";", "}", "return", "true", ";", "}" ]
Determines if this store contains the key-path and if its value is not NULL. Traverses each node in the key-path until the endpoint is located. @param string $key The key-path to check. @return boolean TRUE if $key exists and has a value other than NULL, FALSE otherwise.
[ "Determines", "if", "this", "store", "contains", "the", "key", "-", "path", "and", "if", "its", "value", "is", "not", "NULL", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/SeparatorAwareTrait.php#L67-L81
train
locomotivemtl/charcoal-config
src/Charcoal/Config/SeparatorAwareTrait.php
SeparatorAwareTrait.getWithSeparator
final protected function getWithSeparator($key) { $structure = $this; $splitKeys = explode($this->separator, $key); foreach ($splitKeys as $key) { if (!isset($structure[$key])) { return null; } if (!is_array($structure[$key])) { return $structure[$key]; } $structure = $structure[$key]; } return $structure; }
php
final protected function getWithSeparator($key) { $structure = $this; $splitKeys = explode($this->separator, $key); foreach ($splitKeys as $key) { if (!isset($structure[$key])) { return null; } if (!is_array($structure[$key])) { return $structure[$key]; } $structure = $structure[$key]; } return $structure; }
[ "final", "protected", "function", "getWithSeparator", "(", "$", "key", ")", "{", "$", "structure", "=", "$", "this", ";", "$", "splitKeys", "=", "explode", "(", "$", "this", "->", "separator", ",", "$", "key", ")", ";", "foreach", "(", "$", "splitKeys", "as", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "structure", "[", "$", "key", "]", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "is_array", "(", "$", "structure", "[", "$", "key", "]", ")", ")", "{", "return", "$", "structure", "[", "$", "key", "]", ";", "}", "$", "structure", "=", "$", "structure", "[", "$", "key", "]", ";", "}", "return", "$", "structure", ";", "}" ]
Returns the value from the key-path found on this object. Traverses each node in the key-path until the endpoint is located. @param string $key The key-path to retrieve. @return mixed Value of the requested $key on success, NULL if the $key is not set.
[ "Returns", "the", "value", "from", "the", "key", "-", "path", "found", "on", "this", "object", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/SeparatorAwareTrait.php#L91-L105
train
jenskooij/cloudcontrol
src/cc/Application.php
Application.config
private function config() { if (realpath($this->configPath) !== false) { $json = file_get_contents($this->configPath); $this->config = json_decode($json); $this->config->rootDir = $this->rootDir; } else { throw new \RuntimeException('Framework not initialized yet. Consider running composer install'); } }
php
private function config() { if (realpath($this->configPath) !== false) { $json = file_get_contents($this->configPath); $this->config = json_decode($json); $this->config->rootDir = $this->rootDir; } else { throw new \RuntimeException('Framework not initialized yet. Consider running composer install'); } }
[ "private", "function", "config", "(", ")", "{", "if", "(", "realpath", "(", "$", "this", "->", "configPath", ")", "!==", "false", ")", "{", "$", "json", "=", "file_get_contents", "(", "$", "this", "->", "configPath", ")", ";", "$", "this", "->", "config", "=", "json_decode", "(", "$", "json", ")", ";", "$", "this", "->", "config", "->", "rootDir", "=", "$", "this", "->", "rootDir", ";", "}", "else", "{", "throw", "new", "\\", "RuntimeException", "(", "'Framework not initialized yet. Consider running composer install'", ")", ";", "}", "}" ]
Initialize the config @throws \Exception
[ "Initialize", "the", "config" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/cc/Application.php#L86-L95
train
jenskooij/cloudcontrol
src/cc/Application.php
Application.storage
private function storage() { $this->storage = new Storage($this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->imagesDir, $this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->filesDir); }
php
private function storage() { $this->storage = new Storage($this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->imagesDir, $this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->filesDir); }
[ "private", "function", "storage", "(", ")", "{", "$", "this", "->", "storage", "=", "new", "Storage", "(", "$", "this", "->", "config", "->", "rootDir", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "config", "->", "storageDir", ",", "$", "this", "->", "config", "->", "rootDir", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "config", "->", "imagesDir", ",", "$", "this", "->", "config", "->", "rootDir", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "config", "->", "filesDir", ")", ";", "}" ]
Initialize the storage @throws \Exception
[ "Initialize", "the", "storage" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/cc/Application.php#L101-L106
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.digipolisSwitchPrevious
public function digipolisSwitchPrevious($releasesDir, $currentSymlink) { $finder = new Finder(); // Get all releases. $releases = iterator_to_array( $finder ->directories() ->in($releasesDir) ->sortByName() ->depth(0) ->getIterator() ); // Last element is the current release. array_pop($releases); if ($releases) { // Normalize the paths. $currentDir = readlink($currentSymlink); $releasesDir = realpath($releasesDir); // Get the right folder within the release dir to symlink. $relativeRootDir = substr($currentDir, strlen($releasesDir . '/')); $parts = explode('/', $relativeRootDir); array_shift($parts); $relativeWebDir = implode('/', $parts); $previous = end($releases)->getRealPath() . '/' . $relativeWebDir; return $this->taskExec('ln -s -T -f ' . $previous . ' ' . $currentSymlink) ->run(); } }
php
public function digipolisSwitchPrevious($releasesDir, $currentSymlink) { $finder = new Finder(); // Get all releases. $releases = iterator_to_array( $finder ->directories() ->in($releasesDir) ->sortByName() ->depth(0) ->getIterator() ); // Last element is the current release. array_pop($releases); if ($releases) { // Normalize the paths. $currentDir = readlink($currentSymlink); $releasesDir = realpath($releasesDir); // Get the right folder within the release dir to symlink. $relativeRootDir = substr($currentDir, strlen($releasesDir . '/')); $parts = explode('/', $relativeRootDir); array_shift($parts); $relativeWebDir = implode('/', $parts); $previous = end($releases)->getRealPath() . '/' . $relativeWebDir; return $this->taskExec('ln -s -T -f ' . $previous . ' ' . $currentSymlink) ->run(); } }
[ "public", "function", "digipolisSwitchPrevious", "(", "$", "releasesDir", ",", "$", "currentSymlink", ")", "{", "$", "finder", "=", "new", "Finder", "(", ")", ";", "// Get all releases.", "$", "releases", "=", "iterator_to_array", "(", "$", "finder", "->", "directories", "(", ")", "->", "in", "(", "$", "releasesDir", ")", "->", "sortByName", "(", ")", "->", "depth", "(", "0", ")", "->", "getIterator", "(", ")", ")", ";", "// Last element is the current release.", "array_pop", "(", "$", "releases", ")", ";", "if", "(", "$", "releases", ")", "{", "// Normalize the paths.", "$", "currentDir", "=", "readlink", "(", "$", "currentSymlink", ")", ";", "$", "releasesDir", "=", "realpath", "(", "$", "releasesDir", ")", ";", "// Get the right folder within the release dir to symlink.", "$", "relativeRootDir", "=", "substr", "(", "$", "currentDir", ",", "strlen", "(", "$", "releasesDir", ".", "'/'", ")", ")", ";", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "relativeRootDir", ")", ";", "array_shift", "(", "$", "parts", ")", ";", "$", "relativeWebDir", "=", "implode", "(", "'/'", ",", "$", "parts", ")", ";", "$", "previous", "=", "end", "(", "$", "releases", ")", "->", "getRealPath", "(", ")", ".", "'/'", ".", "$", "relativeWebDir", ";", "return", "$", "this", "->", "taskExec", "(", "'ln -s -T -f '", ".", "$", "previous", ".", "' '", ".", "$", "currentSymlink", ")", "->", "run", "(", ")", ";", "}", "}" ]
Switch the current release symlink to the previous release. @param string $releasesDir Path to the folder containing all releases. @param string $currentSymlink Path to the current release symlink.
[ "Switch", "the", "current", "release", "symlink", "to", "the", "previous", "release", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L222-L249
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.digipolisMirrorDir
public function digipolisMirrorDir($dir, $destination) { if (!is_dir($dir)) { return; } $task = $this->taskFilesystemStack(); $task->mkdir($destination); $directoryIterator = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS); $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST); foreach ($recursiveIterator as $item) { $destinationFile = $destination . DIRECTORY_SEPARATOR . $recursiveIterator->getSubPathName(); if (file_exists($destinationFile)) { continue; } if (is_link($item)) { if ($item->getRealPath() !== false) { $task->symlink($item->getLinkTarget(), $destinationFile); } continue; } if ($item->isDir()) { $task->mkdir($destinationFile); continue; } $task->copy($item, $destinationFile); } return $task; }
php
public function digipolisMirrorDir($dir, $destination) { if (!is_dir($dir)) { return; } $task = $this->taskFilesystemStack(); $task->mkdir($destination); $directoryIterator = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS); $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST); foreach ($recursiveIterator as $item) { $destinationFile = $destination . DIRECTORY_SEPARATOR . $recursiveIterator->getSubPathName(); if (file_exists($destinationFile)) { continue; } if (is_link($item)) { if ($item->getRealPath() !== false) { $task->symlink($item->getLinkTarget(), $destinationFile); } continue; } if ($item->isDir()) { $task->mkdir($destinationFile); continue; } $task->copy($item, $destinationFile); } return $task; }
[ "public", "function", "digipolisMirrorDir", "(", "$", "dir", ",", "$", "destination", ")", "{", "if", "(", "!", "is_dir", "(", "$", "dir", ")", ")", "{", "return", ";", "}", "$", "task", "=", "$", "this", "->", "taskFilesystemStack", "(", ")", ";", "$", "task", "->", "mkdir", "(", "$", "destination", ")", ";", "$", "directoryIterator", "=", "new", "\\", "RecursiveDirectoryIterator", "(", "$", "dir", ",", "\\", "RecursiveDirectoryIterator", "::", "SKIP_DOTS", ")", ";", "$", "recursiveIterator", "=", "new", "\\", "RecursiveIteratorIterator", "(", "$", "directoryIterator", ",", "\\", "RecursiveIteratorIterator", "::", "SELF_FIRST", ")", ";", "foreach", "(", "$", "recursiveIterator", "as", "$", "item", ")", "{", "$", "destinationFile", "=", "$", "destination", ".", "DIRECTORY_SEPARATOR", ".", "$", "recursiveIterator", "->", "getSubPathName", "(", ")", ";", "if", "(", "file_exists", "(", "$", "destinationFile", ")", ")", "{", "continue", ";", "}", "if", "(", "is_link", "(", "$", "item", ")", ")", "{", "if", "(", "$", "item", "->", "getRealPath", "(", ")", "!==", "false", ")", "{", "$", "task", "->", "symlink", "(", "$", "item", "->", "getLinkTarget", "(", ")", ",", "$", "destinationFile", ")", ";", "}", "continue", ";", "}", "if", "(", "$", "item", "->", "isDir", "(", ")", ")", "{", "$", "task", "->", "mkdir", "(", "$", "destinationFile", ")", ";", "continue", ";", "}", "$", "task", "->", "copy", "(", "$", "item", ",", "$", "destinationFile", ")", ";", "}", "return", "$", "task", ";", "}" ]
Mirror a directory. @param string $dir Path of the directory to mirror. @param string $destination Path of the directory where $dir should be mirrored. @return \Robo\Contract\TaskInterface The mirror dir task.
[ "Mirror", "a", "directory", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L270-L298
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.buildTask
protected function buildTask($archivename = null) { $this->readProperties(); $archive = is_null($archivename) ? $this->time . '.tar.gz' : $archivename; $collection = $this->collectionBuilder(); $collection ->taskPackageProject($archive); return $collection; }
php
protected function buildTask($archivename = null) { $this->readProperties(); $archive = is_null($archivename) ? $this->time . '.tar.gz' : $archivename; $collection = $this->collectionBuilder(); $collection ->taskPackageProject($archive); return $collection; }
[ "protected", "function", "buildTask", "(", "$", "archivename", "=", "null", ")", "{", "$", "this", "->", "readProperties", "(", ")", ";", "$", "archive", "=", "is_null", "(", "$", "archivename", ")", "?", "$", "this", "->", "time", ".", "'.tar.gz'", ":", "$", "archivename", ";", "$", "collection", "=", "$", "this", "->", "collectionBuilder", "(", ")", ";", "$", "collection", "->", "taskPackageProject", "(", "$", "archive", ")", ";", "return", "$", "collection", ";", "}" ]
Build a site and package it. @param string $archivename Name of the archive to create. @return \Robo\Contract\TaskInterface The deploy task.
[ "Build", "a", "site", "and", "package", "it", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L309-L317
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.postSymlinkTask
protected function postSymlinkTask($worker, AbstractAuth $auth, $remote) { if (isset($remote['postsymlink_filechecks']) && $remote['postsymlink_filechecks']) { $projectRoot = $remote['rootdir']; $collection = $this->collectionBuilder(); $collection->taskSsh($worker, $auth) ->remoteDirectory($projectRoot, true) ->timeout($this->getTimeoutSetting('postsymlink_filechecks')); foreach ($remote['postsymlink_filechecks'] as $file) { // If this command fails, the collection will fail, which will // trigger a rollback. $builder = CommandBuilder::create('ls') ->addArgument($file) ->pipeOutputTo('grep') ->addArgument($file) ->onFailure( CommandBuilder::create('echo') ->addArgument('[ERROR] ' . $file . ' was not found.') ->onFinished('exit') ->addArgument('1') ); $collection->exec((string) $builder); } return $collection; } return false; }
php
protected function postSymlinkTask($worker, AbstractAuth $auth, $remote) { if (isset($remote['postsymlink_filechecks']) && $remote['postsymlink_filechecks']) { $projectRoot = $remote['rootdir']; $collection = $this->collectionBuilder(); $collection->taskSsh($worker, $auth) ->remoteDirectory($projectRoot, true) ->timeout($this->getTimeoutSetting('postsymlink_filechecks')); foreach ($remote['postsymlink_filechecks'] as $file) { // If this command fails, the collection will fail, which will // trigger a rollback. $builder = CommandBuilder::create('ls') ->addArgument($file) ->pipeOutputTo('grep') ->addArgument($file) ->onFailure( CommandBuilder::create('echo') ->addArgument('[ERROR] ' . $file . ' was not found.') ->onFinished('exit') ->addArgument('1') ); $collection->exec((string) $builder); } return $collection; } return false; }
[ "protected", "function", "postSymlinkTask", "(", "$", "worker", ",", "AbstractAuth", "$", "auth", ",", "$", "remote", ")", "{", "if", "(", "isset", "(", "$", "remote", "[", "'postsymlink_filechecks'", "]", ")", "&&", "$", "remote", "[", "'postsymlink_filechecks'", "]", ")", "{", "$", "projectRoot", "=", "$", "remote", "[", "'rootdir'", "]", ";", "$", "collection", "=", "$", "this", "->", "collectionBuilder", "(", ")", ";", "$", "collection", "->", "taskSsh", "(", "$", "worker", ",", "$", "auth", ")", "->", "remoteDirectory", "(", "$", "projectRoot", ",", "true", ")", "->", "timeout", "(", "$", "this", "->", "getTimeoutSetting", "(", "'postsymlink_filechecks'", ")", ")", ";", "foreach", "(", "$", "remote", "[", "'postsymlink_filechecks'", "]", "as", "$", "file", ")", "{", "// If this command fails, the collection will fail, which will", "// trigger a rollback.", "$", "builder", "=", "CommandBuilder", "::", "create", "(", "'ls'", ")", "->", "addArgument", "(", "$", "file", ")", "->", "pipeOutputTo", "(", "'grep'", ")", "->", "addArgument", "(", "$", "file", ")", "->", "onFailure", "(", "CommandBuilder", "::", "create", "(", "'echo'", ")", "->", "addArgument", "(", "'[ERROR] '", ".", "$", "file", ".", "' was not found.'", ")", "->", "onFinished", "(", "'exit'", ")", "->", "addArgument", "(", "'1'", ")", ")", ";", "$", "collection", "->", "exec", "(", "(", "string", ")", "$", "builder", ")", ";", "}", "return", "$", "collection", ";", "}", "return", "false", ";", "}" ]
Tasks to execute after creating the symlinks. @param string $worker The server to install the site on. @param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth The ssh authentication to connect to the server. @param array $remote The remote settings for this server. @return bool|\Robo\Contract\TaskInterface The postsymlink task, false if no post symlink tasks need to run.
[ "Tasks", "to", "execute", "after", "creating", "the", "symlinks", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L332-L358
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.preSymlinkTask
protected function preSymlinkTask($worker, AbstractAuth $auth, $remote) { $projectRoot = $remote['rootdir']; $collection = $this->collectionBuilder(); $collection->taskSsh($worker, $auth) ->remoteDirectory($projectRoot, true) ->timeout($this->getTimeoutSetting('presymlink_mirror_dir')); foreach ($remote['symlinks'] as $symlink) { list($target, $link) = explode(':', $symlink); if ($link === $remote['currentdir']) { continue; } // If the link we're going to create is an existing directory, // mirror that directory on the symlink target and then delete it // before creating the symlink $collection->exec('vendor/bin/robo digipolis:mirror-dir ' . $link . ' ' . $target); $collection->exec('rm -rf ' . $link); } return $collection; }
php
protected function preSymlinkTask($worker, AbstractAuth $auth, $remote) { $projectRoot = $remote['rootdir']; $collection = $this->collectionBuilder(); $collection->taskSsh($worker, $auth) ->remoteDirectory($projectRoot, true) ->timeout($this->getTimeoutSetting('presymlink_mirror_dir')); foreach ($remote['symlinks'] as $symlink) { list($target, $link) = explode(':', $symlink); if ($link === $remote['currentdir']) { continue; } // If the link we're going to create is an existing directory, // mirror that directory on the symlink target and then delete it // before creating the symlink $collection->exec('vendor/bin/robo digipolis:mirror-dir ' . $link . ' ' . $target); $collection->exec('rm -rf ' . $link); } return $collection; }
[ "protected", "function", "preSymlinkTask", "(", "$", "worker", ",", "AbstractAuth", "$", "auth", ",", "$", "remote", ")", "{", "$", "projectRoot", "=", "$", "remote", "[", "'rootdir'", "]", ";", "$", "collection", "=", "$", "this", "->", "collectionBuilder", "(", ")", ";", "$", "collection", "->", "taskSsh", "(", "$", "worker", ",", "$", "auth", ")", "->", "remoteDirectory", "(", "$", "projectRoot", ",", "true", ")", "->", "timeout", "(", "$", "this", "->", "getTimeoutSetting", "(", "'presymlink_mirror_dir'", ")", ")", ";", "foreach", "(", "$", "remote", "[", "'symlinks'", "]", "as", "$", "symlink", ")", "{", "list", "(", "$", "target", ",", "$", "link", ")", "=", "explode", "(", "':'", ",", "$", "symlink", ")", ";", "if", "(", "$", "link", "===", "$", "remote", "[", "'currentdir'", "]", ")", "{", "continue", ";", "}", "// If the link we're going to create is an existing directory,", "// mirror that directory on the symlink target and then delete it", "// before creating the symlink", "$", "collection", "->", "exec", "(", "'vendor/bin/robo digipolis:mirror-dir '", ".", "$", "link", ".", "' '", ".", "$", "target", ")", ";", "$", "collection", "->", "exec", "(", "'rm -rf '", ".", "$", "link", ")", ";", "}", "return", "$", "collection", ";", "}" ]
Tasks to execute before creating the symlinks. @param string $worker The server to install the site on. @param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth The ssh authentication to connect to the server. @param array $remote The remote settings for this server. @return bool|\Robo\Contract\TaskInterface The presymlink task, false if no pre symlink tasks need to run.
[ "Tasks", "to", "execute", "before", "creating", "the", "symlinks", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L373-L392
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.initRemoteTask
protected function initRemoteTask($worker, AbstractAuth $auth, $remote, $extra = [], $force = false) { $collection = $this->collectionBuilder(); if (!$this->isSiteInstalled($worker, $auth, $remote) || $force) { $this->say($force ? 'Forcing site install.' : 'Site status failed.'); $this->say('Triggering install script.'); $collection->addTask($this->installTask($worker, $auth, $remote, $extra, $force)); return $collection; } $collection->addTask($this->updateTask($worker, $auth, $remote, $extra)); return $collection; }
php
protected function initRemoteTask($worker, AbstractAuth $auth, $remote, $extra = [], $force = false) { $collection = $this->collectionBuilder(); if (!$this->isSiteInstalled($worker, $auth, $remote) || $force) { $this->say($force ? 'Forcing site install.' : 'Site status failed.'); $this->say('Triggering install script.'); $collection->addTask($this->installTask($worker, $auth, $remote, $extra, $force)); return $collection; } $collection->addTask($this->updateTask($worker, $auth, $remote, $extra)); return $collection; }
[ "protected", "function", "initRemoteTask", "(", "$", "worker", ",", "AbstractAuth", "$", "auth", ",", "$", "remote", ",", "$", "extra", "=", "[", "]", ",", "$", "force", "=", "false", ")", "{", "$", "collection", "=", "$", "this", "->", "collectionBuilder", "(", ")", ";", "if", "(", "!", "$", "this", "->", "isSiteInstalled", "(", "$", "worker", ",", "$", "auth", ",", "$", "remote", ")", "||", "$", "force", ")", "{", "$", "this", "->", "say", "(", "$", "force", "?", "'Forcing site install.'", ":", "'Site status failed.'", ")", ";", "$", "this", "->", "say", "(", "'Triggering install script.'", ")", ";", "$", "collection", "->", "addTask", "(", "$", "this", "->", "installTask", "(", "$", "worker", ",", "$", "auth", ",", "$", "remote", ",", "$", "extra", ",", "$", "force", ")", ")", ";", "return", "$", "collection", ";", "}", "$", "collection", "->", "addTask", "(", "$", "this", "->", "updateTask", "(", "$", "worker", ",", "$", "auth", ",", "$", "remote", ",", "$", "extra", ")", ")", ";", "return", "$", "collection", ";", "}" ]
Install or update a remote site. @param string $worker The server to install the site on. @param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth The ssh authentication to connect to the server. @param array $remote The remote settings for this server. @param array $extra Extra parameters to pass to site install. @param bool $force Whether or not to force the install even when the site is present. @return \Robo\Contract\TaskInterface The init remote task.
[ "Install", "or", "update", "a", "remote", "site", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L411-L423
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.removeBackupTask
protected function removeBackupTask( $worker, AbstractAuth $auth, $remote, $opts = ['files' => false, 'data' => false] ) { $backupDir = $remote['backupsdir'] . '/' . $remote['time']; $collection = $this->collectionBuilder(); $collection->taskSsh($worker, $auth) ->timeout($this->getTimeoutSetting('remove_backup')) ->exec('rm -rf ' . $backupDir); return $collection; }
php
protected function removeBackupTask( $worker, AbstractAuth $auth, $remote, $opts = ['files' => false, 'data' => false] ) { $backupDir = $remote['backupsdir'] . '/' . $remote['time']; $collection = $this->collectionBuilder(); $collection->taskSsh($worker, $auth) ->timeout($this->getTimeoutSetting('remove_backup')) ->exec('rm -rf ' . $backupDir); return $collection; }
[ "protected", "function", "removeBackupTask", "(", "$", "worker", ",", "AbstractAuth", "$", "auth", ",", "$", "remote", ",", "$", "opts", "=", "[", "'files'", "=>", "false", ",", "'data'", "=>", "false", "]", ")", "{", "$", "backupDir", "=", "$", "remote", "[", "'backupsdir'", "]", ".", "'/'", ".", "$", "remote", "[", "'time'", "]", ";", "$", "collection", "=", "$", "this", "->", "collectionBuilder", "(", ")", ";", "$", "collection", "->", "taskSsh", "(", "$", "worker", ",", "$", "auth", ")", "->", "timeout", "(", "$", "this", "->", "getTimeoutSetting", "(", "'remove_backup'", ")", ")", "->", "exec", "(", "'rm -rf '", ".", "$", "backupDir", ")", ";", "return", "$", "collection", ";", "}" ]
Remove a backup. @param string $worker The server to install the site on. @param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth The ssh authentication to connect to the server. @param array $remote The remote settings for this server. @return \Robo\Contract\TaskInterface The backup task.
[ "Remove", "a", "backup", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L735-L749
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.preRestoreBackupTask
protected function preRestoreBackupTask( $worker, AbstractAuth $auth, $remote, $opts = ['files' => false, 'data' => false] ) { if (!$opts['files'] && !$opts['data']) { $opts['files'] = true; $opts['data'] = true; } if ($opts['files']) { $removeFiles = 'rm -rf'; if (!$this->fileBackupSubDirs) { $removeFiles .= ' ./* ./.??*'; } foreach ($this->fileBackupSubDirs as $subdir) { $removeFiles .= ' ' . $subdir . '/* ' . $subdir . '/.??*'; } return $this->taskSsh($worker, $auth) ->remoteDirectory($remote['filesdir'], true) // Files dir can be pretty big on large sites. ->timeout($this->getTimeoutSetting('pre_restore_remove_files')) ->exec($removeFiles); } return false; }
php
protected function preRestoreBackupTask( $worker, AbstractAuth $auth, $remote, $opts = ['files' => false, 'data' => false] ) { if (!$opts['files'] && !$opts['data']) { $opts['files'] = true; $opts['data'] = true; } if ($opts['files']) { $removeFiles = 'rm -rf'; if (!$this->fileBackupSubDirs) { $removeFiles .= ' ./* ./.??*'; } foreach ($this->fileBackupSubDirs as $subdir) { $removeFiles .= ' ' . $subdir . '/* ' . $subdir . '/.??*'; } return $this->taskSsh($worker, $auth) ->remoteDirectory($remote['filesdir'], true) // Files dir can be pretty big on large sites. ->timeout($this->getTimeoutSetting('pre_restore_remove_files')) ->exec($removeFiles); } return false; }
[ "protected", "function", "preRestoreBackupTask", "(", "$", "worker", ",", "AbstractAuth", "$", "auth", ",", "$", "remote", ",", "$", "opts", "=", "[", "'files'", "=>", "false", ",", "'data'", "=>", "false", "]", ")", "{", "if", "(", "!", "$", "opts", "[", "'files'", "]", "&&", "!", "$", "opts", "[", "'data'", "]", ")", "{", "$", "opts", "[", "'files'", "]", "=", "true", ";", "$", "opts", "[", "'data'", "]", "=", "true", ";", "}", "if", "(", "$", "opts", "[", "'files'", "]", ")", "{", "$", "removeFiles", "=", "'rm -rf'", ";", "if", "(", "!", "$", "this", "->", "fileBackupSubDirs", ")", "{", "$", "removeFiles", ".=", "' ./* ./.??*'", ";", "}", "foreach", "(", "$", "this", "->", "fileBackupSubDirs", "as", "$", "subdir", ")", "{", "$", "removeFiles", ".=", "' '", ".", "$", "subdir", ".", "'/* '", ".", "$", "subdir", ".", "'/.??*'", ";", "}", "return", "$", "this", "->", "taskSsh", "(", "$", "worker", ",", "$", "auth", ")", "->", "remoteDirectory", "(", "$", "remote", "[", "'filesdir'", "]", ",", "true", ")", "// Files dir can be pretty big on large sites.", "->", "timeout", "(", "$", "this", "->", "getTimeoutSetting", "(", "'pre_restore_remove_files'", ")", ")", "->", "exec", "(", "$", "removeFiles", ")", ";", "}", "return", "false", ";", "}" ]
Pre restore backup task. @param string $worker The server to install the site on. @param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth The ssh authentication to connect to the server. @param array $remote The remote settings for this server. @return bool|\Robo\Contract\TaskInterface The pre restore backup task, false if no pre restore backup tasks need to run.
[ "Pre", "restore", "backup", "task", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L823-L850
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.pushPackageTask
protected function pushPackageTask($worker, AbstractAuth $auth, $remote, $archivename = null) { $archive = is_null($archivename) ? $remote['time'] . '.tar.gz' : $archivename; $releaseDir = $remote['releasesdir'] . '/' . $remote['time']; $collection = $this->collectionBuilder(); $collection->taskPushPackage($worker, $auth) ->destinationFolder($releaseDir) ->package($archive); $collection->taskSsh($worker, $auth) ->remoteDirectory($releaseDir, true) ->exec('chmod u+rx vendor/bin/robo'); return $collection; }
php
protected function pushPackageTask($worker, AbstractAuth $auth, $remote, $archivename = null) { $archive = is_null($archivename) ? $remote['time'] . '.tar.gz' : $archivename; $releaseDir = $remote['releasesdir'] . '/' . $remote['time']; $collection = $this->collectionBuilder(); $collection->taskPushPackage($worker, $auth) ->destinationFolder($releaseDir) ->package($archive); $collection->taskSsh($worker, $auth) ->remoteDirectory($releaseDir, true) ->exec('chmod u+rx vendor/bin/robo'); return $collection; }
[ "protected", "function", "pushPackageTask", "(", "$", "worker", ",", "AbstractAuth", "$", "auth", ",", "$", "remote", ",", "$", "archivename", "=", "null", ")", "{", "$", "archive", "=", "is_null", "(", "$", "archivename", ")", "?", "$", "remote", "[", "'time'", "]", ".", "'.tar.gz'", ":", "$", "archivename", ";", "$", "releaseDir", "=", "$", "remote", "[", "'releasesdir'", "]", ".", "'/'", ".", "$", "remote", "[", "'time'", "]", ";", "$", "collection", "=", "$", "this", "->", "collectionBuilder", "(", ")", ";", "$", "collection", "->", "taskPushPackage", "(", "$", "worker", ",", "$", "auth", ")", "->", "destinationFolder", "(", "$", "releaseDir", ")", "->", "package", "(", "$", "archive", ")", ";", "$", "collection", "->", "taskSsh", "(", "$", "worker", ",", "$", "auth", ")", "->", "remoteDirectory", "(", "$", "releaseDir", ",", "true", ")", "->", "exec", "(", "'chmod u+rx vendor/bin/robo'", ")", ";", "return", "$", "collection", ";", "}" ]
Push a package to the server. @param string $worker The server to install the site on. @param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth The ssh authentication to connect to the server. @param array $remote The remote settings for this server. @param string|null $archivename The path to the package to push. @return \Robo\Contract\TaskInterface The push package task.
[ "Push", "a", "package", "to", "the", "server", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L951-L967
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.switchPreviousTask
protected function switchPreviousTask($worker, AbstractAuth $auth, $remote) { return $this->taskSsh($worker, $auth) ->remoteDirectory($this->getCurrentProjectRoot($worker, $auth, $remote), true) ->exec( 'vendor/bin/robo digipolis:switch-previous ' . $remote['releasesdir'] . ' ' . $remote['currentdir'] ); }
php
protected function switchPreviousTask($worker, AbstractAuth $auth, $remote) { return $this->taskSsh($worker, $auth) ->remoteDirectory($this->getCurrentProjectRoot($worker, $auth, $remote), true) ->exec( 'vendor/bin/robo digipolis:switch-previous ' . $remote['releasesdir'] . ' ' . $remote['currentdir'] ); }
[ "protected", "function", "switchPreviousTask", "(", "$", "worker", ",", "AbstractAuth", "$", "auth", ",", "$", "remote", ")", "{", "return", "$", "this", "->", "taskSsh", "(", "$", "worker", ",", "$", "auth", ")", "->", "remoteDirectory", "(", "$", "this", "->", "getCurrentProjectRoot", "(", "$", "worker", ",", "$", "auth", ",", "$", "remote", ")", ",", "true", ")", "->", "exec", "(", "'vendor/bin/robo digipolis:switch-previous '", ".", "$", "remote", "[", "'releasesdir'", "]", ".", "' '", ".", "$", "remote", "[", "'currentdir'", "]", ")", ";", "}" ]
Switch the current symlink to the previous release on the server. @param string $worker The server to install the site on. @param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth The ssh authentication to connect to the server. @param array $remote The remote settings for this server. @return \Robo\Contract\TaskInterface The switch previous task.
[ "Switch", "the", "current", "symlink", "to", "the", "previous", "release", "on", "the", "server", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L982-L991
train
digipolisgent/robo-digipolis-helpers
src/AbstractRoboFile.php
AbstractRoboFile.removeFailedRelease
protected function removeFailedRelease($worker, AbstractAuth $auth, $remote, $releaseDirname = null) { $releaseDir = is_null($releaseDirname) ? $remote['releasesdir'] . '/' . $remote['time'] : $releaseDirname; return $this->taskSsh($worker, $auth) ->remoteDirectory($remote['rootdir'], true) ->exec('chown -R ' . $remote['user'] . ':' . $remote['user'] . ' ' . $releaseDir) ->exec('chmod -R a+rwx ' . $releaseDir) ->exec('rm -rf ' . $releaseDir); }
php
protected function removeFailedRelease($worker, AbstractAuth $auth, $remote, $releaseDirname = null) { $releaseDir = is_null($releaseDirname) ? $remote['releasesdir'] . '/' . $remote['time'] : $releaseDirname; return $this->taskSsh($worker, $auth) ->remoteDirectory($remote['rootdir'], true) ->exec('chown -R ' . $remote['user'] . ':' . $remote['user'] . ' ' . $releaseDir) ->exec('chmod -R a+rwx ' . $releaseDir) ->exec('rm -rf ' . $releaseDir); }
[ "protected", "function", "removeFailedRelease", "(", "$", "worker", ",", "AbstractAuth", "$", "auth", ",", "$", "remote", ",", "$", "releaseDirname", "=", "null", ")", "{", "$", "releaseDir", "=", "is_null", "(", "$", "releaseDirname", ")", "?", "$", "remote", "[", "'releasesdir'", "]", ".", "'/'", ".", "$", "remote", "[", "'time'", "]", ":", "$", "releaseDirname", ";", "return", "$", "this", "->", "taskSsh", "(", "$", "worker", ",", "$", "auth", ")", "->", "remoteDirectory", "(", "$", "remote", "[", "'rootdir'", "]", ",", "true", ")", "->", "exec", "(", "'chown -R '", ".", "$", "remote", "[", "'user'", "]", ".", "':'", ".", "$", "remote", "[", "'user'", "]", ".", "' '", ".", "$", "releaseDir", ")", "->", "exec", "(", "'chmod -R a+rwx '", ".", "$", "releaseDir", ")", "->", "exec", "(", "'rm -rf '", ".", "$", "releaseDir", ")", ";", "}" ]
Remove a failed release from the server. @param string $worker The server to install the site on. @param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth The ssh authentication to connect to the server. @param array $remote The remote settings for this server. @param string|null $releaseDirname The path of the release dir to remove. @return \Robo\Contract\TaskInterface The remove release task.
[ "Remove", "a", "failed", "release", "from", "the", "server", "." ]
f51099e27b2eb7ad13b78444e3139c431d848b3c
https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1008-L1018
train