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
atayahmet/laravel-nestable
src/NestableTrait.php
NestableTrait.to
protected function to() { if (static::$to === 1) { $method = 'renderAsArray'; } elseif (static::$to === 2) { $method = 'renderAsJson'; } elseif (static::$to === 3) { $method = 'renderAsHtml'; } elseif (static::$to === 4) { $method = 'renderAsDropdown'; } else { return $this->source; } $nest = new NestableService(); $nest->save(static::$parameters); $nestable = $nest->make($this->source); static::$nested = false; return call_user_func([$nestable, $method]); }
php
protected function to() { if (static::$to === 1) { $method = 'renderAsArray'; } elseif (static::$to === 2) { $method = 'renderAsJson'; } elseif (static::$to === 3) { $method = 'renderAsHtml'; } elseif (static::$to === 4) { $method = 'renderAsDropdown'; } else { return $this->source; } $nest = new NestableService(); $nest->save(static::$parameters); $nestable = $nest->make($this->source); static::$nested = false; return call_user_func([$nestable, $method]); }
[ "protected", "function", "to", "(", ")", "{", "if", "(", "static", "::", "$", "to", "===", "1", ")", "{", "$", "method", "=", "'renderAsArray'", ";", "}", "elseif", "(", "static", "::", "$", "to", "===", "2", ")", "{", "$", "method", "=", "'rende...
Pass data to nest methods. @return mixed
[ "Pass", "data", "to", "nest", "methods", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/NestableTrait.php#L119-L140
train
atayahmet/laravel-nestable
src/NestableTrait.php
NestableTrait.saveParameter
protected function saveParameter($method, $value) { if (!isset(static::$parameters[$method])) { static::$parameters[$method] = []; } if ($value instanceof Closure) { static::$parameters[$method]['callback'] = $value; } elseif (is_array($value)) { foreach ($value as $key => $attr) { static::$parameters[$method][$key] = $attr; } }else{ static::$parameters[$method][] = $value; } return $this; }
php
protected function saveParameter($method, $value) { if (!isset(static::$parameters[$method])) { static::$parameters[$method] = []; } if ($value instanceof Closure) { static::$parameters[$method]['callback'] = $value; } elseif (is_array($value)) { foreach ($value as $key => $attr) { static::$parameters[$method][$key] = $attr; } }else{ static::$parameters[$method][] = $value; } return $this; }
[ "protected", "function", "saveParameter", "(", "$", "method", ",", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "parameters", "[", "$", "method", "]", ")", ")", "{", "static", "::", "$", "parameters", "[", "$", "method",...
Save the service parameters. @param string $method Method name in NestableService @param mixed $value @return object
[ "Save", "the", "service", "parameters", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/NestableTrait.php#L210-L227
train
atayahmet/laravel-nestable
src/NestableTrait.php
NestableTrait.where
public static function where($column, $operator = null, $value = null, $boolean = 'and') { return parent::query()->where($column, $operator, $value, $boolean); }
php
public static function where($column, $operator = null, $value = null, $boolean = 'and') { return parent::query()->where($column, $operator, $value, $boolean); }
[ "public", "static", "function", "where", "(", "$", "column", ",", "$", "operator", "=", "null", ",", "$", "value", "=", "null", ",", "$", "boolean", "=", "'and'", ")", "{", "return", "parent", "::", "query", "(", ")", "->", "where", "(", "$", "colu...
Call the parent where method @return bool|null @throws \Exception
[ "Call", "the", "parent", "where", "method" ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/NestableTrait.php#L246-L249
train
atayahmet/laravel-nestable
src/MacrosTrait.php
MacrosTrait.runMacro
public function runMacro($name, $args) { if (isset($this->macros[$name])) { if (is_callable($this->macros[$name])) { return call_user_func_array($this->macros[$name], array_merge([$this], $args)); } } }
php
public function runMacro($name, $args) { if (isset($this->macros[$name])) { if (is_callable($this->macros[$name])) { return call_user_func_array($this->macros[$name], array_merge([$this], $args)); } } }
[ "public", "function", "runMacro", "(", "$", "name", ",", "$", "args", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "macros", "[", "$", "name", "]", ")", ")", "{", "if", "(", "is_callable", "(", "$", "this", "->", "macros", "[", "$", "n...
Run the macros. @param string $name @param mixed $args @return mixed
[ "Run", "the", "macros", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/MacrosTrait.php#L30-L37
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.make
public function make($data) { if ($data instanceof Collection) { $this->data = collect($data->toArray()); } elseif (is_array($data)) { $this->data = collect($data); } else { throw new InvalidArgumentException('Invalid data type.'); } $this->config = Config::get('nestable'); $this->parent = $this->config['parent']; $this->primary_key = $this->config['primary_key']; return $this; }
php
public function make($data) { if ($data instanceof Collection) { $this->data = collect($data->toArray()); } elseif (is_array($data)) { $this->data = collect($data); } else { throw new InvalidArgumentException('Invalid data type.'); } $this->config = Config::get('nestable'); $this->parent = $this->config['parent']; $this->primary_key = $this->config['primary_key']; return $this; }
[ "public", "function", "make", "(", "$", "data", ")", "{", "if", "(", "$", "data", "instanceof", "Collection", ")", "{", "$", "this", "->", "data", "=", "collect", "(", "$", "data", "->", "toArray", "(", ")", ")", ";", "}", "elseif", "(", "is_array"...
Set the data to wrap class. @param mixed $data @return object (instance)
[ "Set", "the", "data", "to", "wrap", "class", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L122-L139
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.renderAsArray
public function renderAsArray($data = false, $parent = 0) { $args = $this->setParameters(func_get_args()); $tree = collect([]); $args['data']->each(function ($item) use (&$tree, $args) { $currentData = collect([]); if (intval($item[$this->parent]) == intval($args['parent'])) { // fill the array with the body fields foreach ($this->config['body'] as $field) { $currentData->put($field, isset($item[$field]) ? $item[$field] : null); } // Get the child node name $child = $this->config['childNode']; $currentData->put($child, []); $currentData->put($this->parent, $item[$this->parent]); // Get the primary key name $item_id = $item[$this->config['primary_key']]; // check the child element if ($this->hasChild($this->parent, $item_id, $args['data'])) { // function call again for child elements $currentData->put($child, $this->renderAsArray($args['data'], $item_id)); } // current data push to global array $tree->push($currentData->toArray()); } }); return $tree->toArray(); }
php
public function renderAsArray($data = false, $parent = 0) { $args = $this->setParameters(func_get_args()); $tree = collect([]); $args['data']->each(function ($item) use (&$tree, $args) { $currentData = collect([]); if (intval($item[$this->parent]) == intval($args['parent'])) { // fill the array with the body fields foreach ($this->config['body'] as $field) { $currentData->put($field, isset($item[$field]) ? $item[$field] : null); } // Get the child node name $child = $this->config['childNode']; $currentData->put($child, []); $currentData->put($this->parent, $item[$this->parent]); // Get the primary key name $item_id = $item[$this->config['primary_key']]; // check the child element if ($this->hasChild($this->parent, $item_id, $args['data'])) { // function call again for child elements $currentData->put($child, $this->renderAsArray($args['data'], $item_id)); } // current data push to global array $tree->push($currentData->toArray()); } }); return $tree->toArray(); }
[ "public", "function", "renderAsArray", "(", "$", "data", "=", "false", ",", "$", "parent", "=", "0", ")", "{", "$", "args", "=", "$", "this", "->", "setParameters", "(", "func_get_args", "(", ")", ")", ";", "$", "tree", "=", "collect", "(", "[", "]...
Pass to array of all data as nesting. @param object $data Illuminate\Support\Collection @param int $parent @return Recursion|array
[ "Pass", "to", "array", "of", "all", "data", "as", "nesting", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L174-L210
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.renderAsJson
public function renderAsJson($data = false, $parent = 0) { $args = func_get_args(); if (count($args) < 1) { $data = $this->renderAsArray(); } else { $data = $this->renderAsArray($data); } return json_encode($data); }
php
public function renderAsJson($data = false, $parent = 0) { $args = func_get_args(); if (count($args) < 1) { $data = $this->renderAsArray(); } else { $data = $this->renderAsArray($data); } return json_encode($data); }
[ "public", "function", "renderAsJson", "(", "$", "data", "=", "false", ",", "$", "parent", "=", "0", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "if", "(", "count", "(", "$", "args", ")", "<", "1", ")", "{", "$", "data", "=", "$"...
Pass to json string of all data as nesting. @param object $data Illuminate\Support\Collection @param int $parent @return Recursion|array
[ "Pass", "to", "json", "string", "of", "all", "data", "as", "nesting", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L220-L231
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.renderAsDropdown
public function renderAsDropdown($data = false, $parent = 0, $first = true, $level = 0) { $args = $this->setParameters(func_get_args()); $tree = ''; // open the select tag if ($first) { $tree = $first ? '<select '.$this->addAttributes().' ' : ''; } // if pass array data to selected method procces will generate multiple dropdown menu. if ($first && $this->multiple == true) { $tree .= ' multiple'; } if ($first) { $tree .= '>'; if(current($this->placeholder)) { $tree .= '<option value="'.key($this->placeholder).'">' . current($this->placeholder) . '</option>'; } } $args['data']->each(function ($child_item) use (&$tree, $args, $level) { $childItems = ''; if (intval($child_item[$this->parent]) == intval($args['parent'])) { // Get the value $value = $child_item[$this->config['dropdown']['value']]; // Get the label text $label = $child_item[$this->config['dropdown']['label']]; $prefix = $this->config['dropdown']['prefix']; // Generating nest level $levels = str_repeat('&nbsp;&nbsp;', $level); // check the does want select value $selected = $this->doSelect($value, $label); // Generating dropdown item $childItems .= '<option '.$selected.' value="'.$value.'">'.$levels.$prefix.$label.'</option>'; $item_id = $child_item[$this->config['primary_key']]; // check the child element if ($this->hasChild($this->parent, $item_id, $args['data'])) { ++$level; // nest level increasing // function call again for child elements $childItems .= $this->renderAsDropdown($args['data'], $item_id, false, $level); } } // current data contact to the parent variable $tree = $tree.$childItems; }); // close the select tag $tree = $first ? $tree.'</select>' : $tree; return $tree; }
php
public function renderAsDropdown($data = false, $parent = 0, $first = true, $level = 0) { $args = $this->setParameters(func_get_args()); $tree = ''; // open the select tag if ($first) { $tree = $first ? '<select '.$this->addAttributes().' ' : ''; } // if pass array data to selected method procces will generate multiple dropdown menu. if ($first && $this->multiple == true) { $tree .= ' multiple'; } if ($first) { $tree .= '>'; if(current($this->placeholder)) { $tree .= '<option value="'.key($this->placeholder).'">' . current($this->placeholder) . '</option>'; } } $args['data']->each(function ($child_item) use (&$tree, $args, $level) { $childItems = ''; if (intval($child_item[$this->parent]) == intval($args['parent'])) { // Get the value $value = $child_item[$this->config['dropdown']['value']]; // Get the label text $label = $child_item[$this->config['dropdown']['label']]; $prefix = $this->config['dropdown']['prefix']; // Generating nest level $levels = str_repeat('&nbsp;&nbsp;', $level); // check the does want select value $selected = $this->doSelect($value, $label); // Generating dropdown item $childItems .= '<option '.$selected.' value="'.$value.'">'.$levels.$prefix.$label.'</option>'; $item_id = $child_item[$this->config['primary_key']]; // check the child element if ($this->hasChild($this->parent, $item_id, $args['data'])) { ++$level; // nest level increasing // function call again for child elements $childItems .= $this->renderAsDropdown($args['data'], $item_id, false, $level); } } // current data contact to the parent variable $tree = $tree.$childItems; }); // close the select tag $tree = $first ? $tree.'</select>' : $tree; return $tree; }
[ "public", "function", "renderAsDropdown", "(", "$", "data", "=", "false", ",", "$", "parent", "=", "0", ",", "$", "first", "=", "true", ",", "$", "level", "=", "0", ")", "{", "$", "args", "=", "$", "this", "->", "setParameters", "(", "func_get_args",...
Convert to dropdown. @param object $data Illuminate\Support\Collection @param int $parent Current parent id @param bool $first first run @param int $level nest counter @return string
[ "Convert", "to", "dropdown", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L309-L375
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.addAttributes
protected function addAttributes() { $attrs = ''; foreach ($this->dropdownAttr as $attr => $value) { $attrs .= $attr.'='.'"'.$value.'" '; } return $attrs; }
php
protected function addAttributes() { $attrs = ''; foreach ($this->dropdownAttr as $attr => $value) { $attrs .= $attr.'='.'"'.$value.'" '; } return $attrs; }
[ "protected", "function", "addAttributes", "(", ")", "{", "$", "attrs", "=", "''", ";", "foreach", "(", "$", "this", "->", "dropdownAttr", "as", "$", "attr", "=>", "$", "value", ")", "{", "$", "attrs", ".=", "$", "attr", ".", "'='", ".", "'\"'", "."...
Contact th attributes to dropdown. @return string
[ "Contact", "th", "attributes", "to", "dropdown", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L401-L410
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.hasChild
public function hasChild($key = null, $value = null, Collect $data = null) { if (func_num_args() < 3) { $data = $this->data; $key = $this->parent; $value = current(func_get_args()); } $child = false; $data->each(function ($item) use (&$child, $key, $value) { if (intval($item[$key]) == intval($value) && !$child) { $child = true; } }); return $child; }
php
public function hasChild($key = null, $value = null, Collect $data = null) { if (func_num_args() < 3) { $data = $this->data; $key = $this->parent; $value = current(func_get_args()); } $child = false; $data->each(function ($item) use (&$child, $key, $value) { if (intval($item[$key]) == intval($value) && !$child) { $child = true; } }); return $child; }
[ "public", "function", "hasChild", "(", "$", "key", "=", "null", ",", "$", "value", "=", "null", ",", "Collect", "$", "data", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", "<", "3", ")", "{", "$", "data", "=", "$", "this", "->", "...
Child menu checker. @param string $key @param mixed $value @param object $data Illuminate\Support\Collection as Collect @return bool
[ "Child", "menu", "checker", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L421-L440
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.selected
public function selected($values) { if (is_array($values) || $values instanceof Closure) { $this->selected = $values; } else if (func_num_args() > 1) { $this->selected = func_get_args(); } else { $this->selected = [$values]; } return $this; }
php
public function selected($values) { if (is_array($values) || $values instanceof Closure) { $this->selected = $values; } else if (func_num_args() > 1) { $this->selected = func_get_args(); } else { $this->selected = [$values]; } return $this; }
[ "public", "function", "selected", "(", "$", "values", ")", "{", "if", "(", "is_array", "(", "$", "values", ")", "||", "$", "values", "instanceof", "Closure", ")", "{", "$", "this", "->", "selected", "=", "$", "values", ";", "}", "else", "if", "(", ...
Save the will select values. @param int|array $values @return object (instance)
[ "Save", "the", "will", "select", "values", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L449-L461
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.active
public function active() { $args = func_get_args(); $this->active = current($args); if (func_num_args() > 1) { $this->active = $args; } return $this; }
php
public function active() { $args = func_get_args(); $this->active = current($args); if (func_num_args() > 1) { $this->active = $args; } return $this; }
[ "public", "function", "active", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "this", "->", "active", "=", "current", "(", "$", "args", ")", ";", "if", "(", "func_num_args", "(", ")", ">", "1", ")", "{", "$", "this", "->",...
Attribute insert helper for html render. @return object (instance)
[ "Attribute", "insert", "helper", "for", "html", "render", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L483-L493
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.parent
public function parent($parent = false) { if ($parent) { $this->parents = !is_array($parent) ? [$parent] : $parent; if (func_num_args() > 1) { $this->parents = func_get_args(); } } return $this; }
php
public function parent($parent = false) { if ($parent) { $this->parents = !is_array($parent) ? [$parent] : $parent; if (func_num_args() > 1) { $this->parents = func_get_args(); } } return $this; }
[ "public", "function", "parent", "(", "$", "parent", "=", "false", ")", "{", "if", "(", "$", "parent", ")", "{", "$", "this", "->", "parents", "=", "!", "is_array", "(", "$", "parent", ")", "?", "[", "$", "parent", "]", ":", "$", "parent", ";", ...
Set the parent id for child elements. @param int $parent @return object (instance)
[ "Set", "the", "parent", "id", "for", "child", "elements", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L557-L568
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.doSelect
protected function doSelect($value, $label) { if ($this->selected) { if (is_array($this->selected) && count($this->selected) > 0) { $result = array_search($value, $this->selected); if ($result !== false) { unset($this->selected[$result]); return 'selected="selected"'; } } elseif ($this->selected instanceof Closure) { call_user_func_array($this->selected, [$this, $value, $label]); $attrs = $this->renderAttr($this->optionAttr); $this->optionAttr = null; return $attrs; } else { if ($this->selected == $value) { $this->selected = null; return 'selected="selected"'; } } } }
php
protected function doSelect($value, $label) { if ($this->selected) { if (is_array($this->selected) && count($this->selected) > 0) { $result = array_search($value, $this->selected); if ($result !== false) { unset($this->selected[$result]); return 'selected="selected"'; } } elseif ($this->selected instanceof Closure) { call_user_func_array($this->selected, [$this, $value, $label]); $attrs = $this->renderAttr($this->optionAttr); $this->optionAttr = null; return $attrs; } else { if ($this->selected == $value) { $this->selected = null; return 'selected="selected"'; } } } }
[ "protected", "function", "doSelect", "(", "$", "value", ",", "$", "label", ")", "{", "if", "(", "$", "this", "->", "selected", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "selected", ")", "&&", "count", "(", "$", "this", "->", "selecte...
Set the as selected of items. @param mixed $value @return string
[ "Set", "the", "as", "selected", "of", "items", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L577-L601
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.renderAttr
protected function renderAttr($attributes = false, $params = false) { $attrStr = ''; if (isset($attributes['callback'])) { $callbackParams = [$this]; if ($params !== false) { array_push($callbackParams, $params); } call_user_func_array($attributes['callback'], $callbackParams); } if (is_array($attributes)) { foreach ($attributes as $attr => $value) { if (is_string($value)) { $attrStr .= ' '.$attr.'="'.$value.'"'; } } } return $attrStr; }
php
protected function renderAttr($attributes = false, $params = false) { $attrStr = ''; if (isset($attributes['callback'])) { $callbackParams = [$this]; if ($params !== false) { array_push($callbackParams, $params); } call_user_func_array($attributes['callback'], $callbackParams); } if (is_array($attributes)) { foreach ($attributes as $attr => $value) { if (is_string($value)) { $attrStr .= ' '.$attr.'="'.$value.'"'; } } } return $attrStr; }
[ "protected", "function", "renderAttr", "(", "$", "attributes", "=", "false", ",", "$", "params", "=", "false", ")", "{", "$", "attrStr", "=", "''", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'callback'", "]", ")", ")", "{", "$", "callback...
Render the attritues of html elements. @param mixed $attributes @param mixed $params @return string
[ "Render", "the", "attritues", "of", "html", "elements", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L669-L692
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.save
public function save(array $params) { foreach ($params as $method => $param) { if (is_array($param) && isset($param[0])) { call_user_func_array([$this, $method], $param); } else { $this->{$method}($param); } } }
php
public function save(array $params) { foreach ($params as $method => $param) { if (is_array($param) && isset($param[0])) { call_user_func_array([$this, $method], $param); } else { $this->{$method}($param); } } }
[ "public", "function", "save", "(", "array", "$", "params", ")", "{", "foreach", "(", "$", "params", "as", "$", "method", "=>", "$", "param", ")", "{", "if", "(", "is_array", "(", "$", "param", ")", "&&", "isset", "(", "$", "param", "[", "0", "]",...
Save the parameters. @param array $params
[ "Save", "the", "parameters", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L699-L708
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.url
protected function url($path, $label, $parent = null) { if ($this->config['generate_url']) { if ($this->route) { if (array_has($this->route, 'callback')) { if(is_array($parent)) $parent = (object)$parent; return call_user_func_array($this->route['callback'], [$path, $label, $parent]); } else { end($this->route); $param = current($this->route); $name = key($this->route); return URL::route($name, [$param => $path]); } } return URL::to($path); } return '/'.$path; }
php
protected function url($path, $label, $parent = null) { if ($this->config['generate_url']) { if ($this->route) { if (array_has($this->route, 'callback')) { if(is_array($parent)) $parent = (object)$parent; return call_user_func_array($this->route['callback'], [$path, $label, $parent]); } else { end($this->route); $param = current($this->route); $name = key($this->route); return URL::route($name, [$param => $path]); } } return URL::to($path); } return '/'.$path; }
[ "protected", "function", "url", "(", "$", "path", ",", "$", "label", ",", "$", "parent", "=", "null", ")", "{", "if", "(", "$", "this", "->", "config", "[", "'generate_url'", "]", ")", "{", "if", "(", "$", "this", "->", "route", ")", "{", "if", ...
URL Generator. @param string $path @return string
[ "URL", "Generator", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L717-L736
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.makeUrl
protected function makeUrl($path) { return URL::to(str_replace('{'.$this->config['html']['href'].'}', $path, $this->customUrl)); }
php
protected function makeUrl($path) { return URL::to(str_replace('{'.$this->config['html']['href'].'}', $path, $this->customUrl)); }
[ "protected", "function", "makeUrl", "(", "$", "path", ")", "{", "return", "URL", "::", "to", "(", "str_replace", "(", "'{'", ".", "$", "this", "->", "config", "[", "'html'", "]", "[", "'href'", "]", ".", "'}'", ",", "$", "path", ",", "$", "this", ...
Generate custom url @param string $path @return type
[ "Generate", "custom", "url" ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L769-L772
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.ul
public function ul($items = false, $parent_id = 0, $first = false) { $attrs = ''; if (! $first && is_array($this->optionUlAttr) && count($this->optionUlAttr) > 0) { $attrs = $this->renderAttr($this->optionUlAttr, $parent_id); } else if($first && count($this->firstUlAttrs) > 0) { $attrs = $this->renderAttr($this->firstUlAttrs, $parent_id); } if (!$items) { return "\n".'<ul'.$attrs.'>'."\n"; } return '<ul'.$attrs.'>'."\n".$items."\n".'</ul>'; }
php
public function ul($items = false, $parent_id = 0, $first = false) { $attrs = ''; if (! $first && is_array($this->optionUlAttr) && count($this->optionUlAttr) > 0) { $attrs = $this->renderAttr($this->optionUlAttr, $parent_id); } else if($first && count($this->firstUlAttrs) > 0) { $attrs = $this->renderAttr($this->firstUlAttrs, $parent_id); } if (!$items) { return "\n".'<ul'.$attrs.'>'."\n"; } return '<ul'.$attrs.'>'."\n".$items."\n".'</ul>'; }
[ "public", "function", "ul", "(", "$", "items", "=", "false", ",", "$", "parent_id", "=", "0", ",", "$", "first", "=", "false", ")", "{", "$", "attrs", "=", "''", ";", "if", "(", "!", "$", "first", "&&", "is_array", "(", "$", "this", "->", "opti...
Generate open ul tag. @param string $items @return string
[ "Generate", "open", "ul", "tag", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L781-L797
train
atayahmet/laravel-nestable
src/Services/NestableService.php
NestableService.isValid
public function isValid($type, $render = false) { $original = $type; if (in_array($type, ['json', 'array'])) { $type = 'body'; } $type = $type == 'multiple' ? 'dropdown' : $type; $fields = $this->config[$type]; $valid = true; // mapping all data $this->data->map(function ($item) use ($fields, &$valid, $type) { foreach ($fields as $field) { if ($valid && !empty($field)) { $valid = isset($item[$field]); } } }); // render data if ($valid && $render) { return call_user_func([$this, 'renderAs'.ucfirst($original)]); } return $valid; }
php
public function isValid($type, $render = false) { $original = $type; if (in_array($type, ['json', 'array'])) { $type = 'body'; } $type = $type == 'multiple' ? 'dropdown' : $type; $fields = $this->config[$type]; $valid = true; // mapping all data $this->data->map(function ($item) use ($fields, &$valid, $type) { foreach ($fields as $field) { if ($valid && !empty($field)) { $valid = isset($item[$field]); } } }); // render data if ($valid && $render) { return call_user_func([$this, 'renderAs'.ucfirst($original)]); } return $valid; }
[ "public", "function", "isValid", "(", "$", "type", ",", "$", "render", "=", "false", ")", "{", "$", "original", "=", "$", "type", ";", "if", "(", "in_array", "(", "$", "type", ",", "[", "'json'", ",", "'array'", "]", ")", ")", "{", "$", "type", ...
Array validator. @param string $type @param bool $return @return mixed
[ "Array", "validator", "." ]
c4997757c0234d705ca079939acd50453741cf42
https://github.com/atayahmet/laravel-nestable/blob/c4997757c0234d705ca079939acd50453741cf42/src/Services/NestableService.php#L843-L872
train
GoogleCloudPlatform/grpc-gcp-php
src/GCPBidiStreamingCall.php
GCPBidiStreamingCall.write
public function write($data, array $options = []) { if (!$this->has_real_call) { $this->createRealCall($data); $this->has_real_call = true; } $this->real_call->write($data, $options); }
php
public function write($data, array $options = []) { if (!$this->has_real_call) { $this->createRealCall($data); $this->has_real_call = true; } $this->real_call->write($data, $options); }
[ "public", "function", "write", "(", "$", "data", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "has_real_call", ")", "{", "$", "this", "->", "createRealCall", "(", "$", "data", ")", ";", "$", "this", "-...
Write a single message to the server. This cannot be called after writesDone is called. @param ByteBuffer $data The data to write @param array $options An array of options, possible keys: 'flags' => a number (optional)
[ "Write", "a", "single", "message", "to", "the", "server", ".", "This", "cannot", "be", "called", "after", "writesDone", "is", "called", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GCPBidiStreamingCall.php#L75-L82
train
GoogleCloudPlatform/grpc-gcp-php
src/GCPBidiStreamingCall.php
GCPBidiStreamingCall.writesDone
public function writesDone() { if (!$this->has_real_call) { $this->createRealCall(); $this->has_real_call = true; } $this->real_call->writesDone(); }
php
public function writesDone() { if (!$this->has_real_call) { $this->createRealCall(); $this->has_real_call = true; } $this->real_call->writesDone(); }
[ "public", "function", "writesDone", "(", ")", "{", "if", "(", "!", "$", "this", "->", "has_real_call", ")", "{", "$", "this", "->", "createRealCall", "(", ")", ";", "$", "this", "->", "has_real_call", "=", "true", ";", "}", "$", "this", "->", "real_c...
Indicate that no more writes will be sent.
[ "Indicate", "that", "no", "more", "writes", "will", "be", "sent", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GCPBidiStreamingCall.php#L87-L94
train
GoogleCloudPlatform/grpc-gcp-php
src/generated/Grpc/Gcp/ApiConfig.php
ApiConfig.setMethod
public function setMethod($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Grpc\Gcp\MethodConfig::class); $this->method = $arr; return $this; }
php
public function setMethod($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Grpc\Gcp\MethodConfig::class); $this->method = $arr; return $this; }
[ "public", "function", "setMethod", "(", "$", "var", ")", "{", "$", "arr", "=", "GPBUtil", "::", "checkRepeatedField", "(", "$", "var", ",", "\\", "Google", "\\", "Protobuf", "\\", "Internal", "\\", "GPBType", "::", "MESSAGE", ",", "\\", "Grpc", "\\", "...
The method configurations. Generated from protobuf field <code>repeated .grpc.gcp.MethodConfig method = 1001;</code> @param \Grpc\Gcp\MethodConfig[]|\Google\Protobuf\Internal\RepeatedField $var @return $this
[ "The", "method", "configurations", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/generated/Grpc/Gcp/ApiConfig.php#L77-L83
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpExtensionChannel.php
GcpExtensionChannel.bind
public function bind($channel_ref, $affinity_key) { if (!array_key_exists($affinity_key, $this->affinity_key_to_channel_ref)) { $this->affinity_key_to_channel_ref[$affinity_key] = $channel_ref; } $channel_ref->affinityRefIncr(); return $channel_ref; }
php
public function bind($channel_ref, $affinity_key) { if (!array_key_exists($affinity_key, $this->affinity_key_to_channel_ref)) { $this->affinity_key_to_channel_ref[$affinity_key] = $channel_ref; } $channel_ref->affinityRefIncr(); return $channel_ref; }
[ "public", "function", "bind", "(", "$", "channel_ref", ",", "$", "affinity_key", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "affinity_key", ",", "$", "this", "->", "affinity_key_to_channel_ref", ")", ")", "{", "$", "this", "->", "affinity_key_to...
Bind the ChannelRef with the affinity key. This is a private method. @param ChannelRef $channel_ref @param string $affinity_key @return ChannelRef
[ "Bind", "the", "ChannelRef", "with", "the", "affinity", "key", ".", "This", "is", "a", "private", "method", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpExtensionChannel.php#L102-L109
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpExtensionChannel.php
GcpExtensionChannel.unbind
public function unbind($affinity_key) { $channel_ref = null; if (array_key_exists($affinity_key, $this->affinity_key_to_channel_ref)) { $channel_ref = $this->affinity_key_to_channel_ref[$affinity_key]; $channel_ref->affinityRefDecr(); } unset($this->affinity_key_to_channel_ref[$affinity_key]); return $channel_ref; }
php
public function unbind($affinity_key) { $channel_ref = null; if (array_key_exists($affinity_key, $this->affinity_key_to_channel_ref)) { $channel_ref = $this->affinity_key_to_channel_ref[$affinity_key]; $channel_ref->affinityRefDecr(); } unset($this->affinity_key_to_channel_ref[$affinity_key]); return $channel_ref; }
[ "public", "function", "unbind", "(", "$", "affinity_key", ")", "{", "$", "channel_ref", "=", "null", ";", "if", "(", "array_key_exists", "(", "$", "affinity_key", ",", "$", "this", "->", "affinity_key_to_channel_ref", ")", ")", "{", "$", "channel_ref", "=", ...
Unbind the affinity key. This is a private method. @param string $affinity_key @return ChannelRef
[ "Unbind", "the", "affinity", "key", ".", "This", "is", "a", "private", "method", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpExtensionChannel.php#L118-L127
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpExtensionChannel.php
GcpExtensionChannel.getChannelRef
public function getChannelRef($affinity_key = null) { if ($affinity_key) { if (array_key_exists($affinity_key, $this->affinity_key_to_channel_ref)) { return $this->affinity_key_to_channel_ref[$affinity_key]; } return $this->getChannelRef(); } usort($this->channel_refs, array($this, 'cmp_by_active_stream_ref')); if (count($this->channel_refs) > 0 && $this->channel_refs[0]->getActiveStreamRef() < $this->max_concurrent_streams_low_watermark) { return $this->channel_refs[0]; } $num_channel_refs = count($this->channel_refs); if ($num_channel_refs < $this->max_size) { // grpc_target_persist_bound stands for how many channels can be persisted for // the same target in the C extension. It is possible that the user use the pure // gRPC and this GCP extension at the same time, which share the same target. In this case // pure gRPC channel may occupy positions in C extension, which deletes some channels created // by this GCP extension. // If that happens, it won't cause the script failure because we saves all arguments for creating // a channel instead of a channel itself. If we watch to fetch a GCP channel already deleted, // it will create a new channel. The only cons is the latency of the first RPC will high because // it will establish the connection again. if (!isset($this->options['grpc_target_persist_bound']) || $this->options['grpc_target_persist_bound'] < $this->max_size) { $this->options['grpc_target_persist_bound'] = $this->max_size; } $cur_opts = array_merge($this->options, ['grpc_gcp_channel_id' => $num_channel_refs]); $channel_ref = new ChannelRef($this->target, $num_channel_refs, $cur_opts); array_unshift($this->channel_refs, $channel_ref); } return $this->channel_refs[0]; }
php
public function getChannelRef($affinity_key = null) { if ($affinity_key) { if (array_key_exists($affinity_key, $this->affinity_key_to_channel_ref)) { return $this->affinity_key_to_channel_ref[$affinity_key]; } return $this->getChannelRef(); } usort($this->channel_refs, array($this, 'cmp_by_active_stream_ref')); if (count($this->channel_refs) > 0 && $this->channel_refs[0]->getActiveStreamRef() < $this->max_concurrent_streams_low_watermark) { return $this->channel_refs[0]; } $num_channel_refs = count($this->channel_refs); if ($num_channel_refs < $this->max_size) { // grpc_target_persist_bound stands for how many channels can be persisted for // the same target in the C extension. It is possible that the user use the pure // gRPC and this GCP extension at the same time, which share the same target. In this case // pure gRPC channel may occupy positions in C extension, which deletes some channels created // by this GCP extension. // If that happens, it won't cause the script failure because we saves all arguments for creating // a channel instead of a channel itself. If we watch to fetch a GCP channel already deleted, // it will create a new channel. The only cons is the latency of the first RPC will high because // it will establish the connection again. if (!isset($this->options['grpc_target_persist_bound']) || $this->options['grpc_target_persist_bound'] < $this->max_size) { $this->options['grpc_target_persist_bound'] = $this->max_size; } $cur_opts = array_merge($this->options, ['grpc_gcp_channel_id' => $num_channel_refs]); $channel_ref = new ChannelRef($this->target, $num_channel_refs, $cur_opts); array_unshift($this->channel_refs, $channel_ref); } return $this->channel_refs[0]; }
[ "public", "function", "getChannelRef", "(", "$", "affinity_key", "=", "null", ")", "{", "if", "(", "$", "affinity_key", ")", "{", "if", "(", "array_key_exists", "(", "$", "affinity_key", ",", "$", "this", "->", "affinity_key_to_channel_ref", ")", ")", "{", ...
Pick or create a ChannelRef from the pool by affinity key. @param string $affinity_key @return ChannelRef
[ "Pick", "or", "create", "a", "ChannelRef", "from", "the", "pool", "by", "affinity", "key", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpExtensionChannel.php#L142-L177
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpExtensionChannel.php
GcpExtensionChannel.getConnectivityState
public function getConnectivityState($try_to_connect = false) { // Since getRealChannel is creating a PHP Channel object. However in gRPC, when a Channel // object is closed, we only mark this Object to be invalid. Thus, we need a global variable // to mark whether this GCPExtensionChannel is close or not. if ($this->is_closed) { throw new \RuntimeException("Channel has already been closed"); } $ready = 0; $idle = 0; $connecting = 0; $transient_failure = 0; $shutdown = 0; foreach ($this->channel_refs as $channel_ref) { $state = $channel_ref->getRealChannel($this->credentials)->getConnectivityState($try_to_connect); switch ($state) { case \Grpc\CHANNEL_READY: $ready += 1; break 2; case \Grpc\CHANNEL_FATAL_FAILURE: $shutdown += 1; break; case \Grpc\CHANNEL_CONNECTING: $connecting += 1; break; case \Grpc\CHANNEL_TRANSIENT_FAILURE: $transient_failure += 1; break; case \Grpc\CHANNEL_IDLE: $idle += 1; break; } } if ($ready > 0) { return \Grpc\CHANNEL_READY; } elseif ($idle > 0) { return \Grpc\CHANNEL_IDLE; } elseif ($connecting > 0) { return \Grpc\CHANNEL_CONNECTING; } elseif ($transient_failure > 0) { return \Grpc\CHANNEL_TRANSIENT_FAILURE; } elseif ($shutdown > 0) { return \Grpc\CHANNEL_SHUTDOWN; } }
php
public function getConnectivityState($try_to_connect = false) { // Since getRealChannel is creating a PHP Channel object. However in gRPC, when a Channel // object is closed, we only mark this Object to be invalid. Thus, we need a global variable // to mark whether this GCPExtensionChannel is close or not. if ($this->is_closed) { throw new \RuntimeException("Channel has already been closed"); } $ready = 0; $idle = 0; $connecting = 0; $transient_failure = 0; $shutdown = 0; foreach ($this->channel_refs as $channel_ref) { $state = $channel_ref->getRealChannel($this->credentials)->getConnectivityState($try_to_connect); switch ($state) { case \Grpc\CHANNEL_READY: $ready += 1; break 2; case \Grpc\CHANNEL_FATAL_FAILURE: $shutdown += 1; break; case \Grpc\CHANNEL_CONNECTING: $connecting += 1; break; case \Grpc\CHANNEL_TRANSIENT_FAILURE: $transient_failure += 1; break; case \Grpc\CHANNEL_IDLE: $idle += 1; break; } } if ($ready > 0) { return \Grpc\CHANNEL_READY; } elseif ($idle > 0) { return \Grpc\CHANNEL_IDLE; } elseif ($connecting > 0) { return \Grpc\CHANNEL_CONNECTING; } elseif ($transient_failure > 0) { return \Grpc\CHANNEL_TRANSIENT_FAILURE; } elseif ($shutdown > 0) { return \Grpc\CHANNEL_SHUTDOWN; } }
[ "public", "function", "getConnectivityState", "(", "$", "try_to_connect", "=", "false", ")", "{", "// Since getRealChannel is creating a PHP Channel object. However in gRPC, when a Channel", "// object is closed, we only mark this Object to be invalid. Thus, we need a global variable", "// t...
Get the connectivity state of the channel @param bool $try_to_connect try to connect on the channel @return int The grpc connectivity state @throws \InvalidArgumentException
[ "Get", "the", "connectivity", "state", "of", "the", "channel" ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpExtensionChannel.php#L187-L231
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpExtensionChannel.php
GcpExtensionChannel.watchConnectivityState
public function watchConnectivityState($last_state, $deadline_obj = null) { if ($deadline_obj == null || !is_a($deadline_obj, '\Grpc\Timeval')) { throw new \InvalidArgumentException(""); } // Since getRealChannel is creating a PHP Channel object. However in gRPC, when a Channel // object is closed, we only mark this Object to be invalid. Thus, we need a global variable // to mark whether this GCPExtensionChannel is close or not. if ($this->is_closed) { throw new \RuntimeException("Channel has already been closed"); } $state = 0; foreach ($this->channel_refs as $channel_ref) { $state = $channel_ref->getRealChannel($this->credentials)->watchConnectivityState($last_state, $deadline_obj); } return $state; }
php
public function watchConnectivityState($last_state, $deadline_obj = null) { if ($deadline_obj == null || !is_a($deadline_obj, '\Grpc\Timeval')) { throw new \InvalidArgumentException(""); } // Since getRealChannel is creating a PHP Channel object. However in gRPC, when a Channel // object is closed, we only mark this Object to be invalid. Thus, we need a global variable // to mark whether this GCPExtensionChannel is close or not. if ($this->is_closed) { throw new \RuntimeException("Channel has already been closed"); } $state = 0; foreach ($this->channel_refs as $channel_ref) { $state = $channel_ref->getRealChannel($this->credentials)->watchConnectivityState($last_state, $deadline_obj); } return $state; }
[ "public", "function", "watchConnectivityState", "(", "$", "last_state", ",", "$", "deadline_obj", "=", "null", ")", "{", "if", "(", "$", "deadline_obj", "==", "null", "||", "!", "is_a", "(", "$", "deadline_obj", ",", "'\\Grpc\\Timeval'", ")", ")", "{", "th...
Watch the connectivity state of the channel until it changed @param int $last_state The previous connectivity state of the channel @param Timeval $deadline_obj The deadline this function should wait until @return bool If the connectivity state changes from last_state before deadline @throws \InvalidArgumentException
[ "Watch", "the", "connectivity", "state", "of", "the", "channel", "until", "it", "changed" ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpExtensionChannel.php#L243-L259
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpExtensionChannel.php
GcpExtensionChannel.close
public function close() { foreach ($this->channel_refs as $channel_ref) { $channel_ref->getRealChannel($this->credentials)->close(); } $this->is_closed = true; }
php
public function close() { foreach ($this->channel_refs as $channel_ref) { $channel_ref->getRealChannel($this->credentials)->close(); } $this->is_closed = true; }
[ "public", "function", "close", "(", ")", "{", "foreach", "(", "$", "this", "->", "channel_refs", "as", "$", "channel_ref", ")", "{", "$", "channel_ref", "->", "getRealChannel", "(", "$", "this", "->", "credentials", ")", "->", "close", "(", ")", ";", "...
Close the channel
[ "Close", "the", "channel" ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpExtensionChannel.php#L274-L280
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpBaseCall.php
GcpBaseCall._rpcPreProcess
protected function _rpcPreProcess($argument) { $this->affinity_key = null; if ($this->_affinity) { $command = $this->_affinity['command']; if ($command == self::BOUND || $command == self::UNBIND) { $this->affinity_key = $this->getAffinityKeyFromProto($argument); } } $this->channel_ref = $this->gcp_channel->getChannelRef($this->affinity_key); $this->channel_ref->activeStreamRefIncr(); return $this->channel_ref; }
php
protected function _rpcPreProcess($argument) { $this->affinity_key = null; if ($this->_affinity) { $command = $this->_affinity['command']; if ($command == self::BOUND || $command == self::UNBIND) { $this->affinity_key = $this->getAffinityKeyFromProto($argument); } } $this->channel_ref = $this->gcp_channel->getChannelRef($this->affinity_key); $this->channel_ref->activeStreamRefIncr(); return $this->channel_ref; }
[ "protected", "function", "_rpcPreProcess", "(", "$", "argument", ")", "{", "$", "this", "->", "affinity_key", "=", "null", ";", "if", "(", "$", "this", "->", "_affinity", ")", "{", "$", "command", "=", "$", "this", "->", "_affinity", "[", "'command'", ...
Pick a ChannelRef from the channel pool based on the request and the affinity config. @param mixed $argument Requests. @return ChannelRef
[ "Pick", "a", "ChannelRef", "from", "the", "channel", "pool", "based", "on", "the", "request", "and", "the", "affinity", "config", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpBaseCall.php#L82-L94
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpBaseCall.php
GcpBaseCall._rpcPostProcess
protected function _rpcPostProcess($status, $response) { if ($this->_affinity) { $command = $this->_affinity['command']; if ($command == self::BIND) { if ($status->code != \Grpc\STATUS_OK) { return; } $affinity_key = $this->getAffinityKeyFromProto($response); $this->gcp_channel->bind($this->channel_ref, $affinity_key); } elseif ($command == self::UNBIND) { $this->gcp_channel->unbind($this->affinity_key); } } $this->channel_ref->activeStreamRefDecr(); }
php
protected function _rpcPostProcess($status, $response) { if ($this->_affinity) { $command = $this->_affinity['command']; if ($command == self::BIND) { if ($status->code != \Grpc\STATUS_OK) { return; } $affinity_key = $this->getAffinityKeyFromProto($response); $this->gcp_channel->bind($this->channel_ref, $affinity_key); } elseif ($command == self::UNBIND) { $this->gcp_channel->unbind($this->affinity_key); } } $this->channel_ref->activeStreamRefDecr(); }
[ "protected", "function", "_rpcPostProcess", "(", "$", "status", ",", "$", "response", ")", "{", "if", "(", "$", "this", "->", "_affinity", ")", "{", "$", "command", "=", "$", "this", "->", "_affinity", "[", "'command'", "]", ";", "if", "(", "$", "com...
Update ChannelRef when RPC finishes. @param \stdClass $status The status object, with integer $code, string $details, and array $metadata members @param mixed $response Response.
[ "Update", "ChannelRef", "when", "RPC", "finishes", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpBaseCall.php#L103-L118
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpBaseCall.php
GcpBaseCall.getAffinityKeyFromProto
protected function getAffinityKeyFromProto($proto) { if ($this->_affinity) { $names = $this->_affinity['affinityKey']; $names_arr = explode(".", $names); foreach ($names_arr as $name) { $getAttrMethod = 'get' . ucfirst($name); $proto = call_user_func_array(array($proto, $getAttrMethod), array()); } return $proto; } echo "Cannot find the field in the proto\n"; }
php
protected function getAffinityKeyFromProto($proto) { if ($this->_affinity) { $names = $this->_affinity['affinityKey']; $names_arr = explode(".", $names); foreach ($names_arr as $name) { $getAttrMethod = 'get' . ucfirst($name); $proto = call_user_func_array(array($proto, $getAttrMethod), array()); } return $proto; } echo "Cannot find the field in the proto\n"; }
[ "protected", "function", "getAffinityKeyFromProto", "(", "$", "proto", ")", "{", "if", "(", "$", "this", "->", "_affinity", ")", "{", "$", "names", "=", "$", "this", "->", "_affinity", "[", "'affinityKey'", "]", ";", "$", "names_arr", "=", "explode", "("...
Get the affinity key based on the affinity config. @param mixed $proto Objects may contain the affinity key. @return string Affinity key.
[ "Get", "the", "affinity", "key", "based", "on", "the", "affinity", "config", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpBaseCall.php#L127-L139
train
GoogleCloudPlatform/grpc-gcp-php
src/GcpBaseCall.php
GcpBaseCall.cancel
public function cancel() { if (!$this->has_real_call) { $this->has_real_call = true; $this->createRealCall(); } $this->real_call->cancel(); }
php
public function cancel() { if (!$this->has_real_call) { $this->has_real_call = true; $this->createRealCall(); } $this->real_call->cancel(); }
[ "public", "function", "cancel", "(", ")", "{", "if", "(", "!", "$", "this", "->", "has_real_call", ")", "{", "$", "this", "->", "has_real_call", "=", "true", ";", "$", "this", "->", "createRealCall", "(", ")", ";", "}", "$", "this", "->", "real_call"...
Cancels the call.
[ "Cancels", "the", "call", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GcpBaseCall.php#L180-L187
train
GoogleCloudPlatform/grpc-gcp-php
src/GCPUnaryCall.php
GCPUnaryCall.start
public function start($argument, $metadata, $options) { $channel_ref = $this->_rpcPreProcess($argument); $real_channel = $channel_ref->getRealChannel($this->gcp_channel->credentials); $this->createRealCall($real_channel); $this->real_call->start($argument, $metadata, $options); }
php
public function start($argument, $metadata, $options) { $channel_ref = $this->_rpcPreProcess($argument); $real_channel = $channel_ref->getRealChannel($this->gcp_channel->credentials); $this->createRealCall($real_channel); $this->real_call->start($argument, $metadata, $options); }
[ "public", "function", "start", "(", "$", "argument", ",", "$", "metadata", ",", "$", "options", ")", "{", "$", "channel_ref", "=", "$", "this", "->", "_rpcPreProcess", "(", "$", "argument", ")", ";", "$", "real_channel", "=", "$", "channel_ref", "->", ...
Pick a channel and start the call. @param mixed $data The data to send @param array $metadata Metadata to send with the call, if applicable (optional) @param array $options An array of options, possible keys: 'flags' => a number (optional)
[ "Pick", "a", "channel", "and", "start", "the", "call", "." ]
71b333aef3678ee268fdf12765b422bb19640e11
https://github.com/GoogleCloudPlatform/grpc-gcp-php/blob/71b333aef3678ee268fdf12765b422bb19640e11/src/GCPUnaryCall.php#L43-L49
train
dg/MySQL-dump
src/MySQLImport.php
MySQLImport.load
public function load($file) { $handle = strcasecmp(substr($file, -3), '.gz') ? fopen($file, 'rb') : gzopen($file, 'rb'); if (!$handle) { throw new Exception("ERROR: Cannot open file '$file'."); } return $this->read($handle); }
php
public function load($file) { $handle = strcasecmp(substr($file, -3), '.gz') ? fopen($file, 'rb') : gzopen($file, 'rb'); if (!$handle) { throw new Exception("ERROR: Cannot open file '$file'."); } return $this->read($handle); }
[ "public", "function", "load", "(", "$", "file", ")", "{", "$", "handle", "=", "strcasecmp", "(", "substr", "(", "$", "file", ",", "-", "3", ")", ",", "'.gz'", ")", "?", "fopen", "(", "$", "file", ",", "'rb'", ")", ":", "gzopen", "(", "$", "file...
Loads dump from the file. @param string filename @return int
[ "Loads", "dump", "from", "the", "file", "." ]
6c9cf07092bcc4a140bef01c64d883ebfccfccfa
https://github.com/dg/MySQL-dump/blob/6c9cf07092bcc4a140bef01c64d883ebfccfccfa/src/MySQLImport.php#L41-L48
train
dg/MySQL-dump
src/MySQLImport.php
MySQLImport.read
public function read($handle) { if (!is_resource($handle) || get_resource_type($handle) !== 'stream') { throw new Exception('Argument must be stream resource.'); } $stat = fstat($handle); $sql = ''; $delimiter = ';'; $count = $size = 0; while (!feof($handle)) { $s = fgets($handle); $size += strlen($s); if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') { $delimiter = trim(substr($s, 10)); } elseif (substr($ts = rtrim($s), -strlen($delimiter)) === $delimiter) { $sql .= substr($ts, 0, -strlen($delimiter)); if (!$this->connection->query($sql)) { throw new Exception($this->connection->error . ': ' . $sql); } $sql = ''; $count++; if ($this->onProgress) { call_user_func($this->onProgress, $count, isset($stat['size']) ? $size * 100 / $stat['size'] : null); } } else { $sql .= $s; } } if (rtrim($sql) !== '') { $count++; if (!$this->connection->query($sql)) { throw new Exception($this->connection->error . ': ' . $sql); } if ($this->onProgress) { call_user_func($this->onProgress, $count, isset($stat['size']) ? 100 : null); } } return $count; }
php
public function read($handle) { if (!is_resource($handle) || get_resource_type($handle) !== 'stream') { throw new Exception('Argument must be stream resource.'); } $stat = fstat($handle); $sql = ''; $delimiter = ';'; $count = $size = 0; while (!feof($handle)) { $s = fgets($handle); $size += strlen($s); if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') { $delimiter = trim(substr($s, 10)); } elseif (substr($ts = rtrim($s), -strlen($delimiter)) === $delimiter) { $sql .= substr($ts, 0, -strlen($delimiter)); if (!$this->connection->query($sql)) { throw new Exception($this->connection->error . ': ' . $sql); } $sql = ''; $count++; if ($this->onProgress) { call_user_func($this->onProgress, $count, isset($stat['size']) ? $size * 100 / $stat['size'] : null); } } else { $sql .= $s; } } if (rtrim($sql) !== '') { $count++; if (!$this->connection->query($sql)) { throw new Exception($this->connection->error . ': ' . $sql); } if ($this->onProgress) { call_user_func($this->onProgress, $count, isset($stat['size']) ? 100 : null); } } return $count; }
[ "public", "function", "read", "(", "$", "handle", ")", "{", "if", "(", "!", "is_resource", "(", "$", "handle", ")", "||", "get_resource_type", "(", "$", "handle", ")", "!==", "'stream'", ")", "{", "throw", "new", "Exception", "(", "'Argument must be stream...
Reads dump from logical file. @param resource @return int
[ "Reads", "dump", "from", "logical", "file", "." ]
6c9cf07092bcc4a140bef01c64d883ebfccfccfa
https://github.com/dg/MySQL-dump/blob/6c9cf07092bcc4a140bef01c64d883ebfccfccfa/src/MySQLImport.php#L56-L101
train
dg/MySQL-dump
src/MySQLDump.php
MySQLDump.save
public function save($file) { $handle = strcasecmp(substr($file, -3), '.gz') ? fopen($file, 'wb') : gzopen($file, 'wb'); if (!$handle) { throw new Exception("ERROR: Cannot write file '$file'."); } $this->write($handle); }
php
public function save($file) { $handle = strcasecmp(substr($file, -3), '.gz') ? fopen($file, 'wb') : gzopen($file, 'wb'); if (!$handle) { throw new Exception("ERROR: Cannot write file '$file'."); } $this->write($handle); }
[ "public", "function", "save", "(", "$", "file", ")", "{", "$", "handle", "=", "strcasecmp", "(", "substr", "(", "$", "file", ",", "-", "3", ")", ",", "'.gz'", ")", "?", "fopen", "(", "$", "file", ",", "'wb'", ")", ":", "gzopen", "(", "$", "file...
Saves dump to the file. @param string filename @return void
[ "Saves", "dump", "to", "the", "file", "." ]
6c9cf07092bcc4a140bef01c64d883ebfccfccfa
https://github.com/dg/MySQL-dump/blob/6c9cf07092bcc4a140bef01c64d883ebfccfccfa/src/MySQLDump.php#L52-L59
train
dg/MySQL-dump
src/MySQLDump.php
MySQLDump.write
public function write($handle = null) { if ($handle === null) { $handle = fopen('php://output', 'wb'); } elseif (!is_resource($handle) || get_resource_type($handle) !== 'stream') { throw new Exception('Argument must be stream resource.'); } $tables = $views = []; $res = $this->connection->query('SHOW FULL TABLES'); while ($row = $res->fetch_row()) { if ($row[1] === 'VIEW') { $views[] = $row[0]; } else { $tables[] = $row[0]; } } $res->close(); $tables = array_merge($tables, $views); // views must be last $this->connection->query('LOCK TABLES `' . implode('` READ, `', $tables) . '` READ'); $db = $this->connection->query('SELECT DATABASE()')->fetch_row(); fwrite($handle, '-- Created at ' . date('j.n.Y G:i') . " using David Grudl MySQL Dump Utility\n" . (isset($_SERVER['HTTP_HOST']) ? "-- Host: $_SERVER[HTTP_HOST]\n" : '') . '-- MySQL Server: ' . $this->connection->server_info . "\n" . '-- Database: ' . $db[0] . "\n" . "\n" . "SET NAMES utf8;\n" . "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\n" . "SET FOREIGN_KEY_CHECKS=0;\n" . "SET UNIQUE_CHECKS=0;\n" . "SET AUTOCOMMIT=0;\n" ); foreach ($tables as $table) { $this->dumpTable($handle, $table); } fwrite($handle, "COMMIT;\n"); fwrite($handle, "-- THE END\n"); $this->connection->query('UNLOCK TABLES'); }
php
public function write($handle = null) { if ($handle === null) { $handle = fopen('php://output', 'wb'); } elseif (!is_resource($handle) || get_resource_type($handle) !== 'stream') { throw new Exception('Argument must be stream resource.'); } $tables = $views = []; $res = $this->connection->query('SHOW FULL TABLES'); while ($row = $res->fetch_row()) { if ($row[1] === 'VIEW') { $views[] = $row[0]; } else { $tables[] = $row[0]; } } $res->close(); $tables = array_merge($tables, $views); // views must be last $this->connection->query('LOCK TABLES `' . implode('` READ, `', $tables) . '` READ'); $db = $this->connection->query('SELECT DATABASE()')->fetch_row(); fwrite($handle, '-- Created at ' . date('j.n.Y G:i') . " using David Grudl MySQL Dump Utility\n" . (isset($_SERVER['HTTP_HOST']) ? "-- Host: $_SERVER[HTTP_HOST]\n" : '') . '-- MySQL Server: ' . $this->connection->server_info . "\n" . '-- Database: ' . $db[0] . "\n" . "\n" . "SET NAMES utf8;\n" . "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\n" . "SET FOREIGN_KEY_CHECKS=0;\n" . "SET UNIQUE_CHECKS=0;\n" . "SET AUTOCOMMIT=0;\n" ); foreach ($tables as $table) { $this->dumpTable($handle, $table); } fwrite($handle, "COMMIT;\n"); fwrite($handle, "-- THE END\n"); $this->connection->query('UNLOCK TABLES'); }
[ "public", "function", "write", "(", "$", "handle", "=", "null", ")", "{", "if", "(", "$", "handle", "===", "null", ")", "{", "$", "handle", "=", "fopen", "(", "'php://output'", ",", "'wb'", ")", ";", "}", "elseif", "(", "!", "is_resource", "(", "$"...
Writes dump to logical file. @param resource @return void
[ "Writes", "dump", "to", "logical", "file", "." ]
6c9cf07092bcc4a140bef01c64d883ebfccfccfa
https://github.com/dg/MySQL-dump/blob/6c9cf07092bcc4a140bef01c64d883ebfccfccfa/src/MySQLDump.php#L67-L112
train
franzose/ClosureTable
src/Franzose/ClosureTable/Extensions/QueryBuilder.php
QueryBuilder.buildWherePosition
public function buildWherePosition($column, array $values) { if (count($values) == 1 || is_null($values[1])) { $this->where($column, '>=', $values[0]); } else { $this->whereIn($column, range($values[0], $values[1])); } return $this; }
php
public function buildWherePosition($column, array $values) { if (count($values) == 1 || is_null($values[1])) { $this->where($column, '>=', $values[0]); } else { $this->whereIn($column, range($values[0], $values[1])); } return $this; }
[ "public", "function", "buildWherePosition", "(", "$", "column", ",", "array", "$", "values", ")", "{", "if", "(", "count", "(", "$", "values", ")", "==", "1", "||", "is_null", "(", "$", "values", "[", "1", "]", ")", ")", "{", "$", "this", "->", "...
Builds "where position" query part based on given values. @param string $column @param array $values @return $this
[ "Builds", "where", "position", "query", "part", "based", "on", "given", "values", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Extensions/QueryBuilder.php#L20-L29
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/ClosureTable.php
ClosureTable.insertNode
public function insertNode($ancestorId, $descendantId) { $table = $this->getPrefixedTable(); $ancestor = $this->getAncestorColumn(); $descendant = $this->getDescendantColumn(); $depth = $this->getDepthColumn(); $query = " INSERT INTO {$table} ({$ancestor}, {$descendant}, {$depth}) SELECT tbl.{$ancestor}, {$descendantId}, tbl.{$depth}+1 FROM {$table} AS tbl WHERE tbl.{$descendant} = {$ancestorId} UNION ALL SELECT {$descendantId}, {$descendantId}, 0 "; DB::connection($this->connection)->statement($query); }
php
public function insertNode($ancestorId, $descendantId) { $table = $this->getPrefixedTable(); $ancestor = $this->getAncestorColumn(); $descendant = $this->getDescendantColumn(); $depth = $this->getDepthColumn(); $query = " INSERT INTO {$table} ({$ancestor}, {$descendant}, {$depth}) SELECT tbl.{$ancestor}, {$descendantId}, tbl.{$depth}+1 FROM {$table} AS tbl WHERE tbl.{$descendant} = {$ancestorId} UNION ALL SELECT {$descendantId}, {$descendantId}, 0 "; DB::connection($this->connection)->statement($query); }
[ "public", "function", "insertNode", "(", "$", "ancestorId", ",", "$", "descendantId", ")", "{", "$", "table", "=", "$", "this", "->", "getPrefixedTable", "(", ")", ";", "$", "ancestor", "=", "$", "this", "->", "getAncestorColumn", "(", ")", ";", "$", "...
Inserts new node into closure table. @param int $ancestorId @param int $descendantId @return void @throws \InvalidArgumentException
[ "Inserts", "new", "node", "into", "closure", "table", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/ClosureTable.php#L48-L65
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/ClosureTable.php
ClosureTable.moveNodeTo
public function moveNodeTo($ancestorId = null) { $table = $this->getPrefixedTable(); $ancestor = $this->getAncestorColumn(); $descendant = $this->getDescendantColumn(); $depth = $this->getDepthColumn(); $thisAncestorId = $this->ancestor; $thisDescendantId = $this->descendant; // Prevent constraint collision if (!is_null($ancestorId) && $thisAncestorId === $ancestorId) { return; } $this->unbindRelationships(); // Since we have already unbound the node relationships, // given null ancestor id, we have nothing else to do, // because now the node is already root. if (is_null($ancestorId)) { return; } $query = " INSERT INTO {$table} ({$ancestor}, {$descendant}, {$depth}) SELECT supertbl.{$ancestor}, subtbl.{$descendant}, supertbl.{$depth}+subtbl.{$depth}+1 FROM {$table} as supertbl CROSS JOIN {$table} as subtbl WHERE supertbl.{$descendant} = {$ancestorId} AND subtbl.{$ancestor} = {$thisDescendantId} "; DB::connection($this->connection)->statement($query); }
php
public function moveNodeTo($ancestorId = null) { $table = $this->getPrefixedTable(); $ancestor = $this->getAncestorColumn(); $descendant = $this->getDescendantColumn(); $depth = $this->getDepthColumn(); $thisAncestorId = $this->ancestor; $thisDescendantId = $this->descendant; // Prevent constraint collision if (!is_null($ancestorId) && $thisAncestorId === $ancestorId) { return; } $this->unbindRelationships(); // Since we have already unbound the node relationships, // given null ancestor id, we have nothing else to do, // because now the node is already root. if (is_null($ancestorId)) { return; } $query = " INSERT INTO {$table} ({$ancestor}, {$descendant}, {$depth}) SELECT supertbl.{$ancestor}, subtbl.{$descendant}, supertbl.{$depth}+subtbl.{$depth}+1 FROM {$table} as supertbl CROSS JOIN {$table} as subtbl WHERE supertbl.{$descendant} = {$ancestorId} AND subtbl.{$ancestor} = {$thisDescendantId} "; DB::connection($this->connection)->statement($query); }
[ "public", "function", "moveNodeTo", "(", "$", "ancestorId", "=", "null", ")", "{", "$", "table", "=", "$", "this", "->", "getPrefixedTable", "(", ")", ";", "$", "ancestor", "=", "$", "this", "->", "getAncestorColumn", "(", ")", ";", "$", "descendant", ...
Make a node a descendant of another ancestor or makes it a root node. @param int $ancestorId @return void @throws \InvalidArgumentException
[ "Make", "a", "node", "a", "descendant", "of", "another", "ancestor", "or", "makes", "it", "a", "root", "node", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/ClosureTable.php#L74-L108
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/ClosureTable.php
ClosureTable.unbindRelationships
protected function unbindRelationships() { $table = $this->getPrefixedTable(); $ancestorColumn = $this->getAncestorColumn(); $descendantColumn = $this->getDescendantColumn(); $descendant = $this->descendant; $query = " DELETE FROM {$table} WHERE {$descendantColumn} IN ( SELECT d FROM ( SELECT {$descendantColumn} as d FROM {$table} WHERE {$ancestorColumn} = {$descendant} ) as dct ) AND {$ancestorColumn} IN ( SELECT a FROM ( SELECT {$ancestorColumn} AS a FROM {$table} WHERE {$descendantColumn} = {$descendant} AND {$ancestorColumn} <> {$descendant} ) as ct ) "; DB::connection($this->connection)->delete($query); }
php
protected function unbindRelationships() { $table = $this->getPrefixedTable(); $ancestorColumn = $this->getAncestorColumn(); $descendantColumn = $this->getDescendantColumn(); $descendant = $this->descendant; $query = " DELETE FROM {$table} WHERE {$descendantColumn} IN ( SELECT d FROM ( SELECT {$descendantColumn} as d FROM {$table} WHERE {$ancestorColumn} = {$descendant} ) as dct ) AND {$ancestorColumn} IN ( SELECT a FROM ( SELECT {$ancestorColumn} AS a FROM {$table} WHERE {$descendantColumn} = {$descendant} AND {$ancestorColumn} <> {$descendant} ) as ct ) "; DB::connection($this->connection)->delete($query); }
[ "protected", "function", "unbindRelationships", "(", ")", "{", "$", "table", "=", "$", "this", "->", "getPrefixedTable", "(", ")", ";", "$", "ancestorColumn", "=", "$", "this", "->", "getAncestorColumn", "(", ")", ";", "$", "descendantColumn", "=", "$", "t...
Unbinds current relationships. @return void
[ "Unbinds", "current", "relationships", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/ClosureTable.php#L115-L140
train
franzose/ClosureTable
src/Franzose/ClosureTable/Generators/Generator.php
Generator.getStub
protected function getStub($name, $type) { if (stripos($name, '.php') === false) { $name = $name . '.php'; } return $this->filesystem->get($this->getStubsPath($type) . '/' . $name); }
php
protected function getStub($name, $type) { if (stripos($name, '.php') === false) { $name = $name . '.php'; } return $this->filesystem->get($this->getStubsPath($type) . '/' . $name); }
[ "protected", "function", "getStub", "(", "$", "name", ",", "$", "type", ")", "{", "if", "(", "stripos", "(", "$", "name", ",", "'.php'", ")", "===", "false", ")", "{", "$", "name", "=", "$", "name", ".", "'.php'", ";", "}", "return", "$", "this",...
Get a stub file by name. @param string $name @param string $type @return string
[ "Get", "a", "stub", "file", "by", "name", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Generators/Generator.php#L56-L63
train
franzose/ClosureTable
src/Franzose/ClosureTable/Generators/Generator.php
Generator.parseStub
protected function parseStub($stub, array $replacements = []) { foreach ($replacements as $key => $replacement) { $stub = str_replace('{{' . $key . '}}', $replacement, $stub); } return $stub; }
php
protected function parseStub($stub, array $replacements = []) { foreach ($replacements as $key => $replacement) { $stub = str_replace('{{' . $key . '}}', $replacement, $stub); } return $stub; }
[ "protected", "function", "parseStub", "(", "$", "stub", ",", "array", "$", "replacements", "=", "[", "]", ")", "{", "foreach", "(", "$", "replacements", "as", "$", "key", "=>", "$", "replacement", ")", "{", "$", "stub", "=", "str_replace", "(", "'{{'",...
Parses a stub file replacing tags with provided values. @param string $stub @param array $replacements @return string
[ "Parses", "a", "stub", "file", "replacing", "tags", "with", "provided", "values", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Generators/Generator.php#L72-L79
train
franzose/ClosureTable
src/Franzose/ClosureTable/Extensions/Collection.php
Collection.getChildrenOf
public function getChildrenOf($position) { if (!$this->hasChildren($position)) { return null; } $item = $this->get($position); $relation = $item->getChildrenRelationIndex(); return $item->getRelation($relation); }
php
public function getChildrenOf($position) { if (!$this->hasChildren($position)) { return null; } $item = $this->get($position); $relation = $item->getChildrenRelationIndex(); return $item->getRelation($relation); }
[ "public", "function", "getChildrenOf", "(", "$", "position", ")", "{", "if", "(", "!", "$", "this", "->", "hasChildren", "(", "$", "position", ")", ")", "{", "return", "null", ";", "}", "$", "item", "=", "$", "this", "->", "get", "(", "$", "positio...
Retrieves children relation. @param $position @return Collection|null
[ "Retrieves", "children", "relation", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Extensions/Collection.php#L20-L30
train
franzose/ClosureTable
src/Franzose/ClosureTable/Extensions/Collection.php
Collection.hasChildren
public function hasChildren($position) { $item = $this->get($position); $relation = $item->getChildrenRelationIndex(); return array_key_exists($relation, $item->getRelations()); }
php
public function hasChildren($position) { $item = $this->get($position); $relation = $item->getChildrenRelationIndex(); return array_key_exists($relation, $item->getRelations()); }
[ "public", "function", "hasChildren", "(", "$", "position", ")", "{", "$", "item", "=", "$", "this", "->", "get", "(", "$", "position", ")", ";", "$", "relation", "=", "$", "item", "->", "getChildrenRelationIndex", "(", ")", ";", "return", "array_key_exis...
Indicates whether an item has children. @param $position @return bool
[ "Indicates", "whether", "an", "item", "has", "children", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Extensions/Collection.php#L38-L44
train
franzose/ClosureTable
src/Franzose/ClosureTable/Extensions/Collection.php
Collection.makeTree
protected function makeTree(array &$items) { $result = []; $tops = []; /** * @var Entity $item */ foreach ($items as $item) { $result[$item->getKey()] = $item; } foreach ($items as $item) { $parentId = $item->{$item->getParentIdColumn()}; if (array_key_exists($parentId, $result)) { $result[$parentId]->appendRelation($item->getChildrenRelationIndex(), $item); } else { $tops[] = $item; } } return $tops; }
php
protected function makeTree(array &$items) { $result = []; $tops = []; /** * @var Entity $item */ foreach ($items as $item) { $result[$item->getKey()] = $item; } foreach ($items as $item) { $parentId = $item->{$item->getParentIdColumn()}; if (array_key_exists($parentId, $result)) { $result[$parentId]->appendRelation($item->getChildrenRelationIndex(), $item); } else { $tops[] = $item; } } return $tops; }
[ "protected", "function", "makeTree", "(", "array", "&", "$", "items", ")", "{", "$", "result", "=", "[", "]", ";", "$", "tops", "=", "[", "]", ";", "/**\n * @var Entity $item\n */", "foreach", "(", "$", "items", "as", "$", "item", ")", "{...
Performs actual tree building. @param array $items @return array
[ "Performs", "actual", "tree", "building", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Extensions/Collection.php#L64-L87
train
franzose/ClosureTable
src/Franzose/ClosureTable/Extensions/Str.php
Str.tableize
public static function tableize($name) { $name = str_replace('\\', '', $name); return (ends_with($name, 'Closure') ? snake_case($name) : snake_case(str_plural($name))); }
php
public static function tableize($name) { $name = str_replace('\\', '', $name); return (ends_with($name, 'Closure') ? snake_case($name) : snake_case(str_plural($name))); }
[ "public", "static", "function", "tableize", "(", "$", "name", ")", "{", "$", "name", "=", "str_replace", "(", "'\\\\'", ",", "''", ",", "$", "name", ")", ";", "return", "(", "ends_with", "(", "$", "name", ",", "'Closure'", ")", "?", "snake_case", "("...
Makes database table name from given class name. @param $name @return string
[ "Makes", "database", "table", "name", "from", "given", "class", "name", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Extensions/Str.php#L30-L35
train
franzose/ClosureTable
src/Franzose/ClosureTable/Generators/Model.php
Model.create
public function create(array $options) { $paths = []; $nsplaceholder = (!empty($options['namespace']) ? "namespace " . $options['namespace'] . ";" : ''); $closureInterface = $options['closure'] . 'Interface'; $qualifiedEntityName = $options['entity']; $qualifiedEntityInterfaceName = $qualifiedEntityName . 'Interface'; $qualifiedClosureName = $options['closure']; $qualifiedClosureInterfaceName = $qualifiedClosureName . 'Interface'; // First, we make entity classes $paths[] = $path = $this->getPath($qualifiedEntityName, $options['models-path']); $stub = $this->getStub('entity', 'models'); $this->filesystem->put($path, $this->parseStub($stub, [ 'namespace' => $nsplaceholder, 'entity_class' => $options['entity'], 'entity_table' => $options['entity-table'], 'closure_class' => $options['namespace'] . '\\' . $options['closure'], 'closure_class_short' => $options['closure'], 'closure_interface' => $closureInterface ])); $paths[] = $path = $this->getPath($qualifiedEntityInterfaceName, $options['models-path']); $stub = $this->getStub('entityinterface', 'models'); $this->filesystem->put($path, $this->parseStub($stub, [ 'namespace' => $nsplaceholder, 'entity_class' => $options['entity'] ])); // Second, we make closure classes $paths[] = $path = $this->getPath($qualifiedClosureName, $options['models-path']); $stub = $this->getStub('closuretable', 'models'); $this->filesystem->put($path, $this->parseStub($stub, [ 'namespace' => $nsplaceholder, 'closure_class' => $options['closure'], 'closure_table' => $options['closure-table'] ])); $paths[] = $path = $this->getPath($qualifiedClosureInterfaceName, $options['models-path']); $stub = $this->getStub('closuretableinterface', 'models'); $this->filesystem->put($path, $this->parseStub($stub, [ 'namespace' => $nsplaceholder, 'closure_class' => $options['closure'] ])); return $paths; }
php
public function create(array $options) { $paths = []; $nsplaceholder = (!empty($options['namespace']) ? "namespace " . $options['namespace'] . ";" : ''); $closureInterface = $options['closure'] . 'Interface'; $qualifiedEntityName = $options['entity']; $qualifiedEntityInterfaceName = $qualifiedEntityName . 'Interface'; $qualifiedClosureName = $options['closure']; $qualifiedClosureInterfaceName = $qualifiedClosureName . 'Interface'; // First, we make entity classes $paths[] = $path = $this->getPath($qualifiedEntityName, $options['models-path']); $stub = $this->getStub('entity', 'models'); $this->filesystem->put($path, $this->parseStub($stub, [ 'namespace' => $nsplaceholder, 'entity_class' => $options['entity'], 'entity_table' => $options['entity-table'], 'closure_class' => $options['namespace'] . '\\' . $options['closure'], 'closure_class_short' => $options['closure'], 'closure_interface' => $closureInterface ])); $paths[] = $path = $this->getPath($qualifiedEntityInterfaceName, $options['models-path']); $stub = $this->getStub('entityinterface', 'models'); $this->filesystem->put($path, $this->parseStub($stub, [ 'namespace' => $nsplaceholder, 'entity_class' => $options['entity'] ])); // Second, we make closure classes $paths[] = $path = $this->getPath($qualifiedClosureName, $options['models-path']); $stub = $this->getStub('closuretable', 'models'); $this->filesystem->put($path, $this->parseStub($stub, [ 'namespace' => $nsplaceholder, 'closure_class' => $options['closure'], 'closure_table' => $options['closure-table'] ])); $paths[] = $path = $this->getPath($qualifiedClosureInterfaceName, $options['models-path']); $stub = $this->getStub('closuretableinterface', 'models'); $this->filesystem->put($path, $this->parseStub($stub, [ 'namespace' => $nsplaceholder, 'closure_class' => $options['closure'] ])); return $paths; }
[ "public", "function", "create", "(", "array", "$", "options", ")", "{", "$", "paths", "=", "[", "]", ";", "$", "nsplaceholder", "=", "(", "!", "empty", "(", "$", "options", "[", "'namespace'", "]", ")", "?", "\"namespace \"", ".", "$", "options", "["...
Creates models and interfaces files. @param array $options @return array
[ "Creates", "models", "and", "interfaces", "files", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Generators/Model.php#L19-L72
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.setParentIdAttribute
public function setParentIdAttribute($value) { if ($this->parent_id === $value) { return; } $this->old_parent_id = $this->parent_id; $this->attributes[$this->getParentIdColumn()] = $value; }
php
public function setParentIdAttribute($value) { if ($this->parent_id === $value) { return; } $this->old_parent_id = $this->parent_id; $this->attributes[$this->getParentIdColumn()] = $value; }
[ "public", "function", "setParentIdAttribute", "(", "$", "value", ")", "{", "if", "(", "$", "this", "->", "parent_id", "===", "$", "value", ")", "{", "return", ";", "}", "$", "this", "->", "old_parent_id", "=", "$", "this", "->", "parent_id", ";", "$", ...
Sets new parent id and caches the old one. @param int $value
[ "Sets", "new", "parent", "id", "and", "caches", "the", "old", "one", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L128-L135
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.setPositionAttribute
public function setPositionAttribute($value) { if ($this->position === $value) { return; } $this->old_position = $this->position; $this->attributes[$this->getPositionColumn()] = intval($value); }
php
public function setPositionAttribute($value) { if ($this->position === $value) { return; } $this->old_position = $this->position; $this->attributes[$this->getPositionColumn()] = intval($value); }
[ "public", "function", "setPositionAttribute", "(", "$", "value", ")", "{", "if", "(", "$", "this", "->", "position", "===", "$", "value", ")", "{", "return", ";", "}", "$", "this", "->", "old_position", "=", "$", "this", "->", "position", ";", "$", "...
Sets new position and caches the old one. @param int $value
[ "Sets", "new", "position", "and", "caches", "the", "old", "one", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L172-L179
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.setRealDepthAttribute
protected function setRealDepthAttribute($value) { if ($this->real_depth === $value) { return; } $this->old_real_depth = $this->real_depth; $this->attributes[$this->getRealDepthColumn()] = intval($value); }
php
protected function setRealDepthAttribute($value) { if ($this->real_depth === $value) { return; } $this->old_real_depth = $this->real_depth; $this->attributes[$this->getRealDepthColumn()] = intval($value); }
[ "protected", "function", "setRealDepthAttribute", "(", "$", "value", ")", "{", "if", "(", "$", "this", "->", "real_depth", "===", "$", "value", ")", "{", "return", ";", "}", "$", "this", "->", "old_real_depth", "=", "$", "this", "->", "real_depth", ";", ...
Sets value of the "real depth" attribute. @param int $value
[ "Sets", "value", "of", "the", "real", "depth", "attribute", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L216-L223
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.joinClosureBy
protected function joinClosureBy($column, $withSelf = false) { $primary = $this->getQualifiedKeyName(); $closure = $this->closure->getTable(); $ancestor = $this->closure->getQualifiedAncestorColumn(); $descendant = $this->closure->getQualifiedDescendantColumn(); switch ($column) { case 'ancestor': $query = $this->join($closure, $ancestor, '=', $primary) ->where($descendant, '=', $this->getKey()); break; case 'descendant': $query = $this->join($closure, $descendant, '=', $primary) ->where($ancestor, '=', $this->getKey()); break; } $depthOperator = ($withSelf === true ? '>=' : '>'); $query->where($this->closure->getQualifiedDepthColumn(), $depthOperator, 0); return $query; }
php
protected function joinClosureBy($column, $withSelf = false) { $primary = $this->getQualifiedKeyName(); $closure = $this->closure->getTable(); $ancestor = $this->closure->getQualifiedAncestorColumn(); $descendant = $this->closure->getQualifiedDescendantColumn(); switch ($column) { case 'ancestor': $query = $this->join($closure, $ancestor, '=', $primary) ->where($descendant, '=', $this->getKey()); break; case 'descendant': $query = $this->join($closure, $descendant, '=', $primary) ->where($ancestor, '=', $this->getKey()); break; } $depthOperator = ($withSelf === true ? '>=' : '>'); $query->where($this->closure->getQualifiedDepthColumn(), $depthOperator, 0); return $query; }
[ "protected", "function", "joinClosureBy", "(", "$", "column", ",", "$", "withSelf", "=", "false", ")", "{", "$", "primary", "=", "$", "this", "->", "getQualifiedKeyName", "(", ")", ";", "$", "closure", "=", "$", "this", "->", "closure", "->", "getTable",...
Builds closure table join based on the given column. @param string $column @param bool $withSelf @return QueryBuilder
[ "Builds", "closure", "table", "join", "based", "on", "the", "given", "column", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L329-L353
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.subqueryClosureBy
protected function subqueryClosureBy($column, $withSelf = false) { $self = $this; return $this->whereIn($this->getQualifiedKeyName(), function ($qb) use ($self, $column, $withSelf) { switch ($column) { case 'ancestor': $selectedColumn = $self->closure->getAncestorColumn(); $whereColumn = $self->closure->getDescendantColumn(); break; case 'descendant': $selectedColumn = $self->closure->getDescendantColumn(); $whereColumn = $self->closure->getAncestorColumn(); break; } $depthOperator = ($withSelf === true ? '>=' : '>'); return $qb->select($selectedColumn) ->from($self->closure->getTable()) ->where($whereColumn, '=', $self->getKey()) ->where($self->closure->getDepthColumn(), $depthOperator, 0); }); }
php
protected function subqueryClosureBy($column, $withSelf = false) { $self = $this; return $this->whereIn($this->getQualifiedKeyName(), function ($qb) use ($self, $column, $withSelf) { switch ($column) { case 'ancestor': $selectedColumn = $self->closure->getAncestorColumn(); $whereColumn = $self->closure->getDescendantColumn(); break; case 'descendant': $selectedColumn = $self->closure->getDescendantColumn(); $whereColumn = $self->closure->getAncestorColumn(); break; } $depthOperator = ($withSelf === true ? '>=' : '>'); return $qb->select($selectedColumn) ->from($self->closure->getTable()) ->where($whereColumn, '=', $self->getKey()) ->where($self->closure->getDepthColumn(), $depthOperator, 0); }); }
[ "protected", "function", "subqueryClosureBy", "(", "$", "column", ",", "$", "withSelf", "=", "false", ")", "{", "$", "self", "=", "$", "this", ";", "return", "$", "this", "->", "whereIn", "(", "$", "this", "->", "getQualifiedKeyName", "(", ")", ",", "f...
Builds closure table "where in" query on the given column. @param string $column @param bool $withSelf @return QueryBuilder
[ "Builds", "closure", "table", "where", "in", "query", "on", "the", "given", "column", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L362-L386
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getAncestorsWhere
public function getAncestorsWhere($column, $operator = null, $value = null, array $columns = ['*']) { return $this->joinClosureBy('ancestor')->where($column, $operator, $value)->get($columns); }
php
public function getAncestorsWhere($column, $operator = null, $value = null, array $columns = ['*']) { return $this->joinClosureBy('ancestor')->where($column, $operator, $value)->get($columns); }
[ "public", "function", "getAncestorsWhere", "(", "$", "column", ",", "$", "operator", "=", "null", ",", "$", "value", "=", "null", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "return", "$", "this", "->", "joinClosureBy", "(", "'ancesto...
Retrieves ancestors applying given conditions. @param mixed $column @param mixed $operator @param mixed $value @param array $columns @return Collection
[ "Retrieves", "ancestors", "applying", "given", "conditions", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L419-L422
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.children
protected function children($position = null, $order = 'asc') { $query = $this->queryByParentId(); if (!is_null($position)) { if (is_array($position)) { $query->buildWherePosition($this->getPositionColumn(), $position); } else { if ($position === static::QUERY_LAST) { $query->orderBy($this->getPositionColumn(), 'desc'); } else { $query->where($this->getPositionColumn(), '=', $position); } } } if ($position !== static::QUERY_LAST) { $query->orderBy($this->getPositionColumn(), $order); } return $query; }
php
protected function children($position = null, $order = 'asc') { $query = $this->queryByParentId(); if (!is_null($position)) { if (is_array($position)) { $query->buildWherePosition($this->getPositionColumn(), $position); } else { if ($position === static::QUERY_LAST) { $query->orderBy($this->getPositionColumn(), 'desc'); } else { $query->where($this->getPositionColumn(), '=', $position); } } } if ($position !== static::QUERY_LAST) { $query->orderBy($this->getPositionColumn(), $order); } return $query; }
[ "protected", "function", "children", "(", "$", "position", "=", "null", ",", "$", "order", "=", "'asc'", ")", "{", "$", "query", "=", "$", "this", "->", "queryByParentId", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "position", ")", ")", "{...
Shorthand of the children query part. @param array|int|null $position @param string $order @return QueryBuilder
[ "Shorthand", "of", "the", "children", "query", "part", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L507-L528
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.queryByParentId
protected function queryByParentId($id = null) { $id = ($id ?: $this->getKey()); return $this->where($this->getParentIdColumn(), '=', $id); }
php
protected function queryByParentId($id = null) { $id = ($id ?: $this->getKey()); return $this->where($this->getParentIdColumn(), '=', $id); }
[ "protected", "function", "queryByParentId", "(", "$", "id", "=", "null", ")", "{", "$", "id", "=", "(", "$", "id", "?", ":", "$", "this", "->", "getKey", "(", ")", ")", ";", "return", "$", "this", "->", "where", "(", "$", "this", "->", "getParent...
Starts a query by parent identifier. @param mixed $id @return QueryBuilder
[ "Starts", "a", "query", "by", "parent", "identifier", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L536-L541
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getChildren
public function getChildren(array $columns = ['*']) { if ($this->hasChildrenRelation()) { $result = $this->getRelation($this->getChildrenRelationIndex()); } else { $result = $this->children()->get($columns); } return $result; }
php
public function getChildren(array $columns = ['*']) { if ($this->hasChildrenRelation()) { $result = $this->getRelation($this->getChildrenRelationIndex()); } else { $result = $this->children()->get($columns); } return $result; }
[ "public", "function", "getChildren", "(", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "if", "(", "$", "this", "->", "hasChildrenRelation", "(", ")", ")", "{", "$", "result", "=", "$", "this", "->", "getRelation", "(", "$", "this", "->", ...
Retrieves all children of a model. @param array $columns @return \Franzose\ClosureTable\Extensions\Collection
[ "Retrieves", "all", "children", "of", "a", "model", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L549-L558
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.countChildren
public function countChildren() { if ($this->hasChildrenRelation()) { $result = $this->getRelation($this->getChildrenRelationIndex())->count(); } else { $result = $this->queryByParentId()->count(); } return $result; }
php
public function countChildren() { if ($this->hasChildrenRelation()) { $result = $this->getRelation($this->getChildrenRelationIndex())->count(); } else { $result = $this->queryByParentId()->count(); } return $result; }
[ "public", "function", "countChildren", "(", ")", "{", "if", "(", "$", "this", "->", "hasChildrenRelation", "(", ")", ")", "{", "$", "result", "=", "$", "this", "->", "getRelation", "(", "$", "this", "->", "getChildrenRelationIndex", "(", ")", ")", "->", ...
Returns a number of model's children. @return int
[ "Returns", "a", "number", "of", "model", "s", "children", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L565-L574
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.appendRelation
public function appendRelation($relation, $value) { if (!array_key_exists($relation, $this->getRelations())) { $this->setRelation($relation, new Collection([$value])); } else { $this->getRelation($relation)->add($value); } return $this; }
php
public function appendRelation($relation, $value) { if (!array_key_exists($relation, $this->getRelations())) { $this->setRelation($relation, new Collection([$value])); } else { $this->getRelation($relation)->add($value); } return $this; }
[ "public", "function", "appendRelation", "(", "$", "relation", ",", "$", "value", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "relation", ",", "$", "this", "->", "getRelations", "(", ")", ")", ")", "{", "$", "this", "->", "setRelation", "(",...
Pushes a new item to a relation. @param $relation @param $value @return $this
[ "Pushes", "a", "new", "item", "to", "a", "relation", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L603-L612
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getChildAt
public function getChildAt($position, array $columns = ['*']) { if ($this->hasChildrenRelation()) { $result = $this->getRelation($this->getChildrenRelationIndex())->get($position); } else { $result = $this->children($position)->first($columns); } return $result; }
php
public function getChildAt($position, array $columns = ['*']) { if ($this->hasChildrenRelation()) { $result = $this->getRelation($this->getChildrenRelationIndex())->get($position); } else { $result = $this->children($position)->first($columns); } return $result; }
[ "public", "function", "getChildAt", "(", "$", "position", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "if", "(", "$", "this", "->", "hasChildrenRelation", "(", ")", ")", "{", "$", "result", "=", "$", "this", "->", "getRelation", "("...
Retrieves a child with given position. @param $position @param array $columns @return Entity
[ "Retrieves", "a", "child", "with", "given", "position", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L621-L630
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getLastChild
public function getLastChild(array $columns = ['*']) { if ($this->hasChildrenRelation()) { $result = $this->getRelation($this->getChildrenRelationIndex())->last(); } else { $result = $this->children(static::QUERY_LAST)->first($columns); } return $result; }
php
public function getLastChild(array $columns = ['*']) { if ($this->hasChildrenRelation()) { $result = $this->getRelation($this->getChildrenRelationIndex())->last(); } else { $result = $this->children(static::QUERY_LAST)->first($columns); } return $result; }
[ "public", "function", "getLastChild", "(", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "if", "(", "$", "this", "->", "hasChildrenRelation", "(", ")", ")", "{", "$", "result", "=", "$", "this", "->", "getRelation", "(", "$", "this", "->",...
Retrieves the last child. @param array $columns @return Entity
[ "Retrieves", "the", "last", "child", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L649-L658
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getChildrenRange
public function getChildrenRange($from, $to = null, array $columns = ['*']) { return $this->children([$from, $to])->get($columns); }
php
public function getChildrenRange($from, $to = null, array $columns = ['*']) { return $this->children([$from, $to])->get($columns); }
[ "public", "function", "getChildrenRange", "(", "$", "from", ",", "$", "to", "=", "null", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "return", "$", "this", "->", "children", "(", "[", "$", "from", ",", "$", "to", "]", ")", "->",...
Retrieves children within given positions range. @param int $from @param int $to @param array $columns @return Collection
[ "Retrieves", "children", "within", "given", "positions", "range", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L668-L671
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getLastChildPosition
protected function getLastChildPosition() { $lastChild = $this->getLastChild([$this->getPositionColumn()]); return (is_null($lastChild) ? 0 : $lastChild->position); }
php
protected function getLastChildPosition() { $lastChild = $this->getLastChild([$this->getPositionColumn()]); return (is_null($lastChild) ? 0 : $lastChild->position); }
[ "protected", "function", "getLastChildPosition", "(", ")", "{", "$", "lastChild", "=", "$", "this", "->", "getLastChild", "(", "[", "$", "this", "->", "getPositionColumn", "(", ")", "]", ")", ";", "return", "(", "is_null", "(", "$", "lastChild", ")", "?"...
Gets last child position. @return int
[ "Gets", "last", "child", "position", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L678-L683
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.addChild
public function addChild(EntityInterface $child, $position = null, $returnChild = false) { if ($this->exists) { if (is_null($position)) { $position = $this->getNextAfterLastPosition($this->getKey()); } $child->moveTo($position, $this); } return ($returnChild === true ? $child : $this); }
php
public function addChild(EntityInterface $child, $position = null, $returnChild = false) { if ($this->exists) { if (is_null($position)) { $position = $this->getNextAfterLastPosition($this->getKey()); } $child->moveTo($position, $this); } return ($returnChild === true ? $child : $this); }
[ "public", "function", "addChild", "(", "EntityInterface", "$", "child", ",", "$", "position", "=", "null", ",", "$", "returnChild", "=", "false", ")", "{", "if", "(", "$", "this", "->", "exists", ")", "{", "if", "(", "is_null", "(", "$", "position", ...
Appends a child to the model. @param EntityInterface $child @param int $position @param bool $returnChild @return EntityInterface
[ "Appends", "a", "child", "to", "the", "model", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L693-L704
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.addChildren
public function addChildren(array $children) { if ($this->exists) { \DB::connection($this->connection)->transaction(function () use ($children) { $lastChildPosition = $this->getLastChildPosition(); foreach ($children as $child) { if (!$child instanceof EntityInterface) { if (isset($child['id'])) { unset($child['id']); } $child = new static($child); } $this->addChild($child, $lastChildPosition); $lastChildPosition++; } }); } return $this; }
php
public function addChildren(array $children) { if ($this->exists) { \DB::connection($this->connection)->transaction(function () use ($children) { $lastChildPosition = $this->getLastChildPosition(); foreach ($children as $child) { if (!$child instanceof EntityInterface) { if (isset($child['id'])) { unset($child['id']); } $child = new static($child); } $this->addChild($child, $lastChildPosition); $lastChildPosition++; } }); } return $this; }
[ "public", "function", "addChildren", "(", "array", "$", "children", ")", "{", "if", "(", "$", "this", "->", "exists", ")", "{", "\\", "DB", "::", "connection", "(", "$", "this", "->", "connection", ")", "->", "transaction", "(", "function", "(", ")", ...
Appends a collection of children to the model. @param array $children @return $this @throws \InvalidArgumentException
[ "Appends", "a", "collection", "of", "children", "to", "the", "model", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L713-L735
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.removeChild
public function removeChild($position = null, $forceDelete = false) { if ($this->exists) { $action = ($forceDelete === true ? 'forceDelete' : 'delete'); $this->children($position)->$action(); } return $this; }
php
public function removeChild($position = null, $forceDelete = false) { if ($this->exists) { $action = ($forceDelete === true ? 'forceDelete' : 'delete'); $this->children($position)->$action(); } return $this; }
[ "public", "function", "removeChild", "(", "$", "position", "=", "null", ",", "$", "forceDelete", "=", "false", ")", "{", "if", "(", "$", "this", "->", "exists", ")", "{", "$", "action", "=", "(", "$", "forceDelete", "===", "true", "?", "'forceDelete'",...
Removes a model's child with given position. @param int $position @param bool $forceDelete @return $this
[ "Removes", "a", "model", "s", "child", "with", "given", "position", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L744-L753
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.removeChildren
public function removeChildren($from, $to = null, $forceDelete = false) { if (!is_numeric($from) || (!is_null($to) && !is_numeric($to))) { throw new \InvalidArgumentException('`from` and `to` are the position boundaries. They must be of type int.'); } if ($this->exists) { $action = ($forceDelete === true ? 'forceDelete' : 'delete'); $this->children([$from, $to])->$action(); } return $this; }
php
public function removeChildren($from, $to = null, $forceDelete = false) { if (!is_numeric($from) || (!is_null($to) && !is_numeric($to))) { throw new \InvalidArgumentException('`from` and `to` are the position boundaries. They must be of type int.'); } if ($this->exists) { $action = ($forceDelete === true ? 'forceDelete' : 'delete'); $this->children([$from, $to])->$action(); } return $this; }
[ "public", "function", "removeChildren", "(", "$", "from", ",", "$", "to", "=", "null", ",", "$", "forceDelete", "=", "false", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "from", ")", "||", "(", "!", "is_null", "(", "$", "to", ")", "&&", "!"...
Removes model's children within a range of positions. @param int $from @param int $to @param bool $forceDelete @return $this @throws \InvalidArgumentException
[ "Removes", "model", "s", "children", "within", "a", "range", "of", "positions", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L764-L777
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.siblings
protected function siblings($direction = '', $parentId = false, $order = 'asc') { $parentId = ($parentId === false ? $this->parent_id : $parentId); /** * @var QueryBuilder $query */ $query = $this->where($this->getParentIdColumn(), '=', $parentId); $column = $this->getPositionColumn(); switch ($direction) { case static::QUERY_ALL: $query->where($column, '<>', $this->position)->orderBy($column, $order); break; case static::QUERY_PREV_ALL: $query->where($column, '<', $this->position)->orderBy($column, $order); break; case static::QUERY_PREV_ONE: $query->where($column, '=', $this->position - 1); break; case static::QUERY_NEXT_ALL: $query->where($column, '>', $this->position)->orderBy($column, $order); break; case static::QUERY_NEXT_ONE: $query->where($column, '=', $this->position + 1); break; case static::QUERY_NEIGHBORS: $query->whereIn($column, [$this->position - 1, $this->position + 1]); break; case static::QUERY_LAST: $query->orderBy($column, 'desc'); break; } if (is_int($direction)) { $query->where($column, '=', $direction); } else if (is_array($direction)) { $query->buildWherePosition($this->getPositionColumn(), $direction); } return $query; }
php
protected function siblings($direction = '', $parentId = false, $order = 'asc') { $parentId = ($parentId === false ? $this->parent_id : $parentId); /** * @var QueryBuilder $query */ $query = $this->where($this->getParentIdColumn(), '=', $parentId); $column = $this->getPositionColumn(); switch ($direction) { case static::QUERY_ALL: $query->where($column, '<>', $this->position)->orderBy($column, $order); break; case static::QUERY_PREV_ALL: $query->where($column, '<', $this->position)->orderBy($column, $order); break; case static::QUERY_PREV_ONE: $query->where($column, '=', $this->position - 1); break; case static::QUERY_NEXT_ALL: $query->where($column, '>', $this->position)->orderBy($column, $order); break; case static::QUERY_NEXT_ONE: $query->where($column, '=', $this->position + 1); break; case static::QUERY_NEIGHBORS: $query->whereIn($column, [$this->position - 1, $this->position + 1]); break; case static::QUERY_LAST: $query->orderBy($column, 'desc'); break; } if (is_int($direction)) { $query->where($column, '=', $direction); } else if (is_array($direction)) { $query->buildWherePosition($this->getPositionColumn(), $direction); } return $query; }
[ "protected", "function", "siblings", "(", "$", "direction", "=", "''", ",", "$", "parentId", "=", "false", ",", "$", "order", "=", "'asc'", ")", "{", "$", "parentId", "=", "(", "$", "parentId", "===", "false", "?", "$", "this", "->", "parent_id", ":"...
Builds a part of the siblings query. @param string|int|array $direction @param int|bool $parentId @param string $order @return QueryBuilder
[ "Builds", "a", "part", "of", "the", "siblings", "query", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L787-L835
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getSiblingsRange
public function getSiblingsRange($from, $to = null, array $columns = ['*']) { return $this->siblings([$from, $to])->get($columns); }
php
public function getSiblingsRange($from, $to = null, array $columns = ['*']) { return $this->siblings([$from, $to])->get($columns); }
[ "public", "function", "getSiblingsRange", "(", "$", "from", ",", "$", "to", "=", "null", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "return", "$", "this", "->", "siblings", "(", "[", "$", "from", ",", "$", "to", "]", ")", "->",...
Retrieves siblings within given positions range. @param int $from @param int $to @param array $columns @return Collection
[ "Retrieves", "siblings", "within", "given", "positions", "range", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1005-L1008
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.addSibling
public function addSibling(EntityInterface $sibling, $position = null, $returnSibling = false) { if ($this->exists) { if (is_null($position)) { $position = $this->getNextAfterLastPosition(); } $sibling->moveTo($position, $this->parent_id); } return ($returnSibling === true ? $sibling : $this); }
php
public function addSibling(EntityInterface $sibling, $position = null, $returnSibling = false) { if ($this->exists) { if (is_null($position)) { $position = $this->getNextAfterLastPosition(); } $sibling->moveTo($position, $this->parent_id); } return ($returnSibling === true ? $sibling : $this); }
[ "public", "function", "addSibling", "(", "EntityInterface", "$", "sibling", ",", "$", "position", "=", "null", ",", "$", "returnSibling", "=", "false", ")", "{", "if", "(", "$", "this", "->", "exists", ")", "{", "if", "(", "is_null", "(", "$", "positio...
Appends a sibling within the current depth. @param EntityInterface $sibling @param int|null $position @param bool $returnSibling @return EntityInterface
[ "Appends", "a", "sibling", "within", "the", "current", "depth", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1018-L1029
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.addSiblings
public function addSiblings(array $siblings, $from = null) { if ($this->exists) { if (is_null($from)) { $from = $this->getNextAfterLastPosition(); } $parent = $this->getParent(); /** * @var Entity $sibling */ foreach ($siblings as $sibling) { $sibling->moveTo($from, $parent); $from++; } } return $this; }
php
public function addSiblings(array $siblings, $from = null) { if ($this->exists) { if (is_null($from)) { $from = $this->getNextAfterLastPosition(); } $parent = $this->getParent(); /** * @var Entity $sibling */ foreach ($siblings as $sibling) { $sibling->moveTo($from, $parent); $from++; } } return $this; }
[ "public", "function", "addSiblings", "(", "array", "$", "siblings", ",", "$", "from", "=", "null", ")", "{", "if", "(", "$", "this", "->", "exists", ")", "{", "if", "(", "is_null", "(", "$", "from", ")", ")", "{", "$", "from", "=", "$", "this", ...
Appends multiple siblings within the current depth. @param array $siblings @param int|null $from @return $this
[ "Appends", "multiple", "siblings", "within", "the", "current", "depth", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1038-L1056
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getTree
public static function getTree(array $columns = ['*']) { /** * @var Entity $instance */ $instance = new static; return $instance->orderBy($instance->getParentIdColumn())->orderBy($instance->getPositionColumn()) ->get($instance->prepareTreeQueryColumns($columns))->toTree(); }
php
public static function getTree(array $columns = ['*']) { /** * @var Entity $instance */ $instance = new static; return $instance->orderBy($instance->getParentIdColumn())->orderBy($instance->getPositionColumn()) ->get($instance->prepareTreeQueryColumns($columns))->toTree(); }
[ "public", "static", "function", "getTree", "(", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "/**\n * @var Entity $instance\n */", "$", "instance", "=", "new", "static", ";", "return", "$", "instance", "->", "orderBy", "(", "$", "in...
Retrieves entire tree. @param array $columns @return \Franzose\ClosureTable\Extensions\Collection
[ "Retrieves", "entire", "tree", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1102-L1111
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getTreeWhere
public static function getTreeWhere($column, $operator = null, $value = null, array $columns = ['*']) { /** * @var Entity $instance */ $instance = new static; $columns = $instance->prepareTreeQueryColumns($columns); return $instance->where($column, $operator, $value)->get($columns)->toTree(); }
php
public static function getTreeWhere($column, $operator = null, $value = null, array $columns = ['*']) { /** * @var Entity $instance */ $instance = new static; $columns = $instance->prepareTreeQueryColumns($columns); return $instance->where($column, $operator, $value)->get($columns)->toTree(); }
[ "public", "static", "function", "getTreeWhere", "(", "$", "column", ",", "$", "operator", "=", "null", ",", "$", "value", "=", "null", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "/**\n * @var Entity $instance\n */", "$", "i...
Retrieves tree by condition. @param mixed $column @param mixed $operator @param mixed $value @param array $columns @return \Franzose\ClosureTable\Extensions\Collection
[ "Retrieves", "tree", "by", "condition", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1122-L1131
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getTreeByQuery
public static function getTreeByQuery(EloquentBuilder $query, array $columns = ['*']) { /** * @var Entity $instance */ $instance = new static; $columns = $instance->prepareTreeQueryColumns($columns); return $query->get($columns)->toTree(); }
php
public static function getTreeByQuery(EloquentBuilder $query, array $columns = ['*']) { /** * @var Entity $instance */ $instance = new static; $columns = $instance->prepareTreeQueryColumns($columns); return $query->get($columns)->toTree(); }
[ "public", "static", "function", "getTreeByQuery", "(", "EloquentBuilder", "$", "query", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "/**\n * @var Entity $instance\n */", "$", "instance", "=", "new", "static", ";", "$", "columns", ...
Retrieves tree with any conditions using QueryBuilder @param EloquentBuilder $query @param array $columns @return \Franzose\ClosureTable\Extensions\Collection
[ "Retrieves", "tree", "with", "any", "conditions", "using", "QueryBuilder" ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1139-L1147
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.createFromArray
public static function createFromArray(array $tree, EntityInterface $parent = null) { $childrenRelationIndex = with(new static)->getChildrenRelationIndex(); $entities = []; foreach ($tree as $item) { $children = array_pull($item, $childrenRelationIndex); /** * @var Entity $entity */ $entity = new static($item); $entity->parent_id = $parent ? $parent->getKey() : null; $entity->save(); if (!is_null($children)) { $children = static::createFromArray($children, $entity); $entity->setRelation($childrenRelationIndex, $children); $entity->addChildren($children->all()); } $entities[] = $entity; } return new Collection($entities); }
php
public static function createFromArray(array $tree, EntityInterface $parent = null) { $childrenRelationIndex = with(new static)->getChildrenRelationIndex(); $entities = []; foreach ($tree as $item) { $children = array_pull($item, $childrenRelationIndex); /** * @var Entity $entity */ $entity = new static($item); $entity->parent_id = $parent ? $parent->getKey() : null; $entity->save(); if (!is_null($children)) { $children = static::createFromArray($children, $entity); $entity->setRelation($childrenRelationIndex, $children); $entity->addChildren($children->all()); } $entities[] = $entity; } return new Collection($entities); }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "tree", ",", "EntityInterface", "$", "parent", "=", "null", ")", "{", "$", "childrenRelationIndex", "=", "with", "(", "new", "static", ")", "->", "getChildrenRelationIndex", "(", ")", ";", ...
Saves models from the given attributes array. @param array $tree @param \Franzose\ClosureTable\Contracts\EntityInterface $parent @return \Franzose\ClosureTable\Extensions\Collection
[ "Saves", "models", "from", "the", "given", "attributes", "array", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1156-L1181
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getNewRealDepth
protected function getNewRealDepth($ancestor) { if (!$ancestor instanceof EntityInterface) { if (is_null($ancestor)) { return 0; } else { return static::find($ancestor)->real_depth + 1; } } else { return $ancestor->real_depth + 1; } }
php
protected function getNewRealDepth($ancestor) { if (!$ancestor instanceof EntityInterface) { if (is_null($ancestor)) { return 0; } else { return static::find($ancestor)->real_depth + 1; } } else { return $ancestor->real_depth + 1; } }
[ "protected", "function", "getNewRealDepth", "(", "$", "ancestor", ")", "{", "if", "(", "!", "$", "ancestor", "instanceof", "EntityInterface", ")", "{", "if", "(", "is_null", "(", "$", "ancestor", ")", ")", "{", "return", "0", ";", "}", "else", "{", "re...
Gets real depth of the new ancestor of the model. @param Entity|int|null $ancestor @return int
[ "Gets", "real", "depth", "of", "the", "new", "ancestor", "of", "the", "model", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1222-L1233
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.getNextAfterLastPosition
public function getNextAfterLastPosition($parentId = false) { $position = $this->getLastPosition($parentId); return $position === null ? 0 : $position + 1; }
php
public function getNextAfterLastPosition($parentId = false) { $position = $this->getLastPosition($parentId); return $position === null ? 0 : $position + 1; }
[ "public", "function", "getNextAfterLastPosition", "(", "$", "parentId", "=", "false", ")", "{", "$", "position", "=", "$", "this", "->", "getLastPosition", "(", "$", "parentId", ")", ";", "return", "$", "position", "===", "null", "?", "0", ":", "$", "pos...
Gets the next sibling position after the last one at the given ancestor. @param int|bool $parentId @return int
[ "Gets", "the", "next", "sibling", "position", "after", "the", "last", "one", "at", "the", "given", "ancestor", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1283-L1287
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.reorderSiblings
protected function reorderSiblings($parentIdChanged = false) { list($range, $action) = $this->setupReordering($parentIdChanged); $positionColumn = $this->getPositionColumn(); // As the method called twice (before moving and after moving), // first we gather "old" siblings by the old parent id value of the model. if ($parentIdChanged === true) { $query = $this->siblings(false, $this->old_parent_id); } else { $query = $this->siblings(); } if ($action) { $query->buildWherePosition($positionColumn, $range) ->where($this->getKeyName(), '<>', $this->getKey()) ->$action($positionColumn); } }
php
protected function reorderSiblings($parentIdChanged = false) { list($range, $action) = $this->setupReordering($parentIdChanged); $positionColumn = $this->getPositionColumn(); // As the method called twice (before moving and after moving), // first we gather "old" siblings by the old parent id value of the model. if ($parentIdChanged === true) { $query = $this->siblings(false, $this->old_parent_id); } else { $query = $this->siblings(); } if ($action) { $query->buildWherePosition($positionColumn, $range) ->where($this->getKeyName(), '<>', $this->getKey()) ->$action($positionColumn); } }
[ "protected", "function", "reorderSiblings", "(", "$", "parentIdChanged", "=", "false", ")", "{", "list", "(", "$", "range", ",", "$", "action", ")", "=", "$", "this", "->", "setupReordering", "(", "$", "parentIdChanged", ")", ";", "$", "positionColumn", "=...
Reorders model's siblings when one is moved to another position or ancestor. @param bool $parentIdChanged @return void
[ "Reorders", "model", "s", "siblings", "when", "one", "is", "moved", "to", "another", "position", "or", "ancestor", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1310-L1329
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.setupReordering
protected function setupReordering($parentIdChanged) { $range = $action = null; // If the model's parent was changed, firstly we decrement // positions of the 'old' next siblings of the model. if ($parentIdChanged === true) { $range = $this->old_position; $action = 'decrement'; } else { // TODO: There's probably a bug here where if you just created an entity and you set it to be // a root (parent_id = null) then it comes in here (while it should have gone in the else) // Reordering within the same ancestor if ($this->old_parent_id !== false && $this->old_parent_id == $this->parent_id) { if ($this->position > $this->old_position) { $range = [$this->old_position, $this->position]; $action = 'decrement'; } else if ($this->position < $this->old_position) { $range = [$this->position, $this->old_position]; $action = 'increment'; } } // Ancestor has changed else { $range = $this->position; $action = 'increment'; } } if (!is_array($range)) { $range = [$range, null]; } return [$range, $action]; }
php
protected function setupReordering($parentIdChanged) { $range = $action = null; // If the model's parent was changed, firstly we decrement // positions of the 'old' next siblings of the model. if ($parentIdChanged === true) { $range = $this->old_position; $action = 'decrement'; } else { // TODO: There's probably a bug here where if you just created an entity and you set it to be // a root (parent_id = null) then it comes in here (while it should have gone in the else) // Reordering within the same ancestor if ($this->old_parent_id !== false && $this->old_parent_id == $this->parent_id) { if ($this->position > $this->old_position) { $range = [$this->old_position, $this->position]; $action = 'decrement'; } else if ($this->position < $this->old_position) { $range = [$this->position, $this->old_position]; $action = 'increment'; } } // Ancestor has changed else { $range = $this->position; $action = 'increment'; } } if (!is_array($range)) { $range = [$range, null]; } return [$range, $action]; }
[ "protected", "function", "setupReordering", "(", "$", "parentIdChanged", ")", "{", "$", "range", "=", "$", "action", "=", "null", ";", "// If the model's parent was changed, firstly we decrement", "// positions of the 'old' next siblings of the model.", "if", "(", "$", "par...
Setups model's siblings reordering. Actually, the method determines siblings that will be reordered by creating range of theirs positions and determining the action that will be used in reordering ('increment' or 'decrement'). @param bool $parentIdChanged @return array
[ "Setups", "model", "s", "siblings", "reordering", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1341-L1373
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.insertNode
protected function insertNode() { $descendant = $this->getKey(); $ancestor = (isset($this->parent_id) ? $this->parent_id : $descendant); $this->closure->insertNode($ancestor, $descendant); }
php
protected function insertNode() { $descendant = $this->getKey(); $ancestor = (isset($this->parent_id) ? $this->parent_id : $descendant); $this->closure->insertNode($ancestor, $descendant); }
[ "protected", "function", "insertNode", "(", ")", "{", "$", "descendant", "=", "$", "this", "->", "getKey", "(", ")", ";", "$", "ancestor", "=", "(", "isset", "(", "$", "this", "->", "parent_id", ")", "?", "$", "this", "->", "parent_id", ":", "$", "...
Inserts new node to closure table. @return void
[ "Inserts", "new", "node", "to", "closure", "table", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1380-L1386
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.moveNode
protected function moveNode() { if ($this->exists) { if (is_null($this->closure->ancestor)) { $primaryKey = $this->getKey(); $this->closure->ancestor = $primaryKey; $this->closure->descendant = $primaryKey; $this->closure->depth = 0; } if ($this->isDirty($this->getParentIdColumn())) { $this->reorderSiblings(true); $this->closure->moveNodeTo($this->parent_id); } } }
php
protected function moveNode() { if ($this->exists) { if (is_null($this->closure->ancestor)) { $primaryKey = $this->getKey(); $this->closure->ancestor = $primaryKey; $this->closure->descendant = $primaryKey; $this->closure->depth = 0; } if ($this->isDirty($this->getParentIdColumn())) { $this->reorderSiblings(true); $this->closure->moveNodeTo($this->parent_id); } } }
[ "protected", "function", "moveNode", "(", ")", "{", "if", "(", "$", "this", "->", "exists", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "closure", "->", "ancestor", ")", ")", "{", "$", "primaryKey", "=", "$", "this", "->", "getKey", "("...
Moves node to another ancestor. @return void
[ "Moves", "node", "to", "another", "ancestor", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1393-L1408
train
franzose/ClosureTable
src/Franzose/ClosureTable/Models/Entity.php
Entity.clampPosition
protected function clampPosition() { if (!$this->isDirty($this->getPositionColumn())) { return; } $newPosition = max(0, min($this->position, $this->getNextAfterLastPosition())); $this->attributes[$this->getPositionColumn()] = $newPosition; }
php
protected function clampPosition() { if (!$this->isDirty($this->getPositionColumn())) { return; } $newPosition = max(0, min($this->position, $this->getNextAfterLastPosition())); $this->attributes[$this->getPositionColumn()] = $newPosition; }
[ "protected", "function", "clampPosition", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isDirty", "(", "$", "this", "->", "getPositionColumn", "(", ")", ")", ")", "{", "return", ";", "}", "$", "newPosition", "=", "max", "(", "0", ",", "min", "...
Clamp the position between 0 and the last position of the current parent.
[ "Clamp", "the", "position", "between", "0", "and", "the", "last", "position", "of", "the", "current", "parent", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Models/Entity.php#L1413-L1420
train
franzose/ClosureTable
src/Franzose/ClosureTable/Console/MakeCommand.php
MakeCommand.writeMigrations
protected function writeMigrations() { $files = $this->migrator->create($this->options); foreach ($files as $file) { $path = pathinfo($file, PATHINFO_FILENAME); $this->line(" <fg=green;options=bold>create</fg=green;options=bold> $path"); } $this->composer->dumpAutoloads(); }
php
protected function writeMigrations() { $files = $this->migrator->create($this->options); foreach ($files as $file) { $path = pathinfo($file, PATHINFO_FILENAME); $this->line(" <fg=green;options=bold>create</fg=green;options=bold> $path"); } $this->composer->dumpAutoloads(); }
[ "protected", "function", "writeMigrations", "(", ")", "{", "$", "files", "=", "$", "this", "->", "migrator", "->", "create", "(", "$", "this", "->", "options", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "path", "=", "...
Writes migration files to disk. @return void
[ "Writes", "migration", "files", "to", "disk", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Console/MakeCommand.php#L93-L103
train
franzose/ClosureTable
src/Franzose/ClosureTable/Console/MakeCommand.php
MakeCommand.writeModels
protected function writeModels() { $files = $this->modeler->create($this->options); foreach ($files as $file) { $path = pathinfo($file, PATHINFO_FILENAME); $this->line(" <fg=green;options=bold>create</fg=green;options=bold> $path"); } }
php
protected function writeModels() { $files = $this->modeler->create($this->options); foreach ($files as $file) { $path = pathinfo($file, PATHINFO_FILENAME); $this->line(" <fg=green;options=bold>create</fg=green;options=bold> $path"); } }
[ "protected", "function", "writeModels", "(", ")", "{", "$", "files", "=", "$", "this", "->", "modeler", "->", "create", "(", "$", "this", "->", "options", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "path", "=", "pathi...
Writes model files to disk. @return void
[ "Writes", "model", "files", "to", "disk", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Console/MakeCommand.php#L110-L118
train
franzose/ClosureTable
src/Franzose/ClosureTable/Console/MakeCommand.php
MakeCommand.getOptions
protected function getOptions() { return [ ['namespace', 'ns', InputOption::VALUE_OPTIONAL, 'Namespace for entity and its closure.'], ['entity', 'e', InputOption::VALUE_REQUIRED, 'Entity class name.'], ['entity-table', 'et', InputOption::VALUE_OPTIONAL, 'Entity table name.'], ['closure', 'c', InputOption::VALUE_OPTIONAL, 'Closure class name'], ['closure-table', 'ct', InputOption::VALUE_OPTIONAL, 'Closure table name.'], ['models-path', 'mdl', InputOption::VALUE_OPTIONAL, 'Models path.'], ['migrations-path', 'mgr', InputOption::VALUE_OPTIONAL, 'Migrations path.'], ['use-innodb', 'i', InputOption::VALUE_OPTIONAL, 'Use InnoDB tables.'], ]; }
php
protected function getOptions() { return [ ['namespace', 'ns', InputOption::VALUE_OPTIONAL, 'Namespace for entity and its closure.'], ['entity', 'e', InputOption::VALUE_REQUIRED, 'Entity class name.'], ['entity-table', 'et', InputOption::VALUE_OPTIONAL, 'Entity table name.'], ['closure', 'c', InputOption::VALUE_OPTIONAL, 'Closure class name'], ['closure-table', 'ct', InputOption::VALUE_OPTIONAL, 'Closure table name.'], ['models-path', 'mdl', InputOption::VALUE_OPTIONAL, 'Models path.'], ['migrations-path', 'mgr', InputOption::VALUE_OPTIONAL, 'Migrations path.'], ['use-innodb', 'i', InputOption::VALUE_OPTIONAL, 'Use InnoDB tables.'], ]; }
[ "protected", "function", "getOptions", "(", ")", "{", "return", "[", "[", "'namespace'", ",", "'ns'", ",", "InputOption", "::", "VALUE_OPTIONAL", ",", "'Namespace for entity and its closure.'", "]", ",", "[", "'entity'", ",", "'e'", ",", "InputOption", "::", "VA...
Gets the console command options. @return array
[ "Gets", "the", "console", "command", "options", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Console/MakeCommand.php#L125-L137
train
franzose/ClosureTable
src/Franzose/ClosureTable/Console/MakeCommand.php
MakeCommand.prepareOptions
protected function prepareOptions() { $options = $this->getOptions(); $input = []; foreach ($options as $option) { $input[] = $this->option($option[0]); } $lastnsdelim = strrpos($input[1], '\\'); $this->options[$options[0][0]] = $input[0] ?: rtrim($this->getAppNamespace(), '\\'); $this->options[$options[1][0]] = substr($input[1], $lastnsdelim); $this->options[$options[2][0]] = $input[2] ?: ExtStr::tableize($input[1]); $this->options[$options[3][0]] = $input[3] ?: $this->options[$options[1][0]] . 'Closure'; $this->options[$options[4][0]] = $input[4] ?: ExtStr::tableize($input[1] . 'Closure'); $this->options[$options[5][0]] = $input[5] ? $input[5] : './app'; $this->options[$options[6][0]] = $input[6] ? $input[6] : './database/migrations'; $this->options[$options[7][0]] = $input[7] ?: false; }
php
protected function prepareOptions() { $options = $this->getOptions(); $input = []; foreach ($options as $option) { $input[] = $this->option($option[0]); } $lastnsdelim = strrpos($input[1], '\\'); $this->options[$options[0][0]] = $input[0] ?: rtrim($this->getAppNamespace(), '\\'); $this->options[$options[1][0]] = substr($input[1], $lastnsdelim); $this->options[$options[2][0]] = $input[2] ?: ExtStr::tableize($input[1]); $this->options[$options[3][0]] = $input[3] ?: $this->options[$options[1][0]] . 'Closure'; $this->options[$options[4][0]] = $input[4] ?: ExtStr::tableize($input[1] . 'Closure'); $this->options[$options[5][0]] = $input[5] ? $input[5] : './app'; $this->options[$options[6][0]] = $input[6] ? $input[6] : './database/migrations'; $this->options[$options[7][0]] = $input[7] ?: false; }
[ "protected", "function", "prepareOptions", "(", ")", "{", "$", "options", "=", "$", "this", "->", "getOptions", "(", ")", ";", "$", "input", "=", "[", "]", ";", "foreach", "(", "$", "options", "as", "$", "option", ")", "{", "$", "input", "[", "]", ...
Prepares user input options to be passed to migrator and modeler instances. @return void
[ "Prepares", "user", "input", "options", "to", "be", "passed", "to", "migrator", "and", "modeler", "instances", "." ]
7a97e6fa0890e531e58133a8aa87488278cfe19f
https://github.com/franzose/ClosureTable/blob/7a97e6fa0890e531e58133a8aa87488278cfe19f/src/Franzose/ClosureTable/Console/MakeCommand.php#L144-L163
train
browner12/helpers
src/HelperServiceProvider.php
HelperServiceProvider.register
public function register() { //register commands $this->commands([ Commands\HelperMakeCommand::class, ]); //include the active package helpers foreach (config('helpers.package_helpers', []) as $activeHelper) { $file = __DIR__ . '/Helpers/' . $activeHelper . '.php'; if (file_exists($file)) { require_once($file); } } //load custom helpers with a mapper if (count(config('helpers.custom_helpers', []))) { foreach (config('helpers.custom_helpers', []) as $customHelper) { $file = app_path() . '/' . $this->getHelpersDirectory() . '/' . $customHelper . '.php'; if(file_exists($file)) { require_once($file); } } } //load custom helpers automatically else { //include the custom helpers foreach (glob(app_path() . '/' . $this->getHelpersDirectory() . '/*.php') as $file) { require_once($file); } } }
php
public function register() { //register commands $this->commands([ Commands\HelperMakeCommand::class, ]); //include the active package helpers foreach (config('helpers.package_helpers', []) as $activeHelper) { $file = __DIR__ . '/Helpers/' . $activeHelper . '.php'; if (file_exists($file)) { require_once($file); } } //load custom helpers with a mapper if (count(config('helpers.custom_helpers', []))) { foreach (config('helpers.custom_helpers', []) as $customHelper) { $file = app_path() . '/' . $this->getHelpersDirectory() . '/' . $customHelper . '.php'; if(file_exists($file)) { require_once($file); } } } //load custom helpers automatically else { //include the custom helpers foreach (glob(app_path() . '/' . $this->getHelpersDirectory() . '/*.php') as $file) { require_once($file); } } }
[ "public", "function", "register", "(", ")", "{", "//register commands", "$", "this", "->", "commands", "(", "[", "Commands", "\\", "HelperMakeCommand", "::", "class", ",", "]", ")", ";", "//include the active package helpers", "foreach", "(", "config", "(", "'he...
register the service provider @return void
[ "register", "the", "service", "provider" ]
482bd71d18fd463eae52eac720a06210530b02f2
https://github.com/browner12/helpers/blob/482bd71d18fd463eae52eac720a06210530b02f2/src/HelperServiceProvider.php#L12-L50
train
FriendsOfCake/crud
src/Traits/RedirectTrait.php
RedirectTrait.redirectConfig
public function redirectConfig($name = null, $config = null) { if ($name === null && $config === null) { return $this->getConfig('redirect'); } $path = sprintf('redirect.%s', $name); if ($config === null) { return $this->getConfig($path); } return $this->setConfig($path, $config); }
php
public function redirectConfig($name = null, $config = null) { if ($name === null && $config === null) { return $this->getConfig('redirect'); } $path = sprintf('redirect.%s', $name); if ($config === null) { return $this->getConfig($path); } return $this->setConfig($path, $config); }
[ "public", "function", "redirectConfig", "(", "$", "name", "=", "null", ",", "$", "config", "=", "null", ")", "{", "if", "(", "$", "name", "===", "null", "&&", "$", "config", "===", "null", ")", "{", "return", "$", "this", "->", "getConfig", "(", "'...
Change redirect configuration If both `$name` and `$config` is empty all redirection rules will be returned. If `$name` is provided and `$config` is null, the named redirection configuration is returned. If both `$name` and `$config` is provided, the configuration is changed for the named rule. $config should contain the following keys: - type : name of the reader - key : the key to read inside the reader - url : the URL to redirect to @param null|string $name Name of the redirection rule @param null|array $config Redirection configuration @return mixed
[ "Change", "redirect", "configuration" ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/RedirectTrait.php#L30-L42
train
FriendsOfCake/crud
src/Traits/RedirectTrait.php
RedirectTrait._refererRedirectUrl
protected function _refererRedirectUrl($default = null) { $controller = $this->_controller(); return $this->_redirectUrl($controller->referer($default, true)); }
php
protected function _refererRedirectUrl($default = null) { $controller = $this->_controller(); return $this->_redirectUrl($controller->referer($default, true)); }
[ "protected", "function", "_refererRedirectUrl", "(", "$", "default", "=", "null", ")", "{", "$", "controller", "=", "$", "this", "->", "_controller", "(", ")", ";", "return", "$", "this", "->", "_redirectUrl", "(", "$", "controller", "->", "referer", "(", ...
Returns the redirect_url for this request, with a fallback to the referring page @param string|null $default Default URL to use redirect_url is not found in request or data @return mixed
[ "Returns", "the", "redirect_url", "for", "this", "request", "with", "a", "fallback", "to", "the", "referring", "page" ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/RedirectTrait.php#L50-L55
train
FriendsOfCake/crud
src/Traits/RedirectTrait.php
RedirectTrait._redirectUrl
protected function _redirectUrl($default = null) { $request = $this->_request(); if (!empty($request->getData('_redirect_url'))) { return $request->getData('_redirect_url'); } if (!empty($request->getQuery('_redirect_url'))) { return $request->getQuery('_redirect_url'); } if (!empty($request->getData('redirect_url'))) { return $request->getData('redirect_url'); } if (!empty($request->getQuery('redirect_url'))) { return $request->getQuery('redirect_url'); } return $default; }
php
protected function _redirectUrl($default = null) { $request = $this->_request(); if (!empty($request->getData('_redirect_url'))) { return $request->getData('_redirect_url'); } if (!empty($request->getQuery('_redirect_url'))) { return $request->getQuery('_redirect_url'); } if (!empty($request->getData('redirect_url'))) { return $request->getData('redirect_url'); } if (!empty($request->getQuery('redirect_url'))) { return $request->getQuery('redirect_url'); } return $default; }
[ "protected", "function", "_redirectUrl", "(", "$", "default", "=", "null", ")", "{", "$", "request", "=", "$", "this", "->", "_request", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "request", "->", "getData", "(", "'_redirect_url'", ")", ")", "...
Returns the _redirect_url for this request. @param string|null $default Default URL to use if _redirect_url if not found in request or data. @return mixed
[ "Returns", "the", "_redirect_url", "for", "this", "request", "." ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/RedirectTrait.php#L63-L81
train
FriendsOfCake/crud
src/Traits/RedirectTrait.php
RedirectTrait._redirect
protected function _redirect(Subject $subject, $url = null, $status = null) { $url = $this->_redirectUrl($url); $subject->url = $url; $subject->status = $status; $event = $this->_trigger('beforeRedirect', $subject); if ($event->isStopped()) { return $this->_controller()->response; } return $this->_controller()->redirect($subject->url, $subject->status); }
php
protected function _redirect(Subject $subject, $url = null, $status = null) { $url = $this->_redirectUrl($url); $subject->url = $url; $subject->status = $status; $event = $this->_trigger('beforeRedirect', $subject); if ($event->isStopped()) { return $this->_controller()->response; } return $this->_controller()->redirect($subject->url, $subject->status); }
[ "protected", "function", "_redirect", "(", "Subject", "$", "subject", ",", "$", "url", "=", "null", ",", "$", "status", "=", "null", ")", "{", "$", "url", "=", "$", "this", "->", "_redirectUrl", "(", "$", "url", ")", ";", "$", "subject", "->", "url...
Called for all redirects inside CRUD @param \Crud\Event\Subject $subject Event subject @param string|array|null $url URL @param int|null $status Status code @return \Cake\Http\Response
[ "Called", "for", "all", "redirects", "inside", "CRUD" ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/RedirectTrait.php#L91-L104
train
FriendsOfCake/crud
src/Event/Subject.php
Subject.shouldProcess
public function shouldProcess($mode, $actions = []) { if (is_string($actions)) { $actions = [$actions]; } switch ($mode) { case 'only': return in_array($this->action, $actions); case 'not': return !in_array($this->action, $actions); default: throw new \Exception('Invalid mode'); } }
php
public function shouldProcess($mode, $actions = []) { if (is_string($actions)) { $actions = [$actions]; } switch ($mode) { case 'only': return in_array($this->action, $actions); case 'not': return !in_array($this->action, $actions); default: throw new \Exception('Invalid mode'); } }
[ "public", "function", "shouldProcess", "(", "$", "mode", ",", "$", "actions", "=", "[", "]", ")", "{", "if", "(", "is_string", "(", "$", "actions", ")", ")", "{", "$", "actions", "=", "[", "$", "actions", "]", ";", "}", "switch", "(", "$", "mode"...
Check if the called action is white listed or blacklisted depending on the mode Modes: only => only if in array (white list) not => only if NOT in array (blacklist) @param string $mode Mode @param mixed $actions Actions list @return bool @throws \Exception In case of invalid mode
[ "Check", "if", "the", "called", "action", "is", "white", "listed", "or", "blacklisted", "depending", "on", "the", "mode" ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Event/Subject.php#L93-L109
train
FriendsOfCake/crud
src/Traits/SerializeTrait.php
SerializeTrait.serialize
public function serialize($keys = null) { if ($keys === null) { return (array)$this->getConfig('serialize'); } return $this->setConfig('serialize', (array)$keys); }
php
public function serialize($keys = null) { if ($keys === null) { return (array)$this->getConfig('serialize'); } return $this->setConfig('serialize', (array)$keys); }
[ "public", "function", "serialize", "(", "$", "keys", "=", "null", ")", "{", "if", "(", "$", "keys", "===", "null", ")", "{", "return", "(", "array", ")", "$", "this", "->", "getConfig", "(", "'serialize'", ")", ";", "}", "return", "$", "this", "->"...
Change the serialize keys If `$keys` is NULL the current configuration is returned else the `$serialize` configuration is changed. @param null|array $keys Keys to serialize @return mixed
[ "Change", "the", "serialize", "keys" ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/SerializeTrait.php#L16-L23
train
FriendsOfCake/crud
src/Traits/SaveMethodTrait.php
SaveMethodTrait.saveOptions
public function saveOptions($config = null) { if ($config === null) { return $this->getConfig('saveOptions'); } return $this->setConfig('saveOptions', $config); }
php
public function saveOptions($config = null) { if ($config === null) { return $this->getConfig('saveOptions'); } return $this->setConfig('saveOptions', $config); }
[ "public", "function", "saveOptions", "(", "$", "config", "=", "null", ")", "{", "if", "(", "$", "config", "===", "null", ")", "{", "return", "$", "this", "->", "getConfig", "(", "'saveOptions'", ")", ";", "}", "return", "$", "this", "->", "setConfig", ...
Change the saveOptions configuration This is the 2nd argument passed to saveAll() if `$config` is NULL the current config is returned else the `saveOptions` is changed @param mixed $config Configuration array @return mixed
[ "Change", "the", "saveOptions", "configuration" ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/SaveMethodTrait.php#L36-L43
train
FriendsOfCake/crud
src/Error/ExceptionRenderer.php
ExceptionRenderer.validation
public function validation($error) { $url = $this->controller->request->getRequestTarget(); $status = $code = $error->getCode(); try { $this->controller->response = $this->controller->response->withStatus($status); } catch (Exception $e) { $status = 422; $this->controller->response = $this->controller->response->withStatus($status); } $sets = [ 'code' => $code, 'url' => h($url), 'message' => $error->getMessage(), 'error' => $error, 'errorCount' => $error->getValidationErrorCount(), 'errors' => $error->getValidationErrors(), '_serialize' => ['code', 'url', 'message', 'errorCount', 'errors'] ]; $this->controller->set($sets); return $this->_outputMessage('error400'); }
php
public function validation($error) { $url = $this->controller->request->getRequestTarget(); $status = $code = $error->getCode(); try { $this->controller->response = $this->controller->response->withStatus($status); } catch (Exception $e) { $status = 422; $this->controller->response = $this->controller->response->withStatus($status); } $sets = [ 'code' => $code, 'url' => h($url), 'message' => $error->getMessage(), 'error' => $error, 'errorCount' => $error->getValidationErrorCount(), 'errors' => $error->getValidationErrors(), '_serialize' => ['code', 'url', 'message', 'errorCount', 'errors'] ]; $this->controller->set($sets); return $this->_outputMessage('error400'); }
[ "public", "function", "validation", "(", "$", "error", ")", "{", "$", "url", "=", "$", "this", "->", "controller", "->", "request", "->", "getRequestTarget", "(", ")", ";", "$", "status", "=", "$", "code", "=", "$", "error", "->", "getCode", "(", ")"...
Renders validation errors and sends a 422 error code @param \Crud\Error\Exception\ValidationException $error Exception instance @return \Cake\Http\Response
[ "Renders", "validation", "errors", "and", "sends", "a", "422", "error", "code" ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Error/ExceptionRenderer.php#L24-L47
train
FriendsOfCake/crud
src/Error/ExceptionRenderer.php
ExceptionRenderer._getErrorData
protected function _getErrorData() { $data = []; $viewVars = $this->controller->viewVars; if (!empty($viewVars['_serialize'])) { foreach ($viewVars['_serialize'] as $v) { $data[$v] = $viewVars[$v]; } } if (!empty($viewVars['error']) && Configure::read('debug')) { $data['exception'] = [ 'class' => get_class($viewVars['error']), 'code' => $viewVars['error']->getCode(), 'message' => $viewVars['error']->getMessage(), ]; if (!isset($data['trace'])) { $data['trace'] = Debugger::formatTrace($viewVars['error']->getTrace(), [ 'format' => 'array', 'args' => false ]); } } return $data; }
php
protected function _getErrorData() { $data = []; $viewVars = $this->controller->viewVars; if (!empty($viewVars['_serialize'])) { foreach ($viewVars['_serialize'] as $v) { $data[$v] = $viewVars[$v]; } } if (!empty($viewVars['error']) && Configure::read('debug')) { $data['exception'] = [ 'class' => get_class($viewVars['error']), 'code' => $viewVars['error']->getCode(), 'message' => $viewVars['error']->getMessage(), ]; if (!isset($data['trace'])) { $data['trace'] = Debugger::formatTrace($viewVars['error']->getTrace(), [ 'format' => 'array', 'args' => false ]); } } return $data; }
[ "protected", "function", "_getErrorData", "(", ")", "{", "$", "data", "=", "[", "]", ";", "$", "viewVars", "=", "$", "this", "->", "controller", "->", "viewVars", ";", "if", "(", "!", "empty", "(", "$", "viewVars", "[", "'_serialize'", "]", ")", ")",...
Helper method used to generate extra debugging data into the error template @return array debugging data
[ "Helper", "method", "used", "to", "generate", "extra", "debugging", "data", "into", "the", "error", "template" ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Error/ExceptionRenderer.php#L82-L109
train
FriendsOfCake/crud
src/Error/ExceptionRenderer.php
ExceptionRenderer._getQueryLog
protected function _getQueryLog() { $queryLog = []; $sources = ConnectionManager::configured(); foreach ($sources as $source) { $logger = ConnectionManager::get($source)->getLogger(); if (method_exists($logger, 'getLogs')) { $queryLog[$source] = $logger->getLogs(); } } return $queryLog; }
php
protected function _getQueryLog() { $queryLog = []; $sources = ConnectionManager::configured(); foreach ($sources as $source) { $logger = ConnectionManager::get($source)->getLogger(); if (method_exists($logger, 'getLogs')) { $queryLog[$source] = $logger->getLogs(); } } return $queryLog; }
[ "protected", "function", "_getQueryLog", "(", ")", "{", "$", "queryLog", "=", "[", "]", ";", "$", "sources", "=", "ConnectionManager", "::", "configured", "(", ")", ";", "foreach", "(", "$", "sources", "as", "$", "source", ")", "{", "$", "logger", "=",...
Helper method to get query log. @return array Query log.
[ "Helper", "method", "to", "get", "query", "log", "." ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Error/ExceptionRenderer.php#L116-L128
train
FriendsOfCake/crud
src/Action/BaseAction.php
BaseAction.message
public function message($type, array $replacements = []) { if (empty($type)) { throw new \Exception('Missing message type'); } $crud = $this->_crud(); $config = $this->getConfig('messages.' . $type); if (empty($config)) { $config = $crud->getConfig('messages.' . $type); if (empty($config)) { throw new \Exception(sprintf('Invalid message type "%s"', $type)); } } if (is_string($config)) { $config = ['text' => $config]; } $config = Hash::merge([ 'element' => 'default', 'params' => ['class' => 'message'], 'key' => 'flash', 'type' => $this->getConfig('action') . '.' . $type, 'name' => $this->resourceName() ], $config); if (!isset($config['text'])) { throw new \Exception(sprintf('Invalid message config for "%s" no text key found', $type)); } $config['params']['original'] = ucfirst(str_replace('{name}', $config['name'], $config['text'])); $domain = $this->getConfig('messages.domain'); if (!$domain) { $domain = $crud->getConfig('messages.domain') ?: 'crud'; } $config['text'] = __d($domain, $config['params']['original']); $config['text'] = Text::insert( $config['text'], $replacements + ['name' => $config['name']], ['before' => '{', 'after' => '}'] ); $config['params']['class'] .= ' ' . $type; return $config; }
php
public function message($type, array $replacements = []) { if (empty($type)) { throw new \Exception('Missing message type'); } $crud = $this->_crud(); $config = $this->getConfig('messages.' . $type); if (empty($config)) { $config = $crud->getConfig('messages.' . $type); if (empty($config)) { throw new \Exception(sprintf('Invalid message type "%s"', $type)); } } if (is_string($config)) { $config = ['text' => $config]; } $config = Hash::merge([ 'element' => 'default', 'params' => ['class' => 'message'], 'key' => 'flash', 'type' => $this->getConfig('action') . '.' . $type, 'name' => $this->resourceName() ], $config); if (!isset($config['text'])) { throw new \Exception(sprintf('Invalid message config for "%s" no text key found', $type)); } $config['params']['original'] = ucfirst(str_replace('{name}', $config['name'], $config['text'])); $domain = $this->getConfig('messages.domain'); if (!$domain) { $domain = $crud->getConfig('messages.domain') ?: 'crud'; } $config['text'] = __d($domain, $config['params']['original']); $config['text'] = Text::insert( $config['text'], $replacements + ['name' => $config['name']], ['before' => '{', 'after' => '}'] ); $config['params']['class'] .= ' ' . $type; return $config; }
[ "public", "function", "message", "(", "$", "type", ",", "array", "$", "replacements", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "type", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Missing message type'", ")", ";", "}", "$", ...
return the config for a given message type @param string $type Message type. @param array $replacements Replacements @return array @throws \Exception for a missing or undefined message type
[ "return", "the", "config", "for", "a", "given", "message", "type" ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/BaseAction.php#L129-L179
train
FriendsOfCake/crud
src/Action/BaseAction.php
BaseAction.publishSuccess
public function publishSuccess(Event $event) { if (!isset($event->getSubject()->success)) { return false; } $this->_controller()->set('success', $event->getSubject()->success); }
php
public function publishSuccess(Event $event) { if (!isset($event->getSubject()->success)) { return false; } $this->_controller()->set('success', $event->getSubject()->success); }
[ "public", "function", "publishSuccess", "(", "Event", "$", "event", ")", "{", "if", "(", "!", "isset", "(", "$", "event", "->", "getSubject", "(", ")", "->", "success", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "_controller", "("...
Set "success" variable for view. @param \Cake\Event\Event $event Event @return bool|null
[ "Set", "success", "variable", "for", "view", "." ]
fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057
https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/BaseAction.php#L257-L264
train