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,300
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._authRequired
protected function _authRequired(Controller $controller) { $request = $controller->getRequest(); if (is_array($this->_config['requireAuth']) && !empty($this->_config['requireAuth']) && $request->getData() ) { deprecationWarning('SecurityComponent::requireAuth() will be removed in 4.0.0.'); $requireAuth = $this->_config['requireAuth']; if (in_array($request->getParam('action'), $requireAuth) || $requireAuth == ['*']) { if ($request->getData('_Token') === null) { throw new AuthSecurityException('\'_Token\' was not found in request data.'); } if ($this->session->check('_Token')) { $tData = $this->session->read('_Token'); if (!empty($tData['allowedControllers']) && !in_array($request->getParam('controller'), $tData['allowedControllers'])) { throw new AuthSecurityException( sprintf( 'Controller \'%s\' was not found in allowed controllers: \'%s\'.', $request->getParam('controller'), implode(', ', (array)$tData['allowedControllers']) ) ); } if (!empty($tData['allowedActions']) && !in_array($request->getParam('action'), $tData['allowedActions']) ) { throw new AuthSecurityException( sprintf( 'Action \'%s::%s\' was not found in allowed actions: \'%s\'.', $request->getParam('controller'), $request->getParam('action'), implode(', ', (array)$tData['allowedActions']) ) ); } } else { throw new AuthSecurityException('\'_Token\' was not found in session.'); } } } return true; }
php
protected function _authRequired(Controller $controller) { $request = $controller->getRequest(); if (is_array($this->_config['requireAuth']) && !empty($this->_config['requireAuth']) && $request->getData() ) { deprecationWarning('SecurityComponent::requireAuth() will be removed in 4.0.0.'); $requireAuth = $this->_config['requireAuth']; if (in_array($request->getParam('action'), $requireAuth) || $requireAuth == ['*']) { if ($request->getData('_Token') === null) { throw new AuthSecurityException('\'_Token\' was not found in request data.'); } if ($this->session->check('_Token')) { $tData = $this->session->read('_Token'); if (!empty($tData['allowedControllers']) && !in_array($request->getParam('controller'), $tData['allowedControllers'])) { throw new AuthSecurityException( sprintf( 'Controller \'%s\' was not found in allowed controllers: \'%s\'.', $request->getParam('controller'), implode(', ', (array)$tData['allowedControllers']) ) ); } if (!empty($tData['allowedActions']) && !in_array($request->getParam('action'), $tData['allowedActions']) ) { throw new AuthSecurityException( sprintf( 'Action \'%s::%s\' was not found in allowed actions: \'%s\'.', $request->getParam('controller'), $request->getParam('action'), implode(', ', (array)$tData['allowedActions']) ) ); } } else { throw new AuthSecurityException('\'_Token\' was not found in session.'); } } } return true; }
[ "protected", "function", "_authRequired", "(", "Controller", "$", "controller", ")", "{", "$", "request", "=", "$", "controller", "->", "getRequest", "(", ")", ";", "if", "(", "is_array", "(", "$", "this", "->", "_config", "[", "'requireAuth'", "]", ")", "&&", "!", "empty", "(", "$", "this", "->", "_config", "[", "'requireAuth'", "]", ")", "&&", "$", "request", "->", "getData", "(", ")", ")", "{", "deprecationWarning", "(", "'SecurityComponent::requireAuth() will be removed in 4.0.0.'", ")", ";", "$", "requireAuth", "=", "$", "this", "->", "_config", "[", "'requireAuth'", "]", ";", "if", "(", "in_array", "(", "$", "request", "->", "getParam", "(", "'action'", ")", ",", "$", "requireAuth", ")", "||", "$", "requireAuth", "==", "[", "'*'", "]", ")", "{", "if", "(", "$", "request", "->", "getData", "(", "'_Token'", ")", "===", "null", ")", "{", "throw", "new", "AuthSecurityException", "(", "'\\'_Token\\' was not found in request data.'", ")", ";", "}", "if", "(", "$", "this", "->", "session", "->", "check", "(", "'_Token'", ")", ")", "{", "$", "tData", "=", "$", "this", "->", "session", "->", "read", "(", "'_Token'", ")", ";", "if", "(", "!", "empty", "(", "$", "tData", "[", "'allowedControllers'", "]", ")", "&&", "!", "in_array", "(", "$", "request", "->", "getParam", "(", "'controller'", ")", ",", "$", "tData", "[", "'allowedControllers'", "]", ")", ")", "{", "throw", "new", "AuthSecurityException", "(", "sprintf", "(", "'Controller \\'%s\\' was not found in allowed controllers: \\'%s\\'.'", ",", "$", "request", "->", "getParam", "(", "'controller'", ")", ",", "implode", "(", "', '", ",", "(", "array", ")", "$", "tData", "[", "'allowedControllers'", "]", ")", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "tData", "[", "'allowedActions'", "]", ")", "&&", "!", "in_array", "(", "$", "request", "->", "getParam", "(", "'action'", ")", ",", "$", "tData", "[", "'allowedActions'", "]", ")", ")", "{", "throw", "new", "AuthSecurityException", "(", "sprintf", "(", "'Action \\'%s::%s\\' was not found in allowed actions: \\'%s\\'.'", ",", "$", "request", "->", "getParam", "(", "'controller'", ")", ",", "$", "request", "->", "getParam", "(", "'action'", ")", ",", "implode", "(", "', '", ",", "(", "array", ")", "$", "tData", "[", "'allowedActions'", "]", ")", ")", ")", ";", "}", "}", "else", "{", "throw", "new", "AuthSecurityException", "(", "'\\'_Token\\' was not found in session.'", ")", ";", "}", "}", "}", "return", "true", ";", "}" ]
Check if authentication is required @param \Cake\Controller\Controller $controller Instantiating controller @return bool true if authentication required @deprecated 3.2.2 This feature is confusing and not useful.
[ "Check", "if", "authentication", "is", "required" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L264-L311
211,301
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._validatePost
protected function _validatePost(Controller $controller) { $token = $this->_validToken($controller); $hashParts = $this->_hashParts($controller); $check = hash_hmac('sha1', implode('', $hashParts), Security::getSalt()); if (hash_equals($check, $token)) { return true; } $msg = self::DEFAULT_EXCEPTION_MESSAGE; if (Configure::read('debug')) { $msg = $this->_debugPostTokenNotMatching($controller, $hashParts); } throw new AuthSecurityException($msg); }
php
protected function _validatePost(Controller $controller) { $token = $this->_validToken($controller); $hashParts = $this->_hashParts($controller); $check = hash_hmac('sha1', implode('', $hashParts), Security::getSalt()); if (hash_equals($check, $token)) { return true; } $msg = self::DEFAULT_EXCEPTION_MESSAGE; if (Configure::read('debug')) { $msg = $this->_debugPostTokenNotMatching($controller, $hashParts); } throw new AuthSecurityException($msg); }
[ "protected", "function", "_validatePost", "(", "Controller", "$", "controller", ")", "{", "$", "token", "=", "$", "this", "->", "_validToken", "(", "$", "controller", ")", ";", "$", "hashParts", "=", "$", "this", "->", "_hashParts", "(", "$", "controller", ")", ";", "$", "check", "=", "hash_hmac", "(", "'sha1'", ",", "implode", "(", "''", ",", "$", "hashParts", ")", ",", "Security", "::", "getSalt", "(", ")", ")", ";", "if", "(", "hash_equals", "(", "$", "check", ",", "$", "token", ")", ")", "{", "return", "true", ";", "}", "$", "msg", "=", "self", "::", "DEFAULT_EXCEPTION_MESSAGE", ";", "if", "(", "Configure", "::", "read", "(", "'debug'", ")", ")", "{", "$", "msg", "=", "$", "this", "->", "_debugPostTokenNotMatching", "(", "$", "controller", ",", "$", "hashParts", ")", ";", "}", "throw", "new", "AuthSecurityException", "(", "$", "msg", ")", ";", "}" ]
Validate submitted form @param \Cake\Controller\Controller $controller Instantiating controller @throws \Cake\Controller\Exception\AuthSecurityException @return bool true if submitted form is valid
[ "Validate", "submitted", "form" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L320-L336
211,302
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._hashParts
protected function _hashParts(Controller $controller) { $request = $controller->getRequest(); // Start the session to ensure we get the correct session id. $session = $request->getSession(); $session->start(); $data = $request->getData(); $fieldList = $this->_fieldsList($data); $unlocked = $this->_sortedUnlocked($data); return [ Router::url($request->getRequestTarget()), serialize($fieldList), $unlocked, $session->id() ]; }
php
protected function _hashParts(Controller $controller) { $request = $controller->getRequest(); // Start the session to ensure we get the correct session id. $session = $request->getSession(); $session->start(); $data = $request->getData(); $fieldList = $this->_fieldsList($data); $unlocked = $this->_sortedUnlocked($data); return [ Router::url($request->getRequestTarget()), serialize($fieldList), $unlocked, $session->id() ]; }
[ "protected", "function", "_hashParts", "(", "Controller", "$", "controller", ")", "{", "$", "request", "=", "$", "controller", "->", "getRequest", "(", ")", ";", "// Start the session to ensure we get the correct session id.", "$", "session", "=", "$", "request", "->", "getSession", "(", ")", ";", "$", "session", "->", "start", "(", ")", ";", "$", "data", "=", "$", "request", "->", "getData", "(", ")", ";", "$", "fieldList", "=", "$", "this", "->", "_fieldsList", "(", "$", "data", ")", ";", "$", "unlocked", "=", "$", "this", "->", "_sortedUnlocked", "(", "$", "data", ")", ";", "return", "[", "Router", "::", "url", "(", "$", "request", "->", "getRequestTarget", "(", ")", ")", ",", "serialize", "(", "$", "fieldList", ")", ",", "$", "unlocked", ",", "$", "session", "->", "id", "(", ")", "]", ";", "}" ]
Return hash parts for the Token generation @param \Cake\Controller\Controller $controller Instantiating controller @return array
[ "Return", "hash", "parts", "for", "the", "Token", "generation" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L380-L398
211,303
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._fieldsList
protected function _fieldsList(array $check) { $locked = ''; $token = urldecode($check['_Token']['fields']); $unlocked = $this->_unlocked($check); if (strpos($token, ':')) { list($token, $locked) = explode(':', $token, 2); } unset($check['_Token'], $check['_csrfToken']); $locked = explode('|', $locked); $unlocked = explode('|', $unlocked); $fields = Hash::flatten($check); $fieldList = array_keys($fields); $multi = $lockedFields = []; $isUnlocked = false; foreach ($fieldList as $i => $key) { if (preg_match('/(\.\d+){1,10}$/', $key)) { $multi[$i] = preg_replace('/(\.\d+){1,10}$/', '', $key); unset($fieldList[$i]); } else { $fieldList[$i] = (string)$key; } } if (!empty($multi)) { $fieldList += array_unique($multi); } $unlockedFields = array_unique( array_merge((array)$this->getConfig('disabledFields'), (array)$this->_config['unlockedFields'], $unlocked) ); foreach ($fieldList as $i => $key) { $isLocked = (is_array($locked) && in_array($key, $locked)); if (!empty($unlockedFields)) { foreach ($unlockedFields as $off) { $off = explode('.', $off); $field = array_values(array_intersect(explode('.', $key), $off)); $isUnlocked = ($field === $off); if ($isUnlocked) { break; } } } if ($isUnlocked || $isLocked) { unset($fieldList[$i]); if ($isLocked) { $lockedFields[$key] = $fields[$key]; } } } sort($fieldList, SORT_STRING); ksort($lockedFields, SORT_STRING); $fieldList += $lockedFields; return $fieldList; }
php
protected function _fieldsList(array $check) { $locked = ''; $token = urldecode($check['_Token']['fields']); $unlocked = $this->_unlocked($check); if (strpos($token, ':')) { list($token, $locked) = explode(':', $token, 2); } unset($check['_Token'], $check['_csrfToken']); $locked = explode('|', $locked); $unlocked = explode('|', $unlocked); $fields = Hash::flatten($check); $fieldList = array_keys($fields); $multi = $lockedFields = []; $isUnlocked = false; foreach ($fieldList as $i => $key) { if (preg_match('/(\.\d+){1,10}$/', $key)) { $multi[$i] = preg_replace('/(\.\d+){1,10}$/', '', $key); unset($fieldList[$i]); } else { $fieldList[$i] = (string)$key; } } if (!empty($multi)) { $fieldList += array_unique($multi); } $unlockedFields = array_unique( array_merge((array)$this->getConfig('disabledFields'), (array)$this->_config['unlockedFields'], $unlocked) ); foreach ($fieldList as $i => $key) { $isLocked = (is_array($locked) && in_array($key, $locked)); if (!empty($unlockedFields)) { foreach ($unlockedFields as $off) { $off = explode('.', $off); $field = array_values(array_intersect(explode('.', $key), $off)); $isUnlocked = ($field === $off); if ($isUnlocked) { break; } } } if ($isUnlocked || $isLocked) { unset($fieldList[$i]); if ($isLocked) { $lockedFields[$key] = $fields[$key]; } } } sort($fieldList, SORT_STRING); ksort($lockedFields, SORT_STRING); $fieldList += $lockedFields; return $fieldList; }
[ "protected", "function", "_fieldsList", "(", "array", "$", "check", ")", "{", "$", "locked", "=", "''", ";", "$", "token", "=", "urldecode", "(", "$", "check", "[", "'_Token'", "]", "[", "'fields'", "]", ")", ";", "$", "unlocked", "=", "$", "this", "->", "_unlocked", "(", "$", "check", ")", ";", "if", "(", "strpos", "(", "$", "token", ",", "':'", ")", ")", "{", "list", "(", "$", "token", ",", "$", "locked", ")", "=", "explode", "(", "':'", ",", "$", "token", ",", "2", ")", ";", "}", "unset", "(", "$", "check", "[", "'_Token'", "]", ",", "$", "check", "[", "'_csrfToken'", "]", ")", ";", "$", "locked", "=", "explode", "(", "'|'", ",", "$", "locked", ")", ";", "$", "unlocked", "=", "explode", "(", "'|'", ",", "$", "unlocked", ")", ";", "$", "fields", "=", "Hash", "::", "flatten", "(", "$", "check", ")", ";", "$", "fieldList", "=", "array_keys", "(", "$", "fields", ")", ";", "$", "multi", "=", "$", "lockedFields", "=", "[", "]", ";", "$", "isUnlocked", "=", "false", ";", "foreach", "(", "$", "fieldList", "as", "$", "i", "=>", "$", "key", ")", "{", "if", "(", "preg_match", "(", "'/(\\.\\d+){1,10}$/'", ",", "$", "key", ")", ")", "{", "$", "multi", "[", "$", "i", "]", "=", "preg_replace", "(", "'/(\\.\\d+){1,10}$/'", ",", "''", ",", "$", "key", ")", ";", "unset", "(", "$", "fieldList", "[", "$", "i", "]", ")", ";", "}", "else", "{", "$", "fieldList", "[", "$", "i", "]", "=", "(", "string", ")", "$", "key", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "multi", ")", ")", "{", "$", "fieldList", "+=", "array_unique", "(", "$", "multi", ")", ";", "}", "$", "unlockedFields", "=", "array_unique", "(", "array_merge", "(", "(", "array", ")", "$", "this", "->", "getConfig", "(", "'disabledFields'", ")", ",", "(", "array", ")", "$", "this", "->", "_config", "[", "'unlockedFields'", "]", ",", "$", "unlocked", ")", ")", ";", "foreach", "(", "$", "fieldList", "as", "$", "i", "=>", "$", "key", ")", "{", "$", "isLocked", "=", "(", "is_array", "(", "$", "locked", ")", "&&", "in_array", "(", "$", "key", ",", "$", "locked", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "unlockedFields", ")", ")", "{", "foreach", "(", "$", "unlockedFields", "as", "$", "off", ")", "{", "$", "off", "=", "explode", "(", "'.'", ",", "$", "off", ")", ";", "$", "field", "=", "array_values", "(", "array_intersect", "(", "explode", "(", "'.'", ",", "$", "key", ")", ",", "$", "off", ")", ")", ";", "$", "isUnlocked", "=", "(", "$", "field", "===", "$", "off", ")", ";", "if", "(", "$", "isUnlocked", ")", "{", "break", ";", "}", "}", "}", "if", "(", "$", "isUnlocked", "||", "$", "isLocked", ")", "{", "unset", "(", "$", "fieldList", "[", "$", "i", "]", ")", ";", "if", "(", "$", "isLocked", ")", "{", "$", "lockedFields", "[", "$", "key", "]", "=", "$", "fields", "[", "$", "key", "]", ";", "}", "}", "}", "sort", "(", "$", "fieldList", ",", "SORT_STRING", ")", ";", "ksort", "(", "$", "lockedFields", ",", "SORT_STRING", ")", ";", "$", "fieldList", "+=", "$", "lockedFields", ";", "return", "$", "fieldList", ";", "}" ]
Return the fields list for the hash calculation @param array $check Data array @return array
[ "Return", "the", "fields", "list", "for", "the", "hash", "calculation" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L406-L467
211,304
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._sortedUnlocked
protected function _sortedUnlocked($data) { $unlocked = $this->_unlocked($data); $unlocked = explode('|', $unlocked); sort($unlocked, SORT_STRING); return implode('|', $unlocked); }
php
protected function _sortedUnlocked($data) { $unlocked = $this->_unlocked($data); $unlocked = explode('|', $unlocked); sort($unlocked, SORT_STRING); return implode('|', $unlocked); }
[ "protected", "function", "_sortedUnlocked", "(", "$", "data", ")", "{", "$", "unlocked", "=", "$", "this", "->", "_unlocked", "(", "$", "data", ")", ";", "$", "unlocked", "=", "explode", "(", "'|'", ",", "$", "unlocked", ")", ";", "sort", "(", "$", "unlocked", ",", "SORT_STRING", ")", ";", "return", "implode", "(", "'|'", ",", "$", "unlocked", ")", ";", "}" ]
Get the sorted unlocked string @param array $data Data array @return string
[ "Get", "the", "sorted", "unlocked", "string" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L486-L493
211,305
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._debugPostTokenNotMatching
protected function _debugPostTokenNotMatching(Controller $controller, $hashParts) { $messages = []; $expectedParts = json_decode(urldecode($controller->getRequest()->getData('_Token.debug')), true); if (!is_array($expectedParts) || count($expectedParts) !== 3) { return 'Invalid security debug token.'; } $expectedUrl = Hash::get($expectedParts, 0); $url = Hash::get($hashParts, 0); if ($expectedUrl !== $url) { $messages[] = sprintf('URL mismatch in POST data (expected \'%s\' but found \'%s\')', $expectedUrl, $url); } $expectedFields = Hash::get($expectedParts, 1); $dataFields = Hash::get($hashParts, 1); if ($dataFields) { $dataFields = unserialize($dataFields); } $fieldsMessages = $this->_debugCheckFields( $dataFields, $expectedFields, 'Unexpected field \'%s\' in POST data', 'Tampered field \'%s\' in POST data (expected value \'%s\' but found \'%s\')', 'Missing field \'%s\' in POST data' ); $expectedUnlockedFields = Hash::get($expectedParts, 2); $dataUnlockedFields = Hash::get($hashParts, 2) ?: null; if ($dataUnlockedFields) { $dataUnlockedFields = explode('|', $dataUnlockedFields); } $unlockFieldsMessages = $this->_debugCheckFields( (array)$dataUnlockedFields, $expectedUnlockedFields, 'Unexpected unlocked field \'%s\' in POST data', null, 'Missing unlocked field: \'%s\'' ); $messages = array_merge($messages, $fieldsMessages, $unlockFieldsMessages); return implode(', ', $messages); }
php
protected function _debugPostTokenNotMatching(Controller $controller, $hashParts) { $messages = []; $expectedParts = json_decode(urldecode($controller->getRequest()->getData('_Token.debug')), true); if (!is_array($expectedParts) || count($expectedParts) !== 3) { return 'Invalid security debug token.'; } $expectedUrl = Hash::get($expectedParts, 0); $url = Hash::get($hashParts, 0); if ($expectedUrl !== $url) { $messages[] = sprintf('URL mismatch in POST data (expected \'%s\' but found \'%s\')', $expectedUrl, $url); } $expectedFields = Hash::get($expectedParts, 1); $dataFields = Hash::get($hashParts, 1); if ($dataFields) { $dataFields = unserialize($dataFields); } $fieldsMessages = $this->_debugCheckFields( $dataFields, $expectedFields, 'Unexpected field \'%s\' in POST data', 'Tampered field \'%s\' in POST data (expected value \'%s\' but found \'%s\')', 'Missing field \'%s\' in POST data' ); $expectedUnlockedFields = Hash::get($expectedParts, 2); $dataUnlockedFields = Hash::get($hashParts, 2) ?: null; if ($dataUnlockedFields) { $dataUnlockedFields = explode('|', $dataUnlockedFields); } $unlockFieldsMessages = $this->_debugCheckFields( (array)$dataUnlockedFields, $expectedUnlockedFields, 'Unexpected unlocked field \'%s\' in POST data', null, 'Missing unlocked field: \'%s\'' ); $messages = array_merge($messages, $fieldsMessages, $unlockFieldsMessages); return implode(', ', $messages); }
[ "protected", "function", "_debugPostTokenNotMatching", "(", "Controller", "$", "controller", ",", "$", "hashParts", ")", "{", "$", "messages", "=", "[", "]", ";", "$", "expectedParts", "=", "json_decode", "(", "urldecode", "(", "$", "controller", "->", "getRequest", "(", ")", "->", "getData", "(", "'_Token.debug'", ")", ")", ",", "true", ")", ";", "if", "(", "!", "is_array", "(", "$", "expectedParts", ")", "||", "count", "(", "$", "expectedParts", ")", "!==", "3", ")", "{", "return", "'Invalid security debug token.'", ";", "}", "$", "expectedUrl", "=", "Hash", "::", "get", "(", "$", "expectedParts", ",", "0", ")", ";", "$", "url", "=", "Hash", "::", "get", "(", "$", "hashParts", ",", "0", ")", ";", "if", "(", "$", "expectedUrl", "!==", "$", "url", ")", "{", "$", "messages", "[", "]", "=", "sprintf", "(", "'URL mismatch in POST data (expected \\'%s\\' but found \\'%s\\')'", ",", "$", "expectedUrl", ",", "$", "url", ")", ";", "}", "$", "expectedFields", "=", "Hash", "::", "get", "(", "$", "expectedParts", ",", "1", ")", ";", "$", "dataFields", "=", "Hash", "::", "get", "(", "$", "hashParts", ",", "1", ")", ";", "if", "(", "$", "dataFields", ")", "{", "$", "dataFields", "=", "unserialize", "(", "$", "dataFields", ")", ";", "}", "$", "fieldsMessages", "=", "$", "this", "->", "_debugCheckFields", "(", "$", "dataFields", ",", "$", "expectedFields", ",", "'Unexpected field \\'%s\\' in POST data'", ",", "'Tampered field \\'%s\\' in POST data (expected value \\'%s\\' but found \\'%s\\')'", ",", "'Missing field \\'%s\\' in POST data'", ")", ";", "$", "expectedUnlockedFields", "=", "Hash", "::", "get", "(", "$", "expectedParts", ",", "2", ")", ";", "$", "dataUnlockedFields", "=", "Hash", "::", "get", "(", "$", "hashParts", ",", "2", ")", "?", ":", "null", ";", "if", "(", "$", "dataUnlockedFields", ")", "{", "$", "dataUnlockedFields", "=", "explode", "(", "'|'", ",", "$", "dataUnlockedFields", ")", ";", "}", "$", "unlockFieldsMessages", "=", "$", "this", "->", "_debugCheckFields", "(", "(", "array", ")", "$", "dataUnlockedFields", ",", "$", "expectedUnlockedFields", ",", "'Unexpected unlocked field \\'%s\\' in POST data'", ",", "null", ",", "'Missing unlocked field: \\'%s\\''", ")", ";", "$", "messages", "=", "array_merge", "(", "$", "messages", ",", "$", "fieldsMessages", ",", "$", "unlockFieldsMessages", ")", ";", "return", "implode", "(", "', '", ",", "$", "messages", ")", ";", "}" ]
Create a message for humans to understand why Security token is not matching @param \Cake\Controller\Controller $controller Instantiating controller @param array $hashParts Elements used to generate the Token hash @return string Message explaining why the tokens are not matching
[ "Create", "a", "message", "for", "humans", "to", "understand", "why", "Security", "token", "is", "not", "matching" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L502-L542
211,306
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._debugCheckFields
protected function _debugCheckFields($dataFields, $expectedFields = [], $intKeyMessage = '', $stringKeyMessage = '', $missingMessage = '') { $messages = $this->_matchExistingFields($dataFields, $expectedFields, $intKeyMessage, $stringKeyMessage); $expectedFieldsMessage = $this->_debugExpectedFields($expectedFields, $missingMessage); if ($expectedFieldsMessage !== null) { $messages[] = $expectedFieldsMessage; } return $messages; }
php
protected function _debugCheckFields($dataFields, $expectedFields = [], $intKeyMessage = '', $stringKeyMessage = '', $missingMessage = '') { $messages = $this->_matchExistingFields($dataFields, $expectedFields, $intKeyMessage, $stringKeyMessage); $expectedFieldsMessage = $this->_debugExpectedFields($expectedFields, $missingMessage); if ($expectedFieldsMessage !== null) { $messages[] = $expectedFieldsMessage; } return $messages; }
[ "protected", "function", "_debugCheckFields", "(", "$", "dataFields", ",", "$", "expectedFields", "=", "[", "]", ",", "$", "intKeyMessage", "=", "''", ",", "$", "stringKeyMessage", "=", "''", ",", "$", "missingMessage", "=", "''", ")", "{", "$", "messages", "=", "$", "this", "->", "_matchExistingFields", "(", "$", "dataFields", ",", "$", "expectedFields", ",", "$", "intKeyMessage", ",", "$", "stringKeyMessage", ")", ";", "$", "expectedFieldsMessage", "=", "$", "this", "->", "_debugExpectedFields", "(", "$", "expectedFields", ",", "$", "missingMessage", ")", ";", "if", "(", "$", "expectedFieldsMessage", "!==", "null", ")", "{", "$", "messages", "[", "]", "=", "$", "expectedFieldsMessage", ";", "}", "return", "$", "messages", ";", "}" ]
Iterates data array to check against expected @param array $dataFields Fields array, containing the POST data fields @param array $expectedFields Fields array, containing the expected fields we should have in POST @param string $intKeyMessage Message string if unexpected found in data fields indexed by int (not protected) @param string $stringKeyMessage Message string if tampered found in data fields indexed by string (protected) @param string $missingMessage Message string if missing field @return array Messages
[ "Iterates", "data", "array", "to", "check", "against", "expected" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L554-L563
211,307
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent.generateToken
public function generateToken(ServerRequest $request) { if ($request->is('requested')) { if ($this->session->check('_Token')) { $request = $request->withParam('_Token', $this->session->read('_Token')); } return $request; } $token = [ 'allowedControllers' => $this->_config['allowedControllers'], 'allowedActions' => $this->_config['allowedActions'], 'unlockedFields' => $this->_config['unlockedFields'], ]; $this->session->write('_Token', $token); return $request->withParam('_Token', [ 'unlockedFields' => $token['unlockedFields'] ]); }
php
public function generateToken(ServerRequest $request) { if ($request->is('requested')) { if ($this->session->check('_Token')) { $request = $request->withParam('_Token', $this->session->read('_Token')); } return $request; } $token = [ 'allowedControllers' => $this->_config['allowedControllers'], 'allowedActions' => $this->_config['allowedActions'], 'unlockedFields' => $this->_config['unlockedFields'], ]; $this->session->write('_Token', $token); return $request->withParam('_Token', [ 'unlockedFields' => $token['unlockedFields'] ]); }
[ "public", "function", "generateToken", "(", "ServerRequest", "$", "request", ")", "{", "if", "(", "$", "request", "->", "is", "(", "'requested'", ")", ")", "{", "if", "(", "$", "this", "->", "session", "->", "check", "(", "'_Token'", ")", ")", "{", "$", "request", "=", "$", "request", "->", "withParam", "(", "'_Token'", ",", "$", "this", "->", "session", "->", "read", "(", "'_Token'", ")", ")", ";", "}", "return", "$", "request", ";", "}", "$", "token", "=", "[", "'allowedControllers'", "=>", "$", "this", "->", "_config", "[", "'allowedControllers'", "]", ",", "'allowedActions'", "=>", "$", "this", "->", "_config", "[", "'allowedActions'", "]", ",", "'unlockedFields'", "=>", "$", "this", "->", "_config", "[", "'unlockedFields'", "]", ",", "]", ";", "$", "this", "->", "session", "->", "write", "(", "'_Token'", ",", "$", "token", ")", ";", "return", "$", "request", "->", "withParam", "(", "'_Token'", ",", "[", "'unlockedFields'", "=>", "$", "token", "[", "'unlockedFields'", "]", "]", ")", ";", "}" ]
Manually add form tampering prevention token information into the provided request object. @param \Cake\Http\ServerRequest $request The request object to add into. @return \Cake\Http\ServerRequest The modified request.
[ "Manually", "add", "form", "tampering", "prevention", "token", "information", "into", "the", "provided", "request", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L572-L592
211,308
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._callback
protected function _callback(Controller $controller, $method, $params = []) { if (!is_callable([$controller, $method])) { throw new BadRequestException('The request has been black-holed'); } return call_user_func_array([&$controller, $method], empty($params) ? null : $params); }
php
protected function _callback(Controller $controller, $method, $params = []) { if (!is_callable([$controller, $method])) { throw new BadRequestException('The request has been black-holed'); } return call_user_func_array([&$controller, $method], empty($params) ? null : $params); }
[ "protected", "function", "_callback", "(", "Controller", "$", "controller", ",", "$", "method", ",", "$", "params", "=", "[", "]", ")", "{", "if", "(", "!", "is_callable", "(", "[", "$", "controller", ",", "$", "method", "]", ")", ")", "{", "throw", "new", "BadRequestException", "(", "'The request has been black-holed'", ")", ";", "}", "return", "call_user_func_array", "(", "[", "&", "$", "controller", ",", "$", "method", "]", ",", "empty", "(", "$", "params", ")", "?", "null", ":", "$", "params", ")", ";", "}" ]
Calls a controller callback method @param \Cake\Controller\Controller $controller Instantiating controller @param string $method Method to execute @param array $params Parameters to send to method @return mixed Controller callback method's response @throws \Cake\Http\Exception\BadRequestException When a the blackholeCallback is not callable.
[ "Calls", "a", "controller", "callback", "method" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L603-L610
211,309
cakephp/cakephp
src/Controller/Component/SecurityComponent.php
SecurityComponent._debugExpectedFields
protected function _debugExpectedFields($expectedFields = [], $missingMessage = '') { if (count($expectedFields) === 0) { return null; } $expectedFieldNames = []; foreach ((array)$expectedFields as $key => $expectedField) { if (is_int($key)) { $expectedFieldNames[] = $expectedField; } else { $expectedFieldNames[] = $key; } } return sprintf($missingMessage, implode(', ', $expectedFieldNames)); }
php
protected function _debugExpectedFields($expectedFields = [], $missingMessage = '') { if (count($expectedFields) === 0) { return null; } $expectedFieldNames = []; foreach ((array)$expectedFields as $key => $expectedField) { if (is_int($key)) { $expectedFieldNames[] = $expectedField; } else { $expectedFieldNames[] = $key; } } return sprintf($missingMessage, implode(', ', $expectedFieldNames)); }
[ "protected", "function", "_debugExpectedFields", "(", "$", "expectedFields", "=", "[", "]", ",", "$", "missingMessage", "=", "''", ")", "{", "if", "(", "count", "(", "$", "expectedFields", ")", "===", "0", ")", "{", "return", "null", ";", "}", "$", "expectedFieldNames", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "expectedFields", "as", "$", "key", "=>", "$", "expectedField", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "$", "expectedFieldNames", "[", "]", "=", "$", "expectedField", ";", "}", "else", "{", "$", "expectedFieldNames", "[", "]", "=", "$", "key", ";", "}", "}", "return", "sprintf", "(", "$", "missingMessage", ",", "implode", "(", "', '", ",", "$", "expectedFieldNames", ")", ")", ";", "}" ]
Generate debug message for the expected fields @param array $expectedFields Expected fields @param string $missingMessage Message template @return string|null Error message about expected fields
[ "Generate", "debug", "message", "for", "the", "expected", "fields" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/SecurityComponent.php#L651-L667
211,310
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest._processPost
protected function _processPost($data) { $method = $this->getEnv('REQUEST_METHOD'); $override = false; if (in_array($method, ['PUT', 'DELETE', 'PATCH']) && strpos($this->contentType(), 'application/x-www-form-urlencoded') === 0 ) { $data = $this->input(); parse_str($data, $data); } if ($this->hasHeader('X-Http-Method-Override')) { $data['_method'] = $this->getHeaderLine('X-Http-Method-Override'); $override = true; } $this->_environment['ORIGINAL_REQUEST_METHOD'] = $method; if (isset($data['_method'])) { $this->_environment['REQUEST_METHOD'] = $data['_method']; unset($data['_method']); $override = true; } if ($override && !in_array($this->_environment['REQUEST_METHOD'], ['PUT', 'POST', 'DELETE', 'PATCH'])) { $data = []; } return $data; }
php
protected function _processPost($data) { $method = $this->getEnv('REQUEST_METHOD'); $override = false; if (in_array($method, ['PUT', 'DELETE', 'PATCH']) && strpos($this->contentType(), 'application/x-www-form-urlencoded') === 0 ) { $data = $this->input(); parse_str($data, $data); } if ($this->hasHeader('X-Http-Method-Override')) { $data['_method'] = $this->getHeaderLine('X-Http-Method-Override'); $override = true; } $this->_environment['ORIGINAL_REQUEST_METHOD'] = $method; if (isset($data['_method'])) { $this->_environment['REQUEST_METHOD'] = $data['_method']; unset($data['_method']); $override = true; } if ($override && !in_array($this->_environment['REQUEST_METHOD'], ['PUT', 'POST', 'DELETE', 'PATCH'])) { $data = []; } return $data; }
[ "protected", "function", "_processPost", "(", "$", "data", ")", "{", "$", "method", "=", "$", "this", "->", "getEnv", "(", "'REQUEST_METHOD'", ")", ";", "$", "override", "=", "false", ";", "if", "(", "in_array", "(", "$", "method", ",", "[", "'PUT'", ",", "'DELETE'", ",", "'PATCH'", "]", ")", "&&", "strpos", "(", "$", "this", "->", "contentType", "(", ")", ",", "'application/x-www-form-urlencoded'", ")", "===", "0", ")", "{", "$", "data", "=", "$", "this", "->", "input", "(", ")", ";", "parse_str", "(", "$", "data", ",", "$", "data", ")", ";", "}", "if", "(", "$", "this", "->", "hasHeader", "(", "'X-Http-Method-Override'", ")", ")", "{", "$", "data", "[", "'_method'", "]", "=", "$", "this", "->", "getHeaderLine", "(", "'X-Http-Method-Override'", ")", ";", "$", "override", "=", "true", ";", "}", "$", "this", "->", "_environment", "[", "'ORIGINAL_REQUEST_METHOD'", "]", "=", "$", "method", ";", "if", "(", "isset", "(", "$", "data", "[", "'_method'", "]", ")", ")", "{", "$", "this", "->", "_environment", "[", "'REQUEST_METHOD'", "]", "=", "$", "data", "[", "'_method'", "]", ";", "unset", "(", "$", "data", "[", "'_method'", "]", ")", ";", "$", "override", "=", "true", ";", "}", "if", "(", "$", "override", "&&", "!", "in_array", "(", "$", "this", "->", "_environment", "[", "'REQUEST_METHOD'", "]", ",", "[", "'PUT'", ",", "'POST'", ",", "'DELETE'", ",", "'PATCH'", "]", ")", ")", "{", "$", "data", "=", "[", "]", ";", "}", "return", "$", "data", ";", "}" ]
Sets the REQUEST_METHOD environment variable based on the simulated _method HTTP override value. The 'ORIGINAL_REQUEST_METHOD' is also preserved, if you want the read the non-simulated HTTP method the client used. @param array $data Array of post data. @return array
[ "Sets", "the", "REQUEST_METHOD", "environment", "variable", "based", "on", "the", "simulated", "_method", "HTTP", "override", "value", ".", "The", "ORIGINAL_REQUEST_METHOD", "is", "also", "preserved", "if", "you", "want", "the", "read", "the", "non", "-", "simulated", "HTTP", "method", "the", "client", "used", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L382-L409
211,311
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest._processGet
protected function _processGet($query, $queryString = '') { $unsetUrl = '/' . str_replace(['.', ' '], '_', urldecode($this->url)); unset($query[$unsetUrl], $query[$this->base . $unsetUrl]); if (strlen($queryString)) { parse_str($queryString, $queryArgs); $query += $queryArgs; } return $query; }
php
protected function _processGet($query, $queryString = '') { $unsetUrl = '/' . str_replace(['.', ' '], '_', urldecode($this->url)); unset($query[$unsetUrl], $query[$this->base . $unsetUrl]); if (strlen($queryString)) { parse_str($queryString, $queryArgs); $query += $queryArgs; } return $query; }
[ "protected", "function", "_processGet", "(", "$", "query", ",", "$", "queryString", "=", "''", ")", "{", "$", "unsetUrl", "=", "'/'", ".", "str_replace", "(", "[", "'.'", ",", "' '", "]", ",", "'_'", ",", "urldecode", "(", "$", "this", "->", "url", ")", ")", ";", "unset", "(", "$", "query", "[", "$", "unsetUrl", "]", ",", "$", "query", "[", "$", "this", "->", "base", ".", "$", "unsetUrl", "]", ")", ";", "if", "(", "strlen", "(", "$", "queryString", ")", ")", "{", "parse_str", "(", "$", "queryString", ",", "$", "queryArgs", ")", ";", "$", "query", "+=", "$", "queryArgs", ";", "}", "return", "$", "query", ";", "}" ]
Process the GET parameters and move things into the object. @param array $query The array to which the parsed keys/values are being added. @param string $queryString A query string from the URL if provided @return array An array containing the parsed query string as keys/values.
[ "Process", "the", "GET", "parameters", "and", "move", "things", "into", "the", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L418-L428
211,312
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest._processFiles
protected function _processFiles($post, $files) { if (!is_array($files)) { return $post; } $fileData = []; foreach ($files as $key => $value) { if ($value instanceof UploadedFileInterface) { $fileData[$key] = $value; continue; } if (is_array($value) && isset($value['tmp_name'])) { $fileData[$key] = $this->_createUploadedFile($value); continue; } throw new InvalidArgumentException(sprintf( 'Invalid value in FILES "%s"', json_encode($value) )); } $this->uploadedFiles = $fileData; // Make a flat map that can be inserted into $post for BC. $fileMap = Hash::flatten($fileData); foreach ($fileMap as $key => $file) { $error = $file->getError(); $tmpName = ''; if ($error === UPLOAD_ERR_OK) { $tmpName = $file->getStream()->getMetadata('uri'); } $post = Hash::insert($post, $key, [ 'tmp_name' => $tmpName, 'error' => $error, 'name' => $file->getClientFilename(), 'type' => $file->getClientMediaType(), 'size' => $file->getSize(), ]); } return $post; }
php
protected function _processFiles($post, $files) { if (!is_array($files)) { return $post; } $fileData = []; foreach ($files as $key => $value) { if ($value instanceof UploadedFileInterface) { $fileData[$key] = $value; continue; } if (is_array($value) && isset($value['tmp_name'])) { $fileData[$key] = $this->_createUploadedFile($value); continue; } throw new InvalidArgumentException(sprintf( 'Invalid value in FILES "%s"', json_encode($value) )); } $this->uploadedFiles = $fileData; // Make a flat map that can be inserted into $post for BC. $fileMap = Hash::flatten($fileData); foreach ($fileMap as $key => $file) { $error = $file->getError(); $tmpName = ''; if ($error === UPLOAD_ERR_OK) { $tmpName = $file->getStream()->getMetadata('uri'); } $post = Hash::insert($post, $key, [ 'tmp_name' => $tmpName, 'error' => $error, 'name' => $file->getClientFilename(), 'type' => $file->getClientMediaType(), 'size' => $file->getSize(), ]); } return $post; }
[ "protected", "function", "_processFiles", "(", "$", "post", ",", "$", "files", ")", "{", "if", "(", "!", "is_array", "(", "$", "files", ")", ")", "{", "return", "$", "post", ";", "}", "$", "fileData", "=", "[", "]", ";", "foreach", "(", "$", "files", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "UploadedFileInterface", ")", "{", "$", "fileData", "[", "$", "key", "]", "=", "$", "value", ";", "continue", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", "&&", "isset", "(", "$", "value", "[", "'tmp_name'", "]", ")", ")", "{", "$", "fileData", "[", "$", "key", "]", "=", "$", "this", "->", "_createUploadedFile", "(", "$", "value", ")", ";", "continue", ";", "}", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid value in FILES \"%s\"'", ",", "json_encode", "(", "$", "value", ")", ")", ")", ";", "}", "$", "this", "->", "uploadedFiles", "=", "$", "fileData", ";", "// Make a flat map that can be inserted into $post for BC.", "$", "fileMap", "=", "Hash", "::", "flatten", "(", "$", "fileData", ")", ";", "foreach", "(", "$", "fileMap", "as", "$", "key", "=>", "$", "file", ")", "{", "$", "error", "=", "$", "file", "->", "getError", "(", ")", ";", "$", "tmpName", "=", "''", ";", "if", "(", "$", "error", "===", "UPLOAD_ERR_OK", ")", "{", "$", "tmpName", "=", "$", "file", "->", "getStream", "(", ")", "->", "getMetadata", "(", "'uri'", ")", ";", "}", "$", "post", "=", "Hash", "::", "insert", "(", "$", "post", ",", "$", "key", ",", "[", "'tmp_name'", "=>", "$", "tmpName", ",", "'error'", "=>", "$", "error", ",", "'name'", "=>", "$", "file", "->", "getClientFilename", "(", ")", ",", "'type'", "=>", "$", "file", "->", "getClientMediaType", "(", ")", ",", "'size'", "=>", "$", "file", "->", "getSize", "(", ")", ",", "]", ")", ";", "}", "return", "$", "post", ";", "}" ]
Process uploaded files and move things onto the post data. @param array $post Post data to merge files onto. @param array $files Uploaded files to merge in. @return array merged post + file data.
[ "Process", "uploaded", "files", "and", "move", "things", "onto", "the", "post", "data", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L437-L479
211,313
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.session
public function session(Session $session = null) { deprecationWarning( 'ServerRequest::session() is deprecated. ' . 'Use getSession() instead. The setter part will be removed.' ); if ($session === null) { return $this->session; } return $this->session = $session; }
php
public function session(Session $session = null) { deprecationWarning( 'ServerRequest::session() is deprecated. ' . 'Use getSession() instead. The setter part will be removed.' ); if ($session === null) { return $this->session; } return $this->session = $session; }
[ "public", "function", "session", "(", "Session", "$", "session", "=", "null", ")", "{", "deprecationWarning", "(", "'ServerRequest::session() is deprecated. '", ".", "'Use getSession() instead. The setter part will be removed.'", ")", ";", "if", "(", "$", "session", "===", "null", ")", "{", "return", "$", "this", "->", "session", ";", "}", "return", "$", "this", "->", "session", "=", "$", "session", ";", "}" ]
Returns the instance of the Session object for this request If a session object is passed as first argument it will be set as the session to use for this request @deprecated 3.5.0 Use getSession() instead. The setter part will be removed. @param \Cake\Http\Session|null $session the session object to use @return \Cake\Http\Session
[ "Returns", "the", "instance", "of", "the", "Session", "object", "for", "this", "request" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L566-L578
211,314
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.clientIp
public function clientIp() { if ($this->trustProxy && $this->getEnv('HTTP_X_FORWARDED_FOR')) { $addresses = array_map('trim', explode(',', $this->getEnv('HTTP_X_FORWARDED_FOR'))); $trusted = (count($this->trustedProxies) > 0); $n = count($addresses); if ($trusted) { $trusted = array_diff($addresses, $this->trustedProxies); $trusted = (count($trusted) === 1); } if ($trusted) { return $addresses[0]; } return $addresses[$n - 1]; } if ($this->trustProxy && $this->getEnv('HTTP_X_REAL_IP')) { $ipaddr = $this->getEnv('HTTP_X_REAL_IP'); } elseif ($this->trustProxy && $this->getEnv('HTTP_CLIENT_IP')) { $ipaddr = $this->getEnv('HTTP_CLIENT_IP'); } else { $ipaddr = $this->getEnv('REMOTE_ADDR'); } return trim($ipaddr); }
php
public function clientIp() { if ($this->trustProxy && $this->getEnv('HTTP_X_FORWARDED_FOR')) { $addresses = array_map('trim', explode(',', $this->getEnv('HTTP_X_FORWARDED_FOR'))); $trusted = (count($this->trustedProxies) > 0); $n = count($addresses); if ($trusted) { $trusted = array_diff($addresses, $this->trustedProxies); $trusted = (count($trusted) === 1); } if ($trusted) { return $addresses[0]; } return $addresses[$n - 1]; } if ($this->trustProxy && $this->getEnv('HTTP_X_REAL_IP')) { $ipaddr = $this->getEnv('HTTP_X_REAL_IP'); } elseif ($this->trustProxy && $this->getEnv('HTTP_CLIENT_IP')) { $ipaddr = $this->getEnv('HTTP_CLIENT_IP'); } else { $ipaddr = $this->getEnv('REMOTE_ADDR'); } return trim($ipaddr); }
[ "public", "function", "clientIp", "(", ")", "{", "if", "(", "$", "this", "->", "trustProxy", "&&", "$", "this", "->", "getEnv", "(", "'HTTP_X_FORWARDED_FOR'", ")", ")", "{", "$", "addresses", "=", "array_map", "(", "'trim'", ",", "explode", "(", "','", ",", "$", "this", "->", "getEnv", "(", "'HTTP_X_FORWARDED_FOR'", ")", ")", ")", ";", "$", "trusted", "=", "(", "count", "(", "$", "this", "->", "trustedProxies", ")", ">", "0", ")", ";", "$", "n", "=", "count", "(", "$", "addresses", ")", ";", "if", "(", "$", "trusted", ")", "{", "$", "trusted", "=", "array_diff", "(", "$", "addresses", ",", "$", "this", "->", "trustedProxies", ")", ";", "$", "trusted", "=", "(", "count", "(", "$", "trusted", ")", "===", "1", ")", ";", "}", "if", "(", "$", "trusted", ")", "{", "return", "$", "addresses", "[", "0", "]", ";", "}", "return", "$", "addresses", "[", "$", "n", "-", "1", "]", ";", "}", "if", "(", "$", "this", "->", "trustProxy", "&&", "$", "this", "->", "getEnv", "(", "'HTTP_X_REAL_IP'", ")", ")", "{", "$", "ipaddr", "=", "$", "this", "->", "getEnv", "(", "'HTTP_X_REAL_IP'", ")", ";", "}", "elseif", "(", "$", "this", "->", "trustProxy", "&&", "$", "this", "->", "getEnv", "(", "'HTTP_CLIENT_IP'", ")", ")", "{", "$", "ipaddr", "=", "$", "this", "->", "getEnv", "(", "'HTTP_CLIENT_IP'", ")", ";", "}", "else", "{", "$", "ipaddr", "=", "$", "this", "->", "getEnv", "(", "'REMOTE_ADDR'", ")", ";", "}", "return", "trim", "(", "$", "ipaddr", ")", ";", "}" ]
Get the IP the client is using, or says they are using. @return string The client IP.
[ "Get", "the", "IP", "the", "client", "is", "using", "or", "says", "they", "are", "using", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L585-L613
211,315
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.referer
public function referer($local = false) { $ref = $this->getEnv('HTTP_REFERER'); $base = Configure::read('App.fullBaseUrl') . $this->webroot; if (!empty($ref) && !empty($base)) { if ($local && strpos($ref, $base) === 0) { $ref = substr($ref, strlen($base)); if (!strlen($ref) || strpos($ref, '//') === 0) { $ref = '/'; } if ($ref[0] !== '/') { $ref = '/' . $ref; } return $ref; } if (!$local) { return $ref; } } return '/'; }
php
public function referer($local = false) { $ref = $this->getEnv('HTTP_REFERER'); $base = Configure::read('App.fullBaseUrl') . $this->webroot; if (!empty($ref) && !empty($base)) { if ($local && strpos($ref, $base) === 0) { $ref = substr($ref, strlen($base)); if (!strlen($ref) || strpos($ref, '//') === 0) { $ref = '/'; } if ($ref[0] !== '/') { $ref = '/' . $ref; } return $ref; } if (!$local) { return $ref; } } return '/'; }
[ "public", "function", "referer", "(", "$", "local", "=", "false", ")", "{", "$", "ref", "=", "$", "this", "->", "getEnv", "(", "'HTTP_REFERER'", ")", ";", "$", "base", "=", "Configure", "::", "read", "(", "'App.fullBaseUrl'", ")", ".", "$", "this", "->", "webroot", ";", "if", "(", "!", "empty", "(", "$", "ref", ")", "&&", "!", "empty", "(", "$", "base", ")", ")", "{", "if", "(", "$", "local", "&&", "strpos", "(", "$", "ref", ",", "$", "base", ")", "===", "0", ")", "{", "$", "ref", "=", "substr", "(", "$", "ref", ",", "strlen", "(", "$", "base", ")", ")", ";", "if", "(", "!", "strlen", "(", "$", "ref", ")", "||", "strpos", "(", "$", "ref", ",", "'//'", ")", "===", "0", ")", "{", "$", "ref", "=", "'/'", ";", "}", "if", "(", "$", "ref", "[", "0", "]", "!==", "'/'", ")", "{", "$", "ref", "=", "'/'", ".", "$", "ref", ";", "}", "return", "$", "ref", ";", "}", "if", "(", "!", "$", "local", ")", "{", "return", "$", "ref", ";", "}", "}", "return", "'/'", ";", "}" ]
Returns the referer that referred this request. @param bool $local Attempt to return a local address. Local addresses do not contain hostnames. @return string The referring address for this request.
[ "Returns", "the", "referer", "that", "referred", "this", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L644-L667
211,316
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.&
public function &__get($name) { if (isset($this->deprecatedProperties[$name])) { $method = $this->deprecatedProperties[$name]['get']; deprecationWarning( "Accessing `{$name}` as a property will be removed in 4.0.0. " . "Use request->{$method} instead." ); return $this->{$name}; } deprecationWarning(sprintf( 'Accessing routing parameters through `%s` will removed in 4.0.0. ' . 'Use `getParam()` instead.', $name )); if (isset($this->params[$name])) { return $this->params[$name]; } $value = null; return $value; }
php
public function &__get($name) { if (isset($this->deprecatedProperties[$name])) { $method = $this->deprecatedProperties[$name]['get']; deprecationWarning( "Accessing `{$name}` as a property will be removed in 4.0.0. " . "Use request->{$method} instead." ); return $this->{$name}; } deprecationWarning(sprintf( 'Accessing routing parameters through `%s` will removed in 4.0.0. ' . 'Use `getParam()` instead.', $name )); if (isset($this->params[$name])) { return $this->params[$name]; } $value = null; return $value; }
[ "public", "function", "&", "__get", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "deprecatedProperties", "[", "$", "name", "]", ")", ")", "{", "$", "method", "=", "$", "this", "->", "deprecatedProperties", "[", "$", "name", "]", "[", "'get'", "]", ";", "deprecationWarning", "(", "\"Accessing `{$name}` as a property will be removed in 4.0.0. \"", ".", "\"Use request->{$method} instead.\"", ")", ";", "return", "$", "this", "->", "{", "$", "name", "}", ";", "}", "deprecationWarning", "(", "sprintf", "(", "'Accessing routing parameters through `%s` will removed in 4.0.0. '", ".", "'Use `getParam()` instead.'", ",", "$", "name", ")", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "params", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "params", "[", "$", "name", "]", ";", "}", "$", "value", "=", "null", ";", "return", "$", "value", ";", "}" ]
Magic get method allows access to parsed routing parameters directly on the object. Allows access to `$this->params['controller']` via `$this->controller` @param string $name The property being accessed. @return mixed Either the value of the parameter or null. @deprecated 3.4.0 Accessing routing parameters through __get will removed in 4.0.0. Use getParam() instead.
[ "Magic", "get", "method", "allows", "access", "to", "parsed", "routing", "parameters", "directly", "on", "the", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L723-L747
211,317
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.is
public function is($type, ...$args) { if (is_array($type)) { $result = array_map([$this, 'is'], $type); return count(array_filter($result)) > 0; } $type = strtolower($type); if (!isset(static::$_detectors[$type])) { return false; } if ($args) { return $this->_is($type, $args); } if (!isset($this->_detectorCache[$type])) { $this->_detectorCache[$type] = $this->_is($type, $args); } return $this->_detectorCache[$type]; }
php
public function is($type, ...$args) { if (is_array($type)) { $result = array_map([$this, 'is'], $type); return count(array_filter($result)) > 0; } $type = strtolower($type); if (!isset(static::$_detectors[$type])) { return false; } if ($args) { return $this->_is($type, $args); } if (!isset($this->_detectorCache[$type])) { $this->_detectorCache[$type] = $this->_is($type, $args); } return $this->_detectorCache[$type]; }
[ "public", "function", "is", "(", "$", "type", ",", "...", "$", "args", ")", "{", "if", "(", "is_array", "(", "$", "type", ")", ")", "{", "$", "result", "=", "array_map", "(", "[", "$", "this", ",", "'is'", "]", ",", "$", "type", ")", ";", "return", "count", "(", "array_filter", "(", "$", "result", ")", ")", ">", "0", ";", "}", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "if", "(", "!", "isset", "(", "static", "::", "$", "_detectors", "[", "$", "type", "]", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "args", ")", "{", "return", "$", "this", "->", "_is", "(", "$", "type", ",", "$", "args", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "_detectorCache", "[", "$", "type", "]", ")", ")", "{", "$", "this", "->", "_detectorCache", "[", "$", "type", "]", "=", "$", "this", "->", "_is", "(", "$", "type", ",", "$", "args", ")", ";", "}", "return", "$", "this", "->", "_detectorCache", "[", "$", "type", "]", ";", "}" ]
Check whether or not a Request is a certain type. Uses the built in detection rules as well as additional rules defined with Cake\Http\ServerRequest::addDetector(). Any detector can be called as `is($type)` or `is$Type()`. @param string|array $type The type of request you want to check. If an array this method will return true if the request matches any type. @param array ...$args List of arguments @return bool Whether or not the request is the type you are checking.
[ "Check", "whether", "or", "not", "a", "Request", "is", "a", "certain", "type", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L790-L810
211,318
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest._headerDetector
protected function _headerDetector($detect) { foreach ($detect['header'] as $header => $value) { $header = $this->getEnv('http_' . $header); if ($header !== null) { if (!is_string($value) && !is_bool($value) && is_callable($value)) { return call_user_func($value, $header); } return ($header === $value); } } return false; }
php
protected function _headerDetector($detect) { foreach ($detect['header'] as $header => $value) { $header = $this->getEnv('http_' . $header); if ($header !== null) { if (!is_string($value) && !is_bool($value) && is_callable($value)) { return call_user_func($value, $header); } return ($header === $value); } } return false; }
[ "protected", "function", "_headerDetector", "(", "$", "detect", ")", "{", "foreach", "(", "$", "detect", "[", "'header'", "]", "as", "$", "header", "=>", "$", "value", ")", "{", "$", "header", "=", "$", "this", "->", "getEnv", "(", "'http_'", ".", "$", "header", ")", ";", "if", "(", "$", "header", "!==", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", "&&", "!", "is_bool", "(", "$", "value", ")", "&&", "is_callable", "(", "$", "value", ")", ")", "{", "return", "call_user_func", "(", "$", "value", ",", "$", "header", ")", ";", "}", "return", "(", "$", "header", "===", "$", "value", ")", ";", "}", "}", "return", "false", ";", "}" ]
Detects if a specific header is present. @param array $detect Detector options array. @return bool Whether or not the request is the type you are checking.
[ "Detects", "if", "a", "specific", "header", "is", "present", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L877-L891
211,319
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest._paramDetector
protected function _paramDetector($detect) { $key = $detect['param']; if (isset($detect['value'])) { $value = $detect['value']; return isset($this->params[$key]) ? $this->params[$key] == $value : false; } if (isset($detect['options'])) { return isset($this->params[$key]) ? in_array($this->params[$key], $detect['options']) : false; } return false; }
php
protected function _paramDetector($detect) { $key = $detect['param']; if (isset($detect['value'])) { $value = $detect['value']; return isset($this->params[$key]) ? $this->params[$key] == $value : false; } if (isset($detect['options'])) { return isset($this->params[$key]) ? in_array($this->params[$key], $detect['options']) : false; } return false; }
[ "protected", "function", "_paramDetector", "(", "$", "detect", ")", "{", "$", "key", "=", "$", "detect", "[", "'param'", "]", ";", "if", "(", "isset", "(", "$", "detect", "[", "'value'", "]", ")", ")", "{", "$", "value", "=", "$", "detect", "[", "'value'", "]", ";", "return", "isset", "(", "$", "this", "->", "params", "[", "$", "key", "]", ")", "?", "$", "this", "->", "params", "[", "$", "key", "]", "==", "$", "value", ":", "false", ";", "}", "if", "(", "isset", "(", "$", "detect", "[", "'options'", "]", ")", ")", "{", "return", "isset", "(", "$", "this", "->", "params", "[", "$", "key", "]", ")", "?", "in_array", "(", "$", "this", "->", "params", "[", "$", "key", "]", ",", "$", "detect", "[", "'options'", "]", ")", ":", "false", ";", "}", "return", "false", ";", "}" ]
Detects if a specific request parameter is present. @param array $detect Detector options array. @return bool Whether or not the request is the type you are checking.
[ "Detects", "if", "a", "specific", "request", "parameter", "is", "present", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L899-L912
211,320
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest._environmentDetector
protected function _environmentDetector($detect) { if (isset($detect['env'])) { if (isset($detect['value'])) { return $this->getEnv($detect['env']) == $detect['value']; } if (isset($detect['pattern'])) { return (bool)preg_match($detect['pattern'], $this->getEnv($detect['env'])); } if (isset($detect['options'])) { $pattern = '/' . implode('|', $detect['options']) . '/i'; return (bool)preg_match($pattern, $this->getEnv($detect['env'])); } } return false; }
php
protected function _environmentDetector($detect) { if (isset($detect['env'])) { if (isset($detect['value'])) { return $this->getEnv($detect['env']) == $detect['value']; } if (isset($detect['pattern'])) { return (bool)preg_match($detect['pattern'], $this->getEnv($detect['env'])); } if (isset($detect['options'])) { $pattern = '/' . implode('|', $detect['options']) . '/i'; return (bool)preg_match($pattern, $this->getEnv($detect['env'])); } } return false; }
[ "protected", "function", "_environmentDetector", "(", "$", "detect", ")", "{", "if", "(", "isset", "(", "$", "detect", "[", "'env'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "detect", "[", "'value'", "]", ")", ")", "{", "return", "$", "this", "->", "getEnv", "(", "$", "detect", "[", "'env'", "]", ")", "==", "$", "detect", "[", "'value'", "]", ";", "}", "if", "(", "isset", "(", "$", "detect", "[", "'pattern'", "]", ")", ")", "{", "return", "(", "bool", ")", "preg_match", "(", "$", "detect", "[", "'pattern'", "]", ",", "$", "this", "->", "getEnv", "(", "$", "detect", "[", "'env'", "]", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "detect", "[", "'options'", "]", ")", ")", "{", "$", "pattern", "=", "'/'", ".", "implode", "(", "'|'", ",", "$", "detect", "[", "'options'", "]", ")", ".", "'/i'", ";", "return", "(", "bool", ")", "preg_match", "(", "$", "pattern", ",", "$", "this", "->", "getEnv", "(", "$", "detect", "[", "'env'", "]", ")", ")", ";", "}", "}", "return", "false", ";", "}" ]
Detects if a specific environment variable is present. @param array $detect Detector options array. @return bool Whether or not the request is the type you are checking.
[ "Detects", "if", "a", "specific", "environment", "variable", "is", "present", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L920-L937
211,321
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.isAll
public function isAll(array $types) { $result = array_filter(array_map([$this, 'is'], $types)); return count($result) === count($types); }
php
public function isAll(array $types) { $result = array_filter(array_map([$this, 'is'], $types)); return count($result) === count($types); }
[ "public", "function", "isAll", "(", "array", "$", "types", ")", "{", "$", "result", "=", "array_filter", "(", "array_map", "(", "[", "$", "this", ",", "'is'", "]", ",", "$", "types", ")", ")", ";", "return", "count", "(", "$", "result", ")", "===", "count", "(", "$", "types", ")", ";", "}" ]
Check that a request matches all the given types. Allows you to test multiple types and union the results. See Request::is() for how to add additional types and the built-in types. @param array $types The types to check. @return bool Success. @see \Cake\Http\ServerRequest::is()
[ "Check", "that", "a", "request", "matches", "all", "the", "given", "types", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L950-L955
211,322
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.addDetector
public static function addDetector($name, $callable) { $name = strtolower($name); if (is_callable($callable)) { static::$_detectors[$name] = $callable; return; } if (isset(static::$_detectors[$name], $callable['options'])) { $callable = Hash::merge(static::$_detectors[$name], $callable); } static::$_detectors[$name] = $callable; }
php
public static function addDetector($name, $callable) { $name = strtolower($name); if (is_callable($callable)) { static::$_detectors[$name] = $callable; return; } if (isset(static::$_detectors[$name], $callable['options'])) { $callable = Hash::merge(static::$_detectors[$name], $callable); } static::$_detectors[$name] = $callable; }
[ "public", "static", "function", "addDetector", "(", "$", "name", ",", "$", "callable", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "is_callable", "(", "$", "callable", ")", ")", "{", "static", "::", "$", "_detectors", "[", "$", "name", "]", "=", "$", "callable", ";", "return", ";", "}", "if", "(", "isset", "(", "static", "::", "$", "_detectors", "[", "$", "name", "]", ",", "$", "callable", "[", "'options'", "]", ")", ")", "{", "$", "callable", "=", "Hash", "::", "merge", "(", "static", "::", "$", "_detectors", "[", "$", "name", "]", ",", "$", "callable", ")", ";", "}", "static", "::", "$", "_detectors", "[", "$", "name", "]", "=", "$", "callable", ";", "}" ]
Add a new detector to the list of detectors that a request can use. There are several different formats and types of detectors that can be set. ### Callback detectors Callback detectors allow you to provide a callable to handle the check. The callback will receive the request object as its only parameter. ``` addDetector('custom', function ($request) { //Return a boolean }); addDetector('custom', ['SomeClass', 'somemethod']); ``` ### Environment value comparison An environment value comparison, compares a value fetched from `env()` to a known value the environment value is equality checked against the provided value. e.g `addDetector('post', ['env' => 'REQUEST_METHOD', 'value' => 'POST'])` ### Pattern value comparison Pattern value comparison allows you to compare a value fetched from `env()` to a regular expression. ``` addDetector('iphone', ['env' => 'HTTP_USER_AGENT', 'pattern' => '/iPhone/i']); ``` ### Option based comparison Option based comparisons use a list of options to create a regular expression. Subsequent calls to add an already defined options detector will merge the options. ``` addDetector('mobile', ['env' => 'HTTP_USER_AGENT', 'options' => ['Fennec']]); ``` ### Request parameter detectors Allows for custom detectors on the request parameters. e.g `addDetector('requested', ['param' => 'requested', 'value' => 1]` You can also make parameter detectors that accept multiple values using the `options` key. This is useful when you want to check if a request parameter is in a list of options. `addDetector('extension', ['param' => 'ext', 'options' => ['pdf', 'csv']]` @param string $name The name of the detector. @param callable|array $callable A callable or options array for the detector definition. @return void
[ "Add", "a", "new", "detector", "to", "the", "list", "of", "detectors", "that", "a", "request", "can", "use", ".", "There", "are", "several", "different", "formats", "and", "types", "of", "detectors", "that", "can", "be", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1011-L1023
211,323
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.addPaths
public function addPaths(array $paths) { deprecationWarning( 'ServerRequest::addPaths() is deprecated. ' . 'Use `withAttribute($key, $value)` instead.' ); foreach (['webroot', 'here', 'base'] as $element) { if (isset($paths[$element])) { $this->{$element} = $paths[$element]; } } return $this; }
php
public function addPaths(array $paths) { deprecationWarning( 'ServerRequest::addPaths() is deprecated. ' . 'Use `withAttribute($key, $value)` instead.' ); foreach (['webroot', 'here', 'base'] as $element) { if (isset($paths[$element])) { $this->{$element} = $paths[$element]; } } return $this; }
[ "public", "function", "addPaths", "(", "array", "$", "paths", ")", "{", "deprecationWarning", "(", "'ServerRequest::addPaths() is deprecated. '", ".", "'Use `withAttribute($key, $value)` instead.'", ")", ";", "foreach", "(", "[", "'webroot'", ",", "'here'", ",", "'base'", "]", "as", "$", "element", ")", "{", "if", "(", "isset", "(", "$", "paths", "[", "$", "element", "]", ")", ")", "{", "$", "this", "->", "{", "$", "element", "}", "=", "$", "paths", "[", "$", "element", "]", ";", "}", "}", "return", "$", "this", ";", "}" ]
Add paths to the requests' paths vars. This will overwrite any existing paths. Provides an easy way to modify, here, webroot and base. @param array $paths Array of paths to merge in @return $this The current object, you can chain this method. @deprecated 3.6.0 Mutating a request in place is deprecated. Use `withAttribute()` to modify paths instead.
[ "Add", "paths", "to", "the", "requests", "paths", "vars", ".", "This", "will", "overwrite", "any", "existing", "paths", ".", "Provides", "an", "easy", "way", "to", "modify", "here", "webroot", "and", "base", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1053-L1066
211,324
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.here
public function here($base = true) { deprecationWarning( 'ServerRequest::here() will be removed in 4.0.0. You should use getRequestTarget() instead.' ); $url = $this->here; if (!empty($this->query)) { $url .= '?' . http_build_query($this->query, null, '&'); } if (!$base) { $url = preg_replace('/^' . preg_quote($this->base, '/') . '/', '', $url, 1); } return $url; }
php
public function here($base = true) { deprecationWarning( 'ServerRequest::here() will be removed in 4.0.0. You should use getRequestTarget() instead.' ); $url = $this->here; if (!empty($this->query)) { $url .= '?' . http_build_query($this->query, null, '&'); } if (!$base) { $url = preg_replace('/^' . preg_quote($this->base, '/') . '/', '', $url, 1); } return $url; }
[ "public", "function", "here", "(", "$", "base", "=", "true", ")", "{", "deprecationWarning", "(", "'ServerRequest::here() will be removed in 4.0.0. You should use getRequestTarget() instead.'", ")", ";", "$", "url", "=", "$", "this", "->", "here", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "query", ")", ")", "{", "$", "url", ".=", "'?'", ".", "http_build_query", "(", "$", "this", "->", "query", ",", "null", ",", "'&'", ")", ";", "}", "if", "(", "!", "$", "base", ")", "{", "$", "url", "=", "preg_replace", "(", "'/^'", ".", "preg_quote", "(", "$", "this", "->", "base", ",", "'/'", ")", ".", "'/'", ",", "''", ",", "$", "url", ",", "1", ")", ";", "}", "return", "$", "url", ";", "}" ]
Get the value of the current requests URL. Will include the query string arguments. @param bool $base Include the base path, set to false to trim the base path off. @return string The current request URL including query string args. @deprecated 3.4.0 This method will be removed in 4.0.0. You should use getRequestTarget() instead.
[ "Get", "the", "value", "of", "the", "current", "requests", "URL", ".", "Will", "include", "the", "query", "string", "arguments", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1075-L1090
211,325
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.normalizeHeaderName
protected function normalizeHeaderName($name) { $name = str_replace('-', '_', strtoupper($name)); if (!in_array($name, ['CONTENT_LENGTH', 'CONTENT_TYPE'])) { $name = 'HTTP_' . $name; } return $name; }
php
protected function normalizeHeaderName($name) { $name = str_replace('-', '_', strtoupper($name)); if (!in_array($name, ['CONTENT_LENGTH', 'CONTENT_TYPE'])) { $name = 'HTTP_' . $name; } return $name; }
[ "protected", "function", "normalizeHeaderName", "(", "$", "name", ")", "{", "$", "name", "=", "str_replace", "(", "'-'", ",", "'_'", ",", "strtoupper", "(", "$", "name", ")", ")", ";", "if", "(", "!", "in_array", "(", "$", "name", ",", "[", "'CONTENT_LENGTH'", ",", "'CONTENT_TYPE'", "]", ")", ")", "{", "$", "name", "=", "'HTTP_'", ".", "$", "name", ";", "}", "return", "$", "name", ";", "}" ]
Normalize a header name into the SERVER version. @param string $name The header name. @return string The normalized header name.
[ "Normalize", "a", "header", "name", "into", "the", "SERVER", "version", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1098-L1106
211,326
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.header
public function header($name) { deprecationWarning( 'ServerRequest::header() is deprecated. ' . 'The automatic fallback to env() will be removed in 4.0.0, see getHeader()' ); $name = $this->normalizeHeaderName($name); return $this->getEnv($name); }
php
public function header($name) { deprecationWarning( 'ServerRequest::header() is deprecated. ' . 'The automatic fallback to env() will be removed in 4.0.0, see getHeader()' ); $name = $this->normalizeHeaderName($name); return $this->getEnv($name); }
[ "public", "function", "header", "(", "$", "name", ")", "{", "deprecationWarning", "(", "'ServerRequest::header() is deprecated. '", ".", "'The automatic fallback to env() will be removed in 4.0.0, see getHeader()'", ")", ";", "$", "name", "=", "$", "this", "->", "normalizeHeaderName", "(", "$", "name", ")", ";", "return", "$", "this", "->", "getEnv", "(", "$", "name", ")", ";", "}" ]
Read an HTTP header from the Request information. If the header is not defined in the request, this method will fallback to reading data from $_SERVER and $_ENV. This fallback behavior is deprecated, and will be removed in 4.0.0 @param string $name Name of the header you want. @return string|null Either null on no header being set or the value of the header. @deprecated 4.0.0 The automatic fallback to env() will be removed in 4.0.0, see getHeader()
[ "Read", "an", "HTTP", "header", "from", "the", "Request", "information", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1119-L1129
211,327
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.getHeaders
public function getHeaders() { $headers = []; foreach ($this->_environment as $key => $value) { $name = null; if (strpos($key, 'HTTP_') === 0) { $name = substr($key, 5); } if (strpos($key, 'CONTENT_') === 0) { $name = $key; } if ($name !== null) { $name = str_replace('_', ' ', strtolower($name)); $name = str_replace(' ', '-', ucwords($name)); $headers[$name] = (array)$value; } } return $headers; }
php
public function getHeaders() { $headers = []; foreach ($this->_environment as $key => $value) { $name = null; if (strpos($key, 'HTTP_') === 0) { $name = substr($key, 5); } if (strpos($key, 'CONTENT_') === 0) { $name = $key; } if ($name !== null) { $name = str_replace('_', ' ', strtolower($name)); $name = str_replace(' ', '-', ucwords($name)); $headers[$name] = (array)$value; } } return $headers; }
[ "public", "function", "getHeaders", "(", ")", "{", "$", "headers", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "_environment", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "name", "=", "null", ";", "if", "(", "strpos", "(", "$", "key", ",", "'HTTP_'", ")", "===", "0", ")", "{", "$", "name", "=", "substr", "(", "$", "key", ",", "5", ")", ";", "}", "if", "(", "strpos", "(", "$", "key", ",", "'CONTENT_'", ")", "===", "0", ")", "{", "$", "name", "=", "$", "key", ";", "}", "if", "(", "$", "name", "!==", "null", ")", "{", "$", "name", "=", "str_replace", "(", "'_'", ",", "' '", ",", "strtolower", "(", "$", "name", ")", ")", ";", "$", "name", "=", "str_replace", "(", "' '", ",", "'-'", ",", "ucwords", "(", "$", "name", ")", ")", ";", "$", "headers", "[", "$", "name", "]", "=", "(", "array", ")", "$", "value", ";", "}", "}", "return", "$", "headers", ";", "}" ]
Get all headers in the request. Returns an associative array where the header names are the keys and the values are a list of header values. While header names are not case-sensitive, getHeaders() will normalize the headers. @return array An associative array of headers and their values. @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
[ "Get", "all", "headers", "in", "the", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1143-L1162
211,328
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.hasHeader
public function hasHeader($name) { $name = $this->normalizeHeaderName($name); return isset($this->_environment[$name]); }
php
public function hasHeader($name) { $name = $this->normalizeHeaderName($name); return isset($this->_environment[$name]); }
[ "public", "function", "hasHeader", "(", "$", "name", ")", "{", "$", "name", "=", "$", "this", "->", "normalizeHeaderName", "(", "$", "name", ")", ";", "return", "isset", "(", "$", "this", "->", "_environment", "[", "$", "name", "]", ")", ";", "}" ]
Check if a header is set in the request. @param string $name The header you want to get (case-insensitive) @return bool Whether or not the header is defined. @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
[ "Check", "if", "a", "header", "is", "set", "in", "the", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1171-L1176
211,329
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.getHeader
public function getHeader($name) { $name = $this->normalizeHeaderName($name); if (isset($this->_environment[$name])) { return (array)$this->_environment[$name]; } return []; }
php
public function getHeader($name) { $name = $this->normalizeHeaderName($name); if (isset($this->_environment[$name])) { return (array)$this->_environment[$name]; } return []; }
[ "public", "function", "getHeader", "(", "$", "name", ")", "{", "$", "name", "=", "$", "this", "->", "normalizeHeaderName", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_environment", "[", "$", "name", "]", ")", ")", "{", "return", "(", "array", ")", "$", "this", "->", "_environment", "[", "$", "name", "]", ";", "}", "return", "[", "]", ";", "}" ]
Get a single header from the request. Return the header value as an array. If the header is not present an empty array will be returned. @param string $name The header you want to get (case-insensitive) @return array An associative array of headers and their values. If the header doesn't exist, an empty array will be returned. @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
[ "Get", "a", "single", "header", "from", "the", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1189-L1197
211,330
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.withMethod
public function withMethod($method) { $new = clone $this; if (!is_string($method) || !preg_match('/^[!#$%&\'*+.^_`\|~0-9a-z-]+$/i', $method) ) { throw new InvalidArgumentException(sprintf( 'Unsupported HTTP method "%s" provided', $method )); } $new->_environment['REQUEST_METHOD'] = $method; return $new; }
php
public function withMethod($method) { $new = clone $this; if (!is_string($method) || !preg_match('/^[!#$%&\'*+.^_`\|~0-9a-z-]+$/i', $method) ) { throw new InvalidArgumentException(sprintf( 'Unsupported HTTP method "%s" provided', $method )); } $new->_environment['REQUEST_METHOD'] = $method; return $new; }
[ "public", "function", "withMethod", "(", "$", "method", ")", "{", "$", "new", "=", "clone", "$", "this", ";", "if", "(", "!", "is_string", "(", "$", "method", ")", "||", "!", "preg_match", "(", "'/^[!#$%&\\'*+.^_`\\|~0-9a-z-]+$/i'", ",", "$", "method", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Unsupported HTTP method \"%s\" provided'", ",", "$", "method", ")", ")", ";", "}", "$", "new", "->", "_environment", "[", "'REQUEST_METHOD'", "]", "=", "$", "method", ";", "return", "$", "new", ";", "}" ]
Update the request method and get a new instance. @param string $method The HTTP method to use. @return static A new instance with the updated method. @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
[ "Update", "the", "request", "method", "and", "get", "a", "new", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1313-L1328
211,331
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.accepts
public function accepts($type = null) { $raw = $this->parseAccept(); $accept = []; foreach ($raw as $types) { $accept = array_merge($accept, $types); } if ($type === null) { return $accept; } return in_array($type, $accept); }
php
public function accepts($type = null) { $raw = $this->parseAccept(); $accept = []; foreach ($raw as $types) { $accept = array_merge($accept, $types); } if ($type === null) { return $accept; } return in_array($type, $accept); }
[ "public", "function", "accepts", "(", "$", "type", "=", "null", ")", "{", "$", "raw", "=", "$", "this", "->", "parseAccept", "(", ")", ";", "$", "accept", "=", "[", "]", ";", "foreach", "(", "$", "raw", "as", "$", "types", ")", "{", "$", "accept", "=", "array_merge", "(", "$", "accept", ",", "$", "types", ")", ";", "}", "if", "(", "$", "type", "===", "null", ")", "{", "return", "$", "accept", ";", "}", "return", "in_array", "(", "$", "type", ",", "$", "accept", ")", ";", "}" ]
Find out which content types the client accepts or check if they accept a particular type of content. #### Get all types: ``` $this->request->accepts(); ``` #### Check for a single type: ``` $this->request->accepts('application/json'); ``` This method will order the returned content types by the preference values indicated by the client. @param string|null $type The content type to check for. Leave null to get all types a client accepts. @return array|bool Either an array of all the types the client accepts or a boolean if they accept the provided type.
[ "Find", "out", "which", "content", "types", "the", "client", "accepts", "or", "check", "if", "they", "accept", "a", "particular", "type", "of", "content", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1467-L1479
211,332
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.acceptLanguage
public function acceptLanguage($language = null) { $raw = $this->_parseAcceptWithQualifier($this->getHeaderLine('Accept-Language')); $accept = []; foreach ($raw as $languages) { foreach ($languages as &$lang) { if (strpos($lang, '_')) { $lang = str_replace('_', '-', $lang); } $lang = strtolower($lang); } $accept = array_merge($accept, $languages); } if ($language === null) { return $accept; } return in_array(strtolower($language), $accept); }
php
public function acceptLanguage($language = null) { $raw = $this->_parseAcceptWithQualifier($this->getHeaderLine('Accept-Language')); $accept = []; foreach ($raw as $languages) { foreach ($languages as &$lang) { if (strpos($lang, '_')) { $lang = str_replace('_', '-', $lang); } $lang = strtolower($lang); } $accept = array_merge($accept, $languages); } if ($language === null) { return $accept; } return in_array(strtolower($language), $accept); }
[ "public", "function", "acceptLanguage", "(", "$", "language", "=", "null", ")", "{", "$", "raw", "=", "$", "this", "->", "_parseAcceptWithQualifier", "(", "$", "this", "->", "getHeaderLine", "(", "'Accept-Language'", ")", ")", ";", "$", "accept", "=", "[", "]", ";", "foreach", "(", "$", "raw", "as", "$", "languages", ")", "{", "foreach", "(", "$", "languages", "as", "&", "$", "lang", ")", "{", "if", "(", "strpos", "(", "$", "lang", ",", "'_'", ")", ")", "{", "$", "lang", "=", "str_replace", "(", "'_'", ",", "'-'", ",", "$", "lang", ")", ";", "}", "$", "lang", "=", "strtolower", "(", "$", "lang", ")", ";", "}", "$", "accept", "=", "array_merge", "(", "$", "accept", ",", "$", "languages", ")", ";", "}", "if", "(", "$", "language", "===", "null", ")", "{", "return", "$", "accept", ";", "}", "return", "in_array", "(", "strtolower", "(", "$", "language", ")", ",", "$", "accept", ")", ";", "}" ]
Get the languages accepted by the client, or check if a specific language is accepted. Get the list of accepted languages: ``` \Cake\Http\ServerRequest::acceptLanguage(); ``` Check if a specific language is accepted: ``` \Cake\Http\ServerRequest::acceptLanguage('es-es'); ``` @param string|null $language The language to test. @return array|bool If a $language is provided, a boolean. Otherwise the array of accepted languages.
[ "Get", "the", "languages", "accepted", "by", "the", "client", "or", "check", "if", "a", "specific", "language", "is", "accepted", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1509-L1527
211,333
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.getQuery
public function getQuery($name = null, $default = null) { if ($name === null) { return $this->query; } return Hash::get($this->query, $name, $default); }
php
public function getQuery($name = null, $default = null) { if ($name === null) { return $this->query; } return Hash::get($this->query, $name, $default); }
[ "public", "function", "getQuery", "(", "$", "name", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "name", "===", "null", ")", "{", "return", "$", "this", "->", "query", ";", "}", "return", "Hash", "::", "get", "(", "$", "this", "->", "query", ",", "$", "name", ",", "$", "default", ")", ";", "}" ]
Read a specific query value or dotted path. Developers are encouraged to use getQueryParams() when possible as it is PSR-7 compliant, and this method is not. ### PSR-7 Alternative ``` $value = Hash::get($request->getQueryParams(), 'Post.id', null); ``` @param string|null $name The name or dotted path to the query param or null to read all. @param mixed $default The default value if the named parameter is not set, and $name is not null. @return null|string|array Query data. @see ServerRequest::getQueryParams()
[ "Read", "a", "specific", "query", "value", "or", "dotted", "path", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1609-L1616
211,334
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.cookie
public function cookie($key) { deprecationWarning( 'ServerRequest::cookie() is deprecated. ' . 'Use getCookie() instead.' ); if (isset($this->cookies[$key])) { return $this->cookies[$key]; } return null; }
php
public function cookie($key) { deprecationWarning( 'ServerRequest::cookie() is deprecated. ' . 'Use getCookie() instead.' ); if (isset($this->cookies[$key])) { return $this->cookies[$key]; } return null; }
[ "public", "function", "cookie", "(", "$", "key", ")", "{", "deprecationWarning", "(", "'ServerRequest::cookie() is deprecated. '", ".", "'Use getCookie() instead.'", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "cookies", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "cookies", "[", "$", "key", "]", ";", "}", "return", "null", ";", "}" ]
Read cookie data from the request's cookie data. @param string $key The key you want to read. @return null|string Either the cookie value, or null if the value doesn't exist. @deprecated 3.4.0 Use getCookie() instead.
[ "Read", "cookie", "data", "from", "the", "request", "s", "cookie", "data", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1767-L1779
211,335
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.withCookieCollection
public function withCookieCollection(CookieCollection $cookies) { $new = clone $this; $values = []; foreach ($cookies as $cookie) { $values[$cookie->getName()] = $cookie->getValue(); } $new->cookies = $values; return $new; }
php
public function withCookieCollection(CookieCollection $cookies) { $new = clone $this; $values = []; foreach ($cookies as $cookie) { $values[$cookie->getName()] = $cookie->getValue(); } $new->cookies = $values; return $new; }
[ "public", "function", "withCookieCollection", "(", "CookieCollection", "$", "cookies", ")", "{", "$", "new", "=", "clone", "$", "this", ";", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "cookies", "as", "$", "cookie", ")", "{", "$", "values", "[", "$", "cookie", "->", "getName", "(", ")", "]", "=", "$", "cookie", "->", "getValue", "(", ")", ";", "}", "$", "new", "->", "cookies", "=", "$", "values", ";", "return", "$", "new", ";", "}" ]
Replace the cookies in the request with those contained in the provided CookieCollection. @param \Cake\Http\Cookie\CookieCollection $cookies The cookie collection @return static
[ "Replace", "the", "cookies", "in", "the", "request", "with", "those", "contained", "in", "the", "provided", "CookieCollection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L1820-L1830
211,336
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.allowMethod
public function allowMethod($methods) { $methods = (array)$methods; foreach ($methods as $method) { if ($this->is($method)) { return true; } } $allowed = strtoupper(implode(', ', $methods)); $e = new MethodNotAllowedException(); $e->responseHeader('Allow', $allowed); throw $e; }
php
public function allowMethod($methods) { $methods = (array)$methods; foreach ($methods as $method) { if ($this->is($method)) { return true; } } $allowed = strtoupper(implode(', ', $methods)); $e = new MethodNotAllowedException(); $e->responseHeader('Allow', $allowed); throw $e; }
[ "public", "function", "allowMethod", "(", "$", "methods", ")", "{", "$", "methods", "=", "(", "array", ")", "$", "methods", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "if", "(", "$", "this", "->", "is", "(", "$", "method", ")", ")", "{", "return", "true", ";", "}", "}", "$", "allowed", "=", "strtoupper", "(", "implode", "(", "', '", ",", "$", "methods", ")", ")", ";", "$", "e", "=", "new", "MethodNotAllowedException", "(", ")", ";", "$", "e", "->", "responseHeader", "(", "'Allow'", ",", "$", "allowed", ")", ";", "throw", "$", "e", ";", "}" ]
Allow only certain HTTP request methods, if the request method does not match a 405 error will be shown and the required "Allow" response header will be set. Example: $this->request->allowMethod('post'); or $this->request->allowMethod(['post', 'delete']); If the request would be GET, response header "Allow: POST, DELETE" will be set and a 405 error will be returned. @param string|array $methods Allowed HTTP request methods. @return bool true @throws \Cake\Http\Exception\MethodNotAllowedException
[ "Allow", "only", "certain", "HTTP", "request", "methods", "if", "the", "request", "method", "does", "not", "match", "a", "405", "error", "will", "be", "shown", "and", "the", "required", "Allow", "response", "header", "will", "be", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2018-L2030
211,337
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.withData
public function withData($name, $value) { $copy = clone $this; $copy->data = Hash::insert($copy->data, $name, $value); return $copy; }
php
public function withData($name, $value) { $copy = clone $this; $copy->data = Hash::insert($copy->data, $name, $value); return $copy; }
[ "public", "function", "withData", "(", "$", "name", ",", "$", "value", ")", "{", "$", "copy", "=", "clone", "$", "this", ";", "$", "copy", "->", "data", "=", "Hash", "::", "insert", "(", "$", "copy", "->", "data", ",", "$", "name", ",", "$", "value", ")", ";", "return", "$", "copy", ";", "}" ]
Update the request with a new request data element. Returns an updated request object. This method returns a *new* request object and does not mutate the request in-place. Use `withParsedBody()` if you need to replace the all request data. @param string $name The dot separated path to insert $value at. @param mixed $value The value to insert into the request data. @return static
[ "Update", "the", "request", "with", "a", "new", "request", "data", "element", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2082-L2088
211,338
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.withoutData
public function withoutData($name) { $copy = clone $this; $copy->data = Hash::remove($copy->data, $name); return $copy; }
php
public function withoutData($name) { $copy = clone $this; $copy->data = Hash::remove($copy->data, $name); return $copy; }
[ "public", "function", "withoutData", "(", "$", "name", ")", "{", "$", "copy", "=", "clone", "$", "this", ";", "$", "copy", "->", "data", "=", "Hash", "::", "remove", "(", "$", "copy", "->", "data", ",", "$", "name", ")", ";", "return", "$", "copy", ";", "}" ]
Update the request removing a data element. Returns an updated request object. This method returns a *new* request object and does not mutate the request in-place. @param string $name The dot separated path to remove. @return static
[ "Update", "the", "request", "removing", "a", "data", "element", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2099-L2105
211,339
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.withParam
public function withParam($name, $value) { $copy = clone $this; $copy->params = Hash::insert($copy->params, $name, $value); return $copy; }
php
public function withParam($name, $value) { $copy = clone $this; $copy->params = Hash::insert($copy->params, $name, $value); return $copy; }
[ "public", "function", "withParam", "(", "$", "name", ",", "$", "value", ")", "{", "$", "copy", "=", "clone", "$", "this", ";", "$", "copy", "->", "params", "=", "Hash", "::", "insert", "(", "$", "copy", "->", "params", ",", "$", "name", ",", "$", "value", ")", ";", "return", "$", "copy", ";", "}" ]
Update the request with a new routing parameter Returns an updated request object. This method returns a *new* request object and does not mutate the request in-place. @param string $name The dot separated path to insert $value at. @param mixed $value The value to insert into the the request parameters. @return static
[ "Update", "the", "request", "with", "a", "new", "routing", "parameter" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2117-L2123
211,340
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.withAttribute
public function withAttribute($name, $value) { $new = clone $this; if (in_array($name, $this->emulatedAttributes, true)) { $new->{$name} = $value; } else { $new->attributes[$name] = $value; } return $new; }
php
public function withAttribute($name, $value) { $new = clone $this; if (in_array($name, $this->emulatedAttributes, true)) { $new->{$name} = $value; } else { $new->attributes[$name] = $value; } return $new; }
[ "public", "function", "withAttribute", "(", "$", "name", ",", "$", "value", ")", "{", "$", "new", "=", "clone", "$", "this", ";", "if", "(", "in_array", "(", "$", "name", ",", "$", "this", "->", "emulatedAttributes", ",", "true", ")", ")", "{", "$", "new", "->", "{", "$", "name", "}", "=", "$", "value", ";", "}", "else", "{", "$", "new", "->", "attributes", "[", "$", "name", "]", "=", "$", "value", ";", "}", "return", "$", "new", ";", "}" ]
Return an instance with the specified request attribute. @param string $name The attribute name. @param mixed $value The value of the attribute. @return static
[ "Return", "an", "instance", "with", "the", "specified", "request", "attribute", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2144-L2154
211,341
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.withoutAttribute
public function withoutAttribute($name) { $new = clone $this; if (in_array($name, $this->emulatedAttributes, true)) { throw new InvalidArgumentException( "You cannot unset '$name'. It is a required CakePHP attribute." ); } unset($new->attributes[$name]); return $new; }
php
public function withoutAttribute($name) { $new = clone $this; if (in_array($name, $this->emulatedAttributes, true)) { throw new InvalidArgumentException( "You cannot unset '$name'. It is a required CakePHP attribute." ); } unset($new->attributes[$name]); return $new; }
[ "public", "function", "withoutAttribute", "(", "$", "name", ")", "{", "$", "new", "=", "clone", "$", "this", ";", "if", "(", "in_array", "(", "$", "name", ",", "$", "this", "->", "emulatedAttributes", ",", "true", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"You cannot unset '$name'. It is a required CakePHP attribute.\"", ")", ";", "}", "unset", "(", "$", "new", "->", "attributes", "[", "$", "name", "]", ")", ";", "return", "$", "new", ";", "}" ]
Return an instance without the specified request attribute. @param string $name The attribute name. @return static @throws \InvalidArgumentException
[ "Return", "an", "instance", "without", "the", "specified", "request", "attribute", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2163-L2174
211,342
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.getAttribute
public function getAttribute($name, $default = null) { if (in_array($name, $this->emulatedAttributes, true)) { return $this->{$name}; } if (array_key_exists($name, $this->attributes)) { return $this->attributes[$name]; } return $default; }
php
public function getAttribute($name, $default = null) { if (in_array($name, $this->emulatedAttributes, true)) { return $this->{$name}; } if (array_key_exists($name, $this->attributes)) { return $this->attributes[$name]; } return $default; }
[ "public", "function", "getAttribute", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "if", "(", "in_array", "(", "$", "name", ",", "$", "this", "->", "emulatedAttributes", ",", "true", ")", ")", "{", "return", "$", "this", "->", "{", "$", "name", "}", ";", "}", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "attributes", ")", ")", "{", "return", "$", "this", "->", "attributes", "[", "$", "name", "]", ";", "}", "return", "$", "default", ";", "}" ]
Read an attribute from the request, or get the default @param string $name The attribute name. @param mixed|null $default The default value if the attribute has not been set. @return mixed
[ "Read", "an", "attribute", "from", "the", "request", "or", "get", "the", "default" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2183-L2193
211,343
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.getAttributes
public function getAttributes() { $emulated = [ 'params' => $this->params, 'webroot' => $this->webroot, 'base' => $this->base, 'here' => $this->here ]; return $this->attributes + $emulated; }
php
public function getAttributes() { $emulated = [ 'params' => $this->params, 'webroot' => $this->webroot, 'base' => $this->base, 'here' => $this->here ]; return $this->attributes + $emulated; }
[ "public", "function", "getAttributes", "(", ")", "{", "$", "emulated", "=", "[", "'params'", "=>", "$", "this", "->", "params", ",", "'webroot'", "=>", "$", "this", "->", "webroot", ",", "'base'", "=>", "$", "this", "->", "base", ",", "'here'", "=>", "$", "this", "->", "here", "]", ";", "return", "$", "this", "->", "attributes", "+", "$", "emulated", ";", "}" ]
Get all the attributes in the request. This will include the params, webroot, base, and here attributes that CakePHP provides. @return array
[ "Get", "all", "the", "attributes", "in", "the", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2203-L2213
211,344
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.getUploadedFile
public function getUploadedFile($path) { $file = Hash::get($this->uploadedFiles, $path); if (!$file instanceof UploadedFile) { return null; } return $file; }
php
public function getUploadedFile($path) { $file = Hash::get($this->uploadedFiles, $path); if (!$file instanceof UploadedFile) { return null; } return $file; }
[ "public", "function", "getUploadedFile", "(", "$", "path", ")", "{", "$", "file", "=", "Hash", "::", "get", "(", "$", "this", "->", "uploadedFiles", ",", "$", "path", ")", ";", "if", "(", "!", "$", "file", "instanceof", "UploadedFile", ")", "{", "return", "null", ";", "}", "return", "$", "file", ";", "}" ]
Get the uploaded file from a dotted path. @param string $path The dot separated path to the file you want. @return null|\Psr\Http\Message\UploadedFileInterface
[ "Get", "the", "uploaded", "file", "from", "a", "dotted", "path", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2221-L2229
211,345
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.withUri
public function withUri(UriInterface $uri, $preserveHost = false) { $new = clone $this; $new->uri = $uri; if ($preserveHost && $this->hasHeader('Host')) { return $new; } $host = $uri->getHost(); if (!$host) { return $new; } if ($uri->getPort()) { $host .= ':' . $uri->getPort(); } $new->_environment['HTTP_HOST'] = $host; return $new; }
php
public function withUri(UriInterface $uri, $preserveHost = false) { $new = clone $this; $new->uri = $uri; if ($preserveHost && $this->hasHeader('Host')) { return $new; } $host = $uri->getHost(); if (!$host) { return $new; } if ($uri->getPort()) { $host .= ':' . $uri->getPort(); } $new->_environment['HTTP_HOST'] = $host; return $new; }
[ "public", "function", "withUri", "(", "UriInterface", "$", "uri", ",", "$", "preserveHost", "=", "false", ")", "{", "$", "new", "=", "clone", "$", "this", ";", "$", "new", "->", "uri", "=", "$", "uri", ";", "if", "(", "$", "preserveHost", "&&", "$", "this", "->", "hasHeader", "(", "'Host'", ")", ")", "{", "return", "$", "new", ";", "}", "$", "host", "=", "$", "uri", "->", "getHost", "(", ")", ";", "if", "(", "!", "$", "host", ")", "{", "return", "$", "new", ";", "}", "if", "(", "$", "uri", "->", "getPort", "(", ")", ")", "{", "$", "host", ".=", "':'", ".", "$", "uri", "->", "getPort", "(", ")", ";", "}", "$", "new", "->", "_environment", "[", "'HTTP_HOST'", "]", "=", "$", "host", ";", "return", "$", "new", ";", "}" ]
Return an instance with the specified uri *Warning* Replacing the Uri will not update the `base`, `webroot`, and `url` attributes. @param \Psr\Http\Message\UriInterface $uri The new request uri @param bool $preserveHost Whether or not the host should be retained. @return static
[ "Return", "an", "instance", "with", "the", "specified", "uri" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2324-L2343
211,346
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.getPath
public function getPath() { if ($this->requestTarget === null) { return $this->uri->getPath(); } list($path) = explode('?', $this->requestTarget); return $path; }
php
public function getPath() { if ($this->requestTarget === null) { return $this->uri->getPath(); } list($path) = explode('?', $this->requestTarget); return $path; }
[ "public", "function", "getPath", "(", ")", "{", "if", "(", "$", "this", "->", "requestTarget", "===", "null", ")", "{", "return", "$", "this", "->", "uri", "->", "getPath", "(", ")", ";", "}", "list", "(", "$", "path", ")", "=", "explode", "(", "'?'", ",", "$", "this", "->", "requestTarget", ")", ";", "return", "$", "path", ";", "}" ]
Get the path of current request. @return string @since 3.6.1
[ "Get", "the", "path", "of", "current", "request", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2399-L2408
211,347
cakephp/cakephp
src/Http/ServerRequest.php
ServerRequest.offsetGet
public function offsetGet($name) { deprecationWarning( 'The ArrayAccess methods will be removed in 4.0.0.' . 'Use getParam(), getData() and getQuery() instead.' ); if (isset($this->params[$name])) { return $this->params[$name]; } if ($name === 'url') { return $this->query; } if ($name === 'data') { return $this->data; } return null; }
php
public function offsetGet($name) { deprecationWarning( 'The ArrayAccess methods will be removed in 4.0.0.' . 'Use getParam(), getData() and getQuery() instead.' ); if (isset($this->params[$name])) { return $this->params[$name]; } if ($name === 'url') { return $this->query; } if ($name === 'data') { return $this->data; } return null; }
[ "public", "function", "offsetGet", "(", "$", "name", ")", "{", "deprecationWarning", "(", "'The ArrayAccess methods will be removed in 4.0.0.'", ".", "'Use getParam(), getData() and getQuery() instead.'", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "params", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "params", "[", "$", "name", "]", ";", "}", "if", "(", "$", "name", "===", "'url'", ")", "{", "return", "$", "this", "->", "query", ";", "}", "if", "(", "$", "name", "===", "'data'", ")", "{", "return", "$", "this", "->", "data", ";", "}", "return", "null", ";", "}" ]
Array access read implementation @param string $name Name of the key being accessed. @return mixed @deprecated 3.4.0 The ArrayAccess methods will be removed in 4.0.0. Use getParam(), getData() and getQuery() instead.
[ "Array", "access", "read", "implementation" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequest.php#L2417-L2435
211,348
cakephp/cakephp
src/Collection/ExtractTrait.php
ExtractTrait._propertyExtractor
protected function _propertyExtractor($callback) { if (!is_string($callback)) { return $callback; } $path = explode('.', $callback); if (strpos($callback, '{*}') !== false) { return function ($element) use ($path) { return $this->_extract($element, $path); }; } return function ($element) use ($path) { return $this->_simpleExtract($element, $path); }; }
php
protected function _propertyExtractor($callback) { if (!is_string($callback)) { return $callback; } $path = explode('.', $callback); if (strpos($callback, '{*}') !== false) { return function ($element) use ($path) { return $this->_extract($element, $path); }; } return function ($element) use ($path) { return $this->_simpleExtract($element, $path); }; }
[ "protected", "function", "_propertyExtractor", "(", "$", "callback", ")", "{", "if", "(", "!", "is_string", "(", "$", "callback", ")", ")", "{", "return", "$", "callback", ";", "}", "$", "path", "=", "explode", "(", "'.'", ",", "$", "callback", ")", ";", "if", "(", "strpos", "(", "$", "callback", ",", "'{*}'", ")", "!==", "false", ")", "{", "return", "function", "(", "$", "element", ")", "use", "(", "$", "path", ")", "{", "return", "$", "this", "->", "_extract", "(", "$", "element", ",", "$", "path", ")", ";", "}", ";", "}", "return", "function", "(", "$", "element", ")", "use", "(", "$", "path", ")", "{", "return", "$", "this", "->", "_simpleExtract", "(", "$", "element", ",", "$", "path", ")", ";", "}", ";", "}" ]
Returns a callable that can be used to extract a property or column from an array or object based on a dot separated path. @param string|callable $callback A dot separated path of column to follow so that the final one can be returned or a callable that will take care of doing that. @return callable
[ "Returns", "a", "callable", "that", "can", "be", "used", "to", "extract", "a", "property", "or", "column", "from", "an", "array", "or", "object", "based", "on", "a", "dot", "separated", "path", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/ExtractTrait.php#L35-L52
211,349
cakephp/cakephp
src/Collection/ExtractTrait.php
ExtractTrait._createMatcherFilter
protected function _createMatcherFilter(array $conditions) { $matchers = []; foreach ($conditions as $property => $value) { $extractor = $this->_propertyExtractor($property); $matchers[] = function ($v) use ($extractor, $value) { return $extractor($v) == $value; }; } return function ($value) use ($matchers) { foreach ($matchers as $match) { if (!$match($value)) { return false; } } return true; }; }
php
protected function _createMatcherFilter(array $conditions) { $matchers = []; foreach ($conditions as $property => $value) { $extractor = $this->_propertyExtractor($property); $matchers[] = function ($v) use ($extractor, $value) { return $extractor($v) == $value; }; } return function ($value) use ($matchers) { foreach ($matchers as $match) { if (!$match($value)) { return false; } } return true; }; }
[ "protected", "function", "_createMatcherFilter", "(", "array", "$", "conditions", ")", "{", "$", "matchers", "=", "[", "]", ";", "foreach", "(", "$", "conditions", "as", "$", "property", "=>", "$", "value", ")", "{", "$", "extractor", "=", "$", "this", "->", "_propertyExtractor", "(", "$", "property", ")", ";", "$", "matchers", "[", "]", "=", "function", "(", "$", "v", ")", "use", "(", "$", "extractor", ",", "$", "value", ")", "{", "return", "$", "extractor", "(", "$", "v", ")", "==", "$", "value", ";", "}", ";", "}", "return", "function", "(", "$", "value", ")", "use", "(", "$", "matchers", ")", "{", "foreach", "(", "$", "matchers", "as", "$", "match", ")", "{", "if", "(", "!", "$", "match", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", ";", "}" ]
Returns a callable that receives a value and will return whether or not it matches certain condition. @param array $conditions A key-value list of conditions to match where the key is the property path to get from the current item and the value is the value to be compared the item with. @return callable
[ "Returns", "a", "callable", "that", "receives", "a", "value", "and", "will", "return", "whether", "or", "not", "it", "matches", "certain", "condition", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/ExtractTrait.php#L127-L146
211,350
cakephp/cakephp
src/View/ViewBlock.php
ViewBlock.start
public function start($name, $mode = ViewBlock::OVERRIDE) { if (array_key_exists($name, $this->_active)) { throw new Exception(sprintf("A view block with the name '%s' is already/still open.", $name)); } $this->_active[$name] = $mode; ob_start(); }
php
public function start($name, $mode = ViewBlock::OVERRIDE) { if (array_key_exists($name, $this->_active)) { throw new Exception(sprintf("A view block with the name '%s' is already/still open.", $name)); } $this->_active[$name] = $mode; ob_start(); }
[ "public", "function", "start", "(", "$", "name", ",", "$", "mode", "=", "ViewBlock", "::", "OVERRIDE", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "_active", ")", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "\"A view block with the name '%s' is already/still open.\"", ",", "$", "name", ")", ")", ";", "}", "$", "this", "->", "_active", "[", "$", "name", "]", "=", "$", "mode", ";", "ob_start", "(", ")", ";", "}" ]
Start capturing output for a 'block' Blocks allow you to create slots or blocks of dynamic content in the layout. view files can implement some or all of a layout's slots. You can end capturing blocks using View::end(). Blocks can be output using View::get(); @param string $name The name of the block to capture for. @param string $mode If ViewBlock::OVERRIDE existing content will be overridden by new content. If ViewBlock::APPEND content will be appended to existing content. If ViewBlock::PREPEND it will be prepended. @throws \Cake\Core\Exception\Exception When starting a block twice @return void
[ "Start", "capturing", "output", "for", "a", "block" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBlock.php#L87-L94
211,351
cakephp/cakephp
src/View/ViewBlock.php
ViewBlock.concat
public function concat($name, $value = null, $mode = ViewBlock::APPEND) { if ($value === null) { $this->start($name, $mode); return; } if (!isset($this->_blocks[$name])) { $this->_blocks[$name] = ''; } if ($mode === ViewBlock::PREPEND) { $this->_blocks[$name] = $value . $this->_blocks[$name]; } else { $this->_blocks[$name] .= $value; } }
php
public function concat($name, $value = null, $mode = ViewBlock::APPEND) { if ($value === null) { $this->start($name, $mode); return; } if (!isset($this->_blocks[$name])) { $this->_blocks[$name] = ''; } if ($mode === ViewBlock::PREPEND) { $this->_blocks[$name] = $value . $this->_blocks[$name]; } else { $this->_blocks[$name] .= $value; } }
[ "public", "function", "concat", "(", "$", "name", ",", "$", "value", "=", "null", ",", "$", "mode", "=", "ViewBlock", "::", "APPEND", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "$", "this", "->", "start", "(", "$", "name", ",", "$", "mode", ")", ";", "return", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "_blocks", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "_blocks", "[", "$", "name", "]", "=", "''", ";", "}", "if", "(", "$", "mode", "===", "ViewBlock", "::", "PREPEND", ")", "{", "$", "this", "->", "_blocks", "[", "$", "name", "]", "=", "$", "value", ".", "$", "this", "->", "_blocks", "[", "$", "name", "]", ";", "}", "else", "{", "$", "this", "->", "_blocks", "[", "$", "name", "]", ".=", "$", "value", ";", "}", "}" ]
Concat content to an existing or new block. Concating to a new block will create the block. Calling concat() without a value will create a new capturing block that needs to be finished with View::end(). The content of the new capturing context will be added to the existing block context. @param string $name Name of the block @param mixed $value The content for the block. Value will be type cast to string. @param string $mode If ViewBlock::APPEND content will be appended to existing content. If ViewBlock::PREPEND it will be prepended. @return void
[ "Concat", "content", "to", "an", "existing", "or", "new", "block", ".", "Concating", "to", "a", "new", "block", "will", "create", "the", "block", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBlock.php#L138-L154
211,352
cakephp/cakephp
src/Command/VersionCommand.php
VersionCommand.execute
public function execute(Arguments $args, ConsoleIo $io) { $io->out(Configure::version()); return static::CODE_SUCCESS; }
php
public function execute(Arguments $args, ConsoleIo $io) { $io->out(Configure::version()); return static::CODE_SUCCESS; }
[ "public", "function", "execute", "(", "Arguments", "$", "args", ",", "ConsoleIo", "$", "io", ")", "{", "$", "io", "->", "out", "(", "Configure", "::", "version", "(", ")", ")", ";", "return", "static", "::", "CODE_SUCCESS", ";", "}" ]
Print out the version of CakePHP in use. @param \Cake\Console\Arguments $args The command arguments. @param \Cake\Console\ConsoleIo $io The console io @return int
[ "Print", "out", "the", "version", "of", "CakePHP", "in", "use", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Command/VersionCommand.php#L34-L39
211,353
cakephp/cakephp
src/Mailer/Transport/SmtpTransport.php
SmtpTransport._bufferResponseLines
protected function _bufferResponseLines(array $responseLines) { $response = []; foreach ($responseLines as $responseLine) { if (preg_match('/^(\d{3})(?:[ -]+(.*))?$/', $responseLine, $match)) { $response[] = [ 'code' => $match[1], 'message' => isset($match[2]) ? $match[2] : null ]; } } $this->_lastResponse = array_merge($this->_lastResponse, $response); }
php
protected function _bufferResponseLines(array $responseLines) { $response = []; foreach ($responseLines as $responseLine) { if (preg_match('/^(\d{3})(?:[ -]+(.*))?$/', $responseLine, $match)) { $response[] = [ 'code' => $match[1], 'message' => isset($match[2]) ? $match[2] : null ]; } } $this->_lastResponse = array_merge($this->_lastResponse, $response); }
[ "protected", "function", "_bufferResponseLines", "(", "array", "$", "responseLines", ")", "{", "$", "response", "=", "[", "]", ";", "foreach", "(", "$", "responseLines", "as", "$", "responseLine", ")", "{", "if", "(", "preg_match", "(", "'/^(\\d{3})(?:[ -]+(.*))?$/'", ",", "$", "responseLine", ",", "$", "match", ")", ")", "{", "$", "response", "[", "]", "=", "[", "'code'", "=>", "$", "match", "[", "1", "]", ",", "'message'", "=>", "isset", "(", "$", "match", "[", "2", "]", ")", "?", "$", "match", "[", "2", "]", ":", "null", "]", ";", "}", "}", "$", "this", "->", "_lastResponse", "=", "array_merge", "(", "$", "this", "->", "_lastResponse", ",", "$", "response", ")", ";", "}" ]
Parses and stores the response lines in `'code' => 'message'` format. @param array $responseLines Response lines to parse. @return void
[ "Parses", "and", "stores", "the", "response", "lines", "in", "code", "=", ">", "message", "format", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Transport/SmtpTransport.php#L196-L208
211,354
cakephp/cakephp
src/Mailer/Transport/SmtpTransport.php
SmtpTransport._connect
protected function _connect() { $this->_generateSocket(); if (!$this->_socket->connect()) { throw new SocketException('Unable to connect to SMTP server.'); } $this->_smtpSend(null, '220'); $config = $this->_config; if (isset($config['client'])) { $host = $config['client']; } elseif ($httpHost = env('HTTP_HOST')) { list($host) = explode(':', $httpHost); } else { $host = 'localhost'; } try { $this->_smtpSend("EHLO {$host}", '250'); if ($config['tls']) { $this->_smtpSend('STARTTLS', '220'); $this->_socket->enableCrypto('tls'); $this->_smtpSend("EHLO {$host}", '250'); } } catch (SocketException $e) { if ($config['tls']) { throw new SocketException('SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.', null, $e); } try { $this->_smtpSend("HELO {$host}", '250'); } catch (SocketException $e2) { throw new SocketException('SMTP server did not accept the connection.', null, $e2); } } }
php
protected function _connect() { $this->_generateSocket(); if (!$this->_socket->connect()) { throw new SocketException('Unable to connect to SMTP server.'); } $this->_smtpSend(null, '220'); $config = $this->_config; if (isset($config['client'])) { $host = $config['client']; } elseif ($httpHost = env('HTTP_HOST')) { list($host) = explode(':', $httpHost); } else { $host = 'localhost'; } try { $this->_smtpSend("EHLO {$host}", '250'); if ($config['tls']) { $this->_smtpSend('STARTTLS', '220'); $this->_socket->enableCrypto('tls'); $this->_smtpSend("EHLO {$host}", '250'); } } catch (SocketException $e) { if ($config['tls']) { throw new SocketException('SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.', null, $e); } try { $this->_smtpSend("HELO {$host}", '250'); } catch (SocketException $e2) { throw new SocketException('SMTP server did not accept the connection.', null, $e2); } } }
[ "protected", "function", "_connect", "(", ")", "{", "$", "this", "->", "_generateSocket", "(", ")", ";", "if", "(", "!", "$", "this", "->", "_socket", "->", "connect", "(", ")", ")", "{", "throw", "new", "SocketException", "(", "'Unable to connect to SMTP server.'", ")", ";", "}", "$", "this", "->", "_smtpSend", "(", "null", ",", "'220'", ")", ";", "$", "config", "=", "$", "this", "->", "_config", ";", "if", "(", "isset", "(", "$", "config", "[", "'client'", "]", ")", ")", "{", "$", "host", "=", "$", "config", "[", "'client'", "]", ";", "}", "elseif", "(", "$", "httpHost", "=", "env", "(", "'HTTP_HOST'", ")", ")", "{", "list", "(", "$", "host", ")", "=", "explode", "(", "':'", ",", "$", "httpHost", ")", ";", "}", "else", "{", "$", "host", "=", "'localhost'", ";", "}", "try", "{", "$", "this", "->", "_smtpSend", "(", "\"EHLO {$host}\"", ",", "'250'", ")", ";", "if", "(", "$", "config", "[", "'tls'", "]", ")", "{", "$", "this", "->", "_smtpSend", "(", "'STARTTLS'", ",", "'220'", ")", ";", "$", "this", "->", "_socket", "->", "enableCrypto", "(", "'tls'", ")", ";", "$", "this", "->", "_smtpSend", "(", "\"EHLO {$host}\"", ",", "'250'", ")", ";", "}", "}", "catch", "(", "SocketException", "$", "e", ")", "{", "if", "(", "$", "config", "[", "'tls'", "]", ")", "{", "throw", "new", "SocketException", "(", "'SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.'", ",", "null", ",", "$", "e", ")", ";", "}", "try", "{", "$", "this", "->", "_smtpSend", "(", "\"HELO {$host}\"", ",", "'250'", ")", ";", "}", "catch", "(", "SocketException", "$", "e2", ")", "{", "throw", "new", "SocketException", "(", "'SMTP server did not accept the connection.'", ",", "null", ",", "$", "e2", ")", ";", "}", "}", "}" ]
Connect to SMTP Server @return void @throws \Cake\Network\Exception\SocketException
[ "Connect", "to", "SMTP", "Server" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Transport/SmtpTransport.php#L216-L251
211,355
cakephp/cakephp
src/Mailer/Transport/SmtpTransport.php
SmtpTransport._prepareFromAddress
protected function _prepareFromAddress($email) { $from = $email->getReturnPath(); if (empty($from)) { $from = $email->getFrom(); } return $from; }
php
protected function _prepareFromAddress($email) { $from = $email->getReturnPath(); if (empty($from)) { $from = $email->getFrom(); } return $from; }
[ "protected", "function", "_prepareFromAddress", "(", "$", "email", ")", "{", "$", "from", "=", "$", "email", "->", "getReturnPath", "(", ")", ";", "if", "(", "empty", "(", "$", "from", ")", ")", "{", "$", "from", "=", "$", "email", "->", "getFrom", "(", ")", ";", "}", "return", "$", "from", ";", "}" ]
Prepares the `from` email address. @param \Cake\Mailer\Email $email Email instance @return array
[ "Prepares", "the", "from", "email", "address", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Transport/SmtpTransport.php#L310-L318
211,356
cakephp/cakephp
src/Mailer/Transport/SmtpTransport.php
SmtpTransport._prepareRecipientAddresses
protected function _prepareRecipientAddresses($email) { $to = $email->getTo(); $cc = $email->getCc(); $bcc = $email->getBcc(); return array_merge(array_keys($to), array_keys($cc), array_keys($bcc)); }
php
protected function _prepareRecipientAddresses($email) { $to = $email->getTo(); $cc = $email->getCc(); $bcc = $email->getBcc(); return array_merge(array_keys($to), array_keys($cc), array_keys($bcc)); }
[ "protected", "function", "_prepareRecipientAddresses", "(", "$", "email", ")", "{", "$", "to", "=", "$", "email", "->", "getTo", "(", ")", ";", "$", "cc", "=", "$", "email", "->", "getCc", "(", ")", ";", "$", "bcc", "=", "$", "email", "->", "getBcc", "(", ")", ";", "return", "array_merge", "(", "array_keys", "(", "$", "to", ")", ",", "array_keys", "(", "$", "cc", ")", ",", "array_keys", "(", "$", "bcc", ")", ")", ";", "}" ]
Prepares the recipient email addresses. @param \Cake\Mailer\Email $email Email instance @return array
[ "Prepares", "the", "recipient", "email", "addresses", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Transport/SmtpTransport.php#L326-L333
211,357
cakephp/cakephp
src/Mailer/Transport/SmtpTransport.php
SmtpTransport._prepareMessage
protected function _prepareMessage($email) { $lines = $email->message(); $messages = []; foreach ($lines as $line) { if (!empty($line) && ($line[0] === '.')) { $messages[] = '.' . $line; } else { $messages[] = $line; } } return implode("\r\n", $messages); }
php
protected function _prepareMessage($email) { $lines = $email->message(); $messages = []; foreach ($lines as $line) { if (!empty($line) && ($line[0] === '.')) { $messages[] = '.' . $line; } else { $messages[] = $line; } } return implode("\r\n", $messages); }
[ "protected", "function", "_prepareMessage", "(", "$", "email", ")", "{", "$", "lines", "=", "$", "email", "->", "message", "(", ")", ";", "$", "messages", "=", "[", "]", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "if", "(", "!", "empty", "(", "$", "line", ")", "&&", "(", "$", "line", "[", "0", "]", "===", "'.'", ")", ")", "{", "$", "messages", "[", "]", "=", "'.'", ".", "$", "line", ";", "}", "else", "{", "$", "messages", "[", "]", "=", "$", "line", ";", "}", "}", "return", "implode", "(", "\"\\r\\n\"", ",", "$", "messages", ")", ";", "}" ]
Prepares the message body. @param \Cake\Mailer\Email $email Email instance @return string
[ "Prepares", "the", "message", "body", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Transport/SmtpTransport.php#L352-L365
211,358
cakephp/cakephp
src/Mailer/Transport/SmtpTransport.php
SmtpTransport._smtpSend
protected function _smtpSend($data, $checkCode = '250') { $this->_lastResponse = []; if ($data !== null) { $this->_socket->write($data . "\r\n"); } $timeout = $this->_config['timeout']; while ($checkCode !== false) { $response = ''; $startTime = time(); while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $timeout)) { $bytes = $this->_socket->read(); if ($bytes === false || $bytes === null) { break; } $response .= $bytes; } if (substr($response, -2) !== "\r\n") { throw new SocketException('SMTP timeout.'); } $responseLines = explode("\r\n", rtrim($response, "\r\n")); $response = end($responseLines); $this->_bufferResponseLines($responseLines); if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) { if ($code[2] === '-') { continue; } return $code[1]; } throw new SocketException(sprintf('SMTP Error: %s', $response)); } }
php
protected function _smtpSend($data, $checkCode = '250') { $this->_lastResponse = []; if ($data !== null) { $this->_socket->write($data . "\r\n"); } $timeout = $this->_config['timeout']; while ($checkCode !== false) { $response = ''; $startTime = time(); while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $timeout)) { $bytes = $this->_socket->read(); if ($bytes === false || $bytes === null) { break; } $response .= $bytes; } if (substr($response, -2) !== "\r\n") { throw new SocketException('SMTP timeout.'); } $responseLines = explode("\r\n", rtrim($response, "\r\n")); $response = end($responseLines); $this->_bufferResponseLines($responseLines); if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) { if ($code[2] === '-') { continue; } return $code[1]; } throw new SocketException(sprintf('SMTP Error: %s', $response)); } }
[ "protected", "function", "_smtpSend", "(", "$", "data", ",", "$", "checkCode", "=", "'250'", ")", "{", "$", "this", "->", "_lastResponse", "=", "[", "]", ";", "if", "(", "$", "data", "!==", "null", ")", "{", "$", "this", "->", "_socket", "->", "write", "(", "$", "data", ".", "\"\\r\\n\"", ")", ";", "}", "$", "timeout", "=", "$", "this", "->", "_config", "[", "'timeout'", "]", ";", "while", "(", "$", "checkCode", "!==", "false", ")", "{", "$", "response", "=", "''", ";", "$", "startTime", "=", "time", "(", ")", ";", "while", "(", "substr", "(", "$", "response", ",", "-", "2", ")", "!==", "\"\\r\\n\"", "&&", "(", "(", "time", "(", ")", "-", "$", "startTime", ")", "<", "$", "timeout", ")", ")", "{", "$", "bytes", "=", "$", "this", "->", "_socket", "->", "read", "(", ")", ";", "if", "(", "$", "bytes", "===", "false", "||", "$", "bytes", "===", "null", ")", "{", "break", ";", "}", "$", "response", ".=", "$", "bytes", ";", "}", "if", "(", "substr", "(", "$", "response", ",", "-", "2", ")", "!==", "\"\\r\\n\"", ")", "{", "throw", "new", "SocketException", "(", "'SMTP timeout.'", ")", ";", "}", "$", "responseLines", "=", "explode", "(", "\"\\r\\n\"", ",", "rtrim", "(", "$", "response", ",", "\"\\r\\n\"", ")", ")", ";", "$", "response", "=", "end", "(", "$", "responseLines", ")", ";", "$", "this", "->", "_bufferResponseLines", "(", "$", "responseLines", ")", ";", "if", "(", "preg_match", "(", "'/^('", ".", "$", "checkCode", ".", "')(.)/'", ",", "$", "response", ",", "$", "code", ")", ")", "{", "if", "(", "$", "code", "[", "2", "]", "===", "'-'", ")", "{", "continue", ";", "}", "return", "$", "code", "[", "1", "]", ";", "}", "throw", "new", "SocketException", "(", "sprintf", "(", "'SMTP Error: %s'", ",", "$", "response", ")", ")", ";", "}", "}" ]
Protected method for sending data to SMTP connection @param string|null $data Data to be sent to SMTP server @param string|bool $checkCode Code to check for in server response, false to skip @return string|null The matched code, or null if nothing matched @throws \Cake\Network\Exception\SocketException
[ "Protected", "method", "for", "sending", "data", "to", "SMTP", "connection" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Transport/SmtpTransport.php#L434-L471
211,359
cakephp/cakephp
src/Console/ConsoleIo.php
ConsoleIo.out
public function out($message = '', $newlines = 1, $level = self::NORMAL) { if ($level <= $this->_level) { $this->_lastWritten = (int)$this->_out->write($message, $newlines); return $this->_lastWritten; } return true; }
php
public function out($message = '', $newlines = 1, $level = self::NORMAL) { if ($level <= $this->_level) { $this->_lastWritten = (int)$this->_out->write($message, $newlines); return $this->_lastWritten; } return true; }
[ "public", "function", "out", "(", "$", "message", "=", "''", ",", "$", "newlines", "=", "1", ",", "$", "level", "=", "self", "::", "NORMAL", ")", "{", "if", "(", "$", "level", "<=", "$", "this", "->", "_level", ")", "{", "$", "this", "->", "_lastWritten", "=", "(", "int", ")", "$", "this", "->", "_out", "->", "write", "(", "$", "message", ",", "$", "newlines", ")", ";", "return", "$", "this", "->", "_lastWritten", ";", "}", "return", "true", ";", "}" ]
Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline. ### Output levels There are 3 built-in output level. ConsoleIo::QUIET, ConsoleIo::NORMAL, ConsoleIo::VERBOSE. The verbose and quiet output levels, map to the `verbose` and `quiet` output switches present in most shells. Using ConsoleIo::QUIET for a message means it will always display. While using ConsoleIo::VERBOSE means it will only display when verbose output is toggled. @param string|array $message A string or an array of strings to output @param int $newlines Number of newlines to append @param int $level The message's output level, see above. @return int|bool The number of bytes returned from writing to stdout.
[ "Outputs", "a", "single", "or", "multiple", "messages", "to", "stdout", ".", "If", "no", "parameters", "are", "passed", "outputs", "just", "a", "newline", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleIo.php#L176-L185
211,360
cakephp/cakephp
src/Console/ConsoleIo.php
ConsoleIo.overwrite
public function overwrite($message, $newlines = 1, $size = null) { $size = $size ?: $this->_lastWritten; // Output backspaces. $this->out(str_repeat("\x08", $size), 0); $newBytes = $this->out($message, 0); // Fill any remaining bytes with spaces. $fill = $size - $newBytes; if ($fill > 0) { $this->out(str_repeat(' ', $fill), 0); } if ($newlines) { $this->out($this->nl($newlines), 0); } // Store length of content + fill so if the new content // is shorter than the old content the next overwrite // will work. if ($fill > 0) { $this->_lastWritten = $newBytes + $fill; } }
php
public function overwrite($message, $newlines = 1, $size = null) { $size = $size ?: $this->_lastWritten; // Output backspaces. $this->out(str_repeat("\x08", $size), 0); $newBytes = $this->out($message, 0); // Fill any remaining bytes with spaces. $fill = $size - $newBytes; if ($fill > 0) { $this->out(str_repeat(' ', $fill), 0); } if ($newlines) { $this->out($this->nl($newlines), 0); } // Store length of content + fill so if the new content // is shorter than the old content the next overwrite // will work. if ($fill > 0) { $this->_lastWritten = $newBytes + $fill; } }
[ "public", "function", "overwrite", "(", "$", "message", ",", "$", "newlines", "=", "1", ",", "$", "size", "=", "null", ")", "{", "$", "size", "=", "$", "size", "?", ":", "$", "this", "->", "_lastWritten", ";", "// Output backspaces.", "$", "this", "->", "out", "(", "str_repeat", "(", "\"\\x08\"", ",", "$", "size", ")", ",", "0", ")", ";", "$", "newBytes", "=", "$", "this", "->", "out", "(", "$", "message", ",", "0", ")", ";", "// Fill any remaining bytes with spaces.", "$", "fill", "=", "$", "size", "-", "$", "newBytes", ";", "if", "(", "$", "fill", ">", "0", ")", "{", "$", "this", "->", "out", "(", "str_repeat", "(", "' '", ",", "$", "fill", ")", ",", "0", ")", ";", "}", "if", "(", "$", "newlines", ")", "{", "$", "this", "->", "out", "(", "$", "this", "->", "nl", "(", "$", "newlines", ")", ",", "0", ")", ";", "}", "// Store length of content + fill so if the new content", "// is shorter than the old content the next overwrite", "// will work.", "if", "(", "$", "fill", ">", "0", ")", "{", "$", "this", "->", "_lastWritten", "=", "$", "newBytes", "+", "$", "fill", ";", "}", "}" ]
Overwrite some already output text. Useful for building progress bars, or when you want to replace text already output to the screen with new text. **Warning** You cannot overwrite text that contains newlines. @param array|string $message The message to output. @param int $newlines Number of newlines to append. @param int|null $size The number of bytes to overwrite. Defaults to the length of the last message output. @return void
[ "Overwrite", "some", "already", "output", "text", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleIo.php#L287-L311
211,361
cakephp/cakephp
src/Console/ConsoleIo.php
ConsoleIo.hr
public function hr($newlines = 0, $width = 79) { $this->out(null, $newlines); $this->out(str_repeat('-', $width)); $this->out(null, $newlines); }
php
public function hr($newlines = 0, $width = 79) { $this->out(null, $newlines); $this->out(str_repeat('-', $width)); $this->out(null, $newlines); }
[ "public", "function", "hr", "(", "$", "newlines", "=", "0", ",", "$", "width", "=", "79", ")", "{", "$", "this", "->", "out", "(", "null", ",", "$", "newlines", ")", ";", "$", "this", "->", "out", "(", "str_repeat", "(", "'-'", ",", "$", "width", ")", ")", ";", "$", "this", "->", "out", "(", "null", ",", "$", "newlines", ")", ";", "}" ]
Outputs a series of minus characters to the standard output, acts as a visual separator. @param int $newlines Number of newlines to pre- and append @param int $width Width of the line, defaults to 79 @return void
[ "Outputs", "a", "series", "of", "minus", "characters", "to", "the", "standard", "output", "acts", "as", "a", "visual", "separator", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleIo.php#L344-L349
211,362
cakephp/cakephp
src/Console/ConsoleIo.php
ConsoleIo.styles
public function styles($style = null, $definition = null) { return $this->_out->styles($style, $definition); }
php
public function styles($style = null, $definition = null) { return $this->_out->styles($style, $definition); }
[ "public", "function", "styles", "(", "$", "style", "=", "null", ",", "$", "definition", "=", "null", ")", "{", "return", "$", "this", "->", "_out", "->", "styles", "(", "$", "style", ",", "$", "definition", ")", ";", "}" ]
Add a new output style or get defined styles. @param string|null $style The style to get or create. @param array|bool|null $definition The array definition of the style to change or create a style or false to remove a style. @return mixed If you are getting styles, the style or null will be returned. If you are creating/modifying styles true will be returned. @see \Cake\Console\ConsoleOutput::styles()
[ "Add", "a", "new", "output", "style", "or", "get", "defined", "styles", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleIo.php#L399-L402
211,363
cakephp/cakephp
src/Console/ConsoleIo.php
ConsoleIo.askChoice
public function askChoice($prompt, $options, $default = null) { if ($options && is_string($options)) { if (strpos($options, ',')) { $options = explode(',', $options); } elseif (strpos($options, '/')) { $options = explode('/', $options); } else { $options = [$options]; } } $printOptions = '(' . implode('/', $options) . ')'; $options = array_merge( array_map('strtolower', $options), array_map('strtoupper', $options), $options ); $in = ''; while ($in === '' || !in_array($in, $options)) { $in = $this->_getInput($prompt, $printOptions, $default); } return $in; }
php
public function askChoice($prompt, $options, $default = null) { if ($options && is_string($options)) { if (strpos($options, ',')) { $options = explode(',', $options); } elseif (strpos($options, '/')) { $options = explode('/', $options); } else { $options = [$options]; } } $printOptions = '(' . implode('/', $options) . ')'; $options = array_merge( array_map('strtolower', $options), array_map('strtoupper', $options), $options ); $in = ''; while ($in === '' || !in_array($in, $options)) { $in = $this->_getInput($prompt, $printOptions, $default); } return $in; }
[ "public", "function", "askChoice", "(", "$", "prompt", ",", "$", "options", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "options", "&&", "is_string", "(", "$", "options", ")", ")", "{", "if", "(", "strpos", "(", "$", "options", ",", "','", ")", ")", "{", "$", "options", "=", "explode", "(", "','", ",", "$", "options", ")", ";", "}", "elseif", "(", "strpos", "(", "$", "options", ",", "'/'", ")", ")", "{", "$", "options", "=", "explode", "(", "'/'", ",", "$", "options", ")", ";", "}", "else", "{", "$", "options", "=", "[", "$", "options", "]", ";", "}", "}", "$", "printOptions", "=", "'('", ".", "implode", "(", "'/'", ",", "$", "options", ")", ".", "')'", ";", "$", "options", "=", "array_merge", "(", "array_map", "(", "'strtolower'", ",", "$", "options", ")", ",", "array_map", "(", "'strtoupper'", ",", "$", "options", ")", ",", "$", "options", ")", ";", "$", "in", "=", "''", ";", "while", "(", "$", "in", "===", "''", "||", "!", "in_array", "(", "$", "in", ",", "$", "options", ")", ")", "{", "$", "in", "=", "$", "this", "->", "_getInput", "(", "$", "prompt", ",", "$", "printOptions", ",", "$", "default", ")", ";", "}", "return", "$", "in", ";", "}" ]
Prompts the user for input based on a list of options, and returns it. @param string $prompt Prompt text. @param string|array $options Array or string of options. @param string|null $default Default input value. @return mixed Either the default value, or the user-provided input.
[ "Prompts", "the", "user", "for", "input", "based", "on", "a", "list", "of", "options", "and", "returns", "it", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleIo.php#L412-L436
211,364
cakephp/cakephp
src/Console/ConsoleIo.php
ConsoleIo.setLoggers
public function setLoggers($enable) { Log::drop('stdout'); Log::drop('stderr'); if ($enable === false) { return; } $outLevels = ['notice', 'info']; if ($enable === static::VERBOSE || $enable === true) { $outLevels[] = 'debug'; } if ($enable !== static::QUIET) { $stdout = new ConsoleLog([ 'types' => $outLevels, 'stream' => $this->_out ]); Log::setConfig('stdout', ['engine' => $stdout]); } $stderr = new ConsoleLog([ 'types' => ['emergency', 'alert', 'critical', 'error', 'warning'], 'stream' => $this->_err, ]); Log::setConfig('stderr', ['engine' => $stderr]); }
php
public function setLoggers($enable) { Log::drop('stdout'); Log::drop('stderr'); if ($enable === false) { return; } $outLevels = ['notice', 'info']; if ($enable === static::VERBOSE || $enable === true) { $outLevels[] = 'debug'; } if ($enable !== static::QUIET) { $stdout = new ConsoleLog([ 'types' => $outLevels, 'stream' => $this->_out ]); Log::setConfig('stdout', ['engine' => $stdout]); } $stderr = new ConsoleLog([ 'types' => ['emergency', 'alert', 'critical', 'error', 'warning'], 'stream' => $this->_err, ]); Log::setConfig('stderr', ['engine' => $stderr]); }
[ "public", "function", "setLoggers", "(", "$", "enable", ")", "{", "Log", "::", "drop", "(", "'stdout'", ")", ";", "Log", "::", "drop", "(", "'stderr'", ")", ";", "if", "(", "$", "enable", "===", "false", ")", "{", "return", ";", "}", "$", "outLevels", "=", "[", "'notice'", ",", "'info'", "]", ";", "if", "(", "$", "enable", "===", "static", "::", "VERBOSE", "||", "$", "enable", "===", "true", ")", "{", "$", "outLevels", "[", "]", "=", "'debug'", ";", "}", "if", "(", "$", "enable", "!==", "static", "::", "QUIET", ")", "{", "$", "stdout", "=", "new", "ConsoleLog", "(", "[", "'types'", "=>", "$", "outLevels", ",", "'stream'", "=>", "$", "this", "->", "_out", "]", ")", ";", "Log", "::", "setConfig", "(", "'stdout'", ",", "[", "'engine'", "=>", "$", "stdout", "]", ")", ";", "}", "$", "stderr", "=", "new", "ConsoleLog", "(", "[", "'types'", "=>", "[", "'emergency'", ",", "'alert'", ",", "'critical'", ",", "'error'", ",", "'warning'", "]", ",", "'stream'", "=>", "$", "this", "->", "_err", ",", "]", ")", ";", "Log", "::", "setConfig", "(", "'stderr'", ",", "[", "'engine'", "=>", "$", "stderr", "]", ")", ";", "}" ]
Connects or disconnects the loggers to the console output. Used to enable or disable logging stream output to stdout and stderr If you don't wish all log output in stdout or stderr through Cake's Log class, call this function with `$enable=false`. @param int|bool $enable Use a boolean to enable/toggle all logging. Use one of the verbosity constants (self::VERBOSE, self::QUIET, self::NORMAL) to control logging levels. VERBOSE enables debug logs, NORMAL does not include debug logs, QUIET disables notice, info and debug logs. @return void
[ "Connects", "or", "disconnects", "the", "loggers", "to", "the", "console", "output", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleIo.php#L481-L504
211,365
cakephp/cakephp
src/Console/ConsoleIo.php
ConsoleIo.helper
public function helper($name, array $settings = []) { $name = ucfirst($name); return $this->_helpers->load($name, $settings); }
php
public function helper($name, array $settings = []) { $name = ucfirst($name); return $this->_helpers->load($name, $settings); }
[ "public", "function", "helper", "(", "$", "name", ",", "array", "$", "settings", "=", "[", "]", ")", "{", "$", "name", "=", "ucfirst", "(", "$", "name", ")", ";", "return", "$", "this", "->", "_helpers", "->", "load", "(", "$", "name", ",", "$", "settings", ")", ";", "}" ]
Render a Console Helper Create and render the output for a helper object. If the helper object has not already been loaded, it will be loaded and constructed. @param string $name The name of the helper to render @param array $settings Configuration data for the helper. @return \Cake\Console\Helper The created helper instance.
[ "Render", "a", "Console", "Helper" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleIo.php#L516-L521
211,366
cakephp/cakephp
src/Console/ConsoleIo.php
ConsoleIo.createFile
public function createFile($path, $contents, $forceOverwrite = false) { $this->out(); $forceOverwrite = $forceOverwrite || $this->forceOverwrite; if (file_exists($path) && $forceOverwrite === false) { $this->warning("File `{$path}` exists"); $key = $this->askChoice('Do you want to overwrite?', ['y', 'n', 'a', 'q'], 'n'); $key = strtolower($key); if ($key === 'q') { $this->error('Quitting.', 2); throw new StopException('Not creating file. Quitting.'); } if ($key === 'a') { $this->forceOverwrite = true; $key = 'y'; } if ($key !== 'y') { $this->out("Skip `{$path}`", 2); return false; } } else { $this->out("Creating file {$path}"); } try { // Create the directory using the current user permissions. $directory = dirname($path); if (!file_exists($directory)) { mkdir($directory, 0777 ^ umask(), true); } $file = new SplFileObject($path, 'w'); } catch (RuntimeException $e) { $this->error("Could not write to `{$path}`. Permission denied.", 2); return false; } $file->rewind(); if ($file->fwrite($contents) > 0) { $this->out("<success>Wrote</success> `{$path}`"); return true; } $this->error("Could not write to `{$path}`.", 2); return false; }
php
public function createFile($path, $contents, $forceOverwrite = false) { $this->out(); $forceOverwrite = $forceOverwrite || $this->forceOverwrite; if (file_exists($path) && $forceOverwrite === false) { $this->warning("File `{$path}` exists"); $key = $this->askChoice('Do you want to overwrite?', ['y', 'n', 'a', 'q'], 'n'); $key = strtolower($key); if ($key === 'q') { $this->error('Quitting.', 2); throw new StopException('Not creating file. Quitting.'); } if ($key === 'a') { $this->forceOverwrite = true; $key = 'y'; } if ($key !== 'y') { $this->out("Skip `{$path}`", 2); return false; } } else { $this->out("Creating file {$path}"); } try { // Create the directory using the current user permissions. $directory = dirname($path); if (!file_exists($directory)) { mkdir($directory, 0777 ^ umask(), true); } $file = new SplFileObject($path, 'w'); } catch (RuntimeException $e) { $this->error("Could not write to `{$path}`. Permission denied.", 2); return false; } $file->rewind(); if ($file->fwrite($contents) > 0) { $this->out("<success>Wrote</success> `{$path}`"); return true; } $this->error("Could not write to `{$path}`.", 2); return false; }
[ "public", "function", "createFile", "(", "$", "path", ",", "$", "contents", ",", "$", "forceOverwrite", "=", "false", ")", "{", "$", "this", "->", "out", "(", ")", ";", "$", "forceOverwrite", "=", "$", "forceOverwrite", "||", "$", "this", "->", "forceOverwrite", ";", "if", "(", "file_exists", "(", "$", "path", ")", "&&", "$", "forceOverwrite", "===", "false", ")", "{", "$", "this", "->", "warning", "(", "\"File `{$path}` exists\"", ")", ";", "$", "key", "=", "$", "this", "->", "askChoice", "(", "'Do you want to overwrite?'", ",", "[", "'y'", ",", "'n'", ",", "'a'", ",", "'q'", "]", ",", "'n'", ")", ";", "$", "key", "=", "strtolower", "(", "$", "key", ")", ";", "if", "(", "$", "key", "===", "'q'", ")", "{", "$", "this", "->", "error", "(", "'Quitting.'", ",", "2", ")", ";", "throw", "new", "StopException", "(", "'Not creating file. Quitting.'", ")", ";", "}", "if", "(", "$", "key", "===", "'a'", ")", "{", "$", "this", "->", "forceOverwrite", "=", "true", ";", "$", "key", "=", "'y'", ";", "}", "if", "(", "$", "key", "!==", "'y'", ")", "{", "$", "this", "->", "out", "(", "\"Skip `{$path}`\"", ",", "2", ")", ";", "return", "false", ";", "}", "}", "else", "{", "$", "this", "->", "out", "(", "\"Creating file {$path}\"", ")", ";", "}", "try", "{", "// Create the directory using the current user permissions.", "$", "directory", "=", "dirname", "(", "$", "path", ")", ";", "if", "(", "!", "file_exists", "(", "$", "directory", ")", ")", "{", "mkdir", "(", "$", "directory", ",", "0777", "^", "umask", "(", ")", ",", "true", ")", ";", "}", "$", "file", "=", "new", "SplFileObject", "(", "$", "path", ",", "'w'", ")", ";", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "$", "this", "->", "error", "(", "\"Could not write to `{$path}`. Permission denied.\"", ",", "2", ")", ";", "return", "false", ";", "}", "$", "file", "->", "rewind", "(", ")", ";", "if", "(", "$", "file", "->", "fwrite", "(", "$", "contents", ")", ">", "0", ")", "{", "$", "this", "->", "out", "(", "\"<success>Wrote</success> `{$path}`\"", ")", ";", "return", "true", ";", "}", "$", "this", "->", "error", "(", "\"Could not write to `{$path}`.\"", ",", "2", ")", ";", "return", "false", ";", "}" ]
Create a file at the given path. This method will prompt the user if a file will be overwritten. Setting `forceOverwrite` to true will suppress this behavior and always overwrite the file. If the user replies `a` subsequent `forceOverwrite` parameters will be coerced to true and all files will be overwritten. @param string $path The path to create the file at. @param string $contents The contents to put into the file. @param bool $forceOverwrite Whether or not the file should be overwritten. If true, no question will be asked about whether or not to overwrite existing files. @return bool Success. @throws \Cake\Console\Exception\StopException When `q` is given as an answer to whether or not a file should be overwritten.
[ "Create", "a", "file", "at", "the", "given", "path", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleIo.php#L541-L591
211,367
cakephp/cakephp
src/Cache/Engine/FileEngine.php
FileEngine.init
public function init(array $config = []) { parent::init($config); if ($this->_config['path'] === null) { $this->_config['path'] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'cake_cache' . DIRECTORY_SEPARATOR; } if (DIRECTORY_SEPARATOR === '\\') { $this->_config['isWindows'] = true; } if (substr($this->_config['path'], -1) !== DIRECTORY_SEPARATOR) { $this->_config['path'] .= DIRECTORY_SEPARATOR; } if ($this->_groupPrefix) { $this->_groupPrefix = str_replace('_', DIRECTORY_SEPARATOR, $this->_groupPrefix); } return $this->_active(); }
php
public function init(array $config = []) { parent::init($config); if ($this->_config['path'] === null) { $this->_config['path'] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'cake_cache' . DIRECTORY_SEPARATOR; } if (DIRECTORY_SEPARATOR === '\\') { $this->_config['isWindows'] = true; } if (substr($this->_config['path'], -1) !== DIRECTORY_SEPARATOR) { $this->_config['path'] .= DIRECTORY_SEPARATOR; } if ($this->_groupPrefix) { $this->_groupPrefix = str_replace('_', DIRECTORY_SEPARATOR, $this->_groupPrefix); } return $this->_active(); }
[ "public", "function", "init", "(", "array", "$", "config", "=", "[", "]", ")", "{", "parent", "::", "init", "(", "$", "config", ")", ";", "if", "(", "$", "this", "->", "_config", "[", "'path'", "]", "===", "null", ")", "{", "$", "this", "->", "_config", "[", "'path'", "]", "=", "sys_get_temp_dir", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "'cake_cache'", ".", "DIRECTORY_SEPARATOR", ";", "}", "if", "(", "DIRECTORY_SEPARATOR", "===", "'\\\\'", ")", "{", "$", "this", "->", "_config", "[", "'isWindows'", "]", "=", "true", ";", "}", "if", "(", "substr", "(", "$", "this", "->", "_config", "[", "'path'", "]", ",", "-", "1", ")", "!==", "DIRECTORY_SEPARATOR", ")", "{", "$", "this", "->", "_config", "[", "'path'", "]", ".=", "DIRECTORY_SEPARATOR", ";", "}", "if", "(", "$", "this", "->", "_groupPrefix", ")", "{", "$", "this", "->", "_groupPrefix", "=", "str_replace", "(", "'_'", ",", "DIRECTORY_SEPARATOR", ",", "$", "this", "->", "_groupPrefix", ")", ";", "}", "return", "$", "this", "->", "_active", "(", ")", ";", "}" ]
Initialize File Cache Engine Called automatically by the cache frontend. @param array $config array of setting for the engine @return bool True if the engine has been successfully initialized, false if not
[ "Initialize", "File", "Cache", "Engine" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/FileEngine.php#L89-L107
211,368
cakephp/cakephp
src/Cache/Engine/FileEngine.php
FileEngine.clear
public function clear($check) { if (!$this->_init) { return false; } $this->_File = null; $threshold = $now = false; if ($check) { $now = time(); $threshold = $now - $this->_config['duration']; } $this->_clearDirectory($this->_config['path'], $now, $threshold); $directory = new RecursiveDirectoryIterator( $this->_config['path'], \FilesystemIterator::SKIP_DOTS ); $contents = new RecursiveIteratorIterator( $directory, RecursiveIteratorIterator::SELF_FIRST ); $cleared = []; foreach ($contents as $path) { if ($path->isFile()) { continue; } $path = $path->getRealPath() . DIRECTORY_SEPARATOR; if (!in_array($path, $cleared)) { $this->_clearDirectory($path, $now, $threshold); $cleared[] = $path; } } return true; }
php
public function clear($check) { if (!$this->_init) { return false; } $this->_File = null; $threshold = $now = false; if ($check) { $now = time(); $threshold = $now - $this->_config['duration']; } $this->_clearDirectory($this->_config['path'], $now, $threshold); $directory = new RecursiveDirectoryIterator( $this->_config['path'], \FilesystemIterator::SKIP_DOTS ); $contents = new RecursiveIteratorIterator( $directory, RecursiveIteratorIterator::SELF_FIRST ); $cleared = []; foreach ($contents as $path) { if ($path->isFile()) { continue; } $path = $path->getRealPath() . DIRECTORY_SEPARATOR; if (!in_array($path, $cleared)) { $this->_clearDirectory($path, $now, $threshold); $cleared[] = $path; } } return true; }
[ "public", "function", "clear", "(", "$", "check", ")", "{", "if", "(", "!", "$", "this", "->", "_init", ")", "{", "return", "false", ";", "}", "$", "this", "->", "_File", "=", "null", ";", "$", "threshold", "=", "$", "now", "=", "false", ";", "if", "(", "$", "check", ")", "{", "$", "now", "=", "time", "(", ")", ";", "$", "threshold", "=", "$", "now", "-", "$", "this", "->", "_config", "[", "'duration'", "]", ";", "}", "$", "this", "->", "_clearDirectory", "(", "$", "this", "->", "_config", "[", "'path'", "]", ",", "$", "now", ",", "$", "threshold", ")", ";", "$", "directory", "=", "new", "RecursiveDirectoryIterator", "(", "$", "this", "->", "_config", "[", "'path'", "]", ",", "\\", "FilesystemIterator", "::", "SKIP_DOTS", ")", ";", "$", "contents", "=", "new", "RecursiveIteratorIterator", "(", "$", "directory", ",", "RecursiveIteratorIterator", "::", "SELF_FIRST", ")", ";", "$", "cleared", "=", "[", "]", ";", "foreach", "(", "$", "contents", "as", "$", "path", ")", "{", "if", "(", "$", "path", "->", "isFile", "(", ")", ")", "{", "continue", ";", "}", "$", "path", "=", "$", "path", "->", "getRealPath", "(", ")", ".", "DIRECTORY_SEPARATOR", ";", "if", "(", "!", "in_array", "(", "$", "path", ",", "$", "cleared", ")", ")", "{", "$", "this", "->", "_clearDirectory", "(", "$", "path", ",", "$", "now", ",", "$", "threshold", ")", ";", "$", "cleared", "[", "]", "=", "$", "path", ";", "}", "}", "return", "true", ";", "}" ]
Delete all values from the cache @param bool $check Optional - only delete expired cache items @return bool True if the cache was successfully cleared, false otherwise
[ "Delete", "all", "values", "from", "the", "cache" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/FileEngine.php#L257-L294
211,369
cakephp/cakephp
src/Cache/Engine/FileEngine.php
FileEngine._clearDirectory
protected function _clearDirectory($path, $now, $threshold) { if (!is_dir($path)) { return; } $prefixLength = strlen($this->_config['prefix']); $dir = dir($path); while (($entry = $dir->read()) !== false) { if (substr($entry, 0, $prefixLength) !== $this->_config['prefix']) { continue; } try { $file = new SplFileObject($path . $entry, 'r'); } catch (Exception $e) { continue; } if ($threshold) { $mtime = $file->getMTime(); if ($mtime > $threshold) { continue; } $expires = (int)$file->current(); if ($expires > $now) { continue; } } if ($file->isFile()) { $filePath = $file->getRealPath(); $file = null; //@codingStandardsIgnoreStart @unlink($filePath); //@codingStandardsIgnoreEnd } } $dir->close(); }
php
protected function _clearDirectory($path, $now, $threshold) { if (!is_dir($path)) { return; } $prefixLength = strlen($this->_config['prefix']); $dir = dir($path); while (($entry = $dir->read()) !== false) { if (substr($entry, 0, $prefixLength) !== $this->_config['prefix']) { continue; } try { $file = new SplFileObject($path . $entry, 'r'); } catch (Exception $e) { continue; } if ($threshold) { $mtime = $file->getMTime(); if ($mtime > $threshold) { continue; } $expires = (int)$file->current(); if ($expires > $now) { continue; } } if ($file->isFile()) { $filePath = $file->getRealPath(); $file = null; //@codingStandardsIgnoreStart @unlink($filePath); //@codingStandardsIgnoreEnd } } $dir->close(); }
[ "protected", "function", "_clearDirectory", "(", "$", "path", ",", "$", "now", ",", "$", "threshold", ")", "{", "if", "(", "!", "is_dir", "(", "$", "path", ")", ")", "{", "return", ";", "}", "$", "prefixLength", "=", "strlen", "(", "$", "this", "->", "_config", "[", "'prefix'", "]", ")", ";", "$", "dir", "=", "dir", "(", "$", "path", ")", ";", "while", "(", "(", "$", "entry", "=", "$", "dir", "->", "read", "(", ")", ")", "!==", "false", ")", "{", "if", "(", "substr", "(", "$", "entry", ",", "0", ",", "$", "prefixLength", ")", "!==", "$", "this", "->", "_config", "[", "'prefix'", "]", ")", "{", "continue", ";", "}", "try", "{", "$", "file", "=", "new", "SplFileObject", "(", "$", "path", ".", "$", "entry", ",", "'r'", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "continue", ";", "}", "if", "(", "$", "threshold", ")", "{", "$", "mtime", "=", "$", "file", "->", "getMTime", "(", ")", ";", "if", "(", "$", "mtime", ">", "$", "threshold", ")", "{", "continue", ";", "}", "$", "expires", "=", "(", "int", ")", "$", "file", "->", "current", "(", ")", ";", "if", "(", "$", "expires", ">", "$", "now", ")", "{", "continue", ";", "}", "}", "if", "(", "$", "file", "->", "isFile", "(", ")", ")", "{", "$", "filePath", "=", "$", "file", "->", "getRealPath", "(", ")", ";", "$", "file", "=", "null", ";", "//@codingStandardsIgnoreStart", "@", "unlink", "(", "$", "filePath", ")", ";", "//@codingStandardsIgnoreEnd", "}", "}", "$", "dir", "->", "close", "(", ")", ";", "}" ]
Used to clear a directory of matching files. @param string $path The path to search. @param int $now The current timestamp @param int $threshold Any file not modified after this value will be deleted. @return void
[ "Used", "to", "clear", "a", "directory", "of", "matching", "files", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/FileEngine.php#L304-L345
211,370
cakephp/cakephp
src/Cache/Engine/FileEngine.php
FileEngine._setKey
protected function _setKey($key, $createKey = false) { $groups = null; if ($this->_groupPrefix) { $groups = vsprintf($this->_groupPrefix, $this->groups()); } $dir = $this->_config['path'] . $groups; if (!is_dir($dir)) { mkdir($dir, 0775, true); } $path = new SplFileInfo($dir . $key); if (!$createKey && !$path->isFile()) { return false; } if (empty($this->_File) || $this->_File->getBasename() !== $key || $this->_File->valid() === false ) { $exists = file_exists($path->getPathname()); try { $this->_File = $path->openFile('c+'); } catch (Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); return false; } unset($path); if (!$exists && !chmod($this->_File->getPathname(), (int)$this->_config['mask'])) { trigger_error(sprintf( 'Could not apply permission mask "%s" on cache file "%s"', $this->_File->getPathname(), $this->_config['mask'] ), E_USER_WARNING); } } return true; }
php
protected function _setKey($key, $createKey = false) { $groups = null; if ($this->_groupPrefix) { $groups = vsprintf($this->_groupPrefix, $this->groups()); } $dir = $this->_config['path'] . $groups; if (!is_dir($dir)) { mkdir($dir, 0775, true); } $path = new SplFileInfo($dir . $key); if (!$createKey && !$path->isFile()) { return false; } if (empty($this->_File) || $this->_File->getBasename() !== $key || $this->_File->valid() === false ) { $exists = file_exists($path->getPathname()); try { $this->_File = $path->openFile('c+'); } catch (Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); return false; } unset($path); if (!$exists && !chmod($this->_File->getPathname(), (int)$this->_config['mask'])) { trigger_error(sprintf( 'Could not apply permission mask "%s" on cache file "%s"', $this->_File->getPathname(), $this->_config['mask'] ), E_USER_WARNING); } } return true; }
[ "protected", "function", "_setKey", "(", "$", "key", ",", "$", "createKey", "=", "false", ")", "{", "$", "groups", "=", "null", ";", "if", "(", "$", "this", "->", "_groupPrefix", ")", "{", "$", "groups", "=", "vsprintf", "(", "$", "this", "->", "_groupPrefix", ",", "$", "this", "->", "groups", "(", ")", ")", ";", "}", "$", "dir", "=", "$", "this", "->", "_config", "[", "'path'", "]", ".", "$", "groups", ";", "if", "(", "!", "is_dir", "(", "$", "dir", ")", ")", "{", "mkdir", "(", "$", "dir", ",", "0775", ",", "true", ")", ";", "}", "$", "path", "=", "new", "SplFileInfo", "(", "$", "dir", ".", "$", "key", ")", ";", "if", "(", "!", "$", "createKey", "&&", "!", "$", "path", "->", "isFile", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "_File", ")", "||", "$", "this", "->", "_File", "->", "getBasename", "(", ")", "!==", "$", "key", "||", "$", "this", "->", "_File", "->", "valid", "(", ")", "===", "false", ")", "{", "$", "exists", "=", "file_exists", "(", "$", "path", "->", "getPathname", "(", ")", ")", ";", "try", "{", "$", "this", "->", "_File", "=", "$", "path", "->", "openFile", "(", "'c+'", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "trigger_error", "(", "$", "e", "->", "getMessage", "(", ")", ",", "E_USER_WARNING", ")", ";", "return", "false", ";", "}", "unset", "(", "$", "path", ")", ";", "if", "(", "!", "$", "exists", "&&", "!", "chmod", "(", "$", "this", "->", "_File", "->", "getPathname", "(", ")", ",", "(", "int", ")", "$", "this", "->", "_config", "[", "'mask'", "]", ")", ")", "{", "trigger_error", "(", "sprintf", "(", "'Could not apply permission mask \"%s\" on cache file \"%s\"'", ",", "$", "this", "->", "_File", "->", "getPathname", "(", ")", ",", "$", "this", "->", "_config", "[", "'mask'", "]", ")", ",", "E_USER_WARNING", ")", ";", "}", "}", "return", "true", ";", "}" ]
Sets the current cache key this class is managing, and creates a writable SplFileObject for the cache file the key is referring to. @param string $key The key @param bool $createKey Whether the key should be created if it doesn't exists, or not @return bool true if the cache key could be set, false otherwise
[ "Sets", "the", "current", "cache", "key", "this", "class", "is", "managing", "and", "creates", "a", "writable", "SplFileObject", "for", "the", "cache", "file", "the", "key", "is", "referring", "to", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/FileEngine.php#L381-L422
211,371
cakephp/cakephp
src/Cache/Engine/FileEngine.php
FileEngine._active
protected function _active() { $dir = new SplFileInfo($this->_config['path']); $path = $dir->getPathname(); $success = true; if (!is_dir($path)) { //@codingStandardsIgnoreStart $success = @mkdir($path, 0775, true); //@codingStandardsIgnoreEnd } $isWritableDir = ($dir->isDir() && $dir->isWritable()); if (!$success || ($this->_init && !$isWritableDir)) { $this->_init = false; trigger_error(sprintf( '%s is not writable', $this->_config['path'] ), E_USER_WARNING); } return $success; }
php
protected function _active() { $dir = new SplFileInfo($this->_config['path']); $path = $dir->getPathname(); $success = true; if (!is_dir($path)) { //@codingStandardsIgnoreStart $success = @mkdir($path, 0775, true); //@codingStandardsIgnoreEnd } $isWritableDir = ($dir->isDir() && $dir->isWritable()); if (!$success || ($this->_init && !$isWritableDir)) { $this->_init = false; trigger_error(sprintf( '%s is not writable', $this->_config['path'] ), E_USER_WARNING); } return $success; }
[ "protected", "function", "_active", "(", ")", "{", "$", "dir", "=", "new", "SplFileInfo", "(", "$", "this", "->", "_config", "[", "'path'", "]", ")", ";", "$", "path", "=", "$", "dir", "->", "getPathname", "(", ")", ";", "$", "success", "=", "true", ";", "if", "(", "!", "is_dir", "(", "$", "path", ")", ")", "{", "//@codingStandardsIgnoreStart", "$", "success", "=", "@", "mkdir", "(", "$", "path", ",", "0775", ",", "true", ")", ";", "//@codingStandardsIgnoreEnd", "}", "$", "isWritableDir", "=", "(", "$", "dir", "->", "isDir", "(", ")", "&&", "$", "dir", "->", "isWritable", "(", ")", ")", ";", "if", "(", "!", "$", "success", "||", "(", "$", "this", "->", "_init", "&&", "!", "$", "isWritableDir", ")", ")", "{", "$", "this", "->", "_init", "=", "false", ";", "trigger_error", "(", "sprintf", "(", "'%s is not writable'", ",", "$", "this", "->", "_config", "[", "'path'", "]", ")", ",", "E_USER_WARNING", ")", ";", "}", "return", "$", "success", ";", "}" ]
Determine if cache directory is writable @return bool
[ "Determine", "if", "cache", "directory", "is", "writable" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/FileEngine.php#L429-L450
211,372
cakephp/cakephp
src/Routing/Route/RedirectRoute.php
RedirectRoute.parse
public function parse($url, $method = '') { $params = parent::parse($url, $method); if (!$params) { return false; } $redirect = $this->redirect; if (count($this->redirect) === 1 && !isset($this->redirect['controller'])) { $redirect = $this->redirect[0]; } if (isset($this->options['persist']) && is_array($redirect)) { $redirect += ['pass' => $params['pass'], 'url' => []]; if (is_array($this->options['persist'])) { foreach ($this->options['persist'] as $elem) { if (isset($params[$elem])) { $redirect[$elem] = $params[$elem]; } } } $redirect = Router::reverseToArray($redirect); } $status = 301; if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) { $status = $this->options['status']; } throw new RedirectException(Router::url($redirect, true), $status); }
php
public function parse($url, $method = '') { $params = parent::parse($url, $method); if (!$params) { return false; } $redirect = $this->redirect; if (count($this->redirect) === 1 && !isset($this->redirect['controller'])) { $redirect = $this->redirect[0]; } if (isset($this->options['persist']) && is_array($redirect)) { $redirect += ['pass' => $params['pass'], 'url' => []]; if (is_array($this->options['persist'])) { foreach ($this->options['persist'] as $elem) { if (isset($params[$elem])) { $redirect[$elem] = $params[$elem]; } } } $redirect = Router::reverseToArray($redirect); } $status = 301; if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) { $status = $this->options['status']; } throw new RedirectException(Router::url($redirect, true), $status); }
[ "public", "function", "parse", "(", "$", "url", ",", "$", "method", "=", "''", ")", "{", "$", "params", "=", "parent", "::", "parse", "(", "$", "url", ",", "$", "method", ")", ";", "if", "(", "!", "$", "params", ")", "{", "return", "false", ";", "}", "$", "redirect", "=", "$", "this", "->", "redirect", ";", "if", "(", "count", "(", "$", "this", "->", "redirect", ")", "===", "1", "&&", "!", "isset", "(", "$", "this", "->", "redirect", "[", "'controller'", "]", ")", ")", "{", "$", "redirect", "=", "$", "this", "->", "redirect", "[", "0", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'persist'", "]", ")", "&&", "is_array", "(", "$", "redirect", ")", ")", "{", "$", "redirect", "+=", "[", "'pass'", "=>", "$", "params", "[", "'pass'", "]", ",", "'url'", "=>", "[", "]", "]", ";", "if", "(", "is_array", "(", "$", "this", "->", "options", "[", "'persist'", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "options", "[", "'persist'", "]", "as", "$", "elem", ")", "{", "if", "(", "isset", "(", "$", "params", "[", "$", "elem", "]", ")", ")", "{", "$", "redirect", "[", "$", "elem", "]", "=", "$", "params", "[", "$", "elem", "]", ";", "}", "}", "}", "$", "redirect", "=", "Router", "::", "reverseToArray", "(", "$", "redirect", ")", ";", "}", "$", "status", "=", "301", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'status'", "]", ")", "&&", "(", "$", "this", "->", "options", "[", "'status'", "]", ">=", "300", "&&", "$", "this", "->", "options", "[", "'status'", "]", "<", "400", ")", ")", "{", "$", "status", "=", "$", "this", "->", "options", "[", "'status'", "]", ";", "}", "throw", "new", "RedirectException", "(", "Router", "::", "url", "(", "$", "redirect", ",", "true", ")", ",", "$", "status", ")", ";", "}" ]
Parses a string URL into an array. Parsed URLs will result in an automatic redirection. @param string $url The URL to parse. @param string $method The HTTP method being used. @return bool|null False on failure. An exception is raised on a successful match. @throws \Cake\Routing\Exception\RedirectException An exception is raised on successful match. This is used to halt route matching and signal to the middleware that a redirect should happen.
[ "Parses", "a", "string", "URL", "into", "an", "array", ".", "Parsed", "URLs", "will", "result", "in", "an", "automatic", "redirection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/RedirectRoute.php#L72-L98
211,373
cakephp/cakephp
src/Cache/CacheRegistry.php
CacheRegistry._create
protected function _create($class, $alias, $config) { if (is_object($class)) { $instance = $class; } unset($config['className']); if (!isset($instance)) { $instance = new $class($config); } if (!($instance instanceof CacheEngine)) { throw new RuntimeException( 'Cache engines must use Cake\Cache\CacheEngine as a base class.' ); } if (!$instance->init($config)) { throw new RuntimeException( sprintf('Cache engine %s is not properly configured.', get_class($instance)) ); } $config = $instance->getConfig(); if ($config['probability'] && time() % $config['probability'] === 0) { $instance->gc(); } return $instance; }
php
protected function _create($class, $alias, $config) { if (is_object($class)) { $instance = $class; } unset($config['className']); if (!isset($instance)) { $instance = new $class($config); } if (!($instance instanceof CacheEngine)) { throw new RuntimeException( 'Cache engines must use Cake\Cache\CacheEngine as a base class.' ); } if (!$instance->init($config)) { throw new RuntimeException( sprintf('Cache engine %s is not properly configured.', get_class($instance)) ); } $config = $instance->getConfig(); if ($config['probability'] && time() % $config['probability'] === 0) { $instance->gc(); } return $instance; }
[ "protected", "function", "_create", "(", "$", "class", ",", "$", "alias", ",", "$", "config", ")", "{", "if", "(", "is_object", "(", "$", "class", ")", ")", "{", "$", "instance", "=", "$", "class", ";", "}", "unset", "(", "$", "config", "[", "'className'", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "instance", ")", ")", "{", "$", "instance", "=", "new", "$", "class", "(", "$", "config", ")", ";", "}", "if", "(", "!", "(", "$", "instance", "instanceof", "CacheEngine", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Cache engines must use Cake\\Cache\\CacheEngine as a base class.'", ")", ";", "}", "if", "(", "!", "$", "instance", "->", "init", "(", "$", "config", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Cache engine %s is not properly configured.'", ",", "get_class", "(", "$", "instance", ")", ")", ")", ";", "}", "$", "config", "=", "$", "instance", "->", "getConfig", "(", ")", ";", "if", "(", "$", "config", "[", "'probability'", "]", "&&", "time", "(", ")", "%", "$", "config", "[", "'probability'", "]", "===", "0", ")", "{", "$", "instance", "->", "gc", "(", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Create the cache engine instance. Part of the template method for Cake\Core\ObjectRegistry::load() @param string|\Cake\Cache\CacheEngine $class The classname or object to make. @param string $alias The alias of the object. @param array $config An array of settings to use for the cache engine. @return \Cake\Cache\CacheEngine The constructed CacheEngine class. @throws \RuntimeException when an object doesn't implement the correct interface.
[ "Create", "the", "cache", "engine", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/CacheRegistry.php#L73-L102
211,374
cakephp/cakephp
src/View/ViewVarsTrait.php
ViewVarsTrait.createView
public function createView($viewClass = null) { $builder = $this->viewBuilder(); if ($viewClass === null && $builder->getClassName() === null) { $builder->setClassName($this->viewClass); $this->viewClass = null; } if ($viewClass) { $builder->setClassName($viewClass); } $validViewOptions = isset($this->_validViewOptions) ? $this->_validViewOptions : []; $viewOptions = []; foreach ($validViewOptions as $option) { if (property_exists($this, $option)) { $viewOptions[$option] = $this->{$option}; } } $deprecatedOptions = [ 'layout' => 'setLayout', 'view' => 'setTemplate', 'theme' => 'setTheme', 'autoLayout' => 'enableAutoLayout', 'viewPath' => 'setTemplatePath', 'layoutPath' => 'setLayoutPath', ]; foreach ($deprecatedOptions as $old => $new) { if (property_exists($this, $old)) { $builder->{$new}($this->{$old}); $message = sprintf( 'Property $%s is deprecated. Use $this->viewBuilder()->%s() instead in beforeRender().', $old, $new ); deprecationWarning($message); } } foreach (['name', 'helpers', 'plugin'] as $prop) { if (isset($this->{$prop})) { $method = 'set' . ucfirst($prop); $builder->{$method}($this->{$prop}); } } $builder->setOptions($viewOptions); return $builder->build( $this->viewVars, isset($this->request) ? $this->request : null, isset($this->response) ? $this->response : null, $this instanceof EventDispatcherInterface ? $this->getEventManager() : null ); }
php
public function createView($viewClass = null) { $builder = $this->viewBuilder(); if ($viewClass === null && $builder->getClassName() === null) { $builder->setClassName($this->viewClass); $this->viewClass = null; } if ($viewClass) { $builder->setClassName($viewClass); } $validViewOptions = isset($this->_validViewOptions) ? $this->_validViewOptions : []; $viewOptions = []; foreach ($validViewOptions as $option) { if (property_exists($this, $option)) { $viewOptions[$option] = $this->{$option}; } } $deprecatedOptions = [ 'layout' => 'setLayout', 'view' => 'setTemplate', 'theme' => 'setTheme', 'autoLayout' => 'enableAutoLayout', 'viewPath' => 'setTemplatePath', 'layoutPath' => 'setLayoutPath', ]; foreach ($deprecatedOptions as $old => $new) { if (property_exists($this, $old)) { $builder->{$new}($this->{$old}); $message = sprintf( 'Property $%s is deprecated. Use $this->viewBuilder()->%s() instead in beforeRender().', $old, $new ); deprecationWarning($message); } } foreach (['name', 'helpers', 'plugin'] as $prop) { if (isset($this->{$prop})) { $method = 'set' . ucfirst($prop); $builder->{$method}($this->{$prop}); } } $builder->setOptions($viewOptions); return $builder->build( $this->viewVars, isset($this->request) ? $this->request : null, isset($this->response) ? $this->response : null, $this instanceof EventDispatcherInterface ? $this->getEventManager() : null ); }
[ "public", "function", "createView", "(", "$", "viewClass", "=", "null", ")", "{", "$", "builder", "=", "$", "this", "->", "viewBuilder", "(", ")", ";", "if", "(", "$", "viewClass", "===", "null", "&&", "$", "builder", "->", "getClassName", "(", ")", "===", "null", ")", "{", "$", "builder", "->", "setClassName", "(", "$", "this", "->", "viewClass", ")", ";", "$", "this", "->", "viewClass", "=", "null", ";", "}", "if", "(", "$", "viewClass", ")", "{", "$", "builder", "->", "setClassName", "(", "$", "viewClass", ")", ";", "}", "$", "validViewOptions", "=", "isset", "(", "$", "this", "->", "_validViewOptions", ")", "?", "$", "this", "->", "_validViewOptions", ":", "[", "]", ";", "$", "viewOptions", "=", "[", "]", ";", "foreach", "(", "$", "validViewOptions", "as", "$", "option", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "$", "option", ")", ")", "{", "$", "viewOptions", "[", "$", "option", "]", "=", "$", "this", "->", "{", "$", "option", "}", ";", "}", "}", "$", "deprecatedOptions", "=", "[", "'layout'", "=>", "'setLayout'", ",", "'view'", "=>", "'setTemplate'", ",", "'theme'", "=>", "'setTheme'", ",", "'autoLayout'", "=>", "'enableAutoLayout'", ",", "'viewPath'", "=>", "'setTemplatePath'", ",", "'layoutPath'", "=>", "'setLayoutPath'", ",", "]", ";", "foreach", "(", "$", "deprecatedOptions", "as", "$", "old", "=>", "$", "new", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "$", "old", ")", ")", "{", "$", "builder", "->", "{", "$", "new", "}", "(", "$", "this", "->", "{", "$", "old", "}", ")", ";", "$", "message", "=", "sprintf", "(", "'Property $%s is deprecated. Use $this->viewBuilder()->%s() instead in beforeRender().'", ",", "$", "old", ",", "$", "new", ")", ";", "deprecationWarning", "(", "$", "message", ")", ";", "}", "}", "foreach", "(", "[", "'name'", ",", "'helpers'", ",", "'plugin'", "]", "as", "$", "prop", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "{", "$", "prop", "}", ")", ")", "{", "$", "method", "=", "'set'", ".", "ucfirst", "(", "$", "prop", ")", ";", "$", "builder", "->", "{", "$", "method", "}", "(", "$", "this", "->", "{", "$", "prop", "}", ")", ";", "}", "}", "$", "builder", "->", "setOptions", "(", "$", "viewOptions", ")", ";", "return", "$", "builder", "->", "build", "(", "$", "this", "->", "viewVars", ",", "isset", "(", "$", "this", "->", "request", ")", "?", "$", "this", "->", "request", ":", "null", ",", "isset", "(", "$", "this", "->", "response", ")", "?", "$", "this", "->", "response", ":", "null", ",", "$", "this", "instanceof", "EventDispatcherInterface", "?", "$", "this", "->", "getEventManager", "(", ")", ":", "null", ")", ";", "}" ]
Constructs the view class instance based on the current configuration. @param string|null $viewClass Optional namespaced class name of the View class to instantiate. @return \Cake\View\View @throws \Cake\View\Exception\MissingViewException If view class was not found.
[ "Constructs", "the", "view", "class", "instance", "based", "on", "the", "current", "configuration", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewVarsTrait.php#L73-L126
211,375
cakephp/cakephp
src/View/ViewVarsTrait.php
ViewVarsTrait.set
public function set($name, $value = null) { if (is_array($name)) { if (is_array($value)) { $data = array_combine($name, $value); } else { $data = $name; } } else { $data = [$name => $value]; } $this->viewVars = $data + $this->viewVars; return $this; }
php
public function set($name, $value = null) { if (is_array($name)) { if (is_array($value)) { $data = array_combine($name, $value); } else { $data = $name; } } else { $data = [$name => $value]; } $this->viewVars = $data + $this->viewVars; return $this; }
[ "public", "function", "set", "(", "$", "name", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "data", "=", "array_combine", "(", "$", "name", ",", "$", "value", ")", ";", "}", "else", "{", "$", "data", "=", "$", "name", ";", "}", "}", "else", "{", "$", "data", "=", "[", "$", "name", "=>", "$", "value", "]", ";", "}", "$", "this", "->", "viewVars", "=", "$", "data", "+", "$", "this", "->", "viewVars", ";", "return", "$", "this", ";", "}" ]
Saves a variable or an associative array of variables for use inside a template. @param string|array $name A string or an array of data. @param mixed $value Value in case $name is a string (which then works as the key). Unused if $name is an associative array, otherwise serves as the values to $name's keys. @return $this
[ "Saves", "a", "variable", "or", "an", "associative", "array", "of", "variables", "for", "use", "inside", "a", "template", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewVarsTrait.php#L136-L150
211,376
cakephp/cakephp
src/Core/Retry/CommandRetry.php
CommandRetry.run
public function run(callable $action) { $retryCount = 0; $lastException = null; do { try { return $action(); } catch (Exception $e) { $lastException = $e; if (!$this->strategy->shouldRetry($e, $retryCount)) { throw $e; } } } while ($this->retries > $retryCount++); if ($lastException !== null) { throw $lastException; } }
php
public function run(callable $action) { $retryCount = 0; $lastException = null; do { try { return $action(); } catch (Exception $e) { $lastException = $e; if (!$this->strategy->shouldRetry($e, $retryCount)) { throw $e; } } } while ($this->retries > $retryCount++); if ($lastException !== null) { throw $lastException; } }
[ "public", "function", "run", "(", "callable", "$", "action", ")", "{", "$", "retryCount", "=", "0", ";", "$", "lastException", "=", "null", ";", "do", "{", "try", "{", "return", "$", "action", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "lastException", "=", "$", "e", ";", "if", "(", "!", "$", "this", "->", "strategy", "->", "shouldRetry", "(", "$", "e", ",", "$", "retryCount", ")", ")", "{", "throw", "$", "e", ";", "}", "}", "}", "while", "(", "$", "this", "->", "retries", ">", "$", "retryCount", "++", ")", ";", "if", "(", "$", "lastException", "!==", "null", ")", "{", "throw", "$", "lastException", ";", "}", "}" ]
The number of retries to perform in case of failure @param callable $action The callable action to execute with a retry strategy @return mixed The return value of the passed action callable @throws \Exception
[ "The", "number", "of", "retries", "to", "perform", "in", "case", "of", "failure" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Retry/CommandRetry.php#L61-L80
211,377
cakephp/cakephp
src/Routing/Route/Route.php
Route.setExtensions
public function setExtensions(array $extensions) { $this->_extensions = []; foreach ($extensions as $ext) { $this->_extensions[] = strtolower($ext); } return $this; }
php
public function setExtensions(array $extensions) { $this->_extensions = []; foreach ($extensions as $ext) { $this->_extensions[] = strtolower($ext); } return $this; }
[ "public", "function", "setExtensions", "(", "array", "$", "extensions", ")", "{", "$", "this", "->", "_extensions", "=", "[", "]", ";", "foreach", "(", "$", "extensions", "as", "$", "ext", ")", "{", "$", "this", "->", "_extensions", "[", "]", "=", "strtolower", "(", "$", "ext", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the supported extensions for this route. @param array $extensions The extensions to set. @return $this
[ "Set", "the", "supported", "extensions", "for", "this", "route", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/Route.php#L167-L175
211,378
cakephp/cakephp
src/Routing/Route/Route.php
Route.setMethods
public function setMethods(array $methods) { $methods = array_map('strtoupper', $methods); $diff = array_diff($methods, static::VALID_METHODS); if ($diff !== []) { throw new InvalidArgumentException( sprintf('Invalid HTTP method received. %s is invalid.', implode(', ', $diff)) ); } $this->defaults['_method'] = $methods; return $this; }
php
public function setMethods(array $methods) { $methods = array_map('strtoupper', $methods); $diff = array_diff($methods, static::VALID_METHODS); if ($diff !== []) { throw new InvalidArgumentException( sprintf('Invalid HTTP method received. %s is invalid.', implode(', ', $diff)) ); } $this->defaults['_method'] = $methods; return $this; }
[ "public", "function", "setMethods", "(", "array", "$", "methods", ")", "{", "$", "methods", "=", "array_map", "(", "'strtoupper'", ",", "$", "methods", ")", ";", "$", "diff", "=", "array_diff", "(", "$", "methods", ",", "static", "::", "VALID_METHODS", ")", ";", "if", "(", "$", "diff", "!==", "[", "]", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid HTTP method received. %s is invalid.'", ",", "implode", "(", "', '", ",", "$", "diff", ")", ")", ")", ";", "}", "$", "this", "->", "defaults", "[", "'_method'", "]", "=", "$", "methods", ";", "return", "$", "this", ";", "}" ]
Set the accepted HTTP methods for this route. @param array $methods The HTTP methods to accept. @return $this @throws \InvalidArgumentException
[ "Set", "the", "accepted", "HTTP", "methods", "for", "this", "route", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/Route.php#L194-L206
211,379
cakephp/cakephp
src/Routing/Route/Route.php
Route.setPatterns
public function setPatterns(array $patterns) { $patternValues = implode("", $patterns); if (mb_strlen($patternValues) < strlen($patternValues)) { $this->options['multibytePattern'] = true; } $this->options = array_merge($this->options, $patterns); return $this; }
php
public function setPatterns(array $patterns) { $patternValues = implode("", $patterns); if (mb_strlen($patternValues) < strlen($patternValues)) { $this->options['multibytePattern'] = true; } $this->options = array_merge($this->options, $patterns); return $this; }
[ "public", "function", "setPatterns", "(", "array", "$", "patterns", ")", "{", "$", "patternValues", "=", "implode", "(", "\"\"", ",", "$", "patterns", ")", ";", "if", "(", "mb_strlen", "(", "$", "patternValues", ")", "<", "strlen", "(", "$", "patternValues", ")", ")", "{", "$", "this", "->", "options", "[", "'multibytePattern'", "]", "=", "true", ";", "}", "$", "this", "->", "options", "=", "array_merge", "(", "$", "this", "->", "options", ",", "$", "patterns", ")", ";", "return", "$", "this", ";", "}" ]
Set regexp patterns for routing parameters If any of your patterns contain multibyte values, the `multibytePattern` mode will be enabled. @param array $patterns The patterns to apply to routing elements @return $this
[ "Set", "regexp", "patterns", "for", "routing", "parameters" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/Route.php#L217-L226
211,380
cakephp/cakephp
src/Routing/Route/Route.php
Route.hostMatches
public function hostMatches($host) { $pattern = '@^' . str_replace('\*', '.*', preg_quote($this->options['_host'], '@')) . '$@'; return preg_match($pattern, $host) !== 0; }
php
public function hostMatches($host) { $pattern = '@^' . str_replace('\*', '.*', preg_quote($this->options['_host'], '@')) . '$@'; return preg_match($pattern, $host) !== 0; }
[ "public", "function", "hostMatches", "(", "$", "host", ")", "{", "$", "pattern", "=", "'@^'", ".", "str_replace", "(", "'\\*'", ",", "'.*'", ",", "preg_quote", "(", "$", "this", "->", "options", "[", "'_host'", "]", ",", "'@'", ")", ")", ".", "'$@'", ";", "return", "preg_match", "(", "$", "pattern", ",", "$", "host", ")", "!==", "0", ";", "}" ]
Check to see if the host matches the route requirements @param string $host The request's host name @return bool Whether or not the host matches any conditions set in for this route.
[ "Check", "to", "see", "if", "the", "host", "matches", "the", "route", "requirements" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/Route.php#L531-L536
211,381
cakephp/cakephp
src/Routing/Route/Route.php
Route._parseArgs
protected function _parseArgs($args, $context) { $pass = []; $args = explode('/', $args); foreach ($args as $param) { if (empty($param) && $param !== '0' && $param !== 0) { continue; } $pass[] = rawurldecode($param); } return $pass; }
php
protected function _parseArgs($args, $context) { $pass = []; $args = explode('/', $args); foreach ($args as $param) { if (empty($param) && $param !== '0' && $param !== 0) { continue; } $pass[] = rawurldecode($param); } return $pass; }
[ "protected", "function", "_parseArgs", "(", "$", "args", ",", "$", "context", ")", "{", "$", "pass", "=", "[", "]", ";", "$", "args", "=", "explode", "(", "'/'", ",", "$", "args", ")", ";", "foreach", "(", "$", "args", "as", "$", "param", ")", "{", "if", "(", "empty", "(", "$", "param", ")", "&&", "$", "param", "!==", "'0'", "&&", "$", "param", "!==", "0", ")", "{", "continue", ";", "}", "$", "pass", "[", "]", "=", "rawurldecode", "(", "$", "param", ")", ";", "}", "return", "$", "pass", ";", "}" ]
Parse passed parameters into a list of passed args. Return true if a given named $param's $val matches a given $rule depending on $context. Currently implemented rule types are controller, action and match that can be combined with each other. @param string $args A string with the passed params. eg. /1/foo @param string $context The current route context, which should contain controller/action keys. @return array Array of passed args.
[ "Parse", "passed", "parameters", "into", "a", "list", "of", "passed", "args", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/Route.php#L569-L582
211,382
cakephp/cakephp
src/Routing/Route/Route.php
Route._persistParams
protected function _persistParams(array $url, array $params) { foreach ($this->options['persist'] as $persistKey) { if (array_key_exists($persistKey, $params) && !isset($url[$persistKey])) { $url[$persistKey] = $params[$persistKey]; } } return $url; }
php
protected function _persistParams(array $url, array $params) { foreach ($this->options['persist'] as $persistKey) { if (array_key_exists($persistKey, $params) && !isset($url[$persistKey])) { $url[$persistKey] = $params[$persistKey]; } } return $url; }
[ "protected", "function", "_persistParams", "(", "array", "$", "url", ",", "array", "$", "params", ")", "{", "foreach", "(", "$", "this", "->", "options", "[", "'persist'", "]", "as", "$", "persistKey", ")", "{", "if", "(", "array_key_exists", "(", "$", "persistKey", ",", "$", "params", ")", "&&", "!", "isset", "(", "$", "url", "[", "$", "persistKey", "]", ")", ")", "{", "$", "url", "[", "$", "persistKey", "]", "=", "$", "params", "[", "$", "persistKey", "]", ";", "}", "}", "return", "$", "url", ";", "}" ]
Apply persistent parameters to a URL array. Persistent parameters are a special key used during route creation to force route parameters to persist when omitted from a URL array. @param array $url The array to apply persistent parameters to. @param array $params An array of persistent values to replace persistent ones. @return array An array with persistent parameters applied.
[ "Apply", "persistent", "parameters", "to", "a", "URL", "array", ".", "Persistent", "parameters", "are", "a", "special", "key", "used", "during", "route", "creation", "to", "force", "route", "parameters", "to", "persist", "when", "omitted", "from", "a", "URL", "array", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/Route.php#L593-L602
211,383
cakephp/cakephp
src/Routing/Route/Route.php
Route._matchMethod
protected function _matchMethod($url) { if (empty($this->defaults['_method'])) { return true; } // @deprecated The `[method]` support should be removed in 4.0.0 if (isset($url['[method]'])) { deprecationWarning('The `[method]` key is deprecated. Use `_method` instead.'); $url['_method'] = $url['[method]']; } if (empty($url['_method'])) { $url['_method'] = 'GET'; } $methods = array_map('strtoupper', (array)$url['_method']); foreach ($methods as $value) { if (in_array($value, (array)$this->defaults['_method'])) { return true; } } return false; }
php
protected function _matchMethod($url) { if (empty($this->defaults['_method'])) { return true; } // @deprecated The `[method]` support should be removed in 4.0.0 if (isset($url['[method]'])) { deprecationWarning('The `[method]` key is deprecated. Use `_method` instead.'); $url['_method'] = $url['[method]']; } if (empty($url['_method'])) { $url['_method'] = 'GET'; } $methods = array_map('strtoupper', (array)$url['_method']); foreach ($methods as $value) { if (in_array($value, (array)$this->defaults['_method'])) { return true; } } return false; }
[ "protected", "function", "_matchMethod", "(", "$", "url", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "defaults", "[", "'_method'", "]", ")", ")", "{", "return", "true", ";", "}", "// @deprecated The `[method]` support should be removed in 4.0.0", "if", "(", "isset", "(", "$", "url", "[", "'[method]'", "]", ")", ")", "{", "deprecationWarning", "(", "'The `[method]` key is deprecated. Use `_method` instead.'", ")", ";", "$", "url", "[", "'_method'", "]", "=", "$", "url", "[", "'[method]'", "]", ";", "}", "if", "(", "empty", "(", "$", "url", "[", "'_method'", "]", ")", ")", "{", "$", "url", "[", "'_method'", "]", "=", "'GET'", ";", "}", "$", "methods", "=", "array_map", "(", "'strtoupper'", ",", "(", "array", ")", "$", "url", "[", "'_method'", "]", ")", ";", "foreach", "(", "$", "methods", "as", "$", "value", ")", "{", "if", "(", "in_array", "(", "$", "value", ",", "(", "array", ")", "$", "this", "->", "defaults", "[", "'_method'", "]", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check whether or not the URL's HTTP method matches. @param array $url The array for the URL being generated. @return bool
[ "Check", "whether", "or", "not", "the", "URL", "s", "HTTP", "method", "matches", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/Route.php#L761-L782
211,384
cakephp/cakephp
src/Routing/Route/Route.php
Route._writeUrl
protected function _writeUrl($params, $pass = [], $query = []) { $pass = implode('/', array_map('rawurlencode', $pass)); $out = $this->template; $search = $replace = []; foreach ($this->keys as $key) { $string = null; if (isset($params[$key])) { $string = $params[$key]; } elseif (strpos($out, $key) != strlen($out) - strlen($key)) { $key .= '/'; } if ($this->braceKeys) { $search[] = "{{$key}}"; } else { $search[] = ':' . $key; } $replace[] = $string; } if (strpos($this->template, '**') !== false) { array_push($search, '**', '%2F'); array_push($replace, $pass, '/'); } elseif (strpos($this->template, '*') !== false) { $search[] = '*'; $replace[] = $pass; } $out = str_replace($search, $replace, $out); // add base url if applicable. if (isset($params['_base'])) { $out = $params['_base'] . $out; unset($params['_base']); } $out = str_replace('//', '/', $out); if (isset($params['_scheme']) || isset($params['_host']) || isset($params['_port']) ) { $host = $params['_host']; // append the port & scheme if they exists. if (isset($params['_port'])) { $host .= ':' . $params['_port']; } $scheme = isset($params['_scheme']) ? $params['_scheme'] : 'http'; $out = "{$scheme}://{$host}{$out}"; } if (!empty($params['_ext']) || !empty($query)) { $out = rtrim($out, '/'); } if (!empty($params['_ext'])) { $out .= '.' . $params['_ext']; } if (!empty($query)) { $out .= rtrim('?' . http_build_query($query), '?'); } return $out; }
php
protected function _writeUrl($params, $pass = [], $query = []) { $pass = implode('/', array_map('rawurlencode', $pass)); $out = $this->template; $search = $replace = []; foreach ($this->keys as $key) { $string = null; if (isset($params[$key])) { $string = $params[$key]; } elseif (strpos($out, $key) != strlen($out) - strlen($key)) { $key .= '/'; } if ($this->braceKeys) { $search[] = "{{$key}}"; } else { $search[] = ':' . $key; } $replace[] = $string; } if (strpos($this->template, '**') !== false) { array_push($search, '**', '%2F'); array_push($replace, $pass, '/'); } elseif (strpos($this->template, '*') !== false) { $search[] = '*'; $replace[] = $pass; } $out = str_replace($search, $replace, $out); // add base url if applicable. if (isset($params['_base'])) { $out = $params['_base'] . $out; unset($params['_base']); } $out = str_replace('//', '/', $out); if (isset($params['_scheme']) || isset($params['_host']) || isset($params['_port']) ) { $host = $params['_host']; // append the port & scheme if they exists. if (isset($params['_port'])) { $host .= ':' . $params['_port']; } $scheme = isset($params['_scheme']) ? $params['_scheme'] : 'http'; $out = "{$scheme}://{$host}{$out}"; } if (!empty($params['_ext']) || !empty($query)) { $out = rtrim($out, '/'); } if (!empty($params['_ext'])) { $out .= '.' . $params['_ext']; } if (!empty($query)) { $out .= rtrim('?' . http_build_query($query), '?'); } return $out; }
[ "protected", "function", "_writeUrl", "(", "$", "params", ",", "$", "pass", "=", "[", "]", ",", "$", "query", "=", "[", "]", ")", "{", "$", "pass", "=", "implode", "(", "'/'", ",", "array_map", "(", "'rawurlencode'", ",", "$", "pass", ")", ")", ";", "$", "out", "=", "$", "this", "->", "template", ";", "$", "search", "=", "$", "replace", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "keys", "as", "$", "key", ")", "{", "$", "string", "=", "null", ";", "if", "(", "isset", "(", "$", "params", "[", "$", "key", "]", ")", ")", "{", "$", "string", "=", "$", "params", "[", "$", "key", "]", ";", "}", "elseif", "(", "strpos", "(", "$", "out", ",", "$", "key", ")", "!=", "strlen", "(", "$", "out", ")", "-", "strlen", "(", "$", "key", ")", ")", "{", "$", "key", ".=", "'/'", ";", "}", "if", "(", "$", "this", "->", "braceKeys", ")", "{", "$", "search", "[", "]", "=", "\"{{$key}}\"", ";", "}", "else", "{", "$", "search", "[", "]", "=", "':'", ".", "$", "key", ";", "}", "$", "replace", "[", "]", "=", "$", "string", ";", "}", "if", "(", "strpos", "(", "$", "this", "->", "template", ",", "'**'", ")", "!==", "false", ")", "{", "array_push", "(", "$", "search", ",", "'**'", ",", "'%2F'", ")", ";", "array_push", "(", "$", "replace", ",", "$", "pass", ",", "'/'", ")", ";", "}", "elseif", "(", "strpos", "(", "$", "this", "->", "template", ",", "'*'", ")", "!==", "false", ")", "{", "$", "search", "[", "]", "=", "'*'", ";", "$", "replace", "[", "]", "=", "$", "pass", ";", "}", "$", "out", "=", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "out", ")", ";", "// add base url if applicable.", "if", "(", "isset", "(", "$", "params", "[", "'_base'", "]", ")", ")", "{", "$", "out", "=", "$", "params", "[", "'_base'", "]", ".", "$", "out", ";", "unset", "(", "$", "params", "[", "'_base'", "]", ")", ";", "}", "$", "out", "=", "str_replace", "(", "'//'", ",", "'/'", ",", "$", "out", ")", ";", "if", "(", "isset", "(", "$", "params", "[", "'_scheme'", "]", ")", "||", "isset", "(", "$", "params", "[", "'_host'", "]", ")", "||", "isset", "(", "$", "params", "[", "'_port'", "]", ")", ")", "{", "$", "host", "=", "$", "params", "[", "'_host'", "]", ";", "// append the port & scheme if they exists.", "if", "(", "isset", "(", "$", "params", "[", "'_port'", "]", ")", ")", "{", "$", "host", ".=", "':'", ".", "$", "params", "[", "'_port'", "]", ";", "}", "$", "scheme", "=", "isset", "(", "$", "params", "[", "'_scheme'", "]", ")", "?", "$", "params", "[", "'_scheme'", "]", ":", "'http'", ";", "$", "out", "=", "\"{$scheme}://{$host}{$out}\"", ";", "}", "if", "(", "!", "empty", "(", "$", "params", "[", "'_ext'", "]", ")", "||", "!", "empty", "(", "$", "query", ")", ")", "{", "$", "out", "=", "rtrim", "(", "$", "out", ",", "'/'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "params", "[", "'_ext'", "]", ")", ")", "{", "$", "out", ".=", "'.'", ".", "$", "params", "[", "'_ext'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "query", ")", ")", "{", "$", "out", ".=", "rtrim", "(", "'?'", ".", "http_build_query", "(", "$", "query", ")", ",", "'?'", ")", ";", "}", "return", "$", "out", ";", "}" ]
Converts a matching route array into a URL string. Composes the string URL using the template used to create the route. @param array $params The params to convert to a string url @param array $pass The additional passed arguments @param array $query An array of parameters @return string Composed route string.
[ "Converts", "a", "matching", "route", "array", "into", "a", "URL", "string", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/Route.php#L795-L856
211,385
cakephp/cakephp
src/Routing/Route/Route.php
Route.staticPath
public function staticPath() { $routeKey = strpos($this->template, ':'); if ($routeKey !== false) { return substr($this->template, 0, $routeKey); } $routeKey = strpos($this->template, '{'); if ($routeKey !== false && strpos($this->template, '}') !== false) { return substr($this->template, 0, $routeKey); } $star = strpos($this->template, '*'); if ($star !== false) { $path = rtrim(substr($this->template, 0, $star), '/'); return $path === '' ? '/' : $path; } return $this->template; }
php
public function staticPath() { $routeKey = strpos($this->template, ':'); if ($routeKey !== false) { return substr($this->template, 0, $routeKey); } $routeKey = strpos($this->template, '{'); if ($routeKey !== false && strpos($this->template, '}') !== false) { return substr($this->template, 0, $routeKey); } $star = strpos($this->template, '*'); if ($star !== false) { $path = rtrim(substr($this->template, 0, $star), '/'); return $path === '' ? '/' : $path; } return $this->template; }
[ "public", "function", "staticPath", "(", ")", "{", "$", "routeKey", "=", "strpos", "(", "$", "this", "->", "template", ",", "':'", ")", ";", "if", "(", "$", "routeKey", "!==", "false", ")", "{", "return", "substr", "(", "$", "this", "->", "template", ",", "0", ",", "$", "routeKey", ")", ";", "}", "$", "routeKey", "=", "strpos", "(", "$", "this", "->", "template", ",", "'{'", ")", ";", "if", "(", "$", "routeKey", "!==", "false", "&&", "strpos", "(", "$", "this", "->", "template", ",", "'}'", ")", "!==", "false", ")", "{", "return", "substr", "(", "$", "this", "->", "template", ",", "0", ",", "$", "routeKey", ")", ";", "}", "$", "star", "=", "strpos", "(", "$", "this", "->", "template", ",", "'*'", ")", ";", "if", "(", "$", "star", "!==", "false", ")", "{", "$", "path", "=", "rtrim", "(", "substr", "(", "$", "this", "->", "template", ",", "0", ",", "$", "star", ")", ",", "'/'", ")", ";", "return", "$", "path", "===", "''", "?", "'/'", ":", "$", "path", ";", "}", "return", "$", "this", "->", "template", ";", "}" ]
Get the static path portion for this route. @return string
[ "Get", "the", "static", "path", "portion", "for", "this", "route", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/Route.php#L863-L881
211,386
cakephp/cakephp
src/Core/PluginCollection.php
PluginCollection.findPath
public function findPath($name) { $this->loadConfig(); $path = Configure::read('plugins.' . $name); if ($path) { return $path; } $pluginPath = str_replace('/', DIRECTORY_SEPARATOR, $name); $paths = App::path('Plugin'); foreach ($paths as $path) { if (is_dir($path . $pluginPath)) { return $path . $pluginPath . DIRECTORY_SEPARATOR; } } throw new MissingPluginException(['plugin' => $name]); }
php
public function findPath($name) { $this->loadConfig(); $path = Configure::read('plugins.' . $name); if ($path) { return $path; } $pluginPath = str_replace('/', DIRECTORY_SEPARATOR, $name); $paths = App::path('Plugin'); foreach ($paths as $path) { if (is_dir($path . $pluginPath)) { return $path . $pluginPath . DIRECTORY_SEPARATOR; } } throw new MissingPluginException(['plugin' => $name]); }
[ "public", "function", "findPath", "(", "$", "name", ")", "{", "$", "this", "->", "loadConfig", "(", ")", ";", "$", "path", "=", "Configure", "::", "read", "(", "'plugins.'", ".", "$", "name", ")", ";", "if", "(", "$", "path", ")", "{", "return", "$", "path", ";", "}", "$", "pluginPath", "=", "str_replace", "(", "'/'", ",", "DIRECTORY_SEPARATOR", ",", "$", "name", ")", ";", "$", "paths", "=", "App", "::", "path", "(", "'Plugin'", ")", ";", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "if", "(", "is_dir", "(", "$", "path", ".", "$", "pluginPath", ")", ")", "{", "return", "$", "path", ".", "$", "pluginPath", ".", "DIRECTORY_SEPARATOR", ";", "}", "}", "throw", "new", "MissingPluginException", "(", "[", "'plugin'", "=>", "$", "name", "]", ")", ";", "}" ]
Locate a plugin path by looking at configuration data. This will use the `plugins` Configure key, and fallback to enumerating `App::path('Plugin')` This method is not part of the official public API as plugins with no plugin class are being phased out. @param string $name The plugin name to locate a path for. Will return '' when a plugin cannot be found. @return string @throws \Cake\Core\Exception\MissingPluginException when a plugin path cannot be resolved. @internal
[ "Locate", "a", "plugin", "path", "by", "looking", "at", "configuration", "data", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/PluginCollection.php#L110-L128
211,387
cakephp/cakephp
src/Core/PluginCollection.php
PluginCollection.add
public function add(PluginInterface $plugin) { $name = $plugin->getName(); $this->plugins[$name] = $plugin; $this->names = array_keys($this->plugins); return $this; }
php
public function add(PluginInterface $plugin) { $name = $plugin->getName(); $this->plugins[$name] = $plugin; $this->names = array_keys($this->plugins); return $this; }
[ "public", "function", "add", "(", "PluginInterface", "$", "plugin", ")", "{", "$", "name", "=", "$", "plugin", "->", "getName", "(", ")", ";", "$", "this", "->", "plugins", "[", "$", "name", "]", "=", "$", "plugin", ";", "$", "this", "->", "names", "=", "array_keys", "(", "$", "this", "->", "plugins", ")", ";", "return", "$", "this", ";", "}" ]
Add a plugin to the collection Plugins will be keyed by their names. @param \Cake\Core\PluginInterface $plugin The plugin to load. @return $this
[ "Add", "a", "plugin", "to", "the", "collection" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/PluginCollection.php#L138-L145
211,388
cakephp/cakephp
src/Core/PluginCollection.php
PluginCollection.remove
public function remove($name) { unset($this->plugins[$name]); $this->names = array_keys($this->plugins); return $this; }
php
public function remove($name) { unset($this->plugins[$name]); $this->names = array_keys($this->plugins); return $this; }
[ "public", "function", "remove", "(", "$", "name", ")", "{", "unset", "(", "$", "this", "->", "plugins", "[", "$", "name", "]", ")", ";", "$", "this", "->", "names", "=", "array_keys", "(", "$", "this", "->", "plugins", ")", ";", "return", "$", "this", ";", "}" ]
Remove a plugin from the collection if it exists. @param string $name The named plugin. @return $this
[ "Remove", "a", "plugin", "from", "the", "collection", "if", "it", "exists", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/PluginCollection.php#L153-L159
211,389
cakephp/cakephp
src/Core/PluginCollection.php
PluginCollection.get
public function get($name) { if (!$this->has($name)) { throw new MissingPluginException(['plugin' => $name]); } return $this->plugins[$name]; }
php
public function get($name) { if (!$this->has($name)) { throw new MissingPluginException(['plugin' => $name]); } return $this->plugins[$name]; }
[ "public", "function", "get", "(", "$", "name", ")", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "name", ")", ")", "{", "throw", "new", "MissingPluginException", "(", "[", "'plugin'", "=>", "$", "name", "]", ")", ";", "}", "return", "$", "this", "->", "plugins", "[", "$", "name", "]", ";", "}" ]
Get the a plugin by name @param string $name The plugin to get. @return \Cake\Core\PluginInterface The plugin. @throws \Cake\Core\Exception\MissingPluginException when unknown plugins are fetched.
[ "Get", "the", "a", "plugin", "by", "name" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/PluginCollection.php#L191-L198
211,390
cakephp/cakephp
src/Core/PluginCollection.php
PluginCollection.with
public function with($hook) { if (!in_array($hook, PluginInterface::VALID_HOOKS)) { throw new InvalidArgumentException("The `{$hook}` hook is not a known plugin hook."); } foreach ($this as $plugin) { if ($plugin->isEnabled($hook)) { yield $plugin; } } }
php
public function with($hook) { if (!in_array($hook, PluginInterface::VALID_HOOKS)) { throw new InvalidArgumentException("The `{$hook}` hook is not a known plugin hook."); } foreach ($this as $plugin) { if ($plugin->isEnabled($hook)) { yield $plugin; } } }
[ "public", "function", "with", "(", "$", "hook", ")", "{", "if", "(", "!", "in_array", "(", "$", "hook", ",", "PluginInterface", "::", "VALID_HOOKS", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The `{$hook}` hook is not a known plugin hook.\"", ")", ";", "}", "foreach", "(", "$", "this", "as", "$", "plugin", ")", "{", "if", "(", "$", "plugin", "->", "isEnabled", "(", "$", "hook", ")", ")", "{", "yield", "$", "plugin", ";", "}", "}", "}" ]
Filter the plugins to those with the named hook enabled. @param string $hook The hook to filter plugins by @return \Generator A generator containing matching plugins. @throws \InvalidArgumentException on invalid hooks
[ "Filter", "the", "plugins", "to", "those", "with", "the", "named", "hook", "enabled", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/PluginCollection.php#L271-L281
211,391
cakephp/cakephp
src/View/Helper/PaginatorHelper.php
PaginatorHelper.params
public function params($model = null) { $request = $this->_View->getRequest(); if (empty($model)) { $model = $this->defaultModel(); } if (!$request->getParam('paging') || !$request->getParam('paging.' . $model)) { return []; } return $request->getParam('paging.' . $model); }
php
public function params($model = null) { $request = $this->_View->getRequest(); if (empty($model)) { $model = $this->defaultModel(); } if (!$request->getParam('paging') || !$request->getParam('paging.' . $model)) { return []; } return $request->getParam('paging.' . $model); }
[ "public", "function", "params", "(", "$", "model", "=", "null", ")", "{", "$", "request", "=", "$", "this", "->", "_View", "->", "getRequest", "(", ")", ";", "if", "(", "empty", "(", "$", "model", ")", ")", "{", "$", "model", "=", "$", "this", "->", "defaultModel", "(", ")", ";", "}", "if", "(", "!", "$", "request", "->", "getParam", "(", "'paging'", ")", "||", "!", "$", "request", "->", "getParam", "(", "'paging.'", ".", "$", "model", ")", ")", "{", "return", "[", "]", ";", "}", "return", "$", "request", "->", "getParam", "(", "'paging.'", ".", "$", "model", ")", ";", "}" ]
Gets the current paging parameters from the resultset for the given model @param string|null $model Optional model name. Uses the default if none is specified. @return array The array of paging parameters for the paginated resultset.
[ "Gets", "the", "current", "paging", "parameters", "from", "the", "resultset", "for", "the", "given", "model" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L117-L129
211,392
cakephp/cakephp
src/View/Helper/PaginatorHelper.php
PaginatorHelper.options
public function options(array $options = []) { $request = $this->_View->getRequest(); if (!empty($options['paging'])) { $request = $request->withParam( 'paging', $options['paging'] + $request->getParam('paging', []) ); unset($options['paging']); } $model = $this->defaultModel(); if (!empty($options[$model])) { $request = $request->withParam( 'paging.' . $model, $options[$model] + (array)$request->getParam('paging.' . $model, []) ); unset($options[$model]); } $this->_View->setRequest($request); $this->_config['options'] = array_filter($options + $this->_config['options']); if (empty($this->_config['options']['url'])) { $this->_config['options']['url'] = []; } if (!empty($this->_config['options']['model'])) { $this->defaultModel($this->_config['options']['model']); } }
php
public function options(array $options = []) { $request = $this->_View->getRequest(); if (!empty($options['paging'])) { $request = $request->withParam( 'paging', $options['paging'] + $request->getParam('paging', []) ); unset($options['paging']); } $model = $this->defaultModel(); if (!empty($options[$model])) { $request = $request->withParam( 'paging.' . $model, $options[$model] + (array)$request->getParam('paging.' . $model, []) ); unset($options[$model]); } $this->_View->setRequest($request); $this->_config['options'] = array_filter($options + $this->_config['options']); if (empty($this->_config['options']['url'])) { $this->_config['options']['url'] = []; } if (!empty($this->_config['options']['model'])) { $this->defaultModel($this->_config['options']['model']); } }
[ "public", "function", "options", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "request", "=", "$", "this", "->", "_View", "->", "getRequest", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'paging'", "]", ")", ")", "{", "$", "request", "=", "$", "request", "->", "withParam", "(", "'paging'", ",", "$", "options", "[", "'paging'", "]", "+", "$", "request", "->", "getParam", "(", "'paging'", ",", "[", "]", ")", ")", ";", "unset", "(", "$", "options", "[", "'paging'", "]", ")", ";", "}", "$", "model", "=", "$", "this", "->", "defaultModel", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "$", "model", "]", ")", ")", "{", "$", "request", "=", "$", "request", "->", "withParam", "(", "'paging.'", ".", "$", "model", ",", "$", "options", "[", "$", "model", "]", "+", "(", "array", ")", "$", "request", "->", "getParam", "(", "'paging.'", ".", "$", "model", ",", "[", "]", ")", ")", ";", "unset", "(", "$", "options", "[", "$", "model", "]", ")", ";", "}", "$", "this", "->", "_View", "->", "setRequest", "(", "$", "request", ")", ";", "$", "this", "->", "_config", "[", "'options'", "]", "=", "array_filter", "(", "$", "options", "+", "$", "this", "->", "_config", "[", "'options'", "]", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "_config", "[", "'options'", "]", "[", "'url'", "]", ")", ")", "{", "$", "this", "->", "_config", "[", "'options'", "]", "[", "'url'", "]", "=", "[", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_config", "[", "'options'", "]", "[", "'model'", "]", ")", ")", "{", "$", "this", "->", "defaultModel", "(", "$", "this", "->", "_config", "[", "'options'", "]", "[", "'model'", "]", ")", ";", "}", "}" ]
Sets default options for all pagination links @param array $options Default options for pagination links. See PaginatorHelper::$options for list of keys. @return void
[ "Sets", "default", "options", "for", "all", "pagination", "links" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L155-L185
211,393
cakephp/cakephp
src/View/Helper/PaginatorHelper.php
PaginatorHelper.current
public function current($model = null) { $params = $this->params($model); if (isset($params['page'])) { return $params['page']; } return 1; }
php
public function current($model = null) { $params = $this->params($model); if (isset($params['page'])) { return $params['page']; } return 1; }
[ "public", "function", "current", "(", "$", "model", "=", "null", ")", "{", "$", "params", "=", "$", "this", "->", "params", "(", "$", "model", ")", ";", "if", "(", "isset", "(", "$", "params", "[", "'page'", "]", ")", ")", "{", "return", "$", "params", "[", "'page'", "]", ";", "}", "return", "1", ";", "}" ]
Gets the current page of the recordset for the given model @param string|null $model Optional model name. Uses the default if none is specified. @return int The current page number of the recordset. @link https://book.cakephp.org/3.0/en/views/helpers/paginator.html#checking-the-pagination-state
[ "Gets", "the", "current", "page", "of", "the", "recordset", "for", "the", "given", "model" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L194-L203
211,394
cakephp/cakephp
src/View/Helper/PaginatorHelper.php
PaginatorHelper.total
public function total($model = null) { $params = $this->params($model); if (isset($params['pageCount'])) { return $params['pageCount']; } return 0; }
php
public function total($model = null) { $params = $this->params($model); if (isset($params['pageCount'])) { return $params['pageCount']; } return 0; }
[ "public", "function", "total", "(", "$", "model", "=", "null", ")", "{", "$", "params", "=", "$", "this", "->", "params", "(", "$", "model", ")", ";", "if", "(", "isset", "(", "$", "params", "[", "'pageCount'", "]", ")", ")", "{", "return", "$", "params", "[", "'pageCount'", "]", ";", "}", "return", "0", ";", "}" ]
Gets the total number of pages in the recordset for the given model. @param string|null $model Optional model name. Uses the default if none is specified. @return int The total pages for the recordset.
[ "Gets", "the", "total", "number", "of", "pages", "in", "the", "recordset", "for", "the", "given", "model", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L211-L220
211,395
cakephp/cakephp
src/View/Helper/PaginatorHelper.php
PaginatorHelper.sortKey
public function sortKey($model = null, array $options = []) { if (empty($options)) { $options = $this->params($model); } if (!empty($options['sort'])) { return $options['sort']; } return null; }
php
public function sortKey($model = null, array $options = []) { if (empty($options)) { $options = $this->params($model); } if (!empty($options['sort'])) { return $options['sort']; } return null; }
[ "public", "function", "sortKey", "(", "$", "model", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "$", "options", "=", "$", "this", "->", "params", "(", "$", "model", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'sort'", "]", ")", ")", "{", "return", "$", "options", "[", "'sort'", "]", ";", "}", "return", "null", ";", "}" ]
Gets the current key by which the recordset is sorted @param string|null $model Optional model name. Uses the default if none is specified. @param array $options Options for pagination links. See #options for list of keys. @return string|null The name of the key by which the recordset is being sorted, or null if the results are not currently sorted. @link https://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-sort-links
[ "Gets", "the", "current", "key", "by", "which", "the", "recordset", "is", "sorted" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L231-L241
211,396
cakephp/cakephp
src/View/Helper/PaginatorHelper.php
PaginatorHelper.sortDir
public function sortDir($model = null, array $options = []) { $dir = null; if (empty($options)) { $options = $this->params($model); } if (isset($options['direction'])) { $dir = strtolower($options['direction']); } if ($dir === 'desc') { return 'desc'; } return 'asc'; }
php
public function sortDir($model = null, array $options = []) { $dir = null; if (empty($options)) { $options = $this->params($model); } if (isset($options['direction'])) { $dir = strtolower($options['direction']); } if ($dir === 'desc') { return 'desc'; } return 'asc'; }
[ "public", "function", "sortDir", "(", "$", "model", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "dir", "=", "null", ";", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "$", "options", "=", "$", "this", "->", "params", "(", "$", "model", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'direction'", "]", ")", ")", "{", "$", "dir", "=", "strtolower", "(", "$", "options", "[", "'direction'", "]", ")", ";", "}", "if", "(", "$", "dir", "===", "'desc'", ")", "{", "return", "'desc'", ";", "}", "return", "'asc'", ";", "}" ]
Gets the current direction the recordset is sorted @param string|null $model Optional model name. Uses the default if none is specified. @param array $options Options for pagination links. See #options for list of keys. @return string The direction by which the recordset is being sorted, or null if the results are not currently sorted. @link https://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-sort-links
[ "Gets", "the", "current", "direction", "the", "recordset", "is", "sorted" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L252-L269
211,397
cakephp/cakephp
src/View/Helper/PaginatorHelper.php
PaginatorHelper.prev
public function prev($title = '<< Previous', array $options = []) { $defaults = [ 'url' => [], 'model' => $this->defaultModel(), 'disabledTitle' => $title, 'escape' => true, ]; $options += $defaults; $options['step'] = -1; $enabled = $this->hasPrev($options['model']); $templates = [ 'active' => 'prevActive', 'disabled' => 'prevDisabled' ]; return $this->_toggledLink($title, $enabled, $options, $templates); }
php
public function prev($title = '<< Previous', array $options = []) { $defaults = [ 'url' => [], 'model' => $this->defaultModel(), 'disabledTitle' => $title, 'escape' => true, ]; $options += $defaults; $options['step'] = -1; $enabled = $this->hasPrev($options['model']); $templates = [ 'active' => 'prevActive', 'disabled' => 'prevDisabled' ]; return $this->_toggledLink($title, $enabled, $options, $templates); }
[ "public", "function", "prev", "(", "$", "title", "=", "'<< Previous'", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'url'", "=>", "[", "]", ",", "'model'", "=>", "$", "this", "->", "defaultModel", "(", ")", ",", "'disabledTitle'", "=>", "$", "title", ",", "'escape'", "=>", "true", ",", "]", ";", "$", "options", "+=", "$", "defaults", ";", "$", "options", "[", "'step'", "]", "=", "-", "1", ";", "$", "enabled", "=", "$", "this", "->", "hasPrev", "(", "$", "options", "[", "'model'", "]", ")", ";", "$", "templates", "=", "[", "'active'", "=>", "'prevActive'", ",", "'disabled'", "=>", "'prevDisabled'", "]", ";", "return", "$", "this", "->", "_toggledLink", "(", "$", "title", ",", "$", "enabled", ",", "$", "options", ",", "$", "templates", ")", ";", "}" ]
Generates a "previous" link for a set of paged records ### Options: - `disabledTitle` The text to used when the link is disabled. This defaults to the same text at the active link. Setting to false will cause this method to return ''. - `escape` Whether you want the contents html entity encoded, defaults to true - `model` The model to use, defaults to PaginatorHelper::defaultModel() - `url` An array of additional URL options to use for link generation. - `templates` An array of templates, or template file name containing the templates you'd like to use when generating the link for previous page. The helper's original templates will be restored once prev() is done. @param string $title Title for the link. Defaults to '<< Previous'. @param array $options Options for pagination link. See above for list of keys. @return string A "previous" link or a disabled link. @link https://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-jump-links
[ "Generates", "a", "previous", "link", "for", "a", "set", "of", "paged", "records" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L352-L370
211,398
cakephp/cakephp
src/View/Helper/PaginatorHelper.php
PaginatorHelper.sort
public function sort($key, $title = null, array $options = []) { $options += ['url' => [], 'model' => null, 'escape' => true]; $url = $options['url']; unset($options['url']); if (empty($title)) { $title = $key; if (strpos($title, '.') !== false) { $title = str_replace('.', ' ', $title); } $title = __(Inflector::humanize(preg_replace('/_id$/', '', $title))); } $defaultDir = isset($options['direction']) ? strtolower($options['direction']) : 'asc'; unset($options['direction']); $locked = isset($options['lock']) ? $options['lock'] : false; unset($options['lock']); $sortKey = $this->sortKey($options['model']); $defaultModel = $this->defaultModel(); $model = $options['model'] ?: $defaultModel; list($table, $field) = explode('.', $key . '.'); if (!$field) { $field = $table; $table = $model; } $isSorted = ( $sortKey === $table . '.' . $field || $sortKey === $model . '.' . $key || $table . '.' . $field === $model . '.' . $sortKey ); $template = 'sort'; $dir = $defaultDir; if ($isSorted) { if ($locked) { $template = $dir === 'asc' ? 'sortDescLocked' : 'sortAscLocked'; } else { $dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc'; $template = $dir === 'asc' ? 'sortDesc' : 'sortAsc'; } } if (is_array($title) && array_key_exists($dir, $title)) { $title = $title[$dir]; } $url = array_merge( ['sort' => $key, 'direction' => $dir, 'page' => 1], $url, ['order' => null] ); $vars = [ 'text' => $options['escape'] ? h($title) : $title, 'url' => $this->generateUrl($url, $options['model']), ]; return $this->templater()->format($template, $vars); }
php
public function sort($key, $title = null, array $options = []) { $options += ['url' => [], 'model' => null, 'escape' => true]; $url = $options['url']; unset($options['url']); if (empty($title)) { $title = $key; if (strpos($title, '.') !== false) { $title = str_replace('.', ' ', $title); } $title = __(Inflector::humanize(preg_replace('/_id$/', '', $title))); } $defaultDir = isset($options['direction']) ? strtolower($options['direction']) : 'asc'; unset($options['direction']); $locked = isset($options['lock']) ? $options['lock'] : false; unset($options['lock']); $sortKey = $this->sortKey($options['model']); $defaultModel = $this->defaultModel(); $model = $options['model'] ?: $defaultModel; list($table, $field) = explode('.', $key . '.'); if (!$field) { $field = $table; $table = $model; } $isSorted = ( $sortKey === $table . '.' . $field || $sortKey === $model . '.' . $key || $table . '.' . $field === $model . '.' . $sortKey ); $template = 'sort'; $dir = $defaultDir; if ($isSorted) { if ($locked) { $template = $dir === 'asc' ? 'sortDescLocked' : 'sortAscLocked'; } else { $dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc'; $template = $dir === 'asc' ? 'sortDesc' : 'sortAsc'; } } if (is_array($title) && array_key_exists($dir, $title)) { $title = $title[$dir]; } $url = array_merge( ['sort' => $key, 'direction' => $dir, 'page' => 1], $url, ['order' => null] ); $vars = [ 'text' => $options['escape'] ? h($title) : $title, 'url' => $this->generateUrl($url, $options['model']), ]; return $this->templater()->format($template, $vars); }
[ "public", "function", "sort", "(", "$", "key", ",", "$", "title", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "+=", "[", "'url'", "=>", "[", "]", ",", "'model'", "=>", "null", ",", "'escape'", "=>", "true", "]", ";", "$", "url", "=", "$", "options", "[", "'url'", "]", ";", "unset", "(", "$", "options", "[", "'url'", "]", ")", ";", "if", "(", "empty", "(", "$", "title", ")", ")", "{", "$", "title", "=", "$", "key", ";", "if", "(", "strpos", "(", "$", "title", ",", "'.'", ")", "!==", "false", ")", "{", "$", "title", "=", "str_replace", "(", "'.'", ",", "' '", ",", "$", "title", ")", ";", "}", "$", "title", "=", "__", "(", "Inflector", "::", "humanize", "(", "preg_replace", "(", "'/_id$/'", ",", "''", ",", "$", "title", ")", ")", ")", ";", "}", "$", "defaultDir", "=", "isset", "(", "$", "options", "[", "'direction'", "]", ")", "?", "strtolower", "(", "$", "options", "[", "'direction'", "]", ")", ":", "'asc'", ";", "unset", "(", "$", "options", "[", "'direction'", "]", ")", ";", "$", "locked", "=", "isset", "(", "$", "options", "[", "'lock'", "]", ")", "?", "$", "options", "[", "'lock'", "]", ":", "false", ";", "unset", "(", "$", "options", "[", "'lock'", "]", ")", ";", "$", "sortKey", "=", "$", "this", "->", "sortKey", "(", "$", "options", "[", "'model'", "]", ")", ";", "$", "defaultModel", "=", "$", "this", "->", "defaultModel", "(", ")", ";", "$", "model", "=", "$", "options", "[", "'model'", "]", "?", ":", "$", "defaultModel", ";", "list", "(", "$", "table", ",", "$", "field", ")", "=", "explode", "(", "'.'", ",", "$", "key", ".", "'.'", ")", ";", "if", "(", "!", "$", "field", ")", "{", "$", "field", "=", "$", "table", ";", "$", "table", "=", "$", "model", ";", "}", "$", "isSorted", "=", "(", "$", "sortKey", "===", "$", "table", ".", "'.'", ".", "$", "field", "||", "$", "sortKey", "===", "$", "model", ".", "'.'", ".", "$", "key", "||", "$", "table", ".", "'.'", ".", "$", "field", "===", "$", "model", ".", "'.'", ".", "$", "sortKey", ")", ";", "$", "template", "=", "'sort'", ";", "$", "dir", "=", "$", "defaultDir", ";", "if", "(", "$", "isSorted", ")", "{", "if", "(", "$", "locked", ")", "{", "$", "template", "=", "$", "dir", "===", "'asc'", "?", "'sortDescLocked'", ":", "'sortAscLocked'", ";", "}", "else", "{", "$", "dir", "=", "$", "this", "->", "sortDir", "(", "$", "options", "[", "'model'", "]", ")", "===", "'asc'", "?", "'desc'", ":", "'asc'", ";", "$", "template", "=", "$", "dir", "===", "'asc'", "?", "'sortDesc'", ":", "'sortAsc'", ";", "}", "}", "if", "(", "is_array", "(", "$", "title", ")", "&&", "array_key_exists", "(", "$", "dir", ",", "$", "title", ")", ")", "{", "$", "title", "=", "$", "title", "[", "$", "dir", "]", ";", "}", "$", "url", "=", "array_merge", "(", "[", "'sort'", "=>", "$", "key", ",", "'direction'", "=>", "$", "dir", ",", "'page'", "=>", "1", "]", ",", "$", "url", ",", "[", "'order'", "=>", "null", "]", ")", ";", "$", "vars", "=", "[", "'text'", "=>", "$", "options", "[", "'escape'", "]", "?", "h", "(", "$", "title", ")", ":", "$", "title", ",", "'url'", "=>", "$", "this", "->", "generateUrl", "(", "$", "url", ",", "$", "options", "[", "'model'", "]", ")", ",", "]", ";", "return", "$", "this", "->", "templater", "(", ")", "->", "format", "(", "$", "template", ",", "$", "vars", ")", ";", "}" ]
Generates a sorting link. Sets named parameters for the sort and direction. Handles direction switching automatically. ### Options: - `escape` Whether you want the contents html entity encoded, defaults to true. - `model` The model to use, defaults to PaginatorHelper::defaultModel(). - `direction` The default direction to use when this link isn't active. - `lock` Lock direction. Will only use the default direction then, defaults to false. @param string $key The name of the key that the recordset should be sorted. @param string|null $title Title for the link. If $title is null $key will be used for the title and will be generated by inflection. @param array $options Options for sorting link. See above for list of keys. @return string A link sorting default by 'asc'. If the resultset is sorted 'asc' by the specified key the returned link will sort by 'desc'. @link https://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-sort-links
[ "Generates", "a", "sorting", "link", ".", "Sets", "named", "parameters", "for", "the", "sort", "and", "direction", ".", "Handles", "direction", "switching", "automatically", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L431-L492
211,399
cakephp/cakephp
src/View/Helper/PaginatorHelper.php
PaginatorHelper.defaultModel
public function defaultModel($model = null) { if ($model !== null) { $this->_defaultModel = $model; } if ($this->_defaultModel) { return $this->_defaultModel; } if (!$this->_View->getRequest()->getParam('paging')) { return null; } list($this->_defaultModel) = array_keys($this->_View->getRequest()->getParam('paging')); return $this->_defaultModel; }
php
public function defaultModel($model = null) { if ($model !== null) { $this->_defaultModel = $model; } if ($this->_defaultModel) { return $this->_defaultModel; } if (!$this->_View->getRequest()->getParam('paging')) { return null; } list($this->_defaultModel) = array_keys($this->_View->getRequest()->getParam('paging')); return $this->_defaultModel; }
[ "public", "function", "defaultModel", "(", "$", "model", "=", "null", ")", "{", "if", "(", "$", "model", "!==", "null", ")", "{", "$", "this", "->", "_defaultModel", "=", "$", "model", ";", "}", "if", "(", "$", "this", "->", "_defaultModel", ")", "{", "return", "$", "this", "->", "_defaultModel", ";", "}", "if", "(", "!", "$", "this", "->", "_View", "->", "getRequest", "(", ")", "->", "getParam", "(", "'paging'", ")", ")", "{", "return", "null", ";", "}", "list", "(", "$", "this", "->", "_defaultModel", ")", "=", "array_keys", "(", "$", "this", "->", "_View", "->", "getRequest", "(", ")", "->", "getParam", "(", "'paging'", ")", ")", ";", "return", "$", "this", "->", "_defaultModel", ";", "}" ]
Gets or sets the default model of the paged sets @param string|null $model Model name to set @return string|null Model name or null if the pagination isn't initialized.
[ "Gets", "or", "sets", "the", "default", "model", "of", "the", "paged", "sets" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L688-L702