id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
210,400
cakephp/cakephp
src/Controller/Component/AuthComponent.php
AuthComponent.getAuthenticate
public function getAuthenticate($alias) { if (empty($this->_authenticateObjects)) { $this->constructAuthenticate(); } return isset($this->_authenticateObjects[$alias]) ? $this->_authenticateObjects[$alias] : null; }
php
public function getAuthenticate($alias) { if (empty($this->_authenticateObjects)) { $this->constructAuthenticate(); } return isset($this->_authenticateObjects[$alias]) ? $this->_authenticateObjects[$alias] : null; }
[ "public", "function", "getAuthenticate", "(", "$", "alias", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_authenticateObjects", ")", ")", "{", "$", "this", "->", "constructAuthenticate", "(", ")", ";", "}", "return", "isset", "(", "$", "this", "->", "_authenticateObjects", "[", "$", "alias", "]", ")", "?", "$", "this", "->", "_authenticateObjects", "[", "$", "alias", "]", ":", "null", ";", "}" ]
Getter for authenticate objects. Will return a particular authenticate object. @param string $alias Alias for the authenticate object @return \Cake\Auth\BaseAuthenticate|null
[ "Getter", "for", "authenticate", "objects", ".", "Will", "return", "a", "particular", "authenticate", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/AuthComponent.php#L966-L973
210,401
cakephp/cakephp
src/Controller/Component/AuthComponent.php
AuthComponent.flash
public function flash($message) { if ($message === false) { return; } $this->Flash->set($message, $this->_config['flash']); }
php
public function flash($message) { if ($message === false) { return; } $this->Flash->set($message, $this->_config['flash']); }
[ "public", "function", "flash", "(", "$", "message", ")", "{", "if", "(", "$", "message", "===", "false", ")", "{", "return", ";", "}", "$", "this", "->", "Flash", "->", "set", "(", "$", "message", ",", "$", "this", "->", "_config", "[", "'flash'", "]", ")", ";", "}" ]
Set a flash message. Uses the Flash component with values from `flash` config. @param string $message The message to set. @return void
[ "Set", "a", "flash", "message", ".", "Uses", "the", "Flash", "component", "with", "values", "from", "flash", "config", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/AuthComponent.php#L981-L988
210,402
cakephp/cakephp
src/Http/Client/Auth/Oauth.php
Oauth.authentication
public function authentication(Request $request, array $credentials) { if (!isset($credentials['consumerKey'])) { return $request; } if (empty($credentials['method'])) { $credentials['method'] = 'hmac-sha1'; } $credentials['method'] = strtoupper($credentials['method']); $value = null; switch ($credentials['method']) { case 'HMAC-SHA1': $hasKeys = isset( $credentials['consumerSecret'], $credentials['token'], $credentials['tokenSecret'] ); if (!$hasKeys) { return $request; } $value = $this->_hmacSha1($request, $credentials); break; case 'RSA-SHA1': if (!isset($credentials['privateKey'])) { return $request; } $value = $this->_rsaSha1($request, $credentials); break; case 'PLAINTEXT': $hasKeys = isset( $credentials['consumerSecret'], $credentials['token'], $credentials['tokenSecret'] ); if (!$hasKeys) { return $request; } $value = $this->_plaintext($request, $credentials); break; default: throw new Exception(sprintf('Unknown Oauth signature method %s', $credentials['method'])); } return $request->withHeader('Authorization', $value); }
php
public function authentication(Request $request, array $credentials) { if (!isset($credentials['consumerKey'])) { return $request; } if (empty($credentials['method'])) { $credentials['method'] = 'hmac-sha1'; } $credentials['method'] = strtoupper($credentials['method']); $value = null; switch ($credentials['method']) { case 'HMAC-SHA1': $hasKeys = isset( $credentials['consumerSecret'], $credentials['token'], $credentials['tokenSecret'] ); if (!$hasKeys) { return $request; } $value = $this->_hmacSha1($request, $credentials); break; case 'RSA-SHA1': if (!isset($credentials['privateKey'])) { return $request; } $value = $this->_rsaSha1($request, $credentials); break; case 'PLAINTEXT': $hasKeys = isset( $credentials['consumerSecret'], $credentials['token'], $credentials['tokenSecret'] ); if (!$hasKeys) { return $request; } $value = $this->_plaintext($request, $credentials); break; default: throw new Exception(sprintf('Unknown Oauth signature method %s', $credentials['method'])); } return $request->withHeader('Authorization', $value); }
[ "public", "function", "authentication", "(", "Request", "$", "request", ",", "array", "$", "credentials", ")", "{", "if", "(", "!", "isset", "(", "$", "credentials", "[", "'consumerKey'", "]", ")", ")", "{", "return", "$", "request", ";", "}", "if", "(", "empty", "(", "$", "credentials", "[", "'method'", "]", ")", ")", "{", "$", "credentials", "[", "'method'", "]", "=", "'hmac-sha1'", ";", "}", "$", "credentials", "[", "'method'", "]", "=", "strtoupper", "(", "$", "credentials", "[", "'method'", "]", ")", ";", "$", "value", "=", "null", ";", "switch", "(", "$", "credentials", "[", "'method'", "]", ")", "{", "case", "'HMAC-SHA1'", ":", "$", "hasKeys", "=", "isset", "(", "$", "credentials", "[", "'consumerSecret'", "]", ",", "$", "credentials", "[", "'token'", "]", ",", "$", "credentials", "[", "'tokenSecret'", "]", ")", ";", "if", "(", "!", "$", "hasKeys", ")", "{", "return", "$", "request", ";", "}", "$", "value", "=", "$", "this", "->", "_hmacSha1", "(", "$", "request", ",", "$", "credentials", ")", ";", "break", ";", "case", "'RSA-SHA1'", ":", "if", "(", "!", "isset", "(", "$", "credentials", "[", "'privateKey'", "]", ")", ")", "{", "return", "$", "request", ";", "}", "$", "value", "=", "$", "this", "->", "_rsaSha1", "(", "$", "request", ",", "$", "credentials", ")", ";", "break", ";", "case", "'PLAINTEXT'", ":", "$", "hasKeys", "=", "isset", "(", "$", "credentials", "[", "'consumerSecret'", "]", ",", "$", "credentials", "[", "'token'", "]", ",", "$", "credentials", "[", "'tokenSecret'", "]", ")", ";", "if", "(", "!", "$", "hasKeys", ")", "{", "return", "$", "request", ";", "}", "$", "value", "=", "$", "this", "->", "_plaintext", "(", "$", "request", ",", "$", "credentials", ")", ";", "break", ";", "default", ":", "throw", "new", "Exception", "(", "sprintf", "(", "'Unknown Oauth signature method %s'", ",", "$", "credentials", "[", "'method'", "]", ")", ")", ";", "}", "return", "$", "request", "->", "withHeader", "(", "'Authorization'", ",", "$", "value", ")", ";", "}" ]
Add headers for Oauth authorization. @param \Cake\Http\Client\Request $request The request object. @param array $credentials Authentication credentials. @return \Cake\Http\Client\Request The updated request. @throws \Cake\Core\Exception\Exception On invalid signature types.
[ "Add", "headers", "for", "Oauth", "authorization", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Oauth.php#L42-L90
210,403
cakephp/cakephp
src/Http/Client/Auth/Oauth.php
Oauth._hmacSha1
protected function _hmacSha1($request, $credentials) { $nonce = isset($credentials['nonce']) ? $credentials['nonce'] : uniqid(); $timestamp = isset($credentials['timestamp']) ? $credentials['timestamp'] : time(); $values = [ 'oauth_version' => '1.0', 'oauth_nonce' => $nonce, 'oauth_timestamp' => $timestamp, 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $credentials['token'], 'oauth_consumer_key' => $credentials['consumerKey'], ]; $baseString = $this->baseString($request, $values); if (isset($credentials['realm'])) { $values['oauth_realm'] = $credentials['realm']; } $key = [$credentials['consumerSecret'], $credentials['tokenSecret']]; $key = array_map([$this, '_encode'], $key); $key = implode('&', $key); $values['oauth_signature'] = base64_encode( hash_hmac('sha1', $baseString, $key, true) ); return $this->_buildAuth($values); }
php
protected function _hmacSha1($request, $credentials) { $nonce = isset($credentials['nonce']) ? $credentials['nonce'] : uniqid(); $timestamp = isset($credentials['timestamp']) ? $credentials['timestamp'] : time(); $values = [ 'oauth_version' => '1.0', 'oauth_nonce' => $nonce, 'oauth_timestamp' => $timestamp, 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $credentials['token'], 'oauth_consumer_key' => $credentials['consumerKey'], ]; $baseString = $this->baseString($request, $values); if (isset($credentials['realm'])) { $values['oauth_realm'] = $credentials['realm']; } $key = [$credentials['consumerSecret'], $credentials['tokenSecret']]; $key = array_map([$this, '_encode'], $key); $key = implode('&', $key); $values['oauth_signature'] = base64_encode( hash_hmac('sha1', $baseString, $key, true) ); return $this->_buildAuth($values); }
[ "protected", "function", "_hmacSha1", "(", "$", "request", ",", "$", "credentials", ")", "{", "$", "nonce", "=", "isset", "(", "$", "credentials", "[", "'nonce'", "]", ")", "?", "$", "credentials", "[", "'nonce'", "]", ":", "uniqid", "(", ")", ";", "$", "timestamp", "=", "isset", "(", "$", "credentials", "[", "'timestamp'", "]", ")", "?", "$", "credentials", "[", "'timestamp'", "]", ":", "time", "(", ")", ";", "$", "values", "=", "[", "'oauth_version'", "=>", "'1.0'", ",", "'oauth_nonce'", "=>", "$", "nonce", ",", "'oauth_timestamp'", "=>", "$", "timestamp", ",", "'oauth_signature_method'", "=>", "'HMAC-SHA1'", ",", "'oauth_token'", "=>", "$", "credentials", "[", "'token'", "]", ",", "'oauth_consumer_key'", "=>", "$", "credentials", "[", "'consumerKey'", "]", ",", "]", ";", "$", "baseString", "=", "$", "this", "->", "baseString", "(", "$", "request", ",", "$", "values", ")", ";", "if", "(", "isset", "(", "$", "credentials", "[", "'realm'", "]", ")", ")", "{", "$", "values", "[", "'oauth_realm'", "]", "=", "$", "credentials", "[", "'realm'", "]", ";", "}", "$", "key", "=", "[", "$", "credentials", "[", "'consumerSecret'", "]", ",", "$", "credentials", "[", "'tokenSecret'", "]", "]", ";", "$", "key", "=", "array_map", "(", "[", "$", "this", ",", "'_encode'", "]", ",", "$", "key", ")", ";", "$", "key", "=", "implode", "(", "'&'", ",", "$", "key", ")", ";", "$", "values", "[", "'oauth_signature'", "]", "=", "base64_encode", "(", "hash_hmac", "(", "'sha1'", ",", "$", "baseString", ",", "$", "key", ",", "true", ")", ")", ";", "return", "$", "this", "->", "_buildAuth", "(", "$", "values", ")", ";", "}" ]
Use HMAC-SHA1 signing. This method is suitable for plain HTTP or HTTPS. @param \Cake\Http\Client\Request $request The request object. @param array $credentials Authentication credentials. @return string
[ "Use", "HMAC", "-", "SHA1", "signing", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Oauth.php#L132-L158
210,404
cakephp/cakephp
src/Http/Client/Auth/Oauth.php
Oauth._rsaSha1
protected function _rsaSha1($request, $credentials) { if (!function_exists('openssl_pkey_get_private')) { throw new RuntimeException('RSA-SHA1 signature method requires the OpenSSL extension.'); } $nonce = isset($credentials['nonce']) ? $credentials['nonce'] : bin2hex(Security::randomBytes(16)); $timestamp = isset($credentials['timestamp']) ? $credentials['timestamp'] : time(); $values = [ 'oauth_version' => '1.0', 'oauth_nonce' => $nonce, 'oauth_timestamp' => $timestamp, 'oauth_signature_method' => 'RSA-SHA1', 'oauth_consumer_key' => $credentials['consumerKey'], ]; if (isset($credentials['consumerSecret'])) { $values['oauth_consumer_secret'] = $credentials['consumerSecret']; } if (isset($credentials['token'])) { $values['oauth_token'] = $credentials['token']; } if (isset($credentials['tokenSecret'])) { $values['oauth_token_secret'] = $credentials['tokenSecret']; } $baseString = $this->baseString($request, $values); if (isset($credentials['realm'])) { $values['oauth_realm'] = $credentials['realm']; } if (is_resource($credentials['privateKey'])) { $resource = $credentials['privateKey']; $privateKey = stream_get_contents($resource); rewind($resource); $credentials['privateKey'] = $privateKey; } $credentials += [ 'privateKeyPassphrase' => null, ]; if (is_resource($credentials['privateKeyPassphrase'])) { $resource = $credentials['privateKeyPassphrase']; $passphrase = stream_get_line($resource, 0, PHP_EOL); rewind($resource); $credentials['privateKeyPassphrase'] = $passphrase; } $privateKey = openssl_pkey_get_private($credentials['privateKey'], $credentials['privateKeyPassphrase']); $signature = ''; openssl_sign($baseString, $signature, $privateKey); openssl_free_key($privateKey); $values['oauth_signature'] = base64_encode($signature); return $this->_buildAuth($values); }
php
protected function _rsaSha1($request, $credentials) { if (!function_exists('openssl_pkey_get_private')) { throw new RuntimeException('RSA-SHA1 signature method requires the OpenSSL extension.'); } $nonce = isset($credentials['nonce']) ? $credentials['nonce'] : bin2hex(Security::randomBytes(16)); $timestamp = isset($credentials['timestamp']) ? $credentials['timestamp'] : time(); $values = [ 'oauth_version' => '1.0', 'oauth_nonce' => $nonce, 'oauth_timestamp' => $timestamp, 'oauth_signature_method' => 'RSA-SHA1', 'oauth_consumer_key' => $credentials['consumerKey'], ]; if (isset($credentials['consumerSecret'])) { $values['oauth_consumer_secret'] = $credentials['consumerSecret']; } if (isset($credentials['token'])) { $values['oauth_token'] = $credentials['token']; } if (isset($credentials['tokenSecret'])) { $values['oauth_token_secret'] = $credentials['tokenSecret']; } $baseString = $this->baseString($request, $values); if (isset($credentials['realm'])) { $values['oauth_realm'] = $credentials['realm']; } if (is_resource($credentials['privateKey'])) { $resource = $credentials['privateKey']; $privateKey = stream_get_contents($resource); rewind($resource); $credentials['privateKey'] = $privateKey; } $credentials += [ 'privateKeyPassphrase' => null, ]; if (is_resource($credentials['privateKeyPassphrase'])) { $resource = $credentials['privateKeyPassphrase']; $passphrase = stream_get_line($resource, 0, PHP_EOL); rewind($resource); $credentials['privateKeyPassphrase'] = $passphrase; } $privateKey = openssl_pkey_get_private($credentials['privateKey'], $credentials['privateKeyPassphrase']); $signature = ''; openssl_sign($baseString, $signature, $privateKey); openssl_free_key($privateKey); $values['oauth_signature'] = base64_encode($signature); return $this->_buildAuth($values); }
[ "protected", "function", "_rsaSha1", "(", "$", "request", ",", "$", "credentials", ")", "{", "if", "(", "!", "function_exists", "(", "'openssl_pkey_get_private'", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'RSA-SHA1 signature method requires the OpenSSL extension.'", ")", ";", "}", "$", "nonce", "=", "isset", "(", "$", "credentials", "[", "'nonce'", "]", ")", "?", "$", "credentials", "[", "'nonce'", "]", ":", "bin2hex", "(", "Security", "::", "randomBytes", "(", "16", ")", ")", ";", "$", "timestamp", "=", "isset", "(", "$", "credentials", "[", "'timestamp'", "]", ")", "?", "$", "credentials", "[", "'timestamp'", "]", ":", "time", "(", ")", ";", "$", "values", "=", "[", "'oauth_version'", "=>", "'1.0'", ",", "'oauth_nonce'", "=>", "$", "nonce", ",", "'oauth_timestamp'", "=>", "$", "timestamp", ",", "'oauth_signature_method'", "=>", "'RSA-SHA1'", ",", "'oauth_consumer_key'", "=>", "$", "credentials", "[", "'consumerKey'", "]", ",", "]", ";", "if", "(", "isset", "(", "$", "credentials", "[", "'consumerSecret'", "]", ")", ")", "{", "$", "values", "[", "'oauth_consumer_secret'", "]", "=", "$", "credentials", "[", "'consumerSecret'", "]", ";", "}", "if", "(", "isset", "(", "$", "credentials", "[", "'token'", "]", ")", ")", "{", "$", "values", "[", "'oauth_token'", "]", "=", "$", "credentials", "[", "'token'", "]", ";", "}", "if", "(", "isset", "(", "$", "credentials", "[", "'tokenSecret'", "]", ")", ")", "{", "$", "values", "[", "'oauth_token_secret'", "]", "=", "$", "credentials", "[", "'tokenSecret'", "]", ";", "}", "$", "baseString", "=", "$", "this", "->", "baseString", "(", "$", "request", ",", "$", "values", ")", ";", "if", "(", "isset", "(", "$", "credentials", "[", "'realm'", "]", ")", ")", "{", "$", "values", "[", "'oauth_realm'", "]", "=", "$", "credentials", "[", "'realm'", "]", ";", "}", "if", "(", "is_resource", "(", "$", "credentials", "[", "'privateKey'", "]", ")", ")", "{", "$", "resource", "=", "$", "credentials", "[", "'privateKey'", "]", ";", "$", "privateKey", "=", "stream_get_contents", "(", "$", "resource", ")", ";", "rewind", "(", "$", "resource", ")", ";", "$", "credentials", "[", "'privateKey'", "]", "=", "$", "privateKey", ";", "}", "$", "credentials", "+=", "[", "'privateKeyPassphrase'", "=>", "null", ",", "]", ";", "if", "(", "is_resource", "(", "$", "credentials", "[", "'privateKeyPassphrase'", "]", ")", ")", "{", "$", "resource", "=", "$", "credentials", "[", "'privateKeyPassphrase'", "]", ";", "$", "passphrase", "=", "stream_get_line", "(", "$", "resource", ",", "0", ",", "PHP_EOL", ")", ";", "rewind", "(", "$", "resource", ")", ";", "$", "credentials", "[", "'privateKeyPassphrase'", "]", "=", "$", "passphrase", ";", "}", "$", "privateKey", "=", "openssl_pkey_get_private", "(", "$", "credentials", "[", "'privateKey'", "]", ",", "$", "credentials", "[", "'privateKeyPassphrase'", "]", ")", ";", "$", "signature", "=", "''", ";", "openssl_sign", "(", "$", "baseString", ",", "$", "signature", ",", "$", "privateKey", ")", ";", "openssl_free_key", "(", "$", "privateKey", ")", ";", "$", "values", "[", "'oauth_signature'", "]", "=", "base64_encode", "(", "$", "signature", ")", ";", "return", "$", "this", "->", "_buildAuth", "(", "$", "values", ")", ";", "}" ]
Use RSA-SHA1 signing. This method is suitable for plain HTTP or HTTPS. @param \Cake\Http\Client\Request $request The request object. @param array $credentials Authentication credentials. @return string @throws \RuntimeException
[ "Use", "RSA", "-", "SHA1", "signing", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Oauth.php#L171-L225
210,405
cakephp/cakephp
src/Http/Client/Auth/Oauth.php
Oauth.baseString
public function baseString($request, $oauthValues) { $parts = [ $request->getMethod(), $this->_normalizedUrl($request->getUri()), $this->_normalizedParams($request, $oauthValues), ]; $parts = array_map([$this, '_encode'], $parts); return implode('&', $parts); }
php
public function baseString($request, $oauthValues) { $parts = [ $request->getMethod(), $this->_normalizedUrl($request->getUri()), $this->_normalizedParams($request, $oauthValues), ]; $parts = array_map([$this, '_encode'], $parts); return implode('&', $parts); }
[ "public", "function", "baseString", "(", "$", "request", ",", "$", "oauthValues", ")", "{", "$", "parts", "=", "[", "$", "request", "->", "getMethod", "(", ")", ",", "$", "this", "->", "_normalizedUrl", "(", "$", "request", "->", "getUri", "(", ")", ")", ",", "$", "this", "->", "_normalizedParams", "(", "$", "request", ",", "$", "oauthValues", ")", ",", "]", ";", "$", "parts", "=", "array_map", "(", "[", "$", "this", ",", "'_encode'", "]", ",", "$", "parts", ")", ";", "return", "implode", "(", "'&'", ",", "$", "parts", ")", ";", "}" ]
Generate the Oauth basestring - Querystring, request data and oauth_* parameters are combined. - Values are sorted by name and then value. - Request values are concatenated and urlencoded. - The request URL (without querystring) is normalized. - The HTTP method, URL and request parameters are concatenated and returned. @param \Cake\Http\Client\Request $request The request object. @param array $oauthValues Oauth values. @return string
[ "Generate", "the", "Oauth", "basestring" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Oauth.php#L240-L250
210,406
cakephp/cakephp
src/Http/Client/Auth/Oauth.php
Oauth._normalizedUrl
protected function _normalizedUrl($uri) { $out = $uri->getScheme() . '://'; $out .= strtolower($uri->getHost()); $out .= $uri->getPath(); return $out; }
php
protected function _normalizedUrl($uri) { $out = $uri->getScheme() . '://'; $out .= strtolower($uri->getHost()); $out .= $uri->getPath(); return $out; }
[ "protected", "function", "_normalizedUrl", "(", "$", "uri", ")", "{", "$", "out", "=", "$", "uri", "->", "getScheme", "(", ")", ".", "'://'", ";", "$", "out", ".=", "strtolower", "(", "$", "uri", "->", "getHost", "(", ")", ")", ";", "$", "out", ".=", "$", "uri", "->", "getPath", "(", ")", ";", "return", "$", "out", ";", "}" ]
Builds a normalized URL Section 9.1.2. of the Oauth spec @param \Psr\Http\Message\UriInterface $uri Uri object to build a normalized version of. @return string Normalized URL
[ "Builds", "a", "normalized", "URL" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Oauth.php#L260-L267
210,407
cakephp/cakephp
src/Http/Client/Auth/Oauth.php
Oauth._normalizedParams
protected function _normalizedParams($request, $oauthValues) { $query = parse_url($request->getUri(), PHP_URL_QUERY); parse_str($query, $queryArgs); $post = []; $body = $request->body(); if (is_string($body) && $request->getHeaderLine('content-type') === 'application/x-www-form-urlencoded') { parse_str($body, $post); } if (is_array($body)) { $post = $body; } $args = array_merge($queryArgs, $oauthValues, $post); $pairs = $this->_normalizeData($args); $data = []; foreach ($pairs as $pair) { $data[] = implode('=', $pair); } sort($data, SORT_STRING); return implode('&', $data); }
php
protected function _normalizedParams($request, $oauthValues) { $query = parse_url($request->getUri(), PHP_URL_QUERY); parse_str($query, $queryArgs); $post = []; $body = $request->body(); if (is_string($body) && $request->getHeaderLine('content-type') === 'application/x-www-form-urlencoded') { parse_str($body, $post); } if (is_array($body)) { $post = $body; } $args = array_merge($queryArgs, $oauthValues, $post); $pairs = $this->_normalizeData($args); $data = []; foreach ($pairs as $pair) { $data[] = implode('=', $pair); } sort($data, SORT_STRING); return implode('&', $data); }
[ "protected", "function", "_normalizedParams", "(", "$", "request", ",", "$", "oauthValues", ")", "{", "$", "query", "=", "parse_url", "(", "$", "request", "->", "getUri", "(", ")", ",", "PHP_URL_QUERY", ")", ";", "parse_str", "(", "$", "query", ",", "$", "queryArgs", ")", ";", "$", "post", "=", "[", "]", ";", "$", "body", "=", "$", "request", "->", "body", "(", ")", ";", "if", "(", "is_string", "(", "$", "body", ")", "&&", "$", "request", "->", "getHeaderLine", "(", "'content-type'", ")", "===", "'application/x-www-form-urlencoded'", ")", "{", "parse_str", "(", "$", "body", ",", "$", "post", ")", ";", "}", "if", "(", "is_array", "(", "$", "body", ")", ")", "{", "$", "post", "=", "$", "body", ";", "}", "$", "args", "=", "array_merge", "(", "$", "queryArgs", ",", "$", "oauthValues", ",", "$", "post", ")", ";", "$", "pairs", "=", "$", "this", "->", "_normalizeData", "(", "$", "args", ")", ";", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "pairs", "as", "$", "pair", ")", "{", "$", "data", "[", "]", "=", "implode", "(", "'='", ",", "$", "pair", ")", ";", "}", "sort", "(", "$", "data", ",", "SORT_STRING", ")", ";", "return", "implode", "(", "'&'", ",", "$", "data", ")", ";", "}" ]
Sorts and normalizes request data and oauthValues Section 9.1.1 of Oauth spec. - URL encode keys + values. - Sort keys & values by byte value. @param \Cake\Http\Client\Request $request The request object. @param array $oauthValues Oauth values. @return string sorted and normalized values
[ "Sorts", "and", "normalizes", "request", "data", "and", "oauthValues" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Oauth.php#L281-L304
210,408
cakephp/cakephp
src/Http/Client/Auth/Oauth.php
Oauth._normalizeData
protected function _normalizeData($args, $path = '') { $data = []; foreach ($args as $key => $value) { if ($path) { // Fold string keys with []. // Numeric keys result in a=b&a=c. While this isn't // standard behavior in PHP, it is common in other platforms. if (!is_numeric($key)) { $key = "{$path}[{$key}]"; } else { $key = $path; } } if (is_array($value)) { uksort($value, 'strcmp'); $data = array_merge($data, $this->_normalizeData($value, $key)); } else { $data[] = [$key, $value]; } } return $data; }
php
protected function _normalizeData($args, $path = '') { $data = []; foreach ($args as $key => $value) { if ($path) { // Fold string keys with []. // Numeric keys result in a=b&a=c. While this isn't // standard behavior in PHP, it is common in other platforms. if (!is_numeric($key)) { $key = "{$path}[{$key}]"; } else { $key = $path; } } if (is_array($value)) { uksort($value, 'strcmp'); $data = array_merge($data, $this->_normalizeData($value, $key)); } else { $data[] = [$key, $value]; } } return $data; }
[ "protected", "function", "_normalizeData", "(", "$", "args", ",", "$", "path", "=", "''", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "args", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "path", ")", "{", "// Fold string keys with [].", "// Numeric keys result in a=b&a=c. While this isn't", "// standard behavior in PHP, it is common in other platforms.", "if", "(", "!", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "key", "=", "\"{$path}[{$key}]\"", ";", "}", "else", "{", "$", "key", "=", "$", "path", ";", "}", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "uksort", "(", "$", "value", ",", "'strcmp'", ")", ";", "$", "data", "=", "array_merge", "(", "$", "data", ",", "$", "this", "->", "_normalizeData", "(", "$", "value", ",", "$", "key", ")", ")", ";", "}", "else", "{", "$", "data", "[", "]", "=", "[", "$", "key", ",", "$", "value", "]", ";", "}", "}", "return", "$", "data", ";", "}" ]
Recursively convert request data into the normalized form. @param array $args The arguments to normalize. @param string $path The current path being converted. @see https://tools.ietf.org/html/rfc5849#section-3.4.1.3.2 @return array
[ "Recursively", "convert", "request", "data", "into", "the", "normalized", "form", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Oauth.php#L314-L337
210,409
cakephp/cakephp
src/Http/Client/Auth/Oauth.php
Oauth._buildAuth
protected function _buildAuth($data) { $out = 'OAuth '; $params = []; foreach ($data as $key => $value) { $params[] = $key . '="' . $this->_encode($value) . '"'; } $out .= implode(',', $params); return $out; }
php
protected function _buildAuth($data) { $out = 'OAuth '; $params = []; foreach ($data as $key => $value) { $params[] = $key . '="' . $this->_encode($value) . '"'; } $out .= implode(',', $params); return $out; }
[ "protected", "function", "_buildAuth", "(", "$", "data", ")", "{", "$", "out", "=", "'OAuth '", ";", "$", "params", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "params", "[", "]", "=", "$", "key", ".", "'=\"'", ".", "$", "this", "->", "_encode", "(", "$", "value", ")", ".", "'\"'", ";", "}", "$", "out", ".=", "implode", "(", "','", ",", "$", "params", ")", ";", "return", "$", "out", ";", "}" ]
Builds the Oauth Authorization header value. @param array $data The oauth_* values to build @return string
[ "Builds", "the", "Oauth", "Authorization", "header", "value", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Oauth.php#L345-L355
210,410
cakephp/cakephp
src/Utility/Hash.php
Hash._splitConditions
protected static function _splitConditions($token) { $conditions = false; $position = strpos($token, '['); if ($position !== false) { $conditions = substr($token, $position); $token = substr($token, 0, $position); } return [$token, $conditions]; }
php
protected static function _splitConditions($token) { $conditions = false; $position = strpos($token, '['); if ($position !== false) { $conditions = substr($token, $position); $token = substr($token, 0, $position); } return [$token, $conditions]; }
[ "protected", "static", "function", "_splitConditions", "(", "$", "token", ")", "{", "$", "conditions", "=", "false", ";", "$", "position", "=", "strpos", "(", "$", "token", ",", "'['", ")", ";", "if", "(", "$", "position", "!==", "false", ")", "{", "$", "conditions", "=", "substr", "(", "$", "token", ",", "$", "position", ")", ";", "$", "token", "=", "substr", "(", "$", "token", ",", "0", ",", "$", "position", ")", ";", "}", "return", "[", "$", "token", ",", "$", "conditions", "]", ";", "}" ]
Split token conditions @param string $token the token being splitted. @return array [token, conditions] with token splitted
[ "Split", "token", "conditions" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Hash.php#L197-L207
210,411
cakephp/cakephp
src/Utility/Hash.php
Hash._matchToken
protected static function _matchToken($key, $token) { switch ($token) { case '{n}': return is_numeric($key); case '{s}': return is_string($key); case '{*}': return true; default: return is_numeric($token) ? ($key == $token) : $key === $token; } }
php
protected static function _matchToken($key, $token) { switch ($token) { case '{n}': return is_numeric($key); case '{s}': return is_string($key); case '{*}': return true; default: return is_numeric($token) ? ($key == $token) : $key === $token; } }
[ "protected", "static", "function", "_matchToken", "(", "$", "key", ",", "$", "token", ")", "{", "switch", "(", "$", "token", ")", "{", "case", "'{n}'", ":", "return", "is_numeric", "(", "$", "key", ")", ";", "case", "'{s}'", ":", "return", "is_string", "(", "$", "key", ")", ";", "case", "'{*}'", ":", "return", "true", ";", "default", ":", "return", "is_numeric", "(", "$", "token", ")", "?", "(", "$", "key", "==", "$", "token", ")", ":", "$", "key", "===", "$", "token", ";", "}", "}" ]
Check a key against a token. @param string $key The key in the array being searched. @param string $token The token being matched. @return bool
[ "Check", "a", "key", "against", "a", "token", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Hash.php#L216-L228
210,412
cakephp/cakephp
src/Utility/Hash.php
Hash.contains
public static function contains(array $data, array $needle) { if (empty($data) || empty($needle)) { return false; } $stack = []; while (!empty($needle)) { $key = key($needle); $val = $needle[$key]; unset($needle[$key]); if (array_key_exists($key, $data) && is_array($val)) { $next = $data[$key]; unset($data[$key]); if (!empty($val)) { $stack[] = [$val, $next]; } } elseif (!array_key_exists($key, $data) || $data[$key] != $val) { return false; } if (empty($needle) && !empty($stack)) { list($needle, $data) = array_pop($stack); } } return true; }
php
public static function contains(array $data, array $needle) { if (empty($data) || empty($needle)) { return false; } $stack = []; while (!empty($needle)) { $key = key($needle); $val = $needle[$key]; unset($needle[$key]); if (array_key_exists($key, $data) && is_array($val)) { $next = $data[$key]; unset($data[$key]); if (!empty($val)) { $stack[] = [$val, $next]; } } elseif (!array_key_exists($key, $data) || $data[$key] != $val) { return false; } if (empty($needle) && !empty($stack)) { list($needle, $data) = array_pop($stack); } } return true; }
[ "public", "static", "function", "contains", "(", "array", "$", "data", ",", "array", "$", "needle", ")", "{", "if", "(", "empty", "(", "$", "data", ")", "||", "empty", "(", "$", "needle", ")", ")", "{", "return", "false", ";", "}", "$", "stack", "=", "[", "]", ";", "while", "(", "!", "empty", "(", "$", "needle", ")", ")", "{", "$", "key", "=", "key", "(", "$", "needle", ")", ";", "$", "val", "=", "$", "needle", "[", "$", "key", "]", ";", "unset", "(", "$", "needle", "[", "$", "key", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "data", ")", "&&", "is_array", "(", "$", "val", ")", ")", "{", "$", "next", "=", "$", "data", "[", "$", "key", "]", ";", "unset", "(", "$", "data", "[", "$", "key", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "val", ")", ")", "{", "$", "stack", "[", "]", "=", "[", "$", "val", ",", "$", "next", "]", ";", "}", "}", "elseif", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "data", ")", "||", "$", "data", "[", "$", "key", "]", "!=", "$", "val", ")", "{", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "needle", ")", "&&", "!", "empty", "(", "$", "stack", ")", ")", "{", "list", "(", "$", "needle", ",", "$", "data", ")", "=", "array_pop", "(", "$", "stack", ")", ";", "}", "}", "return", "true", ";", "}" ]
Determines if one array contains the exact keys and values of another. @param array $data The data to search through. @param array $needle The values to file in $data @return bool true If $data contains $needle, false otherwise @link https://book.cakephp.org/3.0/en/core-libraries/hash.html#Cake\Utility\Hash::contains
[ "Determines", "if", "one", "array", "contains", "the", "exact", "keys", "and", "values", "of", "another", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Hash.php#L572-L601
210,413
cakephp/cakephp
src/Utility/Hash.php
Hash.filter
public static function filter(array $data, $callback = ['self', '_filter']) { foreach ($data as $k => $v) { if (is_array($v)) { $data[$k] = static::filter($v, $callback); } } return array_filter($data, $callback); }
php
public static function filter(array $data, $callback = ['self', '_filter']) { foreach ($data as $k => $v) { if (is_array($v)) { $data[$k] = static::filter($v, $callback); } } return array_filter($data, $callback); }
[ "public", "static", "function", "filter", "(", "array", "$", "data", ",", "$", "callback", "=", "[", "'self'", ",", "'_filter'", "]", ")", "{", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "$", "data", "[", "$", "k", "]", "=", "static", "::", "filter", "(", "$", "v", ",", "$", "callback", ")", ";", "}", "}", "return", "array_filter", "(", "$", "data", ",", "$", "callback", ")", ";", "}" ]
Recursively filters a data set. @param array $data Either an array to filter, or value when in callback @param callable|array $callback A function to filter the data with. Defaults to `static::_filter()` Which strips out all non-zero empty values. @return array Filtered array @link https://book.cakephp.org/3.0/en/core-libraries/hash.html#Cake\Utility\Hash::filter
[ "Recursively", "filters", "a", "data", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Hash.php#L635-L644
210,414
cakephp/cakephp
src/Http/Client/CookieCollection.php
CookieCollection.store
public function store(Response $response, $url) { $host = parse_url($url, PHP_URL_HOST); $path = parse_url($url, PHP_URL_PATH); $path = $path ?: '/'; $header = $response->getHeader('Set-Cookie'); $cookies = $this->parseSetCookieHeader($header); $cookies = $this->setRequestDefaults($cookies, $host, $path); foreach ($cookies as $cookie) { $this->cookies[$cookie->getId()] = $cookie; } $this->removeExpiredCookies($host, $path); }
php
public function store(Response $response, $url) { $host = parse_url($url, PHP_URL_HOST); $path = parse_url($url, PHP_URL_PATH); $path = $path ?: '/'; $header = $response->getHeader('Set-Cookie'); $cookies = $this->parseSetCookieHeader($header); $cookies = $this->setRequestDefaults($cookies, $host, $path); foreach ($cookies as $cookie) { $this->cookies[$cookie->getId()] = $cookie; } $this->removeExpiredCookies($host, $path); }
[ "public", "function", "store", "(", "Response", "$", "response", ",", "$", "url", ")", "{", "$", "host", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_HOST", ")", ";", "$", "path", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_PATH", ")", ";", "$", "path", "=", "$", "path", "?", ":", "'/'", ";", "$", "header", "=", "$", "response", "->", "getHeader", "(", "'Set-Cookie'", ")", ";", "$", "cookies", "=", "$", "this", "->", "parseSetCookieHeader", "(", "$", "header", ")", ";", "$", "cookies", "=", "$", "this", "->", "setRequestDefaults", "(", "$", "cookies", ",", "$", "host", ",", "$", "path", ")", ";", "foreach", "(", "$", "cookies", "as", "$", "cookie", ")", "{", "$", "this", "->", "cookies", "[", "$", "cookie", "->", "getId", "(", ")", "]", "=", "$", "cookie", ";", "}", "$", "this", "->", "removeExpiredCookies", "(", "$", "host", ",", "$", "path", ")", ";", "}" ]
Store the cookies from a response. Store the cookies that haven't expired. If a cookie has been expired and is currently stored, it will be removed. @param Response $response The response to read cookies from @param string $url The request URL used for default host/path values. @return void
[ "Store", "the", "cookies", "from", "a", "response", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/CookieCollection.php#L50-L63
210,415
cakephp/cakephp
src/Http/Client/CookieCollection.php
CookieCollection.get
public function get($url) { $path = parse_url($url, PHP_URL_PATH) ?: '/'; $host = parse_url($url, PHP_URL_HOST); $scheme = parse_url($url, PHP_URL_SCHEME); return $this->findMatchingCookies($scheme, $host, $path); }
php
public function get($url) { $path = parse_url($url, PHP_URL_PATH) ?: '/'; $host = parse_url($url, PHP_URL_HOST); $scheme = parse_url($url, PHP_URL_SCHEME); return $this->findMatchingCookies($scheme, $host, $path); }
[ "public", "function", "get", "(", "$", "url", ")", "{", "$", "path", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_PATH", ")", "?", ":", "'/'", ";", "$", "host", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_HOST", ")", ";", "$", "scheme", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_SCHEME", ")", ";", "return", "$", "this", "->", "findMatchingCookies", "(", "$", "scheme", ",", "$", "host", ",", "$", "path", ")", ";", "}" ]
Get stored cookies for a URL. Finds matching stored cookies and returns a simple array of name => value @param string $url The URL to find cookies for. @return array
[ "Get", "stored", "cookies", "for", "a", "URL", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/CookieCollection.php#L74-L81
210,416
cakephp/cakephp
src/Http/Client/CookieCollection.php
CookieCollection.getAll
public function getAll() { $out = []; foreach ($this->cookies as $cookie) { $out[] = $this->convertCookieToArray($cookie); } return $out; }
php
public function getAll() { $out = []; foreach ($this->cookies as $cookie) { $out[] = $this->convertCookieToArray($cookie); } return $out; }
[ "public", "function", "getAll", "(", ")", "{", "$", "out", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "cookie", ")", "{", "$", "out", "[", "]", "=", "$", "this", "->", "convertCookieToArray", "(", "$", "cookie", ")", ";", "}", "return", "$", "out", ";", "}" ]
Get all the stored cookies as arrays. @return array
[ "Get", "all", "the", "stored", "cookies", "as", "arrays", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/CookieCollection.php#L88-L96
210,417
cakephp/cakephp
src/Database/Expression/OrderByExpression.php
OrderByExpression._addConditions
protected function _addConditions(array $orders, array $types) { foreach ($orders as $key => $val) { if (is_string($key) && is_string($val) && !in_array(strtoupper($val), ['ASC', 'DESC'], true)) { deprecationWarning( 'Passing extra sort expressions by associative array is deprecated. ' . 'Use QueryExpression or numeric array instead.' ); } } $this->_conditions = array_merge($this->_conditions, $orders); }
php
protected function _addConditions(array $orders, array $types) { foreach ($orders as $key => $val) { if (is_string($key) && is_string($val) && !in_array(strtoupper($val), ['ASC', 'DESC'], true)) { deprecationWarning( 'Passing extra sort expressions by associative array is deprecated. ' . 'Use QueryExpression or numeric array instead.' ); } } $this->_conditions = array_merge($this->_conditions, $orders); }
[ "protected", "function", "_addConditions", "(", "array", "$", "orders", ",", "array", "$", "types", ")", "{", "foreach", "(", "$", "orders", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "is_string", "(", "$", "key", ")", "&&", "is_string", "(", "$", "val", ")", "&&", "!", "in_array", "(", "strtoupper", "(", "$", "val", ")", ",", "[", "'ASC'", ",", "'DESC'", "]", ",", "true", ")", ")", "{", "deprecationWarning", "(", "'Passing extra sort expressions by associative array is deprecated. '", ".", "'Use QueryExpression or numeric array instead.'", ")", ";", "}", "}", "$", "this", "->", "_conditions", "=", "array_merge", "(", "$", "this", "->", "_conditions", ",", "$", "orders", ")", ";", "}" ]
Auxiliary function used for decomposing a nested array of conditions and building a tree structure inside this object to represent the full SQL expression. New order by expressions are merged to existing ones @param array $orders list of order by expressions @param array $types list of types associated on fields referenced in $conditions @return void
[ "Auxiliary", "function", "used", "for", "decomposing", "a", "nested", "array", "of", "conditions", "and", "building", "a", "tree", "structure", "inside", "this", "object", "to", "represent", "the", "full", "SQL", "expression", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/OrderByExpression.php#L67-L78
210,418
cakephp/cakephp
src/Console/ConsoleInputSubcommand.php
ConsoleInputSubcommand.help
public function help($width = 0) { $name = $this->_name; if (strlen($name) < $width) { $name = str_pad($name, $width, ' '); } return $name . $this->_help; }
php
public function help($width = 0) { $name = $this->_name; if (strlen($name) < $width) { $name = str_pad($name, $width, ' '); } return $name . $this->_help; }
[ "public", "function", "help", "(", "$", "width", "=", "0", ")", "{", "$", "name", "=", "$", "this", "->", "_name", ";", "if", "(", "strlen", "(", "$", "name", ")", "<", "$", "width", ")", "{", "$", "name", "=", "str_pad", "(", "$", "name", ",", "$", "width", ",", "' '", ")", ";", "}", "return", "$", "name", ".", "$", "this", "->", "_help", ";", "}" ]
Generate the help for this this subcommand. @param int $width The width to make the name of the subcommand. @return string
[ "Generate", "the", "help", "for", "this", "this", "subcommand", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInputSubcommand.php#L102-L110
210,419
cakephp/cakephp
src/Console/ConsoleInputSubcommand.php
ConsoleInputSubcommand.xml
public function xml(SimpleXMLElement $parent) { $command = $parent->addChild('command'); $command->addAttribute('name', $this->_name); $command->addAttribute('help', $this->_help); return $parent; }
php
public function xml(SimpleXMLElement $parent) { $command = $parent->addChild('command'); $command->addAttribute('name', $this->_name); $command->addAttribute('help', $this->_help); return $parent; }
[ "public", "function", "xml", "(", "SimpleXMLElement", "$", "parent", ")", "{", "$", "command", "=", "$", "parent", "->", "addChild", "(", "'command'", ")", ";", "$", "command", "->", "addAttribute", "(", "'name'", ",", "$", "this", "->", "_name", ")", ";", "$", "command", "->", "addAttribute", "(", "'help'", ",", "$", "this", "->", "_help", ")", ";", "return", "$", "parent", ";", "}" ]
Append this subcommand to the Parent element @param \SimpleXMLElement $parent The parent element. @return \SimpleXMLElement The parent with this subcommand appended.
[ "Append", "this", "subcommand", "to", "the", "Parent", "element" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInputSubcommand.php#L132-L139
210,420
cakephp/cakephp
src/Collection/Iterator/TreePrinter.php
TreePrinter.key
public function key() { $extractor = $this->_key; return $extractor($this->_fetchCurrent(), parent::key(), $this); }
php
public function key() { $extractor = $this->_key; return $extractor($this->_fetchCurrent(), parent::key(), $this); }
[ "public", "function", "key", "(", ")", "{", "$", "extractor", "=", "$", "this", "->", "_key", ";", "return", "$", "extractor", "(", "$", "this", "->", "_fetchCurrent", "(", ")", ",", "parent", "::", "key", "(", ")", ",", "$", "this", ")", ";", "}" ]
Returns the current iteration key @return mixed
[ "Returns", "the", "current", "iteration", "key" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/TreePrinter.php#L82-L87
210,421
cakephp/cakephp
src/Collection/Iterator/TreePrinter.php
TreePrinter.current
public function current() { $extractor = $this->_value; $current = $this->_fetchCurrent(); $spacer = str_repeat($this->_spacer, $this->getDepth()); return $spacer . $extractor($current, parent::key(), $this); }
php
public function current() { $extractor = $this->_value; $current = $this->_fetchCurrent(); $spacer = str_repeat($this->_spacer, $this->getDepth()); return $spacer . $extractor($current, parent::key(), $this); }
[ "public", "function", "current", "(", ")", "{", "$", "extractor", "=", "$", "this", "->", "_value", ";", "$", "current", "=", "$", "this", "->", "_fetchCurrent", "(", ")", ";", "$", "spacer", "=", "str_repeat", "(", "$", "this", "->", "_spacer", ",", "$", "this", "->", "getDepth", "(", ")", ")", ";", "return", "$", "spacer", ".", "$", "extractor", "(", "$", "current", ",", "parent", "::", "key", "(", ")", ",", "$", "this", ")", ";", "}" ]
Returns the current iteration value @return string
[ "Returns", "the", "current", "iteration", "value" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/TreePrinter.php#L94-L101
210,422
cakephp/cakephp
src/Collection/Iterator/TreePrinter.php
TreePrinter._fetchCurrent
protected function _fetchCurrent() { if ($this->_current !== null) { return $this->_current; } return $this->_current = parent::current(); }
php
protected function _fetchCurrent() { if ($this->_current !== null) { return $this->_current; } return $this->_current = parent::current(); }
[ "protected", "function", "_fetchCurrent", "(", ")", "{", "if", "(", "$", "this", "->", "_current", "!==", "null", ")", "{", "return", "$", "this", "->", "_current", ";", "}", "return", "$", "this", "->", "_current", "=", "parent", "::", "current", "(", ")", ";", "}" ]
Returns the current iteration element and caches its value @return mixed
[ "Returns", "the", "current", "iteration", "element", "and", "caches", "its", "value" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/TreePrinter.php#L119-L126
210,423
cakephp/cakephp
src/Database/Connection.php
Connection.prepare
public function prepare($sql) { return $this->getDisconnectRetry()->run(function () use ($sql) { $statement = $this->_driver->prepare($sql); if ($this->_logQueries) { $statement = $this->_newLogger($statement); } return $statement; }); }
php
public function prepare($sql) { return $this->getDisconnectRetry()->run(function () use ($sql) { $statement = $this->_driver->prepare($sql); if ($this->_logQueries) { $statement = $this->_newLogger($statement); } return $statement; }); }
[ "public", "function", "prepare", "(", "$", "sql", ")", "{", "return", "$", "this", "->", "getDisconnectRetry", "(", ")", "->", "run", "(", "function", "(", ")", "use", "(", "$", "sql", ")", "{", "$", "statement", "=", "$", "this", "->", "_driver", "->", "prepare", "(", "$", "sql", ")", ";", "if", "(", "$", "this", "->", "_logQueries", ")", "{", "$", "statement", "=", "$", "this", "->", "_newLogger", "(", "$", "statement", ")", ";", "}", "return", "$", "statement", ";", "}", ")", ";", "}" ]
Prepares a SQL statement to be executed. @param string|\Cake\Database\Query $sql The SQL to convert into a prepared statement. @return \Cake\Database\StatementInterface
[ "Prepares", "a", "SQL", "statement", "to", "be", "executed", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L272-L283
210,424
cakephp/cakephp
src/Database/Connection.php
Connection.compileQuery
public function compileQuery(Query $query, ValueBinder $generator) { return $this->getDriver()->compileQuery($query, $generator)[1]; }
php
public function compileQuery(Query $query, ValueBinder $generator) { return $this->getDriver()->compileQuery($query, $generator)[1]; }
[ "public", "function", "compileQuery", "(", "Query", "$", "query", ",", "ValueBinder", "$", "generator", ")", "{", "return", "$", "this", "->", "getDriver", "(", ")", "->", "compileQuery", "(", "$", "query", ",", "$", "generator", ")", "[", "1", "]", ";", "}" ]
Compiles a Query object into a SQL string according to the dialect for this connection's driver @param \Cake\Database\Query $query The query to be compiled @param \Cake\Database\ValueBinder $generator The placeholder generator to use @return string
[ "Compiles", "a", "Query", "object", "into", "a", "SQL", "string", "according", "to", "the", "dialect", "for", "this", "connection", "s", "driver" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L317-L320
210,425
cakephp/cakephp
src/Database/Connection.php
Connection.run
public function run(Query $query) { return $this->getDisconnectRetry()->run(function () use ($query) { $statement = $this->prepare($query); $query->getValueBinder()->attachTo($statement); $statement->execute(); return $statement; }); }
php
public function run(Query $query) { return $this->getDisconnectRetry()->run(function () use ($query) { $statement = $this->prepare($query); $query->getValueBinder()->attachTo($statement); $statement->execute(); return $statement; }); }
[ "public", "function", "run", "(", "Query", "$", "query", ")", "{", "return", "$", "this", "->", "getDisconnectRetry", "(", ")", "->", "run", "(", "function", "(", ")", "use", "(", "$", "query", ")", "{", "$", "statement", "=", "$", "this", "->", "prepare", "(", "$", "query", ")", ";", "$", "query", "->", "getValueBinder", "(", ")", "->", "attachTo", "(", "$", "statement", ")", ";", "$", "statement", "->", "execute", "(", ")", ";", "return", "$", "statement", ";", "}", ")", ";", "}" ]
Executes the provided query after compiling it for the specific driver dialect and returns the executed Statement object. @param \Cake\Database\Query $query The query to be executed @return \Cake\Database\StatementInterface executed statement
[ "Executes", "the", "provided", "query", "after", "compiling", "it", "for", "the", "specific", "driver", "dialect", "and", "returns", "the", "executed", "Statement", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L329-L338
210,426
cakephp/cakephp
src/Database/Connection.php
Connection.query
public function query($sql) { return $this->getDisconnectRetry()->run(function () use ($sql) { $statement = $this->prepare($sql); $statement->execute(); return $statement; }); }
php
public function query($sql) { return $this->getDisconnectRetry()->run(function () use ($sql) { $statement = $this->prepare($sql); $statement->execute(); return $statement; }); }
[ "public", "function", "query", "(", "$", "sql", ")", "{", "return", "$", "this", "->", "getDisconnectRetry", "(", ")", "->", "run", "(", "function", "(", ")", "use", "(", "$", "sql", ")", "{", "$", "statement", "=", "$", "this", "->", "prepare", "(", "$", "sql", ")", ";", "$", "statement", "->", "execute", "(", ")", ";", "return", "$", "statement", ";", "}", ")", ";", "}" ]
Executes a SQL statement and returns the Statement object as result. @param string $sql The SQL query to execute. @return \Cake\Database\StatementInterface
[ "Executes", "a", "SQL", "statement", "and", "returns", "the", "Statement", "object", "as", "result", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L346-L354
210,427
cakephp/cakephp
src/Database/Connection.php
Connection.getSchemaCollection
public function getSchemaCollection() { if ($this->_schemaCollection !== null) { return $this->_schemaCollection; } if (!empty($this->_config['cacheMetadata'])) { return $this->_schemaCollection = new CachedCollection($this, $this->_config['cacheMetadata']); } return $this->_schemaCollection = new SchemaCollection($this); }
php
public function getSchemaCollection() { if ($this->_schemaCollection !== null) { return $this->_schemaCollection; } if (!empty($this->_config['cacheMetadata'])) { return $this->_schemaCollection = new CachedCollection($this, $this->_config['cacheMetadata']); } return $this->_schemaCollection = new SchemaCollection($this); }
[ "public", "function", "getSchemaCollection", "(", ")", "{", "if", "(", "$", "this", "->", "_schemaCollection", "!==", "null", ")", "{", "return", "$", "this", "->", "_schemaCollection", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_config", "[", "'cacheMetadata'", "]", ")", ")", "{", "return", "$", "this", "->", "_schemaCollection", "=", "new", "CachedCollection", "(", "$", "this", ",", "$", "this", "->", "_config", "[", "'cacheMetadata'", "]", ")", ";", "}", "return", "$", "this", "->", "_schemaCollection", "=", "new", "SchemaCollection", "(", "$", "this", ")", ";", "}" ]
Gets a Schema\Collection object for this connection. @return \Cake\Database\Schema\Collection
[ "Gets", "a", "Schema", "\\", "Collection", "object", "for", "this", "connection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L384-L395
210,428
cakephp/cakephp
src/Database/Connection.php
Connection.schemaCollection
public function schemaCollection(SchemaCollection $collection = null) { deprecationWarning( 'Connection::schemaCollection() is deprecated. ' . 'Use Connection::setSchemaCollection()/getSchemaCollection() instead.' ); if ($collection !== null) { $this->setSchemaCollection($collection); } return $this->getSchemaCollection(); }
php
public function schemaCollection(SchemaCollection $collection = null) { deprecationWarning( 'Connection::schemaCollection() is deprecated. ' . 'Use Connection::setSchemaCollection()/getSchemaCollection() instead.' ); if ($collection !== null) { $this->setSchemaCollection($collection); } return $this->getSchemaCollection(); }
[ "public", "function", "schemaCollection", "(", "SchemaCollection", "$", "collection", "=", "null", ")", "{", "deprecationWarning", "(", "'Connection::schemaCollection() is deprecated. '", ".", "'Use Connection::setSchemaCollection()/getSchemaCollection() instead.'", ")", ";", "if", "(", "$", "collection", "!==", "null", ")", "{", "$", "this", "->", "setSchemaCollection", "(", "$", "collection", ")", ";", "}", "return", "$", "this", "->", "getSchemaCollection", "(", ")", ";", "}" ]
Gets or sets a Schema\Collection object for this connection. @deprecated 3.4.0 Use setSchemaCollection()/getSchemaCollection() @param \Cake\Database\Schema\Collection|null $collection The schema collection object @return \Cake\Database\Schema\Collection
[ "Gets", "or", "sets", "a", "Schema", "\\", "Collection", "object", "for", "this", "connection", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L404-L415
210,429
cakephp/cakephp
src/Database/Connection.php
Connection.insert
public function insert($table, array $data, array $types = []) { return $this->getDisconnectRetry()->run(function () use ($table, $data, $types) { $columns = array_keys($data); return $this->newQuery()->insert($columns, $types) ->into($table) ->values($data) ->execute(); }); }
php
public function insert($table, array $data, array $types = []) { return $this->getDisconnectRetry()->run(function () use ($table, $data, $types) { $columns = array_keys($data); return $this->newQuery()->insert($columns, $types) ->into($table) ->values($data) ->execute(); }); }
[ "public", "function", "insert", "(", "$", "table", ",", "array", "$", "data", ",", "array", "$", "types", "=", "[", "]", ")", "{", "return", "$", "this", "->", "getDisconnectRetry", "(", ")", "->", "run", "(", "function", "(", ")", "use", "(", "$", "table", ",", "$", "data", ",", "$", "types", ")", "{", "$", "columns", "=", "array_keys", "(", "$", "data", ")", ";", "return", "$", "this", "->", "newQuery", "(", ")", "->", "insert", "(", "$", "columns", ",", "$", "types", ")", "->", "into", "(", "$", "table", ")", "->", "values", "(", "$", "data", ")", "->", "execute", "(", ")", ";", "}", ")", ";", "}" ]
Executes an INSERT query on the specified table. @param string $table the table to insert values in @param array $data values to be inserted @param array $types list of associative array containing the types to be used for casting @return \Cake\Database\StatementInterface
[ "Executes", "an", "INSERT", "query", "on", "the", "specified", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L425-L435
210,430
cakephp/cakephp
src/Database/Connection.php
Connection.update
public function update($table, array $data, array $conditions = [], $types = []) { return $this->getDisconnectRetry()->run(function () use ($table, $data, $conditions, $types) { return $this->newQuery()->update($table) ->set($data, $types) ->where($conditions, $types) ->execute(); }); }
php
public function update($table, array $data, array $conditions = [], $types = []) { return $this->getDisconnectRetry()->run(function () use ($table, $data, $conditions, $types) { return $this->newQuery()->update($table) ->set($data, $types) ->where($conditions, $types) ->execute(); }); }
[ "public", "function", "update", "(", "$", "table", ",", "array", "$", "data", ",", "array", "$", "conditions", "=", "[", "]", ",", "$", "types", "=", "[", "]", ")", "{", "return", "$", "this", "->", "getDisconnectRetry", "(", ")", "->", "run", "(", "function", "(", ")", "use", "(", "$", "table", ",", "$", "data", ",", "$", "conditions", ",", "$", "types", ")", "{", "return", "$", "this", "->", "newQuery", "(", ")", "->", "update", "(", "$", "table", ")", "->", "set", "(", "$", "data", ",", "$", "types", ")", "->", "where", "(", "$", "conditions", ",", "$", "types", ")", "->", "execute", "(", ")", ";", "}", ")", ";", "}" ]
Executes an UPDATE statement on the specified table. @param string $table the table to update rows from @param array $data values to be updated @param array $conditions conditions to be set for update statement @param array $types list of associative array containing the types to be used for casting @return \Cake\Database\StatementInterface
[ "Executes", "an", "UPDATE", "statement", "on", "the", "specified", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L446-L454
210,431
cakephp/cakephp
src/Database/Connection.php
Connection.delete
public function delete($table, $conditions = [], $types = []) { return $this->getDisconnectRetry()->run(function () use ($table, $conditions, $types) { return $this->newQuery()->delete($table) ->where($conditions, $types) ->execute(); }); }
php
public function delete($table, $conditions = [], $types = []) { return $this->getDisconnectRetry()->run(function () use ($table, $conditions, $types) { return $this->newQuery()->delete($table) ->where($conditions, $types) ->execute(); }); }
[ "public", "function", "delete", "(", "$", "table", ",", "$", "conditions", "=", "[", "]", ",", "$", "types", "=", "[", "]", ")", "{", "return", "$", "this", "->", "getDisconnectRetry", "(", ")", "->", "run", "(", "function", "(", ")", "use", "(", "$", "table", ",", "$", "conditions", ",", "$", "types", ")", "{", "return", "$", "this", "->", "newQuery", "(", ")", "->", "delete", "(", "$", "table", ")", "->", "where", "(", "$", "conditions", ",", "$", "types", ")", "->", "execute", "(", ")", ";", "}", ")", ";", "}" ]
Executes a DELETE statement on the specified table. @param string $table the table to delete rows from @param array $conditions conditions to be set for delete statement @param array $types list of associative array containing the types to be used for casting @return \Cake\Database\StatementInterface
[ "Executes", "a", "DELETE", "statement", "on", "the", "specified", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L464-L471
210,432
cakephp/cakephp
src/Database/Connection.php
Connection.commit
public function commit() { if (!$this->_transactionStarted) { return false; } if ($this->_transactionLevel === 0) { if ($this->wasNestedTransactionRolledback()) { $e = $this->nestedTransactionRollbackException; $this->nestedTransactionRollbackException = null; throw $e; } $this->_transactionStarted = false; $this->nestedTransactionRollbackException = null; if ($this->_logQueries) { $this->log('COMMIT'); } return $this->_driver->commitTransaction(); } if ($this->isSavePointsEnabled()) { $this->releaseSavePoint((string)$this->_transactionLevel); } $this->_transactionLevel--; return true; }
php
public function commit() { if (!$this->_transactionStarted) { return false; } if ($this->_transactionLevel === 0) { if ($this->wasNestedTransactionRolledback()) { $e = $this->nestedTransactionRollbackException; $this->nestedTransactionRollbackException = null; throw $e; } $this->_transactionStarted = false; $this->nestedTransactionRollbackException = null; if ($this->_logQueries) { $this->log('COMMIT'); } return $this->_driver->commitTransaction(); } if ($this->isSavePointsEnabled()) { $this->releaseSavePoint((string)$this->_transactionLevel); } $this->_transactionLevel--; return true; }
[ "public", "function", "commit", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_transactionStarted", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "_transactionLevel", "===", "0", ")", "{", "if", "(", "$", "this", "->", "wasNestedTransactionRolledback", "(", ")", ")", "{", "$", "e", "=", "$", "this", "->", "nestedTransactionRollbackException", ";", "$", "this", "->", "nestedTransactionRollbackException", "=", "null", ";", "throw", "$", "e", ";", "}", "$", "this", "->", "_transactionStarted", "=", "false", ";", "$", "this", "->", "nestedTransactionRollbackException", "=", "null", ";", "if", "(", "$", "this", "->", "_logQueries", ")", "{", "$", "this", "->", "log", "(", "'COMMIT'", ")", ";", "}", "return", "$", "this", "->", "_driver", "->", "commitTransaction", "(", ")", ";", "}", "if", "(", "$", "this", "->", "isSavePointsEnabled", "(", ")", ")", "{", "$", "this", "->", "releaseSavePoint", "(", "(", "string", ")", "$", "this", "->", "_transactionLevel", ")", ";", "}", "$", "this", "->", "_transactionLevel", "--", ";", "return", "true", ";", "}" ]
Commits current transaction. @return bool true on success, false otherwise
[ "Commits", "current", "transaction", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L507-L535
210,433
cakephp/cakephp
src/Database/Connection.php
Connection.rollback
public function rollback($toBeginning = null) { if (!$this->_transactionStarted) { return false; } $useSavePoint = $this->isSavePointsEnabled(); if ($toBeginning === null) { $toBeginning = !$useSavePoint; } if ($this->_transactionLevel === 0 || $toBeginning) { $this->_transactionLevel = 0; $this->_transactionStarted = false; $this->nestedTransactionRollbackException = null; if ($this->_logQueries) { $this->log('ROLLBACK'); } $this->_driver->rollbackTransaction(); return true; } $savePoint = $this->_transactionLevel--; if ($useSavePoint) { $this->rollbackSavepoint($savePoint); } elseif ($this->nestedTransactionRollbackException === null) { $this->nestedTransactionRollbackException = new NestedTransactionRollbackException(); } return true; }
php
public function rollback($toBeginning = null) { if (!$this->_transactionStarted) { return false; } $useSavePoint = $this->isSavePointsEnabled(); if ($toBeginning === null) { $toBeginning = !$useSavePoint; } if ($this->_transactionLevel === 0 || $toBeginning) { $this->_transactionLevel = 0; $this->_transactionStarted = false; $this->nestedTransactionRollbackException = null; if ($this->_logQueries) { $this->log('ROLLBACK'); } $this->_driver->rollbackTransaction(); return true; } $savePoint = $this->_transactionLevel--; if ($useSavePoint) { $this->rollbackSavepoint($savePoint); } elseif ($this->nestedTransactionRollbackException === null) { $this->nestedTransactionRollbackException = new NestedTransactionRollbackException(); } return true; }
[ "public", "function", "rollback", "(", "$", "toBeginning", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "_transactionStarted", ")", "{", "return", "false", ";", "}", "$", "useSavePoint", "=", "$", "this", "->", "isSavePointsEnabled", "(", ")", ";", "if", "(", "$", "toBeginning", "===", "null", ")", "{", "$", "toBeginning", "=", "!", "$", "useSavePoint", ";", "}", "if", "(", "$", "this", "->", "_transactionLevel", "===", "0", "||", "$", "toBeginning", ")", "{", "$", "this", "->", "_transactionLevel", "=", "0", ";", "$", "this", "->", "_transactionStarted", "=", "false", ";", "$", "this", "->", "nestedTransactionRollbackException", "=", "null", ";", "if", "(", "$", "this", "->", "_logQueries", ")", "{", "$", "this", "->", "log", "(", "'ROLLBACK'", ")", ";", "}", "$", "this", "->", "_driver", "->", "rollbackTransaction", "(", ")", ";", "return", "true", ";", "}", "$", "savePoint", "=", "$", "this", "->", "_transactionLevel", "--", ";", "if", "(", "$", "useSavePoint", ")", "{", "$", "this", "->", "rollbackSavepoint", "(", "$", "savePoint", ")", ";", "}", "elseif", "(", "$", "this", "->", "nestedTransactionRollbackException", "===", "null", ")", "{", "$", "this", "->", "nestedTransactionRollbackException", "=", "new", "NestedTransactionRollbackException", "(", ")", ";", "}", "return", "true", ";", "}" ]
Rollback current transaction. @param bool|null $toBeginning Whether or not the transaction should be rolled back to the beginning of it. Defaults to false if using savepoints, or true if not. @return bool
[ "Rollback", "current", "transaction", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L544-L574
210,434
cakephp/cakephp
src/Database/Connection.php
Connection.disableForeignKeys
public function disableForeignKeys() { $this->getDisconnectRetry()->run(function () { $this->execute($this->_driver->disableForeignKeySQL())->closeCursor(); }); }
php
public function disableForeignKeys() { $this->getDisconnectRetry()->run(function () { $this->execute($this->_driver->disableForeignKeySQL())->closeCursor(); }); }
[ "public", "function", "disableForeignKeys", "(", ")", "{", "$", "this", "->", "getDisconnectRetry", "(", ")", "->", "run", "(", "function", "(", ")", "{", "$", "this", "->", "execute", "(", "$", "this", "->", "_driver", "->", "disableForeignKeySQL", "(", ")", ")", "->", "closeCursor", "(", ")", ";", "}", ")", ";", "}" ]
Run driver specific SQL to disable foreign key checks. @return void
[ "Run", "driver", "specific", "SQL", "to", "disable", "foreign", "key", "checks", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L692-L697
210,435
cakephp/cakephp
src/Database/Connection.php
Connection.enableForeignKeys
public function enableForeignKeys() { $this->getDisconnectRetry()->run(function () { $this->execute($this->_driver->enableForeignKeySQL())->closeCursor(); }); }
php
public function enableForeignKeys() { $this->getDisconnectRetry()->run(function () { $this->execute($this->_driver->enableForeignKeySQL())->closeCursor(); }); }
[ "public", "function", "enableForeignKeys", "(", ")", "{", "$", "this", "->", "getDisconnectRetry", "(", ")", "->", "run", "(", "function", "(", ")", "{", "$", "this", "->", "execute", "(", "$", "this", "->", "_driver", "->", "enableForeignKeySQL", "(", ")", ")", "->", "closeCursor", "(", ")", ";", "}", ")", ";", "}" ]
Run driver specific SQL to enable foreign key checks. @return void
[ "Run", "driver", "specific", "SQL", "to", "enable", "foreign", "key", "checks", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L704-L709
210,436
cakephp/cakephp
src/Database/Connection.php
Connection.quote
public function quote($value, $type = null) { list($value, $type) = $this->cast($value, $type); return $this->_driver->quote($value, $type); }
php
public function quote($value, $type = null) { list($value, $type) = $this->cast($value, $type); return $this->_driver->quote($value, $type); }
[ "public", "function", "quote", "(", "$", "value", ",", "$", "type", "=", "null", ")", "{", "list", "(", "$", "value", ",", "$", "type", ")", "=", "$", "this", "->", "cast", "(", "$", "value", ",", "$", "type", ")", ";", "return", "$", "this", "->", "_driver", "->", "quote", "(", "$", "value", ",", "$", "type", ")", ";", "}" ]
Quotes value to be used safely in database query. @param mixed $value The value to quote. @param string|null $type Type to be used for determining kind of quoting to perform @return string Quoted value
[ "Quotes", "value", "to", "be", "used", "safely", "in", "database", "query", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L816-L821
210,437
cakephp/cakephp
src/Database/Connection.php
Connection.log
public function log($sql) { $query = new LoggedQuery(); $query->query = $sql; $this->getLogger()->log($query); }
php
public function log($sql) { $query = new LoggedQuery(); $query->query = $sql; $this->getLogger()->log($query); }
[ "public", "function", "log", "(", "$", "sql", ")", "{", "$", "query", "=", "new", "LoggedQuery", "(", ")", ";", "$", "query", "->", "query", "=", "$", "sql", ";", "$", "this", "->", "getLogger", "(", ")", "->", "log", "(", "$", "query", ")", ";", "}" ]
Logs a Query string using the configured logger object. @param string $sql string to be logged @return void
[ "Logs", "a", "Query", "string", "using", "the", "configured", "logger", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L963-L968
210,438
cakephp/cakephp
src/Database/Connection.php
Connection._newLogger
protected function _newLogger(StatementInterface $statement) { $log = new LoggingStatement($statement, $this->_driver); $log->setLogger($this->getLogger()); return $log; }
php
protected function _newLogger(StatementInterface $statement) { $log = new LoggingStatement($statement, $this->_driver); $log->setLogger($this->getLogger()); return $log; }
[ "protected", "function", "_newLogger", "(", "StatementInterface", "$", "statement", ")", "{", "$", "log", "=", "new", "LoggingStatement", "(", "$", "statement", ",", "$", "this", "->", "_driver", ")", ";", "$", "log", "->", "setLogger", "(", "$", "this", "->", "getLogger", "(", ")", ")", ";", "return", "$", "log", ";", "}" ]
Returns a new statement object that will log the activity for the passed original statement instance. @param \Cake\Database\StatementInterface $statement the instance to be decorated @return \Cake\Database\Log\LoggingStatement
[ "Returns", "a", "new", "statement", "object", "that", "will", "log", "the", "activity", "for", "the", "passed", "original", "statement", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Connection.php#L977-L983
210,439
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.set
public function set($property, $value = null, array $options = []) { if (is_string($property) && $property !== '') { $guard = false; $property = [$property => $value]; } else { $guard = true; $options = (array)$value; } if (!is_array($property)) { throw new InvalidArgumentException('Cannot set an empty property'); } $options += ['setter' => true, 'guard' => $guard]; foreach ($property as $p => $value) { if ($options['guard'] === true && !$this->isAccessible($p)) { continue; } $this->setDirty($p, true); if (!array_key_exists($p, $this->_original) && array_key_exists($p, $this->_properties) && $this->_properties[$p] !== $value ) { $this->_original[$p] = $this->_properties[$p]; } if (!$options['setter']) { $this->_properties[$p] = $value; continue; } $setter = static::_accessor($p, 'set'); if ($setter) { $value = $this->{$setter}($value); } $this->_properties[$p] = $value; } return $this; }
php
public function set($property, $value = null, array $options = []) { if (is_string($property) && $property !== '') { $guard = false; $property = [$property => $value]; } else { $guard = true; $options = (array)$value; } if (!is_array($property)) { throw new InvalidArgumentException('Cannot set an empty property'); } $options += ['setter' => true, 'guard' => $guard]; foreach ($property as $p => $value) { if ($options['guard'] === true && !$this->isAccessible($p)) { continue; } $this->setDirty($p, true); if (!array_key_exists($p, $this->_original) && array_key_exists($p, $this->_properties) && $this->_properties[$p] !== $value ) { $this->_original[$p] = $this->_properties[$p]; } if (!$options['setter']) { $this->_properties[$p] = $value; continue; } $setter = static::_accessor($p, 'set'); if ($setter) { $value = $this->{$setter}($value); } $this->_properties[$p] = $value; } return $this; }
[ "public", "function", "set", "(", "$", "property", ",", "$", "value", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "is_string", "(", "$", "property", ")", "&&", "$", "property", "!==", "''", ")", "{", "$", "guard", "=", "false", ";", "$", "property", "=", "[", "$", "property", "=>", "$", "value", "]", ";", "}", "else", "{", "$", "guard", "=", "true", ";", "$", "options", "=", "(", "array", ")", "$", "value", ";", "}", "if", "(", "!", "is_array", "(", "$", "property", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Cannot set an empty property'", ")", ";", "}", "$", "options", "+=", "[", "'setter'", "=>", "true", ",", "'guard'", "=>", "$", "guard", "]", ";", "foreach", "(", "$", "property", "as", "$", "p", "=>", "$", "value", ")", "{", "if", "(", "$", "options", "[", "'guard'", "]", "===", "true", "&&", "!", "$", "this", "->", "isAccessible", "(", "$", "p", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "setDirty", "(", "$", "p", ",", "true", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "p", ",", "$", "this", "->", "_original", ")", "&&", "array_key_exists", "(", "$", "p", ",", "$", "this", "->", "_properties", ")", "&&", "$", "this", "->", "_properties", "[", "$", "p", "]", "!==", "$", "value", ")", "{", "$", "this", "->", "_original", "[", "$", "p", "]", "=", "$", "this", "->", "_properties", "[", "$", "p", "]", ";", "}", "if", "(", "!", "$", "options", "[", "'setter'", "]", ")", "{", "$", "this", "->", "_properties", "[", "$", "p", "]", "=", "$", "value", ";", "continue", ";", "}", "$", "setter", "=", "static", "::", "_accessor", "(", "$", "p", ",", "'set'", ")", ";", "if", "(", "$", "setter", ")", "{", "$", "value", "=", "$", "this", "->", "{", "$", "setter", "}", "(", "$", "value", ")", ";", "}", "$", "this", "->", "_properties", "[", "$", "p", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Sets a single property inside this entity. ### Example: ``` $entity->set('name', 'Andrew'); ``` It is also possible to mass-assign multiple properties to this entity with one call by passing a hashed array as properties in the form of property => value pairs ### Example: ``` $entity->set(['name' => 'andrew', 'id' => 1]); echo $entity->name // prints andrew echo $entity->id // prints 1 ``` Some times it is handy to bypass setter functions in this entity when assigning properties. You can achieve this by disabling the `setter` option using the `$options` parameter: ``` $entity->set('name', 'Andrew', ['setter' => false]); $entity->set(['name' => 'Andrew', 'id' => 1], ['setter' => false]); ``` Mass assignment should be treated carefully when accepting user input, by default entities will guard all fields when properties are assigned in bulk. You can disable the guarding for a single set call with the `guard` option: ``` $entity->set(['name' => 'Andrew', 'id' => 1], ['guard' => true]); ``` You do not need to use the guard option when assigning properties individually: ``` // No need to use the guard option. $entity->set('name', 'Andrew'); ``` @param string|array $property the name of property to set or a list of properties with their respective values @param mixed $value The value to set to the property or an array if the first argument is also an array, in which case will be treated as $options @param array $options options to be used for setting the property. Allowed option keys are `setter` and `guard` @return $this @throws \InvalidArgumentException
[ "Sets", "a", "single", "property", "inside", "this", "entity", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L229-L271
210,440
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.&
public function &get($property) { if (!strlen((string)$property)) { throw new InvalidArgumentException('Cannot get an empty property'); } $value = null; $method = static::_accessor($property, 'get'); if (isset($this->_properties[$property])) { $value =& $this->_properties[$property]; } if ($method) { $result = $this->{$method}($value); return $result; } return $value; }
php
public function &get($property) { if (!strlen((string)$property)) { throw new InvalidArgumentException('Cannot get an empty property'); } $value = null; $method = static::_accessor($property, 'get'); if (isset($this->_properties[$property])) { $value =& $this->_properties[$property]; } if ($method) { $result = $this->{$method}($value); return $result; } return $value; }
[ "public", "function", "&", "get", "(", "$", "property", ")", "{", "if", "(", "!", "strlen", "(", "(", "string", ")", "$", "property", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Cannot get an empty property'", ")", ";", "}", "$", "value", "=", "null", ";", "$", "method", "=", "static", "::", "_accessor", "(", "$", "property", ",", "'get'", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_properties", "[", "$", "property", "]", ")", ")", "{", "$", "value", "=", "&", "$", "this", "->", "_properties", "[", "$", "property", "]", ";", "}", "if", "(", "$", "method", ")", "{", "$", "result", "=", "$", "this", "->", "{", "$", "method", "}", "(", "$", "value", ")", ";", "return", "$", "result", ";", "}", "return", "$", "value", ";", "}" ]
Returns the value of a property by name @param string $property the name of the property to retrieve @return mixed @throws \InvalidArgumentException if an empty property name is passed
[ "Returns", "the", "value", "of", "a", "property", "by", "name" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L280-L300
210,441
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.getOriginal
public function getOriginal($property) { if (!strlen((string)$property)) { throw new InvalidArgumentException('Cannot get an empty property'); } if (array_key_exists($property, $this->_original)) { return $this->_original[$property]; } return $this->get($property); }
php
public function getOriginal($property) { if (!strlen((string)$property)) { throw new InvalidArgumentException('Cannot get an empty property'); } if (array_key_exists($property, $this->_original)) { return $this->_original[$property]; } return $this->get($property); }
[ "public", "function", "getOriginal", "(", "$", "property", ")", "{", "if", "(", "!", "strlen", "(", "(", "string", ")", "$", "property", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Cannot get an empty property'", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "property", ",", "$", "this", "->", "_original", ")", ")", "{", "return", "$", "this", "->", "_original", "[", "$", "property", "]", ";", "}", "return", "$", "this", "->", "get", "(", "$", "property", ")", ";", "}" ]
Returns the value of an original property by name @param string $property the name of the property for which original value is retrieved. @return mixed @throws \InvalidArgumentException if an empty property name is passed.
[ "Returns", "the", "value", "of", "an", "original", "property", "by", "name" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L309-L319
210,442
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.getOriginalValues
public function getOriginalValues() { $originals = $this->_original; $originalKeys = array_keys($originals); foreach ($this->_properties as $key => $value) { if (!in_array($key, $originalKeys)) { $originals[$key] = $value; } } return $originals; }
php
public function getOriginalValues() { $originals = $this->_original; $originalKeys = array_keys($originals); foreach ($this->_properties as $key => $value) { if (!in_array($key, $originalKeys)) { $originals[$key] = $value; } } return $originals; }
[ "public", "function", "getOriginalValues", "(", ")", "{", "$", "originals", "=", "$", "this", "->", "_original", ";", "$", "originalKeys", "=", "array_keys", "(", "$", "originals", ")", ";", "foreach", "(", "$", "this", "->", "_properties", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "originalKeys", ")", ")", "{", "$", "originals", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "originals", ";", "}" ]
Gets all original values of the entity. @return array
[ "Gets", "all", "original", "values", "of", "the", "entity", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L326-L337
210,443
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.isEmpty
public function isEmpty($property) { $value = $this->get($property); if ($value === null || (is_array($value) && empty($value) || (is_string($value) && empty($value))) ) { return true; } return false; }
php
public function isEmpty($property) { $value = $this->get($property); if ($value === null || (is_array($value) && empty($value) || (is_string($value) && empty($value))) ) { return true; } return false; }
[ "public", "function", "isEmpty", "(", "$", "property", ")", "{", "$", "value", "=", "$", "this", "->", "get", "(", "$", "property", ")", ";", "if", "(", "$", "value", "===", "null", "||", "(", "is_array", "(", "$", "value", ")", "&&", "empty", "(", "$", "value", ")", "||", "(", "is_string", "(", "$", "value", ")", "&&", "empty", "(", "$", "value", ")", ")", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks that a property is empty This is not working like the PHP `empty()` function. The method will return true for: - `''` (empty string) - `null` - `[]` and false in all other cases. @param string $property The property to check. @return bool
[ "Checks", "that", "a", "property", "is", "empty" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L392-L403
210,444
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.unsetProperty
public function unsetProperty($property) { $property = (array)$property; foreach ($property as $p) { unset($this->_properties[$p], $this->_dirty[$p]); } return $this; }
php
public function unsetProperty($property) { $property = (array)$property; foreach ($property as $p) { unset($this->_properties[$p], $this->_dirty[$p]); } return $this; }
[ "public", "function", "unsetProperty", "(", "$", "property", ")", "{", "$", "property", "=", "(", "array", ")", "$", "property", ";", "foreach", "(", "$", "property", "as", "$", "p", ")", "{", "unset", "(", "$", "this", "->", "_properties", "[", "$", "p", "]", ",", "$", "this", "->", "_dirty", "[", "$", "p", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Removes a property or list of properties from this entity ### Examples: ``` $entity->unsetProperty('name'); $entity->unsetProperty(['name', 'last_name']); ``` @param string|array $property The property to unset. @return $this
[ "Removes", "a", "property", "or", "list", "of", "properties", "from", "this", "entity" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L439-L447
210,445
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.setHidden
public function setHidden(array $properties, $merge = false) { if ($merge === false) { $this->_hidden = $properties; return $this; } $properties = array_merge($this->_hidden, $properties); $this->_hidden = array_unique($properties); return $this; }
php
public function setHidden(array $properties, $merge = false) { if ($merge === false) { $this->_hidden = $properties; return $this; } $properties = array_merge($this->_hidden, $properties); $this->_hidden = array_unique($properties); return $this; }
[ "public", "function", "setHidden", "(", "array", "$", "properties", ",", "$", "merge", "=", "false", ")", "{", "if", "(", "$", "merge", "===", "false", ")", "{", "$", "this", "->", "_hidden", "=", "$", "properties", ";", "return", "$", "this", ";", "}", "$", "properties", "=", "array_merge", "(", "$", "this", "->", "_hidden", ",", "$", "properties", ")", ";", "$", "this", "->", "_hidden", "=", "array_unique", "(", "$", "properties", ")", ";", "return", "$", "this", ";", "}" ]
Sets hidden properties. @param array $properties An array of properties to hide from array exports. @param bool $merge Merge the new properties with the existing. By default false. @return $this
[ "Sets", "hidden", "properties", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L480-L492
210,446
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.setVirtual
public function setVirtual(array $properties, $merge = false) { if ($merge === false) { $this->_virtual = $properties; return $this; } $properties = array_merge($this->_virtual, $properties); $this->_virtual = array_unique($properties); return $this; }
php
public function setVirtual(array $properties, $merge = false) { if ($merge === false) { $this->_virtual = $properties; return $this; } $properties = array_merge($this->_virtual, $properties); $this->_virtual = array_unique($properties); return $this; }
[ "public", "function", "setVirtual", "(", "array", "$", "properties", ",", "$", "merge", "=", "false", ")", "{", "if", "(", "$", "merge", "===", "false", ")", "{", "$", "this", "->", "_virtual", "=", "$", "properties", ";", "return", "$", "this", ";", "}", "$", "properties", "=", "array_merge", "(", "$", "this", "->", "_virtual", ",", "$", "properties", ")", ";", "$", "this", "->", "_virtual", "=", "array_unique", "(", "$", "properties", ")", ";", "return", "$", "this", ";", "}" ]
Sets the virtual properties on this entity. @param array $properties An array of properties to treat as virtual. @param bool $merge Merge the new properties with the existing. By default false. @return $this
[ "Sets", "the", "virtual", "properties", "on", "this", "entity", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L534-L546
210,447
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.visibleProperties
public function visibleProperties() { $properties = array_keys($this->_properties); $properties = array_merge($properties, $this->_virtual); return array_diff($properties, $this->_hidden); }
php
public function visibleProperties() { $properties = array_keys($this->_properties); $properties = array_merge($properties, $this->_virtual); return array_diff($properties, $this->_hidden); }
[ "public", "function", "visibleProperties", "(", ")", "{", "$", "properties", "=", "array_keys", "(", "$", "this", "->", "_properties", ")", ";", "$", "properties", "=", "array_merge", "(", "$", "properties", ",", "$", "this", "->", "_virtual", ")", ";", "return", "array_diff", "(", "$", "properties", ",", "$", "this", "->", "_hidden", ")", ";", "}" ]
Get the list of visible properties. The list of visible properties is all standard properties plus virtual properties minus hidden properties. @return array A list of properties that are 'visible' in all representations.
[ "Get", "the", "list", "of", "visible", "properties", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L567-L573
210,448
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.extract
public function extract(array $properties, $onlyDirty = false) { $result = []; foreach ($properties as $property) { if (!$onlyDirty || $this->isDirty($property)) { $result[$property] = $this->get($property); } } return $result; }
php
public function extract(array $properties, $onlyDirty = false) { $result = []; foreach ($properties as $property) { if (!$onlyDirty || $this->isDirty($property)) { $result[$property] = $this->get($property); } } return $result; }
[ "public", "function", "extract", "(", "array", "$", "properties", ",", "$", "onlyDirty", "=", "false", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "properties", "as", "$", "property", ")", "{", "if", "(", "!", "$", "onlyDirty", "||", "$", "this", "->", "isDirty", "(", "$", "property", ")", ")", "{", "$", "result", "[", "$", "property", "]", "=", "$", "this", "->", "get", "(", "$", "property", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns an array with the requested properties stored in this entity, indexed by property name @param array $properties list of properties to be returned @param bool $onlyDirty Return the requested property only if it is dirty @return array
[ "Returns", "an", "array", "with", "the", "requested", "properties", "stored", "in", "this", "entity", "indexed", "by", "property", "name" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L715-L725
210,449
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.extractOriginal
public function extractOriginal(array $properties) { $result = []; foreach ($properties as $property) { $result[$property] = $this->getOriginal($property); } return $result; }
php
public function extractOriginal(array $properties) { $result = []; foreach ($properties as $property) { $result[$property] = $this->getOriginal($property); } return $result; }
[ "public", "function", "extractOriginal", "(", "array", "$", "properties", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "properties", "as", "$", "property", ")", "{", "$", "result", "[", "$", "property", "]", "=", "$", "this", "->", "getOriginal", "(", "$", "property", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns an array with the requested original properties stored in this entity, indexed by property name. Properties that are unchanged from their original value will be included in the return of this method. @param array $properties List of properties to be returned @return array
[ "Returns", "an", "array", "with", "the", "requested", "original", "properties", "stored", "in", "this", "entity", "indexed", "by", "property", "name", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L737-L745
210,450
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.extractOriginalChanged
public function extractOriginalChanged(array $properties) { $result = []; foreach ($properties as $property) { $original = $this->getOriginal($property); if ($original !== $this->get($property)) { $result[$property] = $original; } } return $result; }
php
public function extractOriginalChanged(array $properties) { $result = []; foreach ($properties as $property) { $original = $this->getOriginal($property); if ($original !== $this->get($property)) { $result[$property] = $original; } } return $result; }
[ "public", "function", "extractOriginalChanged", "(", "array", "$", "properties", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "properties", "as", "$", "property", ")", "{", "$", "original", "=", "$", "this", "->", "getOriginal", "(", "$", "property", ")", ";", "if", "(", "$", "original", "!==", "$", "this", "->", "get", "(", "$", "property", ")", ")", "{", "$", "result", "[", "$", "property", "]", "=", "$", "original", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns an array with only the original properties stored in this entity, indexed by property name. This method will only return properties that have been modified since the entity was built. Unchanged properties will be omitted. @param array $properties List of properties to be returned @return array
[ "Returns", "an", "array", "with", "only", "the", "original", "properties", "stored", "in", "this", "entity", "indexed", "by", "property", "name", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L757-L768
210,451
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.dirty
public function dirty($property = null, $isDirty = null) { deprecationWarning( get_called_class() . '::dirty() is deprecated. ' . 'Use setDirty()/isDirty() instead.' ); if ($property === null) { return $this->isDirty(); } if ($isDirty === null) { return $this->isDirty($property); } $this->setDirty($property, $isDirty); return true; }
php
public function dirty($property = null, $isDirty = null) { deprecationWarning( get_called_class() . '::dirty() is deprecated. ' . 'Use setDirty()/isDirty() instead.' ); if ($property === null) { return $this->isDirty(); } if ($isDirty === null) { return $this->isDirty($property); } $this->setDirty($property, $isDirty); return true; }
[ "public", "function", "dirty", "(", "$", "property", "=", "null", ",", "$", "isDirty", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::dirty() is deprecated. '", ".", "'Use setDirty()/isDirty() instead.'", ")", ";", "if", "(", "$", "property", "===", "null", ")", "{", "return", "$", "this", "->", "isDirty", "(", ")", ";", "}", "if", "(", "$", "isDirty", "===", "null", ")", "{", "return", "$", "this", "->", "isDirty", "(", "$", "property", ")", ";", "}", "$", "this", "->", "setDirty", "(", "$", "property", ",", "$", "isDirty", ")", ";", "return", "true", ";", "}" ]
Sets the dirty status of a single property. If called with no second argument, it will return whether the property was modified or not after the object creation. When called with no arguments it will return whether or not there are any dirty property in the entity @deprecated 3.4.0 Use EntityTrait::setDirty() and EntityTrait::isDirty() @param string|null $property the field to set or check status for @param null|bool $isDirty true means the property was changed, false means it was not changed and null will make the function return current state for that property @return bool Whether the property was changed or not
[ "Sets", "the", "dirty", "status", "of", "a", "single", "property", ".", "If", "called", "with", "no", "second", "argument", "it", "will", "return", "whether", "the", "property", "was", "modified", "or", "not", "after", "the", "object", "creation", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L785-L802
210,452
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.setDirty
public function setDirty($property, $isDirty = true) { if ($isDirty === false) { unset($this->_dirty[$property]); return $this; } $this->_dirty[$property] = true; unset($this->_errors[$property], $this->_invalid[$property]); return $this; }
php
public function setDirty($property, $isDirty = true) { if ($isDirty === false) { unset($this->_dirty[$property]); return $this; } $this->_dirty[$property] = true; unset($this->_errors[$property], $this->_invalid[$property]); return $this; }
[ "public", "function", "setDirty", "(", "$", "property", ",", "$", "isDirty", "=", "true", ")", "{", "if", "(", "$", "isDirty", "===", "false", ")", "{", "unset", "(", "$", "this", "->", "_dirty", "[", "$", "property", "]", ")", ";", "return", "$", "this", ";", "}", "$", "this", "->", "_dirty", "[", "$", "property", "]", "=", "true", ";", "unset", "(", "$", "this", "->", "_errors", "[", "$", "property", "]", ",", "$", "this", "->", "_invalid", "[", "$", "property", "]", ")", ";", "return", "$", "this", ";", "}" ]
Sets the dirty status of a single property. @param string $property the field to set or check status for @param bool $isDirty true means the property was changed, false means it was not changed. Defaults to true. @return $this
[ "Sets", "the", "dirty", "status", "of", "a", "single", "property", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L812-L824
210,453
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.isDirty
public function isDirty($property = null) { if ($property === null) { return !empty($this->_dirty); } return isset($this->_dirty[$property]); }
php
public function isDirty($property = null) { if ($property === null) { return !empty($this->_dirty); } return isset($this->_dirty[$property]); }
[ "public", "function", "isDirty", "(", "$", "property", "=", "null", ")", "{", "if", "(", "$", "property", "===", "null", ")", "{", "return", "!", "empty", "(", "$", "this", "->", "_dirty", ")", ";", "}", "return", "isset", "(", "$", "this", "->", "_dirty", "[", "$", "property", "]", ")", ";", "}" ]
Checks if the entity is dirty or if a single property of it is dirty. @param string|null $property The field to check the status for. Null for the whole entity. @return bool Whether the property was changed or not
[ "Checks", "if", "the", "entity", "is", "dirty", "or", "if", "a", "single", "property", "of", "it", "is", "dirty", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L832-L839
210,454
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.isNew
public function isNew($new = null) { if ($new === null) { return $this->_new; } $new = (bool)$new; if ($new) { foreach ($this->_properties as $k => $p) { $this->_dirty[$k] = true; } } return $this->_new = $new; }
php
public function isNew($new = null) { if ($new === null) { return $this->_new; } $new = (bool)$new; if ($new) { foreach ($this->_properties as $k => $p) { $this->_dirty[$k] = true; } } return $this->_new = $new; }
[ "public", "function", "isNew", "(", "$", "new", "=", "null", ")", "{", "if", "(", "$", "new", "===", "null", ")", "{", "return", "$", "this", "->", "_new", ";", "}", "$", "new", "=", "(", "bool", ")", "$", "new", ";", "if", "(", "$", "new", ")", "{", "foreach", "(", "$", "this", "->", "_properties", "as", "$", "k", "=>", "$", "p", ")", "{", "$", "this", "->", "_dirty", "[", "$", "k", "]", "=", "true", ";", "}", "}", "return", "$", "this", "->", "_new", "=", "$", "new", ";", "}" ]
Returns whether or not this entity has already been persisted. This method can return null in the case there is no prior information on the status of this entity. If called with a boolean it will set the known status of this instance, true means that the instance is not yet persisted in the database, false that it already is. @param bool|null $new true if it is known this instance was not yet persisted @return bool Whether or not the entity has been persisted.
[ "Returns", "whether", "or", "not", "this", "entity", "has", "already", "been", "persisted", ".", "This", "method", "can", "return", "null", "in", "the", "case", "there", "is", "no", "prior", "information", "on", "the", "status", "of", "this", "entity", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L878-L893
210,455
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.hasErrors
public function hasErrors($includeNested = true) { if (Hash::filter($this->_errors)) { return true; } if ($includeNested === false) { return false; } foreach ($this->_properties as $property) { if ($this->_readHasErrors($property)) { return true; } } return false; }
php
public function hasErrors($includeNested = true) { if (Hash::filter($this->_errors)) { return true; } if ($includeNested === false) { return false; } foreach ($this->_properties as $property) { if ($this->_readHasErrors($property)) { return true; } } return false; }
[ "public", "function", "hasErrors", "(", "$", "includeNested", "=", "true", ")", "{", "if", "(", "Hash", "::", "filter", "(", "$", "this", "->", "_errors", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "includeNested", "===", "false", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "this", "->", "_properties", "as", "$", "property", ")", "{", "if", "(", "$", "this", "->", "_readHasErrors", "(", "$", "property", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns whether this entity has errors. @param bool $includeNested true will check nested entities for hasErrors() @return bool
[ "Returns", "whether", "this", "entity", "has", "errors", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L901-L918
210,456
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.getErrors
public function getErrors() { $diff = array_diff_key($this->_properties, $this->_errors); return $this->_errors + (new Collection($diff)) ->filter(function ($value) { return is_array($value) || $value instanceof EntityInterface; }) ->map(function ($value) { return $this->_readError($value); }) ->filter() ->toArray(); }
php
public function getErrors() { $diff = array_diff_key($this->_properties, $this->_errors); return $this->_errors + (new Collection($diff)) ->filter(function ($value) { return is_array($value) || $value instanceof EntityInterface; }) ->map(function ($value) { return $this->_readError($value); }) ->filter() ->toArray(); }
[ "public", "function", "getErrors", "(", ")", "{", "$", "diff", "=", "array_diff_key", "(", "$", "this", "->", "_properties", ",", "$", "this", "->", "_errors", ")", ";", "return", "$", "this", "->", "_errors", "+", "(", "new", "Collection", "(", "$", "diff", ")", ")", "->", "filter", "(", "function", "(", "$", "value", ")", "{", "return", "is_array", "(", "$", "value", ")", "||", "$", "value", "instanceof", "EntityInterface", ";", "}", ")", "->", "map", "(", "function", "(", "$", "value", ")", "{", "return", "$", "this", "->", "_readError", "(", "$", "value", ")", ";", "}", ")", "->", "filter", "(", ")", "->", "toArray", "(", ")", ";", "}" ]
Returns all validation errors. @return array
[ "Returns", "all", "validation", "errors", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L925-L938
210,457
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.getError
public function getError($field) { $errors = isset($this->_errors[$field]) ? $this->_errors[$field] : []; if ($errors) { return $errors; } return $this->_nestedErrors($field); }
php
public function getError($field) { $errors = isset($this->_errors[$field]) ? $this->_errors[$field] : []; if ($errors) { return $errors; } return $this->_nestedErrors($field); }
[ "public", "function", "getError", "(", "$", "field", ")", "{", "$", "errors", "=", "isset", "(", "$", "this", "->", "_errors", "[", "$", "field", "]", ")", "?", "$", "this", "->", "_errors", "[", "$", "field", "]", ":", "[", "]", ";", "if", "(", "$", "errors", ")", "{", "return", "$", "errors", ";", "}", "return", "$", "this", "->", "_nestedErrors", "(", "$", "field", ")", ";", "}" ]
Returns validation errors of a field @param string $field Field name to get the errors from @return array
[ "Returns", "validation", "errors", "of", "a", "field" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L946-L954
210,458
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.setErrors
public function setErrors(array $fields, $overwrite = false) { if ($overwrite) { foreach ($fields as $f => $error) { $this->_errors[$f] = (array)$error; } return $this; } foreach ($fields as $f => $error) { $this->_errors += [$f => []]; // String messages are appended to the list, // while more complex error structures need their // keys preserved for nested validator. if (is_string($error)) { $this->_errors[$f][] = $error; } else { foreach ($error as $k => $v) { $this->_errors[$f][$k] = $v; } } } return $this; }
php
public function setErrors(array $fields, $overwrite = false) { if ($overwrite) { foreach ($fields as $f => $error) { $this->_errors[$f] = (array)$error; } return $this; } foreach ($fields as $f => $error) { $this->_errors += [$f => []]; // String messages are appended to the list, // while more complex error structures need their // keys preserved for nested validator. if (is_string($error)) { $this->_errors[$f][] = $error; } else { foreach ($error as $k => $v) { $this->_errors[$f][$k] = $v; } } } return $this; }
[ "public", "function", "setErrors", "(", "array", "$", "fields", ",", "$", "overwrite", "=", "false", ")", "{", "if", "(", "$", "overwrite", ")", "{", "foreach", "(", "$", "fields", "as", "$", "f", "=>", "$", "error", ")", "{", "$", "this", "->", "_errors", "[", "$", "f", "]", "=", "(", "array", ")", "$", "error", ";", "}", "return", "$", "this", ";", "}", "foreach", "(", "$", "fields", "as", "$", "f", "=>", "$", "error", ")", "{", "$", "this", "->", "_errors", "+=", "[", "$", "f", "=>", "[", "]", "]", ";", "// String messages are appended to the list,", "// while more complex error structures need their", "// keys preserved for nested validator.", "if", "(", "is_string", "(", "$", "error", ")", ")", "{", "$", "this", "->", "_errors", "[", "$", "f", "]", "[", "]", "=", "$", "error", ";", "}", "else", "{", "foreach", "(", "$", "error", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "_errors", "[", "$", "f", "]", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Sets error messages to the entity ## Example ``` // Sets the error messages for multiple fields at once $entity->setErrors(['salary' => ['message'], 'name' => ['another message']]); ``` @param array $fields The array of errors to set. @param bool $overwrite Whether or not to overwrite pre-existing errors for $fields @return $this
[ "Sets", "error", "messages", "to", "the", "entity" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L970-L996
210,459
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.setError
public function setError($field, $errors, $overwrite = false) { if (is_string($errors)) { $errors = [$errors]; } return $this->setErrors([$field => $errors], $overwrite); }
php
public function setError($field, $errors, $overwrite = false) { if (is_string($errors)) { $errors = [$errors]; } return $this->setErrors([$field => $errors], $overwrite); }
[ "public", "function", "setError", "(", "$", "field", ",", "$", "errors", ",", "$", "overwrite", "=", "false", ")", "{", "if", "(", "is_string", "(", "$", "errors", ")", ")", "{", "$", "errors", "=", "[", "$", "errors", "]", ";", "}", "return", "$", "this", "->", "setErrors", "(", "[", "$", "field", "=>", "$", "errors", "]", ",", "$", "overwrite", ")", ";", "}" ]
Sets errors for a single field ### Example ``` // Sets the error messages for a single field $entity->setError('salary', ['must be numeric', 'must be a positive number']); ``` @param string $field The field to get errors for, or the array of errors to set. @param string|array $errors The errors to be set for $field @param bool $overwrite Whether or not to overwrite pre-existing errors for $field @return $this
[ "Sets", "errors", "for", "a", "single", "field" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L1013-L1020
210,460
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.errors
public function errors($field = null, $errors = null, $overwrite = false) { deprecationWarning( get_called_class() . '::errors() is deprecated. ' . 'Use setError()/getError() or setErrors()/getErrors() instead.' ); if ($field === null) { return $this->getErrors(); } if (is_string($field) && $errors === null) { return $this->getError($field); } if (!is_array($field)) { $field = [$field => $errors]; } return $this->setErrors($field, $overwrite); }
php
public function errors($field = null, $errors = null, $overwrite = false) { deprecationWarning( get_called_class() . '::errors() is deprecated. ' . 'Use setError()/getError() or setErrors()/getErrors() instead.' ); if ($field === null) { return $this->getErrors(); } if (is_string($field) && $errors === null) { return $this->getError($field); } if (!is_array($field)) { $field = [$field => $errors]; } return $this->setErrors($field, $overwrite); }
[ "public", "function", "errors", "(", "$", "field", "=", "null", ",", "$", "errors", "=", "null", ",", "$", "overwrite", "=", "false", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::errors() is deprecated. '", ".", "'Use setError()/getError() or setErrors()/getErrors() instead.'", ")", ";", "if", "(", "$", "field", "===", "null", ")", "{", "return", "$", "this", "->", "getErrors", "(", ")", ";", "}", "if", "(", "is_string", "(", "$", "field", ")", "&&", "$", "errors", "===", "null", ")", "{", "return", "$", "this", "->", "getError", "(", "$", "field", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "field", ")", ")", "{", "$", "field", "=", "[", "$", "field", "=>", "$", "errors", "]", ";", "}", "return", "$", "this", "->", "setErrors", "(", "$", "field", ",", "$", "overwrite", ")", ";", "}" ]
Sets the error messages for a field or a list of fields. When called without the second argument it returns the validation errors for the specified fields. If called with no arguments it returns all the validation error messages stored in this entity and any other nested entity. ### Example ``` // Sets the error messages for a single field $entity->errors('salary', ['must be numeric', 'must be a positive number']); // Returns the error messages for a single field $entity->getErrors('salary'); // Returns all error messages indexed by field name $entity->getErrors(); // Sets the error messages for multiple fields at once $entity->getErrors(['salary' => ['message'], 'name' => ['another message']); ``` When used as a setter, this method will return this entity instance for method chaining. @deprecated 3.4.0 Use EntityTrait::setError(), EntityTrait::setErrors(), EntityTrait::getError() and EntityTrait::getErrors() @param string|array|null $field The field to get errors for, or the array of errors to set. @param string|array|null $errors The errors to be set for $field @param bool $overwrite Whether or not to overwrite pre-existing errors for $field @return array|$this
[ "Sets", "the", "error", "messages", "for", "a", "field", "or", "a", "list", "of", "fields", ".", "When", "called", "without", "the", "second", "argument", "it", "returns", "the", "validation", "errors", "for", "the", "specified", "fields", ".", "If", "called", "with", "no", "arguments", "it", "returns", "all", "the", "validation", "error", "messages", "stored", "in", "this", "entity", "and", "any", "other", "nested", "entity", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L1054-L1073
210,461
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait._nestedErrors
protected function _nestedErrors($field) { $path = explode('.', $field); // Only one path element, check for nested entity with error. if (count($path) === 1) { return $this->_readError($this->get($path[0])); } $entity = $this; $len = count($path); while ($len) { $part = array_shift($path); $len = count($path); $val = null; if ($entity instanceof EntityInterface) { $val = $entity->get($part); } elseif (is_array($entity)) { $val = isset($entity[$part]) ? $entity[$part] : false; } if (is_array($val) || $val instanceof Traversable || $val instanceof EntityInterface ) { $entity = $val; } else { $path[] = $part; break; } } if (count($path) <= 1) { return $this->_readError($entity, array_pop($path)); } return []; }
php
protected function _nestedErrors($field) { $path = explode('.', $field); // Only one path element, check for nested entity with error. if (count($path) === 1) { return $this->_readError($this->get($path[0])); } $entity = $this; $len = count($path); while ($len) { $part = array_shift($path); $len = count($path); $val = null; if ($entity instanceof EntityInterface) { $val = $entity->get($part); } elseif (is_array($entity)) { $val = isset($entity[$part]) ? $entity[$part] : false; } if (is_array($val) || $val instanceof Traversable || $val instanceof EntityInterface ) { $entity = $val; } else { $path[] = $part; break; } } if (count($path) <= 1) { return $this->_readError($entity, array_pop($path)); } return []; }
[ "protected", "function", "_nestedErrors", "(", "$", "field", ")", "{", "$", "path", "=", "explode", "(", "'.'", ",", "$", "field", ")", ";", "// Only one path element, check for nested entity with error.", "if", "(", "count", "(", "$", "path", ")", "===", "1", ")", "{", "return", "$", "this", "->", "_readError", "(", "$", "this", "->", "get", "(", "$", "path", "[", "0", "]", ")", ")", ";", "}", "$", "entity", "=", "$", "this", ";", "$", "len", "=", "count", "(", "$", "path", ")", ";", "while", "(", "$", "len", ")", "{", "$", "part", "=", "array_shift", "(", "$", "path", ")", ";", "$", "len", "=", "count", "(", "$", "path", ")", ";", "$", "val", "=", "null", ";", "if", "(", "$", "entity", "instanceof", "EntityInterface", ")", "{", "$", "val", "=", "$", "entity", "->", "get", "(", "$", "part", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "entity", ")", ")", "{", "$", "val", "=", "isset", "(", "$", "entity", "[", "$", "part", "]", ")", "?", "$", "entity", "[", "$", "part", "]", ":", "false", ";", "}", "if", "(", "is_array", "(", "$", "val", ")", "||", "$", "val", "instanceof", "Traversable", "||", "$", "val", "instanceof", "EntityInterface", ")", "{", "$", "entity", "=", "$", "val", ";", "}", "else", "{", "$", "path", "[", "]", "=", "$", "part", ";", "break", ";", "}", "}", "if", "(", "count", "(", "$", "path", ")", "<=", "1", ")", "{", "return", "$", "this", "->", "_readError", "(", "$", "entity", ",", "array_pop", "(", "$", "path", ")", ")", ";", "}", "return", "[", "]", ";", "}" ]
Auxiliary method for getting errors in nested entities @param string $field the field in this entity to check for errors @return array errors in nested entity if any
[ "Auxiliary", "method", "for", "getting", "errors", "in", "nested", "entities" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L1081-L1117
210,462
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait._readHasErrors
protected function _readHasErrors($object) { if ($object instanceof EntityInterface && $object->hasErrors()) { return true; } if (is_array($object)) { foreach ($object as $value) { if ($this->_readHasErrors($value)) { return true; } } } return false; }
php
protected function _readHasErrors($object) { if ($object instanceof EntityInterface && $object->hasErrors()) { return true; } if (is_array($object)) { foreach ($object as $value) { if ($this->_readHasErrors($value)) { return true; } } } return false; }
[ "protected", "function", "_readHasErrors", "(", "$", "object", ")", "{", "if", "(", "$", "object", "instanceof", "EntityInterface", "&&", "$", "object", "->", "hasErrors", "(", ")", ")", "{", "return", "true", ";", "}", "if", "(", "is_array", "(", "$", "object", ")", ")", "{", "foreach", "(", "$", "object", "as", "$", "value", ")", "{", "if", "(", "$", "this", "->", "_readHasErrors", "(", "$", "value", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Reads if there are errors for one or many objects. @param mixed $object The object to read errors from. @return bool
[ "Reads", "if", "there", "are", "errors", "for", "one", "or", "many", "objects", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L1125-L1140
210,463
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.getInvalidField
public function getInvalidField($field) { $value = isset($this->_invalid[$field]) ? $this->_invalid[$field] : null; return $value; }
php
public function getInvalidField($field) { $value = isset($this->_invalid[$field]) ? $this->_invalid[$field] : null; return $value; }
[ "public", "function", "getInvalidField", "(", "$", "field", ")", "{", "$", "value", "=", "isset", "(", "$", "this", "->", "_invalid", "[", "$", "field", "]", ")", "?", "$", "this", "->", "_invalid", "[", "$", "field", "]", ":", "null", ";", "return", "$", "value", ";", "}" ]
Get a single value of an invalid field. Returns null if not set. @param string $field The name of the field. @return mixed
[ "Get", "a", "single", "value", "of", "an", "invalid", "field", ".", "Returns", "null", "if", "not", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L1186-L1191
210,464
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.setInvalid
public function setInvalid(array $fields, $overwrite = false) { foreach ($fields as $field => $value) { if ($overwrite === true) { $this->_invalid[$field] = $value; continue; } $this->_invalid += [$field => $value]; } return $this; }
php
public function setInvalid(array $fields, $overwrite = false) { foreach ($fields as $field => $value) { if ($overwrite === true) { $this->_invalid[$field] = $value; continue; } $this->_invalid += [$field => $value]; } return $this; }
[ "public", "function", "setInvalid", "(", "array", "$", "fields", ",", "$", "overwrite", "=", "false", ")", "{", "foreach", "(", "$", "fields", "as", "$", "field", "=>", "$", "value", ")", "{", "if", "(", "$", "overwrite", "===", "true", ")", "{", "$", "this", "->", "_invalid", "[", "$", "field", "]", "=", "$", "value", ";", "continue", ";", "}", "$", "this", "->", "_invalid", "+=", "[", "$", "field", "=>", "$", "value", "]", ";", "}", "return", "$", "this", ";", "}" ]
Set fields as invalid and not patchable into the entity. This is useful for batch operations when one needs to get the original value for an error message after patching. This value could not be patched into the entity and is simply copied into the _invalid property for debugging purposes or to be able to log it away. @param array $fields The values to set. @param bool $overwrite Whether or not to overwrite pre-existing values for $field. @return $this
[ "Set", "fields", "as", "invalid", "and", "not", "patchable", "into", "the", "entity", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L1204-L1215
210,465
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.invalid
public function invalid($field = null, $value = null, $overwrite = false) { deprecationWarning( get_called_class() . '::invalid() is deprecated. ' . 'Use setInvalid()/getInvalid()/getInvalidField() instead.' ); if ($field === null) { return $this->_invalid; } if (is_string($field) && $value === null) { $value = isset($this->_invalid[$field]) ? $this->_invalid[$field] : null; return $value; } if (!is_array($field)) { $field = [$field => $value]; } foreach ($field as $f => $value) { if ($overwrite) { $this->_invalid[$f] = $value; continue; } $this->_invalid += [$f => $value]; } return $this; }
php
public function invalid($field = null, $value = null, $overwrite = false) { deprecationWarning( get_called_class() . '::invalid() is deprecated. ' . 'Use setInvalid()/getInvalid()/getInvalidField() instead.' ); if ($field === null) { return $this->_invalid; } if (is_string($field) && $value === null) { $value = isset($this->_invalid[$field]) ? $this->_invalid[$field] : null; return $value; } if (!is_array($field)) { $field = [$field => $value]; } foreach ($field as $f => $value) { if ($overwrite) { $this->_invalid[$f] = $value; continue; } $this->_invalid += [$f => $value]; } return $this; }
[ "public", "function", "invalid", "(", "$", "field", "=", "null", ",", "$", "value", "=", "null", ",", "$", "overwrite", "=", "false", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::invalid() is deprecated. '", ".", "'Use setInvalid()/getInvalid()/getInvalidField() instead.'", ")", ";", "if", "(", "$", "field", "===", "null", ")", "{", "return", "$", "this", "->", "_invalid", ";", "}", "if", "(", "is_string", "(", "$", "field", ")", "&&", "$", "value", "===", "null", ")", "{", "$", "value", "=", "isset", "(", "$", "this", "->", "_invalid", "[", "$", "field", "]", ")", "?", "$", "this", "->", "_invalid", "[", "$", "field", "]", ":", "null", ";", "return", "$", "value", ";", "}", "if", "(", "!", "is_array", "(", "$", "field", ")", ")", "{", "$", "field", "=", "[", "$", "field", "=>", "$", "value", "]", ";", "}", "foreach", "(", "$", "field", "as", "$", "f", "=>", "$", "value", ")", "{", "if", "(", "$", "overwrite", ")", "{", "$", "this", "->", "_invalid", "[", "$", "f", "]", "=", "$", "value", ";", "continue", ";", "}", "$", "this", "->", "_invalid", "+=", "[", "$", "f", "=>", "$", "value", "]", ";", "}", "return", "$", "this", ";", "}" ]
Sets a field as invalid and not patchable into the entity. This is useful for batch operations when one needs to get the original value for an error message after patching. This value could not be patched into the entity and is simply copied into the _invalid property for debugging purposes or to be able to log it away. @deprecated 3.5 Use getInvalid()/getInvalidField()/setInvalid() instead. @param string|array|null $field The field to get invalid value for, or the value to set. @param mixed|null $value The invalid value to be set for $field. @param bool $overwrite Whether or not to overwrite pre-existing values for $field. @return $this|mixed
[ "Sets", "a", "field", "as", "invalid", "and", "not", "patchable", "into", "the", "entity", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L1244-L1273
210,466
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.isAccessible
public function isAccessible($property) { $value = isset($this->_accessible[$property]) ? $this->_accessible[$property] : null; return ($value === null && !empty($this->_accessible['*'])) || $value; }
php
public function isAccessible($property) { $value = isset($this->_accessible[$property]) ? $this->_accessible[$property] : null; return ($value === null && !empty($this->_accessible['*'])) || $value; }
[ "public", "function", "isAccessible", "(", "$", "property", ")", "{", "$", "value", "=", "isset", "(", "$", "this", "->", "_accessible", "[", "$", "property", "]", ")", "?", "$", "this", "->", "_accessible", "[", "$", "property", "]", ":", "null", ";", "return", "(", "$", "value", "===", "null", "&&", "!", "empty", "(", "$", "this", "->", "_accessible", "[", "'*'", "]", ")", ")", "||", "$", "value", ";", "}" ]
Checks if a property is accessible ### Example: ``` $entity->isAccessible('id'); // Returns whether it can be set or not ``` @param string $property Property name to check @return bool
[ "Checks", "if", "a", "property", "is", "accessible" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L1376-L1383
210,467
cakephp/cakephp
src/Datasource/EntityTrait.php
EntityTrait.source
public function source($alias = null) { deprecationWarning( get_called_class() . '::source() is deprecated. ' . 'Use setSource()/getSource() instead.' ); if ($alias === null) { return $this->getSource(); } $this->setSource($alias); return $this; }
php
public function source($alias = null) { deprecationWarning( get_called_class() . '::source() is deprecated. ' . 'Use setSource()/getSource() instead.' ); if ($alias === null) { return $this->getSource(); } $this->setSource($alias); return $this; }
[ "public", "function", "source", "(", "$", "alias", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::source() is deprecated. '", ".", "'Use setSource()/getSource() instead.'", ")", ";", "if", "(", "$", "alias", "===", "null", ")", "{", "return", "$", "this", "->", "getSource", "(", ")", ";", "}", "$", "this", "->", "setSource", "(", "$", "alias", ")", ";", "return", "$", "this", ";", "}" ]
Returns the alias of the repository from which this entity came from. If called with no arguments, it returns the alias of the repository this entity came from if it is known. @deprecated 3.4.0 Use EntityTrait::getSource() and EntityTrait::setSource() @param string|null $alias the alias of the repository @return string|$this
[ "Returns", "the", "alias", "of", "the", "repository", "from", "which", "this", "entity", "came", "from", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/EntityTrait.php#L1418-L1431
210,468
cakephp/cakephp
src/Shell/Task/AssetsTask.php
AssetsTask.copy
public function copy($name = null) { $this->_process($this->_list($name), true, $this->param('overwrite')); }
php
public function copy($name = null) { $this->_process($this->_list($name), true, $this->param('overwrite')); }
[ "public", "function", "copy", "(", "$", "name", "=", "null", ")", "{", "$", "this", "->", "_process", "(", "$", "this", "->", "_list", "(", "$", "name", ")", ",", "true", ",", "$", "this", "->", "param", "(", "'overwrite'", ")", ")", ";", "}" ]
Copying plugin assets to app's webroot. For vendor namespaced plugin, parent folder for vendor name are created if required. @param string|null $name Name of plugin for which to symlink assets. If null all plugins will be processed. @return void
[ "Copying", "plugin", "assets", "to", "app", "s", "webroot", ".", "For", "vendor", "namespaced", "plugin", "parent", "folder", "for", "vendor", "name", "are", "created", "if", "required", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/AssetsTask.php#L50-L53
210,469
cakephp/cakephp
src/Shell/Task/AssetsTask.php
AssetsTask.remove
public function remove($name = null) { $plugins = $this->_list($name); foreach ($plugins as $plugin => $config) { $this->out(); $this->out('For plugin: ' . $plugin); $this->hr(); $this->_remove($config); } $this->out(); $this->out('Done'); }
php
public function remove($name = null) { $plugins = $this->_list($name); foreach ($plugins as $plugin => $config) { $this->out(); $this->out('For plugin: ' . $plugin); $this->hr(); $this->_remove($config); } $this->out(); $this->out('Done'); }
[ "public", "function", "remove", "(", "$", "name", "=", "null", ")", "{", "$", "plugins", "=", "$", "this", "->", "_list", "(", "$", "name", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "config", ")", "{", "$", "this", "->", "out", "(", ")", ";", "$", "this", "->", "out", "(", "'For plugin: '", ".", "$", "plugin", ")", ";", "$", "this", "->", "hr", "(", ")", ";", "$", "this", "->", "_remove", "(", "$", "config", ")", ";", "}", "$", "this", "->", "out", "(", ")", ";", "$", "this", "->", "out", "(", "'Done'", ")", ";", "}" ]
Remove plugin assets from app's webroot. @param string|null $name Name of plugin for which to remove assets. If null all plugins will be processed. @return void @since 3.5.12
[ "Remove", "plugin", "assets", "from", "app", "s", "webroot", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/AssetsTask.php#L63-L77
210,470
cakephp/cakephp
src/Shell/Task/AssetsTask.php
AssetsTask._list
protected function _list($name = null) { if ($name === null) { $pluginsList = Plugin::loaded(); } else { if (!Plugin::isLoaded($name)) { $this->err(sprintf('Plugin %s is not loaded.', $name)); return []; } $pluginsList = [$name]; } $plugins = []; foreach ($pluginsList as $plugin) { $path = Plugin::path($plugin) . 'webroot'; if (!is_dir($path)) { $this->verbose('', 1); $this->verbose( sprintf('Skipping plugin %s. It does not have webroot folder.', $plugin), 2 ); continue; } $link = Inflector::underscore($plugin); $dir = WWW_ROOT; $namespaced = false; if (strpos($link, '/') !== false) { $namespaced = true; $parts = explode('/', $link); $link = array_pop($parts); $dir = WWW_ROOT . implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR; } $plugins[$plugin] = [ 'srcPath' => Plugin::path($plugin) . 'webroot', 'destDir' => $dir, 'link' => $link, 'namespaced' => $namespaced ]; } return $plugins; }
php
protected function _list($name = null) { if ($name === null) { $pluginsList = Plugin::loaded(); } else { if (!Plugin::isLoaded($name)) { $this->err(sprintf('Plugin %s is not loaded.', $name)); return []; } $pluginsList = [$name]; } $plugins = []; foreach ($pluginsList as $plugin) { $path = Plugin::path($plugin) . 'webroot'; if (!is_dir($path)) { $this->verbose('', 1); $this->verbose( sprintf('Skipping plugin %s. It does not have webroot folder.', $plugin), 2 ); continue; } $link = Inflector::underscore($plugin); $dir = WWW_ROOT; $namespaced = false; if (strpos($link, '/') !== false) { $namespaced = true; $parts = explode('/', $link); $link = array_pop($parts); $dir = WWW_ROOT . implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR; } $plugins[$plugin] = [ 'srcPath' => Plugin::path($plugin) . 'webroot', 'destDir' => $dir, 'link' => $link, 'namespaced' => $namespaced ]; } return $plugins; }
[ "protected", "function", "_list", "(", "$", "name", "=", "null", ")", "{", "if", "(", "$", "name", "===", "null", ")", "{", "$", "pluginsList", "=", "Plugin", "::", "loaded", "(", ")", ";", "}", "else", "{", "if", "(", "!", "Plugin", "::", "isLoaded", "(", "$", "name", ")", ")", "{", "$", "this", "->", "err", "(", "sprintf", "(", "'Plugin %s is not loaded.'", ",", "$", "name", ")", ")", ";", "return", "[", "]", ";", "}", "$", "pluginsList", "=", "[", "$", "name", "]", ";", "}", "$", "plugins", "=", "[", "]", ";", "foreach", "(", "$", "pluginsList", "as", "$", "plugin", ")", "{", "$", "path", "=", "Plugin", "::", "path", "(", "$", "plugin", ")", ".", "'webroot'", ";", "if", "(", "!", "is_dir", "(", "$", "path", ")", ")", "{", "$", "this", "->", "verbose", "(", "''", ",", "1", ")", ";", "$", "this", "->", "verbose", "(", "sprintf", "(", "'Skipping plugin %s. It does not have webroot folder.'", ",", "$", "plugin", ")", ",", "2", ")", ";", "continue", ";", "}", "$", "link", "=", "Inflector", "::", "underscore", "(", "$", "plugin", ")", ";", "$", "dir", "=", "WWW_ROOT", ";", "$", "namespaced", "=", "false", ";", "if", "(", "strpos", "(", "$", "link", ",", "'/'", ")", "!==", "false", ")", "{", "$", "namespaced", "=", "true", ";", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "link", ")", ";", "$", "link", "=", "array_pop", "(", "$", "parts", ")", ";", "$", "dir", "=", "WWW_ROOT", ".", "implode", "(", "DIRECTORY_SEPARATOR", ",", "$", "parts", ")", ".", "DIRECTORY_SEPARATOR", ";", "}", "$", "plugins", "[", "$", "plugin", "]", "=", "[", "'srcPath'", "=>", "Plugin", "::", "path", "(", "$", "plugin", ")", ".", "'webroot'", ",", "'destDir'", "=>", "$", "dir", ",", "'link'", "=>", "$", "link", ",", "'namespaced'", "=>", "$", "namespaced", "]", ";", "}", "return", "$", "plugins", ";", "}" ]
Get list of plugins to process. Plugins without a webroot directory are skipped. @param string|null $name Name of plugin for which to symlink assets. If null all plugins will be processed. @return array List of plugins with meta data.
[ "Get", "list", "of", "plugins", "to", "process", ".", "Plugins", "without", "a", "webroot", "directory", "are", "skipped", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/AssetsTask.php#L86-L131
210,471
cakephp/cakephp
src/Datasource/ResultSetDecorator.php
ResultSetDecorator.count
public function count() { if ($this->getInnerIterator() instanceof Countable) { return $this->getInnerIterator()->count(); } return count($this->toArray()); }
php
public function count() { if ($this->getInnerIterator() instanceof Countable) { return $this->getInnerIterator()->count(); } return count($this->toArray()); }
[ "public", "function", "count", "(", ")", "{", "if", "(", "$", "this", "->", "getInnerIterator", "(", ")", "instanceof", "Countable", ")", "{", "return", "$", "this", "->", "getInnerIterator", "(", ")", "->", "count", "(", ")", ";", "}", "return", "count", "(", "$", "this", "->", "toArray", "(", ")", ")", ";", "}" ]
Make this object countable. Part of the Countable interface. Calling this method will convert the underlying traversable object into an array and get the count of the underlying data. @return int
[ "Make", "this", "object", "countable", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/ResultSetDecorator.php#L36-L43
210,472
cakephp/cakephp
src/Http/Client/Adapter/Curl.php
Curl.buildOptions
public function buildOptions(Request $request, array $options) { $headers = []; foreach ($request->getHeaders() as $key => $values) { $headers[] = $key . ': ' . implode(', ', $values); } $out = [ CURLOPT_URL => (string)$request->getUri(), CURLOPT_HTTP_VERSION => $request->getProtocolVersion(), CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => $headers ]; switch ($request->getMethod()) { case Request::METHOD_GET: $out[CURLOPT_HTTPGET] = true; break; case Request::METHOD_POST: $out[CURLOPT_POST] = true; break; default: $out[CURLOPT_POST] = true; $out[CURLOPT_CUSTOMREQUEST] = $request->getMethod(); break; } $body = $request->getBody(); if ($body) { $body->rewind(); $out[CURLOPT_POSTFIELDS] = $body->getContents(); } if (empty($options['ssl_cafile'])) { $options['ssl_cafile'] = CORE_PATH . 'config' . DIRECTORY_SEPARATOR . 'cacert.pem'; } if (!empty($options['ssl_verify_host'])) { // Value of 1 or true is deprecated. Only 2 or 0 should be used now. $options['ssl_verify_host'] = 2; } $optionMap = [ 'timeout' => CURLOPT_TIMEOUT, 'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER, 'ssl_verify_host' => CURLOPT_SSL_VERIFYHOST, 'ssl_cafile' => CURLOPT_CAINFO, 'ssl_local_cert' => CURLOPT_SSLCERT, 'ssl_passphrase' => CURLOPT_SSLCERTPASSWD, ]; foreach ($optionMap as $option => $curlOpt) { if (isset($options[$option])) { $out[$curlOpt] = $options[$option]; } } if (isset($options['proxy']['proxy'])) { $out[CURLOPT_PROXY] = $options['proxy']['proxy']; } if (isset($options['proxy']['username'])) { $password = !empty($options['proxy']['password']) ? $options['proxy']['password'] : ''; $out[CURLOPT_PROXYUSERPWD] = $options['proxy']['username'] . ':' . $password; } if (isset($options['curl']) && is_array($options['curl'])) { // Can't use array_merge() because keys will be re-ordered. foreach ($options['curl'] as $key => $value) { $out[$key] = $value; } } return $out; }
php
public function buildOptions(Request $request, array $options) { $headers = []; foreach ($request->getHeaders() as $key => $values) { $headers[] = $key . ': ' . implode(', ', $values); } $out = [ CURLOPT_URL => (string)$request->getUri(), CURLOPT_HTTP_VERSION => $request->getProtocolVersion(), CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => $headers ]; switch ($request->getMethod()) { case Request::METHOD_GET: $out[CURLOPT_HTTPGET] = true; break; case Request::METHOD_POST: $out[CURLOPT_POST] = true; break; default: $out[CURLOPT_POST] = true; $out[CURLOPT_CUSTOMREQUEST] = $request->getMethod(); break; } $body = $request->getBody(); if ($body) { $body->rewind(); $out[CURLOPT_POSTFIELDS] = $body->getContents(); } if (empty($options['ssl_cafile'])) { $options['ssl_cafile'] = CORE_PATH . 'config' . DIRECTORY_SEPARATOR . 'cacert.pem'; } if (!empty($options['ssl_verify_host'])) { // Value of 1 or true is deprecated. Only 2 or 0 should be used now. $options['ssl_verify_host'] = 2; } $optionMap = [ 'timeout' => CURLOPT_TIMEOUT, 'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER, 'ssl_verify_host' => CURLOPT_SSL_VERIFYHOST, 'ssl_cafile' => CURLOPT_CAINFO, 'ssl_local_cert' => CURLOPT_SSLCERT, 'ssl_passphrase' => CURLOPT_SSLCERTPASSWD, ]; foreach ($optionMap as $option => $curlOpt) { if (isset($options[$option])) { $out[$curlOpt] = $options[$option]; } } if (isset($options['proxy']['proxy'])) { $out[CURLOPT_PROXY] = $options['proxy']['proxy']; } if (isset($options['proxy']['username'])) { $password = !empty($options['proxy']['password']) ? $options['proxy']['password'] : ''; $out[CURLOPT_PROXYUSERPWD] = $options['proxy']['username'] . ':' . $password; } if (isset($options['curl']) && is_array($options['curl'])) { // Can't use array_merge() because keys will be re-ordered. foreach ($options['curl'] as $key => $value) { $out[$key] = $value; } } return $out; }
[ "public", "function", "buildOptions", "(", "Request", "$", "request", ",", "array", "$", "options", ")", "{", "$", "headers", "=", "[", "]", ";", "foreach", "(", "$", "request", "->", "getHeaders", "(", ")", "as", "$", "key", "=>", "$", "values", ")", "{", "$", "headers", "[", "]", "=", "$", "key", ".", "': '", ".", "implode", "(", "', '", ",", "$", "values", ")", ";", "}", "$", "out", "=", "[", "CURLOPT_URL", "=>", "(", "string", ")", "$", "request", "->", "getUri", "(", ")", ",", "CURLOPT_HTTP_VERSION", "=>", "$", "request", "->", "getProtocolVersion", "(", ")", ",", "CURLOPT_RETURNTRANSFER", "=>", "true", ",", "CURLOPT_HEADER", "=>", "true", ",", "CURLOPT_HTTPHEADER", "=>", "$", "headers", "]", ";", "switch", "(", "$", "request", "->", "getMethod", "(", ")", ")", "{", "case", "Request", "::", "METHOD_GET", ":", "$", "out", "[", "CURLOPT_HTTPGET", "]", "=", "true", ";", "break", ";", "case", "Request", "::", "METHOD_POST", ":", "$", "out", "[", "CURLOPT_POST", "]", "=", "true", ";", "break", ";", "default", ":", "$", "out", "[", "CURLOPT_POST", "]", "=", "true", ";", "$", "out", "[", "CURLOPT_CUSTOMREQUEST", "]", "=", "$", "request", "->", "getMethod", "(", ")", ";", "break", ";", "}", "$", "body", "=", "$", "request", "->", "getBody", "(", ")", ";", "if", "(", "$", "body", ")", "{", "$", "body", "->", "rewind", "(", ")", ";", "$", "out", "[", "CURLOPT_POSTFIELDS", "]", "=", "$", "body", "->", "getContents", "(", ")", ";", "}", "if", "(", "empty", "(", "$", "options", "[", "'ssl_cafile'", "]", ")", ")", "{", "$", "options", "[", "'ssl_cafile'", "]", "=", "CORE_PATH", ".", "'config'", ".", "DIRECTORY_SEPARATOR", ".", "'cacert.pem'", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'ssl_verify_host'", "]", ")", ")", "{", "// Value of 1 or true is deprecated. Only 2 or 0 should be used now.", "$", "options", "[", "'ssl_verify_host'", "]", "=", "2", ";", "}", "$", "optionMap", "=", "[", "'timeout'", "=>", "CURLOPT_TIMEOUT", ",", "'ssl_verify_peer'", "=>", "CURLOPT_SSL_VERIFYPEER", ",", "'ssl_verify_host'", "=>", "CURLOPT_SSL_VERIFYHOST", ",", "'ssl_cafile'", "=>", "CURLOPT_CAINFO", ",", "'ssl_local_cert'", "=>", "CURLOPT_SSLCERT", ",", "'ssl_passphrase'", "=>", "CURLOPT_SSLCERTPASSWD", ",", "]", ";", "foreach", "(", "$", "optionMap", "as", "$", "option", "=>", "$", "curlOpt", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "$", "option", "]", ")", ")", "{", "$", "out", "[", "$", "curlOpt", "]", "=", "$", "options", "[", "$", "option", "]", ";", "}", "}", "if", "(", "isset", "(", "$", "options", "[", "'proxy'", "]", "[", "'proxy'", "]", ")", ")", "{", "$", "out", "[", "CURLOPT_PROXY", "]", "=", "$", "options", "[", "'proxy'", "]", "[", "'proxy'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'proxy'", "]", "[", "'username'", "]", ")", ")", "{", "$", "password", "=", "!", "empty", "(", "$", "options", "[", "'proxy'", "]", "[", "'password'", "]", ")", "?", "$", "options", "[", "'proxy'", "]", "[", "'password'", "]", ":", "''", ";", "$", "out", "[", "CURLOPT_PROXYUSERPWD", "]", "=", "$", "options", "[", "'proxy'", "]", "[", "'username'", "]", ".", "':'", ".", "$", "password", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'curl'", "]", ")", "&&", "is_array", "(", "$", "options", "[", "'curl'", "]", ")", ")", "{", "// Can't use array_merge() because keys will be re-ordered.", "foreach", "(", "$", "options", "[", "'curl'", "]", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "out", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "out", ";", "}" ]
Convert client options into curl options. @param \Cake\Http\Client\Request $request The request. @param array $options The client options @return array
[ "Convert", "client", "options", "into", "curl", "options", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Curl.php#L66-L136
210,473
cakephp/cakephp
src/Http/Client/Adapter/Curl.php
Curl.createResponse
protected function createResponse($handle, $responseData) { $headerSize = curl_getinfo($handle, CURLINFO_HEADER_SIZE); $headers = trim(substr($responseData, 0, $headerSize)); $body = substr($responseData, $headerSize); $response = new Response(explode("\r\n", $headers), $body); return [$response]; }
php
protected function createResponse($handle, $responseData) { $headerSize = curl_getinfo($handle, CURLINFO_HEADER_SIZE); $headers = trim(substr($responseData, 0, $headerSize)); $body = substr($responseData, $headerSize); $response = new Response(explode("\r\n", $headers), $body); return [$response]; }
[ "protected", "function", "createResponse", "(", "$", "handle", ",", "$", "responseData", ")", "{", "$", "headerSize", "=", "curl_getinfo", "(", "$", "handle", ",", "CURLINFO_HEADER_SIZE", ")", ";", "$", "headers", "=", "trim", "(", "substr", "(", "$", "responseData", ",", "0", ",", "$", "headerSize", ")", ")", ";", "$", "body", "=", "substr", "(", "$", "responseData", ",", "$", "headerSize", ")", ";", "$", "response", "=", "new", "Response", "(", "explode", "(", "\"\\r\\n\"", ",", "$", "headers", ")", ",", "$", "body", ")", ";", "return", "[", "$", "response", "]", ";", "}" ]
Convert the raw curl response into an Http\Client\Response @param resource $handle Curl handle @param string $responseData string The response data from curl_exec @return \Cake\Http\Client\Response
[ "Convert", "the", "raw", "curl", "response", "into", "an", "Http", "\\", "Client", "\\", "Response" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Curl.php#L145-L153
210,474
cakephp/cakephp
src/Http/RequestTransformer.php
RequestTransformer.toCake
public static function toCake(PsrRequest $request) { $post = $request->getParsedBody(); $headers = []; foreach ($request->getHeaders() as $k => $value) { $name = sprintf('HTTP_%s', strtoupper(str_replace('-', '_', $k))); $headers[$name] = implode(',', $value); } $server = $headers + $request->getServerParams(); $files = static::getFiles($request); if (!empty($files)) { $post = Hash::merge($post, $files); } $input = $request->getBody()->getContents(); $input = $input === '' ? null : $input; return new ServerRequest([ 'query' => $request->getQueryParams(), 'post' => $post, 'cookies' => $request->getCookieParams(), 'environment' => $server, 'params' => static::getParams($request), 'url' => $request->getUri()->getPath(), 'base' => $request->getAttribute('base', ''), 'webroot' => $request->getAttribute('webroot', '/'), 'session' => $request->getAttribute('session', null), 'input' => $input, ]); }
php
public static function toCake(PsrRequest $request) { $post = $request->getParsedBody(); $headers = []; foreach ($request->getHeaders() as $k => $value) { $name = sprintf('HTTP_%s', strtoupper(str_replace('-', '_', $k))); $headers[$name] = implode(',', $value); } $server = $headers + $request->getServerParams(); $files = static::getFiles($request); if (!empty($files)) { $post = Hash::merge($post, $files); } $input = $request->getBody()->getContents(); $input = $input === '' ? null : $input; return new ServerRequest([ 'query' => $request->getQueryParams(), 'post' => $post, 'cookies' => $request->getCookieParams(), 'environment' => $server, 'params' => static::getParams($request), 'url' => $request->getUri()->getPath(), 'base' => $request->getAttribute('base', ''), 'webroot' => $request->getAttribute('webroot', '/'), 'session' => $request->getAttribute('session', null), 'input' => $input, ]); }
[ "public", "static", "function", "toCake", "(", "PsrRequest", "$", "request", ")", "{", "$", "post", "=", "$", "request", "->", "getParsedBody", "(", ")", ";", "$", "headers", "=", "[", "]", ";", "foreach", "(", "$", "request", "->", "getHeaders", "(", ")", "as", "$", "k", "=>", "$", "value", ")", "{", "$", "name", "=", "sprintf", "(", "'HTTP_%s'", ",", "strtoupper", "(", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "k", ")", ")", ")", ";", "$", "headers", "[", "$", "name", "]", "=", "implode", "(", "','", ",", "$", "value", ")", ";", "}", "$", "server", "=", "$", "headers", "+", "$", "request", "->", "getServerParams", "(", ")", ";", "$", "files", "=", "static", "::", "getFiles", "(", "$", "request", ")", ";", "if", "(", "!", "empty", "(", "$", "files", ")", ")", "{", "$", "post", "=", "Hash", "::", "merge", "(", "$", "post", ",", "$", "files", ")", ";", "}", "$", "input", "=", "$", "request", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ";", "$", "input", "=", "$", "input", "===", "''", "?", "null", ":", "$", "input", ";", "return", "new", "ServerRequest", "(", "[", "'query'", "=>", "$", "request", "->", "getQueryParams", "(", ")", ",", "'post'", "=>", "$", "post", ",", "'cookies'", "=>", "$", "request", "->", "getCookieParams", "(", ")", ",", "'environment'", "=>", "$", "server", ",", "'params'", "=>", "static", "::", "getParams", "(", "$", "request", ")", ",", "'url'", "=>", "$", "request", "->", "getUri", "(", ")", "->", "getPath", "(", ")", ",", "'base'", "=>", "$", "request", "->", "getAttribute", "(", "'base'", ",", "''", ")", ",", "'webroot'", "=>", "$", "request", "->", "getAttribute", "(", "'webroot'", ",", "'/'", ")", ",", "'session'", "=>", "$", "request", "->", "getAttribute", "(", "'session'", ",", "null", ")", ",", "'input'", "=>", "$", "input", ",", "]", ")", ";", "}" ]
Transform a PSR7 request into a CakePHP one. @param \Psr\Http\Message\ServerRequestInterface $request The PSR7 request. @return \Cake\Http\ServerRequest The transformed request.
[ "Transform", "a", "PSR7", "request", "into", "a", "CakePHP", "one", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/RequestTransformer.php#L40-L70
210,475
cakephp/cakephp
src/Http/RequestTransformer.php
RequestTransformer.getParams
protected static function getParams(PsrRequest $request) { $params = (array)$request->getAttribute('params', []); $params += [ 'plugin' => null, 'controller' => null, 'action' => null, '_ext' => null, 'pass' => [] ]; return $params; }
php
protected static function getParams(PsrRequest $request) { $params = (array)$request->getAttribute('params', []); $params += [ 'plugin' => null, 'controller' => null, 'action' => null, '_ext' => null, 'pass' => [] ]; return $params; }
[ "protected", "static", "function", "getParams", "(", "PsrRequest", "$", "request", ")", "{", "$", "params", "=", "(", "array", ")", "$", "request", "->", "getAttribute", "(", "'params'", ",", "[", "]", ")", ";", "$", "params", "+=", "[", "'plugin'", "=>", "null", ",", "'controller'", "=>", "null", ",", "'action'", "=>", "null", ",", "'_ext'", "=>", "null", ",", "'pass'", "=>", "[", "]", "]", ";", "return", "$", "params", ";", "}" ]
Extract the routing parameters out of the request object. @param \Psr\Http\Message\ServerRequestInterface $request The request to extract params from. @return array The routing parameters.
[ "Extract", "the", "routing", "parameters", "out", "of", "the", "request", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/RequestTransformer.php#L78-L90
210,476
cakephp/cakephp
src/Http/RequestTransformer.php
RequestTransformer.convertFiles
protected static function convertFiles($data, $files, $path = '') { foreach ($files as $key => $file) { $newPath = $path; if ($newPath === '') { $newPath = $key; } if ($newPath !== $key) { $newPath .= '.' . $key; } if (is_array($file)) { $data = static::convertFiles($data, $file, $newPath); } else { $data = Hash::insert($data, $newPath, static::convertFile($file)); } } return $data; }
php
protected static function convertFiles($data, $files, $path = '') { foreach ($files as $key => $file) { $newPath = $path; if ($newPath === '') { $newPath = $key; } if ($newPath !== $key) { $newPath .= '.' . $key; } if (is_array($file)) { $data = static::convertFiles($data, $file, $newPath); } else { $data = Hash::insert($data, $newPath, static::convertFile($file)); } } return $data; }
[ "protected", "static", "function", "convertFiles", "(", "$", "data", ",", "$", "files", ",", "$", "path", "=", "''", ")", "{", "foreach", "(", "$", "files", "as", "$", "key", "=>", "$", "file", ")", "{", "$", "newPath", "=", "$", "path", ";", "if", "(", "$", "newPath", "===", "''", ")", "{", "$", "newPath", "=", "$", "key", ";", "}", "if", "(", "$", "newPath", "!==", "$", "key", ")", "{", "$", "newPath", ".=", "'.'", ".", "$", "key", ";", "}", "if", "(", "is_array", "(", "$", "file", ")", ")", "{", "$", "data", "=", "static", "::", "convertFiles", "(", "$", "data", ",", "$", "file", ",", "$", "newPath", ")", ";", "}", "else", "{", "$", "data", "=", "Hash", "::", "insert", "(", "$", "data", ",", "$", "newPath", ",", "static", "::", "convertFile", "(", "$", "file", ")", ")", ";", "}", "}", "return", "$", "data", ";", "}" ]
Convert a nested array of files to arrays. @param array $data The data to add files to. @param array $files The file objects to convert. @param string $path The current array path. @return array Converted file data
[ "Convert", "a", "nested", "array", "of", "files", "to", "arrays", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/RequestTransformer.php#L114-L133
210,477
cakephp/cakephp
src/Http/RequestTransformer.php
RequestTransformer.convertFile
protected static function convertFile($file) { $error = $file->getError(); $tmpName = ''; if ($error === UPLOAD_ERR_OK) { $tmpName = $file->getStream()->getMetadata('uri'); } return [ 'name' => $file->getClientFilename(), 'type' => $file->getClientMediaType(), 'tmp_name' => $tmpName, 'error' => $error, 'size' => $file->getSize(), ]; }
php
protected static function convertFile($file) { $error = $file->getError(); $tmpName = ''; if ($error === UPLOAD_ERR_OK) { $tmpName = $file->getStream()->getMetadata('uri'); } return [ 'name' => $file->getClientFilename(), 'type' => $file->getClientMediaType(), 'tmp_name' => $tmpName, 'error' => $error, 'size' => $file->getSize(), ]; }
[ "protected", "static", "function", "convertFile", "(", "$", "file", ")", "{", "$", "error", "=", "$", "file", "->", "getError", "(", ")", ";", "$", "tmpName", "=", "''", ";", "if", "(", "$", "error", "===", "UPLOAD_ERR_OK", ")", "{", "$", "tmpName", "=", "$", "file", "->", "getStream", "(", ")", "->", "getMetadata", "(", "'uri'", ")", ";", "}", "return", "[", "'name'", "=>", "$", "file", "->", "getClientFilename", "(", ")", ",", "'type'", "=>", "$", "file", "->", "getClientMediaType", "(", ")", ",", "'tmp_name'", "=>", "$", "tmpName", ",", "'error'", "=>", "$", "error", ",", "'size'", "=>", "$", "file", "->", "getSize", "(", ")", ",", "]", ";", "}" ]
Convert a single file back into an array. @param \Psr\Http\Message\UploadedFileInterface $file The file to convert. @return array
[ "Convert", "a", "single", "file", "back", "into", "an", "array", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/RequestTransformer.php#L141-L156
210,478
cakephp/cakephp
src/Validation/ValidationSet.php
ValidationSet.isPresenceRequired
public function isPresenceRequired($validatePresent = null) { if ($validatePresent === null) { return $this->_validatePresent; } deprecationWarning( 'ValidationSet::isPresenceRequired() is deprecated as a setter. ' . 'Use ValidationSet::requirePresence() instead.' ); return $this->requirePresence($validatePresent); }
php
public function isPresenceRequired($validatePresent = null) { if ($validatePresent === null) { return $this->_validatePresent; } deprecationWarning( 'ValidationSet::isPresenceRequired() is deprecated as a setter. ' . 'Use ValidationSet::requirePresence() instead.' ); return $this->requirePresence($validatePresent); }
[ "public", "function", "isPresenceRequired", "(", "$", "validatePresent", "=", "null", ")", "{", "if", "(", "$", "validatePresent", "===", "null", ")", "{", "return", "$", "this", "->", "_validatePresent", ";", "}", "deprecationWarning", "(", "'ValidationSet::isPresenceRequired() is deprecated as a setter. '", ".", "'Use ValidationSet::requirePresence() instead.'", ")", ";", "return", "$", "this", "->", "requirePresence", "(", "$", "validatePresent", ")", ";", "}" ]
Sets whether a field is required to be present in data array. If no argument is passed the currently set `validatePresent` value will be returned. @param bool|string|callable|null $validatePresent Deprecated since 3.6.0 ValidationSet::isPresenceRequired() is deprecated as a setter Use ValidationSet::requirePresence() instead. @return bool|string|callable
[ "Sets", "whether", "a", "field", "is", "required", "to", "be", "present", "in", "data", "array", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/ValidationSet.php#L59-L71
210,479
cakephp/cakephp
src/Validation/ValidationSet.php
ValidationSet.isEmptyAllowed
public function isEmptyAllowed($allowEmpty = null) { if ($allowEmpty === null) { return $this->_allowEmpty; } deprecationWarning( 'ValidationSet::isEmptyAllowed() is deprecated as a setter. ' . 'Use ValidationSet::allowEmpty() instead.' ); return $this->allowEmpty($allowEmpty); }
php
public function isEmptyAllowed($allowEmpty = null) { if ($allowEmpty === null) { return $this->_allowEmpty; } deprecationWarning( 'ValidationSet::isEmptyAllowed() is deprecated as a setter. ' . 'Use ValidationSet::allowEmpty() instead.' ); return $this->allowEmpty($allowEmpty); }
[ "public", "function", "isEmptyAllowed", "(", "$", "allowEmpty", "=", "null", ")", "{", "if", "(", "$", "allowEmpty", "===", "null", ")", "{", "return", "$", "this", "->", "_allowEmpty", ";", "}", "deprecationWarning", "(", "'ValidationSet::isEmptyAllowed() is deprecated as a setter. '", ".", "'Use ValidationSet::allowEmpty() instead.'", ")", ";", "return", "$", "this", "->", "allowEmpty", "(", "$", "allowEmpty", ")", ";", "}" ]
Sets whether a field value is allowed to be empty. If no argument is passed the currently set `allowEmpty` value will be returned. @param bool|string|callable|null $allowEmpty Deprecated since 3.6.0 ValidationSet::isEmptyAllowed() is deprecated as a setter. Use ValidationSet::allowEmpty() instead. @return bool|string|callable
[ "Sets", "whether", "a", "field", "value", "is", "allowed", "to", "be", "empty", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/ValidationSet.php#L95-L107
210,480
cakephp/cakephp
src/Routing/DispatcherFilter.php
DispatcherFilter.handle
public function handle(Event $event) { $name = $event->getName(); list(, $method) = explode('.', $name); if (empty($this->_config['for']) && empty($this->_config['when'])) { return $this->{$method}($event); } if ($this->matches($event)) { return $this->{$method}($event); } }
php
public function handle(Event $event) { $name = $event->getName(); list(, $method) = explode('.', $name); if (empty($this->_config['for']) && empty($this->_config['when'])) { return $this->{$method}($event); } if ($this->matches($event)) { return $this->{$method}($event); } }
[ "public", "function", "handle", "(", "Event", "$", "event", ")", "{", "$", "name", "=", "$", "event", "->", "getName", "(", ")", ";", "list", "(", ",", "$", "method", ")", "=", "explode", "(", "'.'", ",", "$", "name", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "_config", "[", "'for'", "]", ")", "&&", "empty", "(", "$", "this", "->", "_config", "[", "'when'", "]", ")", ")", "{", "return", "$", "this", "->", "{", "$", "method", "}", "(", "$", "event", ")", ";", "}", "if", "(", "$", "this", "->", "matches", "(", "$", "event", ")", ")", "{", "return", "$", "this", "->", "{", "$", "method", "}", "(", "$", "event", ")", ";", "}", "}" ]
Handler method that applies conditions and resolves the correct method to call. @param \Cake\Event\Event $event The event instance. @return mixed
[ "Handler", "method", "that", "applies", "conditions", "and", "resolves", "the", "correct", "method", "to", "call", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/DispatcherFilter.php#L138-L148
210,481
cakephp/cakephp
src/Routing/DispatcherFilter.php
DispatcherFilter.matches
public function matches(Event $event) { /* @var \Cake\Http\ServerRequest $request */ $request = $event->getData('request'); $pass = true; if (!empty($this->_config['for'])) { $len = strlen('preg:'); $for = $this->_config['for']; $url = $request->getRequestTarget(); if (substr($for, 0, $len) === 'preg:') { $pass = (bool)preg_match(substr($for, $len), $url); } else { $pass = strpos($url, $for) === 0; } } if ($pass && !empty($this->_config['when'])) { $response = $event->getData('response'); $pass = $this->_config['when']($request, $response); } return $pass; }
php
public function matches(Event $event) { /* @var \Cake\Http\ServerRequest $request */ $request = $event->getData('request'); $pass = true; if (!empty($this->_config['for'])) { $len = strlen('preg:'); $for = $this->_config['for']; $url = $request->getRequestTarget(); if (substr($for, 0, $len) === 'preg:') { $pass = (bool)preg_match(substr($for, $len), $url); } else { $pass = strpos($url, $for) === 0; } } if ($pass && !empty($this->_config['when'])) { $response = $event->getData('response'); $pass = $this->_config['when']($request, $response); } return $pass; }
[ "public", "function", "matches", "(", "Event", "$", "event", ")", "{", "/* @var \\Cake\\Http\\ServerRequest $request */", "$", "request", "=", "$", "event", "->", "getData", "(", "'request'", ")", ";", "$", "pass", "=", "true", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_config", "[", "'for'", "]", ")", ")", "{", "$", "len", "=", "strlen", "(", "'preg:'", ")", ";", "$", "for", "=", "$", "this", "->", "_config", "[", "'for'", "]", ";", "$", "url", "=", "$", "request", "->", "getRequestTarget", "(", ")", ";", "if", "(", "substr", "(", "$", "for", ",", "0", ",", "$", "len", ")", "===", "'preg:'", ")", "{", "$", "pass", "=", "(", "bool", ")", "preg_match", "(", "substr", "(", "$", "for", ",", "$", "len", ")", ",", "$", "url", ")", ";", "}", "else", "{", "$", "pass", "=", "strpos", "(", "$", "url", ",", "$", "for", ")", "===", "0", ";", "}", "}", "if", "(", "$", "pass", "&&", "!", "empty", "(", "$", "this", "->", "_config", "[", "'when'", "]", ")", ")", "{", "$", "response", "=", "$", "event", "->", "getData", "(", "'response'", ")", ";", "$", "pass", "=", "$", "this", "->", "_config", "[", "'when'", "]", "(", "$", "request", ",", "$", "response", ")", ";", "}", "return", "$", "pass", ";", "}" ]
Check to see if the incoming request matches this filter's criteria. @param \Cake\Event\Event $event The event to match. @return bool
[ "Check", "to", "see", "if", "the", "incoming", "request", "matches", "this", "filter", "s", "criteria", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/DispatcherFilter.php#L156-L177
210,482
cakephp/cakephp
src/ORM/Rule/IsUnique.php
IsUnique._alias
protected function _alias($alias, $conditions, $multipleNulls) { $aliased = []; foreach ($conditions as $key => $value) { if ($multipleNulls) { $aliased["$alias.$key"] = $value; } else { $aliased["$alias.$key IS"] = $value; } } return $aliased; }
php
protected function _alias($alias, $conditions, $multipleNulls) { $aliased = []; foreach ($conditions as $key => $value) { if ($multipleNulls) { $aliased["$alias.$key"] = $value; } else { $aliased["$alias.$key IS"] = $value; } } return $aliased; }
[ "protected", "function", "_alias", "(", "$", "alias", ",", "$", "conditions", ",", "$", "multipleNulls", ")", "{", "$", "aliased", "=", "[", "]", ";", "foreach", "(", "$", "conditions", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "multipleNulls", ")", "{", "$", "aliased", "[", "\"$alias.$key\"", "]", "=", "$", "value", ";", "}", "else", "{", "$", "aliased", "[", "\"$alias.$key IS\"", "]", "=", "$", "value", ";", "}", "}", "return", "$", "aliased", ";", "}" ]
Add a model alias to all the keys in a set of conditions. Null values will be omitted from the generated conditions, as SQL UNIQUE indexes treat `NULL != NULL` @param string $alias The alias to add. @param array $conditions The conditions to alias. @param bool $multipleNulls Whether or not to allow multiple nulls. @return array
[ "Add", "a", "model", "alias", "to", "all", "the", "keys", "in", "a", "set", "of", "conditions", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Rule/IsUnique.php#L96-L108
210,483
cakephp/cakephp
src/ORM/LazyEagerLoader.php
LazyEagerLoader.loadInto
public function loadInto($entities, array $contain, Table $source) { $returnSingle = false; if ($entities instanceof EntityInterface) { $entities = [$entities]; $returnSingle = true; } $entities = new Collection($entities); $query = $this->_getQuery($entities, $contain, $source); $associations = array_keys($query->getContain()); $entities = $this->_injectResults($entities, $query, $associations, $source); return $returnSingle ? array_shift($entities) : $entities; }
php
public function loadInto($entities, array $contain, Table $source) { $returnSingle = false; if ($entities instanceof EntityInterface) { $entities = [$entities]; $returnSingle = true; } $entities = new Collection($entities); $query = $this->_getQuery($entities, $contain, $source); $associations = array_keys($query->getContain()); $entities = $this->_injectResults($entities, $query, $associations, $source); return $returnSingle ? array_shift($entities) : $entities; }
[ "public", "function", "loadInto", "(", "$", "entities", ",", "array", "$", "contain", ",", "Table", "$", "source", ")", "{", "$", "returnSingle", "=", "false", ";", "if", "(", "$", "entities", "instanceof", "EntityInterface", ")", "{", "$", "entities", "=", "[", "$", "entities", "]", ";", "$", "returnSingle", "=", "true", ";", "}", "$", "entities", "=", "new", "Collection", "(", "$", "entities", ")", ";", "$", "query", "=", "$", "this", "->", "_getQuery", "(", "$", "entities", ",", "$", "contain", ",", "$", "source", ")", ";", "$", "associations", "=", "array_keys", "(", "$", "query", "->", "getContain", "(", ")", ")", ";", "$", "entities", "=", "$", "this", "->", "_injectResults", "(", "$", "entities", ",", "$", "query", ",", "$", "associations", ",", "$", "source", ")", ";", "return", "$", "returnSingle", "?", "array_shift", "(", "$", "entities", ")", ":", "$", "entities", ";", "}" ]
Loads the specified associations in the passed entity or list of entities by executing extra queries in the database and merging the results in the appropriate properties. The properties for the associations to be loaded will be overwritten on each entity. @param \Cake\Datasource\EntityInterface|array $entities a single entity or list of entities @param array $contain A `contain()` compatible array. @see \Cake\ORM\Query::contain() @param \Cake\ORM\Table $source The table to use for fetching the top level entities @return \Cake\Datasource\EntityInterface|array
[ "Loads", "the", "specified", "associations", "in", "the", "passed", "entity", "or", "list", "of", "entities", "by", "executing", "extra", "queries", "in", "the", "database", "and", "merging", "the", "results", "in", "the", "appropriate", "properties", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/LazyEagerLoader.php#L43-L59
210,484
cakephp/cakephp
src/ORM/LazyEagerLoader.php
LazyEagerLoader._getPropertyMap
protected function _getPropertyMap($source, $associations) { $map = []; $container = $source->associations(); foreach ($associations as $assoc) { $map[$assoc] = $container->get($assoc)->getProperty(); } return $map; }
php
protected function _getPropertyMap($source, $associations) { $map = []; $container = $source->associations(); foreach ($associations as $assoc) { $map[$assoc] = $container->get($assoc)->getProperty(); } return $map; }
[ "protected", "function", "_getPropertyMap", "(", "$", "source", ",", "$", "associations", ")", "{", "$", "map", "=", "[", "]", ";", "$", "container", "=", "$", "source", "->", "associations", "(", ")", ";", "foreach", "(", "$", "associations", "as", "$", "assoc", ")", "{", "$", "map", "[", "$", "assoc", "]", "=", "$", "container", "->", "get", "(", "$", "assoc", ")", "->", "getProperty", "(", ")", ";", "}", "return", "$", "map", ";", "}" ]
Returns a map of property names where the association results should be injected in the top level entities. @param \Cake\ORM\Table $source The table having the top level associations @param string[] $associations The name of the top level associations @return array
[ "Returns", "a", "map", "of", "property", "names", "where", "the", "association", "results", "should", "be", "injected", "in", "the", "top", "level", "entities", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/LazyEagerLoader.php#L116-L125
210,485
cakephp/cakephp
src/ORM/LazyEagerLoader.php
LazyEagerLoader._injectResults
protected function _injectResults($objects, $results, $associations, $source) { $injected = []; $properties = $this->_getPropertyMap($source, $associations); $primaryKey = (array)$source->getPrimaryKey(); $results = $results ->indexBy(function ($e) use ($primaryKey) { /** @var \Cake\Datasource\EntityInterface $e */ return implode(';', $e->extract($primaryKey)); }) ->toArray(); foreach ($objects as $k => $object) { $key = implode(';', $object->extract($primaryKey)); if (!isset($results[$key])) { $injected[$k] = $object; continue; } /** @var \Cake\Datasource\EntityInterface $loaded */ $loaded = $results[$key]; foreach ($associations as $assoc) { $property = $properties[$assoc]; $object->set($property, $loaded->get($property), ['useSetters' => false]); $object->setDirty($property, false); } $injected[$k] = $object; } return $injected; }
php
protected function _injectResults($objects, $results, $associations, $source) { $injected = []; $properties = $this->_getPropertyMap($source, $associations); $primaryKey = (array)$source->getPrimaryKey(); $results = $results ->indexBy(function ($e) use ($primaryKey) { /** @var \Cake\Datasource\EntityInterface $e */ return implode(';', $e->extract($primaryKey)); }) ->toArray(); foreach ($objects as $k => $object) { $key = implode(';', $object->extract($primaryKey)); if (!isset($results[$key])) { $injected[$k] = $object; continue; } /** @var \Cake\Datasource\EntityInterface $loaded */ $loaded = $results[$key]; foreach ($associations as $assoc) { $property = $properties[$assoc]; $object->set($property, $loaded->get($property), ['useSetters' => false]); $object->setDirty($property, false); } $injected[$k] = $object; } return $injected; }
[ "protected", "function", "_injectResults", "(", "$", "objects", ",", "$", "results", ",", "$", "associations", ",", "$", "source", ")", "{", "$", "injected", "=", "[", "]", ";", "$", "properties", "=", "$", "this", "->", "_getPropertyMap", "(", "$", "source", ",", "$", "associations", ")", ";", "$", "primaryKey", "=", "(", "array", ")", "$", "source", "->", "getPrimaryKey", "(", ")", ";", "$", "results", "=", "$", "results", "->", "indexBy", "(", "function", "(", "$", "e", ")", "use", "(", "$", "primaryKey", ")", "{", "/** @var \\Cake\\Datasource\\EntityInterface $e */", "return", "implode", "(", "';'", ",", "$", "e", "->", "extract", "(", "$", "primaryKey", ")", ")", ";", "}", ")", "->", "toArray", "(", ")", ";", "foreach", "(", "$", "objects", "as", "$", "k", "=>", "$", "object", ")", "{", "$", "key", "=", "implode", "(", "';'", ",", "$", "object", "->", "extract", "(", "$", "primaryKey", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "results", "[", "$", "key", "]", ")", ")", "{", "$", "injected", "[", "$", "k", "]", "=", "$", "object", ";", "continue", ";", "}", "/** @var \\Cake\\Datasource\\EntityInterface $loaded */", "$", "loaded", "=", "$", "results", "[", "$", "key", "]", ";", "foreach", "(", "$", "associations", "as", "$", "assoc", ")", "{", "$", "property", "=", "$", "properties", "[", "$", "assoc", "]", ";", "$", "object", "->", "set", "(", "$", "property", ",", "$", "loaded", "->", "get", "(", "$", "property", ")", ",", "[", "'useSetters'", "=>", "false", "]", ")", ";", "$", "object", "->", "setDirty", "(", "$", "property", ",", "false", ")", ";", "}", "$", "injected", "[", "$", "k", "]", "=", "$", "object", ";", "}", "return", "$", "injected", ";", "}" ]
Injects the results of the eager loader query into the original list of entities. @param \Cake\Datasource\EntityInterface[]|\Traversable $objects The original list of entities @param \Cake\Collection\CollectionInterface|\Cake\Database\Query $results The loaded results @param string[] $associations The top level associations that were loaded @param \Cake\ORM\Table $source The table where the entities came from @return array
[ "Injects", "the", "results", "of", "the", "eager", "loader", "query", "into", "the", "original", "list", "of", "entities", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/LazyEagerLoader.php#L137-L167
210,486
cakephp/cakephp
src/Http/ResponseTransformer.php
ResponseTransformer.toCake
public static function toCake(PsrResponse $response) { $body = static::getBody($response); $data = [ 'status' => $response->getStatusCode(), 'body' => $body['body'], ]; $cake = new CakeResponse($data); if ($body['file']) { $cake->file($body['file']); } $cookies = static::parseCookies($response->getHeader('Set-Cookie')); foreach ($cookies as $cookie) { $cake->cookie($cookie); } $headers = static::collapseHeaders($response); $cake->header($headers); if (!empty($headers['Content-Type'])) { $cake->type($headers['Content-Type']); } return $cake; }
php
public static function toCake(PsrResponse $response) { $body = static::getBody($response); $data = [ 'status' => $response->getStatusCode(), 'body' => $body['body'], ]; $cake = new CakeResponse($data); if ($body['file']) { $cake->file($body['file']); } $cookies = static::parseCookies($response->getHeader('Set-Cookie')); foreach ($cookies as $cookie) { $cake->cookie($cookie); } $headers = static::collapseHeaders($response); $cake->header($headers); if (!empty($headers['Content-Type'])) { $cake->type($headers['Content-Type']); } return $cake; }
[ "public", "static", "function", "toCake", "(", "PsrResponse", "$", "response", ")", "{", "$", "body", "=", "static", "::", "getBody", "(", "$", "response", ")", ";", "$", "data", "=", "[", "'status'", "=>", "$", "response", "->", "getStatusCode", "(", ")", ",", "'body'", "=>", "$", "body", "[", "'body'", "]", ",", "]", ";", "$", "cake", "=", "new", "CakeResponse", "(", "$", "data", ")", ";", "if", "(", "$", "body", "[", "'file'", "]", ")", "{", "$", "cake", "->", "file", "(", "$", "body", "[", "'file'", "]", ")", ";", "}", "$", "cookies", "=", "static", "::", "parseCookies", "(", "$", "response", "->", "getHeader", "(", "'Set-Cookie'", ")", ")", ";", "foreach", "(", "$", "cookies", "as", "$", "cookie", ")", "{", "$", "cake", "->", "cookie", "(", "$", "cookie", ")", ";", "}", "$", "headers", "=", "static", "::", "collapseHeaders", "(", "$", "response", ")", ";", "$", "cake", "->", "header", "(", "$", "headers", ")", ";", "if", "(", "!", "empty", "(", "$", "headers", "[", "'Content-Type'", "]", ")", ")", "{", "$", "cake", "->", "type", "(", "$", "headers", "[", "'Content-Type'", "]", ")", ";", "}", "return", "$", "cake", ";", "}" ]
Convert a PSR7 Response into a CakePHP one. @param \Psr\Http\Message\ResponseInterface $response The response to convert. @return \Cake\Http\Response The equivalent CakePHP response
[ "Convert", "a", "PSR7", "Response", "into", "a", "CakePHP", "one", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ResponseTransformer.php#L39-L62
210,487
cakephp/cakephp
src/Http/ResponseTransformer.php
ResponseTransformer.getBody
protected static function getBody(PsrResponse $response) { $stream = $response->getBody(); if ($stream->getMetadata('wrapper_type') === 'plainfile') { return ['body' => '', 'file' => $stream->getMetadata('uri')]; } if ($stream->getSize() === 0) { return ['body' => '', 'file' => false]; } $stream->rewind(); return ['body' => $stream->getContents(), 'file' => false]; }
php
protected static function getBody(PsrResponse $response) { $stream = $response->getBody(); if ($stream->getMetadata('wrapper_type') === 'plainfile') { return ['body' => '', 'file' => $stream->getMetadata('uri')]; } if ($stream->getSize() === 0) { return ['body' => '', 'file' => false]; } $stream->rewind(); return ['body' => $stream->getContents(), 'file' => false]; }
[ "protected", "static", "function", "getBody", "(", "PsrResponse", "$", "response", ")", "{", "$", "stream", "=", "$", "response", "->", "getBody", "(", ")", ";", "if", "(", "$", "stream", "->", "getMetadata", "(", "'wrapper_type'", ")", "===", "'plainfile'", ")", "{", "return", "[", "'body'", "=>", "''", ",", "'file'", "=>", "$", "stream", "->", "getMetadata", "(", "'uri'", ")", "]", ";", "}", "if", "(", "$", "stream", "->", "getSize", "(", ")", "===", "0", ")", "{", "return", "[", "'body'", "=>", "''", ",", "'file'", "=>", "false", "]", ";", "}", "$", "stream", "->", "rewind", "(", ")", ";", "return", "[", "'body'", "=>", "$", "stream", "->", "getContents", "(", ")", ",", "'file'", "=>", "false", "]", ";", "}" ]
Get the response body from a PSR7 Response. @param \Psr\Http\Message\ResponseInterface $response The response to convert. @return array A hash of 'body' and 'file'
[ "Get", "the", "response", "body", "from", "a", "PSR7", "Response", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ResponseTransformer.php#L70-L82
210,488
cakephp/cakephp
src/Http/ResponseTransformer.php
ResponseTransformer.parseCookies
protected static function parseCookies(array $cookieHeader) { $cookies = []; foreach ($cookieHeader as $cookie) { if (strpos($cookie, '";"') !== false) { $cookie = str_replace('";"', '{__cookie_replace__}', $cookie); $parts = preg_split('/\;[ \t]*/', $cookie); $parts = str_replace('{__cookie_replace__}', '";"', $parts); } else { $parts = preg_split('/\;[ \t]*/', $cookie); } list($name, $value) = explode('=', array_shift($parts), 2); $parsed = ['name' => $name, 'value' => urldecode($value)]; foreach ($parts as $part) { if (strpos($part, '=') !== false) { list($key, $value) = explode('=', $part); } else { $key = $part; $value = true; } $key = strtolower($key); if ($key === 'httponly') { $key = 'httpOnly'; } if ($key === 'expires') { $key = 'expire'; $value = strtotime($value); } if (!isset($parsed[$key])) { $parsed[$key] = $value; } } $cookies[] = $parsed; } return $cookies; }
php
protected static function parseCookies(array $cookieHeader) { $cookies = []; foreach ($cookieHeader as $cookie) { if (strpos($cookie, '";"') !== false) { $cookie = str_replace('";"', '{__cookie_replace__}', $cookie); $parts = preg_split('/\;[ \t]*/', $cookie); $parts = str_replace('{__cookie_replace__}', '";"', $parts); } else { $parts = preg_split('/\;[ \t]*/', $cookie); } list($name, $value) = explode('=', array_shift($parts), 2); $parsed = ['name' => $name, 'value' => urldecode($value)]; foreach ($parts as $part) { if (strpos($part, '=') !== false) { list($key, $value) = explode('=', $part); } else { $key = $part; $value = true; } $key = strtolower($key); if ($key === 'httponly') { $key = 'httpOnly'; } if ($key === 'expires') { $key = 'expire'; $value = strtotime($value); } if (!isset($parsed[$key])) { $parsed[$key] = $value; } } $cookies[] = $parsed; } return $cookies; }
[ "protected", "static", "function", "parseCookies", "(", "array", "$", "cookieHeader", ")", "{", "$", "cookies", "=", "[", "]", ";", "foreach", "(", "$", "cookieHeader", "as", "$", "cookie", ")", "{", "if", "(", "strpos", "(", "$", "cookie", ",", "'\";\"'", ")", "!==", "false", ")", "{", "$", "cookie", "=", "str_replace", "(", "'\";\"'", ",", "'{__cookie_replace__}'", ",", "$", "cookie", ")", ";", "$", "parts", "=", "preg_split", "(", "'/\\;[ \\t]*/'", ",", "$", "cookie", ")", ";", "$", "parts", "=", "str_replace", "(", "'{__cookie_replace__}'", ",", "'\";\"'", ",", "$", "parts", ")", ";", "}", "else", "{", "$", "parts", "=", "preg_split", "(", "'/\\;[ \\t]*/'", ",", "$", "cookie", ")", ";", "}", "list", "(", "$", "name", ",", "$", "value", ")", "=", "explode", "(", "'='", ",", "array_shift", "(", "$", "parts", ")", ",", "2", ")", ";", "$", "parsed", "=", "[", "'name'", "=>", "$", "name", ",", "'value'", "=>", "urldecode", "(", "$", "value", ")", "]", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "if", "(", "strpos", "(", "$", "part", ",", "'='", ")", "!==", "false", ")", "{", "list", "(", "$", "key", ",", "$", "value", ")", "=", "explode", "(", "'='", ",", "$", "part", ")", ";", "}", "else", "{", "$", "key", "=", "$", "part", ";", "$", "value", "=", "true", ";", "}", "$", "key", "=", "strtolower", "(", "$", "key", ")", ";", "if", "(", "$", "key", "===", "'httponly'", ")", "{", "$", "key", "=", "'httpOnly'", ";", "}", "if", "(", "$", "key", "===", "'expires'", ")", "{", "$", "key", "=", "'expire'", ";", "$", "value", "=", "strtotime", "(", "$", "value", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "parsed", "[", "$", "key", "]", ")", ")", "{", "$", "parsed", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "$", "cookies", "[", "]", "=", "$", "parsed", ";", "}", "return", "$", "cookies", ";", "}" ]
Parse the Set-Cookie headers in a PSR7 response into the format CakePHP expects. @param array $cookieHeader A list of Set-Cookie headers. @return array Parsed cookie data.
[ "Parse", "the", "Set", "-", "Cookie", "headers", "in", "a", "PSR7", "response", "into", "the", "format", "CakePHP", "expects", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ResponseTransformer.php#L91-L130
210,489
cakephp/cakephp
src/Http/ResponseTransformer.php
ResponseTransformer.collapseHeaders
protected static function collapseHeaders(PsrResponse $response) { $out = []; foreach ($response->getHeaders() as $name => $value) { if (count($value) === 1) { $out[$name] = $value[0]; } else { $out[$name] = $value; } } return $out; }
php
protected static function collapseHeaders(PsrResponse $response) { $out = []; foreach ($response->getHeaders() as $name => $value) { if (count($value) === 1) { $out[$name] = $value[0]; } else { $out[$name] = $value; } } return $out; }
[ "protected", "static", "function", "collapseHeaders", "(", "PsrResponse", "$", "response", ")", "{", "$", "out", "=", "[", "]", ";", "foreach", "(", "$", "response", "->", "getHeaders", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "count", "(", "$", "value", ")", "===", "1", ")", "{", "$", "out", "[", "$", "name", "]", "=", "$", "value", "[", "0", "]", ";", "}", "else", "{", "$", "out", "[", "$", "name", "]", "=", "$", "value", ";", "}", "}", "return", "$", "out", ";", "}" ]
Convert a PSR7 Response headers into a flat array @param \Psr\Http\Message\ResponseInterface $response The response to convert. @return array Headers.
[ "Convert", "a", "PSR7", "Response", "headers", "into", "a", "flat", "array" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ResponseTransformer.php#L138-L150
210,490
cakephp/cakephp
src/Http/ResponseTransformer.php
ResponseTransformer.toPsr
public static function toPsr(CakeResponse $response) { $status = $response->statusCode(); $headers = $response->header(); if (!isset($headers['Content-Type'])) { $headers = static::setContentType($headers, $response); } $cookies = $response->cookie(); if ($cookies) { $headers['Set-Cookie'] = static::buildCookieHeader($cookies); } $stream = static::getStream($response); return new DiactorosResponse($stream, $status, $headers); }
php
public static function toPsr(CakeResponse $response) { $status = $response->statusCode(); $headers = $response->header(); if (!isset($headers['Content-Type'])) { $headers = static::setContentType($headers, $response); } $cookies = $response->cookie(); if ($cookies) { $headers['Set-Cookie'] = static::buildCookieHeader($cookies); } $stream = static::getStream($response); return new DiactorosResponse($stream, $status, $headers); }
[ "public", "static", "function", "toPsr", "(", "CakeResponse", "$", "response", ")", "{", "$", "status", "=", "$", "response", "->", "statusCode", "(", ")", ";", "$", "headers", "=", "$", "response", "->", "header", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "headers", "[", "'Content-Type'", "]", ")", ")", "{", "$", "headers", "=", "static", "::", "setContentType", "(", "$", "headers", ",", "$", "response", ")", ";", "}", "$", "cookies", "=", "$", "response", "->", "cookie", "(", ")", ";", "if", "(", "$", "cookies", ")", "{", "$", "headers", "[", "'Set-Cookie'", "]", "=", "static", "::", "buildCookieHeader", "(", "$", "cookies", ")", ";", "}", "$", "stream", "=", "static", "::", "getStream", "(", "$", "response", ")", ";", "return", "new", "DiactorosResponse", "(", "$", "stream", ",", "$", "status", ",", "$", "headers", ")", ";", "}" ]
Convert a CakePHP response into a PSR7 one. @param \Cake\Http\Response $response The CakePHP response to convert @return \Psr\Http\Message\ResponseInterface $response The equivalent PSR7 response.
[ "Convert", "a", "CakePHP", "response", "into", "a", "PSR7", "one", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ResponseTransformer.php#L158-L172
210,491
cakephp/cakephp
src/Http/ResponseTransformer.php
ResponseTransformer.setContentType
protected static function setContentType($headers, $response) { if (isset($headers['Content-Type'])) { return $headers; } if (in_array($response->statusCode(), [204, 304])) { return $headers; } $whitelist = [ 'application/javascript', 'application/json', 'application/xml', 'application/rss+xml' ]; $type = $response->type(); $charset = $response->charset(); $hasCharset = false; if ($charset && (strpos($type, 'text/') === 0 || in_array($type, $whitelist))) { $hasCharset = true; } $value = $type; if ($hasCharset) { $value = "{$type}; charset={$charset}"; } $headers['Content-Type'] = $value; return $headers; }
php
protected static function setContentType($headers, $response) { if (isset($headers['Content-Type'])) { return $headers; } if (in_array($response->statusCode(), [204, 304])) { return $headers; } $whitelist = [ 'application/javascript', 'application/json', 'application/xml', 'application/rss+xml' ]; $type = $response->type(); $charset = $response->charset(); $hasCharset = false; if ($charset && (strpos($type, 'text/') === 0 || in_array($type, $whitelist))) { $hasCharset = true; } $value = $type; if ($hasCharset) { $value = "{$type}; charset={$charset}"; } $headers['Content-Type'] = $value; return $headers; }
[ "protected", "static", "function", "setContentType", "(", "$", "headers", ",", "$", "response", ")", "{", "if", "(", "isset", "(", "$", "headers", "[", "'Content-Type'", "]", ")", ")", "{", "return", "$", "headers", ";", "}", "if", "(", "in_array", "(", "$", "response", "->", "statusCode", "(", ")", ",", "[", "204", ",", "304", "]", ")", ")", "{", "return", "$", "headers", ";", "}", "$", "whitelist", "=", "[", "'application/javascript'", ",", "'application/json'", ",", "'application/xml'", ",", "'application/rss+xml'", "]", ";", "$", "type", "=", "$", "response", "->", "type", "(", ")", ";", "$", "charset", "=", "$", "response", "->", "charset", "(", ")", ";", "$", "hasCharset", "=", "false", ";", "if", "(", "$", "charset", "&&", "(", "strpos", "(", "$", "type", ",", "'text/'", ")", "===", "0", "||", "in_array", "(", "$", "type", ",", "$", "whitelist", ")", ")", ")", "{", "$", "hasCharset", "=", "true", ";", "}", "$", "value", "=", "$", "type", ";", "if", "(", "$", "hasCharset", ")", "{", "$", "value", "=", "\"{$type}; charset={$charset}\"", ";", "}", "$", "headers", "[", "'Content-Type'", "]", "=", "$", "value", ";", "return", "$", "headers", ";", "}" ]
Add in the Content-Type header if necessary. @param array $headers The headers to update @param \Cake\Http\Response $response The CakePHP response to convert @return array The updated headers.
[ "Add", "in", "the", "Content", "-", "Type", "header", "if", "necessary", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ResponseTransformer.php#L181-L209
210,492
cakephp/cakephp
src/Http/ResponseTransformer.php
ResponseTransformer.buildCookieHeader
protected static function buildCookieHeader($cookies) { $headers = []; foreach ($cookies as $cookie) { $parts = [ sprintf('%s=%s', urlencode($cookie['name']), urlencode($cookie['value'])) ]; if ($cookie['expire']) { $cookie['expire'] = gmdate('D, d M Y H:i:s T', $cookie['expire']); } $attributes = [ 'expire' => 'Expires=%s', 'path' => 'Path=%s', 'domain' => 'Domain=%s', 'httpOnly' => 'HttpOnly', 'secure' => 'Secure', ]; foreach ($attributes as $key => $attr) { if ($cookie[$key]) { $parts[] = sprintf($attr, $cookie[$key]); } } $headers[] = implode('; ', $parts); } return $headers; }
php
protected static function buildCookieHeader($cookies) { $headers = []; foreach ($cookies as $cookie) { $parts = [ sprintf('%s=%s', urlencode($cookie['name']), urlencode($cookie['value'])) ]; if ($cookie['expire']) { $cookie['expire'] = gmdate('D, d M Y H:i:s T', $cookie['expire']); } $attributes = [ 'expire' => 'Expires=%s', 'path' => 'Path=%s', 'domain' => 'Domain=%s', 'httpOnly' => 'HttpOnly', 'secure' => 'Secure', ]; foreach ($attributes as $key => $attr) { if ($cookie[$key]) { $parts[] = sprintf($attr, $cookie[$key]); } } $headers[] = implode('; ', $parts); } return $headers; }
[ "protected", "static", "function", "buildCookieHeader", "(", "$", "cookies", ")", "{", "$", "headers", "=", "[", "]", ";", "foreach", "(", "$", "cookies", "as", "$", "cookie", ")", "{", "$", "parts", "=", "[", "sprintf", "(", "'%s=%s'", ",", "urlencode", "(", "$", "cookie", "[", "'name'", "]", ")", ",", "urlencode", "(", "$", "cookie", "[", "'value'", "]", ")", ")", "]", ";", "if", "(", "$", "cookie", "[", "'expire'", "]", ")", "{", "$", "cookie", "[", "'expire'", "]", "=", "gmdate", "(", "'D, d M Y H:i:s T'", ",", "$", "cookie", "[", "'expire'", "]", ")", ";", "}", "$", "attributes", "=", "[", "'expire'", "=>", "'Expires=%s'", ",", "'path'", "=>", "'Path=%s'", ",", "'domain'", "=>", "'Domain=%s'", ",", "'httpOnly'", "=>", "'HttpOnly'", ",", "'secure'", "=>", "'Secure'", ",", "]", ";", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "attr", ")", "{", "if", "(", "$", "cookie", "[", "$", "key", "]", ")", "{", "$", "parts", "[", "]", "=", "sprintf", "(", "$", "attr", ",", "$", "cookie", "[", "$", "key", "]", ")", ";", "}", "}", "$", "headers", "[", "]", "=", "implode", "(", "'; '", ",", "$", "parts", ")", ";", "}", "return", "$", "headers", ";", "}" ]
Convert an array of cookies into header lines. @param array $cookies The cookies to serialize. @return array A list of cookie header values.
[ "Convert", "an", "array", "of", "cookies", "into", "header", "lines", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ResponseTransformer.php#L217-L243
210,493
cakephp/cakephp
src/Http/ResponseTransformer.php
ResponseTransformer.getStream
protected static function getStream($response) { $stream = 'php://memory'; $body = $response->body(); if (is_string($body) && strlen($body)) { $stream = new Stream('php://memory', 'wb'); $stream->write($body); return $stream; } if (is_callable($body)) { $stream = new CallbackStream($body); return $stream; } $file = $response->getFile(); if ($file) { $stream = new Stream($file->path, 'rb'); return $stream; } return $stream; }
php
protected static function getStream($response) { $stream = 'php://memory'; $body = $response->body(); if (is_string($body) && strlen($body)) { $stream = new Stream('php://memory', 'wb'); $stream->write($body); return $stream; } if (is_callable($body)) { $stream = new CallbackStream($body); return $stream; } $file = $response->getFile(); if ($file) { $stream = new Stream($file->path, 'rb'); return $stream; } return $stream; }
[ "protected", "static", "function", "getStream", "(", "$", "response", ")", "{", "$", "stream", "=", "'php://memory'", ";", "$", "body", "=", "$", "response", "->", "body", "(", ")", ";", "if", "(", "is_string", "(", "$", "body", ")", "&&", "strlen", "(", "$", "body", ")", ")", "{", "$", "stream", "=", "new", "Stream", "(", "'php://memory'", ",", "'wb'", ")", ";", "$", "stream", "->", "write", "(", "$", "body", ")", ";", "return", "$", "stream", ";", "}", "if", "(", "is_callable", "(", "$", "body", ")", ")", "{", "$", "stream", "=", "new", "CallbackStream", "(", "$", "body", ")", ";", "return", "$", "stream", ";", "}", "$", "file", "=", "$", "response", "->", "getFile", "(", ")", ";", "if", "(", "$", "file", ")", "{", "$", "stream", "=", "new", "Stream", "(", "$", "file", "->", "path", ",", "'rb'", ")", ";", "return", "$", "stream", ";", "}", "return", "$", "stream", ";", "}" ]
Get the stream for the new response. @param \Cake\Http\Response $response The cake response to extract the body from. @return \Psr\Http\Message\StreamInterface|string The stream.
[ "Get", "the", "stream", "for", "the", "new", "response", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ResponseTransformer.php#L251-L274
210,494
cakephp/cakephp
src/Datasource/ConnectionManager.php
ConnectionManager.setConfig
public static function setConfig($key, $config = null) { if (is_array($config)) { $config['name'] = $key; } static::_setConfig($key, $config); }
php
public static function setConfig($key, $config = null) { if (is_array($config)) { $config['name'] = $key; } static::_setConfig($key, $config); }
[ "public", "static", "function", "setConfig", "(", "$", "key", ",", "$", "config", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "config", ")", ")", "{", "$", "config", "[", "'name'", "]", "=", "$", "key", ";", "}", "static", "::", "_setConfig", "(", "$", "key", ",", "$", "config", ")", ";", "}" ]
Configure a new connection object. The connection will not be constructed until it is first used. @param string|array $key The name of the connection config, or an array of multiple configs. @param array|null $config An array of name => config data for adapter. @return void @throws \Cake\Core\Exception\Exception When trying to modify an existing config. @see \Cake\Core\StaticConfigTrait::config()
[ "Configure", "a", "new", "connection", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/ConnectionManager.php#L74-L81
210,495
cakephp/cakephp
src/Datasource/ConnectionManager.php
ConnectionManager.alias
public static function alias($alias, $source) { if (empty(static::$_config[$source]) && empty(static::$_config[$alias])) { throw new MissingDatasourceConfigException( sprintf('Cannot create alias of "%s" as it does not exist.', $alias) ); } static::$_aliasMap[$source] = $alias; }
php
public static function alias($alias, $source) { if (empty(static::$_config[$source]) && empty(static::$_config[$alias])) { throw new MissingDatasourceConfigException( sprintf('Cannot create alias of "%s" as it does not exist.', $alias) ); } static::$_aliasMap[$source] = $alias; }
[ "public", "static", "function", "alias", "(", "$", "alias", ",", "$", "source", ")", "{", "if", "(", "empty", "(", "static", "::", "$", "_config", "[", "$", "source", "]", ")", "&&", "empty", "(", "static", "::", "$", "_config", "[", "$", "alias", "]", ")", ")", "{", "throw", "new", "MissingDatasourceConfigException", "(", "sprintf", "(", "'Cannot create alias of \"%s\" as it does not exist.'", ",", "$", "alias", ")", ")", ";", "}", "static", "::", "$", "_aliasMap", "[", "$", "source", "]", "=", "$", "alias", ";", "}" ]
Set one or more connection aliases. Connection aliases allow you to rename active connections without overwriting the aliased connection. This is most useful in the test-suite for replacing connections with their test variant. Defined aliases will take precedence over normal connection names. For example, if you alias 'default' to 'test', fetching 'default' will always return the 'test' connection as long as the alias is defined. You can remove aliases with ConnectionManager::dropAlias(). ### Usage ``` // Make 'things' resolve to 'test_things' connection ConnectionManager::alias('test_things', 'things'); ``` @param string $alias The alias to add. Fetching $source will return $alias when loaded with get. @param string $source The connection to add an alias to. @return void @throws \Cake\Datasource\Exception\MissingDatasourceConfigException When aliasing a connection that does not exist.
[ "Set", "one", "or", "more", "connection", "aliases", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/ConnectionManager.php#L152-L160
210,496
cakephp/cakephp
src/Shell/Helper/ProgressHelper.php
ProgressHelper.output
public function output($args) { $args += ['callback' => null]; if (isset($args[0])) { $args['callback'] = $args[0]; } if (!$args['callback'] || !is_callable($args['callback'])) { throw new RuntimeException('Callback option must be a callable.'); } $this->init($args); $callback = $args['callback']; $this->_io->out('', 0); while ($this->_progress < $this->_total) { $callback($this); $this->draw(); } $this->_io->out(''); }
php
public function output($args) { $args += ['callback' => null]; if (isset($args[0])) { $args['callback'] = $args[0]; } if (!$args['callback'] || !is_callable($args['callback'])) { throw new RuntimeException('Callback option must be a callable.'); } $this->init($args); $callback = $args['callback']; $this->_io->out('', 0); while ($this->_progress < $this->_total) { $callback($this); $this->draw(); } $this->_io->out(''); }
[ "public", "function", "output", "(", "$", "args", ")", "{", "$", "args", "+=", "[", "'callback'", "=>", "null", "]", ";", "if", "(", "isset", "(", "$", "args", "[", "0", "]", ")", ")", "{", "$", "args", "[", "'callback'", "]", "=", "$", "args", "[", "0", "]", ";", "}", "if", "(", "!", "$", "args", "[", "'callback'", "]", "||", "!", "is_callable", "(", "$", "args", "[", "'callback'", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Callback option must be a callable.'", ")", ";", "}", "$", "this", "->", "init", "(", "$", "args", ")", ";", "$", "callback", "=", "$", "args", "[", "'callback'", "]", ";", "$", "this", "->", "_io", "->", "out", "(", "''", ",", "0", ")", ";", "while", "(", "$", "this", "->", "_progress", "<", "$", "this", "->", "_total", ")", "{", "$", "callback", "(", "$", "this", ")", ";", "$", "this", "->", "draw", "(", ")", ";", "}", "$", "this", "->", "_io", "->", "out", "(", "''", ")", ";", "}" ]
Output a progress bar. Takes a number of options to customize the behavior: - `total` The total number of items in the progress bar. Defaults to 100. - `width` The width of the progress bar. Defaults to 80. - `callback` The callback that will be called in a loop to advance the progress bar. @param array $args The arguments/options to use when outputing the progress bar. @return void
[ "Output", "a", "progress", "bar", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Helper/ProgressHelper.php#L71-L90
210,497
cakephp/cakephp
src/Shell/Helper/ProgressHelper.php
ProgressHelper.init
public function init(array $args = []) { $args += ['total' => 100, 'width' => 80]; $this->_progress = 0; $this->_width = $args['width']; $this->_total = $args['total']; return $this; }
php
public function init(array $args = []) { $args += ['total' => 100, 'width' => 80]; $this->_progress = 0; $this->_width = $args['width']; $this->_total = $args['total']; return $this; }
[ "public", "function", "init", "(", "array", "$", "args", "=", "[", "]", ")", "{", "$", "args", "+=", "[", "'total'", "=>", "100", ",", "'width'", "=>", "80", "]", ";", "$", "this", "->", "_progress", "=", "0", ";", "$", "this", "->", "_width", "=", "$", "args", "[", "'width'", "]", ";", "$", "this", "->", "_total", "=", "$", "args", "[", "'total'", "]", ";", "return", "$", "this", ";", "}" ]
Initialize the progress bar for use. - `total` The total number of items in the progress bar. Defaults to 100. - `width` The width of the progress bar. Defaults to 80. @param array $args The initialization data. @return $this
[ "Initialize", "the", "progress", "bar", "for", "use", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Helper/ProgressHelper.php#L102-L110
210,498
cakephp/cakephp
src/Shell/Helper/ProgressHelper.php
ProgressHelper.increment
public function increment($num = 1) { $this->_progress = min(max(0, $this->_progress + $num), $this->_total); return $this; }
php
public function increment($num = 1) { $this->_progress = min(max(0, $this->_progress + $num), $this->_total); return $this; }
[ "public", "function", "increment", "(", "$", "num", "=", "1", ")", "{", "$", "this", "->", "_progress", "=", "min", "(", "max", "(", "0", ",", "$", "this", "->", "_progress", "+", "$", "num", ")", ",", "$", "this", "->", "_total", ")", ";", "return", "$", "this", ";", "}" ]
Increment the progress bar. @param int $num The amount of progress to advance by. @return $this
[ "Increment", "the", "progress", "bar", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Helper/ProgressHelper.php#L118-L123
210,499
cakephp/cakephp
src/Shell/Helper/ProgressHelper.php
ProgressHelper.draw
public function draw() { $numberLen = strlen(' 100%'); $complete = round($this->_progress / $this->_total, 2); $barLen = ($this->_width - $numberLen) * ($this->_progress / $this->_total); $bar = ''; if ($barLen > 1) { $bar = str_repeat('=', $barLen - 1) . '>'; } $pad = ceil($this->_width - $numberLen - $barLen); if ($pad > 0) { $bar .= str_repeat(' ', $pad); } $percent = ($complete * 100) . '%'; $bar .= str_pad($percent, $numberLen, ' ', STR_PAD_LEFT); $this->_io->overwrite($bar, 0); return $this; }
php
public function draw() { $numberLen = strlen(' 100%'); $complete = round($this->_progress / $this->_total, 2); $barLen = ($this->_width - $numberLen) * ($this->_progress / $this->_total); $bar = ''; if ($barLen > 1) { $bar = str_repeat('=', $barLen - 1) . '>'; } $pad = ceil($this->_width - $numberLen - $barLen); if ($pad > 0) { $bar .= str_repeat(' ', $pad); } $percent = ($complete * 100) . '%'; $bar .= str_pad($percent, $numberLen, ' ', STR_PAD_LEFT); $this->_io->overwrite($bar, 0); return $this; }
[ "public", "function", "draw", "(", ")", "{", "$", "numberLen", "=", "strlen", "(", "' 100%'", ")", ";", "$", "complete", "=", "round", "(", "$", "this", "->", "_progress", "/", "$", "this", "->", "_total", ",", "2", ")", ";", "$", "barLen", "=", "(", "$", "this", "->", "_width", "-", "$", "numberLen", ")", "*", "(", "$", "this", "->", "_progress", "/", "$", "this", "->", "_total", ")", ";", "$", "bar", "=", "''", ";", "if", "(", "$", "barLen", ">", "1", ")", "{", "$", "bar", "=", "str_repeat", "(", "'='", ",", "$", "barLen", "-", "1", ")", ".", "'>'", ";", "}", "$", "pad", "=", "ceil", "(", "$", "this", "->", "_width", "-", "$", "numberLen", "-", "$", "barLen", ")", ";", "if", "(", "$", "pad", ">", "0", ")", "{", "$", "bar", ".=", "str_repeat", "(", "' '", ",", "$", "pad", ")", ";", "}", "$", "percent", "=", "(", "$", "complete", "*", "100", ")", ".", "'%'", ";", "$", "bar", ".=", "str_pad", "(", "$", "percent", ",", "$", "numberLen", ",", "' '", ",", "STR_PAD_LEFT", ")", ";", "$", "this", "->", "_io", "->", "overwrite", "(", "$", "bar", ",", "0", ")", ";", "return", "$", "this", ";", "}" ]
Render the progress bar based on the current state. @return $this
[ "Render", "the", "progress", "bar", "based", "on", "the", "current", "state", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Helper/ProgressHelper.php#L130-L150