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
axelitus/php-base
src/Str.php
Str.nsprintf
public static function nsprintf($format, array $args = []) { // Filter unnamed %s strings that should not be processed $filterRegex = '/%s/'; $format = preg_replace($filterRegex, '#[:~s]#', $format); // The pattern to match variables $pattern = '/(?<=%)([a-zA-Z0-9_]\w*)(?=\$)/'; // Add predefined values $pool = ['cr' => "\r", 'lf' => "\n", 'crlf' => "\r\n", 'tab' => "\t"] + $args; // Build args array and substitute variables with numbers $args = []; $pos = 0; $match = null; while (static::match($format, $pattern, $match, PREG_OFFSET_CAPTURE, $pos)) { list($varKey, $varPos) = $match[0]; if (!array_key_exists($varKey, $pool)) { throw new \BadFunctionCallException("Missing argument '${varKey}'.", E_USER_WARNING); } array_push($args, $pool[$varKey]); $format = substr_replace($format, count($args), $varPos, $wordLength = static::length($varKey)); $pos = $varPos + $wordLength; // skip to end of replacement for next iteration } // Return the original %s strings $filterRegex = '/#\[:~s\]#/'; return preg_replace($filterRegex, '%s', vsprintf($format, $args)); }
php
public static function nsprintf($format, array $args = []) { // Filter unnamed %s strings that should not be processed $filterRegex = '/%s/'; $format = preg_replace($filterRegex, '#[:~s]#', $format); // The pattern to match variables $pattern = '/(?<=%)([a-zA-Z0-9_]\w*)(?=\$)/'; // Add predefined values $pool = ['cr' => "\r", 'lf' => "\n", 'crlf' => "\r\n", 'tab' => "\t"] + $args; // Build args array and substitute variables with numbers $args = []; $pos = 0; $match = null; while (static::match($format, $pattern, $match, PREG_OFFSET_CAPTURE, $pos)) { list($varKey, $varPos) = $match[0]; if (!array_key_exists($varKey, $pool)) { throw new \BadFunctionCallException("Missing argument '${varKey}'.", E_USER_WARNING); } array_push($args, $pool[$varKey]); $format = substr_replace($format, count($args), $varPos, $wordLength = static::length($varKey)); $pos = $varPos + $wordLength; // skip to end of replacement for next iteration } // Return the original %s strings $filterRegex = '/#\[:~s\]#/'; return preg_replace($filterRegex, '%s', vsprintf($format, $args)); }
[ "public", "static", "function", "nsprintf", "(", "$", "format", ",", "array", "$", "args", "=", "[", "]", ")", "{", "// Filter unnamed %s strings that should not be processed", "$", "filterRegex", "=", "'/%s/'", ";", "$", "format", "=", "preg_replace", "(", "$", "filterRegex", ",", "'#[:~s]#'", ",", "$", "format", ")", ";", "// The pattern to match variables", "$", "pattern", "=", "'/(?<=%)([a-zA-Z0-9_]\\w*)(?=\\$)/'", ";", "// Add predefined values", "$", "pool", "=", "[", "'cr'", "=>", "\"\\r\"", ",", "'lf'", "=>", "\"\\n\"", ",", "'crlf'", "=>", "\"\\r\\n\"", ",", "'tab'", "=>", "\"\\t\"", "]", "+", "$", "args", ";", "// Build args array and substitute variables with numbers", "$", "args", "=", "[", "]", ";", "$", "pos", "=", "0", ";", "$", "match", "=", "null", ";", "while", "(", "static", "::", "match", "(", "$", "format", ",", "$", "pattern", ",", "$", "match", ",", "PREG_OFFSET_CAPTURE", ",", "$", "pos", ")", ")", "{", "list", "(", "$", "varKey", ",", "$", "varPos", ")", "=", "$", "match", "[", "0", "]", ";", "if", "(", "!", "array_key_exists", "(", "$", "varKey", ",", "$", "pool", ")", ")", "{", "throw", "new", "\\", "BadFunctionCallException", "(", "\"Missing argument '${varKey}'.\"", ",", "E_USER_WARNING", ")", ";", "}", "array_push", "(", "$", "args", ",", "$", "pool", "[", "$", "varKey", "]", ")", ";", "$", "format", "=", "substr_replace", "(", "$", "format", ",", "count", "(", "$", "args", ")", ",", "$", "varPos", ",", "$", "wordLength", "=", "static", "::", "length", "(", "$", "varKey", ")", ")", ";", "$", "pos", "=", "$", "varPos", "+", "$", "wordLength", ";", "// skip to end of replacement for next iteration", "}", "// Return the original %s strings", "$", "filterRegex", "=", "'/#\\[:~s\\]#/'", ";", "return", "preg_replace", "(", "$", "filterRegex", ",", "'%s'", ",", "vsprintf", "(", "$", "format", ",", "$", "args", ")", ")", ";", "}" ]
Function sprintf for named variables inside format. Args are only used if found in the format. Predefined tags (which can be overwritten passing them as args): %cr$s -> \r %lf$s -> \n %crlf$s -> \r\n %tab$s -> \t This method is based on the work of Nate Bessette (www.twitter.com/frickenate) @param string $format The format to replace the named variables into @param array $args The args to be replaced (var => replacement). @return string|bool The string with args replaced or false on error @throws \BadFunctionCallException @throws \LengthException
[ "Function", "sprintf", "for", "named", "variables", "inside", "format", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Str.php#L872-L904
ryanwachtl/silverstripe-foundation-forms
code/forms/FoundationSwitchField.php
FoundationSwitchField.getSource
public function getSource() { if (is_array($this->source)) { if (count($this->source) != 2) { user_error('FoundationSwitchField::getSource(): accepts only 2 options', E_USER_ERROR); } return array_slice($this->source, 0, 2); } }
php
public function getSource() { if (is_array($this->source)) { if (count($this->source) != 2) { user_error('FoundationSwitchField::getSource(): accepts only 2 options', E_USER_ERROR); } return array_slice($this->source, 0, 2); } }
[ "public", "function", "getSource", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "source", ")", ")", "{", "if", "(", "count", "(", "$", "this", "->", "source", ")", "!=", "2", ")", "{", "user_error", "(", "'FoundationSwitchField::getSource(): accepts only 2 options'", ",", "E_USER_ERROR", ")", ";", "}", "return", "array_slice", "(", "$", "this", "->", "source", ",", "0", ",", "2", ")", ";", "}", "}" ]
Gets the first two items from source array, since SwitchField only works with two values. @return array
[ "Gets", "the", "first", "two", "items", "from", "source", "array", "since", "SwitchField", "only", "works", "with", "two", "values", "." ]
train
https://github.com/ryanwachtl/silverstripe-foundation-forms/blob/9055449fcb895811187124d81e57b7c93948403f/code/forms/FoundationSwitchField.php#L26-L33
gintonicweb/GintonicCMS
src/Shell/GintonicShell.php
GintonicShell.install
public function install() { $connections = ConnectionManager::configured(); if (empty($connections)) { $this->out('Your database configuration was not found.'); $this->out('Add your database connection information to config/app.php.'); return false; } $this->migrate(); $this->migrate('Users'); $this->migrate('Permissions'); $this->cleanup(); }
php
public function install() { $connections = ConnectionManager::configured(); if (empty($connections)) { $this->out('Your database configuration was not found.'); $this->out('Add your database connection information to config/app.php.'); return false; } $this->migrate(); $this->migrate('Users'); $this->migrate('Permissions'); $this->cleanup(); }
[ "public", "function", "install", "(", ")", "{", "$", "connections", "=", "ConnectionManager", "::", "configured", "(", ")", ";", "if", "(", "empty", "(", "$", "connections", ")", ")", "{", "$", "this", "->", "out", "(", "'Your database configuration was not found.'", ")", ";", "$", "this", "->", "out", "(", "'Add your database connection information to config/app.php.'", ")", ";", "return", "false", ";", "}", "$", "this", "->", "migrate", "(", ")", ";", "$", "this", "->", "migrate", "(", "'Users'", ")", ";", "$", "this", "->", "migrate", "(", "'Permissions'", ")", ";", "$", "this", "->", "cleanup", "(", ")", ";", "}" ]
main() method. @return bool|int Success or error code.
[ "main", "()", "method", "." ]
train
https://github.com/gintonicweb/GintonicCMS/blob/b34445fecea56a7d432d0f3e2f988cde8ead746b/src/Shell/GintonicShell.php#L21-L35
gintonicweb/GintonicCMS
src/Shell/GintonicShell.php
GintonicShell.cleanup
public function cleanup() { Cache::clear(false, 'default'); Cache::clear(false, '_cake_model_'); Cache::clear(false, '_cake_core_'); $this->dispatchShell('orm_cache clear'); $this->dispatchShell('orm_cache build'); }
php
public function cleanup() { Cache::clear(false, 'default'); Cache::clear(false, '_cake_model_'); Cache::clear(false, '_cake_core_'); $this->dispatchShell('orm_cache clear'); $this->dispatchShell('orm_cache build'); }
[ "public", "function", "cleanup", "(", ")", "{", "Cache", "::", "clear", "(", "false", ",", "'default'", ")", ";", "Cache", "::", "clear", "(", "false", ",", "'_cake_model_'", ")", ";", "Cache", "::", "clear", "(", "false", ",", "'_cake_core_'", ")", ";", "$", "this", "->", "dispatchShell", "(", "'orm_cache clear'", ")", ";", "$", "this", "->", "dispatchShell", "(", "'orm_cache build'", ")", ";", "}" ]
Clears the cache @return void
[ "Clears", "the", "cache" ]
train
https://github.com/gintonicweb/GintonicCMS/blob/b34445fecea56a7d432d0f3e2f988cde8ead746b/src/Shell/GintonicShell.php#L42-L49
gintonicweb/GintonicCMS
src/Shell/GintonicShell.php
GintonicShell.migrate
public function migrate($plugin = null) { $plugin = ($plugin === null)? '' : ' -p ' . $plugin; $this->dispatchShell('migrations migrate' . $plugin); }
php
public function migrate($plugin = null) { $plugin = ($plugin === null)? '' : ' -p ' . $plugin; $this->dispatchShell('migrations migrate' . $plugin); }
[ "public", "function", "migrate", "(", "$", "plugin", "=", "null", ")", "{", "$", "plugin", "=", "(", "$", "plugin", "===", "null", ")", "?", "''", ":", "' -p '", ".", "$", "plugin", ";", "$", "this", "->", "dispatchShell", "(", "'migrations migrate'", ".", "$", "plugin", ")", ";", "}" ]
Run the migration, optionally for a plugin @param string $plugin Plugin name (optional) @return void
[ "Run", "the", "migration", "optionally", "for", "a", "plugin" ]
train
https://github.com/gintonicweb/GintonicCMS/blob/b34445fecea56a7d432d0f3e2f988cde8ead746b/src/Shell/GintonicShell.php#L57-L61
faustbrian/Laravel-Countries
src/Console/Commands/SeedCountries.php
SeedCountries.handle
public function handle() { $model = $this->getModel(); $data = base_path('vendor/mledoze/countries/dist/countries.json'); $data = json_decode(file_get_contents($data), true); foreach ($data as $country) { $model->create($country); } $this->getOutput()->writeln('<info>Seeded:</info> Countries'); }
php
public function handle() { $model = $this->getModel(); $data = base_path('vendor/mledoze/countries/dist/countries.json'); $data = json_decode(file_get_contents($data), true); foreach ($data as $country) { $model->create($country); } $this->getOutput()->writeln('<info>Seeded:</info> Countries'); }
[ "public", "function", "handle", "(", ")", "{", "$", "model", "=", "$", "this", "->", "getModel", "(", ")", ";", "$", "data", "=", "base_path", "(", "'vendor/mledoze/countries/dist/countries.json'", ")", ";", "$", "data", "=", "json_decode", "(", "file_get_contents", "(", "$", "data", ")", ",", "true", ")", ";", "foreach", "(", "$", "data", "as", "$", "country", ")", "{", "$", "model", "->", "create", "(", "$", "country", ")", ";", "}", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "'<info>Seeded:</info> Countries'", ")", ";", "}" ]
Execute the console command. @return mixed
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/faustbrian/Laravel-Countries/blob/3d72301acd37e7f351d9b991dba41807ab68362b/src/Console/Commands/SeedCountries.php#L40-L52
mayoturis/properties-ini
src/FileSaver.php
FileSaver.save
public function save($fileName, $values, $map = null) { if ($map !== null) { $output = $this->createOutputWithMap($values,$map); } else { $output = $this->createOutput($values); } $this->saveToFile($fileName, $output); }
php
public function save($fileName, $values, $map = null) { if ($map !== null) { $output = $this->createOutputWithMap($values,$map); } else { $output = $this->createOutput($values); } $this->saveToFile($fileName, $output); }
[ "public", "function", "save", "(", "$", "fileName", ",", "$", "values", ",", "$", "map", "=", "null", ")", "{", "if", "(", "$", "map", "!==", "null", ")", "{", "$", "output", "=", "$", "this", "->", "createOutputWithMap", "(", "$", "values", ",", "$", "map", ")", ";", "}", "else", "{", "$", "output", "=", "$", "this", "->", "createOutput", "(", "$", "values", ")", ";", "}", "$", "this", "->", "saveToFile", "(", "$", "fileName", ",", "$", "output", ")", ";", "}" ]
Writes configuration array to file @param string $fileName File name @param array $values Configuration values @param array|null $map File map
[ "Writes", "configuration", "array", "to", "file" ]
train
https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/FileSaver.php#L24-L32
mayoturis/properties-ini
src/FileSaver.php
FileSaver.createOutputWithMap
public function createOutputWithMap(array $values, array $map) { $output = ''; foreach ($map as $outputLine) { if ($outputLine['type'] == 'empty') { $output .= PHP_EOL; } elseif($outputLine['type'] == 'comment') { $output .= $outputLine['value'] . PHP_EOL; } else { $output .= $this->createLine($outputLine['key'], $values[$outputLine['key']], $outputLine) . PHP_EOL; unset($values[$outputLine['key']]); } } // Add values which are not mapped at the end $output .= $this->createOutput($values); return $output; }
php
public function createOutputWithMap(array $values, array $map) { $output = ''; foreach ($map as $outputLine) { if ($outputLine['type'] == 'empty') { $output .= PHP_EOL; } elseif($outputLine['type'] == 'comment') { $output .= $outputLine['value'] . PHP_EOL; } else { $output .= $this->createLine($outputLine['key'], $values[$outputLine['key']], $outputLine) . PHP_EOL; unset($values[$outputLine['key']]); } } // Add values which are not mapped at the end $output .= $this->createOutput($values); return $output; }
[ "public", "function", "createOutputWithMap", "(", "array", "$", "values", ",", "array", "$", "map", ")", "{", "$", "output", "=", "''", ";", "foreach", "(", "$", "map", "as", "$", "outputLine", ")", "{", "if", "(", "$", "outputLine", "[", "'type'", "]", "==", "'empty'", ")", "{", "$", "output", ".=", "PHP_EOL", ";", "}", "elseif", "(", "$", "outputLine", "[", "'type'", "]", "==", "'comment'", ")", "{", "$", "output", ".=", "$", "outputLine", "[", "'value'", "]", ".", "PHP_EOL", ";", "}", "else", "{", "$", "output", ".=", "$", "this", "->", "createLine", "(", "$", "outputLine", "[", "'key'", "]", ",", "$", "values", "[", "$", "outputLine", "[", "'key'", "]", "]", ",", "$", "outputLine", ")", ".", "PHP_EOL", ";", "unset", "(", "$", "values", "[", "$", "outputLine", "[", "'key'", "]", "]", ")", ";", "}", "}", "// Add values which are not mapped at the end", "$", "output", ".=", "$", "this", "->", "createOutput", "(", "$", "values", ")", ";", "return", "$", "output", ";", "}" ]
Creates output string with provided map @param array $values Configuration values @param array $map @return string
[ "Creates", "output", "string", "with", "provided", "map" ]
train
https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/FileSaver.php#L41-L58
mayoturis/properties-ini
src/FileSaver.php
FileSaver.createOutput
public function createOutput($values) { $output = ''; foreach ($values as $key => $value) { $output .= $this->createLine($key, $value) . PHP_EOL; } return $output; }
php
public function createOutput($values) { $output = ''; foreach ($values as $key => $value) { $output .= $this->createLine($key, $value) . PHP_EOL; } return $output; }
[ "public", "function", "createOutput", "(", "$", "values", ")", "{", "$", "output", "=", "''", ";", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "output", ".=", "$", "this", "->", "createLine", "(", "$", "key", ",", "$", "value", ")", ".", "PHP_EOL", ";", "}", "return", "$", "output", ";", "}" ]
Creates output string from configuration values @param array $values Configuration values @return string
[ "Creates", "output", "string", "from", "configuration", "values" ]
train
https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/FileSaver.php#L66-L73
mayoturis/properties-ini
src/FileSaver.php
FileSaver.createLine
protected function createLine($key, $value, $outputLineMap = null) { return $key .= '=' . $this->createValue($value, $outputLineMap); }
php
protected function createLine($key, $value, $outputLineMap = null) { return $key .= '=' . $this->createValue($value, $outputLineMap); }
[ "protected", "function", "createLine", "(", "$", "key", ",", "$", "value", ",", "$", "outputLineMap", "=", "null", ")", "{", "return", "$", "key", ".=", "'='", ".", "$", "this", "->", "createValue", "(", "$", "value", ",", "$", "outputLineMap", ")", ";", "}" ]
Creates string from $key and $value @param string $key @param mixed $value @param array|null $outputLineMap @return string
[ "Creates", "string", "from", "$key", "and", "$value" ]
train
https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/FileSaver.php#L83-L85
mayoturis/properties-ini
src/FileSaver.php
FileSaver.createValue
protected function createValue($value, $outputLineMap = null) { if (is_bool($value)) { return $this->processor->boolToString($value); } if (is_numeric($value)) { return $value . ''; } if ($value == null) { return 'null'; } if (isset($outputLineMap['info']['around'])) { return $outputLineMap['info']['around'] . $value . $outputLineMap['info']['around']; } if ($outputLineMap === null) { return '"' . $value . '"'; } return $value; }
php
protected function createValue($value, $outputLineMap = null) { if (is_bool($value)) { return $this->processor->boolToString($value); } if (is_numeric($value)) { return $value . ''; } if ($value == null) { return 'null'; } if (isset($outputLineMap['info']['around'])) { return $outputLineMap['info']['around'] . $value . $outputLineMap['info']['around']; } if ($outputLineMap === null) { return '"' . $value . '"'; } return $value; }
[ "protected", "function", "createValue", "(", "$", "value", ",", "$", "outputLineMap", "=", "null", ")", "{", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "return", "$", "this", "->", "processor", "->", "boolToString", "(", "$", "value", ")", ";", "}", "if", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "return", "$", "value", ".", "''", ";", "}", "if", "(", "$", "value", "==", "null", ")", "{", "return", "'null'", ";", "}", "if", "(", "isset", "(", "$", "outputLineMap", "[", "'info'", "]", "[", "'around'", "]", ")", ")", "{", "return", "$", "outputLineMap", "[", "'info'", "]", "[", "'around'", "]", ".", "$", "value", ".", "$", "outputLineMap", "[", "'info'", "]", "[", "'around'", "]", ";", "}", "if", "(", "$", "outputLineMap", "===", "null", ")", "{", "return", "'\"'", ".", "$", "value", ".", "'\"'", ";", "}", "return", "$", "value", ";", "}" ]
Creates string from $value. $outputLineMap can help to create the value @param mixed $value @param array|null $outputLineMap @return string
[ "Creates", "string", "from", "$value", ".", "$outputLineMap", "can", "help", "to", "create", "the", "value" ]
train
https://github.com/mayoturis/properties-ini/blob/79d56d8174637b1124eb90a41ffa3dca4c4a4e93/src/FileSaver.php#L95-L117
phossa2/middleware
src/Middleware/Queue.php
Queue.push
public function push($middleware, $condition = null) { $this->queue->push([$middleware, $condition]); $this->queue->rewind(); return $this; }
php
public function push($middleware, $condition = null) { $this->queue->push([$middleware, $condition]); $this->queue->rewind(); return $this; }
[ "public", "function", "push", "(", "$", "middleware", ",", "$", "condition", "=", "null", ")", "{", "$", "this", "->", "queue", "->", "push", "(", "[", "$", "middleware", ",", "$", "condition", "]", ")", ";", "$", "this", "->", "queue", "->", "rewind", "(", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/phossa2/middleware/blob/518e97ae48077f2c11adcd3c2393830ed7ab7ce7/src/Middleware/Queue.php#L92-L97
phossa2/middleware
src/Middleware/Queue.php
Queue.process
public function process( RequestInterface $request, ResponseInterface $response, DelegateInterface $next = null )/*# : ResponseInterface */ { // process the queue $response = $this->next($request, $response); // $next is parent queue return ($next && !$this->terminate) ? $next->next($request, $response) : $response; }
php
public function process( RequestInterface $request, ResponseInterface $response, DelegateInterface $next = null )/*# : ResponseInterface */ { // process the queue $response = $this->next($request, $response); // $next is parent queue return ($next && !$this->terminate) ? $next->next($request, $response) : $response; }
[ "public", "function", "process", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ",", "DelegateInterface", "$", "next", "=", "null", ")", "/*# : ResponseInterface */", "{", "// process the queue", "$", "response", "=", "$", "this", "->", "next", "(", "$", "request", ",", "$", "response", ")", ";", "// $next is parent queue", "return", "(", "$", "next", "&&", "!", "$", "this", "->", "terminate", ")", "?", "$", "next", "->", "next", "(", "$", "request", ",", "$", "response", ")", ":", "$", "response", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/phossa2/middleware/blob/518e97ae48077f2c11adcd3c2393830ed7ab7ce7/src/Middleware/Queue.php#L102-L114
phossa2/middleware
src/Middleware/Queue.php
Queue.next
public function next( RequestInterface $request, ResponseInterface $response )/*# : ResponseInterface */ { if ($this->queue->valid()) { list($middleware, $condition) = $this->queue->current(); $this->queue->next(); if (null === $condition || $this->evalCondition($condition, $request, $response) ) { // run this mw return $this->runMiddleware($middleware, $request, $response); } else { // skip this mw return $this->next($request, $response); } } $this->queue->rewind(); return $response; }
php
public function next( RequestInterface $request, ResponseInterface $response )/*# : ResponseInterface */ { if ($this->queue->valid()) { list($middleware, $condition) = $this->queue->current(); $this->queue->next(); if (null === $condition || $this->evalCondition($condition, $request, $response) ) { // run this mw return $this->runMiddleware($middleware, $request, $response); } else { // skip this mw return $this->next($request, $response); } } $this->queue->rewind(); return $response; }
[ "public", "function", "next", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "/*# : ResponseInterface */", "{", "if", "(", "$", "this", "->", "queue", "->", "valid", "(", ")", ")", "{", "list", "(", "$", "middleware", ",", "$", "condition", ")", "=", "$", "this", "->", "queue", "->", "current", "(", ")", ";", "$", "this", "->", "queue", "->", "next", "(", ")", ";", "if", "(", "null", "===", "$", "condition", "||", "$", "this", "->", "evalCondition", "(", "$", "condition", ",", "$", "request", ",", "$", "response", ")", ")", "{", "// run this mw", "return", "$", "this", "->", "runMiddleware", "(", "$", "middleware", ",", "$", "request", ",", "$", "response", ")", ";", "}", "else", "{", "// skip this mw", "return", "$", "this", "->", "next", "(", "$", "request", ",", "$", "response", ")", ";", "}", "}", "$", "this", "->", "queue", "->", "rewind", "(", ")", ";", "return", "$", "response", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/phossa2/middleware/blob/518e97ae48077f2c11adcd3c2393830ed7ab7ce7/src/Middleware/Queue.php#L119-L137
phossa2/middleware
src/Middleware/Queue.php
Queue.fillTheQueue
protected function fillTheQueue(array $middlewares) { foreach ($middlewares as $mw) { // with conditions specified if (is_array($mw)) { $this->push($mw[0], $mw[1]); // no condition } else { $this->push($mw); } } }
php
protected function fillTheQueue(array $middlewares) { foreach ($middlewares as $mw) { // with conditions specified if (is_array($mw)) { $this->push($mw[0], $mw[1]); // no condition } else { $this->push($mw); } } }
[ "protected", "function", "fillTheQueue", "(", "array", "$", "middlewares", ")", "{", "foreach", "(", "$", "middlewares", "as", "$", "mw", ")", "{", "// with conditions specified", "if", "(", "is_array", "(", "$", "mw", ")", ")", "{", "$", "this", "->", "push", "(", "$", "mw", "[", "0", "]", ",", "$", "mw", "[", "1", "]", ")", ";", "// no condition", "}", "else", "{", "$", "this", "->", "push", "(", "$", "mw", ")", ";", "}", "}", "}" ]
Fill the queue with middlewares @param array $middlewares @access protected
[ "Fill", "the", "queue", "with", "middlewares" ]
train
https://github.com/phossa2/middleware/blob/518e97ae48077f2c11adcd3c2393830ed7ab7ce7/src/Middleware/Queue.php#L145-L157
phossa2/middleware
src/Middleware/Queue.php
Queue.runMiddleware
protected function runMiddleware( $middleware, RequestInterface $request, ResponseInterface $response )/*# : ResponseInterface */ { // instance of MiddlewareInterface if (is_object($middleware) && $middleware instanceof MiddlewareInterface) { return $middleware->process($request, $response, $this); // old style callable } elseif (is_callable($middleware)) { return $middleware($request, $response, $this); // unknown middleware type } else { throw new LogicException( Message::get(Message::MIDDLEWARE_INVALID, $middleware), Message::MIDDLEWARE_INVALID ); } }
php
protected function runMiddleware( $middleware, RequestInterface $request, ResponseInterface $response )/*# : ResponseInterface */ { // instance of MiddlewareInterface if (is_object($middleware) && $middleware instanceof MiddlewareInterface) { return $middleware->process($request, $response, $this); // old style callable } elseif (is_callable($middleware)) { return $middleware($request, $response, $this); // unknown middleware type } else { throw new LogicException( Message::get(Message::MIDDLEWARE_INVALID, $middleware), Message::MIDDLEWARE_INVALID ); } }
[ "protected", "function", "runMiddleware", "(", "$", "middleware", ",", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "/*# : ResponseInterface */", "{", "// instance of MiddlewareInterface", "if", "(", "is_object", "(", "$", "middleware", ")", "&&", "$", "middleware", "instanceof", "MiddlewareInterface", ")", "{", "return", "$", "middleware", "->", "process", "(", "$", "request", ",", "$", "response", ",", "$", "this", ")", ";", "// old style callable", "}", "elseif", "(", "is_callable", "(", "$", "middleware", ")", ")", "{", "return", "$", "middleware", "(", "$", "request", ",", "$", "response", ",", "$", "this", ")", ";", "// unknown middleware type", "}", "else", "{", "throw", "new", "LogicException", "(", "Message", "::", "get", "(", "Message", "::", "MIDDLEWARE_INVALID", ",", "$", "middleware", ")", ",", "Message", "::", "MIDDLEWARE_INVALID", ")", ";", "}", "}" ]
Process/run this middleware @param MiddlewareInterface|callable $middleware @param RequestInterface $request @param ResponseInterface $response @return ResponseInterface @throws LogicException if invalid middleware type @access protected
[ "Process", "/", "run", "this", "middleware" ]
train
https://github.com/phossa2/middleware/blob/518e97ae48077f2c11adcd3c2393830ed7ab7ce7/src/Middleware/Queue.php#L169-L189
phossa2/middleware
src/Middleware/Queue.php
Queue.evalCondition
protected function evalCondition( $condition, RequestInterface $request, ResponseInterface $response )/*# : bool */ { // instanceof ConditionInterface if (is_object($condition) && $condition instanceof ConditionInterface) { return $condition->evaluate($request, $response); // old style callable } elseif (is_callable($condition)) { return $condition($request, $response); // unknown type } else { throw new LogicException( Message::get(Message::CONDITION_INVALID, $condition), Message::CONDITION_INVALID ); } }
php
protected function evalCondition( $condition, RequestInterface $request, ResponseInterface $response )/*# : bool */ { // instanceof ConditionInterface if (is_object($condition) && $condition instanceof ConditionInterface) { return $condition->evaluate($request, $response); // old style callable } elseif (is_callable($condition)) { return $condition($request, $response); // unknown type } else { throw new LogicException( Message::get(Message::CONDITION_INVALID, $condition), Message::CONDITION_INVALID ); } }
[ "protected", "function", "evalCondition", "(", "$", "condition", ",", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "/*# : bool */", "{", "// instanceof ConditionInterface", "if", "(", "is_object", "(", "$", "condition", ")", "&&", "$", "condition", "instanceof", "ConditionInterface", ")", "{", "return", "$", "condition", "->", "evaluate", "(", "$", "request", ",", "$", "response", ")", ";", "// old style callable", "}", "elseif", "(", "is_callable", "(", "$", "condition", ")", ")", "{", "return", "$", "condition", "(", "$", "request", ",", "$", "response", ")", ";", "// unknown type", "}", "else", "{", "throw", "new", "LogicException", "(", "Message", "::", "get", "(", "Message", "::", "CONDITION_INVALID", ",", "$", "condition", ")", ",", "Message", "::", "CONDITION_INVALID", ")", ";", "}", "}" ]
Evaluate the condition support both a callable returns bool value or an object instance of ConditionInterface. @param ConditionInterface|callable $condition @param RequestInterface $request @param ResponseInterface $response @return bool @throws LogicException if condition is invalid @access protected
[ "Evaluate", "the", "condition" ]
train
https://github.com/phossa2/middleware/blob/518e97ae48077f2c11adcd3c2393830ed7ab7ce7/src/Middleware/Queue.php#L204-L224
blast-project/CoreBundle
src/Tools/Reflection/ClassAnalyzer.php
ClassAnalyzer.getAncestors
public static function getAncestors($class) { $rc = $class instanceof \ReflectionClass ? \ReflectionClass($class->getName()) : new \ReflectionClass($class); $ancestors = []; while ($parent = $rc->getParentClass()) { $ancestors[] = $parent->getName(); $rc = $parent; } return $ancestors; }
php
public static function getAncestors($class) { $rc = $class instanceof \ReflectionClass ? \ReflectionClass($class->getName()) : new \ReflectionClass($class); $ancestors = []; while ($parent = $rc->getParentClass()) { $ancestors[] = $parent->getName(); $rc = $parent; } return $ancestors; }
[ "public", "static", "function", "getAncestors", "(", "$", "class", ")", "{", "$", "rc", "=", "$", "class", "instanceof", "\\", "ReflectionClass", "?", "\\", "ReflectionClass", "(", "$", "class", "->", "getName", "(", ")", ")", ":", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "$", "ancestors", "=", "[", "]", ";", "while", "(", "$", "parent", "=", "$", "rc", "->", "getParentClass", "(", ")", ")", "{", "$", "ancestors", "[", "]", "=", "$", "parent", "->", "getName", "(", ")", ";", "$", "rc", "=", "$", "parent", ";", "}", "return", "$", "ancestors", ";", "}" ]
Returns all parents of a class (parent, parent of parent, parent of parent's parent and so on). @param ReflectionClass|string $class A ReflectionClass object or a class name @return array
[ "Returns", "all", "parents", "of", "a", "class", "(", "parent", "parent", "of", "parent", "parent", "of", "parent", "s", "parent", "and", "so", "on", ")", "." ]
train
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Tools/Reflection/ClassAnalyzer.php#L24-L34
blast-project/CoreBundle
src/Tools/Reflection/ClassAnalyzer.php
ClassAnalyzer.hasProperty
public static function hasProperty($class, $propertyName) { $rc = $class instanceof \ReflectionClass ? $class : new ReflectionClass($class); if ($rc->hasProperty($propertyName)) { return true; } $parentClass = $rc->getParentClass(); if (false === $parentClass) { return false; } return $this->hasProperty($parentClass, $propertyName); }
php
public static function hasProperty($class, $propertyName) { $rc = $class instanceof \ReflectionClass ? $class : new ReflectionClass($class); if ($rc->hasProperty($propertyName)) { return true; } $parentClass = $rc->getParentClass(); if (false === $parentClass) { return false; } return $this->hasProperty($parentClass, $propertyName); }
[ "public", "static", "function", "hasProperty", "(", "$", "class", ",", "$", "propertyName", ")", "{", "$", "rc", "=", "$", "class", "instanceof", "\\", "ReflectionClass", "?", "$", "class", ":", "new", "ReflectionClass", "(", "$", "class", ")", ";", "if", "(", "$", "rc", "->", "hasProperty", "(", "$", "propertyName", ")", ")", "{", "return", "true", ";", "}", "$", "parentClass", "=", "$", "rc", "->", "getParentClass", "(", ")", ";", "if", "(", "false", "===", "$", "parentClass", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "hasProperty", "(", "$", "parentClass", ",", "$", "propertyName", ")", ";", "}" ]
hasProperty. This static method says if a class has a property @param ReflectionClass|string $class A ReflectionClass object or a class name @param string $propertyName A string representing an existing property @return bool
[ "hasProperty", "." ]
train
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Tools/Reflection/ClassAnalyzer.php#L77-L92
blast-project/CoreBundle
src/Tools/Reflection/ClassAnalyzer.php
ClassAnalyzer._getTraits
private static function _getTraits($class, array $traits = null) { $rc = $class instanceof \ReflectionClass ? $class : new \ReflectionClass($class); if (is_null($traits)) { $traits = array(); } // traits being embedded through the current class or the embedded traits foreach ($rc->getTraits() as $trait) { $traits = self::_getTraits($trait, $traits); // first the embedded traits that come first... if (!in_array($trait->name, $traits)) { $traits[] = $trait->name; } // then the current trait } // traits embedded by the parent class if ($rc->getParentClass()) { $traits = self::_getTraits($rc->getParentClass(), $traits); } return $traits; }
php
private static function _getTraits($class, array $traits = null) { $rc = $class instanceof \ReflectionClass ? $class : new \ReflectionClass($class); if (is_null($traits)) { $traits = array(); } // traits being embedded through the current class or the embedded traits foreach ($rc->getTraits() as $trait) { $traits = self::_getTraits($trait, $traits); // first the embedded traits that come first... if (!in_array($trait->name, $traits)) { $traits[] = $trait->name; } // then the current trait } // traits embedded by the parent class if ($rc->getParentClass()) { $traits = self::_getTraits($rc->getParentClass(), $traits); } return $traits; }
[ "private", "static", "function", "_getTraits", "(", "$", "class", ",", "array", "$", "traits", "=", "null", ")", "{", "$", "rc", "=", "$", "class", "instanceof", "\\", "ReflectionClass", "?", "$", "class", ":", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "if", "(", "is_null", "(", "$", "traits", ")", ")", "{", "$", "traits", "=", "array", "(", ")", ";", "}", "// traits being embedded through the current class or the embedded traits", "foreach", "(", "$", "rc", "->", "getTraits", "(", ")", "as", "$", "trait", ")", "{", "$", "traits", "=", "self", "::", "_getTraits", "(", "$", "trait", ",", "$", "traits", ")", ";", "// first the embedded traits that come first...", "if", "(", "!", "in_array", "(", "$", "trait", "->", "name", ",", "$", "traits", ")", ")", "{", "$", "traits", "[", "]", "=", "$", "trait", "->", "name", ";", "}", "// then the current trait", "}", "// traits embedded by the parent class", "if", "(", "$", "rc", "->", "getParentClass", "(", ")", ")", "{", "$", "traits", "=", "self", "::", "_getTraits", "(", "$", "rc", "->", "getParentClass", "(", ")", ",", "$", "traits", ")", ";", "}", "return", "$", "traits", ";", "}" ]
@param ReflectionClass|string $class A ReflectionClass object or a class name @param array $traits An array of traits (strings) @return array
[ "@param", "ReflectionClass|string", "$class", "A", "ReflectionClass", "object", "or", "a", "class", "name", "@param", "array", "$traits", "An", "array", "of", "traits", "(", "strings", ")" ]
train
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Tools/Reflection/ClassAnalyzer.php#L117-L138
paulzi/multicurl
MultiCurl.php
MultiCurl.add
public function add($request) { $this->onBefore($request); array_push($this->_requests, $request); curl_multi_add_handle($this->_mh, $request->curl); $this->_updated = true; }
php
public function add($request) { $this->onBefore($request); array_push($this->_requests, $request); curl_multi_add_handle($this->_mh, $request->curl); $this->_updated = true; }
[ "public", "function", "add", "(", "$", "request", ")", "{", "$", "this", "->", "onBefore", "(", "$", "request", ")", ";", "array_push", "(", "$", "this", "->", "_requests", ",", "$", "request", ")", ";", "curl_multi_add_handle", "(", "$", "this", "->", "_mh", ",", "$", "request", "->", "curl", ")", ";", "$", "this", "->", "_updated", "=", "true", ";", "}" ]
Add request to execute @param MultiCurlRequest $request
[ "Add", "request", "to", "execute" ]
train
https://github.com/paulzi/multicurl/blob/2e326d868add238bb2820f3271e235bfed12e5cb/MultiCurl.php#L47-L53
paulzi/multicurl
MultiCurl.php
MultiCurl.run
public function run() { $running = null; do { curl_multi_exec($this->_mh, $running); $this->_updated = false; while ($info = curl_multi_info_read($this->_mh)) { $index = false; foreach ($this->_requests as $i => $item) { if ($item->curl === $info['handle']) { $index = $i; break; } } if ($index === false) { throw new \Exception('Curl request not founded in list'); } $request = $this->_requests[$index]; unset($this->_requests[$index]); $content = curl_multi_getcontent($request->curl); $response = curl_getinfo($request->curl); curl_multi_remove_handle($this->_mh, $info['handle']); if ($info['result'] === CURLE_OK) { $this->onSuccess($request, $response, $content); } else { $errCode = $info['result']; $errMsg = function_exists('curl_strerror') ? curl_strerror($errCode) : "cURL error {$errCode}"; $this->onError($request, $response, $content, $errCode, $errMsg); } $this->onAlways($request, $response, $content); } curl_multi_select($this->_mh, 1); } while ($running>0 || $this->_updated); }
php
public function run() { $running = null; do { curl_multi_exec($this->_mh, $running); $this->_updated = false; while ($info = curl_multi_info_read($this->_mh)) { $index = false; foreach ($this->_requests as $i => $item) { if ($item->curl === $info['handle']) { $index = $i; break; } } if ($index === false) { throw new \Exception('Curl request not founded in list'); } $request = $this->_requests[$index]; unset($this->_requests[$index]); $content = curl_multi_getcontent($request->curl); $response = curl_getinfo($request->curl); curl_multi_remove_handle($this->_mh, $info['handle']); if ($info['result'] === CURLE_OK) { $this->onSuccess($request, $response, $content); } else { $errCode = $info['result']; $errMsg = function_exists('curl_strerror') ? curl_strerror($errCode) : "cURL error {$errCode}"; $this->onError($request, $response, $content, $errCode, $errMsg); } $this->onAlways($request, $response, $content); } curl_multi_select($this->_mh, 1); } while ($running>0 || $this->_updated); }
[ "public", "function", "run", "(", ")", "{", "$", "running", "=", "null", ";", "do", "{", "curl_multi_exec", "(", "$", "this", "->", "_mh", ",", "$", "running", ")", ";", "$", "this", "->", "_updated", "=", "false", ";", "while", "(", "$", "info", "=", "curl_multi_info_read", "(", "$", "this", "->", "_mh", ")", ")", "{", "$", "index", "=", "false", ";", "foreach", "(", "$", "this", "->", "_requests", "as", "$", "i", "=>", "$", "item", ")", "{", "if", "(", "$", "item", "->", "curl", "===", "$", "info", "[", "'handle'", "]", ")", "{", "$", "index", "=", "$", "i", ";", "break", ";", "}", "}", "if", "(", "$", "index", "===", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'Curl request not founded in list'", ")", ";", "}", "$", "request", "=", "$", "this", "->", "_requests", "[", "$", "index", "]", ";", "unset", "(", "$", "this", "->", "_requests", "[", "$", "index", "]", ")", ";", "$", "content", "=", "curl_multi_getcontent", "(", "$", "request", "->", "curl", ")", ";", "$", "response", "=", "curl_getinfo", "(", "$", "request", "->", "curl", ")", ";", "curl_multi_remove_handle", "(", "$", "this", "->", "_mh", ",", "$", "info", "[", "'handle'", "]", ")", ";", "if", "(", "$", "info", "[", "'result'", "]", "===", "CURLE_OK", ")", "{", "$", "this", "->", "onSuccess", "(", "$", "request", ",", "$", "response", ",", "$", "content", ")", ";", "}", "else", "{", "$", "errCode", "=", "$", "info", "[", "'result'", "]", ";", "$", "errMsg", "=", "function_exists", "(", "'curl_strerror'", ")", "?", "curl_strerror", "(", "$", "errCode", ")", ":", "\"cURL error {$errCode}\"", ";", "$", "this", "->", "onError", "(", "$", "request", ",", "$", "response", ",", "$", "content", ",", "$", "errCode", ",", "$", "errMsg", ")", ";", "}", "$", "this", "->", "onAlways", "(", "$", "request", ",", "$", "response", ",", "$", "content", ")", ";", "}", "curl_multi_select", "(", "$", "this", "->", "_mh", ",", "1", ")", ";", "}", "while", "(", "$", "running", ">", "0", "||", "$", "this", "->", "_updated", ")", ";", "}" ]
Execute requests
[ "Execute", "requests" ]
train
https://github.com/paulzi/multicurl/blob/2e326d868add238bb2820f3271e235bfed12e5cb/MultiCurl.php#L58-L94
philippfrenzel/yii2-textareaautosize
yii2textareaautosize.php
yii2textareaautosize.registerAssets
public function registerAssets() { $id = $this->options['id']; $view = $this->getView(); CoreAsset::register($view); $cleanOptions = $this->getClientOptions(); $js[] = "$('textarea.element-$id').textareaAutoSize();"; $view->registerJs(implode("\n", $js),View::POS_READY); }
php
public function registerAssets() { $id = $this->options['id']; $view = $this->getView(); CoreAsset::register($view); $cleanOptions = $this->getClientOptions(); $js[] = "$('textarea.element-$id').textareaAutoSize();"; $view->registerJs(implode("\n", $js),View::POS_READY); }
[ "public", "function", "registerAssets", "(", ")", "{", "$", "id", "=", "$", "this", "->", "options", "[", "'id'", "]", ";", "$", "view", "=", "$", "this", "->", "getView", "(", ")", ";", "CoreAsset", "::", "register", "(", "$", "view", ")", ";", "$", "cleanOptions", "=", "$", "this", "->", "getClientOptions", "(", ")", ";", "$", "js", "[", "]", "=", "\"$('textarea.element-$id').textareaAutoSize();\"", ";", "$", "view", "->", "registerJs", "(", "implode", "(", "\"\\n\"", ",", "$", "js", ")", ",", "View", "::", "POS_READY", ")", ";", "}" ]
Registers the needed assets
[ "Registers", "the", "needed", "assets" ]
train
https://github.com/philippfrenzel/yii2-textareaautosize/blob/3732a29a48c0b1c15aba608e3f49e6529d13a8bd/yii2textareaautosize.php#L56-L64
philippfrenzel/yii2-textareaautosize
yii2textareaautosize.php
yii2textareaautosize.renderInput
public function renderInput() { Html::addCssClass($this->_displayOptions, 'element-' . $this->options['id']); Html::addCssClass($this->_displayOptions, 'form-control'); $this->_displayOptions['rows'] = 1; $input = Html::activeTextarea($this->model, $this->attribute, $this->_displayOptions); echo $input; }
php
public function renderInput() { Html::addCssClass($this->_displayOptions, 'element-' . $this->options['id']); Html::addCssClass($this->_displayOptions, 'form-control'); $this->_displayOptions['rows'] = 1; $input = Html::activeTextarea($this->model, $this->attribute, $this->_displayOptions); echo $input; }
[ "public", "function", "renderInput", "(", ")", "{", "Html", "::", "addCssClass", "(", "$", "this", "->", "_displayOptions", ",", "'element-'", ".", "$", "this", "->", "options", "[", "'id'", "]", ")", ";", "Html", "::", "addCssClass", "(", "$", "this", "->", "_displayOptions", ",", "'form-control'", ")", ";", "$", "this", "->", "_displayOptions", "[", "'rows'", "]", "=", "1", ";", "$", "input", "=", "Html", "::", "activeTextarea", "(", "$", "this", "->", "model", ",", "$", "this", "->", "attribute", ",", "$", "this", "->", "_displayOptions", ")", ";", "echo", "$", "input", ";", "}" ]
Renders the widget.
[ "Renders", "the", "widget", "." ]
train
https://github.com/philippfrenzel/yii2-textareaautosize/blob/3732a29a48c0b1c15aba608e3f49e6529d13a8bd/yii2textareaautosize.php#L81-L88
blast-project/CoreBundle
src/Admin/Traits/Mapper.php
Mapper.addContent
protected function addContent(BaseMapper $mapper, $group) { // helper links $this->parseHelperLinks(); // flat organization (DatagridMapper / ListMapper...) if (!$mapper instanceof BaseGroupedMapper) { //list actions $this->addActions(); $this->removeActions(); // options pre-treatment $options = []; if (isset($group['_options'])) { $options = $group['_options']; unset($group['_options']); } // content foreach ($group as $add => $opts) { $this->addField($mapper, $add, $opts); } // options if (isset($options['fieldsOrder'])) { $mapper->reorder($options['fieldsOrder']); } // extra templates $this->parseExtraTemplates(); return $mapper; } $fcts = [ 'tabs' => $mapper instanceof ShowMapper ? ['getter' => 'getShowTabs', 'setter' => 'setShowTabs'] : ['getter' => 'getFormTabs', 'setter' => 'setFormTabs'], 'groups' => $mapper instanceof ShowMapper ? ['getter' => 'getShowGroups', 'setter' => 'setShowGroups'] : ['getter' => 'getFormGroups', 'setter' => 'setFormGroups'], ]; // if a grouped organization can be shapped // options $tabsOptions = null; if (isset($group['_options'])) { $tabsOptions = $group['_options']; unset($group['_options']); } // content foreach ($group as $tab => $tabcontent) { // loop on content... if (self::arrayDepth($tabcontent) < 1) { // direct add $this->addField($mapper, $tab, $tabcontent); $mapper->end()->end(); } else { // groups/withs order $groupsOrder = null; if (isset($tabcontent['_options']['groupsOrder'])) { $groupsOrder = $tabcontent['_options']['groupsOrder']; unset($tabcontent['_options']['groupsOrder']); } $endgroup = $endtab = false; // tab if (!empty($tabcontent['_options']['hideTitle']) || $mapper instanceof ShowMapper && !$this->forceTabs) { // display tabs as groups $tabs = $this->{$fcts['tabs']['getter']}(); $groups = $this->{$fcts['groups']['getter']}(); if (isset($tabs[$tab])) { $tabs[$tab]['auto_created'] = true; $this->{$fcts['tabs']['setter']}($tabs); foreach ($groups as $groupkey => $group) { if (!isset($groups[$group['name']])) { $groups[$group['name']] = $group; unset($groups[$groupkey]); } } $this->{$fcts['groups']['setter']}($groups); } } else { $mapper->tab($tab, isset($tabcontent['_options']) ? $tabcontent['_options'] : []); $endtab = true; } // adding count of collections items in tab if (isset($tabcontent['_options']['countChildItems']) && is_array($tabcontent['_options']['countChildItems'])) { $tabs = $this->{$fcts['tabs']['getter']}(); if (strpos($tabs[$tab]['class'], 'countable-tab') === false) { $tabs[$tab]['class'] .= ' countable-tab'; foreach ($tabcontent['_options']['countChildItems'] as $fieldToCount) { if (strpos($tabs[$tab]['class'], 'count-' . $fieldToCount) === false) { $tabs[$tab]['class'] .= ' count-' . $fieldToCount; } } $this->{$fcts['tabs']['setter']}($tabs); } } // clearing tabcontent options if (isset($tabcontent['_options'])) { unset($tabcontent['_options']); } $finalOrder = null; // with if (self::arrayDepth($tabcontent) > 0) { foreach ($tabcontent as $with => $withcontent) { $opt = isset($withcontent['_options']) ? $withcontent['_options'] : []; $finalOrder = (isset($opt['fieldsOrder']) ? $opt['fieldsOrder'] : null); if (empty($opt['hideTitle'])) { $endtab = true; $endgroup = true; $mapper->with($with, $opt); } if (isset($withcontent['_options'])) { unset($withcontent['_options']); } // final adds if (self::arrayDepth($withcontent) > 0) { foreach ($withcontent as $name => $options) { $fieldDescriptionOptions = []; if (isset($options['_options'])) { $fieldDescriptionOptions = $options['_options']; unset($options['_options']); } $this->addField($mapper, $name, $options, $fieldDescriptionOptions); $endgroup = $endtab = true; } } if ($finalOrder != null) { $mapper->reorder($finalOrder); } if ($endgroup) { $mapper->end(); } } } // order groups / withs (using tabs, because they are prioritary at the end) if (isset($groupsOrder)) { // preparing $otabs = $mapper->getAdmin()->{$fcts['tabs']['getter']}(); $groups = $mapper->getAdmin()->{$fcts['groups']['getter']}(); // pre-ordering $newgroups = []; $buf = empty($otabs[$tab]['auto_created']) ? "$tab." : ''; foreach ($groupsOrder as $groupname) { if (isset($otabs[$tab]) && in_array("$buf$groupname", $otabs[$tab]['groups'])) { $newgroups[] = "$buf$groupname"; } } // ordering tabs foreach (empty($otabs[$tab]['groups']) ? [] : $otabs[$tab]['groups'] as $groupname) { if (!in_array($groupname, $newgroups)) { $newgroups[] = $groupname; } } $otabs[$tab]['groups'] = $newgroups; // "persisting" $mapper->getAdmin()->{$fcts['tabs']['setter']}($otabs); } if ($endtab) { $mapper->end(); } } } // ordering tabs if (isset($tabsOptions['tabsOrder']) && $tabs = $this->{$fcts['tabs']['getter']}()) { $newtabs = []; foreach ($tabsOptions['tabsOrder'] as $tabname) { if (isset($tabs[$tabname])) { $newtabs[$tabname] = $tabs[$tabname]; } } foreach ($tabs as $tabname => $tab) { if (!isset($newtabs[$tabname])) { $newtabs[$tabname] = $tab; } } $this->{$fcts['tabs']['setter']}($newtabs); } // ordering the ShowMapper if ($mapper instanceof ShowMapper) { foreach ($group as $tabName => $tabContent) { $tabOptions = null; if (isset($tabContent['_options'])) { $tabOptions = $tabContent['_options']; unset($tabContent['_options']); } if (isset($tabOptions['groupsOrder'])) { $tabs = $this->{$fcts['tabs']['getter']}(); $groups = $this->{$fcts['groups']['getter']}(); $groupOrder = $tabOptions['groupsOrder']; $properOrderedArray = array_merge(array_flip($groupOrder), $groups); $this->{$fcts['groups']['setter']}($properOrderedArray); $this->{$fcts['tabs']['setter']}($tabs); } } } return $mapper; }
php
protected function addContent(BaseMapper $mapper, $group) { // helper links $this->parseHelperLinks(); // flat organization (DatagridMapper / ListMapper...) if (!$mapper instanceof BaseGroupedMapper) { //list actions $this->addActions(); $this->removeActions(); // options pre-treatment $options = []; if (isset($group['_options'])) { $options = $group['_options']; unset($group['_options']); } // content foreach ($group as $add => $opts) { $this->addField($mapper, $add, $opts); } // options if (isset($options['fieldsOrder'])) { $mapper->reorder($options['fieldsOrder']); } // extra templates $this->parseExtraTemplates(); return $mapper; } $fcts = [ 'tabs' => $mapper instanceof ShowMapper ? ['getter' => 'getShowTabs', 'setter' => 'setShowTabs'] : ['getter' => 'getFormTabs', 'setter' => 'setFormTabs'], 'groups' => $mapper instanceof ShowMapper ? ['getter' => 'getShowGroups', 'setter' => 'setShowGroups'] : ['getter' => 'getFormGroups', 'setter' => 'setFormGroups'], ]; // if a grouped organization can be shapped // options $tabsOptions = null; if (isset($group['_options'])) { $tabsOptions = $group['_options']; unset($group['_options']); } // content foreach ($group as $tab => $tabcontent) { // loop on content... if (self::arrayDepth($tabcontent) < 1) { // direct add $this->addField($mapper, $tab, $tabcontent); $mapper->end()->end(); } else { // groups/withs order $groupsOrder = null; if (isset($tabcontent['_options']['groupsOrder'])) { $groupsOrder = $tabcontent['_options']['groupsOrder']; unset($tabcontent['_options']['groupsOrder']); } $endgroup = $endtab = false; // tab if (!empty($tabcontent['_options']['hideTitle']) || $mapper instanceof ShowMapper && !$this->forceTabs) { // display tabs as groups $tabs = $this->{$fcts['tabs']['getter']}(); $groups = $this->{$fcts['groups']['getter']}(); if (isset($tabs[$tab])) { $tabs[$tab]['auto_created'] = true; $this->{$fcts['tabs']['setter']}($tabs); foreach ($groups as $groupkey => $group) { if (!isset($groups[$group['name']])) { $groups[$group['name']] = $group; unset($groups[$groupkey]); } } $this->{$fcts['groups']['setter']}($groups); } } else { $mapper->tab($tab, isset($tabcontent['_options']) ? $tabcontent['_options'] : []); $endtab = true; } // adding count of collections items in tab if (isset($tabcontent['_options']['countChildItems']) && is_array($tabcontent['_options']['countChildItems'])) { $tabs = $this->{$fcts['tabs']['getter']}(); if (strpos($tabs[$tab]['class'], 'countable-tab') === false) { $tabs[$tab]['class'] .= ' countable-tab'; foreach ($tabcontent['_options']['countChildItems'] as $fieldToCount) { if (strpos($tabs[$tab]['class'], 'count-' . $fieldToCount) === false) { $tabs[$tab]['class'] .= ' count-' . $fieldToCount; } } $this->{$fcts['tabs']['setter']}($tabs); } } // clearing tabcontent options if (isset($tabcontent['_options'])) { unset($tabcontent['_options']); } $finalOrder = null; // with if (self::arrayDepth($tabcontent) > 0) { foreach ($tabcontent as $with => $withcontent) { $opt = isset($withcontent['_options']) ? $withcontent['_options'] : []; $finalOrder = (isset($opt['fieldsOrder']) ? $opt['fieldsOrder'] : null); if (empty($opt['hideTitle'])) { $endtab = true; $endgroup = true; $mapper->with($with, $opt); } if (isset($withcontent['_options'])) { unset($withcontent['_options']); } // final adds if (self::arrayDepth($withcontent) > 0) { foreach ($withcontent as $name => $options) { $fieldDescriptionOptions = []; if (isset($options['_options'])) { $fieldDescriptionOptions = $options['_options']; unset($options['_options']); } $this->addField($mapper, $name, $options, $fieldDescriptionOptions); $endgroup = $endtab = true; } } if ($finalOrder != null) { $mapper->reorder($finalOrder); } if ($endgroup) { $mapper->end(); } } } // order groups / withs (using tabs, because they are prioritary at the end) if (isset($groupsOrder)) { // preparing $otabs = $mapper->getAdmin()->{$fcts['tabs']['getter']}(); $groups = $mapper->getAdmin()->{$fcts['groups']['getter']}(); // pre-ordering $newgroups = []; $buf = empty($otabs[$tab]['auto_created']) ? "$tab." : ''; foreach ($groupsOrder as $groupname) { if (isset($otabs[$tab]) && in_array("$buf$groupname", $otabs[$tab]['groups'])) { $newgroups[] = "$buf$groupname"; } } // ordering tabs foreach (empty($otabs[$tab]['groups']) ? [] : $otabs[$tab]['groups'] as $groupname) { if (!in_array($groupname, $newgroups)) { $newgroups[] = $groupname; } } $otabs[$tab]['groups'] = $newgroups; // "persisting" $mapper->getAdmin()->{$fcts['tabs']['setter']}($otabs); } if ($endtab) { $mapper->end(); } } } // ordering tabs if (isset($tabsOptions['tabsOrder']) && $tabs = $this->{$fcts['tabs']['getter']}()) { $newtabs = []; foreach ($tabsOptions['tabsOrder'] as $tabname) { if (isset($tabs[$tabname])) { $newtabs[$tabname] = $tabs[$tabname]; } } foreach ($tabs as $tabname => $tab) { if (!isset($newtabs[$tabname])) { $newtabs[$tabname] = $tab; } } $this->{$fcts['tabs']['setter']}($newtabs); } // ordering the ShowMapper if ($mapper instanceof ShowMapper) { foreach ($group as $tabName => $tabContent) { $tabOptions = null; if (isset($tabContent['_options'])) { $tabOptions = $tabContent['_options']; unset($tabContent['_options']); } if (isset($tabOptions['groupsOrder'])) { $tabs = $this->{$fcts['tabs']['getter']}(); $groups = $this->{$fcts['groups']['getter']}(); $groupOrder = $tabOptions['groupsOrder']; $properOrderedArray = array_merge(array_flip($groupOrder), $groups); $this->{$fcts['groups']['setter']}($properOrderedArray); $this->{$fcts['tabs']['setter']}($tabs); } } } return $mapper; }
[ "protected", "function", "addContent", "(", "BaseMapper", "$", "mapper", ",", "$", "group", ")", "{", "// helper links", "$", "this", "->", "parseHelperLinks", "(", ")", ";", "// flat organization (DatagridMapper / ListMapper...)", "if", "(", "!", "$", "mapper", "instanceof", "BaseGroupedMapper", ")", "{", "//list actions", "$", "this", "->", "addActions", "(", ")", ";", "$", "this", "->", "removeActions", "(", ")", ";", "// options pre-treatment", "$", "options", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "group", "[", "'_options'", "]", ")", ")", "{", "$", "options", "=", "$", "group", "[", "'_options'", "]", ";", "unset", "(", "$", "group", "[", "'_options'", "]", ")", ";", "}", "// content", "foreach", "(", "$", "group", "as", "$", "add", "=>", "$", "opts", ")", "{", "$", "this", "->", "addField", "(", "$", "mapper", ",", "$", "add", ",", "$", "opts", ")", ";", "}", "// options", "if", "(", "isset", "(", "$", "options", "[", "'fieldsOrder'", "]", ")", ")", "{", "$", "mapper", "->", "reorder", "(", "$", "options", "[", "'fieldsOrder'", "]", ")", ";", "}", "// extra templates", "$", "this", "->", "parseExtraTemplates", "(", ")", ";", "return", "$", "mapper", ";", "}", "$", "fcts", "=", "[", "'tabs'", "=>", "$", "mapper", "instanceof", "ShowMapper", "?", "[", "'getter'", "=>", "'getShowTabs'", ",", "'setter'", "=>", "'setShowTabs'", "]", ":", "[", "'getter'", "=>", "'getFormTabs'", ",", "'setter'", "=>", "'setFormTabs'", "]", ",", "'groups'", "=>", "$", "mapper", "instanceof", "ShowMapper", "?", "[", "'getter'", "=>", "'getShowGroups'", ",", "'setter'", "=>", "'setShowGroups'", "]", ":", "[", "'getter'", "=>", "'getFormGroups'", ",", "'setter'", "=>", "'setFormGroups'", "]", ",", "]", ";", "// if a grouped organization can be shapped", "// options", "$", "tabsOptions", "=", "null", ";", "if", "(", "isset", "(", "$", "group", "[", "'_options'", "]", ")", ")", "{", "$", "tabsOptions", "=", "$", "group", "[", "'_options'", "]", ";", "unset", "(", "$", "group", "[", "'_options'", "]", ")", ";", "}", "// content", "foreach", "(", "$", "group", "as", "$", "tab", "=>", "$", "tabcontent", ")", "{", "// loop on content...", "if", "(", "self", "::", "arrayDepth", "(", "$", "tabcontent", ")", "<", "1", ")", "{", "// direct add", "$", "this", "->", "addField", "(", "$", "mapper", ",", "$", "tab", ",", "$", "tabcontent", ")", ";", "$", "mapper", "->", "end", "(", ")", "->", "end", "(", ")", ";", "}", "else", "{", "// groups/withs order", "$", "groupsOrder", "=", "null", ";", "if", "(", "isset", "(", "$", "tabcontent", "[", "'_options'", "]", "[", "'groupsOrder'", "]", ")", ")", "{", "$", "groupsOrder", "=", "$", "tabcontent", "[", "'_options'", "]", "[", "'groupsOrder'", "]", ";", "unset", "(", "$", "tabcontent", "[", "'_options'", "]", "[", "'groupsOrder'", "]", ")", ";", "}", "$", "endgroup", "=", "$", "endtab", "=", "false", ";", "// tab", "if", "(", "!", "empty", "(", "$", "tabcontent", "[", "'_options'", "]", "[", "'hideTitle'", "]", ")", "||", "$", "mapper", "instanceof", "ShowMapper", "&&", "!", "$", "this", "->", "forceTabs", ")", "{", "// display tabs as groups", "$", "tabs", "=", "$", "this", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'getter'", "]", "}", "(", ")", ";", "$", "groups", "=", "$", "this", "->", "{", "$", "fcts", "[", "'groups'", "]", "[", "'getter'", "]", "}", "(", ")", ";", "if", "(", "isset", "(", "$", "tabs", "[", "$", "tab", "]", ")", ")", "{", "$", "tabs", "[", "$", "tab", "]", "[", "'auto_created'", "]", "=", "true", ";", "$", "this", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'setter'", "]", "}", "(", "$", "tabs", ")", ";", "foreach", "(", "$", "groups", "as", "$", "groupkey", "=>", "$", "group", ")", "{", "if", "(", "!", "isset", "(", "$", "groups", "[", "$", "group", "[", "'name'", "]", "]", ")", ")", "{", "$", "groups", "[", "$", "group", "[", "'name'", "]", "]", "=", "$", "group", ";", "unset", "(", "$", "groups", "[", "$", "groupkey", "]", ")", ";", "}", "}", "$", "this", "->", "{", "$", "fcts", "[", "'groups'", "]", "[", "'setter'", "]", "}", "(", "$", "groups", ")", ";", "}", "}", "else", "{", "$", "mapper", "->", "tab", "(", "$", "tab", ",", "isset", "(", "$", "tabcontent", "[", "'_options'", "]", ")", "?", "$", "tabcontent", "[", "'_options'", "]", ":", "[", "]", ")", ";", "$", "endtab", "=", "true", ";", "}", "// adding count of collections items in tab", "if", "(", "isset", "(", "$", "tabcontent", "[", "'_options'", "]", "[", "'countChildItems'", "]", ")", "&&", "is_array", "(", "$", "tabcontent", "[", "'_options'", "]", "[", "'countChildItems'", "]", ")", ")", "{", "$", "tabs", "=", "$", "this", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'getter'", "]", "}", "(", ")", ";", "if", "(", "strpos", "(", "$", "tabs", "[", "$", "tab", "]", "[", "'class'", "]", ",", "'countable-tab'", ")", "===", "false", ")", "{", "$", "tabs", "[", "$", "tab", "]", "[", "'class'", "]", ".=", "' countable-tab'", ";", "foreach", "(", "$", "tabcontent", "[", "'_options'", "]", "[", "'countChildItems'", "]", "as", "$", "fieldToCount", ")", "{", "if", "(", "strpos", "(", "$", "tabs", "[", "$", "tab", "]", "[", "'class'", "]", ",", "'count-'", ".", "$", "fieldToCount", ")", "===", "false", ")", "{", "$", "tabs", "[", "$", "tab", "]", "[", "'class'", "]", ".=", "' count-'", ".", "$", "fieldToCount", ";", "}", "}", "$", "this", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'setter'", "]", "}", "(", "$", "tabs", ")", ";", "}", "}", "// clearing tabcontent options", "if", "(", "isset", "(", "$", "tabcontent", "[", "'_options'", "]", ")", ")", "{", "unset", "(", "$", "tabcontent", "[", "'_options'", "]", ")", ";", "}", "$", "finalOrder", "=", "null", ";", "// with", "if", "(", "self", "::", "arrayDepth", "(", "$", "tabcontent", ")", ">", "0", ")", "{", "foreach", "(", "$", "tabcontent", "as", "$", "with", "=>", "$", "withcontent", ")", "{", "$", "opt", "=", "isset", "(", "$", "withcontent", "[", "'_options'", "]", ")", "?", "$", "withcontent", "[", "'_options'", "]", ":", "[", "]", ";", "$", "finalOrder", "=", "(", "isset", "(", "$", "opt", "[", "'fieldsOrder'", "]", ")", "?", "$", "opt", "[", "'fieldsOrder'", "]", ":", "null", ")", ";", "if", "(", "empty", "(", "$", "opt", "[", "'hideTitle'", "]", ")", ")", "{", "$", "endtab", "=", "true", ";", "$", "endgroup", "=", "true", ";", "$", "mapper", "->", "with", "(", "$", "with", ",", "$", "opt", ")", ";", "}", "if", "(", "isset", "(", "$", "withcontent", "[", "'_options'", "]", ")", ")", "{", "unset", "(", "$", "withcontent", "[", "'_options'", "]", ")", ";", "}", "// final adds", "if", "(", "self", "::", "arrayDepth", "(", "$", "withcontent", ")", ">", "0", ")", "{", "foreach", "(", "$", "withcontent", "as", "$", "name", "=>", "$", "options", ")", "{", "$", "fieldDescriptionOptions", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "options", "[", "'_options'", "]", ")", ")", "{", "$", "fieldDescriptionOptions", "=", "$", "options", "[", "'_options'", "]", ";", "unset", "(", "$", "options", "[", "'_options'", "]", ")", ";", "}", "$", "this", "->", "addField", "(", "$", "mapper", ",", "$", "name", ",", "$", "options", ",", "$", "fieldDescriptionOptions", ")", ";", "$", "endgroup", "=", "$", "endtab", "=", "true", ";", "}", "}", "if", "(", "$", "finalOrder", "!=", "null", ")", "{", "$", "mapper", "->", "reorder", "(", "$", "finalOrder", ")", ";", "}", "if", "(", "$", "endgroup", ")", "{", "$", "mapper", "->", "end", "(", ")", ";", "}", "}", "}", "// order groups / withs (using tabs, because they are prioritary at the end)", "if", "(", "isset", "(", "$", "groupsOrder", ")", ")", "{", "// preparing", "$", "otabs", "=", "$", "mapper", "->", "getAdmin", "(", ")", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'getter'", "]", "}", "(", ")", ";", "$", "groups", "=", "$", "mapper", "->", "getAdmin", "(", ")", "->", "{", "$", "fcts", "[", "'groups'", "]", "[", "'getter'", "]", "}", "(", ")", ";", "// pre-ordering", "$", "newgroups", "=", "[", "]", ";", "$", "buf", "=", "empty", "(", "$", "otabs", "[", "$", "tab", "]", "[", "'auto_created'", "]", ")", "?", "\"$tab.\"", ":", "''", ";", "foreach", "(", "$", "groupsOrder", "as", "$", "groupname", ")", "{", "if", "(", "isset", "(", "$", "otabs", "[", "$", "tab", "]", ")", "&&", "in_array", "(", "\"$buf$groupname\"", ",", "$", "otabs", "[", "$", "tab", "]", "[", "'groups'", "]", ")", ")", "{", "$", "newgroups", "[", "]", "=", "\"$buf$groupname\"", ";", "}", "}", "// ordering tabs", "foreach", "(", "empty", "(", "$", "otabs", "[", "$", "tab", "]", "[", "'groups'", "]", ")", "?", "[", "]", ":", "$", "otabs", "[", "$", "tab", "]", "[", "'groups'", "]", "as", "$", "groupname", ")", "{", "if", "(", "!", "in_array", "(", "$", "groupname", ",", "$", "newgroups", ")", ")", "{", "$", "newgroups", "[", "]", "=", "$", "groupname", ";", "}", "}", "$", "otabs", "[", "$", "tab", "]", "[", "'groups'", "]", "=", "$", "newgroups", ";", "// \"persisting\"", "$", "mapper", "->", "getAdmin", "(", ")", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'setter'", "]", "}", "(", "$", "otabs", ")", ";", "}", "if", "(", "$", "endtab", ")", "{", "$", "mapper", "->", "end", "(", ")", ";", "}", "}", "}", "// ordering tabs", "if", "(", "isset", "(", "$", "tabsOptions", "[", "'tabsOrder'", "]", ")", "&&", "$", "tabs", "=", "$", "this", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'getter'", "]", "}", "(", ")", ")", "{", "$", "newtabs", "=", "[", "]", ";", "foreach", "(", "$", "tabsOptions", "[", "'tabsOrder'", "]", "as", "$", "tabname", ")", "{", "if", "(", "isset", "(", "$", "tabs", "[", "$", "tabname", "]", ")", ")", "{", "$", "newtabs", "[", "$", "tabname", "]", "=", "$", "tabs", "[", "$", "tabname", "]", ";", "}", "}", "foreach", "(", "$", "tabs", "as", "$", "tabname", "=>", "$", "tab", ")", "{", "if", "(", "!", "isset", "(", "$", "newtabs", "[", "$", "tabname", "]", ")", ")", "{", "$", "newtabs", "[", "$", "tabname", "]", "=", "$", "tab", ";", "}", "}", "$", "this", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'setter'", "]", "}", "(", "$", "newtabs", ")", ";", "}", "// ordering the ShowMapper", "if", "(", "$", "mapper", "instanceof", "ShowMapper", ")", "{", "foreach", "(", "$", "group", "as", "$", "tabName", "=>", "$", "tabContent", ")", "{", "$", "tabOptions", "=", "null", ";", "if", "(", "isset", "(", "$", "tabContent", "[", "'_options'", "]", ")", ")", "{", "$", "tabOptions", "=", "$", "tabContent", "[", "'_options'", "]", ";", "unset", "(", "$", "tabContent", "[", "'_options'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "tabOptions", "[", "'groupsOrder'", "]", ")", ")", "{", "$", "tabs", "=", "$", "this", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'getter'", "]", "}", "(", ")", ";", "$", "groups", "=", "$", "this", "->", "{", "$", "fcts", "[", "'groups'", "]", "[", "'getter'", "]", "}", "(", ")", ";", "$", "groupOrder", "=", "$", "tabOptions", "[", "'groupsOrder'", "]", ";", "$", "properOrderedArray", "=", "array_merge", "(", "array_flip", "(", "$", "groupOrder", ")", ",", "$", "groups", ")", ";", "$", "this", "->", "{", "$", "fcts", "[", "'groups'", "]", "[", "'setter'", "]", "}", "(", "$", "properOrderedArray", ")", ";", "$", "this", "->", "{", "$", "fcts", "[", "'tabs'", "]", "[", "'setter'", "]", "}", "(", "$", "tabs", ")", ";", "}", "}", "}", "return", "$", "mapper", ";", "}" ]
@param BaseMapper $mapper @param array $group @return BaseMapper
[ "@param", "BaseMapper", "$mapper", "@param", "array", "$group" ]
train
https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Admin/Traits/Mapper.php#L232-L455
alexpts/psr15-middlewares
src/Memory.php
Memory.process
public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface { $response = $next->handle($request); $memory = $this->getPeakMemory() . ' kbyte'; return $response->withHeader(self::HEADER, $memory); }
php
public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface { $response = $next->handle($request); $memory = $this->getPeakMemory() . ' kbyte'; return $response->withHeader(self::HEADER, $memory); }
[ "public", "function", "process", "(", "ServerRequestInterface", "$", "request", ",", "RequestHandlerInterface", "$", "next", ")", ":", "ResponseInterface", "{", "$", "response", "=", "$", "next", "->", "handle", "(", "$", "request", ")", ";", "$", "memory", "=", "$", "this", "->", "getPeakMemory", "(", ")", ".", "' kbyte'", ";", "return", "$", "response", "->", "withHeader", "(", "self", "::", "HEADER", ",", "$", "memory", ")", ";", "}" ]
@param ServerRequestInterface $request @param RequestHandlerInterface $next @return ResponseInterface @throws \InvalidArgumentException
[ "@param", "ServerRequestInterface", "$request", "@param", "RequestHandlerInterface", "$next" ]
train
https://github.com/alexpts/psr15-middlewares/blob/bff2887d5af01c54d9288fd19c20f0f593b69358/src/Memory.php#L28-L34
jan-dolata/crude-crud
src/Http/Requests/ApiUpdateRequest.php
ApiUpdateRequest.authorize
public function authorize() { $crude = CrudeInstance::get($this->crudeName); if ($crude == null) return false; if ($crude->cannotView()) return false; $model = $crude->getById($this->id); return $crude->canUpdate($model); }
php
public function authorize() { $crude = CrudeInstance::get($this->crudeName); if ($crude == null) return false; if ($crude->cannotView()) return false; $model = $crude->getById($this->id); return $crude->canUpdate($model); }
[ "public", "function", "authorize", "(", ")", "{", "$", "crude", "=", "CrudeInstance", "::", "get", "(", "$", "this", "->", "crudeName", ")", ";", "if", "(", "$", "crude", "==", "null", ")", "return", "false", ";", "if", "(", "$", "crude", "->", "cannotView", "(", ")", ")", "return", "false", ";", "$", "model", "=", "$", "crude", "->", "getById", "(", "$", "this", "->", "id", ")", ";", "return", "$", "crude", "->", "canUpdate", "(", "$", "model", ")", ";", "}" ]
Determine if the user is authorized to make this request. @return bool
[ "Determine", "if", "the", "user", "is", "authorized", "to", "make", "this", "request", "." ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Http/Requests/ApiUpdateRequest.php#L16-L29
jan-dolata/crude-crud
src/Http/Requests/ApiUpdateRequest.php
ApiUpdateRequest.rules
public function rules() { $crude = CrudeInstance::get($this->crudeName); if ($crude == null) return []; if (! $crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithValidationInterface) return []; $attr = $crude->getCrudeSetup()->getEditForm(); return $crude->getValidationRules($attr, $this->all()); }
php
public function rules() { $crude = CrudeInstance::get($this->crudeName); if ($crude == null) return []; if (! $crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithValidationInterface) return []; $attr = $crude->getCrudeSetup()->getEditForm(); return $crude->getValidationRules($attr, $this->all()); }
[ "public", "function", "rules", "(", ")", "{", "$", "crude", "=", "CrudeInstance", "::", "get", "(", "$", "this", "->", "crudeName", ")", ";", "if", "(", "$", "crude", "==", "null", ")", "return", "[", "]", ";", "if", "(", "!", "$", "crude", "instanceof", "\\", "JanDolata", "\\", "CrudeCRUD", "\\", "Engine", "\\", "Interfaces", "\\", "WithValidationInterface", ")", "return", "[", "]", ";", "$", "attr", "=", "$", "crude", "->", "getCrudeSetup", "(", ")", "->", "getEditForm", "(", ")", ";", "return", "$", "crude", "->", "getValidationRules", "(", "$", "attr", ",", "$", "this", "->", "all", "(", ")", ")", ";", "}" ]
Get the validation rules that apply to the request. @return array
[ "Get", "the", "validation", "rules", "that", "apply", "to", "the", "request", "." ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Http/Requests/ApiUpdateRequest.php#L36-L49
jan-dolata/crude-crud
src/Engine/Traits/FromModelTraitPart/ModelTrait.php
ModelTrait.prepareModelCrudeSetup
public function prepareModelCrudeSetup() { $crudeName = $this->getCalledClassName(); $modelAttr = array_merge(['id'], $this->model->getFillable(), ['created_at']); foreach ($modelAttr as $attr) $this->scope[$attr] = $this->model->getTable() . '.' . $attr; $this->crudeSetup = new CrudeSetup($crudeName, $modelAttr); if ($this->cannotUpdate()) $this->crudeSetup->lockEditOption(); if ($this->cannotStore('check with permission')) $this->crudeSetup->lockAddOption(); if ($this->cannotDelete()) $this->crudeSetup->lockDeleteOption(); if ($this->cannotOrder()) $this->crudeSetup->lockOrderOption(); $this->crudeSetup->setFilters(['id']); return $this->crudeSetup; }
php
public function prepareModelCrudeSetup() { $crudeName = $this->getCalledClassName(); $modelAttr = array_merge(['id'], $this->model->getFillable(), ['created_at']); foreach ($modelAttr as $attr) $this->scope[$attr] = $this->model->getTable() . '.' . $attr; $this->crudeSetup = new CrudeSetup($crudeName, $modelAttr); if ($this->cannotUpdate()) $this->crudeSetup->lockEditOption(); if ($this->cannotStore('check with permission')) $this->crudeSetup->lockAddOption(); if ($this->cannotDelete()) $this->crudeSetup->lockDeleteOption(); if ($this->cannotOrder()) $this->crudeSetup->lockOrderOption(); $this->crudeSetup->setFilters(['id']); return $this->crudeSetup; }
[ "public", "function", "prepareModelCrudeSetup", "(", ")", "{", "$", "crudeName", "=", "$", "this", "->", "getCalledClassName", "(", ")", ";", "$", "modelAttr", "=", "array_merge", "(", "[", "'id'", "]", ",", "$", "this", "->", "model", "->", "getFillable", "(", ")", ",", "[", "'created_at'", "]", ")", ";", "foreach", "(", "$", "modelAttr", "as", "$", "attr", ")", "$", "this", "->", "scope", "[", "$", "attr", "]", "=", "$", "this", "->", "model", "->", "getTable", "(", ")", ".", "'.'", ".", "$", "attr", ";", "$", "this", "->", "crudeSetup", "=", "new", "CrudeSetup", "(", "$", "crudeName", ",", "$", "modelAttr", ")", ";", "if", "(", "$", "this", "->", "cannotUpdate", "(", ")", ")", "$", "this", "->", "crudeSetup", "->", "lockEditOption", "(", ")", ";", "if", "(", "$", "this", "->", "cannotStore", "(", "'check with permission'", ")", ")", "$", "this", "->", "crudeSetup", "->", "lockAddOption", "(", ")", ";", "if", "(", "$", "this", "->", "cannotDelete", "(", ")", ")", "$", "this", "->", "crudeSetup", "->", "lockDeleteOption", "(", ")", ";", "if", "(", "$", "this", "->", "cannotOrder", "(", ")", ")", "$", "this", "->", "crudeSetup", "->", "lockOrderOption", "(", ")", ";", "$", "this", "->", "crudeSetup", "->", "setFilters", "(", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "crudeSetup", ";", "}" ]
Prepare default crude setup @return self
[ "Prepare", "default", "crude", "setup" ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/ModelTrait.php#L40-L65
FrenchFrogs/framework
src/Table/Column/Link.php
Link.getBindedLink
public function getBindedLink($row = []) { $bind = array_intersect_key($row, array_fill_keys($this->getBinds(), '')); // patch pour les paramètre bindé en query $link = str_replace('%25', '%', $this->getLink()); return vsprintf($link, $bind); }
php
public function getBindedLink($row = []) { $bind = array_intersect_key($row, array_fill_keys($this->getBinds(), '')); // patch pour les paramètre bindé en query $link = str_replace('%25', '%', $this->getLink()); return vsprintf($link, $bind); }
[ "public", "function", "getBindedLink", "(", "$", "row", "=", "[", "]", ")", "{", "$", "bind", "=", "array_intersect_key", "(", "$", "row", ",", "array_fill_keys", "(", "$", "this", "->", "getBinds", "(", ")", ",", "''", ")", ")", ";", "// patch pour les paramètre bindé en query", "$", "link", "=", "str_replace", "(", "'%25'", ",", "'%'", ",", "$", "this", "->", "getLink", "(", ")", ")", ";", "return", "vsprintf", "(", "$", "link", ",", "$", "bind", ")", ";", "}" ]
Return the binded link @param array $row @return string
[ "Return", "the", "binded", "link" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Link.php#L154-L161
joomla-framework/profiler
src/Profiler.php
Profiler.getTimeBetween
public function getTimeBetween($first, $second) { if (!isset($this->lookup[$first])) { throw new \LogicException( sprintf( 'The point %s was not marked in the profiler %s.', $first, $this->name ) ); } if (!isset($this->lookup[$second])) { throw new \LogicException( sprintf( 'The point %s was not marked in the profiler %s.', $second, $this->name ) ); } $indexFirst = $this->lookup[$first]; $indexSecond = $this->lookup[$second]; $firstPoint = $this->points[$indexFirst]; $secondPoint = $this->points[$indexSecond]; return abs($secondPoint->getTime() - $firstPoint->getTime()); }
php
public function getTimeBetween($first, $second) { if (!isset($this->lookup[$first])) { throw new \LogicException( sprintf( 'The point %s was not marked in the profiler %s.', $first, $this->name ) ); } if (!isset($this->lookup[$second])) { throw new \LogicException( sprintf( 'The point %s was not marked in the profiler %s.', $second, $this->name ) ); } $indexFirst = $this->lookup[$first]; $indexSecond = $this->lookup[$second]; $firstPoint = $this->points[$indexFirst]; $secondPoint = $this->points[$indexSecond]; return abs($secondPoint->getTime() - $firstPoint->getTime()); }
[ "public", "function", "getTimeBetween", "(", "$", "first", ",", "$", "second", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "lookup", "[", "$", "first", "]", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'The point %s was not marked in the profiler %s.'", ",", "$", "first", ",", "$", "this", "->", "name", ")", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "lookup", "[", "$", "second", "]", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'The point %s was not marked in the profiler %s.'", ",", "$", "second", ",", "$", "this", "->", "name", ")", ")", ";", "}", "$", "indexFirst", "=", "$", "this", "->", "lookup", "[", "$", "first", "]", ";", "$", "indexSecond", "=", "$", "this", "->", "lookup", "[", "$", "second", "]", ";", "$", "firstPoint", "=", "$", "this", "->", "points", "[", "$", "indexFirst", "]", ";", "$", "secondPoint", "=", "$", "this", "->", "points", "[", "$", "indexSecond", "]", ";", "return", "abs", "(", "$", "secondPoint", "->", "getTime", "(", ")", "-", "$", "firstPoint", "->", "getTime", "(", ")", ")", ";", "}" ]
Get the elapsed time in seconds between the two points. @param string $first The name of the first point. @param string $second The name of the second point. @return float The elapsed time between these points in seconds. @since 1.0 @throws \LogicException If the points were not marked.
[ "Get", "the", "elapsed", "time", "in", "seconds", "between", "the", "two", "points", "." ]
train
https://github.com/joomla-framework/profiler/blob/efdea10dc547d8fa853be6737100c844be227ca6/src/Profiler.php#L269-L300
joomla-framework/profiler
src/Profiler.php
Profiler.getMemoryBytesBetween
public function getMemoryBytesBetween($first, $second) { if (!isset($this->lookup[$first])) { throw new \LogicException( sprintf( 'The point %s was not marked in the profiler %s.', $first, $this->name ) ); } if (!isset($this->lookup[$second])) { throw new \LogicException( sprintf( 'The point %s was not marked in the profiler %s.', $second, $this->name ) ); } $indexFirst = $this->lookup[$first]; $indexSecond = $this->lookup[$second]; $firstPoint = $this->points[$indexFirst]; $secondPoint = $this->points[$indexSecond]; return abs($secondPoint->getMemoryBytes() - $firstPoint->getMemoryBytes()); }
php
public function getMemoryBytesBetween($first, $second) { if (!isset($this->lookup[$first])) { throw new \LogicException( sprintf( 'The point %s was not marked in the profiler %s.', $first, $this->name ) ); } if (!isset($this->lookup[$second])) { throw new \LogicException( sprintf( 'The point %s was not marked in the profiler %s.', $second, $this->name ) ); } $indexFirst = $this->lookup[$first]; $indexSecond = $this->lookup[$second]; $firstPoint = $this->points[$indexFirst]; $secondPoint = $this->points[$indexSecond]; return abs($secondPoint->getMemoryBytes() - $firstPoint->getMemoryBytes()); }
[ "public", "function", "getMemoryBytesBetween", "(", "$", "first", ",", "$", "second", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "lookup", "[", "$", "first", "]", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'The point %s was not marked in the profiler %s.'", ",", "$", "first", ",", "$", "this", "->", "name", ")", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "lookup", "[", "$", "second", "]", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'The point %s was not marked in the profiler %s.'", ",", "$", "second", ",", "$", "this", "->", "name", ")", ")", ";", "}", "$", "indexFirst", "=", "$", "this", "->", "lookup", "[", "$", "first", "]", ";", "$", "indexSecond", "=", "$", "this", "->", "lookup", "[", "$", "second", "]", ";", "$", "firstPoint", "=", "$", "this", "->", "points", "[", "$", "indexFirst", "]", ";", "$", "secondPoint", "=", "$", "this", "->", "points", "[", "$", "indexSecond", "]", ";", "return", "abs", "(", "$", "secondPoint", "->", "getMemoryBytes", "(", ")", "-", "$", "firstPoint", "->", "getMemoryBytes", "(", ")", ")", ";", "}" ]
Get the amount of allocated memory in bytes between the two points. @param string $first The name of the first point. @param string $second The name of the second point. @return integer The amount of allocated memory between these points in bytes. @since 1.0 @throws \LogicException If the points were not marked.
[ "Get", "the", "amount", "of", "allocated", "memory", "in", "bytes", "between", "the", "two", "points", "." ]
train
https://github.com/joomla-framework/profiler/blob/efdea10dc547d8fa853be6737100c844be227ca6/src/Profiler.php#L313-L344
joomla-framework/profiler
src/Profiler.php
Profiler.setStart
public function setStart($timeStamp = 0.0, $memoryBytes = 0) { if (!empty($this->points)) { throw new \RuntimeException('The start point cannot be adjusted after points are added to the profiler.'); } $this->startTimeStamp = $timeStamp; $this->startMemoryBytes = $memoryBytes; $point = new ProfilePoint('start'); // Store the point. $this->points[] = $point; // Add it in the lookup table. $this->lookup[$point->getName()] = \count($this->points) - 1; return $this; }
php
public function setStart($timeStamp = 0.0, $memoryBytes = 0) { if (!empty($this->points)) { throw new \RuntimeException('The start point cannot be adjusted after points are added to the profiler.'); } $this->startTimeStamp = $timeStamp; $this->startMemoryBytes = $memoryBytes; $point = new ProfilePoint('start'); // Store the point. $this->points[] = $point; // Add it in the lookup table. $this->lookup[$point->getName()] = \count($this->points) - 1; return $this; }
[ "public", "function", "setStart", "(", "$", "timeStamp", "=", "0.0", ",", "$", "memoryBytes", "=", "0", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "points", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'The start point cannot be adjusted after points are added to the profiler.'", ")", ";", "}", "$", "this", "->", "startTimeStamp", "=", "$", "timeStamp", ";", "$", "this", "->", "startMemoryBytes", "=", "$", "memoryBytes", ";", "$", "point", "=", "new", "ProfilePoint", "(", "'start'", ")", ";", "// Store the point.", "$", "this", "->", "points", "[", "]", "=", "$", "point", ";", "// Add it in the lookup table.", "$", "this", "->", "lookup", "[", "$", "point", "->", "getName", "(", ")", "]", "=", "\\", "count", "(", "$", "this", "->", "points", ")", "-", "1", ";", "return", "$", "this", ";", "}" ]
Creates a profile point with the specified starting time and memory. This method will only add a point if no other points have been added as the ProfilePointInterface objects created before changing the start point would result in inaccurate measurements. @param float $timeStamp Unix timestamp in microseconds when the profiler should start measuring time. @param integer $memoryBytes Memory amount in bytes when the profiler should start measuring memory. @return ProfilerInterface This method is chainable. @since 1.2.0 @throws \RuntimeException
[ "Creates", "a", "profile", "point", "with", "the", "specified", "starting", "time", "and", "memory", "." ]
train
https://github.com/joomla-framework/profiler/blob/efdea10dc547d8fa853be6737100c844be227ca6/src/Profiler.php#L460-L479
yosmanyga/resource
src/Yosmanyga/Resource/Reader/Flat/FileReader.php
FileReader.read
public function read(Resource $resource) { $file = $resource->getMetadata('file'); if (!is_file($file)) { throw new \InvalidArgumentException(sprintf('File "%s" not found.', $file)); } return file_get_contents($file); }
php
public function read(Resource $resource) { $file = $resource->getMetadata('file'); if (!is_file($file)) { throw new \InvalidArgumentException(sprintf('File "%s" not found.', $file)); } return file_get_contents($file); }
[ "public", "function", "read", "(", "Resource", "$", "resource", ")", "{", "$", "file", "=", "$", "resource", "->", "getMetadata", "(", "'file'", ")", ";", "if", "(", "!", "is_file", "(", "$", "file", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'File \"%s\" not found.'", ",", "$", "file", ")", ")", ";", "}", "return", "file_get_contents", "(", "$", "file", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/yosmanyga/resource/blob/a8b505c355920a908917a0484f764ddfa63205fa/src/Yosmanyga/Resource/Reader/Flat/FileReader.php#L33-L42
verschoof/bunq-api
src/Service/DefaultInstallationService.php
DefaultInstallationService.install
public function install() { $publicKey = $this->certificateStorage->load(CertificateType::PUBLIC_KEY()); $response = $this->sendInstallationPostRequest( '/v1/installation', [ 'json' => [ 'client_public_key' => $publicKey->toString(), ], ] ); $responseArray = \json_decode((string)$response->getBody(), true); return [ 'token' => $responseArray['Response'][1]['Token']['token'], 'public_key' => $responseArray['Response'][2]['ServerPublicKey']['server_public_key'], ]; }
php
public function install() { $publicKey = $this->certificateStorage->load(CertificateType::PUBLIC_KEY()); $response = $this->sendInstallationPostRequest( '/v1/installation', [ 'json' => [ 'client_public_key' => $publicKey->toString(), ], ] ); $responseArray = \json_decode((string)$response->getBody(), true); return [ 'token' => $responseArray['Response'][1]['Token']['token'], 'public_key' => $responseArray['Response'][2]['ServerPublicKey']['server_public_key'], ]; }
[ "public", "function", "install", "(", ")", "{", "$", "publicKey", "=", "$", "this", "->", "certificateStorage", "->", "load", "(", "CertificateType", "::", "PUBLIC_KEY", "(", ")", ")", ";", "$", "response", "=", "$", "this", "->", "sendInstallationPostRequest", "(", "'/v1/installation'", ",", "[", "'json'", "=>", "[", "'client_public_key'", "=>", "$", "publicKey", "->", "toString", "(", ")", ",", "]", ",", "]", ")", ";", "$", "responseArray", "=", "\\", "json_decode", "(", "(", "string", ")", "$", "response", "->", "getBody", "(", ")", ",", "true", ")", ";", "return", "[", "'token'", "=>", "$", "responseArray", "[", "'Response'", "]", "[", "1", "]", "[", "'Token'", "]", "[", "'token'", "]", ",", "'public_key'", "=>", "$", "responseArray", "[", "'Response'", "]", "[", "2", "]", "[", "'ServerPublicKey'", "]", "[", "'server_public_key'", "]", ",", "]", ";", "}" ]
Registers your public key with the Bunq API. @return array
[ "Registers", "your", "public", "key", "with", "the", "Bunq", "API", "." ]
train
https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Service/DefaultInstallationService.php#L60-L79
verschoof/bunq-api
src/Service/DefaultInstallationService.php
DefaultInstallationService.registerDevice
public function registerDevice(Token $token) { $this->sendInstallationPostRequest( '/v1/device-server', [ 'headers' => [ 'X-Bunq-Client-Authentication' => $token->toString(), ], 'json' => [ 'description' => 'Bunq PHP API Client', 'secret' => $this->apiKey, 'permitted_ips' => $this->permittedIps, ], ] ); }
php
public function registerDevice(Token $token) { $this->sendInstallationPostRequest( '/v1/device-server', [ 'headers' => [ 'X-Bunq-Client-Authentication' => $token->toString(), ], 'json' => [ 'description' => 'Bunq PHP API Client', 'secret' => $this->apiKey, 'permitted_ips' => $this->permittedIps, ], ] ); }
[ "public", "function", "registerDevice", "(", "Token", "$", "token", ")", "{", "$", "this", "->", "sendInstallationPostRequest", "(", "'/v1/device-server'", ",", "[", "'headers'", "=>", "[", "'X-Bunq-Client-Authentication'", "=>", "$", "token", "->", "toString", "(", ")", ",", "]", ",", "'json'", "=>", "[", "'description'", "=>", "'Bunq PHP API Client'", ",", "'secret'", "=>", "$", "this", "->", "apiKey", ",", "'permitted_ips'", "=>", "$", "this", "->", "permittedIps", ",", "]", ",", "]", ")", ";", "}" ]
Registers a device with the Bunq API. @param Token $token return void
[ "Registers", "a", "device", "with", "the", "Bunq", "API", "." ]
train
https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Service/DefaultInstallationService.php#L88-L103
verschoof/bunq-api
src/Service/DefaultInstallationService.php
DefaultInstallationService.createSession
public function createSession(Token $token) { $response = $this->sendInstallationPostRequest( '/v1/session-server', [ 'headers' => [ 'X-Bunq-Client-Authentication' => $token->toString(), ], 'json' => [ 'secret' => $this->apiKey, ], ] ); $responseArray = \json_decode((string)$response->getBody(), true); return $responseArray['Response'][1]['Token']['token']; }
php
public function createSession(Token $token) { $response = $this->sendInstallationPostRequest( '/v1/session-server', [ 'headers' => [ 'X-Bunq-Client-Authentication' => $token->toString(), ], 'json' => [ 'secret' => $this->apiKey, ], ] ); $responseArray = \json_decode((string)$response->getBody(), true); return $responseArray['Response'][1]['Token']['token']; }
[ "public", "function", "createSession", "(", "Token", "$", "token", ")", "{", "$", "response", "=", "$", "this", "->", "sendInstallationPostRequest", "(", "'/v1/session-server'", ",", "[", "'headers'", "=>", "[", "'X-Bunq-Client-Authentication'", "=>", "$", "token", "->", "toString", "(", ")", ",", "]", ",", "'json'", "=>", "[", "'secret'", "=>", "$", "this", "->", "apiKey", ",", "]", ",", "]", ")", ";", "$", "responseArray", "=", "\\", "json_decode", "(", "(", "string", ")", "$", "response", "->", "getBody", "(", ")", ",", "true", ")", ";", "return", "$", "responseArray", "[", "'Response'", "]", "[", "1", "]", "[", "'Token'", "]", "[", "'token'", "]", ";", "}" ]
Registers a session with the Bunq API. @param Token $token @return array
[ "Registers", "a", "session", "with", "the", "Bunq", "API", "." ]
train
https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Service/DefaultInstallationService.php#L112-L129
verschoof/bunq-api
src/Service/DefaultInstallationService.php
DefaultInstallationService.sendInstallationPostRequest
private function sendInstallationPostRequest($url, array $options = []) { try { return $this->httpClient->request('POST', $url, $options); } catch (ClientException $exception) { throw new BunqException($exception); } }
php
private function sendInstallationPostRequest($url, array $options = []) { try { return $this->httpClient->request('POST', $url, $options); } catch (ClientException $exception) { throw new BunqException($exception); } }
[ "private", "function", "sendInstallationPostRequest", "(", "$", "url", ",", "array", "$", "options", "=", "[", "]", ")", "{", "try", "{", "return", "$", "this", "->", "httpClient", "->", "request", "(", "'POST'", ",", "$", "url", ",", "$", "options", ")", ";", "}", "catch", "(", "ClientException", "$", "exception", ")", "{", "throw", "new", "BunqException", "(", "$", "exception", ")", ";", "}", "}" ]
Sends a post request using the installation HTTP Client @param $url @param array $options @return ResponseInterface @throws BunqException
[ "Sends", "a", "post", "request", "using", "the", "installation", "HTTP", "Client" ]
train
https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Service/DefaultInstallationService.php#L140-L147
huasituo/hstcms
src/Libraries/Fields/Kindeditor.php
Kindeditor.input
public function input($cname, $name, $cfg, $value = NULL, $id = 0) { $source = isset($cfg['option']['source']) && $cfg['option']['source'] ? 'true' : 'false'; $cfg['option']['value'] = isset($cfg['option']['value']) ? $cfg['option']['value'] : ""; // 字段显示名称 $text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font>' : '').'&nbsp;'.$cname.':'; // 表单宽度设置 $width = isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '90%'; // 表单高度设置 $key = isset($cfg['option']['key']) && $cfg['option']['key'] ? $cfg['option']['key'] : ''; $height = isset($cfg['option']['height']) && $cfg['option']['height'] ? $cfg['option']['height'] : '300'; // 字段提示信息 $tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips']: ''; $_pagebreak = isset($cfg['option']['pagebreak']) ? $cfg['option']['pagebreak'] : 0; // 字段默认值 $value = $value ? $value : $cfg['option']['value']; $style = 'style="width:'.$width.';height:'.$height.'px;"'; // 输出 $str = ''; $tool = $this->isadmin ? "" : ''; // 后台引用时显示html工具栏 $pagebreak = $name == 'content' || $_pagebreak ? ', \'pagebreak\'' : ''; // 编辑器模式 $mode = $this->isadmin ? $cfg['option']['mode'] : (isset($cfg['option']['mode2']) ? $cfg['option']['mode2'] : $cfg['option']['mode']); switch ($mode) { case 3: // 自定义 $tool.= $this->isadmin ? $cfg['option']['tool'] : (isset($cfg['option']['tool2']) ? $cfg['option']['tool2'] : $cfg['option']['tool']); break; case 2: // 精简 $tool.= "'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|', 'emoticons'$pagebreak"; break; case 1: // 默认 $tool.= "'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat','undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'selectall', 'fullscreen','|', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage', 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'anchor', 'link', 'unlink'$pagebreak"; break; } // $uploadJson = site_index_url('upload/index', $urlA); $uploadJson =''; $str.= " <textarea class=\"hstui-input hstui-textarea\" name=\"$name\" id=\"hstcms_$name\" $style>$value</textarea> <script type=\"text/javascript\"> Hstui.use('jquery', 'common', 'kindeditor', function() { Hstui.editer('#hstcms_$name', { source:$source, items:[$tool] }); }) </script> "; return $this->input_format($name, $text, $str, $tips); }
php
public function input($cname, $name, $cfg, $value = NULL, $id = 0) { $source = isset($cfg['option']['source']) && $cfg['option']['source'] ? 'true' : 'false'; $cfg['option']['value'] = isset($cfg['option']['value']) ? $cfg['option']['value'] : ""; // 字段显示名称 $text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font>' : '').'&nbsp;'.$cname.':'; // 表单宽度设置 $width = isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '90%'; // 表单高度设置 $key = isset($cfg['option']['key']) && $cfg['option']['key'] ? $cfg['option']['key'] : ''; $height = isset($cfg['option']['height']) && $cfg['option']['height'] ? $cfg['option']['height'] : '300'; // 字段提示信息 $tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips']: ''; $_pagebreak = isset($cfg['option']['pagebreak']) ? $cfg['option']['pagebreak'] : 0; // 字段默认值 $value = $value ? $value : $cfg['option']['value']; $style = 'style="width:'.$width.';height:'.$height.'px;"'; // 输出 $str = ''; $tool = $this->isadmin ? "" : ''; // 后台引用时显示html工具栏 $pagebreak = $name == 'content' || $_pagebreak ? ', \'pagebreak\'' : ''; // 编辑器模式 $mode = $this->isadmin ? $cfg['option']['mode'] : (isset($cfg['option']['mode2']) ? $cfg['option']['mode2'] : $cfg['option']['mode']); switch ($mode) { case 3: // 自定义 $tool.= $this->isadmin ? $cfg['option']['tool'] : (isset($cfg['option']['tool2']) ? $cfg['option']['tool2'] : $cfg['option']['tool']); break; case 2: // 精简 $tool.= "'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|', 'emoticons'$pagebreak"; break; case 1: // 默认 $tool.= "'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat','undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'selectall', 'fullscreen','|', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage', 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'anchor', 'link', 'unlink'$pagebreak"; break; } // $uploadJson = site_index_url('upload/index', $urlA); $uploadJson =''; $str.= " <textarea class=\"hstui-input hstui-textarea\" name=\"$name\" id=\"hstcms_$name\" $style>$value</textarea> <script type=\"text/javascript\"> Hstui.use('jquery', 'common', 'kindeditor', function() { Hstui.editer('#hstcms_$name', { source:$source, items:[$tool] }); }) </script> "; return $this->input_format($name, $text, $str, $tips); }
[ "public", "function", "input", "(", "$", "cname", ",", "$", "name", ",", "$", "cfg", ",", "$", "value", "=", "NULL", ",", "$", "id", "=", "0", ")", "{", "$", "source", "=", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'source'", "]", ")", "&&", "$", "cfg", "[", "'option'", "]", "[", "'source'", "]", "?", "'true'", ":", "'false'", ";", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", "=", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", ")", "?", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", ":", "\"\"", ";", "// 字段显示名称", "$", "text", "=", "(", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'required'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'required'", "]", "==", "1", "?", "'<font color=\"red\">*</font>'", ":", "''", ")", ".", "'&nbsp;'", ".", "$", "cname", ".", "':';", "", "// 表单宽度设置", "$", "width", "=", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'width'", "]", ")", "&&", "$", "cfg", "[", "'option'", "]", "[", "'width'", "]", "?", "$", "cfg", "[", "'option'", "]", "[", "'width'", "]", ":", "'90%'", ";", "// 表单高度设置", "$", "key", "=", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'key'", "]", ")", "&&", "$", "cfg", "[", "'option'", "]", "[", "'key'", "]", "?", "$", "cfg", "[", "'option'", "]", "[", "'key'", "]", ":", "''", ";", "$", "height", "=", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'height'", "]", ")", "&&", "$", "cfg", "[", "'option'", "]", "[", "'height'", "]", "?", "$", "cfg", "[", "'option'", "]", "[", "'height'", "]", ":", "'300'", ";", "// 字段提示信息", "$", "tips", "=", "isset", "(", "$", "cfg", "[", "'validate'", "]", "[", "'tips'", "]", ")", "&&", "$", "cfg", "[", "'validate'", "]", "[", "'tips'", "]", "?", "$", "cfg", "[", "'validate'", "]", "[", "'tips'", "]", ":", "''", ";", "$", "_pagebreak", "=", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'pagebreak'", "]", ")", "?", "$", "cfg", "[", "'option'", "]", "[", "'pagebreak'", "]", ":", "0", ";", "// 字段默认值", "$", "value", "=", "$", "value", "?", "$", "value", ":", "$", "cfg", "[", "'option'", "]", "[", "'value'", "]", ";", "$", "style", "=", "'style=\"width:'", ".", "$", "width", ".", "';height:'", ".", "$", "height", ".", "'px;\"'", ";", "// 输出", "$", "str", "=", "''", ";", "$", "tool", "=", "$", "this", "->", "isadmin", "?", "\"\"", ":", "''", ";", "// 后台引用时显示html工具栏", "$", "pagebreak", "=", "$", "name", "==", "'content'", "||", "$", "_pagebreak", "?", "', \\'pagebreak\\''", ":", "''", ";", "// 编辑器模式", "$", "mode", "=", "$", "this", "->", "isadmin", "?", "$", "cfg", "[", "'option'", "]", "[", "'mode'", "]", ":", "(", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'mode2'", "]", ")", "?", "$", "cfg", "[", "'option'", "]", "[", "'mode2'", "]", ":", "$", "cfg", "[", "'option'", "]", "[", "'mode'", "]", ")", ";", "switch", "(", "$", "mode", ")", "{", "case", "3", ":", "// 自定义", "$", "tool", ".=", "$", "this", "->", "isadmin", "?", "$", "cfg", "[", "'option'", "]", "[", "'tool'", "]", ":", "(", "isset", "(", "$", "cfg", "[", "'option'", "]", "[", "'tool2'", "]", ")", "?", "$", "cfg", "[", "'option'", "]", "[", "'tool2'", "]", ":", "$", "cfg", "[", "'option'", "]", "[", "'tool'", "]", ")", ";", "break", ";", "case", "2", ":", "// 精简", "$", "tool", ".=", "\"'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',\n\t\t\t\t\t\t'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',\n\t\t\t\t\t\t'insertunorderedlist', '|', 'emoticons'$pagebreak\"", ";", "break", ";", "case", "1", ":", "// 默认", "$", "tool", ".=", "\"'justifyleft', 'justifycenter', 'justifyright',\n\t\t'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',\n\t\t'superscript', 'clearhtml', 'quickformat','undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',\n\t\t'plainpaste', 'wordpaste', '|', 'selectall', 'fullscreen','|', '/',\n\t\t'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',\n\t\t'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',\n\t\t'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap',\n\t\t'anchor', 'link', 'unlink'$pagebreak\"", ";", "break", ";", "}", "// $uploadJson = site_index_url('upload/index', $urlA);", "$", "uploadJson", "=", "''", ";", "$", "str", ".=", "\"\n\t\t<textarea class=\\\"hstui-input hstui-textarea\\\" name=\\\"$name\\\" id=\\\"hstcms_$name\\\" $style>$value</textarea>\n\t\t<script type=\\\"text/javascript\\\">\n\t\t\tHstui.use('jquery', 'common', 'kindeditor', function() {\n\t\t\t\tHstui.editer('#hstcms_$name', {\n\t\t\t\t\tsource:$source,\n\t\t\t\t\titems:[$tool]\n\t\t\t\t});\n\t\t\t})\n\t\t</script>\n\t\t\"", ";", "return", "$", "this", "->", "input_format", "(", "$", "name", ",", "$", "text", ",", "$", "str", ",", "$", "tips", ")", ";", "}" ]
字段表单输入 @param string $cname 字段别名 @param string $name 字段名称 @param array $cfg 字段配置 @param string $value 值 @return string
[ "字段表单输入" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Kindeditor.php#L120-L178
huasituo/hstcms
src/Libraries/Fields/Kindeditor.php
Kindeditor.insert_value
public function insert_value(Request $request, $field, $postData = []) { $value = $request->get($field['fieldname']); $postData[$field['relatedtable']][$field['fieldname']] = $value; return $postData; }
php
public function insert_value(Request $request, $field, $postData = []) { $value = $request->get($field['fieldname']); $postData[$field['relatedtable']][$field['fieldname']] = $value; return $postData; }
[ "public", "function", "insert_value", "(", "Request", "$", "request", ",", "$", "field", ",", "$", "postData", "=", "[", "]", ")", "{", "$", "value", "=", "$", "request", "->", "get", "(", "$", "field", "[", "'fieldname'", "]", ")", ";", "$", "postData", "[", "$", "field", "[", "'relatedtable'", "]", "]", "[", "$", "field", "[", "'fieldname'", "]", "]", "=", "$", "value", ";", "return", "$", "postData", ";", "}" ]
处理输入数据,提供给入库
[ "处理输入数据,提供给入库" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Kindeditor.php#L183-L188
ray-di/Ray.WebFormModule
src/AuraInputModule.php
AuraInputModule.configure
protected function configure() { $this->install(new AuraSessionModule); $this->bind(Reader::class)->to(AnnotationReader::class)->in(Scope::SINGLETON); $this->bind(BuilderInterface::class)->to(Builder::class); $this->bind(FilterInterface::class)->to(Filter::class); $this->bind(AntiCsrfInterface::class)->to(AntiCsrf::class)->in(Scope::SINGLETON); $this->bind(FailureHandlerInterface::class)->to(OnFailureMethodHandler::class); $this->bind(FailureHandlerInterface::class)->annotatedWith('vnd_error')->to(VndErrorHandler::class)->in(Scope::SINGLETON); $this->bind(HelperLocatorFactory::class); $this->bind(FilterFactory::class); $this->bindInterceptor( $this->matcher->any(), $this->matcher->annotatedWith(InputValidation::class), [InputValidationInterceptor::class] ); $this->bindInterceptor( $this->matcher->any(), $this->matcher->annotatedWith(FormValidation::class), [AuraInputInterceptor::class] ); }
php
protected function configure() { $this->install(new AuraSessionModule); $this->bind(Reader::class)->to(AnnotationReader::class)->in(Scope::SINGLETON); $this->bind(BuilderInterface::class)->to(Builder::class); $this->bind(FilterInterface::class)->to(Filter::class); $this->bind(AntiCsrfInterface::class)->to(AntiCsrf::class)->in(Scope::SINGLETON); $this->bind(FailureHandlerInterface::class)->to(OnFailureMethodHandler::class); $this->bind(FailureHandlerInterface::class)->annotatedWith('vnd_error')->to(VndErrorHandler::class)->in(Scope::SINGLETON); $this->bind(HelperLocatorFactory::class); $this->bind(FilterFactory::class); $this->bindInterceptor( $this->matcher->any(), $this->matcher->annotatedWith(InputValidation::class), [InputValidationInterceptor::class] ); $this->bindInterceptor( $this->matcher->any(), $this->matcher->annotatedWith(FormValidation::class), [AuraInputInterceptor::class] ); }
[ "protected", "function", "configure", "(", ")", "{", "$", "this", "->", "install", "(", "new", "AuraSessionModule", ")", ";", "$", "this", "->", "bind", "(", "Reader", "::", "class", ")", "->", "to", "(", "AnnotationReader", "::", "class", ")", "->", "in", "(", "Scope", "::", "SINGLETON", ")", ";", "$", "this", "->", "bind", "(", "BuilderInterface", "::", "class", ")", "->", "to", "(", "Builder", "::", "class", ")", ";", "$", "this", "->", "bind", "(", "FilterInterface", "::", "class", ")", "->", "to", "(", "Filter", "::", "class", ")", ";", "$", "this", "->", "bind", "(", "AntiCsrfInterface", "::", "class", ")", "->", "to", "(", "AntiCsrf", "::", "class", ")", "->", "in", "(", "Scope", "::", "SINGLETON", ")", ";", "$", "this", "->", "bind", "(", "FailureHandlerInterface", "::", "class", ")", "->", "to", "(", "OnFailureMethodHandler", "::", "class", ")", ";", "$", "this", "->", "bind", "(", "FailureHandlerInterface", "::", "class", ")", "->", "annotatedWith", "(", "'vnd_error'", ")", "->", "to", "(", "VndErrorHandler", "::", "class", ")", "->", "in", "(", "Scope", "::", "SINGLETON", ")", ";", "$", "this", "->", "bind", "(", "HelperLocatorFactory", "::", "class", ")", ";", "$", "this", "->", "bind", "(", "FilterFactory", "::", "class", ")", ";", "$", "this", "->", "bindInterceptor", "(", "$", "this", "->", "matcher", "->", "any", "(", ")", ",", "$", "this", "->", "matcher", "->", "annotatedWith", "(", "InputValidation", "::", "class", ")", ",", "[", "InputValidationInterceptor", "::", "class", "]", ")", ";", "$", "this", "->", "bindInterceptor", "(", "$", "this", "->", "matcher", "->", "any", "(", ")", ",", "$", "this", "->", "matcher", "->", "annotatedWith", "(", "FormValidation", "::", "class", ")", ",", "[", "AuraInputInterceptor", "::", "class", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ray-di/Ray.WebFormModule/blob/4b6d33adb4a5c285278a068f3e7a5afdc4e680d9/src/AuraInputModule.php#L29-L50
mremi/Dolist
src/Mremi/Dolist/Authentication/AuthenticationManager.php
AuthenticationManager.getAuthenticationTokenContext
public function getAuthenticationTokenContext() { if (!$this->authenticationTokenResponse || $this->authenticationTokenResponse->isDeprecated()) { $this->authenticationTokenResponse = $this->authenticate(); } return new AuthenticationTokenContext($this->authenticationRequest->getAccountId(), $this->authenticationTokenResponse->getKey()); }
php
public function getAuthenticationTokenContext() { if (!$this->authenticationTokenResponse || $this->authenticationTokenResponse->isDeprecated()) { $this->authenticationTokenResponse = $this->authenticate(); } return new AuthenticationTokenContext($this->authenticationRequest->getAccountId(), $this->authenticationTokenResponse->getKey()); }
[ "public", "function", "getAuthenticationTokenContext", "(", ")", "{", "if", "(", "!", "$", "this", "->", "authenticationTokenResponse", "||", "$", "this", "->", "authenticationTokenResponse", "->", "isDeprecated", "(", ")", ")", "{", "$", "this", "->", "authenticationTokenResponse", "=", "$", "this", "->", "authenticate", "(", ")", ";", "}", "return", "new", "AuthenticationTokenContext", "(", "$", "this", "->", "authenticationRequest", "->", "getAccountId", "(", ")", ",", "$", "this", "->", "authenticationTokenResponse", "->", "getKey", "(", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/mremi/Dolist/blob/452c863aba12ef2965bafdb619c0278f8fc732d0/src/Mremi/Dolist/Authentication/AuthenticationManager.php#L67-L74
mremi/Dolist
src/Mremi/Dolist/Authentication/AuthenticationManager.php
AuthenticationManager.authenticate
private function authenticate() { $try = 0; while (true) { $try++; try { $response = $this->soapClient->__soapCall('GetAuthenticationToken', array(array( 'authenticationRequest' => $this->authenticationRequest->toArray(), ))); return new AuthenticationTokenResponse(new \DateTime($response->GetAuthenticationTokenResult->DeprecatedDate), $response->GetAuthenticationTokenResult->Key); } catch (\SoapFault $e) { if (null !== $this->logger) { $this->logger->critical(sprintf('[%] %s', __CLASS__, $e->getMessage())); } if ($try >= $this->retries) { throw $e; } // waiting 500ms before next call usleep(500000); } } }
php
private function authenticate() { $try = 0; while (true) { $try++; try { $response = $this->soapClient->__soapCall('GetAuthenticationToken', array(array( 'authenticationRequest' => $this->authenticationRequest->toArray(), ))); return new AuthenticationTokenResponse(new \DateTime($response->GetAuthenticationTokenResult->DeprecatedDate), $response->GetAuthenticationTokenResult->Key); } catch (\SoapFault $e) { if (null !== $this->logger) { $this->logger->critical(sprintf('[%] %s', __CLASS__, $e->getMessage())); } if ($try >= $this->retries) { throw $e; } // waiting 500ms before next call usleep(500000); } } }
[ "private", "function", "authenticate", "(", ")", "{", "$", "try", "=", "0", ";", "while", "(", "true", ")", "{", "$", "try", "++", ";", "try", "{", "$", "response", "=", "$", "this", "->", "soapClient", "->", "__soapCall", "(", "'GetAuthenticationToken'", ",", "array", "(", "array", "(", "'authenticationRequest'", "=>", "$", "this", "->", "authenticationRequest", "->", "toArray", "(", ")", ",", ")", ")", ")", ";", "return", "new", "AuthenticationTokenResponse", "(", "new", "\\", "DateTime", "(", "$", "response", "->", "GetAuthenticationTokenResult", "->", "DeprecatedDate", ")", ",", "$", "response", "->", "GetAuthenticationTokenResult", "->", "Key", ")", ";", "}", "catch", "(", "\\", "SoapFault", "$", "e", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "logger", ")", "{", "$", "this", "->", "logger", "->", "critical", "(", "sprintf", "(", "'[%] %s'", ",", "__CLASS__", ",", "$", "e", "->", "getMessage", "(", ")", ")", ")", ";", "}", "if", "(", "$", "try", ">=", "$", "this", "->", "retries", ")", "{", "throw", "$", "e", ";", "}", "// waiting 500ms before next call", "usleep", "(", "500000", ")", ";", "}", "}", "}" ]
Calls the authentication API @return AuthenticationTokenResponse @throws \SoapFault
[ "Calls", "the", "authentication", "API" ]
train
https://github.com/mremi/Dolist/blob/452c863aba12ef2965bafdb619c0278f8fc732d0/src/Mremi/Dolist/Authentication/AuthenticationManager.php#L83-L109
rinvex/obsolete-module
src/ModuleServiceProvider.php
ModuleServiceProvider.register
public function register() { // Merge config $this->mergeConfigFrom( realpath(__DIR__.'/../config/config.php'), 'rinvex.module' ); // Bind rinvex module instance to the IoC container $this->app->singleton('rinvex.module', function ($app) { return new ModuleManager($app); }); // Alias services within the IoC container $this->app->alias('Module', ModuleFacade::class); $this->app->alias('rinvex.module', ModuleManager::class); // Find and register all modules $this->app['rinvex.module']->find()->sort()->register(); }
php
public function register() { // Merge config $this->mergeConfigFrom( realpath(__DIR__.'/../config/config.php'), 'rinvex.module' ); // Bind rinvex module instance to the IoC container $this->app->singleton('rinvex.module', function ($app) { return new ModuleManager($app); }); // Alias services within the IoC container $this->app->alias('Module', ModuleFacade::class); $this->app->alias('rinvex.module', ModuleManager::class); // Find and register all modules $this->app['rinvex.module']->find()->sort()->register(); }
[ "public", "function", "register", "(", ")", "{", "// Merge config", "$", "this", "->", "mergeConfigFrom", "(", "realpath", "(", "__DIR__", ".", "'/../config/config.php'", ")", ",", "'rinvex.module'", ")", ";", "// Bind rinvex module instance to the IoC container", "$", "this", "->", "app", "->", "singleton", "(", "'rinvex.module'", ",", "function", "(", "$", "app", ")", "{", "return", "new", "ModuleManager", "(", "$", "app", ")", ";", "}", ")", ";", "// Alias services within the IoC container", "$", "this", "->", "app", "->", "alias", "(", "'Module'", ",", "ModuleFacade", "::", "class", ")", ";", "$", "this", "->", "app", "->", "alias", "(", "'rinvex.module'", ",", "ModuleManager", "::", "class", ")", ";", "// Find and register all modules", "$", "this", "->", "app", "[", "'rinvex.module'", "]", "->", "find", "(", ")", "->", "sort", "(", ")", "->", "register", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/rinvex/obsolete-module/blob/95e372ae97ecbe7071c3da397b0afd57f327361f/src/ModuleServiceProvider.php#L27-L45
comodojo/dispatcher.framework
src/Comodojo/Dispatcher/Response/Preprocessor/Status201.php
Status201.consolidate
public function consolidate(Response $response) { $location = $response->getLocation()->get(); if ($location != null) { $response->getHeaders() ->set("Location", $location); } parent::consolidate(); }
php
public function consolidate(Response $response) { $location = $response->getLocation()->get(); if ($location != null) { $response->getHeaders() ->set("Location", $location); } parent::consolidate(); }
[ "public", "function", "consolidate", "(", "Response", "$", "response", ")", "{", "$", "location", "=", "$", "response", "->", "getLocation", "(", ")", "->", "get", "(", ")", ";", "if", "(", "$", "location", "!=", "null", ")", "{", "$", "response", "->", "getHeaders", "(", ")", "->", "set", "(", "\"Location\"", ",", "$", "location", ")", ";", "}", "parent", "::", "consolidate", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Response/Preprocessor/Status201.php#L28-L39
fsi-open/datasource-bundle
DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php
FormFieldExtension.initOptions
public function initOptions(FieldTypeInterface $field) { $field->getOptionsResolver() ->setDefaults([ 'form_filter' => true, 'form_options' => [], 'form_from_options' => [], 'form_to_options' =>[] ]) ->setDefined([ 'form_type', 'form_order' ]) ->setAllowedTypes('form_filter', 'bool') ->setAllowedTypes('form_options', 'array') ->setAllowedTypes('form_from_options', 'array') ->setAllowedTypes('form_to_options', 'array') ->setAllowedTypes('form_order', 'integer') ->setAllowedTypes('form_type', 'string') ; }
php
public function initOptions(FieldTypeInterface $field) { $field->getOptionsResolver() ->setDefaults([ 'form_filter' => true, 'form_options' => [], 'form_from_options' => [], 'form_to_options' =>[] ]) ->setDefined([ 'form_type', 'form_order' ]) ->setAllowedTypes('form_filter', 'bool') ->setAllowedTypes('form_options', 'array') ->setAllowedTypes('form_from_options', 'array') ->setAllowedTypes('form_to_options', 'array') ->setAllowedTypes('form_order', 'integer') ->setAllowedTypes('form_type', 'string') ; }
[ "public", "function", "initOptions", "(", "FieldTypeInterface", "$", "field", ")", "{", "$", "field", "->", "getOptionsResolver", "(", ")", "->", "setDefaults", "(", "[", "'form_filter'", "=>", "true", ",", "'form_options'", "=>", "[", "]", ",", "'form_from_options'", "=>", "[", "]", ",", "'form_to_options'", "=>", "[", "]", "]", ")", "->", "setDefined", "(", "[", "'form_type'", ",", "'form_order'", "]", ")", "->", "setAllowedTypes", "(", "'form_filter'", ",", "'bool'", ")", "->", "setAllowedTypes", "(", "'form_options'", ",", "'array'", ")", "->", "setAllowedTypes", "(", "'form_from_options'", ",", "'array'", ")", "->", "setAllowedTypes", "(", "'form_to_options'", ",", "'array'", ")", "->", "setAllowedTypes", "(", "'form_order'", ",", "'integer'", ")", "->", "setAllowedTypes", "(", "'form_type'", ",", "'string'", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/fsi-open/datasource-bundle/blob/06964672c838af9f4125065e3a90b2df4e8aa077/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php#L77-L97
fsi-open/datasource-bundle
DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php
FormFieldExtension.postBuildView
public function postBuildView(FieldEvent\ViewEventArgs $event) { $field = $event->getField(); $view = $event->getView(); if ($form = $this->getForm($field)) { $view->setAttribute('form', $form->createView()); } }
php
public function postBuildView(FieldEvent\ViewEventArgs $event) { $field = $event->getField(); $view = $event->getView(); if ($form = $this->getForm($field)) { $view->setAttribute('form', $form->createView()); } }
[ "public", "function", "postBuildView", "(", "FieldEvent", "\\", "ViewEventArgs", "$", "event", ")", "{", "$", "field", "=", "$", "event", "->", "getField", "(", ")", ";", "$", "view", "=", "$", "event", "->", "getView", "(", ")", ";", "if", "(", "$", "form", "=", "$", "this", "->", "getForm", "(", "$", "field", ")", ")", "{", "$", "view", "->", "setAttribute", "(", "'form'", ",", "$", "form", "->", "createView", "(", ")", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/fsi-open/datasource-bundle/blob/06964672c838af9f4125065e3a90b2df4e8aa077/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php#L102-L110
fsi-open/datasource-bundle
DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php
FormFieldExtension.preBindParameter
public function preBindParameter(FieldEvent\ParameterEventArgs $event) { $field = $event->getField(); $form = $this->getForm($field); if ($form === null) { return; } $field_oid = spl_object_hash($field); $parameter = $event->getParameter(); if ($form->isSubmitted()) { $form = $this->getForm($field, true); } $datasourceName = $field->getDataSource() ? $field->getDataSource()->getName() : null; if (empty($datasourceName)) { return; } if ($this->hasParameterValue($parameter, $field)) { $this->parameters[$field_oid] = $this->getParameterValue($parameter, $field); $fieldForm = $form->get(DataSourceInterface::PARAMETER_FIELDS)->get($field->getName()); $fieldForm->submit($this->parameters[$field_oid]); $data = $fieldForm->getData(); if ($data !== null) { $this->setParameterValue($parameter, $field, $data); } else { $this->clearParameterValue($parameter, $field); } $event->setParameter($parameter); } }
php
public function preBindParameter(FieldEvent\ParameterEventArgs $event) { $field = $event->getField(); $form = $this->getForm($field); if ($form === null) { return; } $field_oid = spl_object_hash($field); $parameter = $event->getParameter(); if ($form->isSubmitted()) { $form = $this->getForm($field, true); } $datasourceName = $field->getDataSource() ? $field->getDataSource()->getName() : null; if (empty($datasourceName)) { return; } if ($this->hasParameterValue($parameter, $field)) { $this->parameters[$field_oid] = $this->getParameterValue($parameter, $field); $fieldForm = $form->get(DataSourceInterface::PARAMETER_FIELDS)->get($field->getName()); $fieldForm->submit($this->parameters[$field_oid]); $data = $fieldForm->getData(); if ($data !== null) { $this->setParameterValue($parameter, $field, $data); } else { $this->clearParameterValue($parameter, $field); } $event->setParameter($parameter); } }
[ "public", "function", "preBindParameter", "(", "FieldEvent", "\\", "ParameterEventArgs", "$", "event", ")", "{", "$", "field", "=", "$", "event", "->", "getField", "(", ")", ";", "$", "form", "=", "$", "this", "->", "getForm", "(", "$", "field", ")", ";", "if", "(", "$", "form", "===", "null", ")", "{", "return", ";", "}", "$", "field_oid", "=", "spl_object_hash", "(", "$", "field", ")", ";", "$", "parameter", "=", "$", "event", "->", "getParameter", "(", ")", ";", "if", "(", "$", "form", "->", "isSubmitted", "(", ")", ")", "{", "$", "form", "=", "$", "this", "->", "getForm", "(", "$", "field", ",", "true", ")", ";", "}", "$", "datasourceName", "=", "$", "field", "->", "getDataSource", "(", ")", "?", "$", "field", "->", "getDataSource", "(", ")", "->", "getName", "(", ")", ":", "null", ";", "if", "(", "empty", "(", "$", "datasourceName", ")", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "hasParameterValue", "(", "$", "parameter", ",", "$", "field", ")", ")", "{", "$", "this", "->", "parameters", "[", "$", "field_oid", "]", "=", "$", "this", "->", "getParameterValue", "(", "$", "parameter", ",", "$", "field", ")", ";", "$", "fieldForm", "=", "$", "form", "->", "get", "(", "DataSourceInterface", "::", "PARAMETER_FIELDS", ")", "->", "get", "(", "$", "field", "->", "getName", "(", ")", ")", ";", "$", "fieldForm", "->", "submit", "(", "$", "this", "->", "parameters", "[", "$", "field_oid", "]", ")", ";", "$", "data", "=", "$", "fieldForm", "->", "getData", "(", ")", ";", "if", "(", "$", "data", "!==", "null", ")", "{", "$", "this", "->", "setParameterValue", "(", "$", "parameter", ",", "$", "field", ",", "$", "data", ")", ";", "}", "else", "{", "$", "this", "->", "clearParameterValue", "(", "$", "parameter", ",", "$", "field", ")", ";", "}", "$", "event", "->", "setParameter", "(", "$", "parameter", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/fsi-open/datasource-bundle/blob/06964672c838af9f4125065e3a90b2df4e8aa077/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php#L115-L151
fsi-open/datasource-bundle
DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php
FormFieldExtension.preGetParameter
public function preGetParameter(FieldEvent\ParameterEventArgs $event) { $field = $event->getField(); $field_oid = spl_object_hash($field); if (isset($this->parameters[$field_oid])) { $parameters = []; $this->setParameterValue($parameters, $field, $this->parameters[$field_oid]); $event->setParameter($parameters); } }
php
public function preGetParameter(FieldEvent\ParameterEventArgs $event) { $field = $event->getField(); $field_oid = spl_object_hash($field); if (isset($this->parameters[$field_oid])) { $parameters = []; $this->setParameterValue($parameters, $field, $this->parameters[$field_oid]); $event->setParameter($parameters); } }
[ "public", "function", "preGetParameter", "(", "FieldEvent", "\\", "ParameterEventArgs", "$", "event", ")", "{", "$", "field", "=", "$", "event", "->", "getField", "(", ")", ";", "$", "field_oid", "=", "spl_object_hash", "(", "$", "field", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "parameters", "[", "$", "field_oid", "]", ")", ")", "{", "$", "parameters", "=", "[", "]", ";", "$", "this", "->", "setParameterValue", "(", "$", "parameters", ",", "$", "field", ",", "$", "this", "->", "parameters", "[", "$", "field_oid", "]", ")", ";", "$", "event", "->", "setParameter", "(", "$", "parameters", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/fsi-open/datasource-bundle/blob/06964672c838af9f4125065e3a90b2df4e8aa077/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php#L156-L166
fsi-open/datasource-bundle
DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php
FormFieldExtension.getForm
protected function getForm(FieldTypeInterface $field, $force = false) { $datasource = $field->getDataSource(); if ($datasource === null) { return null; } if (!$field->getOption('form_filter')) { return null; } $field_oid = spl_object_hash($field); if (isset($this->forms[$field_oid]) && !$force) { return $this->forms[$field_oid]; } $options = $field->getOption('form_options'); $options = array_merge($options, ['required' => false, 'auto_initialize' => false]); $form = $this->formFactory->createNamed( $datasource->getName(), $this->isFqcnFormTypePossible() ? 'Symfony\Component\Form\Extension\Core\Type\CollectionType' : 'collection', null, ['csrf_protection' => false] ); $fieldsForm = $this->formFactory->createNamed( DataSourceInterface::PARAMETER_FIELDS, $this->isFqcnFormTypePossible() ? 'Symfony\Component\Form\Extension\Core\Type\FormType' : 'form', null, ['auto_initialize' => false] ); switch ($field->getComparison()) { case 'between': $this->buildBetweenComparisonForm($fieldsForm, $field, $options); break; case 'isNull': $this->buildIsNullComparisonForm($fieldsForm, $field, $options); break; default: switch ($field->getType()) { case 'boolean': $this->buildBooleanForm($fieldsForm, $field, $options); break; default: $fieldsForm->add($field->getName(), $this->getFieldFormType($field), $options); } } $form->add($fieldsForm); $this->forms[$field_oid] = $form; return $this->forms[$field_oid]; }
php
protected function getForm(FieldTypeInterface $field, $force = false) { $datasource = $field->getDataSource(); if ($datasource === null) { return null; } if (!$field->getOption('form_filter')) { return null; } $field_oid = spl_object_hash($field); if (isset($this->forms[$field_oid]) && !$force) { return $this->forms[$field_oid]; } $options = $field->getOption('form_options'); $options = array_merge($options, ['required' => false, 'auto_initialize' => false]); $form = $this->formFactory->createNamed( $datasource->getName(), $this->isFqcnFormTypePossible() ? 'Symfony\Component\Form\Extension\Core\Type\CollectionType' : 'collection', null, ['csrf_protection' => false] ); $fieldsForm = $this->formFactory->createNamed( DataSourceInterface::PARAMETER_FIELDS, $this->isFqcnFormTypePossible() ? 'Symfony\Component\Form\Extension\Core\Type\FormType' : 'form', null, ['auto_initialize' => false] ); switch ($field->getComparison()) { case 'between': $this->buildBetweenComparisonForm($fieldsForm, $field, $options); break; case 'isNull': $this->buildIsNullComparisonForm($fieldsForm, $field, $options); break; default: switch ($field->getType()) { case 'boolean': $this->buildBooleanForm($fieldsForm, $field, $options); break; default: $fieldsForm->add($field->getName(), $this->getFieldFormType($field), $options); } } $form->add($fieldsForm); $this->forms[$field_oid] = $form; return $this->forms[$field_oid]; }
[ "protected", "function", "getForm", "(", "FieldTypeInterface", "$", "field", ",", "$", "force", "=", "false", ")", "{", "$", "datasource", "=", "$", "field", "->", "getDataSource", "(", ")", ";", "if", "(", "$", "datasource", "===", "null", ")", "{", "return", "null", ";", "}", "if", "(", "!", "$", "field", "->", "getOption", "(", "'form_filter'", ")", ")", "{", "return", "null", ";", "}", "$", "field_oid", "=", "spl_object_hash", "(", "$", "field", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "forms", "[", "$", "field_oid", "]", ")", "&&", "!", "$", "force", ")", "{", "return", "$", "this", "->", "forms", "[", "$", "field_oid", "]", ";", "}", "$", "options", "=", "$", "field", "->", "getOption", "(", "'form_options'", ")", ";", "$", "options", "=", "array_merge", "(", "$", "options", ",", "[", "'required'", "=>", "false", ",", "'auto_initialize'", "=>", "false", "]", ")", ";", "$", "form", "=", "$", "this", "->", "formFactory", "->", "createNamed", "(", "$", "datasource", "->", "getName", "(", ")", ",", "$", "this", "->", "isFqcnFormTypePossible", "(", ")", "?", "'Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType'", ":", "'collection'", ",", "null", ",", "[", "'csrf_protection'", "=>", "false", "]", ")", ";", "$", "fieldsForm", "=", "$", "this", "->", "formFactory", "->", "createNamed", "(", "DataSourceInterface", "::", "PARAMETER_FIELDS", ",", "$", "this", "->", "isFqcnFormTypePossible", "(", ")", "?", "'Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType'", ":", "'form'", ",", "null", ",", "[", "'auto_initialize'", "=>", "false", "]", ")", ";", "switch", "(", "$", "field", "->", "getComparison", "(", ")", ")", "{", "case", "'between'", ":", "$", "this", "->", "buildBetweenComparisonForm", "(", "$", "fieldsForm", ",", "$", "field", ",", "$", "options", ")", ";", "break", ";", "case", "'isNull'", ":", "$", "this", "->", "buildIsNullComparisonForm", "(", "$", "fieldsForm", ",", "$", "field", ",", "$", "options", ")", ";", "break", ";", "default", ":", "switch", "(", "$", "field", "->", "getType", "(", ")", ")", "{", "case", "'boolean'", ":", "$", "this", "->", "buildBooleanForm", "(", "$", "fieldsForm", ",", "$", "field", ",", "$", "options", ")", ";", "break", ";", "default", ":", "$", "fieldsForm", "->", "add", "(", "$", "field", "->", "getName", "(", ")", ",", "$", "this", "->", "getFieldFormType", "(", "$", "field", ")", ",", "$", "options", ")", ";", "}", "}", "$", "form", "->", "add", "(", "$", "fieldsForm", ")", ";", "$", "this", "->", "forms", "[", "$", "field_oid", "]", "=", "$", "form", ";", "return", "$", "this", "->", "forms", "[", "$", "field_oid", "]", ";", "}" ]
Builds form. @param FieldTypeInterface $field @param bool $force @return FormInterface|null
[ "Builds", "form", "." ]
train
https://github.com/fsi-open/datasource-bundle/blob/06964672c838af9f4125065e3a90b2df4e8aa077/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php#L175-L238
codezero-be/cookie
src/VanillaCookie.php
VanillaCookie.get
public function get($cookieName) { $cookieValue = $this->cookie->get($cookieName); return $this->decrypt($cookieValue); }
php
public function get($cookieName) { $cookieValue = $this->cookie->get($cookieName); return $this->decrypt($cookieValue); }
[ "public", "function", "get", "(", "$", "cookieName", ")", "{", "$", "cookieValue", "=", "$", "this", "->", "cookie", "->", "get", "(", "$", "cookieName", ")", ";", "return", "$", "this", "->", "decrypt", "(", "$", "cookieValue", ")", ";", "}" ]
Get the value of a cookie @param string $cookieName @return null|string
[ "Get", "the", "value", "of", "a", "cookie" ]
train
https://github.com/codezero-be/cookie/blob/5300089c9dc7bd48c9865d53c3aed8bd513da6d2/src/VanillaCookie.php#L40-L45
codezero-be/cookie
src/VanillaCookie.php
VanillaCookie.store
public function store($cookieName, $cookieValue, $minutes = 60, $path = "/", $domain = null, $secure = true, $httponly = true) { return $this->cookie->set( $cookieName, $this->encrypt($cookieValue), $this->calculateExpirationTime($minutes), $path, $domain, $secure, $httponly ); }
php
public function store($cookieName, $cookieValue, $minutes = 60, $path = "/", $domain = null, $secure = true, $httponly = true) { return $this->cookie->set( $cookieName, $this->encrypt($cookieValue), $this->calculateExpirationTime($minutes), $path, $domain, $secure, $httponly ); }
[ "public", "function", "store", "(", "$", "cookieName", ",", "$", "cookieValue", ",", "$", "minutes", "=", "60", ",", "$", "path", "=", "\"/\"", ",", "$", "domain", "=", "null", ",", "$", "secure", "=", "true", ",", "$", "httponly", "=", "true", ")", "{", "return", "$", "this", "->", "cookie", "->", "set", "(", "$", "cookieName", ",", "$", "this", "->", "encrypt", "(", "$", "cookieValue", ")", ",", "$", "this", "->", "calculateExpirationTime", "(", "$", "minutes", ")", ",", "$", "path", ",", "$", "domain", ",", "$", "secure", ",", "$", "httponly", ")", ";", "}" ]
Store a cookie @param string $cookieName @param string $cookieValue @param int $minutes @param string $path @param string $domain @param bool $secure @param bool $httponly @return bool
[ "Store", "a", "cookie" ]
train
https://github.com/codezero-be/cookie/blob/5300089c9dc7bd48c9865d53c3aed8bd513da6d2/src/VanillaCookie.php#L60-L71
codezero-be/cookie
src/VanillaCookie.php
VanillaCookie.decrypt
private function decrypt($cookieValue) { if ($this->encrypter && ! empty($cookieValue)) { return $this->encrypter->decrypt($cookieValue); } return $cookieValue; }
php
private function decrypt($cookieValue) { if ($this->encrypter && ! empty($cookieValue)) { return $this->encrypter->decrypt($cookieValue); } return $cookieValue; }
[ "private", "function", "decrypt", "(", "$", "cookieValue", ")", "{", "if", "(", "$", "this", "->", "encrypter", "&&", "!", "empty", "(", "$", "cookieValue", ")", ")", "{", "return", "$", "this", "->", "encrypter", "->", "decrypt", "(", "$", "cookieValue", ")", ";", "}", "return", "$", "cookieValue", ";", "}" ]
Decrypt a cookie @param string $cookieValue @return string
[ "Decrypt", "a", "cookie" ]
train
https://github.com/codezero-be/cookie/blob/5300089c9dc7bd48c9865d53c3aed8bd513da6d2/src/VanillaCookie.php#L135-L142
kiwiz/ecl
src/ExpressionLanguage.php
ExpressionLanguage.evaluate
public function evaluate($expression, $values=[]) { if(is_array($values)) { return parent::evaluate($expression, $values); } else { return $this->parse($expression, $values->getKeys())->getNodes()->evaluate($this->functions, $values); } }
php
public function evaluate($expression, $values=[]) { if(is_array($values)) { return parent::evaluate($expression, $values); } else { return $this->parse($expression, $values->getKeys())->getNodes()->evaluate($this->functions, $values); } }
[ "public", "function", "evaluate", "(", "$", "expression", ",", "$", "values", "=", "[", "]", ")", "{", "if", "(", "is_array", "(", "$", "values", ")", ")", "{", "return", "parent", "::", "evaluate", "(", "$", "expression", ",", "$", "values", ")", ";", "}", "else", "{", "return", "$", "this", "->", "parse", "(", "$", "expression", ",", "$", "values", "->", "getKeys", "(", ")", ")", "->", "getNodes", "(", ")", "->", "evaluate", "(", "$", "this", "->", "functions", ",", "$", "values", ")", ";", "}", "}" ]
Evaluate an expression. Overridden to allow passing in a SymbolTable. @param \Symfony\Component\ExpressionLanguage\Expression|string $expression @param SymbolTable|array|\ArrayAccess $values @return mixed
[ "Evaluate", "an", "expression", ".", "Overridden", "to", "allow", "passing", "in", "a", "SymbolTable", "." ]
train
https://github.com/kiwiz/ecl/blob/6536dd2a4c1905a08cf718bdbef56a22f0e9b488/src/ExpressionLanguage.php#L53-L59
Wonail/wocenter
libs/IpLocation.php
IpLocation.getstring
private function getstring($data = "") { $char = fread($this->fp, 1); while (ord($char) > 0) { // 字符串按照C格式保存,以\0结束 $data .= $char; // 将读取的字符连接到给定字符串之后 $char = fread($this->fp, 1); } return $data; }
php
private function getstring($data = "") { $char = fread($this->fp, 1); while (ord($char) > 0) { // 字符串按照C格式保存,以\0结束 $data .= $char; // 将读取的字符连接到给定字符串之后 $char = fread($this->fp, 1); } return $data; }
[ "private", "function", "getstring", "(", "$", "data", "=", "\"\"", ")", "{", "$", "char", "=", "fread", "(", "$", "this", "->", "fp", ",", "1", ")", ";", "while", "(", "ord", "(", "$", "char", ")", ">", "0", ")", "{", "// 字符串按照C格式保存,以\\0结束\r", "$", "data", ".=", "$", "char", ";", "// 将读取的字符连接到给定字符串之后\r", "$", "char", "=", "fread", "(", "$", "this", "->", "fp", ",", "1", ")", ";", "}", "return", "$", "data", ";", "}" ]
返回读取的字符串 @access private @param string $data @return string
[ "返回读取的字符串" ]
train
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/libs/IpLocation.php#L108-L117
Wonail/wocenter
libs/IpLocation.php
IpLocation.getarea
private function getarea() { $byte = fread($this->fp, 1); // 标志字节 switch (ord($byte)) { case 0: // 没有区域信息 $area = ""; break; case 1: case 2: // 标志字节为1或2,表示区域信息被重定向 fseek($this->fp, $this->getlong3()); $area = $this->getstring(); break; default: // 否则,表示区域信息没有被重定向 $area = $this->getstring($byte); break; } return $area; }
php
private function getarea() { $byte = fread($this->fp, 1); // 标志字节 switch (ord($byte)) { case 0: // 没有区域信息 $area = ""; break; case 1: case 2: // 标志字节为1或2,表示区域信息被重定向 fseek($this->fp, $this->getlong3()); $area = $this->getstring(); break; default: // 否则,表示区域信息没有被重定向 $area = $this->getstring($byte); break; } return $area; }
[ "private", "function", "getarea", "(", ")", "{", "$", "byte", "=", "fread", "(", "$", "this", "->", "fp", ",", "1", ")", ";", "// 标志字节\r", "switch", "(", "ord", "(", "$", "byte", ")", ")", "{", "case", "0", ":", "// 没有区域信息\r", "$", "area", "=", "\"\"", ";", "break", ";", "case", "1", ":", "case", "2", ":", "// 标志字节为1或2,表示区域信息被重定向\r", "fseek", "(", "$", "this", "->", "fp", ",", "$", "this", "->", "getlong3", "(", ")", ")", ";", "$", "area", "=", "$", "this", "->", "getstring", "(", ")", ";", "break", ";", "default", ":", "// 否则,表示区域信息没有被重定向\r", "$", "area", "=", "$", "this", "->", "getstring", "(", "$", "byte", ")", ";", "break", ";", "}", "return", "$", "area", ";", "}" ]
返回地区信息 @access private @return string
[ "返回地区信息" ]
train
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/libs/IpLocation.php#L125-L143
Wonail/wocenter
libs/IpLocation.php
IpLocation.getlocation
public function getlocation($ip = '') { if (!$this->fp) return null; // 如果数据文件没有被正确打开,则直接返回空 if (empty($ip)) $ip = Utils::getClientIp(); $location['ip'] = gethostbyname($ip); // 将输入的域名转化为IP地址 $ip = $this->packip($location['ip']); // 将输入的IP地址转化为可比较的IP地址 // 不合法的IP地址会被转化为255.255.255.255 // 对分搜索 $l = 0; // 搜索的下边界 $u = $this->totalip; // 搜索的上边界 $findip = $this->lastip; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息) while ($l <= $u) { // 当上边界小于下边界时,查找失败 $i = floor(($l + $u) / 2); // 计算近似中间记录 fseek($this->fp, $this->firstip + $i * 7); $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址 // strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式 // 以便用于比较,后面相同。 if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时 $u = $i - 1; // 将搜索的上边界修改为中间记录减一 } else { fseek($this->fp, $this->getlong3()); $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址 if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时 $l = $i + 1; // 将搜索的下边界修改为中间记录加一 } else { // 用户的IP在中间记录的IP范围内时 $findip = $this->firstip + $i * 7; break; // 则表示找到结果,退出循环 } } } //获取查找到的IP地理位置信息 fseek($this->fp, $findip); $location['beginip'] = long2ip($this->getlong()); // 用户IP所在范围的开始地址 $offset = $this->getlong3(); fseek($this->fp, $offset); $location['endip'] = long2ip($this->getlong()); // 用户IP所在范围的结束地址 $byte = fread($this->fp, 1); // 标志字节 switch (ord($byte)) { case 1: // 标志字节为1,表示国家和区域信息都被同时重定向 $countryOffset = $this->getlong3(); // 重定向地址 fseek($this->fp, $countryOffset); $byte = fread($this->fp, 1); // 标志字节 switch (ord($byte)) { case 2: // 标志字节为2,表示国家信息又被重定向 fseek($this->fp, $this->getlong3()); $location['country'] = $this->getstring(); fseek($this->fp, $countryOffset + 4); $location['area'] = $this->getarea(); break; default: // 否则,表示国家信息没有被重定向 $location['country'] = $this->getstring($byte); $location['area'] = $this->getarea(); break; } break; case 2: // 标志字节为2,表示国家信息被重定向 fseek($this->fp, $this->getlong3()); $location['country'] = $this->getstring(); fseek($this->fp, $offset + 8); $location['area'] = $this->getarea(); break; default: // 否则,表示国家信息没有被重定向 $location['country'] = $this->getstring($byte); $location['area'] = $this->getarea(); break; } if (trim($location['country']) == 'CZ88.NET') { // CZ88.NET表示没有有效信息 $location['country'] = '未知'; } if (trim($location['area']) == 'CZ88.NET') { $location['area'] = ''; } return $location; }
php
public function getlocation($ip = '') { if (!$this->fp) return null; // 如果数据文件没有被正确打开,则直接返回空 if (empty($ip)) $ip = Utils::getClientIp(); $location['ip'] = gethostbyname($ip); // 将输入的域名转化为IP地址 $ip = $this->packip($location['ip']); // 将输入的IP地址转化为可比较的IP地址 // 不合法的IP地址会被转化为255.255.255.255 // 对分搜索 $l = 0; // 搜索的下边界 $u = $this->totalip; // 搜索的上边界 $findip = $this->lastip; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息) while ($l <= $u) { // 当上边界小于下边界时,查找失败 $i = floor(($l + $u) / 2); // 计算近似中间记录 fseek($this->fp, $this->firstip + $i * 7); $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址 // strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式 // 以便用于比较,后面相同。 if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时 $u = $i - 1; // 将搜索的上边界修改为中间记录减一 } else { fseek($this->fp, $this->getlong3()); $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址 if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时 $l = $i + 1; // 将搜索的下边界修改为中间记录加一 } else { // 用户的IP在中间记录的IP范围内时 $findip = $this->firstip + $i * 7; break; // 则表示找到结果,退出循环 } } } //获取查找到的IP地理位置信息 fseek($this->fp, $findip); $location['beginip'] = long2ip($this->getlong()); // 用户IP所在范围的开始地址 $offset = $this->getlong3(); fseek($this->fp, $offset); $location['endip'] = long2ip($this->getlong()); // 用户IP所在范围的结束地址 $byte = fread($this->fp, 1); // 标志字节 switch (ord($byte)) { case 1: // 标志字节为1,表示国家和区域信息都被同时重定向 $countryOffset = $this->getlong3(); // 重定向地址 fseek($this->fp, $countryOffset); $byte = fread($this->fp, 1); // 标志字节 switch (ord($byte)) { case 2: // 标志字节为2,表示国家信息又被重定向 fseek($this->fp, $this->getlong3()); $location['country'] = $this->getstring(); fseek($this->fp, $countryOffset + 4); $location['area'] = $this->getarea(); break; default: // 否则,表示国家信息没有被重定向 $location['country'] = $this->getstring($byte); $location['area'] = $this->getarea(); break; } break; case 2: // 标志字节为2,表示国家信息被重定向 fseek($this->fp, $this->getlong3()); $location['country'] = $this->getstring(); fseek($this->fp, $offset + 8); $location['area'] = $this->getarea(); break; default: // 否则,表示国家信息没有被重定向 $location['country'] = $this->getstring($byte); $location['area'] = $this->getarea(); break; } if (trim($location['country']) == 'CZ88.NET') { // CZ88.NET表示没有有效信息 $location['country'] = '未知'; } if (trim($location['area']) == 'CZ88.NET') { $location['area'] = ''; } return $location; }
[ "public", "function", "getlocation", "(", "$", "ip", "=", "''", ")", "{", "if", "(", "!", "$", "this", "->", "fp", ")", "return", "null", ";", "// 如果数据文件没有被正确打开,则直接返回空\r", "if", "(", "empty", "(", "$", "ip", ")", ")", "$", "ip", "=", "Utils", "::", "getClientIp", "(", ")", ";", "$", "location", "[", "'ip'", "]", "=", "gethostbyname", "(", "$", "ip", ")", ";", "// 将输入的域名转化为IP地址\r", "$", "ip", "=", "$", "this", "->", "packip", "(", "$", "location", "[", "'ip'", "]", ")", ";", "// 将输入的IP地址转化为可比较的IP地址\r", "// 不合法的IP地址会被转化为255.255.255.255\r", "// 对分搜索\r", "$", "l", "=", "0", ";", "// 搜索的下边界\r", "$", "u", "=", "$", "this", "->", "totalip", ";", "// 搜索的上边界\r", "$", "findip", "=", "$", "this", "->", "lastip", ";", "// 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息)\r", "while", "(", "$", "l", "<=", "$", "u", ")", "{", "// 当上边界小于下边界时,查找失败\r", "$", "i", "=", "floor", "(", "(", "$", "l", "+", "$", "u", ")", "/", "2", ")", ";", "// 计算近似中间记录\r", "fseek", "(", "$", "this", "->", "fp", ",", "$", "this", "->", "firstip", "+", "$", "i", "*", "7", ")", ";", "$", "beginip", "=", "strrev", "(", "fread", "(", "$", "this", "->", "fp", ",", "4", ")", ")", ";", "// 获取中间记录的开始IP地址\r", "// strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式\r", "// 以便用于比较,后面相同。\r", "if", "(", "$", "ip", "<", "$", "beginip", ")", "{", "// 用户的IP小于中间记录的开始IP地址时\r", "$", "u", "=", "$", "i", "-", "1", ";", "// 将搜索的上边界修改为中间记录减一\r", "}", "else", "{", "fseek", "(", "$", "this", "->", "fp", ",", "$", "this", "->", "getlong3", "(", ")", ")", ";", "$", "endip", "=", "strrev", "(", "fread", "(", "$", "this", "->", "fp", ",", "4", ")", ")", ";", "// 获取中间记录的结束IP地址\r", "if", "(", "$", "ip", ">", "$", "endip", ")", "{", "// 用户的IP大于中间记录的结束IP地址时\r", "$", "l", "=", "$", "i", "+", "1", ";", "// 将搜索的下边界修改为中间记录加一\r", "}", "else", "{", "// 用户的IP在中间记录的IP范围内时\r", "$", "findip", "=", "$", "this", "->", "firstip", "+", "$", "i", "*", "7", ";", "break", ";", "// 则表示找到结果,退出循环\r", "}", "}", "}", "//获取查找到的IP地理位置信息\r", "fseek", "(", "$", "this", "->", "fp", ",", "$", "findip", ")", ";", "$", "location", "[", "'beginip'", "]", "=", "long2ip", "(", "$", "this", "->", "getlong", "(", ")", ")", ";", "// 用户IP所在范围的开始地址\r", "$", "offset", "=", "$", "this", "->", "getlong3", "(", ")", ";", "fseek", "(", "$", "this", "->", "fp", ",", "$", "offset", ")", ";", "$", "location", "[", "'endip'", "]", "=", "long2ip", "(", "$", "this", "->", "getlong", "(", ")", ")", ";", "// 用户IP所在范围的结束地址\r", "$", "byte", "=", "fread", "(", "$", "this", "->", "fp", ",", "1", ")", ";", "// 标志字节\r", "switch", "(", "ord", "(", "$", "byte", ")", ")", "{", "case", "1", ":", "// 标志字节为1,表示国家和区域信息都被同时重定向\r", "$", "countryOffset", "=", "$", "this", "->", "getlong3", "(", ")", ";", "// 重定向地址\r", "fseek", "(", "$", "this", "->", "fp", ",", "$", "countryOffset", ")", ";", "$", "byte", "=", "fread", "(", "$", "this", "->", "fp", ",", "1", ")", ";", "// 标志字节\r", "switch", "(", "ord", "(", "$", "byte", ")", ")", "{", "case", "2", ":", "// 标志字节为2,表示国家信息又被重定向\r", "fseek", "(", "$", "this", "->", "fp", ",", "$", "this", "->", "getlong3", "(", ")", ")", ";", "$", "location", "[", "'country'", "]", "=", "$", "this", "->", "getstring", "(", ")", ";", "fseek", "(", "$", "this", "->", "fp", ",", "$", "countryOffset", "+", "4", ")", ";", "$", "location", "[", "'area'", "]", "=", "$", "this", "->", "getarea", "(", ")", ";", "break", ";", "default", ":", "// 否则,表示国家信息没有被重定向\r", "$", "location", "[", "'country'", "]", "=", "$", "this", "->", "getstring", "(", "$", "byte", ")", ";", "$", "location", "[", "'area'", "]", "=", "$", "this", "->", "getarea", "(", ")", ";", "break", ";", "}", "break", ";", "case", "2", ":", "// 标志字节为2,表示国家信息被重定向\r", "fseek", "(", "$", "this", "->", "fp", ",", "$", "this", "->", "getlong3", "(", ")", ")", ";", "$", "location", "[", "'country'", "]", "=", "$", "this", "->", "getstring", "(", ")", ";", "fseek", "(", "$", "this", "->", "fp", ",", "$", "offset", "+", "8", ")", ";", "$", "location", "[", "'area'", "]", "=", "$", "this", "->", "getarea", "(", ")", ";", "break", ";", "default", ":", "// 否则,表示国家信息没有被重定向\r", "$", "location", "[", "'country'", "]", "=", "$", "this", "->", "getstring", "(", "$", "byte", ")", ";", "$", "location", "[", "'area'", "]", "=", "$", "this", "->", "getarea", "(", ")", ";", "break", ";", "}", "if", "(", "trim", "(", "$", "location", "[", "'country'", "]", ")", "==", "'CZ88.NET'", ")", "{", "// CZ88.NET表示没有有效信息\r", "$", "location", "[", "'country'", "]", "=", "'未知';\r", "", "}", "if", "(", "trim", "(", "$", "location", "[", "'area'", "]", ")", "==", "'CZ88.NET'", ")", "{", "$", "location", "[", "'area'", "]", "=", "''", ";", "}", "return", "$", "location", ";", "}" ]
根据所给 IP 地址或域名返回所在地区信息 @access public @param string $ip @return array
[ "根据所给", "IP", "地址或域名返回所在地区信息" ]
train
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/libs/IpLocation.php#L154-L231
tjbp/laravel-verify-emails
src/Foundation/Auth/VerifiesEmails.php
VerifiesEmails.resend
public function resend(Request $request) { $user = Auth::user(); if ($user->getVerified()) { return redirect()->back(); } $response = VerifyEmail::sendVerificationLink($user, function (Message $message) use ($user) { $message->subject($user->getVerifyEmailSubject()); }); switch ($response) { case VerifyEmail::VERIFY_LINK_SENT: return redirect()->back()->with('status', trans($response)); } }
php
public function resend(Request $request) { $user = Auth::user(); if ($user->getVerified()) { return redirect()->back(); } $response = VerifyEmail::sendVerificationLink($user, function (Message $message) use ($user) { $message->subject($user->getVerifyEmailSubject()); }); switch ($response) { case VerifyEmail::VERIFY_LINK_SENT: return redirect()->back()->with('status', trans($response)); } }
[ "public", "function", "resend", "(", "Request", "$", "request", ")", "{", "$", "user", "=", "Auth", "::", "user", "(", ")", ";", "if", "(", "$", "user", "->", "getVerified", "(", ")", ")", "{", "return", "redirect", "(", ")", "->", "back", "(", ")", ";", "}", "$", "response", "=", "VerifyEmail", "::", "sendVerificationLink", "(", "$", "user", ",", "function", "(", "Message", "$", "message", ")", "use", "(", "$", "user", ")", "{", "$", "message", "->", "subject", "(", "$", "user", "->", "getVerifyEmailSubject", "(", ")", ")", ";", "}", ")", ";", "switch", "(", "$", "response", ")", "{", "case", "VerifyEmail", "::", "VERIFY_LINK_SENT", ":", "return", "redirect", "(", ")", "->", "back", "(", ")", "->", "with", "(", "'status'", ",", "trans", "(", "$", "response", ")", ")", ";", "}", "}" ]
Send another verification email. @param \Illuminate\Http\Request $request @return \Illuminate\Http\Response
[ "Send", "another", "verification", "email", "." ]
train
https://github.com/tjbp/laravel-verify-emails/blob/1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6/src/Foundation/Auth/VerifiesEmails.php#L28-L44
tjbp/laravel-verify-emails
src/Foundation/Auth/VerifiesEmails.php
VerifiesEmails.verify
public function verify($token) { $response = VerifyEmail::verify(Auth::user(), $token); switch ($response) { case VerifyEmail::EMAIL_VERIFIED: return redirect($this->redirectPath())->with('status', trans($response)); default: return redirect()->back() ->withErrors(['email' => trans($response)]); } }
php
public function verify($token) { $response = VerifyEmail::verify(Auth::user(), $token); switch ($response) { case VerifyEmail::EMAIL_VERIFIED: return redirect($this->redirectPath())->with('status', trans($response)); default: return redirect()->back() ->withErrors(['email' => trans($response)]); } }
[ "public", "function", "verify", "(", "$", "token", ")", "{", "$", "response", "=", "VerifyEmail", "::", "verify", "(", "Auth", "::", "user", "(", ")", ",", "$", "token", ")", ";", "switch", "(", "$", "response", ")", "{", "case", "VerifyEmail", "::", "EMAIL_VERIFIED", ":", "return", "redirect", "(", "$", "this", "->", "redirectPath", "(", ")", ")", "->", "with", "(", "'status'", ",", "trans", "(", "$", "response", ")", ")", ";", "default", ":", "return", "redirect", "(", ")", "->", "back", "(", ")", "->", "withErrors", "(", "[", "'email'", "=>", "trans", "(", "$", "response", ")", "]", ")", ";", "}", "}" ]
Attempt to verify a user. @param string $token @return \Illuminate\Http\Response
[ "Attempt", "to", "verify", "a", "user", "." ]
train
https://github.com/tjbp/laravel-verify-emails/blob/1e2ac10a696c10f2fdf0d7de6c3388d549bc07c6/src/Foundation/Auth/VerifiesEmails.php#L52-L64
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addColumn
public function addColumn(Column\Column $column) { // Join column to the table $column->setTable($this); // Add renderer to column if it didn't has one if (!$column->hasRenderer()) { $column->setRenderer($this->getRenderer()); } $this->columns[$column->getName()] = $column; return $this; }
php
public function addColumn(Column\Column $column) { // Join column to the table $column->setTable($this); // Add renderer to column if it didn't has one if (!$column->hasRenderer()) { $column->setRenderer($this->getRenderer()); } $this->columns[$column->getName()] = $column; return $this; }
[ "public", "function", "addColumn", "(", "Column", "\\", "Column", "$", "column", ")", "{", "// Join column to the table", "$", "column", "->", "setTable", "(", "$", "this", ")", ";", "// Add renderer to column if it didn't has one", "if", "(", "!", "$", "column", "->", "hasRenderer", "(", ")", ")", "{", "$", "column", "->", "setRenderer", "(", "$", "this", "->", "getRenderer", "(", ")", ")", ";", "}", "$", "this", "->", "columns", "[", "$", "column", "->", "getName", "(", ")", "]", "=", "$", "column", ";", "return", "$", "this", ";", "}" ]
Add a single column to the column container @param Column\Column $column @return $this
[ "Add", "a", "single", "column", "to", "the", "column", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L52-L65
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.removeColumn
public function removeColumn($name) { if (isset($this->columns[$name])){ unset($this->columns[$name]); } return $this; }
php
public function removeColumn($name) { if (isset($this->columns[$name])){ unset($this->columns[$name]); } return $this; }
[ "public", "function", "removeColumn", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "columns", "[", "$", "name", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "columns", "[", "$", "name", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Remove $name columns from the $columns container @param $name @return $this
[ "Remove", "$name", "columns", "from", "the", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L73-L81
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.getColumn
public function getColumn($name) { // check all the columns foreach ($this->columns as $index => $column) { if ($name == $index) { return $column; } // recursivity if (method_exists($column, 'hasColumn')) { if ($column->hasColumn($name)) { return $column->getColumn($name); } } } return null; }
php
public function getColumn($name) { // check all the columns foreach ($this->columns as $index => $column) { if ($name == $index) { return $column; } // recursivity if (method_exists($column, 'hasColumn')) { if ($column->hasColumn($name)) { return $column->getColumn($name); } } } return null; }
[ "public", "function", "getColumn", "(", "$", "name", ")", "{", "// check all the columns", "foreach", "(", "$", "this", "->", "columns", "as", "$", "index", "=>", "$", "column", ")", "{", "if", "(", "$", "name", "==", "$", "index", ")", "{", "return", "$", "column", ";", "}", "// recursivity", "if", "(", "method_exists", "(", "$", "column", ",", "'hasColumn'", ")", ")", "{", "if", "(", "$", "column", "->", "hasColumn", "(", "$", "name", ")", ")", "{", "return", "$", "column", "->", "getColumn", "(", "$", "name", ")", ";", "}", "}", "}", "return", "null", ";", "}" ]
Return the $name column from $column container @param $name @return Column\Column $column
[ "Return", "the", "$name", "column", "from", "$column", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L101-L119
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.getColumnByIndex
public function getColumnByIndex($index) { $keys = array_keys($this->columns); if (empty($keys[$index]) || empty($column = $this->columns[$keys[$index]])) { throw new \InvalidArgumentException('Table don\'t have a column index : ' . $index); } return $column; }
php
public function getColumnByIndex($index) { $keys = array_keys($this->columns); if (empty($keys[$index]) || empty($column = $this->columns[$keys[$index]])) { throw new \InvalidArgumentException('Table don\'t have a column index : ' . $index); } return $column; }
[ "public", "function", "getColumnByIndex", "(", "$", "index", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "this", "->", "columns", ")", ";", "if", "(", "empty", "(", "$", "keys", "[", "$", "index", "]", ")", "||", "empty", "(", "$", "column", "=", "$", "this", "->", "columns", "[", "$", "keys", "[", "$", "index", "]", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Table don\\'t have a column index : '", ".", "$", "index", ")", ";", "}", "return", "$", "column", ";", "}" ]
Return the column from his index @return Column\Column $column
[ "Return", "the", "column", "from", "his", "index" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L126-L134
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addText
public function addText($name, $label = '', $attr = []) { $c = new Column\Text($name, $label, $attr); $this->addColumn($c); return $c; }
php
public function addText($name, $label = '', $attr = []) { $c = new Column\Text($name, $label, $attr); $this->addColumn($c); return $c; }
[ "public", "function", "addText", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "attr", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Text", "(", "$", "name", ",", "$", "label", ",", "$", "attr", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add Text column to $columns container @param $name @param string $label @param array $attr @return \FrenchFrogs\Table\Column\Text
[ "Add", "Text", "column", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L145-L150
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addNumber
public function addNumber($name, $label = '', $decimal = 2) { $c = new Column\Number($name, $label, $decimal); $this->addColumn($c); return $c; }
php
public function addNumber($name, $label = '', $decimal = 2) { $c = new Column\Number($name, $label, $decimal); $this->addColumn($c); return $c; }
[ "public", "function", "addNumber", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "decimal", "=", "2", ")", "{", "$", "c", "=", "new", "Column", "\\", "Number", "(", "$", "name", ",", "$", "label", ",", "$", "decimal", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add number column to $columns container @param $name @param string $label @param int $decimal @return \FrenchFrogs\Table\Column\Number
[ "Add", "number", "column", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L160-L165
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addCode
public function addCode($name, $label = '', $attr = []) { $c = new Column\Code($name, $label, $attr); $this->addColumn($c); return $c; }
php
public function addCode($name, $label = '', $attr = []) { $c = new Column\Code($name, $label, $attr); $this->addColumn($c); return $c; }
[ "public", "function", "addCode", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "attr", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Code", "(", "$", "name", ",", "$", "label", ",", "$", "attr", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add Code column to $columns container @param $name @param string $label @param array $attr @return \FrenchFrogs\Table\Column\Code
[ "Add", "Code", "column", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L175-L180
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addPre
public function addPre($name, $label = '', $attr = []) { $c = new Column\Pre($name, $label, $attr); $this->addColumn($c); return $c; }
php
public function addPre($name, $label = '', $attr = []) { $c = new Column\Pre($name, $label, $attr); $this->addColumn($c); return $c; }
[ "public", "function", "addPre", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "attr", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Pre", "(", "$", "name", ",", "$", "label", ",", "$", "attr", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add Pre column to $columns container @param $name @param string $label @param array $attr @return \FrenchFrogs\Table\Column\Code
[ "Add", "Pre", "column", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L190-L195
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addDate
public function addDate($name, $label = '', $format = null, $attr = []) { $c = new Column\Date($name, $label, $format, $attr); $this->addColumn($c); return $c; }
php
public function addDate($name, $label = '', $format = null, $attr = []) { $c = new Column\Date($name, $label, $format, $attr); $this->addColumn($c); return $c; }
[ "public", "function", "addDate", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "format", "=", "null", ",", "$", "attr", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Date", "(", "$", "name", ",", "$", "label", ",", "$", "format", ",", "$", "attr", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add Date column to $columns container @param $name @param string $label @param array $attr @return \FrenchFrogs\Table\Column\Date
[ "Add", "Date", "column", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L221-L226
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addDatetime
public function addDatetime($name, $label = '', $format = null, $attr = []) { $c = new Column\Datetime($name, $label, $format, $attr); $this->addColumn($c); return $c; }
php
public function addDatetime($name, $label = '', $format = null, $attr = []) { $c = new Column\Datetime($name, $label, $format, $attr); $this->addColumn($c); return $c; }
[ "public", "function", "addDatetime", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "format", "=", "null", ",", "$", "attr", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Datetime", "(", "$", "name", ",", "$", "label", ",", "$", "format", ",", "$", "attr", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add Datetime column to $columns container @param $name @param string $label @param array $attr @return \FrenchFrogs\Table\Column\Datetime
[ "Add", "Datetime", "column", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L236-L241
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addBoolean
public function addBoolean($name, $label = '', $attr = []) { $c = new Column\Boolean($name, $label, $attr); $this->addColumn($c); return $c; }
php
public function addBoolean($name, $label = '', $attr = []) { $c = new Column\Boolean($name, $label, $attr); $this->addColumn($c); return $c; }
[ "public", "function", "addBoolean", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "attr", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Boolean", "(", "$", "name", ",", "$", "label", ",", "$", "attr", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add Boolean column to $columns container @param $name @param string $label @param array $attr @return \FrenchFrogs\Table\Column\Text
[ "Add", "Boolean", "column", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L252-L259
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addRemoteBoolean
public function addRemoteBoolean($name, $label = '', $function = null) { $c = new Column\RemoteBoolean($name, $label, $function); $this->addColumn($c); return $c; }
php
public function addRemoteBoolean($name, $label = '', $function = null) { $c = new Column\RemoteBoolean($name, $label, $function); $this->addColumn($c); return $c; }
[ "public", "function", "addRemoteBoolean", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "function", "=", "null", ")", "{", "$", "c", "=", "new", "Column", "\\", "RemoteBoolean", "(", "$", "name", ",", "$", "label", ",", "$", "function", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add boolean switch @param $name @param string $label @return \FrenchFrogs\Table\Column\RemoteBoolean
[ "Add", "boolean", "switch" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L268-L274
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addRemoteText
public function addRemoteText($name, $label = '', $function = null) { $c = new Column\RemoteText($name, $label, $function); $this->addColumn($c); return $c; }
php
public function addRemoteText($name, $label = '', $function = null) { $c = new Column\RemoteText($name, $label, $function); $this->addColumn($c); return $c; }
[ "public", "function", "addRemoteText", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "function", "=", "null", ")", "{", "$", "c", "=", "new", "Column", "\\", "RemoteText", "(", "$", "name", ",", "$", "label", ",", "$", "function", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add remote text @param $name @param string $label @return \FrenchFrogs\Table\Column\RemoteText
[ "Add", "remote", "text" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L284-L290
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addRemoteSelect
public function addRemoteSelect($name, $label = '', $index = null, $option = [], $function = null) { $c = new Column\RemoteSelect($name, $label, $index, $option, $function); $this->addColumn($c); return $c; }
php
public function addRemoteSelect($name, $label = '', $index = null, $option = [], $function = null) { $c = new Column\RemoteSelect($name, $label, $index, $option, $function); $this->addColumn($c); return $c; }
[ "public", "function", "addRemoteSelect", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "index", "=", "null", ",", "$", "option", "=", "[", "]", ",", "$", "function", "=", "null", ")", "{", "$", "c", "=", "new", "Column", "\\", "RemoteSelect", "(", "$", "name", ",", "$", "label", ",", "$", "index", ",", "$", "option", ",", "$", "function", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add remote select @param $name @param string $label @return \FrenchFrogs\Table\Column\RemoteSelect
[ "Add", "remote", "select" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L299-L305
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addIcon
public function addIcon($name, $label = '', $mapping = []) { $c = new Column\Icon($name, $label, $mapping); $this->addColumn($c); return $c; }
php
public function addIcon($name, $label = '', $mapping = []) { $c = new Column\Icon($name, $label, $mapping); $this->addColumn($c); return $c; }
[ "public", "function", "addIcon", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "mapping", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Icon", "(", "$", "name", ",", "$", "label", ",", "$", "mapping", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add Boolean column to $columns container @param $name @param string $label @param array $attr @return \FrenchFrogs\Table\Column\Text
[ "Add", "Boolean", "column", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L315-L322
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addLink
public function addLink($name, $label = '', $link = '#', $binds = [], $attr = [] ) { $c = new Column\Link($name, $label, $link, $binds, $attr); $this->addColumn($c); return $c; }
php
public function addLink($name, $label = '', $link = '#', $binds = [], $attr = [] ) { $c = new Column\Link($name, $label, $link, $binds, $attr); $this->addColumn($c); return $c; }
[ "public", "function", "addLink", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "link", "=", "'#'", ",", "$", "binds", "=", "[", "]", ",", "$", "attr", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Link", "(", "$", "name", ",", "$", "label", ",", "$", "link", ",", "$", "binds", ",", "$", "attr", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add Link columns to $columns container @param $name @param string $label @param string $link @param array $binds @param array $attr @return \FrenchFrogs\Table\Column\Link
[ "Add", "Link", "columns", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L335-L341
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addMedia
public function addMedia($name, $label, $link = '#', $binds = [], $width = 320, $height = 180) { $c = new Column\Media($name, $label, $link, $binds, $width, $height); $this->addColumn($c); return $c; }
php
public function addMedia($name, $label, $link = '#', $binds = [], $width = 320, $height = 180) { $c = new Column\Media($name, $label, $link, $binds, $width, $height); $this->addColumn($c); return $c; }
[ "public", "function", "addMedia", "(", "$", "name", ",", "$", "label", ",", "$", "link", "=", "'#'", ",", "$", "binds", "=", "[", "]", ",", "$", "width", "=", "320", ",", "$", "height", "=", "180", ")", "{", "$", "c", "=", "new", "Column", "\\", "Media", "(", "$", "name", ",", "$", "label", ",", "$", "link", ",", "$", "binds", ",", "$", "width", ",", "$", "height", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add Link columns to $columns container @param $name @param string $label @param string $link @param array $binds @param array $attr @return \FrenchFrogs\Table\Column\Link
[ "Add", "Link", "columns", "to", "$columns", "container" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L353-L359
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addButton
public function addButton($name, $label = '%s', $link = '#', $binds = [], $attr = [] ) { $c = new Column\Button($name, $label, $link, $binds, $attr); $c->setOptionAsDefault(); $this->addColumn($c); return $c; }
php
public function addButton($name, $label = '%s', $link = '#', $binds = [], $attr = [] ) { $c = new Column\Button($name, $label, $link, $binds, $attr); $c->setOptionAsDefault(); $this->addColumn($c); return $c; }
[ "public", "function", "addButton", "(", "$", "name", ",", "$", "label", "=", "'%s'", ",", "$", "link", "=", "'#'", ",", "$", "binds", "=", "[", "]", ",", "$", "attr", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Button", "(", "$", "name", ",", "$", "label", ",", "$", "link", ",", "$", "binds", ",", "$", "attr", ")", ";", "$", "c", "->", "setOptionAsDefault", "(", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add as Button Column @param $name @param string $label @param string $link @param array $binds @param array $attr @return \FrenchFrogs\Table\Column\Button
[ "Add", "as", "Button", "Column" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L372-L379
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addButtonRemote
public function addButtonRemote($name, $label = '%s', $link = '#', $binds = [], $method = 'post' ) { return $this->addButton($name, $label, $link, $binds)->enableRemote($method); }
php
public function addButtonRemote($name, $label = '%s', $link = '#', $binds = [], $method = 'post' ) { return $this->addButton($name, $label, $link, $binds)->enableRemote($method); }
[ "public", "function", "addButtonRemote", "(", "$", "name", ",", "$", "label", "=", "'%s'", ",", "$", "link", "=", "'#'", ",", "$", "binds", "=", "[", "]", ",", "$", "method", "=", "'post'", ")", "{", "return", "$", "this", "->", "addButton", "(", "$", "name", ",", "$", "label", ",", "$", "link", ",", "$", "binds", ")", "->", "enableRemote", "(", "$", "method", ")", ";", "}" ]
Add remote button as column @param $name @param string $label @param string $link @param array $binds @param array $attr @return \FrenchFrogs\Table\Column\Button
[ "Add", "remote", "button", "as", "column" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L391-L394
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addButtonCallback
public function addButtonCallback($name, $label = '%s', $link = '#', $binds = [], $method = 'post' ) { return $this->addButton($name, $label, $link, $binds)->enableCallback($method); }
php
public function addButtonCallback($name, $label = '%s', $link = '#', $binds = [], $method = 'post' ) { return $this->addButton($name, $label, $link, $binds)->enableCallback($method); }
[ "public", "function", "addButtonCallback", "(", "$", "name", ",", "$", "label", "=", "'%s'", ",", "$", "link", "=", "'#'", ",", "$", "binds", "=", "[", "]", ",", "$", "method", "=", "'post'", ")", "{", "return", "$", "this", "->", "addButton", "(", "$", "name", ",", "$", "label", ",", "$", "link", ",", "$", "binds", ")", "->", "enableCallback", "(", "$", "method", ")", ";", "}" ]
Add remote button as column @param $name @param string $label @param string $link @param array $binds @param array $attr @return \FrenchFrogs\Table\Column\Button
[ "Add", "remote", "button", "as", "column" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L406-L409
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addButtonEdit
public function addButtonEdit($link = '#', $binds = [], $is_remote = true, $method = 'post') { $c = new Column\Button(configurator()->get('button.edit.name'), configurator()->get('button.edit.label'), $link, $binds); $c->setOptionAsPrimary(); $c->icon(configurator()->get('button.edit.icon')); if ($is_remote) { $c->enableRemote($method); } $this->addColumn($c); return $c; }
php
public function addButtonEdit($link = '#', $binds = [], $is_remote = true, $method = 'post') { $c = new Column\Button(configurator()->get('button.edit.name'), configurator()->get('button.edit.label'), $link, $binds); $c->setOptionAsPrimary(); $c->icon(configurator()->get('button.edit.icon')); if ($is_remote) { $c->enableRemote($method); } $this->addColumn($c); return $c; }
[ "public", "function", "addButtonEdit", "(", "$", "link", "=", "'#'", ",", "$", "binds", "=", "[", "]", ",", "$", "is_remote", "=", "true", ",", "$", "method", "=", "'post'", ")", "{", "$", "c", "=", "new", "Column", "\\", "Button", "(", "configurator", "(", ")", "->", "get", "(", "'button.edit.name'", ")", ",", "configurator", "(", ")", "->", "get", "(", "'button.edit.label'", ")", ",", "$", "link", ",", "$", "binds", ")", ";", "$", "c", "->", "setOptionAsPrimary", "(", ")", ";", "$", "c", "->", "icon", "(", "configurator", "(", ")", "->", "get", "(", "'button.edit.icon'", ")", ")", ";", "if", "(", "$", "is_remote", ")", "{", "$", "c", "->", "enableRemote", "(", "$", "method", ")", ";", "}", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add default edit button @param string $link @param array $binds @param array $attr @return \FrenchFrogs\Table\Column\Button
[ "Add", "default", "edit", "button" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L420-L433
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addButtonDelete
public function addButtonDelete($link = '#', $binds = [], $is_remote = true, $method = 'delete') { $c = new Column\Button(configurator()->get('button.delete.name'), configurator()->get('button.delete.label'), $link, $binds); $c->setOptionAsDanger(); $c->icon(configurator()->get('button.delete.icon')); if ($is_remote) { $c->enableRemote($method); } $this->addColumn($c); return $c; }
php
public function addButtonDelete($link = '#', $binds = [], $is_remote = true, $method = 'delete') { $c = new Column\Button(configurator()->get('button.delete.name'), configurator()->get('button.delete.label'), $link, $binds); $c->setOptionAsDanger(); $c->icon(configurator()->get('button.delete.icon')); if ($is_remote) { $c->enableRemote($method); } $this->addColumn($c); return $c; }
[ "public", "function", "addButtonDelete", "(", "$", "link", "=", "'#'", ",", "$", "binds", "=", "[", "]", ",", "$", "is_remote", "=", "true", ",", "$", "method", "=", "'delete'", ")", "{", "$", "c", "=", "new", "Column", "\\", "Button", "(", "configurator", "(", ")", "->", "get", "(", "'button.delete.name'", ")", ",", "configurator", "(", ")", "->", "get", "(", "'button.delete.label'", ")", ",", "$", "link", ",", "$", "binds", ")", ";", "$", "c", "->", "setOptionAsDanger", "(", ")", ";", "$", "c", "->", "icon", "(", "configurator", "(", ")", "->", "get", "(", "'button.delete.icon'", ")", ")", ";", "if", "(", "$", "is_remote", ")", "{", "$", "c", "->", "enableRemote", "(", "$", "method", ")", ";", "}", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add default delete button @param string $link @param array $binds @param array $attr @return \FrenchFrogs\Table\Column\Button
[ "Add", "default", "delete", "button" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L443-L453
FrenchFrogs/framework
src/Table/Table/Columns.php
Columns.addContainer
public function addContainer($name, $label = '', $attr = []) { $c = new Column\Container($name, $label, $attr); $this->addColumn($c); return $c; }
php
public function addContainer($name, $label = '', $attr = []) { $c = new Column\Container($name, $label, $attr); $this->addColumn($c); return $c; }
[ "public", "function", "addContainer", "(", "$", "name", ",", "$", "label", "=", "''", ",", "$", "attr", "=", "[", "]", ")", "{", "$", "c", "=", "new", "Column", "\\", "Container", "(", "$", "name", ",", "$", "label", ",", "$", "attr", ")", ";", "$", "this", "->", "addColumn", "(", "$", "c", ")", ";", "return", "$", "c", ";", "}" ]
Add a container columns @param $name @param string $label @param array $attr @return \FrenchFrogs\Table\Column\Container
[ "Add", "a", "container", "columns" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Columns.php#L465-L470
jpuck/color-mixer
src/Mixer.php
Mixer.addColor
public function addColor($color) { if ( ! $color instanceof Color ) { $color = new Color($color); } $this->colors []= $color; }
php
public function addColor($color) { if ( ! $color instanceof Color ) { $color = new Color($color); } $this->colors []= $color; }
[ "public", "function", "addColor", "(", "$", "color", ")", "{", "if", "(", "!", "$", "color", "instanceof", "Color", ")", "{", "$", "color", "=", "new", "Color", "(", "$", "color", ")", ";", "}", "$", "this", "->", "colors", "[", "]", "=", "$", "color", ";", "}" ]
Adds a color to the Mixer. @param mixed Color object or string @return null
[ "Adds", "a", "color", "to", "the", "Mixer", "." ]
train
https://github.com/jpuck/color-mixer/blob/cea01c3082a921a35e00ae0a287c795d9fd73ada/src/Mixer.php#L28-L35
jpuck/color-mixer
src/Mixer.php
Mixer.mix
public function mix() : Color { foreach ($this->colors as $color) { $colors = $color->dec(); $reds []= $colors[0]; $greens[]= $colors[1]; $blues []= $colors[2]; } $red = dechex( round(array_sum($reds) / count($reds) ) ); $green = dechex( round(array_sum($greens)/ count($greens)) ); $blue = dechex( round(array_sum($blues) / count($blues) ) ); // pad single-digit hexadecimals with leading zero foreach ([&$red, &$green, &$blue] as &$color) { if (strlen($color) === 1) { $color = "0$color"; } } return new Color($red.$green.$blue); }
php
public function mix() : Color { foreach ($this->colors as $color) { $colors = $color->dec(); $reds []= $colors[0]; $greens[]= $colors[1]; $blues []= $colors[2]; } $red = dechex( round(array_sum($reds) / count($reds) ) ); $green = dechex( round(array_sum($greens)/ count($greens)) ); $blue = dechex( round(array_sum($blues) / count($blues) ) ); // pad single-digit hexadecimals with leading zero foreach ([&$red, &$green, &$blue] as &$color) { if (strlen($color) === 1) { $color = "0$color"; } } return new Color($red.$green.$blue); }
[ "public", "function", "mix", "(", ")", ":", "Color", "{", "foreach", "(", "$", "this", "->", "colors", "as", "$", "color", ")", "{", "$", "colors", "=", "$", "color", "->", "dec", "(", ")", ";", "$", "reds", "[", "]", "=", "$", "colors", "[", "0", "]", ";", "$", "greens", "[", "]", "=", "$", "colors", "[", "1", "]", ";", "$", "blues", "[", "]", "=", "$", "colors", "[", "2", "]", ";", "}", "$", "red", "=", "dechex", "(", "round", "(", "array_sum", "(", "$", "reds", ")", "/", "count", "(", "$", "reds", ")", ")", ")", ";", "$", "green", "=", "dechex", "(", "round", "(", "array_sum", "(", "$", "greens", ")", "/", "count", "(", "$", "greens", ")", ")", ")", ";", "$", "blue", "=", "dechex", "(", "round", "(", "array_sum", "(", "$", "blues", ")", "/", "count", "(", "$", "blues", ")", ")", ")", ";", "// pad single-digit hexadecimals with leading zero", "foreach", "(", "[", "&", "$", "red", ",", "&", "$", "green", ",", "&", "$", "blue", "]", "as", "&", "$", "color", ")", "{", "if", "(", "strlen", "(", "$", "color", ")", "===", "1", ")", "{", "$", "color", "=", "\"0$color\"", ";", "}", "}", "return", "new", "Color", "(", "$", "red", ".", "$", "green", ".", "$", "blue", ")", ";", "}" ]
Get the mixed color. @return Color Returns a new Color object from the Mixer.
[ "Get", "the", "mixed", "color", "." ]
train
https://github.com/jpuck/color-mixer/blob/cea01c3082a921a35e00ae0a287c795d9fd73ada/src/Mixer.php#L52-L73
FrenchFrogs/framework
src/Table/Table/Table.php
Table.extractRows
protected function extractRows() { $source = $this->source; // Laravel query builder case if( $this->isSourceQueryBuilder()) { /** @var $source \Illuminate\Database\Query\Builder */ $count = query(raw("({$source->toSql()}) as a"), [raw('COUNT(*) as _num_rows')], $source->getConnection()->getName())->mergeBindings($source)->first(); $this->itemsTotal = isset($count['_num_rows']) ? $count['_num_rows'] : null; $source = $source->skip($this->getItemsOffset())->take($this->getItemsPerPage())->get(); $source = new \ArrayIterator($source); // Array case } elseif(is_array($source)) { $this->itemsTotal = count($source); $source = array_slice($source, $this->getItemsOffset(), $this->getItemsPerPage()); $source = new \ArrayIterator($source); } /**@var $source \Iterator */ if (!($source instanceof \Iterator)) { throw new \InvalidArgumentException("Source must be an array or an Iterator"); } if (!is_null($source)) { $this->setRows($source); if ($this->hasJsonField()) { $this->extractJson(); } } return $this; }
php
protected function extractRows() { $source = $this->source; // Laravel query builder case if( $this->isSourceQueryBuilder()) { /** @var $source \Illuminate\Database\Query\Builder */ $count = query(raw("({$source->toSql()}) as a"), [raw('COUNT(*) as _num_rows')], $source->getConnection()->getName())->mergeBindings($source)->first(); $this->itemsTotal = isset($count['_num_rows']) ? $count['_num_rows'] : null; $source = $source->skip($this->getItemsOffset())->take($this->getItemsPerPage())->get(); $source = new \ArrayIterator($source); // Array case } elseif(is_array($source)) { $this->itemsTotal = count($source); $source = array_slice($source, $this->getItemsOffset(), $this->getItemsPerPage()); $source = new \ArrayIterator($source); } /**@var $source \Iterator */ if (!($source instanceof \Iterator)) { throw new \InvalidArgumentException("Source must be an array or an Iterator"); } if (!is_null($source)) { $this->setRows($source); if ($this->hasJsonField()) { $this->extractJson(); } } return $this; }
[ "protected", "function", "extractRows", "(", ")", "{", "$", "source", "=", "$", "this", "->", "source", ";", "// Laravel query builder case", "if", "(", "$", "this", "->", "isSourceQueryBuilder", "(", ")", ")", "{", "/** @var $source \\Illuminate\\Database\\Query\\Builder */", "$", "count", "=", "query", "(", "raw", "(", "\"({$source->toSql()}) as a\"", ")", ",", "[", "raw", "(", "'COUNT(*) as _num_rows'", ")", "]", ",", "$", "source", "->", "getConnection", "(", ")", "->", "getName", "(", ")", ")", "->", "mergeBindings", "(", "$", "source", ")", "->", "first", "(", ")", ";", "$", "this", "->", "itemsTotal", "=", "isset", "(", "$", "count", "[", "'_num_rows'", "]", ")", "?", "$", "count", "[", "'_num_rows'", "]", ":", "null", ";", "$", "source", "=", "$", "source", "->", "skip", "(", "$", "this", "->", "getItemsOffset", "(", ")", ")", "->", "take", "(", "$", "this", "->", "getItemsPerPage", "(", ")", ")", "->", "get", "(", ")", ";", "$", "source", "=", "new", "\\", "ArrayIterator", "(", "$", "source", ")", ";", "// Array case", "}", "elseif", "(", "is_array", "(", "$", "source", ")", ")", "{", "$", "this", "->", "itemsTotal", "=", "count", "(", "$", "source", ")", ";", "$", "source", "=", "array_slice", "(", "$", "source", ",", "$", "this", "->", "getItemsOffset", "(", ")", ",", "$", "this", "->", "getItemsPerPage", "(", ")", ")", ";", "$", "source", "=", "new", "\\", "ArrayIterator", "(", "$", "source", ")", ";", "}", "/**@var $source \\Iterator */", "if", "(", "!", "(", "$", "source", "instanceof", "\\", "Iterator", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Source must be an array or an Iterator\"", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "source", ")", ")", "{", "$", "this", "->", "setRows", "(", "$", "source", ")", ";", "if", "(", "$", "this", "->", "hasJsonField", "(", ")", ")", "{", "$", "this", "->", "extractJson", "(", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Extract rows from $source attribute @return $this
[ "Extract", "rows", "from", "$source", "attribute" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Table.php#L218-L254
FrenchFrogs/framework
src/Table/Table/Table.php
Table.isSourceQueryBuilder
public function isSourceQueryBuilder() { return is_object($this->getSource()) && get_class($this->getSource()) == \Illuminate\Database\Query\Builder::class; }
php
public function isSourceQueryBuilder() { return is_object($this->getSource()) && get_class($this->getSource()) == \Illuminate\Database\Query\Builder::class; }
[ "public", "function", "isSourceQueryBuilder", "(", ")", "{", "return", "is_object", "(", "$", "this", "->", "getSource", "(", ")", ")", "&&", "get_class", "(", "$", "this", "->", "getSource", "(", ")", ")", "==", "\\", "Illuminate", "\\", "Database", "\\", "Query", "\\", "Builder", "::", "class", ";", "}" ]
Return true if the source is an instance of \Illuminate\Database\Query\Builder @return bool
[ "Return", "true", "if", "the", "source", "is", "an", "instance", "of", "\\", "Illuminate", "\\", "Database", "\\", "Query", "\\", "Builder" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Table.php#L261-L264
FrenchFrogs/framework
src/Table/Table/Table.php
Table.removeJsonField
public function removeJsonField($field) { $i = array_search($field, $this->jsonField); if ($i !== false) { unset($this->jsonField[$i]); } return $this; }
php
public function removeJsonField($field) { $i = array_search($field, $this->jsonField); if ($i !== false) { unset($this->jsonField[$i]); } return $this; }
[ "public", "function", "removeJsonField", "(", "$", "field", ")", "{", "$", "i", "=", "array_search", "(", "$", "field", ",", "$", "this", "->", "jsonField", ")", ";", "if", "(", "$", "i", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "jsonField", "[", "$", "i", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Remove $field from $jsonField @param $field @return $this
[ "Remove", "$field", "from", "$jsonField" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Table.php#L359-L369
FrenchFrogs/framework
src/Table/Table/Table.php
Table.extractJson
public function extractJson() { foreach($this->getRows() as &$row) { foreach($this->getJsonFields() as $field) { if (isset($row[$field])) { $data = json_decode($row[$field], JSON_OBJECT_AS_ARRAY); foreach((array) $data as $k => $v) { $row[sprintf('_%s__%s', $field, $k)] = $v; } } } } return $this; }
php
public function extractJson() { foreach($this->getRows() as &$row) { foreach($this->getJsonFields() as $field) { if (isset($row[$field])) { $data = json_decode($row[$field], JSON_OBJECT_AS_ARRAY); foreach((array) $data as $k => $v) { $row[sprintf('_%s__%s', $field, $k)] = $v; } } } } return $this; }
[ "public", "function", "extractJson", "(", ")", "{", "foreach", "(", "$", "this", "->", "getRows", "(", ")", "as", "&", "$", "row", ")", "{", "foreach", "(", "$", "this", "->", "getJsonFields", "(", ")", "as", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "row", "[", "$", "field", "]", ")", ")", "{", "$", "data", "=", "json_decode", "(", "$", "row", "[", "$", "field", "]", ",", "JSON_OBJECT_AS_ARRAY", ")", ";", "foreach", "(", "(", "array", ")", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "row", "[", "sprintf", "(", "'_%s__%s'", ",", "$", "field", ",", "$", "k", ")", "]", "=", "$", "v", ";", "}", "}", "}", "}", "return", "$", "this", ";", "}" ]
Extract json data @return $this
[ "Extract", "json", "data" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Table/Table.php#L409-L425
WellCommerce/CoreBundle
DependencyInjection/Compiler/DataSetTransformerPass.php
DataSetTransformerPass.process
public function process(ContainerBuilder $container) { $tag = 'dataset.transformer'; $interface = DataSetTransformerInterface::class; $definition = $container->getDefinition('dataset.transformer.collection'); foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) { $itemDefinition = $container->getDefinition($id); $refClass = new \ReflectionClass($itemDefinition->getClass()); if (!$refClass->implementsInterface($interface)) { throw new \InvalidArgumentException( sprintf('DataSetTransformer "%s" tagged with "%s" must implement interface "%s".', $id, $tag, $interface) ); } $definition->addMethodCall('add', [ $attributes[0]['alias'], new Reference($id) ]); } }
php
public function process(ContainerBuilder $container) { $tag = 'dataset.transformer'; $interface = DataSetTransformerInterface::class; $definition = $container->getDefinition('dataset.transformer.collection'); foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) { $itemDefinition = $container->getDefinition($id); $refClass = new \ReflectionClass($itemDefinition->getClass()); if (!$refClass->implementsInterface($interface)) { throw new \InvalidArgumentException( sprintf('DataSetTransformer "%s" tagged with "%s" must implement interface "%s".', $id, $tag, $interface) ); } $definition->addMethodCall('add', [ $attributes[0]['alias'], new Reference($id) ]); } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "tag", "=", "'dataset.transformer'", ";", "$", "interface", "=", "DataSetTransformerInterface", "::", "class", ";", "$", "definition", "=", "$", "container", "->", "getDefinition", "(", "'dataset.transformer.collection'", ")", ";", "foreach", "(", "$", "container", "->", "findTaggedServiceIds", "(", "$", "tag", ")", "as", "$", "id", "=>", "$", "attributes", ")", "{", "$", "itemDefinition", "=", "$", "container", "->", "getDefinition", "(", "$", "id", ")", ";", "$", "refClass", "=", "new", "\\", "ReflectionClass", "(", "$", "itemDefinition", "->", "getClass", "(", ")", ")", ";", "if", "(", "!", "$", "refClass", "->", "implementsInterface", "(", "$", "interface", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'DataSetTransformer \"%s\" tagged with \"%s\" must implement interface \"%s\".'", ",", "$", "id", ",", "$", "tag", ",", "$", "interface", ")", ")", ";", "}", "$", "definition", "->", "addMethodCall", "(", "'add'", ",", "[", "$", "attributes", "[", "0", "]", "[", "'alias'", "]", ",", "new", "Reference", "(", "$", "id", ")", "]", ")", ";", "}", "}" ]
Processes the container @param ContainerBuilder $container
[ "Processes", "the", "container" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/DependencyInjection/Compiler/DataSetTransformerPass.php#L32-L53
axelitus/php-base
src/BigFloat.php
BigFloat.isEven
public static function isEven($value, $scale = null) { if (!static::is($value)) { throw new \InvalidArgumentException( "The \$value parameter must be of type float (or string representing a big float)." ); } return static::equals(static::mod($value, 2.0, $scale), 0.0, $scale); }
php
public static function isEven($value, $scale = null) { if (!static::is($value)) { throw new \InvalidArgumentException( "The \$value parameter must be of type float (or string representing a big float)." ); } return static::equals(static::mod($value, 2.0, $scale), 0.0, $scale); }
[ "public", "static", "function", "isEven", "(", "$", "value", ",", "$", "scale", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "value", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$value parameter must be of type float (or string representing a big float).\"", ")", ";", "}", "return", "static", "::", "equals", "(", "static", "::", "mod", "(", "$", "value", ",", "2.0", ",", "$", "scale", ")", ",", "0.0", ",", "$", "scale", ")", ";", "}" ]
Tests if the given value is even. @param float|string $value The value to test. @param null|int $scale The scale to use for BCMath functions. If null is given the value set by {@link bcscale()} is used. @throws \InvalidArgumentException @return bool Returns true if the given value is even, false otherwise.
[ "Tests", "if", "the", "given", "value", "is", "even", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L53-L62
axelitus/php-base
src/BigFloat.php
BigFloat.isOdd
public static function isOdd($value, $scale = null) { if (!static::is($value)) { throw new \InvalidArgumentException( "The \$value parameter must be of type float (or string representing a big float)." ); } return static::equals(static::abs(static::mod($value, 2.0, $scale)), 1.0, $scale); }
php
public static function isOdd($value, $scale = null) { if (!static::is($value)) { throw new \InvalidArgumentException( "The \$value parameter must be of type float (or string representing a big float)." ); } return static::equals(static::abs(static::mod($value, 2.0, $scale)), 1.0, $scale); }
[ "public", "static", "function", "isOdd", "(", "$", "value", ",", "$", "scale", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "value", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$value parameter must be of type float (or string representing a big float).\"", ")", ";", "}", "return", "static", "::", "equals", "(", "static", "::", "abs", "(", "static", "::", "mod", "(", "$", "value", ",", "2.0", ",", "$", "scale", ")", ")", ",", "1.0", ",", "$", "scale", ")", ";", "}" ]
Tests if the given value is odd. @param float|string $value The value to test. @param null|int $scale The scale to use for BCMath functions. If null is given the value set by {@link bcscale()} is used. @throws \InvalidArgumentException @return bool Returns true if the given value is odd, false otherwise.
[ "Tests", "if", "the", "given", "value", "is", "odd", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L74-L83
axelitus/php-base
src/BigFloat.php
BigFloat.inRange
public static function inRange($value, $lower, $upper, $lowerExclusive = false, $upperExclusive = false) { if (!static::is($value) || !static::is($lower) || !static::is($upper)) { throw new \InvalidArgumentException( "The \$value, \$lower and \$upper parameters must be of type float" . " (or string representing a big float)." ); } $lowerLimit = min($lower, $upper); if (!(($lowerExclusive) ? $lowerLimit < $value : $lowerLimit <= $value)) { return false; } $upperLimit = max($lower, $upper); if (!(($upperExclusive) ? $upperLimit > $value : $upperLimit >= $value)) { return false; } return true; }
php
public static function inRange($value, $lower, $upper, $lowerExclusive = false, $upperExclusive = false) { if (!static::is($value) || !static::is($lower) || !static::is($upper)) { throw new \InvalidArgumentException( "The \$value, \$lower and \$upper parameters must be of type float" . " (or string representing a big float)." ); } $lowerLimit = min($lower, $upper); if (!(($lowerExclusive) ? $lowerLimit < $value : $lowerLimit <= $value)) { return false; } $upperLimit = max($lower, $upper); if (!(($upperExclusive) ? $upperLimit > $value : $upperLimit >= $value)) { return false; } return true; }
[ "public", "static", "function", "inRange", "(", "$", "value", ",", "$", "lower", ",", "$", "upper", ",", "$", "lowerExclusive", "=", "false", ",", "$", "upperExclusive", "=", "false", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "value", ")", "||", "!", "static", "::", "is", "(", "$", "lower", ")", "||", "!", "static", "::", "is", "(", "$", "upper", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$value, \\$lower and \\$upper parameters must be of type float\"", ".", "\" (or string representing a big float).\"", ")", ";", "}", "$", "lowerLimit", "=", "min", "(", "$", "lower", ",", "$", "upper", ")", ";", "if", "(", "!", "(", "(", "$", "lowerExclusive", ")", "?", "$", "lowerLimit", "<", "$", "value", ":", "$", "lowerLimit", "<=", "$", "value", ")", ")", "{", "return", "false", ";", "}", "$", "upperLimit", "=", "max", "(", "$", "lower", ",", "$", "upper", ")", ";", "if", "(", "!", "(", "(", "$", "upperExclusive", ")", "?", "$", "upperLimit", ">", "$", "value", ":", "$", "upperLimit", ">=", "$", "value", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Tests if an integer is in a range. Tests if a value is in a range. The function will correct the limits if inverted. The tested range can be set to have its lower and upper limits inclusive (bounds closed) or exclusive (bounds opened) using the $lowerExclusive and $upperExclusive parameters (all possible variations: ]a,b[ -or- ]a,b] -or- [a,b[ -or- [a,b]). @param float|string $value The value to test in range. @param float|string $lower The range's lower limit. @param float|string $upper The range's upper limit. @param bool $lowerExclusive Whether the lower bound is exclusive. @param bool $upperExclusive Whether the upper bound is exclusive. @return bool Whether the value is in the given range given the bounds configurations. @throws \InvalidArgumentException @SuppressWarnings(PHPMD.BooleanArgumentFlag)
[ "Tests", "if", "an", "integer", "is", "in", "a", "range", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L178-L198
axelitus/php-base
src/BigFloat.php
BigFloat.abs
public static function abs($float) { if (!static::is($float)) { throw new \InvalidArgumentException( "The \$float parameter must be of type float (or string representing a big float)." ); } if (Float::is($float)) { return Float::abs($float); } else { return Str::replace($float, '-', ''); } }
php
public static function abs($float) { if (!static::is($float)) { throw new \InvalidArgumentException( "The \$float parameter must be of type float (or string representing a big float)." ); } if (Float::is($float)) { return Float::abs($float); } else { return Str::replace($float, '-', ''); } }
[ "public", "static", "function", "abs", "(", "$", "float", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "float", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$float parameter must be of type float (or string representing a big float).\"", ")", ";", "}", "if", "(", "Float", "::", "is", "(", "$", "float", ")", ")", "{", "return", "Float", "::", "abs", "(", "$", "float", ")", ";", "}", "else", "{", "return", "Str", "::", "replace", "(", "$", "float", ",", "'-'", ",", "''", ")", ";", "}", "}" ]
Gets the absolute value of the given float. @param int|string $float The number to get the absolute value of. @return int|string Returns the absolute value of the given float.
[ "Gets", "the", "absolute", "value", "of", "the", "given", "float", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L245-L258
axelitus/php-base
src/BigFloat.php
BigFloat.add
public static function add($float1, $float2, $scale = null) { if (!static::is($float1) || !static::is($float2)) { throw new \InvalidArgumentException( "The \$float1 and \$float2 parameters must be of type float (or string representing a big float)." ); } if (is_float($float1) && is_float($float2)) { return ($float1 + $float2); } elseif (function_exists('bcadd')) { return BigNum::toFloat(((is_null($scale)) ? bcadd($float1, $float2) : bcadd($float1, $float2, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
php
public static function add($float1, $float2, $scale = null) { if (!static::is($float1) || !static::is($float2)) { throw new \InvalidArgumentException( "The \$float1 and \$float2 parameters must be of type float (or string representing a big float)." ); } if (is_float($float1) && is_float($float2)) { return ($float1 + $float2); } elseif (function_exists('bcadd')) { return BigNum::toFloat(((is_null($scale)) ? bcadd($float1, $float2) : bcadd($float1, $float2, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
[ "public", "static", "function", "add", "(", "$", "float1", ",", "$", "float2", ",", "$", "scale", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "float1", ")", "||", "!", "static", "::", "is", "(", "$", "float2", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$float1 and \\$float2 parameters must be of type float (or string representing a big float).\"", ")", ";", "}", "if", "(", "is_float", "(", "$", "float1", ")", "&&", "is_float", "(", "$", "float2", ")", ")", "{", "return", "(", "$", "float1", "+", "$", "float2", ")", ";", "}", "elseif", "(", "function_exists", "(", "'bcadd'", ")", ")", "{", "return", "BigNum", "::", "toFloat", "(", "(", "(", "is_null", "(", "$", "scale", ")", ")", "?", "bcadd", "(", "$", "float1", ",", "$", "float2", ")", ":", "bcadd", "(", "$", "float1", ",", "$", "float2", ",", "$", "scale", ")", ")", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "\"The BCMath library is not available.\"", ")", ";", "// @codeCoverageIgnore", "}" ]
Adds a number to another number. @param float|string $float1 The left operand. @param float|string $float2 The right operand. @param null|int $scale The scale to use for BCMath functions. If null is given the value set by {@link bcscale()} is used. @return float|string The result of the operation. @throws \InvalidArgumentException @throws \RuntimeException
[ "Adds", "a", "number", "to", "another", "number", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L272-L289
axelitus/php-base
src/BigFloat.php
BigFloat.sub
public static function sub($float1, $float2, $scale = null) { if (!static::is($float1) || !static::is($float2)) { throw new \InvalidArgumentException( "The \$float1 and \$float2 parameters must be of type float (or string representing a big float)." ); } if (is_float($float1) && is_float($float2)) { return ($float1 - $float2); } elseif (function_exists('bcsub')) { return BigNum::toFloat(((is_null($scale)) ? bcsub($float1, $float2) : bcsub($float1, $float2, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
php
public static function sub($float1, $float2, $scale = null) { if (!static::is($float1) || !static::is($float2)) { throw new \InvalidArgumentException( "The \$float1 and \$float2 parameters must be of type float (or string representing a big float)." ); } if (is_float($float1) && is_float($float2)) { return ($float1 - $float2); } elseif (function_exists('bcsub')) { return BigNum::toFloat(((is_null($scale)) ? bcsub($float1, $float2) : bcsub($float1, $float2, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
[ "public", "static", "function", "sub", "(", "$", "float1", ",", "$", "float2", ",", "$", "scale", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "float1", ")", "||", "!", "static", "::", "is", "(", "$", "float2", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$float1 and \\$float2 parameters must be of type float (or string representing a big float).\"", ")", ";", "}", "if", "(", "is_float", "(", "$", "float1", ")", "&&", "is_float", "(", "$", "float2", ")", ")", "{", "return", "(", "$", "float1", "-", "$", "float2", ")", ";", "}", "elseif", "(", "function_exists", "(", "'bcsub'", ")", ")", "{", "return", "BigNum", "::", "toFloat", "(", "(", "(", "is_null", "(", "$", "scale", ")", ")", "?", "bcsub", "(", "$", "float1", ",", "$", "float2", ")", ":", "bcsub", "(", "$", "float1", ",", "$", "float2", ",", "$", "scale", ")", ")", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "\"The BCMath library is not available.\"", ")", ";", "// @codeCoverageIgnore", "}" ]
Subtracts a number from another number. @param float|string $float1 The left operand. @param float|string $float2 The right operand. @param null|int $scale The scale to use for BCMath functions. If null is given the value set by {@link bcscale()} is used. @return float|string The result of the operation. @throws \InvalidArgumentException @throws \RuntimeException
[ "Subtracts", "a", "number", "from", "another", "number", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L303-L320
axelitus/php-base
src/BigFloat.php
BigFloat.mul
public static function mul($float1, $float2, $scale = null) { if (!static::is($float1) || !static::is($float2)) { throw new \InvalidArgumentException( "The \$float1 and \$float2 parameters must be of type float (or string representing a big float)." ); } if (is_float($float1) && is_float($float2)) { return ($float1 * $float2); } elseif (function_exists('bcmul')) { return BigNum::toFloat(((is_null($scale)) ? bcmul($float1, $float2) : bcmul($float1, $float2, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
php
public static function mul($float1, $float2, $scale = null) { if (!static::is($float1) || !static::is($float2)) { throw new \InvalidArgumentException( "The \$float1 and \$float2 parameters must be of type float (or string representing a big float)." ); } if (is_float($float1) && is_float($float2)) { return ($float1 * $float2); } elseif (function_exists('bcmul')) { return BigNum::toFloat(((is_null($scale)) ? bcmul($float1, $float2) : bcmul($float1, $float2, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
[ "public", "static", "function", "mul", "(", "$", "float1", ",", "$", "float2", ",", "$", "scale", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "float1", ")", "||", "!", "static", "::", "is", "(", "$", "float2", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$float1 and \\$float2 parameters must be of type float (or string representing a big float).\"", ")", ";", "}", "if", "(", "is_float", "(", "$", "float1", ")", "&&", "is_float", "(", "$", "float2", ")", ")", "{", "return", "(", "$", "float1", "*", "$", "float2", ")", ";", "}", "elseif", "(", "function_exists", "(", "'bcmul'", ")", ")", "{", "return", "BigNum", "::", "toFloat", "(", "(", "(", "is_null", "(", "$", "scale", ")", ")", "?", "bcmul", "(", "$", "float1", ",", "$", "float2", ")", ":", "bcmul", "(", "$", "float1", ",", "$", "float2", ",", "$", "scale", ")", ")", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "\"The BCMath library is not available.\"", ")", ";", "// @codeCoverageIgnore", "}" ]
Multiplies a number by another number. @param float|string $float1 The left operand. @param float|string $float2 The right operand. @param null|int $scale The scale to use for BCMath functions. If null is given the value set by {@link bcscale()} is used. @return float|string The result of the operation. @throws \InvalidArgumentException @throws \RuntimeException
[ "Multiplies", "a", "number", "by", "another", "number", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L334-L351
axelitus/php-base
src/BigFloat.php
BigFloat.div
public static function div($float1, $float2, $scale = null) { if (!static::is($float1) || !static::is($float2)) { throw new \InvalidArgumentException( "The \$float1 and \$float2 parameters must be of type float (or string representing a big float)." ); } if ($float2 == '0') { throw new \InvalidArgumentException("Cannot divide by zero. The \$float2 parameter cannot be zero."); } if (is_float($float1) && is_float($float2)) { return ($float1 / $float2); } elseif (function_exists('bcdiv')) { return BigNum::toFloat(((is_null($scale)) ? bcdiv($float1, $float2) : bcdiv($float1, $float2, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
php
public static function div($float1, $float2, $scale = null) { if (!static::is($float1) || !static::is($float2)) { throw new \InvalidArgumentException( "The \$float1 and \$float2 parameters must be of type float (or string representing a big float)." ); } if ($float2 == '0') { throw new \InvalidArgumentException("Cannot divide by zero. The \$float2 parameter cannot be zero."); } if (is_float($float1) && is_float($float2)) { return ($float1 / $float2); } elseif (function_exists('bcdiv')) { return BigNum::toFloat(((is_null($scale)) ? bcdiv($float1, $float2) : bcdiv($float1, $float2, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
[ "public", "static", "function", "div", "(", "$", "float1", ",", "$", "float2", ",", "$", "scale", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "float1", ")", "||", "!", "static", "::", "is", "(", "$", "float2", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$float1 and \\$float2 parameters must be of type float (or string representing a big float).\"", ")", ";", "}", "if", "(", "$", "float2", "==", "'0'", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Cannot divide by zero. The \\$float2 parameter cannot be zero.\"", ")", ";", "}", "if", "(", "is_float", "(", "$", "float1", ")", "&&", "is_float", "(", "$", "float2", ")", ")", "{", "return", "(", "$", "float1", "/", "$", "float2", ")", ";", "}", "elseif", "(", "function_exists", "(", "'bcdiv'", ")", ")", "{", "return", "BigNum", "::", "toFloat", "(", "(", "(", "is_null", "(", "$", "scale", ")", ")", "?", "bcdiv", "(", "$", "float1", ",", "$", "float2", ")", ":", "bcdiv", "(", "$", "float1", ",", "$", "float2", ",", "$", "scale", ")", ")", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "\"The BCMath library is not available.\"", ")", ";", "// @codeCoverageIgnore", "}" ]
Divides a number by another number. @param float|string $float1 The left operand. @param float|string $float2 The right operand. @param null|int $scale The scale to use for BCMath functions. If null is given the value set by {@link bcscale()} is used. @return float|string The result of the operation. @throws \InvalidArgumentException @throws \RuntimeException
[ "Divides", "a", "number", "by", "another", "number", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L365-L386
axelitus/php-base
src/BigFloat.php
BigFloat.pow
public static function pow($base, $exponent, $scale = null) { if (!static::is($base) || !static::is($exponent)) { throw new \InvalidArgumentException( "The \$base and \$exponent parameters must be of type float (or string representing a big float)." ); } if (is_float($base) && is_float($exponent)) { return pow($base, $exponent); } elseif (function_exists('bcpow')) { return BigNum::toFloat(((is_null($scale)) ? bcpow($base, $exponent) : bcpow($base, $exponent, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
php
public static function pow($base, $exponent, $scale = null) { if (!static::is($base) || !static::is($exponent)) { throw new \InvalidArgumentException( "The \$base and \$exponent parameters must be of type float (or string representing a big float)." ); } if (is_float($base) && is_float($exponent)) { return pow($base, $exponent); } elseif (function_exists('bcpow')) { return BigNum::toFloat(((is_null($scale)) ? bcpow($base, $exponent) : bcpow($base, $exponent, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
[ "public", "static", "function", "pow", "(", "$", "base", ",", "$", "exponent", ",", "$", "scale", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "base", ")", "||", "!", "static", "::", "is", "(", "$", "exponent", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$base and \\$exponent parameters must be of type float (or string representing a big float).\"", ")", ";", "}", "if", "(", "is_float", "(", "$", "base", ")", "&&", "is_float", "(", "$", "exponent", ")", ")", "{", "return", "pow", "(", "$", "base", ",", "$", "exponent", ")", ";", "}", "elseif", "(", "function_exists", "(", "'bcpow'", ")", ")", "{", "return", "BigNum", "::", "toFloat", "(", "(", "(", "is_null", "(", "$", "scale", ")", ")", "?", "bcpow", "(", "$", "base", ",", "$", "exponent", ")", ":", "bcpow", "(", "$", "base", ",", "$", "exponent", ",", "$", "scale", ")", ")", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "\"The BCMath library is not available.\"", ")", ";", "// @codeCoverageIgnore", "}" ]
Raises a number to the power of another number. @param float|string $base The base number. @param float|string $exponent The power exponent. @param null|int $scale The scale to use for BCMath functions. If null is given the value set by {@link bcscale()} is used. @return float|string The result of the operation. @throws \InvalidArgumentException @throws \RuntimeException
[ "Raises", "a", "number", "to", "the", "power", "of", "another", "number", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L400-L417
axelitus/php-base
src/BigFloat.php
BigFloat.mod
public static function mod($base, $modulus, $scale = null) { if (!static::is($base) || !static::is($modulus)) { throw new \InvalidArgumentException( "The \$base and \$modulus parameters must be of type float (or string representing a big float)." ); } if ($modulus == '0') { throw new \InvalidArgumentException("Cannot divide by zero. The \$modulus parameter cannot be zero."); } if (is_float($base) && is_float($modulus)) { return fmod($base, $modulus); } elseif (function_exists('bcdiv')) { // We cannot use bcmod because it only returns the int remainder $times = BigNum::toFloat(((is_null($scale)) ? static::toInt(BigNum::toFloat(bcdiv($base, $modulus))) : static::toInt(BigNum::toFloat(bcdiv($base, $modulus, $scale))) )); return BigNum::toFloat(static::sub($base, static::mul($times, $modulus, $scale), $scale)); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
php
public static function mod($base, $modulus, $scale = null) { if (!static::is($base) || !static::is($modulus)) { throw new \InvalidArgumentException( "The \$base and \$modulus parameters must be of type float (or string representing a big float)." ); } if ($modulus == '0') { throw new \InvalidArgumentException("Cannot divide by zero. The \$modulus parameter cannot be zero."); } if (is_float($base) && is_float($modulus)) { return fmod($base, $modulus); } elseif (function_exists('bcdiv')) { // We cannot use bcmod because it only returns the int remainder $times = BigNum::toFloat(((is_null($scale)) ? static::toInt(BigNum::toFloat(bcdiv($base, $modulus))) : static::toInt(BigNum::toFloat(bcdiv($base, $modulus, $scale))) )); return BigNum::toFloat(static::sub($base, static::mul($times, $modulus, $scale), $scale)); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
[ "public", "static", "function", "mod", "(", "$", "base", ",", "$", "modulus", ",", "$", "scale", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "base", ")", "||", "!", "static", "::", "is", "(", "$", "modulus", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$base and \\$modulus parameters must be of type float (or string representing a big float).\"", ")", ";", "}", "if", "(", "$", "modulus", "==", "'0'", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Cannot divide by zero. The \\$modulus parameter cannot be zero.\"", ")", ";", "}", "if", "(", "is_float", "(", "$", "base", ")", "&&", "is_float", "(", "$", "modulus", ")", ")", "{", "return", "fmod", "(", "$", "base", ",", "$", "modulus", ")", ";", "}", "elseif", "(", "function_exists", "(", "'bcdiv'", ")", ")", "{", "// We cannot use bcmod because it only returns the int remainder", "$", "times", "=", "BigNum", "::", "toFloat", "(", "(", "(", "is_null", "(", "$", "scale", ")", ")", "?", "static", "::", "toInt", "(", "BigNum", "::", "toFloat", "(", "bcdiv", "(", "$", "base", ",", "$", "modulus", ")", ")", ")", ":", "static", "::", "toInt", "(", "BigNum", "::", "toFloat", "(", "bcdiv", "(", "$", "base", ",", "$", "modulus", ",", "$", "scale", ")", ")", ")", ")", ")", ";", "return", "BigNum", "::", "toFloat", "(", "static", "::", "sub", "(", "$", "base", ",", "static", "::", "mul", "(", "$", "times", ",", "$", "modulus", ",", "$", "scale", ")", ",", "$", "scale", ")", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "\"The BCMath library is not available.\"", ")", ";", "// @codeCoverageIgnore", "}" ]
Gets the remainder of a number divided by another number. @param float|string $base The left operand. @param float|string $modulus The right operand. @param null|int $scale The scale to use for BCMath functions. If null is given the value set by {@link bcscale()} is used. @return float|string The result of the operation. @throws \InvalidArgumentException @throws \RuntimeException
[ "Gets", "the", "remainder", "of", "a", "number", "divided", "by", "another", "number", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L431-L456
axelitus/php-base
src/BigFloat.php
BigFloat.sqrt
public static function sqrt($base, $scale = null) { if (!static::is($base)) { throw new \InvalidArgumentException( "The \$base parameters must be of type float (or string representing a big float)." ); } if (is_float($base)) { return sqrt($base); } elseif (function_exists('bcsqrt')) { return BigNum::toFloat(((is_null($scale)) ? bcsqrt($base) : bcsqrt($base, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
php
public static function sqrt($base, $scale = null) { if (!static::is($base)) { throw new \InvalidArgumentException( "The \$base parameters must be of type float (or string representing a big float)." ); } if (is_float($base)) { return sqrt($base); } elseif (function_exists('bcsqrt')) { return BigNum::toFloat(((is_null($scale)) ? bcsqrt($base) : bcsqrt($base, $scale))); } throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore }
[ "public", "static", "function", "sqrt", "(", "$", "base", ",", "$", "scale", "=", "null", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "base", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"The \\$base parameters must be of type float (or string representing a big float).\"", ")", ";", "}", "if", "(", "is_float", "(", "$", "base", ")", ")", "{", "return", "sqrt", "(", "$", "base", ")", ";", "}", "elseif", "(", "function_exists", "(", "'bcsqrt'", ")", ")", "{", "return", "BigNum", "::", "toFloat", "(", "(", "(", "is_null", "(", "$", "scale", ")", ")", "?", "bcsqrt", "(", "$", "base", ")", ":", "bcsqrt", "(", "$", "base", ",", "$", "scale", ")", ")", ")", ";", "}", "throw", "new", "\\", "RuntimeException", "(", "\"The BCMath library is not available.\"", ")", ";", "// @codeCoverageIgnore", "}" ]
Gets the square root of a number. @param float|string $base The base to use. @param null|int $scale The scale to use for BCMath functions. If null is given the value set by {@link bcscale()} is used. @return float|string The result of the operation. @throws \InvalidArgumentException @throws \RuntimeException
[ "Gets", "the", "square", "root", "of", "a", "number", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/BigFloat.php#L469-L486