id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
210,900
cakephp/cakephp
src/Controller/ComponentRegistry.php
ComponentRegistry._create
protected function _create($class, $alias, $config) { $instance = new $class($this, $config); $enable = isset($config['enabled']) ? $config['enabled'] : true; if ($enable) { $this->getEventManager()->on($instance); } return $instance; }
php
protected function _create($class, $alias, $config) { $instance = new $class($this, $config); $enable = isset($config['enabled']) ? $config['enabled'] : true; if ($enable) { $this->getEventManager()->on($instance); } return $instance; }
[ "protected", "function", "_create", "(", "$", "class", ",", "$", "alias", ",", "$", "config", ")", "{", "$", "instance", "=", "new", "$", "class", "(", "$", "this", ",", "$", "config", ")", ";", "$", "enable", "=", "isset", "(", "$", "config", "[", "'enabled'", "]", ")", "?", "$", "config", "[", "'enabled'", "]", ":", "true", ";", "if", "(", "$", "enable", ")", "{", "$", "this", "->", "getEventManager", "(", ")", "->", "on", "(", "$", "instance", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Create the component instance. Part of the template method for Cake\Core\ObjectRegistry::load() Enabled components will be registered with the event manager. @param string $class The classname to create. @param string $alias The alias of the component. @param array $config An array of config to use for the component. @return \Cake\Controller\Component The constructed component class.
[ "Create", "the", "component", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/ComponentRegistry.php#L117-L126
210,901
cakephp/cakephp
src/I18n/MessagesFileLoader.php
MessagesFileLoader.translationsFolders
public function translationsFolders() { $locale = Locale::parseLocale($this->_locale) + ['region' => null]; $folders = [ implode('_', [$locale['language'], $locale['region']]), $locale['language'] ]; $searchPaths = []; $localePaths = App::path('Locale'); if (empty($localePaths) && defined('APP')) { $localePaths[] = APP . 'Locale' . DIRECTORY_SEPARATOR; } foreach ($localePaths as $path) { foreach ($folders as $folder) { $searchPaths[] = $path . $folder . DIRECTORY_SEPARATOR; } } // If space is not added after slash, the character after it remains lowercased $pluginName = Inflector::camelize(str_replace('/', '/ ', $this->_name)); if (Plugin::isLoaded($pluginName)) { $basePath = Plugin::classPath($pluginName) . 'Locale' . DIRECTORY_SEPARATOR; foreach ($folders as $folder) { $searchPaths[] = $basePath . $folder . DIRECTORY_SEPARATOR; } } return $searchPaths; }
php
public function translationsFolders() { $locale = Locale::parseLocale($this->_locale) + ['region' => null]; $folders = [ implode('_', [$locale['language'], $locale['region']]), $locale['language'] ]; $searchPaths = []; $localePaths = App::path('Locale'); if (empty($localePaths) && defined('APP')) { $localePaths[] = APP . 'Locale' . DIRECTORY_SEPARATOR; } foreach ($localePaths as $path) { foreach ($folders as $folder) { $searchPaths[] = $path . $folder . DIRECTORY_SEPARATOR; } } // If space is not added after slash, the character after it remains lowercased $pluginName = Inflector::camelize(str_replace('/', '/ ', $this->_name)); if (Plugin::isLoaded($pluginName)) { $basePath = Plugin::classPath($pluginName) . 'Locale' . DIRECTORY_SEPARATOR; foreach ($folders as $folder) { $searchPaths[] = $basePath . $folder . DIRECTORY_SEPARATOR; } } return $searchPaths; }
[ "public", "function", "translationsFolders", "(", ")", "{", "$", "locale", "=", "Locale", "::", "parseLocale", "(", "$", "this", "->", "_locale", ")", "+", "[", "'region'", "=>", "null", "]", ";", "$", "folders", "=", "[", "implode", "(", "'_'", ",", "[", "$", "locale", "[", "'language'", "]", ",", "$", "locale", "[", "'region'", "]", "]", ")", ",", "$", "locale", "[", "'language'", "]", "]", ";", "$", "searchPaths", "=", "[", "]", ";", "$", "localePaths", "=", "App", "::", "path", "(", "'Locale'", ")", ";", "if", "(", "empty", "(", "$", "localePaths", ")", "&&", "defined", "(", "'APP'", ")", ")", "{", "$", "localePaths", "[", "]", "=", "APP", ".", "'Locale'", ".", "DIRECTORY_SEPARATOR", ";", "}", "foreach", "(", "$", "localePaths", "as", "$", "path", ")", "{", "foreach", "(", "$", "folders", "as", "$", "folder", ")", "{", "$", "searchPaths", "[", "]", "=", "$", "path", ".", "$", "folder", ".", "DIRECTORY_SEPARATOR", ";", "}", "}", "// If space is not added after slash, the character after it remains lowercased", "$", "pluginName", "=", "Inflector", "::", "camelize", "(", "str_replace", "(", "'/'", ",", "'/ '", ",", "$", "this", "->", "_name", ")", ")", ";", "if", "(", "Plugin", "::", "isLoaded", "(", "$", "pluginName", ")", ")", "{", "$", "basePath", "=", "Plugin", "::", "classPath", "(", "$", "pluginName", ")", ".", "'Locale'", ".", "DIRECTORY_SEPARATOR", ";", "foreach", "(", "$", "folders", "as", "$", "folder", ")", "{", "$", "searchPaths", "[", "]", "=", "$", "basePath", ".", "$", "folder", ".", "DIRECTORY_SEPARATOR", ";", "}", "}", "return", "$", "searchPaths", ";", "}" ]
Returns the folders where the file should be looked for according to the locale and package name. @return array The list of folders where the translation file should be looked for
[ "Returns", "the", "folders", "where", "the", "file", "should", "be", "looked", "for", "according", "to", "the", "locale", "and", "package", "name", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/MessagesFileLoader.php#L151-L182
210,902
cakephp/cakephp
src/Console/CommandScanner.php
CommandScanner.scanCore
public function scanCore() { $coreShells = $this->scanDir( dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Shell' . DIRECTORY_SEPARATOR, 'Cake\Shell\\', '', ['command_list'] ); $coreCommands = $this->scanDir( dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Command' . DIRECTORY_SEPARATOR, 'Cake\Command\\', '', ['command_list'] ); return array_merge($coreShells, $coreCommands); }
php
public function scanCore() { $coreShells = $this->scanDir( dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Shell' . DIRECTORY_SEPARATOR, 'Cake\Shell\\', '', ['command_list'] ); $coreCommands = $this->scanDir( dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Command' . DIRECTORY_SEPARATOR, 'Cake\Command\\', '', ['command_list'] ); return array_merge($coreShells, $coreCommands); }
[ "public", "function", "scanCore", "(", ")", "{", "$", "coreShells", "=", "$", "this", "->", "scanDir", "(", "dirname", "(", "__DIR__", ")", ".", "DIRECTORY_SEPARATOR", ".", "'Shell'", ".", "DIRECTORY_SEPARATOR", ",", "'Cake\\Shell\\\\'", ",", "''", ",", "[", "'command_list'", "]", ")", ";", "$", "coreCommands", "=", "$", "this", "->", "scanDir", "(", "dirname", "(", "__DIR__", ")", ".", "DIRECTORY_SEPARATOR", ".", "'Command'", ".", "DIRECTORY_SEPARATOR", ",", "'Cake\\Command\\\\'", ",", "''", ",", "[", "'command_list'", "]", ")", ";", "return", "array_merge", "(", "$", "coreShells", ",", "$", "coreCommands", ")", ";", "}" ]
Scan CakePHP internals for shells & commands. @return array A list of command metadata.
[ "Scan", "CakePHP", "internals", "for", "shells", "&", "commands", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandScanner.php#L36-L52
210,903
cakephp/cakephp
src/Console/CommandScanner.php
CommandScanner.scanApp
public function scanApp() { $appNamespace = Configure::read('App.namespace'); $appShells = $this->scanDir( App::path('Shell')[0], $appNamespace . '\Shell\\', '', [] ); $appCommands = $this->scanDir( App::path('Command')[0], $appNamespace . '\Command\\', '', [] ); return array_merge($appShells, $appCommands); }
php
public function scanApp() { $appNamespace = Configure::read('App.namespace'); $appShells = $this->scanDir( App::path('Shell')[0], $appNamespace . '\Shell\\', '', [] ); $appCommands = $this->scanDir( App::path('Command')[0], $appNamespace . '\Command\\', '', [] ); return array_merge($appShells, $appCommands); }
[ "public", "function", "scanApp", "(", ")", "{", "$", "appNamespace", "=", "Configure", "::", "read", "(", "'App.namespace'", ")", ";", "$", "appShells", "=", "$", "this", "->", "scanDir", "(", "App", "::", "path", "(", "'Shell'", ")", "[", "0", "]", ",", "$", "appNamespace", ".", "'\\Shell\\\\'", ",", "''", ",", "[", "]", ")", ";", "$", "appCommands", "=", "$", "this", "->", "scanDir", "(", "App", "::", "path", "(", "'Command'", ")", "[", "0", "]", ",", "$", "appNamespace", ".", "'\\Command\\\\'", ",", "''", ",", "[", "]", ")", ";", "return", "array_merge", "(", "$", "appShells", ",", "$", "appCommands", ")", ";", "}" ]
Scan the application for shells & commands. @return array A list of command metadata.
[ "Scan", "the", "application", "for", "shells", "&", "commands", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandScanner.php#L59-L76
210,904
cakephp/cakephp
src/Console/CommandScanner.php
CommandScanner.scanPlugin
public function scanPlugin($plugin) { if (!Plugin::isLoaded($plugin)) { return []; } $path = Plugin::classPath($plugin); $namespace = str_replace('/', '\\', $plugin); $prefix = Inflector::underscore($plugin) . '.'; $commands = $this->scanDir($path . 'Command', $namespace . '\Command\\', $prefix, []); $shells = $this->scanDir($path . 'Shell', $namespace . '\Shell\\', $prefix, []); return array_merge($shells, $commands); }
php
public function scanPlugin($plugin) { if (!Plugin::isLoaded($plugin)) { return []; } $path = Plugin::classPath($plugin); $namespace = str_replace('/', '\\', $plugin); $prefix = Inflector::underscore($plugin) . '.'; $commands = $this->scanDir($path . 'Command', $namespace . '\Command\\', $prefix, []); $shells = $this->scanDir($path . 'Shell', $namespace . '\Shell\\', $prefix, []); return array_merge($shells, $commands); }
[ "public", "function", "scanPlugin", "(", "$", "plugin", ")", "{", "if", "(", "!", "Plugin", "::", "isLoaded", "(", "$", "plugin", ")", ")", "{", "return", "[", "]", ";", "}", "$", "path", "=", "Plugin", "::", "classPath", "(", "$", "plugin", ")", ";", "$", "namespace", "=", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "$", "plugin", ")", ";", "$", "prefix", "=", "Inflector", "::", "underscore", "(", "$", "plugin", ")", ".", "'.'", ";", "$", "commands", "=", "$", "this", "->", "scanDir", "(", "$", "path", ".", "'Command'", ",", "$", "namespace", ".", "'\\Command\\\\'", ",", "$", "prefix", ",", "[", "]", ")", ";", "$", "shells", "=", "$", "this", "->", "scanDir", "(", "$", "path", ".", "'Shell'", ",", "$", "namespace", ".", "'\\Shell\\\\'", ",", "$", "prefix", ",", "[", "]", ")", ";", "return", "array_merge", "(", "$", "shells", ",", "$", "commands", ")", ";", "}" ]
Scan the named plugin for shells and commands @param string $plugin The named plugin. @return array A list of command metadata.
[ "Scan", "the", "named", "plugin", "for", "shells", "and", "commands" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandScanner.php#L84-L97
210,905
cakephp/cakephp
src/Routing/Route/DashedRoute.php
DashedRoute.parse
public function parse($url, $method = '') { $params = parent::parse($url, $method); if (!$params) { return false; } if (!empty($params['controller'])) { $params['controller'] = Inflector::camelize($params['controller'], '-'); } if (!empty($params['plugin'])) { $params['plugin'] = $this->_camelizePlugin($params['plugin']); } if (!empty($params['action'])) { $params['action'] = Inflector::variable(str_replace( '-', '_', $params['action'] )); } return $params; }
php
public function parse($url, $method = '') { $params = parent::parse($url, $method); if (!$params) { return false; } if (!empty($params['controller'])) { $params['controller'] = Inflector::camelize($params['controller'], '-'); } if (!empty($params['plugin'])) { $params['plugin'] = $this->_camelizePlugin($params['plugin']); } if (!empty($params['action'])) { $params['action'] = Inflector::variable(str_replace( '-', '_', $params['action'] )); } return $params; }
[ "public", "function", "parse", "(", "$", "url", ",", "$", "method", "=", "''", ")", "{", "$", "params", "=", "parent", "::", "parse", "(", "$", "url", ",", "$", "method", ")", ";", "if", "(", "!", "$", "params", ")", "{", "return", "false", ";", "}", "if", "(", "!", "empty", "(", "$", "params", "[", "'controller'", "]", ")", ")", "{", "$", "params", "[", "'controller'", "]", "=", "Inflector", "::", "camelize", "(", "$", "params", "[", "'controller'", "]", ",", "'-'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "params", "[", "'plugin'", "]", ")", ")", "{", "$", "params", "[", "'plugin'", "]", "=", "$", "this", "->", "_camelizePlugin", "(", "$", "params", "[", "'plugin'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "params", "[", "'action'", "]", ")", ")", "{", "$", "params", "[", "'action'", "]", "=", "Inflector", "::", "variable", "(", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "params", "[", "'action'", "]", ")", ")", ";", "}", "return", "$", "params", ";", "}" ]
Parses a string URL into an array. If it matches, it will convert the controller and plugin keys to their CamelCased form and action key to camelBacked form. @param string $url The URL to parse @param string $method The HTTP method. @return array|false An array of request parameters, or false on failure.
[ "Parses", "a", "string", "URL", "into", "an", "array", ".", "If", "it", "matches", "it", "will", "convert", "the", "controller", "and", "plugin", "keys", "to", "their", "CamelCased", "form", "and", "action", "key", "to", "camelBacked", "form", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/DashedRoute.php#L63-L84
210,906
cakephp/cakephp
src/Routing/Route/DashedRoute.php
DashedRoute.match
public function match(array $url, array $context = []) { $url = $this->_dasherize($url); if (!$this->_inflectedDefaults) { $this->_inflectedDefaults = true; $this->defaults = $this->_dasherize($this->defaults); } return parent::match($url, $context); }
php
public function match(array $url, array $context = []) { $url = $this->_dasherize($url); if (!$this->_inflectedDefaults) { $this->_inflectedDefaults = true; $this->defaults = $this->_dasherize($this->defaults); } return parent::match($url, $context); }
[ "public", "function", "match", "(", "array", "$", "url", ",", "array", "$", "context", "=", "[", "]", ")", "{", "$", "url", "=", "$", "this", "->", "_dasherize", "(", "$", "url", ")", ";", "if", "(", "!", "$", "this", "->", "_inflectedDefaults", ")", "{", "$", "this", "->", "_inflectedDefaults", "=", "true", ";", "$", "this", "->", "defaults", "=", "$", "this", "->", "_dasherize", "(", "$", "this", "->", "defaults", ")", ";", "}", "return", "parent", "::", "match", "(", "$", "url", ",", "$", "context", ")", ";", "}" ]
Dasherizes the controller, action and plugin params before passing them on to the parent class. @param array $url Array of parameters to convert to a string. @param array $context An array of the current request context. Contains information such as the current host, scheme, port, and base directory. @return bool|string Either false or a string URL.
[ "Dasherizes", "the", "controller", "action", "and", "plugin", "params", "before", "passing", "them", "on", "to", "the", "parent", "class", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/DashedRoute.php#L96-L105
210,907
cakephp/cakephp
src/Routing/Route/DashedRoute.php
DashedRoute._dasherize
protected function _dasherize($url) { foreach (['controller', 'plugin', 'action'] as $element) { if (!empty($url[$element])) { $url[$element] = Inflector::dasherize($url[$element]); } } return $url; }
php
protected function _dasherize($url) { foreach (['controller', 'plugin', 'action'] as $element) { if (!empty($url[$element])) { $url[$element] = Inflector::dasherize($url[$element]); } } return $url; }
[ "protected", "function", "_dasherize", "(", "$", "url", ")", "{", "foreach", "(", "[", "'controller'", ",", "'plugin'", ",", "'action'", "]", "as", "$", "element", ")", "{", "if", "(", "!", "empty", "(", "$", "url", "[", "$", "element", "]", ")", ")", "{", "$", "url", "[", "$", "element", "]", "=", "Inflector", "::", "dasherize", "(", "$", "url", "[", "$", "element", "]", ")", ";", "}", "}", "return", "$", "url", ";", "}" ]
Helper method for dasherizing keys in a URL array. @param array $url An array of URL keys. @return array
[ "Helper", "method", "for", "dasherizing", "keys", "in", "a", "URL", "array", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/DashedRoute.php#L113-L122
210,908
cakephp/cakephp
src/Console/ConsoleInput.php
ConsoleInput.read
public function read() { if ($this->_canReadline) { $line = readline(''); if (strlen($line) > 0) { readline_add_history($line); } return $line; } return fgets($this->_input); }
php
public function read() { if ($this->_canReadline) { $line = readline(''); if (strlen($line) > 0) { readline_add_history($line); } return $line; } return fgets($this->_input); }
[ "public", "function", "read", "(", ")", "{", "if", "(", "$", "this", "->", "_canReadline", ")", "{", "$", "line", "=", "readline", "(", "''", ")", ";", "if", "(", "strlen", "(", "$", "line", ")", ">", "0", ")", "{", "readline_add_history", "(", "$", "line", ")", ";", "}", "return", "$", "line", ";", "}", "return", "fgets", "(", "$", "this", "->", "_input", ")", ";", "}" ]
Read a value from the stream @return mixed The value of the stream
[ "Read", "a", "value", "from", "the", "stream" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInput.php#L57-L69
210,909
cakephp/cakephp
src/Console/ConsoleInput.php
ConsoleInput.dataAvailable
public function dataAvailable($timeout = 0) { $readFds = [$this->_input]; $writeFds = null; $errorFds = null; $readyFds = stream_select($readFds, $writeFds, $errorFds, $timeout); return ($readyFds > 0); }
php
public function dataAvailable($timeout = 0) { $readFds = [$this->_input]; $writeFds = null; $errorFds = null; $readyFds = stream_select($readFds, $writeFds, $errorFds, $timeout); return ($readyFds > 0); }
[ "public", "function", "dataAvailable", "(", "$", "timeout", "=", "0", ")", "{", "$", "readFds", "=", "[", "$", "this", "->", "_input", "]", ";", "$", "writeFds", "=", "null", ";", "$", "errorFds", "=", "null", ";", "$", "readyFds", "=", "stream_select", "(", "$", "readFds", ",", "$", "writeFds", ",", "$", "errorFds", ",", "$", "timeout", ")", ";", "return", "(", "$", "readyFds", ">", "0", ")", ";", "}" ]
Check if data is available on stdin @param int $timeout An optional time to wait for data @return bool True for data available, false otherwise
[ "Check", "if", "data", "is", "available", "on", "stdin" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInput.php#L77-L85
210,910
cakephp/cakephp
src/Controller/Component/CookieComponent.php
CookieComponent.initialize
public function initialize(array $config) { if (!$this->_config['key']) { $this->setConfig('key', Security::getSalt()); } $controller = $this->_registry->getController(); if ($controller === null) { $this->request = ServerRequestFactory::fromGlobals(); } if (empty($this->_config['path'])) { $this->setConfig('path', $this->getController()->getRequest()->getAttribute('webroot')); } }
php
public function initialize(array $config) { if (!$this->_config['key']) { $this->setConfig('key', Security::getSalt()); } $controller = $this->_registry->getController(); if ($controller === null) { $this->request = ServerRequestFactory::fromGlobals(); } if (empty($this->_config['path'])) { $this->setConfig('path', $this->getController()->getRequest()->getAttribute('webroot')); } }
[ "public", "function", "initialize", "(", "array", "$", "config", ")", "{", "if", "(", "!", "$", "this", "->", "_config", "[", "'key'", "]", ")", "{", "$", "this", "->", "setConfig", "(", "'key'", ",", "Security", "::", "getSalt", "(", ")", ")", ";", "}", "$", "controller", "=", "$", "this", "->", "_registry", "->", "getController", "(", ")", ";", "if", "(", "$", "controller", "===", "null", ")", "{", "$", "this", "->", "request", "=", "ServerRequestFactory", "::", "fromGlobals", "(", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "_config", "[", "'path'", "]", ")", ")", "{", "$", "this", "->", "setConfig", "(", "'path'", ",", "$", "this", "->", "getController", "(", ")", "->", "getRequest", "(", ")", "->", "getAttribute", "(", "'webroot'", ")", ")", ";", "}", "}" ]
Initialize config data and properties. @param array $config The config data. @return void
[ "Initialize", "config", "data", "and", "properties", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/CookieComponent.php#L119-L134
210,911
cakephp/cakephp
src/Controller/Component/CookieComponent.php
CookieComponent.configKey
public function configKey($keyname, $option = null, $value = null) { if ($option === null) { $default = $this->_config; $local = isset($this->_keyConfig[$keyname]) ? $this->_keyConfig[$keyname] : []; return $local + $default; } if (!is_array($option)) { $option = [$option => $value]; } $this->_keyConfig[$keyname] = $option; return null; }
php
public function configKey($keyname, $option = null, $value = null) { if ($option === null) { $default = $this->_config; $local = isset($this->_keyConfig[$keyname]) ? $this->_keyConfig[$keyname] : []; return $local + $default; } if (!is_array($option)) { $option = [$option => $value]; } $this->_keyConfig[$keyname] = $option; return null; }
[ "public", "function", "configKey", "(", "$", "keyname", ",", "$", "option", "=", "null", ",", "$", "value", "=", "null", ")", "{", "if", "(", "$", "option", "===", "null", ")", "{", "$", "default", "=", "$", "this", "->", "_config", ";", "$", "local", "=", "isset", "(", "$", "this", "->", "_keyConfig", "[", "$", "keyname", "]", ")", "?", "$", "this", "->", "_keyConfig", "[", "$", "keyname", "]", ":", "[", "]", ";", "return", "$", "local", "+", "$", "default", ";", "}", "if", "(", "!", "is_array", "(", "$", "option", ")", ")", "{", "$", "option", "=", "[", "$", "option", "=>", "$", "value", "]", ";", "}", "$", "this", "->", "_keyConfig", "[", "$", "keyname", "]", "=", "$", "option", ";", "return", "null", ";", "}" ]
Set the configuration for a specific top level key. ### Examples: Set a single config option for a key: ``` $this->Cookie->configKey('User', 'expires', '+3 months'); ``` Set multiple options: ``` $this->Cookie->configKey('User', [ 'expires', '+3 months', 'httpOnly' => true, ]); ``` @param string $keyname The top level keyname to configure. @param null|string|array $option Either the option name to set, or an array of options to set, or null to read config options for a given key. @param string|null $value Either the value to set, or empty when $option is an array. @return array|null
[ "Set", "the", "configuration", "for", "a", "specific", "top", "level", "key", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/CookieComponent.php#L162-L176
210,912
cakephp/cakephp
src/Controller/Component/CookieComponent.php
CookieComponent.write
public function write($key, $value = null) { if (!is_array($key)) { $key = [$key => $value]; } $keys = []; foreach ($key as $name => $value) { $this->_load($name); $this->_values = Hash::insert($this->_values, $name, $value); $parts = explode('.', $name); $keys[] = $parts[0]; } foreach ($keys as $name) { $this->_write($name, $this->_values[$name]); } }
php
public function write($key, $value = null) { if (!is_array($key)) { $key = [$key => $value]; } $keys = []; foreach ($key as $name => $value) { $this->_load($name); $this->_values = Hash::insert($this->_values, $name, $value); $parts = explode('.', $name); $keys[] = $parts[0]; } foreach ($keys as $name) { $this->_write($name, $this->_values[$name]); } }
[ "public", "function", "write", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "key", ")", ")", "{", "$", "key", "=", "[", "$", "key", "=>", "$", "value", "]", ";", "}", "$", "keys", "=", "[", "]", ";", "foreach", "(", "$", "key", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "this", "->", "_load", "(", "$", "name", ")", ";", "$", "this", "->", "_values", "=", "Hash", "::", "insert", "(", "$", "this", "->", "_values", ",", "$", "name", ",", "$", "value", ")", ";", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "name", ")", ";", "$", "keys", "[", "]", "=", "$", "parts", "[", "0", "]", ";", "}", "foreach", "(", "$", "keys", "as", "$", "name", ")", "{", "$", "this", "->", "_write", "(", "$", "name", ",", "$", "this", "->", "_values", "[", "$", "name", "]", ")", ";", "}", "}" ]
Write a value to the response cookies. You must use this method before any output is sent to the browser. Failure to do so will result in header already sent errors. @param string|array $key Key for the value @param mixed $value Value @return void
[ "Write", "a", "value", "to", "the", "response", "cookies", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/CookieComponent.php#L198-L216
210,913
cakephp/cakephp
src/Controller/Component/CookieComponent.php
CookieComponent.read
public function read($key = null) { $this->_load($key); return Hash::get($this->_values, $key); }
php
public function read($key = null) { $this->_load($key); return Hash::get($this->_values, $key); }
[ "public", "function", "read", "(", "$", "key", "=", "null", ")", "{", "$", "this", "->", "_load", "(", "$", "key", ")", ";", "return", "Hash", "::", "get", "(", "$", "this", "->", "_values", ",", "$", "key", ")", ";", "}" ]
Read the value of key path from request cookies. This method will also allow you to read cookies that have been written in this request, but not yet sent to the client. @param string|null $key Key of the value to be obtained. @return string or null, value for specified key
[ "Read", "the", "value", "of", "key", "path", "from", "request", "cookies", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/CookieComponent.php#L227-L232
210,914
cakephp/cakephp
src/Controller/Component/CookieComponent.php
CookieComponent._load
protected function _load($key) { $parts = explode('.', $key); $first = array_shift($parts); if (isset($this->_loaded[$first])) { return; } $cookie = $this->getController()->getRequest()->getCookie($first); if ($cookie === null) { return; } $config = $this->configKey($first); $this->_loaded[$first] = true; $this->_values[$first] = $this->_decrypt($cookie, $config['encryption'], $config['key']); }
php
protected function _load($key) { $parts = explode('.', $key); $first = array_shift($parts); if (isset($this->_loaded[$first])) { return; } $cookie = $this->getController()->getRequest()->getCookie($first); if ($cookie === null) { return; } $config = $this->configKey($first); $this->_loaded[$first] = true; $this->_values[$first] = $this->_decrypt($cookie, $config['encryption'], $config['key']); }
[ "protected", "function", "_load", "(", "$", "key", ")", "{", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "first", "=", "array_shift", "(", "$", "parts", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_loaded", "[", "$", "first", "]", ")", ")", "{", "return", ";", "}", "$", "cookie", "=", "$", "this", "->", "getController", "(", ")", "->", "getRequest", "(", ")", "->", "getCookie", "(", "$", "first", ")", ";", "if", "(", "$", "cookie", "===", "null", ")", "{", "return", ";", "}", "$", "config", "=", "$", "this", "->", "configKey", "(", "$", "first", ")", ";", "$", "this", "->", "_loaded", "[", "$", "first", "]", "=", "true", ";", "$", "this", "->", "_values", "[", "$", "first", "]", "=", "$", "this", "->", "_decrypt", "(", "$", "cookie", ",", "$", "config", "[", "'encryption'", "]", ",", "$", "config", "[", "'key'", "]", ")", ";", "}" ]
Load the cookie data from the request and response objects. Based on the configuration data, cookies will be decrypted. When cookies contain array data, that data will be expanded. @param string|array $key The key to load. @return void
[ "Load", "the", "cookie", "data", "from", "the", "request", "and", "response", "objects", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/CookieComponent.php#L243-L257
210,915
cakephp/cakephp
src/Controller/Component/CookieComponent.php
CookieComponent.check
public function check($key = null) { if (empty($key)) { return false; } return $this->read($key) !== null; }
php
public function check($key = null) { if (empty($key)) { return false; } return $this->read($key) !== null; }
[ "public", "function", "check", "(", "$", "key", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "key", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "read", "(", "$", "key", ")", "!==", "null", ";", "}" ]
Returns true if given key is set in the cookie. @param string|null $key Key to check for @return bool True if the key exists
[ "Returns", "true", "if", "given", "key", "is", "set", "in", "the", "cookie", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/CookieComponent.php#L265-L272
210,916
cakephp/cakephp
src/Controller/Component/CookieComponent.php
CookieComponent.delete
public function delete($key) { $this->_load($key); $this->_values = Hash::remove($this->_values, $key); $parts = explode('.', $key); $top = $parts[0]; if (isset($this->_values[$top])) { $this->_write($top, $this->_values[$top]); } else { $this->_delete($top); } }
php
public function delete($key) { $this->_load($key); $this->_values = Hash::remove($this->_values, $key); $parts = explode('.', $key); $top = $parts[0]; if (isset($this->_values[$top])) { $this->_write($top, $this->_values[$top]); } else { $this->_delete($top); } }
[ "public", "function", "delete", "(", "$", "key", ")", "{", "$", "this", "->", "_load", "(", "$", "key", ")", ";", "$", "this", "->", "_values", "=", "Hash", "::", "remove", "(", "$", "this", "->", "_values", ",", "$", "key", ")", ";", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "top", "=", "$", "parts", "[", "0", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "_values", "[", "$", "top", "]", ")", ")", "{", "$", "this", "->", "_write", "(", "$", "top", ",", "$", "this", "->", "_values", "[", "$", "top", "]", ")", ";", "}", "else", "{", "$", "this", "->", "_delete", "(", "$", "top", ")", ";", "}", "}" ]
Delete a cookie value You must use this method before any output is sent to the browser. Failure to do so will result in header already sent errors. Deleting a top level key will delete all keys nested within that key. For example deleting the `User` key, will also delete `User.email`. @param string $key Key of the value to be deleted @return void
[ "Delete", "a", "cookie", "value" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/CookieComponent.php#L286-L299
210,917
cakephp/cakephp
src/Controller/Component/CookieComponent.php
CookieComponent._delete
protected function _delete($name) { $config = $this->configKey($name); $expires = new Time('now'); $controller = $this->getController(); $cookie = new Cookie( $name, '', $expires, $config['path'], $config['domain'], (bool)$config['secure'], (bool)$config['httpOnly'] ); $controller->response = $controller->response->withExpiredCookie($cookie); }
php
protected function _delete($name) { $config = $this->configKey($name); $expires = new Time('now'); $controller = $this->getController(); $cookie = new Cookie( $name, '', $expires, $config['path'], $config['domain'], (bool)$config['secure'], (bool)$config['httpOnly'] ); $controller->response = $controller->response->withExpiredCookie($cookie); }
[ "protected", "function", "_delete", "(", "$", "name", ")", "{", "$", "config", "=", "$", "this", "->", "configKey", "(", "$", "name", ")", ";", "$", "expires", "=", "new", "Time", "(", "'now'", ")", ";", "$", "controller", "=", "$", "this", "->", "getController", "(", ")", ";", "$", "cookie", "=", "new", "Cookie", "(", "$", "name", ",", "''", ",", "$", "expires", ",", "$", "config", "[", "'path'", "]", ",", "$", "config", "[", "'domain'", "]", ",", "(", "bool", ")", "$", "config", "[", "'secure'", "]", ",", "(", "bool", ")", "$", "config", "[", "'httpOnly'", "]", ")", ";", "$", "controller", "->", "response", "=", "$", "controller", "->", "response", "->", "withExpiredCookie", "(", "$", "cookie", ")", ";", "}" ]
Sets a cookie expire time to remove cookie value. This is only done once all values in a cookie key have been removed with delete. @param string $name Name of cookie @return void
[ "Sets", "a", "cookie", "expire", "time", "to", "remove", "cookie", "value", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/CookieComponent.php#L337-L354
210,918
cakephp/cakephp
src/Collection/Iterator/InsertIterator.php
InsertIterator.next
public function next() { parent::next(); if ($this->_validValues) { $this->_values->next(); } $this->_validValues = $this->_values->valid(); }
php
public function next() { parent::next(); if ($this->_validValues) { $this->_values->next(); } $this->_validValues = $this->_values->valid(); }
[ "public", "function", "next", "(", ")", "{", "parent", "::", "next", "(", ")", ";", "if", "(", "$", "this", "->", "_validValues", ")", "{", "$", "this", "->", "_values", "->", "next", "(", ")", ";", "}", "$", "this", "->", "_validValues", "=", "$", "this", "->", "_values", "->", "valid", "(", ")", ";", "}" ]
Advances the cursor to the next record @return void
[ "Advances", "the", "cursor", "to", "the", "next", "record" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/InsertIterator.php#L88-L95
210,919
cakephp/cakephp
src/Collection/Iterator/InsertIterator.php
InsertIterator.current
public function current() { $row = parent::current(); if (!$this->_validValues) { return $row; } $pointer =& $row; foreach ($this->_path as $step) { if (!isset($pointer[$step])) { return $row; } $pointer =& $pointer[$step]; } $pointer[$this->_target] = $this->_values->current(); return $row; }
php
public function current() { $row = parent::current(); if (!$this->_validValues) { return $row; } $pointer =& $row; foreach ($this->_path as $step) { if (!isset($pointer[$step])) { return $row; } $pointer =& $pointer[$step]; } $pointer[$this->_target] = $this->_values->current(); return $row; }
[ "public", "function", "current", "(", ")", "{", "$", "row", "=", "parent", "::", "current", "(", ")", ";", "if", "(", "!", "$", "this", "->", "_validValues", ")", "{", "return", "$", "row", ";", "}", "$", "pointer", "=", "&", "$", "row", ";", "foreach", "(", "$", "this", "->", "_path", "as", "$", "step", ")", "{", "if", "(", "!", "isset", "(", "$", "pointer", "[", "$", "step", "]", ")", ")", "{", "return", "$", "row", ";", "}", "$", "pointer", "=", "&", "$", "pointer", "[", "$", "step", "]", ";", "}", "$", "pointer", "[", "$", "this", "->", "_target", "]", "=", "$", "this", "->", "_values", "->", "current", "(", ")", ";", "return", "$", "row", ";", "}" ]
Returns the current element in the target collection after inserting the value from the source collection into the specified path. @return mixed
[ "Returns", "the", "current", "element", "in", "the", "target", "collection", "after", "inserting", "the", "value", "from", "the", "source", "collection", "into", "the", "specified", "path", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/InsertIterator.php#L103-L122
210,920
cakephp/cakephp
src/Collection/Iterator/InsertIterator.php
InsertIterator.rewind
public function rewind() { parent::rewind(); $this->_values->rewind(); $this->_validValues = $this->_values->valid(); }
php
public function rewind() { parent::rewind(); $this->_values->rewind(); $this->_validValues = $this->_values->valid(); }
[ "public", "function", "rewind", "(", ")", "{", "parent", "::", "rewind", "(", ")", ";", "$", "this", "->", "_values", "->", "rewind", "(", ")", ";", "$", "this", "->", "_validValues", "=", "$", "this", "->", "_values", "->", "valid", "(", ")", ";", "}" ]
Resets the collection pointer. @return void
[ "Resets", "the", "collection", "pointer", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/InsertIterator.php#L129-L134
210,921
cakephp/cakephp
src/Database/Statement/StatementDecorator.php
StatementDecorator.execute
public function execute($params = null) { $this->_hasExecuted = true; return $this->_statement->execute($params); }
php
public function execute($params = null) { $this->_hasExecuted = true; return $this->_statement->execute($params); }
[ "public", "function", "execute", "(", "$", "params", "=", "null", ")", "{", "$", "this", "->", "_hasExecuted", "=", "true", ";", "return", "$", "this", "->", "_statement", "->", "execute", "(", "$", "params", ")", ";", "}" ]
Executes the statement by sending the SQL query to the database. It can optionally take an array or arguments to be bound to the query variables. Please note that binding parameters from this method will not perform any custom type conversion as it would normally happen when calling `bindValue`. @param array|null $params list of values to be bound to query @return bool true on success, false otherwise
[ "Executes", "the", "statement", "by", "sending", "the", "SQL", "query", "to", "the", "database", ".", "It", "can", "optionally", "take", "an", "array", "or", "arguments", "to", "be", "bound", "to", "the", "query", "variables", ".", "Please", "note", "that", "binding", "parameters", "from", "this", "method", "will", "not", "perform", "any", "custom", "type", "conversion", "as", "it", "would", "normally", "happen", "when", "calling", "bindValue", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Statement/StatementDecorator.php#L169-L174
210,922
cakephp/cakephp
src/Database/Statement/StatementDecorator.php
StatementDecorator.bind
public function bind($params, $types) { if (empty($params)) { return; } $anonymousParams = is_int(key($params)) ? true : false; $offset = 1; foreach ($params as $index => $value) { $type = null; if (isset($types[$index])) { $type = $types[$index]; } if ($anonymousParams) { $index += $offset; } $this->bindValue($index, $value, $type); } }
php
public function bind($params, $types) { if (empty($params)) { return; } $anonymousParams = is_int(key($params)) ? true : false; $offset = 1; foreach ($params as $index => $value) { $type = null; if (isset($types[$index])) { $type = $types[$index]; } if ($anonymousParams) { $index += $offset; } $this->bindValue($index, $value, $type); } }
[ "public", "function", "bind", "(", "$", "params", ",", "$", "types", ")", "{", "if", "(", "empty", "(", "$", "params", ")", ")", "{", "return", ";", "}", "$", "anonymousParams", "=", "is_int", "(", "key", "(", "$", "params", ")", ")", "?", "true", ":", "false", ";", "$", "offset", "=", "1", ";", "foreach", "(", "$", "params", "as", "$", "index", "=>", "$", "value", ")", "{", "$", "type", "=", "null", ";", "if", "(", "isset", "(", "$", "types", "[", "$", "index", "]", ")", ")", "{", "$", "type", "=", "$", "types", "[", "$", "index", "]", ";", "}", "if", "(", "$", "anonymousParams", ")", "{", "$", "index", "+=", "$", "offset", ";", "}", "$", "this", "->", "bindValue", "(", "$", "index", ",", "$", "value", ",", "$", "type", ")", ";", "}", "}" ]
Binds a set of values to statement object with corresponding type. @param array $params list of values to be bound @param array $types list of types to be used, keys should match those in $params @return void
[ "Binds", "a", "set", "of", "values", "to", "statement", "object", "with", "corresponding", "type", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Statement/StatementDecorator.php#L306-L324
210,923
cakephp/cakephp
src/Database/Statement/StatementDecorator.php
StatementDecorator.lastInsertId
public function lastInsertId($table = null, $column = null) { $row = null; if ($column && $this->columnCount()) { $row = $this->fetch(static::FETCH_TYPE_ASSOC); } if (isset($row[$column])) { return $row[$column]; } return $this->_driver->lastInsertId($table, $column); }
php
public function lastInsertId($table = null, $column = null) { $row = null; if ($column && $this->columnCount()) { $row = $this->fetch(static::FETCH_TYPE_ASSOC); } if (isset($row[$column])) { return $row[$column]; } return $this->_driver->lastInsertId($table, $column); }
[ "public", "function", "lastInsertId", "(", "$", "table", "=", "null", ",", "$", "column", "=", "null", ")", "{", "$", "row", "=", "null", ";", "if", "(", "$", "column", "&&", "$", "this", "->", "columnCount", "(", ")", ")", "{", "$", "row", "=", "$", "this", "->", "fetch", "(", "static", "::", "FETCH_TYPE_ASSOC", ")", ";", "}", "if", "(", "isset", "(", "$", "row", "[", "$", "column", "]", ")", ")", "{", "return", "$", "row", "[", "$", "column", "]", ";", "}", "return", "$", "this", "->", "_driver", "->", "lastInsertId", "(", "$", "table", ",", "$", "column", ")", ";", "}" ]
Returns the latest primary inserted using this statement. @param string|null $table table name or sequence to get last insert value from @param string|null $column the name of the column representing the primary key @return string|int
[ "Returns", "the", "latest", "primary", "inserted", "using", "this", "statement", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Statement/StatementDecorator.php#L333-L344
210,924
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.buildFromArray
public static function buildFromArray($spec, $defaultOptions = true) { $parser = new static($spec['command'], $defaultOptions); if (!empty($spec['arguments'])) { $parser->addArguments($spec['arguments']); } if (!empty($spec['options'])) { $parser->addOptions($spec['options']); } if (!empty($spec['subcommands'])) { $parser->addSubcommands($spec['subcommands']); } if (!empty($spec['description'])) { $parser->setDescription($spec['description']); } if (!empty($spec['epilog'])) { $parser->setEpilog($spec['epilog']); } return $parser; }
php
public static function buildFromArray($spec, $defaultOptions = true) { $parser = new static($spec['command'], $defaultOptions); if (!empty($spec['arguments'])) { $parser->addArguments($spec['arguments']); } if (!empty($spec['options'])) { $parser->addOptions($spec['options']); } if (!empty($spec['subcommands'])) { $parser->addSubcommands($spec['subcommands']); } if (!empty($spec['description'])) { $parser->setDescription($spec['description']); } if (!empty($spec['epilog'])) { $parser->setEpilog($spec['epilog']); } return $parser; }
[ "public", "static", "function", "buildFromArray", "(", "$", "spec", ",", "$", "defaultOptions", "=", "true", ")", "{", "$", "parser", "=", "new", "static", "(", "$", "spec", "[", "'command'", "]", ",", "$", "defaultOptions", ")", ";", "if", "(", "!", "empty", "(", "$", "spec", "[", "'arguments'", "]", ")", ")", "{", "$", "parser", "->", "addArguments", "(", "$", "spec", "[", "'arguments'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "spec", "[", "'options'", "]", ")", ")", "{", "$", "parser", "->", "addOptions", "(", "$", "spec", "[", "'options'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "spec", "[", "'subcommands'", "]", ")", ")", "{", "$", "parser", "->", "addSubcommands", "(", "$", "spec", "[", "'subcommands'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "spec", "[", "'description'", "]", ")", ")", "{", "$", "parser", "->", "setDescription", "(", "$", "spec", "[", "'description'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "spec", "[", "'epilog'", "]", ")", ")", "{", "$", "parser", "->", "setEpilog", "(", "$", "spec", "[", "'epilog'", "]", ")", ";", "}", "return", "$", "parser", ";", "}" ]
Build a parser from an array. Uses an array like ``` $spec = [ 'description' => 'text', 'epilog' => 'text', 'arguments' => [ // list of arguments compatible with addArguments. ], 'options' => [ // list of options compatible with addOptions ], 'subcommands' => [ // list of subcommands to add. ] ]; ``` @param array $spec The spec to build the OptionParser with. @param bool $defaultOptions Whether you want the verbose and quiet options set. @return static
[ "Build", "a", "parser", "from", "an", "array", ".", "Uses", "an", "array", "like" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L217-L237
210,925
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.toArray
public function toArray() { $result = [ 'command' => $this->_command, 'arguments' => $this->_args, 'options' => $this->_options, 'subcommands' => $this->_subcommands, 'description' => $this->_description, 'epilog' => $this->_epilog ]; return $result; }
php
public function toArray() { $result = [ 'command' => $this->_command, 'arguments' => $this->_args, 'options' => $this->_options, 'subcommands' => $this->_subcommands, 'description' => $this->_description, 'epilog' => $this->_epilog ]; return $result; }
[ "public", "function", "toArray", "(", ")", "{", "$", "result", "=", "[", "'command'", "=>", "$", "this", "->", "_command", ",", "'arguments'", "=>", "$", "this", "->", "_args", ",", "'options'", "=>", "$", "this", "->", "_options", ",", "'subcommands'", "=>", "$", "this", "->", "_subcommands", ",", "'description'", "=>", "$", "this", "->", "_description", ",", "'epilog'", "=>", "$", "this", "->", "_epilog", "]", ";", "return", "$", "result", ";", "}" ]
Returns an array representation of this parser. @return array
[ "Returns", "an", "array", "representation", "of", "this", "parser", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L244-L256
210,926
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.setEpilog
public function setEpilog($text) { if (is_array($text)) { $text = implode("\n", $text); } $this->_epilog = $text; return $this; }
php
public function setEpilog($text) { if (is_array($text)) { $text = implode("\n", $text); } $this->_epilog = $text; return $this; }
[ "public", "function", "setEpilog", "(", "$", "text", ")", "{", "if", "(", "is_array", "(", "$", "text", ")", ")", "{", "$", "text", "=", "implode", "(", "\"\\n\"", ",", "$", "text", ")", ";", "}", "$", "this", "->", "_epilog", "=", "$", "text", ";", "return", "$", "this", ";", "}" ]
Sets an epilog to the parser. The epilog is added to the end of the options and arguments listing when help is generated. @param string|array $text The text to set. If an array the text will be imploded with "\n". @return $this
[ "Sets", "an", "epilog", "to", "the", "parser", ".", "The", "epilog", "is", "added", "to", "the", "end", "of", "the", "options", "and", "arguments", "listing", "when", "help", "is", "generated", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L387-L395
210,927
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.epilog
public function epilog($text = null) { deprecationWarning( 'ConsoleOptionParser::epliog() is deprecated. ' . 'Use ConsoleOptionParser::setEpilog()/getEpilog() instead.' ); if ($text !== null) { return $this->setEpilog($text); } return $this->getEpilog(); }
php
public function epilog($text = null) { deprecationWarning( 'ConsoleOptionParser::epliog() is deprecated. ' . 'Use ConsoleOptionParser::setEpilog()/getEpilog() instead.' ); if ($text !== null) { return $this->setEpilog($text); } return $this->getEpilog(); }
[ "public", "function", "epilog", "(", "$", "text", "=", "null", ")", "{", "deprecationWarning", "(", "'ConsoleOptionParser::epliog() is deprecated. '", ".", "'Use ConsoleOptionParser::setEpilog()/getEpilog() instead.'", ")", ";", "if", "(", "$", "text", "!==", "null", ")", "{", "return", "$", "this", "->", "setEpilog", "(", "$", "text", ")", ";", "}", "return", "$", "this", "->", "getEpilog", "(", ")", ";", "}" ]
Gets or sets an epilog to the parser. The epilog is added to the end of the options and arguments listing when help is generated. @deprecated 3.4.0 Use setEpilog()/getEpilog() instead. @param string|array|null $text Text when setting or null when reading. If an array the text will be imploded with "\n". @return string|$this If reading, the value of the epilog. If setting $this will be returned.
[ "Gets", "or", "sets", "an", "epilog", "to", "the", "parser", ".", "The", "epilog", "is", "added", "to", "the", "end", "of", "the", "options", "and", "arguments", "listing", "when", "help", "is", "generated", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L416-L427
210,928
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.addOption
public function addOption($name, array $options = []) { if ($name instanceof ConsoleInputOption) { $option = $name; $name = $option->name(); } else { $defaults = [ 'name' => $name, 'short' => null, 'help' => '', 'default' => null, 'boolean' => false, 'choices' => [] ]; $options += $defaults; $option = new ConsoleInputOption($options); } $this->_options[$name] = $option; asort($this->_options); if ($option->short() !== null) { $this->_shortOptions[$option->short()] = $name; asort($this->_shortOptions); } return $this; }
php
public function addOption($name, array $options = []) { if ($name instanceof ConsoleInputOption) { $option = $name; $name = $option->name(); } else { $defaults = [ 'name' => $name, 'short' => null, 'help' => '', 'default' => null, 'boolean' => false, 'choices' => [] ]; $options += $defaults; $option = new ConsoleInputOption($options); } $this->_options[$name] = $option; asort($this->_options); if ($option->short() !== null) { $this->_shortOptions[$option->short()] = $name; asort($this->_shortOptions); } return $this; }
[ "public", "function", "addOption", "(", "$", "name", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "name", "instanceof", "ConsoleInputOption", ")", "{", "$", "option", "=", "$", "name", ";", "$", "name", "=", "$", "option", "->", "name", "(", ")", ";", "}", "else", "{", "$", "defaults", "=", "[", "'name'", "=>", "$", "name", ",", "'short'", "=>", "null", ",", "'help'", "=>", "''", ",", "'default'", "=>", "null", ",", "'boolean'", "=>", "false", ",", "'choices'", "=>", "[", "]", "]", ";", "$", "options", "+=", "$", "defaults", ";", "$", "option", "=", "new", "ConsoleInputOption", "(", "$", "options", ")", ";", "}", "$", "this", "->", "_options", "[", "$", "name", "]", "=", "$", "option", ";", "asort", "(", "$", "this", "->", "_options", ")", ";", "if", "(", "$", "option", "->", "short", "(", ")", "!==", "null", ")", "{", "$", "this", "->", "_shortOptions", "[", "$", "option", "->", "short", "(", ")", "]", "=", "$", "name", ";", "asort", "(", "$", "this", "->", "_shortOptions", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add an option to the option parser. Options allow you to define optional or required parameters for your console application. Options are defined by the parameters they use. ### Options - `short` - The single letter variant for this option, leave undefined for none. - `help` - Help text for this option. Used when generating help for the option. - `default` - The default value for this option. Defaults are added into the parsed params when the attached option is not provided or has no value. Using default and boolean together will not work. are added into the parsed parameters when the option is undefined. Defaults to null. - `boolean` - The option uses no value, it's just a boolean switch. Defaults to false. If an option is defined as boolean, it will always be added to the parsed params. If no present it will be false, if present it will be true. - `multiple` - The option can be provided multiple times. The parsed option will be an array of values when this option is enabled. - `choices` A list of valid choices for this option. If left empty all values are valid.. An exception will be raised when parse() encounters an invalid value. @param \Cake\Console\ConsoleInputOption|string $name The long name you want to the value to be parsed out as when options are parsed. Will also accept an instance of ConsoleInputOption @param array $options An array of parameters that define the behavior of the option @return $this
[ "Add", "an", "option", "to", "the", "option", "parser", ".", "Options", "allow", "you", "to", "define", "optional", "or", "required", "parameters", "for", "your", "console", "application", ".", "Options", "are", "defined", "by", "the", "parameters", "they", "use", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L476-L501
210,929
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.addArgument
public function addArgument($name, array $params = []) { if ($name instanceof ConsoleInputArgument) { $arg = $name; $index = count($this->_args); } else { $defaults = [ 'name' => $name, 'help' => '', 'index' => count($this->_args), 'required' => false, 'choices' => [] ]; $options = $params + $defaults; $index = $options['index']; unset($options['index']); $arg = new ConsoleInputArgument($options); } foreach ($this->_args as $k => $a) { if ($a->isEqualTo($arg)) { return $this; } if (!empty($options['required']) && !$a->isRequired()) { throw new LogicException('A required argument cannot follow an optional one'); } } $this->_args[$index] = $arg; ksort($this->_args); return $this; }
php
public function addArgument($name, array $params = []) { if ($name instanceof ConsoleInputArgument) { $arg = $name; $index = count($this->_args); } else { $defaults = [ 'name' => $name, 'help' => '', 'index' => count($this->_args), 'required' => false, 'choices' => [] ]; $options = $params + $defaults; $index = $options['index']; unset($options['index']); $arg = new ConsoleInputArgument($options); } foreach ($this->_args as $k => $a) { if ($a->isEqualTo($arg)) { return $this; } if (!empty($options['required']) && !$a->isRequired()) { throw new LogicException('A required argument cannot follow an optional one'); } } $this->_args[$index] = $arg; ksort($this->_args); return $this; }
[ "public", "function", "addArgument", "(", "$", "name", ",", "array", "$", "params", "=", "[", "]", ")", "{", "if", "(", "$", "name", "instanceof", "ConsoleInputArgument", ")", "{", "$", "arg", "=", "$", "name", ";", "$", "index", "=", "count", "(", "$", "this", "->", "_args", ")", ";", "}", "else", "{", "$", "defaults", "=", "[", "'name'", "=>", "$", "name", ",", "'help'", "=>", "''", ",", "'index'", "=>", "count", "(", "$", "this", "->", "_args", ")", ",", "'required'", "=>", "false", ",", "'choices'", "=>", "[", "]", "]", ";", "$", "options", "=", "$", "params", "+", "$", "defaults", ";", "$", "index", "=", "$", "options", "[", "'index'", "]", ";", "unset", "(", "$", "options", "[", "'index'", "]", ")", ";", "$", "arg", "=", "new", "ConsoleInputArgument", "(", "$", "options", ")", ";", "}", "foreach", "(", "$", "this", "->", "_args", "as", "$", "k", "=>", "$", "a", ")", "{", "if", "(", "$", "a", "->", "isEqualTo", "(", "$", "arg", ")", ")", "{", "return", "$", "this", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'required'", "]", ")", "&&", "!", "$", "a", "->", "isRequired", "(", ")", ")", "{", "throw", "new", "LogicException", "(", "'A required argument cannot follow an optional one'", ")", ";", "}", "}", "$", "this", "->", "_args", "[", "$", "index", "]", "=", "$", "arg", ";", "ksort", "(", "$", "this", "->", "_args", ")", ";", "return", "$", "this", ";", "}" ]
Add a positional argument to the option parser. ### Params - `help` The help text to display for this argument. - `required` Whether this parameter is required. - `index` The index for the arg, if left undefined the argument will be put onto the end of the arguments. If you define the same index twice the first option will be overwritten. - `choices` A list of valid choices for this argument. If left empty all values are valid.. An exception will be raised when parse() encounters an invalid value. @param \Cake\Console\ConsoleInputArgument|string $name The name of the argument. Will also accept an instance of ConsoleInputArgument. @param array $params Parameters for the argument, see above. @return $this
[ "Add", "a", "positional", "argument", "to", "the", "option", "parser", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L534-L564
210,930
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.addArguments
public function addArguments(array $args) { foreach ($args as $name => $params) { if ($params instanceof ConsoleInputArgument) { $name = $params; $params = []; } $this->addArgument($name, $params); } return $this; }
php
public function addArguments(array $args) { foreach ($args as $name => $params) { if ($params instanceof ConsoleInputArgument) { $name = $params; $params = []; } $this->addArgument($name, $params); } return $this; }
[ "public", "function", "addArguments", "(", "array", "$", "args", ")", "{", "foreach", "(", "$", "args", "as", "$", "name", "=>", "$", "params", ")", "{", "if", "(", "$", "params", "instanceof", "ConsoleInputArgument", ")", "{", "$", "name", "=", "$", "params", ";", "$", "params", "=", "[", "]", ";", "}", "$", "this", "->", "addArgument", "(", "$", "name", ",", "$", "params", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add multiple arguments at once. Take an array of argument definitions. The keys are used as the argument names, and the values as params for the argument. @param array $args Array of arguments to add. @see \Cake\Console\ConsoleOptionParser::addArgument() @return $this
[ "Add", "multiple", "arguments", "at", "once", ".", "Take", "an", "array", "of", "argument", "definitions", ".", "The", "keys", "are", "used", "as", "the", "argument", "names", "and", "the", "values", "as", "params", "for", "the", "argument", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L574-L585
210,931
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.addOptions
public function addOptions(array $options) { foreach ($options as $name => $params) { if ($params instanceof ConsoleInputOption) { $name = $params; $params = []; } $this->addOption($name, $params); } return $this; }
php
public function addOptions(array $options) { foreach ($options as $name => $params) { if ($params instanceof ConsoleInputOption) { $name = $params; $params = []; } $this->addOption($name, $params); } return $this; }
[ "public", "function", "addOptions", "(", "array", "$", "options", ")", "{", "foreach", "(", "$", "options", "as", "$", "name", "=>", "$", "params", ")", "{", "if", "(", "$", "params", "instanceof", "ConsoleInputOption", ")", "{", "$", "name", "=", "$", "params", ";", "$", "params", "=", "[", "]", ";", "}", "$", "this", "->", "addOption", "(", "$", "name", ",", "$", "params", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add multiple options at once. Takes an array of option definitions. The keys are used as option names, and the values as params for the option. @param array $options Array of options to add. @see \Cake\Console\ConsoleOptionParser::addOption() @return $this
[ "Add", "multiple", "options", "at", "once", ".", "Takes", "an", "array", "of", "option", "definitions", ".", "The", "keys", "are", "used", "as", "option", "names", "and", "the", "values", "as", "params", "for", "the", "option", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L595-L606
210,932
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.addSubcommand
public function addSubcommand($name, array $options = []) { if ($name instanceof ConsoleInputSubcommand) { $command = $name; $name = $command->name(); } else { $name = Inflector::underscore($name); $defaults = [ 'name' => $name, 'help' => '', 'parser' => null ]; $options += $defaults; $command = new ConsoleInputSubcommand($options); } $this->_subcommands[$name] = $command; if ($this->_subcommandSort) { asort($this->_subcommands); } return $this; }
php
public function addSubcommand($name, array $options = []) { if ($name instanceof ConsoleInputSubcommand) { $command = $name; $name = $command->name(); } else { $name = Inflector::underscore($name); $defaults = [ 'name' => $name, 'help' => '', 'parser' => null ]; $options += $defaults; $command = new ConsoleInputSubcommand($options); } $this->_subcommands[$name] = $command; if ($this->_subcommandSort) { asort($this->_subcommands); } return $this; }
[ "public", "function", "addSubcommand", "(", "$", "name", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "name", "instanceof", "ConsoleInputSubcommand", ")", "{", "$", "command", "=", "$", "name", ";", "$", "name", "=", "$", "command", "->", "name", "(", ")", ";", "}", "else", "{", "$", "name", "=", "Inflector", "::", "underscore", "(", "$", "name", ")", ";", "$", "defaults", "=", "[", "'name'", "=>", "$", "name", ",", "'help'", "=>", "''", ",", "'parser'", "=>", "null", "]", ";", "$", "options", "+=", "$", "defaults", ";", "$", "command", "=", "new", "ConsoleInputSubcommand", "(", "$", "options", ")", ";", "}", "$", "this", "->", "_subcommands", "[", "$", "name", "]", "=", "$", "command", ";", "if", "(", "$", "this", "->", "_subcommandSort", ")", "{", "asort", "(", "$", "this", "->", "_subcommands", ")", ";", "}", "return", "$", "this", ";", "}" ]
Append a subcommand to the subcommand list. Subcommands are usually methods on your Shell, but can also be used to document Tasks. ### Options - `help` - Help text for the subcommand. - `parser` - A ConsoleOptionParser for the subcommand. This allows you to create method specific option parsers. When help is generated for a subcommand, if a parser is present it will be used. @param \Cake\Console\ConsoleInputSubcommand|string $name Name of the subcommand. Will also accept an instance of ConsoleInputSubcommand @param array $options Array of params, see above. @return $this
[ "Append", "a", "subcommand", "to", "the", "subcommand", "list", ".", "Subcommands", "are", "usually", "methods", "on", "your", "Shell", "but", "can", "also", "be", "used", "to", "document", "Tasks", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L623-L645
210,933
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.addSubcommands
public function addSubcommands(array $commands) { foreach ($commands as $name => $params) { if ($params instanceof ConsoleInputSubcommand) { $name = $params; $params = []; } $this->addSubcommand($name, $params); } return $this; }
php
public function addSubcommands(array $commands) { foreach ($commands as $name => $params) { if ($params instanceof ConsoleInputSubcommand) { $name = $params; $params = []; } $this->addSubcommand($name, $params); } return $this; }
[ "public", "function", "addSubcommands", "(", "array", "$", "commands", ")", "{", "foreach", "(", "$", "commands", "as", "$", "name", "=>", "$", "params", ")", "{", "if", "(", "$", "params", "instanceof", "ConsoleInputSubcommand", ")", "{", "$", "name", "=", "$", "params", ";", "$", "params", "=", "[", "]", ";", "}", "$", "this", "->", "addSubcommand", "(", "$", "name", ",", "$", "params", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add multiple subcommands at once. @param array $commands Array of subcommands. @return $this
[ "Add", "multiple", "subcommands", "at", "once", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L666-L677
210,934
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.argumentNames
public function argumentNames() { $out = []; foreach ($this->_args as $arg) { $out[] = $arg->name(); } return $out; }
php
public function argumentNames() { $out = []; foreach ($this->_args as $arg) { $out[] = $arg->name(); } return $out; }
[ "public", "function", "argumentNames", "(", ")", "{", "$", "out", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "_args", "as", "$", "arg", ")", "{", "$", "out", "[", "]", "=", "$", "arg", "->", "name", "(", ")", ";", "}", "return", "$", "out", ";", "}" ]
Get the list of argument names. @return string[]
[ "Get", "the", "list", "of", "argument", "names", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L694-L702
210,935
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.help
public function help($subcommand = null, $format = 'text', $width = 72) { if ($subcommand === null) { $formatter = new HelpFormatter($this); $formatter->setAlias($this->rootName); if ($format === 'text') { return $formatter->text($width); } if ($format === 'xml') { return (string)$formatter->xml(); } } if (isset($this->_subcommands[$subcommand])) { $command = $this->_subcommands[$subcommand]; $subparser = $command->parser(); // Generate a parser as the subcommand didn't define one. if (!($subparser instanceof self)) { // $subparser = clone $this; $subparser = new self($subcommand); $subparser ->setDescription($command->getRawHelp()) ->addOptions($this->options()) ->addArguments($this->arguments()); } if (strlen($subparser->getDescription()) === 0) { $subparser->setDescription($command->getRawHelp()); } $subparser->setCommand($this->getCommand() . ' ' . $subcommand); $subparser->setRootName($this->rootName); return $subparser->help(null, $format, $width); } return $this->getCommandError($subcommand); }
php
public function help($subcommand = null, $format = 'text', $width = 72) { if ($subcommand === null) { $formatter = new HelpFormatter($this); $formatter->setAlias($this->rootName); if ($format === 'text') { return $formatter->text($width); } if ($format === 'xml') { return (string)$formatter->xml(); } } if (isset($this->_subcommands[$subcommand])) { $command = $this->_subcommands[$subcommand]; $subparser = $command->parser(); // Generate a parser as the subcommand didn't define one. if (!($subparser instanceof self)) { // $subparser = clone $this; $subparser = new self($subcommand); $subparser ->setDescription($command->getRawHelp()) ->addOptions($this->options()) ->addArguments($this->arguments()); } if (strlen($subparser->getDescription()) === 0) { $subparser->setDescription($command->getRawHelp()); } $subparser->setCommand($this->getCommand() . ' ' . $subcommand); $subparser->setRootName($this->rootName); return $subparser->help(null, $format, $width); } return $this->getCommandError($subcommand); }
[ "public", "function", "help", "(", "$", "subcommand", "=", "null", ",", "$", "format", "=", "'text'", ",", "$", "width", "=", "72", ")", "{", "if", "(", "$", "subcommand", "===", "null", ")", "{", "$", "formatter", "=", "new", "HelpFormatter", "(", "$", "this", ")", ";", "$", "formatter", "->", "setAlias", "(", "$", "this", "->", "rootName", ")", ";", "if", "(", "$", "format", "===", "'text'", ")", "{", "return", "$", "formatter", "->", "text", "(", "$", "width", ")", ";", "}", "if", "(", "$", "format", "===", "'xml'", ")", "{", "return", "(", "string", ")", "$", "formatter", "->", "xml", "(", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "_subcommands", "[", "$", "subcommand", "]", ")", ")", "{", "$", "command", "=", "$", "this", "->", "_subcommands", "[", "$", "subcommand", "]", ";", "$", "subparser", "=", "$", "command", "->", "parser", "(", ")", ";", "// Generate a parser as the subcommand didn't define one.", "if", "(", "!", "(", "$", "subparser", "instanceof", "self", ")", ")", "{", "// $subparser = clone $this;", "$", "subparser", "=", "new", "self", "(", "$", "subcommand", ")", ";", "$", "subparser", "->", "setDescription", "(", "$", "command", "->", "getRawHelp", "(", ")", ")", "->", "addOptions", "(", "$", "this", "->", "options", "(", ")", ")", "->", "addArguments", "(", "$", "this", "->", "arguments", "(", ")", ")", ";", "}", "if", "(", "strlen", "(", "$", "subparser", "->", "getDescription", "(", ")", ")", "===", "0", ")", "{", "$", "subparser", "->", "setDescription", "(", "$", "command", "->", "getRawHelp", "(", ")", ")", ";", "}", "$", "subparser", "->", "setCommand", "(", "$", "this", "->", "getCommand", "(", ")", ".", "' '", ".", "$", "subcommand", ")", ";", "$", "subparser", "->", "setRootName", "(", "$", "this", "->", "rootName", ")", ";", "return", "$", "subparser", "->", "help", "(", "null", ",", "$", "format", ",", "$", "width", ")", ";", "}", "return", "$", "this", "->", "getCommandError", "(", "$", "subcommand", ")", ";", "}" ]
Gets formatted help for this parser object. Generates help text based on the description, options, arguments, subcommands and epilog in the parser. @param string|null $subcommand If present and a valid subcommand that has a linked parser. That subcommands help will be shown instead. @param string $format Define the output format, can be text or xml @param int $width The width to format user content to. Defaults to 72 @return string Generated help.
[ "Gets", "formatted", "help", "for", "this", "parser", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L791-L828
210,936
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.getCommandError
protected function getCommandError($command) { $rootCommand = $this->getCommand(); $subcommands = array_keys((array)$this->subcommands()); $bestGuess = $this->findClosestItem($command, $subcommands); $out = [ sprintf( 'Unable to find the `%s %s` subcommand. See `bin/%s %s --help`.', $rootCommand, $command, $this->rootName, $rootCommand ), '' ]; if ($bestGuess !== null) { $out[] = sprintf('Did you mean : `%s %s` ?', $rootCommand, $bestGuess); $out[] = ''; } $out[] = sprintf('Available subcommands for the `%s` command are : ', $rootCommand); $out[] = ''; foreach ($subcommands as $subcommand) { $out[] = ' - ' . $subcommand; } return implode("\n", $out); }
php
protected function getCommandError($command) { $rootCommand = $this->getCommand(); $subcommands = array_keys((array)$this->subcommands()); $bestGuess = $this->findClosestItem($command, $subcommands); $out = [ sprintf( 'Unable to find the `%s %s` subcommand. See `bin/%s %s --help`.', $rootCommand, $command, $this->rootName, $rootCommand ), '' ]; if ($bestGuess !== null) { $out[] = sprintf('Did you mean : `%s %s` ?', $rootCommand, $bestGuess); $out[] = ''; } $out[] = sprintf('Available subcommands for the `%s` command are : ', $rootCommand); $out[] = ''; foreach ($subcommands as $subcommand) { $out[] = ' - ' . $subcommand; } return implode("\n", $out); }
[ "protected", "function", "getCommandError", "(", "$", "command", ")", "{", "$", "rootCommand", "=", "$", "this", "->", "getCommand", "(", ")", ";", "$", "subcommands", "=", "array_keys", "(", "(", "array", ")", "$", "this", "->", "subcommands", "(", ")", ")", ";", "$", "bestGuess", "=", "$", "this", "->", "findClosestItem", "(", "$", "command", ",", "$", "subcommands", ")", ";", "$", "out", "=", "[", "sprintf", "(", "'Unable to find the `%s %s` subcommand. See `bin/%s %s --help`.'", ",", "$", "rootCommand", ",", "$", "command", ",", "$", "this", "->", "rootName", ",", "$", "rootCommand", ")", ",", "''", "]", ";", "if", "(", "$", "bestGuess", "!==", "null", ")", "{", "$", "out", "[", "]", "=", "sprintf", "(", "'Did you mean : `%s %s` ?'", ",", "$", "rootCommand", ",", "$", "bestGuess", ")", ";", "$", "out", "[", "]", "=", "''", ";", "}", "$", "out", "[", "]", "=", "sprintf", "(", "'Available subcommands for the `%s` command are : '", ",", "$", "rootCommand", ")", ";", "$", "out", "[", "]", "=", "''", ";", "foreach", "(", "$", "subcommands", "as", "$", "subcommand", ")", "{", "$", "out", "[", "]", "=", "' - '", ".", "$", "subcommand", ";", "}", "return", "implode", "(", "\"\\n\"", ",", "$", "out", ")", ";", "}" ]
Get the message output in the console stating that the command can not be found and tries to guess what the user wanted to say. Output a list of available subcommands as well. @param string $command Unknown command name trying to be dispatched. @return string The message to be displayed in the console.
[ "Get", "the", "message", "output", "in", "the", "console", "stating", "that", "the", "command", "can", "not", "be", "found", "and", "tries", "to", "guess", "what", "the", "user", "wanted", "to", "say", ".", "Output", "a", "list", "of", "available", "subcommands", "as", "well", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L866-L894
210,937
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.getOptionError
protected function getOptionError($option) { $availableOptions = array_keys($this->_options); $bestGuess = $this->findClosestItem($option, $availableOptions); $out = [ sprintf('Unknown option `%s`.', $option), '' ]; if ($bestGuess !== null) { $out[] = sprintf('Did you mean `%s` ?', $bestGuess); $out[] = ''; } $out[] = 'Available options are :'; $out[] = ''; foreach ($availableOptions as $availableOption) { $out[] = ' - ' . $availableOption; } return implode("\n", $out); }
php
protected function getOptionError($option) { $availableOptions = array_keys($this->_options); $bestGuess = $this->findClosestItem($option, $availableOptions); $out = [ sprintf('Unknown option `%s`.', $option), '' ]; if ($bestGuess !== null) { $out[] = sprintf('Did you mean `%s` ?', $bestGuess); $out[] = ''; } $out[] = 'Available options are :'; $out[] = ''; foreach ($availableOptions as $availableOption) { $out[] = ' - ' . $availableOption; } return implode("\n", $out); }
[ "protected", "function", "getOptionError", "(", "$", "option", ")", "{", "$", "availableOptions", "=", "array_keys", "(", "$", "this", "->", "_options", ")", ";", "$", "bestGuess", "=", "$", "this", "->", "findClosestItem", "(", "$", "option", ",", "$", "availableOptions", ")", ";", "$", "out", "=", "[", "sprintf", "(", "'Unknown option `%s`.'", ",", "$", "option", ")", ",", "''", "]", ";", "if", "(", "$", "bestGuess", "!==", "null", ")", "{", "$", "out", "[", "]", "=", "sprintf", "(", "'Did you mean `%s` ?'", ",", "$", "bestGuess", ")", ";", "$", "out", "[", "]", "=", "''", ";", "}", "$", "out", "[", "]", "=", "'Available options are :'", ";", "$", "out", "[", "]", "=", "''", ";", "foreach", "(", "$", "availableOptions", "as", "$", "availableOption", ")", "{", "$", "out", "[", "]", "=", "' - '", ".", "$", "availableOption", ";", "}", "return", "implode", "(", "\"\\n\"", ",", "$", "out", ")", ";", "}" ]
Get the message output in the console stating that the option can not be found and tries to guess what the user wanted to say. Output a list of available options as well. @param string $option Unknown option name trying to be used. @return string The message to be displayed in the console.
[ "Get", "the", "message", "output", "in", "the", "console", "stating", "that", "the", "option", "can", "not", "be", "found", "and", "tries", "to", "guess", "what", "the", "user", "wanted", "to", "say", ".", "Output", "a", "list", "of", "available", "options", "as", "well", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L903-L924
210,938
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.getShortOptionError
protected function getShortOptionError($option) { $out = [sprintf('Unknown short option `%s`', $option)]; $out[] = ''; $out[] = 'Available short options are :'; $out[] = ''; foreach ($this->_shortOptions as $short => $long) { $out[] = sprintf(' - `%s` (short for `--%s`)', $short, $long); } return implode("\n", $out); }
php
protected function getShortOptionError($option) { $out = [sprintf('Unknown short option `%s`', $option)]; $out[] = ''; $out[] = 'Available short options are :'; $out[] = ''; foreach ($this->_shortOptions as $short => $long) { $out[] = sprintf(' - `%s` (short for `--%s`)', $short, $long); } return implode("\n", $out); }
[ "protected", "function", "getShortOptionError", "(", "$", "option", ")", "{", "$", "out", "=", "[", "sprintf", "(", "'Unknown short option `%s`'", ",", "$", "option", ")", "]", ";", "$", "out", "[", "]", "=", "''", ";", "$", "out", "[", "]", "=", "'Available short options are :'", ";", "$", "out", "[", "]", "=", "''", ";", "foreach", "(", "$", "this", "->", "_shortOptions", "as", "$", "short", "=>", "$", "long", ")", "{", "$", "out", "[", "]", "=", "sprintf", "(", "' - `%s` (short for `--%s`)'", ",", "$", "short", ",", "$", "long", ")", ";", "}", "return", "implode", "(", "\"\\n\"", ",", "$", "out", ")", ";", "}" ]
Get the message output in the console stating that the short option can not be found. Output a list of available short options and what option they refer to as well. @param string $option Unknown short option name trying to be used. @return string The message to be displayed in the console.
[ "Get", "the", "message", "output", "in", "the", "console", "stating", "that", "the", "short", "option", "can", "not", "be", "found", ".", "Output", "a", "list", "of", "available", "short", "options", "and", "what", "option", "they", "refer", "to", "as", "well", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L933-L945
210,939
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser.findClosestItem
protected function findClosestItem($needle, $haystack) { $bestGuess = null; foreach ($haystack as $item) { if (preg_match('/^' . $needle . '/', $item)) { return $item; } } foreach ($haystack as $item) { if (preg_match('/' . $needle . '/', $item)) { return $item; } $score = levenshtein($needle, $item); if (!isset($bestScore) || $score < $bestScore) { $bestScore = $score; $bestGuess = $item; } } return $bestGuess; }
php
protected function findClosestItem($needle, $haystack) { $bestGuess = null; foreach ($haystack as $item) { if (preg_match('/^' . $needle . '/', $item)) { return $item; } } foreach ($haystack as $item) { if (preg_match('/' . $needle . '/', $item)) { return $item; } $score = levenshtein($needle, $item); if (!isset($bestScore) || $score < $bestScore) { $bestScore = $score; $bestGuess = $item; } } return $bestGuess; }
[ "protected", "function", "findClosestItem", "(", "$", "needle", ",", "$", "haystack", ")", "{", "$", "bestGuess", "=", "null", ";", "foreach", "(", "$", "haystack", "as", "$", "item", ")", "{", "if", "(", "preg_match", "(", "'/^'", ".", "$", "needle", ".", "'/'", ",", "$", "item", ")", ")", "{", "return", "$", "item", ";", "}", "}", "foreach", "(", "$", "haystack", "as", "$", "item", ")", "{", "if", "(", "preg_match", "(", "'/'", ".", "$", "needle", ".", "'/'", ",", "$", "item", ")", ")", "{", "return", "$", "item", ";", "}", "$", "score", "=", "levenshtein", "(", "$", "needle", ",", "$", "item", ")", ";", "if", "(", "!", "isset", "(", "$", "bestScore", ")", "||", "$", "score", "<", "$", "bestScore", ")", "{", "$", "bestScore", "=", "$", "score", ";", "$", "bestGuess", "=", "$", "item", ";", "}", "}", "return", "$", "bestGuess", ";", "}" ]
Tries to guess the item name the user originally wanted using the some regex pattern and the levenshtein algorithm. @param string $needle Unknown item (either a subcommand name or an option for instance) trying to be used. @param string[] $haystack List of items available for the type $needle belongs to. @return string|null The closest name to the item submitted by the user.
[ "Tries", "to", "guess", "the", "item", "name", "the", "user", "originally", "wanted", "using", "the", "some", "regex", "pattern", "and", "the", "levenshtein", "algorithm", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L955-L978
210,940
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser._parseOption
protected function _parseOption($name, $params) { if (!isset($this->_options[$name])) { throw new ConsoleException($this->getOptionError($name)); } $option = $this->_options[$name]; $isBoolean = $option->isBoolean(); $nextValue = $this->_nextToken(); $emptyNextValue = (empty($nextValue) && $nextValue !== '0'); if (!$isBoolean && !$emptyNextValue && !$this->_optionExists($nextValue)) { array_shift($this->_tokens); $value = $nextValue; } elseif ($isBoolean) { $value = true; } else { $value = $option->defaultValue(); } if ($option->validChoice($value)) { if ($option->acceptsMultiple()) { $params[$name][] = $value; } else { $params[$name] = $value; } return $params; } return []; }
php
protected function _parseOption($name, $params) { if (!isset($this->_options[$name])) { throw new ConsoleException($this->getOptionError($name)); } $option = $this->_options[$name]; $isBoolean = $option->isBoolean(); $nextValue = $this->_nextToken(); $emptyNextValue = (empty($nextValue) && $nextValue !== '0'); if (!$isBoolean && !$emptyNextValue && !$this->_optionExists($nextValue)) { array_shift($this->_tokens); $value = $nextValue; } elseif ($isBoolean) { $value = true; } else { $value = $option->defaultValue(); } if ($option->validChoice($value)) { if ($option->acceptsMultiple()) { $params[$name][] = $value; } else { $params[$name] = $value; } return $params; } return []; }
[ "protected", "function", "_parseOption", "(", "$", "name", ",", "$", "params", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_options", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "ConsoleException", "(", "$", "this", "->", "getOptionError", "(", "$", "name", ")", ")", ";", "}", "$", "option", "=", "$", "this", "->", "_options", "[", "$", "name", "]", ";", "$", "isBoolean", "=", "$", "option", "->", "isBoolean", "(", ")", ";", "$", "nextValue", "=", "$", "this", "->", "_nextToken", "(", ")", ";", "$", "emptyNextValue", "=", "(", "empty", "(", "$", "nextValue", ")", "&&", "$", "nextValue", "!==", "'0'", ")", ";", "if", "(", "!", "$", "isBoolean", "&&", "!", "$", "emptyNextValue", "&&", "!", "$", "this", "->", "_optionExists", "(", "$", "nextValue", ")", ")", "{", "array_shift", "(", "$", "this", "->", "_tokens", ")", ";", "$", "value", "=", "$", "nextValue", ";", "}", "elseif", "(", "$", "isBoolean", ")", "{", "$", "value", "=", "true", ";", "}", "else", "{", "$", "value", "=", "$", "option", "->", "defaultValue", "(", ")", ";", "}", "if", "(", "$", "option", "->", "validChoice", "(", "$", "value", ")", ")", "{", "if", "(", "$", "option", "->", "acceptsMultiple", "(", ")", ")", "{", "$", "params", "[", "$", "name", "]", "[", "]", "=", "$", "value", ";", "}", "else", "{", "$", "params", "[", "$", "name", "]", "=", "$", "value", ";", "}", "return", "$", "params", ";", "}", "return", "[", "]", ";", "}" ]
Parse an option by its name index. @param string $name The name to parse. @param array $params The params to append the parsed value into @return array Params with $option added in. @throws \Cake\Console\Exception\ConsoleException
[ "Parse", "an", "option", "by", "its", "name", "index", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L1035-L1063
210,941
cakephp/cakephp
src/Console/ConsoleOptionParser.php
ConsoleOptionParser._parseArg
protected function _parseArg($argument, $args) { if (empty($this->_args)) { $args[] = $argument; return $args; } $next = count($args); if (!isset($this->_args[$next])) { throw new ConsoleException('Too many arguments.'); } if ($this->_args[$next]->validChoice($argument)) { $args[] = $argument; return $args; } }
php
protected function _parseArg($argument, $args) { if (empty($this->_args)) { $args[] = $argument; return $args; } $next = count($args); if (!isset($this->_args[$next])) { throw new ConsoleException('Too many arguments.'); } if ($this->_args[$next]->validChoice($argument)) { $args[] = $argument; return $args; } }
[ "protected", "function", "_parseArg", "(", "$", "argument", ",", "$", "args", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_args", ")", ")", "{", "$", "args", "[", "]", "=", "$", "argument", ";", "return", "$", "args", ";", "}", "$", "next", "=", "count", "(", "$", "args", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_args", "[", "$", "next", "]", ")", ")", "{", "throw", "new", "ConsoleException", "(", "'Too many arguments.'", ")", ";", "}", "if", "(", "$", "this", "->", "_args", "[", "$", "next", "]", "->", "validChoice", "(", "$", "argument", ")", ")", "{", "$", "args", "[", "]", "=", "$", "argument", ";", "return", "$", "args", ";", "}", "}" ]
Parse an argument, and ensure that the argument doesn't exceed the number of arguments and that the argument is a valid choice. @param string $argument The argument to append @param array $args The array of parsed args to append to. @return string[] Args @throws \Cake\Console\Exception\ConsoleException
[ "Parse", "an", "argument", "and", "ensure", "that", "the", "argument", "doesn", "t", "exceed", "the", "number", "of", "arguments", "and", "that", "the", "argument", "is", "a", "valid", "choice", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOptionParser.php#L1092-L1109
210,942
cakephp/cakephp
src/Database/Schema/CachedCollection.php
CachedCollection.cacheMetadata
public function cacheMetadata($enable = null) { deprecationWarning( 'CachedCollection::cacheMetadata() is deprecated. ' . 'Use CachedCollection::setCacheMetadata()/getCacheMetadata() instead.' ); if ($enable !== null) { $this->setCacheMetadata($enable); } return $this->getCacheMetadata(); }
php
public function cacheMetadata($enable = null) { deprecationWarning( 'CachedCollection::cacheMetadata() is deprecated. ' . 'Use CachedCollection::setCacheMetadata()/getCacheMetadata() instead.' ); if ($enable !== null) { $this->setCacheMetadata($enable); } return $this->getCacheMetadata(); }
[ "public", "function", "cacheMetadata", "(", "$", "enable", "=", "null", ")", "{", "deprecationWarning", "(", "'CachedCollection::cacheMetadata() is deprecated. '", ".", "'Use CachedCollection::setCacheMetadata()/getCacheMetadata() instead.'", ")", ";", "if", "(", "$", "enable", "!==", "null", ")", "{", "$", "this", "->", "setCacheMetadata", "(", "$", "enable", ")", ";", "}", "return", "$", "this", "->", "getCacheMetadata", "(", ")", ";", "}" ]
Sets the cache config name to use for caching table metadata, or disables it if false is passed. If called with no arguments it returns the current configuration name. @deprecated 3.4.0 Use setCacheMetadata()/getCacheMetadata() @param bool|null $enable Whether or not to enable caching @return string|bool
[ "Sets", "the", "cache", "config", "name", "to", "use", "for", "caching", "table", "metadata", "or", "disables", "it", "if", "false", "is", "passed", ".", "If", "called", "with", "no", "arguments", "it", "returns", "the", "current", "configuration", "name", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/CachedCollection.php#L120-L131
210,943
cakephp/cakephp
src/Error/ExceptionRenderer.php
ExceptionRenderer._getController
protected function _getController() { $request = $this->request; $routerRequest = Router::getRequest(true); // Fallback to the request in the router or make a new one from // $_SERVER if ($request === null) { $request = $routerRequest ?: ServerRequestFactory::fromGlobals(); } // If the current request doesn't have routing data, but we // found a request in the router context copy the params over if ($request->getParam('controller') === false && $routerRequest !== null) { $request = $request->withAttribute('params', $routerRequest->getAttribute('params')); } $response = new Response(); $controller = null; try { $namespace = 'Controller'; $prefix = $request->getParam('prefix'); if ($prefix) { if (strpos($prefix, '/') === false) { $namespace .= '/' . Inflector::camelize($prefix); } else { $prefixes = array_map( 'Cake\Utility\Inflector::camelize', explode('/', $prefix) ); $namespace .= '/' . implode('/', $prefixes); } } $class = App::className('Error', $namespace, 'Controller'); if (!$class && $namespace !== 'Controller') { $class = App::className('Error', 'Controller', 'Controller'); } /* @var \Cake\Controller\Controller $controller */ $controller = new $class($request, $response); $controller->startupProcess(); $startup = true; } catch (Exception $e) { $startup = false; } // Retry RequestHandler, as another aspect of startupProcess() // could have failed. Ignore any exceptions out of startup, as // there could be userland input data parsers. if ($startup === false && !empty($controller) && isset($controller->RequestHandler)) { try { $event = new Event('Controller.startup', $controller); $controller->RequestHandler->startup($event); } catch (Exception $e) { } } if (empty($controller)) { $controller = new Controller($request, $response); } return $controller; }
php
protected function _getController() { $request = $this->request; $routerRequest = Router::getRequest(true); // Fallback to the request in the router or make a new one from // $_SERVER if ($request === null) { $request = $routerRequest ?: ServerRequestFactory::fromGlobals(); } // If the current request doesn't have routing data, but we // found a request in the router context copy the params over if ($request->getParam('controller') === false && $routerRequest !== null) { $request = $request->withAttribute('params', $routerRequest->getAttribute('params')); } $response = new Response(); $controller = null; try { $namespace = 'Controller'; $prefix = $request->getParam('prefix'); if ($prefix) { if (strpos($prefix, '/') === false) { $namespace .= '/' . Inflector::camelize($prefix); } else { $prefixes = array_map( 'Cake\Utility\Inflector::camelize', explode('/', $prefix) ); $namespace .= '/' . implode('/', $prefixes); } } $class = App::className('Error', $namespace, 'Controller'); if (!$class && $namespace !== 'Controller') { $class = App::className('Error', 'Controller', 'Controller'); } /* @var \Cake\Controller\Controller $controller */ $controller = new $class($request, $response); $controller->startupProcess(); $startup = true; } catch (Exception $e) { $startup = false; } // Retry RequestHandler, as another aspect of startupProcess() // could have failed. Ignore any exceptions out of startup, as // there could be userland input data parsers. if ($startup === false && !empty($controller) && isset($controller->RequestHandler)) { try { $event = new Event('Controller.startup', $controller); $controller->RequestHandler->startup($event); } catch (Exception $e) { } } if (empty($controller)) { $controller = new Controller($request, $response); } return $controller; }
[ "protected", "function", "_getController", "(", ")", "{", "$", "request", "=", "$", "this", "->", "request", ";", "$", "routerRequest", "=", "Router", "::", "getRequest", "(", "true", ")", ";", "// Fallback to the request in the router or make a new one from", "// $_SERVER", "if", "(", "$", "request", "===", "null", ")", "{", "$", "request", "=", "$", "routerRequest", "?", ":", "ServerRequestFactory", "::", "fromGlobals", "(", ")", ";", "}", "// If the current request doesn't have routing data, but we", "// found a request in the router context copy the params over", "if", "(", "$", "request", "->", "getParam", "(", "'controller'", ")", "===", "false", "&&", "$", "routerRequest", "!==", "null", ")", "{", "$", "request", "=", "$", "request", "->", "withAttribute", "(", "'params'", ",", "$", "routerRequest", "->", "getAttribute", "(", "'params'", ")", ")", ";", "}", "$", "response", "=", "new", "Response", "(", ")", ";", "$", "controller", "=", "null", ";", "try", "{", "$", "namespace", "=", "'Controller'", ";", "$", "prefix", "=", "$", "request", "->", "getParam", "(", "'prefix'", ")", ";", "if", "(", "$", "prefix", ")", "{", "if", "(", "strpos", "(", "$", "prefix", ",", "'/'", ")", "===", "false", ")", "{", "$", "namespace", ".=", "'/'", ".", "Inflector", "::", "camelize", "(", "$", "prefix", ")", ";", "}", "else", "{", "$", "prefixes", "=", "array_map", "(", "'Cake\\Utility\\Inflector::camelize'", ",", "explode", "(", "'/'", ",", "$", "prefix", ")", ")", ";", "$", "namespace", ".=", "'/'", ".", "implode", "(", "'/'", ",", "$", "prefixes", ")", ";", "}", "}", "$", "class", "=", "App", "::", "className", "(", "'Error'", ",", "$", "namespace", ",", "'Controller'", ")", ";", "if", "(", "!", "$", "class", "&&", "$", "namespace", "!==", "'Controller'", ")", "{", "$", "class", "=", "App", "::", "className", "(", "'Error'", ",", "'Controller'", ",", "'Controller'", ")", ";", "}", "/* @var \\Cake\\Controller\\Controller $controller */", "$", "controller", "=", "new", "$", "class", "(", "$", "request", ",", "$", "response", ")", ";", "$", "controller", "->", "startupProcess", "(", ")", ";", "$", "startup", "=", "true", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "startup", "=", "false", ";", "}", "// Retry RequestHandler, as another aspect of startupProcess()", "// could have failed. Ignore any exceptions out of startup, as", "// there could be userland input data parsers.", "if", "(", "$", "startup", "===", "false", "&&", "!", "empty", "(", "$", "controller", ")", "&&", "isset", "(", "$", "controller", "->", "RequestHandler", ")", ")", "{", "try", "{", "$", "event", "=", "new", "Event", "(", "'Controller.startup'", ",", "$", "controller", ")", ";", "$", "controller", "->", "RequestHandler", "->", "startup", "(", "$", "event", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "}", "}", "if", "(", "empty", "(", "$", "controller", ")", ")", "{", "$", "controller", "=", "new", "Controller", "(", "$", "request", ",", "$", "response", ")", ";", "}", "return", "$", "controller", ";", "}" ]
Get the controller instance to handle the exception. Override this method in subclasses to customize the controller used. This method returns the built in `ErrorController` normally, or if an error is repeated a bare controller will be used. @return \Cake\Controller\Controller @triggers Controller.startup $controller
[ "Get", "the", "controller", "instance", "to", "handle", "the", "exception", ".", "Override", "this", "method", "in", "subclasses", "to", "customize", "the", "controller", "used", ".", "This", "method", "returns", "the", "built", "in", "ErrorController", "normally", "or", "if", "an", "error", "is", "repeated", "a", "bare", "controller", "will", "be", "used", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ExceptionRenderer.php#L126-L188
210,944
cakephp/cakephp
src/Error/ExceptionRenderer.php
ExceptionRenderer.render
public function render() { $exception = $this->error; $code = $this->_code($exception); $method = $this->_method($exception); $template = $this->_template($exception, $method, $code); $unwrapped = $this->_unwrap($exception); if (method_exists($this, $method)) { return $this->_customMethod($method, $unwrapped); } $message = $this->_message($exception, $code); $url = $this->controller->getRequest()->getRequestTarget(); $response = $this->controller->getResponse(); if ($exception instanceof CakeException) { foreach ((array)$exception->responseHeader() as $key => $value) { $response = $response->withHeader($key, $value); } } $response = $response->withStatus($code); $viewVars = [ 'message' => $message, 'url' => h($url), 'error' => $unwrapped, 'code' => $code, '_serialize' => ['message', 'url', 'code'] ]; $isDebug = Configure::read('debug'); if ($isDebug) { $viewVars['trace'] = Debugger::formatTrace($unwrapped->getTrace(), [ 'format' => 'array', 'args' => false ]); $viewVars['file'] = $exception->getFile() ?: 'null'; $viewVars['line'] = $exception->getLine() ?: 'null'; $viewVars['_serialize'][] = 'file'; $viewVars['_serialize'][] = 'line'; } $this->controller->set($viewVars); if ($unwrapped instanceof CakeException && $isDebug) { $this->controller->set($unwrapped->getAttributes()); } $this->controller->response = $response; return $this->_outputMessage($template); }
php
public function render() { $exception = $this->error; $code = $this->_code($exception); $method = $this->_method($exception); $template = $this->_template($exception, $method, $code); $unwrapped = $this->_unwrap($exception); if (method_exists($this, $method)) { return $this->_customMethod($method, $unwrapped); } $message = $this->_message($exception, $code); $url = $this->controller->getRequest()->getRequestTarget(); $response = $this->controller->getResponse(); if ($exception instanceof CakeException) { foreach ((array)$exception->responseHeader() as $key => $value) { $response = $response->withHeader($key, $value); } } $response = $response->withStatus($code); $viewVars = [ 'message' => $message, 'url' => h($url), 'error' => $unwrapped, 'code' => $code, '_serialize' => ['message', 'url', 'code'] ]; $isDebug = Configure::read('debug'); if ($isDebug) { $viewVars['trace'] = Debugger::formatTrace($unwrapped->getTrace(), [ 'format' => 'array', 'args' => false ]); $viewVars['file'] = $exception->getFile() ?: 'null'; $viewVars['line'] = $exception->getLine() ?: 'null'; $viewVars['_serialize'][] = 'file'; $viewVars['_serialize'][] = 'line'; } $this->controller->set($viewVars); if ($unwrapped instanceof CakeException && $isDebug) { $this->controller->set($unwrapped->getAttributes()); } $this->controller->response = $response; return $this->_outputMessage($template); }
[ "public", "function", "render", "(", ")", "{", "$", "exception", "=", "$", "this", "->", "error", ";", "$", "code", "=", "$", "this", "->", "_code", "(", "$", "exception", ")", ";", "$", "method", "=", "$", "this", "->", "_method", "(", "$", "exception", ")", ";", "$", "template", "=", "$", "this", "->", "_template", "(", "$", "exception", ",", "$", "method", ",", "$", "code", ")", ";", "$", "unwrapped", "=", "$", "this", "->", "_unwrap", "(", "$", "exception", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "return", "$", "this", "->", "_customMethod", "(", "$", "method", ",", "$", "unwrapped", ")", ";", "}", "$", "message", "=", "$", "this", "->", "_message", "(", "$", "exception", ",", "$", "code", ")", ";", "$", "url", "=", "$", "this", "->", "controller", "->", "getRequest", "(", ")", "->", "getRequestTarget", "(", ")", ";", "$", "response", "=", "$", "this", "->", "controller", "->", "getResponse", "(", ")", ";", "if", "(", "$", "exception", "instanceof", "CakeException", ")", "{", "foreach", "(", "(", "array", ")", "$", "exception", "->", "responseHeader", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "response", "=", "$", "response", "->", "withHeader", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}", "$", "response", "=", "$", "response", "->", "withStatus", "(", "$", "code", ")", ";", "$", "viewVars", "=", "[", "'message'", "=>", "$", "message", ",", "'url'", "=>", "h", "(", "$", "url", ")", ",", "'error'", "=>", "$", "unwrapped", ",", "'code'", "=>", "$", "code", ",", "'_serialize'", "=>", "[", "'message'", ",", "'url'", ",", "'code'", "]", "]", ";", "$", "isDebug", "=", "Configure", "::", "read", "(", "'debug'", ")", ";", "if", "(", "$", "isDebug", ")", "{", "$", "viewVars", "[", "'trace'", "]", "=", "Debugger", "::", "formatTrace", "(", "$", "unwrapped", "->", "getTrace", "(", ")", ",", "[", "'format'", "=>", "'array'", ",", "'args'", "=>", "false", "]", ")", ";", "$", "viewVars", "[", "'file'", "]", "=", "$", "exception", "->", "getFile", "(", ")", "?", ":", "'null'", ";", "$", "viewVars", "[", "'line'", "]", "=", "$", "exception", "->", "getLine", "(", ")", "?", ":", "'null'", ";", "$", "viewVars", "[", "'_serialize'", "]", "[", "]", "=", "'file'", ";", "$", "viewVars", "[", "'_serialize'", "]", "[", "]", "=", "'line'", ";", "}", "$", "this", "->", "controller", "->", "set", "(", "$", "viewVars", ")", ";", "if", "(", "$", "unwrapped", "instanceof", "CakeException", "&&", "$", "isDebug", ")", "{", "$", "this", "->", "controller", "->", "set", "(", "$", "unwrapped", "->", "getAttributes", "(", ")", ")", ";", "}", "$", "this", "->", "controller", "->", "response", "=", "$", "response", ";", "return", "$", "this", "->", "_outputMessage", "(", "$", "template", ")", ";", "}" ]
Renders the response for the exception. @return \Cake\Http\Response The response to be sent.
[ "Renders", "the", "response", "for", "the", "exception", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ExceptionRenderer.php#L195-L245
210,945
cakephp/cakephp
src/Error/ExceptionRenderer.php
ExceptionRenderer._method
protected function _method(Exception $exception) { $exception = $this->_unwrap($exception); list(, $baseClass) = namespaceSplit(get_class($exception)); if (substr($baseClass, -9) === 'Exception') { $baseClass = substr($baseClass, 0, -9); } $method = Inflector::variable($baseClass) ?: 'error500'; return $this->method = $method; }
php
protected function _method(Exception $exception) { $exception = $this->_unwrap($exception); list(, $baseClass) = namespaceSplit(get_class($exception)); if (substr($baseClass, -9) === 'Exception') { $baseClass = substr($baseClass, 0, -9); } $method = Inflector::variable($baseClass) ?: 'error500'; return $this->method = $method; }
[ "protected", "function", "_method", "(", "Exception", "$", "exception", ")", "{", "$", "exception", "=", "$", "this", "->", "_unwrap", "(", "$", "exception", ")", ";", "list", "(", ",", "$", "baseClass", ")", "=", "namespaceSplit", "(", "get_class", "(", "$", "exception", ")", ")", ";", "if", "(", "substr", "(", "$", "baseClass", ",", "-", "9", ")", "===", "'Exception'", ")", "{", "$", "baseClass", "=", "substr", "(", "$", "baseClass", ",", "0", ",", "-", "9", ")", ";", "}", "$", "method", "=", "Inflector", "::", "variable", "(", "$", "baseClass", ")", "?", ":", "'error500'", ";", "return", "$", "this", "->", "method", "=", "$", "method", ";", "}" ]
Get method name @param \Exception $exception Exception instance. @return string
[ "Get", "method", "name" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ExceptionRenderer.php#L271-L283
210,946
cakephp/cakephp
src/Error/ExceptionRenderer.php
ExceptionRenderer._template
protected function _template(Exception $exception, $method, $code) { $exception = $this->_unwrap($exception); $isHttpException = $exception instanceof HttpException; if (!Configure::read('debug') && !$isHttpException || $isHttpException) { $template = 'error500'; if ($code < 500) { $template = 'error400'; } return $this->template = $template; } $template = $method ?: 'error500'; if ($exception instanceof PDOException) { $template = 'pdo_error'; } return $this->template = $template; }
php
protected function _template(Exception $exception, $method, $code) { $exception = $this->_unwrap($exception); $isHttpException = $exception instanceof HttpException; if (!Configure::read('debug') && !$isHttpException || $isHttpException) { $template = 'error500'; if ($code < 500) { $template = 'error400'; } return $this->template = $template; } $template = $method ?: 'error500'; if ($exception instanceof PDOException) { $template = 'pdo_error'; } return $this->template = $template; }
[ "protected", "function", "_template", "(", "Exception", "$", "exception", ",", "$", "method", ",", "$", "code", ")", "{", "$", "exception", "=", "$", "this", "->", "_unwrap", "(", "$", "exception", ")", ";", "$", "isHttpException", "=", "$", "exception", "instanceof", "HttpException", ";", "if", "(", "!", "Configure", "::", "read", "(", "'debug'", ")", "&&", "!", "$", "isHttpException", "||", "$", "isHttpException", ")", "{", "$", "template", "=", "'error500'", ";", "if", "(", "$", "code", "<", "500", ")", "{", "$", "template", "=", "'error400'", ";", "}", "return", "$", "this", "->", "template", "=", "$", "template", ";", "}", "$", "template", "=", "$", "method", "?", ":", "'error500'", ";", "if", "(", "$", "exception", "instanceof", "PDOException", ")", "{", "$", "template", "=", "'pdo_error'", ";", "}", "return", "$", "this", "->", "template", "=", "$", "template", ";", "}" ]
Get template for rendering exception info. @param \Exception $exception Exception instance. @param string $method Method name. @param int $code Error code. @return string Template name
[ "Get", "template", "for", "rendering", "exception", "info", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ExceptionRenderer.php#L318-L339
210,947
cakephp/cakephp
src/Error/ExceptionRenderer.php
ExceptionRenderer._code
protected function _code(Exception $exception) { $code = 500; $exception = $this->_unwrap($exception); $errorCode = $exception->getCode(); if ($errorCode >= 400 && $errorCode < 600) { $code = $errorCode; } return $code; }
php
protected function _code(Exception $exception) { $code = 500; $exception = $this->_unwrap($exception); $errorCode = $exception->getCode(); if ($errorCode >= 400 && $errorCode < 600) { $code = $errorCode; } return $code; }
[ "protected", "function", "_code", "(", "Exception", "$", "exception", ")", "{", "$", "code", "=", "500", ";", "$", "exception", "=", "$", "this", "->", "_unwrap", "(", "$", "exception", ")", ";", "$", "errorCode", "=", "$", "exception", "->", "getCode", "(", ")", ";", "if", "(", "$", "errorCode", ">=", "400", "&&", "$", "errorCode", "<", "600", ")", "{", "$", "code", "=", "$", "errorCode", ";", "}", "return", "$", "code", ";", "}" ]
Get HTTP status code. @param \Exception $exception Exception. @return int A valid HTTP error status code.
[ "Get", "HTTP", "status", "code", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ExceptionRenderer.php#L347-L358
210,948
cakephp/cakephp
src/Error/ExceptionRenderer.php
ExceptionRenderer._outputMessageSafe
protected function _outputMessageSafe($template) { $helpers = ['Form', 'Html']; $this->controller->helpers = $helpers; $builder = $this->controller->viewBuilder(); $builder->setHelpers($helpers, false) ->setLayoutPath('') ->setTemplatePath('Error'); $view = $this->controller->createView('View'); $this->controller->response = $this->controller->response ->withType('html') ->withStringBody($view->render($template, 'error')); return $this->controller->response; }
php
protected function _outputMessageSafe($template) { $helpers = ['Form', 'Html']; $this->controller->helpers = $helpers; $builder = $this->controller->viewBuilder(); $builder->setHelpers($helpers, false) ->setLayoutPath('') ->setTemplatePath('Error'); $view = $this->controller->createView('View'); $this->controller->response = $this->controller->response ->withType('html') ->withStringBody($view->render($template, 'error')); return $this->controller->response; }
[ "protected", "function", "_outputMessageSafe", "(", "$", "template", ")", "{", "$", "helpers", "=", "[", "'Form'", ",", "'Html'", "]", ";", "$", "this", "->", "controller", "->", "helpers", "=", "$", "helpers", ";", "$", "builder", "=", "$", "this", "->", "controller", "->", "viewBuilder", "(", ")", ";", "$", "builder", "->", "setHelpers", "(", "$", "helpers", ",", "false", ")", "->", "setLayoutPath", "(", "''", ")", "->", "setTemplatePath", "(", "'Error'", ")", ";", "$", "view", "=", "$", "this", "->", "controller", "->", "createView", "(", "'View'", ")", ";", "$", "this", "->", "controller", "->", "response", "=", "$", "this", "->", "controller", "->", "response", "->", "withType", "(", "'html'", ")", "->", "withStringBody", "(", "$", "view", "->", "render", "(", "$", "template", ",", "'error'", ")", ")", ";", "return", "$", "this", "->", "controller", "->", "response", ";", "}" ]
A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods. @param string $template The template to render. @return \Cake\Http\Response A response object that can be sent.
[ "A", "safer", "way", "to", "render", "error", "messages", "replaces", "all", "helpers", "with", "basics", "and", "doesn", "t", "call", "component", "methods", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ExceptionRenderer.php#L398-L413
210,949
cakephp/cakephp
src/Error/ExceptionRenderer.php
ExceptionRenderer._shutdown
protected function _shutdown() { $this->controller->dispatchEvent('Controller.shutdown'); $dispatcher = DispatcherFactory::create(); $eventManager = $dispatcher->getEventManager(); foreach ($dispatcher->filters() as $filter) { $eventManager->on($filter); } $args = [ 'request' => $this->controller->request, 'response' => $this->controller->response ]; $result = $dispatcher->dispatchEvent('Dispatcher.afterDispatch', $args); return $result->getData('response'); }
php
protected function _shutdown() { $this->controller->dispatchEvent('Controller.shutdown'); $dispatcher = DispatcherFactory::create(); $eventManager = $dispatcher->getEventManager(); foreach ($dispatcher->filters() as $filter) { $eventManager->on($filter); } $args = [ 'request' => $this->controller->request, 'response' => $this->controller->response ]; $result = $dispatcher->dispatchEvent('Dispatcher.afterDispatch', $args); return $result->getData('response'); }
[ "protected", "function", "_shutdown", "(", ")", "{", "$", "this", "->", "controller", "->", "dispatchEvent", "(", "'Controller.shutdown'", ")", ";", "$", "dispatcher", "=", "DispatcherFactory", "::", "create", "(", ")", ";", "$", "eventManager", "=", "$", "dispatcher", "->", "getEventManager", "(", ")", ";", "foreach", "(", "$", "dispatcher", "->", "filters", "(", ")", "as", "$", "filter", ")", "{", "$", "eventManager", "->", "on", "(", "$", "filter", ")", ";", "}", "$", "args", "=", "[", "'request'", "=>", "$", "this", "->", "controller", "->", "request", ",", "'response'", "=>", "$", "this", "->", "controller", "->", "response", "]", ";", "$", "result", "=", "$", "dispatcher", "->", "dispatchEvent", "(", "'Dispatcher.afterDispatch'", ",", "$", "args", ")", ";", "return", "$", "result", "->", "getData", "(", "'response'", ")", ";", "}" ]
Run the shutdown events. Triggers the afterFilter and afterDispatch events. @return \Cake\Http\Response The response to serve.
[ "Run", "the", "shutdown", "events", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ExceptionRenderer.php#L422-L437
210,950
cakephp/cakephp
src/Mailer/TransportRegistry.php
TransportRegistry._resolveClassName
protected function _resolveClassName($class) { if (is_object($class)) { return $class; } $className = App::className($class, 'Mailer/Transport', 'Transport'); if (!$className) { $className = App::className($class, 'Network/Email', 'Transport'); if ($className) { deprecationWarning( 'Transports in "Network/Email" are deprecated, use "Mailer/Transport" instead.' ); } } return $className; }
php
protected function _resolveClassName($class) { if (is_object($class)) { return $class; } $className = App::className($class, 'Mailer/Transport', 'Transport'); if (!$className) { $className = App::className($class, 'Network/Email', 'Transport'); if ($className) { deprecationWarning( 'Transports in "Network/Email" are deprecated, use "Mailer/Transport" instead.' ); } } return $className; }
[ "protected", "function", "_resolveClassName", "(", "$", "class", ")", "{", "if", "(", "is_object", "(", "$", "class", ")", ")", "{", "return", "$", "class", ";", "}", "$", "className", "=", "App", "::", "className", "(", "$", "class", ",", "'Mailer/Transport'", ",", "'Transport'", ")", ";", "if", "(", "!", "$", "className", ")", "{", "$", "className", "=", "App", "::", "className", "(", "$", "class", ",", "'Network/Email'", ",", "'Transport'", ")", ";", "if", "(", "$", "className", ")", "{", "deprecationWarning", "(", "'Transports in \"Network/Email\" are deprecated, use \"Mailer/Transport\" instead.'", ")", ";", "}", "}", "return", "$", "className", ";", "}" ]
Resolve a mailer tranport classname. Part of the template method for Cake\Core\ObjectRegistry::load() @param string|\Cake\Mailer\AbstractTransport $class Partial classname to resolve or transport instance. @return string|false Either the correct classname or false.
[ "Resolve", "a", "mailer", "tranport", "classname", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/TransportRegistry.php#L35-L53
210,951
cakephp/cakephp
src/Mailer/TransportRegistry.php
TransportRegistry._create
protected function _create($class, $alias, $config) { $instance = null; if (is_object($class)) { $instance = $class; } if (!$instance) { $instance = new $class($config); } if ($instance instanceof AbstractTransport) { return $instance; } throw new RuntimeException( 'Mailer transports must use Cake\Mailer\AbstractTransport as a base class.' ); }
php
protected function _create($class, $alias, $config) { $instance = null; if (is_object($class)) { $instance = $class; } if (!$instance) { $instance = new $class($config); } if ($instance instanceof AbstractTransport) { return $instance; } throw new RuntimeException( 'Mailer transports must use Cake\Mailer\AbstractTransport as a base class.' ); }
[ "protected", "function", "_create", "(", "$", "class", ",", "$", "alias", ",", "$", "config", ")", "{", "$", "instance", "=", "null", ";", "if", "(", "is_object", "(", "$", "class", ")", ")", "{", "$", "instance", "=", "$", "class", ";", "}", "if", "(", "!", "$", "instance", ")", "{", "$", "instance", "=", "new", "$", "class", "(", "$", "config", ")", ";", "}", "if", "(", "$", "instance", "instanceof", "AbstractTransport", ")", "{", "return", "$", "instance", ";", "}", "throw", "new", "RuntimeException", "(", "'Mailer transports must use Cake\\Mailer\\AbstractTransport as a base class.'", ")", ";", "}" ]
Create the mailer transport instance. Part of the template method for Cake\Core\ObjectRegistry::load() @param string|\Cake\Mailer\AbstractTransport $class The classname or object to make. @param string $alias The alias of the object. @param array $config An array of settings to use for the cache engine. @return \Cake\Mailer\AbstractTransport The constructed transport class. @throws \RuntimeException when an object doesn't implement the correct interface.
[ "Create", "the", "mailer", "transport", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/TransportRegistry.php#L81-L100
210,952
cakephp/cakephp
src/ORM/Rule/ExistsIn.php
ExistsIn._fieldsAreNull
protected function _fieldsAreNull($entity, $source) { $nulls = 0; $schema = $source->getSchema(); foreach ($this->_fields as $field) { if ($schema->getColumn($field) && $schema->isNullable($field) && $entity->get($field) === null) { $nulls++; } } return $nulls === count($this->_fields); }
php
protected function _fieldsAreNull($entity, $source) { $nulls = 0; $schema = $source->getSchema(); foreach ($this->_fields as $field) { if ($schema->getColumn($field) && $schema->isNullable($field) && $entity->get($field) === null) { $nulls++; } } return $nulls === count($this->_fields); }
[ "protected", "function", "_fieldsAreNull", "(", "$", "entity", ",", "$", "source", ")", "{", "$", "nulls", "=", "0", ";", "$", "schema", "=", "$", "source", "->", "getSchema", "(", ")", ";", "foreach", "(", "$", "this", "->", "_fields", "as", "$", "field", ")", "{", "if", "(", "$", "schema", "->", "getColumn", "(", "$", "field", ")", "&&", "$", "schema", "->", "isNullable", "(", "$", "field", ")", "&&", "$", "entity", "->", "get", "(", "$", "field", ")", "===", "null", ")", "{", "$", "nulls", "++", ";", "}", "}", "return", "$", "nulls", "===", "count", "(", "$", "this", "->", "_fields", ")", ";", "}" ]
Checks whether or not the given entity fields are nullable and null. @param \Cake\Datasource\EntityInterface $entity The entity to check. @param \Cake\ORM\Table $source The table to use schema from. @return bool
[ "Checks", "whether", "or", "not", "the", "given", "entity", "fields", "are", "nullable", "and", "null", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Rule/ExistsIn.php#L148-L159
210,953
cakephp/cakephp
src/View/Helper.php
Helper._confirm
protected function _confirm($message, $okCode, $cancelCode = '', $options = []) { $message = $this->_cleanConfirmMessage($message); $confirm = "if (confirm({$message})) { {$okCode} } {$cancelCode}"; // We cannot change the key here in 3.x, but the behavior is inverted in this case $escape = isset($options['escape']) && $options['escape'] === false; if ($escape) { /** @var string $confirm */ $confirm = h($confirm); } return $confirm; }
php
protected function _confirm($message, $okCode, $cancelCode = '', $options = []) { $message = $this->_cleanConfirmMessage($message); $confirm = "if (confirm({$message})) { {$okCode} } {$cancelCode}"; // We cannot change the key here in 3.x, but the behavior is inverted in this case $escape = isset($options['escape']) && $options['escape'] === false; if ($escape) { /** @var string $confirm */ $confirm = h($confirm); } return $confirm; }
[ "protected", "function", "_confirm", "(", "$", "message", ",", "$", "okCode", ",", "$", "cancelCode", "=", "''", ",", "$", "options", "=", "[", "]", ")", "{", "$", "message", "=", "$", "this", "->", "_cleanConfirmMessage", "(", "$", "message", ")", ";", "$", "confirm", "=", "\"if (confirm({$message})) { {$okCode} } {$cancelCode}\"", ";", "// We cannot change the key here in 3.x, but the behavior is inverted in this case", "$", "escape", "=", "isset", "(", "$", "options", "[", "'escape'", "]", ")", "&&", "$", "options", "[", "'escape'", "]", "===", "false", ";", "if", "(", "$", "escape", ")", "{", "/** @var string $confirm */", "$", "confirm", "=", "h", "(", "$", "confirm", ")", ";", "}", "return", "$", "confirm", ";", "}" ]
Returns a string to be used as onclick handler for confirm dialogs. @param string $message Message to be displayed @param string $okCode Code to be executed after user chose 'OK' @param string $cancelCode Code to be executed after user chose 'Cancel' @param array $options Array of options @return string onclick JS code
[ "Returns", "a", "string", "to", "be", "used", "as", "onclick", "handler", "for", "confirm", "dialogs", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper.php#L230-L242
210,954
cakephp/cakephp
src/Database/SchemaCache.php
SchemaCache.build
public function build($name = null) { $tables = [$name]; if (empty($name)) { $tables = $this->_schema->listTables(); } foreach ($tables as $table) { $this->_schema->describe($table, ['forceRefresh' => true]); } return $tables; }
php
public function build($name = null) { $tables = [$name]; if (empty($name)) { $tables = $this->_schema->listTables(); } foreach ($tables as $table) { $this->_schema->describe($table, ['forceRefresh' => true]); } return $tables; }
[ "public", "function", "build", "(", "$", "name", "=", "null", ")", "{", "$", "tables", "=", "[", "$", "name", "]", ";", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "$", "tables", "=", "$", "this", "->", "_schema", "->", "listTables", "(", ")", ";", "}", "foreach", "(", "$", "tables", "as", "$", "table", ")", "{", "$", "this", "->", "_schema", "->", "describe", "(", "$", "table", ",", "[", "'forceRefresh'", "=>", "true", "]", ")", ";", "}", "return", "$", "tables", ";", "}" ]
Build metadata. @param string|null $name The name of the table to build cache data for. @return array Returns a list build table caches
[ "Build", "metadata", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/SchemaCache.php#L55-L67
210,955
cakephp/cakephp
src/Database/SchemaCache.php
SchemaCache.getSchema
public function getSchema(Connection $connection) { if (!method_exists($connection, 'schemaCollection')) { throw new RuntimeException('The given connection object is not compatible with schema caching, as it does not implement a "schemaCollection()" method.'); } $config = $connection->config(); if (empty($config['cacheMetadata'])) { $connection->cacheMetadata(true); } return $connection->getSchemaCollection(); }
php
public function getSchema(Connection $connection) { if (!method_exists($connection, 'schemaCollection')) { throw new RuntimeException('The given connection object is not compatible with schema caching, as it does not implement a "schemaCollection()" method.'); } $config = $connection->config(); if (empty($config['cacheMetadata'])) { $connection->cacheMetadata(true); } return $connection->getSchemaCollection(); }
[ "public", "function", "getSchema", "(", "Connection", "$", "connection", ")", "{", "if", "(", "!", "method_exists", "(", "$", "connection", ",", "'schemaCollection'", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'The given connection object is not compatible with schema caching, as it does not implement a \"schemaCollection()\" method.'", ")", ";", "}", "$", "config", "=", "$", "connection", "->", "config", "(", ")", ";", "if", "(", "empty", "(", "$", "config", "[", "'cacheMetadata'", "]", ")", ")", "{", "$", "connection", "->", "cacheMetadata", "(", "true", ")", ";", "}", "return", "$", "connection", "->", "getSchemaCollection", "(", ")", ";", "}" ]
Helper method to get the schema collection. @param \Cake\Database\Connection $connection Connection object @return \Cake\Database\Schema\Collection|\Cake\Database\Schema\CachedCollection @throws \RuntimeException If given connection object is not compatible with schema caching
[ "Helper", "method", "to", "get", "the", "schema", "collection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/SchemaCache.php#L98-L110
210,956
cakephp/cakephp
src/View/Widget/SelectBoxWidget.php
SelectBoxWidget.render
public function render(array $data, ContextInterface $context) { $data += [ 'name' => '', 'empty' => false, 'escape' => true, 'options' => [], 'disabled' => null, 'val' => null, 'templateVars' => [] ]; $options = $this->_renderContent($data); $name = $data['name']; unset($data['name'], $data['options'], $data['empty'], $data['val'], $data['escape']); if (isset($data['disabled']) && is_array($data['disabled'])) { unset($data['disabled']); } $template = 'select'; if (!empty($data['multiple'])) { $template = 'selectMultiple'; unset($data['multiple']); } $attrs = $this->_templates->formatAttributes($data); return $this->_templates->format($template, [ 'name' => $name, 'templateVars' => $data['templateVars'], 'attrs' => $attrs, 'content' => implode('', $options), ]); }
php
public function render(array $data, ContextInterface $context) { $data += [ 'name' => '', 'empty' => false, 'escape' => true, 'options' => [], 'disabled' => null, 'val' => null, 'templateVars' => [] ]; $options = $this->_renderContent($data); $name = $data['name']; unset($data['name'], $data['options'], $data['empty'], $data['val'], $data['escape']); if (isset($data['disabled']) && is_array($data['disabled'])) { unset($data['disabled']); } $template = 'select'; if (!empty($data['multiple'])) { $template = 'selectMultiple'; unset($data['multiple']); } $attrs = $this->_templates->formatAttributes($data); return $this->_templates->format($template, [ 'name' => $name, 'templateVars' => $data['templateVars'], 'attrs' => $attrs, 'content' => implode('', $options), ]); }
[ "public", "function", "render", "(", "array", "$", "data", ",", "ContextInterface", "$", "context", ")", "{", "$", "data", "+=", "[", "'name'", "=>", "''", ",", "'empty'", "=>", "false", ",", "'escape'", "=>", "true", ",", "'options'", "=>", "[", "]", ",", "'disabled'", "=>", "null", ",", "'val'", "=>", "null", ",", "'templateVars'", "=>", "[", "]", "]", ";", "$", "options", "=", "$", "this", "->", "_renderContent", "(", "$", "data", ")", ";", "$", "name", "=", "$", "data", "[", "'name'", "]", ";", "unset", "(", "$", "data", "[", "'name'", "]", ",", "$", "data", "[", "'options'", "]", ",", "$", "data", "[", "'empty'", "]", ",", "$", "data", "[", "'val'", "]", ",", "$", "data", "[", "'escape'", "]", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'disabled'", "]", ")", "&&", "is_array", "(", "$", "data", "[", "'disabled'", "]", ")", ")", "{", "unset", "(", "$", "data", "[", "'disabled'", "]", ")", ";", "}", "$", "template", "=", "'select'", ";", "if", "(", "!", "empty", "(", "$", "data", "[", "'multiple'", "]", ")", ")", "{", "$", "template", "=", "'selectMultiple'", ";", "unset", "(", "$", "data", "[", "'multiple'", "]", ")", ";", "}", "$", "attrs", "=", "$", "this", "->", "_templates", "->", "formatAttributes", "(", "$", "data", ")", ";", "return", "$", "this", "->", "_templates", "->", "format", "(", "$", "template", ",", "[", "'name'", "=>", "$", "name", ",", "'templateVars'", "=>", "$", "data", "[", "'templateVars'", "]", ",", "'attrs'", "=>", "$", "attrs", ",", "'content'", "=>", "implode", "(", "''", ",", "$", "options", ")", ",", "]", ")", ";", "}" ]
Render a select box form input. Render a select box input given a set of data. Supported keys are: - `name` - Set the input name. - `options` - An array of options. - `disabled` - Either true or an array of options to disable. When true, the select element will be disabled. - `val` - Either a string or an array of options to mark as selected. - `empty` - Set to true to add an empty option at the top of the option elements. Set to a string to define the display text of the empty option. If an array is used the key will set the value of the empty option while, the value will set the display text. - `escape` - Set to false to disable HTML escaping. ### Options format The options option can take a variety of data format depending on the complexity of HTML you want generated. You can generate simple options using a basic associative array: ``` 'options' => ['elk' => 'Elk', 'beaver' => 'Beaver'] ``` If you need to define additional attributes on your option elements you can use the complex form for options: ``` 'options' => [ ['value' => 'elk', 'text' => 'Elk', 'data-foo' => 'bar'], ] ``` This form **requires** that both the `value` and `text` keys be defined. If either is not set options will not be generated correctly. If you need to define option groups you can do those using nested arrays: ``` 'options' => [ 'Mammals' => [ 'elk' => 'Elk', 'beaver' => 'Beaver' ] ] ``` And finally, if you need to put attributes on your optgroup elements you can do that with a more complex nested array form: ``` 'options' => [ [ 'text' => 'Mammals', 'data-id' => 1, 'options' => [ 'elk' => 'Elk', 'beaver' => 'Beaver' ] ], ] ``` You are free to mix each of the forms in the same option set, and nest complex types as required. @param array $data Data to render with. @param \Cake\View\Form\ContextInterface $context The current form context. @return string A generated select box. @throws \RuntimeException when the name attribute is empty.
[ "Render", "a", "select", "box", "form", "input", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/SelectBoxWidget.php#L104-L136
210,957
cakephp/cakephp
src/View/Widget/SelectBoxWidget.php
SelectBoxWidget._renderContent
protected function _renderContent($data) { $options = $data['options']; if ($options instanceof Traversable) { $options = iterator_to_array($options); } if (!empty($data['empty'])) { $options = $this->_emptyValue($data['empty']) + (array)$options; } if (empty($options)) { return []; } $selected = isset($data['val']) ? $data['val'] : null; $disabled = null; if (isset($data['disabled']) && is_array($data['disabled'])) { $disabled = $data['disabled']; } $templateVars = $data['templateVars']; return $this->_renderOptions($options, $disabled, $selected, $templateVars, $data['escape']); }
php
protected function _renderContent($data) { $options = $data['options']; if ($options instanceof Traversable) { $options = iterator_to_array($options); } if (!empty($data['empty'])) { $options = $this->_emptyValue($data['empty']) + (array)$options; } if (empty($options)) { return []; } $selected = isset($data['val']) ? $data['val'] : null; $disabled = null; if (isset($data['disabled']) && is_array($data['disabled'])) { $disabled = $data['disabled']; } $templateVars = $data['templateVars']; return $this->_renderOptions($options, $disabled, $selected, $templateVars, $data['escape']); }
[ "protected", "function", "_renderContent", "(", "$", "data", ")", "{", "$", "options", "=", "$", "data", "[", "'options'", "]", ";", "if", "(", "$", "options", "instanceof", "Traversable", ")", "{", "$", "options", "=", "iterator_to_array", "(", "$", "options", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "[", "'empty'", "]", ")", ")", "{", "$", "options", "=", "$", "this", "->", "_emptyValue", "(", "$", "data", "[", "'empty'", "]", ")", "+", "(", "array", ")", "$", "options", ";", "}", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "return", "[", "]", ";", "}", "$", "selected", "=", "isset", "(", "$", "data", "[", "'val'", "]", ")", "?", "$", "data", "[", "'val'", "]", ":", "null", ";", "$", "disabled", "=", "null", ";", "if", "(", "isset", "(", "$", "data", "[", "'disabled'", "]", ")", "&&", "is_array", "(", "$", "data", "[", "'disabled'", "]", ")", ")", "{", "$", "disabled", "=", "$", "data", "[", "'disabled'", "]", ";", "}", "$", "templateVars", "=", "$", "data", "[", "'templateVars'", "]", ";", "return", "$", "this", "->", "_renderOptions", "(", "$", "options", ",", "$", "disabled", ",", "$", "selected", ",", "$", "templateVars", ",", "$", "data", "[", "'escape'", "]", ")", ";", "}" ]
Render the contents of the select element. @param array $data The context for rendering a select. @return array
[ "Render", "the", "contents", "of", "the", "select", "element", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/SelectBoxWidget.php#L144-L167
210,958
cakephp/cakephp
src/View/Widget/SelectBoxWidget.php
SelectBoxWidget._emptyValue
protected function _emptyValue($value) { if ($value === true) { return ['' => '']; } if (is_scalar($value)) { return ['' => $value]; } if (is_array($value)) { return $value; } return []; }
php
protected function _emptyValue($value) { if ($value === true) { return ['' => '']; } if (is_scalar($value)) { return ['' => $value]; } if (is_array($value)) { return $value; } return []; }
[ "protected", "function", "_emptyValue", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "true", ")", "{", "return", "[", "''", "=>", "''", "]", ";", "}", "if", "(", "is_scalar", "(", "$", "value", ")", ")", "{", "return", "[", "''", "=>", "$", "value", "]", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "return", "[", "]", ";", "}" ]
Generate the empty value based on the input. @param string|bool|array $value The provided empty value. @return array The generated option key/value.
[ "Generate", "the", "empty", "value", "based", "on", "the", "input", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/SelectBoxWidget.php#L175-L188
210,959
cakephp/cakephp
src/View/Widget/SelectBoxWidget.php
SelectBoxWidget._renderOptgroup
protected function _renderOptgroup($label, $optgroup, $disabled, $selected, $templateVars, $escape) { $opts = $optgroup; $attrs = []; if (isset($optgroup['options'], $optgroup['text'])) { $opts = $optgroup['options']; $label = $optgroup['text']; $attrs = $optgroup; } $groupOptions = $this->_renderOptions($opts, $disabled, $selected, $templateVars, $escape); return $this->_templates->format('optgroup', [ 'label' => $escape ? h($label) : $label, 'content' => implode('', $groupOptions), 'templateVars' => $templateVars, 'attrs' => $this->_templates->formatAttributes($attrs, ['text', 'options']), ]); }
php
protected function _renderOptgroup($label, $optgroup, $disabled, $selected, $templateVars, $escape) { $opts = $optgroup; $attrs = []; if (isset($optgroup['options'], $optgroup['text'])) { $opts = $optgroup['options']; $label = $optgroup['text']; $attrs = $optgroup; } $groupOptions = $this->_renderOptions($opts, $disabled, $selected, $templateVars, $escape); return $this->_templates->format('optgroup', [ 'label' => $escape ? h($label) : $label, 'content' => implode('', $groupOptions), 'templateVars' => $templateVars, 'attrs' => $this->_templates->formatAttributes($attrs, ['text', 'options']), ]); }
[ "protected", "function", "_renderOptgroup", "(", "$", "label", ",", "$", "optgroup", ",", "$", "disabled", ",", "$", "selected", ",", "$", "templateVars", ",", "$", "escape", ")", "{", "$", "opts", "=", "$", "optgroup", ";", "$", "attrs", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "optgroup", "[", "'options'", "]", ",", "$", "optgroup", "[", "'text'", "]", ")", ")", "{", "$", "opts", "=", "$", "optgroup", "[", "'options'", "]", ";", "$", "label", "=", "$", "optgroup", "[", "'text'", "]", ";", "$", "attrs", "=", "$", "optgroup", ";", "}", "$", "groupOptions", "=", "$", "this", "->", "_renderOptions", "(", "$", "opts", ",", "$", "disabled", ",", "$", "selected", ",", "$", "templateVars", ",", "$", "escape", ")", ";", "return", "$", "this", "->", "_templates", "->", "format", "(", "'optgroup'", ",", "[", "'label'", "=>", "$", "escape", "?", "h", "(", "$", "label", ")", ":", "$", "label", ",", "'content'", "=>", "implode", "(", "''", ",", "$", "groupOptions", ")", ",", "'templateVars'", "=>", "$", "templateVars", ",", "'attrs'", "=>", "$", "this", "->", "_templates", "->", "formatAttributes", "(", "$", "attrs", ",", "[", "'text'", ",", "'options'", "]", ")", ",", "]", ")", ";", "}" ]
Render the contents of an optgroup element. @param string $label The optgroup label text @param array $optgroup The opt group data. @param array|null $disabled The options to disable. @param array|string|null $selected The options to select. @param array $templateVars Additional template variables. @param bool $escape Toggle HTML escaping @return string Formatted template string
[ "Render", "the", "contents", "of", "an", "optgroup", "element", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/SelectBoxWidget.php#L201-L218
210,960
cakephp/cakephp
src/View/Widget/SelectBoxWidget.php
SelectBoxWidget._renderOptions
protected function _renderOptions($options, $disabled, $selected, $templateVars, $escape) { $out = []; foreach ($options as $key => $val) { // Option groups $arrayVal = (is_array($val) || $val instanceof Traversable); if ((!is_int($key) && $arrayVal) || (is_int($key) && $arrayVal && (isset($val['options']) || !isset($val['value']))) ) { $out[] = $this->_renderOptgroup($key, $val, $disabled, $selected, $templateVars, $escape); continue; } // Basic options $optAttrs = [ 'value' => $key, 'text' => $val, 'templateVars' => [], ]; if (is_array($val) && isset($val['text'], $val['value'])) { $optAttrs = $val; $key = $optAttrs['value']; } if (!isset($optAttrs['templateVars'])) { $optAttrs['templateVars'] = []; } if ($this->_isSelected($key, $selected)) { $optAttrs['selected'] = true; } if ($this->_isDisabled($key, $disabled)) { $optAttrs['disabled'] = true; } if (!empty($templateVars)) { $optAttrs['templateVars'] = array_merge($templateVars, $optAttrs['templateVars']); } $optAttrs['escape'] = $escape; $out[] = $this->_templates->format('option', [ 'value' => $escape ? h($optAttrs['value']) : $optAttrs['value'], 'text' => $escape ? h($optAttrs['text']) : $optAttrs['text'], 'templateVars' => $optAttrs['templateVars'], 'attrs' => $this->_templates->formatAttributes($optAttrs, ['text', 'value']), ]); } return $out; }
php
protected function _renderOptions($options, $disabled, $selected, $templateVars, $escape) { $out = []; foreach ($options as $key => $val) { // Option groups $arrayVal = (is_array($val) || $val instanceof Traversable); if ((!is_int($key) && $arrayVal) || (is_int($key) && $arrayVal && (isset($val['options']) || !isset($val['value']))) ) { $out[] = $this->_renderOptgroup($key, $val, $disabled, $selected, $templateVars, $escape); continue; } // Basic options $optAttrs = [ 'value' => $key, 'text' => $val, 'templateVars' => [], ]; if (is_array($val) && isset($val['text'], $val['value'])) { $optAttrs = $val; $key = $optAttrs['value']; } if (!isset($optAttrs['templateVars'])) { $optAttrs['templateVars'] = []; } if ($this->_isSelected($key, $selected)) { $optAttrs['selected'] = true; } if ($this->_isDisabled($key, $disabled)) { $optAttrs['disabled'] = true; } if (!empty($templateVars)) { $optAttrs['templateVars'] = array_merge($templateVars, $optAttrs['templateVars']); } $optAttrs['escape'] = $escape; $out[] = $this->_templates->format('option', [ 'value' => $escape ? h($optAttrs['value']) : $optAttrs['value'], 'text' => $escape ? h($optAttrs['text']) : $optAttrs['text'], 'templateVars' => $optAttrs['templateVars'], 'attrs' => $this->_templates->formatAttributes($optAttrs, ['text', 'value']), ]); } return $out; }
[ "protected", "function", "_renderOptions", "(", "$", "options", ",", "$", "disabled", ",", "$", "selected", ",", "$", "templateVars", ",", "$", "escape", ")", "{", "$", "out", "=", "[", "]", ";", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "val", ")", "{", "// Option groups", "$", "arrayVal", "=", "(", "is_array", "(", "$", "val", ")", "||", "$", "val", "instanceof", "Traversable", ")", ";", "if", "(", "(", "!", "is_int", "(", "$", "key", ")", "&&", "$", "arrayVal", ")", "||", "(", "is_int", "(", "$", "key", ")", "&&", "$", "arrayVal", "&&", "(", "isset", "(", "$", "val", "[", "'options'", "]", ")", "||", "!", "isset", "(", "$", "val", "[", "'value'", "]", ")", ")", ")", ")", "{", "$", "out", "[", "]", "=", "$", "this", "->", "_renderOptgroup", "(", "$", "key", ",", "$", "val", ",", "$", "disabled", ",", "$", "selected", ",", "$", "templateVars", ",", "$", "escape", ")", ";", "continue", ";", "}", "// Basic options", "$", "optAttrs", "=", "[", "'value'", "=>", "$", "key", ",", "'text'", "=>", "$", "val", ",", "'templateVars'", "=>", "[", "]", ",", "]", ";", "if", "(", "is_array", "(", "$", "val", ")", "&&", "isset", "(", "$", "val", "[", "'text'", "]", ",", "$", "val", "[", "'value'", "]", ")", ")", "{", "$", "optAttrs", "=", "$", "val", ";", "$", "key", "=", "$", "optAttrs", "[", "'value'", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "optAttrs", "[", "'templateVars'", "]", ")", ")", "{", "$", "optAttrs", "[", "'templateVars'", "]", "=", "[", "]", ";", "}", "if", "(", "$", "this", "->", "_isSelected", "(", "$", "key", ",", "$", "selected", ")", ")", "{", "$", "optAttrs", "[", "'selected'", "]", "=", "true", ";", "}", "if", "(", "$", "this", "->", "_isDisabled", "(", "$", "key", ",", "$", "disabled", ")", ")", "{", "$", "optAttrs", "[", "'disabled'", "]", "=", "true", ";", "}", "if", "(", "!", "empty", "(", "$", "templateVars", ")", ")", "{", "$", "optAttrs", "[", "'templateVars'", "]", "=", "array_merge", "(", "$", "templateVars", ",", "$", "optAttrs", "[", "'templateVars'", "]", ")", ";", "}", "$", "optAttrs", "[", "'escape'", "]", "=", "$", "escape", ";", "$", "out", "[", "]", "=", "$", "this", "->", "_templates", "->", "format", "(", "'option'", ",", "[", "'value'", "=>", "$", "escape", "?", "h", "(", "$", "optAttrs", "[", "'value'", "]", ")", ":", "$", "optAttrs", "[", "'value'", "]", ",", "'text'", "=>", "$", "escape", "?", "h", "(", "$", "optAttrs", "[", "'text'", "]", ")", ":", "$", "optAttrs", "[", "'text'", "]", ",", "'templateVars'", "=>", "$", "optAttrs", "[", "'templateVars'", "]", ",", "'attrs'", "=>", "$", "this", "->", "_templates", "->", "formatAttributes", "(", "$", "optAttrs", ",", "[", "'text'", ",", "'value'", "]", ")", ",", "]", ")", ";", "}", "return", "$", "out", ";", "}" ]
Render a set of options. Will recursively call itself when option groups are in use. @param array $options The options to render. @param array|null $disabled The options to disable. @param array|string|null $selected The options to select. @param array $templateVars Additional template variables. @param bool $escape Toggle HTML escaping. @return array Option elements.
[ "Render", "a", "set", "of", "options", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/SelectBoxWidget.php#L232-L278
210,961
cakephp/cakephp
src/View/Widget/SelectBoxWidget.php
SelectBoxWidget._isSelected
protected function _isSelected($key, $selected) { if ($selected === null) { return false; } $isArray = is_array($selected); if (!$isArray) { $selected = $selected === false ? '0' : $selected; return (string)$key === (string)$selected; } $strict = !is_numeric($key); return in_array((string)$key, $selected, $strict); }
php
protected function _isSelected($key, $selected) { if ($selected === null) { return false; } $isArray = is_array($selected); if (!$isArray) { $selected = $selected === false ? '0' : $selected; return (string)$key === (string)$selected; } $strict = !is_numeric($key); return in_array((string)$key, $selected, $strict); }
[ "protected", "function", "_isSelected", "(", "$", "key", ",", "$", "selected", ")", "{", "if", "(", "$", "selected", "===", "null", ")", "{", "return", "false", ";", "}", "$", "isArray", "=", "is_array", "(", "$", "selected", ")", ";", "if", "(", "!", "$", "isArray", ")", "{", "$", "selected", "=", "$", "selected", "===", "false", "?", "'0'", ":", "$", "selected", ";", "return", "(", "string", ")", "$", "key", "===", "(", "string", ")", "$", "selected", ";", "}", "$", "strict", "=", "!", "is_numeric", "(", "$", "key", ")", ";", "return", "in_array", "(", "(", "string", ")", "$", "key", ",", "$", "selected", ",", "$", "strict", ")", ";", "}" ]
Helper method for deciding what options are selected. @param string $key The key to test. @param array|string|null $selected The selected values. @return bool
[ "Helper", "method", "for", "deciding", "what", "options", "are", "selected", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/SelectBoxWidget.php#L287-L301
210,962
cakephp/cakephp
src/Database/Type/BinaryUuidType.php
BinaryUuidType.toDatabase
public function toDatabase($value, Driver $driver) { if (is_string($value)) { return $this->convertStringToBinaryUuid($value); } return $value; }
php
public function toDatabase($value, Driver $driver) { if (is_string($value)) { return $this->convertStringToBinaryUuid($value); } return $value; }
[ "public", "function", "toDatabase", "(", "$", "value", ",", "Driver", "$", "driver", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "return", "$", "this", "->", "convertStringToBinaryUuid", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Convert binary uuid data into the database format. Binary data is not altered before being inserted into the database. As PDO will handle reading file handles. @param string|resource $value The value to convert. @param \Cake\Database\Driver $driver The driver instance to convert with. @return string|resource
[ "Convert", "binary", "uuid", "data", "into", "the", "database", "format", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/BinaryUuidType.php#L64-L71
210,963
cakephp/cakephp
src/Database/Type/BinaryUuidType.php
BinaryUuidType.toPHP
public function toPHP($value, Driver $driver) { if ($value === null) { return null; } if (is_string($value)) { return $this->convertBinaryUuidToString($value); } if (is_resource($value)) { return $value; } throw new Exception(sprintf('Unable to convert %s into binary uuid.', gettype($value))); }
php
public function toPHP($value, Driver $driver) { if ($value === null) { return null; } if (is_string($value)) { return $this->convertBinaryUuidToString($value); } if (is_resource($value)) { return $value; } throw new Exception(sprintf('Unable to convert %s into binary uuid.', gettype($value))); }
[ "public", "function", "toPHP", "(", "$", "value", ",", "Driver", "$", "driver", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "null", ";", "}", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "return", "$", "this", "->", "convertBinaryUuidToString", "(", "$", "value", ")", ";", "}", "if", "(", "is_resource", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "throw", "new", "Exception", "(", "sprintf", "(", "'Unable to convert %s into binary uuid.'", ",", "gettype", "(", "$", "value", ")", ")", ")", ";", "}" ]
Convert binary uuid into resource handles @param null|string|resource $value The value to convert. @param \Cake\Database\Driver $driver The driver instance to convert with. @return resource|string|null @throws \Cake\Core\Exception\Exception
[ "Convert", "binary", "uuid", "into", "resource", "handles" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/BinaryUuidType.php#L91-L104
210,964
cakephp/cakephp
src/Database/Schema/BaseSchema.php
BaseSchema._foreignOnClause
protected function _foreignOnClause($on) { if ($on === TableSchema::ACTION_SET_NULL) { return 'SET NULL'; } if ($on === TableSchema::ACTION_SET_DEFAULT) { return 'SET DEFAULT'; } if ($on === TableSchema::ACTION_CASCADE) { return 'CASCADE'; } if ($on === TableSchema::ACTION_RESTRICT) { return 'RESTRICT'; } if ($on === TableSchema::ACTION_NO_ACTION) { return 'NO ACTION'; } }
php
protected function _foreignOnClause($on) { if ($on === TableSchema::ACTION_SET_NULL) { return 'SET NULL'; } if ($on === TableSchema::ACTION_SET_DEFAULT) { return 'SET DEFAULT'; } if ($on === TableSchema::ACTION_CASCADE) { return 'CASCADE'; } if ($on === TableSchema::ACTION_RESTRICT) { return 'RESTRICT'; } if ($on === TableSchema::ACTION_NO_ACTION) { return 'NO ACTION'; } }
[ "protected", "function", "_foreignOnClause", "(", "$", "on", ")", "{", "if", "(", "$", "on", "===", "TableSchema", "::", "ACTION_SET_NULL", ")", "{", "return", "'SET NULL'", ";", "}", "if", "(", "$", "on", "===", "TableSchema", "::", "ACTION_SET_DEFAULT", ")", "{", "return", "'SET DEFAULT'", ";", "}", "if", "(", "$", "on", "===", "TableSchema", "::", "ACTION_CASCADE", ")", "{", "return", "'CASCADE'", ";", "}", "if", "(", "$", "on", "===", "TableSchema", "::", "ACTION_RESTRICT", ")", "{", "return", "'RESTRICT'", ";", "}", "if", "(", "$", "on", "===", "TableSchema", "::", "ACTION_NO_ACTION", ")", "{", "return", "'NO ACTION'", ";", "}", "}" ]
Generate an ON clause for a foreign key. @param string|null $on The on clause @return string
[ "Generate", "an", "ON", "clause", "for", "a", "foreign", "key", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/BaseSchema.php#L55-L72
210,965
cakephp/cakephp
src/Database/Schema/BaseSchema.php
BaseSchema._convertOnClause
protected function _convertOnClause($clause) { if ($clause === 'CASCADE' || $clause === 'RESTRICT') { return strtolower($clause); } if ($clause === 'NO ACTION') { return TableSchema::ACTION_NO_ACTION; } return TableSchema::ACTION_SET_NULL; }
php
protected function _convertOnClause($clause) { if ($clause === 'CASCADE' || $clause === 'RESTRICT') { return strtolower($clause); } if ($clause === 'NO ACTION') { return TableSchema::ACTION_NO_ACTION; } return TableSchema::ACTION_SET_NULL; }
[ "protected", "function", "_convertOnClause", "(", "$", "clause", ")", "{", "if", "(", "$", "clause", "===", "'CASCADE'", "||", "$", "clause", "===", "'RESTRICT'", ")", "{", "return", "strtolower", "(", "$", "clause", ")", ";", "}", "if", "(", "$", "clause", "===", "'NO ACTION'", ")", "{", "return", "TableSchema", "::", "ACTION_NO_ACTION", ";", "}", "return", "TableSchema", "::", "ACTION_SET_NULL", ";", "}" ]
Convert string on clauses to the abstract ones. @param string $clause The on clause to convert. @return string|null
[ "Convert", "string", "on", "clauses", "to", "the", "abstract", "ones", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/BaseSchema.php#L80-L90
210,966
cakephp/cakephp
src/Database/Schema/BaseSchema.php
BaseSchema._convertConstraintColumns
protected function _convertConstraintColumns($references) { if (is_string($references)) { return $this->_driver->quoteIdentifier($references); } return implode(', ', array_map( [$this->_driver, 'quoteIdentifier'], $references )); }
php
protected function _convertConstraintColumns($references) { if (is_string($references)) { return $this->_driver->quoteIdentifier($references); } return implode(', ', array_map( [$this->_driver, 'quoteIdentifier'], $references )); }
[ "protected", "function", "_convertConstraintColumns", "(", "$", "references", ")", "{", "if", "(", "is_string", "(", "$", "references", ")", ")", "{", "return", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "references", ")", ";", "}", "return", "implode", "(", "', '", ",", "array_map", "(", "[", "$", "this", "->", "_driver", ",", "'quoteIdentifier'", "]", ",", "$", "references", ")", ")", ";", "}" ]
Convert foreign key constraints references to a valid stringified list @param string|array $references The referenced columns of a foreign key constraint statement @return string
[ "Convert", "foreign", "key", "constraints", "references", "to", "a", "valid", "stringified", "list" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/BaseSchema.php#L99-L109
210,967
cakephp/cakephp
src/Database/Schema/BaseSchema.php
BaseSchema.dropTableSql
public function dropTableSql(TableSchema $schema) { $sql = sprintf( 'DROP TABLE %s', $this->_driver->quoteIdentifier($schema->name()) ); return [$sql]; }
php
public function dropTableSql(TableSchema $schema) { $sql = sprintf( 'DROP TABLE %s', $this->_driver->quoteIdentifier($schema->name()) ); return [$sql]; }
[ "public", "function", "dropTableSql", "(", "TableSchema", "$", "schema", ")", "{", "$", "sql", "=", "sprintf", "(", "'DROP TABLE %s'", ",", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "schema", "->", "name", "(", ")", ")", ")", ";", "return", "[", "$", "sql", "]", ";", "}" ]
Generate the SQL to drop a table. @param \Cake\Database\Schema\TableSchema $schema Schema instance @return array SQL statements to drop a table.
[ "Generate", "the", "SQL", "to", "drop", "a", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/BaseSchema.php#L117-L125
210,968
cakephp/cakephp
src/Datasource/RulesChecker.php
RulesChecker.add
public function add(callable $rule, $name = null, array $options = []) { $this->_rules[] = $this->_addError($rule, $name, $options); return $this; }
php
public function add(callable $rule, $name = null, array $options = []) { $this->_rules[] = $this->_addError($rule, $name, $options); return $this; }
[ "public", "function", "add", "(", "callable", "$", "rule", ",", "$", "name", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "_rules", "[", "]", "=", "$", "this", "->", "_addError", "(", "$", "rule", ",", "$", "name", ",", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Adds a rule that will be applied to the entity both on create and update operations. ### Options The options array accept the following special keys: - `errorField`: The name of the entity field that will be marked as invalid if the rule does not pass. - `message`: The error message to set to `errorField` if the rule does not pass. @param callable $rule A callable function or object that will return whether the entity is valid or not. @param string|null $name The alias for a rule. @param array $options List of extra options to pass to the rule callable as second argument. @return $this
[ "Adds", "a", "rule", "that", "will", "be", "applied", "to", "the", "entity", "both", "on", "create", "and", "update", "operations", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesChecker.php#L135-L140
210,969
cakephp/cakephp
src/Datasource/RulesChecker.php
RulesChecker.addCreate
public function addCreate(callable $rule, $name = null, array $options = []) { $this->_createRules[] = $this->_addError($rule, $name, $options); return $this; }
php
public function addCreate(callable $rule, $name = null, array $options = []) { $this->_createRules[] = $this->_addError($rule, $name, $options); return $this; }
[ "public", "function", "addCreate", "(", "callable", "$", "rule", ",", "$", "name", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "_createRules", "[", "]", "=", "$", "this", "->", "_addError", "(", "$", "rule", ",", "$", "name", ",", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Adds a rule that will be applied to the entity on create operations. ### Options The options array accept the following special keys: - `errorField`: The name of the entity field that will be marked as invalid if the rule does not pass. - `message`: The error message to set to `errorField` if the rule does not pass. @param callable $rule A callable function or object that will return whether the entity is valid or not. @param string|null $name The alias for a rule. @param array $options List of extra options to pass to the rule callable as second argument. @return $this
[ "Adds", "a", "rule", "that", "will", "be", "applied", "to", "the", "entity", "on", "create", "operations", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesChecker.php#L160-L165
210,970
cakephp/cakephp
src/Datasource/RulesChecker.php
RulesChecker.addUpdate
public function addUpdate(callable $rule, $name = null, array $options = []) { $this->_updateRules[] = $this->_addError($rule, $name, $options); return $this; }
php
public function addUpdate(callable $rule, $name = null, array $options = []) { $this->_updateRules[] = $this->_addError($rule, $name, $options); return $this; }
[ "public", "function", "addUpdate", "(", "callable", "$", "rule", ",", "$", "name", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "_updateRules", "[", "]", "=", "$", "this", "->", "_addError", "(", "$", "rule", ",", "$", "name", ",", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Adds a rule that will be applied to the entity on update operations. ### Options The options array accept the following special keys: - `errorField`: The name of the entity field that will be marked as invalid if the rule does not pass. - `message`: The error message to set to `errorField` if the rule does not pass. @param callable $rule A callable function or object that will return whether the entity is valid or not. @param string|null $name The alias for a rule. @param array $options List of extra options to pass to the rule callable as second argument. @return $this
[ "Adds", "a", "rule", "that", "will", "be", "applied", "to", "the", "entity", "on", "update", "operations", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesChecker.php#L185-L190
210,971
cakephp/cakephp
src/Datasource/RulesChecker.php
RulesChecker.addDelete
public function addDelete(callable $rule, $name = null, array $options = []) { $this->_deleteRules[] = $this->_addError($rule, $name, $options); return $this; }
php
public function addDelete(callable $rule, $name = null, array $options = []) { $this->_deleteRules[] = $this->_addError($rule, $name, $options); return $this; }
[ "public", "function", "addDelete", "(", "callable", "$", "rule", ",", "$", "name", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "_deleteRules", "[", "]", "=", "$", "this", "->", "_addError", "(", "$", "rule", ",", "$", "name", ",", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Adds a rule that will be applied to the entity on delete operations. ### Options The options array accept the following special keys: - `errorField`: The name of the entity field that will be marked as invalid if the rule does not pass. - `message`: The error message to set to `errorField` if the rule does not pass. @param callable $rule A callable function or object that will return whether the entity is valid or not. @param string|null $name The alias for a rule. @param array $options List of extra options to pass to the rule callable as second argument. @return $this
[ "Adds", "a", "rule", "that", "will", "be", "applied", "to", "the", "entity", "on", "delete", "operations", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesChecker.php#L210-L215
210,972
cakephp/cakephp
src/Datasource/RulesChecker.php
RulesChecker.checkCreate
public function checkCreate(EntityInterface $entity, array $options = []) { return $this->_checkRules($entity, $options, array_merge($this->_rules, $this->_createRules)); }
php
public function checkCreate(EntityInterface $entity, array $options = []) { return $this->_checkRules($entity, $options, array_merge($this->_rules, $this->_createRules)); }
[ "public", "function", "checkCreate", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "_checkRules", "(", "$", "entity", ",", "$", "options", ",", "array_merge", "(", "$", "this", "->", "_rules", ",", "$", "this", "->", "_createRules", ")", ")", ";", "}" ]
Runs each of the rules by passing the provided entity and returns true if all of them pass. The rules selected will be only those specified to be run on 'create' @param \Cake\Datasource\EntityInterface $entity The entity to check for validity. @param array $options Extra options to pass to checker functions. @return bool
[ "Runs", "each", "of", "the", "rules", "by", "passing", "the", "provided", "entity", "and", "returns", "true", "if", "all", "of", "them", "pass", ".", "The", "rules", "selected", "will", "be", "only", "those", "specified", "to", "be", "run", "on", "create" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesChecker.php#L253-L256
210,973
cakephp/cakephp
src/Datasource/RulesChecker.php
RulesChecker.checkUpdate
public function checkUpdate(EntityInterface $entity, array $options = []) { return $this->_checkRules($entity, $options, array_merge($this->_rules, $this->_updateRules)); }
php
public function checkUpdate(EntityInterface $entity, array $options = []) { return $this->_checkRules($entity, $options, array_merge($this->_rules, $this->_updateRules)); }
[ "public", "function", "checkUpdate", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "_checkRules", "(", "$", "entity", ",", "$", "options", ",", "array_merge", "(", "$", "this", "->", "_rules", ",", "$", "this", "->", "_updateRules", ")", ")", ";", "}" ]
Runs each of the rules by passing the provided entity and returns true if all of them pass. The rules selected will be only those specified to be run on 'update' @param \Cake\Datasource\EntityInterface $entity The entity to check for validity. @param array $options Extra options to pass to checker functions. @return bool
[ "Runs", "each", "of", "the", "rules", "by", "passing", "the", "provided", "entity", "and", "returns", "true", "if", "all", "of", "them", "pass", ".", "The", "rules", "selected", "will", "be", "only", "those", "specified", "to", "be", "run", "on", "update" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesChecker.php#L266-L269
210,974
cakephp/cakephp
src/Datasource/RulesChecker.php
RulesChecker.checkDelete
public function checkDelete(EntityInterface $entity, array $options = []) { return $this->_checkRules($entity, $options, $this->_deleteRules); }
php
public function checkDelete(EntityInterface $entity, array $options = []) { return $this->_checkRules($entity, $options, $this->_deleteRules); }
[ "public", "function", "checkDelete", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "_checkRules", "(", "$", "entity", ",", "$", "options", ",", "$", "this", "->", "_deleteRules", ")", ";", "}" ]
Runs each of the rules by passing the provided entity and returns true if all of them pass. The rules selected will be only those specified to be run on 'delete' @param \Cake\Datasource\EntityInterface $entity The entity to check for validity. @param array $options Extra options to pass to checker functions. @return bool
[ "Runs", "each", "of", "the", "rules", "by", "passing", "the", "provided", "entity", "and", "returns", "true", "if", "all", "of", "them", "pass", ".", "The", "rules", "selected", "will", "be", "only", "those", "specified", "to", "be", "run", "on", "delete" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesChecker.php#L279-L282
210,975
cakephp/cakephp
src/Datasource/RulesChecker.php
RulesChecker._checkRules
protected function _checkRules(EntityInterface $entity, array $options = [], array $rules = []) { $success = true; $options += $this->_options; foreach ($rules as $rule) { $success = $rule($entity, $options) && $success; } return $success; }
php
protected function _checkRules(EntityInterface $entity, array $options = [], array $rules = []) { $success = true; $options += $this->_options; foreach ($rules as $rule) { $success = $rule($entity, $options) && $success; } return $success; }
[ "protected", "function", "_checkRules", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ",", "array", "$", "rules", "=", "[", "]", ")", "{", "$", "success", "=", "true", ";", "$", "options", "+=", "$", "this", "->", "_options", ";", "foreach", "(", "$", "rules", "as", "$", "rule", ")", "{", "$", "success", "=", "$", "rule", "(", "$", "entity", ",", "$", "options", ")", "&&", "$", "success", ";", "}", "return", "$", "success", ";", "}" ]
Used by top level functions checkDelete, checkCreate and checkUpdate, this function iterates an array containing the rules to be checked and checks them all. @param \Cake\Datasource\EntityInterface $entity The entity to check for validity. @param array $options Extra options to pass to checker functions. @param array $rules The list of rules that must be checked. @return bool
[ "Used", "by", "top", "level", "functions", "checkDelete", "checkCreate", "and", "checkUpdate", "this", "function", "iterates", "an", "array", "containing", "the", "rules", "to", "be", "checked", "and", "checks", "them", "all", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesChecker.php#L293-L302
210,976
cakephp/cakephp
src/Datasource/RulesChecker.php
RulesChecker._addError
protected function _addError($rule, $name, $options) { if (is_array($name)) { $options = $name; $name = null; } if (!($rule instanceof RuleInvoker)) { $rule = new RuleInvoker($rule, $name, $options); } else { $rule->setOptions($options)->setName($name); } return $rule; }
php
protected function _addError($rule, $name, $options) { if (is_array($name)) { $options = $name; $name = null; } if (!($rule instanceof RuleInvoker)) { $rule = new RuleInvoker($rule, $name, $options); } else { $rule->setOptions($options)->setName($name); } return $rule; }
[ "protected", "function", "_addError", "(", "$", "rule", ",", "$", "name", ",", "$", "options", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "$", "options", "=", "$", "name", ";", "$", "name", "=", "null", ";", "}", "if", "(", "!", "(", "$", "rule", "instanceof", "RuleInvoker", ")", ")", "{", "$", "rule", "=", "new", "RuleInvoker", "(", "$", "rule", ",", "$", "name", ",", "$", "options", ")", ";", "}", "else", "{", "$", "rule", "->", "setOptions", "(", "$", "options", ")", "->", "setName", "(", "$", "name", ")", ";", "}", "return", "$", "rule", ";", "}" ]
Utility method for decorating any callable so that if it returns false, the correct property in the entity is marked as invalid. @param callable $rule The rule to decorate @param string $name The alias for a rule. @param array $options The options containing the error message and field. @return callable
[ "Utility", "method", "for", "decorating", "any", "callable", "so", "that", "if", "it", "returns", "false", "the", "correct", "property", "in", "the", "entity", "is", "marked", "as", "invalid", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesChecker.php#L313-L327
210,977
cakephp/cakephp
src/Validation/ValidationRule.php
ValidationRule.process
public function process($value, array $providers, array $context = []) { $context += ['data' => [], 'newRecord' => true, 'providers' => $providers]; if ($this->_skip($context)) { return true; } if (!is_string($this->_rule) && is_callable($this->_rule)) { $callable = $this->_rule; $isCallable = true; } else { $provider = $providers[$this->_provider]; $callable = [$provider, $this->_rule]; $isCallable = is_callable($callable); } if (!$isCallable) { $message = 'Unable to call method "%s" in "%s" provider for field "%s"'; throw new InvalidArgumentException( sprintf($message, $this->_rule, $this->_provider, $context['field']) ); } if ($this->_pass) { $args = array_values(array_merge([$value], $this->_pass, [$context])); $result = $callable(...$args); } else { $result = $callable($value, $context); } if ($result === false) { return $this->_message ?: false; } return $result; }
php
public function process($value, array $providers, array $context = []) { $context += ['data' => [], 'newRecord' => true, 'providers' => $providers]; if ($this->_skip($context)) { return true; } if (!is_string($this->_rule) && is_callable($this->_rule)) { $callable = $this->_rule; $isCallable = true; } else { $provider = $providers[$this->_provider]; $callable = [$provider, $this->_rule]; $isCallable = is_callable($callable); } if (!$isCallable) { $message = 'Unable to call method "%s" in "%s" provider for field "%s"'; throw new InvalidArgumentException( sprintf($message, $this->_rule, $this->_provider, $context['field']) ); } if ($this->_pass) { $args = array_values(array_merge([$value], $this->_pass, [$context])); $result = $callable(...$args); } else { $result = $callable($value, $context); } if ($result === false) { return $this->_message ?: false; } return $result; }
[ "public", "function", "process", "(", "$", "value", ",", "array", "$", "providers", ",", "array", "$", "context", "=", "[", "]", ")", "{", "$", "context", "+=", "[", "'data'", "=>", "[", "]", ",", "'newRecord'", "=>", "true", ",", "'providers'", "=>", "$", "providers", "]", ";", "if", "(", "$", "this", "->", "_skip", "(", "$", "context", ")", ")", "{", "return", "true", ";", "}", "if", "(", "!", "is_string", "(", "$", "this", "->", "_rule", ")", "&&", "is_callable", "(", "$", "this", "->", "_rule", ")", ")", "{", "$", "callable", "=", "$", "this", "->", "_rule", ";", "$", "isCallable", "=", "true", ";", "}", "else", "{", "$", "provider", "=", "$", "providers", "[", "$", "this", "->", "_provider", "]", ";", "$", "callable", "=", "[", "$", "provider", ",", "$", "this", "->", "_rule", "]", ";", "$", "isCallable", "=", "is_callable", "(", "$", "callable", ")", ";", "}", "if", "(", "!", "$", "isCallable", ")", "{", "$", "message", "=", "'Unable to call method \"%s\" in \"%s\" provider for field \"%s\"'", ";", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "message", ",", "$", "this", "->", "_rule", ",", "$", "this", "->", "_provider", ",", "$", "context", "[", "'field'", "]", ")", ")", ";", "}", "if", "(", "$", "this", "->", "_pass", ")", "{", "$", "args", "=", "array_values", "(", "array_merge", "(", "[", "$", "value", "]", ",", "$", "this", "->", "_pass", ",", "[", "$", "context", "]", ")", ")", ";", "$", "result", "=", "$", "callable", "(", "...", "$", "args", ")", ";", "}", "else", "{", "$", "result", "=", "$", "callable", "(", "$", "value", ",", "$", "context", ")", ";", "}", "if", "(", "$", "result", "===", "false", ")", "{", "return", "$", "this", "->", "_message", "?", ":", "false", ";", "}", "return", "$", "result", ";", "}" ]
Dispatches the validation rule to the given validator method and returns a boolean indicating whether the rule passed or not. If a string is returned it is assumed that the rule failed and the error message was given as a result. @param mixed $value The data to validate @param array $providers associative array with objects or class names that will be passed as the last argument for the validation method @param array $context A key value list of data that could be used as context during validation. Recognized keys are: - newRecord: (boolean) whether or not the data to be validated belongs to a new record - data: The full data that was passed to the validation process - field: The name of the field that is being processed @return bool|string @throws \InvalidArgumentException when the supplied rule is not a valid callable for the configured scope
[ "Dispatches", "the", "validation", "rule", "to", "the", "given", "validator", "method", "and", "returns", "a", "boolean", "indicating", "whether", "the", "rule", "passed", "or", "not", ".", "If", "a", "string", "is", "returned", "it", "is", "assumed", "that", "the", "rule", "failed", "and", "the", "error", "message", "was", "given", "as", "a", "result", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/ValidationRule.php#L112-L148
210,978
cakephp/cakephp
src/Validation/ValidationRule.php
ValidationRule._skip
protected function _skip($context) { if (!is_string($this->_on) && is_callable($this->_on)) { $function = $this->_on; return !$function($context); } $newRecord = $context['newRecord']; if (!empty($this->_on)) { if (($this->_on === 'create' && !$newRecord) || ($this->_on === 'update' && $newRecord)) { return true; } } return false; }
php
protected function _skip($context) { if (!is_string($this->_on) && is_callable($this->_on)) { $function = $this->_on; return !$function($context); } $newRecord = $context['newRecord']; if (!empty($this->_on)) { if (($this->_on === 'create' && !$newRecord) || ($this->_on === 'update' && $newRecord)) { return true; } } return false; }
[ "protected", "function", "_skip", "(", "$", "context", ")", "{", "if", "(", "!", "is_string", "(", "$", "this", "->", "_on", ")", "&&", "is_callable", "(", "$", "this", "->", "_on", ")", ")", "{", "$", "function", "=", "$", "this", "->", "_on", ";", "return", "!", "$", "function", "(", "$", "context", ")", ";", "}", "$", "newRecord", "=", "$", "context", "[", "'newRecord'", "]", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_on", ")", ")", "{", "if", "(", "(", "$", "this", "->", "_on", "===", "'create'", "&&", "!", "$", "newRecord", ")", "||", "(", "$", "this", "->", "_on", "===", "'update'", "&&", "$", "newRecord", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if the validation rule should be skipped @param array $context A key value list of data that could be used as context during validation. Recognized keys are: - newRecord: (boolean) whether or not the data to be validated belongs to a new record - data: The full data that was passed to the validation process - providers associative array with objects or class names that will be passed as the last argument for the validation method @return bool True if the ValidationRule should be skipped
[ "Checks", "if", "the", "validation", "rule", "should", "be", "skipped" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/ValidationRule.php#L162-L178
210,979
cakephp/cakephp
src/Validation/ValidationRule.php
ValidationRule._addValidatorProps
protected function _addValidatorProps($validator = []) { foreach ($validator as $key => $value) { if (!isset($value) || empty($value)) { continue; } if ($key === 'rule' && is_array($value) && !is_callable($value)) { $this->_pass = array_slice($value, 1); $value = array_shift($value); } if (in_array($key, ['rule', 'on', 'message', 'last', 'provider', 'pass'])) { $this->{"_$key"} = $value; } } }
php
protected function _addValidatorProps($validator = []) { foreach ($validator as $key => $value) { if (!isset($value) || empty($value)) { continue; } if ($key === 'rule' && is_array($value) && !is_callable($value)) { $this->_pass = array_slice($value, 1); $value = array_shift($value); } if (in_array($key, ['rule', 'on', 'message', 'last', 'provider', 'pass'])) { $this->{"_$key"} = $value; } } }
[ "protected", "function", "_addValidatorProps", "(", "$", "validator", "=", "[", "]", ")", "{", "foreach", "(", "$", "validator", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "value", ")", "||", "empty", "(", "$", "value", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "key", "===", "'rule'", "&&", "is_array", "(", "$", "value", ")", "&&", "!", "is_callable", "(", "$", "value", ")", ")", "{", "$", "this", "->", "_pass", "=", "array_slice", "(", "$", "value", ",", "1", ")", ";", "$", "value", "=", "array_shift", "(", "$", "value", ")", ";", "}", "if", "(", "in_array", "(", "$", "key", ",", "[", "'rule'", ",", "'on'", ",", "'message'", ",", "'last'", ",", "'provider'", ",", "'pass'", "]", ")", ")", "{", "$", "this", "->", "{", "\"_$key\"", "}", "=", "$", "value", ";", "}", "}", "}" ]
Sets the rule properties from the rule entry in validate @param array $validator [optional] @return void
[ "Sets", "the", "rule", "properties", "from", "the", "rule", "entry", "in", "validate" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/ValidationRule.php#L186-L200
210,980
cakephp/cakephp
src/Collection/Iterator/ZipIterator.php
ZipIterator.current
public function current() { if ($this->_callback === null) { return parent::current(); } return call_user_func_array($this->_callback, parent::current()); }
php
public function current() { if ($this->_callback === null) { return parent::current(); } return call_user_func_array($this->_callback, parent::current()); }
[ "public", "function", "current", "(", ")", "{", "if", "(", "$", "this", "->", "_callback", "===", "null", ")", "{", "return", "parent", "::", "current", "(", ")", ";", "}", "return", "call_user_func_array", "(", "$", "this", "->", "_callback", ",", "parent", "::", "current", "(", ")", ")", ";", "}" ]
Returns the value resulting out of zipping all the elements for all the iterators with the same positional index. @return mixed
[ "Returns", "the", "value", "resulting", "out", "of", "zipping", "all", "the", "elements", "for", "all", "the", "iterators", "with", "the", "same", "positional", "index", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/ZipIterator.php#L92-L99
210,981
cakephp/cakephp
src/Collection/Iterator/ZipIterator.php
ZipIterator.unserialize
public function unserialize($iterators) { parent::__construct(MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC); $this->_iterators = unserialize($iterators); foreach ($this->_iterators as $it) { $this->attachIterator($it); } }
php
public function unserialize($iterators) { parent::__construct(MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC); $this->_iterators = unserialize($iterators); foreach ($this->_iterators as $it) { $this->attachIterator($it); } }
[ "public", "function", "unserialize", "(", "$", "iterators", ")", "{", "parent", "::", "__construct", "(", "MultipleIterator", "::", "MIT_NEED_ALL", "|", "MultipleIterator", "::", "MIT_KEYS_NUMERIC", ")", ";", "$", "this", "->", "_iterators", "=", "unserialize", "(", "$", "iterators", ")", ";", "foreach", "(", "$", "this", "->", "_iterators", "as", "$", "it", ")", "{", "$", "this", "->", "attachIterator", "(", "$", "it", ")", ";", "}", "}" ]
Unserializes the passed string and rebuilds the ZipIterator instance @param string $iterators The serialized iterators @return void
[ "Unserializes", "the", "passed", "string", "and", "rebuilds", "the", "ZipIterator", "instance" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/ZipIterator.php#L118-L125
210,982
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.beforeSave
public function beforeSave(Event $event, EntityInterface $entity) { $isNew = $entity->isNew(); $config = $this->getConfig(); $parent = $entity->get($config['parent']); $primaryKey = $this->_getPrimaryKey(); $dirty = $entity->isDirty($config['parent']); $level = $config['level']; if ($parent && $entity->get($primaryKey) == $parent) { throw new RuntimeException("Cannot set a node's parent as itself"); } if ($isNew && $parent) { $parentNode = $this->_getNode($parent); $edge = $parentNode->get($config['right']); $entity->set($config['left'], $edge); $entity->set($config['right'], $edge + 1); $this->_sync(2, '+', ">= {$edge}"); if ($level) { $entity->set($level, $parentNode[$level] + 1); } return; } if ($isNew && !$parent) { $edge = $this->_getMax(); $entity->set($config['left'], $edge + 1); $entity->set($config['right'], $edge + 2); if ($level) { $entity->set($level, 0); } return; } if (!$isNew && $dirty && $parent) { $this->_setParent($entity, $parent); if ($level) { $parentNode = $this->_getNode($parent); $entity->set($level, $parentNode[$level] + 1); } return; } if (!$isNew && $dirty && !$parent) { $this->_setAsRoot($entity); if ($level) { $entity->set($level, 0); } } }
php
public function beforeSave(Event $event, EntityInterface $entity) { $isNew = $entity->isNew(); $config = $this->getConfig(); $parent = $entity->get($config['parent']); $primaryKey = $this->_getPrimaryKey(); $dirty = $entity->isDirty($config['parent']); $level = $config['level']; if ($parent && $entity->get($primaryKey) == $parent) { throw new RuntimeException("Cannot set a node's parent as itself"); } if ($isNew && $parent) { $parentNode = $this->_getNode($parent); $edge = $parentNode->get($config['right']); $entity->set($config['left'], $edge); $entity->set($config['right'], $edge + 1); $this->_sync(2, '+', ">= {$edge}"); if ($level) { $entity->set($level, $parentNode[$level] + 1); } return; } if ($isNew && !$parent) { $edge = $this->_getMax(); $entity->set($config['left'], $edge + 1); $entity->set($config['right'], $edge + 2); if ($level) { $entity->set($level, 0); } return; } if (!$isNew && $dirty && $parent) { $this->_setParent($entity, $parent); if ($level) { $parentNode = $this->_getNode($parent); $entity->set($level, $parentNode[$level] + 1); } return; } if (!$isNew && $dirty && !$parent) { $this->_setAsRoot($entity); if ($level) { $entity->set($level, 0); } } }
[ "public", "function", "beforeSave", "(", "Event", "$", "event", ",", "EntityInterface", "$", "entity", ")", "{", "$", "isNew", "=", "$", "entity", "->", "isNew", "(", ")", ";", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "parent", "=", "$", "entity", "->", "get", "(", "$", "config", "[", "'parent'", "]", ")", ";", "$", "primaryKey", "=", "$", "this", "->", "_getPrimaryKey", "(", ")", ";", "$", "dirty", "=", "$", "entity", "->", "isDirty", "(", "$", "config", "[", "'parent'", "]", ")", ";", "$", "level", "=", "$", "config", "[", "'level'", "]", ";", "if", "(", "$", "parent", "&&", "$", "entity", "->", "get", "(", "$", "primaryKey", ")", "==", "$", "parent", ")", "{", "throw", "new", "RuntimeException", "(", "\"Cannot set a node's parent as itself\"", ")", ";", "}", "if", "(", "$", "isNew", "&&", "$", "parent", ")", "{", "$", "parentNode", "=", "$", "this", "->", "_getNode", "(", "$", "parent", ")", ";", "$", "edge", "=", "$", "parentNode", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", ";", "$", "entity", "->", "set", "(", "$", "config", "[", "'left'", "]", ",", "$", "edge", ")", ";", "$", "entity", "->", "set", "(", "$", "config", "[", "'right'", "]", ",", "$", "edge", "+", "1", ")", ";", "$", "this", "->", "_sync", "(", "2", ",", "'+'", ",", "\">= {$edge}\"", ")", ";", "if", "(", "$", "level", ")", "{", "$", "entity", "->", "set", "(", "$", "level", ",", "$", "parentNode", "[", "$", "level", "]", "+", "1", ")", ";", "}", "return", ";", "}", "if", "(", "$", "isNew", "&&", "!", "$", "parent", ")", "{", "$", "edge", "=", "$", "this", "->", "_getMax", "(", ")", ";", "$", "entity", "->", "set", "(", "$", "config", "[", "'left'", "]", ",", "$", "edge", "+", "1", ")", ";", "$", "entity", "->", "set", "(", "$", "config", "[", "'right'", "]", ",", "$", "edge", "+", "2", ")", ";", "if", "(", "$", "level", ")", "{", "$", "entity", "->", "set", "(", "$", "level", ",", "0", ")", ";", "}", "return", ";", "}", "if", "(", "!", "$", "isNew", "&&", "$", "dirty", "&&", "$", "parent", ")", "{", "$", "this", "->", "_setParent", "(", "$", "entity", ",", "$", "parent", ")", ";", "if", "(", "$", "level", ")", "{", "$", "parentNode", "=", "$", "this", "->", "_getNode", "(", "$", "parent", ")", ";", "$", "entity", "->", "set", "(", "$", "level", ",", "$", "parentNode", "[", "$", "level", "]", "+", "1", ")", ";", "}", "return", ";", "}", "if", "(", "!", "$", "isNew", "&&", "$", "dirty", "&&", "!", "$", "parent", ")", "{", "$", "this", "->", "_setAsRoot", "(", "$", "entity", ")", ";", "if", "(", "$", "level", ")", "{", "$", "entity", "->", "set", "(", "$", "level", ",", "0", ")", ";", "}", "}", "}" ]
Before save listener. Transparently manages setting the lft and rght fields if the parent field is included in the parameters to be saved. @param \Cake\Event\Event $event The beforeSave event that was fired @param \Cake\Datasource\EntityInterface $entity the entity that is going to be saved @return void @throws \RuntimeException if the parent to set for the node is invalid
[ "Before", "save", "listener", ".", "Transparently", "manages", "setting", "the", "lft", "and", "rght", "fields", "if", "the", "parent", "field", "is", "included", "in", "the", "parameters", "to", "be", "saved", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L97-L154
210,983
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.afterSave
public function afterSave(Event $event, EntityInterface $entity) { if (!$this->_config['level'] || $entity->isNew()) { return; } $this->_setChildrenLevel($entity); }
php
public function afterSave(Event $event, EntityInterface $entity) { if (!$this->_config['level'] || $entity->isNew()) { return; } $this->_setChildrenLevel($entity); }
[ "public", "function", "afterSave", "(", "Event", "$", "event", ",", "EntityInterface", "$", "entity", ")", "{", "if", "(", "!", "$", "this", "->", "_config", "[", "'level'", "]", "||", "$", "entity", "->", "isNew", "(", ")", ")", "{", "return", ";", "}", "$", "this", "->", "_setChildrenLevel", "(", "$", "entity", ")", ";", "}" ]
After save listener. Manages updating level of descendants of currently saved entity. @param \Cake\Event\Event $event The afterSave event that was fired @param \Cake\Datasource\EntityInterface $entity the entity that is going to be saved @return void
[ "After", "save", "listener", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L165-L172
210,984
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior._setChildrenLevel
protected function _setChildrenLevel($entity) { $config = $this->getConfig(); if ($entity->get($config['left']) + 1 === $entity->get($config['right'])) { return; } $primaryKey = $this->_getPrimaryKey(); $primaryKeyValue = $entity->get($primaryKey); $depths = [$primaryKeyValue => $entity->get($config['level'])]; $children = $this->_table->find('children', [ 'for' => $primaryKeyValue, 'fields' => [$this->_getPrimaryKey(), $config['parent'], $config['level']], 'order' => $config['left'], ]); /* @var \Cake\Datasource\EntityInterface $node */ foreach ($children as $node) { $parentIdValue = $node->get($config['parent']); $depth = $depths[$parentIdValue] + 1; $depths[$node->get($primaryKey)] = $depth; $this->_table->updateAll( [$config['level'] => $depth], [$primaryKey => $node->get($primaryKey)] ); } }
php
protected function _setChildrenLevel($entity) { $config = $this->getConfig(); if ($entity->get($config['left']) + 1 === $entity->get($config['right'])) { return; } $primaryKey = $this->_getPrimaryKey(); $primaryKeyValue = $entity->get($primaryKey); $depths = [$primaryKeyValue => $entity->get($config['level'])]; $children = $this->_table->find('children', [ 'for' => $primaryKeyValue, 'fields' => [$this->_getPrimaryKey(), $config['parent'], $config['level']], 'order' => $config['left'], ]); /* @var \Cake\Datasource\EntityInterface $node */ foreach ($children as $node) { $parentIdValue = $node->get($config['parent']); $depth = $depths[$parentIdValue] + 1; $depths[$node->get($primaryKey)] = $depth; $this->_table->updateAll( [$config['level'] => $depth], [$primaryKey => $node->get($primaryKey)] ); } }
[ "protected", "function", "_setChildrenLevel", "(", "$", "entity", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "if", "(", "$", "entity", "->", "get", "(", "$", "config", "[", "'left'", "]", ")", "+", "1", "===", "$", "entity", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", ")", "{", "return", ";", "}", "$", "primaryKey", "=", "$", "this", "->", "_getPrimaryKey", "(", ")", ";", "$", "primaryKeyValue", "=", "$", "entity", "->", "get", "(", "$", "primaryKey", ")", ";", "$", "depths", "=", "[", "$", "primaryKeyValue", "=>", "$", "entity", "->", "get", "(", "$", "config", "[", "'level'", "]", ")", "]", ";", "$", "children", "=", "$", "this", "->", "_table", "->", "find", "(", "'children'", ",", "[", "'for'", "=>", "$", "primaryKeyValue", ",", "'fields'", "=>", "[", "$", "this", "->", "_getPrimaryKey", "(", ")", ",", "$", "config", "[", "'parent'", "]", ",", "$", "config", "[", "'level'", "]", "]", ",", "'order'", "=>", "$", "config", "[", "'left'", "]", ",", "]", ")", ";", "/* @var \\Cake\\Datasource\\EntityInterface $node */", "foreach", "(", "$", "children", "as", "$", "node", ")", "{", "$", "parentIdValue", "=", "$", "node", "->", "get", "(", "$", "config", "[", "'parent'", "]", ")", ";", "$", "depth", "=", "$", "depths", "[", "$", "parentIdValue", "]", "+", "1", ";", "$", "depths", "[", "$", "node", "->", "get", "(", "$", "primaryKey", ")", "]", "=", "$", "depth", ";", "$", "this", "->", "_table", "->", "updateAll", "(", "[", "$", "config", "[", "'level'", "]", "=>", "$", "depth", "]", ",", "[", "$", "primaryKey", "=>", "$", "node", "->", "get", "(", "$", "primaryKey", ")", "]", ")", ";", "}", "}" ]
Set level for descendants. @param \Cake\Datasource\EntityInterface $entity The entity whose descendants need to be updated. @return void
[ "Set", "level", "for", "descendants", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L180-L209
210,985
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.beforeDelete
public function beforeDelete(Event $event, EntityInterface $entity) { $config = $this->getConfig(); $this->_ensureFields($entity); $left = $entity->get($config['left']); $right = $entity->get($config['right']); $diff = $right - $left + 1; if ($diff > 2) { $query = $this->_scope($this->_table->query()) ->delete() ->where(function ($exp) use ($config, $left, $right) { /* @var \Cake\Database\Expression\QueryExpression $exp */ return $exp ->gte($config['leftField'], $left + 1) ->lte($config['leftField'], $right - 1); }); $statement = $query->execute(); $statement->closeCursor(); } $this->_sync($diff, '-', "> {$right}"); }
php
public function beforeDelete(Event $event, EntityInterface $entity) { $config = $this->getConfig(); $this->_ensureFields($entity); $left = $entity->get($config['left']); $right = $entity->get($config['right']); $diff = $right - $left + 1; if ($diff > 2) { $query = $this->_scope($this->_table->query()) ->delete() ->where(function ($exp) use ($config, $left, $right) { /* @var \Cake\Database\Expression\QueryExpression $exp */ return $exp ->gte($config['leftField'], $left + 1) ->lte($config['leftField'], $right - 1); }); $statement = $query->execute(); $statement->closeCursor(); } $this->_sync($diff, '-', "> {$right}"); }
[ "public", "function", "beforeDelete", "(", "Event", "$", "event", ",", "EntityInterface", "$", "entity", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "this", "->", "_ensureFields", "(", "$", "entity", ")", ";", "$", "left", "=", "$", "entity", "->", "get", "(", "$", "config", "[", "'left'", "]", ")", ";", "$", "right", "=", "$", "entity", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", ";", "$", "diff", "=", "$", "right", "-", "$", "left", "+", "1", ";", "if", "(", "$", "diff", ">", "2", ")", "{", "$", "query", "=", "$", "this", "->", "_scope", "(", "$", "this", "->", "_table", "->", "query", "(", ")", ")", "->", "delete", "(", ")", "->", "where", "(", "function", "(", "$", "exp", ")", "use", "(", "$", "config", ",", "$", "left", ",", "$", "right", ")", "{", "/* @var \\Cake\\Database\\Expression\\QueryExpression $exp */", "return", "$", "exp", "->", "gte", "(", "$", "config", "[", "'leftField'", "]", ",", "$", "left", "+", "1", ")", "->", "lte", "(", "$", "config", "[", "'leftField'", "]", ",", "$", "right", "-", "1", ")", ";", "}", ")", ";", "$", "statement", "=", "$", "query", "->", "execute", "(", ")", ";", "$", "statement", "->", "closeCursor", "(", ")", ";", "}", "$", "this", "->", "_sync", "(", "$", "diff", ",", "'-'", ",", "\"> {$right}\"", ")", ";", "}" ]
Also deletes the nodes in the subtree of the entity to be delete @param \Cake\Event\Event $event The beforeDelete event that was fired @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved @return void
[ "Also", "deletes", "the", "nodes", "in", "the", "subtree", "of", "the", "entity", "to", "be", "delete" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L218-L240
210,986
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior._setParent
protected function _setParent($entity, $parent) { $config = $this->getConfig(); $parentNode = $this->_getNode($parent); $this->_ensureFields($entity); $parentLeft = $parentNode->get($config['left']); $parentRight = $parentNode->get($config['right']); $right = $entity->get($config['right']); $left = $entity->get($config['left']); if ($parentLeft > $left && $parentLeft < $right) { throw new RuntimeException(sprintf( 'Cannot use node "%s" as parent for entity "%s"', $parent, $entity->get($this->_getPrimaryKey()) )); } // Values for moving to the left $diff = $right - $left + 1; $targetLeft = $parentRight; $targetRight = $diff + $parentRight - 1; $min = $parentRight; $max = $left - 1; if ($left < $targetLeft) { // Moving to the right $targetLeft = $parentRight - $diff; $targetRight = $parentRight - 1; $min = $right + 1; $max = $parentRight - 1; $diff *= -1; } if ($right - $left > 1) { // Correcting internal subtree $internalLeft = $left + 1; $internalRight = $right - 1; $this->_sync($targetLeft - $left, '+', "BETWEEN {$internalLeft} AND {$internalRight}", true); } $this->_sync($diff, '+', "BETWEEN {$min} AND {$max}"); if ($right - $left > 1) { $this->_unmarkInternalTree(); } // Allocating new position $entity->set($config['left'], $targetLeft); $entity->set($config['right'], $targetRight); }
php
protected function _setParent($entity, $parent) { $config = $this->getConfig(); $parentNode = $this->_getNode($parent); $this->_ensureFields($entity); $parentLeft = $parentNode->get($config['left']); $parentRight = $parentNode->get($config['right']); $right = $entity->get($config['right']); $left = $entity->get($config['left']); if ($parentLeft > $left && $parentLeft < $right) { throw new RuntimeException(sprintf( 'Cannot use node "%s" as parent for entity "%s"', $parent, $entity->get($this->_getPrimaryKey()) )); } // Values for moving to the left $diff = $right - $left + 1; $targetLeft = $parentRight; $targetRight = $diff + $parentRight - 1; $min = $parentRight; $max = $left - 1; if ($left < $targetLeft) { // Moving to the right $targetLeft = $parentRight - $diff; $targetRight = $parentRight - 1; $min = $right + 1; $max = $parentRight - 1; $diff *= -1; } if ($right - $left > 1) { // Correcting internal subtree $internalLeft = $left + 1; $internalRight = $right - 1; $this->_sync($targetLeft - $left, '+', "BETWEEN {$internalLeft} AND {$internalRight}", true); } $this->_sync($diff, '+', "BETWEEN {$min} AND {$max}"); if ($right - $left > 1) { $this->_unmarkInternalTree(); } // Allocating new position $entity->set($config['left'], $targetLeft); $entity->set($config['right'], $targetRight); }
[ "protected", "function", "_setParent", "(", "$", "entity", ",", "$", "parent", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "parentNode", "=", "$", "this", "->", "_getNode", "(", "$", "parent", ")", ";", "$", "this", "->", "_ensureFields", "(", "$", "entity", ")", ";", "$", "parentLeft", "=", "$", "parentNode", "->", "get", "(", "$", "config", "[", "'left'", "]", ")", ";", "$", "parentRight", "=", "$", "parentNode", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", ";", "$", "right", "=", "$", "entity", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", ";", "$", "left", "=", "$", "entity", "->", "get", "(", "$", "config", "[", "'left'", "]", ")", ";", "if", "(", "$", "parentLeft", ">", "$", "left", "&&", "$", "parentLeft", "<", "$", "right", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Cannot use node \"%s\" as parent for entity \"%s\"'", ",", "$", "parent", ",", "$", "entity", "->", "get", "(", "$", "this", "->", "_getPrimaryKey", "(", ")", ")", ")", ")", ";", "}", "// Values for moving to the left", "$", "diff", "=", "$", "right", "-", "$", "left", "+", "1", ";", "$", "targetLeft", "=", "$", "parentRight", ";", "$", "targetRight", "=", "$", "diff", "+", "$", "parentRight", "-", "1", ";", "$", "min", "=", "$", "parentRight", ";", "$", "max", "=", "$", "left", "-", "1", ";", "if", "(", "$", "left", "<", "$", "targetLeft", ")", "{", "// Moving to the right", "$", "targetLeft", "=", "$", "parentRight", "-", "$", "diff", ";", "$", "targetRight", "=", "$", "parentRight", "-", "1", ";", "$", "min", "=", "$", "right", "+", "1", ";", "$", "max", "=", "$", "parentRight", "-", "1", ";", "$", "diff", "*=", "-", "1", ";", "}", "if", "(", "$", "right", "-", "$", "left", ">", "1", ")", "{", "// Correcting internal subtree", "$", "internalLeft", "=", "$", "left", "+", "1", ";", "$", "internalRight", "=", "$", "right", "-", "1", ";", "$", "this", "->", "_sync", "(", "$", "targetLeft", "-", "$", "left", ",", "'+'", ",", "\"BETWEEN {$internalLeft} AND {$internalRight}\"", ",", "true", ")", ";", "}", "$", "this", "->", "_sync", "(", "$", "diff", ",", "'+'", ",", "\"BETWEEN {$min} AND {$max}\"", ")", ";", "if", "(", "$", "right", "-", "$", "left", ">", "1", ")", "{", "$", "this", "->", "_unmarkInternalTree", "(", ")", ";", "}", "// Allocating new position", "$", "entity", "->", "set", "(", "$", "config", "[", "'left'", "]", ",", "$", "targetLeft", ")", ";", "$", "entity", "->", "set", "(", "$", "config", "[", "'right'", "]", ",", "$", "targetRight", ")", ";", "}" ]
Sets the correct left and right values for the passed entity so it can be updated to a new parent. It also makes the hole in the tree so the node move can be done without corrupting the structure. @param \Cake\Datasource\EntityInterface $entity The entity to re-parent @param mixed $parent the id of the parent to set @return void @throws \RuntimeException if the parent to set to the entity is not valid
[ "Sets", "the", "correct", "left", "and", "right", "values", "for", "the", "passed", "entity", "so", "it", "can", "be", "updated", "to", "a", "new", "parent", ".", "It", "also", "makes", "the", "hole", "in", "the", "tree", "so", "the", "node", "move", "can", "be", "done", "without", "corrupting", "the", "structure", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L252-L302
210,987
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior._setAsRoot
protected function _setAsRoot($entity) { $config = $this->getConfig(); $edge = $this->_getMax(); $this->_ensureFields($entity); $right = $entity->get($config['right']); $left = $entity->get($config['left']); $diff = $right - $left; if ($right - $left > 1) { //Correcting internal subtree $internalLeft = $left + 1; $internalRight = $right - 1; $this->_sync($edge - $diff - $left, '+', "BETWEEN {$internalLeft} AND {$internalRight}", true); } $this->_sync($diff + 1, '-', "BETWEEN {$right} AND {$edge}"); if ($right - $left > 1) { $this->_unmarkInternalTree(); } $entity->set($config['left'], $edge - $diff); $entity->set($config['right'], $edge); }
php
protected function _setAsRoot($entity) { $config = $this->getConfig(); $edge = $this->_getMax(); $this->_ensureFields($entity); $right = $entity->get($config['right']); $left = $entity->get($config['left']); $diff = $right - $left; if ($right - $left > 1) { //Correcting internal subtree $internalLeft = $left + 1; $internalRight = $right - 1; $this->_sync($edge - $diff - $left, '+', "BETWEEN {$internalLeft} AND {$internalRight}", true); } $this->_sync($diff + 1, '-', "BETWEEN {$right} AND {$edge}"); if ($right - $left > 1) { $this->_unmarkInternalTree(); } $entity->set($config['left'], $edge - $diff); $entity->set($config['right'], $edge); }
[ "protected", "function", "_setAsRoot", "(", "$", "entity", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "edge", "=", "$", "this", "->", "_getMax", "(", ")", ";", "$", "this", "->", "_ensureFields", "(", "$", "entity", ")", ";", "$", "right", "=", "$", "entity", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", ";", "$", "left", "=", "$", "entity", "->", "get", "(", "$", "config", "[", "'left'", "]", ")", ";", "$", "diff", "=", "$", "right", "-", "$", "left", ";", "if", "(", "$", "right", "-", "$", "left", ">", "1", ")", "{", "//Correcting internal subtree", "$", "internalLeft", "=", "$", "left", "+", "1", ";", "$", "internalRight", "=", "$", "right", "-", "1", ";", "$", "this", "->", "_sync", "(", "$", "edge", "-", "$", "diff", "-", "$", "left", ",", "'+'", ",", "\"BETWEEN {$internalLeft} AND {$internalRight}\"", ",", "true", ")", ";", "}", "$", "this", "->", "_sync", "(", "$", "diff", "+", "1", ",", "'-'", ",", "\"BETWEEN {$right} AND {$edge}\"", ")", ";", "if", "(", "$", "right", "-", "$", "left", ">", "1", ")", "{", "$", "this", "->", "_unmarkInternalTree", "(", ")", ";", "}", "$", "entity", "->", "set", "(", "$", "config", "[", "'left'", "]", ",", "$", "edge", "-", "$", "diff", ")", ";", "$", "entity", "->", "set", "(", "$", "config", "[", "'right'", "]", ",", "$", "edge", ")", ";", "}" ]
Updates the left and right column for the passed entity so it can be set as a new root in the tree. It also modifies the ordering in the rest of the tree so the structure remains valid @param \Cake\Datasource\EntityInterface $entity The entity to set as a new root @return void
[ "Updates", "the", "left", "and", "right", "column", "for", "the", "passed", "entity", "so", "it", "can", "be", "set", "as", "a", "new", "root", "in", "the", "tree", ".", "It", "also", "modifies", "the", "ordering", "in", "the", "rest", "of", "the", "tree", "so", "the", "structure", "remains", "valid" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L312-L336
210,988
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior._unmarkInternalTree
protected function _unmarkInternalTree() { $config = $this->getConfig(); $this->_table->updateAll( function ($exp) use ($config) { /* @var \Cake\Database\Expression\QueryExpression $exp */ $leftInverse = clone $exp; $leftInverse->setConjunction('*')->add('-1'); $rightInverse = clone $leftInverse; return $exp ->eq($config['leftField'], $leftInverse->add($config['leftField'])) ->eq($config['rightField'], $rightInverse->add($config['rightField'])); }, function ($exp) use ($config) { /* @var \Cake\Database\Expression\QueryExpression $exp */ return $exp->lt($config['leftField'], 0); } ); }
php
protected function _unmarkInternalTree() { $config = $this->getConfig(); $this->_table->updateAll( function ($exp) use ($config) { /* @var \Cake\Database\Expression\QueryExpression $exp */ $leftInverse = clone $exp; $leftInverse->setConjunction('*')->add('-1'); $rightInverse = clone $leftInverse; return $exp ->eq($config['leftField'], $leftInverse->add($config['leftField'])) ->eq($config['rightField'], $rightInverse->add($config['rightField'])); }, function ($exp) use ($config) { /* @var \Cake\Database\Expression\QueryExpression $exp */ return $exp->lt($config['leftField'], 0); } ); }
[ "protected", "function", "_unmarkInternalTree", "(", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "this", "->", "_table", "->", "updateAll", "(", "function", "(", "$", "exp", ")", "use", "(", "$", "config", ")", "{", "/* @var \\Cake\\Database\\Expression\\QueryExpression $exp */", "$", "leftInverse", "=", "clone", "$", "exp", ";", "$", "leftInverse", "->", "setConjunction", "(", "'*'", ")", "->", "add", "(", "'-1'", ")", ";", "$", "rightInverse", "=", "clone", "$", "leftInverse", ";", "return", "$", "exp", "->", "eq", "(", "$", "config", "[", "'leftField'", "]", ",", "$", "leftInverse", "->", "add", "(", "$", "config", "[", "'leftField'", "]", ")", ")", "->", "eq", "(", "$", "config", "[", "'rightField'", "]", ",", "$", "rightInverse", "->", "add", "(", "$", "config", "[", "'rightField'", "]", ")", ")", ";", "}", ",", "function", "(", "$", "exp", ")", "use", "(", "$", "config", ")", "{", "/* @var \\Cake\\Database\\Expression\\QueryExpression $exp */", "return", "$", "exp", "->", "lt", "(", "$", "config", "[", "'leftField'", "]", ",", "0", ")", ";", "}", ")", ";", "}" ]
Helper method used to invert the sign of the left and right columns that are less than 0. They were set to negative values before so their absolute value wouldn't change while performing other tree transformations. @return void
[ "Helper", "method", "used", "to", "invert", "the", "sign", "of", "the", "left", "and", "right", "columns", "that", "are", "less", "than", "0", ".", "They", "were", "set", "to", "negative", "values", "before", "so", "their", "absolute", "value", "wouldn", "t", "change", "while", "performing", "other", "tree", "transformations", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L345-L364
210,989
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.findPath
public function findPath(Query $query, array $options) { if (empty($options['for'])) { throw new InvalidArgumentException("The 'for' key is required for find('path')"); } $config = $this->getConfig(); list($left, $right) = array_map( function ($field) { return $this->_table->aliasField($field); }, [$config['left'], $config['right']] ); $node = $this->_table->get($options['for'], ['fields' => [$left, $right]]); return $this->_scope($query) ->where([ "$left <=" => $node->get($config['left']), "$right >=" => $node->get($config['right']), ]) ->order([$left => 'ASC']); }
php
public function findPath(Query $query, array $options) { if (empty($options['for'])) { throw new InvalidArgumentException("The 'for' key is required for find('path')"); } $config = $this->getConfig(); list($left, $right) = array_map( function ($field) { return $this->_table->aliasField($field); }, [$config['left'], $config['right']] ); $node = $this->_table->get($options['for'], ['fields' => [$left, $right]]); return $this->_scope($query) ->where([ "$left <=" => $node->get($config['left']), "$right >=" => $node->get($config['right']), ]) ->order([$left => 'ASC']); }
[ "public", "function", "findPath", "(", "Query", "$", "query", ",", "array", "$", "options", ")", "{", "if", "(", "empty", "(", "$", "options", "[", "'for'", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The 'for' key is required for find('path')\"", ")", ";", "}", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "list", "(", "$", "left", ",", "$", "right", ")", "=", "array_map", "(", "function", "(", "$", "field", ")", "{", "return", "$", "this", "->", "_table", "->", "aliasField", "(", "$", "field", ")", ";", "}", ",", "[", "$", "config", "[", "'left'", "]", ",", "$", "config", "[", "'right'", "]", "]", ")", ";", "$", "node", "=", "$", "this", "->", "_table", "->", "get", "(", "$", "options", "[", "'for'", "]", ",", "[", "'fields'", "=>", "[", "$", "left", ",", "$", "right", "]", "]", ")", ";", "return", "$", "this", "->", "_scope", "(", "$", "query", ")", "->", "where", "(", "[", "\"$left <=\"", "=>", "$", "node", "->", "get", "(", "$", "config", "[", "'left'", "]", ")", ",", "\"$right >=\"", "=>", "$", "node", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", ",", "]", ")", "->", "order", "(", "[", "$", "left", "=>", "'ASC'", "]", ")", ";", "}" ]
Custom finder method which can be used to return the list of nodes from the root to a specific node in the tree. This custom finder requires that the key 'for' is passed in the options containing the id of the node to get its path for. @param \Cake\ORM\Query $query The constructed query to modify @param array $options the list of options for the query @return \Cake\ORM\Query @throws \InvalidArgumentException If the 'for' key is missing in options
[ "Custom", "finder", "method", "which", "can", "be", "used", "to", "return", "the", "list", "of", "nodes", "from", "the", "root", "to", "a", "specific", "node", "in", "the", "tree", ".", "This", "custom", "finder", "requires", "that", "the", "key", "for", "is", "passed", "in", "the", "options", "containing", "the", "id", "of", "the", "node", "to", "get", "its", "path", "for", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L376-L398
210,990
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.childCount
public function childCount(EntityInterface $node, $direct = false) { $config = $this->getConfig(); $parent = $this->_table->aliasField($config['parent']); if ($direct) { return $this->_scope($this->_table->find()) ->where([$parent => $node->get($this->_getPrimaryKey())]) ->count(); } $this->_ensureFields($node); return ($node->get($config['right']) - $node->get($config['left']) - 1) / 2; }
php
public function childCount(EntityInterface $node, $direct = false) { $config = $this->getConfig(); $parent = $this->_table->aliasField($config['parent']); if ($direct) { return $this->_scope($this->_table->find()) ->where([$parent => $node->get($this->_getPrimaryKey())]) ->count(); } $this->_ensureFields($node); return ($node->get($config['right']) - $node->get($config['left']) - 1) / 2; }
[ "public", "function", "childCount", "(", "EntityInterface", "$", "node", ",", "$", "direct", "=", "false", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "parent", "=", "$", "this", "->", "_table", "->", "aliasField", "(", "$", "config", "[", "'parent'", "]", ")", ";", "if", "(", "$", "direct", ")", "{", "return", "$", "this", "->", "_scope", "(", "$", "this", "->", "_table", "->", "find", "(", ")", ")", "->", "where", "(", "[", "$", "parent", "=>", "$", "node", "->", "get", "(", "$", "this", "->", "_getPrimaryKey", "(", ")", ")", "]", ")", "->", "count", "(", ")", ";", "}", "$", "this", "->", "_ensureFields", "(", "$", "node", ")", ";", "return", "(", "$", "node", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", "-", "$", "node", "->", "get", "(", "$", "config", "[", "'left'", "]", ")", "-", "1", ")", "/", "2", ";", "}" ]
Get the number of children nodes. @param \Cake\Datasource\EntityInterface $node The entity to count children for @param bool $direct whether to count all nodes in the subtree or just direct children @return int Number of children nodes.
[ "Get", "the", "number", "of", "children", "nodes", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L408-L422
210,991
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.findChildren
public function findChildren(Query $query, array $options) { $config = $this->getConfig(); $options += ['for' => null, 'direct' => false]; list($parent, $left, $right) = array_map( function ($field) { return $this->_table->aliasField($field); }, [$config['parent'], $config['left'], $config['right']] ); list($for, $direct) = [$options['for'], $options['direct']]; if (empty($for)) { throw new InvalidArgumentException("The 'for' key is required for find('children')"); } if ($query->clause('order') === null) { $query->order([$left => 'ASC']); } if ($direct) { return $this->_scope($query)->where([$parent => $for]); } $node = $this->_getNode($for); return $this->_scope($query) ->where([ "{$right} <" => $node->get($config['right']), "{$left} >" => $node->get($config['left']), ]); }
php
public function findChildren(Query $query, array $options) { $config = $this->getConfig(); $options += ['for' => null, 'direct' => false]; list($parent, $left, $right) = array_map( function ($field) { return $this->_table->aliasField($field); }, [$config['parent'], $config['left'], $config['right']] ); list($for, $direct) = [$options['for'], $options['direct']]; if (empty($for)) { throw new InvalidArgumentException("The 'for' key is required for find('children')"); } if ($query->clause('order') === null) { $query->order([$left => 'ASC']); } if ($direct) { return $this->_scope($query)->where([$parent => $for]); } $node = $this->_getNode($for); return $this->_scope($query) ->where([ "{$right} <" => $node->get($config['right']), "{$left} >" => $node->get($config['left']), ]); }
[ "public", "function", "findChildren", "(", "Query", "$", "query", ",", "array", "$", "options", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "options", "+=", "[", "'for'", "=>", "null", ",", "'direct'", "=>", "false", "]", ";", "list", "(", "$", "parent", ",", "$", "left", ",", "$", "right", ")", "=", "array_map", "(", "function", "(", "$", "field", ")", "{", "return", "$", "this", "->", "_table", "->", "aliasField", "(", "$", "field", ")", ";", "}", ",", "[", "$", "config", "[", "'parent'", "]", ",", "$", "config", "[", "'left'", "]", ",", "$", "config", "[", "'right'", "]", "]", ")", ";", "list", "(", "$", "for", ",", "$", "direct", ")", "=", "[", "$", "options", "[", "'for'", "]", ",", "$", "options", "[", "'direct'", "]", "]", ";", "if", "(", "empty", "(", "$", "for", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The 'for' key is required for find('children')\"", ")", ";", "}", "if", "(", "$", "query", "->", "clause", "(", "'order'", ")", "===", "null", ")", "{", "$", "query", "->", "order", "(", "[", "$", "left", "=>", "'ASC'", "]", ")", ";", "}", "if", "(", "$", "direct", ")", "{", "return", "$", "this", "->", "_scope", "(", "$", "query", ")", "->", "where", "(", "[", "$", "parent", "=>", "$", "for", "]", ")", ";", "}", "$", "node", "=", "$", "this", "->", "_getNode", "(", "$", "for", ")", ";", "return", "$", "this", "->", "_scope", "(", "$", "query", ")", "->", "where", "(", "[", "\"{$right} <\"", "=>", "$", "node", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", ",", "\"{$left} >\"", "=>", "$", "node", "->", "get", "(", "$", "config", "[", "'left'", "]", ")", ",", "]", ")", ";", "}" ]
Get the children nodes of the current model Available options are: - for: The id of the record to read. - direct: Boolean, whether to return only the direct (true), or all (false) children, defaults to false (all children). If the direct option is set to true, only the direct children are returned (based upon the parent_id field) @param \Cake\ORM\Query $query Query. @param array $options Array of options as described above @return \Cake\ORM\Query @throws \InvalidArgumentException When the 'for' key is not passed in $options
[ "Get", "the", "children", "nodes", "of", "the", "current", "model" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L440-L472
210,992
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.findTreeList
public function findTreeList(Query $query, array $options) { $left = $this->_table->aliasField($this->getConfig('left')); $results = $this->_scope($query) ->find('threaded', [ 'parentField' => $this->getConfig('parent'), 'order' => [$left => 'ASC'], ]); return $this->formatTreeList($results, $options); }
php
public function findTreeList(Query $query, array $options) { $left = $this->_table->aliasField($this->getConfig('left')); $results = $this->_scope($query) ->find('threaded', [ 'parentField' => $this->getConfig('parent'), 'order' => [$left => 'ASC'], ]); return $this->formatTreeList($results, $options); }
[ "public", "function", "findTreeList", "(", "Query", "$", "query", ",", "array", "$", "options", ")", "{", "$", "left", "=", "$", "this", "->", "_table", "->", "aliasField", "(", "$", "this", "->", "getConfig", "(", "'left'", ")", ")", ";", "$", "results", "=", "$", "this", "->", "_scope", "(", "$", "query", ")", "->", "find", "(", "'threaded'", ",", "[", "'parentField'", "=>", "$", "this", "->", "getConfig", "(", "'parent'", ")", ",", "'order'", "=>", "[", "$", "left", "=>", "'ASC'", "]", ",", "]", ")", ";", "return", "$", "this", "->", "formatTreeList", "(", "$", "results", ",", "$", "options", ")", ";", "}" ]
Gets a representation of the elements in the tree as a flat list where the keys are the primary key for the table and the values are the display field for the table. Values are prefixed to visually indicate relative depth in the tree. ### Options - keyPath: A dot separated path to fetch the field to use for the array key, or a closure to return the key out of the provided row. - valuePath: A dot separated path to fetch the field to use for the array value, or a closure to return the value out of the provided row. - spacer: A string to be used as prefix for denoting the depth in the tree for each item @param \Cake\ORM\Query $query Query. @param array $options Array of options as described above. @return \Cake\ORM\Query
[ "Gets", "a", "representation", "of", "the", "elements", "in", "the", "tree", "as", "a", "flat", "list", "where", "the", "keys", "are", "the", "primary", "key", "for", "the", "table", "and", "the", "values", "are", "the", "display", "field", "for", "the", "table", ".", "Values", "are", "prefixed", "to", "visually", "indicate", "relative", "depth", "in", "the", "tree", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L491-L502
210,993
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.formatTreeList
public function formatTreeList(Query $query, array $options = []) { return $query->formatResults(function ($results) use ($options) { /* @var \Cake\Collection\CollectionTrait $results */ $options += [ 'keyPath' => $this->_getPrimaryKey(), 'valuePath' => $this->_table->getDisplayField(), 'spacer' => '_', ]; return $results ->listNested() ->printer($options['valuePath'], $options['keyPath'], $options['spacer']); }); }
php
public function formatTreeList(Query $query, array $options = []) { return $query->formatResults(function ($results) use ($options) { /* @var \Cake\Collection\CollectionTrait $results */ $options += [ 'keyPath' => $this->_getPrimaryKey(), 'valuePath' => $this->_table->getDisplayField(), 'spacer' => '_', ]; return $results ->listNested() ->printer($options['valuePath'], $options['keyPath'], $options['spacer']); }); }
[ "public", "function", "formatTreeList", "(", "Query", "$", "query", ",", "array", "$", "options", "=", "[", "]", ")", "{", "return", "$", "query", "->", "formatResults", "(", "function", "(", "$", "results", ")", "use", "(", "$", "options", ")", "{", "/* @var \\Cake\\Collection\\CollectionTrait $results */", "$", "options", "+=", "[", "'keyPath'", "=>", "$", "this", "->", "_getPrimaryKey", "(", ")", ",", "'valuePath'", "=>", "$", "this", "->", "_table", "->", "getDisplayField", "(", ")", ",", "'spacer'", "=>", "'_'", ",", "]", ";", "return", "$", "results", "->", "listNested", "(", ")", "->", "printer", "(", "$", "options", "[", "'valuePath'", "]", ",", "$", "options", "[", "'keyPath'", "]", ",", "$", "options", "[", "'spacer'", "]", ")", ";", "}", ")", ";", "}" ]
Formats query as a flat list where the keys are the primary key for the table and the values are the display field for the table. Values are prefixed to visually indicate relative depth in the tree. ### Options - keyPath: A dot separated path to the field that will be the result array key, or a closure to return the key from the provided row. - valuePath: A dot separated path to the field that is the array's value, or a closure to return the value from the provided row. - spacer: A string to be used as prefix for denoting the depth in the tree for each item. @param \Cake\ORM\Query $query The query object to format. @param array $options Array of options as described above. @return \Cake\ORM\Query Augmented query.
[ "Formats", "query", "as", "a", "flat", "list", "where", "the", "keys", "are", "the", "primary", "key", "for", "the", "table", "and", "the", "values", "are", "the", "display", "field", "for", "the", "table", ".", "Values", "are", "prefixed", "to", "visually", "indicate", "relative", "depth", "in", "the", "tree", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L521-L535
210,994
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.removeFromTree
public function removeFromTree(EntityInterface $node) { return $this->_table->getConnection()->transactional(function () use ($node) { $this->_ensureFields($node); return $this->_removeFromTree($node); }); }
php
public function removeFromTree(EntityInterface $node) { return $this->_table->getConnection()->transactional(function () use ($node) { $this->_ensureFields($node); return $this->_removeFromTree($node); }); }
[ "public", "function", "removeFromTree", "(", "EntityInterface", "$", "node", ")", "{", "return", "$", "this", "->", "_table", "->", "getConnection", "(", ")", "->", "transactional", "(", "function", "(", ")", "use", "(", "$", "node", ")", "{", "$", "this", "->", "_ensureFields", "(", "$", "node", ")", ";", "return", "$", "this", "->", "_removeFromTree", "(", "$", "node", ")", ";", "}", ")", ";", "}" ]
Removes the current node from the tree, by positioning it as a new root and re-parents all children up one level. Note that the node will not be deleted just moved away from its current position without moving its children with it. @param \Cake\Datasource\EntityInterface $node The node to remove from the tree @return \Cake\Datasource\EntityInterface|false the node after being removed from the tree or false on error
[ "Removes", "the", "current", "node", "from", "the", "tree", "by", "positioning", "it", "as", "a", "new", "root", "and", "re", "-", "parents", "all", "children", "up", "one", "level", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L548-L555
210,995
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior._removeFromTree
protected function _removeFromTree($node) { $config = $this->getConfig(); $left = $node->get($config['left']); $right = $node->get($config['right']); $parent = $node->get($config['parent']); $node->set($config['parent'], null); if ($right - $left == 1) { return $this->_table->save($node); } $primary = $this->_getPrimaryKey(); $this->_table->updateAll( [$config['parent'] => $parent], [$config['parent'] => $node->get($primary)] ); $this->_sync(1, '-', 'BETWEEN ' . ($left + 1) . ' AND ' . ($right - 1)); $this->_sync(2, '-', "> {$right}"); $edge = $this->_getMax(); $node->set($config['left'], $edge + 1); $node->set($config['right'], $edge + 2); $fields = [$config['parent'], $config['left'], $config['right']]; $this->_table->updateAll($node->extract($fields), [$primary => $node->get($primary)]); foreach ($fields as $field) { $node->setDirty($field, false); } return $node; }
php
protected function _removeFromTree($node) { $config = $this->getConfig(); $left = $node->get($config['left']); $right = $node->get($config['right']); $parent = $node->get($config['parent']); $node->set($config['parent'], null); if ($right - $left == 1) { return $this->_table->save($node); } $primary = $this->_getPrimaryKey(); $this->_table->updateAll( [$config['parent'] => $parent], [$config['parent'] => $node->get($primary)] ); $this->_sync(1, '-', 'BETWEEN ' . ($left + 1) . ' AND ' . ($right - 1)); $this->_sync(2, '-', "> {$right}"); $edge = $this->_getMax(); $node->set($config['left'], $edge + 1); $node->set($config['right'], $edge + 2); $fields = [$config['parent'], $config['left'], $config['right']]; $this->_table->updateAll($node->extract($fields), [$primary => $node->get($primary)]); foreach ($fields as $field) { $node->setDirty($field, false); } return $node; }
[ "protected", "function", "_removeFromTree", "(", "$", "node", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "left", "=", "$", "node", "->", "get", "(", "$", "config", "[", "'left'", "]", ")", ";", "$", "right", "=", "$", "node", "->", "get", "(", "$", "config", "[", "'right'", "]", ")", ";", "$", "parent", "=", "$", "node", "->", "get", "(", "$", "config", "[", "'parent'", "]", ")", ";", "$", "node", "->", "set", "(", "$", "config", "[", "'parent'", "]", ",", "null", ")", ";", "if", "(", "$", "right", "-", "$", "left", "==", "1", ")", "{", "return", "$", "this", "->", "_table", "->", "save", "(", "$", "node", ")", ";", "}", "$", "primary", "=", "$", "this", "->", "_getPrimaryKey", "(", ")", ";", "$", "this", "->", "_table", "->", "updateAll", "(", "[", "$", "config", "[", "'parent'", "]", "=>", "$", "parent", "]", ",", "[", "$", "config", "[", "'parent'", "]", "=>", "$", "node", "->", "get", "(", "$", "primary", ")", "]", ")", ";", "$", "this", "->", "_sync", "(", "1", ",", "'-'", ",", "'BETWEEN '", ".", "(", "$", "left", "+", "1", ")", ".", "' AND '", ".", "(", "$", "right", "-", "1", ")", ")", ";", "$", "this", "->", "_sync", "(", "2", ",", "'-'", ",", "\"> {$right}\"", ")", ";", "$", "edge", "=", "$", "this", "->", "_getMax", "(", ")", ";", "$", "node", "->", "set", "(", "$", "config", "[", "'left'", "]", ",", "$", "edge", "+", "1", ")", ";", "$", "node", "->", "set", "(", "$", "config", "[", "'right'", "]", ",", "$", "edge", "+", "2", ")", ";", "$", "fields", "=", "[", "$", "config", "[", "'parent'", "]", ",", "$", "config", "[", "'left'", "]", ",", "$", "config", "[", "'right'", "]", "]", ";", "$", "this", "->", "_table", "->", "updateAll", "(", "$", "node", "->", "extract", "(", "$", "fields", ")", ",", "[", "$", "primary", "=>", "$", "node", "->", "get", "(", "$", "primary", ")", "]", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "node", "->", "setDirty", "(", "$", "field", ",", "false", ")", ";", "}", "return", "$", "node", ";", "}" ]
Helper function containing the actual code for removeFromTree @param \Cake\Datasource\EntityInterface $node The node to remove from the tree @return \Cake\Datasource\EntityInterface|false the node after being removed from the tree or false on error
[ "Helper", "function", "containing", "the", "actual", "code", "for", "removeFromTree" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L564-L596
210,996
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.moveUp
public function moveUp(EntityInterface $node, $number = 1) { if ($number < 1) { return false; } return $this->_table->getConnection()->transactional(function () use ($node, $number) { $this->_ensureFields($node); return $this->_moveUp($node, $number); }); }
php
public function moveUp(EntityInterface $node, $number = 1) { if ($number < 1) { return false; } return $this->_table->getConnection()->transactional(function () use ($node, $number) { $this->_ensureFields($node); return $this->_moveUp($node, $number); }); }
[ "public", "function", "moveUp", "(", "EntityInterface", "$", "node", ",", "$", "number", "=", "1", ")", "{", "if", "(", "$", "number", "<", "1", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "_table", "->", "getConnection", "(", ")", "->", "transactional", "(", "function", "(", ")", "use", "(", "$", "node", ",", "$", "number", ")", "{", "$", "this", "->", "_ensureFields", "(", "$", "node", ")", ";", "return", "$", "this", "->", "_moveUp", "(", "$", "node", ",", "$", "number", ")", ";", "}", ")", ";", "}" ]
Reorders the node without changing its parent. If the node is the first child, or is a top level node with no previous node this method will return false @param \Cake\Datasource\EntityInterface $node The node to move @param int|bool $number How many places to move the node, or true to move to first position @throws \Cake\Datasource\Exception\RecordNotFoundException When node was not found @return \Cake\Datasource\EntityInterface|bool $node The node after being moved or false on failure
[ "Reorders", "the", "node", "without", "changing", "its", "parent", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L609-L620
210,997
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior._moveUp
protected function _moveUp($node, $number) { $config = $this->getConfig(); list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']]; list($nodeParent, $nodeLeft, $nodeRight) = array_values($node->extract([$parent, $left, $right])); $targetNode = null; if ($number !== true) { $targetNode = $this->_scope($this->_table->find()) ->select([$left, $right]) ->where(["$parent IS" => $nodeParent]) ->where(function ($exp) use ($config, $nodeLeft) { /* @var \Cake\Database\Expression\QueryExpression $exp */ return $exp->lt($config['rightField'], $nodeLeft); }) ->orderDesc($config['leftField']) ->offset($number - 1) ->limit(1) ->first(); } if (!$targetNode) { $targetNode = $this->_scope($this->_table->find()) ->select([$left, $right]) ->where(["$parent IS" => $nodeParent]) ->where(function ($exp) use ($config, $nodeLeft) { /* @var \Cake\Database\Expression\QueryExpression $exp */ return $exp->lt($config['rightField'], $nodeLeft); }) ->orderAsc($config['leftField']) ->limit(1) ->first(); if (!$targetNode) { return $node; } } list($targetLeft) = array_values($targetNode->extract([$left, $right])); $edge = $this->_getMax(); $leftBoundary = $targetLeft; $rightBoundary = $nodeLeft - 1; $nodeToEdge = $edge - $nodeLeft + 1; $shift = $nodeRight - $nodeLeft + 1; $nodeToHole = $edge - $leftBoundary + 1; $this->_sync($nodeToEdge, '+', "BETWEEN {$nodeLeft} AND {$nodeRight}"); $this->_sync($shift, '+', "BETWEEN {$leftBoundary} AND {$rightBoundary}"); $this->_sync($nodeToHole, '-', "> {$edge}"); $node->set($left, $targetLeft); $node->set($right, $targetLeft + ($nodeRight - $nodeLeft)); $node->setDirty($left, false); $node->setDirty($right, false); return $node; }
php
protected function _moveUp($node, $number) { $config = $this->getConfig(); list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']]; list($nodeParent, $nodeLeft, $nodeRight) = array_values($node->extract([$parent, $left, $right])); $targetNode = null; if ($number !== true) { $targetNode = $this->_scope($this->_table->find()) ->select([$left, $right]) ->where(["$parent IS" => $nodeParent]) ->where(function ($exp) use ($config, $nodeLeft) { /* @var \Cake\Database\Expression\QueryExpression $exp */ return $exp->lt($config['rightField'], $nodeLeft); }) ->orderDesc($config['leftField']) ->offset($number - 1) ->limit(1) ->first(); } if (!$targetNode) { $targetNode = $this->_scope($this->_table->find()) ->select([$left, $right]) ->where(["$parent IS" => $nodeParent]) ->where(function ($exp) use ($config, $nodeLeft) { /* @var \Cake\Database\Expression\QueryExpression $exp */ return $exp->lt($config['rightField'], $nodeLeft); }) ->orderAsc($config['leftField']) ->limit(1) ->first(); if (!$targetNode) { return $node; } } list($targetLeft) = array_values($targetNode->extract([$left, $right])); $edge = $this->_getMax(); $leftBoundary = $targetLeft; $rightBoundary = $nodeLeft - 1; $nodeToEdge = $edge - $nodeLeft + 1; $shift = $nodeRight - $nodeLeft + 1; $nodeToHole = $edge - $leftBoundary + 1; $this->_sync($nodeToEdge, '+', "BETWEEN {$nodeLeft} AND {$nodeRight}"); $this->_sync($shift, '+', "BETWEEN {$leftBoundary} AND {$rightBoundary}"); $this->_sync($nodeToHole, '-', "> {$edge}"); $node->set($left, $targetLeft); $node->set($right, $targetLeft + ($nodeRight - $nodeLeft)); $node->setDirty($left, false); $node->setDirty($right, false); return $node; }
[ "protected", "function", "_moveUp", "(", "$", "node", ",", "$", "number", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "list", "(", "$", "parent", ",", "$", "left", ",", "$", "right", ")", "=", "[", "$", "config", "[", "'parent'", "]", ",", "$", "config", "[", "'left'", "]", ",", "$", "config", "[", "'right'", "]", "]", ";", "list", "(", "$", "nodeParent", ",", "$", "nodeLeft", ",", "$", "nodeRight", ")", "=", "array_values", "(", "$", "node", "->", "extract", "(", "[", "$", "parent", ",", "$", "left", ",", "$", "right", "]", ")", ")", ";", "$", "targetNode", "=", "null", ";", "if", "(", "$", "number", "!==", "true", ")", "{", "$", "targetNode", "=", "$", "this", "->", "_scope", "(", "$", "this", "->", "_table", "->", "find", "(", ")", ")", "->", "select", "(", "[", "$", "left", ",", "$", "right", "]", ")", "->", "where", "(", "[", "\"$parent IS\"", "=>", "$", "nodeParent", "]", ")", "->", "where", "(", "function", "(", "$", "exp", ")", "use", "(", "$", "config", ",", "$", "nodeLeft", ")", "{", "/* @var \\Cake\\Database\\Expression\\QueryExpression $exp */", "return", "$", "exp", "->", "lt", "(", "$", "config", "[", "'rightField'", "]", ",", "$", "nodeLeft", ")", ";", "}", ")", "->", "orderDesc", "(", "$", "config", "[", "'leftField'", "]", ")", "->", "offset", "(", "$", "number", "-", "1", ")", "->", "limit", "(", "1", ")", "->", "first", "(", ")", ";", "}", "if", "(", "!", "$", "targetNode", ")", "{", "$", "targetNode", "=", "$", "this", "->", "_scope", "(", "$", "this", "->", "_table", "->", "find", "(", ")", ")", "->", "select", "(", "[", "$", "left", ",", "$", "right", "]", ")", "->", "where", "(", "[", "\"$parent IS\"", "=>", "$", "nodeParent", "]", ")", "->", "where", "(", "function", "(", "$", "exp", ")", "use", "(", "$", "config", ",", "$", "nodeLeft", ")", "{", "/* @var \\Cake\\Database\\Expression\\QueryExpression $exp */", "return", "$", "exp", "->", "lt", "(", "$", "config", "[", "'rightField'", "]", ",", "$", "nodeLeft", ")", ";", "}", ")", "->", "orderAsc", "(", "$", "config", "[", "'leftField'", "]", ")", "->", "limit", "(", "1", ")", "->", "first", "(", ")", ";", "if", "(", "!", "$", "targetNode", ")", "{", "return", "$", "node", ";", "}", "}", "list", "(", "$", "targetLeft", ")", "=", "array_values", "(", "$", "targetNode", "->", "extract", "(", "[", "$", "left", ",", "$", "right", "]", ")", ")", ";", "$", "edge", "=", "$", "this", "->", "_getMax", "(", ")", ";", "$", "leftBoundary", "=", "$", "targetLeft", ";", "$", "rightBoundary", "=", "$", "nodeLeft", "-", "1", ";", "$", "nodeToEdge", "=", "$", "edge", "-", "$", "nodeLeft", "+", "1", ";", "$", "shift", "=", "$", "nodeRight", "-", "$", "nodeLeft", "+", "1", ";", "$", "nodeToHole", "=", "$", "edge", "-", "$", "leftBoundary", "+", "1", ";", "$", "this", "->", "_sync", "(", "$", "nodeToEdge", ",", "'+'", ",", "\"BETWEEN {$nodeLeft} AND {$nodeRight}\"", ")", ";", "$", "this", "->", "_sync", "(", "$", "shift", ",", "'+'", ",", "\"BETWEEN {$leftBoundary} AND {$rightBoundary}\"", ")", ";", "$", "this", "->", "_sync", "(", "$", "nodeToHole", ",", "'-'", ",", "\"> {$edge}\"", ")", ";", "$", "node", "->", "set", "(", "$", "left", ",", "$", "targetLeft", ")", ";", "$", "node", "->", "set", "(", "$", "right", ",", "$", "targetLeft", "+", "(", "$", "nodeRight", "-", "$", "nodeLeft", ")", ")", ";", "$", "node", "->", "setDirty", "(", "$", "left", ",", "false", ")", ";", "$", "node", "->", "setDirty", "(", "$", "right", ",", "false", ")", ";", "return", "$", "node", ";", "}" ]
Helper function used with the actual code for moveUp @param \Cake\Datasource\EntityInterface $node The node to move @param int|bool $number How many places to move the node, or true to move to first position @throws \Cake\Datasource\Exception\RecordNotFoundException When node was not found @return \Cake\Datasource\EntityInterface|bool $node The node after being moved or false on failure
[ "Helper", "function", "used", "with", "the", "actual", "code", "for", "moveUp" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L630-L686
210,998
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior.moveDown
public function moveDown(EntityInterface $node, $number = 1) { if ($number < 1) { return false; } return $this->_table->getConnection()->transactional(function () use ($node, $number) { $this->_ensureFields($node); return $this->_moveDown($node, $number); }); }
php
public function moveDown(EntityInterface $node, $number = 1) { if ($number < 1) { return false; } return $this->_table->getConnection()->transactional(function () use ($node, $number) { $this->_ensureFields($node); return $this->_moveDown($node, $number); }); }
[ "public", "function", "moveDown", "(", "EntityInterface", "$", "node", ",", "$", "number", "=", "1", ")", "{", "if", "(", "$", "number", "<", "1", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "_table", "->", "getConnection", "(", ")", "->", "transactional", "(", "function", "(", ")", "use", "(", "$", "node", ",", "$", "number", ")", "{", "$", "this", "->", "_ensureFields", "(", "$", "node", ")", ";", "return", "$", "this", "->", "_moveDown", "(", "$", "node", ",", "$", "number", ")", ";", "}", ")", ";", "}" ]
Reorders the node without changing the parent. If the node is the last child, or is a top level node with no subsequent node this method will return false @param \Cake\Datasource\EntityInterface $node The node to move @param int|bool $number How many places to move the node or true to move to last position @throws \Cake\Datasource\Exception\RecordNotFoundException When node was not found @return \Cake\Datasource\EntityInterface|bool the entity after being moved or false on failure
[ "Reorders", "the", "node", "without", "changing", "the", "parent", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L699-L710
210,999
cakephp/cakephp
src/ORM/Behavior/TreeBehavior.php
TreeBehavior._getNode
protected function _getNode($id) { $config = $this->getConfig(); list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']]; $primaryKey = $this->_getPrimaryKey(); $fields = [$parent, $left, $right]; if ($config['level']) { $fields[] = $config['level']; } $node = $this->_scope($this->_table->find()) ->select($fields) ->where([$this->_table->aliasField($primaryKey) => $id]) ->first(); if (!$node) { throw new RecordNotFoundException("Node \"{$id}\" was not found in the tree."); } return $node; }
php
protected function _getNode($id) { $config = $this->getConfig(); list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']]; $primaryKey = $this->_getPrimaryKey(); $fields = [$parent, $left, $right]; if ($config['level']) { $fields[] = $config['level']; } $node = $this->_scope($this->_table->find()) ->select($fields) ->where([$this->_table->aliasField($primaryKey) => $id]) ->first(); if (!$node) { throw new RecordNotFoundException("Node \"{$id}\" was not found in the tree."); } return $node; }
[ "protected", "function", "_getNode", "(", "$", "id", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "list", "(", "$", "parent", ",", "$", "left", ",", "$", "right", ")", "=", "[", "$", "config", "[", "'parent'", "]", ",", "$", "config", "[", "'left'", "]", ",", "$", "config", "[", "'right'", "]", "]", ";", "$", "primaryKey", "=", "$", "this", "->", "_getPrimaryKey", "(", ")", ";", "$", "fields", "=", "[", "$", "parent", ",", "$", "left", ",", "$", "right", "]", ";", "if", "(", "$", "config", "[", "'level'", "]", ")", "{", "$", "fields", "[", "]", "=", "$", "config", "[", "'level'", "]", ";", "}", "$", "node", "=", "$", "this", "->", "_scope", "(", "$", "this", "->", "_table", "->", "find", "(", ")", ")", "->", "select", "(", "$", "fields", ")", "->", "where", "(", "[", "$", "this", "->", "_table", "->", "aliasField", "(", "$", "primaryKey", ")", "=>", "$", "id", "]", ")", "->", "first", "(", ")", ";", "if", "(", "!", "$", "node", ")", "{", "throw", "new", "RecordNotFoundException", "(", "\"Node \\\"{$id}\\\" was not found in the tree.\"", ")", ";", "}", "return", "$", "node", ";", "}" ]
Returns a single node from the tree from its primary key @param mixed $id Record id. @return \Cake\Datasource\EntityInterface @throws \Cake\Datasource\Exception\RecordNotFoundException When node was not found
[ "Returns", "a", "single", "node", "from", "the", "tree", "from", "its", "primary", "key" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L785-L805