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
pMatviienko/zf2-common
SbxCommon/src/SbxCommon/Form/View/Helper/Bootstrap/FormRow.php
FormRow.getElementErrorsHelper
protected function getElementErrorsHelper() { if ($this->elementErrorsHelper) { return $this->elementErrorsHelper; } if (method_exists($this->view, 'plugin')) { $this->elementErrorsHelper = $this->view->plugin('bootstrap_form_element_errors'); } if (!$this->elementErrorsHelper instanceof FormElementErrors) { $this->elementErrorsHelper = new FormElementErrors(); } return $this->elementErrorsHelper; }
php
protected function getElementErrorsHelper() { if ($this->elementErrorsHelper) { return $this->elementErrorsHelper; } if (method_exists($this->view, 'plugin')) { $this->elementErrorsHelper = $this->view->plugin('bootstrap_form_element_errors'); } if (!$this->elementErrorsHelper instanceof FormElementErrors) { $this->elementErrorsHelper = new FormElementErrors(); } return $this->elementErrorsHelper; }
[ "protected", "function", "getElementErrorsHelper", "(", ")", "{", "if", "(", "$", "this", "->", "elementErrorsHelper", ")", "{", "return", "$", "this", "->", "elementErrorsHelper", ";", "}", "if", "(", "method_exists", "(", "$", "this", "->", "view", ",", "'plugin'", ")", ")", "{", "$", "this", "->", "elementErrorsHelper", "=", "$", "this", "->", "view", "->", "plugin", "(", "'bootstrap_form_element_errors'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "elementErrorsHelper", "instanceof", "FormElementErrors", ")", "{", "$", "this", "->", "elementErrorsHelper", "=", "new", "FormElementErrors", "(", ")", ";", "}", "return", "$", "this", "->", "elementErrorsHelper", ";", "}" ]
Retrieve the FormElementErrors helper @return FormElementErrors
[ "Retrieve", "the", "FormElementErrors", "helper" ]
e59aa9b1eece72437cf0fd7c8466c0daeffcc481
https://github.com/pMatviienko/zf2-common/blob/e59aa9b1eece72437cf0fd7c8466c0daeffcc481/SbxCommon/src/SbxCommon/Form/View/Helper/Bootstrap/FormRow.php#L128-L143
train
olobu/olobu
core/loader.php
O_Loader.database
function database($params='', $return=TRUE) { $O =& get_instance(); if (class_exists('O_Db_driver') and $return === FALSE and isset($O->db) and is_object($O->db)) { throw new \Zanda\Orgasm\Fatal('Untuk sambungan ke database tambahan, harus menambahkan parameter $return bernilai TRUE'); } require_once(BASEPATH . '/database/db.php'); if ($return === TRUE) { return DB($params); } $O->db=''; $O->db =& DB($params); }
php
function database($params='', $return=TRUE) { $O =& get_instance(); if (class_exists('O_Db_driver') and $return === FALSE and isset($O->db) and is_object($O->db)) { throw new \Zanda\Orgasm\Fatal('Untuk sambungan ke database tambahan, harus menambahkan parameter $return bernilai TRUE'); } require_once(BASEPATH . '/database/db.php'); if ($return === TRUE) { return DB($params); } $O->db=''; $O->db =& DB($params); }
[ "function", "database", "(", "$", "params", "=", "''", ",", "$", "return", "=", "TRUE", ")", "{", "$", "O", "=", "&", "get_instance", "(", ")", ";", "if", "(", "class_exists", "(", "'O_Db_driver'", ")", "and", "$", "return", "===", "FALSE", "and", "isset", "(", "$", "O", "->", "db", ")", "and", "is_object", "(", "$", "O", "->", "db", ")", ")", "{", "throw", "new", "\\", "Zanda", "\\", "Orgasm", "\\", "Fatal", "(", "'Untuk sambungan ke database tambahan, harus menambahkan parameter $return bernilai TRUE'", ")", ";", "}", "require_once", "(", "BASEPATH", ".", "'/database/db.php'", ")", ";", "if", "(", "$", "return", "===", "TRUE", ")", "{", "return", "DB", "(", "$", "params", ")", ";", "}", "$", "O", "->", "db", "=", "''", ";", "$", "O", "->", "db", "=", "&", "DB", "(", "$", "params", ")", ";", "}" ]
default kalo ada pangge ini, berarti koneksi tambahan
[ "default", "kalo", "ada", "pangge", "ini", "berarti", "koneksi", "tambahan" ]
05bea2bff63d3e38b458fb42e8f07f1d850ae211
https://github.com/olobu/olobu/blob/05bea2bff63d3e38b458fb42e8f07f1d850ae211/core/loader.php#L325-L341
train
AlexyaFramework/Tools
Alexya/Tools/Collection.php
Collection.map
public function map(callable $callback) : Collection { $result = array_map($callback, array_keys($this->_data), $this->_data); return new static($result); }
php
public function map(callable $callback) : Collection { $result = array_map($callback, array_keys($this->_data), $this->_data); return new static($result); }
[ "public", "function", "map", "(", "callable", "$", "callback", ")", ":", "Collection", "{", "$", "result", "=", "array_map", "(", "$", "callback", ",", "array_keys", "(", "$", "this", "->", "_data", ")", ",", "$", "this", "->", "_data", ")", ";", "return", "new", "static", "(", "$", "result", ")", ";", "}" ]
Maps the array and returns a new object of this class. Example: ```php $arr = new \Alexya\Tools\Collection([ "test", "foo", "bar", "tests" ]); $newArr = $arr->map(function($key, $value) { $value = strtoupper($value); return $value; }); // $newArr = new \Alexya\Tools\Collection([ // "TEST", // "FOO", // "BAR", // "TESTS" // ]); ``` @param callable $callback Callback to apply to the array. @return Collection Mapped array.
[ "Maps", "the", "array", "and", "returns", "a", "new", "object", "of", "this", "class", "." ]
2ae7c91cde0517579b926dd872eaf7ea324fd1e4
https://github.com/AlexyaFramework/Tools/blob/2ae7c91cde0517579b926dd872eaf7ea324fd1e4/Alexya/Tools/Collection.php#L201-L206
train
AlexyaFramework/Tools
Alexya/Tools/Collection.php
Collection.walk
public function walk(callable $callback) : void { $newData = []; foreach($this->_data as $key => $value) { $ret = $callback($key, $value); $newData[$ret[0]] = $ret[1]; } $this->_data = $newData; }
php
public function walk(callable $callback) : void { $newData = []; foreach($this->_data as $key => $value) { $ret = $callback($key, $value); $newData[$ret[0]] = $ret[1]; } $this->_data = $newData; }
[ "public", "function", "walk", "(", "callable", "$", "callback", ")", ":", "void", "{", "$", "newData", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "_data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "ret", "=", "$", "callback", "(", "$", "key", ",", "$", "value", ")", ";", "$", "newData", "[", "$", "ret", "[", "0", "]", "]", "=", "$", "ret", "[", "1", "]", ";", "}", "$", "this", "->", "_data", "=", "$", "newData", ";", "}" ]
Walks through the array. The difference between this method and `map` is that the callback must return an array with two indexes: * The new key of the item. * The new value of the item. This will override the current array while `map` will only loop through the array and call the callback with the item key and value. Example: ```php $arr = new \Alexya\Tools\Collection([ "test", "foo", "bar", "tests" ]); $arr->walk(function($key, $value) { $value = strtoupper($value); return [$key, $value]; }); // $arr = new \Alexya\Tools\Collection([ // "TEST", // "FOO", // "BAR", // "TESTS" // ]); ``` @param callable $callback Callback to apply to the array.
[ "Walks", "through", "the", "array", "." ]
2ae7c91cde0517579b926dd872eaf7ea324fd1e4
https://github.com/AlexyaFramework/Tools/blob/2ae7c91cde0517579b926dd872eaf7ea324fd1e4/Alexya/Tools/Collection.php#L245-L255
train
AlexyaFramework/Tools
Alexya/Tools/Collection.php
Collection.accumulate
public function accumulate(callable $callback, $accumulator = "") { foreach($this->_data as $key => $value) { $accumulator = $callback($key, $value, $accumulator); } return $accumulator; }
php
public function accumulate(callable $callback, $accumulator = "") { foreach($this->_data as $key => $value) { $accumulator = $callback($key, $value, $accumulator); } return $accumulator; }
[ "public", "function", "accumulate", "(", "callable", "$", "callback", ",", "$", "accumulator", "=", "\"\"", ")", "{", "foreach", "(", "$", "this", "->", "_data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "accumulator", "=", "$", "callback", "(", "$", "key", ",", "$", "value", ",", "$", "accumulator", ")", ";", "}", "return", "$", "accumulator", ";", "}" ]
Performs a `array_reduce` action with the array. This method loops through the array and executes the callback on each element. The difference between `accumulate` and `map` and `filter` is that this method sends the result of each call to the callback as a second parameter to the callback. Example: ```php $arr = new \Alexya\Tools\Collection([ "test", "foo", "bar", "tests" ]); $arr->accumulate(function($key, $value, $accumulator) { echo "Previous value {$accumulator}, current value {$value}"; return $value; }, ""); // Previous value , current value test // Previous value test, current value foo // Previous value foo, current value bar // Previous value bar, current value tests ``` @param callable $callback Callback to apply to each element. @param mixed $accumulator Initial accumulator. @return mixed The resulting $accumulator.
[ "Performs", "a", "array_reduce", "action", "with", "the", "array", "." ]
2ae7c91cde0517579b926dd872eaf7ea324fd1e4
https://github.com/AlexyaFramework/Tools/blob/2ae7c91cde0517579b926dd872eaf7ea324fd1e4/Alexya/Tools/Collection.php#L293-L300
train
AlexyaFramework/Tools
Alexya/Tools/Collection.php
Collection.combine
public function combine($arr) : Collection { if($arr instanceof Collection) { $arr = $arr->getAll(); } if(!is_array($arr)) { return new static([]); } return new static(array_combine($this->_data, $arr)); }
php
public function combine($arr) : Collection { if($arr instanceof Collection) { $arr = $arr->getAll(); } if(!is_array($arr)) { return new static([]); } return new static(array_combine($this->_data, $arr)); }
[ "public", "function", "combine", "(", "$", "arr", ")", ":", "Collection", "{", "if", "(", "$", "arr", "instanceof", "Collection", ")", "{", "$", "arr", "=", "$", "arr", "->", "getAll", "(", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "arr", ")", ")", "{", "return", "new", "static", "(", "[", "]", ")", ";", "}", "return", "new", "static", "(", "array_combine", "(", "$", "this", "->", "_data", ",", "$", "arr", ")", ")", ";", "}" ]
Combines this and another array and returns a new object. The resulting array will contain the values of this array as key and the values of the parameter as values: ```php $keys = new Collection([ "foo" => "bar" ]); $values = new Collection([ "test" => "test" ]); $newCollection = $keys->combine($values); // $newCollection = new Collection([ // "bar" => "test" // ]); ``` @param array|\Alexya\Tools\Collection $arr Array to combine. @return \Alexya\Tools\Collection The combination of this array and `$arr`.
[ "Combines", "this", "and", "another", "array", "and", "returns", "a", "new", "object", "." ]
2ae7c91cde0517579b926dd872eaf7ea324fd1e4
https://github.com/AlexyaFramework/Tools/blob/2ae7c91cde0517579b926dd872eaf7ea324fd1e4/Alexya/Tools/Collection.php#L326-L337
train
AlexyaFramework/Tools
Alexya/Tools/Collection.php
Collection.append
public function append($arr) : void { if($arr instanceof Collection) { $arr = $arr->getAll(); } if(!is_array($arr)) { return; } foreach($arr as $key => $value) { $this->_data[$key] = $value; } }
php
public function append($arr) : void { if($arr instanceof Collection) { $arr = $arr->getAll(); } if(!is_array($arr)) { return; } foreach($arr as $key => $value) { $this->_data[$key] = $value; } }
[ "public", "function", "append", "(", "$", "arr", ")", ":", "void", "{", "if", "(", "$", "arr", "instanceof", "Collection", ")", "{", "$", "arr", "=", "$", "arr", "->", "getAll", "(", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "arr", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "arr", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "_data", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}" ]
Appends the contents of an array to this array. The indexes with same key will be overwritten. @param array|Collection $arr Array to append.
[ "Appends", "the", "contents", "of", "an", "array", "to", "this", "array", "." ]
2ae7c91cde0517579b926dd872eaf7ea324fd1e4
https://github.com/AlexyaFramework/Tools/blob/2ae7c91cde0517579b926dd872eaf7ea324fd1e4/Alexya/Tools/Collection.php#L346-L359
train
AlexyaFramework/Tools
Alexya/Tools/Collection.php
Collection.valueExists
public function valueExists($value, bool $strict = true) : bool { foreach($this->_data as $data) { $ret = ($strict) ? ($data === $value) : ($data == $value); if($ret) { return true; } } return false; }
php
public function valueExists($value, bool $strict = true) : bool { foreach($this->_data as $data) { $ret = ($strict) ? ($data === $value) : ($data == $value); if($ret) { return true; } } return false; }
[ "public", "function", "valueExists", "(", "$", "value", ",", "bool", "$", "strict", "=", "true", ")", ":", "bool", "{", "foreach", "(", "$", "this", "->", "_data", "as", "$", "data", ")", "{", "$", "ret", "=", "(", "$", "strict", ")", "?", "(", "$", "data", "===", "$", "value", ")", ":", "(", "$", "data", "==", "$", "value", ")", ";", "if", "(", "$", "ret", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks that a value exists in the array. @param mixed $value Index value. @param bool $strict Flag indicating that the value must be exactly the same or not (default = `true`). @return bool `true` if `$value` exists as a value in the array, `false` if not.
[ "Checks", "that", "a", "value", "exists", "in", "the", "array", "." ]
2ae7c91cde0517579b926dd872eaf7ea324fd1e4
https://github.com/AlexyaFramework/Tools/blob/2ae7c91cde0517579b926dd872eaf7ea324fd1e4/Alexya/Tools/Collection.php#L502-L514
train
AlexyaFramework/Tools
Alexya/Tools/Collection.php
Collection.deleteByValue
public function deleteByValue($value, bool $strict = true) : void { foreach($this->_data as $data) { $exists = ($strict) ? ($data === $value) : ($data == $value); if($exists) { unset($this->_data[$value]); } } }
php
public function deleteByValue($value, bool $strict = true) : void { foreach($this->_data as $data) { $exists = ($strict) ? ($data === $value) : ($data == $value); if($exists) { unset($this->_data[$value]); } } }
[ "public", "function", "deleteByValue", "(", "$", "value", ",", "bool", "$", "strict", "=", "true", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "_data", "as", "$", "data", ")", "{", "$", "exists", "=", "(", "$", "strict", ")", "?", "(", "$", "data", "===", "$", "value", ")", ":", "(", "$", "data", "==", "$", "value", ")", ";", "if", "(", "$", "exists", ")", "{", "unset", "(", "$", "this", "->", "_data", "[", "$", "value", "]", ")", ";", "}", "}", "}" ]
Deletes an index in the array by its value. @param mixed $value Index value. @param bool $strict Flag indicating that the value must be exactly the same or not (default = `true`).
[ "Deletes", "an", "index", "in", "the", "array", "by", "its", "value", "." ]
2ae7c91cde0517579b926dd872eaf7ea324fd1e4
https://github.com/AlexyaFramework/Tools/blob/2ae7c91cde0517579b926dd872eaf7ea324fd1e4/Alexya/Tools/Collection.php#L532-L542
train
mvccore/ext-router-media
src/MvcCore/Ext/Routers/Media/Preparing.php
Preparing.prepareRequestMediaVersionFromUrl
protected function prepareRequestMediaVersionFromUrl () { $this->prepareRequestMediaVersionFromUrlQueryString(); if ($this->requestMediaSiteVersion === NULL && $this->anyRoutesConfigured) $this->prepareRequestMediaVersionFromUrlPath(); if ($this->requestMediaSiteVersion === NULL) $this->requestMediaSiteVersion = static::MEDIA_VERSION_FULL; }
php
protected function prepareRequestMediaVersionFromUrl () { $this->prepareRequestMediaVersionFromUrlQueryString(); if ($this->requestMediaSiteVersion === NULL && $this->anyRoutesConfigured) $this->prepareRequestMediaVersionFromUrlPath(); if ($this->requestMediaSiteVersion === NULL) $this->requestMediaSiteVersion = static::MEDIA_VERSION_FULL; }
[ "protected", "function", "prepareRequestMediaVersionFromUrl", "(", ")", "{", "$", "this", "->", "prepareRequestMediaVersionFromUrlQueryString", "(", ")", ";", "if", "(", "$", "this", "->", "requestMediaSiteVersion", "===", "NULL", "&&", "$", "this", "->", "anyRoutesConfigured", ")", "$", "this", "->", "prepareRequestMediaVersionFromUrlPath", "(", ")", ";", "if", "(", "$", "this", "->", "requestMediaSiteVersion", "===", "NULL", ")", "$", "this", "->", "requestMediaSiteVersion", "=", "static", "::", "MEDIA_VERSION_FULL", ";", "}" ]
Try to set up into `\MvcCore\Request` object new media site version detected from requested url by url query string param or by url path prefix. If there is caught any valid media site version - set this value into request object. If there is nothing caught, set into request object full media site version anyway. @return void
[ "Try", "to", "set", "up", "into", "\\", "MvcCore", "\\", "Request", "object", "new", "media", "site", "version", "detected", "from", "requested", "url", "by", "url", "query", "string", "param", "or", "by", "url", "path", "prefix", ".", "If", "there", "is", "caught", "any", "valid", "media", "site", "version", "-", "set", "this", "value", "into", "request", "object", ".", "If", "there", "is", "nothing", "caught", "set", "into", "request", "object", "full", "media", "site", "version", "anyway", "." ]
976e83290cf25ad6bc32e4824790b5e0d5d4c08b
https://github.com/mvccore/ext-router-media/blob/976e83290cf25ad6bc32e4824790b5e0d5d4c08b/src/MvcCore/Ext/Routers/Media/Preparing.php#L64-L70
train
mvccore/ext-router-media
src/MvcCore/Ext/Routers/Media/Preparing.php
Preparing.prepareRequestMediaVersionFromUrlPath
protected function prepareRequestMediaVersionFromUrlPath () { $requestPath = $this->request->GetPath(TRUE); $requestPathExploded = explode('/', trim($requestPath, '/')); $requestPathFirstPart = mb_strtolower($requestPathExploded[0]); foreach ($this->allowedMediaVersionsAndUrlValues as $mediaSiteVersion => $mediaSiteUrlValue) { $mediaSiteUrlPrefix = mb_strtolower($mediaSiteUrlValue); if ($requestPathFirstPart === $mediaSiteUrlPrefix) { //$this->prepareSetUpRequestMediaSiteVersionIfValid($mediaSiteVersion); $this->requestMediaSiteVersion = $mediaSiteVersion; if (mb_strlen($mediaSiteUrlPrefix) > 0) $this->request->SetPath( mb_substr($requestPath, mb_strlen('/' . $mediaSiteUrlPrefix)) ); break; } } }
php
protected function prepareRequestMediaVersionFromUrlPath () { $requestPath = $this->request->GetPath(TRUE); $requestPathExploded = explode('/', trim($requestPath, '/')); $requestPathFirstPart = mb_strtolower($requestPathExploded[0]); foreach ($this->allowedMediaVersionsAndUrlValues as $mediaSiteVersion => $mediaSiteUrlValue) { $mediaSiteUrlPrefix = mb_strtolower($mediaSiteUrlValue); if ($requestPathFirstPart === $mediaSiteUrlPrefix) { //$this->prepareSetUpRequestMediaSiteVersionIfValid($mediaSiteVersion); $this->requestMediaSiteVersion = $mediaSiteVersion; if (mb_strlen($mediaSiteUrlPrefix) > 0) $this->request->SetPath( mb_substr($requestPath, mb_strlen('/' . $mediaSiteUrlPrefix)) ); break; } } }
[ "protected", "function", "prepareRequestMediaVersionFromUrlPath", "(", ")", "{", "$", "requestPath", "=", "$", "this", "->", "request", "->", "GetPath", "(", "TRUE", ")", ";", "$", "requestPathExploded", "=", "explode", "(", "'/'", ",", "trim", "(", "$", "requestPath", ",", "'/'", ")", ")", ";", "$", "requestPathFirstPart", "=", "mb_strtolower", "(", "$", "requestPathExploded", "[", "0", "]", ")", ";", "foreach", "(", "$", "this", "->", "allowedMediaVersionsAndUrlValues", "as", "$", "mediaSiteVersion", "=>", "$", "mediaSiteUrlValue", ")", "{", "$", "mediaSiteUrlPrefix", "=", "mb_strtolower", "(", "$", "mediaSiteUrlValue", ")", ";", "if", "(", "$", "requestPathFirstPart", "===", "$", "mediaSiteUrlPrefix", ")", "{", "//$this->prepareSetUpRequestMediaSiteVersionIfValid($mediaSiteVersion);", "$", "this", "->", "requestMediaSiteVersion", "=", "$", "mediaSiteVersion", ";", "if", "(", "mb_strlen", "(", "$", "mediaSiteUrlPrefix", ")", ">", "0", ")", "$", "this", "->", "request", "->", "SetPath", "(", "mb_substr", "(", "$", "requestPath", ",", "mb_strlen", "(", "'/'", ".", "$", "mediaSiteUrlPrefix", ")", ")", ")", ";", "break", ";", "}", "}", "}" ]
Try to set up media site version from request path as request media site version. If there is any request path detected, remove media site version from request path and store detected media site version in local context. @return void
[ "Try", "to", "set", "up", "media", "site", "version", "from", "request", "path", "as", "request", "media", "site", "version", ".", "If", "there", "is", "any", "request", "path", "detected", "remove", "media", "site", "version", "from", "request", "path", "and", "store", "detected", "media", "site", "version", "in", "local", "context", "." ]
976e83290cf25ad6bc32e4824790b5e0d5d4c08b
https://github.com/mvccore/ext-router-media/blob/976e83290cf25ad6bc32e4824790b5e0d5d4c08b/src/MvcCore/Ext/Routers/Media/Preparing.php#L88-L104
train
jabernardo/lollipop-php
Library/DOM/Scraper.php
Scraper.getContentsByAttr
public function getContentsByAttr($attr, $attr_value) { $nodes = $this->_dom_x_path->query("//*[contains(@{$attr}, '{$attr_value}')]"); $contents = []; foreach ($nodes as $node) { array_push($contents, $node->nodeValue); } return $contents; }
php
public function getContentsByAttr($attr, $attr_value) { $nodes = $this->_dom_x_path->query("//*[contains(@{$attr}, '{$attr_value}')]"); $contents = []; foreach ($nodes as $node) { array_push($contents, $node->nodeValue); } return $contents; }
[ "public", "function", "getContentsByAttr", "(", "$", "attr", ",", "$", "attr_value", ")", "{", "$", "nodes", "=", "$", "this", "->", "_dom_x_path", "->", "query", "(", "\"//*[contains(@{$attr}, '{$attr_value}')]\"", ")", ";", "$", "contents", "=", "[", "]", ";", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "array_push", "(", "$", "contents", ",", "$", "node", "->", "nodeValue", ")", ";", "}", "return", "$", "contents", ";", "}" ]
Get contents of an element by using attributes @example getContentsByAttr('class', 'thumbnail'); @param string $attr Element attribute @param string $attr_value Value of element attribute @return array
[ "Get", "contents", "of", "an", "element", "by", "using", "attributes" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/DOM/Scraper.php#L112-L122
train
jabernardo/lollipop-php
Library/DOM/Scraper.php
Scraper.getContentsByElem
public function getContentsByElem($elem) { $nodes = $this->_dom_x_path->query("//$elem"); $contents = []; foreach ($nodes as $node) { array_push($contents, $node->nodeValue); } return $contents; }
php
public function getContentsByElem($elem) { $nodes = $this->_dom_x_path->query("//$elem"); $contents = []; foreach ($nodes as $node) { array_push($contents, $node->nodeValue); } return $contents; }
[ "public", "function", "getContentsByElem", "(", "$", "elem", ")", "{", "$", "nodes", "=", "$", "this", "->", "_dom_x_path", "->", "query", "(", "\"//$elem\"", ")", ";", "$", "contents", "=", "[", "]", ";", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "array_push", "(", "$", "contents", ",", "$", "node", "->", "nodeValue", ")", ";", "}", "return", "$", "contents", ";", "}" ]
Get contents of an element by using element name @example getContentsByElem('div'); @param string $elem Element name @return array
[ "Get", "contents", "of", "an", "element", "by", "using", "element", "name" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/DOM/Scraper.php#L134-L144
train
jabernardo/lollipop-php
Library/DOM/Scraper.php
Scraper.getAttrByAttr
public function getAttrByAttr($attr, $attr_value, $attr_to_get) { $nodes = $this->_dom_x_path->query("//*[contains(@{$attr}, '{$attr_value}')]"); $contents = []; foreach ($nodes as $node) { array_push($contents, $node->getAttribute($attr_to_get)); } return $contents; }
php
public function getAttrByAttr($attr, $attr_value, $attr_to_get) { $nodes = $this->_dom_x_path->query("//*[contains(@{$attr}, '{$attr_value}')]"); $contents = []; foreach ($nodes as $node) { array_push($contents, $node->getAttribute($attr_to_get)); } return $contents; }
[ "public", "function", "getAttrByAttr", "(", "$", "attr", ",", "$", "attr_value", ",", "$", "attr_to_get", ")", "{", "$", "nodes", "=", "$", "this", "->", "_dom_x_path", "->", "query", "(", "\"//*[contains(@{$attr}, '{$attr_value}')]\"", ")", ";", "$", "contents", "=", "[", "]", ";", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "array_push", "(", "$", "contents", ",", "$", "node", "->", "getAttribute", "(", "$", "attr_to_get", ")", ")", ";", "}", "return", "$", "contents", ";", "}" ]
Get attribute value using other attributes @example getAttrByAttr('class', 'thumbnail', 'href') @param string @attr Element attribute @param string @attr_value Element attribute value @param string @attr_to_get Name of attribute to get @return array
[ "Get", "attribute", "value", "using", "other", "attributes" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/DOM/Scraper.php#L158-L168
train
jabernardo/lollipop-php
Library/DOM/Scraper.php
Scraper.getAttrByElem
public function getAttrByElem($element) { $nodes = $this->_dom_x_path->query("//{$element}"); $contents = []; $attrs = []; foreach ($nodes as $node) { $attrs = []; foreach ($node->attributes as $attr) { $attrs["{$attr->nodeName}"] = $attr->nodeValue; } array_push($contents, $attrs); } return $contents; }
php
public function getAttrByElem($element) { $nodes = $this->_dom_x_path->query("//{$element}"); $contents = []; $attrs = []; foreach ($nodes as $node) { $attrs = []; foreach ($node->attributes as $attr) { $attrs["{$attr->nodeName}"] = $attr->nodeValue; } array_push($contents, $attrs); } return $contents; }
[ "public", "function", "getAttrByElem", "(", "$", "element", ")", "{", "$", "nodes", "=", "$", "this", "->", "_dom_x_path", "->", "query", "(", "\"//{$element}\"", ")", ";", "$", "contents", "=", "[", "]", ";", "$", "attrs", "=", "[", "]", ";", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "$", "attrs", "=", "[", "]", ";", "foreach", "(", "$", "node", "->", "attributes", "as", "$", "attr", ")", "{", "$", "attrs", "[", "\"{$attr->nodeName}\"", "]", "=", "$", "attr", "->", "nodeValue", ";", "}", "array_push", "(", "$", "contents", ",", "$", "attrs", ")", ";", "}", "return", "$", "contents", ";", "}" ]
Get attributes of elements @example getAttrByElemWithAttr('a'); Output: Array ( [0] => Array ( [href] => www.sample.com [class] => thumbnail ) ) @param string $element Element (e.g. a, div, img) @return array
[ "Get", "attributes", "of", "elements" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/DOM/Scraper.php#L193-L212
train
Vectrex/vxPHP
src/Webpage/MenuGenerator.php
MenuGenerator.create
public static function create($id = null, $level = false, $forceActiveMenu = null, $decorator = null, $renderArgs = null) { return new static($id, $level, $forceActiveMenu, $decorator, $renderArgs); }
php
public static function create($id = null, $level = false, $forceActiveMenu = null, $decorator = null, $renderArgs = null) { return new static($id, $level, $forceActiveMenu, $decorator, $renderArgs); }
[ "public", "static", "function", "create", "(", "$", "id", "=", "null", ",", "$", "level", "=", "false", ",", "$", "forceActiveMenu", "=", "null", ",", "$", "decorator", "=", "null", ",", "$", "renderArgs", "=", "null", ")", "{", "return", "new", "static", "(", "$", "id", ",", "$", "level", ",", "$", "forceActiveMenu", ",", "$", "decorator", ",", "$", "renderArgs", ")", ";", "}" ]
convenience method to allow chaining @param string $id @param bool $level (if NULL, the full menu tree is printed) @param bool $forceActiveMenu @param string $decorator @param mixed $renderArgs @return MenuGenerator @throws MenuGeneratorException @throws \vxPHP\Application\Exception\ApplicationException
[ "convenience", "method", "to", "allow", "chaining" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Webpage/MenuGenerator.php#L185-L189
train
Vectrex/vxPHP
src/Webpage/MenuGenerator.php
MenuGenerator.completeMenu
protected function completeMenu(Menu $m) { if($m->getType() === 'dynamic') { // invoke service to build menu entries Application::getInstance()->getService($m->getServiceId())->appendMenuEntries($m); } foreach($m->getEntries() as $entry) { if(($m = $entry->getSubMenu())) { $this->completeMenu($m); } } }
php
protected function completeMenu(Menu $m) { if($m->getType() === 'dynamic') { // invoke service to build menu entries Application::getInstance()->getService($m->getServiceId())->appendMenuEntries($m); } foreach($m->getEntries() as $entry) { if(($m = $entry->getSubMenu())) { $this->completeMenu($m); } } }
[ "protected", "function", "completeMenu", "(", "Menu", "$", "m", ")", "{", "if", "(", "$", "m", "->", "getType", "(", ")", "===", "'dynamic'", ")", "{", "// invoke service to build menu entries", "Application", "::", "getInstance", "(", ")", "->", "getService", "(", "$", "m", "->", "getServiceId", "(", ")", ")", "->", "appendMenuEntries", "(", "$", "m", ")", ";", "}", "foreach", "(", "$", "m", "->", "getEntries", "(", ")", "as", "$", "entry", ")", "{", "if", "(", "(", "$", "m", "=", "$", "entry", "->", "getSubMenu", "(", ")", ")", ")", "{", "$", "this", "->", "completeMenu", "(", "$", "m", ")", ";", "}", "}", "}" ]
walk the menu tree and invoke service to append dynamic menu entries @param Menu $m @throws \vxPHP\Application\Exception\ApplicationException
[ "walk", "the", "menu", "tree", "and", "invoke", "service", "to", "append", "dynamic", "menu", "entries" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Webpage/MenuGenerator.php#L349-L366
train
Vectrex/vxPHP
src/Webpage/MenuGenerator.php
MenuGenerator.clearSelectedMenuEntries
protected function clearSelectedMenuEntries(Menu $menu) { while(($e = $menu->getSelectedEntry())) { // dynamic menus come either with unselected entry or have a selected entry explicitly set if($menu->getType() == 'static') { $menu->clearSelectedEntry(); } if(!($menu = $e->getSubMenu())) { break; } } }
php
protected function clearSelectedMenuEntries(Menu $menu) { while(($e = $menu->getSelectedEntry())) { // dynamic menus come either with unselected entry or have a selected entry explicitly set if($menu->getType() == 'static') { $menu->clearSelectedEntry(); } if(!($menu = $e->getSubMenu())) { break; } } }
[ "protected", "function", "clearSelectedMenuEntries", "(", "Menu", "$", "menu", ")", "{", "while", "(", "(", "$", "e", "=", "$", "menu", "->", "getSelectedEntry", "(", ")", ")", ")", "{", "// dynamic menus come either with unselected entry or have a selected entry explicitly set", "if", "(", "$", "menu", "->", "getType", "(", ")", "==", "'static'", ")", "{", "$", "menu", "->", "clearSelectedEntry", "(", ")", ";", "}", "if", "(", "!", "(", "$", "menu", "=", "$", "e", "->", "getSubMenu", "(", ")", ")", ")", "{", "break", ";", "}", "}", "}" ]
walks menu tree and clears all previously selected entries @param Menu $menu
[ "walks", "menu", "tree", "and", "clears", "all", "previously", "selected", "entries" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Webpage/MenuGenerator.php#L428-L441
train
Vectrex/vxPHP
src/Webpage/MenuGenerator.php
MenuGenerator.authenticateMenu
protected function authenticateMenu(Menu $menu) { if(!self::$authenticator) { self::$authenticator = new DefaultMenuAuthenticator(); } return self::$authenticator->authenticate($menu, Application::getInstance()->getCurrentUser()); }
php
protected function authenticateMenu(Menu $menu) { if(!self::$authenticator) { self::$authenticator = new DefaultMenuAuthenticator(); } return self::$authenticator->authenticate($menu, Application::getInstance()->getCurrentUser()); }
[ "protected", "function", "authenticateMenu", "(", "Menu", "$", "menu", ")", "{", "if", "(", "!", "self", "::", "$", "authenticator", ")", "{", "self", "::", "$", "authenticator", "=", "new", "DefaultMenuAuthenticator", "(", ")", ";", "}", "return", "self", "::", "$", "authenticator", "->", "authenticate", "(", "$", "menu", ",", "Application", "::", "getInstance", "(", ")", "->", "getCurrentUser", "(", ")", ")", ";", "}" ]
authenticates the complete menu invokes a previously set authenticator class or falls back to a default menu authenticator @param Menu $menu @return boolean @throws \vxPHP\Application\Exception\ApplicationException
[ "authenticates", "the", "complete", "menu", "invokes", "a", "previously", "set", "authenticator", "class", "or", "falls", "back", "to", "a", "default", "menu", "authenticator" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Webpage/MenuGenerator.php#L452-L462
train
shgysk8zer0/core_api
traits/curl.php
cURL.curlSetOpt
final public function curlSetOpt($opt, $value) { if (is_string($opt)) { $opt = 'CURLOPT_' . strtoupper($opt); if (defined($opt)) { $opt = constant($opt); curl_setopt($this->curl_handle, $opt, $value); } else { throw new \InvalidArgumentException( sprintf('%s is not a valid cURL option', func_get_arg(0)), 500 ); } } elseif (is_int($opt)) { curl_setopt($this->curl_handle, $opt, $value); } else { throw new \InvalidArgumentException( sprintf( '%s expects $opt to be a string or int, %s given instead', __METHOD__, gettype($opt) ), 500 ); } return $this; }
php
final public function curlSetOpt($opt, $value) { if (is_string($opt)) { $opt = 'CURLOPT_' . strtoupper($opt); if (defined($opt)) { $opt = constant($opt); curl_setopt($this->curl_handle, $opt, $value); } else { throw new \InvalidArgumentException( sprintf('%s is not a valid cURL option', func_get_arg(0)), 500 ); } } elseif (is_int($opt)) { curl_setopt($this->curl_handle, $opt, $value); } else { throw new \InvalidArgumentException( sprintf( '%s expects $opt to be a string or int, %s given instead', __METHOD__, gettype($opt) ), 500 ); } return $this; }
[ "final", "public", "function", "curlSetOpt", "(", "$", "opt", ",", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "opt", ")", ")", "{", "$", "opt", "=", "'CURLOPT_'", ".", "strtoupper", "(", "$", "opt", ")", ";", "if", "(", "defined", "(", "$", "opt", ")", ")", "{", "$", "opt", "=", "constant", "(", "$", "opt", ")", ";", "curl_setopt", "(", "$", "this", "->", "curl_handle", ",", "$", "opt", ",", "$", "value", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'%s is not a valid cURL option'", ",", "func_get_arg", "(", "0", ")", ")", ",", "500", ")", ";", "}", "}", "elseif", "(", "is_int", "(", "$", "opt", ")", ")", "{", "curl_setopt", "(", "$", "this", "->", "curl_handle", ",", "$", "opt", ",", "$", "value", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'%s expects $opt to be a string or int, %s given instead'", ",", "__METHOD__", ",", "gettype", "(", "$", "opt", ")", ")", ",", "500", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set an option for a cURL transfer @param int $opt The CURLOPT_XXX option to set. @param mixed $value The value to be set on option. @return self @see http://php.net/manual/en/function.curl-setopt.php
[ "Set", "an", "option", "for", "a", "cURL", "transfer" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/curl.php#L108-L134
train
shgysk8zer0/core_api
traits/curl.php
cURL.curlSetOptArray
final public function curlSetOptArray(array $options = array()) { $this->curlFilterOpts($options); curl_setopt_array($this->curl_handle, $options); return $this; }
php
final public function curlSetOptArray(array $options = array()) { $this->curlFilterOpts($options); curl_setopt_array($this->curl_handle, $options); return $this; }
[ "final", "public", "function", "curlSetOptArray", "(", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "curlFilterOpts", "(", "$", "options", ")", ";", "curl_setopt_array", "(", "$", "this", "->", "curl_handle", ",", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Set multiple options for a cURL transfer @param array $options An array specifying which options to set and their values. @return self
[ "Set", "multiple", "options", "for", "a", "cURL", "transfer" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/curl.php#L142-L147
train
shgysk8zer0/core_api
traits/curl.php
cURL.curlFileCreate
final public function curlFileCreate( $filename, $mimetype = null, $postname = null ) { $file = new \CURLFile($fname, $mime, $name); return [$file->getPostFilename(), $file]; }
php
final public function curlFileCreate( $filename, $mimetype = null, $postname = null ) { $file = new \CURLFile($fname, $mime, $name); return [$file->getPostFilename(), $file]; }
[ "final", "public", "function", "curlFileCreate", "(", "$", "filename", ",", "$", "mimetype", "=", "null", ",", "$", "postname", "=", "null", ")", "{", "$", "file", "=", "new", "\\", "CURLFile", "(", "$", "fname", ",", "$", "mime", ",", "$", "name", ")", ";", "return", "[", "$", "file", "->", "getPostFilename", "(", ")", ",", "$", "file", "]", ";", "}" ]
Can be used to upload a file with CURLOPT_POSTFIELDS. @param string $filename Filename of file @param string $mimetype MIME type of file @param string $postname Name of file for post data @see https://php.net/manual/en/class.curlfile.php
[ "Can", "be", "used", "to", "upload", "a", "file", "with", "CURLOPT_POSTFIELDS", "." ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/curl.php#L179-L187
train
Talesoft/tale-framework
src/Tale/ClassLoader.php
ClassLoader.load
public function load($className) { $name = $className; if ($this->_nameSpace) { $ns = rtrim($this->_nameSpace, '\\').'\\'; $nameLen = strlen($className); $nsLen = strlen($ns); if ($nameLen < $nsLen || substr($className, 0, $nsLen) !== $ns) return false; $name = substr($name, $nsLen); } $ds = \DIRECTORY_SEPARATOR; $path = $this->_path ? $this->_path.$ds : ''; $path .= str_replace(['_', '\\'], $ds, sprintf($this->_fileNamePattern, $name)); if (($path = stream_resolve_include_path($path)) !== false) include $path; return class_exists($className, false); }
php
public function load($className) { $name = $className; if ($this->_nameSpace) { $ns = rtrim($this->_nameSpace, '\\').'\\'; $nameLen = strlen($className); $nsLen = strlen($ns); if ($nameLen < $nsLen || substr($className, 0, $nsLen) !== $ns) return false; $name = substr($name, $nsLen); } $ds = \DIRECTORY_SEPARATOR; $path = $this->_path ? $this->_path.$ds : ''; $path .= str_replace(['_', '\\'], $ds, sprintf($this->_fileNamePattern, $name)); if (($path = stream_resolve_include_path($path)) !== false) include $path; return class_exists($className, false); }
[ "public", "function", "load", "(", "$", "className", ")", "{", "$", "name", "=", "$", "className", ";", "if", "(", "$", "this", "->", "_nameSpace", ")", "{", "$", "ns", "=", "rtrim", "(", "$", "this", "->", "_nameSpace", ",", "'\\\\'", ")", ".", "'\\\\'", ";", "$", "nameLen", "=", "strlen", "(", "$", "className", ")", ";", "$", "nsLen", "=", "strlen", "(", "$", "ns", ")", ";", "if", "(", "$", "nameLen", "<", "$", "nsLen", "||", "substr", "(", "$", "className", ",", "0", ",", "$", "nsLen", ")", "!==", "$", "ns", ")", "return", "false", ";", "$", "name", "=", "substr", "(", "$", "name", ",", "$", "nsLen", ")", ";", "}", "$", "ds", "=", "\\", "DIRECTORY_SEPARATOR", ";", "$", "path", "=", "$", "this", "->", "_path", "?", "$", "this", "->", "_path", ".", "$", "ds", ":", "''", ";", "$", "path", ".=", "str_replace", "(", "[", "'_'", ",", "'\\\\'", "]", ",", "$", "ds", ",", "sprintf", "(", "$", "this", "->", "_fileNamePattern", ",", "$", "name", ")", ")", ";", "if", "(", "(", "$", "path", "=", "stream_resolve_include_path", "(", "$", "path", ")", ")", "!==", "false", ")", "include", "$", "path", ";", "return", "class_exists", "(", "$", "className", ",", "false", ")", ";", "}" ]
Loads a class based on its class name If it's not found, it's simply ignored in order to let another loader try to load it If it's the only loader, an error will be thrown after a failed loading There's no loader recursion, the final check uses the second parameter of class_exists() to not trigger another autoloader inside this one @param $className The FQCN of the class to load @return bool Has the class been loaded or not
[ "Loads", "a", "class", "based", "on", "its", "class", "name", "If", "it", "s", "not", "found", "it", "s", "simply", "ignored", "in", "order", "to", "let", "another", "loader", "try", "to", "load", "it", "If", "it", "s", "the", "only", "loader", "an", "error", "will", "be", "thrown", "after", "a", "failed", "loading" ]
739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49
https://github.com/Talesoft/tale-framework/blob/739a7011c6dad409a51c4bcfbcf4b4ffbc8cba49/src/Tale/ClassLoader.php#L235-L260
train
valu-digital/valusetup
src/ValuSetup/Setup/SoftwareVersion.php
SoftwareVersion.setVersion
public function setVersion ($version) { $version = strtolower(strval($version)); if (! self::isValid($version)) { $version = self::DEFAULT_UNRESOLVED_VERSION; } $this->numbers = self::parse($version); $this->version = $version; return $this; }
php
public function setVersion ($version) { $version = strtolower(strval($version)); if (! self::isValid($version)) { $version = self::DEFAULT_UNRESOLVED_VERSION; } $this->numbers = self::parse($version); $this->version = $version; return $this; }
[ "public", "function", "setVersion", "(", "$", "version", ")", "{", "$", "version", "=", "strtolower", "(", "strval", "(", "$", "version", ")", ")", ";", "if", "(", "!", "self", "::", "isValid", "(", "$", "version", ")", ")", "{", "$", "version", "=", "self", "::", "DEFAULT_UNRESOLVED_VERSION", ";", "}", "$", "this", "->", "numbers", "=", "self", "::", "parse", "(", "$", "version", ")", ";", "$", "this", "->", "version", "=", "$", "version", ";", "return", "$", "this", ";", "}" ]
Set current version @param $version string|int Version (float/integer is casted to string) @return SoftwareVersion
[ "Set", "current", "version" ]
db1a0bfe1262d555eb11cd0d99625b9ee43d6744
https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Setup/SoftwareVersion.php#L55-L65
train
valu-digital/valusetup
src/ValuSetup/Setup/SoftwareVersion.php
SoftwareVersion.compareTo
public function compareTo($version) { $cmp = self::parse($version); $result = $this->cmp($cmp, $this->numbers); if ($result === 0) { $result = $this->cmp($this->numbers, $cmp); $result = - $result; } else { return $result; } return $result; }
php
public function compareTo($version) { $cmp = self::parse($version); $result = $this->cmp($cmp, $this->numbers); if ($result === 0) { $result = $this->cmp($this->numbers, $cmp); $result = - $result; } else { return $result; } return $result; }
[ "public", "function", "compareTo", "(", "$", "version", ")", "{", "$", "cmp", "=", "self", "::", "parse", "(", "$", "version", ")", ";", "$", "result", "=", "$", "this", "->", "cmp", "(", "$", "cmp", ",", "$", "this", "->", "numbers", ")", ";", "if", "(", "$", "result", "===", "0", ")", "{", "$", "result", "=", "$", "this", "->", "cmp", "(", "$", "this", "->", "numbers", ",", "$", "cmp", ")", ";", "$", "result", "=", "-", "$", "result", ";", "}", "else", "{", "return", "$", "result", ";", "}", "return", "$", "result", ";", "}" ]
Compare current version to given version and return -1 if current is less and +1 if current version is greater than given version @param $version string @return array
[ "Compare", "current", "version", "to", "given", "version", "and", "return", "-", "1", "if", "current", "is", "less", "and", "+", "1", "if", "current", "version", "is", "greater", "than", "given", "version" ]
db1a0bfe1262d555eb11cd0d99625b9ee43d6744
https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Setup/SoftwareVersion.php#L161-L172
train
valu-digital/valusetup
src/ValuSetup/Setup/SoftwareVersion.php
SoftwareVersion.parse
public static function parse ($version) { $nums = explode(self::DELIMITER, $version); $numbers = array(); foreach ($nums as $num) { if (preg_match('/^0*([0-9]+)/', $num, $matches)) { if (isset($matches[1])) { $numbers[] = $matches[1]; } else { $numbers[] = 0; } } else { break; } } if (! sizeof($numbers)) { $numbers = array(0); } return $numbers; }
php
public static function parse ($version) { $nums = explode(self::DELIMITER, $version); $numbers = array(); foreach ($nums as $num) { if (preg_match('/^0*([0-9]+)/', $num, $matches)) { if (isset($matches[1])) { $numbers[] = $matches[1]; } else { $numbers[] = 0; } } else { break; } } if (! sizeof($numbers)) { $numbers = array(0); } return $numbers; }
[ "public", "static", "function", "parse", "(", "$", "version", ")", "{", "$", "nums", "=", "explode", "(", "self", "::", "DELIMITER", ",", "$", "version", ")", ";", "$", "numbers", "=", "array", "(", ")", ";", "foreach", "(", "$", "nums", "as", "$", "num", ")", "{", "if", "(", "preg_match", "(", "'/^0*([0-9]+)/'", ",", "$", "num", ",", "$", "matches", ")", ")", "{", "if", "(", "isset", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "$", "numbers", "[", "]", "=", "$", "matches", "[", "1", "]", ";", "}", "else", "{", "$", "numbers", "[", "]", "=", "0", ";", "}", "}", "else", "{", "break", ";", "}", "}", "if", "(", "!", "sizeof", "(", "$", "numbers", ")", ")", "{", "$", "numbers", "=", "array", "(", "0", ")", ";", "}", "return", "$", "numbers", ";", "}" ]
Parse array of integers based on version number Non-integer values and preceeding zeros are dropped. @param $version string @return array
[ "Parse", "array", "of", "integers", "based", "on", "version", "number" ]
db1a0bfe1262d555eb11cd0d99625b9ee43d6744
https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Setup/SoftwareVersion.php#L208-L227
train
valu-digital/valusetup
src/ValuSetup/Setup/SoftwareVersion.php
SoftwareVersion.isValid
public static function isValid ($version) { if (self::isDev($version)) { return true; } else { return (boolean) preg_match('/' . self::$validPattern . '/i', $version); } }
php
public static function isValid ($version) { if (self::isDev($version)) { return true; } else { return (boolean) preg_match('/' . self::$validPattern . '/i', $version); } }
[ "public", "static", "function", "isValid", "(", "$", "version", ")", "{", "if", "(", "self", "::", "isDev", "(", "$", "version", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "(", "boolean", ")", "preg_match", "(", "'/'", ".", "self", "::", "$", "validPattern", ".", "'/i'", ",", "$", "version", ")", ";", "}", "}" ]
Test if version is valid @return boolean
[ "Test", "if", "version", "is", "valid" ]
db1a0bfe1262d555eb11cd0d99625b9ee43d6744
https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Setup/SoftwareVersion.php#L234-L241
train
wasinger/adaptimage
src/Output/OutputTypeMap.php
OutputTypeMap.getOutputTypeOptions
public function getOutputTypeOptions($input_type) { if (!in_array($input_type, $this->types)) { $input_type = $this->default_type; } return $this->map[$input_type]; }
php
public function getOutputTypeOptions($input_type) { if (!in_array($input_type, $this->types)) { $input_type = $this->default_type; } return $this->map[$input_type]; }
[ "public", "function", "getOutputTypeOptions", "(", "$", "input_type", ")", "{", "if", "(", "!", "in_array", "(", "$", "input_type", ",", "$", "this", "->", "types", ")", ")", "{", "$", "input_type", "=", "$", "this", "->", "default_type", ";", "}", "return", "$", "this", "->", "map", "[", "$", "input_type", "]", ";", "}" ]
Get OutputTypeOptions for given input type @param int $input_type One of the IMAGETYPE_XX constants @return OutputTypeOptionsInterface
[ "Get", "OutputTypeOptions", "for", "given", "input", "type" ]
7b529b25081b399451c8bbd56d0cef7daaa83ec4
https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/Output/OutputTypeMap.php#L30-L36
train
wasinger/adaptimage
src/Output/OutputTypeMap.php
OutputTypeMap.setOutputTypeOptions
public function setOutputTypeOptions($input_type, OutputTypeOptionsInterface $options) { $this->map[$input_type] = $options; $this->types = array_keys($this->map); return $this; }
php
public function setOutputTypeOptions($input_type, OutputTypeOptionsInterface $options) { $this->map[$input_type] = $options; $this->types = array_keys($this->map); return $this; }
[ "public", "function", "setOutputTypeOptions", "(", "$", "input_type", ",", "OutputTypeOptionsInterface", "$", "options", ")", "{", "$", "this", "->", "map", "[", "$", "input_type", "]", "=", "$", "options", ";", "$", "this", "->", "types", "=", "array_keys", "(", "$", "this", "->", "map", ")", ";", "return", "$", "this", ";", "}" ]
Set an OutputTypeOptionsInterface object for a given input type @param int $input_type One of the IMAGETYPE_XX constants @param OutputTypeOptionsInterface $options @return OutputTypeMap
[ "Set", "an", "OutputTypeOptionsInterface", "object", "for", "a", "given", "input", "type" ]
7b529b25081b399451c8bbd56d0cef7daaa83ec4
https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/Output/OutputTypeMap.php#L45-L50
train
Eden-PHP/Block
Base.php
Base.getHelpers
protected function getHelpers() { $cdnRoot = eden('block')->getAssetRoot(); $language = eden('block')->getLanguage(); return array( 'cdn' => function() use ($cdnRoot) { echo $cdnRoot; }, '_' => function($key) use ($language) { if($language instanceof Eden\Language\Base) { echo $language[$key]; } else { echo $key; } }); }
php
protected function getHelpers() { $cdnRoot = eden('block')->getAssetRoot(); $language = eden('block')->getLanguage(); return array( 'cdn' => function() use ($cdnRoot) { echo $cdnRoot; }, '_' => function($key) use ($language) { if($language instanceof Eden\Language\Base) { echo $language[$key]; } else { echo $key; } }); }
[ "protected", "function", "getHelpers", "(", ")", "{", "$", "cdnRoot", "=", "eden", "(", "'block'", ")", "->", "getAssetRoot", "(", ")", ";", "$", "language", "=", "eden", "(", "'block'", ")", "->", "getLanguage", "(", ")", ";", "return", "array", "(", "'cdn'", "=>", "function", "(", ")", "use", "(", "$", "cdnRoot", ")", "{", "echo", "$", "cdnRoot", ";", "}", ",", "'_'", "=>", "function", "(", "$", "key", ")", "use", "(", "$", "language", ")", "{", "if", "(", "$", "language", "instanceof", "Eden", "\\", "Language", "\\", "Base", ")", "{", "echo", "$", "language", "[", "$", "key", "]", ";", "}", "else", "{", "echo", "$", "key", ";", "}", "}", ")", ";", "}" ]
Returns helper methods @return array
[ "Returns", "helper", "methods" ]
681b9f01dd118612d0fced84d2f702167b52109b
https://github.com/Eden-PHP/Block/blob/681b9f01dd118612d0fced84d2f702167b52109b/Base.php#L85-L102
train
squareproton/Bond
src/Bond/Entity/Types/DateInterval.php
DateInterval.init
public static function init($time = null) { try { $interval = new self( $time ); return $interval; } catch( \Exception $e ) { return null; } }
php
public static function init($time = null) { try { $interval = new self( $time ); return $interval; } catch( \Exception $e ) { return null; } }
[ "public", "static", "function", "init", "(", "$", "time", "=", "null", ")", "{", "try", "{", "$", "interval", "=", "new", "self", "(", "$", "time", ")", ";", "return", "$", "interval", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "null", ";", "}", "}" ]
Standard initalise. Useful for array_map @param $time @return DateInterval|null
[ "Standard", "initalise", ".", "Useful", "for", "array_map" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/DateInterval.php#L89-L97
train
squareproton/Bond
src/Bond/Entity/Types/DateInterval.php
DateInterval.isEmpty
public function isEmpty() { return $this->y === 0 && $this->m === 0 && $this->d === 0 && $this->h === 0 && $this->i === 0 && $this->s === 0; }
php
public function isEmpty() { return $this->y === 0 && $this->m === 0 && $this->d === 0 && $this->h === 0 && $this->i === 0 && $this->s === 0; }
[ "public", "function", "isEmpty", "(", ")", "{", "return", "$", "this", "->", "y", "===", "0", "&&", "$", "this", "->", "m", "===", "0", "&&", "$", "this", "->", "d", "===", "0", "&&", "$", "this", "->", "h", "===", "0", "&&", "$", "this", "->", "i", "===", "0", "&&", "$", "this", "->", "s", "===", "0", ";", "}" ]
Is this interval empty? @return bool
[ "Is", "this", "interval", "empty?" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/DateInterval.php#L103-L106
train
squareproton/Bond
src/Bond/Entity/Types/DateInterval.php
DateInterval.toArray
public function toArray() { return array( 'year' => $this->y, 'month' => $this->m, 'day' => $this->d, 'hour' => $this->h, 'minute' => $this->i, 'second' => $this->s, ); }
php
public function toArray() { return array( 'year' => $this->y, 'month' => $this->m, 'day' => $this->d, 'hour' => $this->h, 'minute' => $this->i, 'second' => $this->s, ); }
[ "public", "function", "toArray", "(", ")", "{", "return", "array", "(", "'year'", "=>", "$", "this", "->", "y", ",", "'month'", "=>", "$", "this", "->", "m", ",", "'day'", "=>", "$", "this", "->", "d", ",", "'hour'", "=>", "$", "this", "->", "h", ",", "'minute'", "=>", "$", "this", "->", "i", ",", "'second'", "=>", "$", "this", "->", "s", ",", ")", ";", "}" ]
Return a array representing interval information @return array
[ "Return", "a", "array", "representing", "interval", "information" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/DateInterval.php#L112-L122
train
rutger-speksnijder/restphp
src/RestPHP/Request/Request.php
Request.sanitize
final protected function sanitize($data) { // Recursively loop through the data array and return the sanitized data $sanitized = []; if (is_array($data)) { foreach ($data as $key => $value) { $sanitized[$key] = $this->sanitize($value); } } else { $sanitized = trim(strip_tags($data)); } return $sanitized; }
php
final protected function sanitize($data) { // Recursively loop through the data array and return the sanitized data $sanitized = []; if (is_array($data)) { foreach ($data as $key => $value) { $sanitized[$key] = $this->sanitize($value); } } else { $sanitized = trim(strip_tags($data)); } return $sanitized; }
[ "final", "protected", "function", "sanitize", "(", "$", "data", ")", "{", "// Recursively loop through the data array and return the sanitized data", "$", "sanitized", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "sanitized", "[", "$", "key", "]", "=", "$", "this", "->", "sanitize", "(", "$", "value", ")", ";", "}", "}", "else", "{", "$", "sanitized", "=", "trim", "(", "strip_tags", "(", "$", "data", ")", ")", ";", "}", "return", "$", "sanitized", ";", "}" ]
Sanitizes an array with data. @param array $data The input data. @return array A sanitized array.
[ "Sanitizes", "an", "array", "with", "data", "." ]
326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d
https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/Request/Request.php#L52-L64
train
ammarfaizi2/icetea-framework
src/System/Crayner/Cookie/Cookie.php
Cookie.get
public function get($name) { $this->toString = isset($_COOKIE[$name]) ? $_COOKIE[$name] : ""; return new InputUtilities($this->toString); }
php
public function get($name) { $this->toString = isset($_COOKIE[$name]) ? $_COOKIE[$name] : ""; return new InputUtilities($this->toString); }
[ "public", "function", "get", "(", "$", "name", ")", "{", "$", "this", "->", "toString", "=", "isset", "(", "$", "_COOKIE", "[", "$", "name", "]", ")", "?", "$", "_COOKIE", "[", "$", "name", "]", ":", "\"\"", ";", "return", "new", "InputUtilities", "(", "$", "this", "->", "toString", ")", ";", "}" ]
Get cookie value. @param string $name @return string
[ "Get", "cookie", "value", "." ]
dedd832846c3e69b429b18b8612fae50881af180
https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Cookie/Cookie.php#L71-L75
train
ammarfaizi2/icetea-framework
src/System/Crayner/Cookie/Cookie.php
Cookie.delete
public function delete($name) { $this->func = function () use ($name) { setcookie($name, null, 0); return $name; }; return new CookieFlush($this->func); }
php
public function delete($name) { $this->func = function () use ($name) { setcookie($name, null, 0); return $name; }; return new CookieFlush($this->func); }
[ "public", "function", "delete", "(", "$", "name", ")", "{", "$", "this", "->", "func", "=", "function", "(", ")", "use", "(", "$", "name", ")", "{", "setcookie", "(", "$", "name", ",", "null", ",", "0", ")", ";", "return", "$", "name", ";", "}", ";", "return", "new", "CookieFlush", "(", "$", "this", "->", "func", ")", ";", "}" ]
Delete cookie. @param string $name @return bool
[ "Delete", "cookie", "." ]
dedd832846c3e69b429b18b8612fae50881af180
https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Cookie/Cookie.php#L83-L90
train
wearenolte/wp-endpoints-static
src/StaticApi/Widgets.php
Widgets.get_all_areas
public static function get_all_areas() { global $sidebars_widgets; $widget_areas = []; foreach ( $sidebars_widgets as $widget_area => $widgets ) { if ( 'wp_inactive_widgets' === $widget_area ) { continue; } $widget_areas[ $widget_area ] = []; if ( empty( $widgets ) ) { continue; } foreach ( $widgets as $widget ) { $model = Register::get_widget_instance( $widget ); if ( ! $model ) { continue; } $widget_areas[ $widget_area ][] = [ 'type' => $model->get_slug(), 'content' => $model->get_data(), ]; } } return $widget_areas; }
php
public static function get_all_areas() { global $sidebars_widgets; $widget_areas = []; foreach ( $sidebars_widgets as $widget_area => $widgets ) { if ( 'wp_inactive_widgets' === $widget_area ) { continue; } $widget_areas[ $widget_area ] = []; if ( empty( $widgets ) ) { continue; } foreach ( $widgets as $widget ) { $model = Register::get_widget_instance( $widget ); if ( ! $model ) { continue; } $widget_areas[ $widget_area ][] = [ 'type' => $model->get_slug(), 'content' => $model->get_data(), ]; } } return $widget_areas; }
[ "public", "static", "function", "get_all_areas", "(", ")", "{", "global", "$", "sidebars_widgets", ";", "$", "widget_areas", "=", "[", "]", ";", "foreach", "(", "$", "sidebars_widgets", "as", "$", "widget_area", "=>", "$", "widgets", ")", "{", "if", "(", "'wp_inactive_widgets'", "===", "$", "widget_area", ")", "{", "continue", ";", "}", "$", "widget_areas", "[", "$", "widget_area", "]", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "widgets", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "widgets", "as", "$", "widget", ")", "{", "$", "model", "=", "Register", "::", "get_widget_instance", "(", "$", "widget", ")", ";", "if", "(", "!", "$", "model", ")", "{", "continue", ";", "}", "$", "widget_areas", "[", "$", "widget_area", "]", "[", "]", "=", "[", "'type'", "=>", "$", "model", "->", "get_slug", "(", ")", ",", "'content'", "=>", "$", "model", "->", "get_data", "(", ")", ",", "]", ";", "}", "}", "return", "$", "widget_areas", ";", "}" ]
Returns an array of widget areas, with the assigned widgets in each. @return array
[ "Returns", "an", "array", "of", "widget", "areas", "with", "the", "assigned", "widgets", "in", "each", "." ]
23258bba9b65d55b78b3dc3edc123d75009b0825
https://github.com/wearenolte/wp-endpoints-static/blob/23258bba9b65d55b78b3dc3edc123d75009b0825/src/StaticApi/Widgets.php#L16-L47
train
concordat/console
src/Commands/AbstractCommand.php
AbstractCommand.iterator
protected function iterator($framework, $source) { $source = $source . DIRECTORY_SEPARATOR . ucfirst($framework); $directory = new \RecursiveDirectoryIterator($source, 4096); return new \RecursiveIteratorIterator($directory, 1); }
php
protected function iterator($framework, $source) { $source = $source . DIRECTORY_SEPARATOR . ucfirst($framework); $directory = new \RecursiveDirectoryIterator($source, 4096); return new \RecursiveIteratorIterator($directory, 1); }
[ "protected", "function", "iterator", "(", "$", "framework", ",", "$", "source", ")", "{", "$", "source", "=", "$", "source", ".", "DIRECTORY_SEPARATOR", ".", "ucfirst", "(", "$", "framework", ")", ";", "$", "directory", "=", "new", "\\", "RecursiveDirectoryIterator", "(", "$", "source", ",", "4096", ")", ";", "return", "new", "\\", "RecursiveIteratorIterator", "(", "$", "directory", ",", "1", ")", ";", "}" ]
Returns a \RecursiveIteratorIterator instance. @param string $framework @param string $source @return \RecursiveIteratorIterator
[ "Returns", "a", "\\", "RecursiveIteratorIterator", "instance", "." ]
bac3da80cb3d1abd26f9f2f5bd3ec8f1479f92d3
https://github.com/concordat/console/blob/bac3da80cb3d1abd26f9f2f5bd3ec8f1479f92d3/src/Commands/AbstractCommand.php#L97-L104
train
concordat/console
src/Commands/AbstractCommand.php
AbstractCommand.migrate
protected function migrate(OutputInterface $output, $source, $path, $framework) { foreach ($this->iterator($framework, $source) as $item) { $name = strtolower(str_replace($source, '', $item->getRealpath())); if ((boolean) $item->isDir() === false) { $date = date($this->times[$framework]); $this->type === 'migrations' && $name = $date . substr($name, 3); $output->writeln('<info>' . $path . $name . '</info>'); copy($item, $path . $name) && sleep(1); continue; } ! file_exists($path . $name) && mkdir($path . $name); } }
php
protected function migrate(OutputInterface $output, $source, $path, $framework) { foreach ($this->iterator($framework, $source) as $item) { $name = strtolower(str_replace($source, '', $item->getRealpath())); if ((boolean) $item->isDir() === false) { $date = date($this->times[$framework]); $this->type === 'migrations' && $name = $date . substr($name, 3); $output->writeln('<info>' . $path . $name . '</info>'); copy($item, $path . $name) && sleep(1); continue; } ! file_exists($path . $name) && mkdir($path . $name); } }
[ "protected", "function", "migrate", "(", "OutputInterface", "$", "output", ",", "$", "source", ",", "$", "path", ",", "$", "framework", ")", "{", "foreach", "(", "$", "this", "->", "iterator", "(", "$", "framework", ",", "$", "source", ")", "as", "$", "item", ")", "{", "$", "name", "=", "strtolower", "(", "str_replace", "(", "$", "source", ",", "''", ",", "$", "item", "->", "getRealpath", "(", ")", ")", ")", ";", "if", "(", "(", "boolean", ")", "$", "item", "->", "isDir", "(", ")", "===", "false", ")", "{", "$", "date", "=", "date", "(", "$", "this", "->", "times", "[", "$", "framework", "]", ")", ";", "$", "this", "->", "type", "===", "'migrations'", "&&", "$", "name", "=", "$", "date", ".", "substr", "(", "$", "name", ",", "3", ")", ";", "$", "output", "->", "writeln", "(", "'<info>'", ".", "$", "path", ".", "$", "name", ".", "'</info>'", ")", ";", "copy", "(", "$", "item", ",", "$", "path", ".", "$", "name", ")", "&&", "sleep", "(", "1", ")", ";", "continue", ";", "}", "!", "file_exists", "(", "$", "path", ".", "$", "name", ")", "&&", "mkdir", "(", "$", "path", ".", "$", "name", ")", ";", "}", "}" ]
Creates a copy of database files to the specified path. @param \Symfony\Component\Console\Output\OutputInterface $output @param string $source @param string $path @param string $framework @return void
[ "Creates", "a", "copy", "of", "database", "files", "to", "the", "specified", "path", "." ]
bac3da80cb3d1abd26f9f2f5bd3ec8f1479f92d3
https://github.com/concordat/console/blob/bac3da80cb3d1abd26f9f2f5bd3ec8f1479f92d3/src/Commands/AbstractCommand.php#L115-L134
train
concordat/console
src/Commands/AbstractCommand.php
AbstractCommand.package
protected function package($name) { $exists = in_array($name, array_keys($this->packages)); if ($exists === false || ! class_exists($this->packages[$name])) { $message = 'Package "' . $name . '" does not exists!'; throw new \InvalidArgumentException((string) $message); } $function = array(new $this->packages[$name], $this->type); if (! $source = call_user_func_array($function, array())) { $message = '"%s" does not provide a path for the list of %s!'; $message = sprintf($message, ucfirst($name), $this->type); throw new \InvalidArgumentException((string) $message); } return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $source); }
php
protected function package($name) { $exists = in_array($name, array_keys($this->packages)); if ($exists === false || ! class_exists($this->packages[$name])) { $message = 'Package "' . $name . '" does not exists!'; throw new \InvalidArgumentException((string) $message); } $function = array(new $this->packages[$name], $this->type); if (! $source = call_user_func_array($function, array())) { $message = '"%s" does not provide a path for the list of %s!'; $message = sprintf($message, ucfirst($name), $this->type); throw new \InvalidArgumentException((string) $message); } return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $source); }
[ "protected", "function", "package", "(", "$", "name", ")", "{", "$", "exists", "=", "in_array", "(", "$", "name", ",", "array_keys", "(", "$", "this", "->", "packages", ")", ")", ";", "if", "(", "$", "exists", "===", "false", "||", "!", "class_exists", "(", "$", "this", "->", "packages", "[", "$", "name", "]", ")", ")", "{", "$", "message", "=", "'Package \"'", ".", "$", "name", ".", "'\" does not exists!'", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "(", "string", ")", "$", "message", ")", ";", "}", "$", "function", "=", "array", "(", "new", "$", "this", "->", "packages", "[", "$", "name", "]", ",", "$", "this", "->", "type", ")", ";", "if", "(", "!", "$", "source", "=", "call_user_func_array", "(", "$", "function", ",", "array", "(", ")", ")", ")", "{", "$", "message", "=", "'\"%s\" does not provide a path for the list of %s!'", ";", "$", "message", "=", "sprintf", "(", "$", "message", ",", "ucfirst", "(", "$", "name", ")", ",", "$", "this", "->", "type", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "(", "string", ")", "$", "message", ")", ";", "}", "return", "str_replace", "(", "array", "(", "'/'", ",", "'\\\\'", ")", ",", "DIRECTORY_SEPARATOR", ",", "$", "source", ")", ";", "}" ]
Return the value of the required type from the specified package. @param string $package @return string
[ "Return", "the", "value", "of", "the", "required", "type", "from", "the", "specified", "package", "." ]
bac3da80cb3d1abd26f9f2f5bd3ec8f1479f92d3
https://github.com/concordat/console/blob/bac3da80cb3d1abd26f9f2f5bd3ec8f1479f92d3/src/Commands/AbstractCommand.php#L142-L163
train
XetaIO/Xetaravel-IpTraceable
src/Providers/IpTraceableServiceProvider.php
IpTraceableServiceProvider.boot
public function boot() { foreach ($this->subscribe as $subscriber) { Event::subscribe($subscriber); } $this->publishes([ __DIR__ . '/../../config/iptraceable.php' => config_path('iptraceable.php'), ], 'config'); }
php
public function boot() { foreach ($this->subscribe as $subscriber) { Event::subscribe($subscriber); } $this->publishes([ __DIR__ . '/../../config/iptraceable.php' => config_path('iptraceable.php'), ], 'config'); }
[ "public", "function", "boot", "(", ")", "{", "foreach", "(", "$", "this", "->", "subscribe", "as", "$", "subscriber", ")", "{", "Event", "::", "subscribe", "(", "$", "subscriber", ")", ";", "}", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/../../config/iptraceable.php'", "=>", "config_path", "(", "'iptraceable.php'", ")", ",", "]", ",", "'config'", ")", ";", "}" ]
Register the application's event listeners and publish the config file. @return void
[ "Register", "the", "application", "s", "event", "listeners", "and", "publish", "the", "config", "file", "." ]
e1c57592d45f240c55e827fd6b756e5143c892b5
https://github.com/XetaIO/Xetaravel-IpTraceable/blob/e1c57592d45f240c55e827fd6b756e5143c892b5/src/Providers/IpTraceableServiceProvider.php#L24-L33
train
ekyna/SettingBundle
Controller/HelperController.php
HelperController.fetchAction
public function fetchAction(Request $request) { $reference = strtoupper($request->query->get('reference', null)); $remote = (bool)$request->query->get('remote', 1); if (0 < strlen($reference) && $remote) { $remoteEndPoints = $this->container->getParameter('ekyna_setting.helper_remotes'); foreach ($remoteEndPoints as $remoteEndPoint) { // remote=0 prevent infinite loop/recursion $url = $remoteEndPoint . '?reference=' . $reference . '&remote=0'; $headers = $request->headers->all(); if (null !== $response = $this->getRemoteResponse($url, $headers)) { return $response; } } } $ttl = 7 * 24 * 3600; $response = new Response(); $response ->setPublic() ->headers->add(['Content-Type' => 'application/xml; charset=utf-8']) ; if (0 < strlen($reference)) { $repository = $this->getDoctrine()->getRepository('EkynaSettingBundle:Helper'); if (null !== $helper = $repository->findOneBy(['reference' => $reference])) { $response->setLastModified($helper->getUpdatedAt()); if ($response->isNotModified($request)) { return $response; } $response->setContent($this->renderView('EkynaSettingBundle:Helper:show.xml.twig', [ 'helper' => $helper, ])); return $this->configureSharedCache($response, [$helper->getEntityTag()], $ttl); } } $expires = new \DateTime(); $expires->modify('+7 days'); return $response ->setMaxAge($ttl) ->setExpires($expires) ->setContent($this->renderView('EkynaSettingBundle:Helper:show.xml.twig')) ; }
php
public function fetchAction(Request $request) { $reference = strtoupper($request->query->get('reference', null)); $remote = (bool)$request->query->get('remote', 1); if (0 < strlen($reference) && $remote) { $remoteEndPoints = $this->container->getParameter('ekyna_setting.helper_remotes'); foreach ($remoteEndPoints as $remoteEndPoint) { // remote=0 prevent infinite loop/recursion $url = $remoteEndPoint . '?reference=' . $reference . '&remote=0'; $headers = $request->headers->all(); if (null !== $response = $this->getRemoteResponse($url, $headers)) { return $response; } } } $ttl = 7 * 24 * 3600; $response = new Response(); $response ->setPublic() ->headers->add(['Content-Type' => 'application/xml; charset=utf-8']) ; if (0 < strlen($reference)) { $repository = $this->getDoctrine()->getRepository('EkynaSettingBundle:Helper'); if (null !== $helper = $repository->findOneBy(['reference' => $reference])) { $response->setLastModified($helper->getUpdatedAt()); if ($response->isNotModified($request)) { return $response; } $response->setContent($this->renderView('EkynaSettingBundle:Helper:show.xml.twig', [ 'helper' => $helper, ])); return $this->configureSharedCache($response, [$helper->getEntityTag()], $ttl); } } $expires = new \DateTime(); $expires->modify('+7 days'); return $response ->setMaxAge($ttl) ->setExpires($expires) ->setContent($this->renderView('EkynaSettingBundle:Helper:show.xml.twig')) ; }
[ "public", "function", "fetchAction", "(", "Request", "$", "request", ")", "{", "$", "reference", "=", "strtoupper", "(", "$", "request", "->", "query", "->", "get", "(", "'reference'", ",", "null", ")", ")", ";", "$", "remote", "=", "(", "bool", ")", "$", "request", "->", "query", "->", "get", "(", "'remote'", ",", "1", ")", ";", "if", "(", "0", "<", "strlen", "(", "$", "reference", ")", "&&", "$", "remote", ")", "{", "$", "remoteEndPoints", "=", "$", "this", "->", "container", "->", "getParameter", "(", "'ekyna_setting.helper_remotes'", ")", ";", "foreach", "(", "$", "remoteEndPoints", "as", "$", "remoteEndPoint", ")", "{", "// remote=0 prevent infinite loop/recursion", "$", "url", "=", "$", "remoteEndPoint", ".", "'?reference='", ".", "$", "reference", ".", "'&remote=0'", ";", "$", "headers", "=", "$", "request", "->", "headers", "->", "all", "(", ")", ";", "if", "(", "null", "!==", "$", "response", "=", "$", "this", "->", "getRemoteResponse", "(", "$", "url", ",", "$", "headers", ")", ")", "{", "return", "$", "response", ";", "}", "}", "}", "$", "ttl", "=", "7", "*", "24", "*", "3600", ";", "$", "response", "=", "new", "Response", "(", ")", ";", "$", "response", "->", "setPublic", "(", ")", "->", "headers", "->", "add", "(", "[", "'Content-Type'", "=>", "'application/xml; charset=utf-8'", "]", ")", ";", "if", "(", "0", "<", "strlen", "(", "$", "reference", ")", ")", "{", "$", "repository", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getRepository", "(", "'EkynaSettingBundle:Helper'", ")", ";", "if", "(", "null", "!==", "$", "helper", "=", "$", "repository", "->", "findOneBy", "(", "[", "'reference'", "=>", "$", "reference", "]", ")", ")", "{", "$", "response", "->", "setLastModified", "(", "$", "helper", "->", "getUpdatedAt", "(", ")", ")", ";", "if", "(", "$", "response", "->", "isNotModified", "(", "$", "request", ")", ")", "{", "return", "$", "response", ";", "}", "$", "response", "->", "setContent", "(", "$", "this", "->", "renderView", "(", "'EkynaSettingBundle:Helper:show.xml.twig'", ",", "[", "'helper'", "=>", "$", "helper", ",", "]", ")", ")", ";", "return", "$", "this", "->", "configureSharedCache", "(", "$", "response", ",", "[", "$", "helper", "->", "getEntityTag", "(", ")", "]", ",", "$", "ttl", ")", ";", "}", "}", "$", "expires", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "expires", "->", "modify", "(", "'+7 days'", ")", ";", "return", "$", "response", "->", "setMaxAge", "(", "$", "ttl", ")", "->", "setExpires", "(", "$", "expires", ")", "->", "setContent", "(", "$", "this", "->", "renderView", "(", "'EkynaSettingBundle:Helper:show.xml.twig'", ")", ")", ";", "}" ]
Fetches the helper content. @param Request $request @return \Symfony\Component\HttpFoundation\Response
[ "Fetches", "the", "helper", "content", "." ]
df58f83eb3a01ef56cd76ea73639322c581e75c1
https://github.com/ekyna/SettingBundle/blob/df58f83eb3a01ef56cd76ea73639322c581e75c1/Controller/HelperController.php#L23-L68
train
rzajac/phptools
src/Traits/Error.php
Error.addError
public function addError($error, $key = null) { if (is_string($error)) { $error = new Exception($error); } elseif ($error instanceof Exception) { // Nothing to do } else { throw new Exception('only string errors or instances of Exception can be added'); } if ($key) { $this->errors[$key] = $error; } else { $this->errors[] = $error; } return false; }
php
public function addError($error, $key = null) { if (is_string($error)) { $error = new Exception($error); } elseif ($error instanceof Exception) { // Nothing to do } else { throw new Exception('only string errors or instances of Exception can be added'); } if ($key) { $this->errors[$key] = $error; } else { $this->errors[] = $error; } return false; }
[ "public", "function", "addError", "(", "$", "error", ",", "$", "key", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "error", ")", ")", "{", "$", "error", "=", "new", "Exception", "(", "$", "error", ")", ";", "}", "elseif", "(", "$", "error", "instanceof", "Exception", ")", "{", "// Nothing to do", "}", "else", "{", "throw", "new", "Exception", "(", "'only string errors or instances of Exception can be added'", ")", ";", "}", "if", "(", "$", "key", ")", "{", "$", "this", "->", "errors", "[", "$", "key", "]", "=", "$", "error", ";", "}", "else", "{", "$", "this", "->", "errors", "[", "]", "=", "$", "error", ";", "}", "return", "false", ";", "}" ]
Add error. If the key is not provided the method will just add another element to the array. @param Exception|string $error The error @param string $key The associative array key @throws Exception @return bool Always returns false
[ "Add", "error", "." ]
3cbece7645942d244603c14ba897d8a676ee3088
https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Traits/Error.php#L49-L66
train
jaredchu/JCRequest
src/JCRequest.php
JCRequest.combineUrl
protected static function combineUrl($url, $params = []) { $urlObject = Url::parse($url); $queryData = array_merge($urlObject->query->getData(), $params); $urlObject->query->setData($queryData); return $urlObject->getUrl(); }
php
protected static function combineUrl($url, $params = []) { $urlObject = Url::parse($url); $queryData = array_merge($urlObject->query->getData(), $params); $urlObject->query->setData($queryData); return $urlObject->getUrl(); }
[ "protected", "static", "function", "combineUrl", "(", "$", "url", ",", "$", "params", "=", "[", "]", ")", "{", "$", "urlObject", "=", "Url", "::", "parse", "(", "$", "url", ")", ";", "$", "queryData", "=", "array_merge", "(", "$", "urlObject", "->", "query", "->", "getData", "(", ")", ",", "$", "params", ")", ";", "$", "urlObject", "->", "query", "->", "setData", "(", "$", "queryData", ")", ";", "return", "$", "urlObject", "->", "getUrl", "(", ")", ";", "}" ]
Manipulate the url & params for GET request @param string $url @param array $params @return string
[ "Manipulate", "the", "url", "&", "params", "for", "GET", "request" ]
d6b2fb2096f1cac9b625481be920fbccb4edae92
https://github.com/jaredchu/JCRequest/blob/d6b2fb2096f1cac9b625481be920fbccb4edae92/src/JCRequest.php#L71-L78
train
Torann/skosh-generator
src/Console/PublishCommand.php
PublishCommand.validateServer
protected function validateServer($server) { if (in_array($server, array_keys($this->servers))) { // Get server options $options = $this->config->get($server); if (!$options || $options['host'] === 'yoursite') { throw new \Exception("Remote server \"{$server}\" not setup in remote.yml."); } if (shell_exec("which {$this->servers[$server]}") == '') { throw new \Exception("Shell command '' is required to publish using {$server}"); } return true; } throw new \Exception("Unknown remote server: \"{$server}\""); }
php
protected function validateServer($server) { if (in_array($server, array_keys($this->servers))) { // Get server options $options = $this->config->get($server); if (!$options || $options['host'] === 'yoursite') { throw new \Exception("Remote server \"{$server}\" not setup in remote.yml."); } if (shell_exec("which {$this->servers[$server]}") == '') { throw new \Exception("Shell command '' is required to publish using {$server}"); } return true; } throw new \Exception("Unknown remote server: \"{$server}\""); }
[ "protected", "function", "validateServer", "(", "$", "server", ")", "{", "if", "(", "in_array", "(", "$", "server", ",", "array_keys", "(", "$", "this", "->", "servers", ")", ")", ")", "{", "// Get server options", "$", "options", "=", "$", "this", "->", "config", "->", "get", "(", "$", "server", ")", ";", "if", "(", "!", "$", "options", "||", "$", "options", "[", "'host'", "]", "===", "'yoursite'", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Remote server \\\"{$server}\\\" not setup in remote.yml.\"", ")", ";", "}", "if", "(", "shell_exec", "(", "\"which {$this->servers[$server]}\"", ")", "==", "''", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Shell command '' is required to publish using {$server}\"", ")", ";", "}", "return", "true", ";", "}", "throw", "new", "\\", "Exception", "(", "\"Unknown remote server: \\\"{$server}\\\"\"", ")", ";", "}" ]
Check existence of remote server. @param string $server @return bool @throws \Exception
[ "Check", "existence", "of", "remote", "server", "." ]
ea60e037d92398d7c146eb2349735d5692e3c48c
https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/Console/PublishCommand.php#L89-L108
train
Torann/skosh-generator
src/Console/PublishCommand.php
PublishCommand.publish_ssh
protected function publish_ssh(OutputInterface $output, $target) { // Get FTP config $config = $this->config->get('ssh'); // Ensure there isn't a leading slash $remote_dir = ltrim($config['remote_dir'], '/'); // Shell command $output->writeln(shell_exec("rsync -avze 'ssh -p {$config['port']}' {$target} {$config['user']}@{$config['host']}:{$remote_dir} --exclude .DS_Store --exclude downloads.json --exclude cache/")); return true; }
php
protected function publish_ssh(OutputInterface $output, $target) { // Get FTP config $config = $this->config->get('ssh'); // Ensure there isn't a leading slash $remote_dir = ltrim($config['remote_dir'], '/'); // Shell command $output->writeln(shell_exec("rsync -avze 'ssh -p {$config['port']}' {$target} {$config['user']}@{$config['host']}:{$remote_dir} --exclude .DS_Store --exclude downloads.json --exclude cache/")); return true; }
[ "protected", "function", "publish_ssh", "(", "OutputInterface", "$", "output", ",", "$", "target", ")", "{", "// Get FTP config", "$", "config", "=", "$", "this", "->", "config", "->", "get", "(", "'ssh'", ")", ";", "// Ensure there isn't a leading slash", "$", "remote_dir", "=", "ltrim", "(", "$", "config", "[", "'remote_dir'", "]", ",", "'/'", ")", ";", "// Shell command", "$", "output", "->", "writeln", "(", "shell_exec", "(", "\"rsync -avze 'ssh -p {$config['port']}' {$target} {$config['user']}@{$config['host']}:{$remote_dir} --exclude .DS_Store --exclude downloads.json --exclude cache/\"", ")", ")", ";", "return", "true", ";", "}" ]
Publish using SSH. @param OutputInterface $output @param string $target @return bool @throws \Exception
[ "Publish", "using", "SSH", "." ]
ea60e037d92398d7c146eb2349735d5692e3c48c
https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/Console/PublishCommand.php#L118-L130
train
Danack/Jig
src/Jig/JigConfig.php
JigConfig.getCompiledFilenameFromClassname
public function getCompiledFilenameFromClassname($fqcn) { $filename = $this->templateCompileDirectory.'/'.$fqcn.'.php'; $filename = str_replace('\\', '/', $filename); return $filename; }
php
public function getCompiledFilenameFromClassname($fqcn) { $filename = $this->templateCompileDirectory.'/'.$fqcn.'.php'; $filename = str_replace('\\', '/', $filename); return $filename; }
[ "public", "function", "getCompiledFilenameFromClassname", "(", "$", "fqcn", ")", "{", "$", "filename", "=", "$", "this", "->", "templateCompileDirectory", ".", "'/'", ".", "$", "fqcn", ".", "'.php'", ";", "$", "filename", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "filename", ")", ";", "return", "$", "filename", ";", "}" ]
Returns the fully pathed filename for a compiled class. @param $fqcn @return string
[ "Returns", "the", "fully", "pathed", "filename", "for", "a", "compiled", "class", "." ]
b11106bc7d634add9873bf246eda1dadb059ed7a
https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/JigConfig.php#L57-L63
train
Danack/Jig
src/Jig/JigConfig.php
JigConfig.getFQCNFromTemplateName
public function getFQCNFromTemplateName($templateName) { $classname = $this->compiledNamespace."\\".$templateName; $classname = str_replace('/', '\\', $classname); $classname .= "Jig"; return $classname; }
php
public function getFQCNFromTemplateName($templateName) { $classname = $this->compiledNamespace."\\".$templateName; $classname = str_replace('/', '\\', $classname); $classname .= "Jig"; return $classname; }
[ "public", "function", "getFQCNFromTemplateName", "(", "$", "templateName", ")", "{", "$", "classname", "=", "$", "this", "->", "compiledNamespace", ".", "\"\\\\\"", ".", "$", "templateName", ";", "$", "classname", "=", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "$", "classname", ")", ";", "$", "classname", ".=", "\"Jig\"", ";", "return", "$", "classname", ";", "}" ]
Generate the full class name for the compiled version of a template.. @param $templateName @return string
[ "Generate", "the", "full", "class", "name", "for", "the", "compiled", "version", "of", "a", "template", ".." ]
b11106bc7d634add9873bf246eda1dadb059ed7a
https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/JigConfig.php#L70-L77
train
FuzeWorks/Core
src/Libraries/Zip.php
FW_Zip.read_file
public function read_file($path, $archive_filepath = FALSE) { if (file_exists($path) && FALSE !== ($data = file_get_contents($path))) { if (is_string($archive_filepath)) { $name = str_replace('\\', '/', $archive_filepath); } else { $name = str_replace('\\', '/', $path); if ($archive_filepath === FALSE) { $name = preg_replace('|.*/(.+)|', '\\1', $name); } } $this->add_data($name, $data); return TRUE; } return FALSE; }
php
public function read_file($path, $archive_filepath = FALSE) { if (file_exists($path) && FALSE !== ($data = file_get_contents($path))) { if (is_string($archive_filepath)) { $name = str_replace('\\', '/', $archive_filepath); } else { $name = str_replace('\\', '/', $path); if ($archive_filepath === FALSE) { $name = preg_replace('|.*/(.+)|', '\\1', $name); } } $this->add_data($name, $data); return TRUE; } return FALSE; }
[ "public", "function", "read_file", "(", "$", "path", ",", "$", "archive_filepath", "=", "FALSE", ")", "{", "if", "(", "file_exists", "(", "$", "path", ")", "&&", "FALSE", "!==", "(", "$", "data", "=", "file_get_contents", "(", "$", "path", ")", ")", ")", "{", "if", "(", "is_string", "(", "$", "archive_filepath", ")", ")", "{", "$", "name", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "archive_filepath", ")", ";", "}", "else", "{", "$", "name", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "path", ")", ";", "if", "(", "$", "archive_filepath", "===", "FALSE", ")", "{", "$", "name", "=", "preg_replace", "(", "'|.*/(.+)|'", ",", "'\\\\1'", ",", "$", "name", ")", ";", "}", "}", "$", "this", "->", "add_data", "(", "$", "name", ",", "$", "data", ")", ";", "return", "TRUE", ";", "}", "return", "FALSE", ";", "}" ]
Read the contents of a file and add it to the zip @param string $path @param bool $archive_filepath @return bool
[ "Read", "the", "contents", "of", "a", "file", "and", "add", "it", "to", "the", "zip" ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/Libraries/Zip.php#L312-L335
train
FuzeWorks/Core
src/Libraries/Zip.php
FW_Zip.read_dir
public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR; if ( ! $fp = @opendir($path)) { return FALSE; } // Set the original directory root for child dir's to use as relative if ($root_path === NULL) { $root_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, dirname($path)).DIRECTORY_SEPARATOR; } while (FALSE !== ($file = readdir($fp))) { if ($file[0] === '.') { continue; } if (is_dir($path.$file)) { $this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path); } elseif (FALSE !== ($data = file_get_contents($path.$file))) { $name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path); if ($preserve_filepath === FALSE) { $name = str_replace($root_path, '', $name); } $this->add_data($name.$file, $data); } } closedir($fp); return TRUE; }
php
public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR; if ( ! $fp = @opendir($path)) { return FALSE; } // Set the original directory root for child dir's to use as relative if ($root_path === NULL) { $root_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, dirname($path)).DIRECTORY_SEPARATOR; } while (FALSE !== ($file = readdir($fp))) { if ($file[0] === '.') { continue; } if (is_dir($path.$file)) { $this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path); } elseif (FALSE !== ($data = file_get_contents($path.$file))) { $name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path); if ($preserve_filepath === FALSE) { $name = str_replace($root_path, '', $name); } $this->add_data($name.$file, $data); } } closedir($fp); return TRUE; }
[ "public", "function", "read_dir", "(", "$", "path", ",", "$", "preserve_filepath", "=", "TRUE", ",", "$", "root_path", "=", "NULL", ")", "{", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/\\\\'", ")", ".", "DIRECTORY_SEPARATOR", ";", "if", "(", "!", "$", "fp", "=", "@", "opendir", "(", "$", "path", ")", ")", "{", "return", "FALSE", ";", "}", "// Set the original directory root for child dir's to use as relative", "if", "(", "$", "root_path", "===", "NULL", ")", "{", "$", "root_path", "=", "str_replace", "(", "array", "(", "'\\\\'", ",", "'/'", ")", ",", "DIRECTORY_SEPARATOR", ",", "dirname", "(", "$", "path", ")", ")", ".", "DIRECTORY_SEPARATOR", ";", "}", "while", "(", "FALSE", "!==", "(", "$", "file", "=", "readdir", "(", "$", "fp", ")", ")", ")", "{", "if", "(", "$", "file", "[", "0", "]", "===", "'.'", ")", "{", "continue", ";", "}", "if", "(", "is_dir", "(", "$", "path", ".", "$", "file", ")", ")", "{", "$", "this", "->", "read_dir", "(", "$", "path", ".", "$", "file", ".", "DIRECTORY_SEPARATOR", ",", "$", "preserve_filepath", ",", "$", "root_path", ")", ";", "}", "elseif", "(", "FALSE", "!==", "(", "$", "data", "=", "file_get_contents", "(", "$", "path", ".", "$", "file", ")", ")", ")", "{", "$", "name", "=", "str_replace", "(", "array", "(", "'\\\\'", ",", "'/'", ")", ",", "DIRECTORY_SEPARATOR", ",", "$", "path", ")", ";", "if", "(", "$", "preserve_filepath", "===", "FALSE", ")", "{", "$", "name", "=", "str_replace", "(", "$", "root_path", ",", "''", ",", "$", "name", ")", ";", "}", "$", "this", "->", "add_data", "(", "$", "name", ".", "$", "file", ",", "$", "data", ")", ";", "}", "}", "closedir", "(", "$", "fp", ")", ";", "return", "TRUE", ";", "}" ]
Read a directory and add it to the zip. This function recursively reads a folder and everything it contains (including sub-folders) and creates a zip based on it. Whatever directory structure is in the original file path will be recreated in the zip file. @param string $path path to source directory @param bool $preserve_filepath @param string $root_path @return bool
[ "Read", "a", "directory", "and", "add", "it", "to", "the", "zip", "." ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/Libraries/Zip.php#L351-L390
train
FuzeWorks/Core
src/Libraries/Zip.php
FW_Zip.get_zip
public function get_zip() { // Is there any data to return? if ($this->entries === 0) { return FALSE; } return $this->zipdata .$this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00" .pack('v', $this->entries) // total # of entries "on this disk" .pack('v', $this->entries) // total # of entries overall .pack('V', strlen($this->directory)) // size of central dir .pack('V', strlen($this->zipdata)) // offset to start of central dir ."\x00\x00"; // .zip file comment length }
php
public function get_zip() { // Is there any data to return? if ($this->entries === 0) { return FALSE; } return $this->zipdata .$this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00" .pack('v', $this->entries) // total # of entries "on this disk" .pack('v', $this->entries) // total # of entries overall .pack('V', strlen($this->directory)) // size of central dir .pack('V', strlen($this->zipdata)) // offset to start of central dir ."\x00\x00"; // .zip file comment length }
[ "public", "function", "get_zip", "(", ")", "{", "// Is there any data to return?", "if", "(", "$", "this", "->", "entries", "===", "0", ")", "{", "return", "FALSE", ";", "}", "return", "$", "this", "->", "zipdata", ".", "$", "this", "->", "directory", ".", "\"\\x50\\x4b\\x05\\x06\\x00\\x00\\x00\\x00\"", ".", "pack", "(", "'v'", ",", "$", "this", "->", "entries", ")", "// total # of entries \"on this disk\"", ".", "pack", "(", "'v'", ",", "$", "this", "->", "entries", ")", "// total # of entries overall", ".", "pack", "(", "'V'", ",", "strlen", "(", "$", "this", "->", "directory", ")", ")", "// size of central dir", ".", "pack", "(", "'V'", ",", "strlen", "(", "$", "this", "->", "zipdata", ")", ")", "// offset to start of central dir", ".", "\"\\x00\\x00\"", ";", "// .zip file comment length", "}" ]
Get the Zip file @return string (binary encoded)
[ "Get", "the", "Zip", "file" ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/Libraries/Zip.php#L399-L414
train
FuzeWorks/Core
src/Libraries/Zip.php
FW_Zip.archive
public function archive($filepath) { if ( ! ($fp = @fopen($filepath, 'w+b'))) { return FALSE; } flock($fp, LOCK_EX); for ($result = $written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result) { if (($result = fwrite($fp, substr($data, $written))) === FALSE) { break; } } flock($fp, LOCK_UN); fclose($fp); return is_int($result); }
php
public function archive($filepath) { if ( ! ($fp = @fopen($filepath, 'w+b'))) { return FALSE; } flock($fp, LOCK_EX); for ($result = $written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result) { if (($result = fwrite($fp, substr($data, $written))) === FALSE) { break; } } flock($fp, LOCK_UN); fclose($fp); return is_int($result); }
[ "public", "function", "archive", "(", "$", "filepath", ")", "{", "if", "(", "!", "(", "$", "fp", "=", "@", "fopen", "(", "$", "filepath", ",", "'w+b'", ")", ")", ")", "{", "return", "FALSE", ";", "}", "flock", "(", "$", "fp", ",", "LOCK_EX", ")", ";", "for", "(", "$", "result", "=", "$", "written", "=", "0", ",", "$", "data", "=", "$", "this", "->", "get_zip", "(", ")", ",", "$", "length", "=", "strlen", "(", "$", "data", ")", ";", "$", "written", "<", "$", "length", ";", "$", "written", "+=", "$", "result", ")", "{", "if", "(", "(", "$", "result", "=", "fwrite", "(", "$", "fp", ",", "substr", "(", "$", "data", ",", "$", "written", ")", ")", ")", "===", "FALSE", ")", "{", "break", ";", "}", "}", "flock", "(", "$", "fp", ",", "LOCK_UN", ")", ";", "fclose", "(", "$", "fp", ")", ";", "return", "is_int", "(", "$", "result", ")", ";", "}" ]
Write File to the specified directory Lets you write a file @param string $filepath the file name @return bool
[ "Write", "File", "to", "the", "specified", "directory" ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/Libraries/Zip.php#L426-L447
train
covex-nn/JooS
src/JooS/Log/Log/Event.php
Log_Event.validateMessage
public function validateMessage($value) { if (is_string($value)) { $result = true; } elseif (is_object($value) && method_exists($value, "__toString")) { $result = true; } else { $result = false; } return $result; }
php
public function validateMessage($value) { if (is_string($value)) { $result = true; } elseif (is_object($value) && method_exists($value, "__toString")) { $result = true; } else { $result = false; } return $result; }
[ "public", "function", "validateMessage", "(", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "result", "=", "true", ";", "}", "elseif", "(", "is_object", "(", "$", "value", ")", "&&", "method_exists", "(", "$", "value", ",", "\"__toString\"", ")", ")", "{", "$", "result", "=", "true", ";", "}", "else", "{", "$", "result", "=", "false", ";", "}", "return", "$", "result", ";", "}" ]
Validator for 'message' property @param string $value Message @return boolean
[ "Validator", "for", "message", "property" ]
8dfb94edccecaf307787d4091ba7f20a674b7792
https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Log/Log/Event.php#L29-L40
train
locomotivemtl/charcoal-config
src/Charcoal/Config/AbstractEntity.php
AbstractEntity.data
public function data(array $keys = null) { if ($keys === null) { $keys = $this->keys(); } $data = []; foreach ($keys as $key) { if (strtolower($key) === 'data') { /** @internal Edge Case: Avoid recursive call */ continue; } if (isset($this[$key])) { $data[$key] = $this[$key]; } } return $data; }
php
public function data(array $keys = null) { if ($keys === null) { $keys = $this->keys(); } $data = []; foreach ($keys as $key) { if (strtolower($key) === 'data') { /** @internal Edge Case: Avoid recursive call */ continue; } if (isset($this[$key])) { $data[$key] = $this[$key]; } } return $data; }
[ "public", "function", "data", "(", "array", "$", "keys", "=", "null", ")", "{", "if", "(", "$", "keys", "===", "null", ")", "{", "$", "keys", "=", "$", "this", "->", "keys", "(", ")", ";", "}", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "strtolower", "(", "$", "key", ")", "===", "'data'", ")", "{", "/** @internal Edge Case: Avoid recursive call */", "continue", ";", "}", "if", "(", "isset", "(", "$", "this", "[", "$", "key", "]", ")", ")", "{", "$", "data", "[", "$", "key", "]", "=", "$", "this", "[", "$", "key", "]", ";", "}", "}", "return", "$", "data", ";", "}" ]
Gets all data, or a subset, from this entity. @uses self::offsetExists() @uses self::offsetGet() @param string[] $keys Optional. Extracts only the requested data. @return array Key-value array of data, excluding pairs with NULL values.
[ "Gets", "all", "data", "or", "a", "subset", "from", "this", "entity", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/AbstractEntity.php#L47-L65
train
locomotivemtl/charcoal-config
src/Charcoal/Config/AbstractEntity.php
AbstractEntity.offsetExists
public function offsetExists($key) { if (is_numeric($key)) { throw new InvalidArgumentException( 'Entity array access only supports non-numeric keys' ); } $key = $this->camelize($key); /** @internal Edge Case: "_" → "" */ if ($key === '') { return false; } if (is_callable([ $this, $key ])) { $value = $this->{$key}(); } else { if (!isset($this->{$key})) { return false; } $value = $this->{$key}; } return ($value !== null); }
php
public function offsetExists($key) { if (is_numeric($key)) { throw new InvalidArgumentException( 'Entity array access only supports non-numeric keys' ); } $key = $this->camelize($key); /** @internal Edge Case: "_" → "" */ if ($key === '') { return false; } if (is_callable([ $this, $key ])) { $value = $this->{$key}(); } else { if (!isset($this->{$key})) { return false; } $value = $this->{$key}; } return ($value !== null); }
[ "public", "function", "offsetExists", "(", "$", "key", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Entity array access only supports non-numeric keys'", ")", ";", "}", "$", "key", "=", "$", "this", "->", "camelize", "(", "$", "key", ")", ";", "/** @internal Edge Case: \"_\" → \"\" */", "if", "(", "$", "key", "===", "''", ")", "{", "return", "false", ";", "}", "if", "(", "is_callable", "(", "[", "$", "this", ",", "$", "key", "]", ")", ")", "{", "$", "value", "=", "$", "this", "->", "{", "$", "key", "}", "(", ")", ";", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "{", "$", "key", "}", ")", ")", "{", "return", "false", ";", "}", "$", "value", "=", "$", "this", "->", "{", "$", "key", "}", ";", "}", "return", "(", "$", "value", "!==", "null", ")", ";", "}" ]
Determines if this entity contains the specified key and if its value is not NULL. Routine: - If the entity has a getter method (e.g., "foo_bar" → `fooBar()`), its called and its value is checked; - If the entity has a property (e.g., `$fooBar`), its value is checked; - If the entity has neither, FALSE is returned. @see \ArrayAccess @param string $key The data key to check. @throws InvalidArgumentException If the $key is not a string or is a numeric value. @return boolean TRUE if $key exists and has a value other than NULL, FALSE otherwise.
[ "Determines", "if", "this", "entity", "contains", "the", "specified", "key", "and", "if", "its", "value", "is", "not", "NULL", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/AbstractEntity.php#L139-L164
train
locomotivemtl/charcoal-config
src/Charcoal/Config/AbstractEntity.php
AbstractEntity.offsetSet
public function offsetSet($key, $value) { if (is_numeric($key)) { throw new InvalidArgumentException( 'Entity array access only supports non-numeric keys' ); } $key = $this->camelize($key); /** @internal Edge Case: "_" → "" */ if ($key === '') { return; } $setter = 'set'.ucfirst($key); if (is_callable([ $this, $setter ])) { $this->{$setter}($value); } else { $this->{$key} = $value; } $this->keys[$key] = true; }
php
public function offsetSet($key, $value) { if (is_numeric($key)) { throw new InvalidArgumentException( 'Entity array access only supports non-numeric keys' ); } $key = $this->camelize($key); /** @internal Edge Case: "_" → "" */ if ($key === '') { return; } $setter = 'set'.ucfirst($key); if (is_callable([ $this, $setter ])) { $this->{$setter}($value); } else { $this->{$key} = $value; } $this->keys[$key] = true; }
[ "public", "function", "offsetSet", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Entity array access only supports non-numeric keys'", ")", ";", "}", "$", "key", "=", "$", "this", "->", "camelize", "(", "$", "key", ")", ";", "/** @internal Edge Case: \"_\" → \"\" */", "if", "(", "$", "key", "===", "''", ")", "{", "return", ";", "}", "$", "setter", "=", "'set'", ".", "ucfirst", "(", "$", "key", ")", ";", "if", "(", "is_callable", "(", "[", "$", "this", ",", "$", "setter", "]", ")", ")", "{", "$", "this", "->", "{", "$", "setter", "}", "(", "$", "value", ")", ";", "}", "else", "{", "$", "this", "->", "{", "$", "key", "}", "=", "$", "value", ";", "}", "$", "this", "->", "keys", "[", "$", "key", "]", "=", "true", ";", "}" ]
Assigns the value to the specified key on this entity. Routine: - The data key is added to the {@see self::$keys entity's key pool}. - If the entity has a setter method (e.g., "foo_bar" → `setFooBar()`), its called and passed the value; - If the entity has NO setter method, the value is assigned to a property (e.g., `$fooBar`). @see \ArrayAccess @param string $key The data key to assign $value to. @param mixed $value The data value to assign to $key. @throws InvalidArgumentException If the $key is not a string or is a numeric value. @return void
[ "Assigns", "the", "value", "to", "the", "specified", "key", "on", "this", "entity", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/AbstractEntity.php#L221-L244
train
locomotivemtl/charcoal-config
src/Charcoal/Config/AbstractEntity.php
AbstractEntity.offsetUnset
public function offsetUnset($key) { if (is_numeric($key)) { throw new InvalidArgumentException( 'Entity array access only supports non-numeric keys' ); } $key = $this->camelize($key); /** @internal Edge Case: "_" → "" */ if ($key === '') { return; } $this[$key] = null; unset($this->keys[$key]); }
php
public function offsetUnset($key) { if (is_numeric($key)) { throw new InvalidArgumentException( 'Entity array access only supports non-numeric keys' ); } $key = $this->camelize($key); /** @internal Edge Case: "_" → "" */ if ($key === '') { return; } $this[$key] = null; unset($this->keys[$key]); }
[ "public", "function", "offsetUnset", "(", "$", "key", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Entity array access only supports non-numeric keys'", ")", ";", "}", "$", "key", "=", "$", "this", "->", "camelize", "(", "$", "key", ")", ";", "/** @internal Edge Case: \"_\" → \"\" */", "if", "(", "$", "key", "===", "''", ")", "{", "return", ";", "}", "$", "this", "[", "$", "key", "]", "=", "null", ";", "unset", "(", "$", "this", "->", "keys", "[", "$", "key", "]", ")", ";", "}" ]
Removes the value from the specified key on this entity. Routine: - The data key is removed from the {@see self::$keys entity's key pool}. - NULL is {@see self::offsetSet() assigned} to the entity. @see \ArrayAccess @uses self::offsetSet() @param string $key The data key to remove. @throws InvalidArgumentException If the $key is not a string or is a numeric value. @return void
[ "Removes", "the", "value", "from", "the", "specified", "key", "on", "this", "entity", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/AbstractEntity.php#L259-L276
train
locomotivemtl/charcoal-config
src/Charcoal/Config/AbstractEntity.php
AbstractEntity.camelize
final protected function camelize($str) { if (strstr($str, '_') === false) { return $str; } return lcfirst(implode('', array_map('ucfirst', explode('_', $str)))); }
php
final protected function camelize($str) { if (strstr($str, '_') === false) { return $str; } return lcfirst(implode('', array_map('ucfirst', explode('_', $str)))); }
[ "final", "protected", "function", "camelize", "(", "$", "str", ")", "{", "if", "(", "strstr", "(", "$", "str", ",", "'_'", ")", "===", "false", ")", "{", "return", "$", "str", ";", "}", "return", "lcfirst", "(", "implode", "(", "''", ",", "array_map", "(", "'ucfirst'", ",", "explode", "(", "'_'", ",", "$", "str", ")", ")", ")", ")", ";", "}" ]
Transform a string from "snake_case" to "camelCase". @param string $str The string to camelize. @return string The camelized string.
[ "Transform", "a", "string", "from", "snake_case", "to", "camelCase", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/AbstractEntity.php#L319-L325
train
midnightLuke/group-security-bundle
Security/GroupRoleVoter.php
GroupRoleVoter.extractRoles
public function extractRoles(GroupMembershipInterface $membership) { $roles = []; foreach ($membership->getRoles() as $role) { $roles[] = new Role($role); } return $roles; }
php
public function extractRoles(GroupMembershipInterface $membership) { $roles = []; foreach ($membership->getRoles() as $role) { $roles[] = new Role($role); } return $roles; }
[ "public", "function", "extractRoles", "(", "GroupMembershipInterface", "$", "membership", ")", "{", "$", "roles", "=", "[", "]", ";", "foreach", "(", "$", "membership", "->", "getRoles", "(", ")", "as", "$", "role", ")", "{", "$", "roles", "[", "]", "=", "new", "Role", "(", "$", "role", ")", ";", "}", "return", "$", "roles", ";", "}" ]
Returns the roles for this membership.
[ "Returns", "the", "roles", "for", "this", "membership", "." ]
b7e497939dc3fd9bc205b4595d29e2aa8f6e62c0
https://github.com/midnightLuke/group-security-bundle/blob/b7e497939dc3fd9bc205b4595d29e2aa8f6e62c0/Security/GroupRoleVoter.php#L68-L75
train
Torann/skosh-generator
src/Content/Post.php
Post.getExcerpt
protected function getExcerpt($content) { // Check for excerpt tags $pattern = '#(\<\!\-\-\s?excerpt\s?\-\-\>)(.*)(\<\!\-\-\s?endexcerpt\s?\-\-\>)#si'; if (preg_match($pattern, $content, $matches)) { return $matches[2]; } // If all else get the content from the first paragraph return $this->description; }
php
protected function getExcerpt($content) { // Check for excerpt tags $pattern = '#(\<\!\-\-\s?excerpt\s?\-\-\>)(.*)(\<\!\-\-\s?endexcerpt\s?\-\-\>)#si'; if (preg_match($pattern, $content, $matches)) { return $matches[2]; } // If all else get the content from the first paragraph return $this->description; }
[ "protected", "function", "getExcerpt", "(", "$", "content", ")", "{", "// Check for excerpt tags", "$", "pattern", "=", "'#(\\<\\!\\-\\-\\s?excerpt\\s?\\-\\-\\>)(.*)(\\<\\!\\-\\-\\s?endexcerpt\\s?\\-\\-\\>)#si'", ";", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "content", ",", "$", "matches", ")", ")", "{", "return", "$", "matches", "[", "2", "]", ";", "}", "// If all else get the content from the first paragraph", "return", "$", "this", "->", "description", ";", "}" ]
Get excerpt from between excerpt tags or first paragraph. @param string $content @return string
[ "Get", "excerpt", "from", "between", "excerpt", "tags", "or", "first", "paragraph", "." ]
ea60e037d92398d7c146eb2349735d5692e3c48c
https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/Content/Post.php#L74-L84
train
Torann/skosh-generator
src/Content/Post.php
Post.getTagClassNames
protected function getTagClassNames() { $tags = array_map(function($tag) { return slugify($tag); }, explode('|', $this->get('tags'))); return implode(' ', $tags); }
php
protected function getTagClassNames() { $tags = array_map(function($tag) { return slugify($tag); }, explode('|', $this->get('tags'))); return implode(' ', $tags); }
[ "protected", "function", "getTagClassNames", "(", ")", "{", "$", "tags", "=", "array_map", "(", "function", "(", "$", "tag", ")", "{", "return", "slugify", "(", "$", "tag", ")", ";", "}", ",", "explode", "(", "'|'", ",", "$", "this", "->", "get", "(", "'tags'", ")", ")", ")", ";", "return", "implode", "(", "' '", ",", "$", "tags", ")", ";", "}" ]
Get human readable tags. @return string
[ "Get", "human", "readable", "tags", "." ]
ea60e037d92398d7c146eb2349735d5692e3c48c
https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/Content/Post.php#L113-L120
train
vdhicts/dicms-html-element
src/Element.php
Element.getAttribute
public function getAttribute(string $attribute): array { // Determine if the attribute is present if (! array_key_exists($attribute, $this->attributes)) { return []; } // Return the value of the attribute return $this->attributes[$attribute]; }
php
public function getAttribute(string $attribute): array { // Determine if the attribute is present if (! array_key_exists($attribute, $this->attributes)) { return []; } // Return the value of the attribute return $this->attributes[$attribute]; }
[ "public", "function", "getAttribute", "(", "string", "$", "attribute", ")", ":", "array", "{", "// Determine if the attribute is present", "if", "(", "!", "array_key_exists", "(", "$", "attribute", ",", "$", "this", "->", "attributes", ")", ")", "{", "return", "[", "]", ";", "}", "// Return the value of the attribute", "return", "$", "this", "->", "attributes", "[", "$", "attribute", "]", ";", "}" ]
Returns the value of the attribute. If the value isn't set, it returns the fallback; @param string $attribute @return array
[ "Returns", "the", "value", "of", "the", "attribute", ".", "If", "the", "value", "isn", "t", "set", "it", "returns", "the", "fallback", ";" ]
4b1013c78cd8d1bc677508ec732a1ba5305e7e4e
https://github.com/vdhicts/dicms-html-element/blob/4b1013c78cd8d1bc677508ec732a1ba5305e7e4e/src/Element.php#L86-L95
train
vdhicts/dicms-html-element
src/Element.php
Element.setAttributes
public function setAttributes(array $attributesValues): self { foreach ($attributesValues as $attribute => $value) { $this->setAttribute($attribute, $value); } return $this; }
php
public function setAttributes(array $attributesValues): self { foreach ($attributesValues as $attribute => $value) { $this->setAttribute($attribute, $value); } return $this; }
[ "public", "function", "setAttributes", "(", "array", "$", "attributesValues", ")", ":", "self", "{", "foreach", "(", "$", "attributesValues", "as", "$", "attribute", "=>", "$", "value", ")", "{", "$", "this", "->", "setAttribute", "(", "$", "attribute", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the value of multiple attributes at once. @param array $attributesValues @return $this
[ "Set", "the", "value", "of", "multiple", "attributes", "at", "once", "." ]
4b1013c78cd8d1bc677508ec732a1ba5305e7e4e
https://github.com/vdhicts/dicms-html-element/blob/4b1013c78cd8d1bc677508ec732a1ba5305e7e4e/src/Element.php#L102-L109
train
vdhicts/dicms-html-element
src/Element.php
Element.setAttribute
public function setAttribute(string $attribute, $value = []): self { $this->attributes[$attribute] = $this->wrap($value); return $this; }
php
public function setAttribute(string $attribute, $value = []): self { $this->attributes[$attribute] = $this->wrap($value); return $this; }
[ "public", "function", "setAttribute", "(", "string", "$", "attribute", ",", "$", "value", "=", "[", "]", ")", ":", "self", "{", "$", "this", "->", "attributes", "[", "$", "attribute", "]", "=", "$", "this", "->", "wrap", "(", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Sets the value of an attribute. If the attribute is already set, it overwrites the current value. @param string $attribute @param array|string $value @return $this
[ "Sets", "the", "value", "of", "an", "attribute", ".", "If", "the", "attribute", "is", "already", "set", "it", "overwrites", "the", "current", "value", "." ]
4b1013c78cd8d1bc677508ec732a1ba5305e7e4e
https://github.com/vdhicts/dicms-html-element/blob/4b1013c78cd8d1bc677508ec732a1ba5305e7e4e/src/Element.php#L117-L122
train
vdhicts/dicms-html-element
src/Element.php
Element.addAttributeValue
public function addAttributeValue(string $attribute, string $value = ''): self { // Retrieve the current values of the attribute $values = $this->getAttribute($attribute); // Merge the values if (! in_array($value, $values)) { $values[] = $value; } // Store the new values $this->setAttribute($attribute, $values); return $this; }
php
public function addAttributeValue(string $attribute, string $value = ''): self { // Retrieve the current values of the attribute $values = $this->getAttribute($attribute); // Merge the values if (! in_array($value, $values)) { $values[] = $value; } // Store the new values $this->setAttribute($attribute, $values); return $this; }
[ "public", "function", "addAttributeValue", "(", "string", "$", "attribute", ",", "string", "$", "value", "=", "''", ")", ":", "self", "{", "// Retrieve the current values of the attribute", "$", "values", "=", "$", "this", "->", "getAttribute", "(", "$", "attribute", ")", ";", "// Merge the values", "if", "(", "!", "in_array", "(", "$", "value", ",", "$", "values", ")", ")", "{", "$", "values", "[", "]", "=", "$", "value", ";", "}", "// Store the new values", "$", "this", "->", "setAttribute", "(", "$", "attribute", ",", "$", "values", ")", ";", "return", "$", "this", ";", "}" ]
Adds a value to the attribute. @param string $attribute @param string $value @return $this
[ "Adds", "a", "value", "to", "the", "attribute", "." ]
4b1013c78cd8d1bc677508ec732a1ba5305e7e4e
https://github.com/vdhicts/dicms-html-element/blob/4b1013c78cd8d1bc677508ec732a1ba5305e7e4e/src/Element.php#L130-L144
train
vdhicts/dicms-html-element
src/Element.php
Element.removeAttributeValue
public function removeAttributeValue(string $attribute, string $value): self { // Only remove value if attribute is present if (! array_key_exists($attribute, $this->attributes)) { return $this; } // Remove the value from the attribute $values = array_filter( $this->getAttribute($attribute), function ($attributeValue) use ($value) { return $attributeValue !== $value; } ); // Stores the new values $this->setAttribute($attribute, $values); return $this; }
php
public function removeAttributeValue(string $attribute, string $value): self { // Only remove value if attribute is present if (! array_key_exists($attribute, $this->attributes)) { return $this; } // Remove the value from the attribute $values = array_filter( $this->getAttribute($attribute), function ($attributeValue) use ($value) { return $attributeValue !== $value; } ); // Stores the new values $this->setAttribute($attribute, $values); return $this; }
[ "public", "function", "removeAttributeValue", "(", "string", "$", "attribute", ",", "string", "$", "value", ")", ":", "self", "{", "// Only remove value if attribute is present", "if", "(", "!", "array_key_exists", "(", "$", "attribute", ",", "$", "this", "->", "attributes", ")", ")", "{", "return", "$", "this", ";", "}", "// Remove the value from the attribute", "$", "values", "=", "array_filter", "(", "$", "this", "->", "getAttribute", "(", "$", "attribute", ")", ",", "function", "(", "$", "attributeValue", ")", "use", "(", "$", "value", ")", "{", "return", "$", "attributeValue", "!==", "$", "value", ";", "}", ")", ";", "// Stores the new values", "$", "this", "->", "setAttribute", "(", "$", "attribute", ",", "$", "values", ")", ";", "return", "$", "this", ";", "}" ]
Removes a value from the attribute. @param string $attribute @param string $value @return $this
[ "Removes", "a", "value", "from", "the", "attribute", "." ]
4b1013c78cd8d1bc677508ec732a1ba5305e7e4e
https://github.com/vdhicts/dicms-html-element/blob/4b1013c78cd8d1bc677508ec732a1ba5305e7e4e/src/Element.php#L178-L197
train
vdhicts/dicms-html-element
src/Element.php
Element.generateAttribute
private function generateAttribute(string $attribute, array $values = []): string { if (! is_numeric($attribute)) { return sprintf( '%s="%s"', $attribute, htmlentities(trim(implode(' ', $values))) ); } return implode(' ', $values); }
php
private function generateAttribute(string $attribute, array $values = []): string { if (! is_numeric($attribute)) { return sprintf( '%s="%s"', $attribute, htmlentities(trim(implode(' ', $values))) ); } return implode(' ', $values); }
[ "private", "function", "generateAttribute", "(", "string", "$", "attribute", ",", "array", "$", "values", "=", "[", "]", ")", ":", "string", "{", "if", "(", "!", "is_numeric", "(", "$", "attribute", ")", ")", "{", "return", "sprintf", "(", "'%s=\"%s\"'", ",", "$", "attribute", ",", "htmlentities", "(", "trim", "(", "implode", "(", "' '", ",", "$", "values", ")", ")", ")", ")", ";", "}", "return", "implode", "(", "' '", ",", "$", "values", ")", ";", "}" ]
Generates the HTML for the attribute. @param string $attribute @param array $values @return string
[ "Generates", "the", "HTML", "for", "the", "attribute", "." ]
4b1013c78cd8d1bc677508ec732a1ba5305e7e4e
https://github.com/vdhicts/dicms-html-element/blob/4b1013c78cd8d1bc677508ec732a1ba5305e7e4e/src/Element.php#L264-L275
train
vdhicts/dicms-html-element
src/Element.php
Element.generateTagAttributes
private function generateTagAttributes(): string { // When no attributes present, return empty string if (count($this->getAttributes()) === 0) { return ''; } // Collect the attributes $renderedAttributes = []; foreach ($this->getAttributes() as $attribute => $value) { // Attributes can have a value or not, it just present (i.e. checked) $renderedAttributes[] = $this->generateAttribute($attribute, $value); } // Join the attributes with a space return implode(' ', $renderedAttributes); }
php
private function generateTagAttributes(): string { // When no attributes present, return empty string if (count($this->getAttributes()) === 0) { return ''; } // Collect the attributes $renderedAttributes = []; foreach ($this->getAttributes() as $attribute => $value) { // Attributes can have a value or not, it just present (i.e. checked) $renderedAttributes[] = $this->generateAttribute($attribute, $value); } // Join the attributes with a space return implode(' ', $renderedAttributes); }
[ "private", "function", "generateTagAttributes", "(", ")", ":", "string", "{", "// When no attributes present, return empty string", "if", "(", "count", "(", "$", "this", "->", "getAttributes", "(", ")", ")", "===", "0", ")", "{", "return", "''", ";", "}", "// Collect the attributes", "$", "renderedAttributes", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getAttributes", "(", ")", "as", "$", "attribute", "=>", "$", "value", ")", "{", "// Attributes can have a value or not, it just present (i.e. checked)", "$", "renderedAttributes", "[", "]", "=", "$", "this", "->", "generateAttribute", "(", "$", "attribute", ",", "$", "value", ")", ";", "}", "// Join the attributes with a space", "return", "implode", "(", "' '", ",", "$", "renderedAttributes", ")", ";", "}" ]
Generates the HTML for the attributes of the HTML element. @return string
[ "Generates", "the", "HTML", "for", "the", "attributes", "of", "the", "HTML", "element", "." ]
4b1013c78cd8d1bc677508ec732a1ba5305e7e4e
https://github.com/vdhicts/dicms-html-element/blob/4b1013c78cd8d1bc677508ec732a1ba5305e7e4e/src/Element.php#L281-L297
train
vdhicts/dicms-html-element
src/Element.php
Element.generate
public function generate(): string { // The tag name is required if ($this->getTag() === '') { return ''; } // Generate the attribute string $tagAttributes = $this->generateTagAttributes(); // When attributes are provided, add a space between the tag and the attributes $tagSeparator = ''; if ($tagAttributes !== '') { $tagSeparator = ' '; } // Create the opening tag $openingTag = sprintf( '<%s%s%s>', $this->getTag(), $tagSeparator, $tagAttributes ); // Create the closing tag $closingTag = ''; if (! in_array($this->getTag(), self::SELF_CLOSING_TAGS)) { $closingTag = sprintf('</%s>', $this->getTag()); } // Collect the tag information return $openingTag . $this->getText() . $closingTag; }
php
public function generate(): string { // The tag name is required if ($this->getTag() === '') { return ''; } // Generate the attribute string $tagAttributes = $this->generateTagAttributes(); // When attributes are provided, add a space between the tag and the attributes $tagSeparator = ''; if ($tagAttributes !== '') { $tagSeparator = ' '; } // Create the opening tag $openingTag = sprintf( '<%s%s%s>', $this->getTag(), $tagSeparator, $tagAttributes ); // Create the closing tag $closingTag = ''; if (! in_array($this->getTag(), self::SELF_CLOSING_TAGS)) { $closingTag = sprintf('</%s>', $this->getTag()); } // Collect the tag information return $openingTag . $this->getText() . $closingTag; }
[ "public", "function", "generate", "(", ")", ":", "string", "{", "// The tag name is required", "if", "(", "$", "this", "->", "getTag", "(", ")", "===", "''", ")", "{", "return", "''", ";", "}", "// Generate the attribute string", "$", "tagAttributes", "=", "$", "this", "->", "generateTagAttributes", "(", ")", ";", "// When attributes are provided, add a space between the tag and the attributes", "$", "tagSeparator", "=", "''", ";", "if", "(", "$", "tagAttributes", "!==", "''", ")", "{", "$", "tagSeparator", "=", "' '", ";", "}", "// Create the opening tag", "$", "openingTag", "=", "sprintf", "(", "'<%s%s%s>'", ",", "$", "this", "->", "getTag", "(", ")", ",", "$", "tagSeparator", ",", "$", "tagAttributes", ")", ";", "// Create the closing tag", "$", "closingTag", "=", "''", ";", "if", "(", "!", "in_array", "(", "$", "this", "->", "getTag", "(", ")", ",", "self", "::", "SELF_CLOSING_TAGS", ")", ")", "{", "$", "closingTag", "=", "sprintf", "(", "'</%s>'", ",", "$", "this", "->", "getTag", "(", ")", ")", ";", "}", "// Collect the tag information", "return", "$", "openingTag", ".", "$", "this", "->", "getText", "(", ")", ".", "$", "closingTag", ";", "}" ]
Generates the HTML tag with it's attributes and text. @return string
[ "Generates", "the", "HTML", "tag", "with", "it", "s", "attributes", "and", "text", "." ]
4b1013c78cd8d1bc677508ec732a1ba5305e7e4e
https://github.com/vdhicts/dicms-html-element/blob/4b1013c78cd8d1bc677508ec732a1ba5305e7e4e/src/Element.php#L303-L335
train
Linkvalue-Interne/MajoraOAuthServerBundle
src/Majora/Bundle/OAuthServerBundle/Controller/TokenApiController.php
TokenApiController.postAction
public function postAction(Request $request) { try { return $this->createJsonResponse($this->get('oauth.server')->grant( $this->getRequestData($request, 'snakelize') )); } catch (InvalidGrantException $e) { return new JsonResponse('Unavailable to create access token : bad credentials.', 401); } catch (\InvalidArgumentException $e) { return new JsonResponse('Invalid or missing fields for grant type.', 400); } }
php
public function postAction(Request $request) { try { return $this->createJsonResponse($this->get('oauth.server')->grant( $this->getRequestData($request, 'snakelize') )); } catch (InvalidGrantException $e) { return new JsonResponse('Unavailable to create access token : bad credentials.', 401); } catch (\InvalidArgumentException $e) { return new JsonResponse('Invalid or missing fields for grant type.', 400); } }
[ "public", "function", "postAction", "(", "Request", "$", "request", ")", "{", "try", "{", "return", "$", "this", "->", "createJsonResponse", "(", "$", "this", "->", "get", "(", "'oauth.server'", ")", "->", "grant", "(", "$", "this", "->", "getRequestData", "(", "$", "request", ",", "'snakelize'", ")", ")", ")", ";", "}", "catch", "(", "InvalidGrantException", "$", "e", ")", "{", "return", "new", "JsonResponse", "(", "'Unavailable to create access token : bad credentials.'", ",", "401", ")", ";", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "e", ")", "{", "return", "new", "JsonResponse", "(", "'Invalid or missing fields for grant type.'", ",", "400", ")", ";", "}", "}" ]
Create a new access_token from given request throught oAuth server. @param Request $request @return Response
[ "Create", "a", "new", "access_token", "from", "given", "request", "throught", "oAuth", "server", "." ]
3e84e2494c947d1bd5d5c16221a3b9e343ebff92
https://github.com/Linkvalue-Interne/MajoraOAuthServerBundle/blob/3e84e2494c947d1bd5d5c16221a3b9e343ebff92/src/Majora/Bundle/OAuthServerBundle/Controller/TokenApiController.php#L25-L36
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/storagefacility/StorageFacilityFile.php
StorageFacilityFile.setID
public function setID($id) { if($id !== null && substr($id, 0, 1) !== '/') throw new Exception("invalid file id, must start with a /"); $this->id = $id; }
php
public function setID($id) { if($id !== null && substr($id, 0, 1) !== '/') throw new Exception("invalid file id, must start with a /"); $this->id = $id; }
[ "public", "function", "setID", "(", "$", "id", ")", "{", "if", "(", "$", "id", "!==", "null", "&&", "substr", "(", "$", "id", ",", "0", ",", "1", ")", "!==", "'/'", ")", "throw", "new", "Exception", "(", "\"invalid file id, must start with a /\"", ")", ";", "$", "this", "->", "id", "=", "$", "id", ";", "}" ]
Set the ID for this file @param string $id The id to set @return void
[ "Set", "the", "ID", "for", "this", "file" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/storagefacility/StorageFacilityFile.php#L123-L128
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/storagefacility/StorageFacilityFile.php
StorageFacilityFile.isValid
public function isValid() { return $this->getID() != null && $this->getURL() != null && $this->getLocalPath() != null; }
php
public function isValid() { return $this->getID() != null && $this->getURL() != null && $this->getLocalPath() != null; }
[ "public", "function", "isValid", "(", ")", "{", "return", "$", "this", "->", "getID", "(", ")", "!=", "null", "&&", "$", "this", "->", "getURL", "(", ")", "!=", "null", "&&", "$", "this", "->", "getLocalPath", "(", ")", "!=", "null", ";", "}" ]
Determines if this is a valid file object or not. @return boolean
[ "Determines", "if", "this", "is", "a", "valid", "file", "object", "or", "not", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/storagefacility/StorageFacilityFile.php#L189-L192
train
horntell/php-sdk
lib/guzzle/GuzzleHttp/Cookie/CookieJar.php
CookieJar.getCookieValue
public static function getCookieValue($value) { if (substr($value, 0, 1) !== '"' && substr($value, -1, 1) !== '"' && strpbrk($value, ';,') ) { $value = '"' . $value . '"'; } return $value; }
php
public static function getCookieValue($value) { if (substr($value, 0, 1) !== '"' && substr($value, -1, 1) !== '"' && strpbrk($value, ';,') ) { $value = '"' . $value . '"'; } return $value; }
[ "public", "static", "function", "getCookieValue", "(", "$", "value", ")", "{", "if", "(", "substr", "(", "$", "value", ",", "0", ",", "1", ")", "!==", "'\"'", "&&", "substr", "(", "$", "value", ",", "-", "1", ",", "1", ")", "!==", "'\"'", "&&", "strpbrk", "(", "$", "value", ",", "';,'", ")", ")", "{", "$", "value", "=", "'\"'", ".", "$", "value", ".", "'\"'", ";", "}", "return", "$", "value", ";", "}" ]
Quote the cookie value if it is not already quoted and it contains problematic characters. @param string $value Value that may or may not need to be quoted @return string
[ "Quote", "the", "cookie", "value", "if", "it", "is", "not", "already", "quoted", "and", "it", "contains", "problematic", "characters", "." ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Cookie/CookieJar.php#L69-L79
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.getFirstChild
public function getFirstChild() { if($this->isLeaf()) { return null; } if($this->children !== null) { $ary = array_slice($this->children, 0, 1); return $ary[0]; } $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getLeftFieldName()." = :lft1") ->setParameter('lft1', $this->getLeftValue() + 1); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); return $this->getManager()->wrapNode($results[0]); }
php
public function getFirstChild() { if($this->isLeaf()) { return null; } if($this->children !== null) { $ary = array_slice($this->children, 0, 1); return $ary[0]; } $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getLeftFieldName()." = :lft1") ->setParameter('lft1', $this->getLeftValue() + 1); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); return $this->getManager()->wrapNode($results[0]); }
[ "public", "function", "getFirstChild", "(", ")", "{", "if", "(", "$", "this", "->", "isLeaf", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "this", "->", "children", "!==", "null", ")", "{", "$", "ary", "=", "array_slice", "(", "$", "this", "->", "children", ",", "0", ",", "1", ")", ";", "return", "$", "ary", "[", "0", "]", ";", "}", "$", "qb", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getBaseQueryBuilder", "(", ")", ";", "$", "alias", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getQueryBuilderAlias", "(", ")", ";", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getLeftFieldName", "(", ")", ".", "\" = :lft1\"", ")", "->", "setParameter", "(", "'lft1'", ",", "$", "this", "->", "getLeftValue", "(", ")", "+", "1", ")", ";", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getRootFieldName", "(", ")", ".", "\" = :root\"", ")", "->", "setParameter", "(", "'root'", ",", "$", "this", "->", "getRootValue", "(", ")", ")", ";", "}", "$", "q", "=", "$", "qb", "->", "getQuery", "(", ")", ";", "if", "(", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "isQueryHintSet", "(", ")", ")", "{", "$", "q", "=", "$", "this", "->", "getManager", "(", ")", "->", "addHintToQuery", "(", "$", "q", ")", ";", "}", "$", "results", "=", "$", "q", "->", "getResult", "(", ")", ";", "return", "$", "this", "->", "getManager", "(", ")", "->", "wrapNode", "(", "$", "results", "[", "0", "]", ")", ";", "}" ]
gets first child or null @return NodeWrapper
[ "gets", "first", "child", "or", "null" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L85-L116
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.getDescendants
public function getDescendants($depth = null) { if(!$this->hasChildren()) { return array(); } if($this->descendants === null) { $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getLeftFieldName()." > :lft1") ->setParameter('lft1', $this->getLeftValue()) ->andWhere("$alias.".$this->getRightFieldName()." < :rgt1") ->setParameter('rgt1', $this->getRightValue()) ->orderBy("$alias.".$this->getLeftFieldName(), "ASC"); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } // TODO: Add depth support or self join support? $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); $this->descendants = array(); foreach($results as $result) { $this->descendants[] = $this->getManager()->wrapNode($result); } } if($depth !== null) { // TODO: Don't rebuild filtered array everytime? return $this->getManager()->filterNodeDepth($this->descendants, $depth); } return $this->descendants; }
php
public function getDescendants($depth = null) { if(!$this->hasChildren()) { return array(); } if($this->descendants === null) { $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getLeftFieldName()." > :lft1") ->setParameter('lft1', $this->getLeftValue()) ->andWhere("$alias.".$this->getRightFieldName()." < :rgt1") ->setParameter('rgt1', $this->getRightValue()) ->orderBy("$alias.".$this->getLeftFieldName(), "ASC"); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } // TODO: Add depth support or self join support? $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); $this->descendants = array(); foreach($results as $result) { $this->descendants[] = $this->getManager()->wrapNode($result); } } if($depth !== null) { // TODO: Don't rebuild filtered array everytime? return $this->getManager()->filterNodeDepth($this->descendants, $depth); } return $this->descendants; }
[ "public", "function", "getDescendants", "(", "$", "depth", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "hasChildren", "(", ")", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "$", "this", "->", "descendants", "===", "null", ")", "{", "$", "qb", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getBaseQueryBuilder", "(", ")", ";", "$", "alias", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getQueryBuilderAlias", "(", ")", ";", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getLeftFieldName", "(", ")", ".", "\" > :lft1\"", ")", "->", "setParameter", "(", "'lft1'", ",", "$", "this", "->", "getLeftValue", "(", ")", ")", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getRightFieldName", "(", ")", ".", "\" < :rgt1\"", ")", "->", "setParameter", "(", "'rgt1'", ",", "$", "this", "->", "getRightValue", "(", ")", ")", "->", "orderBy", "(", "\"$alias.\"", ".", "$", "this", "->", "getLeftFieldName", "(", ")", ",", "\"ASC\"", ")", ";", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getRootFieldName", "(", ")", ".", "\" = :root\"", ")", "->", "setParameter", "(", "'root'", ",", "$", "this", "->", "getRootValue", "(", ")", ")", ";", "}", "// TODO: Add depth support or self join support?", "$", "q", "=", "$", "qb", "->", "getQuery", "(", ")", ";", "if", "(", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "isQueryHintSet", "(", ")", ")", "{", "$", "q", "=", "$", "this", "->", "getManager", "(", ")", "->", "addHintToQuery", "(", "$", "q", ")", ";", "}", "$", "results", "=", "$", "q", "->", "getResult", "(", ")", ";", "$", "this", "->", "descendants", "=", "array", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "this", "->", "descendants", "[", "]", "=", "$", "this", "->", "getManager", "(", ")", "->", "wrapNode", "(", "$", "result", ")", ";", "}", "}", "if", "(", "$", "depth", "!==", "null", ")", "{", "// TODO: Don't rebuild filtered array everytime?", "return", "$", "this", "->", "getManager", "(", ")", "->", "filterNodeDepth", "(", "$", "this", "->", "descendants", ",", "$", "depth", ")", ";", "}", "return", "$", "this", "->", "descendants", ";", "}" ]
gets descendants for this node @param int $depth or null for unlimited depth @return array array of NodeWrapper objects
[ "gets", "descendants", "for", "this", "node" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L181-L225
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.getParent
public function getParent() { if($this->isRoot()) { return null; } if($this->parent == null && $this->ancestors) { // Shortcut if we already loaded the ancestors $this->parent = $this->ancestors[count($this->ancestors)-1]; } if($this->parent == null) { $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getLeftFieldName()." < :lft1") ->setParameter('lft1', $this->getLeftValue()) ->andWhere("$alias.".$this->getRightFieldName()." > :rgt1") ->setParameter('rgt1', $this->getRightValue()) ->orderBy("$alias.".$this->getRightFieldName(), "ASC") ->setMaxResults(1); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); $this->parent = $this->getManager()->wrapNode($results[0]); } return $this->parent; }
php
public function getParent() { if($this->isRoot()) { return null; } if($this->parent == null && $this->ancestors) { // Shortcut if we already loaded the ancestors $this->parent = $this->ancestors[count($this->ancestors)-1]; } if($this->parent == null) { $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getLeftFieldName()." < :lft1") ->setParameter('lft1', $this->getLeftValue()) ->andWhere("$alias.".$this->getRightFieldName()." > :rgt1") ->setParameter('rgt1', $this->getRightValue()) ->orderBy("$alias.".$this->getRightFieldName(), "ASC") ->setMaxResults(1); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); $this->parent = $this->getManager()->wrapNode($results[0]); } return $this->parent; }
[ "public", "function", "getParent", "(", ")", "{", "if", "(", "$", "this", "->", "isRoot", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "this", "->", "parent", "==", "null", "&&", "$", "this", "->", "ancestors", ")", "{", "// Shortcut if we already loaded the ancestors", "$", "this", "->", "parent", "=", "$", "this", "->", "ancestors", "[", "count", "(", "$", "this", "->", "ancestors", ")", "-", "1", "]", ";", "}", "if", "(", "$", "this", "->", "parent", "==", "null", ")", "{", "$", "qb", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getBaseQueryBuilder", "(", ")", ";", "$", "alias", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getQueryBuilderAlias", "(", ")", ";", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getLeftFieldName", "(", ")", ".", "\" < :lft1\"", ")", "->", "setParameter", "(", "'lft1'", ",", "$", "this", "->", "getLeftValue", "(", ")", ")", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getRightFieldName", "(", ")", ".", "\" > :rgt1\"", ")", "->", "setParameter", "(", "'rgt1'", ",", "$", "this", "->", "getRightValue", "(", ")", ")", "->", "orderBy", "(", "\"$alias.\"", ".", "$", "this", "->", "getRightFieldName", "(", ")", ",", "\"ASC\"", ")", "->", "setMaxResults", "(", "1", ")", ";", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getRootFieldName", "(", ")", ".", "\" = :root\"", ")", "->", "setParameter", "(", "'root'", ",", "$", "this", "->", "getRootValue", "(", ")", ")", ";", "}", "$", "q", "=", "$", "qb", "->", "getQuery", "(", ")", ";", "if", "(", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "isQueryHintSet", "(", ")", ")", "{", "$", "q", "=", "$", "this", "->", "getManager", "(", ")", "->", "addHintToQuery", "(", "$", "q", ")", ";", "}", "$", "results", "=", "$", "q", "->", "getResult", "(", ")", ";", "$", "this", "->", "parent", "=", "$", "this", "->", "getManager", "(", ")", "->", "wrapNode", "(", "$", "results", "[", "0", "]", ")", ";", "}", "return", "$", "this", "->", "parent", ";", "}" ]
gets parent Node or null @return NodeWrapper
[ "gets", "parent", "Node", "or", "null" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L233-L273
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.getAncestors
public function getAncestors() { if($this->isRoot()) { return array(); } if($this->ancestors === null) { $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getLeftFieldName()." < :lft1") ->setParameter('lft1', $this->getLeftValue()) ->andWhere("$alias.".$this->getRightFieldName()." > :rgt1") ->setParameter('rgt1', $this->getRightValue()) ->orderBy("$alias.".$this->getLeftFieldName(), "ASC"); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); $this->ancestors = array(); foreach($results as $result) { $this->ancestors[] = $this->getManager()->wrapNode($result); } } return $this->ancestors; }
php
public function getAncestors() { if($this->isRoot()) { return array(); } if($this->ancestors === null) { $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getLeftFieldName()." < :lft1") ->setParameter('lft1', $this->getLeftValue()) ->andWhere("$alias.".$this->getRightFieldName()." > :rgt1") ->setParameter('rgt1', $this->getRightValue()) ->orderBy("$alias.".$this->getLeftFieldName(), "ASC"); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); $this->ancestors = array(); foreach($results as $result) { $this->ancestors[] = $this->getManager()->wrapNode($result); } } return $this->ancestors; }
[ "public", "function", "getAncestors", "(", ")", "{", "if", "(", "$", "this", "->", "isRoot", "(", ")", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "$", "this", "->", "ancestors", "===", "null", ")", "{", "$", "qb", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getBaseQueryBuilder", "(", ")", ";", "$", "alias", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getQueryBuilderAlias", "(", ")", ";", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getLeftFieldName", "(", ")", ".", "\" < :lft1\"", ")", "->", "setParameter", "(", "'lft1'", ",", "$", "this", "->", "getLeftValue", "(", ")", ")", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getRightFieldName", "(", ")", ".", "\" > :rgt1\"", ")", "->", "setParameter", "(", "'rgt1'", ",", "$", "this", "->", "getRightValue", "(", ")", ")", "->", "orderBy", "(", "\"$alias.\"", ".", "$", "this", "->", "getLeftFieldName", "(", ")", ",", "\"ASC\"", ")", ";", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getRootFieldName", "(", ")", ".", "\" = :root\"", ")", "->", "setParameter", "(", "'root'", ",", "$", "this", "->", "getRootValue", "(", ")", ")", ";", "}", "$", "q", "=", "$", "qb", "->", "getQuery", "(", ")", ";", "if", "(", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "isQueryHintSet", "(", ")", ")", "{", "$", "q", "=", "$", "this", "->", "getManager", "(", ")", "->", "addHintToQuery", "(", "$", "q", ")", ";", "}", "$", "results", "=", "$", "q", "->", "getResult", "(", ")", ";", "$", "this", "->", "ancestors", "=", "array", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "this", "->", "ancestors", "[", "]", "=", "$", "this", "->", "getManager", "(", ")", "->", "wrapNode", "(", "$", "result", ")", ";", "}", "}", "return", "$", "this", "->", "ancestors", ";", "}" ]
gets ancestors for node @return array array of NodeWrapper objects
[ "gets", "ancestors", "for", "node" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L281-L318
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.getLevel
public function getLevel() { if($this->level === null) { $this->level = count($this->getAncestors()); } return $this->level; }
php
public function getLevel() { if($this->level === null) { $this->level = count($this->getAncestors()); } return $this->level; }
[ "public", "function", "getLevel", "(", ")", "{", "if", "(", "$", "this", "->", "level", "===", "null", ")", "{", "$", "this", "->", "level", "=", "count", "(", "$", "this", "->", "getAncestors", "(", ")", ")", ";", "}", "return", "$", "this", "->", "level", ";", "}" ]
gets the level of this node @return int
[ "gets", "the", "level", "of", "this", "node" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L326-L334
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.getSiblings
public function getSiblings($includeNode=false) { $parent = $this->getParent(); $siblings = array(); if($parent && $parent->isValidNode()) { $children = $parent->getChildren(); foreach($children as $child) { if(!$includeNode && $this->isEqualTo($child)) { continue; } $siblings[] = $child; } } return $siblings; }
php
public function getSiblings($includeNode=false) { $parent = $this->getParent(); $siblings = array(); if($parent && $parent->isValidNode()) { $children = $parent->getChildren(); foreach($children as $child) { if(!$includeNode && $this->isEqualTo($child)) { continue; } $siblings[] = $child; } } return $siblings; }
[ "public", "function", "getSiblings", "(", "$", "includeNode", "=", "false", ")", "{", "$", "parent", "=", "$", "this", "->", "getParent", "(", ")", ";", "$", "siblings", "=", "array", "(", ")", ";", "if", "(", "$", "parent", "&&", "$", "parent", "->", "isValidNode", "(", ")", ")", "{", "$", "children", "=", "$", "parent", "->", "getChildren", "(", ")", ";", "foreach", "(", "$", "children", "as", "$", "child", ")", "{", "if", "(", "!", "$", "includeNode", "&&", "$", "this", "->", "isEqualTo", "(", "$", "child", ")", ")", "{", "continue", ";", "}", "$", "siblings", "[", "]", "=", "$", "child", ";", "}", "}", "return", "$", "siblings", ";", "}" ]
gets siblings for node @param bool $includeNode whether to include this node in the list of sibling nodes (default: false) @return array array of NodeWrapper objects
[ "gets", "siblings", "for", "node" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L479-L497
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.getPrevSibling
public function getPrevSibling() { // If parent and children are already loaded, avoid database query if($this->parent !== null && ($children = $this->parent->internalGetChildren()) !== null) { for($i=0; $i<count($children); $i++) { if($children[$i] == $this) { return ($i-1 < 0) ? null : $children[$i-1]; } } // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getRightFieldName()." = :rgt1") ->setParameter('rgt1', $this->getLeftValue() - 1); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); if(!$results) { return null; } return $this->getManager()->wrapNode($results[0]); }
php
public function getPrevSibling() { // If parent and children are already loaded, avoid database query if($this->parent !== null && ($children = $this->parent->internalGetChildren()) !== null) { for($i=0; $i<count($children); $i++) { if($children[$i] == $this) { return ($i-1 < 0) ? null : $children[$i-1]; } } // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder(); $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias(); $qb->andWhere("$alias.".$this->getRightFieldName()." = :rgt1") ->setParameter('rgt1', $this->getLeftValue() - 1); if($this->hasManyRoots()) { $qb->andWhere("$alias.".$this->getRootFieldName()." = :root") ->setParameter('root', $this->getRootValue()); } $q = $qb->getQuery(); if ($this->getManager()->getConfiguration()->isQueryHintSet()){ $q = $this->getManager()->addHintToQuery($q); } $results = $q->getResult(); if(!$results) { return null; } return $this->getManager()->wrapNode($results[0]); }
[ "public", "function", "getPrevSibling", "(", ")", "{", "// If parent and children are already loaded, avoid database query", "if", "(", "$", "this", "->", "parent", "!==", "null", "&&", "(", "$", "children", "=", "$", "this", "->", "parent", "->", "internalGetChildren", "(", ")", ")", "!==", "null", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "children", ")", ";", "$", "i", "++", ")", "{", "if", "(", "$", "children", "[", "$", "i", "]", "==", "$", "this", ")", "{", "return", "(", "$", "i", "-", "1", "<", "0", ")", "?", "null", ":", "$", "children", "[", "$", "i", "-", "1", "]", ";", "}", "}", "// @codeCoverageIgnoreStart", "}", "// @codeCoverageIgnoreEnd", "$", "qb", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getBaseQueryBuilder", "(", ")", ";", "$", "alias", "=", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "getQueryBuilderAlias", "(", ")", ";", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getRightFieldName", "(", ")", ".", "\" = :rgt1\"", ")", "->", "setParameter", "(", "'rgt1'", ",", "$", "this", "->", "getLeftValue", "(", ")", "-", "1", ")", ";", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "$", "qb", "->", "andWhere", "(", "\"$alias.\"", ".", "$", "this", "->", "getRootFieldName", "(", ")", ".", "\" = :root\"", ")", "->", "setParameter", "(", "'root'", ",", "$", "this", "->", "getRootValue", "(", ")", ")", ";", "}", "$", "q", "=", "$", "qb", "->", "getQuery", "(", ")", ";", "if", "(", "$", "this", "->", "getManager", "(", ")", "->", "getConfiguration", "(", ")", "->", "isQueryHintSet", "(", ")", ")", "{", "$", "q", "=", "$", "this", "->", "getManager", "(", ")", "->", "addHintToQuery", "(", "$", "q", ")", ";", "}", "$", "results", "=", "$", "q", "->", "getResult", "(", ")", ";", "if", "(", "!", "$", "results", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "getManager", "(", ")", "->", "wrapNode", "(", "$", "results", "[", "0", "]", ")", ";", "}" ]
gets prev sibling or null @return Node
[ "gets", "prev", "sibling", "or", "null" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L505-L545
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.insertAsParentOf
public function insertAsParentOf(NodeWrapper $node) { if($node == $this) { throw new \InvalidArgumentException('Cannot insert node as a parent of itself'); } if($this->isValidNode()) { throw new \InvalidArgumentException('Cannot insert a node that already has a place within the tree'); } if($node->isRoot()) { throw new \InvalidArgumentException('Cannot insert as parent of root'); } $em = $this->getManager()->getEntityManager(); $lftField = $this->getLeftFieldName(); $rgtField = $this->getRightFieldName(); $newLft = $node->getLeftValue(); $newRgt = $node->getRightValue() + 2; $newRoot = $this->hasManyRoots() ? $node->getRootValue() : null; // beginTransaction $em->getConnection()->beginTransaction(); try { // Make space for new node $this->shiftRLRange($newRgt - 1, 0, 2, $newRoot); // Slide child nodes over one and down one to allow new parent to wrap them $qb = $em->createQueryBuilder() ->update(get_class($this->getNode()), 'n') ->set("n.$lftField", "n.$lftField + 1") ->set("n.$rgtField", "n.$rgtField + 1") ->where("n.$lftField >= ?1") ->setParameter(1, $newLft) ->andWhere("n.$rgtField <= ?2") ->setParameter(2, $newRgt); if($this->hasManyRoots()) { $qb->andWhere("n.".$this->getRootFieldName()." = ?3") ->setParameter(3, $newRoot); } $qb->getQuery()->execute(); $this->getManager()->updateValues($newLft, $newRgt, 1, $newRoot); $this->insertNode($newLft, $newRgt, $newRoot); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
php
public function insertAsParentOf(NodeWrapper $node) { if($node == $this) { throw new \InvalidArgumentException('Cannot insert node as a parent of itself'); } if($this->isValidNode()) { throw new \InvalidArgumentException('Cannot insert a node that already has a place within the tree'); } if($node->isRoot()) { throw new \InvalidArgumentException('Cannot insert as parent of root'); } $em = $this->getManager()->getEntityManager(); $lftField = $this->getLeftFieldName(); $rgtField = $this->getRightFieldName(); $newLft = $node->getLeftValue(); $newRgt = $node->getRightValue() + 2; $newRoot = $this->hasManyRoots() ? $node->getRootValue() : null; // beginTransaction $em->getConnection()->beginTransaction(); try { // Make space for new node $this->shiftRLRange($newRgt - 1, 0, 2, $newRoot); // Slide child nodes over one and down one to allow new parent to wrap them $qb = $em->createQueryBuilder() ->update(get_class($this->getNode()), 'n') ->set("n.$lftField", "n.$lftField + 1") ->set("n.$rgtField", "n.$rgtField + 1") ->where("n.$lftField >= ?1") ->setParameter(1, $newLft) ->andWhere("n.$rgtField <= ?2") ->setParameter(2, $newRgt); if($this->hasManyRoots()) { $qb->andWhere("n.".$this->getRootFieldName()." = ?3") ->setParameter(3, $newRoot); } $qb->getQuery()->execute(); $this->getManager()->updateValues($newLft, $newRgt, 1, $newRoot); $this->insertNode($newLft, $newRgt, $newRoot); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
[ "public", "function", "insertAsParentOf", "(", "NodeWrapper", "$", "node", ")", "{", "if", "(", "$", "node", "==", "$", "this", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Cannot insert node as a parent of itself'", ")", ";", "}", "if", "(", "$", "this", "->", "isValidNode", "(", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Cannot insert a node that already has a place within the tree'", ")", ";", "}", "if", "(", "$", "node", "->", "isRoot", "(", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Cannot insert as parent of root'", ")", ";", "}", "$", "em", "=", "$", "this", "->", "getManager", "(", ")", "->", "getEntityManager", "(", ")", ";", "$", "lftField", "=", "$", "this", "->", "getLeftFieldName", "(", ")", ";", "$", "rgtField", "=", "$", "this", "->", "getRightFieldName", "(", ")", ";", "$", "newLft", "=", "$", "node", "->", "getLeftValue", "(", ")", ";", "$", "newRgt", "=", "$", "node", "->", "getRightValue", "(", ")", "+", "2", ";", "$", "newRoot", "=", "$", "this", "->", "hasManyRoots", "(", ")", "?", "$", "node", "->", "getRootValue", "(", ")", ":", "null", ";", "// beginTransaction", "$", "em", "->", "getConnection", "(", ")", "->", "beginTransaction", "(", ")", ";", "try", "{", "// Make space for new node", "$", "this", "->", "shiftRLRange", "(", "$", "newRgt", "-", "1", ",", "0", ",", "2", ",", "$", "newRoot", ")", ";", "// Slide child nodes over one and down one to allow new parent to wrap them", "$", "qb", "=", "$", "em", "->", "createQueryBuilder", "(", ")", "->", "update", "(", "get_class", "(", "$", "this", "->", "getNode", "(", ")", ")", ",", "'n'", ")", "->", "set", "(", "\"n.$lftField\"", ",", "\"n.$lftField + 1\"", ")", "->", "set", "(", "\"n.$rgtField\"", ",", "\"n.$rgtField + 1\"", ")", "->", "where", "(", "\"n.$lftField >= ?1\"", ")", "->", "setParameter", "(", "1", ",", "$", "newLft", ")", "->", "andWhere", "(", "\"n.$rgtField <= ?2\"", ")", "->", "setParameter", "(", "2", ",", "$", "newRgt", ")", ";", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "$", "qb", "->", "andWhere", "(", "\"n.\"", ".", "$", "this", "->", "getRootFieldName", "(", ")", ".", "\" = ?3\"", ")", "->", "setParameter", "(", "3", ",", "$", "newRoot", ")", ";", "}", "$", "qb", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "$", "this", "->", "getManager", "(", ")", "->", "updateValues", "(", "$", "newLft", ",", "$", "newRgt", ",", "1", ",", "$", "newRoot", ")", ";", "$", "this", "->", "insertNode", "(", "$", "newLft", ",", "$", "newRgt", ",", "$", "newRoot", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// @codeCoverageIgnoreStart", "$", "em", "->", "close", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "// @codeCoverageIgnoreEnd", "}", "// endTransaction", "}" ]
inserts node as parent of given node @param NodeWrapper $node
[ "inserts", "node", "as", "parent", "of", "given", "node" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L634-L697
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.insertAsPrevSiblingOf
public function insertAsPrevSiblingOf(NodeWrapper $node) { if($node == $this) { throw new \InvalidArgumentException('Cannot insert node as a sibling of itself'); } $em = $this->getManager()->getEntityManager(); $newLeft = $node->getLeftValue(); $newRight = $node->getLeftValue() + 1; $newRoot = $this->hasManyRoots() ? $node->getRootValue() : null; // beginTransaction $em->getConnection()->beginTransaction(); try { $this->shiftRLRange($newLeft, 0, 2, $newRoot); $this->insertNode($newLeft, $newRight, $newRoot); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
php
public function insertAsPrevSiblingOf(NodeWrapper $node) { if($node == $this) { throw new \InvalidArgumentException('Cannot insert node as a sibling of itself'); } $em = $this->getManager()->getEntityManager(); $newLeft = $node->getLeftValue(); $newRight = $node->getLeftValue() + 1; $newRoot = $this->hasManyRoots() ? $node->getRootValue() : null; // beginTransaction $em->getConnection()->beginTransaction(); try { $this->shiftRLRange($newLeft, 0, 2, $newRoot); $this->insertNode($newLeft, $newRight, $newRoot); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
[ "public", "function", "insertAsPrevSiblingOf", "(", "NodeWrapper", "$", "node", ")", "{", "if", "(", "$", "node", "==", "$", "this", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Cannot insert node as a sibling of itself'", ")", ";", "}", "$", "em", "=", "$", "this", "->", "getManager", "(", ")", "->", "getEntityManager", "(", ")", ";", "$", "newLeft", "=", "$", "node", "->", "getLeftValue", "(", ")", ";", "$", "newRight", "=", "$", "node", "->", "getLeftValue", "(", ")", "+", "1", ";", "$", "newRoot", "=", "$", "this", "->", "hasManyRoots", "(", ")", "?", "$", "node", "->", "getRootValue", "(", ")", ":", "null", ";", "// beginTransaction", "$", "em", "->", "getConnection", "(", ")", "->", "beginTransaction", "(", ")", ";", "try", "{", "$", "this", "->", "shiftRLRange", "(", "$", "newLeft", ",", "0", ",", "2", ",", "$", "newRoot", ")", ";", "$", "this", "->", "insertNode", "(", "$", "newLeft", ",", "$", "newRight", ",", "$", "newRoot", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// @codeCoverageIgnoreStart", "$", "em", "->", "close", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "// @codeCoverageIgnoreEnd", "}", "// endTransaction", "}" ]
inserts node as previous sibling of given node @param NodeWrapper $node
[ "inserts", "node", "as", "previous", "sibling", "of", "given", "node" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L705-L736
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.moveAsLastChildOf
public function moveAsLastChildOf(NodeWrapper $node) { if($node == $this) { throw new \InvalidArgumentException('Cannot move node as a child of itself'); } $em = $this->getManager()->getEntityManager(); // beginTransaction $em->getConnection()->beginTransaction(); try { if($this->hasManyRoots() && $this->getRootValue() !== $node->getRootValue()) { $this->moveBetweenTrees($node, $node->getRightValue(), __FUNCTION__); } else { $this->updateNode($node->getRightValue()); } $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
php
public function moveAsLastChildOf(NodeWrapper $node) { if($node == $this) { throw new \InvalidArgumentException('Cannot move node as a child of itself'); } $em = $this->getManager()->getEntityManager(); // beginTransaction $em->getConnection()->beginTransaction(); try { if($this->hasManyRoots() && $this->getRootValue() !== $node->getRootValue()) { $this->moveBetweenTrees($node, $node->getRightValue(), __FUNCTION__); } else { $this->updateNode($node->getRightValue()); } $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
[ "public", "function", "moveAsLastChildOf", "(", "NodeWrapper", "$", "node", ")", "{", "if", "(", "$", "node", "==", "$", "this", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Cannot move node as a child of itself'", ")", ";", "}", "$", "em", "=", "$", "this", "->", "getManager", "(", ")", "->", "getEntityManager", "(", ")", ";", "// beginTransaction", "$", "em", "->", "getConnection", "(", ")", "->", "beginTransaction", "(", ")", ";", "try", "{", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", "&&", "$", "this", "->", "getRootValue", "(", ")", "!==", "$", "node", "->", "getRootValue", "(", ")", ")", "{", "$", "this", "->", "moveBetweenTrees", "(", "$", "node", ",", "$", "node", "->", "getRightValue", "(", ")", ",", "__FUNCTION__", ")", ";", "}", "else", "{", "$", "this", "->", "updateNode", "(", "$", "node", "->", "getRightValue", "(", ")", ")", ";", "}", "$", "em", "->", "flush", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// @codeCoverageIgnoreStart", "$", "em", "->", "close", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "// @codeCoverageIgnoreEnd", "}", "// endTransaction", "}" ]
moves node as last child of the given node @param NodeWrapper $node
[ "moves", "node", "as", "last", "child", "of", "the", "given", "node" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L987-L1021
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.makeRoot
public function makeRoot($newRoot) { if($this->isRoot()) { return; } if(!$this->hasManyRoots()) { throw new \BadMethodCallException(sprintf('%s::%s is only supported on multiple root trees', __CLASS__, __METHOD__)); } $em = $this->getManager()->getEntityManager(); $lftField = $this->getLeftFieldName(); $rgtField = $this->getRightFieldName(); $rootField = $this->getRootFieldName(); $oldRgt = $this->getRightValue(); $oldLft = $this->getLeftValue(); $oldRoot = $this->getRootValue(); // beginTransaction $em->getConnection()->beginTransaction(); try { // Update descendants lft/rgt/root values $diff = 1 - $oldLft; $qb = $em->createQueryBuilder() ->update(get_class($this->getNode()), 'n') ->set("n.$lftField", "n.$lftField + ?1") ->setParameter(1, $diff) ->set("n.$rgtField", "n.$rgtField + ?2") ->setParameter(2, $diff) ->set("n.$rootField", "?3") ->setParameter(3, $newRoot) ->where("n.$lftField > ?4") ->setParameter(4, $oldLft) ->andWhere("n.$rgtField < ?5") ->setParameter(5, $oldRgt) ->andWhere("n.$rootField = ?6") ->setParameter(6, $oldRoot); $qb->getQuery()->execute(); $this->getManager()->updateValues($oldLft, $oldRgt, $diff, $oldRoot, $newRoot); // Close gap in old tree $first = $oldRgt + 1; $delta = $oldLft - $oldRgt - 1; $this->shiftRLRange($first, 0, $delta, $oldRoot); // Set new lft/rgt/root values for root node $this->setLeftValue(1); $this->setRightValue($oldRgt - $oldLft + 1); $this->setRootValue($newRoot); $em->persist($this->getNode()); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
php
public function makeRoot($newRoot) { if($this->isRoot()) { return; } if(!$this->hasManyRoots()) { throw new \BadMethodCallException(sprintf('%s::%s is only supported on multiple root trees', __CLASS__, __METHOD__)); } $em = $this->getManager()->getEntityManager(); $lftField = $this->getLeftFieldName(); $rgtField = $this->getRightFieldName(); $rootField = $this->getRootFieldName(); $oldRgt = $this->getRightValue(); $oldLft = $this->getLeftValue(); $oldRoot = $this->getRootValue(); // beginTransaction $em->getConnection()->beginTransaction(); try { // Update descendants lft/rgt/root values $diff = 1 - $oldLft; $qb = $em->createQueryBuilder() ->update(get_class($this->getNode()), 'n') ->set("n.$lftField", "n.$lftField + ?1") ->setParameter(1, $diff) ->set("n.$rgtField", "n.$rgtField + ?2") ->setParameter(2, $diff) ->set("n.$rootField", "?3") ->setParameter(3, $newRoot) ->where("n.$lftField > ?4") ->setParameter(4, $oldLft) ->andWhere("n.$rgtField < ?5") ->setParameter(5, $oldRgt) ->andWhere("n.$rootField = ?6") ->setParameter(6, $oldRoot); $qb->getQuery()->execute(); $this->getManager()->updateValues($oldLft, $oldRgt, $diff, $oldRoot, $newRoot); // Close gap in old tree $first = $oldRgt + 1; $delta = $oldLft - $oldRgt - 1; $this->shiftRLRange($first, 0, $delta, $oldRoot); // Set new lft/rgt/root values for root node $this->setLeftValue(1); $this->setRightValue($oldRgt - $oldLft + 1); $this->setRootValue($newRoot); $em->persist($this->getNode()); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
[ "public", "function", "makeRoot", "(", "$", "newRoot", ")", "{", "if", "(", "$", "this", "->", "isRoot", "(", ")", ")", "{", "return", ";", "}", "if", "(", "!", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "sprintf", "(", "'%s::%s is only supported on multiple root trees'", ",", "__CLASS__", ",", "__METHOD__", ")", ")", ";", "}", "$", "em", "=", "$", "this", "->", "getManager", "(", ")", "->", "getEntityManager", "(", ")", ";", "$", "lftField", "=", "$", "this", "->", "getLeftFieldName", "(", ")", ";", "$", "rgtField", "=", "$", "this", "->", "getRightFieldName", "(", ")", ";", "$", "rootField", "=", "$", "this", "->", "getRootFieldName", "(", ")", ";", "$", "oldRgt", "=", "$", "this", "->", "getRightValue", "(", ")", ";", "$", "oldLft", "=", "$", "this", "->", "getLeftValue", "(", ")", ";", "$", "oldRoot", "=", "$", "this", "->", "getRootValue", "(", ")", ";", "// beginTransaction", "$", "em", "->", "getConnection", "(", ")", "->", "beginTransaction", "(", ")", ";", "try", "{", "// Update descendants lft/rgt/root values", "$", "diff", "=", "1", "-", "$", "oldLft", ";", "$", "qb", "=", "$", "em", "->", "createQueryBuilder", "(", ")", "->", "update", "(", "get_class", "(", "$", "this", "->", "getNode", "(", ")", ")", ",", "'n'", ")", "->", "set", "(", "\"n.$lftField\"", ",", "\"n.$lftField + ?1\"", ")", "->", "setParameter", "(", "1", ",", "$", "diff", ")", "->", "set", "(", "\"n.$rgtField\"", ",", "\"n.$rgtField + ?2\"", ")", "->", "setParameter", "(", "2", ",", "$", "diff", ")", "->", "set", "(", "\"n.$rootField\"", ",", "\"?3\"", ")", "->", "setParameter", "(", "3", ",", "$", "newRoot", ")", "->", "where", "(", "\"n.$lftField > ?4\"", ")", "->", "setParameter", "(", "4", ",", "$", "oldLft", ")", "->", "andWhere", "(", "\"n.$rgtField < ?5\"", ")", "->", "setParameter", "(", "5", ",", "$", "oldRgt", ")", "->", "andWhere", "(", "\"n.$rootField = ?6\"", ")", "->", "setParameter", "(", "6", ",", "$", "oldRoot", ")", ";", "$", "qb", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "$", "this", "->", "getManager", "(", ")", "->", "updateValues", "(", "$", "oldLft", ",", "$", "oldRgt", ",", "$", "diff", ",", "$", "oldRoot", ",", "$", "newRoot", ")", ";", "// Close gap in old tree", "$", "first", "=", "$", "oldRgt", "+", "1", ";", "$", "delta", "=", "$", "oldLft", "-", "$", "oldRgt", "-", "1", ";", "$", "this", "->", "shiftRLRange", "(", "$", "first", ",", "0", ",", "$", "delta", ",", "$", "oldRoot", ")", ";", "// Set new lft/rgt/root values for root node", "$", "this", "->", "setLeftValue", "(", "1", ")", ";", "$", "this", "->", "setRightValue", "(", "$", "oldRgt", "-", "$", "oldLft", "+", "1", ")", ";", "$", "this", "->", "setRootValue", "(", "$", "newRoot", ")", ";", "$", "em", "->", "persist", "(", "$", "this", "->", "getNode", "(", ")", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// @codeCoverageIgnoreStart", "$", "em", "->", "close", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "// @codeCoverageIgnoreEnd", "}", "// endTransaction", "}" ]
Makes this node a root node. @param mixed $newRoot
[ "Makes", "this", "node", "a", "root", "node", "." ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L1029-L1096
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.addChild
public function addChild(Node $node) { if($node instanceof NodeWrapper) { if($node == $this) { throw new \InvalidArgumentException('Cannot insert node as a child of itself'); } $node->insertAsLastChildOf($this); return $node; } $node->setLeftValue($this->getRightValue()); $node->setRightValue($this->getRightValue() + 1); if($this->hasManyRoots()) { $node->setRootValue($this->getRootValue()); } $em = $this->getManager()->getEntityManager(); // beginTransaction $em->getConnection()->beginTransaction(); try { $this->shiftRLRange($this->getRightValue(), 0, 2, ($this->hasManyRoots() ? $this->getRootValue() : null)); $em->persist($node); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction return $this->getManager()->wrapNode($node); }
php
public function addChild(Node $node) { if($node instanceof NodeWrapper) { if($node == $this) { throw new \InvalidArgumentException('Cannot insert node as a child of itself'); } $node->insertAsLastChildOf($this); return $node; } $node->setLeftValue($this->getRightValue()); $node->setRightValue($this->getRightValue() + 1); if($this->hasManyRoots()) { $node->setRootValue($this->getRootValue()); } $em = $this->getManager()->getEntityManager(); // beginTransaction $em->getConnection()->beginTransaction(); try { $this->shiftRLRange($this->getRightValue(), 0, 2, ($this->hasManyRoots() ? $this->getRootValue() : null)); $em->persist($node); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction return $this->getManager()->wrapNode($node); }
[ "public", "function", "addChild", "(", "Node", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "NodeWrapper", ")", "{", "if", "(", "$", "node", "==", "$", "this", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Cannot insert node as a child of itself'", ")", ";", "}", "$", "node", "->", "insertAsLastChildOf", "(", "$", "this", ")", ";", "return", "$", "node", ";", "}", "$", "node", "->", "setLeftValue", "(", "$", "this", "->", "getRightValue", "(", ")", ")", ";", "$", "node", "->", "setRightValue", "(", "$", "this", "->", "getRightValue", "(", ")", "+", "1", ")", ";", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "$", "node", "->", "setRootValue", "(", "$", "this", "->", "getRootValue", "(", ")", ")", ";", "}", "$", "em", "=", "$", "this", "->", "getManager", "(", ")", "->", "getEntityManager", "(", ")", ";", "// beginTransaction", "$", "em", "->", "getConnection", "(", ")", "->", "beginTransaction", "(", ")", ";", "try", "{", "$", "this", "->", "shiftRLRange", "(", "$", "this", "->", "getRightValue", "(", ")", ",", "0", ",", "2", ",", "(", "$", "this", "->", "hasManyRoots", "(", ")", "?", "$", "this", "->", "getRootValue", "(", ")", ":", "null", ")", ")", ";", "$", "em", "->", "persist", "(", "$", "node", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// @codeCoverageIgnoreStart", "$", "em", "->", "close", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "// @codeCoverageIgnoreEnd", "}", "// endTransaction", "return", "$", "this", "->", "getManager", "(", ")", "->", "wrapNode", "(", "$", "node", ")", ";", "}" ]
adds given node as the last child of this entity @param Node $node @return NodeWrapper $wrapper
[ "adds", "given", "node", "as", "the", "last", "child", "of", "this", "entity" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L1106-L1150
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.delete
public function delete() { $em = $this->getManager()->getEntityManager(); $lftField = $this->getLeftFieldName(); $rgtField = $this->getRightFieldName(); $oldLft = $this->getLeftValue(); $oldRgt = $this->getRightValue(); $oldRoot = $this->hasManyRoots() ? $this->getRootValue() : null; // beginTransaction $em->getConnection()->beginTransaction(); try { $qb = $em->createQueryBuilder() ->delete(get_class($this->getNode()), 'n') ->where("n.$lftField >= ?1") ->setParameter(1, $oldLft) ->andWhere("n.$rgtField <= ?2") ->setParameter(2, $oldRgt); if($this->hasManyRoots()) { $qb->andWhere("n.".$this->getRootFieldName()." = ?3") ->setParameter(3, $oldRoot); } $qb->getQuery()->execute(); $this->getManager()->removeNodes($oldLft, $oldRgt, $oldRoot); // Close gap in tree $first = $oldRgt + 1; $delta = $oldLft - $oldRgt - 1; $this->shiftRLRange($first, 0, $delta, $oldRoot); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
php
public function delete() { $em = $this->getManager()->getEntityManager(); $lftField = $this->getLeftFieldName(); $rgtField = $this->getRightFieldName(); $oldLft = $this->getLeftValue(); $oldRgt = $this->getRightValue(); $oldRoot = $this->hasManyRoots() ? $this->getRootValue() : null; // beginTransaction $em->getConnection()->beginTransaction(); try { $qb = $em->createQueryBuilder() ->delete(get_class($this->getNode()), 'n') ->where("n.$lftField >= ?1") ->setParameter(1, $oldLft) ->andWhere("n.$rgtField <= ?2") ->setParameter(2, $oldRgt); if($this->hasManyRoots()) { $qb->andWhere("n.".$this->getRootFieldName()." = ?3") ->setParameter(3, $oldRoot); } $qb->getQuery()->execute(); $this->getManager()->removeNodes($oldLft, $oldRgt, $oldRoot); // Close gap in tree $first = $oldRgt + 1; $delta = $oldLft - $oldRgt - 1; $this->shiftRLRange($first, 0, $delta, $oldRoot); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { // @codeCoverageIgnoreStart $em->close(); $em->getConnection()->rollback(); throw $e; // @codeCoverageIgnoreEnd } // endTransaction }
[ "public", "function", "delete", "(", ")", "{", "$", "em", "=", "$", "this", "->", "getManager", "(", ")", "->", "getEntityManager", "(", ")", ";", "$", "lftField", "=", "$", "this", "->", "getLeftFieldName", "(", ")", ";", "$", "rgtField", "=", "$", "this", "->", "getRightFieldName", "(", ")", ";", "$", "oldLft", "=", "$", "this", "->", "getLeftValue", "(", ")", ";", "$", "oldRgt", "=", "$", "this", "->", "getRightValue", "(", ")", ";", "$", "oldRoot", "=", "$", "this", "->", "hasManyRoots", "(", ")", "?", "$", "this", "->", "getRootValue", "(", ")", ":", "null", ";", "// beginTransaction", "$", "em", "->", "getConnection", "(", ")", "->", "beginTransaction", "(", ")", ";", "try", "{", "$", "qb", "=", "$", "em", "->", "createQueryBuilder", "(", ")", "->", "delete", "(", "get_class", "(", "$", "this", "->", "getNode", "(", ")", ")", ",", "'n'", ")", "->", "where", "(", "\"n.$lftField >= ?1\"", ")", "->", "setParameter", "(", "1", ",", "$", "oldLft", ")", "->", "andWhere", "(", "\"n.$rgtField <= ?2\"", ")", "->", "setParameter", "(", "2", ",", "$", "oldRgt", ")", ";", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "$", "qb", "->", "andWhere", "(", "\"n.\"", ".", "$", "this", "->", "getRootFieldName", "(", ")", ".", "\" = ?3\"", ")", "->", "setParameter", "(", "3", ",", "$", "oldRoot", ")", ";", "}", "$", "qb", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "$", "this", "->", "getManager", "(", ")", "->", "removeNodes", "(", "$", "oldLft", ",", "$", "oldRgt", ",", "$", "oldRoot", ")", ";", "// Close gap in tree", "$", "first", "=", "$", "oldRgt", "+", "1", ";", "$", "delta", "=", "$", "oldLft", "-", "$", "oldRgt", "-", "1", ";", "$", "this", "->", "shiftRLRange", "(", "$", "first", ",", "0", ",", "$", "delta", ",", "$", "oldRoot", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// @codeCoverageIgnoreStart", "$", "em", "->", "close", "(", ")", ";", "$", "em", "->", "getConnection", "(", ")", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "// @codeCoverageIgnoreEnd", "}", "// endTransaction", "}" ]
deletes this node and it's decendants
[ "deletes", "this", "node", "and", "it", "s", "decendants" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L1157-L1202
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.insertNode
protected function insertNode($destLeft, $destRight, $destRoot=null) { $this->setLeftValue($destLeft); $this->setRightValue($destRight); if($this->hasManyRoots()) { $this->setRootValue($destRoot); } $this->getManager()->getEntityManager()->persist($this->getNode()); }
php
protected function insertNode($destLeft, $destRight, $destRoot=null) { $this->setLeftValue($destLeft); $this->setRightValue($destRight); if($this->hasManyRoots()) { $this->setRootValue($destRoot); } $this->getManager()->getEntityManager()->persist($this->getNode()); }
[ "protected", "function", "insertNode", "(", "$", "destLeft", ",", "$", "destRight", ",", "$", "destRoot", "=", "null", ")", "{", "$", "this", "->", "setLeftValue", "(", "$", "destLeft", ")", ";", "$", "this", "->", "setRightValue", "(", "$", "destRight", ")", ";", "if", "(", "$", "this", "->", "hasManyRoots", "(", ")", ")", "{", "$", "this", "->", "setRootValue", "(", "$", "destRoot", ")", ";", "}", "$", "this", "->", "getManager", "(", ")", "->", "getEntityManager", "(", ")", "->", "persist", "(", "$", "this", "->", "getNode", "(", ")", ")", ";", "}" ]
sets node's left and right values and persist's it NOTE: This method does not wrap its database queries in a transaction. This should be done before invoking this code. @param int $destLeft @param int $destRight @param mixed $destRoot
[ "sets", "node", "s", "left", "and", "right", "values", "and", "persist", "s", "it" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L1216-L1225
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.isDescendantOf
public function isDescendantOf(Node $node) { return (($this->getLeftValue() > $node->getLeftValue()) && ($this->getRightValue() < $node->getRightValue()) && (!$this->hasManyRoots() || ($this->getRootValue() == $node->getRootValue()))); }
php
public function isDescendantOf(Node $node) { return (($this->getLeftValue() > $node->getLeftValue()) && ($this->getRightValue() < $node->getRightValue()) && (!$this->hasManyRoots() || ($this->getRootValue() == $node->getRootValue()))); }
[ "public", "function", "isDescendantOf", "(", "Node", "$", "node", ")", "{", "return", "(", "(", "$", "this", "->", "getLeftValue", "(", ")", ">", "$", "node", "->", "getLeftValue", "(", ")", ")", "&&", "(", "$", "this", "->", "getRightValue", "(", ")", "<", "$", "node", "->", "getRightValue", "(", ")", ")", "&&", "(", "!", "$", "this", "->", "hasManyRoots", "(", ")", "||", "(", "$", "this", "->", "getRootValue", "(", ")", "==", "$", "node", "->", "getRootValue", "(", ")", ")", ")", ")", ";", "}" ]
determines if this node is a child of the given node @param Node @return bool
[ "determines", "if", "this", "node", "is", "a", "child", "of", "the", "given", "node" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L1478-L1483
train
devlabmtl/haven-core
Lib/NestedSet/NodeWrapper.php
NodeWrapper.isEqualTo
public function isEqualTo(Node $node) { return (($this->getLeftValue() == $node->getLeftValue()) && ($this->getRightValue() == $node->getRightValue()) && (!$this->hasManyRoots() || ($this->getRootValue() == $node->getRootValue()))); }
php
public function isEqualTo(Node $node) { return (($this->getLeftValue() == $node->getLeftValue()) && ($this->getRightValue() == $node->getRightValue()) && (!$this->hasManyRoots() || ($this->getRootValue() == $node->getRootValue()))); }
[ "public", "function", "isEqualTo", "(", "Node", "$", "node", ")", "{", "return", "(", "(", "$", "this", "->", "getLeftValue", "(", ")", "==", "$", "node", "->", "getLeftValue", "(", ")", ")", "&&", "(", "$", "this", "->", "getRightValue", "(", ")", "==", "$", "node", "->", "getRightValue", "(", ")", ")", "&&", "(", "!", "$", "this", "->", "hasManyRoots", "(", ")", "||", "(", "$", "this", "->", "getRootValue", "(", ")", "==", "$", "node", "->", "getRootValue", "(", ")", ")", ")", ")", ";", "}" ]
determines if this node is equal to the given node @param Node @return bool
[ "determines", "if", "this", "node", "is", "equal", "to", "the", "given", "node" ]
f13410f996fd4002efafe482b927adadb211dec8
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/NodeWrapper.php#L1525-L1530
train
fuelphp-storage/session
src/Manager.php
Manager.write
public function write() { // do we need to rotate? if ($this->rotationInterval and $this->rotationTimer < time()) { $this->rotate(); } return $this->driver->write(); }
php
public function write() { // do we need to rotate? if ($this->rotationInterval and $this->rotationTimer < time()) { $this->rotate(); } return $this->driver->write(); }
[ "public", "function", "write", "(", ")", "{", "// do we need to rotate?", "if", "(", "$", "this", "->", "rotationInterval", "and", "$", "this", "->", "rotationTimer", "<", "time", "(", ")", ")", "{", "$", "this", "->", "rotate", "(", ")", ";", "}", "return", "$", "this", "->", "driver", "->", "write", "(", ")", ";", "}" ]
Writes the container data to the session store @return boolean
[ "Writes", "the", "container", "data", "to", "the", "session", "store" ]
948fd2b45286e65e7fababf65de89ca6aaca3c4a
https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Manager.php#L194-L203
train
fuelphp-storage/session
src/Manager.php
Manager.stop
public function stop() { // do we need to rotate? if ($this->rotationInterval and $this->rotationTimer < time()) { $this->rotate(); } // stop the current session return $this->driver->stop(); }
php
public function stop() { // do we need to rotate? if ($this->rotationInterval and $this->rotationTimer < time()) { $this->rotate(); } // stop the current session return $this->driver->stop(); }
[ "public", "function", "stop", "(", ")", "{", "// do we need to rotate?", "if", "(", "$", "this", "->", "rotationInterval", "and", "$", "this", "->", "rotationTimer", "<", "time", "(", ")", ")", "{", "$", "this", "->", "rotate", "(", ")", ";", "}", "// stop the current session", "return", "$", "this", "->", "driver", "->", "stop", "(", ")", ";", "}" ]
Stops a session @return boolean
[ "Stops", "a", "session" ]
948fd2b45286e65e7fababf65de89ca6aaca3c4a
https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Manager.php#L210-L220
train
fuelphp-storage/session
src/Manager.php
Manager.rotate
public function rotate() { // update the session id rotation timer if ($this->rotationInterval) { $this->rotationTimer = time() + $this->rotationInterval; } // regenerate the session id $this->driver->regenerate($this); }
php
public function rotate() { // update the session id rotation timer if ($this->rotationInterval) { $this->rotationTimer = time() + $this->rotationInterval; } // regenerate the session id $this->driver->regenerate($this); }
[ "public", "function", "rotate", "(", ")", "{", "// update the session id rotation timer", "if", "(", "$", "this", "->", "rotationInterval", ")", "{", "$", "this", "->", "rotationTimer", "=", "time", "(", ")", "+", "$", "this", "->", "rotationInterval", ";", "}", "// regenerate the session id", "$", "this", "->", "driver", "->", "regenerate", "(", "$", "this", ")", ";", "}" ]
Rotates the session id, and reset the rotation timer if needed
[ "Rotates", "the", "session", "id", "and", "reset", "the", "rotation", "timer", "if", "needed" ]
948fd2b45286e65e7fababf65de89ca6aaca3c4a
https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Manager.php#L225-L235
train
fuelphp-storage/session
src/Manager.php
Manager.setNamespace
public function setNamespace($name) { $this->config['namespace'] = is_bool($name) ? $name : (string) $name; if ($this->config['namespace'] === true) { $this->config['namespace'] = $this->app ? $app->getName() : false; } $this->data->setNamespace($this->config['namespace']); }
php
public function setNamespace($name) { $this->config['namespace'] = is_bool($name) ? $name : (string) $name; if ($this->config['namespace'] === true) { $this->config['namespace'] = $this->app ? $app->getName() : false; } $this->data->setNamespace($this->config['namespace']); }
[ "public", "function", "setNamespace", "(", "$", "name", ")", "{", "$", "this", "->", "config", "[", "'namespace'", "]", "=", "is_bool", "(", "$", "name", ")", "?", "$", "name", ":", "(", "string", ")", "$", "name", ";", "if", "(", "$", "this", "->", "config", "[", "'namespace'", "]", "===", "true", ")", "{", "$", "this", "->", "config", "[", "'namespace'", "]", "=", "$", "this", "->", "app", "?", "$", "app", "->", "getName", "(", ")", ":", "false", ";", "}", "$", "this", "->", "data", "->", "setNamespace", "(", "$", "this", "->", "config", "[", "'namespace'", "]", ")", ";", "}" ]
Sets the session namespace @param string $name
[ "Sets", "the", "session", "namespace" ]
948fd2b45286e65e7fababf65de89ca6aaca3c4a
https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Manager.php#L282-L292
train
fuelphp-storage/session
src/Manager.php
Manager.setFlashNamespace
public function setFlashNamespace($name) { $this->config['flash_namespace'] = (string) $name; $this->flash->setNamespace($this->config['flash_namespace']); }
php
public function setFlashNamespace($name) { $this->config['flash_namespace'] = (string) $name; $this->flash->setNamespace($this->config['flash_namespace']); }
[ "public", "function", "setFlashNamespace", "(", "$", "name", ")", "{", "$", "this", "->", "config", "[", "'flash_namespace'", "]", "=", "(", "string", ")", "$", "name", ";", "$", "this", "->", "flash", "->", "setNamespace", "(", "$", "this", "->", "config", "[", "'flash_namespace'", "]", ")", ";", "}" ]
Sets the session flash namespace @param string $name
[ "Sets", "the", "session", "flash", "namespace" ]
948fd2b45286e65e7fababf65de89ca6aaca3c4a
https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Manager.php#L309-L314
train
fuelphp-storage/session
src/Manager.php
Manager.reset
protected function reset() { // create the data container $this->data = new DataContainer(); // create the flash container $this->flash = new FlashContainer(); // initialise the flash expiry store $this->flash->set(FlashContainer::EXPIRE_DATA_KEY, array()); }
php
protected function reset() { // create the data container $this->data = new DataContainer(); // create the flash container $this->flash = new FlashContainer(); // initialise the flash expiry store $this->flash->set(FlashContainer::EXPIRE_DATA_KEY, array()); }
[ "protected", "function", "reset", "(", ")", "{", "// create the data container", "$", "this", "->", "data", "=", "new", "DataContainer", "(", ")", ";", "// create the flash container", "$", "this", "->", "flash", "=", "new", "FlashContainer", "(", ")", ";", "// initialise the flash expiry store", "$", "this", "->", "flash", "->", "set", "(", "FlashContainer", "::", "EXPIRE_DATA_KEY", ",", "array", "(", ")", ")", ";", "}" ]
Resets the data and flash data containers
[ "Resets", "the", "data", "and", "flash", "data", "containers" ]
948fd2b45286e65e7fababf65de89ca6aaca3c4a
https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Manager.php#L319-L330
train
sil-project/Contact
Model/Contact.php
Contact.addAddress
public function addAddress(AddressInterface $address) { if ($this->addresses->contains($address)) { throw new \InvalidArgumentException('This contact already owns this address'); } $this->addresses->add($address); if (!$this->defaultAddress) { $this->setDefaultAddress($address); } }
php
public function addAddress(AddressInterface $address) { if ($this->addresses->contains($address)) { throw new \InvalidArgumentException('This contact already owns this address'); } $this->addresses->add($address); if (!$this->defaultAddress) { $this->setDefaultAddress($address); } }
[ "public", "function", "addAddress", "(", "AddressInterface", "$", "address", ")", "{", "if", "(", "$", "this", "->", "addresses", "->", "contains", "(", "$", "address", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'This contact already owns this address'", ")", ";", "}", "$", "this", "->", "addresses", "->", "add", "(", "$", "address", ")", ";", "if", "(", "!", "$", "this", "->", "defaultAddress", ")", "{", "$", "this", "->", "setDefaultAddress", "(", "$", "address", ")", ";", "}", "}" ]
Add an Address to the collection. @param AddressInterface $address
[ "Add", "an", "Address", "to", "the", "collection", "." ]
ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9
https://github.com/sil-project/Contact/blob/ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9/Model/Contact.php#L228-L239
train
sil-project/Contact
Model/Contact.php
Contact.removeAddress
public function removeAddress(AddressInterface $address) { if (!$this->hasAddress($address)) { throw new \InvalidArgumentException('Trying to remove an address that does not belong to this contact'); } $this->addresses->removeElement($address); if ($address === $this->defaultAddress) { if ($this->addresses->count() > 0) { $this->defaultAddress = $this->addresses->first(); return; } $this->defaultAddress = null; } }
php
public function removeAddress(AddressInterface $address) { if (!$this->hasAddress($address)) { throw new \InvalidArgumentException('Trying to remove an address that does not belong to this contact'); } $this->addresses->removeElement($address); if ($address === $this->defaultAddress) { if ($this->addresses->count() > 0) { $this->defaultAddress = $this->addresses->first(); return; } $this->defaultAddress = null; } }
[ "public", "function", "removeAddress", "(", "AddressInterface", "$", "address", ")", "{", "if", "(", "!", "$", "this", "->", "hasAddress", "(", "$", "address", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Trying to remove an address that does not belong to this contact'", ")", ";", "}", "$", "this", "->", "addresses", "->", "removeElement", "(", "$", "address", ")", ";", "if", "(", "$", "address", "===", "$", "this", "->", "defaultAddress", ")", "{", "if", "(", "$", "this", "->", "addresses", "->", "count", "(", ")", ">", "0", ")", "{", "$", "this", "->", "defaultAddress", "=", "$", "this", "->", "addresses", "->", "first", "(", ")", ";", "return", ";", "}", "$", "this", "->", "defaultAddress", "=", "null", ";", "}", "}" ]
Remove an Address from the collection. @param AddressInterface $address
[ "Remove", "an", "Address", "from", "the", "collection", "." ]
ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9
https://github.com/sil-project/Contact/blob/ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9/Model/Contact.php#L246-L263
train
sil-project/Contact
Model/Contact.php
Contact.addPhone
public function addPhone(PhoneInterface $phone) { if ($this->phones->contains($phone)) { throw new \InvalidArgumentException('This contact already owns this phone'); } $this->phones->add($phone); if (!$this->defaultPhone) { $this->setDefaultPhone($phone); } }
php
public function addPhone(PhoneInterface $phone) { if ($this->phones->contains($phone)) { throw new \InvalidArgumentException('This contact already owns this phone'); } $this->phones->add($phone); if (!$this->defaultPhone) { $this->setDefaultPhone($phone); } }
[ "public", "function", "addPhone", "(", "PhoneInterface", "$", "phone", ")", "{", "if", "(", "$", "this", "->", "phones", "->", "contains", "(", "$", "phone", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'This contact already owns this phone'", ")", ";", "}", "$", "this", "->", "phones", "->", "add", "(", "$", "phone", ")", ";", "if", "(", "!", "$", "this", "->", "defaultPhone", ")", "{", "$", "this", "->", "setDefaultPhone", "(", "$", "phone", ")", ";", "}", "}" ]
Add a Phone to the collection. @param PhoneInterface $phone
[ "Add", "a", "Phone", "to", "the", "collection", "." ]
ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9
https://github.com/sil-project/Contact/blob/ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9/Model/Contact.php#L312-L323
train
sil-project/Contact
Model/Contact.php
Contact.removePhone
public function removePhone(PhoneInterface $phone) { if (!$this->hasPhone($phone)) { throw new \InvalidArgumentException('Trying to remove a phone that does not belong to this contact'); } $this->phones->removeElement($phone); if ($phone === $this->defaultPhone) { if ($this->phones->count() > 0) { $this->defaultPhone = $this->phones->first(); return; } $this->defaultPhone = null; } }
php
public function removePhone(PhoneInterface $phone) { if (!$this->hasPhone($phone)) { throw new \InvalidArgumentException('Trying to remove a phone that does not belong to this contact'); } $this->phones->removeElement($phone); if ($phone === $this->defaultPhone) { if ($this->phones->count() > 0) { $this->defaultPhone = $this->phones->first(); return; } $this->defaultPhone = null; } }
[ "public", "function", "removePhone", "(", "PhoneInterface", "$", "phone", ")", "{", "if", "(", "!", "$", "this", "->", "hasPhone", "(", "$", "phone", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Trying to remove a phone that does not belong to this contact'", ")", ";", "}", "$", "this", "->", "phones", "->", "removeElement", "(", "$", "phone", ")", ";", "if", "(", "$", "phone", "===", "$", "this", "->", "defaultPhone", ")", "{", "if", "(", "$", "this", "->", "phones", "->", "count", "(", ")", ">", "0", ")", "{", "$", "this", "->", "defaultPhone", "=", "$", "this", "->", "phones", "->", "first", "(", ")", ";", "return", ";", "}", "$", "this", "->", "defaultPhone", "=", "null", ";", "}", "}" ]
Remove a Phone from the collection. @param PhoneInterface $phone
[ "Remove", "a", "Phone", "from", "the", "collection", "." ]
ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9
https://github.com/sil-project/Contact/blob/ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9/Model/Contact.php#L330-L347
train
melisplatform/melis-calendar
src/Controller/ToolCalendarController.php
ToolCalendarController.retrieveDashboardCalendarEventsAction
public function retrieveDashboardCalendarEventsAction(){ $calendarTable = $this->getServiceLocator()->get('MelisCalendarTable'); $result = $calendarTable->retrieveDashboardCalendarEvents(); return new JsonModel($result->toArray()); }
php
public function retrieveDashboardCalendarEventsAction(){ $calendarTable = $this->getServiceLocator()->get('MelisCalendarTable'); $result = $calendarTable->retrieveDashboardCalendarEvents(); return new JsonModel($result->toArray()); }
[ "public", "function", "retrieveDashboardCalendarEventsAction", "(", ")", "{", "$", "calendarTable", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'MelisCalendarTable'", ")", ";", "$", "result", "=", "$", "calendarTable", "->", "retrieveDashboardCalendarEvents", "(", ")", ";", "return", "new", "JsonModel", "(", "$", "result", "->", "toArray", "(", ")", ")", ";", "}" ]
Retrive Calendar Event to initialize calender uifor Dashboard Calendar @return \Zend\View\Model\JsonModel
[ "Retrive", "Calendar", "Event", "to", "initialize", "calender", "uifor", "Dashboard", "Calendar" ]
1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223
https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Controller/ToolCalendarController.php#L25-L29
train