repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.elementAtOrDefault
public function elementAtOrDefault($key, $default = null) { /** @var $it \Iterator|\ArrayAccess */ $it = $this->getIterator(); if ($it instanceof \ArrayAccess) return $it->offsetExists($key) ? $it->offsetGet($key) : $default; foreach ($it as $k => $v) { if ($k === $key) return $v; } return $default; }
php
public function elementAtOrDefault($key, $default = null) { /** @var $it \Iterator|\ArrayAccess */ $it = $this->getIterator(); if ($it instanceof \ArrayAccess) return $it->offsetExists($key) ? $it->offsetGet($key) : $default; foreach ($it as $k => $v) { if ($k === $key) return $v; } return $default; }
[ "public", "function", "elementAtOrDefault", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "/** @var $it \\Iterator|\\ArrayAccess */", "$", "it", "=", "$", "this", "->", "getIterator", "(", ")", ";", "if", "(", "$", "it", "instanceof", "\\", "ArrayAccess", ")", "return", "$", "it", "->", "offsetExists", "(", "$", "key", ")", "?", "$", "it", "->", "offsetGet", "(", "$", "key", ")", ":", "$", "default", ";", "foreach", "(", "$", "it", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "k", "===", "$", "key", ")", "return", "$", "v", ";", "}", "return", "$", "default", ";", "}" ]
Returns the value at a specified key in a sequence or a default value if the key is not found. <p><b>Syntax</b>: elementAtOrDefault (key [, default]) <p>If the type of source iterator implements {@link ArrayAccess}, that implementation is used to obtain the value at the specified key. Otherwise, this method obtains the specified value. @param mixed $key The key of the value to retrieve. @param mixed $default Value to return if sequence does not contain value with specified key. Default: null. @return mixed default value if the key is not found in the source sequence; otherwise, the value at the specified key in the source sequence. @package YaLinqo\Pagination
[ "Returns", "the", "value", "at", "a", "specified", "key", "in", "a", "sequence", "or", "a", "default", "value", "if", "the", "key", "is", "not", "found", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "elementAtOrDefault", "(", "key", "[", "default", "]", ")", "<p", ">", "If", "the", "type", "of", "source", "iterator", "implements", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L56-L69
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.first
public function first($predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); foreach ($this as $k => $v) { if ($predicate($v, $k)) return $v; } throw new \UnexpectedValueException(Errors::NO_MATCHES); }
php
public function first($predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); foreach ($this as $k => $v) { if ($predicate($v, $k)) return $v; } throw new \UnexpectedValueException(Errors::NO_MATCHES); }
[ "public", "function", "first", "(", "$", "predicate", "=", "null", ")", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ",", "Functions", "::", "$", "true", ")", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "return", "$", "v", ";", "}", "throw", "new", "\\", "UnexpectedValueException", "(", "Errors", "::", "NO_MATCHES", ")", ";", "}" ]
Returns the first element of a sequence. <p><b>Syntax</b>: first () <p>Returns the first element of a sequence. <p>The first method throws an exception if source contains no elements. To instead return a default value when the source sequence is empty, use the {@link firstOrDefault} method. <p><b>Syntax</b>: first (predicate {(v, k) ==> result}) <p>Returns the first element in a sequence that satisfies a specified condition. <p>The first method throws an exception if no matching element is found in source. To instead return a default value when no matching element is found, use the {@link firstOrDefault} method. @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. @throws \UnexpectedValueException If source contains no matching elements. @return mixed If predicate is null: the first element in the specified sequence. If predicate is not null: The first element in the sequence that passes the test in the specified predicate function. @package YaLinqo\Pagination
[ "Returns", "the", "first", "element", "of", "a", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "first", "()", "<p", ">", "Returns", "the", "first", "element", "of", "a", "sequence", ".", "<p", ">", "The", "first", "method", "throws", "an", "exception", "if", "source", "contains", "no", "elements", ".", "To", "instead", "return", "a", "default", "value", "when", "the", "source", "sequence", "is", "empty", "use", "the", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L84-L93
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.firstOrDefault
public function firstOrDefault($default = null, $predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); foreach ($this as $k => $v) { if ($predicate($v, $k)) return $v; } return $default; }
php
public function firstOrDefault($default = null, $predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); foreach ($this as $k => $v) { if ($predicate($v, $k)) return $v; } return $default; }
[ "public", "function", "firstOrDefault", "(", "$", "default", "=", "null", ",", "$", "predicate", "=", "null", ")", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ",", "Functions", "::", "$", "true", ")", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "return", "$", "v", ";", "}", "return", "$", "default", ";", "}" ]
Returns the first element of a sequence, or a default value if the sequence contains no elements. <p><b>Syntax</b>: firstOrDefault ([default]) <p>Returns the first element of a sequence, or a default value if the sequence contains no elements. <p><b>Syntax</b>: firstOrDefault ([default [, predicate {(v, k) ==> result}]]) <p>Returns the first element of the sequence that satisfies a condition or a default value if no such element is found. <p>If obtaining the default value is a costly operation, use {@link firstOrFallback} method to avoid overhead. @param mixed $default A default value. @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. @return mixed If predicate is null: default value if source is empty; otherwise, the first element in source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate. @package YaLinqo\Pagination
[ "Returns", "the", "first", "element", "of", "a", "sequence", "or", "a", "default", "value", "if", "the", "sequence", "contains", "no", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "firstOrDefault", "(", "[", "default", "]", ")", "<p", ">", "Returns", "the", "first", "element", "of", "a", "sequence", "or", "a", "default", "value", "if", "the", "sequence", "contains", "no", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "firstOrDefault", "(", "[", "default", "[", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", "]]", ")", "<p", ">", "Returns", "the", "first", "element", "of", "the", "sequence", "that", "satisfies", "a", "condition", "or", "a", "default", "value", "if", "no", "such", "element", "is", "found", ".", "<p", ">", "If", "obtaining", "the", "default", "value", "is", "a", "costly", "operation", "use", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L107-L116
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.firstOrFallback
public function firstOrFallback($fallback, $predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); foreach ($this as $k => $v) { if ($predicate($v, $k)) return $v; } return $fallback(); }
php
public function firstOrFallback($fallback, $predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); foreach ($this as $k => $v) { if ($predicate($v, $k)) return $v; } return $fallback(); }
[ "public", "function", "firstOrFallback", "(", "$", "fallback", ",", "$", "predicate", "=", "null", ")", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ",", "Functions", "::", "$", "true", ")", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "return", "$", "v", ";", "}", "return", "$", "fallback", "(", ")", ";", "}" ]
Returns the first element of a sequence, or the result of calling a fallback function if the sequence contains no elements. <p><b>Syntax</b>: firstOrFallback ([fallback {() ==> value}]) <p>Returns the first element of a sequence, or the result of calling a fallback function if the sequence contains no elements. <p><b>Syntax</b>: firstOrFallback ([fallback {() ==> value} [, predicate {(v, k) ==> result}]]) <p>Returns the first element of the sequence that satisfies a condition or the result of calling a fallback function if no such element is found. <p>The fallback function is not executed if a matching element is found. Use the firstOrFallback method if obtaining the default value is a costly operation to avoid overhead. Otherwise, use {@link firstOrDefault}. @param callable $fallback {() ==> value} A fallback function to return the default element. @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. @return mixed If predicate is null: the result of calling a fallback function if source is empty; otherwise, the first element in source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate. @package YaLinqo\Pagination
[ "Returns", "the", "first", "element", "of", "a", "sequence", "or", "the", "result", "of", "calling", "a", "fallback", "function", "if", "the", "sequence", "contains", "no", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "firstOrFallback", "(", "[", "fallback", "{", "()", "==", ">", "value", "}", "]", ")", "<p", ">", "Returns", "the", "first", "element", "of", "a", "sequence", "or", "the", "result", "of", "calling", "a", "fallback", "function", "if", "the", "sequence", "contains", "no", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "firstOrFallback", "(", "[", "fallback", "{", "()", "==", ">", "value", "}", "[", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", "]]", ")", "<p", ">", "Returns", "the", "first", "element", "of", "the", "sequence", "that", "satisfies", "a", "condition", "or", "the", "result", "of", "calling", "a", "fallback", "function", "if", "no", "such", "element", "is", "found", ".", "<p", ">", "The", "fallback", "function", "is", "not", "executed", "if", "a", "matching", "element", "is", "found", ".", "Use", "the", "firstOrFallback", "method", "if", "obtaining", "the", "default", "value", "is", "a", "costly", "operation", "to", "avoid", "overhead", ".", "Otherwise", "use", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L130-L139
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.lastOrDefault
public function lastOrDefault($default = null, $predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); $found = false; $value = null; foreach ($this as $k => $v) { if ($predicate($v, $k)) { $found = true; $value = $v; } } return $found ? $value : $default; }
php
public function lastOrDefault($default = null, $predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); $found = false; $value = null; foreach ($this as $k => $v) { if ($predicate($v, $k)) { $found = true; $value = $v; } } return $found ? $value : $default; }
[ "public", "function", "lastOrDefault", "(", "$", "default", "=", "null", ",", "$", "predicate", "=", "null", ")", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ",", "Functions", "::", "$", "true", ")", ";", "$", "found", "=", "false", ";", "$", "value", "=", "null", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "{", "$", "found", "=", "true", ";", "$", "value", "=", "$", "v", ";", "}", "}", "return", "$", "found", "?", "$", "value", ":", "$", "default", ";", "}" ]
Returns the last element of a sequence, or a default value if the sequence contains no elements. <p><b>Syntax</b>: lastOrDefault ([default]) <p>Returns the last element of a sequence, or a default value if the sequence contains no elements. <p><b>Syntax</b>: lastOrDefault ([default [, predicate {(v, k) ==> result}]]) <p>Returns the last element of the sequence that satisfies a condition or a default value if no such element is found. <p>If obtaining the default value is a costly operation, use {@link lastOrFallback} method to avoid overhead. @param mixed $default A default value. @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. @return mixed If predicate is null: default value if source is empty; otherwise, the last element in source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the last element in source that passes the test specified by predicate. @package YaLinqo\Pagination
[ "Returns", "the", "last", "element", "of", "a", "sequence", "or", "a", "default", "value", "if", "the", "sequence", "contains", "no", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "lastOrDefault", "(", "[", "default", "]", ")", "<p", ">", "Returns", "the", "last", "element", "of", "a", "sequence", "or", "a", "default", "value", "if", "the", "sequence", "contains", "no", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "lastOrDefault", "(", "[", "default", "[", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", "]]", ")", "<p", ">", "Returns", "the", "last", "element", "of", "the", "sequence", "that", "satisfies", "a", "condition", "or", "a", "default", "value", "if", "no", "such", "element", "is", "found", ".", "<p", ">", "If", "obtaining", "the", "default", "value", "is", "a", "costly", "operation", "use", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L183-L196
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.singleOrDefault
public function singleOrDefault($default = null, $predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); $found = false; $value = null; foreach ($this as $k => $v) { if ($predicate($v, $k)) { if ($found) throw new \UnexpectedValueException(Errors::MANY_MATCHES); $found = true; $value = $v; } } return $found ? $value : $default; }
php
public function singleOrDefault($default = null, $predicate = null) { $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); $found = false; $value = null; foreach ($this as $k => $v) { if ($predicate($v, $k)) { if ($found) throw new \UnexpectedValueException(Errors::MANY_MATCHES); $found = true; $value = $v; } } return $found ? $value : $default; }
[ "public", "function", "singleOrDefault", "(", "$", "default", "=", "null", ",", "$", "predicate", "=", "null", ")", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ",", "Functions", "::", "$", "true", ")", ";", "$", "found", "=", "false", ";", "$", "value", "=", "null", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "{", "if", "(", "$", "found", ")", "throw", "new", "\\", "UnexpectedValueException", "(", "Errors", "::", "MANY_MATCHES", ")", ";", "$", "found", "=", "true", ";", "$", "value", "=", "$", "v", ";", "}", "}", "return", "$", "found", "?", "$", "value", ":", "$", "default", ";", "}" ]
Returns the only element of a sequence, or a default value if the sequence contains no elements. <p><b>Syntax</b>: singleOrDefault ([default]) <p>Returns the only element of a sequence, or a default value if the sequence contains no elements. <p><b>Syntax</b>: singleOrDefault ([default [, predicate {(v, k) ==> result}]]) <p>Returns the only element of the sequence that satisfies a condition or a default value if no such element is found. <p>If obtaining the default value is a costly operation, use {@link singleOrFallback} method to avoid overhead. @param mixed $default A default value. @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. @throws \UnexpectedValueException If source contains more than one matching element. @return mixed If predicate is null: default value if source is empty; otherwise, the single element of the source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the single element of the source that passes the test specified by predicate. @package YaLinqo\Pagination
[ "Returns", "the", "only", "element", "of", "a", "sequence", "or", "a", "default", "value", "if", "the", "sequence", "contains", "no", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "singleOrDefault", "(", "[", "default", "]", ")", "<p", ">", "Returns", "the", "only", "element", "of", "a", "sequence", "or", "a", "default", "value", "if", "the", "sequence", "contains", "no", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "singleOrDefault", "(", "[", "default", "[", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", "]]", ")", "<p", ">", "Returns", "the", "only", "element", "of", "the", "sequence", "that", "satisfies", "a", "condition", "or", "a", "default", "value", "if", "no", "such", "element", "is", "found", ".", "<p", ">", "If", "obtaining", "the", "default", "value", "is", "a", "costly", "operation", "use", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L270-L285
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.indexOf
public function indexOf($value) { $array = $this->tryGetArrayCopy(); if ($array !== null) return array_search($value, $array, true); else { foreach ($this as $k => $v) { if ($v === $value) return $k; } return false; } }
php
public function indexOf($value) { $array = $this->tryGetArrayCopy(); if ($array !== null) return array_search($value, $array, true); else { foreach ($this as $k => $v) { if ($v === $value) return $k; } return false; } }
[ "public", "function", "indexOf", "(", "$", "value", ")", "{", "$", "array", "=", "$", "this", "->", "tryGetArrayCopy", "(", ")", ";", "if", "(", "$", "array", "!==", "null", ")", "return", "array_search", "(", "$", "value", ",", "$", "array", ",", "true", ")", ";", "else", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "v", "===", "$", "value", ")", "return", "$", "k", ";", "}", "return", "false", ";", "}", "}" ]
Searches for the specified value and returns the key of the first occurrence. <p><b>Syntax</b>: indexOf (value) <p>To search for the zero-based index of the first occurence, call {@link toValues} method first. @param mixed $value The value to locate in the sequence. @return mixed The key of the first occurrence of value, if found; otherwise, false. @package YaLinqo\Pagination
[ "Searches", "for", "the", "specified", "value", "and", "returns", "the", "key", "of", "the", "first", "occurrence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "indexOf", "(", "value", ")", "<p", ">", "To", "search", "for", "the", "zero", "-", "based", "index", "of", "the", "first", "occurence", "call", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L325-L337
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.lastIndexOf
public function lastIndexOf($value) { $key = null; foreach ($this as $k => $v) { if ($v === $value) $key = $k; } return $key; // not -1 }
php
public function lastIndexOf($value) { $key = null; foreach ($this as $k => $v) { if ($v === $value) $key = $k; } return $key; // not -1 }
[ "public", "function", "lastIndexOf", "(", "$", "value", ")", "{", "$", "key", "=", "null", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "v", "===", "$", "value", ")", "$", "key", "=", "$", "k", ";", "}", "return", "$", "key", ";", "// not -1", "}" ]
Searches for the specified value and returns the key of the last occurrence. <p><b>Syntax</b>: lastIndexOf (value) <p>To search for the zero-based index of the last occurence, call {@link toValues} method first. @param mixed $value The value to locate in the sequence. @return mixed The key of the last occurrence of value, if found; otherwise, null. @package YaLinqo\Pagination
[ "Searches", "for", "the", "specified", "value", "and", "returns", "the", "key", "of", "the", "last", "occurrence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "lastIndexOf", "(", "value", ")", "<p", ">", "To", "search", "for", "the", "zero", "-", "based", "index", "of", "the", "last", "occurence", "call", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L347-L355
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.findIndex
public function findIndex($predicate) { $predicate = Utils::createLambda($predicate, 'v,k'); foreach ($this as $k => $v) { if ($predicate($v, $k)) return $k; } return null; // not -1 }
php
public function findIndex($predicate) { $predicate = Utils::createLambda($predicate, 'v,k'); foreach ($this as $k => $v) { if ($predicate($v, $k)) return $k; } return null; // not -1 }
[ "public", "function", "findIndex", "(", "$", "predicate", ")", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ")", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "return", "$", "k", ";", "}", "return", "null", ";", "// not -1", "}" ]
Searches for an element that matches the conditions defined by the specified predicate, and returns the key of the first occurrence. <p><b>Syntax</b>: findIndex (predicate {(v, k) ==> result}) <p>To search for the zero-based index of the first occurence, call {@link toValues} method first. @param callable $predicate {(v, k) ==> result} A function that defines the conditions of the element to search for. @return mixed The key of the first occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null. @package YaLinqo\Pagination
[ "Searches", "for", "an", "element", "that", "matches", "the", "conditions", "defined", "by", "the", "specified", "predicate", "and", "returns", "the", "key", "of", "the", "first", "occurrence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "findIndex", "(", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", ")", "<p", ">", "To", "search", "for", "the", "zero", "-", "based", "index", "of", "the", "first", "occurence", "call", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L365-L374
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.findLastIndex
public function findLastIndex($predicate) { $predicate = Utils::createLambda($predicate, 'v,k'); $key = null; foreach ($this as $k => $v) { if ($predicate($v, $k)) $key = $k; } return $key; // not -1 }
php
public function findLastIndex($predicate) { $predicate = Utils::createLambda($predicate, 'v,k'); $key = null; foreach ($this as $k => $v) { if ($predicate($v, $k)) $key = $k; } return $key; // not -1 }
[ "public", "function", "findLastIndex", "(", "$", "predicate", ")", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ")", ";", "$", "key", "=", "null", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "$", "key", "=", "$", "k", ";", "}", "return", "$", "key", ";", "// not -1", "}" ]
Searches for an element that matches the conditions defined by the specified predicate, and returns the key of the last occurrence. <p><b>Syntax</b>: findLastIndex (predicate {(v, k) ==> result}) <p>To search for the zero-based index of the last occurence, call {@link toValues} method first. @param callable $predicate {(v, k) ==> result} A function that defines the conditions of the element to search for. @return mixed The key of the last occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null. @package YaLinqo\Pagination
[ "Searches", "for", "an", "element", "that", "matches", "the", "conditions", "defined", "by", "the", "specified", "predicate", "and", "returns", "the", "key", "of", "the", "last", "occurrence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "findLastIndex", "(", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", ")", "<p", ">", "To", "search", "for", "the", "zero", "-", "based", "index", "of", "the", "last", "occurence", "call", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L384-L394
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.skip
public function skip(int $count) { return new self(function() use ($count) { $it = $this->getIterator(); $it->rewind(); for ($i = 0; $i < $count && $it->valid(); ++$i) $it->next(); while ($it->valid()) { yield $it->key() => $it->current(); $it->next(); } }); }
php
public function skip(int $count) { return new self(function() use ($count) { $it = $this->getIterator(); $it->rewind(); for ($i = 0; $i < $count && $it->valid(); ++$i) $it->next(); while ($it->valid()) { yield $it->key() => $it->current(); $it->next(); } }); }
[ "public", "function", "skip", "(", "int", "$", "count", ")", "{", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "count", ")", "{", "$", "it", "=", "$", "this", "->", "getIterator", "(", ")", ";", "$", "it", "->", "rewind", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", "&&", "$", "it", "->", "valid", "(", ")", ";", "++", "$", "i", ")", "$", "it", "->", "next", "(", ")", ";", "while", "(", "$", "it", "->", "valid", "(", ")", ")", "{", "yield", "$", "it", "->", "key", "(", ")", "=>", "$", "it", "->", "current", "(", ")", ";", "$", "it", "->", "next", "(", ")", ";", "}", "}", ")", ";", "}" ]
Bypasses a specified number of elements in a sequence and then returns the remaining elements. <p><b>Syntax</b>: skip (count) <p>If source contains fewer than count elements, an empty sequence is returned. If count is less than or equal to zero, all elements of source are yielded. <p>The {@link take} and skip methods are functional complements. Given a sequence coll and an integer n, concatenating the results of coll->take(n) and coll->skip(n) yields the same sequence as coll. @param int $count The number of elements to skip before returning the remaining elements. @return Enumerable A sequence that contains the elements that occur after the specified index in the input sequence. @package YaLinqo\Pagination
[ "Bypasses", "a", "specified", "number", "of", "elements", "in", "a", "sequence", "and", "then", "returns", "the", "remaining", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "skip", "(", "count", ")", "<p", ">", "If", "source", "contains", "fewer", "than", "count", "elements", "an", "empty", "sequence", "is", "returned", ".", "If", "count", "is", "less", "than", "or", "equal", "to", "zero", "all", "elements", "of", "source", "are", "yielded", ".", "<p", ">", "The", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L405-L417
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.skipWhile
public function skipWhile($predicate) { $predicate = Utils::createLambda($predicate, 'v,k'); return new self(function() use ($predicate) { $yielding = false; foreach ($this as $k => $v) { if (!$yielding && !$predicate($v, $k)) $yielding = true; if ($yielding) yield $k => $v; } }); }
php
public function skipWhile($predicate) { $predicate = Utils::createLambda($predicate, 'v,k'); return new self(function() use ($predicate) { $yielding = false; foreach ($this as $k => $v) { if (!$yielding && !$predicate($v, $k)) $yielding = true; if ($yielding) yield $k => $v; } }); }
[ "public", "function", "skipWhile", "(", "$", "predicate", ")", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "predicate", ")", "{", "$", "yielding", "=", "false", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "!", "$", "yielding", "&&", "!", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "$", "yielding", "=", "true", ";", "if", "(", "$", "yielding", ")", "yield", "$", "k", "=>", "$", "v", ";", "}", "}", ")", ";", "}" ]
Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements. <p><b>Syntax</b>: skipWhile (predicate {(v, k) ==> result}) <p>This method tests each element of source by using predicate and skips the element if the result is true. After the predicate function returns false for an element, that element and the remaining elements in source are yielded and there are no more invocations of predicate. If predicate returns true for all elements in the sequence, an empty sequence is returned. <p>The {@link takeWhile} and skipWhile methods are functional complements. Given a sequence coll and a pure function p, concatenating the results of coll->takeWhile(p) and coll->skipWhile(p) yields the same sequence as coll. @param callable $predicate {(v, k) ==> result} A function to test each element for a condition. @return Enumerable A sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate. @package YaLinqo\Pagination
[ "Bypasses", "elements", "in", "a", "sequence", "as", "long", "as", "a", "specified", "condition", "is", "true", "and", "then", "returns", "the", "remaining", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "skipWhile", "(", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", ")", "<p", ">", "This", "method", "tests", "each", "element", "of", "source", "by", "using", "predicate", "and", "skips", "the", "element", "if", "the", "result", "is", "true", ".", "After", "the", "predicate", "function", "returns", "false", "for", "an", "element", "that", "element", "and", "the", "remaining", "elements", "in", "source", "are", "yielded", "and", "there", "are", "no", "more", "invocations", "of", "predicate", ".", "If", "predicate", "returns", "true", "for", "all", "elements", "in", "the", "sequence", "an", "empty", "sequence", "is", "returned", ".", "<p", ">", "The", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L428-L441
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.take
public function take(int $count) { if ($count <= 0) return new self(new \EmptyIterator, false); return new self(function() use ($count) { foreach ($this as $k => $v) { yield $k => $v; if (--$count == 0) break; } }); }
php
public function take(int $count) { if ($count <= 0) return new self(new \EmptyIterator, false); return new self(function() use ($count) { foreach ($this as $k => $v) { yield $k => $v; if (--$count == 0) break; } }); }
[ "public", "function", "take", "(", "int", "$", "count", ")", "{", "if", "(", "$", "count", "<=", "0", ")", "return", "new", "self", "(", "new", "\\", "EmptyIterator", ",", "false", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "count", ")", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "yield", "$", "k", "=>", "$", "v", ";", "if", "(", "--", "$", "count", "==", "0", ")", "break", ";", "}", "}", ")", ";", "}" ]
Returns a specified number of contiguous elements from the start of a sequence. <p><b>Syntax</b>: take (count) <p>Take enumerates source and yields elements until count elements have been yielded or source contains no more elements. If count is less than or equal to zero, source is not enumerated and an empty sequence is returned. <p>The take and {@link skip} methods are functional complements. Given a sequence coll and an integer n, concatenating the results of coll->take(n) and coll->skip(n) yields the same sequence as coll. @param int $count The number of elements to return. @return Enumerable A sequence that contains the specified number of elements from the start of the input sequence. @package YaLinqo\Pagination
[ "Returns", "a", "specified", "number", "of", "contiguous", "elements", "from", "the", "start", "of", "a", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "take", "(", "count", ")", "<p", ">", "Take", "enumerates", "source", "and", "yields", "elements", "until", "count", "elements", "have", "been", "yielded", "or", "source", "contains", "no", "more", "elements", ".", "If", "count", "is", "less", "than", "or", "equal", "to", "zero", "source", "is", "not", "enumerated", "and", "an", "empty", "sequence", "is", "returned", ".", "<p", ">", "The", "take", "and", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L452-L464
Athari/YaLinqo
YaLinqo/EnumerablePagination.php
EnumerablePagination.takeWhile
public function takeWhile($predicate) { $predicate = Utils::createLambda($predicate, 'v,k'); return new self(function() use ($predicate) { foreach ($this as $k => $v) { if (!$predicate($v, $k)) break; yield $k => $v; } }); }
php
public function takeWhile($predicate) { $predicate = Utils::createLambda($predicate, 'v,k'); return new self(function() use ($predicate) { foreach ($this as $k => $v) { if (!$predicate($v, $k)) break; yield $k => $v; } }); }
[ "public", "function", "takeWhile", "(", "$", "predicate", ")", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "predicate", ")", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "!", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "break", ";", "yield", "$", "k", "=>", "$", "v", ";", "}", "}", ")", ";", "}" ]
Returns elements from a sequence as long as a specified condition is true. <p><b>Syntax</b>: takeWhile (predicate {(v, k) ==> result}) <p>The takeWhile method tests each element of source by using predicate and yields the element if the result is true. Enumeration stops when the predicate function returns false for an element or when source contains no more elements. <p>The takeWhile and {@link skipWhile} methods are functional complements. Given a sequence coll and a pure function p, concatenating the results of coll->takeWhile(p) and coll->skipWhile(p) yields the same sequence as coll. @param callable $predicate {(v, k) ==> result} A function to test each element for a condition. @return Enumerable A sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes. @package YaLinqo\Pagination
[ "Returns", "elements", "from", "a", "sequence", "as", "long", "as", "a", "specified", "condition", "is", "true", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "takeWhile", "(", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", ")", "<p", ">", "The", "takeWhile", "method", "tests", "each", "element", "of", "source", "by", "using", "predicate", "and", "yields", "the", "element", "if", "the", "result", "is", "true", ".", "Enumeration", "stops", "when", "the", "predicate", "function", "returns", "false", "for", "an", "element", "or", "when", "source", "contains", "no", "more", "elements", ".", "<p", ">", "The", "takeWhile", "and", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerablePagination.php#L475-L486
Athari/YaLinqo
YaLinqo/Utils.php
Utils.createLambda
public static function createLambda($closure, string $closureArgs, $default = null) { if ($closure === null) { if ($default === null) throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL); return $default; } if ($closure instanceof \Closure) return $closure; if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs))) return $function; if (is_callable($closure)) return $closure; throw new \InvalidArgumentException(self::ERROR_CLOSURE_NOT_CALLABLE); }
php
public static function createLambda($closure, string $closureArgs, $default = null) { if ($closure === null) { if ($default === null) throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL); return $default; } if ($closure instanceof \Closure) return $closure; if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs))) return $function; if (is_callable($closure)) return $closure; throw new \InvalidArgumentException(self::ERROR_CLOSURE_NOT_CALLABLE); }
[ "public", "static", "function", "createLambda", "(", "$", "closure", ",", "string", "$", "closureArgs", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "closure", "===", "null", ")", "{", "if", "(", "$", "default", "===", "null", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "self", "::", "ERROR_CLOSURE_NULL", ")", ";", "return", "$", "default", ";", "}", "if", "(", "$", "closure", "instanceof", "\\", "Closure", ")", "return", "$", "closure", ";", "if", "(", "is_string", "(", "$", "closure", ")", "&&", "(", "$", "function", "=", "self", "::", "createLambdaFromString", "(", "$", "closure", ",", "$", "closureArgs", ")", ")", ")", "return", "$", "function", ";", "if", "(", "is_callable", "(", "$", "closure", ")", ")", "return", "$", "closure", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "self", "::", "ERROR_CLOSURE_NOT_CALLABLE", ")", ";", "}" ]
Convert string lambda to callable function. If callable is passed, return as is. @param callable|null $closure @param string $closureArgs @param \Closure|callable|null $default @throws \InvalidArgumentException Both closure and default are null. @throws \InvalidArgumentException Incorrect lambda syntax. @return callable|null
[ "Convert", "string", "lambda", "to", "callable", "function", ".", "If", "callable", "is", "passed", "return", "as", "is", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Utils.php#L56-L70
Athari/YaLinqo
YaLinqo/Utils.php
Utils.createComparer
public static function createComparer($closure, $sortOrder, &$isReversed) { if ($closure === null) { $isReversed = false; return $sortOrder === SORT_DESC ? Functions::$compareStrictReversed : Functions::$compareStrict; } elseif (is_int($closure)) { switch ($closure) { case SORT_REGULAR: return Functions::$compareStrict; case SORT_NUMERIC: $isReversed = false; return $sortOrder === SORT_DESC ? Functions::$compareIntReversed : Functions::$compareInt; case SORT_STRING: return 'strcmp'; case SORT_STRING | SORT_FLAG_CASE: return 'strcasecmp'; case SORT_LOCALE_STRING: return 'strcoll'; case SORT_NATURAL: return 'strnatcmp'; case SORT_NATURAL | SORT_FLAG_CASE: return 'strnatcasecmp'; default: throw new \InvalidArgumentException("Unexpected sort flag: {$closure}."); } } return self::createLambda($closure, 'a,b'); }
php
public static function createComparer($closure, $sortOrder, &$isReversed) { if ($closure === null) { $isReversed = false; return $sortOrder === SORT_DESC ? Functions::$compareStrictReversed : Functions::$compareStrict; } elseif (is_int($closure)) { switch ($closure) { case SORT_REGULAR: return Functions::$compareStrict; case SORT_NUMERIC: $isReversed = false; return $sortOrder === SORT_DESC ? Functions::$compareIntReversed : Functions::$compareInt; case SORT_STRING: return 'strcmp'; case SORT_STRING | SORT_FLAG_CASE: return 'strcasecmp'; case SORT_LOCALE_STRING: return 'strcoll'; case SORT_NATURAL: return 'strnatcmp'; case SORT_NATURAL | SORT_FLAG_CASE: return 'strnatcasecmp'; default: throw new \InvalidArgumentException("Unexpected sort flag: {$closure}."); } } return self::createLambda($closure, 'a,b'); }
[ "public", "static", "function", "createComparer", "(", "$", "closure", ",", "$", "sortOrder", ",", "&", "$", "isReversed", ")", "{", "if", "(", "$", "closure", "===", "null", ")", "{", "$", "isReversed", "=", "false", ";", "return", "$", "sortOrder", "===", "SORT_DESC", "?", "Functions", "::", "$", "compareStrictReversed", ":", "Functions", "::", "$", "compareStrict", ";", "}", "elseif", "(", "is_int", "(", "$", "closure", ")", ")", "{", "switch", "(", "$", "closure", ")", "{", "case", "SORT_REGULAR", ":", "return", "Functions", "::", "$", "compareStrict", ";", "case", "SORT_NUMERIC", ":", "$", "isReversed", "=", "false", ";", "return", "$", "sortOrder", "===", "SORT_DESC", "?", "Functions", "::", "$", "compareIntReversed", ":", "Functions", "::", "$", "compareInt", ";", "case", "SORT_STRING", ":", "return", "'strcmp'", ";", "case", "SORT_STRING", "|", "SORT_FLAG_CASE", ":", "return", "'strcasecmp'", ";", "case", "SORT_LOCALE_STRING", ":", "return", "'strcoll'", ";", "case", "SORT_NATURAL", ":", "return", "'strnatcmp'", ";", "case", "SORT_NATURAL", "|", "SORT_FLAG_CASE", ":", "return", "'strnatcasecmp'", ";", "default", ":", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Unexpected sort flag: {$closure}.\"", ")", ";", "}", "}", "return", "self", "::", "createLambda", "(", "$", "closure", ",", "'a,b'", ")", ";", "}" ]
Convert string lambda or SORT_ flags to callable function. Sets isReversed to false if descending is reversed. @param callable|int|null $closure @param int $sortOrder @param bool $isReversed @return callable|string|null @throws \InvalidArgumentException Incorrect lambda syntax. @throws \InvalidArgumentException Incorrect SORT_ flags.
[ "Convert", "string", "lambda", "or", "SORT_", "flags", "to", "callable", "function", ".", "Sets", "isReversed", "to", "false", "if", "descending", "is", "reversed", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Utils.php#L81-L109
Athari/YaLinqo
YaLinqo/Utils.php
Utils.lambdaToSortFlagsAndOrder
public static function lambdaToSortFlagsAndOrder($closure, &$sortOrder) { if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC) $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC; if (is_int($closure)) return $closure; elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure])) return self::$compareFunctionToSortFlags[$closure]; else return null; }
php
public static function lambdaToSortFlagsAndOrder($closure, &$sortOrder) { if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC) $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC; if (is_int($closure)) return $closure; elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure])) return self::$compareFunctionToSortFlags[$closure]; else return null; }
[ "public", "static", "function", "lambdaToSortFlagsAndOrder", "(", "$", "closure", ",", "&", "$", "sortOrder", ")", "{", "if", "(", "$", "sortOrder", "!==", "SORT_ASC", "&&", "$", "sortOrder", "!==", "SORT_DESC", ")", "$", "sortOrder", "=", "$", "sortOrder", "?", "SORT_DESC", ":", "SORT_ASC", ";", "if", "(", "is_int", "(", "$", "closure", ")", ")", "return", "$", "closure", ";", "elseif", "(", "(", "$", "closure", "===", "null", "||", "is_string", "(", "$", "closure", ")", ")", "&&", "isset", "(", "self", "::", "$", "compareFunctionToSortFlags", "[", "$", "closure", "]", ")", ")", "return", "self", "::", "$", "compareFunctionToSortFlags", "[", "$", "closure", "]", ";", "else", "return", "null", ";", "}" ]
Convert string lambda to SORT_ flags. Convert sortOrder from bool to SORT_ order. @param callable|string|int|null $closure @param int|bool $sortOrder @return callable|string|int|null
[ "Convert", "string", "lambda", "to", "SORT_", "flags", ".", "Convert", "sortOrder", "from", "bool", "to", "SORT_", "order", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Utils.php#L117-L127
Athari/YaLinqo
YaLinqo/Utils.php
Utils.createLambdaFromString
private static function createLambdaFromString(string $closure, string $closureArgs) { $posDollar = strpos($closure, '$'); if ($posDollar !== false) { if (isset(self::$lambdaCache[$closure][$closureArgs])) return self::$lambdaCache[$closure][$closureArgs]; $posArrow = strpos($closure, '==>', $posDollar); if ($posArrow !== false) { $args = trim(substr($closure, 0, $posArrow), "() \r\n\t"); $code = substr($closure, $posArrow + 3); } else { $args = '$' . str_replace(',', '=null,$', $closureArgs) . '=null'; $code = $closure; } $code = trim($code, " \r\n\t"); if (strlen($code) > 0 && $code[0] != '{') $code = "return {$code};"; $fun = @create_function($args, $code); // @codeCoverageIgnoreStart if (!$fun) throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA); // @codeCoverageIgnoreEnd self::$lambdaCache[$closure][$closureArgs] = $fun; return $fun; } return null; }
php
private static function createLambdaFromString(string $closure, string $closureArgs) { $posDollar = strpos($closure, '$'); if ($posDollar !== false) { if (isset(self::$lambdaCache[$closure][$closureArgs])) return self::$lambdaCache[$closure][$closureArgs]; $posArrow = strpos($closure, '==>', $posDollar); if ($posArrow !== false) { $args = trim(substr($closure, 0, $posArrow), "() \r\n\t"); $code = substr($closure, $posArrow + 3); } else { $args = '$' . str_replace(',', '=null,$', $closureArgs) . '=null'; $code = $closure; } $code = trim($code, " \r\n\t"); if (strlen($code) > 0 && $code[0] != '{') $code = "return {$code};"; $fun = @create_function($args, $code); // @codeCoverageIgnoreStart if (!$fun) throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA); // @codeCoverageIgnoreEnd self::$lambdaCache[$closure][$closureArgs] = $fun; return $fun; } return null; }
[ "private", "static", "function", "createLambdaFromString", "(", "string", "$", "closure", ",", "string", "$", "closureArgs", ")", "{", "$", "posDollar", "=", "strpos", "(", "$", "closure", ",", "'$'", ")", ";", "if", "(", "$", "posDollar", "!==", "false", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "lambdaCache", "[", "$", "closure", "]", "[", "$", "closureArgs", "]", ")", ")", "return", "self", "::", "$", "lambdaCache", "[", "$", "closure", "]", "[", "$", "closureArgs", "]", ";", "$", "posArrow", "=", "strpos", "(", "$", "closure", ",", "'==>'", ",", "$", "posDollar", ")", ";", "if", "(", "$", "posArrow", "!==", "false", ")", "{", "$", "args", "=", "trim", "(", "substr", "(", "$", "closure", ",", "0", ",", "$", "posArrow", ")", ",", "\"() \\r\\n\\t\"", ")", ";", "$", "code", "=", "substr", "(", "$", "closure", ",", "$", "posArrow", "+", "3", ")", ";", "}", "else", "{", "$", "args", "=", "'$'", ".", "str_replace", "(", "','", ",", "'=null,$'", ",", "$", "closureArgs", ")", ".", "'=null'", ";", "$", "code", "=", "$", "closure", ";", "}", "$", "code", "=", "trim", "(", "$", "code", ",", "\" \\r\\n\\t\"", ")", ";", "if", "(", "strlen", "(", "$", "code", ")", ">", "0", "&&", "$", "code", "[", "0", "]", "!=", "'{'", ")", "$", "code", "=", "\"return {$code};\"", ";", "$", "fun", "=", "@", "create_function", "(", "$", "args", ",", "$", "code", ")", ";", "// @codeCoverageIgnoreStart", "if", "(", "!", "$", "fun", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "self", "::", "ERROR_CANNOT_PARSE_LAMBDA", ")", ";", "// @codeCoverageIgnoreEnd", "self", "::", "$", "lambdaCache", "[", "$", "closure", "]", "[", "$", "closureArgs", "]", "=", "$", "fun", ";", "return", "$", "fun", ";", "}", "return", "null", ";", "}" ]
Convert string lambda to callable function. @param string $closure @param string $closureArgs @throws \InvalidArgumentException Incorrect lambda syntax. @return string|null
[ "Convert", "string", "lambda", "to", "callable", "function", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Utils.php#L136-L163
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.cast
public function cast(string $type): Enumerable { switch ($type) { case 'array': return $this->select(function($v) { return (array)$v; }); case 'int': case 'integer': case 'long': return $this->select(function($v) { return (int)$v; }); case 'float': case 'real': case 'double': return $this->select(function($v) { return (float)$v; }); case 'null': case 'unset': return $this->select(function($v) { return null; }); case 'object': return $this->select(function($v) { return (object)$v; }); case 'string': return $this->select(function($v) { return (string)$v; }); default: throw new \InvalidArgumentException(Errors::UNSUPPORTED_BUILTIN_TYPE); } }
php
public function cast(string $type): Enumerable { switch ($type) { case 'array': return $this->select(function($v) { return (array)$v; }); case 'int': case 'integer': case 'long': return $this->select(function($v) { return (int)$v; }); case 'float': case 'real': case 'double': return $this->select(function($v) { return (float)$v; }); case 'null': case 'unset': return $this->select(function($v) { return null; }); case 'object': return $this->select(function($v) { return (object)$v; }); case 'string': return $this->select(function($v) { return (string)$v; }); default: throw new \InvalidArgumentException(Errors::UNSUPPORTED_BUILTIN_TYPE); } }
[ "public", "function", "cast", "(", "string", "$", "type", ")", ":", "Enumerable", "{", "switch", "(", "$", "type", ")", "{", "case", "'array'", ":", "return", "$", "this", "->", "select", "(", "function", "(", "$", "v", ")", "{", "return", "(", "array", ")", "$", "v", ";", "}", ")", ";", "case", "'int'", ":", "case", "'integer'", ":", "case", "'long'", ":", "return", "$", "this", "->", "select", "(", "function", "(", "$", "v", ")", "{", "return", "(", "int", ")", "$", "v", ";", "}", ")", ";", "case", "'float'", ":", "case", "'real'", ":", "case", "'double'", ":", "return", "$", "this", "->", "select", "(", "function", "(", "$", "v", ")", "{", "return", "(", "float", ")", "$", "v", ";", "}", ")", ";", "case", "'null'", ":", "case", "'unset'", ":", "return", "$", "this", "->", "select", "(", "function", "(", "$", "v", ")", "{", "return", "null", ";", "}", ")", ";", "case", "'object'", ":", "return", "$", "this", "->", "select", "(", "function", "(", "$", "v", ")", "{", "return", "(", "object", ")", "$", "v", ";", "}", ")", ";", "case", "'string'", ":", "return", "$", "this", "->", "select", "(", "function", "(", "$", "v", ")", "{", "return", "(", "string", ")", "$", "v", ";", "}", ")", ";", "default", ":", "throw", "new", "\\", "InvalidArgumentException", "(", "Errors", "::", "UNSUPPORTED_BUILTIN_TYPE", ")", ";", "}", "}" ]
Casts the elements of a sequence to the specified type. <p><b>Syntax</b>: cast (type) <p>The cast method causes an error if an element cannot be cast (exact error depends on the implementation of PHP casting), to get only elements of the specified type, use {@link ofType}. @param string $type The type to cast the elements to. Can be one of the built-in types: array, int (integer, long), float (real, double), null (unset), object, string. @return Enumerable An sequence that contains each element of the source sequence cast to the specified type. @link http://php.net/manual/language.types.type-juggling.php Type Juggling @package YaLinqo\Projection and filtering
[ "Casts", "the", "elements", "of", "a", "sequence", "to", "the", "specified", "type", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "cast", "(", "type", ")", "<p", ">", "The", "cast", "method", "causes", "an", "error", "if", "an", "element", "cannot", "be", "cast", "(", "exact", "error", "depends", "on", "the", "implementation", "of", "PHP", "casting", ")", "to", "get", "only", "elements", "of", "the", "specified", "type", "use", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L74-L97
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.ofType
public function ofType(string $type): Enumerable { switch ($type) { case 'array': return $this->where(function($v) { return is_array($v); }); case 'int': case 'integer': case 'long': return $this->where(function($v) { return is_int($v); }); case 'callable': case 'callback': return $this->where(function($v) { return is_callable($v); }); case 'float': case 'real': case 'double': return $this->where(function($v) { return is_float($v); }); case 'null': return $this->where(function($v) { return is_null($v); }); case 'numeric': return $this->where(function($v) { return is_numeric($v); }); case 'object': return $this->where(function($v) { return is_object($v); }); case 'scalar': return $this->where(function($v) { return is_scalar($v); }); case 'string': return $this->where(function($v) { return is_string($v); }); default: return $this->where(function($v) use ($type) { return is_object($v) && get_class($v) === $type; }); } }
php
public function ofType(string $type): Enumerable { switch ($type) { case 'array': return $this->where(function($v) { return is_array($v); }); case 'int': case 'integer': case 'long': return $this->where(function($v) { return is_int($v); }); case 'callable': case 'callback': return $this->where(function($v) { return is_callable($v); }); case 'float': case 'real': case 'double': return $this->where(function($v) { return is_float($v); }); case 'null': return $this->where(function($v) { return is_null($v); }); case 'numeric': return $this->where(function($v) { return is_numeric($v); }); case 'object': return $this->where(function($v) { return is_object($v); }); case 'scalar': return $this->where(function($v) { return is_scalar($v); }); case 'string': return $this->where(function($v) { return is_string($v); }); default: return $this->where(function($v) use ($type) { return is_object($v) && get_class($v) === $type; }); } }
[ "public", "function", "ofType", "(", "string", "$", "type", ")", ":", "Enumerable", "{", "switch", "(", "$", "type", ")", "{", "case", "'array'", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "{", "return", "is_array", "(", "$", "v", ")", ";", "}", ")", ";", "case", "'int'", ":", "case", "'integer'", ":", "case", "'long'", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "{", "return", "is_int", "(", "$", "v", ")", ";", "}", ")", ";", "case", "'callable'", ":", "case", "'callback'", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "{", "return", "is_callable", "(", "$", "v", ")", ";", "}", ")", ";", "case", "'float'", ":", "case", "'real'", ":", "case", "'double'", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "{", "return", "is_float", "(", "$", "v", ")", ";", "}", ")", ";", "case", "'null'", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "{", "return", "is_null", "(", "$", "v", ")", ";", "}", ")", ";", "case", "'numeric'", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "{", "return", "is_numeric", "(", "$", "v", ")", ";", "}", ")", ";", "case", "'object'", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "{", "return", "is_object", "(", "$", "v", ")", ";", "}", ")", ";", "case", "'scalar'", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "{", "return", "is_scalar", "(", "$", "v", ")", ";", "}", ")", ";", "case", "'string'", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "{", "return", "is_string", "(", "$", "v", ")", ";", "}", ")", ";", "default", ":", "return", "$", "this", "->", "where", "(", "function", "(", "$", "v", ")", "use", "(", "$", "type", ")", "{", "return", "is_object", "(", "$", "v", ")", "&&", "get_class", "(", "$", "v", ")", "===", "$", "type", ";", "}", ")", ";", "}", "}" ]
Filters the elements of a sequence based on a specified type. <p><b>Syntax</b>: ofType (type) <p>The ofType method returns only elements of the specified type. To instead receive an error if an element cannot be cast, use {@link cast}. @param string $type The type to filter the elements of the sequence on. Can be either class name or one of the predefined types: array, int (integer, long), callable (callable), float (real, double), null, string, object, numeric, scalar. @return Enumerable A sequence that contains elements from the input sequence of the specified type. @package YaLinqo\Projection and filtering
[ "Filters", "the", "elements", "of", "a", "sequence", "based", "on", "a", "specified", "type", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "ofType", "(", "type", ")", "<p", ">", "The", "ofType", "method", "returns", "only", "elements", "of", "the", "specified", "type", ".", "To", "instead", "receive", "an", "error", "if", "an", "element", "cannot", "be", "cast", "use", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L107-L136
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.select
public function select($selectorValue, $selectorKey = null): Enumerable { $selectorValue = Utils::createLambda($selectorValue, 'v,k'); $selectorKey = Utils::createLambda($selectorKey, 'v,k', Functions::$key); return new self(function() use ($selectorValue, $selectorKey) { foreach ($this as $k => $v) yield $selectorKey($v, $k) => $selectorValue($v, $k); }); }
php
public function select($selectorValue, $selectorKey = null): Enumerable { $selectorValue = Utils::createLambda($selectorValue, 'v,k'); $selectorKey = Utils::createLambda($selectorKey, 'v,k', Functions::$key); return new self(function() use ($selectorValue, $selectorKey) { foreach ($this as $k => $v) yield $selectorKey($v, $k) => $selectorValue($v, $k); }); }
[ "public", "function", "select", "(", "$", "selectorValue", ",", "$", "selectorKey", "=", "null", ")", ":", "Enumerable", "{", "$", "selectorValue", "=", "Utils", "::", "createLambda", "(", "$", "selectorValue", ",", "'v,k'", ")", ";", "$", "selectorKey", "=", "Utils", "::", "createLambda", "(", "$", "selectorKey", ",", "'v,k'", ",", "Functions", "::", "$", "key", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "selectorValue", ",", "$", "selectorKey", ")", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "yield", "$", "selectorKey", "(", "$", "v", ",", "$", "k", ")", "=>", "$", "selectorValue", "(", "$", "v", ",", "$", "k", ")", ";", "}", ")", ";", "}" ]
Projects each element of a sequence into a new form. <p><b>Syntax</b>: select (selectorValue {(v, k) ==> result} [, selectorKey {(v, k) ==> result}]) <p>This projection method requires the transform functions, selectorValue and selectorKey, to produce one key-value pair for each value in the source sequence. If selectorValue returns a value that is itself a collection, it is up to the consumer to traverse the subsequences manually. In such a situation, it might be better for your query to return a single coalesced sequence of values. To achieve this, use the {@link selectMany()} method instead of select. Although selectMany works similarly to select, it differs in that the transform function returns a collection that is then expanded by selectMany before it is returned. @param callable $selectorValue {(v, k) ==> value} A transform function to apply to each value. @param callable|null $selectorKey {(v, k) ==> key} A transform function to apply to each key. Default: key. @return Enumerable A sequence whose elements are the result of invoking the transform functions on each element of source. @package YaLinqo\Projection and filtering
[ "Projects", "each", "element", "of", "a", "sequence", "into", "a", "new", "form", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "select", "(", "selectorValue", "{", "(", "v", "k", ")", "==", ">", "result", "}", "[", "selectorKey", "{", "(", "v", "k", ")", "==", ">", "result", "}", "]", ")", "<p", ">", "This", "projection", "method", "requires", "the", "transform", "functions", "selectorValue", "and", "selectorKey", "to", "produce", "one", "key", "-", "value", "pair", "for", "each", "value", "in", "the", "source", "sequence", ".", "If", "selectorValue", "returns", "a", "value", "that", "is", "itself", "a", "collection", "it", "is", "up", "to", "the", "consumer", "to", "traverse", "the", "subsequences", "manually", ".", "In", "such", "a", "situation", "it", "might", "be", "better", "for", "your", "query", "to", "return", "a", "single", "coalesced", "sequence", "of", "values", ".", "To", "achieve", "this", "use", "the", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L147-L156
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.selectMany
public function selectMany($collectionSelector = null, $resultSelectorValue = null, $resultSelectorKey = null): Enumerable { $collectionSelector = Utils::createLambda($collectionSelector, 'v,k', Functions::$value); $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v,k1,k2', Functions::$value); $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v,k1,k2', false); if ($resultSelectorKey === false) $resultSelectorKey = Functions::increment(); return new self(function() use ($collectionSelector, $resultSelectorValue, $resultSelectorKey) { foreach ($this as $ok => $ov) foreach ($collectionSelector($ov, $ok) as $ik => $iv) yield $resultSelectorKey($iv, $ok, $ik) => $resultSelectorValue($iv, $ok, $ik); }); }
php
public function selectMany($collectionSelector = null, $resultSelectorValue = null, $resultSelectorKey = null): Enumerable { $collectionSelector = Utils::createLambda($collectionSelector, 'v,k', Functions::$value); $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v,k1,k2', Functions::$value); $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v,k1,k2', false); if ($resultSelectorKey === false) $resultSelectorKey = Functions::increment(); return new self(function() use ($collectionSelector, $resultSelectorValue, $resultSelectorKey) { foreach ($this as $ok => $ov) foreach ($collectionSelector($ov, $ok) as $ik => $iv) yield $resultSelectorKey($iv, $ok, $ik) => $resultSelectorValue($iv, $ok, $ik); }); }
[ "public", "function", "selectMany", "(", "$", "collectionSelector", "=", "null", ",", "$", "resultSelectorValue", "=", "null", ",", "$", "resultSelectorKey", "=", "null", ")", ":", "Enumerable", "{", "$", "collectionSelector", "=", "Utils", "::", "createLambda", "(", "$", "collectionSelector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "resultSelectorValue", "=", "Utils", "::", "createLambda", "(", "$", "resultSelectorValue", ",", "'v,k1,k2'", ",", "Functions", "::", "$", "value", ")", ";", "$", "resultSelectorKey", "=", "Utils", "::", "createLambda", "(", "$", "resultSelectorKey", ",", "'v,k1,k2'", ",", "false", ")", ";", "if", "(", "$", "resultSelectorKey", "===", "false", ")", "$", "resultSelectorKey", "=", "Functions", "::", "increment", "(", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "collectionSelector", ",", "$", "resultSelectorValue", ",", "$", "resultSelectorKey", ")", "{", "foreach", "(", "$", "this", "as", "$", "ok", "=>", "$", "ov", ")", "foreach", "(", "$", "collectionSelector", "(", "$", "ov", ",", "$", "ok", ")", "as", "$", "ik", "=>", "$", "iv", ")", "yield", "$", "resultSelectorKey", "(", "$", "iv", ",", "$", "ok", ",", "$", "ik", ")", "=>", "$", "resultSelectorValue", "(", "$", "iv", ",", "$", "ok", ",", "$", "ik", ")", ";", "}", ")", ";", "}" ]
Projects each element of a sequence to a sequence and flattens the resulting sequences into one sequence. <p><b>Syntax</b>: selectMany () <p>The selectMany method enumerates the input sequence, where each element is a sequence, and then enumerates and yields the elements of each such sequence. That is, for each element of source, selectorValue and selectorKey are invoked and a sequence of key-value pairs is returned. selectMany then flattens this two-dimensional collection of collections into a one-dimensional sequence and returns it. For example, if a query uses selectMany to obtain the orders for each customer in a database, the result is a sequence of orders. If instead the query uses {@link select} to obtain the orders, the collection of collections of orders is not combined and the result is a sequence of sequences of orders. <p><b>Syntax</b>: selectMany (collectionSelector {(v, k) ==> enum}) <p>The selectMany method enumerates the input sequence, uses transform functions to map each element to a sequence, and then enumerates and yields the elements of each such sequence. <p><b>Syntax</b>: selectMany (collectionSelector {(v, k) ==> enum} [, resultSelectorValue {(v, k1, k2) ==> value} [, resultSelectorKey {(v, k1, k2) ==> key}]]) <p>Projects each element of a sequence to a sequence, flattens the resulting sequences into one sequence, and invokes a result selector functions on each element therein. <p>The selectMany method is useful when you have to keep the elements of source in scope for query logic that occurs after the call to selectMany. If there is a bidirectional relationship between objects in the source sequence and objects returned from collectionSelector, that is, if a sequence returned from collectionSelector provides a property to retrieve the object that produced it, you do not need this overload of selectMany. Instead, you can use simpler selectMany overload and navigate back to the source object through the returned sequence. @param callable $collectionSelector {(v, k) ==> enum} A transform function to apply to each element. @param callable|null $resultSelectorValue {(v, k1, k2) ==> value} A transform function to apply to each value of the intermediate sequence. Default: {(v, k1, k2) ==> v}. @param callable|null $resultSelectorKey {(v, k1, k2) ==> key} A transform function to apply to each key of the intermediate sequence. Default: increment. @return Enumerable A sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. @package YaLinqo\Projection and filtering
[ "Projects", "each", "element", "of", "a", "sequence", "to", "a", "sequence", "and", "flattens", "the", "resulting", "sequences", "into", "one", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "selectMany", "()", "<p", ">", "The", "selectMany", "method", "enumerates", "the", "input", "sequence", "where", "each", "element", "is", "a", "sequence", "and", "then", "enumerates", "and", "yields", "the", "elements", "of", "each", "such", "sequence", ".", "That", "is", "for", "each", "element", "of", "source", "selectorValue", "and", "selectorKey", "are", "invoked", "and", "a", "sequence", "of", "key", "-", "value", "pairs", "is", "returned", ".", "selectMany", "then", "flattens", "this", "two", "-", "dimensional", "collection", "of", "collections", "into", "a", "one", "-", "dimensional", "sequence", "and", "returns", "it", ".", "For", "example", "if", "a", "query", "uses", "selectMany", "to", "obtain", "the", "orders", "for", "each", "customer", "in", "a", "database", "the", "result", "is", "a", "sequence", "of", "orders", ".", "If", "instead", "the", "query", "uses", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L173-L186
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.where
public function where($predicate): Enumerable { $predicate = Utils::createLambda($predicate, 'v,k'); return new self(function() use ($predicate) { foreach ($this as $k => $v) if ($predicate($v, $k)) yield $k => $v; }); }
php
public function where($predicate): Enumerable { $predicate = Utils::createLambda($predicate, 'v,k'); return new self(function() use ($predicate) { foreach ($this as $k => $v) if ($predicate($v, $k)) yield $k => $v; }); }
[ "public", "function", "where", "(", "$", "predicate", ")", ":", "Enumerable", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "predicate", ")", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "yield", "$", "k", "=>", "$", "v", ";", "}", ")", ";", "}" ]
Filters a sequence of values based on a predicate. <p><b>Syntax</b>: where (predicate {(v, k) ==> result}) @param callable $predicate {(v, k) ==> result} A function to test each element for a condition. @return Enumerable A sequence that contains elements from the input sequence that satisfy the condition. @package YaLinqo\Projection and filtering
[ "Filters", "a", "sequence", "of", "values", "based", "on", "a", "predicate", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "where", "(", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", ")" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L195-L204
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.orderByDir
public function orderByDir($sortOrder, $keySelector = null, $comparer = null): OrderedEnumerable { $sortFlags = Utils::lambdaToSortFlagsAndOrder($comparer, $sortOrder); $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$value); $isReversed = $sortOrder == SORT_DESC; $comparer = Utils::createComparer($comparer, $sortOrder, $isReversed); return new OrderedEnumerable($this, $sortOrder, $sortFlags, $isReversed, $keySelector, $comparer); }
php
public function orderByDir($sortOrder, $keySelector = null, $comparer = null): OrderedEnumerable { $sortFlags = Utils::lambdaToSortFlagsAndOrder($comparer, $sortOrder); $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$value); $isReversed = $sortOrder == SORT_DESC; $comparer = Utils::createComparer($comparer, $sortOrder, $isReversed); return new OrderedEnumerable($this, $sortOrder, $sortFlags, $isReversed, $keySelector, $comparer); }
[ "public", "function", "orderByDir", "(", "$", "sortOrder", ",", "$", "keySelector", "=", "null", ",", "$", "comparer", "=", "null", ")", ":", "OrderedEnumerable", "{", "$", "sortFlags", "=", "Utils", "::", "lambdaToSortFlagsAndOrder", "(", "$", "comparer", ",", "$", "sortOrder", ")", ";", "$", "keySelector", "=", "Utils", "::", "createLambda", "(", "$", "keySelector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "isReversed", "=", "$", "sortOrder", "==", "SORT_DESC", ";", "$", "comparer", "=", "Utils", "::", "createComparer", "(", "$", "comparer", ",", "$", "sortOrder", ",", "$", "isReversed", ")", ";", "return", "new", "OrderedEnumerable", "(", "$", "this", ",", "$", "sortOrder", ",", "$", "sortFlags", ",", "$", "isReversed", ",", "$", "keySelector", ",", "$", "comparer", ")", ";", "}" ]
Sorts the elements of a sequence in a particular direction (ascending, descending) according to a key. <p><b>Syntax</b>: orderByDir (false|true [, {(v, k) ==> key} [, {(a, b) ==> diff}]]) <p>Three methods are defined to extend the type {@link OrderedEnumerable}, which is the return type of this method. These three methods, namely {@link OrderedEnumerable::thenBy thenBy}, {@link OrderedEnumerable::thenByDescending thenByDescending} and {@link OrderedEnumerable::thenByDir thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. <p>Because OrderedEnumerable inherits from Enumerable, you can call {@link orderBy}, {@link orderByDescending} or {@link orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. <p>This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. @param int|bool $sortOrder A direction in which to order the elements: false or SORT_DESC for ascending (by increasing value), true or SORT_ASC for descending (by decreasing value). @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. @param callable|int|null $comparer {(a, b) ==> diff} Difference between a and b: &lt;0 if a&lt;b; 0 if a==b; &gt;0 if a&gt;b. Can also be a combination of SORT_ flags. @return OrderedEnumerable @package YaLinqo\Ordering
[ "Sorts", "the", "elements", "of", "a", "sequence", "in", "a", "particular", "direction", "(", "ascending", "descending", ")", "according", "to", "a", "key", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "orderByDir", "(", "false|true", "[", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "{", "(", "a", "b", ")", "==", ">", "diff", "}", "]]", ")", "<p", ">", "Three", "methods", "are", "defined", "to", "extend", "the", "type", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L222-L229
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.orderBy
public function orderBy($keySelector = null, $comparer = null): OrderedEnumerable { return $this->orderByDir(false, $keySelector, $comparer); }
php
public function orderBy($keySelector = null, $comparer = null): OrderedEnumerable { return $this->orderByDir(false, $keySelector, $comparer); }
[ "public", "function", "orderBy", "(", "$", "keySelector", "=", "null", ",", "$", "comparer", "=", "null", ")", ":", "OrderedEnumerable", "{", "return", "$", "this", "->", "orderByDir", "(", "false", ",", "$", "keySelector", ",", "$", "comparer", ")", ";", "}" ]
Sorts the elements of a sequence in ascending order according to a key. <p><b>Syntax</b>: orderBy ([{(v, k) ==> key} [, {(a, b) ==> diff}]]) <p>Three methods are defined to extend the type {@link OrderedEnumerable}, which is the return type of this method. These three methods, namely {@link OrderedEnumerable::thenBy thenBy}, {@link OrderedEnumerable::thenByDescending thenByDescending} and {@link OrderedEnumerable::thenByDir thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. <p>Because OrderedEnumerable inherits from Enumerable, you can call {@link orderBy}, {@link orderByDescending} or {@link orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. <p>This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. @param callable|int|null $comparer {(a, b) ==> diff} Difference between a and b: &lt;0 if a&lt;b; 0 if a==b; &gt;0 if a&gt;b. Can also be a combination of SORT_ flags. @return OrderedEnumerable @package YaLinqo\Ordering
[ "Sorts", "the", "elements", "of", "a", "sequence", "in", "ascending", "order", "according", "to", "a", "key", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "orderBy", "(", "[", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "{", "(", "a", "b", ")", "==", ">", "diff", "}", "]]", ")", "<p", ">", "Three", "methods", "are", "defined", "to", "extend", "the", "type", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L242-L245
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.orderByDescending
public function orderByDescending($keySelector = null, $comparer = null): OrderedEnumerable { return $this->orderByDir(true, $keySelector, $comparer); }
php
public function orderByDescending($keySelector = null, $comparer = null): OrderedEnumerable { return $this->orderByDir(true, $keySelector, $comparer); }
[ "public", "function", "orderByDescending", "(", "$", "keySelector", "=", "null", ",", "$", "comparer", "=", "null", ")", ":", "OrderedEnumerable", "{", "return", "$", "this", "->", "orderByDir", "(", "true", ",", "$", "keySelector", ",", "$", "comparer", ")", ";", "}" ]
Sorts the elements of a sequence in descending order according to a key. <p><b>Syntax</b>: orderByDescending ([{(v, k) ==> key} [, {(a, b) ==> diff}]]) <p>Three methods are defined to extend the type {@link OrderedEnumerable}, which is the return type of this method. These three methods, namely {@link OrderedEnumerable::thenBy thenBy}, {@link OrderedEnumerable::thenByDescending thenByDescending} and {@link OrderedEnumerable::thenByDir thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. <p>Because OrderedEnumerable inherits from Enumerable, you can call {@link orderBy}, {@link orderByDescending} or {@link orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. <p>This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. @param callable|int|null $comparer {(a, b) ==> diff} Difference between a and b: &lt;0 if a&lt;b; 0 if a==b; &gt;0 if a&gt;b. Can also be a combination of SORT_ flags. @return OrderedEnumerable @package YaLinqo\Ordering
[ "Sorts", "the", "elements", "of", "a", "sequence", "in", "descending", "order", "according", "to", "a", "key", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "orderByDescending", "(", "[", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "{", "(", "a", "b", ")", "==", ">", "diff", "}", "]]", ")", "<p", ">", "Three", "methods", "are", "defined", "to", "extend", "the", "type", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L258-L261
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.groupJoin
public function groupJoin($inner, $outerKeySelector = null, $innerKeySelector = null, $resultSelectorValue = null, $resultSelectorKey = null): Enumerable { $inner = self::from($inner); $outerKeySelector = Utils::createLambda($outerKeySelector, 'v,k', Functions::$key); $innerKeySelector = Utils::createLambda($innerKeySelector, 'v,k', Functions::$key); /** @noinspection PhpUnusedParameterInspection */ $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v,e,k', function($v, $e, $k) { return [ $v, $e ]; }); /** @noinspection PhpUnusedParameterInspection */ $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v,e,k', function($v, $e, $k) { return $k; }); return new self(function() use ($inner, $outerKeySelector, $innerKeySelector, $resultSelectorValue, $resultSelectorKey) { $lookup = $inner->toLookup($innerKeySelector); foreach ($this as $k => $v) { $key = $outerKeySelector($v, $k); $e = isset($lookup[$key]) ? self::from($lookup[$key]) : self::emptyEnum(); yield $resultSelectorKey($v, $e, $key) => $resultSelectorValue($v, $e, $key); } }); }
php
public function groupJoin($inner, $outerKeySelector = null, $innerKeySelector = null, $resultSelectorValue = null, $resultSelectorKey = null): Enumerable { $inner = self::from($inner); $outerKeySelector = Utils::createLambda($outerKeySelector, 'v,k', Functions::$key); $innerKeySelector = Utils::createLambda($innerKeySelector, 'v,k', Functions::$key); /** @noinspection PhpUnusedParameterInspection */ $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v,e,k', function($v, $e, $k) { return [ $v, $e ]; }); /** @noinspection PhpUnusedParameterInspection */ $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v,e,k', function($v, $e, $k) { return $k; }); return new self(function() use ($inner, $outerKeySelector, $innerKeySelector, $resultSelectorValue, $resultSelectorKey) { $lookup = $inner->toLookup($innerKeySelector); foreach ($this as $k => $v) { $key = $outerKeySelector($v, $k); $e = isset($lookup[$key]) ? self::from($lookup[$key]) : self::emptyEnum(); yield $resultSelectorKey($v, $e, $key) => $resultSelectorValue($v, $e, $key); } }); }
[ "public", "function", "groupJoin", "(", "$", "inner", ",", "$", "outerKeySelector", "=", "null", ",", "$", "innerKeySelector", "=", "null", ",", "$", "resultSelectorValue", "=", "null", ",", "$", "resultSelectorKey", "=", "null", ")", ":", "Enumerable", "{", "$", "inner", "=", "self", "::", "from", "(", "$", "inner", ")", ";", "$", "outerKeySelector", "=", "Utils", "::", "createLambda", "(", "$", "outerKeySelector", ",", "'v,k'", ",", "Functions", "::", "$", "key", ")", ";", "$", "innerKeySelector", "=", "Utils", "::", "createLambda", "(", "$", "innerKeySelector", ",", "'v,k'", ",", "Functions", "::", "$", "key", ")", ";", "/** @noinspection PhpUnusedParameterInspection */", "$", "resultSelectorValue", "=", "Utils", "::", "createLambda", "(", "$", "resultSelectorValue", ",", "'v,e,k'", ",", "function", "(", "$", "v", ",", "$", "e", ",", "$", "k", ")", "{", "return", "[", "$", "v", ",", "$", "e", "]", ";", "}", ")", ";", "/** @noinspection PhpUnusedParameterInspection */", "$", "resultSelectorKey", "=", "Utils", "::", "createLambda", "(", "$", "resultSelectorKey", ",", "'v,e,k'", ",", "function", "(", "$", "v", ",", "$", "e", ",", "$", "k", ")", "{", "return", "$", "k", ";", "}", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "inner", ",", "$", "outerKeySelector", ",", "$", "innerKeySelector", ",", "$", "resultSelectorValue", ",", "$", "resultSelectorKey", ")", "{", "$", "lookup", "=", "$", "inner", "->", "toLookup", "(", "$", "innerKeySelector", ")", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "key", "=", "$", "outerKeySelector", "(", "$", "v", ",", "$", "k", ")", ";", "$", "e", "=", "isset", "(", "$", "lookup", "[", "$", "key", "]", ")", "?", "self", "::", "from", "(", "$", "lookup", "[", "$", "key", "]", ")", ":", "self", "::", "emptyEnum", "(", ")", ";", "yield", "$", "resultSelectorKey", "(", "$", "v", ",", "$", "e", ",", "$", "key", ")", "=>", "$", "resultSelectorValue", "(", "$", "v", ",", "$", "e", ",", "$", "key", ")", ";", "}", "}", ")", ";", "}" ]
Correlates the elements of two sequences based on equality of keys and groups the results. <p><b>Syntax</b>: groupJoin (inner [, outerKeySelector {(v, k) ==> key} [, innerKeySelector {(v, k) ==> key} [, resultSelectorValue {(v, e, k) ==> value} [, resultSelectorKey {(v, e, k) ==> key}]]]]) <p>GroupJoin produces hierarchical results, which means that elements from outer are paired with collections of matching elements from inner. GroupJoin enables you to base your results on a whole set of matches for each element of outer. If there are no correlated elements in inner for a given element of outer, the sequence of matches for that element will be empty but will still appear in the results. <p>The resultSelectorValue and resultSelectorKey functions are called only one time for each outer element together with a collection of all the inner elements that match the outer element. This differs from the {@link join} method, in which the result selector function is invoked on pairs that contain one element from outer and one element from inner. GroupJoin preserves the order of the elements of outer, and for each element of outer, the order of the matching elements from inner. <p>GroupJoin has no direct equivalent in traditional relational database terms. However, this method does implement a superset of inner joins and left outer joins. Both of these operations can be written in terms of a grouped join. @param array|\Iterator|\IteratorAggregate|Enumerable $inner The second (inner) sequence to join to the first (source, outer) sequence. @param callable|null $outerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the first sequence. Default: key. @param callable|null $innerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the second sequence. Default: key. @param callable|null $resultSelectorValue {(v, e, k) ==> value} A function to create a result value from an element from the first sequence and a collection of matching elements from the second sequence. Default: {(v, e, k) ==> array(v, e)}. @param callable|null $resultSelectorKey {(v, e, k) ==> key} A function to create a result key from an element from the first sequence and a collection of matching elements from the second sequence. Default: {(v, e, k) ==> k} (keys returned by outerKeySelector and innerKeySelector functions). @return Enumerable A sequence that contains elements that are obtained by performing a grouped join on two sequences. @package YaLinqo\Joining and grouping
[ "Correlates", "the", "elements", "of", "two", "sequences", "based", "on", "equality", "of", "keys", "and", "groups", "the", "results", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "groupJoin", "(", "inner", "[", "outerKeySelector", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "innerKeySelector", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "resultSelectorValue", "{", "(", "v", "e", "k", ")", "==", ">", "value", "}", "[", "resultSelectorKey", "{", "(", "v", "e", "k", ")", "==", ">", "key", "}", "]]]]", ")", "<p", ">", "GroupJoin", "produces", "hierarchical", "results", "which", "means", "that", "elements", "from", "outer", "are", "paired", "with", "collections", "of", "matching", "elements", "from", "inner", ".", "GroupJoin", "enables", "you", "to", "base", "your", "results", "on", "a", "whole", "set", "of", "matches", "for", "each", "element", "of", "outer", ".", "If", "there", "are", "no", "correlated", "elements", "in", "inner", "for", "a", "given", "element", "of", "outer", "the", "sequence", "of", "matches", "for", "that", "element", "will", "be", "empty", "but", "will", "still", "appear", "in", "the", "results", ".", "<p", ">", "The", "resultSelectorValue", "and", "resultSelectorKey", "functions", "are", "called", "only", "one", "time", "for", "each", "outer", "element", "together", "with", "a", "collection", "of", "all", "the", "inner", "elements", "that", "match", "the", "outer", "element", ".", "This", "differs", "from", "the", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L281-L299
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.join
public function join($inner, $outerKeySelector = null, $innerKeySelector = null, $resultSelectorValue = null, $resultSelectorKey = null): Enumerable { $inner = self::from($inner); $outerKeySelector = Utils::createLambda($outerKeySelector, 'v,k', Functions::$key); $innerKeySelector = Utils::createLambda($innerKeySelector, 'v,k', Functions::$key); /** @noinspection PhpUnusedParameterInspection */ $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v1,v2,k', function($v1, $v2, $k) { return [ $v1, $v2 ]; }); /** @noinspection PhpUnusedParameterInspection */ $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v1,v2,k', function($v1, $v2, $k) { return $k; }); return new self(function() use ($inner, $outerKeySelector, $innerKeySelector, $resultSelectorValue, $resultSelectorKey) { $lookup = $inner->toLookup($innerKeySelector); foreach ($this as $ok => $ov) { $key = $outerKeySelector($ov, $ok); if (isset($lookup[$key])) foreach ($lookup[$key] as $iv) yield $resultSelectorKey($ov, $iv, $key) => $resultSelectorValue($ov, $iv, $key); } }); }
php
public function join($inner, $outerKeySelector = null, $innerKeySelector = null, $resultSelectorValue = null, $resultSelectorKey = null): Enumerable { $inner = self::from($inner); $outerKeySelector = Utils::createLambda($outerKeySelector, 'v,k', Functions::$key); $innerKeySelector = Utils::createLambda($innerKeySelector, 'v,k', Functions::$key); /** @noinspection PhpUnusedParameterInspection */ $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v1,v2,k', function($v1, $v2, $k) { return [ $v1, $v2 ]; }); /** @noinspection PhpUnusedParameterInspection */ $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v1,v2,k', function($v1, $v2, $k) { return $k; }); return new self(function() use ($inner, $outerKeySelector, $innerKeySelector, $resultSelectorValue, $resultSelectorKey) { $lookup = $inner->toLookup($innerKeySelector); foreach ($this as $ok => $ov) { $key = $outerKeySelector($ov, $ok); if (isset($lookup[$key])) foreach ($lookup[$key] as $iv) yield $resultSelectorKey($ov, $iv, $key) => $resultSelectorValue($ov, $iv, $key); } }); }
[ "public", "function", "join", "(", "$", "inner", ",", "$", "outerKeySelector", "=", "null", ",", "$", "innerKeySelector", "=", "null", ",", "$", "resultSelectorValue", "=", "null", ",", "$", "resultSelectorKey", "=", "null", ")", ":", "Enumerable", "{", "$", "inner", "=", "self", "::", "from", "(", "$", "inner", ")", ";", "$", "outerKeySelector", "=", "Utils", "::", "createLambda", "(", "$", "outerKeySelector", ",", "'v,k'", ",", "Functions", "::", "$", "key", ")", ";", "$", "innerKeySelector", "=", "Utils", "::", "createLambda", "(", "$", "innerKeySelector", ",", "'v,k'", ",", "Functions", "::", "$", "key", ")", ";", "/** @noinspection PhpUnusedParameterInspection */", "$", "resultSelectorValue", "=", "Utils", "::", "createLambda", "(", "$", "resultSelectorValue", ",", "'v1,v2,k'", ",", "function", "(", "$", "v1", ",", "$", "v2", ",", "$", "k", ")", "{", "return", "[", "$", "v1", ",", "$", "v2", "]", ";", "}", ")", ";", "/** @noinspection PhpUnusedParameterInspection */", "$", "resultSelectorKey", "=", "Utils", "::", "createLambda", "(", "$", "resultSelectorKey", ",", "'v1,v2,k'", ",", "function", "(", "$", "v1", ",", "$", "v2", ",", "$", "k", ")", "{", "return", "$", "k", ";", "}", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "inner", ",", "$", "outerKeySelector", ",", "$", "innerKeySelector", ",", "$", "resultSelectorValue", ",", "$", "resultSelectorKey", ")", "{", "$", "lookup", "=", "$", "inner", "->", "toLookup", "(", "$", "innerKeySelector", ")", ";", "foreach", "(", "$", "this", "as", "$", "ok", "=>", "$", "ov", ")", "{", "$", "key", "=", "$", "outerKeySelector", "(", "$", "ov", ",", "$", "ok", ")", ";", "if", "(", "isset", "(", "$", "lookup", "[", "$", "key", "]", ")", ")", "foreach", "(", "$", "lookup", "[", "$", "key", "]", "as", "$", "iv", ")", "yield", "$", "resultSelectorKey", "(", "$", "ov", ",", "$", "iv", ",", "$", "key", ")", "=>", "$", "resultSelectorValue", "(", "$", "ov", ",", "$", "iv", ",", "$", "key", ")", ";", "}", "}", ")", ";", "}" ]
Correlates the elements of two sequences based on matching keys. <p><b>Syntax</b>: join (inner [, outerKeySelector {(v, k) ==> key} [, innerKeySelector {(v, k) ==> key} [, resultSelectorValue {(v1, v2, k) ==> value} [, resultSelectorKey {(v1, v2, k) ==> key}]]]]) <p>A join refers to the operation of correlating the elements of two sources of information based on a common key. Join brings the two information sources and the keys by which they are matched together in one method call. This differs from the use of {@link selectMany}, which requires more than one method call to perform the same operation. <p>Join preserves the order of the elements of the source, and for each of these elements, the order of the matching elements of inner. <p>In relational database terms, the Join method implements an inner equijoin. 'Inner' means that only elements that have a match in the other sequence are included in the results. An 'equijoin' is a join in which the keys are compared for equality. A left outer join operation has no dedicated standard query operator, but can be performed by using the {@link groupJoin} method. @param array|\Iterator|\IteratorAggregate|Enumerable $inner The sequence to join to the source sequence. @param callable|null $outerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the source sequence. Default: key. @param callable|null $innerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the second sequence. Default: key. @param callable|null $resultSelectorValue {(v1, v2, k) ==> result} A function to create a result value from two matching elements. Default: {(v1, v2, k) ==> array(v1, v2)}. @param callable|null $resultSelectorKey {(v1, v2, k) ==> result} A function to create a result key from two matching elements. Default: {(v1, v2, k) ==> k} (keys returned by outerKeySelector and innerKeySelector functions). @return Enumerable @package YaLinqo\Joining and grouping
[ "Correlates", "the", "elements", "of", "two", "sequences", "based", "on", "matching", "keys", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "join", "(", "inner", "[", "outerKeySelector", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "innerKeySelector", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "resultSelectorValue", "{", "(", "v1", "v2", "k", ")", "==", ">", "value", "}", "[", "resultSelectorKey", "{", "(", "v1", "v2", "k", ")", "==", ">", "key", "}", "]]]]", ")", "<p", ">", "A", "join", "refers", "to", "the", "operation", "of", "correlating", "the", "elements", "of", "two", "sources", "of", "information", "based", "on", "a", "common", "key", ".", "Join", "brings", "the", "two", "information", "sources", "and", "the", "keys", "by", "which", "they", "are", "matched", "together", "in", "one", "method", "call", ".", "This", "differs", "from", "the", "use", "of", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L315-L334
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.groupBy
public function groupBy($keySelector = null, $valueSelector = null, $resultSelectorValue = null, $resultSelectorKey = null): Enumerable { $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$key); $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value); $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'e,k', Functions::$value); $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'e,k', Functions::$key); return self::from($this->toLookup($keySelector, $valueSelector)) ->select($resultSelectorValue, $resultSelectorKey); }
php
public function groupBy($keySelector = null, $valueSelector = null, $resultSelectorValue = null, $resultSelectorKey = null): Enumerable { $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$key); $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value); $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'e,k', Functions::$value); $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'e,k', Functions::$key); return self::from($this->toLookup($keySelector, $valueSelector)) ->select($resultSelectorValue, $resultSelectorKey); }
[ "public", "function", "groupBy", "(", "$", "keySelector", "=", "null", ",", "$", "valueSelector", "=", "null", ",", "$", "resultSelectorValue", "=", "null", ",", "$", "resultSelectorKey", "=", "null", ")", ":", "Enumerable", "{", "$", "keySelector", "=", "Utils", "::", "createLambda", "(", "$", "keySelector", ",", "'v,k'", ",", "Functions", "::", "$", "key", ")", ";", "$", "valueSelector", "=", "Utils", "::", "createLambda", "(", "$", "valueSelector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "resultSelectorValue", "=", "Utils", "::", "createLambda", "(", "$", "resultSelectorValue", ",", "'e,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "resultSelectorKey", "=", "Utils", "::", "createLambda", "(", "$", "resultSelectorKey", ",", "'e,k'", ",", "Functions", "::", "$", "key", ")", ";", "return", "self", "::", "from", "(", "$", "this", "->", "toLookup", "(", "$", "keySelector", ",", "$", "valueSelector", ")", ")", "->", "select", "(", "$", "resultSelectorValue", ",", "$", "resultSelectorKey", ")", ";", "}" ]
Groups the elements of a sequence by its keys or a specified key selector function. <p><b>Syntax</b>: groupBy () <p>Groups the elements of a sequence by its keys. <p><b>Syntax</b>: groupBy (keySelector {(v, k) ==> key}) <p>Groups the elements of a sequence according to a specified key selector function. <p><b>Syntax</b>: groupBy (keySelector {(v, k) ==> key}, valueSelector {(v, k) ==> value}) <p>Groups the elements of a sequence according to a specified key selector function and projects the elements for each group by using a specified function. <p><b>Syntax</b>: groupBy (keySelector {(v, k) ==> key}, valueSelector {(v, k) ==> value}, resultSelectorValue {(e, k) ==> value} [, resultSelectorKey {(e, k) ==> key}]) <p>Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. <p>For all overloads except the last: the groupBy method returns a sequence of sequences, one inner sequence for each distinct key that was encountered. The outer sequence is yielded in an order based on the order of the elements in source that produced the first key of each inner sequence. Elements in a inner sequence are yielded in the order they appear in source. @param callable|null $keySelector {(v, k) ==> key} A function to extract the key for each element. Default: key. @param callable|null $valueSelector {(v, k) ==> value} A function to map each source element to a value in the inner sequence. @param callable|null $resultSelectorValue {(e, k) ==> value} A function to create a result value from each group. @param callable|null $resultSelectorKey {(e, k) ==> key} A function to create a result key from each group. @return Enumerable A sequence of sequences indexed by a key. @package YaLinqo\Joining and grouping
[ "Groups", "the", "elements", "of", "a", "sequence", "by", "its", "keys", "or", "a", "specified", "key", "selector", "function", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "groupBy", "()", "<p", ">", "Groups", "the", "elements", "of", "a", "sequence", "by", "its", "keys", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "groupBy", "(", "keySelector", "{", "(", "v", "k", ")", "==", ">", "key", "}", ")", "<p", ">", "Groups", "the", "elements", "of", "a", "sequence", "according", "to", "a", "specified", "key", "selector", "function", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "groupBy", "(", "keySelector", "{", "(", "v", "k", ")", "==", ">", "key", "}", "valueSelector", "{", "(", "v", "k", ")", "==", ">", "value", "}", ")", "<p", ">", "Groups", "the", "elements", "of", "a", "sequence", "according", "to", "a", "specified", "key", "selector", "function", "and", "projects", "the", "elements", "for", "each", "group", "by", "using", "a", "specified", "function", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "groupBy", "(", "keySelector", "{", "(", "v", "k", ")", "==", ">", "key", "}", "valueSelector", "{", "(", "v", "k", ")", "==", ">", "value", "}", "resultSelectorValue", "{", "(", "e", "k", ")", "==", ">", "value", "}", "[", "resultSelectorKey", "{", "(", "e", "k", ")", "==", ">", "key", "}", "]", ")", "<p", ">", "Groups", "the", "elements", "of", "a", "sequence", "according", "to", "a", "specified", "key", "selector", "function", "and", "creates", "a", "result", "value", "from", "each", "group", "and", "its", "key", ".", "<p", ">", "For", "all", "overloads", "except", "the", "last", ":", "the", "groupBy", "method", "returns", "a", "sequence", "of", "sequences", "one", "inner", "sequence", "for", "each", "distinct", "key", "that", "was", "encountered", ".", "The", "outer", "sequence", "is", "yielded", "in", "an", "order", "based", "on", "the", "order", "of", "the", "elements", "in", "source", "that", "produced", "the", "first", "key", "of", "each", "inner", "sequence", ".", "Elements", "in", "a", "inner", "sequence", "are", "yielded", "in", "the", "order", "they", "appear", "in", "source", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L354-L363
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.aggregate
public function aggregate($func, $seed = null) { $func = Utils::createLambda($func, 'a,v,k'); $result = $seed; if ($seed !== null) { foreach ($this as $k => $v) { $result = $func($result, $v, $k); } } else { $assigned = false; foreach ($this as $k => $v) { if ($assigned) { $result = $func($result, $v, $k); } else { $result = $v; $assigned = true; } } if (!$assigned) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); } return $result; }
php
public function aggregate($func, $seed = null) { $func = Utils::createLambda($func, 'a,v,k'); $result = $seed; if ($seed !== null) { foreach ($this as $k => $v) { $result = $func($result, $v, $k); } } else { $assigned = false; foreach ($this as $k => $v) { if ($assigned) { $result = $func($result, $v, $k); } else { $result = $v; $assigned = true; } } if (!$assigned) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); } return $result; }
[ "public", "function", "aggregate", "(", "$", "func", ",", "$", "seed", "=", "null", ")", "{", "$", "func", "=", "Utils", "::", "createLambda", "(", "$", "func", ",", "'a,v,k'", ")", ";", "$", "result", "=", "$", "seed", ";", "if", "(", "$", "seed", "!==", "null", ")", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "result", "=", "$", "func", "(", "$", "result", ",", "$", "v", ",", "$", "k", ")", ";", "}", "}", "else", "{", "$", "assigned", "=", "false", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "assigned", ")", "{", "$", "result", "=", "$", "func", "(", "$", "result", ",", "$", "v", ",", "$", "k", ")", ";", "}", "else", "{", "$", "result", "=", "$", "v", ";", "$", "assigned", "=", "true", ";", "}", "}", "if", "(", "!", "$", "assigned", ")", "throw", "new", "\\", "UnexpectedValueException", "(", "Errors", "::", "NO_ELEMENTS", ")", ";", "}", "return", "$", "result", ";", "}" ]
Applies an accumulator function over a sequence. If seed is not null, its value is used as the initial accumulator value. <p><b>Syntax</b>: aggregate (func {(a, v, k) ==> accum} [, seed]) <p>Aggregate method makes it simple to perform a calculation over a sequence of values. This method works by calling func one time for each element in source. Each time func is called, aggregate passes both the element from the sequence and an aggregated value (as the first argument to func). If seed is null, the first element of source is used as the initial aggregate value. The result of func replaces the previous aggregated value. Aggregate returns the final result of func. <p>To simplify common aggregation operations, the standard query operators also include a general purpose count method, {@link count}, and four numeric aggregation methods, namely {@link min}, {@link max}, {@link sum}, and {@link average}. @param callable $func {(a, v, k) ==> accum} An accumulator function to be invoked on each element. @param mixed $seed If seed is not null, the first element is used as seed. Default: null. @throws \UnexpectedValueException If seed is null and sequence contains no elements. @return mixed The final accumulator value. @package YaLinqo\Aggregation
[ "Applies", "an", "accumulator", "function", "over", "a", "sequence", ".", "If", "seed", "is", "not", "null", "its", "value", "is", "used", "as", "the", "initial", "accumulator", "value", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "aggregate", "(", "func", "{", "(", "a", "v", "k", ")", "==", ">", "accum", "}", "[", "seed", "]", ")", "<p", ">", "Aggregate", "method", "makes", "it", "simple", "to", "perform", "a", "calculation", "over", "a", "sequence", "of", "values", ".", "This", "method", "works", "by", "calling", "func", "one", "time", "for", "each", "element", "in", "source", ".", "Each", "time", "func", "is", "called", "aggregate", "passes", "both", "the", "element", "from", "the", "sequence", "and", "an", "aggregated", "value", "(", "as", "the", "first", "argument", "to", "func", ")", ".", "If", "seed", "is", "null", "the", "first", "element", "of", "source", "is", "used", "as", "the", "initial", "aggregate", "value", ".", "The", "result", "of", "func", "replaces", "the", "previous", "aggregated", "value", ".", "Aggregate", "returns", "the", "final", "result", "of", "func", ".", "<p", ">", "To", "simplify", "common", "aggregation", "operations", "the", "standard", "query", "operators", "also", "include", "a", "general", "purpose", "count", "method", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L380-L405
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.aggregateOrDefault
public function aggregateOrDefault($func, $seed = null, $default = null) { $func = Utils::createLambda($func, 'a,v,k'); $result = $seed; $assigned = false; if ($seed !== null) { foreach ($this as $k => $v) { $result = $func($result, $v, $k); $assigned = true; } } else { foreach ($this as $k => $v) { if ($assigned) { $result = $func($result, $v, $k); } else { $result = $v; $assigned = true; } } } return $assigned ? $result : $default; }
php
public function aggregateOrDefault($func, $seed = null, $default = null) { $func = Utils::createLambda($func, 'a,v,k'); $result = $seed; $assigned = false; if ($seed !== null) { foreach ($this as $k => $v) { $result = $func($result, $v, $k); $assigned = true; } } else { foreach ($this as $k => $v) { if ($assigned) { $result = $func($result, $v, $k); } else { $result = $v; $assigned = true; } } } return $assigned ? $result : $default; }
[ "public", "function", "aggregateOrDefault", "(", "$", "func", ",", "$", "seed", "=", "null", ",", "$", "default", "=", "null", ")", "{", "$", "func", "=", "Utils", "::", "createLambda", "(", "$", "func", ",", "'a,v,k'", ")", ";", "$", "result", "=", "$", "seed", ";", "$", "assigned", "=", "false", ";", "if", "(", "$", "seed", "!==", "null", ")", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "result", "=", "$", "func", "(", "$", "result", ",", "$", "v", ",", "$", "k", ")", ";", "$", "assigned", "=", "true", ";", "}", "}", "else", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "assigned", ")", "{", "$", "result", "=", "$", "func", "(", "$", "result", ",", "$", "v", ",", "$", "k", ")", ";", "}", "else", "{", "$", "result", "=", "$", "v", ";", "$", "assigned", "=", "true", ";", "}", "}", "}", "return", "$", "assigned", "?", "$", "result", ":", "$", "default", ";", "}" ]
Applies an accumulator function over a sequence. If seed is not null, its value is used as the initial accumulator value. <p>aggregateOrDefault (func {(a, v, k) ==> accum} [, seed [, default]]) <p>Aggregate method makes it simple to perform a calculation over a sequence of values. This method works by calling func one time for each element in source. Each time func is called, aggregate passes both the element from the sequence and an aggregated value (as the first argument to func). If seed is null, the first element of source is used as the initial aggregate value. The result of func replaces the previous aggregated value. Aggregate returns the final result of func. If source sequence is empty, default is returned. <p>To simplify common aggregation operations, the standard query operators also include a general purpose count method, {@link count}, and four numeric aggregation methods, namely {@link min}, {@link max}, {@link sum}, and {@link average}. @param callable $func {(a, v, k) ==> accum} An accumulator function to be invoked on each element. @param mixed $seed If seed is not null, the first element is used as seed. Default: null. @param mixed $default Value to return if sequence is empty. Default: null. @return mixed The final accumulator value, or default if sequence is empty. @package YaLinqo\Aggregation
[ "Applies", "an", "accumulator", "function", "over", "a", "sequence", ".", "If", "seed", "is", "not", "null", "its", "value", "is", "used", "as", "the", "initial", "accumulator", "value", ".", "<p", ">", "aggregateOrDefault", "(", "func", "{", "(", "a", "v", "k", ")", "==", ">", "accum", "}", "[", "seed", "[", "default", "]]", ")", "<p", ">", "Aggregate", "method", "makes", "it", "simple", "to", "perform", "a", "calculation", "over", "a", "sequence", "of", "values", ".", "This", "method", "works", "by", "calling", "func", "one", "time", "for", "each", "element", "in", "source", ".", "Each", "time", "func", "is", "called", "aggregate", "passes", "both", "the", "element", "from", "the", "sequence", "and", "an", "aggregated", "value", "(", "as", "the", "first", "argument", "to", "func", ")", ".", "If", "seed", "is", "null", "the", "first", "element", "of", "source", "is", "used", "as", "the", "initial", "aggregate", "value", ".", "The", "result", "of", "func", "replaces", "the", "previous", "aggregated", "value", ".", "Aggregate", "returns", "the", "final", "result", "of", "func", ".", "If", "source", "sequence", "is", "empty", "default", "is", "returned", ".", "<p", ">", "To", "simplify", "common", "aggregation", "operations", "the", "standard", "query", "operators", "also", "include", "a", "general", "purpose", "count", "method", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L418-L442
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.average
public function average($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); $sum = $count = 0; foreach ($this as $k => $v) { $sum += $selector($v, $k); $count++; } if ($count === 0) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); return $sum / $count; }
php
public function average($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); $sum = $count = 0; foreach ($this as $k => $v) { $sum += $selector($v, $k); $count++; } if ($count === 0) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); return $sum / $count; }
[ "public", "function", "average", "(", "$", "selector", "=", "null", ")", "{", "$", "selector", "=", "Utils", "::", "createLambda", "(", "$", "selector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "sum", "=", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "sum", "+=", "$", "selector", "(", "$", "v", ",", "$", "k", ")", ";", "$", "count", "++", ";", "}", "if", "(", "$", "count", "===", "0", ")", "throw", "new", "\\", "UnexpectedValueException", "(", "Errors", "::", "NO_ELEMENTS", ")", ";", "return", "$", "sum", "/", "$", "count", ";", "}" ]
Computes the average of a sequence of numeric values. <p><b>Syntax</b>: average () <p>Computes the average of a sequence of numeric values. <p><b>Syntax</b>: average (selector {(v, k) ==> result}) <p>Computes the average of a sequence of numeric values that are obtained by invoking a transform function on each element of the input sequence. @param callable|null $selector {(v, k) ==> result} A transform function to apply to each element. Default: value. @throws \UnexpectedValueException If sequence contains no elements. @return number The average of the sequence of values. @package YaLinqo\Aggregation
[ "Computes", "the", "average", "of", "a", "sequence", "of", "numeric", "values", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "average", "()", "<p", ">", "Computes", "the", "average", "of", "a", "sequence", "of", "numeric", "values", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "average", "(", "selector", "{", "(", "v", "k", ")", "==", ">", "result", "}", ")", "<p", ">", "Computes", "the", "average", "of", "a", "sequence", "of", "numeric", "values", "that", "are", "obtained", "by", "invoking", "a", "transform", "function", "on", "each", "element", "of", "the", "input", "sequence", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L455-L467
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.count
public function count($predicate = null): int { $it = $this->getIterator(); if ($it instanceof \Countable && $predicate === null) return count($it); $predicate = Utils::createLambda($predicate, 'v,k', Functions::$value); $count = 0; foreach ($it as $k => $v) if ($predicate($v, $k)) $count++; return $count; }
php
public function count($predicate = null): int { $it = $this->getIterator(); if ($it instanceof \Countable && $predicate === null) return count($it); $predicate = Utils::createLambda($predicate, 'v,k', Functions::$value); $count = 0; foreach ($it as $k => $v) if ($predicate($v, $k)) $count++; return $count; }
[ "public", "function", "count", "(", "$", "predicate", "=", "null", ")", ":", "int", "{", "$", "it", "=", "$", "this", "->", "getIterator", "(", ")", ";", "if", "(", "$", "it", "instanceof", "\\", "Countable", "&&", "$", "predicate", "===", "null", ")", "return", "count", "(", "$", "it", ")", ";", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "count", "=", "0", ";", "foreach", "(", "$", "it", "as", "$", "k", "=>", "$", "v", ")", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "$", "count", "++", ";", "return", "$", "count", ";", "}" ]
Returns the number of elements in a sequence. <p><b>Syntax</b>: count () <p>If source iterator implements {@link Countable}, that implementation is used to obtain the count of elements. Otherwise, this method determines the count. <p><b>Syntax</b>: count (predicate {(v, k) ==> result}) <p>Returns a number that represents how many elements in the specified sequence satisfy a condition. @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: null. @return int The number of elements in the input sequence. @package YaLinqo\Aggregation
[ "Returns", "the", "number", "of", "elements", "in", "a", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "count", "()", "<p", ">", "If", "source", "iterator", "implements", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L479-L493
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.max
public function max($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); $max = -PHP_INT_MAX; $assigned = false; foreach ($this as $k => $v) { $max = max($max, $selector($v, $k)); $assigned = true; } if (!$assigned) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); return $max; }
php
public function max($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); $max = -PHP_INT_MAX; $assigned = false; foreach ($this as $k => $v) { $max = max($max, $selector($v, $k)); $assigned = true; } if (!$assigned) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); return $max; }
[ "public", "function", "max", "(", "$", "selector", "=", "null", ")", "{", "$", "selector", "=", "Utils", "::", "createLambda", "(", "$", "selector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "max", "=", "-", "PHP_INT_MAX", ";", "$", "assigned", "=", "false", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "max", "=", "max", "(", "$", "max", ",", "$", "selector", "(", "$", "v", ",", "$", "k", ")", ")", ";", "$", "assigned", "=", "true", ";", "}", "if", "(", "!", "$", "assigned", ")", "throw", "new", "\\", "UnexpectedValueException", "(", "Errors", "::", "NO_ELEMENTS", ")", ";", "return", "$", "max", ";", "}" ]
Returns the maximum value in a sequence of values. <p><b>Syntax</b>: max () <p>Returns the maximum value in a sequence of values. <p><b>Syntax</b>: max (selector {(v, k) ==> value}) <p>Invokes a transform function on each element of a sequence and returns the maximum value. @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. @throws \UnexpectedValueException If sequence contains no elements. @return number The maximum value in the sequence. @package YaLinqo\Aggregation
[ "Returns", "the", "maximum", "value", "in", "a", "sequence", "of", "values", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "max", "()", "<p", ">", "Returns", "the", "maximum", "value", "in", "a", "sequence", "of", "values", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "max", "(", "selector", "{", "(", "v", "k", ")", "==", ">", "value", "}", ")", "<p", ">", "Invokes", "a", "transform", "function", "on", "each", "element", "of", "a", "sequence", "and", "returns", "the", "maximum", "value", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L506-L519
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.maxBy
public function maxBy($comparer, $selector = null) { $comparer = Utils::createLambda($comparer, 'a,b', Functions::$compareStrict); $enum = $this; if ($selector !== null) $enum = $enum->select($selector); return $enum->aggregate(function($a, $b) use ($comparer) { return $comparer($a, $b) > 0 ? $a : $b; }); }
php
public function maxBy($comparer, $selector = null) { $comparer = Utils::createLambda($comparer, 'a,b', Functions::$compareStrict); $enum = $this; if ($selector !== null) $enum = $enum->select($selector); return $enum->aggregate(function($a, $b) use ($comparer) { return $comparer($a, $b) > 0 ? $a : $b; }); }
[ "public", "function", "maxBy", "(", "$", "comparer", ",", "$", "selector", "=", "null", ")", "{", "$", "comparer", "=", "Utils", "::", "createLambda", "(", "$", "comparer", ",", "'a,b'", ",", "Functions", "::", "$", "compareStrict", ")", ";", "$", "enum", "=", "$", "this", ";", "if", "(", "$", "selector", "!==", "null", ")", "$", "enum", "=", "$", "enum", "->", "select", "(", "$", "selector", ")", ";", "return", "$", "enum", "->", "aggregate", "(", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "comparer", ")", "{", "return", "$", "comparer", "(", "$", "a", ",", "$", "b", ")", ">", "0", "?", "$", "a", ":", "$", "b", ";", "}", ")", ";", "}" ]
Returns the maximum value in a sequence of values, using specified comparer. <p><b>Syntax</b>: maxBy (comparer {(a, b) ==> diff}) <p>Returns the maximum value in a sequence of values, using specified comparer. <p><b>Syntax</b>: maxBy (comparer {(a, b) ==> diff}, selector {(v, k) ==> value}) <p>Invokes a transform function on each element of a sequence and returns the maximum value, using specified comparer. @param callable $comparer {(a, b) ==> diff} Difference between a and b: &lt;0 if a&lt;b; 0 if a==b; &gt;0 if a&gt;b @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. @throws \UnexpectedValueException If sequence contains no elements. @return number The maximum value in the sequence. @package YaLinqo\Aggregation
[ "Returns", "the", "maximum", "value", "in", "a", "sequence", "of", "values", "using", "specified", "comparer", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "maxBy", "(", "comparer", "{", "(", "a", "b", ")", "==", ">", "diff", "}", ")", "<p", ">", "Returns", "the", "maximum", "value", "in", "a", "sequence", "of", "values", "using", "specified", "comparer", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "maxBy", "(", "comparer", "{", "(", "a", "b", ")", "==", ">", "diff", "}", "selector", "{", "(", "v", "k", ")", "==", ">", "value", "}", ")", "<p", ">", "Invokes", "a", "transform", "function", "on", "each", "element", "of", "a", "sequence", "and", "returns", "the", "maximum", "value", "using", "specified", "comparer", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L533-L541
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.min
public function min($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); $min = PHP_INT_MAX; $assigned = false; foreach ($this as $k => $v) { $min = min($min, $selector($v, $k)); $assigned = true; } if (!$assigned) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); return $min; }
php
public function min($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); $min = PHP_INT_MAX; $assigned = false; foreach ($this as $k => $v) { $min = min($min, $selector($v, $k)); $assigned = true; } if (!$assigned) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); return $min; }
[ "public", "function", "min", "(", "$", "selector", "=", "null", ")", "{", "$", "selector", "=", "Utils", "::", "createLambda", "(", "$", "selector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "min", "=", "PHP_INT_MAX", ";", "$", "assigned", "=", "false", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "min", "=", "min", "(", "$", "min", ",", "$", "selector", "(", "$", "v", ",", "$", "k", ")", ")", ";", "$", "assigned", "=", "true", ";", "}", "if", "(", "!", "$", "assigned", ")", "throw", "new", "\\", "UnexpectedValueException", "(", "Errors", "::", "NO_ELEMENTS", ")", ";", "return", "$", "min", ";", "}" ]
Returns the minimum value in a sequence of values. <p><b>Syntax</b>: min () <p>Returns the minimum value in a sequence of values. <p><b>Syntax</b>: min (selector {(v, k) ==> value}) <p>Invokes a transform function on each element of a sequence and returns the minimum value. @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. @throws \UnexpectedValueException If sequence contains no elements. @return number The minimum value in the sequence. @package YaLinqo\Aggregation
[ "Returns", "the", "minimum", "value", "in", "a", "sequence", "of", "values", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "min", "()", "<p", ">", "Returns", "the", "minimum", "value", "in", "a", "sequence", "of", "values", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "min", "(", "selector", "{", "(", "v", "k", ")", "==", ">", "value", "}", ")", "<p", ">", "Invokes", "a", "transform", "function", "on", "each", "element", "of", "a", "sequence", "and", "returns", "the", "minimum", "value", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L554-L567
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.sum
public function sum($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); $sum = 0; foreach ($this as $k => $v) $sum += $selector($v, $k); return $sum; }
php
public function sum($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); $sum = 0; foreach ($this as $k => $v) $sum += $selector($v, $k); return $sum; }
[ "public", "function", "sum", "(", "$", "selector", "=", "null", ")", "{", "$", "selector", "=", "Utils", "::", "createLambda", "(", "$", "selector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "sum", "=", "0", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "$", "sum", "+=", "$", "selector", "(", "$", "v", ",", "$", "k", ")", ";", "return", "$", "sum", ";", "}" ]
Computes the sum of a sequence of values. <p><b>Syntax</b>: sum () <p>Computes the sum of a sequence of values. <p><b>Syntax</b>: sum (selector {(v, k) ==> result}) <p>Computes the sum of the sequence of values that are obtained by invoking a transform function on each element of the input sequence. <p>This method returns zero if source contains no elements. @param callable|null $selector {(v, k) ==> result} A transform function to apply to each element. @return number The sum of the values in the sequence. @package YaLinqo\Aggregation
[ "Computes", "the", "sum", "of", "a", "sequence", "of", "values", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "sum", "()", "<p", ">", "Computes", "the", "sum", "of", "a", "sequence", "of", "values", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "sum", "(", "selector", "{", "(", "v", "k", ")", "==", ">", "result", "}", ")", "<p", ">", "Computes", "the", "sum", "of", "the", "sequence", "of", "values", "that", "are", "obtained", "by", "invoking", "a", "transform", "function", "on", "each", "element", "of", "the", "input", "sequence", ".", "<p", ">", "This", "method", "returns", "zero", "if", "source", "contains", "no", "elements", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L602-L610
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.all
public function all($predicate): bool { $predicate = Utils::createLambda($predicate, 'v,k'); foreach ($this as $k => $v) { if (!$predicate($v, $k)) return false; } return true; }
php
public function all($predicate): bool { $predicate = Utils::createLambda($predicate, 'v,k'); foreach ($this as $k => $v) { if (!$predicate($v, $k)) return false; } return true; }
[ "public", "function", "all", "(", "$", "predicate", ")", ":", "bool", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ")", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "!", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "return", "false", ";", "}", "return", "true", ";", "}" ]
Determines whether all elements of a sequence satisfy a condition. <p><b>Syntax</b>: all (predicate {(v, k) ==> result}) <p>Determines whether all elements of a sequence satisfy a condition. The enumeration of source is stopped as soon as the result can be determined. @param callable $predicate {(v, k) ==> result} A function to test each element for a condition. @return bool true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false. @package YaLinqo\Sets
[ "Determines", "whether", "all", "elements", "of", "a", "sequence", "satisfy", "a", "condition", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "all", "(", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", ")", "<p", ">", "Determines", "whether", "all", "elements", "of", "a", "sequence", "satisfy", "a", "condition", ".", "The", "enumeration", "of", "source", "is", "stopped", "as", "soon", "as", "the", "result", "can", "be", "determined", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L624-L633
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.any
public function any($predicate = null): bool { $predicate = Utils::createLambda($predicate, 'v,k', false); if ($predicate) { foreach ($this as $k => $v) { if ($predicate($v, $k)) return true; } return false; } else { $it = $this->getIterator(); if ($it instanceof \Countable) return count($it) > 0; $it->rewind(); return $it->valid(); } }
php
public function any($predicate = null): bool { $predicate = Utils::createLambda($predicate, 'v,k', false); if ($predicate) { foreach ($this as $k => $v) { if ($predicate($v, $k)) return true; } return false; } else { $it = $this->getIterator(); if ($it instanceof \Countable) return count($it) > 0; $it->rewind(); return $it->valid(); } }
[ "public", "function", "any", "(", "$", "predicate", "=", "null", ")", ":", "bool", "{", "$", "predicate", "=", "Utils", "::", "createLambda", "(", "$", "predicate", ",", "'v,k'", ",", "false", ")", ";", "if", "(", "$", "predicate", ")", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "predicate", "(", "$", "v", ",", "$", "k", ")", ")", "return", "true", ";", "}", "return", "false", ";", "}", "else", "{", "$", "it", "=", "$", "this", "->", "getIterator", "(", ")", ";", "if", "(", "$", "it", "instanceof", "\\", "Countable", ")", "return", "count", "(", "$", "it", ")", ">", "0", ";", "$", "it", "->", "rewind", "(", ")", ";", "return", "$", "it", "->", "valid", "(", ")", ";", "}", "}" ]
Determines whether a sequence contains any elements. <p><b>Syntax</b>: any () <p>Determines whether a sequence contains any elements. The enumeration of source is stopped as soon as the result can be determined. <p><b>Syntax</b>: any (predicate {(v, k) ==> result}) <p>Determines whether any element of a sequence exists or satisfies a condition. The enumeration of source is stopped as soon as the result can be determined. @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: null. @return bool If predicate is null: true if the source sequence contains any elements; otherwise, false. If predicate is not null: true if any elements in the source sequence pass the test in the specified predicate; otherwise, false. @package YaLinqo\Sets
[ "Determines", "whether", "a", "sequence", "contains", "any", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "any", "()", "<p", ">", "Determines", "whether", "a", "sequence", "contains", "any", "elements", ".", "The", "enumeration", "of", "source", "is", "stopped", "as", "soon", "as", "the", "result", "can", "be", "determined", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "any", "(", "predicate", "{", "(", "v", "k", ")", "==", ">", "result", "}", ")", "<p", ">", "Determines", "whether", "any", "element", "of", "a", "sequence", "exists", "or", "satisfies", "a", "condition", ".", "The", "enumeration", "of", "source", "is", "stopped", "as", "soon", "as", "the", "result", "can", "be", "determined", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L645-L663
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.append
public function append($value, $key = null): Enumerable { return new self(function() use ($value, $key) { yield from $this; yield $key => $value; }); }
php
public function append($value, $key = null): Enumerable { return new self(function() use ($value, $key) { yield from $this; yield $key => $value; }); }
[ "public", "function", "append", "(", "$", "value", ",", "$", "key", "=", "null", ")", ":", "Enumerable", "{", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "value", ",", "$", "key", ")", "{", "yield", "from", "$", "this", ";", "yield", "$", "key", "=>", "$", "value", ";", "}", ")", ";", "}" ]
Appends a value to the end of the sequence. <p><b>Syntax</b>: append (other, value) <p>Appends a value to the end of the sequence with null key. <p><b>Syntax</b>: append (other, value, key) <p>Appends a value to the end of the sequence with the specified key. @param mixed $value The value to append. @param mixed $key The key of the value to append. @return Enumerable A new sequence that ends with the value. @package YaLinqo\Sets
[ "Appends", "a", "value", "to", "the", "end", "of", "the", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "append", "(", "other", "value", ")", "<p", ">", "Appends", "a", "value", "to", "the", "end", "of", "the", "sequence", "with", "null", "key", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "append", "(", "other", "value", "key", ")", "<p", ">", "Appends", "a", "value", "to", "the", "end", "of", "the", "sequence", "with", "the", "specified", "key", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L676-L682
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.concat
public function concat($other): Enumerable { $other = self::from($other); return new self(function() use ($other) { yield from $this; yield from $other; }); }
php
public function concat($other): Enumerable { $other = self::from($other); return new self(function() use ($other) { yield from $this; yield from $other; }); }
[ "public", "function", "concat", "(", "$", "other", ")", ":", "Enumerable", "{", "$", "other", "=", "self", "::", "from", "(", "$", "other", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "other", ")", "{", "yield", "from", "$", "this", ";", "yield", "from", "$", "other", ";", "}", ")", ";", "}" ]
Concatenates two sequences. <p>This method differs from the {@link union} method because the concat method returns all the original elements in the input sequences. The union method returns only unique elements. <p><b>Syntax</b>: concat (other) @param array|\Iterator|\IteratorAggregate|Enumerable $other The sequence to concatenate to the source sequence. @return Enumerable A sequence that contains the concatenated elements of the two input sequences. @package YaLinqo\Sets
[ "Concatenates", "two", "sequences", ".", "<p", ">", "This", "method", "differs", "from", "the", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L692-L700
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.contains
public function contains($value): bool { foreach ($this as $v) { if ($v === $value) return true; } return false; }
php
public function contains($value): bool { foreach ($this as $v) { if ($v === $value) return true; } return false; }
[ "public", "function", "contains", "(", "$", "value", ")", ":", "bool", "{", "foreach", "(", "$", "this", "as", "$", "v", ")", "{", "if", "(", "$", "v", "===", "$", "value", ")", "return", "true", ";", "}", "return", "false", ";", "}" ]
Determines whether a sequence contains a specified element. <p><b>Syntax</b>: contains (value) <p>Determines whether a sequence contains a specified element. Enumeration is terminated as soon as a matching element is found. @param $value mixed The value to locate in the sequence. @return bool true if the source sequence contains an element that has the specified value; otherwise, false. @package YaLinqo\Sets
[ "Determines", "whether", "a", "sequence", "contains", "a", "specified", "element", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "contains", "(", "value", ")", "<p", ">", "Determines", "whether", "a", "sequence", "contains", "a", "specified", "element", ".", "Enumeration", "is", "terminated", "as", "soon", "as", "a", "matching", "element", "is", "found", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L710-L717
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.distinct
public function distinct($keySelector = null): Enumerable { $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$value); return new self(function() use ($keySelector) { $set = []; foreach ($this as $k => $v) { $key = $keySelector($v, $k); if (isset($set[$key])) continue; $set[$key] = true; yield $k => $v; } }); }
php
public function distinct($keySelector = null): Enumerable { $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$value); return new self(function() use ($keySelector) { $set = []; foreach ($this as $k => $v) { $key = $keySelector($v, $k); if (isset($set[$key])) continue; $set[$key] = true; yield $k => $v; } }); }
[ "public", "function", "distinct", "(", "$", "keySelector", "=", "null", ")", ":", "Enumerable", "{", "$", "keySelector", "=", "Utils", "::", "createLambda", "(", "$", "keySelector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "keySelector", ")", "{", "$", "set", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "key", "=", "$", "keySelector", "(", "$", "v", ",", "$", "k", ")", ";", "if", "(", "isset", "(", "$", "set", "[", "$", "key", "]", ")", ")", "continue", ";", "$", "set", "[", "$", "key", "]", "=", "true", ";", "yield", "$", "k", "=>", "$", "v", ";", "}", "}", ")", ";", "}" ]
Returns distinct elements from a sequence. <p>Element keys are values identifying elements. They are used as array keys and are subject to the same rules as array keys, for example, integer 100 and string "100" are considered equal. <p><b>Syntax</b>: distinct () <p>Returns distinct elements from a sequence using values as element keys. <p><b>Syntax</b>: distinct (keySelector {(v, k) ==> value}) <p>Returns distinct elements from a sequence using values produced by keySelector as element keys. @param callable|null $keySelector {(v, k) ==> value} A function to extract the element key from each element. Default: value. @return Enumerable A sequence that contains distinct elements of the input sequence. @package YaLinqo\Sets
[ "Returns", "distinct", "elements", "from", "a", "sequence", ".", "<p", ">", "Element", "keys", "are", "values", "identifying", "elements", ".", "They", "are", "used", "as", "array", "keys", "and", "are", "subject", "to", "the", "same", "rules", "as", "array", "keys", "for", "example", "integer", "100", "and", "string", "100", "are", "considered", "equal", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "distinct", "()", "<p", ">", "Returns", "distinct", "elements", "from", "a", "sequence", "using", "values", "as", "element", "keys", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "distinct", "(", "keySelector", "{", "(", "v", "k", ")", "==", ">", "value", "}", ")", "<p", ">", "Returns", "distinct", "elements", "from", "a", "sequence", "using", "values", "produced", "by", "keySelector", "as", "element", "keys", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L730-L744
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.prepend
public function prepend($value, $key = null): Enumerable { return new self(function() use ($value, $key) { yield $key => $value; yield from $this; }); }
php
public function prepend($value, $key = null): Enumerable { return new self(function() use ($value, $key) { yield $key => $value; yield from $this; }); }
[ "public", "function", "prepend", "(", "$", "value", ",", "$", "key", "=", "null", ")", ":", "Enumerable", "{", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "value", ",", "$", "key", ")", "{", "yield", "$", "key", "=>", "$", "value", ";", "yield", "from", "$", "this", ";", "}", ")", ";", "}" ]
Adds a value to the beginning of the sequence. <p><b>Syntax</b>: prepend (other, value) <p>Adds a value to the beginning of the sequence with null key. <p><b>Syntax</b>: prepend (other, value, key) <p>Adds a value to the beginning of the sequence with the specified key. @param mixed $value The value to prepend. @param mixed $key The key of the value to prepend. @return Enumerable A new sequence that begins with the value. @package YaLinqo\Sets
[ "Adds", "a", "value", "to", "the", "beginning", "of", "the", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "prepend", "(", "other", "value", ")", "<p", ">", "Adds", "a", "value", "to", "the", "beginning", "of", "the", "sequence", "with", "null", "key", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "prepend", "(", "other", "value", "key", ")", "<p", ">", "Adds", "a", "value", "to", "the", "beginning", "of", "the", "sequence", "with", "the", "specified", "key", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L823-L829
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.union
public function union($other, $keySelector = null): Enumerable { $other = self::from($other); $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$value); return new self(function() use ($other, $keySelector) { $set = []; foreach ($this as $k => $v) { $key = $keySelector($v, $k); if (isset($set[$key])) continue; $set[$key] = true; yield $k => $v; } foreach ($other as $k => $v) { $key = $keySelector($v, $k); if (isset($set[$key])) continue; $set[$key] = true; yield $k => $v; } }); }
php
public function union($other, $keySelector = null): Enumerable { $other = self::from($other); $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$value); return new self(function() use ($other, $keySelector) { $set = []; foreach ($this as $k => $v) { $key = $keySelector($v, $k); if (isset($set[$key])) continue; $set[$key] = true; yield $k => $v; } foreach ($other as $k => $v) { $key = $keySelector($v, $k); if (isset($set[$key])) continue; $set[$key] = true; yield $k => $v; } }); }
[ "public", "function", "union", "(", "$", "other", ",", "$", "keySelector", "=", "null", ")", ":", "Enumerable", "{", "$", "other", "=", "self", "::", "from", "(", "$", "other", ")", ";", "$", "keySelector", "=", "Utils", "::", "createLambda", "(", "$", "keySelector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "other", ",", "$", "keySelector", ")", "{", "$", "set", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "key", "=", "$", "keySelector", "(", "$", "v", ",", "$", "k", ")", ";", "if", "(", "isset", "(", "$", "set", "[", "$", "key", "]", ")", ")", "continue", ";", "$", "set", "[", "$", "key", "]", "=", "true", ";", "yield", "$", "k", "=>", "$", "v", ";", "}", "foreach", "(", "$", "other", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "key", "=", "$", "keySelector", "(", "$", "v", ",", "$", "k", ")", ";", "if", "(", "isset", "(", "$", "set", "[", "$", "key", "]", ")", ")", "continue", ";", "$", "set", "[", "$", "key", "]", "=", "true", ";", "yield", "$", "k", "=>", "$", "v", ";", "}", "}", ")", ";", "}" ]
Produces the set union of two sequences. <p>Element keys are values identifying elements. They are used as array keys and are subject to the same rules as array keys, for example, integer 100 and string "100" are considered equal. <p>This method excludes duplicates from the return set. This is different behavior to the {@link concat} method, which returns all the elements in the input sequences including duplicates. <p><b>Syntax</b>: union (other) <p>Produces the set union of two sequences using values as element keys. <p><b>Syntax</b>: union (other, keySelector {(v, k) ==> value}) <p>Produces the set union of two sequences using values produced by keySelector as element keys. @param array|\Iterator|\IteratorAggregate|Enumerable $other A sequence whose distinct elements form the second set for the union. @param callable|null $keySelector {(v, k) ==> key} A function to extract the element key from each element. Default: value. @return Enumerable A sequence that contains the elements from both input sequences, excluding duplicates. @package YaLinqo\Sets
[ "Produces", "the", "set", "union", "of", "two", "sequences", ".", "<p", ">", "Element", "keys", "are", "values", "identifying", "elements", ".", "They", "are", "used", "as", "array", "keys", "and", "are", "subject", "to", "the", "same", "rules", "as", "array", "keys", "for", "example", "integer", "100", "and", "string", "100", "are", "considered", "equal", ".", "<p", ">", "This", "method", "excludes", "duplicates", "from", "the", "return", "set", ".", "This", "is", "different", "behavior", "to", "the", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L844-L866
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.toArray
public function toArray(): array { /** @var $it \Iterator|\ArrayIterator */ $it = $this->getIterator(); if ($it instanceof \ArrayIterator) return $it->getArrayCopy(); $array = []; foreach ($it as $k => $v) $array[$k] = $v; return $array; }
php
public function toArray(): array { /** @var $it \Iterator|\ArrayIterator */ $it = $this->getIterator(); if ($it instanceof \ArrayIterator) return $it->getArrayCopy(); $array = []; foreach ($it as $k => $v) $array[$k] = $v; return $array; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "/** @var $it \\Iterator|\\ArrayIterator */", "$", "it", "=", "$", "this", "->", "getIterator", "(", ")", ";", "if", "(", "$", "it", "instanceof", "\\", "ArrayIterator", ")", "return", "$", "it", "->", "getArrayCopy", "(", ")", ";", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "it", "as", "$", "k", "=>", "$", "v", ")", "$", "array", "[", "$", "k", "]", "=", "$", "v", ";", "return", "$", "array", ";", "}" ]
Creates an array from a sequence. <p><b>Syntax</b>: toArray () <p>The toArray method forces immediate query evaluation and returns an array that contains the query results. <p>The toArray method does not traverse into elements of the sequence, only the sequence itself is converted. That is, if elements of the sequence are {@link Traversable} or arrays containing Traversable values, they will remain as is. To traverse deeply, you can use {@link toArrayDeep} method. <p>Keys from the sequence are preserved. If the source sequence contains multiple values with the same key, the result array will only contain the latter value. To discard keys, you can use {@link toList} method. To preserve all values and keys, you can use {@link toLookup} method. @return array An array that contains the elements from the input sequence. @package YaLinqo\Conversion
[ "Creates", "an", "array", "from", "a", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "toArray", "()", "<p", ">", "The", "toArray", "method", "forces", "immediate", "query", "evaluation", "and", "returns", "an", "array", "that", "contains", "the", "query", "results", ".", "<p", ">", "The", "toArray", "method", "does", "not", "traverse", "into", "elements", "of", "the", "sequence", "only", "the", "sequence", "itself", "is", "converted", ".", "That", "is", "if", "elements", "of", "the", "sequence", "are", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L881-L892
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.toArrayDeepProc
protected function toArrayDeepProc($enum): array { $array = []; foreach ($enum as $k => $v) $array[$k] = $v instanceof \Traversable || is_array($v) ? $this->toArrayDeepProc($v) : $v; return $array; }
php
protected function toArrayDeepProc($enum): array { $array = []; foreach ($enum as $k => $v) $array[$k] = $v instanceof \Traversable || is_array($v) ? $this->toArrayDeepProc($v) : $v; return $array; }
[ "protected", "function", "toArrayDeepProc", "(", "$", "enum", ")", ":", "array", "{", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "enum", "as", "$", "k", "=>", "$", "v", ")", "$", "array", "[", "$", "k", "]", "=", "$", "v", "instanceof", "\\", "Traversable", "||", "is_array", "(", "$", "v", ")", "?", "$", "this", "->", "toArrayDeepProc", "(", "$", "v", ")", ":", "$", "v", ";", "return", "$", "array", ";", "}" ]
Proc for {@link toArrayDeep}. @param $enum \Traversable Source sequence. @return array An array that contains the elements from the input sequence. @package YaLinqo\Conversion
[ "Proc", "for", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L914-L920
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.toList
public function toList(): array { /** @var $it \Iterator|\ArrayIterator */ $it = $this->getIterator(); if ($it instanceof \ArrayIterator) return array_values($it->getArrayCopy()); $array = []; foreach ($it as $v) $array[] = $v; return $array; }
php
public function toList(): array { /** @var $it \Iterator|\ArrayIterator */ $it = $this->getIterator(); if ($it instanceof \ArrayIterator) return array_values($it->getArrayCopy()); $array = []; foreach ($it as $v) $array[] = $v; return $array; }
[ "public", "function", "toList", "(", ")", ":", "array", "{", "/** @var $it \\Iterator|\\ArrayIterator */", "$", "it", "=", "$", "this", "->", "getIterator", "(", ")", ";", "if", "(", "$", "it", "instanceof", "\\", "ArrayIterator", ")", "return", "array_values", "(", "$", "it", "->", "getArrayCopy", "(", ")", ")", ";", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "it", "as", "$", "v", ")", "$", "array", "[", "]", "=", "$", "v", ";", "return", "$", "array", ";", "}" ]
Creates an array from a sequence, with sequental integer keys. <p><b>Syntax</b>: toList () <p>The toList method forces immediate query evaluation and returns an array that contains the query results. <p>The toList method does not traverse into elements of the sequence, only the sequence itself is converted. That is, if elements of the sequence are {@link Traversable} or arrays containing Traversable values, they will remain as is. To traverse deeply, you can use {@link toListDeep} method. <p>Keys from the sequence are discarded. To preserve keys and lose values with the same keys, you can use {@link toArray} method. To preserve all values and keys, you can use {@link toLookup} method. @return array An array that contains the elements from the input sequence. @package YaLinqo\Conversion
[ "Creates", "an", "array", "from", "a", "sequence", "with", "sequental", "integer", "keys", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "toList", "()", "<p", ">", "The", "toList", "method", "forces", "immediate", "query", "evaluation", "and", "returns", "an", "array", "that", "contains", "the", "query", "results", ".", "<p", ">", "The", "toList", "method", "does", "not", "traverse", "into", "elements", "of", "the", "sequence", "only", "the", "sequence", "itself", "is", "converted", ".", "That", "is", "if", "elements", "of", "the", "sequence", "are", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L931-L942
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.toListDeepProc
protected function toListDeepProc($enum): array { $array = []; foreach ($enum as $v) $array[] = $v instanceof \Traversable || is_array($v) ? $this->toListDeepProc($v) : $v; return $array; }
php
protected function toListDeepProc($enum): array { $array = []; foreach ($enum as $v) $array[] = $v instanceof \Traversable || is_array($v) ? $this->toListDeepProc($v) : $v; return $array; }
[ "protected", "function", "toListDeepProc", "(", "$", "enum", ")", ":", "array", "{", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "enum", "as", "$", "v", ")", "$", "array", "[", "]", "=", "$", "v", "instanceof", "\\", "Traversable", "||", "is_array", "(", "$", "v", ")", "?", "$", "this", "->", "toListDeepProc", "(", "$", "v", ")", ":", "$", "v", ";", "return", "$", "array", ";", "}" ]
Proc for {@link toListDeep}. @param $enum \Traversable Source sequence. @return array An array that contains the elements from the input sequence. @package YaLinqo\Conversion
[ "Proc", "for", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L964-L970
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.toDictionary
public function toDictionary($keySelector = null, $valueSelector = null): array { $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$key); $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value); $dic = []; foreach ($this as $k => $v) $dic[$keySelector($v, $k)] = $valueSelector($v, $k); return $dic; }
php
public function toDictionary($keySelector = null, $valueSelector = null): array { $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$key); $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value); $dic = []; foreach ($this as $k => $v) $dic[$keySelector($v, $k)] = $valueSelector($v, $k); return $dic; }
[ "public", "function", "toDictionary", "(", "$", "keySelector", "=", "null", ",", "$", "valueSelector", "=", "null", ")", ":", "array", "{", "$", "keySelector", "=", "Utils", "::", "createLambda", "(", "$", "keySelector", ",", "'v,k'", ",", "Functions", "::", "$", "key", ")", ";", "$", "valueSelector", "=", "Utils", "::", "createLambda", "(", "$", "valueSelector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "dic", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "$", "dic", "[", "$", "keySelector", "(", "$", "v", ",", "$", "k", ")", "]", "=", "$", "valueSelector", "(", "$", "v", ",", "$", "k", ")", ";", "return", "$", "dic", ";", "}" ]
Creates an array from a sequence according to specified key selector and value selector functions. <p><b>Syntax</b>: toDictionary ([keySelector {(v, k) ==> key} [, valueSelector {(v, k) ==> value}]]) <p>The toDictionary method returns an array, a one-to-one dictionary that maps keys to values. If the source sequence contains multiple values with the same key, the result array will only contain the latter value. @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from each element. Default: key. @param callable|null $valueSelector {(v, k) ==> value} A transform function to produce a result value from each element. Default: value. @return array An array that contains keys and values selected from the input sequence. @package YaLinqo\Conversion
[ "Creates", "an", "array", "from", "a", "sequence", "according", "to", "specified", "key", "selector", "and", "value", "selector", "functions", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "toDictionary", "(", "[", "keySelector", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "valueSelector", "{", "(", "v", "k", ")", "==", ">", "value", "}", "]]", ")", "<p", ">", "The", "toDictionary", "method", "returns", "an", "array", "a", "one", "-", "to", "-", "one", "dictionary", "that", "maps", "keys", "to", "values", ".", "If", "the", "source", "sequence", "contains", "multiple", "values", "with", "the", "same", "key", "the", "result", "array", "will", "only", "contain", "the", "latter", "value", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L981-L990
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.toLookup
public function toLookup($keySelector = null, $valueSelector = null): array { $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$key); $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value); $lookup = []; foreach ($this as $k => $v) $lookup[$keySelector($v, $k)][] = $valueSelector($v, $k); return $lookup; }
php
public function toLookup($keySelector = null, $valueSelector = null): array { $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$key); $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value); $lookup = []; foreach ($this as $k => $v) $lookup[$keySelector($v, $k)][] = $valueSelector($v, $k); return $lookup; }
[ "public", "function", "toLookup", "(", "$", "keySelector", "=", "null", ",", "$", "valueSelector", "=", "null", ")", ":", "array", "{", "$", "keySelector", "=", "Utils", "::", "createLambda", "(", "$", "keySelector", ",", "'v,k'", ",", "Functions", "::", "$", "key", ")", ";", "$", "valueSelector", "=", "Utils", "::", "createLambda", "(", "$", "valueSelector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "lookup", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "$", "lookup", "[", "$", "keySelector", "(", "$", "v", ",", "$", "k", ")", "]", "[", "]", "=", "$", "valueSelector", "(", "$", "v", ",", "$", "k", ")", ";", "return", "$", "lookup", ";", "}" ]
Creates an array from a sequence according to specified key selector and value selector functions. <p><b>Syntax</b>: toLookup ([keySelector {(v, k) ==> key} [, valueSelector {(v, k) ==> value}]]) <p>The toLookup method returns an array, a one-to-many dictionary that maps keys to arrays of values. @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from each element. Default: key. @param callable|null $valueSelector {(v, k) ==> value} A transform function to produce a result value from each element. Default: value. @return array An array that contains keys and value arrays selected from the input sequence. @package YaLinqo\Conversion
[ "Creates", "an", "array", "from", "a", "sequence", "according", "to", "specified", "key", "selector", "and", "value", "selector", "functions", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "toLookup", "(", "[", "keySelector", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "valueSelector", "{", "(", "v", "k", ")", "==", ">", "value", "}", "]]", ")", "<p", ">", "The", "toLookup", "method", "returns", "an", "array", "a", "one", "-", "to", "-", "many", "dictionary", "that", "maps", "keys", "to", "arrays", "of", "values", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L1015-L1024
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.toObject
public function toObject($propertySelector = null, $valueSelector = null): \stdClass { $propertySelector = Utils::createLambda($propertySelector, 'v,k', Functions::$key); $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value); $obj = new \stdClass(); foreach ($this as $k => $v) $obj->{$propertySelector($v, $k)} = $valueSelector($v, $k); return $obj; }
php
public function toObject($propertySelector = null, $valueSelector = null): \stdClass { $propertySelector = Utils::createLambda($propertySelector, 'v,k', Functions::$key); $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value); $obj = new \stdClass(); foreach ($this as $k => $v) $obj->{$propertySelector($v, $k)} = $valueSelector($v, $k); return $obj; }
[ "public", "function", "toObject", "(", "$", "propertySelector", "=", "null", ",", "$", "valueSelector", "=", "null", ")", ":", "\\", "stdClass", "{", "$", "propertySelector", "=", "Utils", "::", "createLambda", "(", "$", "propertySelector", ",", "'v,k'", ",", "Functions", "::", "$", "key", ")", ";", "$", "valueSelector", "=", "Utils", "::", "createLambda", "(", "$", "valueSelector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "obj", "=", "new", "\\", "stdClass", "(", ")", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "$", "obj", "->", "{", "$", "propertySelector", "(", "$", "v", ",", "$", "k", ")", "}", "=", "$", "valueSelector", "(", "$", "v", ",", "$", "k", ")", ";", "return", "$", "obj", ";", "}" ]
Transform the sequence to an object. <p><b>Syntax</b>: toObject ([propertySelector {(v, k) ==> name} [, valueSelector {(v, k) ==> value}]]) @param callable|null $propertySelector {(v, k) ==> name} A function to extract a property name from an element. Must return a valid PHP identifier. Default: key. @param callable|null $valueSelector {(v, k) ==> value} A function to extract a property value from an element. Default: value. @return \stdClass @package YaLinqo\Conversion
[ "Transform", "the", "sequence", "to", "an", "object", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "toObject", "(", "[", "propertySelector", "{", "(", "v", "k", ")", "==", ">", "name", "}", "[", "valueSelector", "{", "(", "v", "k", ")", "==", ">", "value", "}", "]]", ")" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L1058-L1067
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.toString
public function toString(string $separator = '', $valueSelector = null): string { $valueSelector = Utils::createLambda($valueSelector, 'v,k', false); $array = $valueSelector ? $this->select($valueSelector)->toList() : $this->toList(); return implode($separator, $array); }
php
public function toString(string $separator = '', $valueSelector = null): string { $valueSelector = Utils::createLambda($valueSelector, 'v,k', false); $array = $valueSelector ? $this->select($valueSelector)->toList() : $this->toList(); return implode($separator, $array); }
[ "public", "function", "toString", "(", "string", "$", "separator", "=", "''", ",", "$", "valueSelector", "=", "null", ")", ":", "string", "{", "$", "valueSelector", "=", "Utils", "::", "createLambda", "(", "$", "valueSelector", ",", "'v,k'", ",", "false", ")", ";", "$", "array", "=", "$", "valueSelector", "?", "$", "this", "->", "select", "(", "$", "valueSelector", ")", "->", "toList", "(", ")", ":", "$", "this", "->", "toList", "(", ")", ";", "return", "implode", "(", "$", "separator", ",", "$", "array", ")", ";", "}" ]
Returns a string containing a string representation of all the sequence values, with the separator string between each element. <p><b>Syntax</b>: toString ([separator [, selector]]) @param string $separator A string separating values in the result string. Default: ''. @param callable|null $valueSelector {(v, k) ==> value} A transform function to apply to each element. Default: value. @return string @see implode @package YaLinqo\Conversion
[ "Returns", "a", "string", "containing", "a", "string", "representation", "of", "all", "the", "sequence", "values", "with", "the", "separator", "string", "between", "each", "element", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "toString", "(", "[", "separator", "[", "selector", "]]", ")" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L1078-L1083
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.call
public function call($action): Enumerable { $action = Utils::createLambda($action, 'v,k'); return new self(function() use ($action) { foreach ($this as $k => $v) { $action($v, $k); yield $k => $v; } }); }
php
public function call($action): Enumerable { $action = Utils::createLambda($action, 'v,k'); return new self(function() use ($action) { foreach ($this as $k => $v) { $action($v, $k); yield $k => $v; } }); }
[ "public", "function", "call", "(", "$", "action", ")", ":", "Enumerable", "{", "$", "action", "=", "Utils", "::", "createLambda", "(", "$", "action", ",", "'v,k'", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "action", ")", "{", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "action", "(", "$", "v", ",", "$", "k", ")", ";", "yield", "$", "k", "=>", "$", "v", ";", "}", "}", ")", ";", "}" ]
Invokes an action for each element in the sequence. <p><b>Syntax</b>: process (action {(v, k) ==> void}) <p>Process method does not start enumeration itself. To force enumeration, you can use {@link each} method. <p>Original LINQ method name: do. @param callable $action {(v, k) ==> void} The action to invoke for each element in the sequence. @return Enumerable The source sequence with the side-effecting behavior applied. @package YaLinqo\Actions
[ "Invokes", "an", "action", "for", "each", "element", "in", "the", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "process", "(", "action", "{", "(", "v", "k", ")", "==", ">", "void", "}", ")", "<p", ">", "Process", "method", "does", "not", "start", "enumeration", "itself", ".", "To", "force", "enumeration", "you", "can", "use", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L1098-L1108
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.each
public function each($action = null) { $action = Utils::createLambda($action, 'v,k', Functions::$blank); foreach ($this as $k => $v) $action($v, $k); }
php
public function each($action = null) { $action = Utils::createLambda($action, 'v,k', Functions::$blank); foreach ($this as $k => $v) $action($v, $k); }
[ "public", "function", "each", "(", "$", "action", "=", "null", ")", "{", "$", "action", "=", "Utils", "::", "createLambda", "(", "$", "action", ",", "'v,k'", ",", "Functions", "::", "$", "blank", ")", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "$", "action", "(", "$", "v", ",", "$", "k", ")", ";", "}" ]
Invokes an action for each element in the sequence. <p><b>Syntax</b>: each (action {(v, k) ==> void}) <p>Each method forces enumeration. To just add side-effect without enumerating, you can use {@link process} method. <p>Original LINQ method name: foreach. @param callable $action {(v, k) ==> void} The action to invoke for each element in the sequence. @package YaLinqo\Actions
[ "Invokes", "an", "action", "for", "each", "element", "in", "the", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "each", "(", "action", "{", "(", "v", "k", ")", "==", ">", "void", "}", ")", "<p", ">", "Each", "method", "forces", "enumeration", ".", "To", "just", "add", "side", "-", "effect", "without", "enumerating", "you", "can", "use", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L1118-L1124
Athari/YaLinqo
YaLinqo/Enumerable.php
Enumerable.writeLine
public function writeLine($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); foreach ($this as $k => $v) { echo $selector($v, $k), PHP_EOL; } }
php
public function writeLine($selector = null) { $selector = Utils::createLambda($selector, 'v,k', Functions::$value); foreach ($this as $k => $v) { echo $selector($v, $k), PHP_EOL; } }
[ "public", "function", "writeLine", "(", "$", "selector", "=", "null", ")", "{", "$", "selector", "=", "Utils", "::", "createLambda", "(", "$", "selector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "foreach", "(", "$", "this", "as", "$", "k", "=>", "$", "v", ")", "{", "echo", "$", "selector", "(", "$", "v", ",", "$", "k", ")", ",", "PHP_EOL", ";", "}", "}" ]
Output all the sequence values, with a new line after each element. <p><b>Syntax</b>: writeLine ([selector]) @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. @return string @see echo, PHP_EOL @package YaLinqo\Actions
[ "Output", "all", "the", "sequence", "values", "with", "a", "new", "line", "after", "each", "element", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "writeLine", "(", "[", "selector", "]", ")" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/Enumerable.php#L1147-L1154
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.cycle
public static function cycle($source): Enumerable { $source = self::from($source); return new self(function() use ($source) { $isEmpty = true; while (true) { foreach ($source as $v) { yield $v; $isEmpty = false; } if ($isEmpty) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); } }); }
php
public static function cycle($source): Enumerable { $source = self::from($source); return new self(function() use ($source) { $isEmpty = true; while (true) { foreach ($source as $v) { yield $v; $isEmpty = false; } if ($isEmpty) throw new \UnexpectedValueException(Errors::NO_ELEMENTS); } }); }
[ "public", "static", "function", "cycle", "(", "$", "source", ")", ":", "Enumerable", "{", "$", "source", "=", "self", "::", "from", "(", "$", "source", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "source", ")", "{", "$", "isEmpty", "=", "true", ";", "while", "(", "true", ")", "{", "foreach", "(", "$", "source", "as", "$", "v", ")", "{", "yield", "$", "v", ";", "$", "isEmpty", "=", "false", ";", "}", "if", "(", "$", "isEmpty", ")", "throw", "new", "\\", "UnexpectedValueException", "(", "Errors", "::", "NO_ELEMENTS", ")", ";", "}", "}", ")", ";", "}" ]
Cycles through the source sequence. <p><b>Syntax</b>: cycle (source) <p>Source keys are discarded. @param array|\Iterator|\IteratorAggregate|Enumerable $source Source sequence. @throws \InvalidArgumentException If source is not array or Traversible or Enumerable. @throws \UnexpectedValueException If source contains no elements (checked during enumeration). @return Enumerable Endless list of items repeating the source sequence. @package YaLinqo\Generation
[ "Cycles", "through", "the", "source", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "cycle", "(", "source", ")", "<p", ">", "Source", "keys", "are", "discarded", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L28-L43
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.from
public static function from($source): Enumerable { $it = null; if ($source instanceof Enumerable) return $source; elseif (is_array($source)) $it = new \ArrayIterator($source); elseif ($source instanceof \IteratorAggregate) $it = $source->getIterator(); elseif ($source instanceof \Traversable) $it = $source; if ($it !== null) { return new self($it, false); } throw new \InvalidArgumentException('source must be array or Traversable.'); }
php
public static function from($source): Enumerable { $it = null; if ($source instanceof Enumerable) return $source; elseif (is_array($source)) $it = new \ArrayIterator($source); elseif ($source instanceof \IteratorAggregate) $it = $source->getIterator(); elseif ($source instanceof \Traversable) $it = $source; if ($it !== null) { return new self($it, false); } throw new \InvalidArgumentException('source must be array or Traversable.'); }
[ "public", "static", "function", "from", "(", "$", "source", ")", ":", "Enumerable", "{", "$", "it", "=", "null", ";", "if", "(", "$", "source", "instanceof", "Enumerable", ")", "return", "$", "source", ";", "elseif", "(", "is_array", "(", "$", "source", ")", ")", "$", "it", "=", "new", "\\", "ArrayIterator", "(", "$", "source", ")", ";", "elseif", "(", "$", "source", "instanceof", "\\", "IteratorAggregate", ")", "$", "it", "=", "$", "source", "->", "getIterator", "(", ")", ";", "elseif", "(", "$", "source", "instanceof", "\\", "Traversable", ")", "$", "it", "=", "$", "source", ";", "if", "(", "$", "it", "!==", "null", ")", "{", "return", "new", "self", "(", "$", "it", ",", "false", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'source must be array or Traversable.'", ")", ";", "}" ]
Converts source into Enumerable sequence. <p><b>Syntax</b>: from (source) <p>Result depends on the type of source: <ul> <li><b>array</b>: Enumerable from ArrayIterator; <li><b>Enumerable</b>: Enumerable source itself; <li><b>Iterator</b>: Enumerable from Iterator; <li><b>IteratorAggregate</b>: Enumerable from Iterator returned from getIterator() method; <li><b>Traversable</b>: Enumerable from the result of foreach over source. </ul> @param array|\Iterator|\IteratorAggregate|\Traversable|Enumerable $source Value to convert into Enumerable sequence. @throws \InvalidArgumentException If source is not array or Traversible or Enumerable. @return Enumerable @package YaLinqo\Generation
[ "Converts", "source", "into", "Enumerable", "sequence", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "from", "(", "source", ")", "<p", ">", "Result", "depends", "on", "the", "type", "of", "source", ":", "<ul", ">", "<li", ">", "<b", ">", "array<", "/", "b", ">", ":", "Enumerable", "from", "ArrayIterator", ";", "<li", ">", "<b", ">", "Enumerable<", "/", "b", ">", ":", "Enumerable", "source", "itself", ";", "<li", ">", "<b", ">", "Iterator<", "/", "b", ">", ":", "Enumerable", "from", "Iterator", ";", "<li", ">", "<b", ">", "IteratorAggregate<", "/", "b", ">", ":", "Enumerable", "from", "Iterator", "returned", "from", "getIterator", "()", "method", ";", "<li", ">", "<b", ">", "Traversable<", "/", "b", ">", ":", "Enumerable", "from", "the", "result", "of", "foreach", "over", "source", ".", "<", "/", "ul", ">" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L72-L87
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.generate
public static function generate($funcValue, $seedValue = null, $funcKey = null, $seedKey = null): Enumerable { $funcValue = Utils::createLambda($funcValue, 'v,k'); $funcKey = Utils::createLambda($funcKey, 'v,k', false); return new self(function() use ($funcValue, $funcKey, $seedValue, $seedKey) { $key = $seedKey === null ? ($funcKey ? $funcKey($seedValue, $seedKey) : 0) : $seedKey; $value = $seedValue === null ? $funcValue($seedValue, $seedKey) : $seedValue; yield $key => $value; while (true) { list($value, $key) = [ $funcValue($value, $key), $funcKey ? $funcKey($value, $key) : $key + 1, ]; yield $key => $value; } }); }
php
public static function generate($funcValue, $seedValue = null, $funcKey = null, $seedKey = null): Enumerable { $funcValue = Utils::createLambda($funcValue, 'v,k'); $funcKey = Utils::createLambda($funcKey, 'v,k', false); return new self(function() use ($funcValue, $funcKey, $seedValue, $seedKey) { $key = $seedKey === null ? ($funcKey ? $funcKey($seedValue, $seedKey) : 0) : $seedKey; $value = $seedValue === null ? $funcValue($seedValue, $seedKey) : $seedValue; yield $key => $value; while (true) { list($value, $key) = [ $funcValue($value, $key), $funcKey ? $funcKey($value, $key) : $key + 1, ]; yield $key => $value; } }); }
[ "public", "static", "function", "generate", "(", "$", "funcValue", ",", "$", "seedValue", "=", "null", ",", "$", "funcKey", "=", "null", ",", "$", "seedKey", "=", "null", ")", ":", "Enumerable", "{", "$", "funcValue", "=", "Utils", "::", "createLambda", "(", "$", "funcValue", ",", "'v,k'", ")", ";", "$", "funcKey", "=", "Utils", "::", "createLambda", "(", "$", "funcKey", ",", "'v,k'", ",", "false", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "funcValue", ",", "$", "funcKey", ",", "$", "seedValue", ",", "$", "seedKey", ")", "{", "$", "key", "=", "$", "seedKey", "===", "null", "?", "(", "$", "funcKey", "?", "$", "funcKey", "(", "$", "seedValue", ",", "$", "seedKey", ")", ":", "0", ")", ":", "$", "seedKey", ";", "$", "value", "=", "$", "seedValue", "===", "null", "?", "$", "funcValue", "(", "$", "seedValue", ",", "$", "seedKey", ")", ":", "$", "seedValue", ";", "yield", "$", "key", "=>", "$", "value", ";", "while", "(", "true", ")", "{", "list", "(", "$", "value", ",", "$", "key", ")", "=", "[", "$", "funcValue", "(", "$", "value", ",", "$", "key", ")", ",", "$", "funcKey", "?", "$", "funcKey", "(", "$", "value", ",", "$", "key", ")", ":", "$", "key", "+", "1", ",", "]", ";", "yield", "$", "key", "=>", "$", "value", ";", "}", "}", ")", ";", "}" ]
Generates a sequence by mimicking a for loop. <p><b>Syntax</b>: generate (funcValue {(v, k) ==> value} [, seedValue [, funcKey {(v, k) ==> key} [, seedKey]]]) <p>If seedValue is null, the first value will be the result of calling funcValue on seedValue and seedKey. The same applies for seedKey. @param callable $funcValue {(v, k) ==> value} State update function to run on value after every iteration of the generator loop. Default: value. @param mixed $seedValue Initial state of the generator loop for values. Default: null. @param callable|null $funcKey {(v, k) ==> key} State update function to run on key after every iteration of the generator loop. Default: increment. @param mixed $seedKey Initial state of the generator loop ofr keys. Default: 0. @return Enumerable @package YaLinqo\Generation
[ "Generates", "a", "sequence", "by", "mimicking", "a", "for", "loop", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "generate", "(", "funcValue", "{", "(", "v", "k", ")", "==", ">", "value", "}", "[", "seedValue", "[", "funcKey", "{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "seedKey", "]]]", ")", "<p", ">", "If", "seedValue", "is", "null", "the", "first", "value", "will", "be", "the", "result", "of", "calling", "funcValue", "on", "seedValue", "and", "seedKey", ".", "The", "same", "applies", "for", "seedKey", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L100-L117
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.toInfinity
public static function toInfinity(int $start = 0, int $step = 1): Enumerable { return new self(function() use ($start, $step) { $value = $start - $step; while (true) yield $value += $step; }); }
php
public static function toInfinity(int $start = 0, int $step = 1): Enumerable { return new self(function() use ($start, $step) { $value = $start - $step; while (true) yield $value += $step; }); }
[ "public", "static", "function", "toInfinity", "(", "int", "$", "start", "=", "0", ",", "int", "$", "step", "=", "1", ")", ":", "Enumerable", "{", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "start", ",", "$", "step", ")", "{", "$", "value", "=", "$", "start", "-", "$", "step", ";", "while", "(", "true", ")", "yield", "$", "value", "+=", "$", "step", ";", "}", ")", ";", "}" ]
Generates a sequence of integral numbers to infinity. <p><b>Syntax</b>: toInfinity ([start [, step]]) @param int $start The first integer in the sequence. Default: 0. @param int $step The difference between adjacent integers. Default: 1. @return Enumerable @package YaLinqo\Generation
[ "Generates", "a", "sequence", "of", "integral", "numbers", "to", "infinity", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "toInfinity", "(", "[", "start", "[", "step", "]]", ")" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L127-L134
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.matches
public static function matches(string $subject, string $pattern, int $flags = PREG_SET_ORDER): Enumerable { return new self(function() use ($subject, $pattern, $flags) { preg_match_all($pattern, $subject, $matches, $flags); return $matches !== false ? self::from($matches)->getIterator() : self::emptyEnum(); }); }
php
public static function matches(string $subject, string $pattern, int $flags = PREG_SET_ORDER): Enumerable { return new self(function() use ($subject, $pattern, $flags) { preg_match_all($pattern, $subject, $matches, $flags); return $matches !== false ? self::from($matches)->getIterator() : self::emptyEnum(); }); }
[ "public", "static", "function", "matches", "(", "string", "$", "subject", ",", "string", "$", "pattern", ",", "int", "$", "flags", "=", "PREG_SET_ORDER", ")", ":", "Enumerable", "{", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "subject", ",", "$", "pattern", ",", "$", "flags", ")", "{", "preg_match_all", "(", "$", "pattern", ",", "$", "subject", ",", "$", "matches", ",", "$", "flags", ")", ";", "return", "$", "matches", "!==", "false", "?", "self", "::", "from", "(", "$", "matches", ")", "->", "getIterator", "(", ")", ":", "self", "::", "emptyEnum", "(", ")", ";", "}", ")", ";", "}" ]
Searches subject for all matches to the regular expression given in pattern and enumerates them in the order specified by flags. After the first match is found, the subsequent searches are continued on from end of the last match. <p><b>Syntax</b>: matches (subject, pattern [, flags]) @param string $subject The input string. @param string $pattern The pattern to search for, as a string. @param int $flags Can be a combination of the following flags: PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_OFFSET_CAPTURE. Default: PREG_SET_ORDER. @return Enumerable @see preg_match_all @package YaLinqo\Generation
[ "Searches", "subject", "for", "all", "matches", "to", "the", "regular", "expression", "given", "in", "pattern", "and", "enumerates", "them", "in", "the", "order", "specified", "by", "flags", ".", "After", "the", "first", "match", "is", "found", "the", "subsequent", "searches", "are", "continued", "on", "from", "end", "of", "the", "last", "match", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "matches", "(", "subject", "pattern", "[", "flags", "]", ")" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L146-L152
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.toNegativeInfinity
public static function toNegativeInfinity(int $start = 0, int $step = 1): Enumerable { return self::toInfinity($start, -$step); }
php
public static function toNegativeInfinity(int $start = 0, int $step = 1): Enumerable { return self::toInfinity($start, -$step); }
[ "public", "static", "function", "toNegativeInfinity", "(", "int", "$", "start", "=", "0", ",", "int", "$", "step", "=", "1", ")", ":", "Enumerable", "{", "return", "self", "::", "toInfinity", "(", "$", "start", ",", "-", "$", "step", ")", ";", "}" ]
Generates a sequence of integral numbers to negative infinity. <p><b>Syntax</b>: toNegativeInfinity ([start [, step]]) @param int $start The first integer in the sequence. Default: 0. @param int $step The difference between adjacent integers. Default: 1. @return Enumerable @package YaLinqo\Generation
[ "Generates", "a", "sequence", "of", "integral", "numbers", "to", "negative", "infinity", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "toNegativeInfinity", "(", "[", "start", "[", "step", "]]", ")" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L162-L165
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.range
public static function range(int $start, int $count, int $step = 1): Enumerable { if ($count <= 0) return self::emptyEnum(); return new self(function() use ($start, $count, $step) { $value = $start - $step; while ($count-- > 0) yield $value += $step; }); }
php
public static function range(int $start, int $count, int $step = 1): Enumerable { if ($count <= 0) return self::emptyEnum(); return new self(function() use ($start, $count, $step) { $value = $start - $step; while ($count-- > 0) yield $value += $step; }); }
[ "public", "static", "function", "range", "(", "int", "$", "start", ",", "int", "$", "count", ",", "int", "$", "step", "=", "1", ")", ":", "Enumerable", "{", "if", "(", "$", "count", "<=", "0", ")", "return", "self", "::", "emptyEnum", "(", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "start", ",", "$", "count", ",", "$", "step", ")", "{", "$", "value", "=", "$", "start", "-", "$", "step", ";", "while", "(", "$", "count", "--", ">", "0", ")", "yield", "$", "value", "+=", "$", "step", ";", "}", ")", ";", "}" ]
Generates a sequence of integral numbers, beginning with start and containing count elements. <p><b>Syntax</b>: range (start, count [, step]) <p>Keys in the generated sequence are sequental: 0, 1, 2 etc. <p>Example: range(3, 4, 2) = 3, 5, 7, 9. @param int $start The value of the first integer in the sequence. @param int $count The number of integers to generate. @param int $step The difference between adjacent integers. Default: 1. @return Enumerable A sequence that contains a range of integral numbers. @package YaLinqo\Generation
[ "Generates", "a", "sequence", "of", "integral", "numbers", "beginning", "with", "start", "and", "containing", "count", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "range", "(", "start", "count", "[", "step", "]", ")", "<p", ">", "Keys", "in", "the", "generated", "sequence", "are", "sequental", ":", "0", "1", "2", "etc", ".", "<p", ">", "Example", ":", "range", "(", "3", "4", "2", ")", "=", "3", "5", "7", "9", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L190-L199
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.rangeDown
public static function rangeDown(int $start, int $count, int $step = 1): Enumerable { return self::range($start, $count, -$step); }
php
public static function rangeDown(int $start, int $count, int $step = 1): Enumerable { return self::range($start, $count, -$step); }
[ "public", "static", "function", "rangeDown", "(", "int", "$", "start", ",", "int", "$", "count", ",", "int", "$", "step", "=", "1", ")", ":", "Enumerable", "{", "return", "self", "::", "range", "(", "$", "start", ",", "$", "count", ",", "-", "$", "step", ")", ";", "}" ]
Generates a reversed sequence of integral numbers, beginning with start and containing count elements. <p><b>Syntax</b>: rangeDown (start, count [, step]) <p>Keys in the generated sequence are sequental: 0, 1, 2 etc. <p>Example: rangeDown(9, 4, 2) = 9, 7, 5, 3. @param int $start The value of the first integer in the sequence. @param int $count The number of integers to generate. @param int $step The difference between adjacent integers. Default: 1. @return Enumerable A sequence that contains a range of integral numbers. @package YaLinqo\Generation
[ "Generates", "a", "reversed", "sequence", "of", "integral", "numbers", "beginning", "with", "start", "and", "containing", "count", "elements", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "rangeDown", "(", "start", "count", "[", "step", "]", ")", "<p", ">", "Keys", "in", "the", "generated", "sequence", "are", "sequental", ":", "0", "1", "2", "etc", ".", "<p", ">", "Example", ":", "rangeDown", "(", "9", "4", "2", ")", "=", "9", "7", "5", "3", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L212-L215
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.rangeTo
public static function rangeTo(int $start, int $end, $step = 1): Enumerable { if ($step <= 0) throw new \InvalidArgumentException(Errors::STEP_NEGATIVE); return new self(function() use ($start, $end, $step) { if ($start <= $end) { for ($i = $start; $i < $end; $i += $step) yield $i; } else { for ($i = $start; $i > $end; $i -= $step) yield $i; } }); }
php
public static function rangeTo(int $start, int $end, $step = 1): Enumerable { if ($step <= 0) throw new \InvalidArgumentException(Errors::STEP_NEGATIVE); return new self(function() use ($start, $end, $step) { if ($start <= $end) { for ($i = $start; $i < $end; $i += $step) yield $i; } else { for ($i = $start; $i > $end; $i -= $step) yield $i; } }); }
[ "public", "static", "function", "rangeTo", "(", "int", "$", "start", ",", "int", "$", "end", ",", "$", "step", "=", "1", ")", ":", "Enumerable", "{", "if", "(", "$", "step", "<=", "0", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "Errors", "::", "STEP_NEGATIVE", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "start", ",", "$", "end", ",", "$", "step", ")", "{", "if", "(", "$", "start", "<=", "$", "end", ")", "{", "for", "(", "$", "i", "=", "$", "start", ";", "$", "i", "<", "$", "end", ";", "$", "i", "+=", "$", "step", ")", "yield", "$", "i", ";", "}", "else", "{", "for", "(", "$", "i", "=", "$", "start", ";", "$", "i", ">", "$", "end", ";", "$", "i", "-=", "$", "step", ")", "yield", "$", "i", ";", "}", "}", ")", ";", "}" ]
Generates a sequence of integral numbers within a specified range from start to end. <p><b>Syntax</b>: rangeTo (start, end [, step]) <p>Keys in the generated sequence are sequental: 0, 1, 2 etc. <p>Example: rangeTo(3, 9, 2) = 3, 5, 7, 9. @param int $start The value of the first integer in the sequence. @param int $end The value of the last integer in the sequence (not included). @param int $step The difference between adjacent integers. Default: 1. @throws \InvalidArgumentException If step is not a positive number. @return Enumerable A sequence that contains a range of integral numbers. @package YaLinqo\Generation
[ "Generates", "a", "sequence", "of", "integral", "numbers", "within", "a", "specified", "range", "from", "start", "to", "end", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "rangeTo", "(", "start", "end", "[", "step", "]", ")", "<p", ">", "Keys", "in", "the", "generated", "sequence", "are", "sequental", ":", "0", "1", "2", "etc", ".", "<p", ">", "Example", ":", "rangeTo", "(", "3", "9", "2", ")", "=", "3", "5", "7", "9", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L229-L243
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.repeat
public static function repeat($element, $count = null): Enumerable { if ($count < 0) throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO); return new self(function() use ($element, $count) { for ($i = 0; $i < $count || $count === null; $i++) yield $element; }); }
php
public static function repeat($element, $count = null): Enumerable { if ($count < 0) throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO); return new self(function() use ($element, $count) { for ($i = 0; $i < $count || $count === null; $i++) yield $element; }); }
[ "public", "static", "function", "repeat", "(", "$", "element", ",", "$", "count", "=", "null", ")", ":", "Enumerable", "{", "if", "(", "$", "count", "<", "0", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "Errors", "::", "COUNT_LESS_THAN_ZERO", ")", ";", "return", "new", "self", "(", "function", "(", ")", "use", "(", "$", "element", ",", "$", "count", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", "||", "$", "count", "===", "null", ";", "$", "i", "++", ")", "yield", "$", "element", ";", "}", ")", ";", "}" ]
Generates an sequence that contains one repeated value. <p><b>Syntax</b>: repeat (element) <p>Generates an endless sequence that contains one repeated value. <p><b>Syntax</b>: repeat (element, count) <p>Generates a sequence of specified length that contains one repeated value. <p>Keys in the generated sequence are sequental: 0, 1, 2 etc. @param int $element The value to be repeated. @param int $count The number of times to repeat the value in the generated sequence. Default: null. @throws \InvalidArgumentException If count is less than 0. @return Enumerable A sequence that contains a repeated value. @package YaLinqo\Generation
[ "Generates", "an", "sequence", "that", "contains", "one", "repeated", "value", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "repeat", "(", "element", ")", "<p", ">", "Generates", "an", "endless", "sequence", "that", "contains", "one", "repeated", "value", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "repeat", "(", "element", "count", ")", "<p", ">", "Generates", "a", "sequence", "of", "specified", "length", "that", "contains", "one", "repeated", "value", ".", "<p", ">", "Keys", "in", "the", "generated", "sequence", "are", "sequental", ":", "0", "1", "2", "etc", "." ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L258-L266
Athari/YaLinqo
YaLinqo/EnumerableGeneration.php
EnumerableGeneration.split
public static function split(string $subject, string $pattern, int $flags = 0): Enumerable { return new self( new \ArrayIterator(preg_split($pattern, $subject, -1, $flags)), false ); }
php
public static function split(string $subject, string $pattern, int $flags = 0): Enumerable { return new self( new \ArrayIterator(preg_split($pattern, $subject, -1, $flags)), false ); }
[ "public", "static", "function", "split", "(", "string", "$", "subject", ",", "string", "$", "pattern", ",", "int", "$", "flags", "=", "0", ")", ":", "Enumerable", "{", "return", "new", "self", "(", "new", "\\", "ArrayIterator", "(", "preg_split", "(", "$", "pattern", ",", "$", "subject", ",", "-", "1", ",", "$", "flags", ")", ")", ",", "false", ")", ";", "}" ]
Split the given string by a regular expression. <p><b>Syntax</b>: split (subject, pattern [, flags]) @param string $subject The input string. @param string $pattern The pattern to search for, as a string. @param int $flags flags can be any combination of the following flags: PREG_SPLIT_NO_EMPTY, PREG_SPLIT_DELIM_CAPTURE, PREG_SPLIT_OFFSET_CAPTURE. Default: 0. @return Enumerable @see preg_split @package YaLinqo\Generation
[ "Split", "the", "given", "string", "by", "a", "regular", "expression", ".", "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "split", "(", "subject", "pattern", "[", "flags", "]", ")" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/EnumerableGeneration.php#L278-L284
Athari/YaLinqo
YaLinqo/OrderedEnumerable.php
OrderedEnumerable.thenByDir
public function thenByDir($sortOrder, $keySelector = null, $comparer = null): OrderedEnumerable { $sortFlags = Utils::lambdaToSortFlagsAndOrder($comparer, $sortOrder); $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$value); $isReversed = $sortOrder == SORT_DESC; $comparer = Utils::createComparer($comparer, $sortOrder, $isReversed); return new self($this->source, $sortOrder, $sortFlags, $isReversed, $keySelector, $comparer, $this); }
php
public function thenByDir($sortOrder, $keySelector = null, $comparer = null): OrderedEnumerable { $sortFlags = Utils::lambdaToSortFlagsAndOrder($comparer, $sortOrder); $keySelector = Utils::createLambda($keySelector, 'v,k', Functions::$value); $isReversed = $sortOrder == SORT_DESC; $comparer = Utils::createComparer($comparer, $sortOrder, $isReversed); return new self($this->source, $sortOrder, $sortFlags, $isReversed, $keySelector, $comparer, $this); }
[ "public", "function", "thenByDir", "(", "$", "sortOrder", ",", "$", "keySelector", "=", "null", ",", "$", "comparer", "=", "null", ")", ":", "OrderedEnumerable", "{", "$", "sortFlags", "=", "Utils", "::", "lambdaToSortFlagsAndOrder", "(", "$", "comparer", ",", "$", "sortOrder", ")", ";", "$", "keySelector", "=", "Utils", "::", "createLambda", "(", "$", "keySelector", ",", "'v,k'", ",", "Functions", "::", "$", "value", ")", ";", "$", "isReversed", "=", "$", "sortOrder", "==", "SORT_DESC", ";", "$", "comparer", "=", "Utils", "::", "createComparer", "(", "$", "comparer", ",", "$", "sortOrder", ",", "$", "isReversed", ")", ";", "return", "new", "self", "(", "$", "this", "->", "source", ",", "$", "sortOrder", ",", "$", "sortFlags", ",", "$", "isReversed", ",", "$", "keySelector", ",", "$", "comparer", ",", "$", "this", ")", ";", "}" ]
<p><b>Syntax</b>: thenByDir (false|true [, {{(v, k) ==> key} [, {{(a, b) ==> diff}]]) <p>Performs a subsequent ordering of elements in a sequence in a particular direction (ascending, descending) according to a key. <p>Three methods are defined to extend the type OrderedEnumerable, which is the return type of this method. These three methods, namely {@link thenBy}, {@link thenByDescending} and {@link thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. <p>Because OrderedEnumerable inherits from {@link Enumerable}, you can call {@link Enumerable::orderBy orderBy}, {@link Enumerable::orderByDescending orderByDescending} or {@link Enumerable::orderByDir orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. <p>This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. @param int|bool $sortOrder A direction in which to order the elements: false or SORT_DESC for ascending (by increasing value), true or SORT_ASC for descending (by decreasing value). @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. @param callable|int|null $comparer {(a, b) ==> diff} Difference between a and b: &lt;0 if a&lt;b; 0 if a==b; &gt;0 if a&gt;b. Can also be a combination of SORT_ flags. @return \YaLinqo\OrderedEnumerable
[ "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "thenByDir", "(", "false|true", "[", "{{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "{{", "(", "a", "b", ")", "==", ">", "diff", "}", "]]", ")", "<p", ">", "Performs", "a", "subsequent", "ordering", "of", "elements", "in", "a", "sequence", "in", "a", "particular", "direction", "(", "ascending", "descending", ")", "according", "to", "a", "key", ".", "<p", ">", "Three", "methods", "are", "defined", "to", "extend", "the", "type", "OrderedEnumerable", "which", "is", "the", "return", "type", "of", "this", "method", ".", "These", "three", "methods", "namely", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/OrderedEnumerable.php#L73-L80
Athari/YaLinqo
YaLinqo/OrderedEnumerable.php
OrderedEnumerable.thenBy
public function thenBy($keySelector = null, $comparer = null): OrderedEnumerable { return $this->thenByDir(false, $keySelector, $comparer); }
php
public function thenBy($keySelector = null, $comparer = null): OrderedEnumerable { return $this->thenByDir(false, $keySelector, $comparer); }
[ "public", "function", "thenBy", "(", "$", "keySelector", "=", "null", ",", "$", "comparer", "=", "null", ")", ":", "OrderedEnumerable", "{", "return", "$", "this", "->", "thenByDir", "(", "false", ",", "$", "keySelector", ",", "$", "comparer", ")", ";", "}" ]
<p><b>Syntax</b>: thenBy ([{{(v, k) ==> key} [, {{(a, b) ==> diff}]]) <p>Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. <p>Three methods are defined to extend the type OrderedEnumerable, which is the return type of this method. These three methods, namely {@link thenBy}, {@link thenByDescending} and {@link thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. <p>Because OrderedEnumerable inherits from {@link Enumerable}, you can call {@link Enumerable::orderBy orderBy}, {@link Enumerable::orderByDescending orderByDescending} or {@link Enumerable::orderByDir orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. <p>This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. @param callable|int|null $comparer {(a, b) ==> diff} Difference between a and b: &lt;0 if a&lt;b; 0 if a==b; &gt;0 if a&gt;b. Can also be a combination of SORT_ flags. @return \YaLinqo\OrderedEnumerable
[ "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "thenBy", "(", "[", "{{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "{{", "(", "a", "b", ")", "==", ">", "diff", "}", "]]", ")", "<p", ">", "Performs", "a", "subsequent", "ordering", "of", "the", "elements", "in", "a", "sequence", "in", "ascending", "order", "according", "to", "a", "key", ".", "<p", ">", "Three", "methods", "are", "defined", "to", "extend", "the", "type", "OrderedEnumerable", "which", "is", "the", "return", "type", "of", "this", "method", ".", "These", "three", "methods", "namely", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/OrderedEnumerable.php#L92-L95
Athari/YaLinqo
YaLinqo/OrderedEnumerable.php
OrderedEnumerable.thenByDescending
public function thenByDescending($keySelector = null, $comparer = null): OrderedEnumerable { return $this->thenByDir(true, $keySelector, $comparer); }
php
public function thenByDescending($keySelector = null, $comparer = null): OrderedEnumerable { return $this->thenByDir(true, $keySelector, $comparer); }
[ "public", "function", "thenByDescending", "(", "$", "keySelector", "=", "null", ",", "$", "comparer", "=", "null", ")", ":", "OrderedEnumerable", "{", "return", "$", "this", "->", "thenByDir", "(", "true", ",", "$", "keySelector", ",", "$", "comparer", ")", ";", "}" ]
<p><b>Syntax</b>: thenByDescending ([{{(v, k) ==> key} [, {{(a, b) ==> diff}]]) <p>Performs a subsequent ordering of the elements in a sequence in descending order according to a key. <p>Three methods are defined to extend the type OrderedEnumerable, which is the return type of this method. These three methods, namely {@link thenBy}, {@link thenByDescending} and {@link thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. <p>Because OrderedEnumerable inherits from {@link Enumerable}, you can call {@link Enumerable::orderBy orderBy}, {@link Enumerable::orderByDescending orderByDescending} or {@link Enumerable::orderByDir orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. <p>This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. @param callable|int|null $comparer {(a, b) ==> diff} Difference between a and b: &lt;0 if a&lt;b; 0 if a==b; &gt;0 if a&gt;b. Can also be a combination of SORT_ flags. @return \YaLinqo\OrderedEnumerable
[ "<p", ">", "<b", ">", "Syntax<", "/", "b", ">", ":", "thenByDescending", "(", "[", "{{", "(", "v", "k", ")", "==", ">", "key", "}", "[", "{{", "(", "a", "b", ")", "==", ">", "diff", "}", "]]", ")", "<p", ">", "Performs", "a", "subsequent", "ordering", "of", "the", "elements", "in", "a", "sequence", "in", "descending", "order", "according", "to", "a", "key", ".", "<p", ">", "Three", "methods", "are", "defined", "to", "extend", "the", "type", "OrderedEnumerable", "which", "is", "the", "return", "type", "of", "this", "method", ".", "These", "three", "methods", "namely", "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/OrderedEnumerable.php#L107-L110
Athari/YaLinqo
YaLinqo/OrderedEnumerable.php
OrderedEnumerable.getIterator
public function getIterator(): \Traversable { $canMultisort = $this->sortFlags !== null; $array = $this->source->tryGetArrayCopy(); $it = $this->trySortBySingleField($array, $canMultisort); if ($it !== null) return $it; return $this->sortByMultipleFields($array, $canMultisort); }
php
public function getIterator(): \Traversable { $canMultisort = $this->sortFlags !== null; $array = $this->source->tryGetArrayCopy(); $it = $this->trySortBySingleField($array, $canMultisort); if ($it !== null) return $it; return $this->sortByMultipleFields($array, $canMultisort); }
[ "public", "function", "getIterator", "(", ")", ":", "\\", "Traversable", "{", "$", "canMultisort", "=", "$", "this", "->", "sortFlags", "!==", "null", ";", "$", "array", "=", "$", "this", "->", "source", "->", "tryGetArrayCopy", "(", ")", ";", "$", "it", "=", "$", "this", "->", "trySortBySingleField", "(", "$", "array", ",", "$", "canMultisort", ")", ";", "if", "(", "$", "it", "!==", "null", ")", "return", "$", "it", ";", "return", "$", "this", "->", "sortByMultipleFields", "(", "$", "array", ",", "$", "canMultisort", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Athari/YaLinqo/blob/939469772b36d4d454836681e0be2f220cf1e5cb/YaLinqo/OrderedEnumerable.php#L113-L123
asm89/twig-cache-extension
lib/Asm89/Twig/CacheExtension/CacheStrategy/GenerationalCacheStrategy.php
GenerationalCacheStrategy.generateKey
public function generateKey($annotation, $value) { $key = $this->keyGenerator->generateKey($value); if (null === $key) { throw new InvalidCacheKeyException(); } return $annotation . '__GCS__' . $key; }
php
public function generateKey($annotation, $value) { $key = $this->keyGenerator->generateKey($value); if (null === $key) { throw new InvalidCacheKeyException(); } return $annotation . '__GCS__' . $key; }
[ "public", "function", "generateKey", "(", "$", "annotation", ",", "$", "value", ")", "{", "$", "key", "=", "$", "this", "->", "keyGenerator", "->", "generateKey", "(", "$", "value", ")", ";", "if", "(", "null", "===", "$", "key", ")", "{", "throw", "new", "InvalidCacheKeyException", "(", ")", ";", "}", "return", "$", "annotation", ".", "'__GCS__'", ".", "$", "key", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/asm89/twig-cache-extension/blob/630ea7abdc3fc62ba6786c02590a1560e449cf55/lib/Asm89/Twig/CacheExtension/CacheStrategy/GenerationalCacheStrategy.php#L61-L70
asm89/twig-cache-extension
lib/Asm89/Twig/CacheExtension/CacheStrategy/GenerationalCacheStrategy.php
GenerationalCacheStrategy.saveBlock
public function saveBlock($key, $block) { return $this->cache->save($key, $block, $this->lifetime); }
php
public function saveBlock($key, $block) { return $this->cache->save($key, $block, $this->lifetime); }
[ "public", "function", "saveBlock", "(", "$", "key", ",", "$", "block", ")", "{", "return", "$", "this", "->", "cache", "->", "save", "(", "$", "key", ",", "$", "block", ",", "$", "this", "->", "lifetime", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/asm89/twig-cache-extension/blob/630ea7abdc3fc62ba6786c02590a1560e449cf55/lib/Asm89/Twig/CacheExtension/CacheStrategy/GenerationalCacheStrategy.php#L75-L78
asm89/twig-cache-extension
lib/Asm89/Twig/CacheExtension/CacheProvider/DoctrineCacheAdapter.php
DoctrineCacheAdapter.save
public function save($key, $value, $lifetime = 0) { return $this->cache->save($key, $value, $lifetime); }
php
public function save($key, $value, $lifetime = 0) { return $this->cache->save($key, $value, $lifetime); }
[ "public", "function", "save", "(", "$", "key", ",", "$", "value", ",", "$", "lifetime", "=", "0", ")", "{", "return", "$", "this", "->", "cache", "->", "save", "(", "$", "key", ",", "$", "value", ",", "$", "lifetime", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/asm89/twig-cache-extension/blob/630ea7abdc3fc62ba6786c02590a1560e449cf55/lib/Asm89/Twig/CacheExtension/CacheProvider/DoctrineCacheAdapter.php#L45-L48
asm89/twig-cache-extension
lib/Asm89/Twig/CacheExtension/Node/CacheNode.php
CacheNode.compile
public function compile(\Twig_Compiler $compiler) { $i = self::$cacheCount++; if (version_compare(\Twig_Environment::VERSION, '1.26.0', '>=')) { $extension = 'Asm89\Twig\CacheExtension\Extension'; } else { $extension = 'asm89_cache'; } $compiler ->addDebugInfo($this) ->write("\$asm89CacheStrategy".$i." = \$this->env->getExtension('{$extension}')->getCacheStrategy();\n") ->write("\$asm89Key".$i." = \$asm89CacheStrategy".$i."->generateKey(") ->subcompile($this->getNode('annotation')) ->raw(", ") ->subcompile($this->getNode('key_info')) ->write(");\n") ->write("\$asm89CacheBody".$i." = \$asm89CacheStrategy".$i."->fetchBlock(\$asm89Key".$i.");\n") ->write("if (\$asm89CacheBody".$i." === false) {\n") ->indent() ->write("ob_start();\n") ->indent() ->subcompile($this->getNode('body')) ->outdent() ->write("\n") ->write("\$asm89CacheBody".$i." = ob_get_clean();\n") ->write("\$asm89CacheStrategy".$i."->saveBlock(\$asm89Key".$i.", \$asm89CacheBody".$i.");\n") ->outdent() ->write("}\n") ->write("echo \$asm89CacheBody".$i.";\n") ; }
php
public function compile(\Twig_Compiler $compiler) { $i = self::$cacheCount++; if (version_compare(\Twig_Environment::VERSION, '1.26.0', '>=')) { $extension = 'Asm89\Twig\CacheExtension\Extension'; } else { $extension = 'asm89_cache'; } $compiler ->addDebugInfo($this) ->write("\$asm89CacheStrategy".$i." = \$this->env->getExtension('{$extension}')->getCacheStrategy();\n") ->write("\$asm89Key".$i." = \$asm89CacheStrategy".$i."->generateKey(") ->subcompile($this->getNode('annotation')) ->raw(", ") ->subcompile($this->getNode('key_info')) ->write(");\n") ->write("\$asm89CacheBody".$i." = \$asm89CacheStrategy".$i."->fetchBlock(\$asm89Key".$i.");\n") ->write("if (\$asm89CacheBody".$i." === false) {\n") ->indent() ->write("ob_start();\n") ->indent() ->subcompile($this->getNode('body')) ->outdent() ->write("\n") ->write("\$asm89CacheBody".$i." = ob_get_clean();\n") ->write("\$asm89CacheStrategy".$i."->saveBlock(\$asm89Key".$i.", \$asm89CacheBody".$i.");\n") ->outdent() ->write("}\n") ->write("echo \$asm89CacheBody".$i.";\n") ; }
[ "public", "function", "compile", "(", "\\", "Twig_Compiler", "$", "compiler", ")", "{", "$", "i", "=", "self", "::", "$", "cacheCount", "++", ";", "if", "(", "version_compare", "(", "\\", "Twig_Environment", "::", "VERSION", ",", "'1.26.0'", ",", "'>='", ")", ")", "{", "$", "extension", "=", "'Asm89\\Twig\\CacheExtension\\Extension'", ";", "}", "else", "{", "$", "extension", "=", "'asm89_cache'", ";", "}", "$", "compiler", "->", "addDebugInfo", "(", "$", "this", ")", "->", "write", "(", "\"\\$asm89CacheStrategy\"", ".", "$", "i", ".", "\" = \\$this->env->getExtension('{$extension}')->getCacheStrategy();\\n\"", ")", "->", "write", "(", "\"\\$asm89Key\"", ".", "$", "i", ".", "\" = \\$asm89CacheStrategy\"", ".", "$", "i", ".", "\"->generateKey(\"", ")", "->", "subcompile", "(", "$", "this", "->", "getNode", "(", "'annotation'", ")", ")", "->", "raw", "(", "\", \"", ")", "->", "subcompile", "(", "$", "this", "->", "getNode", "(", "'key_info'", ")", ")", "->", "write", "(", "\");\\n\"", ")", "->", "write", "(", "\"\\$asm89CacheBody\"", ".", "$", "i", ".", "\" = \\$asm89CacheStrategy\"", ".", "$", "i", ".", "\"->fetchBlock(\\$asm89Key\"", ".", "$", "i", ".", "\");\\n\"", ")", "->", "write", "(", "\"if (\\$asm89CacheBody\"", ".", "$", "i", ".", "\" === false) {\\n\"", ")", "->", "indent", "(", ")", "->", "write", "(", "\"ob_start();\\n\"", ")", "->", "indent", "(", ")", "->", "subcompile", "(", "$", "this", "->", "getNode", "(", "'body'", ")", ")", "->", "outdent", "(", ")", "->", "write", "(", "\"\\n\"", ")", "->", "write", "(", "\"\\$asm89CacheBody\"", ".", "$", "i", ".", "\" = ob_get_clean();\\n\"", ")", "->", "write", "(", "\"\\$asm89CacheStrategy\"", ".", "$", "i", ".", "\"->saveBlock(\\$asm89Key\"", ".", "$", "i", ".", "\", \\$asm89CacheBody\"", ".", "$", "i", ".", "\");\\n\"", ")", "->", "outdent", "(", ")", "->", "write", "(", "\"}\\n\"", ")", "->", "write", "(", "\"echo \\$asm89CacheBody\"", ".", "$", "i", ".", "\";\\n\"", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/asm89/twig-cache-extension/blob/630ea7abdc3fc62ba6786c02590a1560e449cf55/lib/Asm89/Twig/CacheExtension/Node/CacheNode.php#L38-L70
asm89/twig-cache-extension
lib/Asm89/Twig/CacheExtension/CacheStrategy/IndexedChainingCacheStrategy.php
IndexedChainingCacheStrategy.generateKey
public function generateKey($annotation, $value) { if (!is_array($value) || null === $strategyKey = key($value)) { throw new NonExistingStrategyKeyException(); } if (!isset($this->strategies[$strategyKey])) { throw new NonExistingStrategyException($strategyKey); } return array( 'strategyKey' => $strategyKey, 'key' => $this->strategies[$strategyKey]->generateKey($annotation, current($value)), ); }
php
public function generateKey($annotation, $value) { if (!is_array($value) || null === $strategyKey = key($value)) { throw new NonExistingStrategyKeyException(); } if (!isset($this->strategies[$strategyKey])) { throw new NonExistingStrategyException($strategyKey); } return array( 'strategyKey' => $strategyKey, 'key' => $this->strategies[$strategyKey]->generateKey($annotation, current($value)), ); }
[ "public", "function", "generateKey", "(", "$", "annotation", ",", "$", "value", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", "||", "null", "===", "$", "strategyKey", "=", "key", "(", "$", "value", ")", ")", "{", "throw", "new", "NonExistingStrategyKeyException", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "strategies", "[", "$", "strategyKey", "]", ")", ")", "{", "throw", "new", "NonExistingStrategyException", "(", "$", "strategyKey", ")", ";", "}", "return", "array", "(", "'strategyKey'", "=>", "$", "strategyKey", ",", "'key'", "=>", "$", "this", "->", "strategies", "[", "$", "strategyKey", "]", "->", "generateKey", "(", "$", "annotation", ",", "current", "(", "$", "value", ")", ")", ",", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/asm89/twig-cache-extension/blob/630ea7abdc3fc62ba6786c02590a1560e449cf55/lib/Asm89/Twig/CacheExtension/CacheStrategy/IndexedChainingCacheStrategy.php#L53-L67
asm89/twig-cache-extension
lib/Asm89/Twig/CacheExtension/TokenParser/Cache.php
Cache.parse
public function parse(\Twig_Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); $annotation = $this->parser->getExpressionParser()->parseExpression(); $key = $this->parser->getExpressionParser()->parseExpression(); $stream->expect(\Twig_Token::BLOCK_END_TYPE); $body = $this->parser->subparse(array($this, 'decideCacheEnd'), true); $stream->expect(\Twig_Token::BLOCK_END_TYPE); return new CacheNode($annotation, $key, $body, $lineno, $this->getTag()); }
php
public function parse(\Twig_Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); $annotation = $this->parser->getExpressionParser()->parseExpression(); $key = $this->parser->getExpressionParser()->parseExpression(); $stream->expect(\Twig_Token::BLOCK_END_TYPE); $body = $this->parser->subparse(array($this, 'decideCacheEnd'), true); $stream->expect(\Twig_Token::BLOCK_END_TYPE); return new CacheNode($annotation, $key, $body, $lineno, $this->getTag()); }
[ "public", "function", "parse", "(", "\\", "Twig_Token", "$", "token", ")", "{", "$", "lineno", "=", "$", "token", "->", "getLine", "(", ")", ";", "$", "stream", "=", "$", "this", "->", "parser", "->", "getStream", "(", ")", ";", "$", "annotation", "=", "$", "this", "->", "parser", "->", "getExpressionParser", "(", ")", "->", "parseExpression", "(", ")", ";", "$", "key", "=", "$", "this", "->", "parser", "->", "getExpressionParser", "(", ")", "->", "parseExpression", "(", ")", ";", "$", "stream", "->", "expect", "(", "\\", "Twig_Token", "::", "BLOCK_END_TYPE", ")", ";", "$", "body", "=", "$", "this", "->", "parser", "->", "subparse", "(", "array", "(", "$", "this", ",", "'decideCacheEnd'", ")", ",", "true", ")", ";", "$", "stream", "->", "expect", "(", "\\", "Twig_Token", "::", "BLOCK_END_TYPE", ")", ";", "return", "new", "CacheNode", "(", "$", "annotation", ",", "$", "key", ",", "$", "body", ",", "$", "lineno", ",", "$", "this", "->", "getTag", "(", ")", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/asm89/twig-cache-extension/blob/630ea7abdc3fc62ba6786c02590a1560e449cf55/lib/Asm89/Twig/CacheExtension/TokenParser/Cache.php#L44-L58
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getColumnClassName
public function getColumnClassName($options) { $model = $this->config->getDataModel(); $namespace = __NAMESPACE__ . '\\'; //if the relationship is set if ($method = $this->validator->arrayGet($options, 'relationship')) { if (method_exists($model, $method)) { $relationship = $model->{$method}(); if (is_a($relationship, self::BELONGS_TO_MANY)) { return $namespace . 'Relationships\BelongsToMany'; } else if (is_a($relationship, self::HAS_ONE) || is_a($relationship, self::HAS_MANY)) { return $namespace . 'Relationships\HasOneOrMany'; } } //assume it's a nested relationship return $namespace . 'Relationships\BelongsTo'; } return $namespace . 'Column'; }
php
public function getColumnClassName($options) { $model = $this->config->getDataModel(); $namespace = __NAMESPACE__ . '\\'; //if the relationship is set if ($method = $this->validator->arrayGet($options, 'relationship')) { if (method_exists($model, $method)) { $relationship = $model->{$method}(); if (is_a($relationship, self::BELONGS_TO_MANY)) { return $namespace . 'Relationships\BelongsToMany'; } else if (is_a($relationship, self::HAS_ONE) || is_a($relationship, self::HAS_MANY)) { return $namespace . 'Relationships\HasOneOrMany'; } } //assume it's a nested relationship return $namespace . 'Relationships\BelongsTo'; } return $namespace . 'Column'; }
[ "public", "function", "getColumnClassName", "(", "$", "options", ")", "{", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "namespace", "=", "__NAMESPACE__", ".", "'\\\\'", ";", "//if the relationship is set", "if", "(", "$", "method", "=", "$", "this", "->", "validator", "->", "arrayGet", "(", "$", "options", ",", "'relationship'", ")", ")", "{", "if", "(", "method_exists", "(", "$", "model", ",", "$", "method", ")", ")", "{", "$", "relationship", "=", "$", "model", "->", "{", "$", "method", "}", "(", ")", ";", "if", "(", "is_a", "(", "$", "relationship", ",", "self", "::", "BELONGS_TO_MANY", ")", ")", "{", "return", "$", "namespace", ".", "'Relationships\\BelongsToMany'", ";", "}", "else", "if", "(", "is_a", "(", "$", "relationship", ",", "self", "::", "HAS_ONE", ")", "||", "is_a", "(", "$", "relationship", ",", "self", "::", "HAS_MANY", ")", ")", "{", "return", "$", "namespace", ".", "'Relationships\\HasOneOrMany'", ";", "}", "}", "//assume it's a nested relationship", "return", "$", "namespace", ".", "'Relationships\\BelongsTo'", ";", "}", "return", "$", "namespace", ".", "'Column'", ";", "}" ]
Gets the column class name depending on whether or not it's a relationship and what type of relationship it is @param array $options @return string
[ "Gets", "the", "column", "class", "name", "depending", "on", "whether", "or", "not", "it", "s", "a", "relationship", "and", "what", "type", "of", "relationship", "it", "is" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L145-L172
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getColumnOptions
public function getColumnOptions() { //make sure we only run this once and then return the cached version if (!sizeof($this->columnOptions)) { foreach ($this->getColumns() as $column) { $this->columnOptions[] = $column->getOptions(); } } return $this->columnOptions; }
php
public function getColumnOptions() { //make sure we only run this once and then return the cached version if (!sizeof($this->columnOptions)) { foreach ($this->getColumns() as $column) { $this->columnOptions[] = $column->getOptions(); } } return $this->columnOptions; }
[ "public", "function", "getColumnOptions", "(", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "!", "sizeof", "(", "$", "this", "->", "columnOptions", ")", ")", "{", "foreach", "(", "$", "this", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "$", "this", "->", "columnOptions", "[", "]", "=", "$", "column", "->", "getOptions", "(", ")", ";", "}", "}", "return", "$", "this", "->", "columnOptions", ";", "}" ]
Gets the column objects as an integer-indexed array @return array
[ "Gets", "the", "column", "objects", "as", "an", "integer", "-", "indexed", "array" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L228-L240
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getRelatedColumns
public function getRelatedColumns() { //make sure we only run this once and then return the cached version if (!sizeof($this->relatedColumns)) { foreach ($this->getColumns() as $column) { if ($column->getOption('is_related')) { $this->relatedColumns[$column->getOption('column_name')] = $column->getOption('column_name'); } } } return $this->relatedColumns; }
php
public function getRelatedColumns() { //make sure we only run this once and then return the cached version if (!sizeof($this->relatedColumns)) { foreach ($this->getColumns() as $column) { if ($column->getOption('is_related')) { $this->relatedColumns[$column->getOption('column_name')] = $column->getOption('column_name'); } } } return $this->relatedColumns; }
[ "public", "function", "getRelatedColumns", "(", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "!", "sizeof", "(", "$", "this", "->", "relatedColumns", ")", ")", "{", "foreach", "(", "$", "this", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "if", "(", "$", "column", "->", "getOption", "(", "'is_related'", ")", ")", "{", "$", "this", "->", "relatedColumns", "[", "$", "column", "->", "getOption", "(", "'column_name'", ")", "]", "=", "$", "column", "->", "getOption", "(", "'column_name'", ")", ";", "}", "}", "}", "return", "$", "this", "->", "relatedColumns", ";", "}" ]
Gets the columns that are relationship columns @return array
[ "Gets", "the", "columns", "that", "are", "relationship", "columns" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L292-L307
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getComputedColumns
public function getComputedColumns() { //make sure we only run this once and then return the cached version if (!sizeof($this->computedColumns)) { foreach ($this->getColumns() as $column) { if (!$column->getOption('is_related') && $column->getOption('is_computed')) { $this->computedColumns[$column->getOption('column_name')] = $column->getOption('column_name'); } } } return $this->computedColumns; }
php
public function getComputedColumns() { //make sure we only run this once and then return the cached version if (!sizeof($this->computedColumns)) { foreach ($this->getColumns() as $column) { if (!$column->getOption('is_related') && $column->getOption('is_computed')) { $this->computedColumns[$column->getOption('column_name')] = $column->getOption('column_name'); } } } return $this->computedColumns; }
[ "public", "function", "getComputedColumns", "(", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "!", "sizeof", "(", "$", "this", "->", "computedColumns", ")", ")", "{", "foreach", "(", "$", "this", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "if", "(", "!", "$", "column", "->", "getOption", "(", "'is_related'", ")", "&&", "$", "column", "->", "getOption", "(", "'is_computed'", ")", ")", "{", "$", "this", "->", "computedColumns", "[", "$", "column", "->", "getOption", "(", "'column_name'", ")", "]", "=", "$", "column", "->", "getOption", "(", "'column_name'", ")", ";", "}", "}", "}", "return", "$", "this", "->", "computedColumns", ";", "}" ]
Gets the columns that are computed @return array
[ "Gets", "the", "columns", "that", "are", "computed" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L314-L329
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Includes/Multup.php
Multup.open
public static function open($input, $rules, $path, $random = true) { return new Multup( $input, $rules, $path, $random ); }
php
public static function open($input, $rules, $path, $random = true) { return new Multup( $input, $rules, $path, $random ); }
[ "public", "static", "function", "open", "(", "$", "input", ",", "$", "rules", ",", "$", "path", ",", "$", "random", "=", "true", ")", "{", "return", "new", "Multup", "(", "$", "input", ",", "$", "rules", ",", "$", "path", ",", "$", "random", ")", ";", "}" ]
Static call, Laravel style. Returns a new Multup object, allowing for chainable calls @param string $input name of the file to upload @param string $rules laravel style validation rules string @param string $path relative to /public/ to move the images if valid @param bool $random Whether or not to randomize the filename, the filename will be set to a 32 character string if true @return Multup
[ "Static", "call", "Laravel", "style", ".", "Returns", "a", "new", "Multup", "object", "allowing", "for", "chainable", "calls" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Includes/Multup.php#L96-L99
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Includes/Multup.php
Multup.upload
public function upload() { $this->image = array($this->input => Input::file($this->input)); $result = array(); $result[] = $this->post_upload_process($this->upload_image()); return $result; if ($image) { $this->image = array( $this->input => array( 'name' => $image->getClientOriginalName(), 'type' => $image->getClientMimeType(), 'tmp_name' => $image->getFilename(), 'error' => $image->getError(), 'size' => $image->getSize(), ) ); $result[] = $this->post_upload_process($this->upload_image()); } return $result; if(!is_array($images)){ $this->image = array($this->input => $images); $result[] = $this->post_upload_process($this->upload_image()); } else { $size = $count($images['name']); for($i = 0; $i < $size; $i++){ $this->image = array( $this->input => array( 'name' => $images['name'][$i], 'type' => $images['type'][$i], 'tmp_name' => $images['tmp_name'][$i], 'error' => $images['error'][$i], 'size' => $images['size'][$i] ) ); $result[] = $this->post_upload_process($this->upload_image()); } } return $result; }
php
public function upload() { $this->image = array($this->input => Input::file($this->input)); $result = array(); $result[] = $this->post_upload_process($this->upload_image()); return $result; if ($image) { $this->image = array( $this->input => array( 'name' => $image->getClientOriginalName(), 'type' => $image->getClientMimeType(), 'tmp_name' => $image->getFilename(), 'error' => $image->getError(), 'size' => $image->getSize(), ) ); $result[] = $this->post_upload_process($this->upload_image()); } return $result; if(!is_array($images)){ $this->image = array($this->input => $images); $result[] = $this->post_upload_process($this->upload_image()); } else { $size = $count($images['name']); for($i = 0; $i < $size; $i++){ $this->image = array( $this->input => array( 'name' => $images['name'][$i], 'type' => $images['type'][$i], 'tmp_name' => $images['tmp_name'][$i], 'error' => $images['error'][$i], 'size' => $images['size'][$i] ) ); $result[] = $this->post_upload_process($this->upload_image()); } } return $result; }
[ "public", "function", "upload", "(", ")", "{", "$", "this", "->", "image", "=", "array", "(", "$", "this", "->", "input", "=>", "Input", "::", "file", "(", "$", "this", "->", "input", ")", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "]", "=", "$", "this", "->", "post_upload_process", "(", "$", "this", "->", "upload_image", "(", ")", ")", ";", "return", "$", "result", ";", "if", "(", "$", "image", ")", "{", "$", "this", "->", "image", "=", "array", "(", "$", "this", "->", "input", "=>", "array", "(", "'name'", "=>", "$", "image", "->", "getClientOriginalName", "(", ")", ",", "'type'", "=>", "$", "image", "->", "getClientMimeType", "(", ")", ",", "'tmp_name'", "=>", "$", "image", "->", "getFilename", "(", ")", ",", "'error'", "=>", "$", "image", "->", "getError", "(", ")", ",", "'size'", "=>", "$", "image", "->", "getSize", "(", ")", ",", ")", ")", ";", "$", "result", "[", "]", "=", "$", "this", "->", "post_upload_process", "(", "$", "this", "->", "upload_image", "(", ")", ")", ";", "}", "return", "$", "result", ";", "if", "(", "!", "is_array", "(", "$", "images", ")", ")", "{", "$", "this", "->", "image", "=", "array", "(", "$", "this", "->", "input", "=>", "$", "images", ")", ";", "$", "result", "[", "]", "=", "$", "this", "->", "post_upload_process", "(", "$", "this", "->", "upload_image", "(", ")", ")", ";", "}", "else", "{", "$", "size", "=", "$", "count", "(", "$", "images", "[", "'name'", "]", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "size", ";", "$", "i", "++", ")", "{", "$", "this", "->", "image", "=", "array", "(", "$", "this", "->", "input", "=>", "array", "(", "'name'", "=>", "$", "images", "[", "'name'", "]", "[", "$", "i", "]", ",", "'type'", "=>", "$", "images", "[", "'type'", "]", "[", "$", "i", "]", ",", "'tmp_name'", "=>", "$", "images", "[", "'tmp_name'", "]", "[", "$", "i", "]", ",", "'error'", "=>", "$", "images", "[", "'error'", "]", "[", "$", "i", "]", ",", "'size'", "=>", "$", "images", "[", "'size'", "]", "[", "$", "i", "]", ")", ")", ";", "$", "result", "[", "]", "=", "$", "this", "->", "post_upload_process", "(", "$", "this", "->", "upload_image", "(", ")", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
/* Upload the image @return array of results each result will be an array() with keys: errors array -> empty if saved properly, otherwise $validation->errors object path string -> full URL to the file if saved, empty if not saved filename string -> name of the saved file or file that could not be uploaded
[ "/", "*", "Upload", "the", "image", "@return", "array", "of", "results", "each", "result", "will", "be", "an", "array", "()", "with", "keys", ":", "errors", "array", "-", ">", "empty", "if", "saved", "properly", "otherwise", "$validation", "-", ">", "errors", "object", "path", "string", "-", ">", "full", "URL", "to", "the", "file", "if", "saved", "empty", "if", "not", "saved", "filename", "string", "-", ">", "name", "of", "the", "saved", "file", "or", "file", "that", "could", "not", "be", "uploaded" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Includes/Multup.php#L121-L175
FrozenNode/Laravel-Administrator
src/controllers/AdminController.php
AdminController.customModelAction
public function customModelAction($modelName) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $actionName = $this->request->input('action_name', false); $dataTable = app('admin_datatable'); //get the sort options and filters $page = $this->request->input('page', 1); $sortOptions = $this->request->input('sortOptions', array()); $filters = $this->request->input('filters', array()); //get the prepared query options $prepared = $dataTable->prepareQuery(app('db'), $page, $sortOptions, $filters); //get the action and perform the custom action $action = $actionFactory->getByName($actionName, true); $result = $action->perform($prepared['query']); //if the result is a string, return that as an error. if (is_string($result)) { return response()->json(array('success' => false, 'error' => $result)); } //if it's falsy, return the standard error message else if (!$result) { $messages = $action->getOption('messages'); return response()->json(array('success' => false, 'error' => $messages['error'])); } else { $response = array('success' => true); //if it's a download response, flash the response to the session and return the download link if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse')) { $file = $result->getFile()->getRealPath(); $headers = $result->headers->all(); $this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers)); $response['download'] = route('admin_file_download'); } //if it's a redirect, put the url into the redirect key so that javascript can transfer the user else if (is_a($result, '\Illuminate\Http\RedirectResponse')) { $response['redirect'] = $result->getTargetUrl(); } return response()->json($response); } }
php
public function customModelAction($modelName) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $actionName = $this->request->input('action_name', false); $dataTable = app('admin_datatable'); //get the sort options and filters $page = $this->request->input('page', 1); $sortOptions = $this->request->input('sortOptions', array()); $filters = $this->request->input('filters', array()); //get the prepared query options $prepared = $dataTable->prepareQuery(app('db'), $page, $sortOptions, $filters); //get the action and perform the custom action $action = $actionFactory->getByName($actionName, true); $result = $action->perform($prepared['query']); //if the result is a string, return that as an error. if (is_string($result)) { return response()->json(array('success' => false, 'error' => $result)); } //if it's falsy, return the standard error message else if (!$result) { $messages = $action->getOption('messages'); return response()->json(array('success' => false, 'error' => $messages['error'])); } else { $response = array('success' => true); //if it's a download response, flash the response to the session and return the download link if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse')) { $file = $result->getFile()->getRealPath(); $headers = $result->headers->all(); $this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers)); $response['download'] = route('admin_file_download'); } //if it's a redirect, put the url into the redirect key so that javascript can transfer the user else if (is_a($result, '\Illuminate\Http\RedirectResponse')) { $response['redirect'] = $result->getTargetUrl(); } return response()->json($response); } }
[ "public", "function", "customModelAction", "(", "$", "modelName", ")", "{", "$", "config", "=", "app", "(", "'itemconfig'", ")", ";", "$", "actionFactory", "=", "app", "(", "'admin_action_factory'", ")", ";", "$", "actionName", "=", "$", "this", "->", "request", "->", "input", "(", "'action_name'", ",", "false", ")", ";", "$", "dataTable", "=", "app", "(", "'admin_datatable'", ")", ";", "//get the sort options and filters", "$", "page", "=", "$", "this", "->", "request", "->", "input", "(", "'page'", ",", "1", ")", ";", "$", "sortOptions", "=", "$", "this", "->", "request", "->", "input", "(", "'sortOptions'", ",", "array", "(", ")", ")", ";", "$", "filters", "=", "$", "this", "->", "request", "->", "input", "(", "'filters'", ",", "array", "(", ")", ")", ";", "//get the prepared query options", "$", "prepared", "=", "$", "dataTable", "->", "prepareQuery", "(", "app", "(", "'db'", ")", ",", "$", "page", ",", "$", "sortOptions", ",", "$", "filters", ")", ";", "//get the action and perform the custom action", "$", "action", "=", "$", "actionFactory", "->", "getByName", "(", "$", "actionName", ",", "true", ")", ";", "$", "result", "=", "$", "action", "->", "perform", "(", "$", "prepared", "[", "'query'", "]", ")", ";", "//if the result is a string, return that as an error.", "if", "(", "is_string", "(", "$", "result", ")", ")", "{", "return", "response", "(", ")", "->", "json", "(", "array", "(", "'success'", "=>", "false", ",", "'error'", "=>", "$", "result", ")", ")", ";", "}", "//if it's falsy, return the standard error message", "else", "if", "(", "!", "$", "result", ")", "{", "$", "messages", "=", "$", "action", "->", "getOption", "(", "'messages'", ")", ";", "return", "response", "(", ")", "->", "json", "(", "array", "(", "'success'", "=>", "false", ",", "'error'", "=>", "$", "messages", "[", "'error'", "]", ")", ")", ";", "}", "else", "{", "$", "response", "=", "array", "(", "'success'", "=>", "true", ")", ";", "//if it's a download response, flash the response to the session and return the download link", "if", "(", "is_a", "(", "$", "result", ",", "'Symfony\\Component\\HttpFoundation\\BinaryFileResponse'", ")", ")", "{", "$", "file", "=", "$", "result", "->", "getFile", "(", ")", "->", "getRealPath", "(", ")", ";", "$", "headers", "=", "$", "result", "->", "headers", "->", "all", "(", ")", ";", "$", "this", "->", "session", "->", "put", "(", "'administrator_download_response'", ",", "array", "(", "'file'", "=>", "$", "file", ",", "'headers'", "=>", "$", "headers", ")", ")", ";", "$", "response", "[", "'download'", "]", "=", "route", "(", "'admin_file_download'", ")", ";", "}", "//if it's a redirect, put the url into the redirect key so that javascript can transfer the user", "else", "if", "(", "is_a", "(", "$", "result", ",", "'\\Illuminate\\Http\\RedirectResponse'", ")", ")", "{", "$", "response", "[", "'redirect'", "]", "=", "$", "result", "->", "getTargetUrl", "(", ")", ";", "}", "return", "response", "(", ")", "->", "json", "(", "$", "response", ")", ";", "}", "}" ]
POST method for handling custom model actions @param string $modelName @return JSON
[ "POST", "method", "for", "handling", "custom", "model", "actions" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/controllers/AdminController.php#L214-L266
FrozenNode/Laravel-Administrator
src/controllers/AdminController.php
AdminController.displayFile
public function displayFile() { //get the stored path of the original $path = $this->request->input('path'); $data = File::get($path); $file = new SFile($path); $headers = array( 'Content-Type' => $file->getMimeType(), 'Content-Length' => $file->getSize(), 'Content-Disposition' => 'attachment; filename="' . $file->getFilename() . '"' ); return response()->make($data, 200, $headers); }
php
public function displayFile() { //get the stored path of the original $path = $this->request->input('path'); $data = File::get($path); $file = new SFile($path); $headers = array( 'Content-Type' => $file->getMimeType(), 'Content-Length' => $file->getSize(), 'Content-Disposition' => 'attachment; filename="' . $file->getFilename() . '"' ); return response()->make($data, 200, $headers); }
[ "public", "function", "displayFile", "(", ")", "{", "//get the stored path of the original", "$", "path", "=", "$", "this", "->", "request", "->", "input", "(", "'path'", ")", ";", "$", "data", "=", "File", "::", "get", "(", "$", "path", ")", ";", "$", "file", "=", "new", "SFile", "(", "$", "path", ")", ";", "$", "headers", "=", "array", "(", "'Content-Type'", "=>", "$", "file", "->", "getMimeType", "(", ")", ",", "'Content-Length'", "=>", "$", "file", "->", "getSize", "(", ")", ",", "'Content-Disposition'", "=>", "'attachment; filename=\"'", ".", "$", "file", "->", "getFilename", "(", ")", ".", "'\"'", ")", ";", "return", "response", "(", ")", "->", "make", "(", "$", "data", ",", "200", ",", "$", "headers", ")", ";", "}" ]
The GET method that displays a file field's file @return Image / File
[ "The", "GET", "method", "that", "displays", "a", "file", "field", "s", "file" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/controllers/AdminController.php#L430-L444
FrozenNode/Laravel-Administrator
src/controllers/AdminController.php
AdminController.resolveDynamicFormRequestErrors
protected function resolveDynamicFormRequestErrors(Request $request) { try { $config = app('itemconfig'); $fieldFactory = app('admin_field_factory'); } catch (\ReflectionException $e) { return null; } if (array_key_exists('form_request', $config->getOptions())) { try { $model = $config->getFilledDataModel($request, $fieldFactory->getEditFields(), $request->id); $request->merge($model->toArray()); $formRequestClass = $config->getOption('form_request'); app($formRequestClass); } catch (HttpResponseException $e) { //Parses the exceptions thrown by Illuminate\Foundation\Http\FormRequest $errorMessages = $e->getResponse()->getContent(); $errorsArray = json_decode($errorMessages); if (!$errorsArray && is_string ( $errorMessages )) { return $errorMessages; } if ($errorsArray) { return implode(".", array_dot($errorsArray)); } } } return null; }
php
protected function resolveDynamicFormRequestErrors(Request $request) { try { $config = app('itemconfig'); $fieldFactory = app('admin_field_factory'); } catch (\ReflectionException $e) { return null; } if (array_key_exists('form_request', $config->getOptions())) { try { $model = $config->getFilledDataModel($request, $fieldFactory->getEditFields(), $request->id); $request->merge($model->toArray()); $formRequestClass = $config->getOption('form_request'); app($formRequestClass); } catch (HttpResponseException $e) { //Parses the exceptions thrown by Illuminate\Foundation\Http\FormRequest $errorMessages = $e->getResponse()->getContent(); $errorsArray = json_decode($errorMessages); if (!$errorsArray && is_string ( $errorMessages )) { return $errorMessages; } if ($errorsArray) { return implode(".", array_dot($errorsArray)); } } } return null; }
[ "protected", "function", "resolveDynamicFormRequestErrors", "(", "Request", "$", "request", ")", "{", "try", "{", "$", "config", "=", "app", "(", "'itemconfig'", ")", ";", "$", "fieldFactory", "=", "app", "(", "'admin_field_factory'", ")", ";", "}", "catch", "(", "\\", "ReflectionException", "$", "e", ")", "{", "return", "null", ";", "}", "if", "(", "array_key_exists", "(", "'form_request'", ",", "$", "config", "->", "getOptions", "(", ")", ")", ")", "{", "try", "{", "$", "model", "=", "$", "config", "->", "getFilledDataModel", "(", "$", "request", ",", "$", "fieldFactory", "->", "getEditFields", "(", ")", ",", "$", "request", "->", "id", ")", ";", "$", "request", "->", "merge", "(", "$", "model", "->", "toArray", "(", ")", ")", ";", "$", "formRequestClass", "=", "$", "config", "->", "getOption", "(", "'form_request'", ")", ";", "app", "(", "$", "formRequestClass", ")", ";", "}", "catch", "(", "HttpResponseException", "$", "e", ")", "{", "//Parses the exceptions thrown by Illuminate\\Foundation\\Http\\FormRequest", "$", "errorMessages", "=", "$", "e", "->", "getResponse", "(", ")", "->", "getContent", "(", ")", ";", "$", "errorsArray", "=", "json_decode", "(", "$", "errorMessages", ")", ";", "if", "(", "!", "$", "errorsArray", "&&", "is_string", "(", "$", "errorMessages", ")", ")", "{", "return", "$", "errorMessages", ";", "}", "if", "(", "$", "errorsArray", ")", "{", "return", "implode", "(", "\".\"", ",", "array_dot", "(", "$", "errorsArray", ")", ")", ";", "}", "}", "}", "return", "null", ";", "}" ]
POST method to capture any form request errors @param \Illuminate\Http\Request $request
[ "POST", "method", "to", "capture", "any", "form", "request", "errors" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/controllers/AdminController.php#L641-L669
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Actions/Factory.php
Factory.getGlobalActions
public function getGlobalActions($override = false) { //make sure we only run this once and then return the cached version if (!sizeof($this->globalActions) || $override) { $this->globalActions = array(); //loop over the actions to build the list foreach ($this->config->getOption('global_actions') as $name => $options) { $this->globalActions[] = $this->make($name, $options); } } return $this->globalActions; }
php
public function getGlobalActions($override = false) { //make sure we only run this once and then return the cached version if (!sizeof($this->globalActions) || $override) { $this->globalActions = array(); //loop over the actions to build the list foreach ($this->config->getOption('global_actions') as $name => $options) { $this->globalActions[] = $this->make($name, $options); } } return $this->globalActions; }
[ "public", "function", "getGlobalActions", "(", "$", "override", "=", "false", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "!", "sizeof", "(", "$", "this", "->", "globalActions", ")", "||", "$", "override", ")", "{", "$", "this", "->", "globalActions", "=", "array", "(", ")", ";", "//loop over the actions to build the list", "foreach", "(", "$", "this", "->", "config", "->", "getOption", "(", "'global_actions'", ")", "as", "$", "name", "=>", "$", "options", ")", "{", "$", "this", "->", "globalActions", "[", "]", "=", "$", "this", "->", "make", "(", "$", "name", ",", "$", "options", ")", ";", "}", "}", "return", "$", "this", "->", "globalActions", ";", "}" ]
Gets all global actions @param bool $override @return array of Action objects
[ "Gets", "all", "global", "actions" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Actions/Factory.php#L222-L237
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Actions/Factory.php
Factory.getGlobalActionsOptions
public function getGlobalActionsOptions($override = false) { //make sure we only run this once and then return the cached version if (!sizeof($this->globalActionsOptions) || $override) { $this->globalActionsOptions = array(); //loop over the global actions to build the list foreach ($this->getGlobalActions($override) as $name => $action) { $this->globalActionsOptions[] = $action->getOptions(); } } return $this->globalActionsOptions; }
php
public function getGlobalActionsOptions($override = false) { //make sure we only run this once and then return the cached version if (!sizeof($this->globalActionsOptions) || $override) { $this->globalActionsOptions = array(); //loop over the global actions to build the list foreach ($this->getGlobalActions($override) as $name => $action) { $this->globalActionsOptions[] = $action->getOptions(); } } return $this->globalActionsOptions; }
[ "public", "function", "getGlobalActionsOptions", "(", "$", "override", "=", "false", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "!", "sizeof", "(", "$", "this", "->", "globalActionsOptions", ")", "||", "$", "override", ")", "{", "$", "this", "->", "globalActionsOptions", "=", "array", "(", ")", ";", "//loop over the global actions to build the list", "foreach", "(", "$", "this", "->", "getGlobalActions", "(", "$", "override", ")", "as", "$", "name", "=>", "$", "action", ")", "{", "$", "this", "->", "globalActionsOptions", "[", "]", "=", "$", "action", "->", "getOptions", "(", ")", ";", "}", "}", "return", "$", "this", "->", "globalActionsOptions", ";", "}" ]
Gets all actions as arrays of options @param bool $override @return array of Action options
[ "Gets", "all", "actions", "as", "arrays", "of", "options" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Actions/Factory.php#L246-L261
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Actions/Factory.php
Factory.getActionPermissions
public function getActionPermissions($override = false) { //make sure we only run this once and then return the cached version if (!sizeof($this->actionPermissions) || $override) { $this->actionPermissions = array(); $model = $this->config->getDataModel(); $options = $this->config->getOption('action_permissions'); $defaults = $this->actionPermissionsDefaults; //merge the user-supplied action permissions into the defaults $permissions = array_merge($defaults, $options); //loop over the actions to build the list foreach ($permissions as $action => $callback) { if (is_callable($callback)) { $this->actionPermissions[$action] = (bool) $callback($model); } else { $this->actionPermissions[$action] = (bool) $callback; } } } return $this->actionPermissions; }
php
public function getActionPermissions($override = false) { //make sure we only run this once and then return the cached version if (!sizeof($this->actionPermissions) || $override) { $this->actionPermissions = array(); $model = $this->config->getDataModel(); $options = $this->config->getOption('action_permissions'); $defaults = $this->actionPermissionsDefaults; //merge the user-supplied action permissions into the defaults $permissions = array_merge($defaults, $options); //loop over the actions to build the list foreach ($permissions as $action => $callback) { if (is_callable($callback)) { $this->actionPermissions[$action] = (bool) $callback($model); } else { $this->actionPermissions[$action] = (bool) $callback; } } } return $this->actionPermissions; }
[ "public", "function", "getActionPermissions", "(", "$", "override", "=", "false", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "!", "sizeof", "(", "$", "this", "->", "actionPermissions", ")", "||", "$", "override", ")", "{", "$", "this", "->", "actionPermissions", "=", "array", "(", ")", ";", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "options", "=", "$", "this", "->", "config", "->", "getOption", "(", "'action_permissions'", ")", ";", "$", "defaults", "=", "$", "this", "->", "actionPermissionsDefaults", ";", "//merge the user-supplied action permissions into the defaults", "$", "permissions", "=", "array_merge", "(", "$", "defaults", ",", "$", "options", ")", ";", "//loop over the actions to build the list", "foreach", "(", "$", "permissions", "as", "$", "action", "=>", "$", "callback", ")", "{", "if", "(", "is_callable", "(", "$", "callback", ")", ")", "{", "$", "this", "->", "actionPermissions", "[", "$", "action", "]", "=", "(", "bool", ")", "$", "callback", "(", "$", "model", ")", ";", "}", "else", "{", "$", "this", "->", "actionPermissions", "[", "$", "action", "]", "=", "(", "bool", ")", "$", "callback", ";", "}", "}", "}", "return", "$", "this", "->", "actionPermissions", ";", "}" ]
Gets all action permissions @param bool $override @return array of Action objects
[ "Gets", "all", "action", "permissions" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Actions/Factory.php#L270-L298
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php
BelongsToMany.constrainQuery
public function constrainQuery(EloquentBuilder &$query, $relatedModel, $constraint) { //if the column hasn't been joined yet, join it if (!$this->validator->isJoined($query, $this->getOption('table'))) { $query->join($this->getOption('table'), $relatedModel->getTable().'.'.$relatedModel->getKeyName(), '=', $this->getOption('column2')); } $query->where($this->getOption('table').'.'.$this->getOption('column'), '=', $constraint); }
php
public function constrainQuery(EloquentBuilder &$query, $relatedModel, $constraint) { //if the column hasn't been joined yet, join it if (!$this->validator->isJoined($query, $this->getOption('table'))) { $query->join($this->getOption('table'), $relatedModel->getTable().'.'.$relatedModel->getKeyName(), '=', $this->getOption('column2')); } $query->where($this->getOption('table').'.'.$this->getOption('column'), '=', $constraint); }
[ "public", "function", "constrainQuery", "(", "EloquentBuilder", "&", "$", "query", ",", "$", "relatedModel", ",", "$", "constraint", ")", "{", "//if the column hasn't been joined yet, join it", "if", "(", "!", "$", "this", "->", "validator", "->", "isJoined", "(", "$", "query", ",", "$", "this", "->", "getOption", "(", "'table'", ")", ")", ")", "{", "$", "query", "->", "join", "(", "$", "this", "->", "getOption", "(", "'table'", ")", ",", "$", "relatedModel", "->", "getTable", "(", ")", ".", "'.'", ".", "$", "relatedModel", "->", "getKeyName", "(", ")", ",", "'='", ",", "$", "this", "->", "getOption", "(", "'column2'", ")", ")", ";", "}", "$", "query", "->", "where", "(", "$", "this", "->", "getOption", "(", "'table'", ")", ".", "'.'", ".", "$", "this", "->", "getOption", "(", "'column'", ")", ",", "'='", ",", "$", "constraint", ")", ";", "}" ]
Constrains a query by a given set of constraints @param \Illuminate\Database\Eloquent\Builder $query @param \Illuminate\Database\Eloquent\Model $relatedModel @param string $constraint @return void
[ "Constrains", "a", "query", "by", "a", "given", "set", "of", "constraints" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php#L133-L142
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Fields/Time.php
Time.getDateString
public function getDateString(DateTime $time) { if ($this->getOption('type') === 'date') { return $time->format('Y-m-d'); } else if ($this->getOption('type') === 'datetime') { return $time->format('Y-m-d H:i:s'); } else { return $time->format('H:i:s'); } }
php
public function getDateString(DateTime $time) { if ($this->getOption('type') === 'date') { return $time->format('Y-m-d'); } else if ($this->getOption('type') === 'datetime') { return $time->format('Y-m-d H:i:s'); } else { return $time->format('H:i:s'); } }
[ "public", "function", "getDateString", "(", "DateTime", "$", "time", ")", "{", "if", "(", "$", "this", "->", "getOption", "(", "'type'", ")", "===", "'date'", ")", "{", "return", "$", "time", "->", "format", "(", "'Y-m-d'", ")", ";", "}", "else", "if", "(", "$", "this", "->", "getOption", "(", "'type'", ")", "===", "'datetime'", ")", "{", "return", "$", "time", "->", "format", "(", "'Y-m-d H:i:s'", ")", ";", "}", "else", "{", "return", "$", "time", "->", "format", "(", "'H:i:s'", ")", ";", "}", "}" ]
Get a date format from a time depending on the type of time field this is @param int $time @return string
[ "Get", "a", "date", "format", "from", "a", "time", "depending", "on", "the", "type", "of", "time", "field", "this", "is" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Fields/Time.php#L99-L113
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getDataModel
public function getDataModel() { if (!$this->model) { $name = $this->getOption('model'); $this->model = new $name; } return $this->model; }
php
public function getDataModel() { if (!$this->model) { $name = $this->getOption('model'); $this->model = new $name; } return $this->model; }
[ "public", "function", "getDataModel", "(", ")", "{", "if", "(", "!", "$", "this", "->", "model", ")", "{", "$", "name", "=", "$", "this", "->", "getOption", "(", "'model'", ")", ";", "$", "this", "->", "model", "=", "new", "$", "name", ";", "}", "return", "$", "this", "->", "model", ";", "}" ]
Fetches the data model for a config @return \Illuminate\Database\Eloquent\Model
[ "Fetches", "the", "data", "model", "for", "a", "config" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Config/Model/Config.php#L82-L91
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getRelationshipInputs
protected function getRelationshipInputs(\Illuminate\Http\Request $request, array $fields) { $inputs = array(); //run through the edit fields to find the relationships foreach ($fields as $name => $field) { if ($field->getOption('external')) { $inputs[$name] = $this->formatRelationshipInput($request->get($name, NULL), $field); } } return $inputs; }
php
protected function getRelationshipInputs(\Illuminate\Http\Request $request, array $fields) { $inputs = array(); //run through the edit fields to find the relationships foreach ($fields as $name => $field) { if ($field->getOption('external')) { $inputs[$name] = $this->formatRelationshipInput($request->get($name, NULL), $field); } } return $inputs; }
[ "protected", "function", "getRelationshipInputs", "(", "\\", "Illuminate", "\\", "Http", "\\", "Request", "$", "request", ",", "array", "$", "fields", ")", "{", "$", "inputs", "=", "array", "(", ")", ";", "//run through the edit fields to find the relationships", "foreach", "(", "$", "fields", "as", "$", "name", "=>", "$", "field", ")", "{", "if", "(", "$", "field", "->", "getOption", "(", "'external'", ")", ")", "{", "$", "inputs", "[", "$", "name", "]", "=", "$", "this", "->", "formatRelationshipInput", "(", "$", "request", "->", "get", "(", "$", "name", ",", "NULL", ")", ",", "$", "field", ")", ";", "}", "}", "return", "$", "inputs", ";", "}" ]
Gets the relationship inputs @param \Illuminate\Http\Request $request @param array $fields @return array
[ "Gets", "the", "relationship", "inputs" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Config/Model/Config.php#L459-L473
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Fields/Factory.php
Factory.validateOptions
public function validateOptions($name, $options) { if (is_string($options)) { $name = $options; $options = array(); } //if the name is not a string or the options is not an array at this point, throw an error because we can't do anything with it if (!is_string($name) || !is_array($options)) { throw new \InvalidArgumentException("One of the fields in your " . $this->config->getOption('name') . " configuration file is invalid"); } //in any case, make sure the 'column_name' option is set $options['field_name'] = $name; return $options; }
php
public function validateOptions($name, $options) { if (is_string($options)) { $name = $options; $options = array(); } //if the name is not a string or the options is not an array at this point, throw an error because we can't do anything with it if (!is_string($name) || !is_array($options)) { throw new \InvalidArgumentException("One of the fields in your " . $this->config->getOption('name') . " configuration file is invalid"); } //in any case, make sure the 'column_name' option is set $options['field_name'] = $name; return $options; }
[ "public", "function", "validateOptions", "(", "$", "name", ",", "$", "options", ")", "{", "if", "(", "is_string", "(", "$", "options", ")", ")", "{", "$", "name", "=", "$", "options", ";", "$", "options", "=", "array", "(", ")", ";", "}", "//if the name is not a string or the options is not an array at this point, throw an error because we can't do anything with it", "if", "(", "!", "is_string", "(", "$", "name", ")", "||", "!", "is_array", "(", "$", "options", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"One of the fields in your \"", ".", "$", "this", "->", "config", "->", "getOption", "(", "'name'", ")", ".", "\" configuration file is invalid\"", ")", ";", "}", "//in any case, make sure the 'column_name' option is set", "$", "options", "[", "'field_name'", "]", "=", "$", "name", ";", "return", "$", "options", ";", "}" ]
Validates an options array item. This could be a string $name and array $options, or a positive integer $name and string $options. @param mixed $name @param mixed $options @return array
[ "Validates", "an", "options", "array", "item", ".", "This", "could", "be", "a", "string", "$name", "and", "array", "$options", "or", "a", "positive", "integer", "$name", "and", "string", "$options", "." ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Fields/Factory.php#L202-L220
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Fields/Factory.php
Factory.getRelationshipKey
public function getRelationshipKey($field) { $model = $this->config->getDataModel(); $invalidArgument = new \InvalidArgumentException("The '" . $field . "' relationship field you supplied for " . $this->config->getOption('name') . " is not a valid relationship method name on the supplied Eloquent model"); //check if the related method exists on the model if (!method_exists($model, $field)) { throw $invalidArgument; } //now that we know the method exists, we can determine if it's multiple or single $related_model = $model->{$field}(); //check if this is a valid relationship object, and return the appropriate key if (is_a($related_model, $this->relationshipBase.'BelongsTo')) { return 'belongs_to'; } else if (is_a($related_model, $this->relationshipBase.'BelongsToMany')) { return 'belongs_to_many'; } else if (is_a($related_model, $this->relationshipBase.'HasOne')) { return 'has_one'; } else if (is_a($related_model, $this->relationshipBase.'HasMany')) { return 'has_many'; } else { throw $invalidArgument; } }
php
public function getRelationshipKey($field) { $model = $this->config->getDataModel(); $invalidArgument = new \InvalidArgumentException("The '" . $field . "' relationship field you supplied for " . $this->config->getOption('name') . " is not a valid relationship method name on the supplied Eloquent model"); //check if the related method exists on the model if (!method_exists($model, $field)) { throw $invalidArgument; } //now that we know the method exists, we can determine if it's multiple or single $related_model = $model->{$field}(); //check if this is a valid relationship object, and return the appropriate key if (is_a($related_model, $this->relationshipBase.'BelongsTo')) { return 'belongs_to'; } else if (is_a($related_model, $this->relationshipBase.'BelongsToMany')) { return 'belongs_to_many'; } else if (is_a($related_model, $this->relationshipBase.'HasOne')) { return 'has_one'; } else if (is_a($related_model, $this->relationshipBase.'HasMany')) { return 'has_many'; } else { throw $invalidArgument; } }
[ "public", "function", "getRelationshipKey", "(", "$", "field", ")", "{", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "invalidArgument", "=", "new", "\\", "InvalidArgumentException", "(", "\"The '\"", ".", "$", "field", ".", "\"' relationship field you supplied for \"", ".", "$", "this", "->", "config", "->", "getOption", "(", "'name'", ")", ".", "\" is not a valid relationship method name on the supplied Eloquent model\"", ")", ";", "//check if the related method exists on the model", "if", "(", "!", "method_exists", "(", "$", "model", ",", "$", "field", ")", ")", "{", "throw", "$", "invalidArgument", ";", "}", "//now that we know the method exists, we can determine if it's multiple or single", "$", "related_model", "=", "$", "model", "->", "{", "$", "field", "}", "(", ")", ";", "//check if this is a valid relationship object, and return the appropriate key", "if", "(", "is_a", "(", "$", "related_model", ",", "$", "this", "->", "relationshipBase", ".", "'BelongsTo'", ")", ")", "{", "return", "'belongs_to'", ";", "}", "else", "if", "(", "is_a", "(", "$", "related_model", ",", "$", "this", "->", "relationshipBase", ".", "'BelongsToMany'", ")", ")", "{", "return", "'belongs_to_many'", ";", "}", "else", "if", "(", "is_a", "(", "$", "related_model", ",", "$", "this", "->", "relationshipBase", ".", "'HasOne'", ")", ")", "{", "return", "'has_one'", ";", "}", "else", "if", "(", "is_a", "(", "$", "related_model", ",", "$", "this", "->", "relationshipBase", ".", "'HasMany'", ")", ")", "{", "return", "'has_many'", ";", "}", "else", "{", "throw", "$", "invalidArgument", ";", "}", "}" ]
Given a field name, returns the type key or false @param string $field the field type to check @return string|false
[ "Given", "a", "field", "name", "returns", "the", "type", "key", "or", "false" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Fields/Factory.php#L298-L334
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Fields/Factory.php
Factory.findField
public function findField($field) { $fields = $this->getEditFields(); //return either the Field object or throw an InvalidArgumentException if (!isset($fields[$field])) { throw new \InvalidArgumentException("The " . $field . " field does not exist on the " . $this->config->getOption('name') . " model"); } return $fields[$field]; }
php
public function findField($field) { $fields = $this->getEditFields(); //return either the Field object or throw an InvalidArgumentException if (!isset($fields[$field])) { throw new \InvalidArgumentException("The " . $field . " field does not exist on the " . $this->config->getOption('name') . " model"); } return $fields[$field]; }
[ "public", "function", "findField", "(", "$", "field", ")", "{", "$", "fields", "=", "$", "this", "->", "getEditFields", "(", ")", ";", "//return either the Field object or throw an InvalidArgumentException", "if", "(", "!", "isset", "(", "$", "fields", "[", "$", "field", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \"", ".", "$", "field", ".", "\" field does not exist on the \"", ".", "$", "this", "->", "config", "->", "getOption", "(", "'name'", ")", ".", "\" model\"", ")", ";", "}", "return", "$", "fields", "[", "$", "field", "]", ";", "}" ]
Given a field name, this returns the field object from the edit fields array @param string $field @return \Frozennode\Administrator\Fields\Field
[ "Given", "a", "field", "name", "this", "returns", "the", "field", "object", "from", "the", "edit", "fields", "array" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Fields/Factory.php#L343-L354
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Fields/Factory.php
Factory.findFilter
public function findFilter($field) { $filters = $this->getFilters(); //return either the Field object or throw an InvalidArgumentException if (!isset($filters[$field])) { throw new \InvalidArgumentException("The " . $field . " filter does not exist on the " . $this->config->getOption('name') . " model"); } return $filters[$field]; }
php
public function findFilter($field) { $filters = $this->getFilters(); //return either the Field object or throw an InvalidArgumentException if (!isset($filters[$field])) { throw new \InvalidArgumentException("The " . $field . " filter does not exist on the " . $this->config->getOption('name') . " model"); } return $filters[$field]; }
[ "public", "function", "findFilter", "(", "$", "field", ")", "{", "$", "filters", "=", "$", "this", "->", "getFilters", "(", ")", ";", "//return either the Field object or throw an InvalidArgumentException", "if", "(", "!", "isset", "(", "$", "filters", "[", "$", "field", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \"", ".", "$", "field", ".", "\" filter does not exist on the \"", ".", "$", "this", "->", "config", "->", "getOption", "(", "'name'", ")", ".", "\" model\"", ")", ";", "}", "return", "$", "filters", "[", "$", "field", "]", ";", "}" ]
Given a field name, this returns the field object from the filters array @param string $field @return \Frozennode\Administrator\Fields\Field
[ "Given", "a", "field", "name", "this", "returns", "the", "field", "object", "from", "the", "filters", "array" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Fields/Factory.php#L363-L374
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Fields/Factory.php
Factory.getEditFields
public function getEditFields($loadRelationships = true, $override = false) { if (!sizeof($this->editFields) || $override) { $this->editFields = array(); //iterate over each supplied edit field foreach ($this->config->getOption('edit_fields') as $name => $options) { $fieldObject = $this->make($name, $options, $loadRelationships); $this->editFields[$fieldObject->getOption('field_name')] = $fieldObject; } } return $this->editFields; }
php
public function getEditFields($loadRelationships = true, $override = false) { if (!sizeof($this->editFields) || $override) { $this->editFields = array(); //iterate over each supplied edit field foreach ($this->config->getOption('edit_fields') as $name => $options) { $fieldObject = $this->make($name, $options, $loadRelationships); $this->editFields[$fieldObject->getOption('field_name')] = $fieldObject; } } return $this->editFields; }
[ "public", "function", "getEditFields", "(", "$", "loadRelationships", "=", "true", ",", "$", "override", "=", "false", ")", "{", "if", "(", "!", "sizeof", "(", "$", "this", "->", "editFields", ")", "||", "$", "override", ")", "{", "$", "this", "->", "editFields", "=", "array", "(", ")", ";", "//iterate over each supplied edit field", "foreach", "(", "$", "this", "->", "config", "->", "getOption", "(", "'edit_fields'", ")", "as", "$", "name", "=>", "$", "options", ")", "{", "$", "fieldObject", "=", "$", "this", "->", "make", "(", "$", "name", ",", "$", "options", ",", "$", "loadRelationships", ")", ";", "$", "this", "->", "editFields", "[", "$", "fieldObject", "->", "getOption", "(", "'field_name'", ")", "]", "=", "$", "fieldObject", ";", "}", "}", "return", "$", "this", "->", "editFields", ";", "}" ]
Creates the edit fields as Field objects @param boolean $loadRelationships //if set to false, no relationship options will be loaded @param boolean $override //if set to true, the fields will be re-loaded, otherwise it will use the cached fields @return array
[ "Creates", "the", "edit", "fields", "as", "Field", "objects" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Fields/Factory.php#L384-L399
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/Fields/Factory.php
Factory.applyConstraints
public function applyConstraints($constraints, EloquentBuilder &$query, Field $fieldObject) { $configConstraints = $fieldObject->getOption('constraints'); if (sizeof($configConstraints)) { //iterate over the config constraints foreach ($configConstraints as $key => $relationshipName) { //now that we're looping through the constraints, check to see if this one was supplied if (isset($constraints[$key]) && $constraints[$key] && sizeof($constraints[$key])) { //first we get the other model and the relationship field on it $model = $this->config->getDataModel(); $relatedModel = $model->{$fieldObject->getOption('field_name')}()->getRelated(); $otherModel = $model->{$key}()->getRelated(); //set the data model for the config $this->config->setDataModel($otherModel); $otherField = $this->make($relationshipName, array('type' => 'relationship'), false); //constrain the query $otherField->constrainQuery($query, $relatedModel, $constraints[$key]); //set the data model back to the original $this->config->setDataModel($model); } } } }
php
public function applyConstraints($constraints, EloquentBuilder &$query, Field $fieldObject) { $configConstraints = $fieldObject->getOption('constraints'); if (sizeof($configConstraints)) { //iterate over the config constraints foreach ($configConstraints as $key => $relationshipName) { //now that we're looping through the constraints, check to see if this one was supplied if (isset($constraints[$key]) && $constraints[$key] && sizeof($constraints[$key])) { //first we get the other model and the relationship field on it $model = $this->config->getDataModel(); $relatedModel = $model->{$fieldObject->getOption('field_name')}()->getRelated(); $otherModel = $model->{$key}()->getRelated(); //set the data model for the config $this->config->setDataModel($otherModel); $otherField = $this->make($relationshipName, array('type' => 'relationship'), false); //constrain the query $otherField->constrainQuery($query, $relatedModel, $constraints[$key]); //set the data model back to the original $this->config->setDataModel($model); } } } }
[ "public", "function", "applyConstraints", "(", "$", "constraints", ",", "EloquentBuilder", "&", "$", "query", ",", "Field", "$", "fieldObject", ")", "{", "$", "configConstraints", "=", "$", "fieldObject", "->", "getOption", "(", "'constraints'", ")", ";", "if", "(", "sizeof", "(", "$", "configConstraints", ")", ")", "{", "//iterate over the config constraints", "foreach", "(", "$", "configConstraints", "as", "$", "key", "=>", "$", "relationshipName", ")", "{", "//now that we're looping through the constraints, check to see if this one was supplied", "if", "(", "isset", "(", "$", "constraints", "[", "$", "key", "]", ")", "&&", "$", "constraints", "[", "$", "key", "]", "&&", "sizeof", "(", "$", "constraints", "[", "$", "key", "]", ")", ")", "{", "//first we get the other model and the relationship field on it", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "relatedModel", "=", "$", "model", "->", "{", "$", "fieldObject", "->", "getOption", "(", "'field_name'", ")", "}", "(", ")", "->", "getRelated", "(", ")", ";", "$", "otherModel", "=", "$", "model", "->", "{", "$", "key", "}", "(", ")", "->", "getRelated", "(", ")", ";", "//set the data model for the config", "$", "this", "->", "config", "->", "setDataModel", "(", "$", "otherModel", ")", ";", "$", "otherField", "=", "$", "this", "->", "make", "(", "$", "relationshipName", ",", "array", "(", "'type'", "=>", "'relationship'", ")", ",", "false", ")", ";", "//constrain the query", "$", "otherField", "->", "constrainQuery", "(", "$", "query", ",", "$", "relatedModel", ",", "$", "constraints", "[", "$", "key", "]", ")", ";", "//set the data model back to the original", "$", "this", "->", "config", "->", "setDataModel", "(", "$", "model", ")", ";", "}", "}", "}", "}" ]
Takes the supplied $selectedItems mixed value and formats it to a usable array @param mixed $constraints @param \Illuminate\Database\Query\Builder $query @param \Frozennode\Administrator\Fields\Field $fieldObject @return array
[ "Takes", "the", "supplied", "$selectedItems", "mixed", "value", "and", "formats", "it", "to", "a", "usable", "array" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/Fields/Factory.php#L712-L741
FrozenNode/Laravel-Administrator
src/Frozennode/Administrator/DataTable/Columns/Relationships/BelongsTo.php
BelongsTo.filterQuery
public function filterQuery(&$selects) { $model = $this->config->getDataModel(); $joins = $where = ''; $columnName = $this->getOption('column_name'); $nested = $this->getOption('nested'); $num_pieces = sizeof($nested['pieces']); //if there is more than one nested relationship, we need to join all the tables if ($num_pieces > 1) { for ($i = 1; $i < $num_pieces; $i++) { $model = $nested['models'][$i]; $relationship = $model->{$nested['pieces'][$i]}(); $relationship_model = $relationship->getRelated(); $table = $this->tablePrefix . $relationship_model->getTable(); $alias = $columnName . '_' . $table; $last_alias = $columnName . '_' . $this->tablePrefix . $model->getTable(); $joins .= ' LEFT JOIN ' . $table . ' AS ' . $alias . ' ON ' . $alias . '.' . $relationship->getOtherKey() . ' = ' . $last_alias . '.' . $relationship->getForeignKey(); } } $first_model = $nested['models'][0]; $first_piece = $nested['pieces'][0]; $first_relationship = $first_model->{$first_piece}(); $relationship_model = $first_relationship->getRelated(); $from_table = $this->tablePrefix . $relationship_model->getTable(); $field_table = $columnName . '_' . $from_table; $where = $this->tablePrefix . $first_model->getTable() . '.' . $first_relationship->getForeignKey() . ' = ' . $field_table . '.' . $first_relationship->getOtherKey(); $selects[] = $this->db->raw("(SELECT " . $this->getOption('select') . " FROM " . $from_table." AS " . $field_table . ' ' . $joins . " WHERE " . $where . ") AS " . $this->db->getQueryGrammar()->wrap($columnName)); }
php
public function filterQuery(&$selects) { $model = $this->config->getDataModel(); $joins = $where = ''; $columnName = $this->getOption('column_name'); $nested = $this->getOption('nested'); $num_pieces = sizeof($nested['pieces']); //if there is more than one nested relationship, we need to join all the tables if ($num_pieces > 1) { for ($i = 1; $i < $num_pieces; $i++) { $model = $nested['models'][$i]; $relationship = $model->{$nested['pieces'][$i]}(); $relationship_model = $relationship->getRelated(); $table = $this->tablePrefix . $relationship_model->getTable(); $alias = $columnName . '_' . $table; $last_alias = $columnName . '_' . $this->tablePrefix . $model->getTable(); $joins .= ' LEFT JOIN ' . $table . ' AS ' . $alias . ' ON ' . $alias . '.' . $relationship->getOtherKey() . ' = ' . $last_alias . '.' . $relationship->getForeignKey(); } } $first_model = $nested['models'][0]; $first_piece = $nested['pieces'][0]; $first_relationship = $first_model->{$first_piece}(); $relationship_model = $first_relationship->getRelated(); $from_table = $this->tablePrefix . $relationship_model->getTable(); $field_table = $columnName . '_' . $from_table; $where = $this->tablePrefix . $first_model->getTable() . '.' . $first_relationship->getForeignKey() . ' = ' . $field_table . '.' . $first_relationship->getOtherKey(); $selects[] = $this->db->raw("(SELECT " . $this->getOption('select') . " FROM " . $from_table." AS " . $field_table . ' ' . $joins . " WHERE " . $where . ") AS " . $this->db->getQueryGrammar()->wrap($columnName)); }
[ "public", "function", "filterQuery", "(", "&", "$", "selects", ")", "{", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "joins", "=", "$", "where", "=", "''", ";", "$", "columnName", "=", "$", "this", "->", "getOption", "(", "'column_name'", ")", ";", "$", "nested", "=", "$", "this", "->", "getOption", "(", "'nested'", ")", ";", "$", "num_pieces", "=", "sizeof", "(", "$", "nested", "[", "'pieces'", "]", ")", ";", "//if there is more than one nested relationship, we need to join all the tables", "if", "(", "$", "num_pieces", ">", "1", ")", "{", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "$", "num_pieces", ";", "$", "i", "++", ")", "{", "$", "model", "=", "$", "nested", "[", "'models'", "]", "[", "$", "i", "]", ";", "$", "relationship", "=", "$", "model", "->", "{", "$", "nested", "[", "'pieces'", "]", "[", "$", "i", "]", "}", "(", ")", ";", "$", "relationship_model", "=", "$", "relationship", "->", "getRelated", "(", ")", ";", "$", "table", "=", "$", "this", "->", "tablePrefix", ".", "$", "relationship_model", "->", "getTable", "(", ")", ";", "$", "alias", "=", "$", "columnName", ".", "'_'", ".", "$", "table", ";", "$", "last_alias", "=", "$", "columnName", ".", "'_'", ".", "$", "this", "->", "tablePrefix", ".", "$", "model", "->", "getTable", "(", ")", ";", "$", "joins", ".=", "' LEFT JOIN '", ".", "$", "table", ".", "' AS '", ".", "$", "alias", ".", "' ON '", ".", "$", "alias", ".", "'.'", ".", "$", "relationship", "->", "getOtherKey", "(", ")", ".", "' = '", ".", "$", "last_alias", ".", "'.'", ".", "$", "relationship", "->", "getForeignKey", "(", ")", ";", "}", "}", "$", "first_model", "=", "$", "nested", "[", "'models'", "]", "[", "0", "]", ";", "$", "first_piece", "=", "$", "nested", "[", "'pieces'", "]", "[", "0", "]", ";", "$", "first_relationship", "=", "$", "first_model", "->", "{", "$", "first_piece", "}", "(", ")", ";", "$", "relationship_model", "=", "$", "first_relationship", "->", "getRelated", "(", ")", ";", "$", "from_table", "=", "$", "this", "->", "tablePrefix", ".", "$", "relationship_model", "->", "getTable", "(", ")", ";", "$", "field_table", "=", "$", "columnName", ".", "'_'", ".", "$", "from_table", ";", "$", "where", "=", "$", "this", "->", "tablePrefix", ".", "$", "first_model", "->", "getTable", "(", ")", ".", "'.'", ".", "$", "first_relationship", "->", "getForeignKey", "(", ")", ".", "' = '", ".", "$", "field_table", ".", "'.'", ".", "$", "first_relationship", "->", "getOtherKey", "(", ")", ";", "$", "selects", "[", "]", "=", "$", "this", "->", "db", "->", "raw", "(", "\"(SELECT \"", ".", "$", "this", "->", "getOption", "(", "'select'", ")", ".", "\"\n\t\t\t\t\t\t\t\t\t\tFROM \"", ".", "$", "from_table", ".", "\" AS \"", ".", "$", "field_table", ".", "' '", ".", "$", "joins", ".", "\"\n\t\t\t\t\t\t\t\t\t\tWHERE \"", ".", "$", "where", ".", "\") AS \"", ".", "$", "this", "->", "db", "->", "getQueryGrammar", "(", ")", "->", "wrap", "(", "$", "columnName", ")", ")", ";", "}" ]
Adds selects to a query @param array $selects @return void
[ "Adds", "selects", "to", "a", "query" ]
train
https://github.com/FrozenNode/Laravel-Administrator/blob/34d604c2029ce2b11f93599baf4ec909501fd356/src/Frozennode/Administrator/DataTable/Columns/Relationships/BelongsTo.php#L92-L131