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
211,600
cakephp/cakephp
src/Controller/Controller.php
Controller.loadComponent
public function loadComponent($name, array $config = []) { list(, $prop) = pluginSplit($name); return $this->{$prop} = $this->components()->load($name, $config); }
php
public function loadComponent($name, array $config = []) { list(, $prop) = pluginSplit($name); return $this->{$prop} = $this->components()->load($name, $config); }
[ "public", "function", "loadComponent", "(", "$", "name", ",", "array", "$", "config", "=", "[", "]", ")", "{", "list", "(", ",", "$", "prop", ")", "=", "pluginSplit", "(", "$", "name", ")", ";", "return", "$", "this", "->", "{", "$", "prop", "}", "=", "$", "this", "->", "components", "(", ")", "->", "load", "(", "$", "name", ",", "$", "config", ")", ";", "}" ]
Add a component to the controller's registry. This method will also set the component to a property. For example: ``` $this->loadComponent('Acl.Acl'); ``` Will result in a `Toolbar` property being set. @param string $name The name of the component to load. @param array $config The config for the component. @return \Cake\Controller\Component @throws \Exception
[ "Add", "a", "component", "to", "the", "controller", "s", "registry", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Controller.php#L331-L336
211,601
cakephp/cakephp
src/Controller/Controller.php
Controller._loadComponents
protected function _loadComponents() { if (empty($this->components)) { return; } $registry = $this->components(); $components = $registry->normalizeArray($this->components); foreach ($components as $properties) { $this->loadComponent($properties['class'], $properties['config']); } }
php
protected function _loadComponents() { if (empty($this->components)) { return; } $registry = $this->components(); $components = $registry->normalizeArray($this->components); foreach ($components as $properties) { $this->loadComponent($properties['class'], $properties['config']); } }
[ "protected", "function", "_loadComponents", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "components", ")", ")", "{", "return", ";", "}", "$", "registry", "=", "$", "this", "->", "components", "(", ")", ";", "$", "components", "=", "$", "registry", "->", "normalizeArray", "(", "$", "this", "->", "components", ")", ";", "foreach", "(", "$", "components", "as", "$", "properties", ")", "{", "$", "this", "->", "loadComponent", "(", "$", "properties", "[", "'class'", "]", ",", "$", "properties", "[", "'config'", "]", ")", ";", "}", "}" ]
Loads the defined components using the Component factory. @return void
[ "Loads", "the", "defined", "components", "using", "the", "Component", "factory", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Controller.php#L648-L658
211,602
cakephp/cakephp
src/Controller/Controller.php
Controller.startupProcess
public function startupProcess() { $event = $this->dispatchEvent('Controller.initialize'); if ($event->getResult() instanceof Response) { return $event->getResult(); } $event = $this->dispatchEvent('Controller.startup'); if ($event->getResult() instanceof Response) { return $event->getResult(); } return null; }
php
public function startupProcess() { $event = $this->dispatchEvent('Controller.initialize'); if ($event->getResult() instanceof Response) { return $event->getResult(); } $event = $this->dispatchEvent('Controller.startup'); if ($event->getResult() instanceof Response) { return $event->getResult(); } return null; }
[ "public", "function", "startupProcess", "(", ")", "{", "$", "event", "=", "$", "this", "->", "dispatchEvent", "(", "'Controller.initialize'", ")", ";", "if", "(", "$", "event", "->", "getResult", "(", ")", "instanceof", "Response", ")", "{", "return", "$", "event", "->", "getResult", "(", ")", ";", "}", "$", "event", "=", "$", "this", "->", "dispatchEvent", "(", "'Controller.startup'", ")", ";", "if", "(", "$", "event", "->", "getResult", "(", ")", "instanceof", "Response", ")", "{", "return", "$", "event", "->", "getResult", "(", ")", ";", "}", "return", "null", ";", "}" ]
Perform the startup process for this controller. Fire the Components and Controller callbacks in the correct order. - Initializes components, which fires their `initialize` callback - Calls the controller `beforeFilter`. - triggers Component `startup` methods. @return \Cake\Http\Response|null
[ "Perform", "the", "startup", "process", "for", "this", "controller", ".", "Fire", "the", "Components", "and", "Controller", "callbacks", "in", "the", "correct", "order", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Controller.php#L670-L682
211,603
cakephp/cakephp
src/Controller/Controller.php
Controller.shutdownProcess
public function shutdownProcess() { $event = $this->dispatchEvent('Controller.shutdown'); if ($event->getResult() instanceof Response) { return $event->getResult(); } return null; }
php
public function shutdownProcess() { $event = $this->dispatchEvent('Controller.shutdown'); if ($event->getResult() instanceof Response) { return $event->getResult(); } return null; }
[ "public", "function", "shutdownProcess", "(", ")", "{", "$", "event", "=", "$", "this", "->", "dispatchEvent", "(", "'Controller.shutdown'", ")", ";", "if", "(", "$", "event", "->", "getResult", "(", ")", "instanceof", "Response", ")", "{", "return", "$", "event", "->", "getResult", "(", ")", ";", "}", "return", "null", ";", "}" ]
Perform the various shutdown processes for this controller. Fire the Components and Controller callbacks in the correct order. - triggers the component `shutdown` callback. - calls the Controller's `afterFilter` method. @return \Cake\Http\Response|null
[ "Perform", "the", "various", "shutdown", "processes", "for", "this", "controller", ".", "Fire", "the", "Components", "and", "Controller", "callbacks", "in", "the", "correct", "order", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Controller.php#L693-L701
211,604
cakephp/cakephp
src/Controller/Controller.php
Controller.render
public function render($view = null, $layout = null) { $builder = $this->viewBuilder(); if (!$builder->getTemplatePath()) { $builder->setTemplatePath($this->_viewPath()); } if ($this->request->getParam('bare')) { $builder->disableAutoLayout(); } $this->autoRender = false; $event = $this->dispatchEvent('Controller.beforeRender'); if ($event->getResult() instanceof Response) { return $event->getResult(); } if ($event->isStopped()) { return $this->response; } if ($builder->getTemplate() === null && $this->request->getParam('action')) { $builder->setTemplate($this->request->getParam('action')); } $this->View = $this->createView(); $contents = $this->View->render($view, $layout); $this->setResponse($this->View->getResponse()->withStringBody($contents)); return $this->response; }
php
public function render($view = null, $layout = null) { $builder = $this->viewBuilder(); if (!$builder->getTemplatePath()) { $builder->setTemplatePath($this->_viewPath()); } if ($this->request->getParam('bare')) { $builder->disableAutoLayout(); } $this->autoRender = false; $event = $this->dispatchEvent('Controller.beforeRender'); if ($event->getResult() instanceof Response) { return $event->getResult(); } if ($event->isStopped()) { return $this->response; } if ($builder->getTemplate() === null && $this->request->getParam('action')) { $builder->setTemplate($this->request->getParam('action')); } $this->View = $this->createView(); $contents = $this->View->render($view, $layout); $this->setResponse($this->View->getResponse()->withStringBody($contents)); return $this->response; }
[ "public", "function", "render", "(", "$", "view", "=", "null", ",", "$", "layout", "=", "null", ")", "{", "$", "builder", "=", "$", "this", "->", "viewBuilder", "(", ")", ";", "if", "(", "!", "$", "builder", "->", "getTemplatePath", "(", ")", ")", "{", "$", "builder", "->", "setTemplatePath", "(", "$", "this", "->", "_viewPath", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "request", "->", "getParam", "(", "'bare'", ")", ")", "{", "$", "builder", "->", "disableAutoLayout", "(", ")", ";", "}", "$", "this", "->", "autoRender", "=", "false", ";", "$", "event", "=", "$", "this", "->", "dispatchEvent", "(", "'Controller.beforeRender'", ")", ";", "if", "(", "$", "event", "->", "getResult", "(", ")", "instanceof", "Response", ")", "{", "return", "$", "event", "->", "getResult", "(", ")", ";", "}", "if", "(", "$", "event", "->", "isStopped", "(", ")", ")", "{", "return", "$", "this", "->", "response", ";", "}", "if", "(", "$", "builder", "->", "getTemplate", "(", ")", "===", "null", "&&", "$", "this", "->", "request", "->", "getParam", "(", "'action'", ")", ")", "{", "$", "builder", "->", "setTemplate", "(", "$", "this", "->", "request", "->", "getParam", "(", "'action'", ")", ")", ";", "}", "$", "this", "->", "View", "=", "$", "this", "->", "createView", "(", ")", ";", "$", "contents", "=", "$", "this", "->", "View", "->", "render", "(", "$", "view", ",", "$", "layout", ")", ";", "$", "this", "->", "setResponse", "(", "$", "this", "->", "View", "->", "getResponse", "(", ")", "->", "withStringBody", "(", "$", "contents", ")", ")", ";", "return", "$", "this", "->", "response", ";", "}" ]
Instantiates the correct view class, hands it its data, and uses it to render the view output. @param string|null $view View to use for rendering @param string|null $layout Layout to use @return \Cake\Http\Response A response object containing the rendered view. @link https://book.cakephp.org/3.0/en/controllers.html#rendering-a-view
[ "Instantiates", "the", "correct", "view", "class", "hands", "it", "its", "data", "and", "uses", "it", "to", "render", "the", "view", "output", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Controller.php#L766-L795
211,605
cakephp/cakephp
src/Controller/Controller.php
Controller._viewPath
protected function _viewPath() { $viewPath = $this->name; if ($this->request->getParam('prefix')) { $prefixes = array_map( 'Cake\Utility\Inflector::camelize', explode('/', $this->request->getParam('prefix')) ); $viewPath = implode(DIRECTORY_SEPARATOR, $prefixes) . DIRECTORY_SEPARATOR . $viewPath; } return $viewPath; }
php
protected function _viewPath() { $viewPath = $this->name; if ($this->request->getParam('prefix')) { $prefixes = array_map( 'Cake\Utility\Inflector::camelize', explode('/', $this->request->getParam('prefix')) ); $viewPath = implode(DIRECTORY_SEPARATOR, $prefixes) . DIRECTORY_SEPARATOR . $viewPath; } return $viewPath; }
[ "protected", "function", "_viewPath", "(", ")", "{", "$", "viewPath", "=", "$", "this", "->", "name", ";", "if", "(", "$", "this", "->", "request", "->", "getParam", "(", "'prefix'", ")", ")", "{", "$", "prefixes", "=", "array_map", "(", "'Cake\\Utility\\Inflector::camelize'", ",", "explode", "(", "'/'", ",", "$", "this", "->", "request", "->", "getParam", "(", "'prefix'", ")", ")", ")", ";", "$", "viewPath", "=", "implode", "(", "DIRECTORY_SEPARATOR", ",", "$", "prefixes", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "viewPath", ";", "}", "return", "$", "viewPath", ";", "}" ]
Get the viewPath based on controller name and request prefix. @return string
[ "Get", "the", "viewPath", "based", "on", "controller", "name", "and", "request", "prefix", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Controller.php#L802-L814
211,606
cakephp/cakephp
src/Controller/Controller.php
Controller.paginate
public function paginate($object = null, array $settings = []) { if (is_object($object)) { $table = $object; } if (is_string($object) || $object === null) { $try = [$object, $this->modelClass]; foreach ($try as $tableName) { if (empty($tableName)) { continue; } $table = $this->loadModel($tableName); break; } } $this->loadComponent('Paginator'); if (empty($table)) { throw new RuntimeException('Unable to locate an object compatible with paginate.'); } $settings += $this->paginate; return $this->Paginator->paginate($table, $settings); }
php
public function paginate($object = null, array $settings = []) { if (is_object($object)) { $table = $object; } if (is_string($object) || $object === null) { $try = [$object, $this->modelClass]; foreach ($try as $tableName) { if (empty($tableName)) { continue; } $table = $this->loadModel($tableName); break; } } $this->loadComponent('Paginator'); if (empty($table)) { throw new RuntimeException('Unable to locate an object compatible with paginate.'); } $settings += $this->paginate; return $this->Paginator->paginate($table, $settings); }
[ "public", "function", "paginate", "(", "$", "object", "=", "null", ",", "array", "$", "settings", "=", "[", "]", ")", "{", "if", "(", "is_object", "(", "$", "object", ")", ")", "{", "$", "table", "=", "$", "object", ";", "}", "if", "(", "is_string", "(", "$", "object", ")", "||", "$", "object", "===", "null", ")", "{", "$", "try", "=", "[", "$", "object", ",", "$", "this", "->", "modelClass", "]", ";", "foreach", "(", "$", "try", "as", "$", "tableName", ")", "{", "if", "(", "empty", "(", "$", "tableName", ")", ")", "{", "continue", ";", "}", "$", "table", "=", "$", "this", "->", "loadModel", "(", "$", "tableName", ")", ";", "break", ";", "}", "}", "$", "this", "->", "loadComponent", "(", "'Paginator'", ")", ";", "if", "(", "empty", "(", "$", "table", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Unable to locate an object compatible with paginate.'", ")", ";", "}", "$", "settings", "+=", "$", "this", "->", "paginate", ";", "return", "$", "this", "->", "Paginator", "->", "paginate", "(", "$", "table", ",", "$", "settings", ")", ";", "}" ]
Handles pagination of records in Table objects. Will load the referenced Table object, and have the PaginatorComponent paginate the query using the request date and settings defined in `$this->paginate`. This method will also make the PaginatorHelper available in the view. @param \Cake\ORM\Table|string|\Cake\ORM\Query|null $object Table to paginate (e.g: Table instance, 'TableName' or a Query object) @param array $settings The settings/configuration used for pagination. @return \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface Query results @link https://book.cakephp.org/3.0/en/controllers.html#paginating-a-model @throws \RuntimeException When no compatible table object can be found.
[ "Handles", "pagination", "of", "records", "in", "Table", "objects", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Controller.php#L863-L887
211,607
cakephp/cakephp
src/Console/Shell.php
Shell._validateTasks
protected function _validateTasks() { foreach ($this->_taskMap as $taskName => $task) { $class = App::className($task['class'], 'Shell/Task', 'Task'); if (!class_exists($class)) { throw new RuntimeException(sprintf( 'Task `%s` not found. Maybe you made a typo or a plugin is missing or not loaded?', $taskName )); } } }
php
protected function _validateTasks() { foreach ($this->_taskMap as $taskName => $task) { $class = App::className($task['class'], 'Shell/Task', 'Task'); if (!class_exists($class)) { throw new RuntimeException(sprintf( 'Task `%s` not found. Maybe you made a typo or a plugin is missing or not loaded?', $taskName )); } } }
[ "protected", "function", "_validateTasks", "(", ")", "{", "foreach", "(", "$", "this", "->", "_taskMap", "as", "$", "taskName", "=>", "$", "task", ")", "{", "$", "class", "=", "App", "::", "className", "(", "$", "task", "[", "'class'", "]", ",", "'Shell/Task'", ",", "'Task'", ")", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Task `%s` not found. Maybe you made a typo or a plugin is missing or not loaded?'", ",", "$", "taskName", ")", ")", ";", "}", "}", "}" ]
Checks that the tasks in the task map are actually available @throws \RuntimeException @return void
[ "Checks", "that", "the", "tasks", "in", "the", "task", "map", "are", "actually", "available" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/Shell.php#L321-L332
211,608
cakephp/cakephp
src/Console/Shell.php
Shell.runCommand
public function runCommand($argv, $autoMethod = false, $extra = []) { $command = isset($argv[0]) ? Inflector::underscore($argv[0]) : null; $this->OptionParser = $this->getOptionParser(); try { list($this->params, $this->args) = $this->OptionParser->parse($argv); } catch (ConsoleException $e) { $this->err('Error: ' . $e->getMessage()); return false; } if (!empty($extra) && is_array($extra)) { $this->params = array_merge($this->params, $extra); } $this->_setOutputLevel(); $this->command = $command; if (!empty($this->params['help'])) { return $this->_displayHelp($command); } $subcommands = $this->OptionParser->subcommands(); $method = Inflector::camelize($command); $isMethod = $this->hasMethod($method); if ($isMethod && $autoMethod && count($subcommands) === 0) { array_shift($this->args); $this->startup(); return $this->$method(...$this->args); } if ($isMethod && isset($subcommands[$command])) { $this->startup(); return $this->$method(...$this->args); } if ($this->hasTask($command) && isset($subcommands[$command])) { $this->startup(); array_shift($argv); return $this->{$method}->runCommand($argv, false, ['requested' => true]); } if ($this->hasMethod('main')) { $this->command = 'main'; $this->startup(); return $this->main(...$this->args); } $this->err('No subcommand provided. Choose one of the available subcommands.', 2); $this->_io->err($this->OptionParser->help($command)); return false; }
php
public function runCommand($argv, $autoMethod = false, $extra = []) { $command = isset($argv[0]) ? Inflector::underscore($argv[0]) : null; $this->OptionParser = $this->getOptionParser(); try { list($this->params, $this->args) = $this->OptionParser->parse($argv); } catch (ConsoleException $e) { $this->err('Error: ' . $e->getMessage()); return false; } if (!empty($extra) && is_array($extra)) { $this->params = array_merge($this->params, $extra); } $this->_setOutputLevel(); $this->command = $command; if (!empty($this->params['help'])) { return $this->_displayHelp($command); } $subcommands = $this->OptionParser->subcommands(); $method = Inflector::camelize($command); $isMethod = $this->hasMethod($method); if ($isMethod && $autoMethod && count($subcommands) === 0) { array_shift($this->args); $this->startup(); return $this->$method(...$this->args); } if ($isMethod && isset($subcommands[$command])) { $this->startup(); return $this->$method(...$this->args); } if ($this->hasTask($command) && isset($subcommands[$command])) { $this->startup(); array_shift($argv); return $this->{$method}->runCommand($argv, false, ['requested' => true]); } if ($this->hasMethod('main')) { $this->command = 'main'; $this->startup(); return $this->main(...$this->args); } $this->err('No subcommand provided. Choose one of the available subcommands.', 2); $this->_io->err($this->OptionParser->help($command)); return false; }
[ "public", "function", "runCommand", "(", "$", "argv", ",", "$", "autoMethod", "=", "false", ",", "$", "extra", "=", "[", "]", ")", "{", "$", "command", "=", "isset", "(", "$", "argv", "[", "0", "]", ")", "?", "Inflector", "::", "underscore", "(", "$", "argv", "[", "0", "]", ")", ":", "null", ";", "$", "this", "->", "OptionParser", "=", "$", "this", "->", "getOptionParser", "(", ")", ";", "try", "{", "list", "(", "$", "this", "->", "params", ",", "$", "this", "->", "args", ")", "=", "$", "this", "->", "OptionParser", "->", "parse", "(", "$", "argv", ")", ";", "}", "catch", "(", "ConsoleException", "$", "e", ")", "{", "$", "this", "->", "err", "(", "'Error: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "if", "(", "!", "empty", "(", "$", "extra", ")", "&&", "is_array", "(", "$", "extra", ")", ")", "{", "$", "this", "->", "params", "=", "array_merge", "(", "$", "this", "->", "params", ",", "$", "extra", ")", ";", "}", "$", "this", "->", "_setOutputLevel", "(", ")", ";", "$", "this", "->", "command", "=", "$", "command", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "params", "[", "'help'", "]", ")", ")", "{", "return", "$", "this", "->", "_displayHelp", "(", "$", "command", ")", ";", "}", "$", "subcommands", "=", "$", "this", "->", "OptionParser", "->", "subcommands", "(", ")", ";", "$", "method", "=", "Inflector", "::", "camelize", "(", "$", "command", ")", ";", "$", "isMethod", "=", "$", "this", "->", "hasMethod", "(", "$", "method", ")", ";", "if", "(", "$", "isMethod", "&&", "$", "autoMethod", "&&", "count", "(", "$", "subcommands", ")", "===", "0", ")", "{", "array_shift", "(", "$", "this", "->", "args", ")", ";", "$", "this", "->", "startup", "(", ")", ";", "return", "$", "this", "->", "$", "method", "(", "...", "$", "this", "->", "args", ")", ";", "}", "if", "(", "$", "isMethod", "&&", "isset", "(", "$", "subcommands", "[", "$", "command", "]", ")", ")", "{", "$", "this", "->", "startup", "(", ")", ";", "return", "$", "this", "->", "$", "method", "(", "...", "$", "this", "->", "args", ")", ";", "}", "if", "(", "$", "this", "->", "hasTask", "(", "$", "command", ")", "&&", "isset", "(", "$", "subcommands", "[", "$", "command", "]", ")", ")", "{", "$", "this", "->", "startup", "(", ")", ";", "array_shift", "(", "$", "argv", ")", ";", "return", "$", "this", "->", "{", "$", "method", "}", "->", "runCommand", "(", "$", "argv", ",", "false", ",", "[", "'requested'", "=>", "true", "]", ")", ";", "}", "if", "(", "$", "this", "->", "hasMethod", "(", "'main'", ")", ")", "{", "$", "this", "->", "command", "=", "'main'", ";", "$", "this", "->", "startup", "(", ")", ";", "return", "$", "this", "->", "main", "(", "...", "$", "this", "->", "args", ")", ";", "}", "$", "this", "->", "err", "(", "'No subcommand provided. Choose one of the available subcommands.'", ",", "2", ")", ";", "$", "this", "->", "_io", "->", "err", "(", "$", "this", "->", "OptionParser", "->", "help", "(", "$", "command", ")", ")", ";", "return", "false", ";", "}" ]
Runs the Shell with the provided argv. Delegates calls to Tasks and resolves methods inside the class. Commands are looked up with the following order: - Method on the shell. - Matching task name. - `main()` method. If a shell implements a `main()` method, all missing method calls will be sent to `main()` with the original method name in the argv. For tasks to be invoked they *must* be exposed as subcommands. If you define any subcommands, you must define all the subcommands your shell needs, whether they be methods on this class or methods on tasks. @param array $argv Array of arguments to run the shell with. This array should be missing the shell name. @param bool $autoMethod Set to true to allow any public method to be called even if it was not defined as a subcommand. This is used by ShellDispatcher to make building simple shells easy. @param array $extra Extra parameters that you can manually pass to the Shell to be dispatched. Built-in extra parameter is : - `requested` : if used, will prevent the Shell welcome message to be displayed @return int|bool|null @link https://book.cakephp.org/3.0/en/console-and-shells.html#the-cakephp-console
[ "Runs", "the", "Shell", "with", "the", "provided", "argv", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/Shell.php#L483-L539
211,609
cakephp/cakephp
src/Console/Shell.php
Shell._setOutputLevel
protected function _setOutputLevel() { $this->_io->setLoggers(ConsoleIo::NORMAL); if (!empty($this->params['quiet'])) { $this->_io->level(ConsoleIo::QUIET); $this->_io->setLoggers(ConsoleIo::QUIET); } if (!empty($this->params['verbose'])) { $this->_io->level(ConsoleIo::VERBOSE); $this->_io->setLoggers(ConsoleIo::VERBOSE); } }
php
protected function _setOutputLevel() { $this->_io->setLoggers(ConsoleIo::NORMAL); if (!empty($this->params['quiet'])) { $this->_io->level(ConsoleIo::QUIET); $this->_io->setLoggers(ConsoleIo::QUIET); } if (!empty($this->params['verbose'])) { $this->_io->level(ConsoleIo::VERBOSE); $this->_io->setLoggers(ConsoleIo::VERBOSE); } }
[ "protected", "function", "_setOutputLevel", "(", ")", "{", "$", "this", "->", "_io", "->", "setLoggers", "(", "ConsoleIo", "::", "NORMAL", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "params", "[", "'quiet'", "]", ")", ")", "{", "$", "this", "->", "_io", "->", "level", "(", "ConsoleIo", "::", "QUIET", ")", ";", "$", "this", "->", "_io", "->", "setLoggers", "(", "ConsoleIo", "::", "QUIET", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "params", "[", "'verbose'", "]", ")", ")", "{", "$", "this", "->", "_io", "->", "level", "(", "ConsoleIo", "::", "VERBOSE", ")", ";", "$", "this", "->", "_io", "->", "setLoggers", "(", "ConsoleIo", "::", "VERBOSE", ")", ";", "}", "}" ]
Set the output level based on the parameters. This reconfigures both the output level for out() and the configured stdout/stderr logging @return void
[ "Set", "the", "output", "level", "based", "on", "the", "parameters", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/Shell.php#L549-L560
211,610
cakephp/cakephp
src/Console/Shell.php
Shell._displayHelp
protected function _displayHelp($command) { $format = 'text'; if (!empty($this->args[0]) && $this->args[0] === 'xml') { $format = 'xml'; $this->_io->setOutputAs(ConsoleOutput::RAW); } else { $this->_welcome(); } $subcommands = $this->OptionParser->subcommands(); $command = isset($subcommands[$command]) ? $command : null; return $this->out($this->OptionParser->help($command, $format)); }
php
protected function _displayHelp($command) { $format = 'text'; if (!empty($this->args[0]) && $this->args[0] === 'xml') { $format = 'xml'; $this->_io->setOutputAs(ConsoleOutput::RAW); } else { $this->_welcome(); } $subcommands = $this->OptionParser->subcommands(); $command = isset($subcommands[$command]) ? $command : null; return $this->out($this->OptionParser->help($command, $format)); }
[ "protected", "function", "_displayHelp", "(", "$", "command", ")", "{", "$", "format", "=", "'text'", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "args", "[", "0", "]", ")", "&&", "$", "this", "->", "args", "[", "0", "]", "===", "'xml'", ")", "{", "$", "format", "=", "'xml'", ";", "$", "this", "->", "_io", "->", "setOutputAs", "(", "ConsoleOutput", "::", "RAW", ")", ";", "}", "else", "{", "$", "this", "->", "_welcome", "(", ")", ";", "}", "$", "subcommands", "=", "$", "this", "->", "OptionParser", "->", "subcommands", "(", ")", ";", "$", "command", "=", "isset", "(", "$", "subcommands", "[", "$", "command", "]", ")", "?", "$", "command", ":", "null", ";", "return", "$", "this", "->", "out", "(", "$", "this", "->", "OptionParser", "->", "help", "(", "$", "command", ",", "$", "format", ")", ")", ";", "}" ]
Display the help in the correct format @param string $command The command to get help for. @return int|bool The number of bytes returned from writing to stdout.
[ "Display", "the", "help", "in", "the", "correct", "format" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/Shell.php#L568-L582
211,611
cakephp/cakephp
src/Console/Shell.php
Shell.shortPath
public function shortPath($file) { $shortPath = str_replace(ROOT, null, $file); $shortPath = str_replace('..' . DIRECTORY_SEPARATOR, '', $shortPath); $shortPath = str_replace(DIRECTORY_SEPARATOR, '/', $shortPath); return str_replace('//', DIRECTORY_SEPARATOR, $shortPath); }
php
public function shortPath($file) { $shortPath = str_replace(ROOT, null, $file); $shortPath = str_replace('..' . DIRECTORY_SEPARATOR, '', $shortPath); $shortPath = str_replace(DIRECTORY_SEPARATOR, '/', $shortPath); return str_replace('//', DIRECTORY_SEPARATOR, $shortPath); }
[ "public", "function", "shortPath", "(", "$", "file", ")", "{", "$", "shortPath", "=", "str_replace", "(", "ROOT", ",", "null", ",", "$", "file", ")", ";", "$", "shortPath", "=", "str_replace", "(", "'..'", ".", "DIRECTORY_SEPARATOR", ",", "''", ",", "$", "shortPath", ")", ";", "$", "shortPath", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ",", "'/'", ",", "$", "shortPath", ")", ";", "return", "str_replace", "(", "'//'", ",", "DIRECTORY_SEPARATOR", ",", "$", "shortPath", ")", ";", "}" ]
Makes absolute file path easier to read @param string $file Absolute file path @return string short path @link https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::shortPath
[ "Makes", "absolute", "file", "path", "easier", "to", "read" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/Shell.php#L956-L963
211,612
cakephp/cakephp
src/Routing/Middleware/AssetMiddleware.php
AssetMiddleware.isNotModified
protected function isNotModified($request, $file) { $modifiedSince = $request->getHeaderLine('If-Modified-Since'); if (!$modifiedSince) { return false; } return strtotime($modifiedSince) === $file->lastChange(); }
php
protected function isNotModified($request, $file) { $modifiedSince = $request->getHeaderLine('If-Modified-Since'); if (!$modifiedSince) { return false; } return strtotime($modifiedSince) === $file->lastChange(); }
[ "protected", "function", "isNotModified", "(", "$", "request", ",", "$", "file", ")", "{", "$", "modifiedSince", "=", "$", "request", "->", "getHeaderLine", "(", "'If-Modified-Since'", ")", ";", "if", "(", "!", "$", "modifiedSince", ")", "{", "return", "false", ";", "}", "return", "strtotime", "(", "$", "modifiedSince", ")", "===", "$", "file", "->", "lastChange", "(", ")", ";", "}" ]
Check the not modified header. @param \Psr\Http\Message\ServerRequestInterface $request The request to check. @param \Cake\Filesystem\File $file The file object to compare. @return bool
[ "Check", "the", "not", "modified", "header", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Middleware/AssetMiddleware.php#L119-L127
211,613
cakephp/cakephp
src/Routing/Middleware/AssetMiddleware.php
AssetMiddleware.getType
protected function getType($file) { $extension = $file->ext(); if (isset($this->typeMap[$extension])) { return $this->typeMap[$extension]; } return $file->mime() ?: 'application/octet-stream'; }
php
protected function getType($file) { $extension = $file->ext(); if (isset($this->typeMap[$extension])) { return $this->typeMap[$extension]; } return $file->mime() ?: 'application/octet-stream'; }
[ "protected", "function", "getType", "(", "$", "file", ")", "{", "$", "extension", "=", "$", "file", "->", "ext", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "typeMap", "[", "$", "extension", "]", ")", ")", "{", "return", "$", "this", "->", "typeMap", "[", "$", "extension", "]", ";", "}", "return", "$", "file", "->", "mime", "(", ")", "?", ":", "'application/octet-stream'", ";", "}" ]
Return the type from a File object @param File $file The file from which you get the type @return string
[ "Return", "the", "type", "from", "a", "File", "object" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Middleware/AssetMiddleware.php#L188-L196
211,614
cakephp/cakephp
src/Form/Schema.php
Schema.addFields
public function addFields(array $fields) { foreach ($fields as $name => $attrs) { $this->addField($name, $attrs); } return $this; }
php
public function addFields(array $fields) { foreach ($fields as $name => $attrs) { $this->addField($name, $attrs); } return $this; }
[ "public", "function", "addFields", "(", "array", "$", "fields", ")", "{", "foreach", "(", "$", "fields", "as", "$", "name", "=>", "$", "attrs", ")", "{", "$", "this", "->", "addField", "(", "$", "name", ",", "$", "attrs", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add multiple fields to the schema. @param array $fields The fields to add. @return $this
[ "Add", "multiple", "fields", "to", "the", "schema", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Form/Schema.php#L48-L55
211,615
cakephp/cakephp
src/Form/Schema.php
Schema.addField
public function addField($name, $attrs) { if (is_string($attrs)) { $attrs = ['type' => $attrs]; } $attrs = array_intersect_key($attrs, $this->_fieldDefaults); $this->_fields[$name] = $attrs + $this->_fieldDefaults; return $this; }
php
public function addField($name, $attrs) { if (is_string($attrs)) { $attrs = ['type' => $attrs]; } $attrs = array_intersect_key($attrs, $this->_fieldDefaults); $this->_fields[$name] = $attrs + $this->_fieldDefaults; return $this; }
[ "public", "function", "addField", "(", "$", "name", ",", "$", "attrs", ")", "{", "if", "(", "is_string", "(", "$", "attrs", ")", ")", "{", "$", "attrs", "=", "[", "'type'", "=>", "$", "attrs", "]", ";", "}", "$", "attrs", "=", "array_intersect_key", "(", "$", "attrs", ",", "$", "this", "->", "_fieldDefaults", ")", ";", "$", "this", "->", "_fields", "[", "$", "name", "]", "=", "$", "attrs", "+", "$", "this", "->", "_fieldDefaults", ";", "return", "$", "this", ";", "}" ]
Adds a field to the schema. @param string $name The field name. @param string|array $attrs The attributes for the field, or the type as a string. @return $this
[ "Adds", "a", "field", "to", "the", "schema", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Form/Schema.php#L65-L74
211,616
cakephp/cakephp
src/Form/Schema.php
Schema.field
public function field($name) { if (!isset($this->_fields[$name])) { return null; } return $this->_fields[$name]; }
php
public function field($name) { if (!isset($this->_fields[$name])) { return null; } return $this->_fields[$name]; }
[ "public", "function", "field", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_fields", "[", "$", "name", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "_fields", "[", "$", "name", "]", ";", "}" ]
Get the attributes for a given field. @param string $name The field name. @return null|array The attributes for a field, or null.
[ "Get", "the", "attributes", "for", "a", "given", "field", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Form/Schema.php#L105-L112
211,617
cakephp/cakephp
src/Mailer/Email.php
Email.replyTo
public function replyTo($email = null, $name = null) { deprecationWarning('Email::replyTo() is deprecated. Use Email::setReplyTo() or Email::getReplyTo() instead.'); if ($email === null) { return $this->getReplyTo(); } return $this->setReplyTo($email, $name); }
php
public function replyTo($email = null, $name = null) { deprecationWarning('Email::replyTo() is deprecated. Use Email::setReplyTo() or Email::getReplyTo() instead.'); if ($email === null) { return $this->getReplyTo(); } return $this->setReplyTo($email, $name); }
[ "public", "function", "replyTo", "(", "$", "email", "=", "null", ",", "$", "name", "=", "null", ")", "{", "deprecationWarning", "(", "'Email::replyTo() is deprecated. Use Email::setReplyTo() or Email::getReplyTo() instead.'", ")", ";", "if", "(", "$", "email", "===", "null", ")", "{", "return", "$", "this", "->", "getReplyTo", "(", ")", ";", "}", "return", "$", "this", "->", "setReplyTo", "(", "$", "email", ",", "$", "name", ")", ";", "}" ]
Reply-To @deprecated 3.4.0 Use setReplyTo()/getReplyTo() instead. @param string|array|null $email Null to get, String with email, Array with email as key, name as value or email as value (without name) @param string|null $name Name @return array|$this @throws \InvalidArgumentException
[ "Reply", "-", "To" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L503-L512
211,618
cakephp/cakephp
src/Mailer/Email.php
Email.setCharset
public function setCharset($charset) { $this->charset = $charset; if (!$this->headerCharset) { $this->headerCharset = $charset; } return $this; }
php
public function setCharset($charset) { $this->charset = $charset; if (!$this->headerCharset) { $this->headerCharset = $charset; } return $this; }
[ "public", "function", "setCharset", "(", "$", "charset", ")", "{", "$", "this", "->", "charset", "=", "$", "charset", ";", "if", "(", "!", "$", "this", "->", "headerCharset", ")", "{", "$", "this", "->", "headerCharset", "=", "$", "charset", ";", "}", "return", "$", "this", ";", "}" ]
Charset setter. @param string|null $charset Character set. @return $this
[ "Charset", "setter", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L777-L785
211,619
cakephp/cakephp
src/Mailer/Email.php
Email.setTransferEncoding
public function setTransferEncoding($encoding) { $encoding = strtolower($encoding); if (!in_array($encoding, $this->_transferEncodingAvailable)) { throw new InvalidArgumentException( sprintf( 'Transfer encoding not available. Can be : %s.', implode(', ', $this->_transferEncodingAvailable) ) ); } $this->transferEncoding = $encoding; return $this; }
php
public function setTransferEncoding($encoding) { $encoding = strtolower($encoding); if (!in_array($encoding, $this->_transferEncodingAvailable)) { throw new InvalidArgumentException( sprintf( 'Transfer encoding not available. Can be : %s.', implode(', ', $this->_transferEncodingAvailable) ) ); } $this->transferEncoding = $encoding; return $this; }
[ "public", "function", "setTransferEncoding", "(", "$", "encoding", ")", "{", "$", "encoding", "=", "strtolower", "(", "$", "encoding", ")", ";", "if", "(", "!", "in_array", "(", "$", "encoding", ",", "$", "this", "->", "_transferEncodingAvailable", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Transfer encoding not available. Can be : %s.'", ",", "implode", "(", "', '", ",", "$", "this", "->", "_transferEncodingAvailable", ")", ")", ")", ";", "}", "$", "this", "->", "transferEncoding", "=", "$", "encoding", ";", "return", "$", "this", ";", "}" ]
TransferEncoding setter. @param string|null $encoding Encoding set. @return $this
[ "TransferEncoding", "setter", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L865-L879
211,620
cakephp/cakephp
src/Mailer/Email.php
Email._validateEmail
protected function _validateEmail($email, $context) { if ($this->_emailPattern === null) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) { return; } } elseif (preg_match($this->_emailPattern, $email)) { return; } $context = ltrim($context, '_'); if ($email == '') { throw new InvalidArgumentException(sprintf('The email set for "%s" is empty.', $context)); } throw new InvalidArgumentException(sprintf('Invalid email set for "%s". You passed "%s".', $context, $email)); }
php
protected function _validateEmail($email, $context) { if ($this->_emailPattern === null) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) { return; } } elseif (preg_match($this->_emailPattern, $email)) { return; } $context = ltrim($context, '_'); if ($email == '') { throw new InvalidArgumentException(sprintf('The email set for "%s" is empty.', $context)); } throw new InvalidArgumentException(sprintf('Invalid email set for "%s". You passed "%s".', $context, $email)); }
[ "protected", "function", "_validateEmail", "(", "$", "email", ",", "$", "context", ")", "{", "if", "(", "$", "this", "->", "_emailPattern", "===", "null", ")", "{", "if", "(", "filter_var", "(", "$", "email", ",", "FILTER_VALIDATE_EMAIL", ")", ")", "{", "return", ";", "}", "}", "elseif", "(", "preg_match", "(", "$", "this", "->", "_emailPattern", ",", "$", "email", ")", ")", "{", "return", ";", "}", "$", "context", "=", "ltrim", "(", "$", "context", ",", "'_'", ")", ";", "if", "(", "$", "email", "==", "''", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'The email set for \"%s\" is empty.'", ",", "$", "context", ")", ")", ";", "}", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid email set for \"%s\". You passed \"%s\".'", ",", "$", "context", ",", "$", "email", ")", ")", ";", "}" ]
Validate email address @param string $email Email address to validate @param string $context Which property was set @return void @throws \InvalidArgumentException If email address does not validate
[ "Validate", "email", "address" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L977-L992
211,621
cakephp/cakephp
src/Mailer/Email.php
Email._setEmailSingle
protected function _setEmailSingle($varName, $email, $name, $throwMessage) { if ($email === []) { $this->{$varName} = $email; return $this; } $current = $this->{$varName}; $this->_setEmail($varName, $email, $name); if (count($this->{$varName}) !== 1) { $this->{$varName} = $current; throw new InvalidArgumentException($throwMessage); } return $this; }
php
protected function _setEmailSingle($varName, $email, $name, $throwMessage) { if ($email === []) { $this->{$varName} = $email; return $this; } $current = $this->{$varName}; $this->_setEmail($varName, $email, $name); if (count($this->{$varName}) !== 1) { $this->{$varName} = $current; throw new InvalidArgumentException($throwMessage); } return $this; }
[ "protected", "function", "_setEmailSingle", "(", "$", "varName", ",", "$", "email", ",", "$", "name", ",", "$", "throwMessage", ")", "{", "if", "(", "$", "email", "===", "[", "]", ")", "{", "$", "this", "->", "{", "$", "varName", "}", "=", "$", "email", ";", "return", "$", "this", ";", "}", "$", "current", "=", "$", "this", "->", "{", "$", "varName", "}", ";", "$", "this", "->", "_setEmail", "(", "$", "varName", ",", "$", "email", ",", "$", "name", ")", ";", "if", "(", "count", "(", "$", "this", "->", "{", "$", "varName", "}", ")", "!==", "1", ")", "{", "$", "this", "->", "{", "$", "varName", "}", "=", "$", "current", ";", "throw", "new", "InvalidArgumentException", "(", "$", "throwMessage", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set only 1 email @param string $varName Property name @param string|array $email String with email, Array with email as key, name as value or email as value (without name) @param string $name Name @param string $throwMessage Exception message @return $this @throws \InvalidArgumentException
[ "Set", "only", "1", "email" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L1005-L1021
211,622
cakephp/cakephp
src/Mailer/Email.php
Email.setEmailFormat
public function setEmailFormat($format) { if (!in_array($format, $this->_emailFormatAvailable)) { throw new InvalidArgumentException('Format not available.'); } $this->_emailFormat = $format; return $this; }
php
public function setEmailFormat($format) { if (!in_array($format, $this->_emailFormatAvailable)) { throw new InvalidArgumentException('Format not available.'); } $this->_emailFormat = $format; return $this; }
[ "public", "function", "setEmailFormat", "(", "$", "format", ")", "{", "if", "(", "!", "in_array", "(", "$", "format", ",", "$", "this", "->", "_emailFormatAvailable", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Format not available.'", ")", ";", "}", "$", "this", "->", "_emailFormat", "=", "$", "format", ";", "return", "$", "this", ";", "}" ]
Sets email format. @param string $format Formatting string. @return $this @throws \InvalidArgumentException
[ "Sets", "email", "format", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L1545-L1553
211,623
cakephp/cakephp
src/Mailer/Email.php
Email.setTransport
public function setTransport($name) { if (is_string($name)) { $transport = TransportFactory::get($name); } elseif (is_object($name)) { $transport = $name; } else { throw new InvalidArgumentException( sprintf('The value passed for the "$name" argument must be either a string, or an object, %s given.', gettype($name)) ); } if (!method_exists($transport, 'send')) { throw new LogicException(sprintf('The "%s" do not have send method.', get_class($transport))); } $this->_transport = $transport; return $this; }
php
public function setTransport($name) { if (is_string($name)) { $transport = TransportFactory::get($name); } elseif (is_object($name)) { $transport = $name; } else { throw new InvalidArgumentException( sprintf('The value passed for the "$name" argument must be either a string, or an object, %s given.', gettype($name)) ); } if (!method_exists($transport, 'send')) { throw new LogicException(sprintf('The "%s" do not have send method.', get_class($transport))); } $this->_transport = $transport; return $this; }
[ "public", "function", "setTransport", "(", "$", "name", ")", "{", "if", "(", "is_string", "(", "$", "name", ")", ")", "{", "$", "transport", "=", "TransportFactory", "::", "get", "(", "$", "name", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "name", ")", ")", "{", "$", "transport", "=", "$", "name", ";", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'The value passed for the \"$name\" argument must be either a string, or an object, %s given.'", ",", "gettype", "(", "$", "name", ")", ")", ")", ";", "}", "if", "(", "!", "method_exists", "(", "$", "transport", ",", "'send'", ")", ")", "{", "throw", "new", "LogicException", "(", "sprintf", "(", "'The \"%s\" do not have send method.'", ",", "get_class", "(", "$", "transport", ")", ")", ")", ";", "}", "$", "this", "->", "_transport", "=", "$", "transport", ";", "return", "$", "this", ";", "}" ]
Sets the transport. When setting the transport you can either use the name of a configured transport or supply a constructed transport. @param string|\Cake\Mailer\AbstractTransport $name Either the name of a configured transport, or a transport instance. @return $this @throws \LogicException When the chosen transport lacks a send method. @throws \InvalidArgumentException When $name is neither a string nor an object.
[ "Sets", "the", "transport", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L1596-L1614
211,624
cakephp/cakephp
src/Mailer/Email.php
Email.setMessageId
public function setMessageId($message) { if (is_bool($message)) { $this->_messageId = $message; } else { if (!preg_match('/^\<.+@.+\>$/', $message)) { throw new InvalidArgumentException('Invalid format to Message-ID. The text should be something like "<uuid@server.com>"'); } $this->_messageId = $message; } return $this; }
php
public function setMessageId($message) { if (is_bool($message)) { $this->_messageId = $message; } else { if (!preg_match('/^\<.+@.+\>$/', $message)) { throw new InvalidArgumentException('Invalid format to Message-ID. The text should be something like "<uuid@server.com>"'); } $this->_messageId = $message; } return $this; }
[ "public", "function", "setMessageId", "(", "$", "message", ")", "{", "if", "(", "is_bool", "(", "$", "message", ")", ")", "{", "$", "this", "->", "_messageId", "=", "$", "message", ";", "}", "else", "{", "if", "(", "!", "preg_match", "(", "'/^\\<.+@.+\\>$/'", ",", "$", "message", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid format to Message-ID. The text should be something like \"<uuid@server.com>\"'", ")", ";", "}", "$", "this", "->", "_messageId", "=", "$", "message", ";", "}", "return", "$", "this", ";", "}" ]
Sets message ID. @param bool|string $message True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID. @return $this @throws \InvalidArgumentException
[ "Sets", "message", "ID", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L1657-L1669
211,625
cakephp/cakephp
src/Mailer/Email.php
Email.messageId
public function messageId($message = null) { deprecationWarning('Email::messageId() is deprecated. Use Email::setMessageId() or Email::getMessageId() instead.'); if ($message === null) { return $this->getMessageId(); } return $this->setMessageId($message); }
php
public function messageId($message = null) { deprecationWarning('Email::messageId() is deprecated. Use Email::setMessageId() or Email::getMessageId() instead.'); if ($message === null) { return $this->getMessageId(); } return $this->setMessageId($message); }
[ "public", "function", "messageId", "(", "$", "message", "=", "null", ")", "{", "deprecationWarning", "(", "'Email::messageId() is deprecated. Use Email::setMessageId() or Email::getMessageId() instead.'", ")", ";", "if", "(", "$", "message", "===", "null", ")", "{", "return", "$", "this", "->", "getMessageId", "(", ")", ";", "}", "return", "$", "this", "->", "setMessageId", "(", "$", "message", ")", ";", "}" ]
Message-ID @deprecated 3.4.0 Use setMessageId()/getMessageId() instead. @param bool|string|null $message True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID @return bool|string|$this @throws \InvalidArgumentException
[ "Message", "-", "ID" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L1689-L1698
211,626
cakephp/cakephp
src/Mailer/Email.php
Email.configTransport
public static function configTransport($key, $config = null) { deprecationWarning('Email::configTransport() is deprecated. Use TransportFactory::setConfig() or TransportFactory::getConfig() instead.'); if ($config === null && is_string($key)) { return TransportFactory::getConfig($key); } if ($config === null && is_array($key)) { TransportFactory::setConfig($key); return null; } TransportFactory::setConfig($key, $config); }
php
public static function configTransport($key, $config = null) { deprecationWarning('Email::configTransport() is deprecated. Use TransportFactory::setConfig() or TransportFactory::getConfig() instead.'); if ($config === null && is_string($key)) { return TransportFactory::getConfig($key); } if ($config === null && is_array($key)) { TransportFactory::setConfig($key); return null; } TransportFactory::setConfig($key, $config); }
[ "public", "static", "function", "configTransport", "(", "$", "key", ",", "$", "config", "=", "null", ")", "{", "deprecationWarning", "(", "'Email::configTransport() is deprecated. Use TransportFactory::setConfig() or TransportFactory::getConfig() instead.'", ")", ";", "if", "(", "$", "config", "===", "null", "&&", "is_string", "(", "$", "key", ")", ")", "{", "return", "TransportFactory", "::", "getConfig", "(", "$", "key", ")", ";", "}", "if", "(", "$", "config", "===", "null", "&&", "is_array", "(", "$", "key", ")", ")", "{", "TransportFactory", "::", "setConfig", "(", "$", "key", ")", ";", "return", "null", ";", "}", "TransportFactory", "::", "setConfig", "(", "$", "key", ",", "$", "config", ")", ";", "}" ]
Add or read transport configuration. Use this method to define transports to use in delivery profiles. Once defined you cannot edit the configurations, and must use Email::dropTransport() to flush the configuration first. When using an array of configuration data a new transport will be constructed for each message sent. When using a Closure, the closure will be evaluated for each message. The `className` is used to define the class to use for a transport. It can either be a short name, or a fully qualified classname @deprecated 3.4.0 Use TransportFactory::setConfig()/getConfig() instead. @param string|array $key The configuration name to read/write. Or an array of multiple transports to set. @param array|\Cake\Mailer\AbstractTransport|null $config Either an array of configuration data, or a transport instance. @return array|null Either null when setting or an array of data when reading. @throws \BadMethodCallException When modifying an existing configuration.
[ "Add", "or", "read", "transport", "configuration", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2023-L2037
211,627
cakephp/cakephp
src/Mailer/Email.php
Email.setProfile
public function setProfile($config) { if (!is_array($config)) { $config = (string)$config; } $this->_applyConfig($config); return $this; }
php
public function setProfile($config) { if (!is_array($config)) { $config = (string)$config; } $this->_applyConfig($config); return $this; }
[ "public", "function", "setProfile", "(", "$", "config", ")", "{", "if", "(", "!", "is_array", "(", "$", "config", ")", ")", "{", "$", "config", "=", "(", "string", ")", "$", "config", ";", "}", "$", "this", "->", "_applyConfig", "(", "$", "config", ")", ";", "return", "$", "this", ";", "}" ]
Sets the configuration profile to use for this instance. @param string|array $config String with configuration name, or an array with config. @return $this
[ "Sets", "the", "configuration", "profile", "to", "use", "for", "this", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2073-L2081
211,628
cakephp/cakephp
src/Mailer/Email.php
Email.send
public function send($content = null) { if (empty($this->_from)) { throw new BadMethodCallException('From is not specified.'); } if (empty($this->_to) && empty($this->_cc) && empty($this->_bcc)) { throw new BadMethodCallException('You need specify one destination on to, cc or bcc.'); } if (is_array($content)) { $content = implode("\n", $content) . "\n"; } $this->_message = $this->_render($this->_wrap($content)); $transport = $this->getTransport(); if (!$transport) { $msg = 'Cannot send email, transport was not defined. Did you call transport() or define ' . ' a transport in the set profile?'; throw new BadMethodCallException($msg); } $contents = $transport->send($this); $this->_logDelivery($contents); return $contents; }
php
public function send($content = null) { if (empty($this->_from)) { throw new BadMethodCallException('From is not specified.'); } if (empty($this->_to) && empty($this->_cc) && empty($this->_bcc)) { throw new BadMethodCallException('You need specify one destination on to, cc or bcc.'); } if (is_array($content)) { $content = implode("\n", $content) . "\n"; } $this->_message = $this->_render($this->_wrap($content)); $transport = $this->getTransport(); if (!$transport) { $msg = 'Cannot send email, transport was not defined. Did you call transport() or define ' . ' a transport in the set profile?'; throw new BadMethodCallException($msg); } $contents = $transport->send($this); $this->_logDelivery($contents); return $contents; }
[ "public", "function", "send", "(", "$", "content", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_from", ")", ")", "{", "throw", "new", "BadMethodCallException", "(", "'From is not specified.'", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "_to", ")", "&&", "empty", "(", "$", "this", "->", "_cc", ")", "&&", "empty", "(", "$", "this", "->", "_bcc", ")", ")", "{", "throw", "new", "BadMethodCallException", "(", "'You need specify one destination on to, cc or bcc.'", ")", ";", "}", "if", "(", "is_array", "(", "$", "content", ")", ")", "{", "$", "content", "=", "implode", "(", "\"\\n\"", ",", "$", "content", ")", ".", "\"\\n\"", ";", "}", "$", "this", "->", "_message", "=", "$", "this", "->", "_render", "(", "$", "this", "->", "_wrap", "(", "$", "content", ")", ")", ";", "$", "transport", "=", "$", "this", "->", "getTransport", "(", ")", ";", "if", "(", "!", "$", "transport", ")", "{", "$", "msg", "=", "'Cannot send email, transport was not defined. Did you call transport() or define '", ".", "' a transport in the set profile?'", ";", "throw", "new", "BadMethodCallException", "(", "$", "msg", ")", ";", "}", "$", "contents", "=", "$", "transport", "->", "send", "(", "$", "this", ")", ";", "$", "this", "->", "_logDelivery", "(", "$", "contents", ")", ";", "return", "$", "contents", ";", "}" ]
Send an email using the specified content, template and layout @param string|array|null $content String with message or array with messages @return array @throws \BadMethodCallException
[ "Send", "an", "email", "using", "the", "specified", "content", "template", "and", "layout" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2119-L2144
211,629
cakephp/cakephp
src/Mailer/Email.php
Email._logDelivery
protected function _logDelivery($contents) { if (empty($this->_profile['log'])) { return; } $config = [ 'level' => 'debug', 'scope' => 'email' ]; if ($this->_profile['log'] !== true) { if (!is_array($this->_profile['log'])) { $this->_profile['log'] = ['level' => $this->_profile['log']]; } $config = $this->_profile['log'] + $config; } Log::write( $config['level'], PHP_EOL . $this->flatten($contents['headers']) . PHP_EOL . PHP_EOL . $this->flatten($contents['message']), $config['scope'] ); }
php
protected function _logDelivery($contents) { if (empty($this->_profile['log'])) { return; } $config = [ 'level' => 'debug', 'scope' => 'email' ]; if ($this->_profile['log'] !== true) { if (!is_array($this->_profile['log'])) { $this->_profile['log'] = ['level' => $this->_profile['log']]; } $config = $this->_profile['log'] + $config; } Log::write( $config['level'], PHP_EOL . $this->flatten($contents['headers']) . PHP_EOL . PHP_EOL . $this->flatten($contents['message']), $config['scope'] ); }
[ "protected", "function", "_logDelivery", "(", "$", "contents", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_profile", "[", "'log'", "]", ")", ")", "{", "return", ";", "}", "$", "config", "=", "[", "'level'", "=>", "'debug'", ",", "'scope'", "=>", "'email'", "]", ";", "if", "(", "$", "this", "->", "_profile", "[", "'log'", "]", "!==", "true", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "_profile", "[", "'log'", "]", ")", ")", "{", "$", "this", "->", "_profile", "[", "'log'", "]", "=", "[", "'level'", "=>", "$", "this", "->", "_profile", "[", "'log'", "]", "]", ";", "}", "$", "config", "=", "$", "this", "->", "_profile", "[", "'log'", "]", "+", "$", "config", ";", "}", "Log", "::", "write", "(", "$", "config", "[", "'level'", "]", ",", "PHP_EOL", ".", "$", "this", "->", "flatten", "(", "$", "contents", "[", "'headers'", "]", ")", ".", "PHP_EOL", ".", "PHP_EOL", ".", "$", "this", "->", "flatten", "(", "$", "contents", "[", "'message'", "]", ")", ",", "$", "config", "[", "'scope'", "]", ")", ";", "}" ]
Log the email message delivery. @param array $contents The content with 'headers' and 'message' keys. @return void
[ "Log", "the", "email", "message", "delivery", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2152-L2172
211,630
cakephp/cakephp
src/Mailer/Email.php
Email.deliver
public static function deliver($to = null, $subject = null, $message = null, $config = 'default', $send = true) { $class = __CLASS__; if (is_array($config) && !isset($config['transport'])) { $config['transport'] = 'default'; } /* @var \Cake\Mailer\Email $instance */ $instance = new $class($config); if ($to !== null) { $instance->setTo($to); } if ($subject !== null) { $instance->setSubject($subject); } if (is_array($message)) { $instance->setViewVars($message); $message = null; } elseif ($message === null && array_key_exists('message', $config = $instance->getProfile())) { $message = $config['message']; } if ($send === true) { $instance->send($message); } return $instance; }
php
public static function deliver($to = null, $subject = null, $message = null, $config = 'default', $send = true) { $class = __CLASS__; if (is_array($config) && !isset($config['transport'])) { $config['transport'] = 'default'; } /* @var \Cake\Mailer\Email $instance */ $instance = new $class($config); if ($to !== null) { $instance->setTo($to); } if ($subject !== null) { $instance->setSubject($subject); } if (is_array($message)) { $instance->setViewVars($message); $message = null; } elseif ($message === null && array_key_exists('message', $config = $instance->getProfile())) { $message = $config['message']; } if ($send === true) { $instance->send($message); } return $instance; }
[ "public", "static", "function", "deliver", "(", "$", "to", "=", "null", ",", "$", "subject", "=", "null", ",", "$", "message", "=", "null", ",", "$", "config", "=", "'default'", ",", "$", "send", "=", "true", ")", "{", "$", "class", "=", "__CLASS__", ";", "if", "(", "is_array", "(", "$", "config", ")", "&&", "!", "isset", "(", "$", "config", "[", "'transport'", "]", ")", ")", "{", "$", "config", "[", "'transport'", "]", "=", "'default'", ";", "}", "/* @var \\Cake\\Mailer\\Email $instance */", "$", "instance", "=", "new", "$", "class", "(", "$", "config", ")", ";", "if", "(", "$", "to", "!==", "null", ")", "{", "$", "instance", "->", "setTo", "(", "$", "to", ")", ";", "}", "if", "(", "$", "subject", "!==", "null", ")", "{", "$", "instance", "->", "setSubject", "(", "$", "subject", ")", ";", "}", "if", "(", "is_array", "(", "$", "message", ")", ")", "{", "$", "instance", "->", "setViewVars", "(", "$", "message", ")", ";", "$", "message", "=", "null", ";", "}", "elseif", "(", "$", "message", "===", "null", "&&", "array_key_exists", "(", "'message'", ",", "$", "config", "=", "$", "instance", "->", "getProfile", "(", ")", ")", ")", "{", "$", "message", "=", "$", "config", "[", "'message'", "]", ";", "}", "if", "(", "$", "send", "===", "true", ")", "{", "$", "instance", "->", "send", "(", "$", "message", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Static method to fast create an instance of \Cake\Mailer\Email @param string|array|null $to Address to send (see Cake\Mailer\Email::to()). If null, will try to use 'to' from transport config @param string|null $subject String of subject or null to use 'subject' from transport config @param string|array|null $message String with message or array with variables to be used in render @param string|array $config String to use Email delivery profile from app.php or array with configs @param bool $send Send the email or just return the instance pre-configured @return static Instance of Cake\Mailer\Email @throws \InvalidArgumentException
[ "Static", "method", "to", "fast", "create", "an", "instance", "of", "\\", "Cake", "\\", "Mailer", "\\", "Email" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2196-L2223
211,631
cakephp/cakephp
src/Mailer/Email.php
Email._applyConfig
protected function _applyConfig($config) { if (is_string($config)) { $name = $config; $config = static::getConfig($name); if (empty($config)) { throw new InvalidArgumentException(sprintf('Unknown email configuration "%s".', $name)); } unset($name); } $this->_profile = array_merge($this->_profile, $config); $simpleMethods = [ 'from', 'sender', 'to', 'replyTo', 'readReceipt', 'returnPath', 'cc', 'bcc', 'messageId', 'domain', 'subject', 'attachments', 'transport', 'emailFormat', 'emailPattern', 'charset', 'headerCharset' ]; foreach ($simpleMethods as $method) { if (isset($config[$method])) { $this->{'set' . ucfirst($method)}($config[$method]); } } if (empty($this->headerCharset)) { $this->headerCharset = $this->charset; } if (isset($config['headers'])) { $this->setHeaders($config['headers']); } $viewBuilderMethods = [ 'template', 'layout', 'theme' ]; foreach ($viewBuilderMethods as $method) { if (array_key_exists($method, $config)) { $this->viewBuilder()->{'set' . ucfirst($method)}($config[$method]); } } if (array_key_exists('helpers', $config)) { $this->viewBuilder()->setHelpers($config['helpers'], false); } if (array_key_exists('viewRender', $config)) { $this->viewBuilder()->setClassName($config['viewRender']); } if (array_key_exists('viewVars', $config)) { $this->set($config['viewVars']); } }
php
protected function _applyConfig($config) { if (is_string($config)) { $name = $config; $config = static::getConfig($name); if (empty($config)) { throw new InvalidArgumentException(sprintf('Unknown email configuration "%s".', $name)); } unset($name); } $this->_profile = array_merge($this->_profile, $config); $simpleMethods = [ 'from', 'sender', 'to', 'replyTo', 'readReceipt', 'returnPath', 'cc', 'bcc', 'messageId', 'domain', 'subject', 'attachments', 'transport', 'emailFormat', 'emailPattern', 'charset', 'headerCharset' ]; foreach ($simpleMethods as $method) { if (isset($config[$method])) { $this->{'set' . ucfirst($method)}($config[$method]); } } if (empty($this->headerCharset)) { $this->headerCharset = $this->charset; } if (isset($config['headers'])) { $this->setHeaders($config['headers']); } $viewBuilderMethods = [ 'template', 'layout', 'theme' ]; foreach ($viewBuilderMethods as $method) { if (array_key_exists($method, $config)) { $this->viewBuilder()->{'set' . ucfirst($method)}($config[$method]); } } if (array_key_exists('helpers', $config)) { $this->viewBuilder()->setHelpers($config['helpers'], false); } if (array_key_exists('viewRender', $config)) { $this->viewBuilder()->setClassName($config['viewRender']); } if (array_key_exists('viewVars', $config)) { $this->set($config['viewVars']); } }
[ "protected", "function", "_applyConfig", "(", "$", "config", ")", "{", "if", "(", "is_string", "(", "$", "config", ")", ")", "{", "$", "name", "=", "$", "config", ";", "$", "config", "=", "static", "::", "getConfig", "(", "$", "name", ")", ";", "if", "(", "empty", "(", "$", "config", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Unknown email configuration \"%s\".'", ",", "$", "name", ")", ")", ";", "}", "unset", "(", "$", "name", ")", ";", "}", "$", "this", "->", "_profile", "=", "array_merge", "(", "$", "this", "->", "_profile", ",", "$", "config", ")", ";", "$", "simpleMethods", "=", "[", "'from'", ",", "'sender'", ",", "'to'", ",", "'replyTo'", ",", "'readReceipt'", ",", "'returnPath'", ",", "'cc'", ",", "'bcc'", ",", "'messageId'", ",", "'domain'", ",", "'subject'", ",", "'attachments'", ",", "'transport'", ",", "'emailFormat'", ",", "'emailPattern'", ",", "'charset'", ",", "'headerCharset'", "]", ";", "foreach", "(", "$", "simpleMethods", "as", "$", "method", ")", "{", "if", "(", "isset", "(", "$", "config", "[", "$", "method", "]", ")", ")", "{", "$", "this", "->", "{", "'set'", ".", "ucfirst", "(", "$", "method", ")", "}", "(", "$", "config", "[", "$", "method", "]", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "this", "->", "headerCharset", ")", ")", "{", "$", "this", "->", "headerCharset", "=", "$", "this", "->", "charset", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'headers'", "]", ")", ")", "{", "$", "this", "->", "setHeaders", "(", "$", "config", "[", "'headers'", "]", ")", ";", "}", "$", "viewBuilderMethods", "=", "[", "'template'", ",", "'layout'", ",", "'theme'", "]", ";", "foreach", "(", "$", "viewBuilderMethods", "as", "$", "method", ")", "{", "if", "(", "array_key_exists", "(", "$", "method", ",", "$", "config", ")", ")", "{", "$", "this", "->", "viewBuilder", "(", ")", "->", "{", "'set'", ".", "ucfirst", "(", "$", "method", ")", "}", "(", "$", "config", "[", "$", "method", "]", ")", ";", "}", "}", "if", "(", "array_key_exists", "(", "'helpers'", ",", "$", "config", ")", ")", "{", "$", "this", "->", "viewBuilder", "(", ")", "->", "setHelpers", "(", "$", "config", "[", "'helpers'", "]", ",", "false", ")", ";", "}", "if", "(", "array_key_exists", "(", "'viewRender'", ",", "$", "config", ")", ")", "{", "$", "this", "->", "viewBuilder", "(", ")", "->", "setClassName", "(", "$", "config", "[", "'viewRender'", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "'viewVars'", ",", "$", "config", ")", ")", "{", "$", "this", "->", "set", "(", "$", "config", "[", "'viewVars'", "]", ")", ";", "}", "}" ]
Apply the config to an instance @param string|array $config Configuration options. @return void @throws \InvalidArgumentException When using a configuration that doesn't exist.
[ "Apply", "the", "config", "to", "an", "instance" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2232-L2281
211,632
cakephp/cakephp
src/Mailer/Email.php
Email.reset
public function reset() { $this->_to = []; $this->_from = []; $this->_sender = []; $this->_replyTo = []; $this->_readReceipt = []; $this->_returnPath = []; $this->_cc = []; $this->_bcc = []; $this->_messageId = true; $this->_subject = ''; $this->_headers = []; $this->_textMessage = ''; $this->_htmlMessage = ''; $this->_message = []; $this->_emailFormat = 'text'; $this->_transport = null; $this->_priority = null; $this->charset = 'utf-8'; $this->headerCharset = null; $this->transferEncoding = null; $this->_attachments = []; $this->_profile = []; $this->_emailPattern = self::EMAIL_PATTERN; $this->viewBuilder()->setLayout('default'); $this->viewBuilder()->setTemplate(''); $this->viewBuilder()->setClassName('Cake\View\View'); $this->viewVars = []; $this->viewBuilder()->setTheme(false); $this->viewBuilder()->setHelpers(['Html'], false); return $this; }
php
public function reset() { $this->_to = []; $this->_from = []; $this->_sender = []; $this->_replyTo = []; $this->_readReceipt = []; $this->_returnPath = []; $this->_cc = []; $this->_bcc = []; $this->_messageId = true; $this->_subject = ''; $this->_headers = []; $this->_textMessage = ''; $this->_htmlMessage = ''; $this->_message = []; $this->_emailFormat = 'text'; $this->_transport = null; $this->_priority = null; $this->charset = 'utf-8'; $this->headerCharset = null; $this->transferEncoding = null; $this->_attachments = []; $this->_profile = []; $this->_emailPattern = self::EMAIL_PATTERN; $this->viewBuilder()->setLayout('default'); $this->viewBuilder()->setTemplate(''); $this->viewBuilder()->setClassName('Cake\View\View'); $this->viewVars = []; $this->viewBuilder()->setTheme(false); $this->viewBuilder()->setHelpers(['Html'], false); return $this; }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "_to", "=", "[", "]", ";", "$", "this", "->", "_from", "=", "[", "]", ";", "$", "this", "->", "_sender", "=", "[", "]", ";", "$", "this", "->", "_replyTo", "=", "[", "]", ";", "$", "this", "->", "_readReceipt", "=", "[", "]", ";", "$", "this", "->", "_returnPath", "=", "[", "]", ";", "$", "this", "->", "_cc", "=", "[", "]", ";", "$", "this", "->", "_bcc", "=", "[", "]", ";", "$", "this", "->", "_messageId", "=", "true", ";", "$", "this", "->", "_subject", "=", "''", ";", "$", "this", "->", "_headers", "=", "[", "]", ";", "$", "this", "->", "_textMessage", "=", "''", ";", "$", "this", "->", "_htmlMessage", "=", "''", ";", "$", "this", "->", "_message", "=", "[", "]", ";", "$", "this", "->", "_emailFormat", "=", "'text'", ";", "$", "this", "->", "_transport", "=", "null", ";", "$", "this", "->", "_priority", "=", "null", ";", "$", "this", "->", "charset", "=", "'utf-8'", ";", "$", "this", "->", "headerCharset", "=", "null", ";", "$", "this", "->", "transferEncoding", "=", "null", ";", "$", "this", "->", "_attachments", "=", "[", "]", ";", "$", "this", "->", "_profile", "=", "[", "]", ";", "$", "this", "->", "_emailPattern", "=", "self", "::", "EMAIL_PATTERN", ";", "$", "this", "->", "viewBuilder", "(", ")", "->", "setLayout", "(", "'default'", ")", ";", "$", "this", "->", "viewBuilder", "(", ")", "->", "setTemplate", "(", "''", ")", ";", "$", "this", "->", "viewBuilder", "(", ")", "->", "setClassName", "(", "'Cake\\View\\View'", ")", ";", "$", "this", "->", "viewVars", "=", "[", "]", ";", "$", "this", "->", "viewBuilder", "(", ")", "->", "setTheme", "(", "false", ")", ";", "$", "this", "->", "viewBuilder", "(", ")", "->", "setHelpers", "(", "[", "'Html'", "]", ",", "false", ")", ";", "return", "$", "this", ";", "}" ]
Reset all the internal variables to be able to send out a new email. @return $this
[ "Reset", "all", "the", "internal", "variables", "to", "be", "able", "to", "send", "out", "a", "new", "email", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2288-L2322
211,633
cakephp/cakephp
src/Mailer/Email.php
Email._encode
protected function _encode($text) { $restore = mb_internal_encoding(); mb_internal_encoding($this->_appCharset); if (empty($this->headerCharset)) { $this->headerCharset = $this->charset; } $return = mb_encode_mimeheader($text, $this->headerCharset, 'B'); mb_internal_encoding($restore); return $return; }
php
protected function _encode($text) { $restore = mb_internal_encoding(); mb_internal_encoding($this->_appCharset); if (empty($this->headerCharset)) { $this->headerCharset = $this->charset; } $return = mb_encode_mimeheader($text, $this->headerCharset, 'B'); mb_internal_encoding($restore); return $return; }
[ "protected", "function", "_encode", "(", "$", "text", ")", "{", "$", "restore", "=", "mb_internal_encoding", "(", ")", ";", "mb_internal_encoding", "(", "$", "this", "->", "_appCharset", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "headerCharset", ")", ")", "{", "$", "this", "->", "headerCharset", "=", "$", "this", "->", "charset", ";", "}", "$", "return", "=", "mb_encode_mimeheader", "(", "$", "text", ",", "$", "this", "->", "headerCharset", ",", "'B'", ")", ";", "mb_internal_encoding", "(", "$", "restore", ")", ";", "return", "$", "return", ";", "}" ]
Encode the specified string using the current charset @param string $text String to encode @return string Encoded string
[ "Encode", "the", "specified", "string", "using", "the", "current", "charset" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2330-L2341
211,634
cakephp/cakephp
src/Mailer/Email.php
Email._decode
protected function _decode($text) { $restore = mb_internal_encoding(); mb_internal_encoding($this->_appCharset); $return = mb_decode_mimeheader($text); mb_internal_encoding($restore); return $return; }
php
protected function _decode($text) { $restore = mb_internal_encoding(); mb_internal_encoding($this->_appCharset); $return = mb_decode_mimeheader($text); mb_internal_encoding($restore); return $return; }
[ "protected", "function", "_decode", "(", "$", "text", ")", "{", "$", "restore", "=", "mb_internal_encoding", "(", ")", ";", "mb_internal_encoding", "(", "$", "this", "->", "_appCharset", ")", ";", "$", "return", "=", "mb_decode_mimeheader", "(", "$", "text", ")", ";", "mb_internal_encoding", "(", "$", "restore", ")", ";", "return", "$", "return", ";", "}" ]
Decode the specified string @param string $text String to decode @return string Decoded string
[ "Decode", "the", "specified", "string" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2349-L2357
211,635
cakephp/cakephp
src/Mailer/Email.php
Email._encodeString
protected function _encodeString($text, $charset) { if ($this->_appCharset === $charset) { return $text; } return mb_convert_encoding($text, $charset, $this->_appCharset); }
php
protected function _encodeString($text, $charset) { if ($this->_appCharset === $charset) { return $text; } return mb_convert_encoding($text, $charset, $this->_appCharset); }
[ "protected", "function", "_encodeString", "(", "$", "text", ",", "$", "charset", ")", "{", "if", "(", "$", "this", "->", "_appCharset", "===", "$", "charset", ")", "{", "return", "$", "text", ";", "}", "return", "mb_convert_encoding", "(", "$", "text", ",", "$", "charset", ",", "$", "this", "->", "_appCharset", ")", ";", "}" ]
Translates a string for one charset to another if the App.encoding value differs and the mb_convert_encoding function exists @param string $text The text to be converted @param string $charset the target encoding @return string
[ "Translates", "a", "string", "for", "one", "charset", "to", "another", "if", "the", "App", ".", "encoding", "value", "differs", "and", "the", "mb_convert_encoding", "function", "exists" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2367-L2374
211,636
cakephp/cakephp
src/Mailer/Email.php
Email._createBoundary
protected function _createBoundary() { if ($this->_attachments || $this->_emailFormat === 'both') { $this->_boundary = md5(Security::randomBytes(16)); } }
php
protected function _createBoundary() { if ($this->_attachments || $this->_emailFormat === 'both') { $this->_boundary = md5(Security::randomBytes(16)); } }
[ "protected", "function", "_createBoundary", "(", ")", "{", "if", "(", "$", "this", "->", "_attachments", "||", "$", "this", "->", "_emailFormat", "===", "'both'", ")", "{", "$", "this", "->", "_boundary", "=", "md5", "(", "Security", "::", "randomBytes", "(", "16", ")", ")", ";", "}", "}" ]
Create unique boundary identifier @return void
[ "Create", "unique", "boundary", "identifier" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2490-L2495
211,637
cakephp/cakephp
src/Mailer/Email.php
Email._attachFiles
protected function _attachFiles($boundary = null) { if ($boundary === null) { $boundary = $this->_boundary; } $msg = []; foreach ($this->_attachments as $filename => $fileInfo) { if (!empty($fileInfo['contentId'])) { continue; } $data = isset($fileInfo['data']) ? $fileInfo['data'] : $this->_readFile($fileInfo['file']); $hasDisposition = ( !isset($fileInfo['contentDisposition']) || $fileInfo['contentDisposition'] ); $part = new FormDataPart(false, $data, false); if ($hasDisposition) { $part->disposition('attachment'); $part->filename($filename); } $part->transferEncoding('base64'); $part->type($fileInfo['mimetype']); $msg[] = '--' . $boundary; $msg[] = (string)$part; $msg[] = ''; } return $msg; }
php
protected function _attachFiles($boundary = null) { if ($boundary === null) { $boundary = $this->_boundary; } $msg = []; foreach ($this->_attachments as $filename => $fileInfo) { if (!empty($fileInfo['contentId'])) { continue; } $data = isset($fileInfo['data']) ? $fileInfo['data'] : $this->_readFile($fileInfo['file']); $hasDisposition = ( !isset($fileInfo['contentDisposition']) || $fileInfo['contentDisposition'] ); $part = new FormDataPart(false, $data, false); if ($hasDisposition) { $part->disposition('attachment'); $part->filename($filename); } $part->transferEncoding('base64'); $part->type($fileInfo['mimetype']); $msg[] = '--' . $boundary; $msg[] = (string)$part; $msg[] = ''; } return $msg; }
[ "protected", "function", "_attachFiles", "(", "$", "boundary", "=", "null", ")", "{", "if", "(", "$", "boundary", "===", "null", ")", "{", "$", "boundary", "=", "$", "this", "->", "_boundary", ";", "}", "$", "msg", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "_attachments", "as", "$", "filename", "=>", "$", "fileInfo", ")", "{", "if", "(", "!", "empty", "(", "$", "fileInfo", "[", "'contentId'", "]", ")", ")", "{", "continue", ";", "}", "$", "data", "=", "isset", "(", "$", "fileInfo", "[", "'data'", "]", ")", "?", "$", "fileInfo", "[", "'data'", "]", ":", "$", "this", "->", "_readFile", "(", "$", "fileInfo", "[", "'file'", "]", ")", ";", "$", "hasDisposition", "=", "(", "!", "isset", "(", "$", "fileInfo", "[", "'contentDisposition'", "]", ")", "||", "$", "fileInfo", "[", "'contentDisposition'", "]", ")", ";", "$", "part", "=", "new", "FormDataPart", "(", "false", ",", "$", "data", ",", "false", ")", ";", "if", "(", "$", "hasDisposition", ")", "{", "$", "part", "->", "disposition", "(", "'attachment'", ")", ";", "$", "part", "->", "filename", "(", "$", "filename", ")", ";", "}", "$", "part", "->", "transferEncoding", "(", "'base64'", ")", ";", "$", "part", "->", "type", "(", "$", "fileInfo", "[", "'mimetype'", "]", ")", ";", "$", "msg", "[", "]", "=", "'--'", ".", "$", "boundary", ";", "$", "msg", "[", "]", "=", "(", "string", ")", "$", "part", ";", "$", "msg", "[", "]", "=", "''", ";", "}", "return", "$", "msg", ";", "}" ]
Attach non-embedded files by adding file contents inside boundaries. @param string|null $boundary Boundary to use. If null, will default to $this->_boundary @return array An array of lines to add to the message
[ "Attach", "non", "-", "embedded", "files", "by", "adding", "file", "contents", "inside", "boundaries", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2503-L2534
211,638
cakephp/cakephp
src/Mailer/Email.php
Email._getContentTransferEncoding
protected function _getContentTransferEncoding() { if ($this->transferEncoding) { return $this->transferEncoding; } $charset = strtoupper($this->charset); if (in_array($charset, $this->_charset8bit)) { return '8bit'; } return '7bit'; }
php
protected function _getContentTransferEncoding() { if ($this->transferEncoding) { return $this->transferEncoding; } $charset = strtoupper($this->charset); if (in_array($charset, $this->_charset8bit)) { return '8bit'; } return '7bit'; }
[ "protected", "function", "_getContentTransferEncoding", "(", ")", "{", "if", "(", "$", "this", "->", "transferEncoding", ")", "{", "return", "$", "this", "->", "transferEncoding", ";", "}", "$", "charset", "=", "strtoupper", "(", "$", "this", "->", "charset", ")", ";", "if", "(", "in_array", "(", "$", "charset", ",", "$", "this", "->", "_charset8bit", ")", ")", "{", "return", "'8bit'", ";", "}", "return", "'7bit'", ";", "}" ]
Return the Content-Transfer Encoding value based on the set transferEncoding or set charset. @return string
[ "Return", "the", "Content", "-", "Transfer", "Encoding", "value", "based", "on", "the", "set", "transferEncoding", "or", "set", "charset", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2746-L2758
211,639
cakephp/cakephp
src/Mailer/Email.php
Email._getContentTypeCharset
protected function _getContentTypeCharset() { $charset = strtoupper($this->charset); if (array_key_exists($charset, $this->_contentTypeCharset)) { return strtoupper($this->_contentTypeCharset[$charset]); } return strtoupper($this->charset); }
php
protected function _getContentTypeCharset() { $charset = strtoupper($this->charset); if (array_key_exists($charset, $this->_contentTypeCharset)) { return strtoupper($this->_contentTypeCharset[$charset]); } return strtoupper($this->charset); }
[ "protected", "function", "_getContentTypeCharset", "(", ")", "{", "$", "charset", "=", "strtoupper", "(", "$", "this", "->", "charset", ")", ";", "if", "(", "array_key_exists", "(", "$", "charset", ",", "$", "this", "->", "_contentTypeCharset", ")", ")", "{", "return", "strtoupper", "(", "$", "this", "->", "_contentTypeCharset", "[", "$", "charset", "]", ")", ";", "}", "return", "strtoupper", "(", "$", "this", "->", "charset", ")", ";", "}" ]
Return charset value for Content-Type. Checks fallback/compatibility types which include workarounds for legacy japanese character sets. @return string
[ "Return", "charset", "value", "for", "Content", "-", "Type", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2768-L2776
211,640
cakephp/cakephp
src/Mailer/Email.php
Email.jsonSerialize
public function jsonSerialize() { $properties = [ '_to', '_from', '_sender', '_replyTo', '_cc', '_bcc', '_subject', '_returnPath', '_readReceipt', '_emailFormat', '_emailPattern', '_domain', '_attachments', '_messageId', '_headers', '_appCharset', 'viewVars', 'charset', 'headerCharset' ]; $array = ['viewConfig' => $this->viewBuilder()->jsonSerialize()]; foreach ($properties as $property) { $array[$property] = $this->{$property}; } array_walk($array['_attachments'], function (&$item, $key) { if (!empty($item['file'])) { $item['data'] = $this->_readFile($item['file']); unset($item['file']); } }); array_walk_recursive($array['viewVars'], [$this, '_checkViewVars']); return array_filter($array, function ($i) { return !is_array($i) && strlen($i) || !empty($i); }); }
php
public function jsonSerialize() { $properties = [ '_to', '_from', '_sender', '_replyTo', '_cc', '_bcc', '_subject', '_returnPath', '_readReceipt', '_emailFormat', '_emailPattern', '_domain', '_attachments', '_messageId', '_headers', '_appCharset', 'viewVars', 'charset', 'headerCharset' ]; $array = ['viewConfig' => $this->viewBuilder()->jsonSerialize()]; foreach ($properties as $property) { $array[$property] = $this->{$property}; } array_walk($array['_attachments'], function (&$item, $key) { if (!empty($item['file'])) { $item['data'] = $this->_readFile($item['file']); unset($item['file']); } }); array_walk_recursive($array['viewVars'], [$this, '_checkViewVars']); return array_filter($array, function ($i) { return !is_array($i) && strlen($i) || !empty($i); }); }
[ "public", "function", "jsonSerialize", "(", ")", "{", "$", "properties", "=", "[", "'_to'", ",", "'_from'", ",", "'_sender'", ",", "'_replyTo'", ",", "'_cc'", ",", "'_bcc'", ",", "'_subject'", ",", "'_returnPath'", ",", "'_readReceipt'", ",", "'_emailFormat'", ",", "'_emailPattern'", ",", "'_domain'", ",", "'_attachments'", ",", "'_messageId'", ",", "'_headers'", ",", "'_appCharset'", ",", "'viewVars'", ",", "'charset'", ",", "'headerCharset'", "]", ";", "$", "array", "=", "[", "'viewConfig'", "=>", "$", "this", "->", "viewBuilder", "(", ")", "->", "jsonSerialize", "(", ")", "]", ";", "foreach", "(", "$", "properties", "as", "$", "property", ")", "{", "$", "array", "[", "$", "property", "]", "=", "$", "this", "->", "{", "$", "property", "}", ";", "}", "array_walk", "(", "$", "array", "[", "'_attachments'", "]", ",", "function", "(", "&", "$", "item", ",", "$", "key", ")", "{", "if", "(", "!", "empty", "(", "$", "item", "[", "'file'", "]", ")", ")", "{", "$", "item", "[", "'data'", "]", "=", "$", "this", "->", "_readFile", "(", "$", "item", "[", "'file'", "]", ")", ";", "unset", "(", "$", "item", "[", "'file'", "]", ")", ";", "}", "}", ")", ";", "array_walk_recursive", "(", "$", "array", "[", "'viewVars'", "]", ",", "[", "$", "this", ",", "'_checkViewVars'", "]", ")", ";", "return", "array_filter", "(", "$", "array", ",", "function", "(", "$", "i", ")", "{", "return", "!", "is_array", "(", "$", "i", ")", "&&", "strlen", "(", "$", "i", ")", "||", "!", "empty", "(", "$", "i", ")", ";", "}", ")", ";", "}" ]
Serializes the email object to a value that can be natively serialized and re-used to clone this email instance. It has certain limitations for viewVars that are good to know: - ORM\Query executed and stored as resultset - SimpleXMLElements stored as associative array - Exceptions stored as strings - Resources, \Closure and \PDO are not supported. @return array Serializable array of configuration properties. @throws \Exception When a view var object can not be properly serialized.
[ "Serializes", "the", "email", "object", "to", "a", "value", "that", "can", "be", "natively", "serialized", "and", "re", "-", "used", "to", "clone", "this", "email", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2792-L2818
211,641
cakephp/cakephp
src/Mailer/Email.php
Email._checkViewVars
protected function _checkViewVars(&$item, $key) { if ($item instanceof Exception) { $item = (string)$item; } if (is_resource($item) || $item instanceof Closure || $item instanceof PDO ) { throw new RuntimeException(sprintf( 'Failed serializing the `%s` %s in the `%s` view var', is_resource($item) ? get_resource_type($item) : get_class($item), is_resource($item) ? 'resource' : 'object', $key )); } }
php
protected function _checkViewVars(&$item, $key) { if ($item instanceof Exception) { $item = (string)$item; } if (is_resource($item) || $item instanceof Closure || $item instanceof PDO ) { throw new RuntimeException(sprintf( 'Failed serializing the `%s` %s in the `%s` view var', is_resource($item) ? get_resource_type($item) : get_class($item), is_resource($item) ? 'resource' : 'object', $key )); } }
[ "protected", "function", "_checkViewVars", "(", "&", "$", "item", ",", "$", "key", ")", "{", "if", "(", "$", "item", "instanceof", "Exception", ")", "{", "$", "item", "=", "(", "string", ")", "$", "item", ";", "}", "if", "(", "is_resource", "(", "$", "item", ")", "||", "$", "item", "instanceof", "Closure", "||", "$", "item", "instanceof", "PDO", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Failed serializing the `%s` %s in the `%s` view var'", ",", "is_resource", "(", "$", "item", ")", "?", "get_resource_type", "(", "$", "item", ")", ":", "get_class", "(", "$", "item", ")", ",", "is_resource", "(", "$", "item", ")", "?", "'resource'", ":", "'object'", ",", "$", "key", ")", ")", ";", "}", "}" ]
Iterates through hash to clean up and normalize. @param mixed $item Reference to the view var value. @param string $key View var key. @return void
[ "Iterates", "through", "hash", "to", "clean", "up", "and", "normalize", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2827-L2844
211,642
cakephp/cakephp
src/Mailer/Email.php
Email.createFromArray
public function createFromArray($config) { if (isset($config['viewConfig'])) { $this->viewBuilder()->createFromArray($config['viewConfig']); unset($config['viewConfig']); } foreach ($config as $property => $value) { $this->{$property} = $value; } return $this; }
php
public function createFromArray($config) { if (isset($config['viewConfig'])) { $this->viewBuilder()->createFromArray($config['viewConfig']); unset($config['viewConfig']); } foreach ($config as $property => $value) { $this->{$property} = $value; } return $this; }
[ "public", "function", "createFromArray", "(", "$", "config", ")", "{", "if", "(", "isset", "(", "$", "config", "[", "'viewConfig'", "]", ")", ")", "{", "$", "this", "->", "viewBuilder", "(", ")", "->", "createFromArray", "(", "$", "config", "[", "'viewConfig'", "]", ")", ";", "unset", "(", "$", "config", "[", "'viewConfig'", "]", ")", ";", "}", "foreach", "(", "$", "config", "as", "$", "property", "=>", "$", "value", ")", "{", "$", "this", "->", "{", "$", "property", "}", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Configures an email instance object from serialized config. @param array $config Email configuration array. @return $this Configured email instance.
[ "Configures", "an", "email", "instance", "object", "from", "serialized", "config", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2852-L2864
211,643
cakephp/cakephp
src/Mailer/Email.php
Email.serialize
public function serialize() { $array = $this->jsonSerialize(); array_walk_recursive($array, function (&$item, $key) { if ($item instanceof SimpleXMLElement) { $item = json_decode(json_encode((array)$item), true); } }); return serialize($array); }
php
public function serialize() { $array = $this->jsonSerialize(); array_walk_recursive($array, function (&$item, $key) { if ($item instanceof SimpleXMLElement) { $item = json_decode(json_encode((array)$item), true); } }); return serialize($array); }
[ "public", "function", "serialize", "(", ")", "{", "$", "array", "=", "$", "this", "->", "jsonSerialize", "(", ")", ";", "array_walk_recursive", "(", "$", "array", ",", "function", "(", "&", "$", "item", ",", "$", "key", ")", "{", "if", "(", "$", "item", "instanceof", "SimpleXMLElement", ")", "{", "$", "item", "=", "json_decode", "(", "json_encode", "(", "(", "array", ")", "$", "item", ")", ",", "true", ")", ";", "}", "}", ")", ";", "return", "serialize", "(", "$", "array", ")", ";", "}" ]
Serializes the Email object. @return string
[ "Serializes", "the", "Email", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Email.php#L2871-L2881
211,644
cakephp/cakephp
src/Log/Engine/SyslogLog.php
SyslogLog.log
public function log($level, $message, array $context = []) { if (!$this->_open) { $config = $this->_config; $this->_open($config['prefix'], $config['flag'], $config['facility']); $this->_open = true; } $priority = LOG_DEBUG; if (isset($this->_levelMap[$level])) { $priority = $this->_levelMap[$level]; } $messages = explode("\n", $this->_format($message, $context)); foreach ($messages as $message) { $message = sprintf($this->_config['format'], $level, $message); $this->_write($priority, $message); } return true; }
php
public function log($level, $message, array $context = []) { if (!$this->_open) { $config = $this->_config; $this->_open($config['prefix'], $config['flag'], $config['facility']); $this->_open = true; } $priority = LOG_DEBUG; if (isset($this->_levelMap[$level])) { $priority = $this->_levelMap[$level]; } $messages = explode("\n", $this->_format($message, $context)); foreach ($messages as $message) { $message = sprintf($this->_config['format'], $level, $message); $this->_write($priority, $message); } return true; }
[ "public", "function", "log", "(", "$", "level", ",", "$", "message", ",", "array", "$", "context", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "_open", ")", "{", "$", "config", "=", "$", "this", "->", "_config", ";", "$", "this", "->", "_open", "(", "$", "config", "[", "'prefix'", "]", ",", "$", "config", "[", "'flag'", "]", ",", "$", "config", "[", "'facility'", "]", ")", ";", "$", "this", "->", "_open", "=", "true", ";", "}", "$", "priority", "=", "LOG_DEBUG", ";", "if", "(", "isset", "(", "$", "this", "->", "_levelMap", "[", "$", "level", "]", ")", ")", "{", "$", "priority", "=", "$", "this", "->", "_levelMap", "[", "$", "level", "]", ";", "}", "$", "messages", "=", "explode", "(", "\"\\n\"", ",", "$", "this", "->", "_format", "(", "$", "message", ",", "$", "context", ")", ")", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "message", "=", "sprintf", "(", "$", "this", "->", "_config", "[", "'format'", "]", ",", "$", "level", ",", "$", "message", ")", ";", "$", "this", "->", "_write", "(", "$", "priority", ",", "$", "message", ")", ";", "}", "return", "true", ";", "}" ]
Writes a message to syslog Map the $level back to a LOG_ constant value, split multi-line messages into multiple log messages, pass all messages through the format defined in the configuration @param string $level The severity level of log you are making. @param string $message The message you want to log. @param array $context Additional information about the logged message @return bool success of write.
[ "Writes", "a", "message", "to", "syslog" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Log/Engine/SyslogLog.php#L94-L114
211,645
cakephp/cakephp
src/I18n/Parser/MoFileParser.php
MoFileParser._readLong
protected function _readLong($stream, $isBigEndian) { $result = unpack($isBigEndian ? 'N1' : 'V1', fread($stream, 4)); $result = current($result); return (int)substr($result, -8); }
php
protected function _readLong($stream, $isBigEndian) { $result = unpack($isBigEndian ? 'N1' : 'V1', fread($stream, 4)); $result = current($result); return (int)substr($result, -8); }
[ "protected", "function", "_readLong", "(", "$", "stream", ",", "$", "isBigEndian", ")", "{", "$", "result", "=", "unpack", "(", "$", "isBigEndian", "?", "'N1'", ":", "'V1'", ",", "fread", "(", "$", "stream", ",", "4", ")", ")", ";", "$", "result", "=", "current", "(", "$", "result", ")", ";", "return", "(", "int", ")", "substr", "(", "$", "result", ",", "-", "8", ")", ";", "}" ]
Reads an unsigned long from stream respecting endianess. @param resource $stream The File being read. @param bool $isBigEndian Whether or not the current platform is Big Endian @return int
[ "Reads", "an", "unsigned", "long", "from", "stream", "respecting", "endianess", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Parser/MoFileParser.php#L155-L161
211,646
cakephp/cakephp
src/Database/IdentifierQuoter.php
IdentifierQuoter.quote
public function quote(Query $query) { $binder = $query->getValueBinder(); $query->setValueBinder(false); if ($query->type() === 'insert') { $this->_quoteInsert($query); } elseif ($query->type() === 'update') { $this->_quoteUpdate($query); } else { $this->_quoteParts($query); } $query->traverseExpressions([$this, 'quoteExpression']); $query->setValueBinder($binder); return $query; }
php
public function quote(Query $query) { $binder = $query->getValueBinder(); $query->setValueBinder(false); if ($query->type() === 'insert') { $this->_quoteInsert($query); } elseif ($query->type() === 'update') { $this->_quoteUpdate($query); } else { $this->_quoteParts($query); } $query->traverseExpressions([$this, 'quoteExpression']); $query->setValueBinder($binder); return $query; }
[ "public", "function", "quote", "(", "Query", "$", "query", ")", "{", "$", "binder", "=", "$", "query", "->", "getValueBinder", "(", ")", ";", "$", "query", "->", "setValueBinder", "(", "false", ")", ";", "if", "(", "$", "query", "->", "type", "(", ")", "===", "'insert'", ")", "{", "$", "this", "->", "_quoteInsert", "(", "$", "query", ")", ";", "}", "elseif", "(", "$", "query", "->", "type", "(", ")", "===", "'update'", ")", "{", "$", "this", "->", "_quoteUpdate", "(", "$", "query", ")", ";", "}", "else", "{", "$", "this", "->", "_quoteParts", "(", "$", "query", ")", ";", "}", "$", "query", "->", "traverseExpressions", "(", "[", "$", "this", ",", "'quoteExpression'", "]", ")", ";", "$", "query", "->", "setValueBinder", "(", "$", "binder", ")", ";", "return", "$", "query", ";", "}" ]
Iterates over each of the clauses in a query looking for identifiers and quotes them @param \Cake\Database\Query $query The query to have its identifiers quoted @return \Cake\Database\Query
[ "Iterates", "over", "each", "of", "the", "clauses", "in", "a", "query", "looking", "for", "identifiers", "and", "quotes", "them" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/IdentifierQuoter.php#L53-L70
211,647
cakephp/cakephp
src/Database/IdentifierQuoter.php
IdentifierQuoter.quoteExpression
public function quoteExpression($expression) { if ($expression instanceof FieldInterface) { $this->_quoteComparison($expression); return; } if ($expression instanceof OrderByExpression) { $this->_quoteOrderBy($expression); return; } if ($expression instanceof IdentifierExpression) { $this->_quoteIdentifierExpression($expression); return; } }
php
public function quoteExpression($expression) { if ($expression instanceof FieldInterface) { $this->_quoteComparison($expression); return; } if ($expression instanceof OrderByExpression) { $this->_quoteOrderBy($expression); return; } if ($expression instanceof IdentifierExpression) { $this->_quoteIdentifierExpression($expression); return; } }
[ "public", "function", "quoteExpression", "(", "$", "expression", ")", "{", "if", "(", "$", "expression", "instanceof", "FieldInterface", ")", "{", "$", "this", "->", "_quoteComparison", "(", "$", "expression", ")", ";", "return", ";", "}", "if", "(", "$", "expression", "instanceof", "OrderByExpression", ")", "{", "$", "this", "->", "_quoteOrderBy", "(", "$", "expression", ")", ";", "return", ";", "}", "if", "(", "$", "expression", "instanceof", "IdentifierExpression", ")", "{", "$", "this", "->", "_quoteIdentifierExpression", "(", "$", "expression", ")", ";", "return", ";", "}", "}" ]
Quotes identifiers inside expression objects @param \Cake\Database\ExpressionInterface $expression The expression object to walk and quote. @return void
[ "Quotes", "identifiers", "inside", "expression", "objects" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/IdentifierQuoter.php#L78-L97
211,648
cakephp/cakephp
src/Database/IdentifierQuoter.php
IdentifierQuoter._quoteParts
protected function _quoteParts($query) { foreach (['distinct', 'select', 'from', 'group'] as $part) { $contents = $query->clause($part); if (!is_array($contents)) { continue; } $result = $this->_basicQuoter($contents); if (!empty($result)) { $query->{$part}($result, true); } } $joins = $query->clause('join'); if ($joins) { $joins = $this->_quoteJoins($joins); $query->join($joins, [], true); } }
php
protected function _quoteParts($query) { foreach (['distinct', 'select', 'from', 'group'] as $part) { $contents = $query->clause($part); if (!is_array($contents)) { continue; } $result = $this->_basicQuoter($contents); if (!empty($result)) { $query->{$part}($result, true); } } $joins = $query->clause('join'); if ($joins) { $joins = $this->_quoteJoins($joins); $query->join($joins, [], true); } }
[ "protected", "function", "_quoteParts", "(", "$", "query", ")", "{", "foreach", "(", "[", "'distinct'", ",", "'select'", ",", "'from'", ",", "'group'", "]", "as", "$", "part", ")", "{", "$", "contents", "=", "$", "query", "->", "clause", "(", "$", "part", ")", ";", "if", "(", "!", "is_array", "(", "$", "contents", ")", ")", "{", "continue", ";", "}", "$", "result", "=", "$", "this", "->", "_basicQuoter", "(", "$", "contents", ")", ";", "if", "(", "!", "empty", "(", "$", "result", ")", ")", "{", "$", "query", "->", "{", "$", "part", "}", "(", "$", "result", ",", "true", ")", ";", "}", "}", "$", "joins", "=", "$", "query", "->", "clause", "(", "'join'", ")", ";", "if", "(", "$", "joins", ")", "{", "$", "joins", "=", "$", "this", "->", "_quoteJoins", "(", "$", "joins", ")", ";", "$", "query", "->", "join", "(", "$", "joins", ",", "[", "]", ",", "true", ")", ";", "}", "}" ]
Quotes all identifiers in each of the clauses of a query @param \Cake\Database\Query $query The query to quote. @return void
[ "Quotes", "all", "identifiers", "in", "each", "of", "the", "clauses", "of", "a", "query" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/IdentifierQuoter.php#L105-L125
211,649
cakephp/cakephp
src/Database/IdentifierQuoter.php
IdentifierQuoter._basicQuoter
protected function _basicQuoter($part) { $result = []; foreach ((array)$part as $alias => $value) { $value = !is_string($value) ? $value : $this->_driver->quoteIdentifier($value); $alias = is_numeric($alias) ? $alias : $this->_driver->quoteIdentifier($alias); $result[$alias] = $value; } return $result; }
php
protected function _basicQuoter($part) { $result = []; foreach ((array)$part as $alias => $value) { $value = !is_string($value) ? $value : $this->_driver->quoteIdentifier($value); $alias = is_numeric($alias) ? $alias : $this->_driver->quoteIdentifier($alias); $result[$alias] = $value; } return $result; }
[ "protected", "function", "_basicQuoter", "(", "$", "part", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "part", "as", "$", "alias", "=>", "$", "value", ")", "{", "$", "value", "=", "!", "is_string", "(", "$", "value", ")", "?", "$", "value", ":", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "value", ")", ";", "$", "alias", "=", "is_numeric", "(", "$", "alias", ")", "?", "$", "alias", ":", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "alias", ")", ";", "$", "result", "[", "$", "alias", "]", "=", "$", "value", ";", "}", "return", "$", "result", ";", "}" ]
A generic identifier quoting function used for various parts of the query @param array $part the part of the query to quote @return array
[ "A", "generic", "identifier", "quoting", "function", "used", "for", "various", "parts", "of", "the", "query" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/IdentifierQuoter.php#L133-L143
211,650
cakephp/cakephp
src/Database/IdentifierQuoter.php
IdentifierQuoter._quoteJoins
protected function _quoteJoins($joins) { $result = []; foreach ($joins as $value) { $alias = null; if (!empty($value['alias'])) { $alias = $this->_driver->quoteIdentifier($value['alias']); $value['alias'] = $alias; } if (is_string($value['table'])) { $value['table'] = $this->_driver->quoteIdentifier($value['table']); } $result[$alias] = $value; } return $result; }
php
protected function _quoteJoins($joins) { $result = []; foreach ($joins as $value) { $alias = null; if (!empty($value['alias'])) { $alias = $this->_driver->quoteIdentifier($value['alias']); $value['alias'] = $alias; } if (is_string($value['table'])) { $value['table'] = $this->_driver->quoteIdentifier($value['table']); } $result[$alias] = $value; } return $result; }
[ "protected", "function", "_quoteJoins", "(", "$", "joins", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "joins", "as", "$", "value", ")", "{", "$", "alias", "=", "null", ";", "if", "(", "!", "empty", "(", "$", "value", "[", "'alias'", "]", ")", ")", "{", "$", "alias", "=", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "value", "[", "'alias'", "]", ")", ";", "$", "value", "[", "'alias'", "]", "=", "$", "alias", ";", "}", "if", "(", "is_string", "(", "$", "value", "[", "'table'", "]", ")", ")", "{", "$", "value", "[", "'table'", "]", "=", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "value", "[", "'table'", "]", ")", ";", "}", "$", "result", "[", "$", "alias", "]", "=", "$", "value", ";", "}", "return", "$", "result", ";", "}" ]
Quotes both the table and alias for an array of joins as stored in a Query object @param array $joins The joins to quote. @return array
[ "Quotes", "both", "the", "table", "and", "alias", "for", "an", "array", "of", "joins", "as", "stored", "in", "a", "Query", "object" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/IdentifierQuoter.php#L152-L170
211,651
cakephp/cakephp
src/Database/IdentifierQuoter.php
IdentifierQuoter._quoteInsert
protected function _quoteInsert($query) { list($table, $columns) = $query->clause('insert'); $table = $this->_driver->quoteIdentifier($table); foreach ($columns as &$column) { if (is_scalar($column)) { $column = $this->_driver->quoteIdentifier($column); } } $query->insert($columns)->into($table); }
php
protected function _quoteInsert($query) { list($table, $columns) = $query->clause('insert'); $table = $this->_driver->quoteIdentifier($table); foreach ($columns as &$column) { if (is_scalar($column)) { $column = $this->_driver->quoteIdentifier($column); } } $query->insert($columns)->into($table); }
[ "protected", "function", "_quoteInsert", "(", "$", "query", ")", "{", "list", "(", "$", "table", ",", "$", "columns", ")", "=", "$", "query", "->", "clause", "(", "'insert'", ")", ";", "$", "table", "=", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "table", ")", ";", "foreach", "(", "$", "columns", "as", "&", "$", "column", ")", "{", "if", "(", "is_scalar", "(", "$", "column", ")", ")", "{", "$", "column", "=", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "column", ")", ";", "}", "}", "$", "query", "->", "insert", "(", "$", "columns", ")", "->", "into", "(", "$", "table", ")", ";", "}" ]
Quotes the table name and columns for an insert query @param \Cake\Database\Query $query The insert query to quote. @return void
[ "Quotes", "the", "table", "name", "and", "columns", "for", "an", "insert", "query" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/IdentifierQuoter.php#L178-L188
211,652
cakephp/cakephp
src/Database/IdentifierQuoter.php
IdentifierQuoter._quoteUpdate
protected function _quoteUpdate($query) { $table = $query->clause('update')[0]; if (is_string($table)) { $query->update($this->_driver->quoteIdentifier($table)); } }
php
protected function _quoteUpdate($query) { $table = $query->clause('update')[0]; if (is_string($table)) { $query->update($this->_driver->quoteIdentifier($table)); } }
[ "protected", "function", "_quoteUpdate", "(", "$", "query", ")", "{", "$", "table", "=", "$", "query", "->", "clause", "(", "'update'", ")", "[", "0", "]", ";", "if", "(", "is_string", "(", "$", "table", ")", ")", "{", "$", "query", "->", "update", "(", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "table", ")", ")", ";", "}", "}" ]
Quotes the table name for an update query @param \Cake\Database\Query $query The update query to quote. @return void
[ "Quotes", "the", "table", "name", "for", "an", "update", "query" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/IdentifierQuoter.php#L196-L203
211,653
cakephp/cakephp
src/Database/IdentifierQuoter.php
IdentifierQuoter._quoteComparison
protected function _quoteComparison(FieldInterface $expression) { $field = $expression->getField(); if (is_string($field)) { $expression->setField($this->_driver->quoteIdentifier($field)); } elseif (is_array($field)) { $quoted = []; foreach ($field as $f) { $quoted[] = $this->_driver->quoteIdentifier($f); } $expression->setField($quoted); } elseif ($field instanceof ExpressionInterface) { $this->quoteExpression($field); } }
php
protected function _quoteComparison(FieldInterface $expression) { $field = $expression->getField(); if (is_string($field)) { $expression->setField($this->_driver->quoteIdentifier($field)); } elseif (is_array($field)) { $quoted = []; foreach ($field as $f) { $quoted[] = $this->_driver->quoteIdentifier($f); } $expression->setField($quoted); } elseif ($field instanceof ExpressionInterface) { $this->quoteExpression($field); } }
[ "protected", "function", "_quoteComparison", "(", "FieldInterface", "$", "expression", ")", "{", "$", "field", "=", "$", "expression", "->", "getField", "(", ")", ";", "if", "(", "is_string", "(", "$", "field", ")", ")", "{", "$", "expression", "->", "setField", "(", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "field", ")", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "field", ")", ")", "{", "$", "quoted", "=", "[", "]", ";", "foreach", "(", "$", "field", "as", "$", "f", ")", "{", "$", "quoted", "[", "]", "=", "$", "this", "->", "_driver", "->", "quoteIdentifier", "(", "$", "f", ")", ";", "}", "$", "expression", "->", "setField", "(", "$", "quoted", ")", ";", "}", "elseif", "(", "$", "field", "instanceof", "ExpressionInterface", ")", "{", "$", "this", "->", "quoteExpression", "(", "$", "field", ")", ";", "}", "}" ]
Quotes identifiers in expression objects implementing the field interface @param \Cake\Database\Expression\FieldInterface $expression The expression to quote. @return void
[ "Quotes", "identifiers", "in", "expression", "objects", "implementing", "the", "field", "interface" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/IdentifierQuoter.php#L211-L225
211,654
cakephp/cakephp
src/View/Cell.php
Cell.render
public function render($template = null) { $cache = []; if ($this->_cache) { $cache = $this->_cacheConfig($this->action, $template); } $render = function () use ($template) { try { $reflect = new ReflectionMethod($this, $this->action); $reflect->invokeArgs($this, $this->args); } catch (ReflectionException $e) { throw new BadMethodCallException(sprintf( 'Class %s does not have a "%s" method.', get_class($this), $this->action )); } $builder = $this->viewBuilder()->setLayout(false); if ($template !== null && strpos($template, '/') === false && strpos($template, '.') === false ) { $template = Inflector::underscore($template); } if ($template !== null) { $builder->setTemplate($template); } $className = get_class($this); $namePrefix = '\View\Cell\\'; $name = substr($className, strpos($className, $namePrefix) + strlen($namePrefix)); $name = substr($name, 0, -4); if (!$builder->getTemplatePath()) { $builder->setTemplatePath('Cell' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $name)); } $template = $builder->getTemplate(); $this->View = $this->createView(); try { return $this->View->render($template); } catch (MissingTemplateException $e) { throw new MissingCellViewException(['file' => $template, 'name' => $name], null, $e); } }; if ($cache) { return Cache::remember($cache['key'], $render, $cache['config']); } return $render(); }
php
public function render($template = null) { $cache = []; if ($this->_cache) { $cache = $this->_cacheConfig($this->action, $template); } $render = function () use ($template) { try { $reflect = new ReflectionMethod($this, $this->action); $reflect->invokeArgs($this, $this->args); } catch (ReflectionException $e) { throw new BadMethodCallException(sprintf( 'Class %s does not have a "%s" method.', get_class($this), $this->action )); } $builder = $this->viewBuilder()->setLayout(false); if ($template !== null && strpos($template, '/') === false && strpos($template, '.') === false ) { $template = Inflector::underscore($template); } if ($template !== null) { $builder->setTemplate($template); } $className = get_class($this); $namePrefix = '\View\Cell\\'; $name = substr($className, strpos($className, $namePrefix) + strlen($namePrefix)); $name = substr($name, 0, -4); if (!$builder->getTemplatePath()) { $builder->setTemplatePath('Cell' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $name)); } $template = $builder->getTemplate(); $this->View = $this->createView(); try { return $this->View->render($template); } catch (MissingTemplateException $e) { throw new MissingCellViewException(['file' => $template, 'name' => $name], null, $e); } }; if ($cache) { return Cache::remember($cache['key'], $render, $cache['config']); } return $render(); }
[ "public", "function", "render", "(", "$", "template", "=", "null", ")", "{", "$", "cache", "=", "[", "]", ";", "if", "(", "$", "this", "->", "_cache", ")", "{", "$", "cache", "=", "$", "this", "->", "_cacheConfig", "(", "$", "this", "->", "action", ",", "$", "template", ")", ";", "}", "$", "render", "=", "function", "(", ")", "use", "(", "$", "template", ")", "{", "try", "{", "$", "reflect", "=", "new", "ReflectionMethod", "(", "$", "this", ",", "$", "this", "->", "action", ")", ";", "$", "reflect", "->", "invokeArgs", "(", "$", "this", ",", "$", "this", "->", "args", ")", ";", "}", "catch", "(", "ReflectionException", "$", "e", ")", "{", "throw", "new", "BadMethodCallException", "(", "sprintf", "(", "'Class %s does not have a \"%s\" method.'", ",", "get_class", "(", "$", "this", ")", ",", "$", "this", "->", "action", ")", ")", ";", "}", "$", "builder", "=", "$", "this", "->", "viewBuilder", "(", ")", "->", "setLayout", "(", "false", ")", ";", "if", "(", "$", "template", "!==", "null", "&&", "strpos", "(", "$", "template", ",", "'/'", ")", "===", "false", "&&", "strpos", "(", "$", "template", ",", "'.'", ")", "===", "false", ")", "{", "$", "template", "=", "Inflector", "::", "underscore", "(", "$", "template", ")", ";", "}", "if", "(", "$", "template", "!==", "null", ")", "{", "$", "builder", "->", "setTemplate", "(", "$", "template", ")", ";", "}", "$", "className", "=", "get_class", "(", "$", "this", ")", ";", "$", "namePrefix", "=", "'\\View\\Cell\\\\'", ";", "$", "name", "=", "substr", "(", "$", "className", ",", "strpos", "(", "$", "className", ",", "$", "namePrefix", ")", "+", "strlen", "(", "$", "namePrefix", ")", ")", ";", "$", "name", "=", "substr", "(", "$", "name", ",", "0", ",", "-", "4", ")", ";", "if", "(", "!", "$", "builder", "->", "getTemplatePath", "(", ")", ")", "{", "$", "builder", "->", "setTemplatePath", "(", "'Cell'", ".", "DIRECTORY_SEPARATOR", ".", "str_replace", "(", "'\\\\'", ",", "DIRECTORY_SEPARATOR", ",", "$", "name", ")", ")", ";", "}", "$", "template", "=", "$", "builder", "->", "getTemplate", "(", ")", ";", "$", "this", "->", "View", "=", "$", "this", "->", "createView", "(", ")", ";", "try", "{", "return", "$", "this", "->", "View", "->", "render", "(", "$", "template", ")", ";", "}", "catch", "(", "MissingTemplateException", "$", "e", ")", "{", "throw", "new", "MissingCellViewException", "(", "[", "'file'", "=>", "$", "template", ",", "'name'", "=>", "$", "name", "]", ",", "null", ",", "$", "e", ")", ";", "}", "}", ";", "if", "(", "$", "cache", ")", "{", "return", "Cache", "::", "remember", "(", "$", "cache", "[", "'key'", "]", ",", "$", "render", ",", "$", "cache", "[", "'config'", "]", ")", ";", "}", "return", "$", "render", "(", ")", ";", "}" ]
Render the cell. @param string|null $template Custom template name to render. If not provided (null), the last value will be used. This value is automatically set by `CellTrait::cell()`. @return string The rendered cell. @throws \Cake\View\Exception\MissingCellViewException When a MissingTemplateException is raised during rendering.
[ "Render", "the", "cell", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Cell.php#L163-L216
211,655
cakephp/cakephp
src/View/Cell.php
Cell._cacheConfig
protected function _cacheConfig($action, $template = null) { if (empty($this->_cache)) { return []; } $template = $template ?: 'default'; $key = 'cell_' . Inflector::underscore(get_class($this)) . '_' . $action . '_' . $template; $key = str_replace('\\', '_', $key); $default = [ 'config' => 'default', 'key' => $key ]; if ($this->_cache === true) { return $default; } return $this->_cache + $default; }
php
protected function _cacheConfig($action, $template = null) { if (empty($this->_cache)) { return []; } $template = $template ?: 'default'; $key = 'cell_' . Inflector::underscore(get_class($this)) . '_' . $action . '_' . $template; $key = str_replace('\\', '_', $key); $default = [ 'config' => 'default', 'key' => $key ]; if ($this->_cache === true) { return $default; } return $this->_cache + $default; }
[ "protected", "function", "_cacheConfig", "(", "$", "action", ",", "$", "template", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_cache", ")", ")", "{", "return", "[", "]", ";", "}", "$", "template", "=", "$", "template", "?", ":", "'default'", ";", "$", "key", "=", "'cell_'", ".", "Inflector", "::", "underscore", "(", "get_class", "(", "$", "this", ")", ")", ".", "'_'", ".", "$", "action", ".", "'_'", ".", "$", "template", ";", "$", "key", "=", "str_replace", "(", "'\\\\'", ",", "'_'", ",", "$", "key", ")", ";", "$", "default", "=", "[", "'config'", "=>", "'default'", ",", "'key'", "=>", "$", "key", "]", ";", "if", "(", "$", "this", "->", "_cache", "===", "true", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "_cache", "+", "$", "default", ";", "}" ]
Generate the cache key to use for this cell. If the key is undefined, the cell class and action name will be used. @param string $action The action invoked. @param string|null $template The name of the template to be rendered. @return array The cache configuration.
[ "Generate", "the", "cache", "key", "to", "use", "for", "this", "cell", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Cell.php#L227-L244
211,656
cakephp/cakephp
src/Database/Type/UuidType.php
UuidType.toDatabase
public function toDatabase($value, Driver $driver) { if ($value === null || $value === '') { return null; } return parent::toDatabase($value, $driver); }
php
public function toDatabase($value, Driver $driver) { if ($value === null || $value === '') { return null; } return parent::toDatabase($value, $driver); }
[ "public", "function", "toDatabase", "(", "$", "value", ",", "Driver", "$", "driver", ")", "{", "if", "(", "$", "value", "===", "null", "||", "$", "value", "===", "''", ")", "{", "return", "null", ";", "}", "return", "parent", "::", "toDatabase", "(", "$", "value", ",", "$", "driver", ")", ";", "}" ]
Casts given value from a PHP type to one acceptable by database @param mixed $value value to be converted to database equivalent @param \Cake\Database\Driver $driver object from which database preferences and configuration will be extracted @return string|null
[ "Casts", "given", "value", "from", "a", "PHP", "type", "to", "one", "acceptable", "by", "database" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/UuidType.php#L33-L40
211,657
cakephp/cakephp
src/Database/Type/UuidType.php
UuidType.marshal
public function marshal($value) { if ($value === null || $value === '' || is_array($value)) { return null; } return (string)$value; }
php
public function marshal($value) { if ($value === null || $value === '' || is_array($value)) { return null; } return (string)$value; }
[ "public", "function", "marshal", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "null", "||", "$", "value", "===", "''", "||", "is_array", "(", "$", "value", ")", ")", "{", "return", "null", ";", "}", "return", "(", "string", ")", "$", "value", ";", "}" ]
Marshals request data into a PHP string @param mixed $value The value to convert. @return string|null Converted value.
[ "Marshals", "request", "data", "into", "a", "PHP", "string" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/UuidType.php#L58-L65
211,658
cakephp/cakephp
src/Cache/Engine/RedisEngine.php
RedisEngine._connect
protected function _connect() { try { $this->_Redis = new Redis(); if (!empty($this->_config['unix_socket'])) { $return = $this->_Redis->connect($this->_config['unix_socket']); } elseif (empty($this->_config['persistent'])) { $return = $this->_Redis->connect($this->_config['server'], $this->_config['port'], $this->_config['timeout']); } else { $persistentId = $this->_config['port'] . $this->_config['timeout'] . $this->_config['database']; $return = $this->_Redis->pconnect($this->_config['server'], $this->_config['port'], $this->_config['timeout'], $persistentId); } } catch (RedisException $e) { return false; } if ($return && $this->_config['password']) { $return = $this->_Redis->auth($this->_config['password']); } if ($return) { $return = $this->_Redis->select($this->_config['database']); } return $return; }
php
protected function _connect() { try { $this->_Redis = new Redis(); if (!empty($this->_config['unix_socket'])) { $return = $this->_Redis->connect($this->_config['unix_socket']); } elseif (empty($this->_config['persistent'])) { $return = $this->_Redis->connect($this->_config['server'], $this->_config['port'], $this->_config['timeout']); } else { $persistentId = $this->_config['port'] . $this->_config['timeout'] . $this->_config['database']; $return = $this->_Redis->pconnect($this->_config['server'], $this->_config['port'], $this->_config['timeout'], $persistentId); } } catch (RedisException $e) { return false; } if ($return && $this->_config['password']) { $return = $this->_Redis->auth($this->_config['password']); } if ($return) { $return = $this->_Redis->select($this->_config['database']); } return $return; }
[ "protected", "function", "_connect", "(", ")", "{", "try", "{", "$", "this", "->", "_Redis", "=", "new", "Redis", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_config", "[", "'unix_socket'", "]", ")", ")", "{", "$", "return", "=", "$", "this", "->", "_Redis", "->", "connect", "(", "$", "this", "->", "_config", "[", "'unix_socket'", "]", ")", ";", "}", "elseif", "(", "empty", "(", "$", "this", "->", "_config", "[", "'persistent'", "]", ")", ")", "{", "$", "return", "=", "$", "this", "->", "_Redis", "->", "connect", "(", "$", "this", "->", "_config", "[", "'server'", "]", ",", "$", "this", "->", "_config", "[", "'port'", "]", ",", "$", "this", "->", "_config", "[", "'timeout'", "]", ")", ";", "}", "else", "{", "$", "persistentId", "=", "$", "this", "->", "_config", "[", "'port'", "]", ".", "$", "this", "->", "_config", "[", "'timeout'", "]", ".", "$", "this", "->", "_config", "[", "'database'", "]", ";", "$", "return", "=", "$", "this", "->", "_Redis", "->", "pconnect", "(", "$", "this", "->", "_config", "[", "'server'", "]", ",", "$", "this", "->", "_config", "[", "'port'", "]", ",", "$", "this", "->", "_config", "[", "'timeout'", "]", ",", "$", "persistentId", ")", ";", "}", "}", "catch", "(", "RedisException", "$", "e", ")", "{", "return", "false", ";", "}", "if", "(", "$", "return", "&&", "$", "this", "->", "_config", "[", "'password'", "]", ")", "{", "$", "return", "=", "$", "this", "->", "_Redis", "->", "auth", "(", "$", "this", "->", "_config", "[", "'password'", "]", ")", ";", "}", "if", "(", "$", "return", ")", "{", "$", "return", "=", "$", "this", "->", "_Redis", "->", "select", "(", "$", "this", "->", "_config", "[", "'database'", "]", ")", ";", "}", "return", "$", "return", ";", "}" ]
Connects to a Redis server @return bool True if Redis server was connected
[ "Connects", "to", "a", "Redis", "server" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/RedisEngine.php#L98-L121
211,659
cakephp/cakephp
src/Cache/Engine/RedisEngine.php
RedisEngine.increment
public function increment($key, $offset = 1) { $duration = $this->_config['duration']; $key = $this->_key($key); $value = (int)$this->_Redis->incrBy($key, $offset); if ($duration > 0) { $this->_Redis->setTimeout($key, $duration); } return $value; }
php
public function increment($key, $offset = 1) { $duration = $this->_config['duration']; $key = $this->_key($key); $value = (int)$this->_Redis->incrBy($key, $offset); if ($duration > 0) { $this->_Redis->setTimeout($key, $duration); } return $value; }
[ "public", "function", "increment", "(", "$", "key", ",", "$", "offset", "=", "1", ")", "{", "$", "duration", "=", "$", "this", "->", "_config", "[", "'duration'", "]", ";", "$", "key", "=", "$", "this", "->", "_key", "(", "$", "key", ")", ";", "$", "value", "=", "(", "int", ")", "$", "this", "->", "_Redis", "->", "incrBy", "(", "$", "key", ",", "$", "offset", ")", ";", "if", "(", "$", "duration", ">", "0", ")", "{", "$", "this", "->", "_Redis", "->", "setTimeout", "(", "$", "key", ",", "$", "duration", ")", ";", "}", "return", "$", "value", ";", "}" ]
Increments the value of an integer cached key & update the expiry time @param string $key Identifier for the data @param int $offset How much to increment @return bool|int New incremented value, false otherwise
[ "Increments", "the", "value", "of", "an", "integer", "cached", "key", "&", "update", "the", "expiry", "time" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/RedisEngine.php#L174-L185
211,660
cakephp/cakephp
src/Cache/Engine/RedisEngine.php
RedisEngine.decrement
public function decrement($key, $offset = 1) { $duration = $this->_config['duration']; $key = $this->_key($key); $value = (int)$this->_Redis->decrBy($key, $offset); if ($duration > 0) { $this->_Redis->setTimeout($key, $duration); } return $value; }
php
public function decrement($key, $offset = 1) { $duration = $this->_config['duration']; $key = $this->_key($key); $value = (int)$this->_Redis->decrBy($key, $offset); if ($duration > 0) { $this->_Redis->setTimeout($key, $duration); } return $value; }
[ "public", "function", "decrement", "(", "$", "key", ",", "$", "offset", "=", "1", ")", "{", "$", "duration", "=", "$", "this", "->", "_config", "[", "'duration'", "]", ";", "$", "key", "=", "$", "this", "->", "_key", "(", "$", "key", ")", ";", "$", "value", "=", "(", "int", ")", "$", "this", "->", "_Redis", "->", "decrBy", "(", "$", "key", ",", "$", "offset", ")", ";", "if", "(", "$", "duration", ">", "0", ")", "{", "$", "this", "->", "_Redis", "->", "setTimeout", "(", "$", "key", ",", "$", "duration", ")", ";", "}", "return", "$", "value", ";", "}" ]
Decrements the value of an integer cached key & update the expiry time @param string $key Identifier for the data @param int $offset How much to subtract @return bool|int New decremented value, false otherwise
[ "Decrements", "the", "value", "of", "an", "integer", "cached", "key", "&", "update", "the", "expiry", "time" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/RedisEngine.php#L194-L205
211,661
cakephp/cakephp
src/Network/Socket.php
Socket.connect
public function connect() { if ($this->connection) { $this->disconnect(); } $hasProtocol = strpos($this->_config['host'], '://') !== false; if ($hasProtocol) { list($this->_config['protocol'], $this->_config['host']) = explode('://', $this->_config['host']); } $scheme = null; if (!empty($this->_config['protocol'])) { $scheme = $this->_config['protocol'] . '://'; } $this->_setSslContext($this->_config['host']); if (!empty($this->_config['context'])) { $context = stream_context_create($this->_config['context']); } else { $context = stream_context_create(); } $connectAs = STREAM_CLIENT_CONNECT; if ($this->_config['persistent']) { $connectAs |= STREAM_CLIENT_PERSISTENT; } set_error_handler([$this, '_connectionErrorHandler']); $this->connection = stream_socket_client( $scheme . $this->_config['host'] . ':' . $this->_config['port'], $errNum, $errStr, $this->_config['timeout'], $connectAs, $context ); restore_error_handler(); if (!empty($errNum) || !empty($errStr)) { $this->setLastError($errNum, $errStr); throw new SocketException($errStr, $errNum); } if (!$this->connection && $this->_connectionErrors) { $message = implode("\n", $this->_connectionErrors); throw new SocketException($message, E_WARNING); } $this->connected = is_resource($this->connection); if ($this->connected) { stream_set_timeout($this->connection, $this->_config['timeout']); } return $this->connected; }
php
public function connect() { if ($this->connection) { $this->disconnect(); } $hasProtocol = strpos($this->_config['host'], '://') !== false; if ($hasProtocol) { list($this->_config['protocol'], $this->_config['host']) = explode('://', $this->_config['host']); } $scheme = null; if (!empty($this->_config['protocol'])) { $scheme = $this->_config['protocol'] . '://'; } $this->_setSslContext($this->_config['host']); if (!empty($this->_config['context'])) { $context = stream_context_create($this->_config['context']); } else { $context = stream_context_create(); } $connectAs = STREAM_CLIENT_CONNECT; if ($this->_config['persistent']) { $connectAs |= STREAM_CLIENT_PERSISTENT; } set_error_handler([$this, '_connectionErrorHandler']); $this->connection = stream_socket_client( $scheme . $this->_config['host'] . ':' . $this->_config['port'], $errNum, $errStr, $this->_config['timeout'], $connectAs, $context ); restore_error_handler(); if (!empty($errNum) || !empty($errStr)) { $this->setLastError($errNum, $errStr); throw new SocketException($errStr, $errNum); } if (!$this->connection && $this->_connectionErrors) { $message = implode("\n", $this->_connectionErrors); throw new SocketException($message, E_WARNING); } $this->connected = is_resource($this->connection); if ($this->connected) { stream_set_timeout($this->connection, $this->_config['timeout']); } return $this->connected; }
[ "public", "function", "connect", "(", ")", "{", "if", "(", "$", "this", "->", "connection", ")", "{", "$", "this", "->", "disconnect", "(", ")", ";", "}", "$", "hasProtocol", "=", "strpos", "(", "$", "this", "->", "_config", "[", "'host'", "]", ",", "'://'", ")", "!==", "false", ";", "if", "(", "$", "hasProtocol", ")", "{", "list", "(", "$", "this", "->", "_config", "[", "'protocol'", "]", ",", "$", "this", "->", "_config", "[", "'host'", "]", ")", "=", "explode", "(", "'://'", ",", "$", "this", "->", "_config", "[", "'host'", "]", ")", ";", "}", "$", "scheme", "=", "null", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_config", "[", "'protocol'", "]", ")", ")", "{", "$", "scheme", "=", "$", "this", "->", "_config", "[", "'protocol'", "]", ".", "'://'", ";", "}", "$", "this", "->", "_setSslContext", "(", "$", "this", "->", "_config", "[", "'host'", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_config", "[", "'context'", "]", ")", ")", "{", "$", "context", "=", "stream_context_create", "(", "$", "this", "->", "_config", "[", "'context'", "]", ")", ";", "}", "else", "{", "$", "context", "=", "stream_context_create", "(", ")", ";", "}", "$", "connectAs", "=", "STREAM_CLIENT_CONNECT", ";", "if", "(", "$", "this", "->", "_config", "[", "'persistent'", "]", ")", "{", "$", "connectAs", "|=", "STREAM_CLIENT_PERSISTENT", ";", "}", "set_error_handler", "(", "[", "$", "this", ",", "'_connectionErrorHandler'", "]", ")", ";", "$", "this", "->", "connection", "=", "stream_socket_client", "(", "$", "scheme", ".", "$", "this", "->", "_config", "[", "'host'", "]", ".", "':'", ".", "$", "this", "->", "_config", "[", "'port'", "]", ",", "$", "errNum", ",", "$", "errStr", ",", "$", "this", "->", "_config", "[", "'timeout'", "]", ",", "$", "connectAs", ",", "$", "context", ")", ";", "restore_error_handler", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "errNum", ")", "||", "!", "empty", "(", "$", "errStr", ")", ")", "{", "$", "this", "->", "setLastError", "(", "$", "errNum", ",", "$", "errStr", ")", ";", "throw", "new", "SocketException", "(", "$", "errStr", ",", "$", "errNum", ")", ";", "}", "if", "(", "!", "$", "this", "->", "connection", "&&", "$", "this", "->", "_connectionErrors", ")", "{", "$", "message", "=", "implode", "(", "\"\\n\"", ",", "$", "this", "->", "_connectionErrors", ")", ";", "throw", "new", "SocketException", "(", "$", "message", ",", "E_WARNING", ")", ";", "}", "$", "this", "->", "connected", "=", "is_resource", "(", "$", "this", "->", "connection", ")", ";", "if", "(", "$", "this", "->", "connected", ")", "{", "stream_set_timeout", "(", "$", "this", "->", "connection", ",", "$", "this", "->", "_config", "[", "'timeout'", "]", ")", ";", "}", "return", "$", "this", "->", "connected", ";", "}" ]
Connect the socket to the given host and port. @return bool Success @throws \Cake\Network\Exception\SocketException
[ "Connect", "the", "socket", "to", "the", "given", "host", "and", "port", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Network/Socket.php#L136-L190
211,662
cakephp/cakephp
src/Network/Socket.php
Socket._setSslContext
protected function _setSslContext($host) { foreach ($this->_config as $key => $value) { if (substr($key, 0, 4) !== 'ssl_') { continue; } $contextKey = substr($key, 4); if (empty($this->_config['context']['ssl'][$contextKey])) { $this->_config['context']['ssl'][$contextKey] = $value; } unset($this->_config[$key]); } if (!isset($this->_config['context']['ssl']['SNI_enabled'])) { $this->_config['context']['ssl']['SNI_enabled'] = true; } if (empty($this->_config['context']['ssl']['peer_name'])) { $this->_config['context']['ssl']['peer_name'] = $host; } if (empty($this->_config['context']['ssl']['cafile'])) { $dir = dirname(dirname(__DIR__)); $this->_config['context']['ssl']['cafile'] = $dir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'cacert.pem'; } if (!empty($this->_config['context']['ssl']['verify_host'])) { $this->_config['context']['ssl']['CN_match'] = $host; } unset($this->_config['context']['ssl']['verify_host']); }
php
protected function _setSslContext($host) { foreach ($this->_config as $key => $value) { if (substr($key, 0, 4) !== 'ssl_') { continue; } $contextKey = substr($key, 4); if (empty($this->_config['context']['ssl'][$contextKey])) { $this->_config['context']['ssl'][$contextKey] = $value; } unset($this->_config[$key]); } if (!isset($this->_config['context']['ssl']['SNI_enabled'])) { $this->_config['context']['ssl']['SNI_enabled'] = true; } if (empty($this->_config['context']['ssl']['peer_name'])) { $this->_config['context']['ssl']['peer_name'] = $host; } if (empty($this->_config['context']['ssl']['cafile'])) { $dir = dirname(dirname(__DIR__)); $this->_config['context']['ssl']['cafile'] = $dir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'cacert.pem'; } if (!empty($this->_config['context']['ssl']['verify_host'])) { $this->_config['context']['ssl']['CN_match'] = $host; } unset($this->_config['context']['ssl']['verify_host']); }
[ "protected", "function", "_setSslContext", "(", "$", "host", ")", "{", "foreach", "(", "$", "this", "->", "_config", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "substr", "(", "$", "key", ",", "0", ",", "4", ")", "!==", "'ssl_'", ")", "{", "continue", ";", "}", "$", "contextKey", "=", "substr", "(", "$", "key", ",", "4", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "$", "contextKey", "]", ")", ")", "{", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "$", "contextKey", "]", "=", "$", "value", ";", "}", "unset", "(", "$", "this", "->", "_config", "[", "$", "key", "]", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "'SNI_enabled'", "]", ")", ")", "{", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "'SNI_enabled'", "]", "=", "true", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "'peer_name'", "]", ")", ")", "{", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "'peer_name'", "]", "=", "$", "host", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "'cafile'", "]", ")", ")", "{", "$", "dir", "=", "dirname", "(", "dirname", "(", "__DIR__", ")", ")", ";", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "'cafile'", "]", "=", "$", "dir", ".", "DIRECTORY_SEPARATOR", ".", "'config'", ".", "DIRECTORY_SEPARATOR", ".", "'cacert.pem'", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "'verify_host'", "]", ")", ")", "{", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "'CN_match'", "]", "=", "$", "host", ";", "}", "unset", "(", "$", "this", "->", "_config", "[", "'context'", "]", "[", "'ssl'", "]", "[", "'verify_host'", "]", ")", ";", "}" ]
Configure the SSL context options. @param string $host The host name being connected to. @return void
[ "Configure", "the", "SSL", "context", "options", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Network/Socket.php#L198-L225
211,663
cakephp/cakephp
src/Network/Socket.php
Socket.host
public function host() { if (Validation::ip($this->_config['host'])) { return gethostbyaddr($this->_config['host']); } return gethostbyaddr($this->address()); }
php
public function host() { if (Validation::ip($this->_config['host'])) { return gethostbyaddr($this->_config['host']); } return gethostbyaddr($this->address()); }
[ "public", "function", "host", "(", ")", "{", "if", "(", "Validation", "::", "ip", "(", "$", "this", "->", "_config", "[", "'host'", "]", ")", ")", "{", "return", "gethostbyaddr", "(", "$", "this", "->", "_config", "[", "'host'", "]", ")", ";", "}", "return", "gethostbyaddr", "(", "$", "this", "->", "address", "(", ")", ")", ";", "}" ]
Get the host name of the current connection. @return string Host name
[ "Get", "the", "host", "name", "of", "the", "current", "connection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Network/Socket.php#L261-L268
211,664
cakephp/cakephp
src/Network/Socket.php
Socket.address
public function address() { if (Validation::ip($this->_config['host'])) { return $this->_config['host']; } return gethostbyname($this->_config['host']); }
php
public function address() { if (Validation::ip($this->_config['host'])) { return $this->_config['host']; } return gethostbyname($this->_config['host']); }
[ "public", "function", "address", "(", ")", "{", "if", "(", "Validation", "::", "ip", "(", "$", "this", "->", "_config", "[", "'host'", "]", ")", ")", "{", "return", "$", "this", "->", "_config", "[", "'host'", "]", ";", "}", "return", "gethostbyname", "(", "$", "this", "->", "_config", "[", "'host'", "]", ")", ";", "}" ]
Get the IP address of the current connection. @return string IP address
[ "Get", "the", "IP", "address", "of", "the", "current", "connection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Network/Socket.php#L275-L282
211,665
cakephp/cakephp
src/Network/Socket.php
Socket.addresses
public function addresses() { if (Validation::ip($this->_config['host'])) { return [$this->_config['host']]; } return gethostbynamel($this->_config['host']); }
php
public function addresses() { if (Validation::ip($this->_config['host'])) { return [$this->_config['host']]; } return gethostbynamel($this->_config['host']); }
[ "public", "function", "addresses", "(", ")", "{", "if", "(", "Validation", "::", "ip", "(", "$", "this", "->", "_config", "[", "'host'", "]", ")", ")", "{", "return", "[", "$", "this", "->", "_config", "[", "'host'", "]", "]", ";", "}", "return", "gethostbynamel", "(", "$", "this", "->", "_config", "[", "'host'", "]", ")", ";", "}" ]
Get all IP addresses associated with the current connection. @return array IP addresses
[ "Get", "all", "IP", "addresses", "associated", "with", "the", "current", "connection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Network/Socket.php#L289-L296
211,666
cakephp/cakephp
src/Network/Socket.php
Socket.write
public function write($data) { if (!$this->connected && !$this->connect()) { return false; } $totalBytes = strlen($data); $written = 0; while ($written < $totalBytes) { $rv = fwrite($this->connection, substr($data, $written)); if ($rv === false || $rv === 0) { return $written; } $written += $rv; } return $written; }
php
public function write($data) { if (!$this->connected && !$this->connect()) { return false; } $totalBytes = strlen($data); $written = 0; while ($written < $totalBytes) { $rv = fwrite($this->connection, substr($data, $written)); if ($rv === false || $rv === 0) { return $written; } $written += $rv; } return $written; }
[ "public", "function", "write", "(", "$", "data", ")", "{", "if", "(", "!", "$", "this", "->", "connected", "&&", "!", "$", "this", "->", "connect", "(", ")", ")", "{", "return", "false", ";", "}", "$", "totalBytes", "=", "strlen", "(", "$", "data", ")", ";", "$", "written", "=", "0", ";", "while", "(", "$", "written", "<", "$", "totalBytes", ")", "{", "$", "rv", "=", "fwrite", "(", "$", "this", "->", "connection", ",", "substr", "(", "$", "data", ",", "$", "written", ")", ")", ";", "if", "(", "$", "rv", "===", "false", "||", "$", "rv", "===", "0", ")", "{", "return", "$", "written", ";", "}", "$", "written", "+=", "$", "rv", ";", "}", "return", "$", "written", ";", "}" ]
Write data to the socket. The bool false return value is deprecated and will be int 0 in the next major. Please code respectively to be future proof. @param string $data The data to write to the socket. @return int|false Bytes written.
[ "Write", "data", "to", "the", "socket", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Network/Socket.php#L333-L349
211,667
cakephp/cakephp
src/Network/Socket.php
Socket.read
public function read($length = 1024) { if (!$this->connected && !$this->connect()) { return false; } if (!feof($this->connection)) { $buffer = fread($this->connection, $length); $info = stream_get_meta_data($this->connection); if ($info['timed_out']) { $this->setLastError(E_WARNING, 'Connection timed out'); return false; } return $buffer; } return false; }
php
public function read($length = 1024) { if (!$this->connected && !$this->connect()) { return false; } if (!feof($this->connection)) { $buffer = fread($this->connection, $length); $info = stream_get_meta_data($this->connection); if ($info['timed_out']) { $this->setLastError(E_WARNING, 'Connection timed out'); return false; } return $buffer; } return false; }
[ "public", "function", "read", "(", "$", "length", "=", "1024", ")", "{", "if", "(", "!", "$", "this", "->", "connected", "&&", "!", "$", "this", "->", "connect", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "feof", "(", "$", "this", "->", "connection", ")", ")", "{", "$", "buffer", "=", "fread", "(", "$", "this", "->", "connection", ",", "$", "length", ")", ";", "$", "info", "=", "stream_get_meta_data", "(", "$", "this", "->", "connection", ")", ";", "if", "(", "$", "info", "[", "'timed_out'", "]", ")", "{", "$", "this", "->", "setLastError", "(", "E_WARNING", ",", "'Connection timed out'", ")", ";", "return", "false", ";", "}", "return", "$", "buffer", ";", "}", "return", "false", ";", "}" ]
Read data from the socket. Returns false if no data is available or no connection could be established. The bool false return value is deprecated and will be null in the next major. Please code respectively to be future proof. @param int $length Optional buffer length to read; defaults to 1024 @return mixed Socket data
[ "Read", "data", "from", "the", "socket", ".", "Returns", "false", "if", "no", "data", "is", "available", "or", "no", "connection", "could", "be", "established", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Network/Socket.php#L361-L380
211,668
cakephp/cakephp
src/Network/Socket.php
Socket.disconnect
public function disconnect() { if (!is_resource($this->connection)) { $this->connected = false; return true; } $this->connected = !fclose($this->connection); if (!$this->connected) { $this->connection = null; } return !$this->connected; }
php
public function disconnect() { if (!is_resource($this->connection)) { $this->connected = false; return true; } $this->connected = !fclose($this->connection); if (!$this->connected) { $this->connection = null; } return !$this->connected; }
[ "public", "function", "disconnect", "(", ")", "{", "if", "(", "!", "is_resource", "(", "$", "this", "->", "connection", ")", ")", "{", "$", "this", "->", "connected", "=", "false", ";", "return", "true", ";", "}", "$", "this", "->", "connected", "=", "!", "fclose", "(", "$", "this", "->", "connection", ")", ";", "if", "(", "!", "$", "this", "->", "connected", ")", "{", "$", "this", "->", "connection", "=", "null", ";", "}", "return", "!", "$", "this", "->", "connected", ";", "}" ]
Disconnect the socket from the current connection. @return bool Success
[ "Disconnect", "the", "socket", "from", "the", "current", "connection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Network/Socket.php#L387-L401
211,669
cakephp/cakephp
src/Network/Socket.php
Socket.enableCrypto
public function enableCrypto($type, $clientOrServer = 'client', $enable = true) { if (!array_key_exists($type . '_' . $clientOrServer, $this->_encryptMethods)) { throw new InvalidArgumentException('Invalid encryption scheme chosen'); } $method = $this->_encryptMethods[$type . '_' . $clientOrServer]; // Prior to PHP 5.6.7 TLS_CLIENT was any version of TLS. This was changed in 5.6.7 // to fix backwards compatibility issues, and now only resolves to TLS1.0 // // See https://github.com/php/php-src/commit/10bc5fd4c4c8e1dd57bd911b086e9872a56300a0 if (version_compare(PHP_VERSION, '5.6.7', '>=')) { if ($method == STREAM_CRYPTO_METHOD_TLS_CLIENT) { // @codingStandardsIgnoreStart $method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; // @codingStandardsIgnoreEnd } if ($method == STREAM_CRYPTO_METHOD_TLS_SERVER) { // @codingStandardsIgnoreStart $method |= STREAM_CRYPTO_METHOD_TLSv1_1_SERVER | STREAM_CRYPTO_METHOD_TLSv1_2_SERVER; // @codingStandardsIgnoreEnd } } try { $enableCryptoResult = stream_socket_enable_crypto($this->connection, $enable, $method); } catch (Exception $e) { $this->setLastError(null, $e->getMessage()); throw new SocketException($e->getMessage(), null, $e); } if ($enableCryptoResult === true) { $this->encrypted = $enable; return true; } $errorMessage = 'Unable to perform enableCrypto operation on the current socket'; $this->setLastError(null, $errorMessage); throw new SocketException($errorMessage); }
php
public function enableCrypto($type, $clientOrServer = 'client', $enable = true) { if (!array_key_exists($type . '_' . $clientOrServer, $this->_encryptMethods)) { throw new InvalidArgumentException('Invalid encryption scheme chosen'); } $method = $this->_encryptMethods[$type . '_' . $clientOrServer]; // Prior to PHP 5.6.7 TLS_CLIENT was any version of TLS. This was changed in 5.6.7 // to fix backwards compatibility issues, and now only resolves to TLS1.0 // // See https://github.com/php/php-src/commit/10bc5fd4c4c8e1dd57bd911b086e9872a56300a0 if (version_compare(PHP_VERSION, '5.6.7', '>=')) { if ($method == STREAM_CRYPTO_METHOD_TLS_CLIENT) { // @codingStandardsIgnoreStart $method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; // @codingStandardsIgnoreEnd } if ($method == STREAM_CRYPTO_METHOD_TLS_SERVER) { // @codingStandardsIgnoreStart $method |= STREAM_CRYPTO_METHOD_TLSv1_1_SERVER | STREAM_CRYPTO_METHOD_TLSv1_2_SERVER; // @codingStandardsIgnoreEnd } } try { $enableCryptoResult = stream_socket_enable_crypto($this->connection, $enable, $method); } catch (Exception $e) { $this->setLastError(null, $e->getMessage()); throw new SocketException($e->getMessage(), null, $e); } if ($enableCryptoResult === true) { $this->encrypted = $enable; return true; } $errorMessage = 'Unable to perform enableCrypto operation on the current socket'; $this->setLastError(null, $errorMessage); throw new SocketException($errorMessage); }
[ "public", "function", "enableCrypto", "(", "$", "type", ",", "$", "clientOrServer", "=", "'client'", ",", "$", "enable", "=", "true", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "type", ".", "'_'", ".", "$", "clientOrServer", ",", "$", "this", "->", "_encryptMethods", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid encryption scheme chosen'", ")", ";", "}", "$", "method", "=", "$", "this", "->", "_encryptMethods", "[", "$", "type", ".", "'_'", ".", "$", "clientOrServer", "]", ";", "// Prior to PHP 5.6.7 TLS_CLIENT was any version of TLS. This was changed in 5.6.7", "// to fix backwards compatibility issues, and now only resolves to TLS1.0", "//", "// See https://github.com/php/php-src/commit/10bc5fd4c4c8e1dd57bd911b086e9872a56300a0", "if", "(", "version_compare", "(", "PHP_VERSION", ",", "'5.6.7'", ",", "'>='", ")", ")", "{", "if", "(", "$", "method", "==", "STREAM_CRYPTO_METHOD_TLS_CLIENT", ")", "{", "// @codingStandardsIgnoreStart", "$", "method", "|=", "STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT", "|", "STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT", ";", "// @codingStandardsIgnoreEnd", "}", "if", "(", "$", "method", "==", "STREAM_CRYPTO_METHOD_TLS_SERVER", ")", "{", "// @codingStandardsIgnoreStart", "$", "method", "|=", "STREAM_CRYPTO_METHOD_TLSv1_1_SERVER", "|", "STREAM_CRYPTO_METHOD_TLSv1_2_SERVER", ";", "// @codingStandardsIgnoreEnd", "}", "}", "try", "{", "$", "enableCryptoResult", "=", "stream_socket_enable_crypto", "(", "$", "this", "->", "connection", ",", "$", "enable", ",", "$", "method", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "this", "->", "setLastError", "(", "null", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "throw", "new", "SocketException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "null", ",", "$", "e", ")", ";", "}", "if", "(", "$", "enableCryptoResult", "===", "true", ")", "{", "$", "this", "->", "encrypted", "=", "$", "enable", ";", "return", "true", ";", "}", "$", "errorMessage", "=", "'Unable to perform enableCrypto operation on the current socket'", ";", "$", "this", "->", "setLastError", "(", "null", ",", "$", "errorMessage", ")", ";", "throw", "new", "SocketException", "(", "$", "errorMessage", ")", ";", "}" ]
Encrypts current stream socket, using one of the defined encryption methods @param string $type can be one of 'ssl2', 'ssl3', 'ssl23' or 'tls' @param string $clientOrServer can be one of 'client', 'server'. Default is 'client' @param bool $enable enable or disable encryption. Default is true (enable) @return bool True on success @throws \InvalidArgumentException When an invalid encryption scheme is chosen. @throws \Cake\Network\Exception\SocketException When attempting to enable SSL/TLS fails @see stream_socket_enable_crypto
[ "Encrypts", "current", "stream", "socket", "using", "one", "of", "the", "defined", "encryption", "methods" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Network/Socket.php#L445-L483
211,670
cakephp/cakephp
src/Database/Driver/Mysql.php
Mysql.supportsNativeJson
public function supportsNativeJson() { if ($this->_supportsNativeJson !== null) { return $this->_supportsNativeJson; } if ($this->_version === null) { $this->_version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION); } return $this->_supportsNativeJson = version_compare($this->_version, '5.7.0', '>='); }
php
public function supportsNativeJson() { if ($this->_supportsNativeJson !== null) { return $this->_supportsNativeJson; } if ($this->_version === null) { $this->_version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION); } return $this->_supportsNativeJson = version_compare($this->_version, '5.7.0', '>='); }
[ "public", "function", "supportsNativeJson", "(", ")", "{", "if", "(", "$", "this", "->", "_supportsNativeJson", "!==", "null", ")", "{", "return", "$", "this", "->", "_supportsNativeJson", ";", "}", "if", "(", "$", "this", "->", "_version", "===", "null", ")", "{", "$", "this", "->", "_version", "=", "$", "this", "->", "_connection", "->", "getAttribute", "(", "PDO", "::", "ATTR_SERVER_VERSION", ")", ";", "}", "return", "$", "this", "->", "_supportsNativeJson", "=", "version_compare", "(", "$", "this", "->", "_version", ",", "'5.7.0'", ",", "'>='", ")", ";", "}" ]
Returns true if the server supports native JSON columns @return bool
[ "Returns", "true", "if", "the", "server", "supports", "native", "JSON", "columns" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver/Mysql.php#L168-L179
211,671
cakephp/cakephp
src/Core/ObjectRegistry.php
ObjectRegistry._checkDuplicate
protected function _checkDuplicate($name, $config) { /** @var \Cake\Core\InstanceConfigTrait $existing */ $existing = $this->_loaded[$name]; $msg = sprintf('The "%s" alias has already been loaded', $name); $hasConfig = method_exists($existing, 'config'); if (!$hasConfig) { throw new RuntimeException($msg); } if (empty($config)) { return; } $existingConfig = $existing->getConfig(); unset($config['enabled'], $existingConfig['enabled']); $fail = false; foreach ($config as $key => $value) { if (!array_key_exists($key, $existingConfig)) { $fail = true; break; } if (isset($existingConfig[$key]) && $existingConfig[$key] !== $value) { $fail = true; break; } } if ($fail) { $msg .= ' with the following config: '; $msg .= var_export($existingConfig, true); $msg .= ' which differs from ' . var_export($config, true); throw new RuntimeException($msg); } }
php
protected function _checkDuplicate($name, $config) { /** @var \Cake\Core\InstanceConfigTrait $existing */ $existing = $this->_loaded[$name]; $msg = sprintf('The "%s" alias has already been loaded', $name); $hasConfig = method_exists($existing, 'config'); if (!$hasConfig) { throw new RuntimeException($msg); } if (empty($config)) { return; } $existingConfig = $existing->getConfig(); unset($config['enabled'], $existingConfig['enabled']); $fail = false; foreach ($config as $key => $value) { if (!array_key_exists($key, $existingConfig)) { $fail = true; break; } if (isset($existingConfig[$key]) && $existingConfig[$key] !== $value) { $fail = true; break; } } if ($fail) { $msg .= ' with the following config: '; $msg .= var_export($existingConfig, true); $msg .= ' which differs from ' . var_export($config, true); throw new RuntimeException($msg); } }
[ "protected", "function", "_checkDuplicate", "(", "$", "name", ",", "$", "config", ")", "{", "/** @var \\Cake\\Core\\InstanceConfigTrait $existing */", "$", "existing", "=", "$", "this", "->", "_loaded", "[", "$", "name", "]", ";", "$", "msg", "=", "sprintf", "(", "'The \"%s\" alias has already been loaded'", ",", "$", "name", ")", ";", "$", "hasConfig", "=", "method_exists", "(", "$", "existing", ",", "'config'", ")", ";", "if", "(", "!", "$", "hasConfig", ")", "{", "throw", "new", "RuntimeException", "(", "$", "msg", ")", ";", "}", "if", "(", "empty", "(", "$", "config", ")", ")", "{", "return", ";", "}", "$", "existingConfig", "=", "$", "existing", "->", "getConfig", "(", ")", ";", "unset", "(", "$", "config", "[", "'enabled'", "]", ",", "$", "existingConfig", "[", "'enabled'", "]", ")", ";", "$", "fail", "=", "false", ";", "foreach", "(", "$", "config", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "existingConfig", ")", ")", "{", "$", "fail", "=", "true", ";", "break", ";", "}", "if", "(", "isset", "(", "$", "existingConfig", "[", "$", "key", "]", ")", "&&", "$", "existingConfig", "[", "$", "key", "]", "!==", "$", "value", ")", "{", "$", "fail", "=", "true", ";", "break", ";", "}", "}", "if", "(", "$", "fail", ")", "{", "$", "msg", ".=", "' with the following config: '", ";", "$", "msg", ".=", "var_export", "(", "$", "existingConfig", ",", "true", ")", ";", "$", "msg", ".=", "' which differs from '", ".", "var_export", "(", "$", "config", ",", "true", ")", ";", "throw", "new", "RuntimeException", "(", "$", "msg", ")", ";", "}", "}" ]
Check for duplicate object loading. If a duplicate is being loaded and has different configuration, that is bad and an exception will be raised. An exception is raised, as replacing the object will not update any references other objects may have. Additionally, simply updating the runtime configuration is not a good option as we may be missing important constructor logic dependent on the configuration. @param string $name The name of the alias in the registry. @param array $config The config data for the new instance. @return void @throws \RuntimeException When a duplicate is found.
[ "Check", "for", "duplicate", "object", "loading", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/ObjectRegistry.php#L119-L151
211,672
cakephp/cakephp
src/Core/ObjectRegistry.php
ObjectRegistry.get
public function get($name) { if (isset($this->_loaded[$name])) { return $this->_loaded[$name]; } return null; }
php
public function get($name) { if (isset($this->_loaded[$name])) { return $this->_loaded[$name]; } return null; }
[ "public", "function", "get", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_loaded", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "_loaded", "[", "$", "name", "]", ";", "}", "return", "null", ";", "}" ]
Get loaded object instance. @param string $name Name of object. @return object|null Object instance if loaded else null.
[ "Get", "loaded", "object", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/ObjectRegistry.php#L211-L218
211,673
cakephp/cakephp
src/Core/ObjectRegistry.php
ObjectRegistry.normalizeArray
public function normalizeArray($objects) { $normal = []; foreach ($objects as $i => $objectName) { $config = []; if (!is_int($i)) { $config = (array)$objectName; $objectName = $i; } list(, $name) = pluginSplit($objectName); if (isset($config['class'])) { $normal[$name] = $config; } else { $normal[$name] = ['class' => $objectName, 'config' => $config]; } } return $normal; }
php
public function normalizeArray($objects) { $normal = []; foreach ($objects as $i => $objectName) { $config = []; if (!is_int($i)) { $config = (array)$objectName; $objectName = $i; } list(, $name) = pluginSplit($objectName); if (isset($config['class'])) { $normal[$name] = $config; } else { $normal[$name] = ['class' => $objectName, 'config' => $config]; } } return $normal; }
[ "public", "function", "normalizeArray", "(", "$", "objects", ")", "{", "$", "normal", "=", "[", "]", ";", "foreach", "(", "$", "objects", "as", "$", "i", "=>", "$", "objectName", ")", "{", "$", "config", "=", "[", "]", ";", "if", "(", "!", "is_int", "(", "$", "i", ")", ")", "{", "$", "config", "=", "(", "array", ")", "$", "objectName", ";", "$", "objectName", "=", "$", "i", ";", "}", "list", "(", ",", "$", "name", ")", "=", "pluginSplit", "(", "$", "objectName", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'class'", "]", ")", ")", "{", "$", "normal", "[", "$", "name", "]", "=", "$", "config", ";", "}", "else", "{", "$", "normal", "[", "$", "name", "]", "=", "[", "'class'", "=>", "$", "objectName", ",", "'config'", "=>", "$", "config", "]", ";", "}", "}", "return", "$", "normal", ";", "}" ]
Normalizes an object array, creates an array that makes lazy loading easier @param array $objects Array of child objects to normalize. @return array Array of normalized objects.
[ "Normalizes", "an", "object", "array", "creates", "an", "array", "that", "makes", "lazy", "loading", "easier" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/ObjectRegistry.php#L272-L290
211,674
cakephp/cakephp
src/Core/ObjectRegistry.php
ObjectRegistry.reset
public function reset() { foreach (array_keys($this->_loaded) as $name) { $this->unload($name); } return $this; }
php
public function reset() { foreach (array_keys($this->_loaded) as $name) { $this->unload($name); } return $this; }
[ "public", "function", "reset", "(", ")", "{", "foreach", "(", "array_keys", "(", "$", "this", "->", "_loaded", ")", "as", "$", "name", ")", "{", "$", "this", "->", "unload", "(", "$", "name", ")", ";", "}", "return", "$", "this", ";", "}" ]
Clear loaded instances in the registry. If the registry subclass has an event manager, the objects will be detached from events as well. @return $this
[ "Clear", "loaded", "instances", "in", "the", "registry", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/ObjectRegistry.php#L299-L306
211,675
cakephp/cakephp
src/Core/ObjectRegistry.php
ObjectRegistry.set
public function set($objectName, $object) { list(, $name) = pluginSplit($objectName); // Just call unload if the object was loaded before if (array_key_exists($objectName, $this->_loaded)) { $this->unload($objectName); } if ($this instanceof EventDispatcherInterface && $object instanceof EventListenerInterface) { $this->getEventManager()->on($object); } $this->_loaded[$name] = $object; return $this; }
php
public function set($objectName, $object) { list(, $name) = pluginSplit($objectName); // Just call unload if the object was loaded before if (array_key_exists($objectName, $this->_loaded)) { $this->unload($objectName); } if ($this instanceof EventDispatcherInterface && $object instanceof EventListenerInterface) { $this->getEventManager()->on($object); } $this->_loaded[$name] = $object; return $this; }
[ "public", "function", "set", "(", "$", "objectName", ",", "$", "object", ")", "{", "list", "(", ",", "$", "name", ")", "=", "pluginSplit", "(", "$", "objectName", ")", ";", "// Just call unload if the object was loaded before", "if", "(", "array_key_exists", "(", "$", "objectName", ",", "$", "this", "->", "_loaded", ")", ")", "{", "$", "this", "->", "unload", "(", "$", "objectName", ")", ";", "}", "if", "(", "$", "this", "instanceof", "EventDispatcherInterface", "&&", "$", "object", "instanceof", "EventListenerInterface", ")", "{", "$", "this", "->", "getEventManager", "(", ")", "->", "on", "(", "$", "object", ")", ";", "}", "$", "this", "->", "_loaded", "[", "$", "name", "]", "=", "$", "object", ";", "return", "$", "this", ";", "}" ]
Set an object directly into the registry by name. If this collection implements events, the passed object will be attached into the event manager @param string $objectName The name of the object to set in the registry. @param object $object instance to store in the registry @return $this
[ "Set", "an", "object", "directly", "into", "the", "registry", "by", "name", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/ObjectRegistry.php#L318-L332
211,676
cakephp/cakephp
src/Core/ObjectRegistry.php
ObjectRegistry.unload
public function unload($objectName) { if (empty($this->_loaded[$objectName])) { list($plugin, $objectName) = pluginSplit($objectName); $this->_throwMissingClassError($objectName, $plugin); } $object = $this->_loaded[$objectName]; if ($this instanceof EventDispatcherInterface && $object instanceof EventListenerInterface) { $this->getEventManager()->off($object); } unset($this->_loaded[$objectName]); return $this; }
php
public function unload($objectName) { if (empty($this->_loaded[$objectName])) { list($plugin, $objectName) = pluginSplit($objectName); $this->_throwMissingClassError($objectName, $plugin); } $object = $this->_loaded[$objectName]; if ($this instanceof EventDispatcherInterface && $object instanceof EventListenerInterface) { $this->getEventManager()->off($object); } unset($this->_loaded[$objectName]); return $this; }
[ "public", "function", "unload", "(", "$", "objectName", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_loaded", "[", "$", "objectName", "]", ")", ")", "{", "list", "(", "$", "plugin", ",", "$", "objectName", ")", "=", "pluginSplit", "(", "$", "objectName", ")", ";", "$", "this", "->", "_throwMissingClassError", "(", "$", "objectName", ",", "$", "plugin", ")", ";", "}", "$", "object", "=", "$", "this", "->", "_loaded", "[", "$", "objectName", "]", ";", "if", "(", "$", "this", "instanceof", "EventDispatcherInterface", "&&", "$", "object", "instanceof", "EventListenerInterface", ")", "{", "$", "this", "->", "getEventManager", "(", ")", "->", "off", "(", "$", "object", ")", ";", "}", "unset", "(", "$", "this", "->", "_loaded", "[", "$", "objectName", "]", ")", ";", "return", "$", "this", ";", "}" ]
Remove an object from the registry. If this registry has an event manager, the object will be detached from any events as well. @param string $objectName The name of the object to remove from the registry. @return $this
[ "Remove", "an", "object", "from", "the", "registry", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/ObjectRegistry.php#L342-L356
211,677
cakephp/cakephp
src/Database/Dialect/TupleComparisonTranslatorTrait.php
TupleComparisonTranslatorTrait._transformTupleComparison
protected function _transformTupleComparison(TupleComparison $expression, $query) { $fields = $expression->getField(); if (!is_array($fields)) { return; } $value = $expression->getValue(); $op = $expression->getOperator(); $true = new QueryExpression('1'); if ($value instanceof Query) { $selected = array_values($value->clause('select')); foreach ($fields as $i => $field) { $value->andWhere([$field . " $op" => new IdentifierExpression($selected[$i])]); } $value->select($true, true); $expression->setField($true); $expression->setOperator('='); return; } $surrogate = $query->getConnection() ->newQuery() ->select($true); if (!is_array(current($value))) { $value = [$value]; } $conditions = ['OR' => []]; foreach ($value as $tuple) { $item = []; foreach (array_values($tuple) as $i => $value) { $item[] = [$fields[$i] => $value]; } $conditions['OR'][] = $item; } $surrogate->where($conditions); $expression->setField($true); $expression->setValue($surrogate); $expression->setOperator('='); }
php
protected function _transformTupleComparison(TupleComparison $expression, $query) { $fields = $expression->getField(); if (!is_array($fields)) { return; } $value = $expression->getValue(); $op = $expression->getOperator(); $true = new QueryExpression('1'); if ($value instanceof Query) { $selected = array_values($value->clause('select')); foreach ($fields as $i => $field) { $value->andWhere([$field . " $op" => new IdentifierExpression($selected[$i])]); } $value->select($true, true); $expression->setField($true); $expression->setOperator('='); return; } $surrogate = $query->getConnection() ->newQuery() ->select($true); if (!is_array(current($value))) { $value = [$value]; } $conditions = ['OR' => []]; foreach ($value as $tuple) { $item = []; foreach (array_values($tuple) as $i => $value) { $item[] = [$fields[$i] => $value]; } $conditions['OR'][] = $item; } $surrogate->where($conditions); $expression->setField($true); $expression->setValue($surrogate); $expression->setOperator('='); }
[ "protected", "function", "_transformTupleComparison", "(", "TupleComparison", "$", "expression", ",", "$", "query", ")", "{", "$", "fields", "=", "$", "expression", "->", "getField", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "fields", ")", ")", "{", "return", ";", "}", "$", "value", "=", "$", "expression", "->", "getValue", "(", ")", ";", "$", "op", "=", "$", "expression", "->", "getOperator", "(", ")", ";", "$", "true", "=", "new", "QueryExpression", "(", "'1'", ")", ";", "if", "(", "$", "value", "instanceof", "Query", ")", "{", "$", "selected", "=", "array_values", "(", "$", "value", "->", "clause", "(", "'select'", ")", ")", ";", "foreach", "(", "$", "fields", "as", "$", "i", "=>", "$", "field", ")", "{", "$", "value", "->", "andWhere", "(", "[", "$", "field", ".", "\" $op\"", "=>", "new", "IdentifierExpression", "(", "$", "selected", "[", "$", "i", "]", ")", "]", ")", ";", "}", "$", "value", "->", "select", "(", "$", "true", ",", "true", ")", ";", "$", "expression", "->", "setField", "(", "$", "true", ")", ";", "$", "expression", "->", "setOperator", "(", "'='", ")", ";", "return", ";", "}", "$", "surrogate", "=", "$", "query", "->", "getConnection", "(", ")", "->", "newQuery", "(", ")", "->", "select", "(", "$", "true", ")", ";", "if", "(", "!", "is_array", "(", "current", "(", "$", "value", ")", ")", ")", "{", "$", "value", "=", "[", "$", "value", "]", ";", "}", "$", "conditions", "=", "[", "'OR'", "=>", "[", "]", "]", ";", "foreach", "(", "$", "value", "as", "$", "tuple", ")", "{", "$", "item", "=", "[", "]", ";", "foreach", "(", "array_values", "(", "$", "tuple", ")", "as", "$", "i", "=>", "$", "value", ")", "{", "$", "item", "[", "]", "=", "[", "$", "fields", "[", "$", "i", "]", "=>", "$", "value", "]", ";", "}", "$", "conditions", "[", "'OR'", "]", "[", "]", "=", "$", "item", ";", "}", "$", "surrogate", "->", "where", "(", "$", "conditions", ")", ";", "$", "expression", "->", "setField", "(", "$", "true", ")", ";", "$", "expression", "->", "setValue", "(", "$", "surrogate", ")", ";", "$", "expression", "->", "setOperator", "(", "'='", ")", ";", "}" ]
Receives a TupleExpression and changes it so that it conforms to this SQL dialect. It transforms expressions looking like '(a, b) IN ((c, d), (e, f)' into an equivalent expression of the form '((a = c) AND (b = d)) OR ((a = e) AND (b = f))'. It can also transform transform expressions where the right hand side is a query selecting the same amount of columns as the elements in the left hand side of the expression: (a, b) IN (SELECT c, d FROM a_table) is transformed into 1 = (SELECT 1 FROM a_table WHERE (a = c) AND (b = d)) @param \Cake\Database\Expression\TupleComparison $expression The expression to transform @param \Cake\Database\Query $query The query to update. @return void
[ "Receives", "a", "TupleExpression", "and", "changes", "it", "so", "that", "it", "conforms", "to", "this", "SQL", "dialect", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Dialect/TupleComparisonTranslatorTrait.php#L49-L94
211,678
cakephp/cakephp
src/Http/Cookie/CookieCollection.php
CookieCollection.createFromServerRequest
public static function createFromServerRequest(ServerRequestInterface $request) { $data = $request->getCookieParams(); $cookies = []; foreach ($data as $name => $value) { $cookies[] = new Cookie($name, $value); } return new static($cookies); }
php
public static function createFromServerRequest(ServerRequestInterface $request) { $data = $request->getCookieParams(); $cookies = []; foreach ($data as $name => $value) { $cookies[] = new Cookie($name, $value); } return new static($cookies); }
[ "public", "static", "function", "createFromServerRequest", "(", "ServerRequestInterface", "$", "request", ")", "{", "$", "data", "=", "$", "request", "->", "getCookieParams", "(", ")", ";", "$", "cookies", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "cookies", "[", "]", "=", "new", "Cookie", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "new", "static", "(", "$", "cookies", ")", ";", "}" ]
Create a new collection from the cookies in a ServerRequest @param \Psr\Http\Message\ServerRequestInterface $request The request to extract cookie data from @return static
[ "Create", "a", "new", "collection", "from", "the", "cookies", "in", "a", "ServerRequest" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/CookieCollection.php#L75-L84
211,679
cakephp/cakephp
src/Http/Cookie/CookieCollection.php
CookieCollection.get
public function get($name) { $key = mb_strtolower($name); foreach ($this->cookies as $cookie) { if (mb_strtolower($cookie->getName()) === $key) { return $cookie; } } return null; }
php
public function get($name) { $key = mb_strtolower($name); foreach ($this->cookies as $cookie) { if (mb_strtolower($cookie->getName()) === $key) { return $cookie; } } return null; }
[ "public", "function", "get", "(", "$", "name", ")", "{", "$", "key", "=", "mb_strtolower", "(", "$", "name", ")", ";", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "cookie", ")", "{", "if", "(", "mb_strtolower", "(", "$", "cookie", "->", "getName", "(", ")", ")", "===", "$", "key", ")", "{", "return", "$", "cookie", ";", "}", "}", "return", "null", ";", "}" ]
Get the first cookie by name. @param string $name The name of the cookie. @return \Cake\Http\Cookie\CookieInterface|null
[ "Get", "the", "first", "cookie", "by", "name", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/CookieCollection.php#L120-L130
211,680
cakephp/cakephp
src/Http/Cookie/CookieCollection.php
CookieCollection.has
public function has($name) { $key = mb_strtolower($name); foreach ($this->cookies as $cookie) { if (mb_strtolower($cookie->getName()) === $key) { return true; } } return false; }
php
public function has($name) { $key = mb_strtolower($name); foreach ($this->cookies as $cookie) { if (mb_strtolower($cookie->getName()) === $key) { return true; } } return false; }
[ "public", "function", "has", "(", "$", "name", ")", "{", "$", "key", "=", "mb_strtolower", "(", "$", "name", ")", ";", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "cookie", ")", "{", "if", "(", "mb_strtolower", "(", "$", "cookie", "->", "getName", "(", ")", ")", "===", "$", "key", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if a cookie with the given name exists @param string $name The cookie name to check. @return bool True if the cookie exists, otherwise false.
[ "Check", "if", "a", "cookie", "with", "the", "given", "name", "exists" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/CookieCollection.php#L138-L148
211,681
cakephp/cakephp
src/Http/Cookie/CookieCollection.php
CookieCollection.checkCookies
protected function checkCookies(array $cookies) { foreach ($cookies as $index => $cookie) { if (!$cookie instanceof CookieInterface) { throw new InvalidArgumentException( sprintf( 'Expected `%s[]` as $cookies but instead got `%s` at index %d', static::class, getTypeName($cookie), $index ) ); } } }
php
protected function checkCookies(array $cookies) { foreach ($cookies as $index => $cookie) { if (!$cookie instanceof CookieInterface) { throw new InvalidArgumentException( sprintf( 'Expected `%s[]` as $cookies but instead got `%s` at index %d', static::class, getTypeName($cookie), $index ) ); } } }
[ "protected", "function", "checkCookies", "(", "array", "$", "cookies", ")", "{", "foreach", "(", "$", "cookies", "as", "$", "index", "=>", "$", "cookie", ")", "{", "if", "(", "!", "$", "cookie", "instanceof", "CookieInterface", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Expected `%s[]` as $cookies but instead got `%s` at index %d'", ",", "static", "::", "class", ",", "getTypeName", "(", "$", "cookie", ")", ",", "$", "index", ")", ")", ";", "}", "}", "}" ]
Checks if only valid cookie objects are in the array @param array $cookies Array of cookie objects @return void @throws \InvalidArgumentException
[ "Checks", "if", "only", "valid", "cookie", "objects", "are", "in", "the", "array" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/CookieCollection.php#L178-L192
211,682
cakephp/cakephp
src/Http/Cookie/CookieCollection.php
CookieCollection.findMatchingCookies
protected function findMatchingCookies($scheme, $host, $path) { $out = []; $now = new DateTimeImmutable('now', new DateTimeZone('UTC')); foreach ($this->cookies as $cookie) { if ($scheme === 'http' && $cookie->isSecure()) { continue; } if (strpos($path, $cookie->getPath()) !== 0) { continue; } $domain = $cookie->getDomain(); $leadingDot = substr($domain, 0, 1) === '.'; if ($leadingDot) { $domain = ltrim($domain, '.'); } if ($cookie->isExpired($now)) { continue; } $pattern = '/' . preg_quote($domain, '/') . '$/'; if (!preg_match($pattern, $host)) { continue; } $out[$cookie->getName()] = $cookie->getValue(); } return $out; }
php
protected function findMatchingCookies($scheme, $host, $path) { $out = []; $now = new DateTimeImmutable('now', new DateTimeZone('UTC')); foreach ($this->cookies as $cookie) { if ($scheme === 'http' && $cookie->isSecure()) { continue; } if (strpos($path, $cookie->getPath()) !== 0) { continue; } $domain = $cookie->getDomain(); $leadingDot = substr($domain, 0, 1) === '.'; if ($leadingDot) { $domain = ltrim($domain, '.'); } if ($cookie->isExpired($now)) { continue; } $pattern = '/' . preg_quote($domain, '/') . '$/'; if (!preg_match($pattern, $host)) { continue; } $out[$cookie->getName()] = $cookie->getValue(); } return $out; }
[ "protected", "function", "findMatchingCookies", "(", "$", "scheme", ",", "$", "host", ",", "$", "path", ")", "{", "$", "out", "=", "[", "]", ";", "$", "now", "=", "new", "DateTimeImmutable", "(", "'now'", ",", "new", "DateTimeZone", "(", "'UTC'", ")", ")", ";", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "cookie", ")", "{", "if", "(", "$", "scheme", "===", "'http'", "&&", "$", "cookie", "->", "isSecure", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "strpos", "(", "$", "path", ",", "$", "cookie", "->", "getPath", "(", ")", ")", "!==", "0", ")", "{", "continue", ";", "}", "$", "domain", "=", "$", "cookie", "->", "getDomain", "(", ")", ";", "$", "leadingDot", "=", "substr", "(", "$", "domain", ",", "0", ",", "1", ")", "===", "'.'", ";", "if", "(", "$", "leadingDot", ")", "{", "$", "domain", "=", "ltrim", "(", "$", "domain", ",", "'.'", ")", ";", "}", "if", "(", "$", "cookie", "->", "isExpired", "(", "$", "now", ")", ")", "{", "continue", ";", "}", "$", "pattern", "=", "'/'", ".", "preg_quote", "(", "$", "domain", ",", "'/'", ")", ".", "'$/'", ";", "if", "(", "!", "preg_match", "(", "$", "pattern", ",", "$", "host", ")", ")", "{", "continue", ";", "}", "$", "out", "[", "$", "cookie", "->", "getName", "(", ")", "]", "=", "$", "cookie", "->", "getValue", "(", ")", ";", "}", "return", "$", "out", ";", "}" ]
Find cookies matching the scheme, host, and path @param string $scheme The http scheme to match @param string $host The host to match. @param string $path The path to match @return array An array of cookie name/value pairs
[ "Find", "cookies", "matching", "the", "scheme", "host", "and", "path" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/CookieCollection.php#L253-L283
211,683
cakephp/cakephp
src/Http/Cookie/CookieCollection.php
CookieCollection.addFromResponse
public function addFromResponse(ResponseInterface $response, RequestInterface $request) { $uri = $request->getUri(); $host = $uri->getHost(); $path = $uri->getPath() ?: '/'; $cookies = static::parseSetCookieHeader($response->getHeader('Set-Cookie')); $cookies = $this->setRequestDefaults($cookies, $host, $path); $new = clone $this; foreach ($cookies as $cookie) { $new->cookies[$cookie->getId()] = $cookie; } $new->removeExpiredCookies($host, $path); return $new; }
php
public function addFromResponse(ResponseInterface $response, RequestInterface $request) { $uri = $request->getUri(); $host = $uri->getHost(); $path = $uri->getPath() ?: '/'; $cookies = static::parseSetCookieHeader($response->getHeader('Set-Cookie')); $cookies = $this->setRequestDefaults($cookies, $host, $path); $new = clone $this; foreach ($cookies as $cookie) { $new->cookies[$cookie->getId()] = $cookie; } $new->removeExpiredCookies($host, $path); return $new; }
[ "public", "function", "addFromResponse", "(", "ResponseInterface", "$", "response", ",", "RequestInterface", "$", "request", ")", "{", "$", "uri", "=", "$", "request", "->", "getUri", "(", ")", ";", "$", "host", "=", "$", "uri", "->", "getHost", "(", ")", ";", "$", "path", "=", "$", "uri", "->", "getPath", "(", ")", "?", ":", "'/'", ";", "$", "cookies", "=", "static", "::", "parseSetCookieHeader", "(", "$", "response", "->", "getHeader", "(", "'Set-Cookie'", ")", ")", ";", "$", "cookies", "=", "$", "this", "->", "setRequestDefaults", "(", "$", "cookies", ",", "$", "host", ",", "$", "path", ")", ";", "$", "new", "=", "clone", "$", "this", ";", "foreach", "(", "$", "cookies", "as", "$", "cookie", ")", "{", "$", "new", "->", "cookies", "[", "$", "cookie", "->", "getId", "(", ")", "]", "=", "$", "cookie", ";", "}", "$", "new", "->", "removeExpiredCookies", "(", "$", "host", ",", "$", "path", ")", ";", "return", "$", "new", ";", "}" ]
Create a new collection that includes cookies from the response. @param \Psr\Http\Message\ResponseInterface $response Response to extract cookies from. @param \Psr\Http\Message\RequestInterface $request Request to get cookie context from. @return static
[ "Create", "a", "new", "collection", "that", "includes", "cookies", "from", "the", "response", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/CookieCollection.php#L292-L307
211,684
cakephp/cakephp
src/Http/Cookie/CookieCollection.php
CookieCollection.setRequestDefaults
protected function setRequestDefaults(array $cookies, $host, $path) { $out = []; foreach ($cookies as $name => $cookie) { if (!$cookie->getDomain()) { $cookie = $cookie->withDomain($host); } if (!$cookie->getPath()) { $cookie = $cookie->withPath($path); } $out[] = $cookie; } return $out; }
php
protected function setRequestDefaults(array $cookies, $host, $path) { $out = []; foreach ($cookies as $name => $cookie) { if (!$cookie->getDomain()) { $cookie = $cookie->withDomain($host); } if (!$cookie->getPath()) { $cookie = $cookie->withPath($path); } $out[] = $cookie; } return $out; }
[ "protected", "function", "setRequestDefaults", "(", "array", "$", "cookies", ",", "$", "host", ",", "$", "path", ")", "{", "$", "out", "=", "[", "]", ";", "foreach", "(", "$", "cookies", "as", "$", "name", "=>", "$", "cookie", ")", "{", "if", "(", "!", "$", "cookie", "->", "getDomain", "(", ")", ")", "{", "$", "cookie", "=", "$", "cookie", "->", "withDomain", "(", "$", "host", ")", ";", "}", "if", "(", "!", "$", "cookie", "->", "getPath", "(", ")", ")", "{", "$", "cookie", "=", "$", "cookie", "->", "withPath", "(", "$", "path", ")", ";", "}", "$", "out", "[", "]", "=", "$", "cookie", ";", "}", "return", "$", "out", ";", "}" ]
Apply path and host to the set of cookies if they are not set. @param array $cookies An array of cookies to update. @param string $host The host to set. @param string $path The path to set. @return array An array of updated cookies.
[ "Apply", "path", "and", "host", "to", "the", "set", "of", "cookies", "if", "they", "are", "not", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/CookieCollection.php#L317-L331
211,685
cakephp/cakephp
src/Http/Cookie/CookieCollection.php
CookieCollection.parseSetCookieHeader
protected static function parseSetCookieHeader($values) { $cookies = []; foreach ($values as $value) { $value = rtrim($value, ';'); $parts = preg_split('/\;[ \t]*/', $value); $name = false; $cookie = [ 'value' => '', 'path' => '', 'domain' => '', 'secure' => false, 'httponly' => false, 'expires' => null, 'max-age' => null ]; foreach ($parts as $i => $part) { if (strpos($part, '=') !== false) { list($key, $value) = explode('=', $part, 2); } else { $key = $part; $value = true; } if ($i === 0) { $name = $key; $cookie['value'] = urldecode($value); continue; } $key = strtolower($key); if (array_key_exists($key, $cookie) && !strlen($cookie[$key])) { $cookie[$key] = $value; } } try { $expires = null; if ($cookie['max-age'] !== null) { $expires = new DateTimeImmutable('@' . (time() + $cookie['max-age'])); } elseif ($cookie['expires']) { $expires = new DateTimeImmutable('@' . strtotime($cookie['expires'])); } } catch (Exception $e) { $expires = null; } try { $cookies[] = new Cookie( $name, $cookie['value'], $expires, $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httponly'] ); } catch (Exception $e) { // Don't blow up on invalid cookies } } return $cookies; }
php
protected static function parseSetCookieHeader($values) { $cookies = []; foreach ($values as $value) { $value = rtrim($value, ';'); $parts = preg_split('/\;[ \t]*/', $value); $name = false; $cookie = [ 'value' => '', 'path' => '', 'domain' => '', 'secure' => false, 'httponly' => false, 'expires' => null, 'max-age' => null ]; foreach ($parts as $i => $part) { if (strpos($part, '=') !== false) { list($key, $value) = explode('=', $part, 2); } else { $key = $part; $value = true; } if ($i === 0) { $name = $key; $cookie['value'] = urldecode($value); continue; } $key = strtolower($key); if (array_key_exists($key, $cookie) && !strlen($cookie[$key])) { $cookie[$key] = $value; } } try { $expires = null; if ($cookie['max-age'] !== null) { $expires = new DateTimeImmutable('@' . (time() + $cookie['max-age'])); } elseif ($cookie['expires']) { $expires = new DateTimeImmutable('@' . strtotime($cookie['expires'])); } } catch (Exception $e) { $expires = null; } try { $cookies[] = new Cookie( $name, $cookie['value'], $expires, $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httponly'] ); } catch (Exception $e) { // Don't blow up on invalid cookies } } return $cookies; }
[ "protected", "static", "function", "parseSetCookieHeader", "(", "$", "values", ")", "{", "$", "cookies", "=", "[", "]", ";", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "$", "value", "=", "rtrim", "(", "$", "value", ",", "';'", ")", ";", "$", "parts", "=", "preg_split", "(", "'/\\;[ \\t]*/'", ",", "$", "value", ")", ";", "$", "name", "=", "false", ";", "$", "cookie", "=", "[", "'value'", "=>", "''", ",", "'path'", "=>", "''", ",", "'domain'", "=>", "''", ",", "'secure'", "=>", "false", ",", "'httponly'", "=>", "false", ",", "'expires'", "=>", "null", ",", "'max-age'", "=>", "null", "]", ";", "foreach", "(", "$", "parts", "as", "$", "i", "=>", "$", "part", ")", "{", "if", "(", "strpos", "(", "$", "part", ",", "'='", ")", "!==", "false", ")", "{", "list", "(", "$", "key", ",", "$", "value", ")", "=", "explode", "(", "'='", ",", "$", "part", ",", "2", ")", ";", "}", "else", "{", "$", "key", "=", "$", "part", ";", "$", "value", "=", "true", ";", "}", "if", "(", "$", "i", "===", "0", ")", "{", "$", "name", "=", "$", "key", ";", "$", "cookie", "[", "'value'", "]", "=", "urldecode", "(", "$", "value", ")", ";", "continue", ";", "}", "$", "key", "=", "strtolower", "(", "$", "key", ")", ";", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "cookie", ")", "&&", "!", "strlen", "(", "$", "cookie", "[", "$", "key", "]", ")", ")", "{", "$", "cookie", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "try", "{", "$", "expires", "=", "null", ";", "if", "(", "$", "cookie", "[", "'max-age'", "]", "!==", "null", ")", "{", "$", "expires", "=", "new", "DateTimeImmutable", "(", "'@'", ".", "(", "time", "(", ")", "+", "$", "cookie", "[", "'max-age'", "]", ")", ")", ";", "}", "elseif", "(", "$", "cookie", "[", "'expires'", "]", ")", "{", "$", "expires", "=", "new", "DateTimeImmutable", "(", "'@'", ".", "strtotime", "(", "$", "cookie", "[", "'expires'", "]", ")", ")", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "expires", "=", "null", ";", "}", "try", "{", "$", "cookies", "[", "]", "=", "new", "Cookie", "(", "$", "name", ",", "$", "cookie", "[", "'value'", "]", ",", "$", "expires", ",", "$", "cookie", "[", "'path'", "]", ",", "$", "cookie", "[", "'domain'", "]", ",", "$", "cookie", "[", "'secure'", "]", ",", "$", "cookie", "[", "'httponly'", "]", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// Don't blow up on invalid cookies", "}", "}", "return", "$", "cookies", ";", "}" ]
Parse Set-Cookie headers into array @param array $values List of Set-Cookie Header values. @return \Cake\Http\Cookie\Cookie[] An array of cookie objects
[ "Parse", "Set", "-", "Cookie", "headers", "into", "array" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/CookieCollection.php#L339-L400
211,686
cakephp/cakephp
src/Http/Cookie/CookieCollection.php
CookieCollection.removeExpiredCookies
protected function removeExpiredCookies($host, $path) { $time = new DateTimeImmutable('now', new DateTimeZone('UTC')); $hostPattern = '/' . preg_quote($host, '/') . '$/'; foreach ($this->cookies as $i => $cookie) { $expired = $cookie->isExpired($time); $pathMatches = strpos($path, $cookie->getPath()) === 0; $hostMatches = preg_match($hostPattern, $cookie->getDomain()); if ($pathMatches && $hostMatches && $expired) { unset($this->cookies[$i]); } } }
php
protected function removeExpiredCookies($host, $path) { $time = new DateTimeImmutable('now', new DateTimeZone('UTC')); $hostPattern = '/' . preg_quote($host, '/') . '$/'; foreach ($this->cookies as $i => $cookie) { $expired = $cookie->isExpired($time); $pathMatches = strpos($path, $cookie->getPath()) === 0; $hostMatches = preg_match($hostPattern, $cookie->getDomain()); if ($pathMatches && $hostMatches && $expired) { unset($this->cookies[$i]); } } }
[ "protected", "function", "removeExpiredCookies", "(", "$", "host", ",", "$", "path", ")", "{", "$", "time", "=", "new", "DateTimeImmutable", "(", "'now'", ",", "new", "DateTimeZone", "(", "'UTC'", ")", ")", ";", "$", "hostPattern", "=", "'/'", ".", "preg_quote", "(", "$", "host", ",", "'/'", ")", ".", "'$/'", ";", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "i", "=>", "$", "cookie", ")", "{", "$", "expired", "=", "$", "cookie", "->", "isExpired", "(", "$", "time", ")", ";", "$", "pathMatches", "=", "strpos", "(", "$", "path", ",", "$", "cookie", "->", "getPath", "(", ")", ")", "===", "0", ";", "$", "hostMatches", "=", "preg_match", "(", "$", "hostPattern", ",", "$", "cookie", "->", "getDomain", "(", ")", ")", ";", "if", "(", "$", "pathMatches", "&&", "$", "hostMatches", "&&", "$", "expired", ")", "{", "unset", "(", "$", "this", "->", "cookies", "[", "$", "i", "]", ")", ";", "}", "}", "}" ]
Remove expired cookies from the collection. @param string $host The host to check for expired cookies on. @param string $path The path to check for expired cookies on. @return void
[ "Remove", "expired", "cookies", "from", "the", "collection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/CookieCollection.php#L409-L422
211,687
cakephp/cakephp
src/View/Widget/CheckboxWidget.php
CheckboxWidget._isChecked
protected function _isChecked($data) { if (array_key_exists('checked', $data)) { return (bool)$data['checked']; } return (string)$data['val'] === (string)$data['value']; }
php
protected function _isChecked($data) { if (array_key_exists('checked', $data)) { return (bool)$data['checked']; } return (string)$data['val'] === (string)$data['value']; }
[ "protected", "function", "_isChecked", "(", "$", "data", ")", "{", "if", "(", "array_key_exists", "(", "'checked'", ",", "$", "data", ")", ")", "{", "return", "(", "bool", ")", "$", "data", "[", "'checked'", "]", ";", "}", "return", "(", "string", ")", "$", "data", "[", "'val'", "]", "===", "(", "string", ")", "$", "data", "[", "'value'", "]", ";", "}" ]
Check whether or not the checkbox should be checked. @param array $data Data to look at and determine checked state. @return bool
[ "Check", "whether", "or", "not", "the", "checkbox", "should", "be", "checked", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/CheckboxWidget.php#L75-L82
211,688
cakephp/cakephp
src/Core/Configure.php
Configure.write
public static function write($config, $value = null) { if (!is_array($config)) { $config = [$config => $value]; } foreach ($config as $name => $value) { static::$_values = Hash::insert(static::$_values, $name, $value); } if (isset($config['debug'])) { if (static::$_hasIniSet === null) { static::$_hasIniSet = function_exists('ini_set'); } if (static::$_hasIniSet) { ini_set('display_errors', $config['debug'] ? '1' : '0'); } } return true; }
php
public static function write($config, $value = null) { if (!is_array($config)) { $config = [$config => $value]; } foreach ($config as $name => $value) { static::$_values = Hash::insert(static::$_values, $name, $value); } if (isset($config['debug'])) { if (static::$_hasIniSet === null) { static::$_hasIniSet = function_exists('ini_set'); } if (static::$_hasIniSet) { ini_set('display_errors', $config['debug'] ? '1' : '0'); } } return true; }
[ "public", "static", "function", "write", "(", "$", "config", ",", "$", "value", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "config", ")", ")", "{", "$", "config", "=", "[", "$", "config", "=>", "$", "value", "]", ";", "}", "foreach", "(", "$", "config", "as", "$", "name", "=>", "$", "value", ")", "{", "static", "::", "$", "_values", "=", "Hash", "::", "insert", "(", "static", "::", "$", "_values", ",", "$", "name", ",", "$", "value", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'debug'", "]", ")", ")", "{", "if", "(", "static", "::", "$", "_hasIniSet", "===", "null", ")", "{", "static", "::", "$", "_hasIniSet", "=", "function_exists", "(", "'ini_set'", ")", ";", "}", "if", "(", "static", "::", "$", "_hasIniSet", ")", "{", "ini_set", "(", "'display_errors'", ",", "$", "config", "[", "'debug'", "]", "?", "'1'", ":", "'0'", ")", ";", "}", "}", "return", "true", ";", "}" ]
Used to store a dynamic variable in Configure. Usage: ``` Configure::write('One.key1', 'value of the Configure::One[key1]'); Configure::write(['One.key1' => 'value of the Configure::One[key1]']); Configure::write('One', [ 'key1' => 'value of the Configure::One[key1]', 'key2' => 'value of the Configure::One[key2]' ]); Configure::write([ 'One.key1' => 'value of the Configure::One[key1]', 'One.key2' => 'value of the Configure::One[key2]' ]); ``` @param string|array $config The key to write, can be a dot notation value. Alternatively can be an array containing key(s) and value(s). @param mixed $value Value to set for var @return bool True if write was successful @link https://book.cakephp.org/3.0/en/development/configuration.html#writing-configuration-data
[ "Used", "to", "store", "a", "dynamic", "variable", "in", "Configure", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Configure.php#L84-L104
211,689
cakephp/cakephp
src/Core/Configure.php
Configure.consume
public static function consume($var) { if (strpos($var, '.') === false) { if (!isset(static::$_values[$var])) { return null; } $value = static::$_values[$var]; unset(static::$_values[$var]); return $value; } $value = Hash::get(static::$_values, $var); static::delete($var); return $value; }
php
public static function consume($var) { if (strpos($var, '.') === false) { if (!isset(static::$_values[$var])) { return null; } $value = static::$_values[$var]; unset(static::$_values[$var]); return $value; } $value = Hash::get(static::$_values, $var); static::delete($var); return $value; }
[ "public", "static", "function", "consume", "(", "$", "var", ")", "{", "if", "(", "strpos", "(", "$", "var", ",", "'.'", ")", "===", "false", ")", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "_values", "[", "$", "var", "]", ")", ")", "{", "return", "null", ";", "}", "$", "value", "=", "static", "::", "$", "_values", "[", "$", "var", "]", ";", "unset", "(", "static", "::", "$", "_values", "[", "$", "var", "]", ")", ";", "return", "$", "value", ";", "}", "$", "value", "=", "Hash", "::", "get", "(", "static", "::", "$", "_values", ",", "$", "var", ")", ";", "static", "::", "delete", "(", "$", "var", ")", ";", "return", "$", "value", ";", "}" ]
Used to read and delete a variable from Configure. This is primarily used during bootstrapping to move configuration data out of configure into the various other classes in CakePHP. @param string $var The key to read and remove. @return array|string|null
[ "Used", "to", "read", "and", "delete", "a", "variable", "from", "Configure", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Configure.php#L222-L237
211,690
cakephp/cakephp
src/Core/Configure.php
Configure.configured
public static function configured($name = null) { if ($name !== null) { deprecationWarning( 'Checking for a named engine with configured() is deprecated. ' . 'Use Configure::isConfigured() instead.' ); return isset(static::$_engines[$name]); } return array_keys(static::$_engines); }
php
public static function configured($name = null) { if ($name !== null) { deprecationWarning( 'Checking for a named engine with configured() is deprecated. ' . 'Use Configure::isConfigured() instead.' ); return isset(static::$_engines[$name]); } return array_keys(static::$_engines); }
[ "public", "static", "function", "configured", "(", "$", "name", "=", "null", ")", "{", "if", "(", "$", "name", "!==", "null", ")", "{", "deprecationWarning", "(", "'Checking for a named engine with configured() is deprecated. '", ".", "'Use Configure::isConfigured() instead.'", ")", ";", "return", "isset", "(", "static", "::", "$", "_engines", "[", "$", "name", "]", ")", ";", "}", "return", "array_keys", "(", "static", "::", "$", "_engines", ")", ";", "}" ]
Gets the names of the configured Engine objects. Checking if a specific engine has been configured with this method is deprecated. Use Configure::isConfigured() instead. @param string|null $name Engine name. @return string[]|bool Array of the configured Engine objects, bool for specific name.
[ "Gets", "the", "names", "of", "the", "configured", "Engine", "objects", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Configure.php#L269-L281
211,691
cakephp/cakephp
src/Core/Configure.php
Configure.restore
public static function restore($name, $cacheConfig = 'default') { if (!class_exists(Cache::class)) { throw new RuntimeException('You must install cakephp/cache to use Configure::restore()'); } $values = Cache::read($name, $cacheConfig); if ($values) { return static::write($values); } return false; }
php
public static function restore($name, $cacheConfig = 'default') { if (!class_exists(Cache::class)) { throw new RuntimeException('You must install cakephp/cache to use Configure::restore()'); } $values = Cache::read($name, $cacheConfig); if ($values) { return static::write($values); } return false; }
[ "public", "static", "function", "restore", "(", "$", "name", ",", "$", "cacheConfig", "=", "'default'", ")", "{", "if", "(", "!", "class_exists", "(", "Cache", "::", "class", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'You must install cakephp/cache to use Configure::restore()'", ")", ";", "}", "$", "values", "=", "Cache", "::", "read", "(", "$", "name", ",", "$", "cacheConfig", ")", ";", "if", "(", "$", "values", ")", "{", "return", "static", "::", "write", "(", "$", "values", ")", ";", "}", "return", "false", ";", "}" ]
Restores configuration data stored in the Cache into configure. Restored values will overwrite existing ones. @param string $name Name of the stored config file to load. @param string $cacheConfig Name of the Cache configuration to read from. @return bool Success.
[ "Restores", "configuration", "data", "stored", "in", "the", "Cache", "into", "configure", ".", "Restored", "values", "will", "overwrite", "existing", "ones", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Configure.php#L464-L475
211,692
cakephp/cakephp
src/ORM/AssociationsNormalizerTrait.php
AssociationsNormalizerTrait._normalizeAssociations
protected function _normalizeAssociations($associations) { $result = []; foreach ((array)$associations as $table => $options) { $pointer =& $result; if (is_int($table)) { $table = $options; $options = []; } if (!strpos($table, '.')) { $result[$table] = $options; continue; } $path = explode('.', $table); $table = array_pop($path); $first = array_shift($path); $pointer += [$first => []]; $pointer =& $pointer[$first]; $pointer += ['associated' => []]; foreach ($path as $t) { $pointer += ['associated' => []]; $pointer['associated'] += [$t => []]; $pointer['associated'][$t] += ['associated' => []]; $pointer =& $pointer['associated'][$t]; } $pointer['associated'] += [$table => []]; $pointer['associated'][$table] = $options + $pointer['associated'][$table]; } return isset($result['associated']) ? $result['associated'] : $result; }
php
protected function _normalizeAssociations($associations) { $result = []; foreach ((array)$associations as $table => $options) { $pointer =& $result; if (is_int($table)) { $table = $options; $options = []; } if (!strpos($table, '.')) { $result[$table] = $options; continue; } $path = explode('.', $table); $table = array_pop($path); $first = array_shift($path); $pointer += [$first => []]; $pointer =& $pointer[$first]; $pointer += ['associated' => []]; foreach ($path as $t) { $pointer += ['associated' => []]; $pointer['associated'] += [$t => []]; $pointer['associated'][$t] += ['associated' => []]; $pointer =& $pointer['associated'][$t]; } $pointer['associated'] += [$table => []]; $pointer['associated'][$table] = $options + $pointer['associated'][$table]; } return isset($result['associated']) ? $result['associated'] : $result; }
[ "protected", "function", "_normalizeAssociations", "(", "$", "associations", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "associations", "as", "$", "table", "=>", "$", "options", ")", "{", "$", "pointer", "=", "&", "$", "result", ";", "if", "(", "is_int", "(", "$", "table", ")", ")", "{", "$", "table", "=", "$", "options", ";", "$", "options", "=", "[", "]", ";", "}", "if", "(", "!", "strpos", "(", "$", "table", ",", "'.'", ")", ")", "{", "$", "result", "[", "$", "table", "]", "=", "$", "options", ";", "continue", ";", "}", "$", "path", "=", "explode", "(", "'.'", ",", "$", "table", ")", ";", "$", "table", "=", "array_pop", "(", "$", "path", ")", ";", "$", "first", "=", "array_shift", "(", "$", "path", ")", ";", "$", "pointer", "+=", "[", "$", "first", "=>", "[", "]", "]", ";", "$", "pointer", "=", "&", "$", "pointer", "[", "$", "first", "]", ";", "$", "pointer", "+=", "[", "'associated'", "=>", "[", "]", "]", ";", "foreach", "(", "$", "path", "as", "$", "t", ")", "{", "$", "pointer", "+=", "[", "'associated'", "=>", "[", "]", "]", ";", "$", "pointer", "[", "'associated'", "]", "+=", "[", "$", "t", "=>", "[", "]", "]", ";", "$", "pointer", "[", "'associated'", "]", "[", "$", "t", "]", "+=", "[", "'associated'", "=>", "[", "]", "]", ";", "$", "pointer", "=", "&", "$", "pointer", "[", "'associated'", "]", "[", "$", "t", "]", ";", "}", "$", "pointer", "[", "'associated'", "]", "+=", "[", "$", "table", "=>", "[", "]", "]", ";", "$", "pointer", "[", "'associated'", "]", "[", "$", "table", "]", "=", "$", "options", "+", "$", "pointer", "[", "'associated'", "]", "[", "$", "table", "]", ";", "}", "return", "isset", "(", "$", "result", "[", "'associated'", "]", ")", "?", "$", "result", "[", "'associated'", "]", ":", "$", "result", ";", "}" ]
Returns an array out of the original passed associations list where dot notation is transformed into nested arrays so that they can be parsed by other routines @param array $associations The array of included associations. @return array An array having dot notation transformed into nested arrays
[ "Returns", "an", "array", "out", "of", "the", "original", "passed", "associations", "list", "where", "dot", "notation", "is", "transformed", "into", "nested", "arrays", "so", "that", "they", "can", "be", "parsed", "by", "other", "routines" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationsNormalizerTrait.php#L31-L66
211,693
cakephp/cakephp
src/Database/Statement/PDOStatement.php
PDOStatement.fetch
public function fetch($type = parent::FETCH_TYPE_NUM) { if ($type === static::FETCH_TYPE_NUM) { return $this->_statement->fetch(PDO::FETCH_NUM); } if ($type === static::FETCH_TYPE_ASSOC) { return $this->_statement->fetch(PDO::FETCH_ASSOC); } if ($type === static::FETCH_TYPE_OBJ) { return $this->_statement->fetch(PDO::FETCH_OBJ); } return $this->_statement->fetch($type); }
php
public function fetch($type = parent::FETCH_TYPE_NUM) { if ($type === static::FETCH_TYPE_NUM) { return $this->_statement->fetch(PDO::FETCH_NUM); } if ($type === static::FETCH_TYPE_ASSOC) { return $this->_statement->fetch(PDO::FETCH_ASSOC); } if ($type === static::FETCH_TYPE_OBJ) { return $this->_statement->fetch(PDO::FETCH_OBJ); } return $this->_statement->fetch($type); }
[ "public", "function", "fetch", "(", "$", "type", "=", "parent", "::", "FETCH_TYPE_NUM", ")", "{", "if", "(", "$", "type", "===", "static", "::", "FETCH_TYPE_NUM", ")", "{", "return", "$", "this", "->", "_statement", "->", "fetch", "(", "PDO", "::", "FETCH_NUM", ")", ";", "}", "if", "(", "$", "type", "===", "static", "::", "FETCH_TYPE_ASSOC", ")", "{", "return", "$", "this", "->", "_statement", "->", "fetch", "(", "PDO", "::", "FETCH_ASSOC", ")", ";", "}", "if", "(", "$", "type", "===", "static", "::", "FETCH_TYPE_OBJ", ")", "{", "return", "$", "this", "->", "_statement", "->", "fetch", "(", "PDO", "::", "FETCH_OBJ", ")", ";", "}", "return", "$", "this", "->", "_statement", "->", "fetch", "(", "$", "type", ")", ";", "}" ]
Returns the next row for the result set after executing this statement. Rows can be fetched to contain columns as names or positions. If no rows are left in result set, this method will return false ### Example: ``` $statement = $connection->prepare('SELECT id, title from articles'); $statement->execute(); print_r($statement->fetch('assoc')); // will show ['id' => 1, 'title' => 'a title'] ``` @param string $type 'num' for positional columns, assoc for named columns @return array|false Result array containing columns and values or false if no results are left
[ "Returns", "the", "next", "row", "for", "the", "result", "set", "after", "executing", "this", "statement", ".", "Rows", "can", "be", "fetched", "to", "contain", "columns", "as", "names", "or", "positions", ".", "If", "no", "rows", "are", "left", "in", "result", "set", "this", "method", "will", "return", "false" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Statement/PDOStatement.php#L91-L104
211,694
cakephp/cakephp
src/Collection/CollectionTrait.php
CollectionTrait.optimizeUnwrap
protected function optimizeUnwrap() { $iterator = $this->unwrap(); if (get_class($iterator) === ArrayIterator::class) { $iterator = $iterator->getArrayCopy(); } return $iterator; }
php
protected function optimizeUnwrap() { $iterator = $this->unwrap(); if (get_class($iterator) === ArrayIterator::class) { $iterator = $iterator->getArrayCopy(); } return $iterator; }
[ "protected", "function", "optimizeUnwrap", "(", ")", "{", "$", "iterator", "=", "$", "this", "->", "unwrap", "(", ")", ";", "if", "(", "get_class", "(", "$", "iterator", ")", "===", "ArrayIterator", "::", "class", ")", "{", "$", "iterator", "=", "$", "iterator", "->", "getArrayCopy", "(", ")", ";", "}", "return", "$", "iterator", ";", "}" ]
Unwraps this iterator and returns the simplest traversable that can be used for getting the data out @return \Traversable|array
[ "Unwraps", "this", "iterator", "and", "returns", "the", "simplest", "traversable", "that", "can", "be", "used", "for", "getting", "the", "data", "out" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/CollectionTrait.php#L1004-L1013
211,695
cakephp/cakephp
src/View/Helper/FormHelper.php
FormHelper.widgetRegistry
public function widgetRegistry(WidgetRegistry $instance = null, $widgets = []) { deprecationWarning('widgetRegistry is deprecated, use widgetLocator instead.'); if ($instance) { $instance->add($widgets); $this->setWidgetLocator($instance); } return $this->getWidgetLocator(); }
php
public function widgetRegistry(WidgetRegistry $instance = null, $widgets = []) { deprecationWarning('widgetRegistry is deprecated, use widgetLocator instead.'); if ($instance) { $instance->add($widgets); $this->setWidgetLocator($instance); } return $this->getWidgetLocator(); }
[ "public", "function", "widgetRegistry", "(", "WidgetRegistry", "$", "instance", "=", "null", ",", "$", "widgets", "=", "[", "]", ")", "{", "deprecationWarning", "(", "'widgetRegistry is deprecated, use widgetLocator instead.'", ")", ";", "if", "(", "$", "instance", ")", "{", "$", "instance", "->", "add", "(", "$", "widgets", ")", ";", "$", "this", "->", "setWidgetLocator", "(", "$", "instance", ")", ";", "}", "return", "$", "this", "->", "getWidgetLocator", "(", ")", ";", "}" ]
Set the widget registry the helper will use. @param \Cake\View\Widget\WidgetRegistry|null $instance The registry instance to set. @param array $widgets An array of widgets @return \Cake\View\Widget\WidgetRegistry @deprecated 3.6.0 Use FormHelper::widgetLocator() instead.
[ "Set", "the", "widget", "registry", "the", "helper", "will", "use", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L316-L326
211,696
cakephp/cakephp
src/View/Helper/FormHelper.php
FormHelper.contextFactory
public function contextFactory(ContextFactory $instance = null, array $contexts = []) { if ($instance === null) { if ($this->_contextFactory === null) { $this->_contextFactory = ContextFactory::createWithDefaults($contexts); } return $this->_contextFactory; } $this->_contextFactory = $instance; return $this->_contextFactory; }
php
public function contextFactory(ContextFactory $instance = null, array $contexts = []) { if ($instance === null) { if ($this->_contextFactory === null) { $this->_contextFactory = ContextFactory::createWithDefaults($contexts); } return $this->_contextFactory; } $this->_contextFactory = $instance; return $this->_contextFactory; }
[ "public", "function", "contextFactory", "(", "ContextFactory", "$", "instance", "=", "null", ",", "array", "$", "contexts", "=", "[", "]", ")", "{", "if", "(", "$", "instance", "===", "null", ")", "{", "if", "(", "$", "this", "->", "_contextFactory", "===", "null", ")", "{", "$", "this", "->", "_contextFactory", "=", "ContextFactory", "::", "createWithDefaults", "(", "$", "contexts", ")", ";", "}", "return", "$", "this", "->", "_contextFactory", ";", "}", "$", "this", "->", "_contextFactory", "=", "$", "instance", ";", "return", "$", "this", "->", "_contextFactory", ";", "}" ]
Set the context factory the helper will use. @param \Cake\View\Form\ContextFactory|null $instance The context factory instance to set. @param array $contexts An array of context providers. @return \Cake\View\Form\ContextFactory
[ "Set", "the", "context", "factory", "the", "helper", "will", "use", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L360-L372
211,697
cakephp/cakephp
src/View/Helper/FormHelper.php
FormHelper._formUrl
protected function _formUrl($context, $options) { $request = $this->_View->getRequest(); if ($options['action'] === null && $options['url'] === null) { return $request->getRequestTarget(); } if (is_string($options['url']) || (is_array($options['url']) && isset($options['url']['_name'])) ) { return $options['url']; } if (isset($options['action']) && empty($options['url']['action'])) { $options['url']['action'] = $options['action']; } $actionDefaults = [ 'plugin' => $this->_View->getPlugin(), 'controller' => $request->getParam('controller'), 'action' => $request->getParam('action'), ]; $action = (array)$options['url'] + $actionDefaults; $pk = $context->primaryKey(); if (count($pk)) { $id = $this->getSourceValue($pk[0]); } if (empty($action[0]) && isset($id)) { $action[0] = $id; } return $action; }
php
protected function _formUrl($context, $options) { $request = $this->_View->getRequest(); if ($options['action'] === null && $options['url'] === null) { return $request->getRequestTarget(); } if (is_string($options['url']) || (is_array($options['url']) && isset($options['url']['_name'])) ) { return $options['url']; } if (isset($options['action']) && empty($options['url']['action'])) { $options['url']['action'] = $options['action']; } $actionDefaults = [ 'plugin' => $this->_View->getPlugin(), 'controller' => $request->getParam('controller'), 'action' => $request->getParam('action'), ]; $action = (array)$options['url'] + $actionDefaults; $pk = $context->primaryKey(); if (count($pk)) { $id = $this->getSourceValue($pk[0]); } if (empty($action[0]) && isset($id)) { $action[0] = $id; } return $action; }
[ "protected", "function", "_formUrl", "(", "$", "context", ",", "$", "options", ")", "{", "$", "request", "=", "$", "this", "->", "_View", "->", "getRequest", "(", ")", ";", "if", "(", "$", "options", "[", "'action'", "]", "===", "null", "&&", "$", "options", "[", "'url'", "]", "===", "null", ")", "{", "return", "$", "request", "->", "getRequestTarget", "(", ")", ";", "}", "if", "(", "is_string", "(", "$", "options", "[", "'url'", "]", ")", "||", "(", "is_array", "(", "$", "options", "[", "'url'", "]", ")", "&&", "isset", "(", "$", "options", "[", "'url'", "]", "[", "'_name'", "]", ")", ")", ")", "{", "return", "$", "options", "[", "'url'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'action'", "]", ")", "&&", "empty", "(", "$", "options", "[", "'url'", "]", "[", "'action'", "]", ")", ")", "{", "$", "options", "[", "'url'", "]", "[", "'action'", "]", "=", "$", "options", "[", "'action'", "]", ";", "}", "$", "actionDefaults", "=", "[", "'plugin'", "=>", "$", "this", "->", "_View", "->", "getPlugin", "(", ")", ",", "'controller'", "=>", "$", "request", "->", "getParam", "(", "'controller'", ")", ",", "'action'", "=>", "$", "request", "->", "getParam", "(", "'action'", ")", ",", "]", ";", "$", "action", "=", "(", "array", ")", "$", "options", "[", "'url'", "]", "+", "$", "actionDefaults", ";", "$", "pk", "=", "$", "context", "->", "primaryKey", "(", ")", ";", "if", "(", "count", "(", "$", "pk", ")", ")", "{", "$", "id", "=", "$", "this", "->", "getSourceValue", "(", "$", "pk", "[", "0", "]", ")", ";", "}", "if", "(", "empty", "(", "$", "action", "[", "0", "]", ")", "&&", "isset", "(", "$", "id", ")", ")", "{", "$", "action", "[", "0", "]", "=", "$", "id", ";", "}", "return", "$", "action", ";", "}" ]
Create the URL for a form based on the options. @param \Cake\View\Form\ContextInterface $context The context object to use. @param array $options An array of options from create() @return string|array The action attribute for the form.
[ "Create", "the", "URL", "for", "a", "form", "based", "on", "the", "options", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L530-L565
211,698
cakephp/cakephp
src/View/Helper/FormHelper.php
FormHelper._lastAction
protected function _lastAction($url) { $action = Router::url($url, true); $query = parse_url($action, PHP_URL_QUERY); $query = $query ? '?' . $query : ''; $this->_lastAction = parse_url($action, PHP_URL_PATH) . $query; }
php
protected function _lastAction($url) { $action = Router::url($url, true); $query = parse_url($action, PHP_URL_QUERY); $query = $query ? '?' . $query : ''; $this->_lastAction = parse_url($action, PHP_URL_PATH) . $query; }
[ "protected", "function", "_lastAction", "(", "$", "url", ")", "{", "$", "action", "=", "Router", "::", "url", "(", "$", "url", ",", "true", ")", ";", "$", "query", "=", "parse_url", "(", "$", "action", ",", "PHP_URL_QUERY", ")", ";", "$", "query", "=", "$", "query", "?", "'?'", ".", "$", "query", ":", "''", ";", "$", "this", "->", "_lastAction", "=", "parse_url", "(", "$", "action", ",", "PHP_URL_PATH", ")", ".", "$", "query", ";", "}" ]
Correctly store the last created form action URL. @param string|array $url The URL of the last form. @return void
[ "Correctly", "store", "the", "last", "created", "form", "action", "URL", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L573-L579
211,699
cakephp/cakephp
src/View/Helper/FormHelper.php
FormHelper._csrfField
protected function _csrfField() { $request = $this->_View->getRequest(); if ($request->getParam('_Token.unlockedFields')) { foreach ((array)$request->getParam('_Token.unlockedFields') as $unlocked) { $this->_unlockedFields[] = $unlocked; } } if (!$request->getParam('_csrfToken')) { return ''; } return $this->hidden('_csrfToken', [ 'value' => $request->getParam('_csrfToken'), 'secure' => static::SECURE_SKIP, 'autocomplete' => 'off', ]); }
php
protected function _csrfField() { $request = $this->_View->getRequest(); if ($request->getParam('_Token.unlockedFields')) { foreach ((array)$request->getParam('_Token.unlockedFields') as $unlocked) { $this->_unlockedFields[] = $unlocked; } } if (!$request->getParam('_csrfToken')) { return ''; } return $this->hidden('_csrfToken', [ 'value' => $request->getParam('_csrfToken'), 'secure' => static::SECURE_SKIP, 'autocomplete' => 'off', ]); }
[ "protected", "function", "_csrfField", "(", ")", "{", "$", "request", "=", "$", "this", "->", "_View", "->", "getRequest", "(", ")", ";", "if", "(", "$", "request", "->", "getParam", "(", "'_Token.unlockedFields'", ")", ")", "{", "foreach", "(", "(", "array", ")", "$", "request", "->", "getParam", "(", "'_Token.unlockedFields'", ")", "as", "$", "unlocked", ")", "{", "$", "this", "->", "_unlockedFields", "[", "]", "=", "$", "unlocked", ";", "}", "}", "if", "(", "!", "$", "request", "->", "getParam", "(", "'_csrfToken'", ")", ")", "{", "return", "''", ";", "}", "return", "$", "this", "->", "hidden", "(", "'_csrfToken'", ",", "[", "'value'", "=>", "$", "request", "->", "getParam", "(", "'_csrfToken'", ")", ",", "'secure'", "=>", "static", "::", "SECURE_SKIP", ",", "'autocomplete'", "=>", "'off'", ",", "]", ")", ";", "}" ]
Return a CSRF input if the request data is present. Used to secure forms in conjunction with CsrfComponent & SecurityComponent @return string
[ "Return", "a", "CSRF", "input", "if", "the", "request", "data", "is", "present", ".", "Used", "to", "secure", "forms", "in", "conjunction", "with", "CsrfComponent", "&", "SecurityComponent" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L588-L606