repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
schpill/thin
src/Bag.php
Bag.set
public function set($key, $value) { $this->values[$this->normalizeKey($key)] = $value; return $this; }
php
public function set($key, $value) { $this->values[$this->normalizeKey($key)] = $value; return $this; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "$", "this", "->", "values", "[", "$", "this", "->", "normalizeKey", "(", "$", "key", ")", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Set data key to value @param string $key The data key @param mixed $value The data value
[ "Set", "data", "key", "to", "value" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Bag.php#L40-L45
train
schpill/thin
src/Bag.php
Bag.get
public function get($key, $default = null) { if ($this->has($key)) { $isInvokable = is_object($this->values[$this->normalizeKey($key)]) && method_exists($this->values[$this->normalizeKey($key)], '__invoke'); return $isInvokable ? $this->values[$this->normalizeKey($key)]($this) : $this->values[$this->normalizeKey($key)]; } return $default; }
php
public function get($key, $default = null) { if ($this->has($key)) { $isInvokable = is_object($this->values[$this->normalizeKey($key)]) && method_exists($this->values[$this->normalizeKey($key)], '__invoke'); return $isInvokable ? $this->values[$this->normalizeKey($key)]($this) : $this->values[$this->normalizeKey($key)]; } return $default; }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "$", "isInvokable", "=", "is_object", "(", "$", "this", "->", "values", "[", "$", "this", "->", "normalizeKey", "(", "$", "key", ")", "]", ")", "&&", "method_exists", "(", "$", "this", "->", "values", "[", "$", "this", "->", "normalizeKey", "(", "$", "key", ")", "]", ",", "'__invoke'", ")", ";", "return", "$", "isInvokable", "?", "$", "this", "->", "values", "[", "$", "this", "->", "normalizeKey", "(", "$", "key", ")", "]", "(", "$", "this", ")", ":", "$", "this", "->", "values", "[", "$", "this", "->", "normalizeKey", "(", "$", "key", ")", "]", ";", "}", "return", "$", "default", ";", "}" ]
Get values value with key @param string $key The values key @param mixed $default The value to return if values key does not exist @return mixed The values value, or the default value
[ "Get", "values", "value", "with", "key" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Bag.php#L53-L64
train
YiMAproject/yimaAdminor
src/yimaAdminor/Auth/AuthService.php
AuthService.identity
function identity() { if (!$this->identity) $this->identity = new BaseIdentity(get_class($this)); return $this->identity; }
php
function identity() { if (!$this->identity) $this->identity = new BaseIdentity(get_class($this)); return $this->identity; }
[ "function", "identity", "(", ")", "{", "if", "(", "!", "$", "this", "->", "identity", ")", "$", "this", "->", "identity", "=", "new", "BaseIdentity", "(", "get_class", "(", "$", "this", ")", ")", ";", "return", "$", "this", "->", "identity", ";", "}" ]
Get Authorized User Identity - identities must inject into adapter by auth services @throws \Exception Not Identity Available Or Set @return BaseIdentity
[ "Get", "Authorized", "User", "Identity" ]
7a6c66e05aedaef8061c8998dfa44ac1ce9cc319
https://github.com/YiMAproject/yimaAdminor/blob/7a6c66e05aedaef8061c8998dfa44ac1ce9cc319/src/yimaAdminor/Auth/AuthService.php#L67-L73
train
atelierspierrot/patterns
src/Patterns/Commons/ConfigurationRegistry.php
ConfigurationRegistry.set
public function set($name, $value, $scope = null) { if (strpos($name, ':')) { list($entry, $name) = explode(':', $name); $cfg = $this->getConfig($entry, array(), $scope); $cfg[$name] = $value; return $this->setConfig($entry, $cfg, $scope); } else { return $this->setConfig($name, $value, $scope); } }
php
public function set($name, $value, $scope = null) { if (strpos($name, ':')) { list($entry, $name) = explode(':', $name); $cfg = $this->getConfig($entry, array(), $scope); $cfg[$name] = $value; return $this->setConfig($entry, $cfg, $scope); } else { return $this->setConfig($name, $value, $scope); } }
[ "public", "function", "set", "(", "$", "name", ",", "$", "value", ",", "$", "scope", "=", "null", ")", "{", "if", "(", "strpos", "(", "$", "name", ",", "':'", ")", ")", "{", "list", "(", "$", "entry", ",", "$", "name", ")", "=", "explode", "(", "':'", ",", "$", "name", ")", ";", "$", "cfg", "=", "$", "this", "->", "getConfig", "(", "$", "entry", ",", "array", "(", ")", ",", "$", "scope", ")", ";", "$", "cfg", "[", "$", "name", "]", "=", "$", "value", ";", "return", "$", "this", "->", "setConfig", "(", "$", "entry", ",", "$", "cfg", ",", "$", "scope", ")", ";", "}", "else", "{", "return", "$", "this", "->", "setConfig", "(", "$", "name", ",", "$", "value", ",", "$", "scope", ")", ";", "}", "}" ]
Set the value of a specific option with depth @param string $name The index of the configuration value to get, with a scope using notation `index:name` @param mixed $value The value to set for $name @param string $scope The scope to use in the configuration registry if it is not defined in the `$name` parameter @return self
[ "Set", "the", "value", "of", "a", "specific", "option", "with", "depth" ]
b7a8313e98bbfb6525e1672d0a726a1ead6f156e
https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/ConfigurationRegistry.php#L62-L72
train
atelierspierrot/patterns
src/Patterns/Commons/ConfigurationRegistry.php
ConfigurationRegistry.setConfigs
public function setConfigs(array $options, $scope = null) { if (!is_null($scope)) { $this->registry[$scope] = $options; } else { $this->registry = $options; } return $this; }
php
public function setConfigs(array $options, $scope = null) { if (!is_null($scope)) { $this->registry[$scope] = $options; } else { $this->registry = $options; } return $this; }
[ "public", "function", "setConfigs", "(", "array", "$", "options", ",", "$", "scope", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "scope", ")", ")", "{", "$", "this", "->", "registry", "[", "$", "scope", "]", "=", "$", "options", ";", "}", "else", "{", "$", "this", "->", "registry", "=", "$", "options", ";", "}", "return", "$", "this", ";", "}" ]
Set an array of options @param array $options The array of values to set for the configuration entry @param string $scope The scope to use in the configuration registry (optional) @return self
[ "Set", "an", "array", "of", "options" ]
b7a8313e98bbfb6525e1672d0a726a1ead6f156e
https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/ConfigurationRegistry.php#L100-L109
train
atelierspierrot/patterns
src/Patterns/Commons/ConfigurationRegistry.php
ConfigurationRegistry.addConfig
public function addConfig($name, $value, $scope = null) { return $this->setConfig($name, $value, $scope); }
php
public function addConfig($name, $value, $scope = null) { return $this->setConfig($name, $value, $scope); }
[ "public", "function", "addConfig", "(", "$", "name", ",", "$", "value", ",", "$", "scope", "=", "null", ")", "{", "return", "$", "this", "->", "setConfig", "(", "$", "name", ",", "$", "value", ",", "$", "scope", ")", ";", "}" ]
Alias of the `setConfig` method @see self::setConfig()
[ "Alias", "of", "the", "setConfig", "method" ]
b7a8313e98bbfb6525e1672d0a726a1ead6f156e
https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/ConfigurationRegistry.php#L138-L141
train
simpleapisecurity/php
src/Entropy.php
Entropy.bytes
static function bytes($bytes = Constants::BYTES) { # Test the length for validity. Helpers::rangeCheck($bytes, Constants::BYTES_MAX, Constants::BYTES_MIN, 'Entropy', 'bytes'); return \Sodium\randombytes_buf($bytes); }
php
static function bytes($bytes = Constants::BYTES) { # Test the length for validity. Helpers::rangeCheck($bytes, Constants::BYTES_MAX, Constants::BYTES_MIN, 'Entropy', 'bytes'); return \Sodium\randombytes_buf($bytes); }
[ "static", "function", "bytes", "(", "$", "bytes", "=", "Constants", "::", "BYTES", ")", "{", "# Test the length for validity.", "Helpers", "::", "rangeCheck", "(", "$", "bytes", ",", "Constants", "::", "BYTES_MAX", ",", "Constants", "::", "BYTES_MIN", ",", "'Entropy'", ",", "'bytes'", ")", ";", "return", "\\", "Sodium", "\\", "randombytes_buf", "(", "$", "bytes", ")", ";", "}" ]
Returns a string of random bytes to the client. @param int $bytes Size of the string of bytes to be generated. @return string @throws Exceptions\InvalidTypeException @throws Exceptions\OutOfRangeException
[ "Returns", "a", "string", "of", "random", "bytes", "to", "the", "client", "." ]
e6cebf3213f4d7be54aa3a188d95a00113e3fda0
https://github.com/simpleapisecurity/php/blob/e6cebf3213f4d7be54aa3a188d95a00113e3fda0/src/Entropy.php#L25-L31
train
simpleapisecurity/php
src/Entropy.php
Entropy.integer
static function integer($range = Constants::RANGE) { # Test the length for validity. Helpers::rangeCheck($range, Constants::RANGE_MAX, Constants::RANGE_MIN, 'Entropy', 'integer'); return \Sodium\randombytes_uniform($range) + 1; }
php
static function integer($range = Constants::RANGE) { # Test the length for validity. Helpers::rangeCheck($range, Constants::RANGE_MAX, Constants::RANGE_MIN, 'Entropy', 'integer'); return \Sodium\randombytes_uniform($range) + 1; }
[ "static", "function", "integer", "(", "$", "range", "=", "Constants", "::", "RANGE", ")", "{", "# Test the length for validity.", "Helpers", "::", "rangeCheck", "(", "$", "range", ",", "Constants", "::", "RANGE_MAX", ",", "Constants", "::", "RANGE_MIN", ",", "'Entropy'", ",", "'integer'", ")", ";", "return", "\\", "Sodium", "\\", "randombytes_uniform", "(", "$", "range", ")", "+", "1", ";", "}" ]
Returns a random integer to the client. @param int $range Upper limit of random numbers to return to the client. @return int @throws Exceptions\InvalidTypeException @throws Exceptions\OutOfRangeException
[ "Returns", "a", "random", "integer", "to", "the", "client", "." ]
e6cebf3213f4d7be54aa3a188d95a00113e3fda0
https://github.com/simpleapisecurity/php/blob/e6cebf3213f4d7be54aa3a188d95a00113e3fda0/src/Entropy.php#L41-L47
train
luoxiaojun1992/lb_framework
controllers/console/ServerController.php
ServerController.index
public function index() { $argv = \Console_Getopt::readPHPArgv(); $opts = \Console_Getopt::getopt(array_slice($argv, 2, count($argv) - 2), 'h::p::d::r::', null, true); if (!empty($opts[0]) && is_array($opts[0])) { foreach ($opts[0] as $val) { if (!empty($val[0]) && !empty($val[1]) && is_string($val[0]) && is_string($val[1])) { switch ($val[0]) { case 'h': $this->host = $val[1]; break; case 'p': $this->port = $val[1]; break; case 'd': $this->docroot = $val[1]; break; case 'r': $this->router = $val[1]; break; } } } } $documentRoot = $this->docroot; $address = $this->host . ':' . $this->port; if (!is_dir($documentRoot)) { Lb::app()->stop("Document root \"$documentRoot\" does not exist.\n", self::EXIT_CODE_NO_DOCUMENT_ROOT); } if ($this->isAddressTaken($address)) { Lb::app()->stop("http://$address is taken by another process.\n", self::EXIT_CODE_ADDRESS_TAKEN_BY_ANOTHER_PROCESS); } if ($this->router !== null && !file_exists($this->router)) { Lb::app()->stop("Routing file \"$this->router\" does not exist.\n", self::EXIT_CODE_NO_ROUTING_FILE); } $this->writeln("Server started on http://{$address}/\n"); $this->writeln("Document root is \"{$documentRoot}\"\n"); if ($this->router) { $this->writeln("Routing file is \"$this->router\"\n"); } $this->writeln("Quit the server with CTRL-C or COMMAND-C.\n"); passthru('"' . PHP_BINARY . '"' . " -S {$address} -t \"{$documentRoot}\" $this->router"); }
php
public function index() { $argv = \Console_Getopt::readPHPArgv(); $opts = \Console_Getopt::getopt(array_slice($argv, 2, count($argv) - 2), 'h::p::d::r::', null, true); if (!empty($opts[0]) && is_array($opts[0])) { foreach ($opts[0] as $val) { if (!empty($val[0]) && !empty($val[1]) && is_string($val[0]) && is_string($val[1])) { switch ($val[0]) { case 'h': $this->host = $val[1]; break; case 'p': $this->port = $val[1]; break; case 'd': $this->docroot = $val[1]; break; case 'r': $this->router = $val[1]; break; } } } } $documentRoot = $this->docroot; $address = $this->host . ':' . $this->port; if (!is_dir($documentRoot)) { Lb::app()->stop("Document root \"$documentRoot\" does not exist.\n", self::EXIT_CODE_NO_DOCUMENT_ROOT); } if ($this->isAddressTaken($address)) { Lb::app()->stop("http://$address is taken by another process.\n", self::EXIT_CODE_ADDRESS_TAKEN_BY_ANOTHER_PROCESS); } if ($this->router !== null && !file_exists($this->router)) { Lb::app()->stop("Routing file \"$this->router\" does not exist.\n", self::EXIT_CODE_NO_ROUTING_FILE); } $this->writeln("Server started on http://{$address}/\n"); $this->writeln("Document root is \"{$documentRoot}\"\n"); if ($this->router) { $this->writeln("Routing file is \"$this->router\"\n"); } $this->writeln("Quit the server with CTRL-C or COMMAND-C.\n"); passthru('"' . PHP_BINARY . '"' . " -S {$address} -t \"{$documentRoot}\" $this->router"); }
[ "public", "function", "index", "(", ")", "{", "$", "argv", "=", "\\", "Console_Getopt", "::", "readPHPArgv", "(", ")", ";", "$", "opts", "=", "\\", "Console_Getopt", "::", "getopt", "(", "array_slice", "(", "$", "argv", ",", "2", ",", "count", "(", "$", "argv", ")", "-", "2", ")", ",", "'h::p::d::r::'", ",", "null", ",", "true", ")", ";", "if", "(", "!", "empty", "(", "$", "opts", "[", "0", "]", ")", "&&", "is_array", "(", "$", "opts", "[", "0", "]", ")", ")", "{", "foreach", "(", "$", "opts", "[", "0", "]", "as", "$", "val", ")", "{", "if", "(", "!", "empty", "(", "$", "val", "[", "0", "]", ")", "&&", "!", "empty", "(", "$", "val", "[", "1", "]", ")", "&&", "is_string", "(", "$", "val", "[", "0", "]", ")", "&&", "is_string", "(", "$", "val", "[", "1", "]", ")", ")", "{", "switch", "(", "$", "val", "[", "0", "]", ")", "{", "case", "'h'", ":", "$", "this", "->", "host", "=", "$", "val", "[", "1", "]", ";", "break", ";", "case", "'p'", ":", "$", "this", "->", "port", "=", "$", "val", "[", "1", "]", ";", "break", ";", "case", "'d'", ":", "$", "this", "->", "docroot", "=", "$", "val", "[", "1", "]", ";", "break", ";", "case", "'r'", ":", "$", "this", "->", "router", "=", "$", "val", "[", "1", "]", ";", "break", ";", "}", "}", "}", "}", "$", "documentRoot", "=", "$", "this", "->", "docroot", ";", "$", "address", "=", "$", "this", "->", "host", ".", "':'", ".", "$", "this", "->", "port", ";", "if", "(", "!", "is_dir", "(", "$", "documentRoot", ")", ")", "{", "Lb", "::", "app", "(", ")", "->", "stop", "(", "\"Document root \\\"$documentRoot\\\" does not exist.\\n\"", ",", "self", "::", "EXIT_CODE_NO_DOCUMENT_ROOT", ")", ";", "}", "if", "(", "$", "this", "->", "isAddressTaken", "(", "$", "address", ")", ")", "{", "Lb", "::", "app", "(", ")", "->", "stop", "(", "\"http://$address is taken by another process.\\n\"", ",", "self", "::", "EXIT_CODE_ADDRESS_TAKEN_BY_ANOTHER_PROCESS", ")", ";", "}", "if", "(", "$", "this", "->", "router", "!==", "null", "&&", "!", "file_exists", "(", "$", "this", "->", "router", ")", ")", "{", "Lb", "::", "app", "(", ")", "->", "stop", "(", "\"Routing file \\\"$this->router\\\" does not exist.\\n\"", ",", "self", "::", "EXIT_CODE_NO_ROUTING_FILE", ")", ";", "}", "$", "this", "->", "writeln", "(", "\"Server started on http://{$address}/\\n\"", ")", ";", "$", "this", "->", "writeln", "(", "\"Document root is \\\"{$documentRoot}\\\"\\n\"", ")", ";", "if", "(", "$", "this", "->", "router", ")", "{", "$", "this", "->", "writeln", "(", "\"Routing file is \\\"$this->router\\\"\\n\"", ")", ";", "}", "$", "this", "->", "writeln", "(", "\"Quit the server with CTRL-C or COMMAND-C.\\n\"", ")", ";", "passthru", "(", "'\"'", ".", "PHP_BINARY", ".", "'\"'", ".", "\" -S {$address} -t \\\"{$documentRoot}\\\" $this->router\"", ")", ";", "}" ]
Runs PHP built-in web server @param string $address address to serve on. Either "host" or "host:port". @return int
[ "Runs", "PHP", "built", "-", "in", "web", "server" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/controllers/console/ServerController.php#L39-L82
train
phramework/phramework
src/Models/Compress.php
Compress.decompress
public static function decompress( $compressedFile, $destinationFolder, $originalFilename = null, $format = 'gz', $allowedExtensions = [ 'csv', 'tsv' ] ) { //TODO ADD tar.gz $supported_formats = [ 'gz', 'zip', 'tar']; if (!in_array($format, $supported_formats)) { throw new \Exception('Unsupported compression format'); } switch ($format) { case 'gz': return self::decompressGz( $compressedFile, $destinationFolder, $originalFilename, $allowedExtensions ); case 'zip': return self::decompressZip( $compressedFile, $destinationFolder, $originalFilename, $allowedExtensions ); case 'tar': return self::decompressTar( $compressedFile, $destinationFolder, $originalFilename, $allowedExtensions ); } }
php
public static function decompress( $compressedFile, $destinationFolder, $originalFilename = null, $format = 'gz', $allowedExtensions = [ 'csv', 'tsv' ] ) { //TODO ADD tar.gz $supported_formats = [ 'gz', 'zip', 'tar']; if (!in_array($format, $supported_formats)) { throw new \Exception('Unsupported compression format'); } switch ($format) { case 'gz': return self::decompressGz( $compressedFile, $destinationFolder, $originalFilename, $allowedExtensions ); case 'zip': return self::decompressZip( $compressedFile, $destinationFolder, $originalFilename, $allowedExtensions ); case 'tar': return self::decompressTar( $compressedFile, $destinationFolder, $originalFilename, $allowedExtensions ); } }
[ "public", "static", "function", "decompress", "(", "$", "compressedFile", ",", "$", "destinationFolder", ",", "$", "originalFilename", "=", "null", ",", "$", "format", "=", "'gz'", ",", "$", "allowedExtensions", "=", "[", "'csv'", ",", "'tsv'", "]", ")", "{", "//TODO ADD tar.gz", "$", "supported_formats", "=", "[", "'gz'", ",", "'zip'", ",", "'tar'", "]", ";", "if", "(", "!", "in_array", "(", "$", "format", ",", "$", "supported_formats", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Unsupported compression format'", ")", ";", "}", "switch", "(", "$", "format", ")", "{", "case", "'gz'", ":", "return", "self", "::", "decompressGz", "(", "$", "compressedFile", ",", "$", "destinationFolder", ",", "$", "originalFilename", ",", "$", "allowedExtensions", ")", ";", "case", "'zip'", ":", "return", "self", "::", "decompressZip", "(", "$", "compressedFile", ",", "$", "destinationFolder", ",", "$", "originalFilename", ",", "$", "allowedExtensions", ")", ";", "case", "'tar'", ":", "return", "self", "::", "decompressTar", "(", "$", "compressedFile", ",", "$", "destinationFolder", ",", "$", "originalFilename", ",", "$", "allowedExtensions", ")", ";", "}", "}" ]
decompress a file archive @param string $compressedFile Archive path @param string $destinationFolder Destination folder to decompress files @param string $originalFilename Original file name @param string $format Select format mode, Default is gz, gz, zip and tar are available. @param string[] $allowedExtensions @return array Returns a list with the decompressed files @throws \Exception
[ "decompress", "a", "file", "archive" ]
40041d1ef23b1f8cdbd26fb112448d6a3dbef012
https://github.com/phramework/phramework/blob/40041d1ef23b1f8cdbd26fb112448d6a3dbef012/src/Models/Compress.php#L42-L80
train
SpoonX/SxMail
src/SxMail/Service/SxMailService.php
SxMailService.getConfig
public function getConfig($configKey = null) { $default = clone $this->config->configs->default; if (null !== $configKey) { $default->merge(clone $this->config->configs->{$configKey}); } return $default->toArray(); }
php
public function getConfig($configKey = null) { $default = clone $this->config->configs->default; if (null !== $configKey) { $default->merge(clone $this->config->configs->{$configKey}); } return $default->toArray(); }
[ "public", "function", "getConfig", "(", "$", "configKey", "=", "null", ")", "{", "$", "default", "=", "clone", "$", "this", "->", "config", "->", "configs", "->", "default", ";", "if", "(", "null", "!==", "$", "configKey", ")", "{", "$", "default", "->", "merge", "(", "clone", "$", "this", "->", "config", "->", "configs", "->", "{", "$", "configKey", "}", ")", ";", "}", "return", "$", "default", "->", "toArray", "(", ")", ";", "}" ]
Get the default config, merged with an option overriding config. @param string $configKey @return array The merged configuration
[ "Get", "the", "default", "config", "merged", "with", "an", "option", "overriding", "config", "." ]
b0663169cd246ba091f7c84785c69d051a652385
https://github.com/SpoonX/SxMail/blob/b0663169cd246ba091f7c84785c69d051a652385/src/SxMail/Service/SxMailService.php#L45-L54
train
cyberspectrum/i18n-contao
src/Mapping/Terminal42ChangeLanguage/PageMap.php
PageMap.findRootPages
private function findRootPages(): array { $result = [ 'source' => null, 'target' => null, 'main' => null, ]; $this->logger->debug( 'Searching root pages for source "{source}" and target "{target}"', ['source' => $this->sourceLanguage, 'target' => $this->targetLanguage] ); foreach ($this->database->getRootPages() as $root) { $language = $root['language']; if ('1' === $root['fallback']) { $this->mainLanguage = $language; $result['main'] = (int) $root['id']; } if ($language === $this->sourceLanguage) { $result['source'] = (int) $root['id']; } if ($language === $this->targetLanguage) { $result['target'] = (int) $root['id']; } // Keep type for being able to filter unknown pages in i.e. articles. $this->types[(int) $root['id']] = 'root'; } $this->logger->debug( 'Found root pages: source: {source}; target: {target}; main: {main}', $result ); if (null === $result['source'] || null === $result['target'] || null === $result['main']) { throw new \RuntimeException('Not all root pages could be found: ' . var_export($result, true)); } return $result; }
php
private function findRootPages(): array { $result = [ 'source' => null, 'target' => null, 'main' => null, ]; $this->logger->debug( 'Searching root pages for source "{source}" and target "{target}"', ['source' => $this->sourceLanguage, 'target' => $this->targetLanguage] ); foreach ($this->database->getRootPages() as $root) { $language = $root['language']; if ('1' === $root['fallback']) { $this->mainLanguage = $language; $result['main'] = (int) $root['id']; } if ($language === $this->sourceLanguage) { $result['source'] = (int) $root['id']; } if ($language === $this->targetLanguage) { $result['target'] = (int) $root['id']; } // Keep type for being able to filter unknown pages in i.e. articles. $this->types[(int) $root['id']] = 'root'; } $this->logger->debug( 'Found root pages: source: {source}; target: {target}; main: {main}', $result ); if (null === $result['source'] || null === $result['target'] || null === $result['main']) { throw new \RuntimeException('Not all root pages could be found: ' . var_export($result, true)); } return $result; }
[ "private", "function", "findRootPages", "(", ")", ":", "array", "{", "$", "result", "=", "[", "'source'", "=>", "null", ",", "'target'", "=>", "null", ",", "'main'", "=>", "null", ",", "]", ";", "$", "this", "->", "logger", "->", "debug", "(", "'Searching root pages for source \"{source}\" and target \"{target}\"'", ",", "[", "'source'", "=>", "$", "this", "->", "sourceLanguage", ",", "'target'", "=>", "$", "this", "->", "targetLanguage", "]", ")", ";", "foreach", "(", "$", "this", "->", "database", "->", "getRootPages", "(", ")", "as", "$", "root", ")", "{", "$", "language", "=", "$", "root", "[", "'language'", "]", ";", "if", "(", "'1'", "===", "$", "root", "[", "'fallback'", "]", ")", "{", "$", "this", "->", "mainLanguage", "=", "$", "language", ";", "$", "result", "[", "'main'", "]", "=", "(", "int", ")", "$", "root", "[", "'id'", "]", ";", "}", "if", "(", "$", "language", "===", "$", "this", "->", "sourceLanguage", ")", "{", "$", "result", "[", "'source'", "]", "=", "(", "int", ")", "$", "root", "[", "'id'", "]", ";", "}", "if", "(", "$", "language", "===", "$", "this", "->", "targetLanguage", ")", "{", "$", "result", "[", "'target'", "]", "=", "(", "int", ")", "$", "root", "[", "'id'", "]", ";", "}", "// Keep type for being able to filter unknown pages in i.e. articles.", "$", "this", "->", "types", "[", "(", "int", ")", "$", "root", "[", "'id'", "]", "]", "=", "'root'", ";", "}", "$", "this", "->", "logger", "->", "debug", "(", "'Found root pages: source: {source}; target: {target}; main: {main}'", ",", "$", "result", ")", ";", "if", "(", "null", "===", "$", "result", "[", "'source'", "]", "||", "null", "===", "$", "result", "[", "'target'", "]", "||", "null", "===", "$", "result", "[", "'main'", "]", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Not all root pages could be found: '", ".", "var_export", "(", "$", "result", ",", "true", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Determine the root pages. @return int[] @throws \RuntimeException When a root page is missing.
[ "Determine", "the", "root", "pages", "." ]
038cf6ea9c609a734d7476fba256bc4b0db236b7
https://github.com/cyberspectrum/i18n-contao/blob/038cf6ea9c609a734d7476fba256bc4b0db236b7/src/Mapping/Terminal42ChangeLanguage/PageMap.php#L95-L136
train
cyberspectrum/i18n-contao
src/Mapping/Terminal42ChangeLanguage/PageMap.php
PageMap.buildPageMap
private function buildPageMap(int $mainRoot, int $otherRoot, array &$map, array &$inverse): array { // Root pages are mapped to each other. $map[$otherRoot] = $mainRoot; $inverse[$mainRoot] = $otherRoot; // Now fetch all other. $isMain = $mainRoot === $otherRoot; $lookupQueue = [$otherRoot]; do { // Fetch children of parents in queue. $children = $this->database->getPagesByPidList($lookupQueue); // Nothing to do anymore, break it. if (empty($children)) { break; } // Reset pid list - we have the children. $lookupQueue = []; foreach ($children as $index => $child) { $childId = (int) $child['id']; $main = $isMain ? $childId : (int) $child['languageMain']; // Try to determine automatically. if (!$isMain && empty($main)) { if (null === ($main = $this->determineMapFor($index, (int) $child['pid'], $map))) { $this->logger->warning( 'Page {id} has no fallback set and unable to determine automatically. Page skipped.', ['id' => $childId] ); continue; } $this->logger->warning( 'Page {id} (index: {index}) has no fallback set, expect problems, I guess it is {guessed}', ['id' => $childId, 'index' => $index, 'guessed' => $main] ); } $map[$childId] = $main; $inverse[$main] = $childId; // Keep type for being able to filter unknown pages in i.e. articles. $this->types[$childId] = $child['type']; $lookupQueue[] = $childId; } } while (true); return $map; }
php
private function buildPageMap(int $mainRoot, int $otherRoot, array &$map, array &$inverse): array { // Root pages are mapped to each other. $map[$otherRoot] = $mainRoot; $inverse[$mainRoot] = $otherRoot; // Now fetch all other. $isMain = $mainRoot === $otherRoot; $lookupQueue = [$otherRoot]; do { // Fetch children of parents in queue. $children = $this->database->getPagesByPidList($lookupQueue); // Nothing to do anymore, break it. if (empty($children)) { break; } // Reset pid list - we have the children. $lookupQueue = []; foreach ($children as $index => $child) { $childId = (int) $child['id']; $main = $isMain ? $childId : (int) $child['languageMain']; // Try to determine automatically. if (!$isMain && empty($main)) { if (null === ($main = $this->determineMapFor($index, (int) $child['pid'], $map))) { $this->logger->warning( 'Page {id} has no fallback set and unable to determine automatically. Page skipped.', ['id' => $childId] ); continue; } $this->logger->warning( 'Page {id} (index: {index}) has no fallback set, expect problems, I guess it is {guessed}', ['id' => $childId, 'index' => $index, 'guessed' => $main] ); } $map[$childId] = $main; $inverse[$main] = $childId; // Keep type for being able to filter unknown pages in i.e. articles. $this->types[$childId] = $child['type']; $lookupQueue[] = $childId; } } while (true); return $map; }
[ "private", "function", "buildPageMap", "(", "int", "$", "mainRoot", ",", "int", "$", "otherRoot", ",", "array", "&", "$", "map", ",", "array", "&", "$", "inverse", ")", ":", "array", "{", "// Root pages are mapped to each other.", "$", "map", "[", "$", "otherRoot", "]", "=", "$", "mainRoot", ";", "$", "inverse", "[", "$", "mainRoot", "]", "=", "$", "otherRoot", ";", "// Now fetch all other.", "$", "isMain", "=", "$", "mainRoot", "===", "$", "otherRoot", ";", "$", "lookupQueue", "=", "[", "$", "otherRoot", "]", ";", "do", "{", "// Fetch children of parents in queue.", "$", "children", "=", "$", "this", "->", "database", "->", "getPagesByPidList", "(", "$", "lookupQueue", ")", ";", "// Nothing to do anymore, break it.", "if", "(", "empty", "(", "$", "children", ")", ")", "{", "break", ";", "}", "// Reset pid list - we have the children.", "$", "lookupQueue", "=", "[", "]", ";", "foreach", "(", "$", "children", "as", "$", "index", "=>", "$", "child", ")", "{", "$", "childId", "=", "(", "int", ")", "$", "child", "[", "'id'", "]", ";", "$", "main", "=", "$", "isMain", "?", "$", "childId", ":", "(", "int", ")", "$", "child", "[", "'languageMain'", "]", ";", "// Try to determine automatically.", "if", "(", "!", "$", "isMain", "&&", "empty", "(", "$", "main", ")", ")", "{", "if", "(", "null", "===", "(", "$", "main", "=", "$", "this", "->", "determineMapFor", "(", "$", "index", ",", "(", "int", ")", "$", "child", "[", "'pid'", "]", ",", "$", "map", ")", ")", ")", "{", "$", "this", "->", "logger", "->", "warning", "(", "'Page {id} has no fallback set and unable to determine automatically. Page skipped.'", ",", "[", "'id'", "=>", "$", "childId", "]", ")", ";", "continue", ";", "}", "$", "this", "->", "logger", "->", "warning", "(", "'Page {id} (index: {index}) has no fallback set, expect problems, I guess it is {guessed}'", ",", "[", "'id'", "=>", "$", "childId", ",", "'index'", "=>", "$", "index", ",", "'guessed'", "=>", "$", "main", "]", ")", ";", "}", "$", "map", "[", "$", "childId", "]", "=", "$", "main", ";", "$", "inverse", "[", "$", "main", "]", "=", "$", "childId", ";", "// Keep type for being able to filter unknown pages in i.e. articles.", "$", "this", "->", "types", "[", "$", "childId", "]", "=", "$", "child", "[", "'type'", "]", ";", "$", "lookupQueue", "[", "]", "=", "$", "childId", ";", "}", "}", "while", "(", "true", ")", ";", "return", "$", "map", ";", "}" ]
Build a map for a language and returns the map from source to main. @param int $mainRoot The main language root page. @param int $otherRoot The root page of the other language. @param array $map The mapping array to populate. @param array $inverse The inverse mapping. @return int[]
[ "Build", "a", "map", "for", "a", "language", "and", "returns", "the", "map", "from", "source", "to", "main", "." ]
038cf6ea9c609a734d7476fba256bc4b0db236b7
https://github.com/cyberspectrum/i18n-contao/blob/038cf6ea9c609a734d7476fba256bc4b0db236b7/src/Mapping/Terminal42ChangeLanguage/PageMap.php#L148-L198
train
cyberspectrum/i18n-contao
src/Mapping/Terminal42ChangeLanguage/PageMap.php
PageMap.determineMapFor
private function determineMapFor(int $index, int $parentId, array $inverseList): ?int { if (!isset($inverseList[$parentId])) { throw new \InvalidArgumentException( 'Page id ' . $parentId . ' has not been mapped' ); } // Lookup all children of parent page in main language. $mainSiblings = $this->database->getPagesByPidList([$inverseList[$parentId]]); return isset($mainSiblings[$index]) ? (int) $mainSiblings[$index]['id'] : null; }
php
private function determineMapFor(int $index, int $parentId, array $inverseList): ?int { if (!isset($inverseList[$parentId])) { throw new \InvalidArgumentException( 'Page id ' . $parentId . ' has not been mapped' ); } // Lookup all children of parent page in main language. $mainSiblings = $this->database->getPagesByPidList([$inverseList[$parentId]]); return isset($mainSiblings[$index]) ? (int) $mainSiblings[$index]['id'] : null; }
[ "private", "function", "determineMapFor", "(", "int", "$", "index", ",", "int", "$", "parentId", ",", "array", "$", "inverseList", ")", ":", "?", "int", "{", "if", "(", "!", "isset", "(", "$", "inverseList", "[", "$", "parentId", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Page id '", ".", "$", "parentId", ".", "' has not been mapped'", ")", ";", "}", "// Lookup all children of parent page in main language.", "$", "mainSiblings", "=", "$", "this", "->", "database", "->", "getPagesByPidList", "(", "[", "$", "inverseList", "[", "$", "parentId", "]", "]", ")", ";", "return", "isset", "(", "$", "mainSiblings", "[", "$", "index", "]", ")", "?", "(", "int", ")", "$", "mainSiblings", "[", "$", "index", "]", "[", "'id'", "]", ":", "null", ";", "}" ]
Determine the mapping for the passed index. @param int $index The index to look up. @param int $parentId The parent id. @param array $inverseList The reverse lookup list. @return int|null @throws \InvalidArgumentException When the parent page has not been mapped.
[ "Determine", "the", "mapping", "for", "the", "passed", "index", "." ]
038cf6ea9c609a734d7476fba256bc4b0db236b7
https://github.com/cyberspectrum/i18n-contao/blob/038cf6ea9c609a734d7476fba256bc4b0db236b7/src/Mapping/Terminal42ChangeLanguage/PageMap.php#L211-L223
train
skck/SbkCronBundle
Cron/Task.php
Task.getCommandToExecute
public function getCommandToExecute() { $command = implode( " ", array( $this->bin, $this->script, $this->command, ) ); return trim(preg_replace('/\s+/', ' ', $command)); }
php
public function getCommandToExecute() { $command = implode( " ", array( $this->bin, $this->script, $this->command, ) ); return trim(preg_replace('/\s+/', ' ', $command)); }
[ "public", "function", "getCommandToExecute", "(", ")", "{", "$", "command", "=", "implode", "(", "\" \"", ",", "array", "(", "$", "this", "->", "bin", ",", "$", "this", "->", "script", ",", "$", "this", "->", "command", ",", ")", ")", ";", "return", "trim", "(", "preg_replace", "(", "'/\\s+/'", ",", "' '", ",", "$", "command", ")", ")", ";", "}" ]
Returns the executable command for the task instance @return string
[ "Returns", "the", "executable", "command", "for", "the", "task", "instance" ]
9a3d2bedfcee76587691a19abc7c25e62039d440
https://github.com/skck/SbkCronBundle/blob/9a3d2bedfcee76587691a19abc7c25e62039d440/Cron/Task.php#L150-L161
train
stonedz/pff2
src/Core/ViewPHP.php
ViewPHP.preView
public function preView($output) { /** @var $purifierConfig \HTMLPurifier_Config */ $purifierConfig = \HTMLPurifier_Config::createDefault(); $purifierConfig->set('Core.Encoding', 'UTF-8'); $purifierConfig->set('HTML.TidyLevel', 'medium'); /** @var \HTMLPurifier_Config $purifierConfig */ $purifier = new \HTMLPurifier($purifierConfig); $output = $purifier->purify($output); return $output; }
php
public function preView($output) { /** @var $purifierConfig \HTMLPurifier_Config */ $purifierConfig = \HTMLPurifier_Config::createDefault(); $purifierConfig->set('Core.Encoding', 'UTF-8'); $purifierConfig->set('HTML.TidyLevel', 'medium'); /** @var \HTMLPurifier_Config $purifierConfig */ $purifier = new \HTMLPurifier($purifierConfig); $output = $purifier->purify($output); return $output; }
[ "public", "function", "preView", "(", "$", "output", ")", "{", "/** @var $purifierConfig \\HTMLPurifier_Config */", "$", "purifierConfig", "=", "\\", "HTMLPurifier_Config", "::", "createDefault", "(", ")", ";", "$", "purifierConfig", "->", "set", "(", "'Core.Encoding'", ",", "'UTF-8'", ")", ";", "$", "purifierConfig", "->", "set", "(", "'HTML.TidyLevel'", ",", "'medium'", ")", ";", "/** @var \\HTMLPurifier_Config $purifierConfig */", "$", "purifier", "=", "new", "\\", "HTMLPurifier", "(", "$", "purifierConfig", ")", ";", "$", "output", "=", "$", "purifier", "->", "purify", "(", "$", "output", ")", ";", "return", "$", "output", ";", "}" ]
Callback method to sanitize HTML output @param string $output HTML output string @return string
[ "Callback", "method", "to", "sanitize", "HTML", "output" ]
ec3b087d4d4732816f61ac487f0cb25511e0da88
https://github.com/stonedz/pff2/blob/ec3b087d4d4732816f61ac487f0cb25511e0da88/src/Core/ViewPHP.php#L70-L81
train
phavour/phavour
Phavour/Auth/Service.php
Service.login
public function login() { $result = $this->adapter->getResult(); if ($result === self::PHAVOUR_AUTH_SERVICE_SUCCESS) { $auth = Auth::getInstance(); $auth->login($this->adapter->getIdentity()); $auth->setRoles($this->adapter->getRoles()); return true; } elseif ($result === self::PHAVOUR_AUTH_SERVICE_INVALID) { throw new InvalidCredentialsException('Invalid credentials exception'); } throw new UnrecognisedAuthenticationResultException('Expected 1 or 2'); }
php
public function login() { $result = $this->adapter->getResult(); if ($result === self::PHAVOUR_AUTH_SERVICE_SUCCESS) { $auth = Auth::getInstance(); $auth->login($this->adapter->getIdentity()); $auth->setRoles($this->adapter->getRoles()); return true; } elseif ($result === self::PHAVOUR_AUTH_SERVICE_INVALID) { throw new InvalidCredentialsException('Invalid credentials exception'); } throw new UnrecognisedAuthenticationResultException('Expected 1 or 2'); }
[ "public", "function", "login", "(", ")", "{", "$", "result", "=", "$", "this", "->", "adapter", "->", "getResult", "(", ")", ";", "if", "(", "$", "result", "===", "self", "::", "PHAVOUR_AUTH_SERVICE_SUCCESS", ")", "{", "$", "auth", "=", "Auth", "::", "getInstance", "(", ")", ";", "$", "auth", "->", "login", "(", "$", "this", "->", "adapter", "->", "getIdentity", "(", ")", ")", ";", "$", "auth", "->", "setRoles", "(", "$", "this", "->", "adapter", "->", "getRoles", "(", ")", ")", ";", "return", "true", ";", "}", "elseif", "(", "$", "result", "===", "self", "::", "PHAVOUR_AUTH_SERVICE_INVALID", ")", "{", "throw", "new", "InvalidCredentialsException", "(", "'Invalid credentials exception'", ")", ";", "}", "throw", "new", "UnrecognisedAuthenticationResultException", "(", "'Expected 1 or 2'", ")", ";", "}" ]
Log a user in using the given adapter from the construct @throws InvalidCredentialsException @throws UnrecognisedAuthenticationResultException @return boolean|throws
[ "Log", "a", "user", "in", "using", "the", "given", "adapter", "from", "the", "construct" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Auth/Service.php#L77-L92
train
deweller/php-cliopts
src/CLIOpts/Help/HelpGenerator.php
HelpGenerator.build
public function build() { $options_data = $this->buildOptionsData(); $out_text = $this->buildUsageLine($this->arguments_spec->getUsage(), $options_data); $options_text = ''; if ($options_data['lines']) { foreach($options_data['lines'] as $option_line_data) { $options_text .= $this->buildOptionLine($option_line_data, $options_data)."\n"; } $out_text .= "\n". ConsoleFormat::applyformatToText('bold','cyan','Options:')."\n". $options_text; } return $out_text; }
php
public function build() { $options_data = $this->buildOptionsData(); $out_text = $this->buildUsageLine($this->arguments_spec->getUsage(), $options_data); $options_text = ''; if ($options_data['lines']) { foreach($options_data['lines'] as $option_line_data) { $options_text .= $this->buildOptionLine($option_line_data, $options_data)."\n"; } $out_text .= "\n". ConsoleFormat::applyformatToText('bold','cyan','Options:')."\n". $options_text; } return $out_text; }
[ "public", "function", "build", "(", ")", "{", "$", "options_data", "=", "$", "this", "->", "buildOptionsData", "(", ")", ";", "$", "out_text", "=", "$", "this", "->", "buildUsageLine", "(", "$", "this", "->", "arguments_spec", "->", "getUsage", "(", ")", ",", "$", "options_data", ")", ";", "$", "options_text", "=", "''", ";", "if", "(", "$", "options_data", "[", "'lines'", "]", ")", "{", "foreach", "(", "$", "options_data", "[", "'lines'", "]", "as", "$", "option_line_data", ")", "{", "$", "options_text", ".=", "$", "this", "->", "buildOptionLine", "(", "$", "option_line_data", ",", "$", "options_data", ")", ".", "\"\\n\"", ";", "}", "$", "out_text", ".=", "\"\\n\"", ".", "ConsoleFormat", "::", "applyformatToText", "(", "'bold'", ",", "'cyan'", ",", "'Options:'", ")", ".", "\"\\n\"", ".", "$", "options_text", ";", "}", "return", "$", "out_text", ";", "}" ]
Builds nicely formatted help text @return string formatted help text
[ "Builds", "nicely", "formatted", "help", "text" ]
1923f3a7ad24062c6279c725579ff3af15141dec
https://github.com/deweller/php-cliopts/blob/1923f3a7ad24062c6279c725579ff3af15141dec/src/CLIOpts/Help/HelpGenerator.php#L62-L81
train
deweller/php-cliopts
src/CLIOpts/Help/HelpGenerator.php
HelpGenerator.buildUsageLine
protected function buildUsageLine($usage_data, $options_data) { if ($usage_data['use_argv_self']) { $self_name = $_SERVER['argv'][0]; } else { $self_name = $usage_data['self']; } $has_options = (count($options_data['lines']) > 0 ? true : false); $has_named_args = (count($usage_data['named_args_spec']) > 0 ? true : false); $out = ConsoleFormat::applyformatToText('bold','cyan',"Usage:")."\n". " {$self_name}". ($has_options ? ' [options]' : ''). ($has_named_args ? ' '.$this->generateValueNamesHelp($usage_data['named_args_spec']) : ''). "\n"; return $out; }
php
protected function buildUsageLine($usage_data, $options_data) { if ($usage_data['use_argv_self']) { $self_name = $_SERVER['argv'][0]; } else { $self_name = $usage_data['self']; } $has_options = (count($options_data['lines']) > 0 ? true : false); $has_named_args = (count($usage_data['named_args_spec']) > 0 ? true : false); $out = ConsoleFormat::applyformatToText('bold','cyan',"Usage:")."\n". " {$self_name}". ($has_options ? ' [options]' : ''). ($has_named_args ? ' '.$this->generateValueNamesHelp($usage_data['named_args_spec']) : ''). "\n"; return $out; }
[ "protected", "function", "buildUsageLine", "(", "$", "usage_data", ",", "$", "options_data", ")", "{", "if", "(", "$", "usage_data", "[", "'use_argv_self'", "]", ")", "{", "$", "self_name", "=", "$", "_SERVER", "[", "'argv'", "]", "[", "0", "]", ";", "}", "else", "{", "$", "self_name", "=", "$", "usage_data", "[", "'self'", "]", ";", "}", "$", "has_options", "=", "(", "count", "(", "$", "options_data", "[", "'lines'", "]", ")", ">", "0", "?", "true", ":", "false", ")", ";", "$", "has_named_args", "=", "(", "count", "(", "$", "usage_data", "[", "'named_args_spec'", "]", ")", ">", "0", "?", "true", ":", "false", ")", ";", "$", "out", "=", "ConsoleFormat", "::", "applyformatToText", "(", "'bold'", ",", "'cyan'", ",", "\"Usage:\"", ")", ".", "\"\\n\"", ".", "\" {$self_name}\"", ".", "(", "$", "has_options", "?", "' [options]'", ":", "''", ")", ".", "(", "$", "has_named_args", "?", "' '", ".", "$", "this", "->", "generateValueNamesHelp", "(", "$", "usage_data", "[", "'named_args_spec'", "]", ")", ":", "''", ")", ".", "\"\\n\"", ";", "return", "$", "out", ";", "}" ]
builds the usage line @param array $usage_data Usage line specification data @param array $options_data Options specification data @return string formatted usage line text
[ "builds", "the", "usage", "line" ]
1923f3a7ad24062c6279c725579ff3af15141dec
https://github.com/deweller/php-cliopts/blob/1923f3a7ad24062c6279c725579ff3af15141dec/src/CLIOpts/Help/HelpGenerator.php#L97-L115
train
deweller/php-cliopts
src/CLIOpts/Help/HelpGenerator.php
HelpGenerator.buildOptionLine
protected function buildOptionLine($option_line_data, $options_data) { $padding = $options_data['padding']; $required = $option_line_data['spec']['required']; $out = str_pad($option_line_data['switch_text'], $padding); $out .= (strlen($option_line_data['spec']['help']) ? ' '.$option_line_data['spec']['help'] : ''); $out .= ($required ? ' (required)' : ''); // surround in bold if required if ($required) { $out = ConsoleFormat::applyformatToText('bold','yellow',$out); } return ' '.$out; }
php
protected function buildOptionLine($option_line_data, $options_data) { $padding = $options_data['padding']; $required = $option_line_data['spec']['required']; $out = str_pad($option_line_data['switch_text'], $padding); $out .= (strlen($option_line_data['spec']['help']) ? ' '.$option_line_data['spec']['help'] : ''); $out .= ($required ? ' (required)' : ''); // surround in bold if required if ($required) { $out = ConsoleFormat::applyformatToText('bold','yellow',$out); } return ' '.$out; }
[ "protected", "function", "buildOptionLine", "(", "$", "option_line_data", ",", "$", "options_data", ")", "{", "$", "padding", "=", "$", "options_data", "[", "'padding'", "]", ";", "$", "required", "=", "$", "option_line_data", "[", "'spec'", "]", "[", "'required'", "]", ";", "$", "out", "=", "str_pad", "(", "$", "option_line_data", "[", "'switch_text'", "]", ",", "$", "padding", ")", ";", "$", "out", ".=", "(", "strlen", "(", "$", "option_line_data", "[", "'spec'", "]", "[", "'help'", "]", ")", "?", "' '", ".", "$", "option_line_data", "[", "'spec'", "]", "[", "'help'", "]", ":", "''", ")", ";", "$", "out", ".=", "(", "$", "required", "?", "' (required)'", ":", "''", ")", ";", "// surround in bold if required", "if", "(", "$", "required", ")", "{", "$", "out", "=", "ConsoleFormat", "::", "applyformatToText", "(", "'bold'", ",", "'yellow'", ",", "$", "out", ")", ";", "}", "return", "' '", ".", "$", "out", ";", "}" ]
builds an option line @param array $option_line_data Option line specification data @param array $options_data All options specification data @return string formatted option line text
[ "builds", "an", "option", "line" ]
1923f3a7ad24062c6279c725579ff3af15141dec
https://github.com/deweller/php-cliopts/blob/1923f3a7ad24062c6279c725579ff3af15141dec/src/CLIOpts/Help/HelpGenerator.php#L125-L140
train
deweller/php-cliopts
src/CLIOpts/Help/HelpGenerator.php
HelpGenerator.generateValueNamesHelp
protected function generateValueNamesHelp($named_args_spec) { $first = true; $out = ''; foreach($named_args_spec as $named_arg_spec) { $out .= ($first ? '' : ' '); if ($named_arg_spec['required']) { $out .= ConsoleFormat::applyformatToText('bold','yellow','<'.$named_arg_spec['name'].'>'); } else { $out .= '[<'.$named_arg_spec['name'].'>]'; } $first = false; } return $out; }
php
protected function generateValueNamesHelp($named_args_spec) { $first = true; $out = ''; foreach($named_args_spec as $named_arg_spec) { $out .= ($first ? '' : ' '); if ($named_arg_spec['required']) { $out .= ConsoleFormat::applyformatToText('bold','yellow','<'.$named_arg_spec['name'].'>'); } else { $out .= '[<'.$named_arg_spec['name'].'>]'; } $first = false; } return $out; }
[ "protected", "function", "generateValueNamesHelp", "(", "$", "named_args_spec", ")", "{", "$", "first", "=", "true", ";", "$", "out", "=", "''", ";", "foreach", "(", "$", "named_args_spec", "as", "$", "named_arg_spec", ")", "{", "$", "out", ".=", "(", "$", "first", "?", "''", ":", "' '", ")", ";", "if", "(", "$", "named_arg_spec", "[", "'required'", "]", ")", "{", "$", "out", ".=", "ConsoleFormat", "::", "applyformatToText", "(", "'bold'", ",", "'yellow'", ",", "'<'", ".", "$", "named_arg_spec", "[", "'name'", "]", ".", "'>'", ")", ";", "}", "else", "{", "$", "out", ".=", "'[<'", ".", "$", "named_arg_spec", "[", "'name'", "]", ".", "'>]'", ";", "}", "$", "first", "=", "false", ";", "}", "return", "$", "out", ";", "}" ]
gerenates the value names in the usage line @param array $named_args_spec value names specifications @return mixed Value.
[ "gerenates", "the", "value", "names", "in", "the", "usage", "line" ]
1923f3a7ad24062c6279c725579ff3af15141dec
https://github.com/deweller/php-cliopts/blob/1923f3a7ad24062c6279c725579ff3af15141dec/src/CLIOpts/Help/HelpGenerator.php#L150-L167
train
deweller/php-cliopts
src/CLIOpts/Help/HelpGenerator.php
HelpGenerator.buildOptionsData
protected function buildOptionsData() { $options_data = array( 'lines' => array(), 'padding' => 0, ); // build the lines foreach($this->arguments_spec as $option_line_spec) { $options_data['lines'][] = $this->buildOptionLineData($option_line_spec); } // calculate padding $options_data['padding'] = $this->buildSwitchTextPaddingLength($options_data); return $options_data; }
php
protected function buildOptionsData() { $options_data = array( 'lines' => array(), 'padding' => 0, ); // build the lines foreach($this->arguments_spec as $option_line_spec) { $options_data['lines'][] = $this->buildOptionLineData($option_line_spec); } // calculate padding $options_data['padding'] = $this->buildSwitchTextPaddingLength($options_data); return $options_data; }
[ "protected", "function", "buildOptionsData", "(", ")", "{", "$", "options_data", "=", "array", "(", "'lines'", "=>", "array", "(", ")", ",", "'padding'", "=>", "0", ",", ")", ";", "// build the lines", "foreach", "(", "$", "this", "->", "arguments_spec", "as", "$", "option_line_spec", ")", "{", "$", "options_data", "[", "'lines'", "]", "[", "]", "=", "$", "this", "->", "buildOptionLineData", "(", "$", "option_line_spec", ")", ";", "}", "// calculate padding", "$", "options_data", "[", "'padding'", "]", "=", "$", "this", "->", "buildSwitchTextPaddingLength", "(", "$", "options_data", ")", ";", "return", "$", "options_data", ";", "}" ]
builds options data from the arguments spec @return array Options data
[ "builds", "options", "data", "from", "the", "arguments", "spec" ]
1923f3a7ad24062c6279c725579ff3af15141dec
https://github.com/deweller/php-cliopts/blob/1923f3a7ad24062c6279c725579ff3af15141dec/src/CLIOpts/Help/HelpGenerator.php#L174-L189
train
deweller/php-cliopts
src/CLIOpts/Help/HelpGenerator.php
HelpGenerator.buildOptionLineData
protected function buildOptionLineData($option_line_spec) { $data = array(); $switch_text = ''; if (strlen($option_line_spec['short'])) { $switch_text .= "-".$option_line_spec['short']; } if (strlen($option_line_spec['long'])) { $switch_text .= ($switch_text ? ", " : "")."--".$option_line_spec['long']; } $data = array( 'switch_text' => $switch_text.(strlen($option_line_spec['value_name']) ? ' <'.$option_line_spec['value_name'].'>' : ''), 'spec' => $option_line_spec, ); return $data; }
php
protected function buildOptionLineData($option_line_spec) { $data = array(); $switch_text = ''; if (strlen($option_line_spec['short'])) { $switch_text .= "-".$option_line_spec['short']; } if (strlen($option_line_spec['long'])) { $switch_text .= ($switch_text ? ", " : "")."--".$option_line_spec['long']; } $data = array( 'switch_text' => $switch_text.(strlen($option_line_spec['value_name']) ? ' <'.$option_line_spec['value_name'].'>' : ''), 'spec' => $option_line_spec, ); return $data; }
[ "protected", "function", "buildOptionLineData", "(", "$", "option_line_spec", ")", "{", "$", "data", "=", "array", "(", ")", ";", "$", "switch_text", "=", "''", ";", "if", "(", "strlen", "(", "$", "option_line_spec", "[", "'short'", "]", ")", ")", "{", "$", "switch_text", ".=", "\"-\"", ".", "$", "option_line_spec", "[", "'short'", "]", ";", "}", "if", "(", "strlen", "(", "$", "option_line_spec", "[", "'long'", "]", ")", ")", "{", "$", "switch_text", ".=", "(", "$", "switch_text", "?", "\", \"", ":", "\"\"", ")", ".", "\"--\"", ".", "$", "option_line_spec", "[", "'long'", "]", ";", "}", "$", "data", "=", "array", "(", "'switch_text'", "=>", "$", "switch_text", ".", "(", "strlen", "(", "$", "option_line_spec", "[", "'value_name'", "]", ")", "?", "' <'", ".", "$", "option_line_spec", "[", "'value_name'", "]", ".", "'>'", ":", "''", ")", ",", "'spec'", "=>", "$", "option_line_spec", ",", ")", ";", "return", "$", "data", ";", "}" ]
builds a line of options data from a line of the argument spec @param array $option_line_spec Data of argument specification representing an options line @return mixed Value.
[ "builds", "a", "line", "of", "options", "data", "from", "a", "line", "of", "the", "argument", "spec" ]
1923f3a7ad24062c6279c725579ff3af15141dec
https://github.com/deweller/php-cliopts/blob/1923f3a7ad24062c6279c725579ff3af15141dec/src/CLIOpts/Help/HelpGenerator.php#L198-L215
train
deweller/php-cliopts
src/CLIOpts/Help/HelpGenerator.php
HelpGenerator.buildSwitchTextPaddingLength
protected function buildSwitchTextPaddingLength($options_data) { $padding_len = 0; foreach($options_data['lines'] as $option_line_data) { $padding_len = max($padding_len, strlen($option_line_data['switch_text'])); } return $padding_len; }
php
protected function buildSwitchTextPaddingLength($options_data) { $padding_len = 0; foreach($options_data['lines'] as $option_line_data) { $padding_len = max($padding_len, strlen($option_line_data['switch_text'])); } return $padding_len; }
[ "protected", "function", "buildSwitchTextPaddingLength", "(", "$", "options_data", ")", "{", "$", "padding_len", "=", "0", ";", "foreach", "(", "$", "options_data", "[", "'lines'", "]", "as", "$", "option_line_data", ")", "{", "$", "padding_len", "=", "max", "(", "$", "padding_len", ",", "strlen", "(", "$", "option_line_data", "[", "'switch_text'", "]", ")", ")", ";", "}", "return", "$", "padding_len", ";", "}" ]
calculates the maximum padding for all options @param mixed $options_data Description. @return int padding length
[ "calculates", "the", "maximum", "padding", "for", "all", "options" ]
1923f3a7ad24062c6279c725579ff3af15141dec
https://github.com/deweller/php-cliopts/blob/1923f3a7ad24062c6279c725579ff3af15141dec/src/CLIOpts/Help/HelpGenerator.php#L225-L231
train
harp-orm/harp
src/Model/Models.php
Models.addObjects
public function addObjects(SplObjectStorage $models) { foreach ($models as $model) { $this->add($model); } return $this; }
php
public function addObjects(SplObjectStorage $models) { foreach ($models as $model) { $this->add($model); } return $this; }
[ "public", "function", "addObjects", "(", "SplObjectStorage", "$", "models", ")", "{", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "$", "this", "->", "add", "(", "$", "model", ")", ";", "}", "return", "$", "this", ";", "}" ]
Link all models from the SplObjectStorage @param SplObjectStorage $models @return Models $this
[ "Link", "all", "models", "from", "the", "SplObjectStorage" ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Model/Models.php#L50-L57
train
harp-orm/harp
src/Model/Models.php
Models.addAll
public function addAll(Models $other) { if ($other->count() > 0) { $this->models->addAll($other->models); } return $this; }
php
public function addAll(Models $other) { if ($other->count() > 0) { $this->models->addAll($other->models); } return $this; }
[ "public", "function", "addAll", "(", "Models", "$", "other", ")", "{", "if", "(", "$", "other", "->", "count", "(", ")", ">", "0", ")", "{", "$", "this", "->", "models", "->", "addAll", "(", "$", "other", "->", "models", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add all models from a different Models collection @param Models $other
[ "Add", "all", "models", "from", "a", "different", "Models", "collection" ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Model/Models.php#L64-L71
train
harp-orm/harp
src/Model/Models.php
Models.sort
public function sort(Closure $closure) { $sorted = clone $this; $sorted->models = Objects::sort($sorted->models, $closure); return $sorted; }
php
public function sort(Closure $closure) { $sorted = clone $this; $sorted->models = Objects::sort($sorted->models, $closure); return $sorted; }
[ "public", "function", "sort", "(", "Closure", "$", "closure", ")", "{", "$", "sorted", "=", "clone", "$", "this", ";", "$", "sorted", "->", "models", "=", "Objects", "::", "sort", "(", "$", "sorted", "->", "models", ",", "$", "closure", ")", ";", "return", "$", "sorted", ";", "}" ]
Sort the models collection using a comparation closure @param Closure $closure @return array
[ "Sort", "the", "models", "collection", "using", "a", "comparation", "closure" ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Model/Models.php#L236-L243
train
harp-orm/harp
src/Model/Models.php
Models.byRepo
public function byRepo(Closure $yield) { $repos = Objects::groupBy($this->models, function (AbstractModel $model) { return $model->getRepo()->getRootRepo(); }); foreach ($repos as $repo) { $models = new Models(); $models->addObjects($repos->getInfo()); $yield($repo, $models); } }
php
public function byRepo(Closure $yield) { $repos = Objects::groupBy($this->models, function (AbstractModel $model) { return $model->getRepo()->getRootRepo(); }); foreach ($repos as $repo) { $models = new Models(); $models->addObjects($repos->getInfo()); $yield($repo, $models); } }
[ "public", "function", "byRepo", "(", "Closure", "$", "yield", ")", "{", "$", "repos", "=", "Objects", "::", "groupBy", "(", "$", "this", "->", "models", ",", "function", "(", "AbstractModel", "$", "model", ")", "{", "return", "$", "model", "->", "getRepo", "(", ")", "->", "getRootRepo", "(", ")", ";", "}", ")", ";", "foreach", "(", "$", "repos", "as", "$", "repo", ")", "{", "$", "models", "=", "new", "Models", "(", ")", ";", "$", "models", "->", "addObjects", "(", "$", "repos", "->", "getInfo", "(", ")", ")", ";", "$", "yield", "(", "$", "repo", ",", "$", "models", ")", ";", "}", "}" ]
Group models by repo, call yield for each repo @param Closure $yield Call for each repo ($repo, $models)
[ "Group", "models", "by", "repo", "call", "yield", "for", "each", "repo" ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Model/Models.php#L272-L284
train
harp-orm/harp
src/Model/Models.php
Models.pluckProperty
public function pluckProperty($property) { $values = []; foreach ($this->models as $model) { $values []= $model->$property; } return $values; }
php
public function pluckProperty($property) { $values = []; foreach ($this->models as $model) { $values []= $model->$property; } return $values; }
[ "public", "function", "pluckProperty", "(", "$", "property", ")", "{", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "models", "as", "$", "model", ")", "{", "$", "values", "[", "]", "=", "$", "model", "->", "$", "property", ";", "}", "return", "$", "values", ";", "}" ]
Return the value of a property for each model @param string $property @return array
[ "Return", "the", "value", "of", "a", "property", "for", "each", "model" ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Model/Models.php#L292-L301
train
harp-orm/harp
src/Model/Models.php
Models.isEmptyProperty
public function isEmptyProperty($property) { foreach ($this->models as $model) { if ($model->$property) { return false; } } return true; }
php
public function isEmptyProperty($property) { foreach ($this->models as $model) { if ($model->$property) { return false; } } return true; }
[ "public", "function", "isEmptyProperty", "(", "$", "property", ")", "{", "foreach", "(", "$", "this", "->", "models", "as", "$", "model", ")", "{", "if", "(", "$", "model", "->", "$", "property", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Return false if there is at least one non-empty property of a model. @param string $property @return boolean
[ "Return", "false", "if", "there", "is", "at", "least", "one", "non", "-", "empty", "property", "of", "a", "model", "." ]
e0751696521164c86ccd0a76d708df490efd8306
https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Model/Models.php#L309-L318
train
bennybi/yii2-cza-base
components/utils/Naming.php
Naming.toSplit
public function toSplit($name, $splitor = '-', $to = self::LOWER) { switch ($to) { case self::UPPER: return strtoupper(preg_replace("/(.)([A-Z])/", "$1{$splitor}$2", $name)); default: return strtolower(preg_replace("/(.)([A-Z])/", "$1{$splitor}$2", $name)); } }
php
public function toSplit($name, $splitor = '-', $to = self::LOWER) { switch ($to) { case self::UPPER: return strtoupper(preg_replace("/(.)([A-Z])/", "$1{$splitor}$2", $name)); default: return strtolower(preg_replace("/(.)([A-Z])/", "$1{$splitor}$2", $name)); } }
[ "public", "function", "toSplit", "(", "$", "name", ",", "$", "splitor", "=", "'-'", ",", "$", "to", "=", "self", "::", "LOWER", ")", "{", "switch", "(", "$", "to", ")", "{", "case", "self", "::", "UPPER", ":", "return", "strtoupper", "(", "preg_replace", "(", "\"/(.)([A-Z])/\"", ",", "\"$1{$splitor}$2\"", ",", "$", "name", ")", ")", ";", "default", ":", "return", "strtolower", "(", "preg_replace", "(", "\"/(.)([A-Z])/\"", ",", "\"$1{$splitor}$2\"", ",", "$", "name", ")", ")", ";", "}", "}" ]
usage example. CmsPageSort => cms-page-sort @param type $name @param type $splitor @param type $to @return type
[ "usage", "example", ".", "CmsPageSort", "=", ">", "cms", "-", "page", "-", "sort" ]
8257db8034bd948712fa469062921f210f0ba8da
https://github.com/bennybi/yii2-cza-base/blob/8257db8034bd948712fa469062921f210f0ba8da/components/utils/Naming.php#L30-L37
train
pmdevelopment/tool-bundle
Components/Helper/ObjectHelper.php
ObjectHelper.getConstantValuesByPrefix
public static function getConstantValuesByPrefix($className, $prefix) { $prefixLength = strlen($prefix); $result = []; $reflection = new \ReflectionClass($className); foreach ($reflection->getConstants() as $constKey => $constValue) { if ($prefix === substr($constKey, 0, $prefixLength)) { $result[] = $constValue; } } return $result; }
php
public static function getConstantValuesByPrefix($className, $prefix) { $prefixLength = strlen($prefix); $result = []; $reflection = new \ReflectionClass($className); foreach ($reflection->getConstants() as $constKey => $constValue) { if ($prefix === substr($constKey, 0, $prefixLength)) { $result[] = $constValue; } } return $result; }
[ "public", "static", "function", "getConstantValuesByPrefix", "(", "$", "className", ",", "$", "prefix", ")", "{", "$", "prefixLength", "=", "strlen", "(", "$", "prefix", ")", ";", "$", "result", "=", "[", "]", ";", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "className", ")", ";", "foreach", "(", "$", "reflection", "->", "getConstants", "(", ")", "as", "$", "constKey", "=>", "$", "constValue", ")", "{", "if", "(", "$", "prefix", "===", "substr", "(", "$", "constKey", ",", "0", ",", "$", "prefixLength", ")", ")", "{", "$", "result", "[", "]", "=", "$", "constValue", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get Contant Values By Prefix @param string $className @param string $prefix @return array
[ "Get", "Contant", "Values", "By", "Prefix" ]
2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129
https://github.com/pmdevelopment/tool-bundle/blob/2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129/Components/Helper/ObjectHelper.php#L27-L40
train
BenGorFile/FileBundle
src/BenGorFile/FileBundle/Form/Type/FileType.php
FileType.emptyData
public function emptyData(FormInterface $form) { $file = $form->get('bengor_file')->getData(); if (null === $file) { return; } return new UploadFileCommand( $file->getClientOriginalName(), file_get_contents($file->getPathname()), $file->getMimeType() ); }
php
public function emptyData(FormInterface $form) { $file = $form->get('bengor_file')->getData(); if (null === $file) { return; } return new UploadFileCommand( $file->getClientOriginalName(), file_get_contents($file->getPathname()), $file->getMimeType() ); }
[ "public", "function", "emptyData", "(", "FormInterface", "$", "form", ")", "{", "$", "file", "=", "$", "form", "->", "get", "(", "'bengor_file'", ")", "->", "getData", "(", ")", ";", "if", "(", "null", "===", "$", "file", ")", "{", "return", ";", "}", "return", "new", "UploadFileCommand", "(", "$", "file", "->", "getClientOriginalName", "(", ")", ",", "file_get_contents", "(", "$", "file", "->", "getPathname", "(", ")", ")", ",", "$", "file", "->", "getMimeType", "(", ")", ")", ";", "}" ]
Method that encapsulates all the logic of build empty data. It returns an instance of data class object. @param FormInterface $form The form @return UploadFileCommand|null
[ "Method", "that", "encapsulates", "all", "the", "logic", "of", "build", "empty", "data", ".", "It", "returns", "an", "instance", "of", "data", "class", "object", "." ]
82c1fa952e7e7b7a188141a34053ab612b699a21
https://github.com/BenGorFile/FileBundle/blob/82c1fa952e7e7b7a188141a34053ab612b699a21/src/BenGorFile/FileBundle/Form/Type/FileType.php#L75-L87
train
issei-m/spike-php
src/Util/DateTimeUtil.php
DateTimeUtil.createDateTimeByUnixTime
public function createDateTimeByUnixTime($unixTime) { $dateTime = new \DateTime('@' . $unixTime); $dateTime->setTimezone($this->specifiedTimeZone); return $dateTime; }
php
public function createDateTimeByUnixTime($unixTime) { $dateTime = new \DateTime('@' . $unixTime); $dateTime->setTimezone($this->specifiedTimeZone); return $dateTime; }
[ "public", "function", "createDateTimeByUnixTime", "(", "$", "unixTime", ")", "{", "$", "dateTime", "=", "new", "\\", "DateTime", "(", "'@'", ".", "$", "unixTime", ")", ";", "$", "dateTime", "->", "setTimezone", "(", "$", "this", "->", "specifiedTimeZone", ")", ";", "return", "$", "dateTime", ";", "}" ]
Returns the created DateTime object specified the timezone. @param $unixTime @return \DateTime
[ "Returns", "the", "created", "DateTime", "object", "specified", "the", "timezone", "." ]
9205b5047a1132bcdca6731feac02fe3d5dc1023
https://github.com/issei-m/spike-php/blob/9205b5047a1132bcdca6731feac02fe3d5dc1023/src/Util/DateTimeUtil.php#L26-L32
train
interactivesolutions/honeycomb-scripts
src/app/commands/service/HCServiceController.php
HCServiceController.createMultiLanguageController
private function createMultiLanguageController(stdClass $data) { $this->createFileFromTemplate([ "destination" => $data->controllerDestination, "templateDestination" => __DIR__ . '/../templates/service/controller/multiLanguage.hctpl', "content" => [ "namespace" => $data->controllerNamespace, "controllerName" => $data->controllerName, "acl_prefix" => $data->aclPrefix, "serviceURL" => $data->serviceURL, "translationsLocation" => $data->translationsLocation, "serviceNameDotted" => $this->stringWithDash($data->translationFilePrefix), "controllerNameDotted" => $data->serviceRouteName, "adminListHeader" => $this->getAdminListHeader($data), "formValidationName" => $data->formValidationName, "translationsFormValidationName" => $data->formTranslationsValidationName, "functions" => replaceBrackets(file_get_contents(__DIR__ . '/../templates/service/controller/multilanguage/functions.hctpl'), [ "modelName" => $data->mainModel->modelName, "modelNameSpace" => $data->modelNamespace, ]), "inputData" => $this->getInputData($data), "useFiles" => $this->getUseFiles($data, true), "mainModelName" => $data->mainModel->modelName, "searchableFields" => $this->getSearchableFields($data), "searchableFieldsTranslations" => $this->getSearchableFields($data, true), ], ]); return $data->controllerDestination; }
php
private function createMultiLanguageController(stdClass $data) { $this->createFileFromTemplate([ "destination" => $data->controllerDestination, "templateDestination" => __DIR__ . '/../templates/service/controller/multiLanguage.hctpl', "content" => [ "namespace" => $data->controllerNamespace, "controllerName" => $data->controllerName, "acl_prefix" => $data->aclPrefix, "serviceURL" => $data->serviceURL, "translationsLocation" => $data->translationsLocation, "serviceNameDotted" => $this->stringWithDash($data->translationFilePrefix), "controllerNameDotted" => $data->serviceRouteName, "adminListHeader" => $this->getAdminListHeader($data), "formValidationName" => $data->formValidationName, "translationsFormValidationName" => $data->formTranslationsValidationName, "functions" => replaceBrackets(file_get_contents(__DIR__ . '/../templates/service/controller/multilanguage/functions.hctpl'), [ "modelName" => $data->mainModel->modelName, "modelNameSpace" => $data->modelNamespace, ]), "inputData" => $this->getInputData($data), "useFiles" => $this->getUseFiles($data, true), "mainModelName" => $data->mainModel->modelName, "searchableFields" => $this->getSearchableFields($data), "searchableFieldsTranslations" => $this->getSearchableFields($data, true), ], ]); return $data->controllerDestination; }
[ "private", "function", "createMultiLanguageController", "(", "stdClass", "$", "data", ")", "{", "$", "this", "->", "createFileFromTemplate", "(", "[", "\"destination\"", "=>", "$", "data", "->", "controllerDestination", ",", "\"templateDestination\"", "=>", "__DIR__", ".", "'/../templates/service/controller/multiLanguage.hctpl'", ",", "\"content\"", "=>", "[", "\"namespace\"", "=>", "$", "data", "->", "controllerNamespace", ",", "\"controllerName\"", "=>", "$", "data", "->", "controllerName", ",", "\"acl_prefix\"", "=>", "$", "data", "->", "aclPrefix", ",", "\"serviceURL\"", "=>", "$", "data", "->", "serviceURL", ",", "\"translationsLocation\"", "=>", "$", "data", "->", "translationsLocation", ",", "\"serviceNameDotted\"", "=>", "$", "this", "->", "stringWithDash", "(", "$", "data", "->", "translationFilePrefix", ")", ",", "\"controllerNameDotted\"", "=>", "$", "data", "->", "serviceRouteName", ",", "\"adminListHeader\"", "=>", "$", "this", "->", "getAdminListHeader", "(", "$", "data", ")", ",", "\"formValidationName\"", "=>", "$", "data", "->", "formValidationName", ",", "\"translationsFormValidationName\"", "=>", "$", "data", "->", "formTranslationsValidationName", ",", "\"functions\"", "=>", "replaceBrackets", "(", "file_get_contents", "(", "__DIR__", ".", "'/../templates/service/controller/multilanguage/functions.hctpl'", ")", ",", "[", "\"modelName\"", "=>", "$", "data", "->", "mainModel", "->", "modelName", ",", "\"modelNameSpace\"", "=>", "$", "data", "->", "modelNamespace", ",", "]", ")", ",", "\"inputData\"", "=>", "$", "this", "->", "getInputData", "(", "$", "data", ")", ",", "\"useFiles\"", "=>", "$", "this", "->", "getUseFiles", "(", "$", "data", ",", "true", ")", ",", "\"mainModelName\"", "=>", "$", "data", "->", "mainModel", "->", "modelName", ",", "\"searchableFields\"", "=>", "$", "this", "->", "getSearchableFields", "(", "$", "data", ")", ",", "\"searchableFieldsTranslations\"", "=>", "$", "this", "->", "getSearchableFields", "(", "$", "data", ",", "true", ")", ",", "]", ",", "]", ")", ";", "return", "$", "data", "->", "controllerDestination", ";", "}" ]
Creating multi language controller @param stdClass $data
[ "Creating", "multi", "language", "controller" ]
be2428ded5219dc612ecc51f43aa4dedff3d034d
https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/service/HCServiceController.php#L75-L105
train
interactivesolutions/honeycomb-scripts
src/app/commands/service/HCServiceController.php
HCServiceController.getAdminListHeader
private function getAdminListHeader(stdClass $data) { $output = ''; $model = $data->mainModel; //getting parameters which are not multilanguage $output .= $this->gatherHeaders($model, array_merge($this->getAutoFill(), ['id']), $data->translationsLocation, false); //getting parameters which are not multilanguage if( isset($model->multiLanguage) ) $output .= $this->gatherHeaders($model->multiLanguage, array_merge($this->getAutoFill(), ['id', 'language_code', 'record_id']), $data->translationsLocation, true); return $output; }
php
private function getAdminListHeader(stdClass $data) { $output = ''; $model = $data->mainModel; //getting parameters which are not multilanguage $output .= $this->gatherHeaders($model, array_merge($this->getAutoFill(), ['id']), $data->translationsLocation, false); //getting parameters which are not multilanguage if( isset($model->multiLanguage) ) $output .= $this->gatherHeaders($model->multiLanguage, array_merge($this->getAutoFill(), ['id', 'language_code', 'record_id']), $data->translationsLocation, true); return $output; }
[ "private", "function", "getAdminListHeader", "(", "stdClass", "$", "data", ")", "{", "$", "output", "=", "''", ";", "$", "model", "=", "$", "data", "->", "mainModel", ";", "//getting parameters which are not multilanguage", "$", "output", ".=", "$", "this", "->", "gatherHeaders", "(", "$", "model", ",", "array_merge", "(", "$", "this", "->", "getAutoFill", "(", ")", ",", "[", "'id'", "]", ")", ",", "$", "data", "->", "translationsLocation", ",", "false", ")", ";", "//getting parameters which are not multilanguage", "if", "(", "isset", "(", "$", "model", "->", "multiLanguage", ")", ")", "$", "output", ".=", "$", "this", "->", "gatherHeaders", "(", "$", "model", "->", "multiLanguage", ",", "array_merge", "(", "$", "this", "->", "getAutoFill", "(", ")", ",", "[", "'id'", ",", "'language_code'", ",", "'record_id'", "]", ")", ",", "$", "data", "->", "translationsLocation", ",", "true", ")", ";", "return", "$", "output", ";", "}" ]
Get list header from model data @param $data @return string
[ "Get", "list", "header", "from", "model", "data" ]
be2428ded5219dc612ecc51f43aa4dedff3d034d
https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/service/HCServiceController.php#L147-L160
train
interactivesolutions/honeycomb-scripts
src/app/commands/service/HCServiceController.php
HCServiceController.getInputData
private function getInputData(stdClass $data) { $output = ''; $skip = array_merge($this->getAutoFill(), ['id']); if( ! empty($data->database) ) { if( isset($data->multiLanguage) ) $path = '/templates/service/controller/multilanguage/input.data.hctpl'; else $path = '/templates/service/controller/basic/input.data.hctpl'; $tpl = file_get_contents(__DIR__ . '/..' . $path); foreach ( $data->database as $tableName => $model ) if( array_key_exists('columns', $model) && ! empty($model->columns) && isset($model->default) ) foreach ( $model->columns as $column ) { if( in_array($column->Field, $skip) ) continue; $line = str_replace('{key}', $column->Field, $tpl); $output .= $line; } } return $output; }
php
private function getInputData(stdClass $data) { $output = ''; $skip = array_merge($this->getAutoFill(), ['id']); if( ! empty($data->database) ) { if( isset($data->multiLanguage) ) $path = '/templates/service/controller/multilanguage/input.data.hctpl'; else $path = '/templates/service/controller/basic/input.data.hctpl'; $tpl = file_get_contents(__DIR__ . '/..' . $path); foreach ( $data->database as $tableName => $model ) if( array_key_exists('columns', $model) && ! empty($model->columns) && isset($model->default) ) foreach ( $model->columns as $column ) { if( in_array($column->Field, $skip) ) continue; $line = str_replace('{key}', $column->Field, $tpl); $output .= $line; } } return $output; }
[ "private", "function", "getInputData", "(", "stdClass", "$", "data", ")", "{", "$", "output", "=", "''", ";", "$", "skip", "=", "array_merge", "(", "$", "this", "->", "getAutoFill", "(", ")", ",", "[", "'id'", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "->", "database", ")", ")", "{", "if", "(", "isset", "(", "$", "data", "->", "multiLanguage", ")", ")", "$", "path", "=", "'/templates/service/controller/multilanguage/input.data.hctpl'", ";", "else", "$", "path", "=", "'/templates/service/controller/basic/input.data.hctpl'", ";", "$", "tpl", "=", "file_get_contents", "(", "__DIR__", ".", "'/..'", ".", "$", "path", ")", ";", "foreach", "(", "$", "data", "->", "database", "as", "$", "tableName", "=>", "$", "model", ")", "if", "(", "array_key_exists", "(", "'columns'", ",", "$", "model", ")", "&&", "!", "empty", "(", "$", "model", "->", "columns", ")", "&&", "isset", "(", "$", "model", "->", "default", ")", ")", "foreach", "(", "$", "model", "->", "columns", "as", "$", "column", ")", "{", "if", "(", "in_array", "(", "$", "column", "->", "Field", ",", "$", "skip", ")", ")", "continue", ";", "$", "line", "=", "str_replace", "(", "'{key}'", ",", "$", "column", "->", "Field", ",", "$", "tpl", ")", ";", "$", "output", ".=", "$", "line", ";", "}", "}", "return", "$", "output", ";", "}" ]
Get input keys from model data @param $data @return string
[ "Get", "input", "keys", "from", "model", "data" ]
be2428ded5219dc612ecc51f43aa4dedff3d034d
https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/service/HCServiceController.php#L191-L217
train
interactivesolutions/honeycomb-scripts
src/app/commands/service/HCServiceController.php
HCServiceController.getUseFiles
private function getUseFiles(stdClass $data, bool $multiLanguage = false) { $output = ''; $list = []; $list[] = [ "nameSpace" => $data->modelNamespace, "name" => $data->mainModel->modelName, ]; if( $multiLanguage ) $list[] = [ "nameSpace" => $data->modelNamespace, "name" => $data->mainModel->modelName . 'Translations', ]; $list[] = [ "nameSpace" => $data->formValidationNameSpace, "name" => $data->formValidationName, ]; if( isset($data->mainModel->multiLanguage) ) { $list[] = [ "nameSpace" => $data->formValidationNameSpace, "name" => $data->formTranslationsValidationName, ]; } foreach ( $list as $key => $value ) $output .= "\r\n" . 'use ' . $value['nameSpace'] . '\\' . $value['name'] . ';'; return $output; }
php
private function getUseFiles(stdClass $data, bool $multiLanguage = false) { $output = ''; $list = []; $list[] = [ "nameSpace" => $data->modelNamespace, "name" => $data->mainModel->modelName, ]; if( $multiLanguage ) $list[] = [ "nameSpace" => $data->modelNamespace, "name" => $data->mainModel->modelName . 'Translations', ]; $list[] = [ "nameSpace" => $data->formValidationNameSpace, "name" => $data->formValidationName, ]; if( isset($data->mainModel->multiLanguage) ) { $list[] = [ "nameSpace" => $data->formValidationNameSpace, "name" => $data->formTranslationsValidationName, ]; } foreach ( $list as $key => $value ) $output .= "\r\n" . 'use ' . $value['nameSpace'] . '\\' . $value['name'] . ';'; return $output; }
[ "private", "function", "getUseFiles", "(", "stdClass", "$", "data", ",", "bool", "$", "multiLanguage", "=", "false", ")", "{", "$", "output", "=", "''", ";", "$", "list", "=", "[", "]", ";", "$", "list", "[", "]", "=", "[", "\"nameSpace\"", "=>", "$", "data", "->", "modelNamespace", ",", "\"name\"", "=>", "$", "data", "->", "mainModel", "->", "modelName", ",", "]", ";", "if", "(", "$", "multiLanguage", ")", "$", "list", "[", "]", "=", "[", "\"nameSpace\"", "=>", "$", "data", "->", "modelNamespace", ",", "\"name\"", "=>", "$", "data", "->", "mainModel", "->", "modelName", ".", "'Translations'", ",", "]", ";", "$", "list", "[", "]", "=", "[", "\"nameSpace\"", "=>", "$", "data", "->", "formValidationNameSpace", ",", "\"name\"", "=>", "$", "data", "->", "formValidationName", ",", "]", ";", "if", "(", "isset", "(", "$", "data", "->", "mainModel", "->", "multiLanguage", ")", ")", "{", "$", "list", "[", "]", "=", "[", "\"nameSpace\"", "=>", "$", "data", "->", "formValidationNameSpace", ",", "\"name\"", "=>", "$", "data", "->", "formTranslationsValidationName", ",", "]", ";", "}", "foreach", "(", "$", "list", "as", "$", "key", "=>", "$", "value", ")", "$", "output", ".=", "\"\\r\\n\"", ".", "'use '", ".", "$", "value", "[", "'nameSpace'", "]", ".", "'\\\\'", ".", "$", "value", "[", "'name'", "]", ".", "';'", ";", "return", "$", "output", ";", "}" ]
get use files @param stdClass $data @param bool $multiLanguage @return string
[ "get", "use", "files" ]
be2428ded5219dc612ecc51f43aa4dedff3d034d
https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/service/HCServiceController.php#L226-L259
train
interactivesolutions/honeycomb-scripts
src/app/commands/service/HCServiceController.php
HCServiceController.getSearchableFields
private function getSearchableFields(stdClass $data, bool $multiLanguage = false) { $output = ''; $model = $data->mainModel; $whereTpl = file_get_contents(__DIR__ . '/../templates/shared/where.hctpl'); $orWhereTpl = file_get_contents(__DIR__ . '/../templates/shared/or.where.hctpl'); $skip = array_merge($this->getAutoFill(), ['id']); if( $multiLanguage ) { if( array_key_exists('multiLanguage', $model) && ! empty($model->multiLanguage) ) if( array_key_exists('columns', $model->multiLanguage) && ! empty($model->multiLanguage->columns) ) foreach ( $model->multiLanguage->columns as $index => $column ) { if( in_array($column->Field, $skip) ) continue; if( $output == '' ) $output .= str_replace('{key}', $column->Field, $whereTpl); else $output .= str_replace('{key}', $column->Field, $orWhereTpl); } } else if( array_key_exists('columns', $model) && ! empty($model->columns) ) { foreach ( $model->columns as $index => $column ) { if( in_array($column->Field, $skip) ) continue; if( $output == '' ) $output .= str_replace('{key}', $column->Field, $whereTpl); else $output .= str_replace('{key}', $column->Field, $orWhereTpl); } } return $output; }
php
private function getSearchableFields(stdClass $data, bool $multiLanguage = false) { $output = ''; $model = $data->mainModel; $whereTpl = file_get_contents(__DIR__ . '/../templates/shared/where.hctpl'); $orWhereTpl = file_get_contents(__DIR__ . '/../templates/shared/or.where.hctpl'); $skip = array_merge($this->getAutoFill(), ['id']); if( $multiLanguage ) { if( array_key_exists('multiLanguage', $model) && ! empty($model->multiLanguage) ) if( array_key_exists('columns', $model->multiLanguage) && ! empty($model->multiLanguage->columns) ) foreach ( $model->multiLanguage->columns as $index => $column ) { if( in_array($column->Field, $skip) ) continue; if( $output == '' ) $output .= str_replace('{key}', $column->Field, $whereTpl); else $output .= str_replace('{key}', $column->Field, $orWhereTpl); } } else if( array_key_exists('columns', $model) && ! empty($model->columns) ) { foreach ( $model->columns as $index => $column ) { if( in_array($column->Field, $skip) ) continue; if( $output == '' ) $output .= str_replace('{key}', $column->Field, $whereTpl); else $output .= str_replace('{key}', $column->Field, $orWhereTpl); } } return $output; }
[ "private", "function", "getSearchableFields", "(", "stdClass", "$", "data", ",", "bool", "$", "multiLanguage", "=", "false", ")", "{", "$", "output", "=", "''", ";", "$", "model", "=", "$", "data", "->", "mainModel", ";", "$", "whereTpl", "=", "file_get_contents", "(", "__DIR__", ".", "'/../templates/shared/where.hctpl'", ")", ";", "$", "orWhereTpl", "=", "file_get_contents", "(", "__DIR__", ".", "'/../templates/shared/or.where.hctpl'", ")", ";", "$", "skip", "=", "array_merge", "(", "$", "this", "->", "getAutoFill", "(", ")", ",", "[", "'id'", "]", ")", ";", "if", "(", "$", "multiLanguage", ")", "{", "if", "(", "array_key_exists", "(", "'multiLanguage'", ",", "$", "model", ")", "&&", "!", "empty", "(", "$", "model", "->", "multiLanguage", ")", ")", "if", "(", "array_key_exists", "(", "'columns'", ",", "$", "model", "->", "multiLanguage", ")", "&&", "!", "empty", "(", "$", "model", "->", "multiLanguage", "->", "columns", ")", ")", "foreach", "(", "$", "model", "->", "multiLanguage", "->", "columns", "as", "$", "index", "=>", "$", "column", ")", "{", "if", "(", "in_array", "(", "$", "column", "->", "Field", ",", "$", "skip", ")", ")", "continue", ";", "if", "(", "$", "output", "==", "''", ")", "$", "output", ".=", "str_replace", "(", "'{key}'", ",", "$", "column", "->", "Field", ",", "$", "whereTpl", ")", ";", "else", "$", "output", ".=", "str_replace", "(", "'{key}'", ",", "$", "column", "->", "Field", ",", "$", "orWhereTpl", ")", ";", "}", "}", "else", "if", "(", "array_key_exists", "(", "'columns'", ",", "$", "model", ")", "&&", "!", "empty", "(", "$", "model", "->", "columns", ")", ")", "{", "foreach", "(", "$", "model", "->", "columns", "as", "$", "index", "=>", "$", "column", ")", "{", "if", "(", "in_array", "(", "$", "column", "->", "Field", ",", "$", "skip", ")", ")", "continue", ";", "if", "(", "$", "output", "==", "''", ")", "$", "output", ".=", "str_replace", "(", "'{key}'", ",", "$", "column", "->", "Field", ",", "$", "whereTpl", ")", ";", "else", "$", "output", ".=", "str_replace", "(", "'{key}'", ",", "$", "column", "->", "Field", ",", "$", "orWhereTpl", ")", ";", "}", "}", "return", "$", "output", ";", "}" ]
Get searchable fields from model data @param stdClass $data @param bool $multiLanguage @return string
[ "Get", "searchable", "fields", "from", "model", "data" ]
be2428ded5219dc612ecc51f43aa4dedff3d034d
https://github.com/interactivesolutions/honeycomb-scripts/blob/be2428ded5219dc612ecc51f43aa4dedff3d034d/src/app/commands/service/HCServiceController.php#L268-L309
train
evispa/TranslationEditorBundle
Form/PropertyAccessor.php
PropertyAccessor.getPropertyPath
private function getPropertyPath($propertyPath) { if (!isset($this->propertyPaths[$propertyPath])) { $this->propertyPaths[$propertyPath] = new \Symfony\Component\Form\Util\PropertyPath($propertyPath); } return $this->propertyPaths[$propertyPath]; }
php
private function getPropertyPath($propertyPath) { if (!isset($this->propertyPaths[$propertyPath])) { $this->propertyPaths[$propertyPath] = new \Symfony\Component\Form\Util\PropertyPath($propertyPath); } return $this->propertyPaths[$propertyPath]; }
[ "private", "function", "getPropertyPath", "(", "$", "propertyPath", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "propertyPaths", "[", "$", "propertyPath", "]", ")", ")", "{", "$", "this", "->", "propertyPaths", "[", "$", "propertyPath", "]", "=", "new", "\\", "Symfony", "\\", "Component", "\\", "Form", "\\", "Util", "\\", "PropertyPath", "(", "$", "propertyPath", ")", ";", "}", "return", "$", "this", "->", "propertyPaths", "[", "$", "propertyPath", "]", ";", "}" ]
Get property path object. @param string $propertyPath Property path string. @return \Symfony\Component\Form\Util\PropertyPath
[ "Get", "property", "path", "object", "." ]
312040605c331fc2520f5d042bc00b05608554b5
https://github.com/evispa/TranslationEditorBundle/blob/312040605c331fc2520f5d042bc00b05608554b5/Form/PropertyAccessor.php#L32-L38
train
querformat/contao-layout-sections-extender
src/layout-sections-extender/dca/tl_article.php
tl_article_qf.addCustomLayoutSectionsHook
public function addCustomLayoutSectionsHook(DataContainer $dc) { $arrSections = $this->getActiveLayoutSections($dc); if (isset($GLOBALS['TL_HOOKS']['addLayoutSections']) && is_array($GLOBALS['TL_HOOKS']['addLayoutSections'])) { foreach ($GLOBALS['TL_HOOKS']['addLayoutSections'] as $arrCustomSections) { if (is_array($arrCustomSections) && count($arrCustomSections) > 0) { foreach ($arrCustomSections as $k => $v) { if (empty($v)) $arrCustomSections[$k] = $k; } $arrSections = array_merge($arrSections, $arrCustomSections); } } } return $arrSections; }
php
public function addCustomLayoutSectionsHook(DataContainer $dc) { $arrSections = $this->getActiveLayoutSections($dc); if (isset($GLOBALS['TL_HOOKS']['addLayoutSections']) && is_array($GLOBALS['TL_HOOKS']['addLayoutSections'])) { foreach ($GLOBALS['TL_HOOKS']['addLayoutSections'] as $arrCustomSections) { if (is_array($arrCustomSections) && count($arrCustomSections) > 0) { foreach ($arrCustomSections as $k => $v) { if (empty($v)) $arrCustomSections[$k] = $k; } $arrSections = array_merge($arrSections, $arrCustomSections); } } } return $arrSections; }
[ "public", "function", "addCustomLayoutSectionsHook", "(", "DataContainer", "$", "dc", ")", "{", "$", "arrSections", "=", "$", "this", "->", "getActiveLayoutSections", "(", "$", "dc", ")", ";", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'TL_HOOKS'", "]", "[", "'addLayoutSections'", "]", ")", "&&", "is_array", "(", "$", "GLOBALS", "[", "'TL_HOOKS'", "]", "[", "'addLayoutSections'", "]", ")", ")", "{", "foreach", "(", "$", "GLOBALS", "[", "'TL_HOOKS'", "]", "[", "'addLayoutSections'", "]", "as", "$", "arrCustomSections", ")", "{", "if", "(", "is_array", "(", "$", "arrCustomSections", ")", "&&", "count", "(", "$", "arrCustomSections", ")", ">", "0", ")", "{", "foreach", "(", "$", "arrCustomSections", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "empty", "(", "$", "v", ")", ")", "$", "arrCustomSections", "[", "$", "k", "]", "=", "$", "k", ";", "}", "$", "arrSections", "=", "array_merge", "(", "$", "arrSections", ",", "$", "arrCustomSections", ")", ";", "}", "}", "}", "return", "$", "arrSections", ";", "}" ]
Costum Column Hack @param DataContainer $dc @return array
[ "Costum", "Column", "Hack" ]
db75bf7d6e6e58342fdbb4d1e0ddc52b86fc7349
https://github.com/querformat/contao-layout-sections-extender/blob/db75bf7d6e6e58342fdbb4d1e0ddc52b86fc7349/src/layout-sections-extender/dca/tl_article.php#L25-L40
train
ideil/laravel-generic-file
src/GenericFile.php
GenericFile.saveModelData
protected function saveModelData(Model $model, \Ideil\GenericFile\Interpolator\InterpolatorResult $input) { // prepare data to fill model $model_map = $model->getFileAssignMap(); $model_fields = []; foreach ($input->getData() as $field => $value) { $model_fields[isset($model_map[$field]) ? $model_map[$field] : $field] = $value; } // not save, just fill data $model->fill($model_fields); return $model; }
php
protected function saveModelData(Model $model, \Ideil\GenericFile\Interpolator\InterpolatorResult $input) { // prepare data to fill model $model_map = $model->getFileAssignMap(); $model_fields = []; foreach ($input->getData() as $field => $value) { $model_fields[isset($model_map[$field]) ? $model_map[$field] : $field] = $value; } // not save, just fill data $model->fill($model_fields); return $model; }
[ "protected", "function", "saveModelData", "(", "Model", "$", "model", ",", "\\", "Ideil", "\\", "GenericFile", "\\", "Interpolator", "\\", "InterpolatorResult", "$", "input", ")", "{", "// prepare data to fill model", "$", "model_map", "=", "$", "model", "->", "getFileAssignMap", "(", ")", ";", "$", "model_fields", "=", "[", "]", ";", "foreach", "(", "$", "input", "->", "getData", "(", ")", "as", "$", "field", "=>", "$", "value", ")", "{", "$", "model_fields", "[", "isset", "(", "$", "model_map", "[", "$", "field", "]", ")", "?", "$", "model_map", "[", "$", "field", "]", ":", "$", "field", "]", "=", "$", "value", ";", "}", "// not save, just fill data", "$", "model", "->", "fill", "(", "$", "model_fields", ")", ";", "return", "$", "model", ";", "}" ]
Save file attributes required for interpolation to model. @param string|Illuminate\Database\Eloquent\Model $model @param Ideil\LaravelFileOre\Interpolator\InterpolatorResult $input @return Illuminate\Database\Eloquent\Model
[ "Save", "file", "attributes", "required", "for", "interpolation", "to", "model", "." ]
3eaeadf06dfb295c391dd7a88c371797c2b70ee3
https://github.com/ideil/laravel-generic-file/blob/3eaeadf06dfb295c391dd7a88c371797c2b70ee3/src/GenericFile.php#L19-L35
train
ideil/laravel-generic-file
src/GenericFile.php
GenericFile.moveUploadedFile
public function moveUploadedFile(File $file, $path_pattern = null, $existing_model = null) { // get model instance if available // not use models if $existing_model === false $model_class = $this->getConfig('store.model'); if (($model_class || $existing_model) && $existing_model !== false) { $model_instance = $existing_model ?: new $model_class(); // cancel upload if event returned false if (!$model_instance->beforeUpload($file)) { return; } } $interpolated = parent::moveUploadedFile($file, $path_pattern); // check is model available // and update it if (isset($model_instance)) { return $this->saveModelData($model_instance, $interpolated); } return $interpolated; }
php
public function moveUploadedFile(File $file, $path_pattern = null, $existing_model = null) { // get model instance if available // not use models if $existing_model === false $model_class = $this->getConfig('store.model'); if (($model_class || $existing_model) && $existing_model !== false) { $model_instance = $existing_model ?: new $model_class(); // cancel upload if event returned false if (!$model_instance->beforeUpload($file)) { return; } } $interpolated = parent::moveUploadedFile($file, $path_pattern); // check is model available // and update it if (isset($model_instance)) { return $this->saveModelData($model_instance, $interpolated); } return $interpolated; }
[ "public", "function", "moveUploadedFile", "(", "File", "$", "file", ",", "$", "path_pattern", "=", "null", ",", "$", "existing_model", "=", "null", ")", "{", "// get model instance if available", "// not use models if $existing_model === false", "$", "model_class", "=", "$", "this", "->", "getConfig", "(", "'store.model'", ")", ";", "if", "(", "(", "$", "model_class", "||", "$", "existing_model", ")", "&&", "$", "existing_model", "!==", "false", ")", "{", "$", "model_instance", "=", "$", "existing_model", "?", ":", "new", "$", "model_class", "(", ")", ";", "// cancel upload if event returned false", "if", "(", "!", "$", "model_instance", "->", "beforeUpload", "(", "$", "file", ")", ")", "{", "return", ";", "}", "}", "$", "interpolated", "=", "parent", "::", "moveUploadedFile", "(", "$", "file", ",", "$", "path_pattern", ")", ";", "// check is model available", "// and update it", "if", "(", "isset", "(", "$", "model_instance", ")", ")", "{", "return", "$", "this", "->", "saveModelData", "(", "$", "model_instance", ",", "$", "interpolated", ")", ";", "}", "return", "$", "interpolated", ";", "}" ]
Move uploaded file to path by pattern and update model. @param File $file @param string|null $path_pattern @param Illuminate\Database\Eloquent\Model|null|false $existing_model @return Illuminate\Database\Eloquent\Model|string|null
[ "Move", "uploaded", "file", "to", "path", "by", "pattern", "and", "update", "model", "." ]
3eaeadf06dfb295c391dd7a88c371797c2b70ee3
https://github.com/ideil/laravel-generic-file/blob/3eaeadf06dfb295c391dd7a88c371797c2b70ee3/src/GenericFile.php#L46-L73
train
ideil/laravel-generic-file
src/GenericFile.php
GenericFile.makeUrlToUploadedFile
public function makeUrlToUploadedFile($model, $path_pattern = null, array $model_map = array(), $domain = null) { return parent::makeUrlToUploadedFile($model, $path_pattern, $model instanceof Model ? $model->getFileAssignMap() : $model_map, $domain); }
php
public function makeUrlToUploadedFile($model, $path_pattern = null, array $model_map = array(), $domain = null) { return parent::makeUrlToUploadedFile($model, $path_pattern, $model instanceof Model ? $model->getFileAssignMap() : $model_map, $domain); }
[ "public", "function", "makeUrlToUploadedFile", "(", "$", "model", ",", "$", "path_pattern", "=", "null", ",", "array", "$", "model_map", "=", "array", "(", ")", ",", "$", "domain", "=", "null", ")", "{", "return", "parent", "::", "makeUrlToUploadedFile", "(", "$", "model", ",", "$", "path_pattern", ",", "$", "model", "instanceof", "Model", "?", "$", "model", "->", "getFileAssignMap", "(", ")", ":", "$", "model_map", ",", "$", "domain", ")", ";", "}" ]
Make url to stored file. @param array|Illuminate\Database\Eloquent\Model $model @param string|null $path_pattern @return string
[ "Make", "url", "to", "stored", "file", "." ]
3eaeadf06dfb295c391dd7a88c371797c2b70ee3
https://github.com/ideil/laravel-generic-file/blob/3eaeadf06dfb295c391dd7a88c371797c2b70ee3/src/GenericFile.php#L99-L103
train
ideil/laravel-generic-file
src/GenericFile.php
GenericFile.makePathToUploadedFile
public function makePathToUploadedFile($model, $path_pattern = null, array $model_map = array()) { return parent::makePathToUploadedFile($model, $path_pattern, $model instanceof Model ? $model->getFileAssignMap() : $model_map); }
php
public function makePathToUploadedFile($model, $path_pattern = null, array $model_map = array()) { return parent::makePathToUploadedFile($model, $path_pattern, $model instanceof Model ? $model->getFileAssignMap() : $model_map); }
[ "public", "function", "makePathToUploadedFile", "(", "$", "model", ",", "$", "path_pattern", "=", "null", ",", "array", "$", "model_map", "=", "array", "(", ")", ")", "{", "return", "parent", "::", "makePathToUploadedFile", "(", "$", "model", ",", "$", "path_pattern", ",", "$", "model", "instanceof", "Model", "?", "$", "model", "->", "getFileAssignMap", "(", ")", ":", "$", "model_map", ")", ";", "}" ]
Full path to stored file. @param array|Illuminate\Database\Eloquent\Model $model @param string|null $path_pattern @return string
[ "Full", "path", "to", "stored", "file", "." ]
3eaeadf06dfb295c391dd7a88c371797c2b70ee3
https://github.com/ideil/laravel-generic-file/blob/3eaeadf06dfb295c391dd7a88c371797c2b70ee3/src/GenericFile.php#L113-L117
train
agilesdesign/flasher
src/Flasher/Support/Notifier.php
Notifier.flash
protected function flash(string $type, string $message, string $level) { $group = Session::get($type, new MessageBag()); Session::flash($type, $group->add($level, $message)); return $this; }
php
protected function flash(string $type, string $message, string $level) { $group = Session::get($type, new MessageBag()); Session::flash($type, $group->add($level, $message)); return $this; }
[ "protected", "function", "flash", "(", "string", "$", "type", ",", "string", "$", "message", ",", "string", "$", "level", ")", "{", "$", "group", "=", "Session", "::", "get", "(", "$", "type", ",", "new", "MessageBag", "(", ")", ")", ";", "Session", "::", "flash", "(", "$", "type", ",", "$", "group", "->", "add", "(", "$", "level", ",", "$", "message", ")", ")", ";", "return", "$", "this", ";", "}" ]
Flash message to the Session. @param string $type @param string $message @param string $level @return $this
[ "Flash", "message", "to", "the", "Session", "." ]
5bf8c04d0a2df55177d3f81983982d5999b9f5b8
https://github.com/agilesdesign/flasher/blob/5bf8c04d0a2df55177d3f81983982d5999b9f5b8/src/Flasher/Support/Notifier.php#L49-L56
train
luxorphp/http-controller
src/Event/Executor.php
Executor.exist
public function exist() { $this->resCallback = $this->callback->filter(function (HttpCallBack $call) { return $this->rutesManager->existRutes($call->getPath(), $this->peticion); }); }
php
public function exist() { $this->resCallback = $this->callback->filter(function (HttpCallBack $call) { return $this->rutesManager->existRutes($call->getPath(), $this->peticion); }); }
[ "public", "function", "exist", "(", ")", "{", "$", "this", "->", "resCallback", "=", "$", "this", "->", "callback", "->", "filter", "(", "function", "(", "HttpCallBack", "$", "call", ")", "{", "return", "$", "this", "->", "rutesManager", "->", "existRutes", "(", "$", "call", "->", "getPath", "(", ")", ",", "$", "this", "->", "peticion", ")", ";", "}", ")", ";", "}" ]
Filtrar si existe algun controlador que pueda ser ejecutado sin importar si es el solicitado, esto se verifica con la longitud de la rutas almacenada, si coinciden con la ruta de la peticion.
[ "Filtrar", "si", "existe", "algun", "controlador", "que", "pueda", "ser", "ejecutado", "sin", "importar", "si", "es", "el", "solicitado", "esto", "se", "verifica", "con", "la", "longitud", "de", "la", "rutas", "almacenada", "si", "coinciden", "con", "la", "ruta", "de", "la", "peticion", "." ]
4cc60fdf2c16b2701cafcce2ba32cb672794c7e1
https://github.com/luxorphp/http-controller/blob/4cc60fdf2c16b2701cafcce2ba32cb672794c7e1/src/Event/Executor.php#L111-L119
train
luxorphp/http-controller
src/Event/Executor.php
Executor.compare
public function compare() { // echo '<br>'; // echo 'Se han encontrado '.$this->resCallback->lenght().' resultados del primer filtro <br>'; $this->resFilter = $this->resCallback->filter(function (HttpCallBack $call) { return $this->rutesManager->compareRute($call->getPath(), $this->peticion); }); }
php
public function compare() { // echo '<br>'; // echo 'Se han encontrado '.$this->resCallback->lenght().' resultados del primer filtro <br>'; $this->resFilter = $this->resCallback->filter(function (HttpCallBack $call) { return $this->rutesManager->compareRute($call->getPath(), $this->peticion); }); }
[ "public", "function", "compare", "(", ")", "{", "// echo '<br>';", "// echo 'Se han encontrado '.$this->resCallback->lenght().' resultados del primer filtro <br>';", "$", "this", "->", "resFilter", "=", "$", "this", "->", "resCallback", "->", "filter", "(", "function", "(", "HttpCallBack", "$", "call", ")", "{", "return", "$", "this", "->", "rutesManager", "->", "compareRute", "(", "$", "call", "->", "getPath", "(", ")", ",", "$", "this", "->", "peticion", ")", ";", "}", ")", ";", "}" ]
Filtrar si existe alguna ruta que sea identica a la ruta de la peticion esto se realiza a travez de la verificacion de patrones en las rutas. @return null
[ "Filtrar", "si", "existe", "alguna", "ruta", "que", "sea", "identica", "a", "la", "ruta", "de", "la", "peticion", "esto", "se", "realiza", "a", "travez", "de", "la", "verificacion", "de", "patrones", "en", "las", "rutas", "." ]
4cc60fdf2c16b2701cafcce2ba32cb672794c7e1
https://github.com/luxorphp/http-controller/blob/4cc60fdf2c16b2701cafcce2ba32cb672794c7e1/src/Event/Executor.php#L127-L138
train
luxorphp/http-controller
src/Event/Executor.php
Executor.execute
public function execute() { // echo '<br>'; // echo 'Se han encontrado '.$this->resFilter->lenght().' resultados del segundo filtro <br>'; //Ejecutar controlador raiz por defecto, si no hay ningun resultado posible. if ($this->resFilter->isEmpty() && $this->rutesManager->isRoot($this->actual, $this->peticion)) { $this->root(); return; } //Ejecutar controlador por defecto, si no hay ningun resultado posible. if ($this->resFilter->isEmpty()) { $this->default(); return; } //Ejecutar controlador. $this->resFilter->each(function (HttpCallBack $call) { $call->call($this->rutesManager->getParameter()); }); }
php
public function execute() { // echo '<br>'; // echo 'Se han encontrado '.$this->resFilter->lenght().' resultados del segundo filtro <br>'; //Ejecutar controlador raiz por defecto, si no hay ningun resultado posible. if ($this->resFilter->isEmpty() && $this->rutesManager->isRoot($this->actual, $this->peticion)) { $this->root(); return; } //Ejecutar controlador por defecto, si no hay ningun resultado posible. if ($this->resFilter->isEmpty()) { $this->default(); return; } //Ejecutar controlador. $this->resFilter->each(function (HttpCallBack $call) { $call->call($this->rutesManager->getParameter()); }); }
[ "public", "function", "execute", "(", ")", "{", "// echo '<br>';", "// echo 'Se han encontrado '.$this->resFilter->lenght().' resultados del segundo filtro <br>';", "//Ejecutar controlador raiz por defecto, si no hay ningun resultado posible.", "if", "(", "$", "this", "->", "resFilter", "->", "isEmpty", "(", ")", "&&", "$", "this", "->", "rutesManager", "->", "isRoot", "(", "$", "this", "->", "actual", ",", "$", "this", "->", "peticion", ")", ")", "{", "$", "this", "->", "root", "(", ")", ";", "return", ";", "}", "//Ejecutar controlador por defecto, si no hay ningun resultado posible.", "if", "(", "$", "this", "->", "resFilter", "->", "isEmpty", "(", ")", ")", "{", "$", "this", "->", "default", "(", ")", ";", "return", ";", "}", "//Ejecutar controlador.", "$", "this", "->", "resFilter", "->", "each", "(", "function", "(", "HttpCallBack", "$", "call", ")", "{", "$", "call", "->", "call", "(", "$", "this", "->", "rutesManager", "->", "getParameter", "(", ")", ")", ";", "}", ")", ";", "}" ]
Ejecutar la ruta encontrada, en caso de no encontrar nada ejecutar una por defecto @return null
[ "Ejecutar", "la", "ruta", "encontrada", "en", "caso", "de", "no", "encontrar", "nada", "ejecutar", "una", "por", "defecto" ]
4cc60fdf2c16b2701cafcce2ba32cb672794c7e1
https://github.com/luxorphp/http-controller/blob/4cc60fdf2c16b2701cafcce2ba32cb672794c7e1/src/Event/Executor.php#L145-L169
train
luxorphp/http-controller
src/Event/Executor.php
Executor.default
private function default() { $this->callback->filter(function (HttpCallBack $test) { return !strcmp($test->getPath(), $this->actual.'/**'); })->each(function (HttpCallBack $test) { $test->call($this->rutesManager->getParameter()); }); }
php
private function default() { $this->callback->filter(function (HttpCallBack $test) { return !strcmp($test->getPath(), $this->actual.'/**'); })->each(function (HttpCallBack $test) { $test->call($this->rutesManager->getParameter()); }); }
[ "private", "function", "default", "(", ")", "{", "$", "this", "->", "callback", "->", "filter", "(", "function", "(", "HttpCallBack", "$", "test", ")", "{", "return", "!", "strcmp", "(", "$", "test", "->", "getPath", "(", ")", ",", "$", "this", "->", "actual", ".", "'/**'", ")", ";", "}", ")", "->", "each", "(", "function", "(", "HttpCallBack", "$", "test", ")", "{", "$", "test", "->", "call", "(", "$", "this", "->", "rutesManager", "->", "getParameter", "(", ")", ")", ";", "}", ")", ";", "}" ]
Metodo quen ejecuta el controlador por defecto cuando no existe una ruta posible a ejecutar.
[ "Metodo", "quen", "ejecuta", "el", "controlador", "por", "defecto", "cuando", "no", "existe", "una", "ruta", "posible", "a", "ejecutar", "." ]
4cc60fdf2c16b2701cafcce2ba32cb672794c7e1
https://github.com/luxorphp/http-controller/blob/4cc60fdf2c16b2701cafcce2ba32cb672794c7e1/src/Event/Executor.php#L175-L187
train
x2ts/x2ts
src/validator/Validator.php
Validator.selfValidate
protected function selfValidate() { if ($this->_isUndefined && $this->onUndefinedIgnore) { $this->_safeVar = null; $this->_isValid = true; goto finish; } if ($this->isEmpty($this->_unsafeVar)) { if ($this->onEmptyIgnore) { $this->_safeVar = null; $this->_isValid = true; $this->_isEmpty = true; goto finish; } else if ($this->onEmptySet) { $this->_safeVar = $this->onEmptySetValue; $this->_isValid = true; goto finish; } else if ($this->emptyMessage) { $this->_isValid = false; $this->message = $this->emptyMessage; $this->_isEmpty = true; } else { $this->_isEmpty = true; } } if (!$this->_isValid && $this->isEmpty($this->message)) { if ($this->onErrorSet) { $this->_safeVar = $this->onErrorSetValue; $this->_isValid = true; } else if ($this->errorMessage !== '') { $this->message = $this->errorMessage; } } else { $this->_safeVar = $this->_unsafeVar; } finish: $this->validated = true; }
php
protected function selfValidate() { if ($this->_isUndefined && $this->onUndefinedIgnore) { $this->_safeVar = null; $this->_isValid = true; goto finish; } if ($this->isEmpty($this->_unsafeVar)) { if ($this->onEmptyIgnore) { $this->_safeVar = null; $this->_isValid = true; $this->_isEmpty = true; goto finish; } else if ($this->onEmptySet) { $this->_safeVar = $this->onEmptySetValue; $this->_isValid = true; goto finish; } else if ($this->emptyMessage) { $this->_isValid = false; $this->message = $this->emptyMessage; $this->_isEmpty = true; } else { $this->_isEmpty = true; } } if (!$this->_isValid && $this->isEmpty($this->message)) { if ($this->onErrorSet) { $this->_safeVar = $this->onErrorSetValue; $this->_isValid = true; } else if ($this->errorMessage !== '') { $this->message = $this->errorMessage; } } else { $this->_safeVar = $this->_unsafeVar; } finish: $this->validated = true; }
[ "protected", "function", "selfValidate", "(", ")", "{", "if", "(", "$", "this", "->", "_isUndefined", "&&", "$", "this", "->", "onUndefinedIgnore", ")", "{", "$", "this", "->", "_safeVar", "=", "null", ";", "$", "this", "->", "_isValid", "=", "true", ";", "goto", "finish", ";", "}", "if", "(", "$", "this", "->", "isEmpty", "(", "$", "this", "->", "_unsafeVar", ")", ")", "{", "if", "(", "$", "this", "->", "onEmptyIgnore", ")", "{", "$", "this", "->", "_safeVar", "=", "null", ";", "$", "this", "->", "_isValid", "=", "true", ";", "$", "this", "->", "_isEmpty", "=", "true", ";", "goto", "finish", ";", "}", "else", "if", "(", "$", "this", "->", "onEmptySet", ")", "{", "$", "this", "->", "_safeVar", "=", "$", "this", "->", "onEmptySetValue", ";", "$", "this", "->", "_isValid", "=", "true", ";", "goto", "finish", ";", "}", "else", "if", "(", "$", "this", "->", "emptyMessage", ")", "{", "$", "this", "->", "_isValid", "=", "false", ";", "$", "this", "->", "message", "=", "$", "this", "->", "emptyMessage", ";", "$", "this", "->", "_isEmpty", "=", "true", ";", "}", "else", "{", "$", "this", "->", "_isEmpty", "=", "true", ";", "}", "}", "if", "(", "!", "$", "this", "->", "_isValid", "&&", "$", "this", "->", "isEmpty", "(", "$", "this", "->", "message", ")", ")", "{", "if", "(", "$", "this", "->", "onErrorSet", ")", "{", "$", "this", "->", "_safeVar", "=", "$", "this", "->", "onErrorSetValue", ";", "$", "this", "->", "_isValid", "=", "true", ";", "}", "else", "if", "(", "$", "this", "->", "errorMessage", "!==", "''", ")", "{", "$", "this", "->", "message", "=", "$", "this", "->", "errorMessage", ";", "}", "}", "else", "{", "$", "this", "->", "_safeVar", "=", "$", "this", "->", "_unsafeVar", ";", "}", "finish", ":", "$", "this", "->", "validated", "=", "true", ";", "}" ]
Start validate the valley itself @return void
[ "Start", "validate", "the", "valley", "itself" ]
65e43952ab940ab05696a34d31a1c3ab91545090
https://github.com/x2ts/x2ts/blob/65e43952ab940ab05696a34d31a1c3ab91545090/src/validator/Validator.php#L382-L420
train
x2ts/x2ts
src/validator/Validator.php
Validator.validate
final public function validate(callable $onDataInvalid = null): Validator { $shell = $this->shell; if (count($shell->subValidators)) { $shell->_safeVar = []; /** * @var Validator $validator * @var string $key */ foreach ($shell->subValidators as $key => $validator) { $validator->selfValidate(); if ($validator->_isUndefined && $validator->onUndefinedIgnore) { continue; } if ($validator->_isEmpty && $validator->onEmptyIgnore) { continue; } if ($validator->_isValid) { $shell->_safeVar[$key] = $validator->safeVar; } else if ($validator->message !== '') { $shell->_messages[$key] = $validator->message; $shell->_isValid = false; } else { $shell->_messages[$key] = "$key is invalid"; $shell->_isValid = false; } } $shell->validated = true; } else { $this->selfValidate(); if (!$this->_isValid) { $this->_messages[] = $this->message; } } if (!$shell->_isValid) { if (is_callable($onDataInvalid)) { $onDataInvalid($shell->messages, $shell); } else { throw new ValidatorException($shell->messages); } } return $shell; }
php
final public function validate(callable $onDataInvalid = null): Validator { $shell = $this->shell; if (count($shell->subValidators)) { $shell->_safeVar = []; /** * @var Validator $validator * @var string $key */ foreach ($shell->subValidators as $key => $validator) { $validator->selfValidate(); if ($validator->_isUndefined && $validator->onUndefinedIgnore) { continue; } if ($validator->_isEmpty && $validator->onEmptyIgnore) { continue; } if ($validator->_isValid) { $shell->_safeVar[$key] = $validator->safeVar; } else if ($validator->message !== '') { $shell->_messages[$key] = $validator->message; $shell->_isValid = false; } else { $shell->_messages[$key] = "$key is invalid"; $shell->_isValid = false; } } $shell->validated = true; } else { $this->selfValidate(); if (!$this->_isValid) { $this->_messages[] = $this->message; } } if (!$shell->_isValid) { if (is_callable($onDataInvalid)) { $onDataInvalid($shell->messages, $shell); } else { throw new ValidatorException($shell->messages); } } return $shell; }
[ "final", "public", "function", "validate", "(", "callable", "$", "onDataInvalid", "=", "null", ")", ":", "Validator", "{", "$", "shell", "=", "$", "this", "->", "shell", ";", "if", "(", "count", "(", "$", "shell", "->", "subValidators", ")", ")", "{", "$", "shell", "->", "_safeVar", "=", "[", "]", ";", "/**\n * @var Validator $validator\n * @var string $key\n */", "foreach", "(", "$", "shell", "->", "subValidators", "as", "$", "key", "=>", "$", "validator", ")", "{", "$", "validator", "->", "selfValidate", "(", ")", ";", "if", "(", "$", "validator", "->", "_isUndefined", "&&", "$", "validator", "->", "onUndefinedIgnore", ")", "{", "continue", ";", "}", "if", "(", "$", "validator", "->", "_isEmpty", "&&", "$", "validator", "->", "onEmptyIgnore", ")", "{", "continue", ";", "}", "if", "(", "$", "validator", "->", "_isValid", ")", "{", "$", "shell", "->", "_safeVar", "[", "$", "key", "]", "=", "$", "validator", "->", "safeVar", ";", "}", "else", "if", "(", "$", "validator", "->", "message", "!==", "''", ")", "{", "$", "shell", "->", "_messages", "[", "$", "key", "]", "=", "$", "validator", "->", "message", ";", "$", "shell", "->", "_isValid", "=", "false", ";", "}", "else", "{", "$", "shell", "->", "_messages", "[", "$", "key", "]", "=", "\"$key is invalid\"", ";", "$", "shell", "->", "_isValid", "=", "false", ";", "}", "}", "$", "shell", "->", "validated", "=", "true", ";", "}", "else", "{", "$", "this", "->", "selfValidate", "(", ")", ";", "if", "(", "!", "$", "this", "->", "_isValid", ")", "{", "$", "this", "->", "_messages", "[", "]", "=", "$", "this", "->", "message", ";", "}", "}", "if", "(", "!", "$", "shell", "->", "_isValid", ")", "{", "if", "(", "is_callable", "(", "$", "onDataInvalid", ")", ")", "{", "$", "onDataInvalid", "(", "$", "shell", "->", "messages", ",", "$", "shell", ")", ";", "}", "else", "{", "throw", "new", "ValidatorException", "(", "$", "shell", "->", "messages", ")", ";", "}", "}", "return", "$", "shell", ";", "}" ]
Start validate the whole chain include the sub valleys @param callable $onDataInvalid @return Validator @throws \x2ts\validator\ValidatorException
[ "Start", "validate", "the", "whole", "chain", "include", "the", "sub", "valleys" ]
65e43952ab940ab05696a34d31a1c3ab91545090
https://github.com/x2ts/x2ts/blob/65e43952ab940ab05696a34d31a1c3ab91545090/src/validator/Validator.php#L431-L473
train
as3io/modlr
src/Metadata/MetadataFactory.php
MetadataFactory.dispatchMetadataEvent
private function dispatchMetadataEvent($eventName, EntityMetadata $metadata) { $metadataArgs = new Events\MetadataArguments($metadata); $this->dispatcher->dispatch($eventName, $metadataArgs); }
php
private function dispatchMetadataEvent($eventName, EntityMetadata $metadata) { $metadataArgs = new Events\MetadataArguments($metadata); $this->dispatcher->dispatch($eventName, $metadataArgs); }
[ "private", "function", "dispatchMetadataEvent", "(", "$", "eventName", ",", "EntityMetadata", "$", "metadata", ")", "{", "$", "metadataArgs", "=", "new", "Events", "\\", "MetadataArguments", "(", "$", "metadata", ")", ";", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "$", "eventName", ",", "$", "metadataArgs", ")", ";", "}" ]
Dispatches a Metadata event @param string $eventName @param EntityMetadata $metadata
[ "Dispatches", "a", "Metadata", "event" ]
7e684b88bb22a2e18397df9402075c6533084b16
https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Metadata/MetadataFactory.php#L176-L180
train
as3io/modlr
src/Metadata/MetadataFactory.php
MetadataFactory.loadPersistenceMetadata
private function loadPersistenceMetadata(EntityMetadata $metadata) { $persisterKey = $metadata->persistence->getKey(); $persistenceFactory = $this->driver->getPersistenceMetadataFactory($persisterKey); $persistenceFactory->handleLoad($metadata); $persistenceFactory->handleValidate($metadata); return $metadata; }
php
private function loadPersistenceMetadata(EntityMetadata $metadata) { $persisterKey = $metadata->persistence->getKey(); $persistenceFactory = $this->driver->getPersistenceMetadataFactory($persisterKey); $persistenceFactory->handleLoad($metadata); $persistenceFactory->handleValidate($metadata); return $metadata; }
[ "private", "function", "loadPersistenceMetadata", "(", "EntityMetadata", "$", "metadata", ")", "{", "$", "persisterKey", "=", "$", "metadata", "->", "persistence", "->", "getKey", "(", ")", ";", "$", "persistenceFactory", "=", "$", "this", "->", "driver", "->", "getPersistenceMetadataFactory", "(", "$", "persisterKey", ")", ";", "$", "persistenceFactory", "->", "handleLoad", "(", "$", "metadata", ")", ";", "$", "persistenceFactory", "->", "handleValidate", "(", "$", "metadata", ")", ";", "return", "$", "metadata", ";", "}" ]
Handles persistence specific metadata loading. @param EntityMetadata $metadata @return EntityMetadata
[ "Handles", "persistence", "specific", "metadata", "loading", "." ]
7e684b88bb22a2e18397df9402075c6533084b16
https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Metadata/MetadataFactory.php#L288-L296
train
as3io/modlr
src/Metadata/MetadataFactory.php
MetadataFactory.loadSearchMetadata
private function loadSearchMetadata(EntityMetadata $metadata) { if (false === $metadata->isSearchEnabled()) { return $metadata; } $clientKey = $metadata->search->getKey(); $searchFactory = $this->driver->getSearchMetadataFactory($clientKey); $searchFactory->handleLoad($metadata); $searchFactory->handleValidate($metadata); return $metadata; }
php
private function loadSearchMetadata(EntityMetadata $metadata) { if (false === $metadata->isSearchEnabled()) { return $metadata; } $clientKey = $metadata->search->getKey(); $searchFactory = $this->driver->getSearchMetadataFactory($clientKey); $searchFactory->handleLoad($metadata); $searchFactory->handleValidate($metadata); return $metadata; }
[ "private", "function", "loadSearchMetadata", "(", "EntityMetadata", "$", "metadata", ")", "{", "if", "(", "false", "===", "$", "metadata", "->", "isSearchEnabled", "(", ")", ")", "{", "return", "$", "metadata", ";", "}", "$", "clientKey", "=", "$", "metadata", "->", "search", "->", "getKey", "(", ")", ";", "$", "searchFactory", "=", "$", "this", "->", "driver", "->", "getSearchMetadataFactory", "(", "$", "clientKey", ")", ";", "$", "searchFactory", "->", "handleLoad", "(", "$", "metadata", ")", ";", "$", "searchFactory", "->", "handleValidate", "(", "$", "metadata", ")", ";", "return", "$", "metadata", ";", "}" ]
Handles search specific metadata loading. @param EntityMetadata $metadata @return EntityMetadata
[ "Handles", "search", "specific", "metadata", "loading", "." ]
7e684b88bb22a2e18397df9402075c6533084b16
https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Metadata/MetadataFactory.php#L304-L315
train
malenkiki/bah
src/Malenki/Bah/N.php
N.less
public function less($num) { self::mustBeNumeric($num, 'Tested number'); if(is_object($num)){ return $this->value < $num->value; } else { return $this->value < $num; } }
php
public function less($num) { self::mustBeNumeric($num, 'Tested number'); if(is_object($num)){ return $this->value < $num->value; } else { return $this->value < $num; } }
[ "public", "function", "less", "(", "$", "num", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "num", ",", "'Tested number'", ")", ";", "if", "(", "is_object", "(", "$", "num", ")", ")", "{", "return", "$", "this", "->", "value", "<", "$", "num", "->", "value", ";", "}", "else", "{", "return", "$", "this", "->", "value", "<", "$", "num", ";", "}", "}" ]
Checks whether current number is less than given one. This is equivalent of `$n < 3`. So, for example: $n = new N(M_PI); $n->less(4); // true $n->less(3); // false @see N::lt() An alias @param mixed $num N or primitive numeric value @return boolean @throws \InvalidArgumentException If argument is not numeric-like
[ "Checks", "whether", "current", "number", "is", "less", "than", "given", "one", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L547-L556
train
malenkiki/bah
src/Malenki/Bah/N.php
N.lte
public function lte($num) { self::mustBeNumeric($num, 'Tested number'); if(is_object($num)){ return $this->value <= $num->value; } else { return $this->value <= $num; } }
php
public function lte($num) { self::mustBeNumeric($num, 'Tested number'); if(is_object($num)){ return $this->value <= $num->value; } else { return $this->value <= $num; } }
[ "public", "function", "lte", "(", "$", "num", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "num", ",", "'Tested number'", ")", ";", "if", "(", "is_object", "(", "$", "num", ")", ")", "{", "return", "$", "this", "->", "value", "<=", "$", "num", "->", "value", ";", "}", "else", "{", "return", "$", "this", "->", "value", "<=", "$", "num", ";", "}", "}" ]
Tests whether current number is less than or equal to given one. This is equivalent of `$n <= 3`. For example; $n = new N(3); $n->lte(3); // true $n->lte(4); // true $n->lte(1); // false @see N::le() An alias @param mixed $num N or numeric value @return boolean @throws \InvalidArgumentException If argument is not numeric-like value
[ "Tests", "whether", "current", "number", "is", "less", "than", "or", "equal", "to", "given", "one", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L586-L595
train
malenkiki/bah
src/Malenki/Bah/N.php
N.greater
public function greater($num) { self::mustBeNumeric($num, 'Tested number'); if(is_object($num)){ return $this->value > $num->value; } else { return $this->value > $num; } }
php
public function greater($num) { self::mustBeNumeric($num, 'Tested number'); if(is_object($num)){ return $this->value > $num->value; } else { return $this->value > $num; } }
[ "public", "function", "greater", "(", "$", "num", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "num", ",", "'Tested number'", ")", ";", "if", "(", "is_object", "(", "$", "num", ")", ")", "{", "return", "$", "this", "->", "value", ">", "$", "num", "->", "value", ";", "}", "else", "{", "return", "$", "this", "->", "value", ">", "$", "num", ";", "}", "}" ]
Tests whether current number is greater than given one. This is equivalent of `$n > 3`. For example: $n = new N(M_PI); $n->greater(2); // true $n->greater(4); // false @see N::gt() An alias @param mixed $num N or numeric value. @return boolean @throws \InvalidArgumentException If argument is not numeric-like value
[ "Tests", "whether", "current", "number", "is", "greater", "than", "given", "one", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L625-L634
train
malenkiki/bah
src/Malenki/Bah/N.php
N.gte
public function gte($num) { self::mustBeNumeric($num, 'Tested number'); if(is_object($num)){ return $this->value >= $num->value; } else { return $this->value >= $num; } }
php
public function gte($num) { self::mustBeNumeric($num, 'Tested number'); if(is_object($num)){ return $this->value >= $num->value; } else { return $this->value >= $num; } }
[ "public", "function", "gte", "(", "$", "num", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "num", ",", "'Tested number'", ")", ";", "if", "(", "is_object", "(", "$", "num", ")", ")", "{", "return", "$", "this", "->", "value", ">=", "$", "num", "->", "value", ";", "}", "else", "{", "return", "$", "this", "->", "value", ">=", "$", "num", ";", "}", "}" ]
Tests whether current number is greater than or equal to the given number. This is equivalent of `$n >= 3`. For example: $n = new N(3); $n->gte(3); // true $n->gte(1); // true $n->gte(5); // false @throw \InvalidArgumentException If argument is not numeric or N class @param mixed $num N or numeric value @return boolean
[ "Tests", "whether", "current", "number", "is", "greater", "than", "or", "equal", "to", "the", "given", "number", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L663-L672
train
malenkiki/bah
src/Malenki/Bah/N.php
N.mod
public function mod($mod) { self::mustBeNumeric($mod, 'Divisor'); if ($mod instanceof N) { $mod = $mod->double; } if ($mod == 0) { throw new \InvalidArgumentException('Cannot divide by 0!'); } return new N(fmod($this->value, $mod)); }
php
public function mod($mod) { self::mustBeNumeric($mod, 'Divisor'); if ($mod instanceof N) { $mod = $mod->double; } if ($mod == 0) { throw new \InvalidArgumentException('Cannot divide by 0!'); } return new N(fmod($this->value, $mod)); }
[ "public", "function", "mod", "(", "$", "mod", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "mod", ",", "'Divisor'", ")", ";", "if", "(", "$", "mod", "instanceof", "N", ")", "{", "$", "mod", "=", "$", "mod", "->", "double", ";", "}", "if", "(", "$", "mod", "==", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Cannot divide by 0!'", ")", ";", "}", "return", "new", "N", "(", "fmod", "(", "$", "this", "->", "value", ",", "$", "mod", ")", ")", ";", "}" ]
Computes modulo of current number Computes modulo of current number using given number as divisor. Unlike `mod()` function, this can use integer or float value, into primitive PHP type or into `\Malenki\Bah\N` object. Example: $n = new N(2001); echo $n->mod(5); // '1'; echo $n->mod(3); // '0' @see N::modulo() Alias method @param int|float|double|N $mod Divisor as an integer/float/double-like value @return N @throws \InvalidArgumentException If given number is not valid type @throws \InvalidArgumentException If given number is zero
[ "Computes", "modulo", "of", "current", "number" ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L859-L872
train
malenkiki/bah
src/Malenki/Bah/N.php
N._prime
protected function _prime() { if ($this->value < 2) { return false; } if (!$this->_decimal()->zero) { throw new \RuntimeException( 'You cannot test if number is prime numer if it is not an integer' ); } $max = floor(sqrt($this->value)); for ($i = 2; $i <= $max; $i++) { if ($this->value % $i == 0) { return false; } } return true; }
php
protected function _prime() { if ($this->value < 2) { return false; } if (!$this->_decimal()->zero) { throw new \RuntimeException( 'You cannot test if number is prime numer if it is not an integer' ); } $max = floor(sqrt($this->value)); for ($i = 2; $i <= $max; $i++) { if ($this->value % $i == 0) { return false; } } return true; }
[ "protected", "function", "_prime", "(", ")", "{", "if", "(", "$", "this", "->", "value", "<", "2", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "_decimal", "(", ")", "->", "zero", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'You cannot test if number is prime numer if it is not an integer'", ")", ";", "}", "$", "max", "=", "floor", "(", "sqrt", "(", "$", "this", "->", "value", ")", ")", ";", "for", "(", "$", "i", "=", "2", ";", "$", "i", "<=", "$", "max", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "value", "%", "$", "i", "==", "0", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks if current number is prime number Checks whether current number is prime number. Prime number can only by divided by itself and by one. Example: $n = new N(5); var_dump($n->prime); // true $n = new N(6); var_dump($n->prime); // false @see N::$prime Magic getter way @return boolean @throws \RuntimeException If current number is not an integer.
[ "Checks", "if", "current", "number", "is", "prime", "number" ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L908-L929
train
malenkiki/bah
src/Malenki/Bah/N.php
N._divisors
protected function _divisors() { if (!$this->_decimal()->zero) { throw new \RuntimeException('You can only get divisors from integers!'); } $n = abs($this->value); $a = new A(); for ($i = 1; $i <= $n; $i++) { if ($n % $i == 0) { $a->add(new self($i)); } } return $a; }
php
protected function _divisors() { if (!$this->_decimal()->zero) { throw new \RuntimeException('You can only get divisors from integers!'); } $n = abs($this->value); $a = new A(); for ($i = 1; $i <= $n; $i++) { if ($n % $i == 0) { $a->add(new self($i)); } } return $a; }
[ "protected", "function", "_divisors", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_decimal", "(", ")", "->", "zero", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'You can only get divisors from integers!'", ")", ";", "}", "$", "n", "=", "abs", "(", "$", "this", "->", "value", ")", ";", "$", "a", "=", "new", "A", "(", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "n", ";", "$", "i", "++", ")", "{", "if", "(", "$", "n", "%", "$", "i", "==", "0", ")", "{", "$", "a", "->", "add", "(", "new", "self", "(", "$", "i", ")", ")", ";", "}", "}", "return", "$", "a", ";", "}" ]
Gets divisors for the current integer numbers. If current number is negative, divisors will be based on its positive version. @throws \RuntimeException If current number is not an integer @return A Instance of A class
[ "Gets", "divisors", "for", "the", "current", "integer", "numbers", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L940-L956
train
malenkiki/bah
src/Malenki/Bah/N.php
N.pow
public function pow($num) { self::mustBeNumeric($num, 'Power calculus'); return new N( pow( $this->value, is_object($num) ? $num->value : $num ) ); }
php
public function pow($num) { self::mustBeNumeric($num, 'Power calculus'); return new N( pow( $this->value, is_object($num) ? $num->value : $num ) ); }
[ "public", "function", "pow", "(", "$", "num", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "num", ",", "'Power calculus'", ")", ";", "return", "new", "N", "(", "pow", "(", "$", "this", "->", "value", ",", "is_object", "(", "$", "num", ")", "?", "$", "num", "->", "value", ":", "$", "num", ")", ")", ";", "}" ]
Computes current number at given power. Takes current number to raise it at given power. Example: $n = new N(3); echo $n->pow(2); // '9' echo $n->pow(3); // '27' @see N::power() Alias @see N::_square() Alias for sqaure @see N::_cube() Alias for cube @param numeric|N $num Power @return N @throws \InvalidArgumentException If given power is not numeric-like value.
[ "Computes", "current", "number", "at", "given", "power", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L977-L987
train
malenkiki/bah
src/Malenki/Bah/N.php
N.root
public function root($num) { self::mustBeNumeric($num, 'Root'); $n = is_object($num) ? $num->value : $num; if ($n == 0) { throw new \InvalidArgumentException('Root must be not nul'); } return new N(pow($this->value, 1 / $n)); }
php
public function root($num) { self::mustBeNumeric($num, 'Root'); $n = is_object($num) ? $num->value : $num; if ($n == 0) { throw new \InvalidArgumentException('Root must be not nul'); } return new N(pow($this->value, 1 / $n)); }
[ "public", "function", "root", "(", "$", "num", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "num", ",", "'Root'", ")", ";", "$", "n", "=", "is_object", "(", "$", "num", ")", "?", "$", "num", "->", "value", ":", "$", "num", ";", "if", "(", "$", "n", "==", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Root must be not nul'", ")", ";", "}", "return", "new", "N", "(", "pow", "(", "$", "this", "->", "value", ",", "1", "/", "$", "n", ")", ")", ";", "}" ]
Gets nth root of current number. Gets Nth root of given number. Example: $n = new N(8); echo $n->root(3); // '2' echo $n->root(1); // '8' @see N::_sqrt() A shorthand for magic getter to get square roots. @see N::_cubeRoot() A shorthand for magic getter to get cube roots. @param numeric|N $num Root @return N @throws \InvalidArgumentException If root level is 0.
[ "Gets", "nth", "root", "of", "current", "number", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1082-L1093
train
malenkiki/bah
src/Malenki/Bah/N.php
N._factorial
protected function _factorial() { if ($this->value == 0) { return new N(1); } if ($this->value < 0) { throw new \RuntimeException( 'Cannot get factorial of negative number!' ); } if (!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot get factorial of non integer!' ); } return new N(array_product(range(1, $this->value))); }
php
protected function _factorial() { if ($this->value == 0) { return new N(1); } if ($this->value < 0) { throw new \RuntimeException( 'Cannot get factorial of negative number!' ); } if (!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot get factorial of non integer!' ); } return new N(array_product(range(1, $this->value))); }
[ "protected", "function", "_factorial", "(", ")", "{", "if", "(", "$", "this", "->", "value", "==", "0", ")", "{", "return", "new", "N", "(", "1", ")", ";", "}", "if", "(", "$", "this", "->", "value", "<", "0", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot get factorial of negative number!'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "_decimal", "(", ")", "->", "zero", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot get factorial of non integer!'", ")", ";", "}", "return", "new", "N", "(", "array_product", "(", "range", "(", "1", ",", "$", "this", "->", "value", ")", ")", ")", ";", "}" ]
Computes the factorial of current number. Computes the factorial of current number, the product form 1 to current integer number. $n = new N(1); echo $n->factorial; // 1 echo $n->incr->factorial; // 2 echo $n->incr->factorial; // 6 echo $n->incr->factorial; // 24 echo $n->incr->factorial; // 120 echo $n->incr->factorial; // 720 This method is the runtime part of magic getter `\Malenki\Bah\N::$factorial`; @see S::$factorial The magic getter `S::$factorial` @see S::$fact Magic getter alias `S::$fact` @return N @throws \RuntimeException If current number is negative or is not an integer.
[ "Computes", "the", "factorial", "of", "current", "number", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1176-L1195
train
malenkiki/bah
src/Malenki/Bah/N.php
N.equal
public function equal($num) { self::mustBeNumeric($num, 'Test of equality'); if(is_object($num)){ return $this->value == $num->value; } else { return $this->value == $num; } }
php
public function equal($num) { self::mustBeNumeric($num, 'Test of equality'); if(is_object($num)){ return $this->value == $num->value; } else { return $this->value == $num; } }
[ "public", "function", "equal", "(", "$", "num", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "num", ",", "'Test of equality'", ")", ";", "if", "(", "is_object", "(", "$", "num", ")", ")", "{", "return", "$", "this", "->", "value", "==", "$", "num", "->", "value", ";", "}", "else", "{", "return", "$", "this", "->", "value", "==", "$", "num", ";", "}", "}" ]
Checks if current number is equal to given argument. This tests current number with given argument, an object or primitive numeric value. Example: $n = new N(5); var_dump($n->eq(5)); // true var_dump($n->eq(5.0)); // true var_dump($n->eq(new N(5))); // true var_dump($n->eq(new N(5.0))); // true @see N::notEqual() The opposite test. @see N::eq() An alias @throw \InvalidArgumentException If argument is not numeric or N class @param numeric|N $num N or numeric value. @return boolean
[ "Checks", "if", "current", "number", "is", "equal", "to", "given", "argument", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1299-L1308
train
malenkiki/bah
src/Malenki/Bah/N.php
N._decimal
protected function _decimal() { $sign = 1; if ($this->value < 0) { $sign = -1; } return new N($sign * (abs($this->value) - floor(abs($this->value)))); }
php
protected function _decimal() { $sign = 1; if ($this->value < 0) { $sign = -1; } return new N($sign * (abs($this->value) - floor(abs($this->value)))); }
[ "protected", "function", "_decimal", "(", ")", "{", "$", "sign", "=", "1", ";", "if", "(", "$", "this", "->", "value", "<", "0", ")", "{", "$", "sign", "=", "-", "1", ";", "}", "return", "new", "N", "(", "$", "sign", "*", "(", "abs", "(", "$", "this", "->", "value", ")", "-", "floor", "(", "abs", "(", "$", "this", "->", "value", ")", ")", ")", ")", ";", "}" ]
Gets decimal part. Gets decimal part of current number . Example: $n = new N(3.14); echo $n->decimal; // '0.14' @see N::$decimal The magic getter version `N::$decimal` @return N
[ "Gets", "decimal", "part", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1433-L1442
train
malenkiki/bah
src/Malenki/Bah/N.php
N._odd
protected function _odd() { if((abs($this->value) - floor(abs($this->value))) != 0){ throw new \RuntimeException( 'Testing if number is odd or even only if it is an integer!' ); } return (boolean) ($this->value & 1); }
php
protected function _odd() { if((abs($this->value) - floor(abs($this->value))) != 0){ throw new \RuntimeException( 'Testing if number is odd or even only if it is an integer!' ); } return (boolean) ($this->value & 1); }
[ "protected", "function", "_odd", "(", ")", "{", "if", "(", "(", "abs", "(", "$", "this", "->", "value", ")", "-", "floor", "(", "abs", "(", "$", "this", "->", "value", ")", ")", ")", "!=", "0", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Testing if number is odd or even only if it is an integer!'", ")", ";", "}", "return", "(", "boolean", ")", "(", "$", "this", "->", "value", "&", "1", ")", ";", "}" ]
Tests whether current number is odd. Tests whether current integer number is odd or not. If current number is not an integer, then raises an `\RuntimeException`. This is used as runtime part of magic getter `S::$odd`. Example: $n = new N(3); $n->odd; // true $n = new N(4); $n->odd; // false $n = new N(3.14); $n->odd; // raises eception @see S::$odd The magic getter `S::$odd` $see S::_even() The opposite implementation for even number @return boolean @throws \RuntimeException If current number is not an integer
[ "Tests", "whether", "current", "number", "is", "odd", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1466-L1475
train
malenkiki/bah
src/Malenki/Bah/N.php
N.plus
public function plus($number) { self::mustBeNumeric($number, 'Value to add'); $number = is_object($number) ? $number->value : $number; return new self($this->value + $number); }
php
public function plus($number) { self::mustBeNumeric($number, 'Value to add'); $number = is_object($number) ? $number->value : $number; return new self($this->value + $number); }
[ "public", "function", "plus", "(", "$", "number", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "number", ",", "'Value to add'", ")", ";", "$", "number", "=", "is_object", "(", "$", "number", ")", "?", "$", "number", "->", "value", ":", "$", "number", ";", "return", "new", "self", "(", "$", "this", "->", "value", "+", "$", "number", ")", ";", "}" ]
Adds current number to given argument. Create new `\Malenki\Bah\N` having the sum of given argument with current number @param mixed $number Numeric-like value @return N @throws \InvalidArgumentException If argument is not N or numeric value.
[ "Adds", "current", "number", "to", "given", "argument", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1583-L1590
train
malenkiki/bah
src/Malenki/Bah/N.php
N.minus
public function minus($number) { self::mustBeNumeric($number, 'Value to substract'); $number = is_object($number) ? $number->value : $number; return new self($this->value - $number); }
php
public function minus($number) { self::mustBeNumeric($number, 'Value to substract'); $number = is_object($number) ? $number->value : $number; return new self($this->value - $number); }
[ "public", "function", "minus", "(", "$", "number", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "number", ",", "'Value to substract'", ")", ";", "$", "number", "=", "is_object", "(", "$", "number", ")", "?", "$", "number", "->", "value", ":", "$", "number", ";", "return", "new", "self", "(", "$", "this", "->", "value", "-", "$", "number", ")", ";", "}" ]
Substract current number with other. Creates new `\Malenki\Bah\N` having the substraction of given argument with current number @param mixed $number N or numeric value @return N @throws \InvalidArgumentException If argument is not N or numeric value.
[ "Substract", "current", "number", "with", "other", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1602-L1609
train
malenkiki/bah
src/Malenki/Bah/N.php
N.multiply
public function multiply($number) { self::mustBeNumeric($number, 'Value to multiply'); $number = is_object($number) ? $number->value : $number; return new self($this->value * $number); }
php
public function multiply($number) { self::mustBeNumeric($number, 'Value to multiply'); $number = is_object($number) ? $number->value : $number; return new self($this->value * $number); }
[ "public", "function", "multiply", "(", "$", "number", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "number", ",", "'Value to multiply'", ")", ";", "$", "number", "=", "is_object", "(", "$", "number", ")", "?", "$", "number", "->", "value", ":", "$", "number", ";", "return", "new", "self", "(", "$", "this", "->", "value", "*", "$", "number", ")", ";", "}" ]
Creates new N by multipling the current to the given one @throw \InvalidArgumentException If argument is not N or numeric value. @param mixed $number N or numeric value @return N
[ "Creates", "new", "N", "by", "multipling", "the", "current", "to", "the", "given", "one" ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1618-L1625
train
malenkiki/bah
src/Malenki/Bah/N.php
N.divide
public function divide($number) { self::mustBeNumeric($number, 'Value to divide'); $number = is_object($number) ? $number->value : $number; if ($number == 0) { throw new \InvalidArgumentException('You cannot divide by zero!'); } return new self($this->value / $number); }
php
public function divide($number) { self::mustBeNumeric($number, 'Value to divide'); $number = is_object($number) ? $number->value : $number; if ($number == 0) { throw new \InvalidArgumentException('You cannot divide by zero!'); } return new self($this->value / $number); }
[ "public", "function", "divide", "(", "$", "number", ")", "{", "self", "::", "mustBeNumeric", "(", "$", "number", ",", "'Value to divide'", ")", ";", "$", "number", "=", "is_object", "(", "$", "number", ")", "?", "$", "number", "->", "value", ":", "$", "number", ";", "if", "(", "$", "number", "==", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'You cannot divide by zero!'", ")", ";", "}", "return", "new", "self", "(", "$", "this", "->", "value", "/", "$", "number", ")", ";", "}" ]
Divide current number with given argument. @throw \InvalidArgumentException If given argument is zero @throw \InvalidArgumentException If given argument is not N or numeric value. @param mixed $number N or numeric value @return N
[ "Divide", "current", "number", "with", "given", "argument", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1635-L1646
train
malenkiki/bah
src/Malenki/Bah/N.php
N._roman
protected function _roman() { if(!$this->_decimal()->zero || $this->value < 0){ throw new \RuntimeException( 'Converting into roman numerals uses only positive integers.' ); } $arr_numerals = array( (object) array( 'integer' => 1000, 'roman' => 'm' ), (object) array( 'integer' => 900, 'roman' => 'cm' ), (object) array( 'integer' => 500, 'roman' => 'd' ), (object) array( 'integer' => 400, 'roman' => 'cd' ), (object) array( 'integer' => 100, 'roman' => 'c' ), (object) array( 'integer' => 90, 'roman' => 'xc' ), (object) array( 'integer' => 50, 'roman' => 'l' ), (object) array( 'integer' => 40, 'roman' => 'xl' ), (object) array( 'integer' => 10, 'roman' => 'x' ), (object) array( 'integer' => 9, 'roman' => 'ix' ), (object) array( 'integer' => 5, 'roman' => 'v' ), (object) array( 'integer' => 4, 'roman' => 'iv' ), (object) array( 'integer' => 1, 'roman' => 'i' ) ); $int_number = $this->value; $str_numeral = ''; $str_least = ''; $int_count_numerals = count($arr_numerals); for ($i = 0; $i < $int_count_numerals; $i++) { while ($int_number >= $arr_numerals[$i]->integer) { $str_least .= $arr_numerals[$i]->roman; $int_number -= $arr_numerals[$i]->integer; } } return new S($str_numeral . $str_least); }
php
protected function _roman() { if(!$this->_decimal()->zero || $this->value < 0){ throw new \RuntimeException( 'Converting into roman numerals uses only positive integers.' ); } $arr_numerals = array( (object) array( 'integer' => 1000, 'roman' => 'm' ), (object) array( 'integer' => 900, 'roman' => 'cm' ), (object) array( 'integer' => 500, 'roman' => 'd' ), (object) array( 'integer' => 400, 'roman' => 'cd' ), (object) array( 'integer' => 100, 'roman' => 'c' ), (object) array( 'integer' => 90, 'roman' => 'xc' ), (object) array( 'integer' => 50, 'roman' => 'l' ), (object) array( 'integer' => 40, 'roman' => 'xl' ), (object) array( 'integer' => 10, 'roman' => 'x' ), (object) array( 'integer' => 9, 'roman' => 'ix' ), (object) array( 'integer' => 5, 'roman' => 'v' ), (object) array( 'integer' => 4, 'roman' => 'iv' ), (object) array( 'integer' => 1, 'roman' => 'i' ) ); $int_number = $this->value; $str_numeral = ''; $str_least = ''; $int_count_numerals = count($arr_numerals); for ($i = 0; $i < $int_count_numerals; $i++) { while ($int_number >= $arr_numerals[$i]->integer) { $str_least .= $arr_numerals[$i]->roman; $int_number -= $arr_numerals[$i]->integer; } } return new S($str_numeral . $str_least); }
[ "protected", "function", "_roman", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_decimal", "(", ")", "->", "zero", "||", "$", "this", "->", "value", "<", "0", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Converting into roman numerals uses only positive integers.'", ")", ";", "}", "$", "arr_numerals", "=", "array", "(", "(", "object", ")", "array", "(", "'integer'", "=>", "1000", ",", "'roman'", "=>", "'m'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "900", ",", "'roman'", "=>", "'cm'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "500", ",", "'roman'", "=>", "'d'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "400", ",", "'roman'", "=>", "'cd'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "100", ",", "'roman'", "=>", "'c'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "90", ",", "'roman'", "=>", "'xc'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "50", ",", "'roman'", "=>", "'l'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "40", ",", "'roman'", "=>", "'xl'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "10", ",", "'roman'", "=>", "'x'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "9", ",", "'roman'", "=>", "'ix'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "5", ",", "'roman'", "=>", "'v'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "4", ",", "'roman'", "=>", "'iv'", ")", ",", "(", "object", ")", "array", "(", "'integer'", "=>", "1", ",", "'roman'", "=>", "'i'", ")", ")", ";", "$", "int_number", "=", "$", "this", "->", "value", ";", "$", "str_numeral", "=", "''", ";", "$", "str_least", "=", "''", ";", "$", "int_count_numerals", "=", "count", "(", "$", "arr_numerals", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "int_count_numerals", ";", "$", "i", "++", ")", "{", "while", "(", "$", "int_number", ">=", "$", "arr_numerals", "[", "$", "i", "]", "->", "integer", ")", "{", "$", "str_least", ".=", "$", "arr_numerals", "[", "$", "i", "]", "->", "roman", ";", "$", "int_number", "-=", "$", "arr_numerals", "[", "$", "i", "]", "->", "integer", ";", "}", "}", "return", "new", "S", "(", "$", "str_numeral", ".", "$", "str_least", ")", ";", "}" ]
Converts current number to roman number. This converts current positive integer to roman numerals, returning `\Malenki\Bah\S` object. Example: $n = new N(1979); echo $n->roman; // 'mcmlxxix' echo $n->roman->upper; // 'MCMLXXIX' @return S @throws \RuntimeException If current number is not an positive integer.
[ "Converts", "current", "number", "to", "roman", "number", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L1663-L1740
train
malenkiki/bah
src/Malenki/Bah/N.php
N._hex
protected function _hex() { if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot get hexadecimal numbers from non integer.' ); } if($this->value < 0){ return new S('-' . dechex(abs($this->value))); } else { return new S(dechex($this->value)); } }
php
protected function _hex() { if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot get hexadecimal numbers from non integer.' ); } if($this->value < 0){ return new S('-' . dechex(abs($this->value))); } else { return new S(dechex($this->value)); } }
[ "protected", "function", "_hex", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_decimal", "(", ")", "->", "zero", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot get hexadecimal numbers from non integer.'", ")", ";", "}", "if", "(", "$", "this", "->", "value", "<", "0", ")", "{", "return", "new", "S", "(", "'-'", ".", "dechex", "(", "abs", "(", "$", "this", "->", "value", ")", ")", ")", ";", "}", "else", "{", "return", "new", "S", "(", "dechex", "(", "$", "this", "->", "value", ")", ")", ";", "}", "}" ]
Converts to hexadecimal number. Returns current integer number converted to hexadecimal as `\Malenki\Bah\S` object. Example: $n = new N(2001); echo $n->hex; // '7d1' Negative numbers are allowed too: $n = new N(-2001); echo $n->hex; // '-7d1' This is runtime part of its associated magic getter. @see N::$hex Magic getter `N::$hex` @see N::_h() Alias @return S @throws \RuntimeException If current number is not an integer.
[ "Converts", "to", "hexadecimal", "number", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L2143-L2156
train
malenkiki/bah
src/Malenki/Bah/N.php
N._oct
protected function _oct() { if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot get octal numbers from non integer.' ); } if($this->value < 0){ return new S('-' . decoct(abs($this->value))); } else { return new S(decoct($this->value)); } }
php
protected function _oct() { if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot get octal numbers from non integer.' ); } if($this->value < 0){ return new S('-' . decoct(abs($this->value))); } else { return new S(decoct($this->value)); } }
[ "protected", "function", "_oct", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_decimal", "(", ")", "->", "zero", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot get octal numbers from non integer.'", ")", ";", "}", "if", "(", "$", "this", "->", "value", "<", "0", ")", "{", "return", "new", "S", "(", "'-'", ".", "decoct", "(", "abs", "(", "$", "this", "->", "value", ")", ")", ")", ";", "}", "else", "{", "return", "new", "S", "(", "decoct", "(", "$", "this", "->", "value", ")", ")", ";", "}", "}" ]
Converts to octal number. Returns current integer number converted to octal as `\Malenki\Bah\S` object. Example: $n = new N(2001); echo $n->oct; // '3721' Negative numbers are allowed too: $n = new N(-2001); echo $n->oct; // '-3721' This is runtime part of its associated magic getter. @see N::$oct Magic getter `N::$oct` @see N::_o() Alias @return S @throws \RuntimeException If current number is not an integer.
[ "Converts", "to", "octal", "number", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L2182-L2196
train
malenkiki/bah
src/Malenki/Bah/N.php
N._bin
protected function _bin() { if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot get binary numbers from non integer.' ); } if($this->value < 0){ return new S('-'.decbin(abs($this->value))); } else { return new S(decbin($this->value)); } }
php
protected function _bin() { if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot get binary numbers from non integer.' ); } if($this->value < 0){ return new S('-'.decbin(abs($this->value))); } else { return new S(decbin($this->value)); } }
[ "protected", "function", "_bin", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_decimal", "(", ")", "->", "zero", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot get binary numbers from non integer.'", ")", ";", "}", "if", "(", "$", "this", "->", "value", "<", "0", ")", "{", "return", "new", "S", "(", "'-'", ".", "decbin", "(", "abs", "(", "$", "this", "->", "value", ")", ")", ")", ";", "}", "else", "{", "return", "new", "S", "(", "decbin", "(", "$", "this", "->", "value", ")", ")", ";", "}", "}" ]
Converts to binary number. Returns current integer number converted to binary as `\Malenki\Bah\S` object. Example: $n = new N(2001); echo $n->bin; // '11111010001' Negative numbers are allowed too: $n = new N(-2001); echo $n->bin; // '-11111010001' This is runtime part of its associated magic getter. @see N::$bin Magic getter `N::$bin` @see N::_b() Alias @return S @throws \RuntimeException If current number is not an integer.
[ "Converts", "to", "binary", "number", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L2223-L2237
train
malenkiki/bah
src/Malenki/Bah/N.php
N.base
public function base($n) { self::mustBeInteger($n, 'Base'); if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot convert to another base from non integer value.' ); } $n = is_object($n) ? $n->int : $n; if (!is_numeric($n) || $n < 2 || $n > 36) { throw new \InvalidArgumentException( 'Base must be an integer or \Malenki\Bah\N value from 2 ' .'to 36 inclusive.' ); } return new S( ($this->value < 0 ? '-' : '') . base_convert($this->value, 10, $n) ); }
php
public function base($n) { self::mustBeInteger($n, 'Base'); if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot convert to another base from non integer value.' ); } $n = is_object($n) ? $n->int : $n; if (!is_numeric($n) || $n < 2 || $n > 36) { throw new \InvalidArgumentException( 'Base must be an integer or \Malenki\Bah\N value from 2 ' .'to 36 inclusive.' ); } return new S( ($this->value < 0 ? '-' : '') . base_convert($this->value, 10, $n) ); }
[ "public", "function", "base", "(", "$", "n", ")", "{", "self", "::", "mustBeInteger", "(", "$", "n", ",", "'Base'", ")", ";", "if", "(", "!", "$", "this", "->", "_decimal", "(", ")", "->", "zero", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot convert to another base from non integer value.'", ")", ";", "}", "$", "n", "=", "is_object", "(", "$", "n", ")", "?", "$", "n", "->", "int", ":", "$", "n", ";", "if", "(", "!", "is_numeric", "(", "$", "n", ")", "||", "$", "n", "<", "2", "||", "$", "n", ">", "36", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Base must be an integer or \\Malenki\\Bah\\N value from 2 '", ".", "'to 36 inclusive.'", ")", ";", "}", "return", "new", "S", "(", "(", "$", "this", "->", "value", "<", "0", "?", "'-'", ":", "''", ")", ".", "base_convert", "(", "$", "this", "->", "value", ",", "10", ",", "$", "n", ")", ")", ";", "}" ]
Converts current number into another base. This converts current number to another base. Alowed bases are into the range `[2, 36]`. $n = new N(2001); echo $n->base(2); // '11111010001' You can have negative result too: $n = new N(-2001); echo $n->base(2); // '-11111010001' @see S::$bin Shorthand for base 2 @see S::$oct Shorthand for base 8 @see S::$hex Shorthand for base 16 @see S::$b Another shorthand for base 2 @see S::$o Another shorthand for base 8 @see S::$h Another shorthand for base 16 @param mixed $n Base as integer-like value. @return S @throws \RuntimeException If current number is not an integer. @throws \InvalidArgumentException If given base number is not an Integer-like value.
[ "Converts", "current", "number", "into", "another", "base", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L2336-L2359
train
malenkiki/bah
src/Malenki/Bah/N.php
N.times
public function times($callback) { self::mustBeCallable($callback); if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot iterate given callback when number is not integer.' ); } if($this->value == 0){ throw new \RuntimeException( 'Cannot iterate given callback on a void range.' ); } if($this->value > 0){ $arr_range = range(0, $this->value - 1); } else { $arr_range = range($this->value + 1, 0); } $a = new A(); foreach($arr_range as $idx){ $idx = new N($idx); $a->add($callback($idx)); } return $a; }
php
public function times($callback) { self::mustBeCallable($callback); if(!$this->_decimal()->zero) { throw new \RuntimeException( 'Cannot iterate given callback when number is not integer.' ); } if($this->value == 0){ throw new \RuntimeException( 'Cannot iterate given callback on a void range.' ); } if($this->value > 0){ $arr_range = range(0, $this->value - 1); } else { $arr_range = range($this->value + 1, 0); } $a = new A(); foreach($arr_range as $idx){ $idx = new N($idx); $a->add($callback($idx)); } return $a; }
[ "public", "function", "times", "(", "$", "callback", ")", "{", "self", "::", "mustBeCallable", "(", "$", "callback", ")", ";", "if", "(", "!", "$", "this", "->", "_decimal", "(", ")", "->", "zero", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot iterate given callback when number is not integer.'", ")", ";", "}", "if", "(", "$", "this", "->", "value", "==", "0", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot iterate given callback on a void range.'", ")", ";", "}", "if", "(", "$", "this", "->", "value", ">", "0", ")", "{", "$", "arr_range", "=", "range", "(", "0", ",", "$", "this", "->", "value", "-", "1", ")", ";", "}", "else", "{", "$", "arr_range", "=", "range", "(", "$", "this", "->", "value", "+", "1", ",", "0", ")", ";", "}", "$", "a", "=", "new", "A", "(", ")", ";", "foreach", "(", "$", "arr_range", "as", "$", "idx", ")", "{", "$", "idx", "=", "new", "N", "(", "$", "idx", ")", ";", "$", "a", "->", "add", "(", "$", "callback", "(", "$", "idx", ")", ")", ";", "}", "return", "$", "a", ";", "}" ]
Repeats given callable param. Runs N times given callable param. N is current number. As argument, callable params as current index of iteration as `\Malenki\Bah\N` object. If callable param returns content, then each returned result is stored into an `\Malenki\Bah\A` object. Example: $n = new N(7); $func = function($i){ if($i->odd){ return true; } return false; }; var_dump($n->times($func)->array); // array(false, true, false, true, false, true, false) __Note:__ Current number can be negative, but cannot be zero @param mixed $callback A callable action @return N @throws \InvalidArgumentException If param is not callable @throws \RuntimeException If number is not an integer @throws \RuntimeException If number is zero
[ "Repeats", "given", "callable", "param", "." ]
23495014acec63c2790e8021c75bc97d7e04a9c7
https://github.com/malenkiki/bah/blob/23495014acec63c2790e8021c75bc97d7e04a9c7/src/Malenki/Bah/N.php#L2395-L2425
train
PhoxPHP/Glider
src/Schema/Scheme.php
Scheme.id
public function id(String $name = 'id', int $length = 15, Bool $null = false) { return $this->integer($name, $length, $null, true, ['primary' => true]); }
php
public function id(String $name = 'id', int $length = 15, Bool $null = false) { return $this->integer($name, $length, $null, true, ['primary' => true]); }
[ "public", "function", "id", "(", "String", "$", "name", "=", "'id'", ",", "int", "$", "length", "=", "15", ",", "Bool", "$", "null", "=", "false", ")", "{", "return", "$", "this", "->", "integer", "(", "$", "name", ",", "$", "length", ",", "$", "null", ",", "true", ",", "[", "'primary'", "=>", "true", "]", ")", ";", "}" ]
Represents an auto incremented field with a primary key index. @param $name String @param $length Integer @param $null Boolean @access public @return Object Kit\Glider\Schema\Column\Type\Contract\TypeContract
[ "Represents", "an", "auto", "incremented", "field", "with", "a", "primary", "key", "index", "." ]
17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042
https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Schema/Scheme.php#L106-L109
train
PhoxPHP/Glider
src/Schema/Scheme.php
Scheme.varchar
public function varchar(String $name, int $length=15, Bool $null=false, Bool $autoIncrement=false, Array $options=[]) { return $this->setType('Varchar', $name, $length, $null, $autoIncrement, $options); }
php
public function varchar(String $name, int $length=15, Bool $null=false, Bool $autoIncrement=false, Array $options=[]) { return $this->setType('Varchar', $name, $length, $null, $autoIncrement, $options); }
[ "public", "function", "varchar", "(", "String", "$", "name", ",", "int", "$", "length", "=", "15", ",", "Bool", "$", "null", "=", "false", ",", "Bool", "$", "autoIncrement", "=", "false", ",", "Array", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "setType", "(", "'Varchar'", ",", "$", "name", ",", "$", "length", ",", "$", "null", ",", "$", "autoIncrement", ",", "$", "options", ")", ";", "}" ]
Represents a variable-length non-binary string field. @param $name String @param $length Integer @param $null Boolean @param $autoIncrement Boolean @param $options Array @access public @return Object Kit\Glider\Schema\Column\Type\Contract\TypeContract
[ "Represents", "a", "variable", "-", "length", "non", "-", "binary", "string", "field", "." ]
17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042
https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Schema/Scheme.php#L122-L125
train
PhoxPHP/Glider
src/Schema/Scheme.php
Scheme.decimal
public function decimal(String $name, $length=15, Bool $null=false, Bool $autoIncrement=false, Array $options=[]) { return $this->setType('Decimal', $name, $length, $null, $autoIncrement, $options); }
php
public function decimal(String $name, $length=15, Bool $null=false, Bool $autoIncrement=false, Array $options=[]) { return $this->setType('Decimal', $name, $length, $null, $autoIncrement, $options); }
[ "public", "function", "decimal", "(", "String", "$", "name", ",", "$", "length", "=", "15", ",", "Bool", "$", "null", "=", "false", ",", "Bool", "$", "autoIncrement", "=", "false", ",", "Array", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "setType", "(", "'Decimal'", ",", "$", "name", ",", "$", "length", ",", "$", "null", ",", "$", "autoIncrement", ",", "$", "options", ")", ";", "}" ]
Represents a fixed-point number field. @param $name String @param $length Integer @param $null Boolean @param $autoIncrement Boolean @param $options Array @access public @return Object Kit\Glider\Schema\Column\Type\Contract\TypeContract
[ "Represents", "a", "fixed", "-", "point", "number", "field", "." ]
17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042
https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Schema/Scheme.php#L250-L253
train
PhoxPHP/Glider
src/Schema/Scheme.php
Scheme.date
public function date(String $name, Bool $null = false, Array $options = []) { return $this->setType('Date', $name, null, $null, false, $options); }
php
public function date(String $name, Bool $null = false, Array $options = []) { return $this->setType('Date', $name, null, $null, false, $options); }
[ "public", "function", "date", "(", "String", "$", "name", ",", "Bool", "$", "null", "=", "false", ",", "Array", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "setType", "(", "'Date'", ",", "$", "name", ",", "null", ",", "$", "null", ",", "false", ",", "$", "options", ")", ";", "}" ]
Represents a date field. @param $name String @param $null Boolean @param $options Array @access public @return Object Kit\Glider\Schema\Column\Type\Contract\TypeContract @since 1.4.6
[ "Represents", "a", "date", "field", "." ]
17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042
https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Schema/Scheme.php#L393-L396
train
PhoxPHP/Glider
src/Schema/Scheme.php
Scheme.foreign
public function foreign(String $keyName, Array $options=[], String $onDelete='NO ACTION', String $onUpdate='NO ACTION') { $columns = $options['columns']; $referenceTable = $options['references']; $refColumns = $options['refColumns']; $clauseList = ['CASCADE', 'RESTRICT', 'NO ACTION']; if (is_array($columns)) { $columns = implode(',', $columns); } if (is_array($refColumns)) { $refColumns = implode(',', $refColumns); } $onDelete = strtoupper($onDelete); $onUpdate = strtoupper($onUpdate); if (!in_array($onDelete, $clauseList)) { $onDelete = $clauseList[2]; } if (!in_array($onUpdate, $clauseList)) { $onUpdate = $clauseList[2]; } $definition = 'FOREIGN KEY ' . $keyName . '(' . $columns . ') REFERENCES ' . $referenceTable . '(' . $refColumns . ')'; $definition .= ' ON UPDATE ' . $onUpdate . ' ON DELETE ' . $onDelete; $options['type'] = 'FOREIGN'; $options['definition'] = $definition; Scheme::$commandsArray[$keyName] = $options; Scheme::$commands[] = $definition; }
php
public function foreign(String $keyName, Array $options=[], String $onDelete='NO ACTION', String $onUpdate='NO ACTION') { $columns = $options['columns']; $referenceTable = $options['references']; $refColumns = $options['refColumns']; $clauseList = ['CASCADE', 'RESTRICT', 'NO ACTION']; if (is_array($columns)) { $columns = implode(',', $columns); } if (is_array($refColumns)) { $refColumns = implode(',', $refColumns); } $onDelete = strtoupper($onDelete); $onUpdate = strtoupper($onUpdate); if (!in_array($onDelete, $clauseList)) { $onDelete = $clauseList[2]; } if (!in_array($onUpdate, $clauseList)) { $onUpdate = $clauseList[2]; } $definition = 'FOREIGN KEY ' . $keyName . '(' . $columns . ') REFERENCES ' . $referenceTable . '(' . $refColumns . ')'; $definition .= ' ON UPDATE ' . $onUpdate . ' ON DELETE ' . $onDelete; $options['type'] = 'FOREIGN'; $options['definition'] = $definition; Scheme::$commandsArray[$keyName] = $options; Scheme::$commands[] = $definition; }
[ "public", "function", "foreign", "(", "String", "$", "keyName", ",", "Array", "$", "options", "=", "[", "]", ",", "String", "$", "onDelete", "=", "'NO ACTION'", ",", "String", "$", "onUpdate", "=", "'NO ACTION'", ")", "{", "$", "columns", "=", "$", "options", "[", "'columns'", "]", ";", "$", "referenceTable", "=", "$", "options", "[", "'references'", "]", ";", "$", "refColumns", "=", "$", "options", "[", "'refColumns'", "]", ";", "$", "clauseList", "=", "[", "'CASCADE'", ",", "'RESTRICT'", ",", "'NO ACTION'", "]", ";", "if", "(", "is_array", "(", "$", "columns", ")", ")", "{", "$", "columns", "=", "implode", "(", "','", ",", "$", "columns", ")", ";", "}", "if", "(", "is_array", "(", "$", "refColumns", ")", ")", "{", "$", "refColumns", "=", "implode", "(", "','", ",", "$", "refColumns", ")", ";", "}", "$", "onDelete", "=", "strtoupper", "(", "$", "onDelete", ")", ";", "$", "onUpdate", "=", "strtoupper", "(", "$", "onUpdate", ")", ";", "if", "(", "!", "in_array", "(", "$", "onDelete", ",", "$", "clauseList", ")", ")", "{", "$", "onDelete", "=", "$", "clauseList", "[", "2", "]", ";", "}", "if", "(", "!", "in_array", "(", "$", "onUpdate", ",", "$", "clauseList", ")", ")", "{", "$", "onUpdate", "=", "$", "clauseList", "[", "2", "]", ";", "}", "$", "definition", "=", "'FOREIGN KEY '", ".", "$", "keyName", ".", "'('", ".", "$", "columns", ".", "') REFERENCES '", ".", "$", "referenceTable", ".", "'('", ".", "$", "refColumns", ".", "')'", ";", "$", "definition", ".=", "' ON UPDATE '", ".", "$", "onUpdate", ".", "' ON DELETE '", ".", "$", "onDelete", ";", "$", "options", "[", "'type'", "]", "=", "'FOREIGN'", ";", "$", "options", "[", "'definition'", "]", "=", "$", "definition", ";", "Scheme", "::", "$", "commandsArray", "[", "$", "keyName", "]", "=", "$", "options", ";", "Scheme", "::", "$", "commands", "[", "]", "=", "$", "definition", ";", "}" ]
Generates a foreign key constraint. @param $keyName <String> @param $options <Array> @param $onDelete <String> @param $onUpdate <String> @access public @return <void>
[ "Generates", "a", "foreign", "key", "constraint", "." ]
17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042
https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Schema/Scheme.php#L517-L552
train
PhoxPHP/Glider
src/Schema/Scheme.php
Scheme.getDefinition
public function getDefinition($separator=',') { $commands = self::$commands; if (sizeof($commands) > 0) { return implode($separator, $commands); } return null; }
php
public function getDefinition($separator=',') { $commands = self::$commands; if (sizeof($commands) > 0) { return implode($separator, $commands); } return null; }
[ "public", "function", "getDefinition", "(", "$", "separator", "=", "','", ")", "{", "$", "commands", "=", "self", "::", "$", "commands", ";", "if", "(", "sizeof", "(", "$", "commands", ")", ">", "0", ")", "{", "return", "implode", "(", "$", "separator", ",", "$", "commands", ")", ";", "}", "return", "null", ";", "}" ]
Returns type sql definition. @access public @return <Mixed>
[ "Returns", "type", "sql", "definition", "." ]
17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042
https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Schema/Scheme.php#L560-L569
train
METANETAG/formHandler
lib/ch/metanet/formHandler/field/FileField.php
FileField.convertMultiFileArray
protected function convertMultiFileArray(array $filesArr) { $files = array(); $filesCount = count($filesArr[self::VALUE_NAME]); for($i = 0; $i < $filesCount; ++$i) { $files[] = array( self::VALUE_NAME => $filesArr[self::VALUE_NAME][$i], self::VALUE_TYPE => $filesArr[self::VALUE_TYPE][$i], self::VALUE_TMP_NAME => $filesArr[self::VALUE_TMP_NAME][$i], self::VALUE_ERROR => $filesArr[self::VALUE_ERROR][$i], self::VALUE_SIZE => $filesArr[self::VALUE_SIZE][$i], ); } return $files; }
php
protected function convertMultiFileArray(array $filesArr) { $files = array(); $filesCount = count($filesArr[self::VALUE_NAME]); for($i = 0; $i < $filesCount; ++$i) { $files[] = array( self::VALUE_NAME => $filesArr[self::VALUE_NAME][$i], self::VALUE_TYPE => $filesArr[self::VALUE_TYPE][$i], self::VALUE_TMP_NAME => $filesArr[self::VALUE_TMP_NAME][$i], self::VALUE_ERROR => $filesArr[self::VALUE_ERROR][$i], self::VALUE_SIZE => $filesArr[self::VALUE_SIZE][$i], ); } return $files; }
[ "protected", "function", "convertMultiFileArray", "(", "array", "$", "filesArr", ")", "{", "$", "files", "=", "array", "(", ")", ";", "$", "filesCount", "=", "count", "(", "$", "filesArr", "[", "self", "::", "VALUE_NAME", "]", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "filesCount", ";", "++", "$", "i", ")", "{", "$", "files", "[", "]", "=", "array", "(", "self", "::", "VALUE_NAME", "=>", "$", "filesArr", "[", "self", "::", "VALUE_NAME", "]", "[", "$", "i", "]", ",", "self", "::", "VALUE_TYPE", "=>", "$", "filesArr", "[", "self", "::", "VALUE_TYPE", "]", "[", "$", "i", "]", ",", "self", "::", "VALUE_TMP_NAME", "=>", "$", "filesArr", "[", "self", "::", "VALUE_TMP_NAME", "]", "[", "$", "i", "]", ",", "self", "::", "VALUE_ERROR", "=>", "$", "filesArr", "[", "self", "::", "VALUE_ERROR", "]", "[", "$", "i", "]", ",", "self", "::", "VALUE_SIZE", "=>", "$", "filesArr", "[", "self", "::", "VALUE_SIZE", "]", "[", "$", "i", "]", ",", ")", ";", "}", "return", "$", "files", ";", "}" ]
Restructures an input array of multiple files @param array $filesArr @return array
[ "Restructures", "an", "input", "array", "of", "multiple", "files" ]
4f6e556e54e3a683edd7da0d2f72ed64e6bf1580
https://github.com/METANETAG/formHandler/blob/4f6e556e54e3a683edd7da0d2f72ed64e6bf1580/lib/ch/metanet/formHandler/field/FileField.php#L178-L194
train
selikhovleonid/nadir
src/core/AbstractCliCtrl.php
AbstractCliCtrl.printLog
protected function printLog($sMessage) { $oDate = new \DateTime(); echo $oDate->format('H:i:s')."\t{$sMessage}".PHP_EOL; return '('.$oDate->format('H:i:s').') '.preg_replace( '#(\[[0-9]+m)#', '', $sMessage ); }
php
protected function printLog($sMessage) { $oDate = new \DateTime(); echo $oDate->format('H:i:s')."\t{$sMessage}".PHP_EOL; return '('.$oDate->format('H:i:s').') '.preg_replace( '#(\[[0-9]+m)#', '', $sMessage ); }
[ "protected", "function", "printLog", "(", "$", "sMessage", ")", "{", "$", "oDate", "=", "new", "\\", "DateTime", "(", ")", ";", "echo", "$", "oDate", "->", "format", "(", "'H:i:s'", ")", ".", "\"\\t{$sMessage}\"", ".", "PHP_EOL", ";", "return", "'('", ".", "$", "oDate", "->", "format", "(", "'H:i:s'", ")", ".", "') '", ".", "preg_replace", "(", "'#(\\[[0-9]+m)#'", ",", "''", ",", "$", "sMessage", ")", ";", "}" ]
Print message to console @param string $sMessage Message to print @return string Message with time
[ "Print", "message", "to", "console" ]
47545fccd8516c8f0a20c02ba62f68269c7199da
https://github.com/selikhovleonid/nadir/blob/47545fccd8516c8f0a20c02ba62f68269c7199da/src/core/AbstractCliCtrl.php#L29-L38
train
the-kbA-team/sap-datetime
src/SapDateTime.php
SapDateTime.createFromSapWeek
public static function createFromSapWeek($sapWeek, $timezone = null) { if (preg_match(static::$sapWeekRegex, $sapWeek, $matches) !== 1) { return false; } $week = sprintf('%sW%s', $matches[1], $matches[2]); return new parent($week, $timezone); }
php
public static function createFromSapWeek($sapWeek, $timezone = null) { if (preg_match(static::$sapWeekRegex, $sapWeek, $matches) !== 1) { return false; } $week = sprintf('%sW%s', $matches[1], $matches[2]); return new parent($week, $timezone); }
[ "public", "static", "function", "createFromSapWeek", "(", "$", "sapWeek", ",", "$", "timezone", "=", "null", ")", "{", "if", "(", "preg_match", "(", "static", "::", "$", "sapWeekRegex", ",", "$", "sapWeek", ",", "$", "matches", ")", "!==", "1", ")", "{", "return", "false", ";", "}", "$", "week", "=", "sprintf", "(", "'%sW%s'", ",", "$", "matches", "[", "1", "]", ",", "$", "matches", "[", "2", "]", ")", ";", "return", "new", "parent", "(", "$", "week", ",", "$", "timezone", ")", ";", "}" ]
Parse an SAP week string into a new DateTime object. @param string $sapWeek String representing the SAP week. @param \DateTimeZone $timezone A DateTimeZone object representing the desired time zone. @return \DateTime|boolean @throws \Exception
[ "Parse", "an", "SAP", "week", "string", "into", "a", "new", "DateTime", "object", "." ]
30c1f7549f4848c7626c2832bf57257dc61bd062
https://github.com/the-kbA-team/sap-datetime/blob/30c1f7549f4848c7626c2832bf57257dc61bd062/src/SapDateTime.php#L55-L62
train
slickframework/form
src/Form.php
Form.getElementData
protected function getElementData( ContainerInterface $container, &$data = [] ) { foreach ($container as $element) { if ($element instanceof InputInterface) { $data[$element->getName()] = $element->getValue(); continue; } if ($element instanceof ContainerInterface) { $this->getElementData($element, $data); continue; } } }
php
protected function getElementData( ContainerInterface $container, &$data = [] ) { foreach ($container as $element) { if ($element instanceof InputInterface) { $data[$element->getName()] = $element->getValue(); continue; } if ($element instanceof ContainerInterface) { $this->getElementData($element, $data); continue; } } }
[ "protected", "function", "getElementData", "(", "ContainerInterface", "$", "container", ",", "&", "$", "data", "=", "[", "]", ")", "{", "foreach", "(", "$", "container", "as", "$", "element", ")", "{", "if", "(", "$", "element", "instanceof", "InputInterface", ")", "{", "$", "data", "[", "$", "element", "->", "getName", "(", ")", "]", "=", "$", "element", "->", "getValue", "(", ")", ";", "continue", ";", "}", "if", "(", "$", "element", "instanceof", "ContainerInterface", ")", "{", "$", "this", "->", "getElementData", "(", "$", "element", ",", "$", "data", ")", ";", "continue", ";", "}", "}", "}" ]
Recursively collects all posted data @param ContainerInterface $container @param array $data
[ "Recursively", "collects", "all", "posted", "data" ]
e7d536b3bad49194e246ff93587da2589e31a003
https://github.com/slickframework/form/blob/e7d536b3bad49194e246ff93587da2589e31a003/src/Form.php#L100-L114
train
slickframework/form
src/Form.php
Form.wasSubmitted
public function wasSubmitted() { $formMethod = strtoupper($this->getAttribute('method', 'post')); $formId = $this->getRequest()->getPost('form-id', false); $formId = $formId ? $formId : $this->getRequest()->getQuery('form-id', null); $submitted = $this->request->getMethod() == $formMethod && $formId == $this->getId(); if ($submitted) { $this->updateValuesFromRequest(); } return $submitted; }
php
public function wasSubmitted() { $formMethod = strtoupper($this->getAttribute('method', 'post')); $formId = $this->getRequest()->getPost('form-id', false); $formId = $formId ? $formId : $this->getRequest()->getQuery('form-id', null); $submitted = $this->request->getMethod() == $formMethod && $formId == $this->getId(); if ($submitted) { $this->updateValuesFromRequest(); } return $submitted; }
[ "public", "function", "wasSubmitted", "(", ")", "{", "$", "formMethod", "=", "strtoupper", "(", "$", "this", "->", "getAttribute", "(", "'method'", ",", "'post'", ")", ")", ";", "$", "formId", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getPost", "(", "'form-id'", ",", "false", ")", ";", "$", "formId", "=", "$", "formId", "?", "$", "formId", ":", "$", "this", "->", "getRequest", "(", ")", "->", "getQuery", "(", "'form-id'", ",", "null", ")", ";", "$", "submitted", "=", "$", "this", "->", "request", "->", "getMethod", "(", ")", "==", "$", "formMethod", "&&", "$", "formId", "==", "$", "this", "->", "getId", "(", ")", ";", "if", "(", "$", "submitted", ")", "{", "$", "this", "->", "updateValuesFromRequest", "(", ")", ";", "}", "return", "$", "submitted", ";", "}" ]
Check if for was submitted or not @return boolean
[ "Check", "if", "for", "was", "submitted", "or", "not" ]
e7d536b3bad49194e246ff93587da2589e31a003
https://github.com/slickframework/form/blob/e7d536b3bad49194e246ff93587da2589e31a003/src/Form.php#L169-L183
train
slickframework/form
src/Form.php
Form.updateValuesFromRequest
protected function updateValuesFromRequest() { $data = $this->getRequest()->isPost() ? $this->getRequest()->getPost() : $this->getRequest()->getQuery(); if (isset($_FILES)) { $data = array_merge($data, $this->request->getUploadedFiles()); } $this->setValues($data); }
php
protected function updateValuesFromRequest() { $data = $this->getRequest()->isPost() ? $this->getRequest()->getPost() : $this->getRequest()->getQuery(); if (isset($_FILES)) { $data = array_merge($data, $this->request->getUploadedFiles()); } $this->setValues($data); }
[ "protected", "function", "updateValuesFromRequest", "(", ")", "{", "$", "data", "=", "$", "this", "->", "getRequest", "(", ")", "->", "isPost", "(", ")", "?", "$", "this", "->", "getRequest", "(", ")", "->", "getPost", "(", ")", ":", "$", "this", "->", "getRequest", "(", ")", "->", "getQuery", "(", ")", ";", "if", "(", "isset", "(", "$", "_FILES", ")", ")", "{", "$", "data", "=", "array_merge", "(", "$", "data", ",", "$", "this", "->", "request", "->", "getUploadedFiles", "(", ")", ")", ";", "}", "$", "this", "->", "setValues", "(", "$", "data", ")", ";", "}" ]
Assign form values from request
[ "Assign", "form", "values", "from", "request" ]
e7d536b3bad49194e246ff93587da2589e31a003
https://github.com/slickframework/form/blob/e7d536b3bad49194e246ff93587da2589e31a003/src/Form.php#L201-L211
train
Synapse-Cmf/synapse-cmf
src/Synapse/Cmf/Framework/Theme/Zone/Domain/Command/CreateCommand.php
CreateCommand.resolve
public function resolve() { $this->zone = new $this->zoneClass(); $this->zone->setZoneType($this->zoneType); $this->zone->setComponents( $this->components->buildRanking() ); $this->assertEntityIsValid($this->zone, array('Zone', 'creation')); $this->fireEvent( ZoneEvents::ZONE_CREATED, new ZoneEvent($this->zone, $this) ); return $this->zone; }
php
public function resolve() { $this->zone = new $this->zoneClass(); $this->zone->setZoneType($this->zoneType); $this->zone->setComponents( $this->components->buildRanking() ); $this->assertEntityIsValid($this->zone, array('Zone', 'creation')); $this->fireEvent( ZoneEvents::ZONE_CREATED, new ZoneEvent($this->zone, $this) ); return $this->zone; }
[ "public", "function", "resolve", "(", ")", "{", "$", "this", "->", "zone", "=", "new", "$", "this", "->", "zoneClass", "(", ")", ";", "$", "this", "->", "zone", "->", "setZoneType", "(", "$", "this", "->", "zoneType", ")", ";", "$", "this", "->", "zone", "->", "setComponents", "(", "$", "this", "->", "components", "->", "buildRanking", "(", ")", ")", ";", "$", "this", "->", "assertEntityIsValid", "(", "$", "this", "->", "zone", ",", "array", "(", "'Zone'", ",", "'creation'", ")", ")", ";", "$", "this", "->", "fireEvent", "(", "ZoneEvents", "::", "ZONE_CREATED", ",", "new", "ZoneEvent", "(", "$", "this", "->", "zone", ",", "$", "this", ")", ")", ";", "return", "$", "this", "->", "zone", ";", "}" ]
Zone creation method. @return Zone
[ "Zone", "creation", "method", "." ]
d8122a4150a83d5607289724425cf35c56a5e880
https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Cmf/Framework/Theme/Zone/Domain/Command/CreateCommand.php#L47-L63
train
wigedev/farm
src/DataInterface/Grid.php
Grid.addRow
public function addRow(array $data = []) : int { $this->crudEnabled(); $table_name = static::$table_name; if (0 == count($data)) { // Insert a blank row $sql = "INSERT INTO {$table_name} DEFAULT VALUES"; // TODO: Move this to the DAO class $this->dbc->query($sql); } else { // Generate the values $components = $this->dbc->generateParameterizedComponents($data); $fields = $components['fields']; $values = $components['values']; $params = $components['params']; // Execute the query $sql = "INSERT INTO {$table_name} ({$fields}) VALUES ({$values})"; $this->dbc->query($sql, ['params' => $params]); } // Return the id of the new field return $this->dbc->lastInsertId(); }
php
public function addRow(array $data = []) : int { $this->crudEnabled(); $table_name = static::$table_name; if (0 == count($data)) { // Insert a blank row $sql = "INSERT INTO {$table_name} DEFAULT VALUES"; // TODO: Move this to the DAO class $this->dbc->query($sql); } else { // Generate the values $components = $this->dbc->generateParameterizedComponents($data); $fields = $components['fields']; $values = $components['values']; $params = $components['params']; // Execute the query $sql = "INSERT INTO {$table_name} ({$fields}) VALUES ({$values})"; $this->dbc->query($sql, ['params' => $params]); } // Return the id of the new field return $this->dbc->lastInsertId(); }
[ "public", "function", "addRow", "(", "array", "$", "data", "=", "[", "]", ")", ":", "int", "{", "$", "this", "->", "crudEnabled", "(", ")", ";", "$", "table_name", "=", "static", "::", "$", "table_name", ";", "if", "(", "0", "==", "count", "(", "$", "data", ")", ")", "{", "// Insert a blank row", "$", "sql", "=", "\"INSERT INTO {$table_name} DEFAULT VALUES\"", ";", "// TODO: Move this to the DAO class", "$", "this", "->", "dbc", "->", "query", "(", "$", "sql", ")", ";", "}", "else", "{", "// Generate the values", "$", "components", "=", "$", "this", "->", "dbc", "->", "generateParameterizedComponents", "(", "$", "data", ")", ";", "$", "fields", "=", "$", "components", "[", "'fields'", "]", ";", "$", "values", "=", "$", "components", "[", "'values'", "]", ";", "$", "params", "=", "$", "components", "[", "'params'", "]", ";", "// Execute the query", "$", "sql", "=", "\"INSERT INTO {$table_name} ({$fields}) VALUES ({$values})\"", ";", "$", "this", "->", "dbc", "->", "query", "(", "$", "sql", ",", "[", "'params'", "=>", "$", "params", "]", ")", ";", "}", "// Return the id of the new field", "return", "$", "this", "->", "dbc", "->", "lastInsertId", "(", ")", ";", "}" ]
Add a row to the table represented by this grid. If a table name, id column or structure for the table is not defined above, this function will not work. @param string[] $data The parameters to be added to the row @return int The id of the generated row @throws \Exception If required values have not been set on the child class.
[ "Add", "a", "row", "to", "the", "table", "represented", "by", "this", "grid", ".", "If", "a", "table", "name", "id", "column", "or", "structure", "for", "the", "table", "is", "not", "defined", "above", "this", "function", "will", "not", "work", "." ]
7a1729ec78628b7e5435e4a42e42d547a07af851
https://github.com/wigedev/farm/blob/7a1729ec78628b7e5435e4a42e42d547a07af851/src/DataInterface/Grid.php#L43-L66
train
wigedev/farm
src/DataInterface/Grid.php
Grid.deleteRow
public function deleteRow(int $id) : void { $this->crudEnabled(); // Generate the values $table_name = static::$table_name; $id_column = static::$id_column; $sql = "DELETE FROM {$table_name} WHERE {$id_column} = :key"; $this->dbc->query($sql, ['params' => [':key' => $id]]); }
php
public function deleteRow(int $id) : void { $this->crudEnabled(); // Generate the values $table_name = static::$table_name; $id_column = static::$id_column; $sql = "DELETE FROM {$table_name} WHERE {$id_column} = :key"; $this->dbc->query($sql, ['params' => [':key' => $id]]); }
[ "public", "function", "deleteRow", "(", "int", "$", "id", ")", ":", "void", "{", "$", "this", "->", "crudEnabled", "(", ")", ";", "// Generate the values", "$", "table_name", "=", "static", "::", "$", "table_name", ";", "$", "id_column", "=", "static", "::", "$", "id_column", ";", "$", "sql", "=", "\"DELETE FROM {$table_name} WHERE {$id_column} = :key\"", ";", "$", "this", "->", "dbc", "->", "query", "(", "$", "sql", ",", "[", "'params'", "=>", "[", "':key'", "=>", "$", "id", "]", "]", ")", ";", "}" ]
Delete the row specified by the passed identifier. If the necessary crud fields have not been identified in the child class, this function will throw an exception. @param int $id @throws \Exception
[ "Delete", "the", "row", "specified", "by", "the", "passed", "identifier", ".", "If", "the", "necessary", "crud", "fields", "have", "not", "been", "identified", "in", "the", "child", "class", "this", "function", "will", "throw", "an", "exception", "." ]
7a1729ec78628b7e5435e4a42e42d547a07af851
https://github.com/wigedev/farm/blob/7a1729ec78628b7e5435e4a42e42d547a07af851/src/DataInterface/Grid.php#L75-L85
train
wigedev/farm
src/DataInterface/Grid.php
Grid.updateRow
public function updateRow($id, array $data) : void { $this->crudEnabled(); // Generate the values $components = $this->dbc->generateParameterizedComponents($data); $table_name = static::$table_name; $id_column = static::$id_column; $fields = $components['update']; $params = $components['params']; $params[':key'] = $id; // Execute the query $sql = "UPDATE {$table_name} SET {$fields} WHERE {$id_column} = :key"; $this->dbc->query($sql, ['params' => $params]); }
php
public function updateRow($id, array $data) : void { $this->crudEnabled(); // Generate the values $components = $this->dbc->generateParameterizedComponents($data); $table_name = static::$table_name; $id_column = static::$id_column; $fields = $components['update']; $params = $components['params']; $params[':key'] = $id; // Execute the query $sql = "UPDATE {$table_name} SET {$fields} WHERE {$id_column} = :key"; $this->dbc->query($sql, ['params' => $params]); }
[ "public", "function", "updateRow", "(", "$", "id", ",", "array", "$", "data", ")", ":", "void", "{", "$", "this", "->", "crudEnabled", "(", ")", ";", "// Generate the values", "$", "components", "=", "$", "this", "->", "dbc", "->", "generateParameterizedComponents", "(", "$", "data", ")", ";", "$", "table_name", "=", "static", "::", "$", "table_name", ";", "$", "id_column", "=", "static", "::", "$", "id_column", ";", "$", "fields", "=", "$", "components", "[", "'update'", "]", ";", "$", "params", "=", "$", "components", "[", "'params'", "]", ";", "$", "params", "[", "':key'", "]", "=", "$", "id", ";", "// Execute the query", "$", "sql", "=", "\"UPDATE {$table_name} SET {$fields} WHERE {$id_column} = :key\"", ";", "$", "this", "->", "dbc", "->", "query", "(", "$", "sql", ",", "[", "'params'", "=>", "$", "params", "]", ")", ";", "}" ]
Updates an existing row, based on the passed identifier. If the necessary crud fields have not been identified in the child class, this function will throw an exception. @param mixed $id The id of the row to update @param array $data The new data to enter @throws \Exception
[ "Updates", "an", "existing", "row", "based", "on", "the", "passed", "identifier", ".", "If", "the", "necessary", "crud", "fields", "have", "not", "been", "identified", "in", "the", "child", "class", "this", "function", "will", "throw", "an", "exception", "." ]
7a1729ec78628b7e5435e4a42e42d547a07af851
https://github.com/wigedev/farm/blob/7a1729ec78628b7e5435e4a42e42d547a07af851/src/DataInterface/Grid.php#L95-L110
train
diasbruno/stc
lib/stc/Database.php
Database.store
public function store($key = '', $value = array(), $lock = true) { if ($key == '') { $this->fault('[Error] Cannot store data without a key. Key is "' . $key . '".'); } if (!$this->has_key($key)) { $this->create($key, $lock); $this->store_data($key, $value); } else { if (!$this->is_locked($key)) { $this->store_data($key, $value); } else { $this->fault('[Error] Cannot store data with a registered key that is locked.'); } } }
php
public function store($key = '', $value = array(), $lock = true) { if ($key == '') { $this->fault('[Error] Cannot store data without a key. Key is "' . $key . '".'); } if (!$this->has_key($key)) { $this->create($key, $lock); $this->store_data($key, $value); } else { if (!$this->is_locked($key)) { $this->store_data($key, $value); } else { $this->fault('[Error] Cannot store data with a registered key that is locked.'); } } }
[ "public", "function", "store", "(", "$", "key", "=", "''", ",", "$", "value", "=", "array", "(", ")", ",", "$", "lock", "=", "true", ")", "{", "if", "(", "$", "key", "==", "''", ")", "{", "$", "this", "->", "fault", "(", "'[Error] Cannot store data without a key. Key is \"'", ".", "$", "key", ".", "'\".'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "has_key", "(", "$", "key", ")", ")", "{", "$", "this", "->", "create", "(", "$", "key", ",", "$", "lock", ")", ";", "$", "this", "->", "store_data", "(", "$", "key", ",", "$", "value", ")", ";", "}", "else", "{", "if", "(", "!", "$", "this", "->", "is_locked", "(", "$", "key", ")", ")", "{", "$", "this", "->", "store_data", "(", "$", "key", ",", "$", "value", ")", ";", "}", "else", "{", "$", "this", "->", "fault", "(", "'[Error] Cannot store data with a registered key that is locked.'", ")", ";", "}", "}", "}" ]
Saves some data by key value. @param $key string | The key name. @param $value any | The value.
[ "Saves", "some", "data", "by", "key", "value", "." ]
43f62c3b28167bff76274f954e235413a9e9c707
https://github.com/diasbruno/stc/blob/43f62c3b28167bff76274f954e235413a9e9c707/lib/stc/Database.php#L81-L97
train
openclerk/users
src/User.php
User.forceLogin
static function forceLogin(\Db\Connection $db, $user_id) { User::$instance = User::findUser($db, $user_id); }
php
static function forceLogin(\Db\Connection $db, $user_id) { User::$instance = User::findUser($db, $user_id); }
[ "static", "function", "forceLogin", "(", "\\", "Db", "\\", "Connection", "$", "db", ",", "$", "user_id", ")", "{", "User", "::", "$", "instance", "=", "User", "::", "findUser", "(", "$", "db", ",", "$", "user_id", ")", ";", "}" ]
Login as the given user_id.
[ "Login", "as", "the", "given", "user_id", "." ]
550c7610c154a2f6655ce65a2df377ccb207bc6d
https://github.com/openclerk/users/blob/550c7610c154a2f6655ce65a2df377ccb207bc6d/src/User.php#L102-L104
train
openclerk/users
src/User.php
User.delete
function delete(\Db\Connection $db) { // delete all possible identities $q = $db->prepare("DELETE FROM user_passwords WHERE user_id=?"); $q->execute(array($this->getId())); $q = $db->prepare("DELETE FROM user_openid_identities WHERE user_id=?"); $q->execute(array($this->getId())); $q = $db->prepare("DELETE FROM user_oauth2_identities WHERE user_id=?"); $q->execute(array($this->getId())); $q = $db->prepare("DELETE FROM user_valid_keys WHERE user_id=?"); $q->execute(array($this->getId())); $q = $db->prepare("DELETE FROM users WHERE id=?"); $q->execute(array($this->getId())); \Openclerk\Events::trigger('user_deleted', $this); }
php
function delete(\Db\Connection $db) { // delete all possible identities $q = $db->prepare("DELETE FROM user_passwords WHERE user_id=?"); $q->execute(array($this->getId())); $q = $db->prepare("DELETE FROM user_openid_identities WHERE user_id=?"); $q->execute(array($this->getId())); $q = $db->prepare("DELETE FROM user_oauth2_identities WHERE user_id=?"); $q->execute(array($this->getId())); $q = $db->prepare("DELETE FROM user_valid_keys WHERE user_id=?"); $q->execute(array($this->getId())); $q = $db->prepare("DELETE FROM users WHERE id=?"); $q->execute(array($this->getId())); \Openclerk\Events::trigger('user_deleted', $this); }
[ "function", "delete", "(", "\\", "Db", "\\", "Connection", "$", "db", ")", "{", "// delete all possible identities", "$", "q", "=", "$", "db", "->", "prepare", "(", "\"DELETE FROM user_passwords WHERE user_id=?\"", ")", ";", "$", "q", "->", "execute", "(", "array", "(", "$", "this", "->", "getId", "(", ")", ")", ")", ";", "$", "q", "=", "$", "db", "->", "prepare", "(", "\"DELETE FROM user_openid_identities WHERE user_id=?\"", ")", ";", "$", "q", "->", "execute", "(", "array", "(", "$", "this", "->", "getId", "(", ")", ")", ")", ";", "$", "q", "=", "$", "db", "->", "prepare", "(", "\"DELETE FROM user_oauth2_identities WHERE user_id=?\"", ")", ";", "$", "q", "->", "execute", "(", "array", "(", "$", "this", "->", "getId", "(", ")", ")", ")", ";", "$", "q", "=", "$", "db", "->", "prepare", "(", "\"DELETE FROM user_valid_keys WHERE user_id=?\"", ")", ";", "$", "q", "->", "execute", "(", "array", "(", "$", "this", "->", "getId", "(", ")", ")", ")", ";", "$", "q", "=", "$", "db", "->", "prepare", "(", "\"DELETE FROM users WHERE id=?\"", ")", ";", "$", "q", "->", "execute", "(", "array", "(", "$", "this", "->", "getId", "(", ")", ")", ")", ";", "\\", "Openclerk", "\\", "Events", "::", "trigger", "(", "'user_deleted'", ",", "$", "this", ")", ";", "}" ]
Delete the given user. Triggers a 'user_deleted' event with the current user as an argument.
[ "Delete", "the", "given", "user", ".", "Triggers", "a", "user_deleted", "event", "with", "the", "current", "user", "as", "an", "argument", "." ]
550c7610c154a2f6655ce65a2df377ccb207bc6d
https://github.com/openclerk/users/blob/550c7610c154a2f6655ce65a2df377ccb207bc6d/src/User.php#L155-L169
train
tetreum/apache-vhost-processor
src/VirtualHost.php
VirtualHost.toString
public function toString () { $content = "<VirtualHost {$this->address}:{$this->port}>" . PHP_EOL; foreach ($this->directives as $directive) { $content .= $directive->toString() . PHP_EOL; } $content .= PHP_EOL; foreach ($this->directories as $directory) { $content .= $directory->toString() . PHP_EOL; } $content .= PHP_EOL; $content .= "</VirtualHost>"; return $content; }
php
public function toString () { $content = "<VirtualHost {$this->address}:{$this->port}>" . PHP_EOL; foreach ($this->directives as $directive) { $content .= $directive->toString() . PHP_EOL; } $content .= PHP_EOL; foreach ($this->directories as $directory) { $content .= $directory->toString() . PHP_EOL; } $content .= PHP_EOL; $content .= "</VirtualHost>"; return $content; }
[ "public", "function", "toString", "(", ")", "{", "$", "content", "=", "\"<VirtualHost {$this->address}:{$this->port}>\"", ".", "PHP_EOL", ";", "foreach", "(", "$", "this", "->", "directives", "as", "$", "directive", ")", "{", "$", "content", ".=", "$", "directive", "->", "toString", "(", ")", ".", "PHP_EOL", ";", "}", "$", "content", ".=", "PHP_EOL", ";", "foreach", "(", "$", "this", "->", "directories", "as", "$", "directory", ")", "{", "$", "content", ".=", "$", "directory", "->", "toString", "(", ")", ".", "PHP_EOL", ";", "}", "$", "content", ".=", "PHP_EOL", ";", "$", "content", ".=", "\"</VirtualHost>\"", ";", "return", "$", "content", ";", "}" ]
Converts vh to plain text @return
[ "Converts", "vh", "to", "plain", "text" ]
bdf46a3a32126dc9667f0ff4c51b2a39dcc796e2
https://github.com/tetreum/apache-vhost-processor/blob/bdf46a3a32126dc9667f0ff4c51b2a39dcc796e2/src/VirtualHost.php#L30-L48
train
jtallant/skimpy-engine
src/Http/Middleware/ContentCacheHandler.php
ContentCacheHandler.handleRequest
public function handleRequest(Request $request, Application $app) { # Rebuild on every request in dev environment if ($this->isAutoRebuildMode($app)) { $this->rebuildDatabase(); return; } if ($this->dbHasNotBeenBuilt()) { $this->rebuildDatabase(); return; } if ($this->isValidRebuildRequest($request, $app)) { $this->rebuildDatabase(); } }
php
public function handleRequest(Request $request, Application $app) { # Rebuild on every request in dev environment if ($this->isAutoRebuildMode($app)) { $this->rebuildDatabase(); return; } if ($this->dbHasNotBeenBuilt()) { $this->rebuildDatabase(); return; } if ($this->isValidRebuildRequest($request, $app)) { $this->rebuildDatabase(); } }
[ "public", "function", "handleRequest", "(", "Request", "$", "request", ",", "Application", "$", "app", ")", "{", "# Rebuild on every request in dev environment", "if", "(", "$", "this", "->", "isAutoRebuildMode", "(", "$", "app", ")", ")", "{", "$", "this", "->", "rebuildDatabase", "(", ")", ";", "return", ";", "}", "if", "(", "$", "this", "->", "dbHasNotBeenBuilt", "(", ")", ")", "{", "$", "this", "->", "rebuildDatabase", "(", ")", ";", "return", ";", "}", "if", "(", "$", "this", "->", "isValidRebuildRequest", "(", "$", "request", ",", "$", "app", ")", ")", "{", "$", "this", "->", "rebuildDatabase", "(", ")", ";", "}", "}" ]
If the request includes an instruction to rebuild the db, do that @param Request $request @param Application $app
[ "If", "the", "request", "includes", "an", "instruction", "to", "rebuild", "the", "db", "do", "that" ]
2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2
https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/Http/Middleware/ContentCacheHandler.php#L42-L60
train
jtallant/skimpy-engine
src/Http/Middleware/ContentCacheHandler.php
ContentCacheHandler.rebuildDatabase
protected function rebuildDatabase() { $this->populator->populate(); $path = $this->buildIndicator->getPathname(); $content = 'Initial Build: '.date('Y-m-d H:i:s'); $this->filesystem->remove($path); $this->filesystem->dumpFile($path, $content); }
php
protected function rebuildDatabase() { $this->populator->populate(); $path = $this->buildIndicator->getPathname(); $content = 'Initial Build: '.date('Y-m-d H:i:s'); $this->filesystem->remove($path); $this->filesystem->dumpFile($path, $content); }
[ "protected", "function", "rebuildDatabase", "(", ")", "{", "$", "this", "->", "populator", "->", "populate", "(", ")", ";", "$", "path", "=", "$", "this", "->", "buildIndicator", "->", "getPathname", "(", ")", ";", "$", "content", "=", "'Initial Build: '", ".", "date", "(", "'Y-m-d H:i:s'", ")", ";", "$", "this", "->", "filesystem", "->", "remove", "(", "$", "path", ")", ";", "$", "this", "->", "filesystem", "->", "dumpFile", "(", "$", "path", ",", "$", "content", ")", ";", "}" ]
Builds the DB and creates a file indicating that the DB has been built at least once. @return void
[ "Builds", "the", "DB", "and", "creates", "a", "file", "indicating", "that", "the", "DB", "has", "been", "built", "at", "least", "once", "." ]
2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2
https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/Http/Middleware/ContentCacheHandler.php#L78-L87
train