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
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
11,500
perinatologie/hub-client-php
src/Factory/ApiClientFactory.php
ApiClientFactory.createV3Client
public function createV3Client($username, $password) { return new HubV3Client( $username, $password, $this->hubUrl, $this->requestHeaders, $this->tlsCertVerification ); }
php
public function createV3Client($username, $password) { return new HubV3Client( $username, $password, $this->hubUrl, $this->requestHeaders, $this->tlsCertVerification ); }
[ "public", "function", "createV3Client", "(", "$", "username", ",", "$", "password", ")", "{", "return", "new", "HubV3Client", "(", "$", "username", ",", "$", "password", ",", "$", "this", "->", "hubUrl", ",", "$", "this", "->", "requestHeaders", ",", "$", "this", "->", "tlsCertVerification", ")", ";", "}" ]
Get a client for the v3 Hub API. @param string $username @param string $password @return \Hub\Client\V3\HubV3Client
[ "Get", "a", "client", "for", "the", "v3", "Hub", "API", "." ]
3a0cf7ec6e3e5bf465167c283ee3dad9f4daaca3
https://github.com/perinatologie/hub-client-php/blob/3a0cf7ec6e3e5bf465167c283ee3dad9f4daaca3/src/Factory/ApiClientFactory.php#L56-L65
11,501
perinatologie/hub-client-php
src/Factory/ApiClientFactory.php
ApiClientFactory.createV4Client
public function createV4Client($username, $password) { if (!$this->userbaseUrl) { throw new RuntimeException( 'In order to createV4Client you need to have previsously called ApiClientFactory::setUserbaseJwtAuthenticatorUrl' ); } $authenticator = new UserbaseJwtAuthenticatorClient( $this->userbaseUrl, $this->tlsCertVerification ); try { $token = $authenticator->authenticate($username, $password); } catch (AuthenticationFailureException $e) { throw new ClientCreationException( 'Failed to create a v4 API client because of a failure during authentication with UserBase.', null, $e ); } $httpClient = new GuzzleClient( [ 'base_uri' => $this->hubUrl, 'verify' => $this->tlsCertVerification, 'headers' => array_replace( ['User-Agent' => 'HubV4Client (Guzzle)'], $this->requestHeaders, ['X-Authorization' => "Bearer {$token}"] ), ] ); return new HubV4Client($httpClient); }
php
public function createV4Client($username, $password) { if (!$this->userbaseUrl) { throw new RuntimeException( 'In order to createV4Client you need to have previsously called ApiClientFactory::setUserbaseJwtAuthenticatorUrl' ); } $authenticator = new UserbaseJwtAuthenticatorClient( $this->userbaseUrl, $this->tlsCertVerification ); try { $token = $authenticator->authenticate($username, $password); } catch (AuthenticationFailureException $e) { throw new ClientCreationException( 'Failed to create a v4 API client because of a failure during authentication with UserBase.', null, $e ); } $httpClient = new GuzzleClient( [ 'base_uri' => $this->hubUrl, 'verify' => $this->tlsCertVerification, 'headers' => array_replace( ['User-Agent' => 'HubV4Client (Guzzle)'], $this->requestHeaders, ['X-Authorization' => "Bearer {$token}"] ), ] ); return new HubV4Client($httpClient); }
[ "public", "function", "createV4Client", "(", "$", "username", ",", "$", "password", ")", "{", "if", "(", "!", "$", "this", "->", "userbaseUrl", ")", "{", "throw", "new", "RuntimeException", "(", "'In order to createV4Client you need to have previsously called ApiClientFactory::setUserbaseJwtAuthenticatorUrl'", ")", ";", "}", "$", "authenticator", "=", "new", "UserbaseJwtAuthenticatorClient", "(", "$", "this", "->", "userbaseUrl", ",", "$", "this", "->", "tlsCertVerification", ")", ";", "try", "{", "$", "token", "=", "$", "authenticator", "->", "authenticate", "(", "$", "username", ",", "$", "password", ")", ";", "}", "catch", "(", "AuthenticationFailureException", "$", "e", ")", "{", "throw", "new", "ClientCreationException", "(", "'Failed to create a v4 API client because of a failure during authentication with UserBase.'", ",", "null", ",", "$", "e", ")", ";", "}", "$", "httpClient", "=", "new", "GuzzleClient", "(", "[", "'base_uri'", "=>", "$", "this", "->", "hubUrl", ",", "'verify'", "=>", "$", "this", "->", "tlsCertVerification", ",", "'headers'", "=>", "array_replace", "(", "[", "'User-Agent'", "=>", "'HubV4Client (Guzzle)'", "]", ",", "$", "this", "->", "requestHeaders", ",", "[", "'X-Authorization'", "=>", "\"Bearer {$token}\"", "]", ")", ",", "]", ")", ";", "return", "new", "HubV4Client", "(", "$", "httpClient", ")", ";", "}" ]
Get a client for the v4 Hub API. @param string $username @param string $password @throws \RuntimeException if setUserbaseJwtAuthenticatorUrl was not called @throws \Hub\Client\Exception\ClientCreationException
[ "Get", "a", "client", "for", "the", "v4", "Hub", "API", "." ]
3a0cf7ec6e3e5bf465167c283ee3dad9f4daaca3
https://github.com/perinatologie/hub-client-php/blob/3a0cf7ec6e3e5bf465167c283ee3dad9f4daaca3/src/Factory/ApiClientFactory.php#L76-L108
11,502
kengoldfarb/underscore_libs
src/_Libs/_Crypt.php
_Crypt._encryptAESPKCS7
public static function _encryptAESPKCS7($str, $key = _CryptConfig::AES_KEY, $cipher = _CryptConfig::CIPHER, $mode = _CryptConfig::MODE) { $key = self::_chopKeyForAES($key); $block = mcrypt_get_block_size($cipher, $mode); $pad = $block - (strlen($str) % $block); $str .= str_repeat(chr($pad), $pad); $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode), MCRYPT_DEV_URANDOM); $encrypted = mcrypt_encrypt($cipher, $key, $str, $mode, $iv); $ret = base64_encode($iv) . base64_encode($encrypted); return $ret; }
php
public static function _encryptAESPKCS7($str, $key = _CryptConfig::AES_KEY, $cipher = _CryptConfig::CIPHER, $mode = _CryptConfig::MODE) { $key = self::_chopKeyForAES($key); $block = mcrypt_get_block_size($cipher, $mode); $pad = $block - (strlen($str) % $block); $str .= str_repeat(chr($pad), $pad); $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode), MCRYPT_DEV_URANDOM); $encrypted = mcrypt_encrypt($cipher, $key, $str, $mode, $iv); $ret = base64_encode($iv) . base64_encode($encrypted); return $ret; }
[ "public", "static", "function", "_encryptAESPKCS7", "(", "$", "str", ",", "$", "key", "=", "_CryptConfig", "::", "AES_KEY", ",", "$", "cipher", "=", "_CryptConfig", "::", "CIPHER", ",", "$", "mode", "=", "_CryptConfig", "::", "MODE", ")", "{", "$", "key", "=", "self", "::", "_chopKeyForAES", "(", "$", "key", ")", ";", "$", "block", "=", "mcrypt_get_block_size", "(", "$", "cipher", ",", "$", "mode", ")", ";", "$", "pad", "=", "$", "block", "-", "(", "strlen", "(", "$", "str", ")", "%", "$", "block", ")", ";", "$", "str", ".=", "str_repeat", "(", "chr", "(", "$", "pad", ")", ",", "$", "pad", ")", ";", "$", "iv", "=", "mcrypt_create_iv", "(", "mcrypt_get_iv_size", "(", "$", "cipher", ",", "$", "mode", ")", ",", "MCRYPT_DEV_URANDOM", ")", ";", "$", "encrypted", "=", "mcrypt_encrypt", "(", "$", "cipher", ",", "$", "key", ",", "$", "str", ",", "$", "mode", ",", "$", "iv", ")", ";", "$", "ret", "=", "base64_encode", "(", "$", "iv", ")", ".", "base64_encode", "(", "$", "encrypted", ")", ";", "return", "$", "ret", ";", "}" ]
Encrypts a string using AES encryption with PKCS7 padding. Random IV is used Adapted from comments in PHP manual: http://php.net/manual/en/function.mcrypt-encrypt.php @param string $str The string to encrypt @param string $key (optional) The private key to encrypt with (note: anything over 24 chars will be chopped off) @param const $cipher (optional) One of the MCRYPT_RIJNDAEL_ ciphers @param cont $mode (optional) One of the MCRYPT_MODE modes @return string The encrypted string
[ "Encrypts", "a", "string", "using", "AES", "encryption", "with", "PKCS7", "padding", ".", "Random", "IV", "is", "used" ]
e0d584f25093b594e67b8a3068ebd41c7f6483c5
https://github.com/kengoldfarb/underscore_libs/blob/e0d584f25093b594e67b8a3068ebd41c7f6483c5/src/_Libs/_Crypt.php#L92-L101
11,503
kengoldfarb/underscore_libs
src/_Libs/_Crypt.php
_Crypt._decryptAESPKCS7
public static function _decryptAESPKCS7($str, $key = _CryptConfig::AES_KEY, $cipher = _CryptConfig::CIPHER, $mode = _CryptConfig::MODE) { $key = self::_chopKeyForAES($key); $ivLength = self::_getBase64IVLength($cipher, $mode); $iv = substr($str, 0, $ivLength - 1); $iv = base64_decode($iv); $str = substr($str, $ivLength - 1); $str = base64_decode($str); $str = mcrypt_decrypt($cipher, $key, $str, $mode, $iv); $block = mcrypt_get_block_size($cipher, $mode); $pad = ord($str[($len = strlen($str)) - 1]); return substr($str, 0, strlen($str) - $pad); }
php
public static function _decryptAESPKCS7($str, $key = _CryptConfig::AES_KEY, $cipher = _CryptConfig::CIPHER, $mode = _CryptConfig::MODE) { $key = self::_chopKeyForAES($key); $ivLength = self::_getBase64IVLength($cipher, $mode); $iv = substr($str, 0, $ivLength - 1); $iv = base64_decode($iv); $str = substr($str, $ivLength - 1); $str = base64_decode($str); $str = mcrypt_decrypt($cipher, $key, $str, $mode, $iv); $block = mcrypt_get_block_size($cipher, $mode); $pad = ord($str[($len = strlen($str)) - 1]); return substr($str, 0, strlen($str) - $pad); }
[ "public", "static", "function", "_decryptAESPKCS7", "(", "$", "str", ",", "$", "key", "=", "_CryptConfig", "::", "AES_KEY", ",", "$", "cipher", "=", "_CryptConfig", "::", "CIPHER", ",", "$", "mode", "=", "_CryptConfig", "::", "MODE", ")", "{", "$", "key", "=", "self", "::", "_chopKeyForAES", "(", "$", "key", ")", ";", "$", "ivLength", "=", "self", "::", "_getBase64IVLength", "(", "$", "cipher", ",", "$", "mode", ")", ";", "$", "iv", "=", "substr", "(", "$", "str", ",", "0", ",", "$", "ivLength", "-", "1", ")", ";", "$", "iv", "=", "base64_decode", "(", "$", "iv", ")", ";", "$", "str", "=", "substr", "(", "$", "str", ",", "$", "ivLength", "-", "1", ")", ";", "$", "str", "=", "base64_decode", "(", "$", "str", ")", ";", "$", "str", "=", "mcrypt_decrypt", "(", "$", "cipher", ",", "$", "key", ",", "$", "str", ",", "$", "mode", ",", "$", "iv", ")", ";", "$", "block", "=", "mcrypt_get_block_size", "(", "$", "cipher", ",", "$", "mode", ")", ";", "$", "pad", "=", "ord", "(", "$", "str", "[", "(", "$", "len", "=", "strlen", "(", "$", "str", ")", ")", "-", "1", "]", ")", ";", "return", "substr", "(", "$", "str", ",", "0", ",", "strlen", "(", "$", "str", ")", "-", "$", "pad", ")", ";", "}" ]
Decrypts a string using AES encryption with PKCS7 padding. Adapted from comments in PHP manual: http://php.net/manual/en/function.mcrypt-encrypt.php @param string $str The string to encrypt @param string $key (optional) The private key to encrypt with (note: anything over 24 chars will be chopped off) @param const $cipher (optional) One of the MCRYPT_RIJNDAEL_ ciphers @param cont $mode (optional) One of the MCRYPT_MODE modes @return string The encrypted string
[ "Decrypts", "a", "string", "using", "AES", "encryption", "with", "PKCS7", "padding", "." ]
e0d584f25093b594e67b8a3068ebd41c7f6483c5
https://github.com/kengoldfarb/underscore_libs/blob/e0d584f25093b594e67b8a3068ebd41c7f6483c5/src/_Libs/_Crypt.php#L115-L126
11,504
kengoldfarb/underscore_libs
src/_Libs/_Crypt.php
_Crypt._createIV
private static function _createIV($cipher, $mode) { $size = self::_getIVSize($cipher, $mode); return mcrypt_create_iv($size, MCRYPT_DEV_RANDOM); }
php
private static function _createIV($cipher, $mode) { $size = self::_getIVSize($cipher, $mode); return mcrypt_create_iv($size, MCRYPT_DEV_RANDOM); }
[ "private", "static", "function", "_createIV", "(", "$", "cipher", ",", "$", "mode", ")", "{", "$", "size", "=", "self", "::", "_getIVSize", "(", "$", "cipher", ",", "$", "mode", ")", ";", "return", "mcrypt_create_iv", "(", "$", "size", ",", "MCRYPT_DEV_RANDOM", ")", ";", "}" ]
Generates an initialization vector based on cipher and mode @param const $cipher The cipher to be used @param const $mode The mode to be used @return string The initialization vector
[ "Generates", "an", "initialization", "vector", "based", "on", "cipher", "and", "mode" ]
e0d584f25093b594e67b8a3068ebd41c7f6483c5
https://github.com/kengoldfarb/underscore_libs/blob/e0d584f25093b594e67b8a3068ebd41c7f6483c5/src/_Libs/_Crypt.php#L212-L215
11,505
zepi/turbo-base
Zepi/Api/Rest/src/Helper/FrontendHelper.php
FrontendHelper.parseAuthorizationString
protected function parseAuthorizationString($authorizationString) { if (strpos($authorizationString, 'Basic') !== false) { $authorizationString = trim(substr($authorizationString, 6)); } $decoded = base64_decode($authorizationString); $delimiterPos = strpos($decoded, ':'); return array( 'publicKey' => substr($decoded, 0, $delimiterPos), 'hmac' => substr($decoded, $delimiterPos + 1) ); }
php
protected function parseAuthorizationString($authorizationString) { if (strpos($authorizationString, 'Basic') !== false) { $authorizationString = trim(substr($authorizationString, 6)); } $decoded = base64_decode($authorizationString); $delimiterPos = strpos($decoded, ':'); return array( 'publicKey' => substr($decoded, 0, $delimiterPos), 'hmac' => substr($decoded, $delimiterPos + 1) ); }
[ "protected", "function", "parseAuthorizationString", "(", "$", "authorizationString", ")", "{", "if", "(", "strpos", "(", "$", "authorizationString", ",", "'Basic'", ")", "!==", "false", ")", "{", "$", "authorizationString", "=", "trim", "(", "substr", "(", "$", "authorizationString", ",", "6", ")", ")", ";", "}", "$", "decoded", "=", "base64_decode", "(", "$", "authorizationString", ")", ";", "$", "delimiterPos", "=", "strpos", "(", "$", "decoded", ",", "':'", ")", ";", "return", "array", "(", "'publicKey'", "=>", "substr", "(", "$", "decoded", ",", "0", ",", "$", "delimiterPos", ")", ",", "'hmac'", "=>", "substr", "(", "$", "decoded", ",", "$", "delimiterPos", "+", "1", ")", ")", ";", "}" ]
Parses the authorization string and returns an array with the public key and the hmac @access protected @param string $authorizationString @return array
[ "Parses", "the", "authorization", "string", "and", "returns", "an", "array", "with", "the", "public", "key", "and", "the", "hmac" ]
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Api/Rest/src/Helper/FrontendHelper.php#L170-L183
11,506
soloproyectos-php/db
src/db/DbConnector.php
DbConnector.startDebug
public function startDebug($listener = null, $type = "") { if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) { throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'"); } $this->_debugListener = $listener !== null? $listener: function ($sql) { echo "$sql\n"; }; $types = Text::isEmpty($type)? ["exec", "query"]: [$type]; foreach ($types as $type) { $this->_debugger->on($type, $this->_debugListener); } }
php
public function startDebug($listener = null, $type = "") { if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) { throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'"); } $this->_debugListener = $listener !== null? $listener: function ($sql) { echo "$sql\n"; }; $types = Text::isEmpty($type)? ["exec", "query"]: [$type]; foreach ($types as $type) { $this->_debugger->on($type, $this->_debugListener); } }
[ "public", "function", "startDebug", "(", "$", "listener", "=", "null", ",", "$", "type", "=", "\"\"", ")", "{", "if", "(", "!", "Text", "::", "isEmpty", "(", "$", "type", ")", "&&", "!", "in_array", "(", "$", "type", ",", "[", "\"exec\"", ",", "\"query\"", "]", ")", ")", "{", "throw", "new", "DbException", "(", "\"Invalid filter type. Valid filter types are 'exec' and 'query'\"", ")", ";", "}", "$", "this", "->", "_debugListener", "=", "$", "listener", "!==", "null", "?", "$", "listener", ":", "function", "(", "$", "sql", ")", "{", "echo", "\"$sql\\n\"", ";", "}", ";", "$", "types", "=", "Text", "::", "isEmpty", "(", "$", "type", ")", "?", "[", "\"exec\"", ",", "\"query\"", "]", ":", "[", "$", "type", "]", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "$", "this", "->", "_debugger", "->", "on", "(", "$", "type", ",", "$", "this", "->", "_debugListener", ")", ";", "}", "}" ]
Starts the debugger mechanism. @param callable $listener Debug listener @param string $type Listener type ('query' or 'exec', not required) @return void
[ "Starts", "the", "debugger", "mechanism", "." ]
09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6
https://github.com/soloproyectos-php/db/blob/09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6/src/db/DbConnector.php#L80-L94
11,507
soloproyectos-php/db
src/db/DbConnector.php
DbConnector.stopDebug
public function stopDebug($type = "") { if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) { throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'"); } $types = Text::isEmpty($type)? ["exec", "query"]: [$type]; foreach ($types as $type) { $this->_debugger->off($type, $this->_debugListener); } }
php
public function stopDebug($type = "") { if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) { throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'"); } $types = Text::isEmpty($type)? ["exec", "query"]: [$type]; foreach ($types as $type) { $this->_debugger->off($type, $this->_debugListener); } }
[ "public", "function", "stopDebug", "(", "$", "type", "=", "\"\"", ")", "{", "if", "(", "!", "Text", "::", "isEmpty", "(", "$", "type", ")", "&&", "!", "in_array", "(", "$", "type", ",", "[", "\"exec\"", ",", "\"query\"", "]", ")", ")", "{", "throw", "new", "DbException", "(", "\"Invalid filter type. Valid filter types are 'exec' and 'query'\"", ")", ";", "}", "$", "types", "=", "Text", "::", "isEmpty", "(", "$", "type", ")", "?", "[", "\"exec\"", ",", "\"query\"", "]", ":", "[", "$", "type", "]", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "$", "this", "->", "_debugger", "->", "off", "(", "$", "type", ",", "$", "this", "->", "_debugListener", ")", ";", "}", "}" ]
Stops the debugger mechanism. @param string $type Listener type ('query' or 'exec', not required) @return void
[ "Stops", "the", "debugger", "mechanism", "." ]
09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6
https://github.com/soloproyectos-php/db/blob/09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6/src/db/DbConnector.php#L103-L113
11,508
soloproyectos-php/db
src/db/DbConnector.php
DbConnector.addDebugListener
public function addDebugListener($listener, $type = "") { if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) { throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'"); } $types = Text::isEmpty($type)? ["exec", "query"]: [$type]; foreach ($types as $type) { $this->_debugger->on($type, $listener); } }
php
public function addDebugListener($listener, $type = "") { if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) { throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'"); } $types = Text::isEmpty($type)? ["exec", "query"]: [$type]; foreach ($types as $type) { $this->_debugger->on($type, $listener); } }
[ "public", "function", "addDebugListener", "(", "$", "listener", ",", "$", "type", "=", "\"\"", ")", "{", "if", "(", "!", "Text", "::", "isEmpty", "(", "$", "type", ")", "&&", "!", "in_array", "(", "$", "type", ",", "[", "\"exec\"", ",", "\"query\"", "]", ")", ")", "{", "throw", "new", "DbException", "(", "\"Invalid filter type. Valid filter types are 'exec' and 'query'\"", ")", ";", "}", "$", "types", "=", "Text", "::", "isEmpty", "(", "$", "type", ")", "?", "[", "\"exec\"", ",", "\"query\"", "]", ":", "[", "$", "type", "]", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "$", "this", "->", "_debugger", "->", "on", "(", "$", "type", ",", "$", "listener", ")", ";", "}", "}" ]
Adds a debug listener. @param Callable $listener Listener @param string $type Filter type ('exec' or 'query'. Not required) @return void
[ "Adds", "a", "debug", "listener", "." ]
09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6
https://github.com/soloproyectos-php/db/blob/09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6/src/db/DbConnector.php#L123-L133
11,509
soloproyectos-php/db
src/db/DbConnector.php
DbConnector.query
public function query($sql, $arguments = array()) { $this->_debugger->trigger("query", [$sql, $arguments]); $ret = new DbSource($this, $sql, $arguments); return $ret; }
php
public function query($sql, $arguments = array()) { $this->_debugger->trigger("query", [$sql, $arguments]); $ret = new DbSource($this, $sql, $arguments); return $ret; }
[ "public", "function", "query", "(", "$", "sql", ",", "$", "arguments", "=", "array", "(", ")", ")", "{", "$", "this", "->", "_debugger", "->", "trigger", "(", "\"query\"", ",", "[", "$", "sql", ",", "$", "arguments", "]", ")", ";", "$", "ret", "=", "new", "DbSource", "(", "$", "this", ",", "$", "sql", ",", "$", "arguments", ")", ";", "return", "$", "ret", ";", "}" ]
Executes a DDL statement. This function executes a DDL statement (select, show, describe, etc...) and returns a datasource. Examples: ```php $db = new DbConnector($dbname, $username, $password); // retrieves a single row $row = $db->query("select count(*) from table"); echo $row[0]; // retrieves multiple rows $rows = $db->query("select id, name from mytable where section = ?", "my-section"); foreach ($rows as $row) { echo "$row[id]: $row[name]\n"; } // uses an array as arguments $rows = $db->query("select id, name from mytable where col1 = ? and col2 = ?", array(101, 102)); echo "Number of rows" . count($rows); ``` @param string $sql SQL statement @param scalar|array $arguments Arguments @return DbSource
[ "Executes", "a", "DDL", "statement", "." ]
09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6
https://github.com/soloproyectos-php/db/blob/09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6/src/db/DbConnector.php#L209-L214
11,510
soloproyectos-php/db
src/db/DbConnector.php
DbConnector.fetchRows
public function fetchRows($sql, $arguments = array()) { $ret = array(); $result = $this->_exec($sql, $arguments); // fetches all rows while ($row = $result->fetch_array()) { array_push($ret, $row); } $result->close(); return $ret; }
php
public function fetchRows($sql, $arguments = array()) { $ret = array(); $result = $this->_exec($sql, $arguments); // fetches all rows while ($row = $result->fetch_array()) { array_push($ret, $row); } $result->close(); return $ret; }
[ "public", "function", "fetchRows", "(", "$", "sql", ",", "$", "arguments", "=", "array", "(", ")", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "$", "result", "=", "$", "this", "->", "_exec", "(", "$", "sql", ",", "$", "arguments", ")", ";", "// fetches all rows", "while", "(", "$", "row", "=", "$", "result", "->", "fetch_array", "(", ")", ")", "{", "array_push", "(", "$", "ret", ",", "$", "row", ")", ";", "}", "$", "result", "->", "close", "(", ")", ";", "return", "$", "ret", ";", "}" ]
Executes a DDL statement and returns all rows. This function executes a DDL statement (select, show, describe, etc...) and returns an associative array. I recommend to use DbConnector::query() instead. @param string $sql SQL statement @param scalar|array $arguments List of arguments (not required) @return array
[ "Executes", "a", "DDL", "statement", "and", "returns", "all", "rows", "." ]
09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6
https://github.com/soloproyectos-php/db/blob/09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6/src/db/DbConnector.php#L227-L239
11,511
soloproyectos-php/db
src/db/DbConnector.php
DbConnector._replaceArguments
private function _replaceArguments($sql, $arguments) { if (!is_array($arguments)) { $arguments = array($arguments); } // searches string segments (startPos, endPos) $stringSegments = []; if (preg_match_all('/(["\'`])((?:\\\\\1|.)*?)\1/', $sql, $matches, PREG_OFFSET_CAPTURE)) { foreach ($matches[2] as $match) { $startPos = $match[1]; $endPos = $startPos + strlen($match[0]); array_push($stringSegments, [$startPos, $endPos]); } } // searches arguments position $argsPos = []; preg_match_all('/\?/', $sql, $matches, PREG_OFFSET_CAPTURE); foreach ($matches[0] as $match) { array_push($argsPos, $match[1]); } // replaces arguments $matchCount = 0; $argCount = 0; return preg_replace_callback( '/\?/', function ($matches) use (&$argCount, &$matchCount, $arguments, $argsPos, $stringSegments) { $ret = $matches[0]; if ($argCount < count($arguments)) { // is the current match inside a quoted string? $argPos = $argsPos[$matchCount]; $isInsideQuotedString = false; foreach ($stringSegments as $segment) { if ($argPos >= $segment[0] && $argPos < $segment[1]) { $isInsideQuotedString = true; break; } } if (!$isInsideQuotedString) { $ret = $this->quote($arguments[$argCount++]); } } $matchCount++; return $ret; }, $sql ); }
php
private function _replaceArguments($sql, $arguments) { if (!is_array($arguments)) { $arguments = array($arguments); } // searches string segments (startPos, endPos) $stringSegments = []; if (preg_match_all('/(["\'`])((?:\\\\\1|.)*?)\1/', $sql, $matches, PREG_OFFSET_CAPTURE)) { foreach ($matches[2] as $match) { $startPos = $match[1]; $endPos = $startPos + strlen($match[0]); array_push($stringSegments, [$startPos, $endPos]); } } // searches arguments position $argsPos = []; preg_match_all('/\?/', $sql, $matches, PREG_OFFSET_CAPTURE); foreach ($matches[0] as $match) { array_push($argsPos, $match[1]); } // replaces arguments $matchCount = 0; $argCount = 0; return preg_replace_callback( '/\?/', function ($matches) use (&$argCount, &$matchCount, $arguments, $argsPos, $stringSegments) { $ret = $matches[0]; if ($argCount < count($arguments)) { // is the current match inside a quoted string? $argPos = $argsPos[$matchCount]; $isInsideQuotedString = false; foreach ($stringSegments as $segment) { if ($argPos >= $segment[0] && $argPos < $segment[1]) { $isInsideQuotedString = true; break; } } if (!$isInsideQuotedString) { $ret = $this->quote($arguments[$argCount++]); } } $matchCount++; return $ret; }, $sql ); }
[ "private", "function", "_replaceArguments", "(", "$", "sql", ",", "$", "arguments", ")", "{", "if", "(", "!", "is_array", "(", "$", "arguments", ")", ")", "{", "$", "arguments", "=", "array", "(", "$", "arguments", ")", ";", "}", "// searches string segments (startPos, endPos)", "$", "stringSegments", "=", "[", "]", ";", "if", "(", "preg_match_all", "(", "'/([\"\\'`])((?:\\\\\\\\\\1|.)*?)\\1/'", ",", "$", "sql", ",", "$", "matches", ",", "PREG_OFFSET_CAPTURE", ")", ")", "{", "foreach", "(", "$", "matches", "[", "2", "]", "as", "$", "match", ")", "{", "$", "startPos", "=", "$", "match", "[", "1", "]", ";", "$", "endPos", "=", "$", "startPos", "+", "strlen", "(", "$", "match", "[", "0", "]", ")", ";", "array_push", "(", "$", "stringSegments", ",", "[", "$", "startPos", ",", "$", "endPos", "]", ")", ";", "}", "}", "// searches arguments position", "$", "argsPos", "=", "[", "]", ";", "preg_match_all", "(", "'/\\?/'", ",", "$", "sql", ",", "$", "matches", ",", "PREG_OFFSET_CAPTURE", ")", ";", "foreach", "(", "$", "matches", "[", "0", "]", "as", "$", "match", ")", "{", "array_push", "(", "$", "argsPos", ",", "$", "match", "[", "1", "]", ")", ";", "}", "// replaces arguments", "$", "matchCount", "=", "0", ";", "$", "argCount", "=", "0", ";", "return", "preg_replace_callback", "(", "'/\\?/'", ",", "function", "(", "$", "matches", ")", "use", "(", "&", "$", "argCount", ",", "&", "$", "matchCount", ",", "$", "arguments", ",", "$", "argsPos", ",", "$", "stringSegments", ")", "{", "$", "ret", "=", "$", "matches", "[", "0", "]", ";", "if", "(", "$", "argCount", "<", "count", "(", "$", "arguments", ")", ")", "{", "// is the current match inside a quoted string?", "$", "argPos", "=", "$", "argsPos", "[", "$", "matchCount", "]", ";", "$", "isInsideQuotedString", "=", "false", ";", "foreach", "(", "$", "stringSegments", "as", "$", "segment", ")", "{", "if", "(", "$", "argPos", ">=", "$", "segment", "[", "0", "]", "&&", "$", "argPos", "<", "$", "segment", "[", "1", "]", ")", "{", "$", "isInsideQuotedString", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "isInsideQuotedString", ")", "{", "$", "ret", "=", "$", "this", "->", "quote", "(", "$", "arguments", "[", "$", "argCount", "++", "]", ")", ";", "}", "}", "$", "matchCount", "++", ";", "return", "$", "ret", ";", "}", ",", "$", "sql", ")", ";", "}" ]
Replaces arguments in an SQL statement. @param string $sql SQL statement @param scalar|array $arguments List of arguments @return string
[ "Replaces", "arguments", "in", "an", "SQL", "statement", "." ]
09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6
https://github.com/soloproyectos-php/db/blob/09db63e37bb4fc3d9f6cc2f581e9e2423dc82cf6/src/db/DbConnector.php#L293-L345
11,512
aedart/model
src/Traits/Strings/DeliveryAddressTrait.php
DeliveryAddressTrait.getDeliveryAddress
public function getDeliveryAddress() : ?string { if ( ! $this->hasDeliveryAddress()) { $this->setDeliveryAddress($this->getDefaultDeliveryAddress()); } return $this->deliveryAddress; }
php
public function getDeliveryAddress() : ?string { if ( ! $this->hasDeliveryAddress()) { $this->setDeliveryAddress($this->getDefaultDeliveryAddress()); } return $this->deliveryAddress; }
[ "public", "function", "getDeliveryAddress", "(", ")", ":", "?", "string", "{", "if", "(", "!", "$", "this", "->", "hasDeliveryAddress", "(", ")", ")", "{", "$", "this", "->", "setDeliveryAddress", "(", "$", "this", "->", "getDefaultDeliveryAddress", "(", ")", ")", ";", "}", "return", "$", "this", "->", "deliveryAddress", ";", "}" ]
Get delivery address If no "delivery address" value has been set, this method will set and return a default "delivery address" value, if any such value is available @see getDefaultDeliveryAddress() @return string|null delivery address or null if no delivery address has been set
[ "Get", "delivery", "address" ]
9a562c1c53a276d01ace0ab71f5305458bea542f
https://github.com/aedart/model/blob/9a562c1c53a276d01ace0ab71f5305458bea542f/src/Traits/Strings/DeliveryAddressTrait.php#L48-L54
11,513
snapwp/snap-debug
src/Debug_Service_Provider.php
Debug_Service_Provider.init_whoops
private function init_whoops() { $whoops = new Run; $general = new General(); $whoops->pushHandler($general->get_handler()); $whoops->pushHandler(new Ajax()); $whoops->pushHandler(new Rest_Api()); $whoops->register(); \ob_start(); // Add to Service container. Container::add_instance($whoops); }
php
private function init_whoops() { $whoops = new Run; $general = new General(); $whoops->pushHandler($general->get_handler()); $whoops->pushHandler(new Ajax()); $whoops->pushHandler(new Rest_Api()); $whoops->register(); \ob_start(); // Add to Service container. Container::add_instance($whoops); }
[ "private", "function", "init_whoops", "(", ")", "{", "$", "whoops", "=", "new", "Run", ";", "$", "general", "=", "new", "General", "(", ")", ";", "$", "whoops", "->", "pushHandler", "(", "$", "general", "->", "get_handler", "(", ")", ")", ";", "$", "whoops", "->", "pushHandler", "(", "new", "Ajax", "(", ")", ")", ";", "$", "whoops", "->", "pushHandler", "(", "new", "Rest_Api", "(", ")", ")", ";", "$", "whoops", "->", "register", "(", ")", ";", "\\", "ob_start", "(", ")", ";", "// Add to Service container.", "Container", "::", "add_instance", "(", "$", "whoops", ")", ";", "}" ]
Register the Whoops service into the service container. @since 1.0.0
[ "Register", "the", "Whoops", "service", "into", "the", "service", "container", "." ]
49c0c258ce50098a3fca076ce122adf57571f2e2
https://github.com/snapwp/snap-debug/blob/49c0c258ce50098a3fca076ce122adf57571f2e2/src/Debug_Service_Provider.php#L55-L70
11,514
gregoriohc/argentum-common
src/Common/Tax.php
Tax.getAmount
public function getAmount($baseAmount = null) { if (is_numeric($this->getFixedAmount())) { return $this->getFixedAmount(); } if (null === $baseAmount) { $baseAmount = $this->getBaseAmount(); } return round($baseAmount * $this->getRate() / 100, 2); }
php
public function getAmount($baseAmount = null) { if (is_numeric($this->getFixedAmount())) { return $this->getFixedAmount(); } if (null === $baseAmount) { $baseAmount = $this->getBaseAmount(); } return round($baseAmount * $this->getRate() / 100, 2); }
[ "public", "function", "getAmount", "(", "$", "baseAmount", "=", "null", ")", "{", "if", "(", "is_numeric", "(", "$", "this", "->", "getFixedAmount", "(", ")", ")", ")", "{", "return", "$", "this", "->", "getFixedAmount", "(", ")", ";", "}", "if", "(", "null", "===", "$", "baseAmount", ")", "{", "$", "baseAmount", "=", "$", "this", "->", "getBaseAmount", "(", ")", ";", "}", "return", "round", "(", "$", "baseAmount", "*", "$", "this", "->", "getRate", "(", ")", "/", "100", ",", "2", ")", ";", "}" ]
Get tax amount from a given base amount @param float $baseAmount @return float
[ "Get", "tax", "amount", "from", "a", "given", "base", "amount" ]
9d914d19aa6ed25d33f00d603eff486484f0f3ba
https://github.com/gregoriohc/argentum-common/blob/9d914d19aa6ed25d33f00d603eff486484f0f3ba/src/Common/Tax.php#L208-L219
11,515
agentmedia/phine-news
src/News/Modules/Frontend/ArticleList.php
ArticleList.InitArticles
private function InitArticles() { $this->archive = Archive::Schema()->ByPage($this->CurrentPage()); if ($this->archive) { $this->InitArchiveArticles(); return; } $this->category = Category::Schema()->ByPage($this->CurrentPage()); if ($this->category) { $this->archive = $this->category->GetArchive(); $this->InitCategoryArticles(); } }
php
private function InitArticles() { $this->archive = Archive::Schema()->ByPage($this->CurrentPage()); if ($this->archive) { $this->InitArchiveArticles(); return; } $this->category = Category::Schema()->ByPage($this->CurrentPage()); if ($this->category) { $this->archive = $this->category->GetArchive(); $this->InitCategoryArticles(); } }
[ "private", "function", "InitArticles", "(", ")", "{", "$", "this", "->", "archive", "=", "Archive", "::", "Schema", "(", ")", "->", "ByPage", "(", "$", "this", "->", "CurrentPage", "(", ")", ")", ";", "if", "(", "$", "this", "->", "archive", ")", "{", "$", "this", "->", "InitArchiveArticles", "(", ")", ";", "return", ";", "}", "$", "this", "->", "category", "=", "Category", "::", "Schema", "(", ")", "->", "ByPage", "(", "$", "this", "->", "CurrentPage", "(", ")", ")", ";", "if", "(", "$", "this", "->", "category", ")", "{", "$", "this", "->", "archive", "=", "$", "this", "->", "category", "->", "GetArchive", "(", ")", ";", "$", "this", "->", "InitCategoryArticles", "(", ")", ";", "}", "}" ]
Initializes the article array
[ "Initializes", "the", "article", "array" ]
51abc830fecd1325f0b7d28391ecd924cdc7c945
https://github.com/agentmedia/phine-news/blob/51abc830fecd1325f0b7d28391ecd924cdc7c945/src/News/Modules/Frontend/ArticleList.php#L97-L111
11,516
agentmedia/phine-news
src/News/Modules/Frontend/ArticleList.php
ArticleList.InitArchiveArticles
private function InitArchiveArticles() { $sql = Access::SqlBuilder(); $tblArticle = Article::Schema()->Table(); $tblCategory = Category::Schema()->Table(); $join = $sql->Join($tblCategory); $joinCond = $sql->Equals($tblArticle->Field('Category'), $tblCategory->Field('ID')); $orderBy = $sql->OrderList($sql->OrderDesc($tblArticle->Field('Created'))); $where = $this->PublishedCondition()-> And_($sql->Equals($tblCategory->Field('Archive'), $sql->Value($this->archive->GetID()))); $this->articles = Article::Schema()->Fetch(false, $where, $orderBy, null, $this->ArticleOffset(), $this->ArticleCount(), $join, Sql\JoinType::Inner(), $joinCond); $this->articlesTotal = Article::Schema()->Count(false, $where, null, $join, Sql\JoinType::Inner(), $joinCond); }
php
private function InitArchiveArticles() { $sql = Access::SqlBuilder(); $tblArticle = Article::Schema()->Table(); $tblCategory = Category::Schema()->Table(); $join = $sql->Join($tblCategory); $joinCond = $sql->Equals($tblArticle->Field('Category'), $tblCategory->Field('ID')); $orderBy = $sql->OrderList($sql->OrderDesc($tblArticle->Field('Created'))); $where = $this->PublishedCondition()-> And_($sql->Equals($tblCategory->Field('Archive'), $sql->Value($this->archive->GetID()))); $this->articles = Article::Schema()->Fetch(false, $where, $orderBy, null, $this->ArticleOffset(), $this->ArticleCount(), $join, Sql\JoinType::Inner(), $joinCond); $this->articlesTotal = Article::Schema()->Count(false, $where, null, $join, Sql\JoinType::Inner(), $joinCond); }
[ "private", "function", "InitArchiveArticles", "(", ")", "{", "$", "sql", "=", "Access", "::", "SqlBuilder", "(", ")", ";", "$", "tblArticle", "=", "Article", "::", "Schema", "(", ")", "->", "Table", "(", ")", ";", "$", "tblCategory", "=", "Category", "::", "Schema", "(", ")", "->", "Table", "(", ")", ";", "$", "join", "=", "$", "sql", "->", "Join", "(", "$", "tblCategory", ")", ";", "$", "joinCond", "=", "$", "sql", "->", "Equals", "(", "$", "tblArticle", "->", "Field", "(", "'Category'", ")", ",", "$", "tblCategory", "->", "Field", "(", "'ID'", ")", ")", ";", "$", "orderBy", "=", "$", "sql", "->", "OrderList", "(", "$", "sql", "->", "OrderDesc", "(", "$", "tblArticle", "->", "Field", "(", "'Created'", ")", ")", ")", ";", "$", "where", "=", "$", "this", "->", "PublishedCondition", "(", ")", "->", "And_", "(", "$", "sql", "->", "Equals", "(", "$", "tblCategory", "->", "Field", "(", "'Archive'", ")", ",", "$", "sql", "->", "Value", "(", "$", "this", "->", "archive", "->", "GetID", "(", ")", ")", ")", ")", ";", "$", "this", "->", "articles", "=", "Article", "::", "Schema", "(", ")", "->", "Fetch", "(", "false", ",", "$", "where", ",", "$", "orderBy", ",", "null", ",", "$", "this", "->", "ArticleOffset", "(", ")", ",", "$", "this", "->", "ArticleCount", "(", ")", ",", "$", "join", ",", "Sql", "\\", "JoinType", "::", "Inner", "(", ")", ",", "$", "joinCond", ")", ";", "$", "this", "->", "articlesTotal", "=", "Article", "::", "Schema", "(", ")", "->", "Count", "(", "false", ",", "$", "where", ",", "null", ",", "$", "join", ",", "Sql", "\\", "JoinType", "::", "Inner", "(", ")", ",", "$", "joinCond", ")", ";", "}" ]
Initializes article array for a page assigned archive
[ "Initializes", "article", "array", "for", "a", "page", "assigned", "archive" ]
51abc830fecd1325f0b7d28391ecd924cdc7c945
https://github.com/agentmedia/phine-news/blob/51abc830fecd1325f0b7d28391ecd924cdc7c945/src/News/Modules/Frontend/ArticleList.php#L116-L129
11,517
agentmedia/phine-news
src/News/Modules/Frontend/ArticleList.php
ArticleList.InitCategoryArticles
private function InitCategoryArticles() { $sql = Access::SqlBuilder(); $tblArticle = Article::Schema()->Table(); $orderBy = $sql->OrderList($sql->OrderDesc($tblArticle->Field('Created'))); $where = $this->PublishedCondition()-> And_($sql->Equals($tblArticle->Field('Category'), $sql->Value($this->category->GetID()))); $this->articles = Article::Schema()->Fetch(false, $where, $orderBy); $this->articlesTotal = Article::Schema()->Count(false, $where); }
php
private function InitCategoryArticles() { $sql = Access::SqlBuilder(); $tblArticle = Article::Schema()->Table(); $orderBy = $sql->OrderList($sql->OrderDesc($tblArticle->Field('Created'))); $where = $this->PublishedCondition()-> And_($sql->Equals($tblArticle->Field('Category'), $sql->Value($this->category->GetID()))); $this->articles = Article::Schema()->Fetch(false, $where, $orderBy); $this->articlesTotal = Article::Schema()->Count(false, $where); }
[ "private", "function", "InitCategoryArticles", "(", ")", "{", "$", "sql", "=", "Access", "::", "SqlBuilder", "(", ")", ";", "$", "tblArticle", "=", "Article", "::", "Schema", "(", ")", "->", "Table", "(", ")", ";", "$", "orderBy", "=", "$", "sql", "->", "OrderList", "(", "$", "sql", "->", "OrderDesc", "(", "$", "tblArticle", "->", "Field", "(", "'Created'", ")", ")", ")", ";", "$", "where", "=", "$", "this", "->", "PublishedCondition", "(", ")", "->", "And_", "(", "$", "sql", "->", "Equals", "(", "$", "tblArticle", "->", "Field", "(", "'Category'", ")", ",", "$", "sql", "->", "Value", "(", "$", "this", "->", "category", "->", "GetID", "(", ")", ")", ")", ")", ";", "$", "this", "->", "articles", "=", "Article", "::", "Schema", "(", ")", "->", "Fetch", "(", "false", ",", "$", "where", ",", "$", "orderBy", ")", ";", "$", "this", "->", "articlesTotal", "=", "Article", "::", "Schema", "(", ")", "->", "Count", "(", "false", ",", "$", "where", ")", ";", "}" ]
Initializes article array for a page assigned category
[ "Initializes", "article", "array", "for", "a", "page", "assigned", "category" ]
51abc830fecd1325f0b7d28391ecd924cdc7c945
https://github.com/agentmedia/phine-news/blob/51abc830fecd1325f0b7d28391ecd924cdc7c945/src/News/Modules/Frontend/ArticleList.php#L134-L144
11,518
agentmedia/phine-news
src/News/Modules/Frontend/ArticleList.php
ArticleList.PublishedCondition
private function PublishedCondition() { $sql = Access::SqlBuilder(); $sqlNow = $sql->Value(Date::Now()); $tblArticle = Article::Schema()->Table(); return $sql->Equals($tblArticle->Field('Publish'), $sql->Value(true)) ->And_($sql->IsNull($tblArticle->Field('PublishFrom')) ->Or_($sql->LTE($tblArticle->Field('PublishFrom'), $sqlNow))) ->And_($sql->IsNull($tblArticle->Field('PublishTo')) ->Or_($sql->GTE($tblArticle->Field('PublishTo'), $sqlNow))); }
php
private function PublishedCondition() { $sql = Access::SqlBuilder(); $sqlNow = $sql->Value(Date::Now()); $tblArticle = Article::Schema()->Table(); return $sql->Equals($tblArticle->Field('Publish'), $sql->Value(true)) ->And_($sql->IsNull($tblArticle->Field('PublishFrom')) ->Or_($sql->LTE($tblArticle->Field('PublishFrom'), $sqlNow))) ->And_($sql->IsNull($tblArticle->Field('PublishTo')) ->Or_($sql->GTE($tblArticle->Field('PublishTo'), $sqlNow))); }
[ "private", "function", "PublishedCondition", "(", ")", "{", "$", "sql", "=", "Access", "::", "SqlBuilder", "(", ")", ";", "$", "sqlNow", "=", "$", "sql", "->", "Value", "(", "Date", "::", "Now", "(", ")", ")", ";", "$", "tblArticle", "=", "Article", "::", "Schema", "(", ")", "->", "Table", "(", ")", ";", "return", "$", "sql", "->", "Equals", "(", "$", "tblArticle", "->", "Field", "(", "'Publish'", ")", ",", "$", "sql", "->", "Value", "(", "true", ")", ")", "->", "And_", "(", "$", "sql", "->", "IsNull", "(", "$", "tblArticle", "->", "Field", "(", "'PublishFrom'", ")", ")", "->", "Or_", "(", "$", "sql", "->", "LTE", "(", "$", "tblArticle", "->", "Field", "(", "'PublishFrom'", ")", ",", "$", "sqlNow", ")", ")", ")", "->", "And_", "(", "$", "sql", "->", "IsNull", "(", "$", "tblArticle", "->", "Field", "(", "'PublishTo'", ")", ")", "->", "Or_", "(", "$", "sql", "->", "GTE", "(", "$", "tblArticle", "->", "Field", "(", "'PublishTo'", ")", ",", "$", "sqlNow", ")", ")", ")", ";", "}" ]
The condition to retreive published articles, only @return Sql\Condition Returns the sql condition for published articles
[ "The", "condition", "to", "retreive", "published", "articles", "only" ]
51abc830fecd1325f0b7d28391ecd924cdc7c945
https://github.com/agentmedia/phine-news/blob/51abc830fecd1325f0b7d28391ecd924cdc7c945/src/News/Modules/Frontend/ArticleList.php#L149-L159
11,519
agentmedia/phine-news
src/News/Modules/Frontend/ArticleList.php
ArticleList.ArticleOffset
private function ArticleOffset() { $page = max(1, (int)Request::GetData('page')); return ($page - 1) * $this->archive->GetItemsPerPage(); }
php
private function ArticleOffset() { $page = max(1, (int)Request::GetData('page')); return ($page - 1) * $this->archive->GetItemsPerPage(); }
[ "private", "function", "ArticleOffset", "(", ")", "{", "$", "page", "=", "max", "(", "1", ",", "(", "int", ")", "Request", "::", "GetData", "(", "'page'", ")", ")", ";", "return", "(", "$", "page", "-", "1", ")", "*", "$", "this", "->", "archive", "->", "GetItemsPerPage", "(", ")", ";", "}" ]
The offset for the database limit @return int
[ "The", "offset", "for", "the", "database", "limit" ]
51abc830fecd1325f0b7d28391ecd924cdc7c945
https://github.com/agentmedia/phine-news/blob/51abc830fecd1325f0b7d28391ecd924cdc7c945/src/News/Modules/Frontend/ArticleList.php#L185-L189
11,520
userapp-io/userapp-php
lib/UserApp/Http/Response.php
Response.fromRaw
public static function fromRaw($raw){ $response = new Response(); $header_end_offset = strpos($raw, "\r\n\r\n"); $raw_head = substr($raw, 0, $header_end_offset); $raw_body = substr($raw, $header_end_offset+4); $raw_headers = explode("\r\n", $raw_head); $status_head = array_shift($raw_headers); $status_segments = explode(" " , $status_head); $status = new stdClass(); $status->protocol = $status_segments[0]; $status->code = (int)$status_segments[1]; $status->message = $status_segments[2]; $headers = array(); foreach($raw_headers as $header){ $segments = explode(": ", $header, 2); $headers[$segments[0]] = $segments[1]; } $response->status = $status; $response->headers = $headers; $response->body = $raw_body; return $response; }
php
public static function fromRaw($raw){ $response = new Response(); $header_end_offset = strpos($raw, "\r\n\r\n"); $raw_head = substr($raw, 0, $header_end_offset); $raw_body = substr($raw, $header_end_offset+4); $raw_headers = explode("\r\n", $raw_head); $status_head = array_shift($raw_headers); $status_segments = explode(" " , $status_head); $status = new stdClass(); $status->protocol = $status_segments[0]; $status->code = (int)$status_segments[1]; $status->message = $status_segments[2]; $headers = array(); foreach($raw_headers as $header){ $segments = explode(": ", $header, 2); $headers[$segments[0]] = $segments[1]; } $response->status = $status; $response->headers = $headers; $response->body = $raw_body; return $response; }
[ "public", "static", "function", "fromRaw", "(", "$", "raw", ")", "{", "$", "response", "=", "new", "Response", "(", ")", ";", "$", "header_end_offset", "=", "strpos", "(", "$", "raw", ",", "\"\\r\\n\\r\\n\"", ")", ";", "$", "raw_head", "=", "substr", "(", "$", "raw", ",", "0", ",", "$", "header_end_offset", ")", ";", "$", "raw_body", "=", "substr", "(", "$", "raw", ",", "$", "header_end_offset", "+", "4", ")", ";", "$", "raw_headers", "=", "explode", "(", "\"\\r\\n\"", ",", "$", "raw_head", ")", ";", "$", "status_head", "=", "array_shift", "(", "$", "raw_headers", ")", ";", "$", "status_segments", "=", "explode", "(", "\" \"", ",", "$", "status_head", ")", ";", "$", "status", "=", "new", "stdClass", "(", ")", ";", "$", "status", "->", "protocol", "=", "$", "status_segments", "[", "0", "]", ";", "$", "status", "->", "code", "=", "(", "int", ")", "$", "status_segments", "[", "1", "]", ";", "$", "status", "->", "message", "=", "$", "status_segments", "[", "2", "]", ";", "$", "headers", "=", "array", "(", ")", ";", "foreach", "(", "$", "raw_headers", "as", "$", "header", ")", "{", "$", "segments", "=", "explode", "(", "\": \"", ",", "$", "header", ",", "2", ")", ";", "$", "headers", "[", "$", "segments", "[", "0", "]", "]", "=", "$", "segments", "[", "1", "]", ";", "}", "$", "response", "->", "status", "=", "$", "status", ";", "$", "response", "->", "headers", "=", "$", "headers", ";", "$", "response", "->", "body", "=", "$", "raw_body", ";", "return", "$", "response", ";", "}" ]
Parse a raw HTTP response
[ "Parse", "a", "raw", "HTTP", "response" ]
02bc3b55b49a050683697da4fa86c50f95e6637e
https://github.com/userapp-io/userapp-php/blob/02bc3b55b49a050683697da4fa86c50f95e6637e/lib/UserApp/Http/Response.php#L14-L40
11,521
philiplb/CRUDlexUser
src/CRUDlex/PasswordReset.php
PasswordReset.getValidPasswordReset
protected function getValidPasswordReset($token) { $passwordResets = $this->passwordResetData->listEntries(['token' => $token]); if (count($passwordResets) !== 1) { return null; } $passwordReset = $passwordResets[0]; $createdAt = $passwordReset->get('created_at'); if (strtotime($createdAt.' UTC') < time() - 2 * 24 * 60 * 60 || $passwordReset->get('reset')) { return null; } return $passwordReset; }
php
protected function getValidPasswordReset($token) { $passwordResets = $this->passwordResetData->listEntries(['token' => $token]); if (count($passwordResets) !== 1) { return null; } $passwordReset = $passwordResets[0]; $createdAt = $passwordReset->get('created_at'); if (strtotime($createdAt.' UTC') < time() - 2 * 24 * 60 * 60 || $passwordReset->get('reset')) { return null; } return $passwordReset; }
[ "protected", "function", "getValidPasswordReset", "(", "$", "token", ")", "{", "$", "passwordResets", "=", "$", "this", "->", "passwordResetData", "->", "listEntries", "(", "[", "'token'", "=>", "$", "token", "]", ")", ";", "if", "(", "count", "(", "$", "passwordResets", ")", "!==", "1", ")", "{", "return", "null", ";", "}", "$", "passwordReset", "=", "$", "passwordResets", "[", "0", "]", ";", "$", "createdAt", "=", "$", "passwordReset", "->", "get", "(", "'created_at'", ")", ";", "if", "(", "strtotime", "(", "$", "createdAt", ".", "' UTC'", ")", "<", "time", "(", ")", "-", "2", "*", "24", "*", "60", "*", "60", "||", "$", "passwordReset", "->", "get", "(", "'reset'", ")", ")", "{", "return", "null", ";", "}", "return", "$", "passwordReset", ";", "}" ]
Gets the password reset of a token but only if it is younger than 48h. @param string $token the password reset token @return null|CRUDlex\Entity the password reset request
[ "Gets", "the", "password", "reset", "of", "a", "token", "but", "only", "if", "it", "is", "younger", "than", "48h", "." ]
011c70106786ded665200a1b6b61234800c2b802
https://github.com/philiplb/CRUDlexUser/blob/011c70106786ded665200a1b6b61234800c2b802/src/CRUDlex/PasswordReset.php#L41-L55
11,522
philiplb/CRUDlexUser
src/CRUDlex/PasswordReset.php
PasswordReset.requestPasswordReset
public function requestPasswordReset($identifyingField, $identifyingValue) { $users = $this->userData->listEntries([$identifyingField => $identifyingValue]); if (count($users) !== 1) { return null; } $user = $users[0]; $userSetup = new UserSetup(); do { $token = $userSetup->getSalt(32); $tokenFound = $this->passwordResetData->countBy($this->passwordResetData->getDefinition()->getTable(), ['token' => $token], ['token' => '='], true) === 0; } while (!$tokenFound); $passwordReset = $this->passwordResetData->createEmpty(); $passwordReset->set('user', $user->get('id')); $passwordReset->set('token', $token); $this->passwordResetData->create($passwordReset); return $token; }
php
public function requestPasswordReset($identifyingField, $identifyingValue) { $users = $this->userData->listEntries([$identifyingField => $identifyingValue]); if (count($users) !== 1) { return null; } $user = $users[0]; $userSetup = new UserSetup(); do { $token = $userSetup->getSalt(32); $tokenFound = $this->passwordResetData->countBy($this->passwordResetData->getDefinition()->getTable(), ['token' => $token], ['token' => '='], true) === 0; } while (!$tokenFound); $passwordReset = $this->passwordResetData->createEmpty(); $passwordReset->set('user', $user->get('id')); $passwordReset->set('token', $token); $this->passwordResetData->create($passwordReset); return $token; }
[ "public", "function", "requestPasswordReset", "(", "$", "identifyingField", ",", "$", "identifyingValue", ")", "{", "$", "users", "=", "$", "this", "->", "userData", "->", "listEntries", "(", "[", "$", "identifyingField", "=>", "$", "identifyingValue", "]", ")", ";", "if", "(", "count", "(", "$", "users", ")", "!==", "1", ")", "{", "return", "null", ";", "}", "$", "user", "=", "$", "users", "[", "0", "]", ";", "$", "userSetup", "=", "new", "UserSetup", "(", ")", ";", "do", "{", "$", "token", "=", "$", "userSetup", "->", "getSalt", "(", "32", ")", ";", "$", "tokenFound", "=", "$", "this", "->", "passwordResetData", "->", "countBy", "(", "$", "this", "->", "passwordResetData", "->", "getDefinition", "(", ")", "->", "getTable", "(", ")", ",", "[", "'token'", "=>", "$", "token", "]", ",", "[", "'token'", "=>", "'='", "]", ",", "true", ")", "===", "0", ";", "}", "while", "(", "!", "$", "tokenFound", ")", ";", "$", "passwordReset", "=", "$", "this", "->", "passwordResetData", "->", "createEmpty", "(", ")", ";", "$", "passwordReset", "->", "set", "(", "'user'", ",", "$", "user", "->", "get", "(", "'id'", ")", ")", ";", "$", "passwordReset", "->", "set", "(", "'token'", ",", "$", "token", ")", ";", "$", "this", "->", "passwordResetData", "->", "create", "(", "$", "passwordReset", ")", ";", "return", "$", "token", ";", "}" ]
Creates a password reset request. @param string $identifyingField the identifying field to grab an user, likely the email @param string $identifyingValue the identifying value to grab an user, likely the email @return null|string the token of the password reset instance ready to be send to the user via a secondary channel like email; might be null if the user could not be identified uniquly via the given parameters: either zero or more than one users were found
[ "Creates", "a", "password", "reset", "request", "." ]
011c70106786ded665200a1b6b61234800c2b802
https://github.com/philiplb/CRUDlexUser/blob/011c70106786ded665200a1b6b61234800c2b802/src/CRUDlex/PasswordReset.php#L85-L107
11,523
philiplb/CRUDlexUser
src/CRUDlex/PasswordReset.php
PasswordReset.resetPassword
public function resetPassword($token, $newPassword) { $passwordReset = $this->getValidPasswordReset($token); if ($passwordReset === null) { return false; } $user = $passwordReset->get('user'); $user = $this->userData->get($user['id']); $user->set('password', $newPassword); $this->userData->update($user); $reset = gmdate('Y-m-d H:i:s'); $passwordReset->set('reset', $reset); $this->passwordResetData->update($passwordReset); return true; }
php
public function resetPassword($token, $newPassword) { $passwordReset = $this->getValidPasswordReset($token); if ($passwordReset === null) { return false; } $user = $passwordReset->get('user'); $user = $this->userData->get($user['id']); $user->set('password', $newPassword); $this->userData->update($user); $reset = gmdate('Y-m-d H:i:s'); $passwordReset->set('reset', $reset); $this->passwordResetData->update($passwordReset); return true; }
[ "public", "function", "resetPassword", "(", "$", "token", ",", "$", "newPassword", ")", "{", "$", "passwordReset", "=", "$", "this", "->", "getValidPasswordReset", "(", "$", "token", ")", ";", "if", "(", "$", "passwordReset", "===", "null", ")", "{", "return", "false", ";", "}", "$", "user", "=", "$", "passwordReset", "->", "get", "(", "'user'", ")", ";", "$", "user", "=", "$", "this", "->", "userData", "->", "get", "(", "$", "user", "[", "'id'", "]", ")", ";", "$", "user", "->", "set", "(", "'password'", ",", "$", "newPassword", ")", ";", "$", "this", "->", "userData", "->", "update", "(", "$", "user", ")", ";", "$", "reset", "=", "gmdate", "(", "'Y-m-d H:i:s'", ")", ";", "$", "passwordReset", "->", "set", "(", "'reset'", ",", "$", "reset", ")", ";", "$", "this", "->", "passwordResetData", "->", "update", "(", "$", "passwordReset", ")", ";", "return", "true", ";", "}" ]
Resets the password of an user belonging to the given password reset token. @param string $token the password reset token @param string $newPassword the new password @return boolean true on success, false on failure with one of this reasons: - no or more than one password reset request found for this token - the password request for this token is older than 48h - the password request for this token has already been used
[ "Resets", "the", "password", "of", "an", "user", "belonging", "to", "the", "given", "password", "reset", "token", "." ]
011c70106786ded665200a1b6b61234800c2b802
https://github.com/philiplb/CRUDlexUser/blob/011c70106786ded665200a1b6b61234800c2b802/src/CRUDlex/PasswordReset.php#L124-L140
11,524
SU-SWS/stanford-api-auth
src/Auth.php
Auth.authenticate
public function authenticate($username, $password) { // Get some things. $client = $this->getClient(); $parameters = $this->getAuthParams(); $endpoint = $this->getEndpoint(); $code = NULL; $response = $client->get($endpoint, ['query' => $parameters, 'auth' => [$username, $password]] ); $code = $response->getStatusCode(); $this->setLastResponse($response); // @todo: handle non 200 responses with error logging. switch ($code) { case '200': $body = $response->getBody(); $json = json_decode($body->getContents()); if (empty($json)) { throw new \Exception("Could not get JSON from body."); } $this->setAuthApiToken($json->access_token); $this->setAuthApiTokenExpires($json->expires_in); break; } return $this; }
php
public function authenticate($username, $password) { // Get some things. $client = $this->getClient(); $parameters = $this->getAuthParams(); $endpoint = $this->getEndpoint(); $code = NULL; $response = $client->get($endpoint, ['query' => $parameters, 'auth' => [$username, $password]] ); $code = $response->getStatusCode(); $this->setLastResponse($response); // @todo: handle non 200 responses with error logging. switch ($code) { case '200': $body = $response->getBody(); $json = json_decode($body->getContents()); if (empty($json)) { throw new \Exception("Could not get JSON from body."); } $this->setAuthApiToken($json->access_token); $this->setAuthApiTokenExpires($json->expires_in); break; } return $this; }
[ "public", "function", "authenticate", "(", "$", "username", ",", "$", "password", ")", "{", "// Get some things.", "$", "client", "=", "$", "this", "->", "getClient", "(", ")", ";", "$", "parameters", "=", "$", "this", "->", "getAuthParams", "(", ")", ";", "$", "endpoint", "=", "$", "this", "->", "getEndpoint", "(", ")", ";", "$", "code", "=", "NULL", ";", "$", "response", "=", "$", "client", "->", "get", "(", "$", "endpoint", ",", "[", "'query'", "=>", "$", "parameters", ",", "'auth'", "=>", "[", "$", "username", ",", "$", "password", "]", "]", ")", ";", "$", "code", "=", "$", "response", "->", "getStatusCode", "(", ")", ";", "$", "this", "->", "setLastResponse", "(", "$", "response", ")", ";", "// @todo: handle non 200 responses with error logging.", "switch", "(", "$", "code", ")", "{", "case", "'200'", ":", "$", "body", "=", "$", "response", "->", "getBody", "(", ")", ";", "$", "json", "=", "json_decode", "(", "$", "body", "->", "getContents", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "json", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Could not get JSON from body.\"", ")", ";", "}", "$", "this", "->", "setAuthApiToken", "(", "$", "json", "->", "access_token", ")", ";", "$", "this", "->", "setAuthApiTokenExpires", "(", "$", "json", "->", "expires_in", ")", ";", "break", ";", "}", "return", "$", "this", ";", "}" ]
Authenticates a username and password with the CAP API. Response returns an API token and expires integer. The API token can then be used in future API calls to protected parts of the API. @return bool True for success and false for some issue.
[ "Authenticates", "a", "username", "and", "password", "with", "the", "CAP", "API", "." ]
633d4226ae2ada22717d938dbfb28dad7d630690
https://github.com/SU-SWS/stanford-api-auth/blob/633d4226ae2ada22717d938dbfb28dad7d630690/src/Auth.php#L170-L199
11,525
jivoo/core
src/Store/Document.php
Document.toDocument
public function toDocument() { $doc = new Document(); $doc->data = $this->data; $doc->defaults = $this->defaultData; return $doc; }
php
public function toDocument() { $doc = new Document(); $doc->data = $this->data; $doc->defaults = $this->defaultData; return $doc; }
[ "public", "function", "toDocument", "(", ")", "{", "$", "doc", "=", "new", "Document", "(", ")", ";", "$", "doc", "->", "data", "=", "$", "this", "->", "data", ";", "$", "doc", "->", "defaults", "=", "$", "this", "->", "defaultData", ";", "return", "$", "doc", ";", "}" ]
Convert to document. @return Document Document.
[ "Convert", "to", "document", "." ]
4ef3445068f0ff9c0a6512cb741831a847013b76
https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Store/Document.php#L154-L160
11,526
jivoo/core
src/Store/Document.php
Document.getSubset
public function getSubset($key) { if (isset($this->emptySubset)) { $this->createTrueSubset(); } $doc = $this->createEmpty(); if (! isset($this->data[$key]) or ! is_array($this->data[$key])) { $doc->data = null; $doc->emptySubset = $key; } else { $doc->data = & $this->data[$key]; } if (! $this->saveDefaults) { if (! isset($this->defaultData[$key]) or ! is_array($this->defaultData[$key])) { $this->defaultData[$key] = array(); } $doc->defaultData = & $this->defaultData[$key]; } $doc->parent = $this; $doc->root = $this->root; return $doc; }
php
public function getSubset($key) { if (isset($this->emptySubset)) { $this->createTrueSubset(); } $doc = $this->createEmpty(); if (! isset($this->data[$key]) or ! is_array($this->data[$key])) { $doc->data = null; $doc->emptySubset = $key; } else { $doc->data = & $this->data[$key]; } if (! $this->saveDefaults) { if (! isset($this->defaultData[$key]) or ! is_array($this->defaultData[$key])) { $this->defaultData[$key] = array(); } $doc->defaultData = & $this->defaultData[$key]; } $doc->parent = $this; $doc->root = $this->root; return $doc; }
[ "public", "function", "getSubset", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "emptySubset", ")", ")", "{", "$", "this", "->", "createTrueSubset", "(", ")", ";", "}", "$", "doc", "=", "$", "this", "->", "createEmpty", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", "or", "!", "is_array", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", ")", "{", "$", "doc", "->", "data", "=", "null", ";", "$", "doc", "->", "emptySubset", "=", "$", "key", ";", "}", "else", "{", "$", "doc", "->", "data", "=", "&", "$", "this", "->", "data", "[", "$", "key", "]", ";", "}", "if", "(", "!", "$", "this", "->", "saveDefaults", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "defaultData", "[", "$", "key", "]", ")", "or", "!", "is_array", "(", "$", "this", "->", "defaultData", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "defaultData", "[", "$", "key", "]", "=", "array", "(", ")", ";", "}", "$", "doc", "->", "defaultData", "=", "&", "$", "this", "->", "defaultData", "[", "$", "key", "]", ";", "}", "$", "doc", "->", "parent", "=", "$", "this", ";", "$", "doc", "->", "root", "=", "$", "this", "->", "root", ";", "return", "$", "doc", ";", "}" ]
Get a subdocument. @param string $key Key. @return Document A subset.
[ "Get", "a", "subdocument", "." ]
4ef3445068f0ff9c0a6512cb741831a847013b76
https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Store/Document.php#L169-L190
11,527
jivoo/core
src/Store/Document.php
Document.createTrueSubset
protected function createTrueSubset() { $this->parent->data[$this->emptySubset] = array(); $this->data = & $this->parent->data[$this->emptySubset]; $this->emptySubset = null; }
php
protected function createTrueSubset() { $this->parent->data[$this->emptySubset] = array(); $this->data = & $this->parent->data[$this->emptySubset]; $this->emptySubset = null; }
[ "protected", "function", "createTrueSubset", "(", ")", "{", "$", "this", "->", "parent", "->", "data", "[", "$", "this", "->", "emptySubset", "]", "=", "array", "(", ")", ";", "$", "this", "->", "data", "=", "&", "$", "this", "->", "parent", "->", "data", "[", "$", "this", "->", "emptySubset", "]", ";", "$", "this", "->", "emptySubset", "=", "null", ";", "}" ]
Create actual subset.
[ "Create", "actual", "subset", "." ]
4ef3445068f0ff9c0a6512cb741831a847013b76
https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Store/Document.php#L205-L210
11,528
jivoo/core
src/Store/Document.php
Document.set
public function set($key, $value) { Assume::that(is_scalar($key)); if (isset($this->emptySubset)) { $this->createTrueSubset(); } $oldValue = null; if (isset($this->data[$key])) { $oldValue = $this->data[$key]; } if (isset($key) and isset($value) and $key !== '') { $this->data[$key] = $value; } else { $this->data[$key] = null; } if (! $this->root->updated and $oldValue !== $value) { $this->root->updated = true; $this->root->update(); } }
php
public function set($key, $value) { Assume::that(is_scalar($key)); if (isset($this->emptySubset)) { $this->createTrueSubset(); } $oldValue = null; if (isset($this->data[$key])) { $oldValue = $this->data[$key]; } if (isset($key) and isset($value) and $key !== '') { $this->data[$key] = $value; } else { $this->data[$key] = null; } if (! $this->root->updated and $oldValue !== $value) { $this->root->updated = true; $this->root->update(); } }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "Assume", "::", "that", "(", "is_scalar", "(", "$", "key", ")", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "emptySubset", ")", ")", "{", "$", "this", "->", "createTrueSubset", "(", ")", ";", "}", "$", "oldValue", "=", "null", ";", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", ")", "{", "$", "oldValue", "=", "$", "this", "->", "data", "[", "$", "key", "]", ";", "}", "if", "(", "isset", "(", "$", "key", ")", "and", "isset", "(", "$", "value", ")", "and", "$", "key", "!==", "''", ")", "{", "$", "this", "->", "data", "[", "$", "key", "]", "=", "$", "value", ";", "}", "else", "{", "$", "this", "->", "data", "[", "$", "key", "]", "=", "null", ";", "}", "if", "(", "!", "$", "this", "->", "root", "->", "updated", "and", "$", "oldValue", "!==", "$", "value", ")", "{", "$", "this", "->", "root", "->", "updated", "=", "true", ";", "$", "this", "->", "root", "->", "update", "(", ")", ";", "}", "}" ]
Update a document key. @param string $key The document key to access. @param mixed $value The value to associate with the key.
[ "Update", "a", "document", "key", "." ]
4ef3445068f0ff9c0a6512cb741831a847013b76
https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Store/Document.php#L220-L239
11,529
jivoo/core
src/Store/Document.php
Document.setRecursive
public function setRecursive($key, $value) { if (! is_array($value)) { $this->set($key, $value); return; } $subset = $this->getSubset($key); $array = $value; foreach ($array as $key => $value) { $subset->setRecursive($key, $value); } }
php
public function setRecursive($key, $value) { if (! is_array($value)) { $this->set($key, $value); return; } $subset = $this->getSubset($key); $array = $value; foreach ($array as $key => $value) { $subset->setRecursive($key, $value); } }
[ "public", "function", "setRecursive", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "$", "this", "->", "set", "(", "$", "key", ",", "$", "value", ")", ";", "return", ";", "}", "$", "subset", "=", "$", "this", "->", "getSubset", "(", "$", "key", ")", ";", "$", "array", "=", "$", "value", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "subset", "->", "setRecursive", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Update a subdocument recursively. @param string $key The document key to access. @param mixed $value The value or subarray to associate with the key.
[ "Update", "a", "subdocument", "recursively", "." ]
4ef3445068f0ff9c0a6512cb741831a847013b76
https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Store/Document.php#L257-L268
11,530
jivoo/core
src/Store/Document.php
Document.get
public function get($key, $default = null) { if (isset($this->data[$key])) { $value = $this->data[$key]; } else { if (isset($default)) { $this->setDefault($key, $default); } elseif (isset($this->defaultData[$key])) { $default = $this->defaultData[$key]; } return $default; } if (isset($default)) { if (gettype($default) !== gettype($value)) { $this->setDefault($key, $default); return $default; } } return $value; }
php
public function get($key, $default = null) { if (isset($this->data[$key])) { $value = $this->data[$key]; } else { if (isset($default)) { $this->setDefault($key, $default); } elseif (isset($this->defaultData[$key])) { $default = $this->defaultData[$key]; } return $default; } if (isset($default)) { if (gettype($default) !== gettype($value)) { $this->setDefault($key, $default); return $default; } } return $value; }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", ")", "{", "$", "value", "=", "$", "this", "->", "data", "[", "$", "key", "]", ";", "}", "else", "{", "if", "(", "isset", "(", "$", "default", ")", ")", "{", "$", "this", "->", "setDefault", "(", "$", "key", ",", "$", "default", ")", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "defaultData", "[", "$", "key", "]", ")", ")", "{", "$", "default", "=", "$", "this", "->", "defaultData", "[", "$", "key", "]", ";", "}", "return", "$", "default", ";", "}", "if", "(", "isset", "(", "$", "default", ")", ")", "{", "if", "(", "gettype", "(", "$", "default", ")", "!==", "gettype", "(", "$", "value", ")", ")", "{", "$", "this", "->", "setDefault", "(", "$", "key", ",", "$", "default", ")", ";", "return", "$", "default", ";", "}", "}", "return", "$", "value", ";", "}" ]
Retreive value of a document key. Returns the default value if the key is not found or if the type of the found value does not match the type of the defuault value. @param string $key Document key. @param mixed $default Optional default value. @return mixed Content of document key.
[ "Retreive", "value", "of", "a", "document", "key", ".", "Returns", "the", "default", "value", "if", "the", "key", "is", "not", "found", "or", "if", "the", "type", "of", "the", "found", "value", "does", "not", "match", "the", "type", "of", "the", "defuault", "value", "." ]
4ef3445068f0ff9c0a6512cb741831a847013b76
https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Store/Document.php#L322-L341
11,531
jivoo/core
src/Store/Document.php
Document.autoVar
public function autoVar($default = null) { $backtrace = debug_backtrace(); $name = ''; if (isset($backtrace[1]['class'])) { $name = $backtrace[1]['class'] . '::'; } $name .= $backtrace[1]['function']; $name .= '(' . $backtrace[1]['line'] . ')'; $var = new DocumentVar($this, $name); if (isset($default)) { $var->setDefault($default); } return $var; }
php
public function autoVar($default = null) { $backtrace = debug_backtrace(); $name = ''; if (isset($backtrace[1]['class'])) { $name = $backtrace[1]['class'] . '::'; } $name .= $backtrace[1]['function']; $name .= '(' . $backtrace[1]['line'] . ')'; $var = new DocumentVar($this, $name); if (isset($default)) { $var->setDefault($default); } return $var; }
[ "public", "function", "autoVar", "(", "$", "default", "=", "null", ")", "{", "$", "backtrace", "=", "debug_backtrace", "(", ")", ";", "$", "name", "=", "''", ";", "if", "(", "isset", "(", "$", "backtrace", "[", "1", "]", "[", "'class'", "]", ")", ")", "{", "$", "name", "=", "$", "backtrace", "[", "1", "]", "[", "'class'", "]", ".", "'::'", ";", "}", "$", "name", ".=", "$", "backtrace", "[", "1", "]", "[", "'function'", "]", ";", "$", "name", ".=", "'('", ".", "$", "backtrace", "[", "1", "]", "[", "'line'", "]", ".", "')'", ";", "$", "var", "=", "new", "DocumentVar", "(", "$", "this", ",", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "default", ")", ")", "{", "$", "var", "->", "setDefault", "(", "$", "default", ")", ";", "}", "return", "$", "var", ";", "}" ]
Create a persistent variable using this document. @param mixed $default Default value. @return Statevar State variable.
[ "Create", "a", "persistent", "variable", "using", "this", "document", "." ]
4ef3445068f0ff9c0a6512cb741831a847013b76
https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Store/Document.php#L362-L376
11,532
rafflesargentina/l5-resource-controller
src/Traits/WorksWithRelations.php
WorksWithRelations.updateOrCreateRelations
public function updateOrCreateRelations(Request $request, Model $model) { $parameterBag = $request->request; foreach ($parameterBag->all() as $name => $attributes) { if (is_array($request->{$name})) { $this->_checkRelationExists($model, $name); $relation = $model->{$name}(); $this->handleRelations($attributes, $model, $relation); } } }
php
public function updateOrCreateRelations(Request $request, Model $model) { $parameterBag = $request->request; foreach ($parameterBag->all() as $name => $attributes) { if (is_array($request->{$name})) { $this->_checkRelationExists($model, $name); $relation = $model->{$name}(); $this->handleRelations($attributes, $model, $relation); } } }
[ "public", "function", "updateOrCreateRelations", "(", "Request", "$", "request", ",", "Model", "$", "model", ")", "{", "$", "parameterBag", "=", "$", "request", "->", "request", ";", "foreach", "(", "$", "parameterBag", "->", "all", "(", ")", "as", "$", "name", "=>", "$", "attributes", ")", "{", "if", "(", "is_array", "(", "$", "request", "->", "{", "$", "name", "}", ")", ")", "{", "$", "this", "->", "_checkRelationExists", "(", "$", "model", ",", "$", "name", ")", ";", "$", "relation", "=", "$", "model", "->", "{", "$", "name", "}", "(", ")", ";", "$", "this", "->", "handleRelations", "(", "$", "attributes", ",", "$", "model", ",", "$", "relation", ")", ";", "}", "}", "}" ]
Update or create relations handling array type request data. @param Request $request The Request object. @param Model $model The eloquent model. @return void
[ "Update", "or", "create", "relations", "handling", "array", "type", "request", "data", "." ]
5ee5de4803a26d0592dd6f5db77aec40c1a56c09
https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithRelations.php#L24-L35
11,533
rafflesargentina/l5-resource-controller
src/Traits/WorksWithRelations.php
WorksWithRelations.handleRelations
protected function handleRelations(array $fillable, Model $model, Relation $relation) { switch (true) { case $relation instanceof HasOne || $relation instanceof MorphOne: $this->updateOrCreateHasOne($fillable, $model, $relation); break; case $relation instanceof BelongsTo: $this->updateOrCreateBelongsToOne($fillable, $model, $relation); break; case $relation instanceof HasMany || $relation instanceof MorphMany: $this->updateOrCreateHasMany($fillable, $model, $relation); break; case $relation instanceof BelongsToMany || $relation instanceof MorphToMany: $this->updateOrCreateBelongsToMany($fillable, $model, $relation); break; } }
php
protected function handleRelations(array $fillable, Model $model, Relation $relation) { switch (true) { case $relation instanceof HasOne || $relation instanceof MorphOne: $this->updateOrCreateHasOne($fillable, $model, $relation); break; case $relation instanceof BelongsTo: $this->updateOrCreateBelongsToOne($fillable, $model, $relation); break; case $relation instanceof HasMany || $relation instanceof MorphMany: $this->updateOrCreateHasMany($fillable, $model, $relation); break; case $relation instanceof BelongsToMany || $relation instanceof MorphToMany: $this->updateOrCreateBelongsToMany($fillable, $model, $relation); break; } }
[ "protected", "function", "handleRelations", "(", "array", "$", "fillable", ",", "Model", "$", "model", ",", "Relation", "$", "relation", ")", "{", "switch", "(", "true", ")", "{", "case", "$", "relation", "instanceof", "HasOne", "||", "$", "relation", "instanceof", "MorphOne", ":", "$", "this", "->", "updateOrCreateHasOne", "(", "$", "fillable", ",", "$", "model", ",", "$", "relation", ")", ";", "break", ";", "case", "$", "relation", "instanceof", "BelongsTo", ":", "$", "this", "->", "updateOrCreateBelongsToOne", "(", "$", "fillable", ",", "$", "model", ",", "$", "relation", ")", ";", "break", ";", "case", "$", "relation", "instanceof", "HasMany", "||", "$", "relation", "instanceof", "MorphMany", ":", "$", "this", "->", "updateOrCreateHasMany", "(", "$", "fillable", ",", "$", "model", ",", "$", "relation", ")", ";", "break", ";", "case", "$", "relation", "instanceof", "BelongsToMany", "||", "$", "relation", "instanceof", "MorphToMany", ":", "$", "this", "->", "updateOrCreateBelongsToMany", "(", "$", "fillable", ",", "$", "model", ",", "$", "relation", ")", ";", "break", ";", "}", "}" ]
Handle relations. @param array $fillable The relation fillable. @param Model $model The eloquent model. @param Relation $relation The eloquent relation. @return void
[ "Handle", "relations", "." ]
5ee5de4803a26d0592dd6f5db77aec40c1a56c09
https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithRelations.php#L46-L62
11,534
rafflesargentina/l5-resource-controller
src/Traits/WorksWithRelations.php
WorksWithRelations.updateOrCreateHasOne
protected function updateOrCreateHasOne(array $fillable, Model $model, Relation $relation) { $id = ''; if (array_key_exists('id', $fillable)) { $id = $fillable['id']; } if (array_except($fillable, ['id'])) { if (property_exists($this, 'pruneHasOne') && $this->pruneHasOne !== false) { $relation->update($fillable); } return $relation->updateOrCreate(['id' => $id], $fillable); } return null; }
php
protected function updateOrCreateHasOne(array $fillable, Model $model, Relation $relation) { $id = ''; if (array_key_exists('id', $fillable)) { $id = $fillable['id']; } if (array_except($fillable, ['id'])) { if (property_exists($this, 'pruneHasOne') && $this->pruneHasOne !== false) { $relation->update($fillable); } return $relation->updateOrCreate(['id' => $id], $fillable); } return null; }
[ "protected", "function", "updateOrCreateHasOne", "(", "array", "$", "fillable", ",", "Model", "$", "model", ",", "Relation", "$", "relation", ")", "{", "$", "id", "=", "''", ";", "if", "(", "array_key_exists", "(", "'id'", ",", "$", "fillable", ")", ")", "{", "$", "id", "=", "$", "fillable", "[", "'id'", "]", ";", "}", "if", "(", "array_except", "(", "$", "fillable", ",", "[", "'id'", "]", ")", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "'pruneHasOne'", ")", "&&", "$", "this", "->", "pruneHasOne", "!==", "false", ")", "{", "$", "relation", "->", "update", "(", "$", "fillable", ")", ";", "}", "return", "$", "relation", "->", "updateOrCreate", "(", "[", "'id'", "=>", "$", "id", "]", ",", "$", "fillable", ")", ";", "}", "return", "null", ";", "}" ]
HasOne relation updateOrCreate logic. @param array $fillable The relation fillable. @param Model $model The eloquent model. @param Relation $relation The eloquent relation. @return Model | null
[ "HasOne", "relation", "updateOrCreate", "logic", "." ]
5ee5de4803a26d0592dd6f5db77aec40c1a56c09
https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithRelations.php#L73-L90
11,535
rafflesargentina/l5-resource-controller
src/Traits/WorksWithRelations.php
WorksWithRelations.updateOrCreateBelongsToOne
protected function updateOrCreateBelongsToOne(array $fillable, Model $model, Relation $relation) { $related = $relation->getRelated(); if (array_except($fillable, ['id'])) { if (!$relation->first()) { $record = $relation->associate($related->create($fillable)); $model->save(); } else { $record = $relation->update($fillable); } return $record; } return null; }
php
protected function updateOrCreateBelongsToOne(array $fillable, Model $model, Relation $relation) { $related = $relation->getRelated(); if (array_except($fillable, ['id'])) { if (!$relation->first()) { $record = $relation->associate($related->create($fillable)); $model->save(); } else { $record = $relation->update($fillable); } return $record; } return null; }
[ "protected", "function", "updateOrCreateBelongsToOne", "(", "array", "$", "fillable", ",", "Model", "$", "model", ",", "Relation", "$", "relation", ")", "{", "$", "related", "=", "$", "relation", "->", "getRelated", "(", ")", ";", "if", "(", "array_except", "(", "$", "fillable", ",", "[", "'id'", "]", ")", ")", "{", "if", "(", "!", "$", "relation", "->", "first", "(", ")", ")", "{", "$", "record", "=", "$", "relation", "->", "associate", "(", "$", "related", "->", "create", "(", "$", "fillable", ")", ")", ";", "$", "model", "->", "save", "(", ")", ";", "}", "else", "{", "$", "record", "=", "$", "relation", "->", "update", "(", "$", "fillable", ")", ";", "}", "return", "$", "record", ";", "}", "return", "null", ";", "}" ]
BelongsToOne relation updateOrCreate logic. @param array $fillable The relation fillable. @param Model $model The eloquent model. @param Relation $relation The eloquent relation. @return Model
[ "BelongsToOne", "relation", "updateOrCreate", "logic", "." ]
5ee5de4803a26d0592dd6f5db77aec40c1a56c09
https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithRelations.php#L101-L117
11,536
rafflesargentina/l5-resource-controller
src/Traits/WorksWithRelations.php
WorksWithRelations.updateOrCreateHasMany
protected function updateOrCreateHasMany(array $fillable, Model $model, Relation $relation) { $keys = []; $id = ''; $records = []; foreach ($fillable as $fields) { if (is_array($fields)) { if (array_key_exists('id', $fields)) { $id = $fields['id']; } if (array_except($fields, ['id'])) { $record = $relation->updateOrCreate(['id' => $id], $fields); array_push($keys, $record->id); array_push($records, $record); } } else { if (array_except($fillable, ['id'])) { $record = $relation->updateOrCreate(['id' => $id], $fillable); array_push($keys, $record->id); array_push($records, $record); } } } if ($keys && (property_exists($this, 'pruneHasMany') && $this->pruneHasMany !== false)) { $notIn = $relation->getRelated()->whereNotIn('id', $keys)->get(); foreach ($notIn as $record) { $record->delete(); } } return $records; }
php
protected function updateOrCreateHasMany(array $fillable, Model $model, Relation $relation) { $keys = []; $id = ''; $records = []; foreach ($fillable as $fields) { if (is_array($fields)) { if (array_key_exists('id', $fields)) { $id = $fields['id']; } if (array_except($fields, ['id'])) { $record = $relation->updateOrCreate(['id' => $id], $fields); array_push($keys, $record->id); array_push($records, $record); } } else { if (array_except($fillable, ['id'])) { $record = $relation->updateOrCreate(['id' => $id], $fillable); array_push($keys, $record->id); array_push($records, $record); } } } if ($keys && (property_exists($this, 'pruneHasMany') && $this->pruneHasMany !== false)) { $notIn = $relation->getRelated()->whereNotIn('id', $keys)->get(); foreach ($notIn as $record) { $record->delete(); } } return $records; }
[ "protected", "function", "updateOrCreateHasMany", "(", "array", "$", "fillable", ",", "Model", "$", "model", ",", "Relation", "$", "relation", ")", "{", "$", "keys", "=", "[", "]", ";", "$", "id", "=", "''", ";", "$", "records", "=", "[", "]", ";", "foreach", "(", "$", "fillable", "as", "$", "fields", ")", "{", "if", "(", "is_array", "(", "$", "fields", ")", ")", "{", "if", "(", "array_key_exists", "(", "'id'", ",", "$", "fields", ")", ")", "{", "$", "id", "=", "$", "fields", "[", "'id'", "]", ";", "}", "if", "(", "array_except", "(", "$", "fields", ",", "[", "'id'", "]", ")", ")", "{", "$", "record", "=", "$", "relation", "->", "updateOrCreate", "(", "[", "'id'", "=>", "$", "id", "]", ",", "$", "fields", ")", ";", "array_push", "(", "$", "keys", ",", "$", "record", "->", "id", ")", ";", "array_push", "(", "$", "records", ",", "$", "record", ")", ";", "}", "}", "else", "{", "if", "(", "array_except", "(", "$", "fillable", ",", "[", "'id'", "]", ")", ")", "{", "$", "record", "=", "$", "relation", "->", "updateOrCreate", "(", "[", "'id'", "=>", "$", "id", "]", ",", "$", "fillable", ")", ";", "array_push", "(", "$", "keys", ",", "$", "record", "->", "id", ")", ";", "array_push", "(", "$", "records", ",", "$", "record", ")", ";", "}", "}", "}", "if", "(", "$", "keys", "&&", "(", "property_exists", "(", "$", "this", ",", "'pruneHasMany'", ")", "&&", "$", "this", "->", "pruneHasMany", "!==", "false", ")", ")", "{", "$", "notIn", "=", "$", "relation", "->", "getRelated", "(", ")", "->", "whereNotIn", "(", "'id'", ",", "$", "keys", ")", "->", "get", "(", ")", ";", "foreach", "(", "$", "notIn", "as", "$", "record", ")", "{", "$", "record", "->", "delete", "(", ")", ";", "}", "}", "return", "$", "records", ";", "}" ]
HasMany relation updateOrCreate logic. @param array $fillable The relation fillable. @param Model $model The eloquent model. @param Relation $relation The eloquent relation. @return array
[ "HasMany", "relation", "updateOrCreate", "logic", "." ]
5ee5de4803a26d0592dd6f5db77aec40c1a56c09
https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithRelations.php#L128-L162
11,537
rafflesargentina/l5-resource-controller
src/Traits/WorksWithRelations.php
WorksWithRelations.updateOrCreateBelongsToMany
protected function updateOrCreateBelongsToMany(array $fillable, Model $model, Relation $relation) { $keys = []; $records = []; $related = $relation->getRelated(); foreach ($fillable as $fields) { if (array_key_exists('id', $fields)) { $id = $fields['id']; array_push($keys, $id); } else { $id = ''; } if (array_except($fields, ['id'])) { $record = $related->updateOrCreate(['id' => $id], $fields); array_push($keys, $record->id); array_push($records, $record); } } $relation->sync($keys); return $records; }
php
protected function updateOrCreateBelongsToMany(array $fillable, Model $model, Relation $relation) { $keys = []; $records = []; $related = $relation->getRelated(); foreach ($fillable as $fields) { if (array_key_exists('id', $fields)) { $id = $fields['id']; array_push($keys, $id); } else { $id = ''; } if (array_except($fields, ['id'])) { $record = $related->updateOrCreate(['id' => $id], $fields); array_push($keys, $record->id); array_push($records, $record); } } $relation->sync($keys); return $records; }
[ "protected", "function", "updateOrCreateBelongsToMany", "(", "array", "$", "fillable", ",", "Model", "$", "model", ",", "Relation", "$", "relation", ")", "{", "$", "keys", "=", "[", "]", ";", "$", "records", "=", "[", "]", ";", "$", "related", "=", "$", "relation", "->", "getRelated", "(", ")", ";", "foreach", "(", "$", "fillable", "as", "$", "fields", ")", "{", "if", "(", "array_key_exists", "(", "'id'", ",", "$", "fields", ")", ")", "{", "$", "id", "=", "$", "fields", "[", "'id'", "]", ";", "array_push", "(", "$", "keys", ",", "$", "id", ")", ";", "}", "else", "{", "$", "id", "=", "''", ";", "}", "if", "(", "array_except", "(", "$", "fields", ",", "[", "'id'", "]", ")", ")", "{", "$", "record", "=", "$", "related", "->", "updateOrCreate", "(", "[", "'id'", "=>", "$", "id", "]", ",", "$", "fields", ")", ";", "array_push", "(", "$", "keys", ",", "$", "record", "->", "id", ")", ";", "array_push", "(", "$", "records", ",", "$", "record", ")", ";", "}", "}", "$", "relation", "->", "sync", "(", "$", "keys", ")", ";", "return", "$", "records", ";", "}" ]
BelongsToMany relation updateOrCreate logic. @param array $fillable The relation fillable. @param Model $model The eloquent model. @param Relation $relation The eloquent relation. @return array
[ "BelongsToMany", "relation", "updateOrCreate", "logic", "." ]
5ee5de4803a26d0592dd6f5db77aec40c1a56c09
https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithRelations.php#L173-L198
11,538
rafflesargentina/l5-resource-controller
src/Traits/WorksWithRelations.php
WorksWithRelations._checkRelationExists
private function _checkRelationExists(Model $model, string $relationName) { if (!method_exists($model, $relationName) || !$model->{$relationName}() instanceof Relation) { if (Lang::has('resource-controller.data2relationinexistent')) { $message = trans('resource-controller.data2relationinexistent', ['relationName' => $relationName]); } else { $message = "Array type request data '{$relationName}' must be named after an existent relation."; } throw new MassAssignmentException($message); } }
php
private function _checkRelationExists(Model $model, string $relationName) { if (!method_exists($model, $relationName) || !$model->{$relationName}() instanceof Relation) { if (Lang::has('resource-controller.data2relationinexistent')) { $message = trans('resource-controller.data2relationinexistent', ['relationName' => $relationName]); } else { $message = "Array type request data '{$relationName}' must be named after an existent relation."; } throw new MassAssignmentException($message); } }
[ "private", "function", "_checkRelationExists", "(", "Model", "$", "model", ",", "string", "$", "relationName", ")", "{", "if", "(", "!", "method_exists", "(", "$", "model", ",", "$", "relationName", ")", "||", "!", "$", "model", "->", "{", "$", "relationName", "}", "(", ")", "instanceof", "Relation", ")", "{", "if", "(", "Lang", "::", "has", "(", "'resource-controller.data2relationinexistent'", ")", ")", "{", "$", "message", "=", "trans", "(", "'resource-controller.data2relationinexistent'", ",", "[", "'relationName'", "=>", "$", "relationName", "]", ")", ";", "}", "else", "{", "$", "message", "=", "\"Array type request data '{$relationName}' must be named after an existent relation.\"", ";", "}", "throw", "new", "MassAssignmentException", "(", "$", "message", ")", ";", "}", "}" ]
Throw an exception if array type request data is not named after an existent Eloquent relation. @param Model $model The eloquent model. @param string $relationName The eloquent relation name. @throws MassAssignmentException @return void
[ "Throw", "an", "exception", "if", "array", "type", "request", "data", "is", "not", "named", "after", "an", "existent", "Eloquent", "relation", "." ]
5ee5de4803a26d0592dd6f5db77aec40c1a56c09
https://github.com/rafflesargentina/l5-resource-controller/blob/5ee5de4803a26d0592dd6f5db77aec40c1a56c09/src/Traits/WorksWithRelations.php#L210-L221
11,539
martinhej/robocloud
src/robocloud/Consumer/Kinesis/ConsumerRecovery.php
ConsumerRecovery.getRecoveryFileContent
protected function getRecoveryFileContent(): array { $content = file_get_contents($this->consumerRecoveryFile); if (!empty($content)) { return json_decode($content, TRUE); } elseif ($content === FALSE) { throw new ConsumerRecoveryException('Error reading Consumer recovery data at ' . $this->consumerRecoveryFile); } return []; }
php
protected function getRecoveryFileContent(): array { $content = file_get_contents($this->consumerRecoveryFile); if (!empty($content)) { return json_decode($content, TRUE); } elseif ($content === FALSE) { throw new ConsumerRecoveryException('Error reading Consumer recovery data at ' . $this->consumerRecoveryFile); } return []; }
[ "protected", "function", "getRecoveryFileContent", "(", ")", ":", "array", "{", "$", "content", "=", "file_get_contents", "(", "$", "this", "->", "consumerRecoveryFile", ")", ";", "if", "(", "!", "empty", "(", "$", "content", ")", ")", "{", "return", "json_decode", "(", "$", "content", ",", "TRUE", ")", ";", "}", "elseif", "(", "$", "content", "===", "FALSE", ")", "{", "throw", "new", "ConsumerRecoveryException", "(", "'Error reading Consumer recovery data at '", ".", "$", "this", "->", "consumerRecoveryFile", ")", ";", "}", "return", "[", "]", ";", "}" ]
Gets the recovery file contents. @return array The recovery file content as array. @throws \robocloud\Exception\ConsumerRecoveryException On the recovery file read error.
[ "Gets", "the", "recovery", "file", "contents", "." ]
108dfbc2b6e9aca2a87795c3e7518cbf1cf5d229
https://github.com/martinhej/robocloud/blob/108dfbc2b6e9aca2a87795c3e7518cbf1cf5d229/src/robocloud/Consumer/Kinesis/ConsumerRecovery.php#L100-L110
11,540
jannisfink/yarf
src/request/Request.php
Request.get
public function get($key) { $get = $this->getParam($key, $this->get); if ($get !== null) { return $get; } $post = $this->getParam($key, $this->post); if ($post !== null) { return $post; } return $this->getParam($key, $this->files); }
php
public function get($key) { $get = $this->getParam($key, $this->get); if ($get !== null) { return $get; } $post = $this->getParam($key, $this->post); if ($post !== null) { return $post; } return $this->getParam($key, $this->files); }
[ "public", "function", "get", "(", "$", "key", ")", "{", "$", "get", "=", "$", "this", "->", "getParam", "(", "$", "key", ",", "$", "this", "->", "get", ")", ";", "if", "(", "$", "get", "!==", "null", ")", "{", "return", "$", "get", ";", "}", "$", "post", "=", "$", "this", "->", "getParam", "(", "$", "key", ",", "$", "this", "->", "post", ")", ";", "if", "(", "$", "post", "!==", "null", ")", "{", "return", "$", "post", ";", "}", "return", "$", "this", "->", "getParam", "(", "$", "key", ",", "$", "this", "->", "files", ")", ";", "}" ]
Returns a parameter given via url variables or post variables. If a key exists both in url an in post variables, the url variable will be returned. @param string $key name of the parameter @return string|null the parameter value, {@code null} if the key does not exist
[ "Returns", "a", "parameter", "given", "via", "url", "variables", "or", "post", "variables", ".", "If", "a", "key", "exists", "both", "in", "url", "an", "in", "post", "variables", "the", "url", "variable", "will", "be", "returned", "." ]
91237dc0f3b724abaaba490f5171f181a92e939f
https://github.com/jannisfink/yarf/blob/91237dc0f3b724abaaba490f5171f181a92e939f/src/request/Request.php#L78-L88
11,541
Rockbeat-Sky/framework
src/core/Output.php
Output.setContentType
public function setContentType($mimes){ if (strpos($mimes, '/') === FALSE) { $extension = ltrim($mimes, '.'); // Is this extension supported? if (isset($this->mimes[$extension])) { $mime_type =& $this->mimes[$extension]; if (is_array($mime_type)) { $mime_type = current($mime_type); } } } $header = 'Content-Type: '.$mime_type; $this->headers[] = array($header, TRUE); return $this; }
php
public function setContentType($mimes){ if (strpos($mimes, '/') === FALSE) { $extension = ltrim($mimes, '.'); // Is this extension supported? if (isset($this->mimes[$extension])) { $mime_type =& $this->mimes[$extension]; if (is_array($mime_type)) { $mime_type = current($mime_type); } } } $header = 'Content-Type: '.$mime_type; $this->headers[] = array($header, TRUE); return $this; }
[ "public", "function", "setContentType", "(", "$", "mimes", ")", "{", "if", "(", "strpos", "(", "$", "mimes", ",", "'/'", ")", "===", "FALSE", ")", "{", "$", "extension", "=", "ltrim", "(", "$", "mimes", ",", "'.'", ")", ";", "// Is this extension supported?", "if", "(", "isset", "(", "$", "this", "->", "mimes", "[", "$", "extension", "]", ")", ")", "{", "$", "mime_type", "=", "&", "$", "this", "->", "mimes", "[", "$", "extension", "]", ";", "if", "(", "is_array", "(", "$", "mime_type", ")", ")", "{", "$", "mime_type", "=", "current", "(", "$", "mime_type", ")", ";", "}", "}", "}", "$", "header", "=", "'Content-Type: '", ".", "$", "mime_type", ";", "$", "this", "->", "headers", "[", "]", "=", "array", "(", "$", "header", ",", "TRUE", ")", ";", "return", "$", "this", ";", "}" ]
set Content Type @param string (Mimes Type, list mimes type at config/Mimes.php) @return void
[ "set", "Content", "Type" ]
e8ffd04f2fdc27a62b185b342f32bf58899ceda4
https://github.com/Rockbeat-Sky/framework/blob/e8ffd04f2fdc27a62b185b342f32bf58899ceda4/src/core/Output.php#L79-L101
11,542
RalfEggert/travello-view-helper
src/ConfigProvider.php
ConfigProvider.getViewHelperConfig
public function getViewHelperConfig() { return [ 'aliases' => [ 'h1' => H1::class, 'date' => Date::class, 'bootstrapForm' => BootstrapForm::class, 'bootstrapMenu' => BootstrapMenu::class, 'bootstrapFlashMessenger' => BootstrapFlashMessenger::class, ], 'factories' => [ H1::class => InvokableFactory::class, Date::class => InvokableFactory::class, BootstrapForm::class => InvokableFactory::class, BootstrapMenu::class => InvokableFactory::class, BootstrapFlashMessenger::class => BootstrapFlashMessengerFactory::class, ], ]; }
php
public function getViewHelperConfig() { return [ 'aliases' => [ 'h1' => H1::class, 'date' => Date::class, 'bootstrapForm' => BootstrapForm::class, 'bootstrapMenu' => BootstrapMenu::class, 'bootstrapFlashMessenger' => BootstrapFlashMessenger::class, ], 'factories' => [ H1::class => InvokableFactory::class, Date::class => InvokableFactory::class, BootstrapForm::class => InvokableFactory::class, BootstrapMenu::class => InvokableFactory::class, BootstrapFlashMessenger::class => BootstrapFlashMessengerFactory::class, ], ]; }
[ "public", "function", "getViewHelperConfig", "(", ")", "{", "return", "[", "'aliases'", "=>", "[", "'h1'", "=>", "H1", "::", "class", ",", "'date'", "=>", "Date", "::", "class", ",", "'bootstrapForm'", "=>", "BootstrapForm", "::", "class", ",", "'bootstrapMenu'", "=>", "BootstrapMenu", "::", "class", ",", "'bootstrapFlashMessenger'", "=>", "BootstrapFlashMessenger", "::", "class", ",", "]", ",", "'factories'", "=>", "[", "H1", "::", "class", "=>", "InvokableFactory", "::", "class", ",", "Date", "::", "class", "=>", "InvokableFactory", "::", "class", ",", "BootstrapForm", "::", "class", "=>", "InvokableFactory", "::", "class", ",", "BootstrapMenu", "::", "class", "=>", "InvokableFactory", "::", "class", ",", "BootstrapFlashMessenger", "::", "class", "=>", "BootstrapFlashMessengerFactory", "::", "class", ",", "]", ",", "]", ";", "}" ]
Get view helper configuration @return array
[ "Get", "view", "helper", "configuration" ]
631a44bed767a6e9a1d45ff3956dd661f67e63a3
https://github.com/RalfEggert/travello-view-helper/blob/631a44bed767a6e9a1d45ff3956dd661f67e63a3/src/ConfigProvider.php#L47-L66
11,543
tux-rampage/rampage-php
library/rampage/core/Logger.php
Logger.log
public function log($priority, $message, $extra = array()) { if (!is_int($priority) || ($priority<0) || ($priority>=count($this->priorities))) { throw new Exception\InvalidArgumentException(sprintf( '$priority must be an integer > 0 and < %d; received %s', count($this->priorities), var_export($priority, 1) )); } if (!is_array($extra) && !$extra instanceof Traversable) { throw new Exception\InvalidArgumentException( '$extra must be an array or implement Traversable' ); } else if ($extra instanceof Traversable) { $extra = ArrayUtils::iteratorToArray($extra); } if ($this->writers->count() === 0) { throw new Exception\RuntimeException('No log writer specified'); } $timestamp = new DateTime(); if (is_array($message)) { $message = var_export($message, true); } foreach ($this->writers->toArray() as $writer) { $writer->write(array( 'timestamp' => $timestamp, 'priority' => (int) $priority, 'priorityName' => $this->priorities[$priority], 'message' => $message, 'extra' => $extra )); } return $this; }
php
public function log($priority, $message, $extra = array()) { if (!is_int($priority) || ($priority<0) || ($priority>=count($this->priorities))) { throw new Exception\InvalidArgumentException(sprintf( '$priority must be an integer > 0 and < %d; received %s', count($this->priorities), var_export($priority, 1) )); } if (!is_array($extra) && !$extra instanceof Traversable) { throw new Exception\InvalidArgumentException( '$extra must be an array or implement Traversable' ); } else if ($extra instanceof Traversable) { $extra = ArrayUtils::iteratorToArray($extra); } if ($this->writers->count() === 0) { throw new Exception\RuntimeException('No log writer specified'); } $timestamp = new DateTime(); if (is_array($message)) { $message = var_export($message, true); } foreach ($this->writers->toArray() as $writer) { $writer->write(array( 'timestamp' => $timestamp, 'priority' => (int) $priority, 'priorityName' => $this->priorities[$priority], 'message' => $message, 'extra' => $extra )); } return $this; }
[ "public", "function", "log", "(", "$", "priority", ",", "$", "message", ",", "$", "extra", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_int", "(", "$", "priority", ")", "||", "(", "$", "priority", "<", "0", ")", "||", "(", "$", "priority", ">=", "count", "(", "$", "this", "->", "priorities", ")", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'$priority must be an integer > 0 and < %d; received %s'", ",", "count", "(", "$", "this", "->", "priorities", ")", ",", "var_export", "(", "$", "priority", ",", "1", ")", ")", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "extra", ")", "&&", "!", "$", "extra", "instanceof", "Traversable", ")", "{", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "'$extra must be an array or implement Traversable'", ")", ";", "}", "else", "if", "(", "$", "extra", "instanceof", "Traversable", ")", "{", "$", "extra", "=", "ArrayUtils", "::", "iteratorToArray", "(", "$", "extra", ")", ";", "}", "if", "(", "$", "this", "->", "writers", "->", "count", "(", ")", "===", "0", ")", "{", "throw", "new", "Exception", "\\", "RuntimeException", "(", "'No log writer specified'", ")", ";", "}", "$", "timestamp", "=", "new", "DateTime", "(", ")", ";", "if", "(", "is_array", "(", "$", "message", ")", ")", "{", "$", "message", "=", "var_export", "(", "$", "message", ",", "true", ")", ";", "}", "foreach", "(", "$", "this", "->", "writers", "->", "toArray", "(", ")", "as", "$", "writer", ")", "{", "$", "writer", "->", "write", "(", "array", "(", "'timestamp'", "=>", "$", "timestamp", ",", "'priority'", "=>", "(", "int", ")", "$", "priority", ",", "'priorityName'", "=>", "$", "this", "->", "priorities", "[", "$", "priority", "]", ",", "'message'", "=>", "$", "message", ",", "'extra'", "=>", "$", "extra", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a message as a log entry In contrast of the zend implementation this does NOT cast the message to a string, nor does it require a stringifyable object. Leaving handling the message to the log writer makes much more sense then the current, shitty implementation. @param int $priority @param mixed $message @param array|Traversable $extra @return Logger @throws Exception\InvalidArgumentException if message can't be cast to string @throws Exception\InvalidArgumentException if extra can't be iterated over @throws Exception\RuntimeException if no log writer specified
[ "Add", "a", "message", "as", "a", "log", "entry" ]
1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf
https://github.com/tux-rampage/rampage-php/blob/1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf/library/rampage/core/Logger.php#L60-L99
11,544
webriq/core
module/Core/src/Grid/Core/Model/SubDomain/Rpc.php
Rpc.isSubdomainAvailable
public function isSubdomainAvailable( $subdomain, $params = array() ) { $params = (object) $params; return ! $this->getMapper() ->isSubdomainExists( $subdomain, empty( $params->id ) ? null : $params->id ); }
php
public function isSubdomainAvailable( $subdomain, $params = array() ) { $params = (object) $params; return ! $this->getMapper() ->isSubdomainExists( $subdomain, empty( $params->id ) ? null : $params->id ); }
[ "public", "function", "isSubdomainAvailable", "(", "$", "subdomain", ",", "$", "params", "=", "array", "(", ")", ")", "{", "$", "params", "=", "(", "object", ")", "$", "params", ";", "return", "!", "$", "this", "->", "getMapper", "(", ")", "->", "isSubdomainExists", "(", "$", "subdomain", ",", "empty", "(", "$", "params", "->", "id", ")", "?", "null", ":", "$", "params", "->", "id", ")", ";", "}" ]
Return true, if subdomain is available @param string $subdomain @param array|object $params @return bool
[ "Return", "true", "if", "subdomain", "is", "available" ]
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Model/SubDomain/Rpc.php#L39-L48
11,545
agentmedia/phine-forms
src/Forms/Modules/Frontend/Select.php
Select.Init
protected function Init() { $select = ContentSelect::Schema()->ByContent($this->Content()); $disableValidation = $select->GetDisableFrontendValidation(); $this->label = $select->GetLabel(); $this->name = $select->GetName(); $this->required = $disableValidation ? false : $select->GetRequired(); $this->value = $this->Value($this->name, $select->GetValue()); $this->id = $this->CssID() ? $this->CssID(): $this->name; $list = new SelectListProvider($select); $this->options = $list->ToArray(); $this->RealizeField($this->name); return parent::Init(); }
php
protected function Init() { $select = ContentSelect::Schema()->ByContent($this->Content()); $disableValidation = $select->GetDisableFrontendValidation(); $this->label = $select->GetLabel(); $this->name = $select->GetName(); $this->required = $disableValidation ? false : $select->GetRequired(); $this->value = $this->Value($this->name, $select->GetValue()); $this->id = $this->CssID() ? $this->CssID(): $this->name; $list = new SelectListProvider($select); $this->options = $list->ToArray(); $this->RealizeField($this->name); return parent::Init(); }
[ "protected", "function", "Init", "(", ")", "{", "$", "select", "=", "ContentSelect", "::", "Schema", "(", ")", "->", "ByContent", "(", "$", "this", "->", "Content", "(", ")", ")", ";", "$", "disableValidation", "=", "$", "select", "->", "GetDisableFrontendValidation", "(", ")", ";", "$", "this", "->", "label", "=", "$", "select", "->", "GetLabel", "(", ")", ";", "$", "this", "->", "name", "=", "$", "select", "->", "GetName", "(", ")", ";", "$", "this", "->", "required", "=", "$", "disableValidation", "?", "false", ":", "$", "select", "->", "GetRequired", "(", ")", ";", "$", "this", "->", "value", "=", "$", "this", "->", "Value", "(", "$", "this", "->", "name", ",", "$", "select", "->", "GetValue", "(", ")", ")", ";", "$", "this", "->", "id", "=", "$", "this", "->", "CssID", "(", ")", "?", "$", "this", "->", "CssID", "(", ")", ":", "$", "this", "->", "name", ";", "$", "list", "=", "new", "SelectListProvider", "(", "$", "select", ")", ";", "$", "this", "->", "options", "=", "$", "list", "->", "ToArray", "(", ")", ";", "$", "this", "->", "RealizeField", "(", "$", "this", "->", "name", ")", ";", "return", "parent", "::", "Init", "(", ")", ";", "}" ]
Initializes the select content @return boolean Returns false if processing shall continue
[ "Initializes", "the", "select", "content" ]
cd7a92ea443756bef5885a9e8f59ad6b8d2771fc
https://github.com/agentmedia/phine-forms/blob/cd7a92ea443756bef5885a9e8f59ad6b8d2771fc/src/Forms/Modules/Frontend/Select.php#L52-L65
11,546
agentmedia/phine-forms
src/Forms/Modules/Frontend/Select.php
Select.BackendName
public function BackendName() { $name = parent::BackendName(); if (!$this->Content()) { return $name; } $select = ContentSelect::Schema()->ByContent($this->Content()); $name .= ' : ' . $select->GetName(); return $name; }
php
public function BackendName() { $name = parent::BackendName(); if (!$this->Content()) { return $name; } $select = ContentSelect::Schema()->ByContent($this->Content()); $name .= ' : ' . $select->GetName(); return $name; }
[ "public", "function", "BackendName", "(", ")", "{", "$", "name", "=", "parent", "::", "BackendName", "(", ")", ";", "if", "(", "!", "$", "this", "->", "Content", "(", ")", ")", "{", "return", "$", "name", ";", "}", "$", "select", "=", "ContentSelect", "::", "Schema", "(", ")", "->", "ByContent", "(", "$", "this", "->", "Content", "(", ")", ")", ";", "$", "name", ".=", "' : '", ".", "$", "select", "->", "GetName", "(", ")", ";", "return", "$", "name", ";", "}" ]
Gets the name for backend views @return string Returns the backend name
[ "Gets", "the", "name", "for", "backend", "views" ]
cd7a92ea443756bef5885a9e8f59ad6b8d2771fc
https://github.com/agentmedia/phine-forms/blob/cd7a92ea443756bef5885a9e8f59ad6b8d2771fc/src/Forms/Modules/Frontend/Select.php#L98-L108
11,547
xmmedia/XMSecurityBundle
Listener/AuthenticationLoggerListener.php
AuthenticationLoggerListener.logSuccess
public function logSuccess() { /** @var XM\SecurityBundle\Entity\User $user */ $user = $this->tokenStorage->getToken()->getUser(); if ($user instanceof \XM\SecurityBundle\Entity\User) { $user->incrementLoginCount(); $this->userManager->updateUser($user); $this->addLogSuccess($user); } }
php
public function logSuccess() { /** @var XM\SecurityBundle\Entity\User $user */ $user = $this->tokenStorage->getToken()->getUser(); if ($user instanceof \XM\SecurityBundle\Entity\User) { $user->incrementLoginCount(); $this->userManager->updateUser($user); $this->addLogSuccess($user); } }
[ "public", "function", "logSuccess", "(", ")", "{", "/** @var XM\\SecurityBundle\\Entity\\User $user */", "$", "user", "=", "$", "this", "->", "tokenStorage", "->", "getToken", "(", ")", "->", "getUser", "(", ")", ";", "if", "(", "$", "user", "instanceof", "\\", "XM", "\\", "SecurityBundle", "\\", "Entity", "\\", "User", ")", "{", "$", "user", "->", "incrementLoginCount", "(", ")", ";", "$", "this", "->", "userManager", "->", "updateUser", "(", "$", "user", ")", ";", "$", "this", "->", "addLogSuccess", "(", "$", "user", ")", ";", "}", "}" ]
Logs the successful login. Event will be passed but we don't use it or care what it is.
[ "Logs", "the", "successful", "login", ".", "Event", "will", "be", "passed", "but", "we", "don", "t", "use", "it", "or", "care", "what", "it", "is", "." ]
ee71a1bb4fe038e5a08e44f73247c4e03631a840
https://github.com/xmmedia/XMSecurityBundle/blob/ee71a1bb4fe038e5a08e44f73247c4e03631a840/Listener/AuthenticationLoggerListener.php#L68-L80
11,548
xmmedia/XMSecurityBundle
Listener/AuthenticationLoggerListener.php
AuthenticationLoggerListener.logFailure
public function logFailure(AuthenticationFailureEvent $event) { $request = $this->requestStack->getCurrentRequest(); $exception = $event->getAuthenticationException() ->getPrevious(); if (null === $exception) { $exception = $event->getAuthenticationException(); } $authLog = $this->createAuthLog(); $authLog->setSuccess(false); $authLog->setUsername($request->request->get('_username')); $authLog->setMessage($exception->getMessage()); $this->em->persist($authLog); $this->em->flush(); }
php
public function logFailure(AuthenticationFailureEvent $event) { $request = $this->requestStack->getCurrentRequest(); $exception = $event->getAuthenticationException() ->getPrevious(); if (null === $exception) { $exception = $event->getAuthenticationException(); } $authLog = $this->createAuthLog(); $authLog->setSuccess(false); $authLog->setUsername($request->request->get('_username')); $authLog->setMessage($exception->getMessage()); $this->em->persist($authLog); $this->em->flush(); }
[ "public", "function", "logFailure", "(", "AuthenticationFailureEvent", "$", "event", ")", "{", "$", "request", "=", "$", "this", "->", "requestStack", "->", "getCurrentRequest", "(", ")", ";", "$", "exception", "=", "$", "event", "->", "getAuthenticationException", "(", ")", "->", "getPrevious", "(", ")", ";", "if", "(", "null", "===", "$", "exception", ")", "{", "$", "exception", "=", "$", "event", "->", "getAuthenticationException", "(", ")", ";", "}", "$", "authLog", "=", "$", "this", "->", "createAuthLog", "(", ")", ";", "$", "authLog", "->", "setSuccess", "(", "false", ")", ";", "$", "authLog", "->", "setUsername", "(", "$", "request", "->", "request", "->", "get", "(", "'_username'", ")", ")", ";", "$", "authLog", "->", "setMessage", "(", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "$", "this", "->", "em", "->", "persist", "(", "$", "authLog", ")", ";", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "}" ]
Logs a failed login. @param AuthenticationFailureEvent $event
[ "Logs", "a", "failed", "login", "." ]
ee71a1bb4fe038e5a08e44f73247c4e03631a840
https://github.com/xmmedia/XMSecurityBundle/blob/ee71a1bb4fe038e5a08e44f73247c4e03631a840/Listener/AuthenticationLoggerListener.php#L87-L104
11,549
xmmedia/XMSecurityBundle
Listener/AuthenticationLoggerListener.php
AuthenticationLoggerListener.createAuthLog
protected function createAuthLog() { $request = $this->requestStack->getCurrentRequest(); /** @var XM\SecurityBundle\Entity\AuthLog $authLog */ $authLog = new $this->authLogClass(); $authLog->setDatetime(new \DateTimeImmutable()); $authLog->setUserAgent($request->headers->get('User-Agent')); $authLog->setIpAddress($request->getClientIp()); return $authLog; }
php
protected function createAuthLog() { $request = $this->requestStack->getCurrentRequest(); /** @var XM\SecurityBundle\Entity\AuthLog $authLog */ $authLog = new $this->authLogClass(); $authLog->setDatetime(new \DateTimeImmutable()); $authLog->setUserAgent($request->headers->get('User-Agent')); $authLog->setIpAddress($request->getClientIp()); return $authLog; }
[ "protected", "function", "createAuthLog", "(", ")", "{", "$", "request", "=", "$", "this", "->", "requestStack", "->", "getCurrentRequest", "(", ")", ";", "/** @var XM\\SecurityBundle\\Entity\\AuthLog $authLog */", "$", "authLog", "=", "new", "$", "this", "->", "authLogClass", "(", ")", ";", "$", "authLog", "->", "setDatetime", "(", "new", "\\", "DateTimeImmutable", "(", ")", ")", ";", "$", "authLog", "->", "setUserAgent", "(", "$", "request", "->", "headers", "->", "get", "(", "'User-Agent'", ")", ")", ";", "$", "authLog", "->", "setIpAddress", "(", "$", "request", "->", "getClientIp", "(", ")", ")", ";", "return", "$", "authLog", ";", "}" ]
Creates the auth log entity with the User Agent and client IP. @return AuthLog
[ "Creates", "the", "auth", "log", "entity", "with", "the", "User", "Agent", "and", "client", "IP", "." ]
ee71a1bb4fe038e5a08e44f73247c4e03631a840
https://github.com/xmmedia/XMSecurityBundle/blob/ee71a1bb4fe038e5a08e44f73247c4e03631a840/Listener/AuthenticationLoggerListener.php#L111-L122
11,550
xmmedia/XMSecurityBundle
Listener/AuthenticationLoggerListener.php
AuthenticationLoggerListener.addLogSuccess
protected function addLogSuccess(UserInterface $user) { $this->userManager->updateUser($user); $authLog = $this->createAuthLog(); $authLog->setSuccess(true); $authLog->setUser($user); $authLog->setUsername($user->getUsername()); $this->em->persist($authLog); $this->em->flush(); }
php
protected function addLogSuccess(UserInterface $user) { $this->userManager->updateUser($user); $authLog = $this->createAuthLog(); $authLog->setSuccess(true); $authLog->setUser($user); $authLog->setUsername($user->getUsername()); $this->em->persist($authLog); $this->em->flush(); }
[ "protected", "function", "addLogSuccess", "(", "UserInterface", "$", "user", ")", "{", "$", "this", "->", "userManager", "->", "updateUser", "(", "$", "user", ")", ";", "$", "authLog", "=", "$", "this", "->", "createAuthLog", "(", ")", ";", "$", "authLog", "->", "setSuccess", "(", "true", ")", ";", "$", "authLog", "->", "setUser", "(", "$", "user", ")", ";", "$", "authLog", "->", "setUsername", "(", "$", "user", "->", "getUsername", "(", ")", ")", ";", "$", "this", "->", "em", "->", "persist", "(", "$", "authLog", ")", ";", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "}" ]
Add successful log. @param UserInterface $user
[ "Add", "successful", "log", "." ]
ee71a1bb4fe038e5a08e44f73247c4e03631a840
https://github.com/xmmedia/XMSecurityBundle/blob/ee71a1bb4fe038e5a08e44f73247c4e03631a840/Listener/AuthenticationLoggerListener.php#L129-L140
11,551
konservs/brilliant.framework
libraries/Users/Social/google.php
BSocialAdapterGoogle.getBirthday
public function getBirthday(){ if(isset($this->_userInfo['birthday'])) { $this->_userInfo['birthday'] = str_replace('0000', date('Y'), $this->_userInfo['birthday']); $result = date('d.m.Y', strtotime($this->_userInfo['birthday'])); } else { $result = null; } return $result; }
php
public function getBirthday(){ if(isset($this->_userInfo['birthday'])) { $this->_userInfo['birthday'] = str_replace('0000', date('Y'), $this->_userInfo['birthday']); $result = date('d.m.Y', strtotime($this->_userInfo['birthday'])); } else { $result = null; } return $result; }
[ "public", "function", "getBirthday", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_userInfo", "[", "'birthday'", "]", ")", ")", "{", "$", "this", "->", "_userInfo", "[", "'birthday'", "]", "=", "str_replace", "(", "'0000'", ",", "date", "(", "'Y'", ")", ",", "$", "this", "->", "_userInfo", "[", "'birthday'", "]", ")", ";", "$", "result", "=", "date", "(", "'d.m.Y'", ",", "strtotime", "(", "$", "this", "->", "_userInfo", "[", "'birthday'", "]", ")", ")", ";", "}", "else", "{", "$", "result", "=", "null", ";", "}", "return", "$", "result", ";", "}" ]
Get user birthday or null if it is not set @return string|null
[ "Get", "user", "birthday", "or", "null", "if", "it", "is", "not", "set" ]
95f03f1917f746fee98bea8a906ba0588c87762d
https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/libraries/Users/Social/google.php#L23-L32
11,552
wudimeicom/WudimeiPHP
Lang.php
Lang.groupAppend
public function groupAppend( $groupName, $groupName2OrArray , $replace = true ){ $this->load($groupName); $data = []; if( is_array( $groupName2OrArray ) ){ $data = $groupName2OrArray; } else{ $this->load( $groupName2OrArray ); $data = $this->langs[ $groupName2OrArray]; } if( !empty( $data)){ foreach ($data as $k => $v ){ if( isset( $this->langs[$groupName][$k])){ if( $replace == true ){ $this->langs[ $groupName ][$k] = $v; } } else{ $this->langs[ $groupName ][$k] = $v; } } } }
php
public function groupAppend( $groupName, $groupName2OrArray , $replace = true ){ $this->load($groupName); $data = []; if( is_array( $groupName2OrArray ) ){ $data = $groupName2OrArray; } else{ $this->load( $groupName2OrArray ); $data = $this->langs[ $groupName2OrArray]; } if( !empty( $data)){ foreach ($data as $k => $v ){ if( isset( $this->langs[$groupName][$k])){ if( $replace == true ){ $this->langs[ $groupName ][$k] = $v; } } else{ $this->langs[ $groupName ][$k] = $v; } } } }
[ "public", "function", "groupAppend", "(", "$", "groupName", ",", "$", "groupName2OrArray", ",", "$", "replace", "=", "true", ")", "{", "$", "this", "->", "load", "(", "$", "groupName", ")", ";", "$", "data", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "groupName2OrArray", ")", ")", "{", "$", "data", "=", "$", "groupName2OrArray", ";", "}", "else", "{", "$", "this", "->", "load", "(", "$", "groupName2OrArray", ")", ";", "$", "data", "=", "$", "this", "->", "langs", "[", "$", "groupName2OrArray", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "langs", "[", "$", "groupName", "]", "[", "$", "k", "]", ")", ")", "{", "if", "(", "$", "replace", "==", "true", ")", "{", "$", "this", "->", "langs", "[", "$", "groupName", "]", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}", "else", "{", "$", "this", "->", "langs", "[", "$", "groupName", "]", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}", "}", "}" ]
append a group or array to the group @param string $groupName @param string|array $groupName2OrArray @param bool $replace
[ "append", "a", "group", "or", "array", "to", "the", "group" ]
ea7267d449cea06dc057919efa498599bd8ee4b9
https://github.com/wudimeicom/WudimeiPHP/blob/ea7267d449cea06dc057919efa498599bd8ee4b9/Lang.php#L189-L213
11,553
tomvlk/sweet-orm
src/SweetORM/Structure/Annotation/Column.php
Column.defaultValue
public function defaultValue() { if ($this->default === null) { return null; } $default = $this->default; if (strstr($this->default, '{{') && strstr($this->default, '}}')) { // Parse special replacements (if we have one) $default = str_replace("{{CURRENT_TIME}}", date('c', time()), $default); } return $default; }
php
public function defaultValue() { if ($this->default === null) { return null; } $default = $this->default; if (strstr($this->default, '{{') && strstr($this->default, '}}')) { // Parse special replacements (if we have one) $default = str_replace("{{CURRENT_TIME}}", date('c', time()), $default); } return $default; }
[ "public", "function", "defaultValue", "(", ")", "{", "if", "(", "$", "this", "->", "default", "===", "null", ")", "{", "return", "null", ";", "}", "$", "default", "=", "$", "this", "->", "default", ";", "if", "(", "strstr", "(", "$", "this", "->", "default", ",", "'{{'", ")", "&&", "strstr", "(", "$", "this", "->", "default", ",", "'}}'", ")", ")", "{", "// Parse special replacements (if we have one)", "$", "default", "=", "str_replace", "(", "\"{{CURRENT_TIME}}\"", ",", "date", "(", "'c'", ",", "time", "(", ")", ")", ",", "$", "default", ")", ";", "}", "return", "$", "default", ";", "}" ]
Parse and return default value of column. @return string|int|null default value
[ "Parse", "and", "return", "default", "value", "of", "column", "." ]
bca014a9f83be34c87b14d6c8a36156e24577374
https://github.com/tomvlk/sweet-orm/blob/bca014a9f83be34c87b14d6c8a36156e24577374/src/SweetORM/Structure/Annotation/Column.php#L82-L96
11,554
DerekMarcinyshyn/monashee-backup
src/Monashee/Backup/UploadS3.php
UploadS3.deleteDailyBackups
private function deleteDailyBackups() { try { $date = strtotime('-2 months'); // leave first day of the month if ((int) date('j', $date) !== 1) { $this->filesystem->deleteDir(date("Y/m/d", $date)); } } catch (\Exception $e) { $this->event->fire('MonasheeBackupError', 'Error trying to delete directory on AWS S3'); } }
php
private function deleteDailyBackups() { try { $date = strtotime('-2 months'); // leave first day of the month if ((int) date('j', $date) !== 1) { $this->filesystem->deleteDir(date("Y/m/d", $date)); } } catch (\Exception $e) { $this->event->fire('MonasheeBackupError', 'Error trying to delete directory on AWS S3'); } }
[ "private", "function", "deleteDailyBackups", "(", ")", "{", "try", "{", "$", "date", "=", "strtotime", "(", "'-2 months'", ")", ";", "// leave first day of the month", "if", "(", "(", "int", ")", "date", "(", "'j'", ",", "$", "date", ")", "!==", "1", ")", "{", "$", "this", "->", "filesystem", "->", "deleteDir", "(", "date", "(", "\"Y/m/d\"", ",", "$", "date", ")", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "event", "->", "fire", "(", "'MonasheeBackupError'", ",", "'Error trying to delete directory on AWS S3'", ")", ";", "}", "}" ]
Delete AWS S3 directory of 2 months ago but keep 1st of the month
[ "Delete", "AWS", "S3", "directory", "of", "2", "months", "ago", "but", "keep", "1st", "of", "the", "month" ]
2f96f3ddbbdd1c672e0064bf3b66951f94975158
https://github.com/DerekMarcinyshyn/monashee-backup/blob/2f96f3ddbbdd1c672e0064bf3b66951f94975158/src/Monashee/Backup/UploadS3.php#L90-L102
11,555
reflex-php/lockdown
src/Reflex/Lockdown/Permissions/Eloquent/Provider.php
Provider.delete
public function delete($key) { $permission = $this->findByKey($key); if (! isset($permission)) { return true; } return $permission->delete(); }
php
public function delete($key) { $permission = $this->findByKey($key); if (! isset($permission)) { return true; } return $permission->delete(); }
[ "public", "function", "delete", "(", "$", "key", ")", "{", "$", "permission", "=", "$", "this", "->", "findByKey", "(", "$", "key", ")", ";", "if", "(", "!", "isset", "(", "$", "permission", ")", ")", "{", "return", "true", ";", "}", "return", "$", "permission", "->", "delete", "(", ")", ";", "}" ]
Delete a permission @param string $key Lookup key @return boolean
[ "Delete", "a", "permission" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Permissions/Eloquent/Provider.php#L70-L78
11,556
reflex-php/lockdown
src/Reflex/Lockdown/Permissions/Eloquent/Provider.php
Provider.findNotInRole
public function findNotInRole(RoleInterface $role) { $callback = function ($permission) use ($role) { return $role->hasnt($permission->key); }; return array_filter($this->findAll(), $callback); }
php
public function findNotInRole(RoleInterface $role) { $callback = function ($permission) use ($role) { return $role->hasnt($permission->key); }; return array_filter($this->findAll(), $callback); }
[ "public", "function", "findNotInRole", "(", "RoleInterface", "$", "role", ")", "{", "$", "callback", "=", "function", "(", "$", "permission", ")", "use", "(", "$", "role", ")", "{", "return", "$", "role", "->", "hasnt", "(", "$", "permission", "->", "key", ")", ";", "}", ";", "return", "array_filter", "(", "$", "this", "->", "findAll", "(", ")", ",", "$", "callback", ")", ";", "}" ]
Find permission not in a role @param Reflex\Lockdown\Roles\RoleInterface $role Role instance @return \Illuminate\Support\Collection
[ "Find", "permission", "not", "in", "a", "role" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Permissions/Eloquent/Provider.php#L140-L147
11,557
AnonymPHP/Anonym-Library
src/Anonym/Security/TypeHint.php
TypeHint.handle
public static function handle($errLevel, $errMessage) { if ($errLevel === E_RECOVERABLE_ERROR) { if ($explode = explode(' ', $errMessage)) { if ( $explode[0] === 'Argument' && $explode[2] === 'passed' && $explode[3] === 'to' && $explode[5] === 'must' && $explode[20] === 'defined' ) { $arg = $explode[1] - 1; $mustType = $explode[10]; $back = debug_backtrace()[1]; $explode = explode('\\', $mustType); $end = end($explode); $getLastType = rtrim($end, ','); $args = $back['args']; $arg = $args[$arg]; if (gettype($arg) != $getLastType) { if (call_user_func(static::$types[$getLastType], $arg)) { return true; } else { return false; } } else { return true; } } else { return false; } } } else { return false; } }
php
public static function handle($errLevel, $errMessage) { if ($errLevel === E_RECOVERABLE_ERROR) { if ($explode = explode(' ', $errMessage)) { if ( $explode[0] === 'Argument' && $explode[2] === 'passed' && $explode[3] === 'to' && $explode[5] === 'must' && $explode[20] === 'defined' ) { $arg = $explode[1] - 1; $mustType = $explode[10]; $back = debug_backtrace()[1]; $explode = explode('\\', $mustType); $end = end($explode); $getLastType = rtrim($end, ','); $args = $back['args']; $arg = $args[$arg]; if (gettype($arg) != $getLastType) { if (call_user_func(static::$types[$getLastType], $arg)) { return true; } else { return false; } } else { return true; } } else { return false; } } } else { return false; } }
[ "public", "static", "function", "handle", "(", "$", "errLevel", ",", "$", "errMessage", ")", "{", "if", "(", "$", "errLevel", "===", "E_RECOVERABLE_ERROR", ")", "{", "if", "(", "$", "explode", "=", "explode", "(", "' '", ",", "$", "errMessage", ")", ")", "{", "if", "(", "$", "explode", "[", "0", "]", "===", "'Argument'", "&&", "$", "explode", "[", "2", "]", "===", "'passed'", "&&", "$", "explode", "[", "3", "]", "===", "'to'", "&&", "$", "explode", "[", "5", "]", "===", "'must'", "&&", "$", "explode", "[", "20", "]", "===", "'defined'", ")", "{", "$", "arg", "=", "$", "explode", "[", "1", "]", "-", "1", ";", "$", "mustType", "=", "$", "explode", "[", "10", "]", ";", "$", "back", "=", "debug_backtrace", "(", ")", "[", "1", "]", ";", "$", "explode", "=", "explode", "(", "'\\\\'", ",", "$", "mustType", ")", ";", "$", "end", "=", "end", "(", "$", "explode", ")", ";", "$", "getLastType", "=", "rtrim", "(", "$", "end", ",", "','", ")", ";", "$", "args", "=", "$", "back", "[", "'args'", "]", ";", "$", "arg", "=", "$", "args", "[", "$", "arg", "]", ";", "if", "(", "gettype", "(", "$", "arg", ")", "!=", "$", "getLastType", ")", "{", "if", "(", "call_user_func", "(", "static", "::", "$", "types", "[", "$", "getLastType", "]", ",", "$", "arg", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "return", "true", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "}", "else", "{", "return", "false", ";", "}", "}" ]
handle the error @param integer $errLevel the level of error @param string $errMessage the message of error @return bool true on success, if failure happen return false
[ "handle", "the", "error" ]
c967ad804f84e8fb204593a0959cda2fed5ae075
https://github.com/AnonymPHP/Anonym-Library/blob/c967ad804f84e8fb204593a0959cda2fed5ae075/src/Anonym/Security/TypeHint.php#L56-L94
11,558
phlexible/phlexible
src/Phlexible/Bundle/SearchBundle/Controller/SearchController.php
SearchController.indexAction
public function indexAction(Request $request) { $query = $request->get('query'); $limit = $request->get('limit', 8); $start = $request->get('start', 0); $search = $this->get('phlexible_search.search'); $results = $search->search($query); return new JsonResponse([ 'totalCount' => count($results), 'results' => array_slice($results, $start, $limit), ]); }
php
public function indexAction(Request $request) { $query = $request->get('query'); $limit = $request->get('limit', 8); $start = $request->get('start', 0); $search = $this->get('phlexible_search.search'); $results = $search->search($query); return new JsonResponse([ 'totalCount' => count($results), 'results' => array_slice($results, $start, $limit), ]); }
[ "public", "function", "indexAction", "(", "Request", "$", "request", ")", "{", "$", "query", "=", "$", "request", "->", "get", "(", "'query'", ")", ";", "$", "limit", "=", "$", "request", "->", "get", "(", "'limit'", ",", "8", ")", ";", "$", "start", "=", "$", "request", "->", "get", "(", "'start'", ",", "0", ")", ";", "$", "search", "=", "$", "this", "->", "get", "(", "'phlexible_search.search'", ")", ";", "$", "results", "=", "$", "search", "->", "search", "(", "$", "query", ")", ";", "return", "new", "JsonResponse", "(", "[", "'totalCount'", "=>", "count", "(", "$", "results", ")", ",", "'results'", "=>", "array_slice", "(", "$", "results", ",", "$", "start", ",", "$", "limit", ")", ",", "]", ")", ";", "}" ]
Return search results. @param Request $request @return JsonResponse @Route("", name="search_search") @Method({"GET", "POST"}) @ApiDoc( description="Search", requirements={ {"name"="query", "dataType"="string", "required"=true, "description"="Search query"} }, filters={ {"name"="limit", "dataType"="integer", "default"=8, "description"="Limit results"}, {"name"="start", "dataType"="integer", "default"=0, "description"="Result offset"} } )
[ "Return", "search", "results", "." ]
132f24924c9bb0dbb6c1ea84db0a463f97fa3893
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/SearchBundle/Controller/SearchController.php#L48-L61
11,559
plista/core
src/Plista/Core/Enum.php
Enum.values
public static final function values() { $calledClass = get_called_class(); // let's check the cache so we don't have to call reflection constantly if (empty(self::$cachedValues[$calledClass])) { $class = new \ReflectionClass($calledClass); self::$cachedValues[$calledClass] = $class->getConstants(); } return self::$cachedValues[$calledClass]; }
php
public static final function values() { $calledClass = get_called_class(); // let's check the cache so we don't have to call reflection constantly if (empty(self::$cachedValues[$calledClass])) { $class = new \ReflectionClass($calledClass); self::$cachedValues[$calledClass] = $class->getConstants(); } return self::$cachedValues[$calledClass]; }
[ "public", "static", "final", "function", "values", "(", ")", "{", "$", "calledClass", "=", "get_called_class", "(", ")", ";", "// let's check the cache so we don't have to call reflection constantly", "if", "(", "empty", "(", "self", "::", "$", "cachedValues", "[", "$", "calledClass", "]", ")", ")", "{", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "calledClass", ")", ";", "self", "::", "$", "cachedValues", "[", "$", "calledClass", "]", "=", "$", "class", "->", "getConstants", "(", ")", ";", "}", "return", "self", "::", "$", "cachedValues", "[", "$", "calledClass", "]", ";", "}" ]
Returns a list of values this Enum can take. The keys are the defined constants and the values are their respective values. @return array
[ "Returns", "a", "list", "of", "values", "this", "Enum", "can", "take", ".", "The", "keys", "are", "the", "defined", "constants", "and", "the", "values", "are", "their", "respective", "values", "." ]
0fa9b97f71ccfc743a4f367744380dc13dddb6d3
https://github.com/plista/core/blob/0fa9b97f71ccfc743a4f367744380dc13dddb6d3/src/Plista/Core/Enum.php#L112-L122
11,560
plista/core
src/Plista/Core/Enum.php
Enum.equals
public final function equals($e) { // first we check the case when an Enum is passed in if (is_object($e)) { // we require it to be the same type, even when the value may be identical if (!($e instanceof static)) { return false; } // strict check return $this->value === $e->value; } // if its a scalar value, we check it directly, still using strict // this will usually happen if the used does something like this: // $enum = EnumChild::FOO(); // if ($enum->equals(EnumChild::FOO)) ... return $this->value === $e; }
php
public final function equals($e) { // first we check the case when an Enum is passed in if (is_object($e)) { // we require it to be the same type, even when the value may be identical if (!($e instanceof static)) { return false; } // strict check return $this->value === $e->value; } // if its a scalar value, we check it directly, still using strict // this will usually happen if the used does something like this: // $enum = EnumChild::FOO(); // if ($enum->equals(EnumChild::FOO)) ... return $this->value === $e; }
[ "public", "final", "function", "equals", "(", "$", "e", ")", "{", "// first we check the case when an Enum is passed in", "if", "(", "is_object", "(", "$", "e", ")", ")", "{", "// we require it to be the same type, even when the value may be identical", "if", "(", "!", "(", "$", "e", "instanceof", "static", ")", ")", "{", "return", "false", ";", "}", "// strict check", "return", "$", "this", "->", "value", "===", "$", "e", "->", "value", ";", "}", "// if its a scalar value, we check it directly, still using strict", "// this will usually happen if the used does something like this:", "// $enum = EnumChild::FOO();", "// if ($enum->equals(EnumChild::FOO)) ...", "return", "$", "this", "->", "value", "===", "$", "e", ";", "}" ]
Helper function to compare an Enum instance to another Enum instance or a scalar value. @param Enum|string|int $e the value to compare against @return bool
[ "Helper", "function", "to", "compare", "an", "Enum", "instance", "to", "another", "Enum", "instance", "or", "a", "scalar", "value", "." ]
0fa9b97f71ccfc743a4f367744380dc13dddb6d3
https://github.com/plista/core/blob/0fa9b97f71ccfc743a4f367744380dc13dddb6d3/src/Plista/Core/Enum.php#L139-L156
11,561
emaphp/eMapper
lib/eMapper/Fluent/Query/FluentInsert.php
FluentInsert.values
public function values($values) { if (is_array($values)) $this->value = $values; else $this->valueList = func_get_args(); return $this; }
php
public function values($values) { if (is_array($values)) $this->value = $values; else $this->valueList = func_get_args(); return $this; }
[ "public", "function", "values", "(", "$", "values", ")", "{", "if", "(", "is_array", "(", "$", "values", ")", ")", "$", "this", "->", "value", "=", "$", "values", ";", "else", "$", "this", "->", "valueList", "=", "func_get_args", "(", ")", ";", "return", "$", "this", ";", "}" ]
Sets the values to insert as a list @param mixed $values @return \eMapper\Fluent\Query\FluentInsert
[ "Sets", "the", "values", "to", "insert", "as", "a", "list" ]
df7100e601d2a1363d07028a786b6ceb22271829
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentInsert.php#L40-L46
11,562
emaphp/eMapper
lib/eMapper/Fluent/Query/FluentInsert.php
FluentInsert.valuesExpr
public function valuesExpr($expression) { $args = func_get_args(); $this->expression = array_shift($args); if (empty($args)) return $this; //check if argument is a list try { $this->valuesArray($args[0]); } catch (\InvalidArgumentException $e) { $this->valueList = $args; } return $this; }
php
public function valuesExpr($expression) { $args = func_get_args(); $this->expression = array_shift($args); if (empty($args)) return $this; //check if argument is a list try { $this->valuesArray($args[0]); } catch (\InvalidArgumentException $e) { $this->valueList = $args; } return $this; }
[ "public", "function", "valuesExpr", "(", "$", "expression", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "this", "->", "expression", "=", "array_shift", "(", "$", "args", ")", ";", "if", "(", "empty", "(", "$", "args", ")", ")", "return", "$", "this", ";", "//check if argument is a list", "try", "{", "$", "this", "->", "valuesArray", "(", "$", "args", "[", "0", "]", ")", ";", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "e", ")", "{", "$", "this", "->", "valueList", "=", "$", "args", ";", "}", "return", "$", "this", ";", "}" ]
Sets the VALUES clause along with its arguments @param string $expression @return \eMapper\Fluent\Query\FluentInsert
[ "Sets", "the", "VALUES", "clause", "along", "with", "its", "arguments" ]
df7100e601d2a1363d07028a786b6ceb22271829
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentInsert.php#L53-L69
11,563
emaphp/eMapper
lib/eMapper/Fluent/Query/FluentInsert.php
FluentInsert.valuesArray
public function valuesArray($values) { if ($values instanceof \ArrayObject) $this->value = $values->getArrayCopy(); elseif (is_object($values)) $this->value = get_object_vars($values); elseif (is_array($values)) $this->value = $values; else throw new \InvalidArgumentException("Method 'valuesArray' expected an object or array value"); if (is_numeric(key($this->value))) { $this->valueList = $this->value; $this->value = null; } return $this; }
php
public function valuesArray($values) { if ($values instanceof \ArrayObject) $this->value = $values->getArrayCopy(); elseif (is_object($values)) $this->value = get_object_vars($values); elseif (is_array($values)) $this->value = $values; else throw new \InvalidArgumentException("Method 'valuesArray' expected an object or array value"); if (is_numeric(key($this->value))) { $this->valueList = $this->value; $this->value = null; } return $this; }
[ "public", "function", "valuesArray", "(", "$", "values", ")", "{", "if", "(", "$", "values", "instanceof", "\\", "ArrayObject", ")", "$", "this", "->", "value", "=", "$", "values", "->", "getArrayCopy", "(", ")", ";", "elseif", "(", "is_object", "(", "$", "values", ")", ")", "$", "this", "->", "value", "=", "get_object_vars", "(", "$", "values", ")", ";", "elseif", "(", "is_array", "(", "$", "values", ")", ")", "$", "this", "->", "value", "=", "$", "values", ";", "else", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Method 'valuesArray' expected an object or array value\"", ")", ";", "if", "(", "is_numeric", "(", "key", "(", "$", "this", "->", "value", ")", ")", ")", "{", "$", "this", "->", "valueList", "=", "$", "this", "->", "value", ";", "$", "this", "->", "value", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
Sets the value to insert as an associative array @param mixed $values @throws \InvalidArgumentException @return \eMapper\Fluent\Query\FluentInsert
[ "Sets", "the", "value", "to", "insert", "as", "an", "associative", "array" ]
df7100e601d2a1363d07028a786b6ceb22271829
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentInsert.php#L77-L93
11,564
emaphp/eMapper
lib/eMapper/Fluent/Query/FluentInsert.php
FluentInsert.columns
public function columns($columns) { if (is_array($columns)) $this->columnList = $columns; else $this->columnList = func_get_args(); return $this; }
php
public function columns($columns) { if (is_array($columns)) $this->columnList = $columns; else $this->columnList = func_get_args(); return $this; }
[ "public", "function", "columns", "(", "$", "columns", ")", "{", "if", "(", "is_array", "(", "$", "columns", ")", ")", "$", "this", "->", "columnList", "=", "$", "columns", ";", "else", "$", "this", "->", "columnList", "=", "func_get_args", "(", ")", ";", "return", "$", "this", ";", "}" ]
Sets the column list @return \eMapper\Fluent\Query\FluentInsert
[ "Sets", "the", "column", "list" ]
df7100e601d2a1363d07028a786b6ceb22271829
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentInsert.php#L99-L105
11,565
emaphp/eMapper
lib/eMapper/Fluent/Query/FluentInsert.php
FluentInsert.translateColumn
protected function translateColumn($column) { if ($column instanceof Column) return $column->getName(); return preg_match('/^(\w+)/', $column, $matches) ? $matches[1] : $column; }
php
protected function translateColumn($column) { if ($column instanceof Column) return $column->getName(); return preg_match('/^(\w+)/', $column, $matches) ? $matches[1] : $column; }
[ "protected", "function", "translateColumn", "(", "$", "column", ")", "{", "if", "(", "$", "column", "instanceof", "Column", ")", "return", "$", "column", "->", "getName", "(", ")", ";", "return", "preg_match", "(", "'/^(\\w+)/'", ",", "$", "column", ",", "$", "matches", ")", "?", "$", "matches", "[", "1", "]", ":", "$", "column", ";", "}" ]
Translates a insert column @param Column | string $column @return string
[ "Translates", "a", "insert", "column" ]
df7100e601d2a1363d07028a786b6ceb22271829
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentInsert.php#L112-L117
11,566
emaphp/eMapper
lib/eMapper/Fluent/Query/FluentInsert.php
FluentInsert.buildColumnsClause
protected function buildColumnsClause() { if (empty($this->columnList)) { if (!empty($this->value)) $this->columnList = array_keys($this->value); else return ''; } $columns = []; foreach ($this->columnList as $column) $columns[] = $this->translateColumn($column); return implode(',', $columns); }
php
protected function buildColumnsClause() { if (empty($this->columnList)) { if (!empty($this->value)) $this->columnList = array_keys($this->value); else return ''; } $columns = []; foreach ($this->columnList as $column) $columns[] = $this->translateColumn($column); return implode(',', $columns); }
[ "protected", "function", "buildColumnsClause", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "columnList", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "value", ")", ")", "$", "this", "->", "columnList", "=", "array_keys", "(", "$", "this", "->", "value", ")", ";", "else", "return", "''", ";", "}", "$", "columns", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "columnList", "as", "$", "column", ")", "$", "columns", "[", "]", "=", "$", "this", "->", "translateColumn", "(", "$", "column", ")", ";", "return", "implode", "(", "','", ",", "$", "columns", ")", ";", "}" ]
Returns the column list as a string @return string
[ "Returns", "the", "column", "list", "as", "a", "string" ]
df7100e601d2a1363d07028a786b6ceb22271829
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentInsert.php#L123-L137
11,567
emaphp/eMapper
lib/eMapper/Fluent/Query/FluentInsert.php
FluentInsert.buildValuesClause
protected function buildValuesClause() { if (!empty($this->expression)) return $this->expression; if (empty($this->value)) { $values = []; for ($i = 0, $n = count($this->valueList); $i < $n; $i++) $values[] = '%{' . $i . '}'; return implode(',', $values); } $values = []; foreach ($this->columnList as $column) { $name = $this->parseColumn($column); $values[] = '#{' . $name . '}'; } return implode(',', $values); }
php
protected function buildValuesClause() { if (!empty($this->expression)) return $this->expression; if (empty($this->value)) { $values = []; for ($i = 0, $n = count($this->valueList); $i < $n; $i++) $values[] = '%{' . $i . '}'; return implode(',', $values); } $values = []; foreach ($this->columnList as $column) { $name = $this->parseColumn($column); $values[] = '#{' . $name . '}'; } return implode(',', $values); }
[ "protected", "function", "buildValuesClause", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "expression", ")", ")", "return", "$", "this", "->", "expression", ";", "if", "(", "empty", "(", "$", "this", "->", "value", ")", ")", "{", "$", "values", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ",", "$", "n", "=", "count", "(", "$", "this", "->", "valueList", ")", ";", "$", "i", "<", "$", "n", ";", "$", "i", "++", ")", "$", "values", "[", "]", "=", "'%{'", ".", "$", "i", ".", "'}'", ";", "return", "implode", "(", "','", ",", "$", "values", ")", ";", "}", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "columnList", "as", "$", "column", ")", "{", "$", "name", "=", "$", "this", "->", "parseColumn", "(", "$", "column", ")", ";", "$", "values", "[", "]", "=", "'#{'", ".", "$", "name", ".", "'}'", ";", "}", "return", "implode", "(", "','", ",", "$", "values", ")", ";", "}" ]
Returns the value list expression @return string
[ "Returns", "the", "value", "list", "expression" ]
df7100e601d2a1363d07028a786b6ceb22271829
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentInsert.php#L157-L179
11,568
benkle-libs/feed-parser
src/Traits/WithMappedLinkTrait.php
WithMappedLinkTrait.setUrl
public function setUrl($url) { $relation = new RelationLink(); $relation ->setRelationType('self') ->setUrl($url); return $this->setRelation($relation); }
php
public function setUrl($url) { $relation = new RelationLink(); $relation ->setRelationType('self') ->setUrl($url); return $this->setRelation($relation); }
[ "public", "function", "setUrl", "(", "$", "url", ")", "{", "$", "relation", "=", "new", "RelationLink", "(", ")", ";", "$", "relation", "->", "setRelationType", "(", "'self'", ")", "->", "setUrl", "(", "$", "url", ")", ";", "return", "$", "this", "->", "setRelation", "(", "$", "relation", ")", ";", "}" ]
Set the feed url. @param string $url @return $this
[ "Set", "the", "feed", "url", "." ]
8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f
https://github.com/benkle-libs/feed-parser/blob/8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f/src/Traits/WithMappedLinkTrait.php#L56-L63
11,569
benkle-libs/feed-parser
src/Traits/WithMappedLinkTrait.php
WithMappedLinkTrait.getRelationSilently
private function getRelationSilently($rel) { $result = null; try { $result = $this->getRelation($rel); } catch (\Exception $e) { } return $result; }
php
private function getRelationSilently($rel) { $result = null; try { $result = $this->getRelation($rel); } catch (\Exception $e) { } return $result; }
[ "private", "function", "getRelationSilently", "(", "$", "rel", ")", "{", "$", "result", "=", "null", ";", "try", "{", "$", "result", "=", "$", "this", "->", "getRelation", "(", "$", "rel", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "return", "$", "result", ";", "}" ]
Get a relation link, failing silently. @codeCoverageIgnore @param string $rel @return RelationLinkInterface|null
[ "Get", "a", "relation", "link", "failing", "silently", "." ]
8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f
https://github.com/benkle-libs/feed-parser/blob/8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f/src/Traits/WithMappedLinkTrait.php#L95-L103
11,570
lucifurious/kisma
src/Kisma/Core/Utility/Option.php
Option.get
public static function get( &$options = array(), $key, $defaultValue = null, $unsetValue = false, $emptyStringIsNull = false ) { // Get many? if ( is_array( $key ) ) { return static::getMany( $options, $key, $defaultValue, $unsetValue ); } $_originalKey = $key; // Set the default value $_newValue = $defaultValue; // Now a deeper search $key = static::_cleanKey( $key ); // Get array value if it exists if ( is_array( $options ) || $options instanceof \ArrayAccess ) { // Check for the original key too if ( !isset( $options[$key] ) && isset( $options[$_originalKey] ) ) { $key = $_originalKey; } if ( isset( $options[$key] ) ) { $_newValue = $options[$key]; if ( false !== $unsetValue ) { unset( $options[$key] ); } return $emptyStringIsNull && empty( $_newValue ) ? null : $_newValue; } } if ( is_object( $options ) ) { if ( !property_exists( $options, $key ) && property_exists( $options, $_originalKey ) ) { $key = $_originalKey; } if ( isset( $options->{$key} ) ) { $_newValue = $options->{$key}; if ( false !== $unsetValue ) { unset( $options->{$key} ); } return $emptyStringIsNull && empty( $_newValue ) ? null : $_newValue; } else if ( method_exists( $options, 'get' . $key ) ) { $_getter = 'get' . Inflector::deneutralize( $key ); $_setter = 'set' . Inflector::deneutralize( $key ); $_newValue = $options->{$_getter}(); if ( false !== $unsetValue && method_exists( $options, $_setter ) ) { $options->{$_setter}( null ); } } } // Return the default... return $emptyStringIsNull && empty( $_newValue ) ? null : $_newValue; }
php
public static function get( &$options = array(), $key, $defaultValue = null, $unsetValue = false, $emptyStringIsNull = false ) { // Get many? if ( is_array( $key ) ) { return static::getMany( $options, $key, $defaultValue, $unsetValue ); } $_originalKey = $key; // Set the default value $_newValue = $defaultValue; // Now a deeper search $key = static::_cleanKey( $key ); // Get array value if it exists if ( is_array( $options ) || $options instanceof \ArrayAccess ) { // Check for the original key too if ( !isset( $options[$key] ) && isset( $options[$_originalKey] ) ) { $key = $_originalKey; } if ( isset( $options[$key] ) ) { $_newValue = $options[$key]; if ( false !== $unsetValue ) { unset( $options[$key] ); } return $emptyStringIsNull && empty( $_newValue ) ? null : $_newValue; } } if ( is_object( $options ) ) { if ( !property_exists( $options, $key ) && property_exists( $options, $_originalKey ) ) { $key = $_originalKey; } if ( isset( $options->{$key} ) ) { $_newValue = $options->{$key}; if ( false !== $unsetValue ) { unset( $options->{$key} ); } return $emptyStringIsNull && empty( $_newValue ) ? null : $_newValue; } else if ( method_exists( $options, 'get' . $key ) ) { $_getter = 'get' . Inflector::deneutralize( $key ); $_setter = 'set' . Inflector::deneutralize( $key ); $_newValue = $options->{$_getter}(); if ( false !== $unsetValue && method_exists( $options, $_setter ) ) { $options->{$_setter}( null ); } } } // Return the default... return $emptyStringIsNull && empty( $_newValue ) ? null : $_newValue; }
[ "public", "static", "function", "get", "(", "&", "$", "options", "=", "array", "(", ")", ",", "$", "key", ",", "$", "defaultValue", "=", "null", ",", "$", "unsetValue", "=", "false", ",", "$", "emptyStringIsNull", "=", "false", ")", "{", "//\tGet many?", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "return", "static", "::", "getMany", "(", "$", "options", ",", "$", "key", ",", "$", "defaultValue", ",", "$", "unsetValue", ")", ";", "}", "$", "_originalKey", "=", "$", "key", ";", "//\tSet the default value", "$", "_newValue", "=", "$", "defaultValue", ";", "//\tNow a deeper search", "$", "key", "=", "static", "::", "_cleanKey", "(", "$", "key", ")", ";", "//\tGet array value if it exists", "if", "(", "is_array", "(", "$", "options", ")", "||", "$", "options", "instanceof", "\\", "ArrayAccess", ")", "{", "//\tCheck for the original key too", "if", "(", "!", "isset", "(", "$", "options", "[", "$", "key", "]", ")", "&&", "isset", "(", "$", "options", "[", "$", "_originalKey", "]", ")", ")", "{", "$", "key", "=", "$", "_originalKey", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "$", "key", "]", ")", ")", "{", "$", "_newValue", "=", "$", "options", "[", "$", "key", "]", ";", "if", "(", "false", "!==", "$", "unsetValue", ")", "{", "unset", "(", "$", "options", "[", "$", "key", "]", ")", ";", "}", "return", "$", "emptyStringIsNull", "&&", "empty", "(", "$", "_newValue", ")", "?", "null", ":", "$", "_newValue", ";", "}", "}", "if", "(", "is_object", "(", "$", "options", ")", ")", "{", "if", "(", "!", "property_exists", "(", "$", "options", ",", "$", "key", ")", "&&", "property_exists", "(", "$", "options", ",", "$", "_originalKey", ")", ")", "{", "$", "key", "=", "$", "_originalKey", ";", "}", "if", "(", "isset", "(", "$", "options", "->", "{", "$", "key", "}", ")", ")", "{", "$", "_newValue", "=", "$", "options", "->", "{", "$", "key", "}", ";", "if", "(", "false", "!==", "$", "unsetValue", ")", "{", "unset", "(", "$", "options", "->", "{", "$", "key", "}", ")", ";", "}", "return", "$", "emptyStringIsNull", "&&", "empty", "(", "$", "_newValue", ")", "?", "null", ":", "$", "_newValue", ";", "}", "else", "if", "(", "method_exists", "(", "$", "options", ",", "'get'", ".", "$", "key", ")", ")", "{", "$", "_getter", "=", "'get'", ".", "Inflector", "::", "deneutralize", "(", "$", "key", ")", ";", "$", "_setter", "=", "'set'", ".", "Inflector", "::", "deneutralize", "(", "$", "key", ")", ";", "$", "_newValue", "=", "$", "options", "->", "{", "$", "_getter", "}", "(", ")", ";", "if", "(", "false", "!==", "$", "unsetValue", "&&", "method_exists", "(", "$", "options", ",", "$", "_setter", ")", ")", "{", "$", "options", "->", "{", "$", "_setter", "}", "(", "null", ")", ";", "}", "}", "}", "//\tReturn the default...", "return", "$", "emptyStringIsNull", "&&", "empty", "(", "$", "_newValue", ")", "?", "null", ":", "$", "_newValue", ";", "}" ]
Retrieves an option from the given array. $defaultValue is returned if $key is not found. Can optionally delete $key from $options. @param array|\ArrayAccess|object $options An array or object from which to get $key's value @param string $key The array index or property to retrieve from $options @param mixed $defaultValue The value to return if $key is not found @param boolean $unsetValue If true, the $key will be removed from $options after retrieval @param bool $emptyStringIsNull If true, empty() values will always return as NULL @return mixed
[ "Retrieves", "an", "option", "from", "the", "given", "array", "." ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Option.php#L101-L173
11,571
lucifurious/kisma
src/Kisma/Core/Utility/Option.php
Option.addTo
public static function addTo( &$source, $key, $subKey, $value = null ) { $_target = static::clean( static::get( $source, $key, array() ) ); static::set( $_target, $subKey, $value ); static::set( $source, $key, $_target ); return $_target; }
php
public static function addTo( &$source, $key, $subKey, $value = null ) { $_target = static::clean( static::get( $source, $key, array() ) ); static::set( $_target, $subKey, $value ); static::set( $source, $key, $_target ); return $_target; }
[ "public", "static", "function", "addTo", "(", "&", "$", "source", ",", "$", "key", ",", "$", "subKey", ",", "$", "value", "=", "null", ")", "{", "$", "_target", "=", "static", "::", "clean", "(", "static", "::", "get", "(", "$", "source", ",", "$", "key", ",", "array", "(", ")", ")", ")", ";", "static", "::", "set", "(", "$", "_target", ",", "$", "subKey", ",", "$", "value", ")", ";", "static", "::", "set", "(", "$", "source", ",", "$", "key", ",", "$", "_target", ")", ";", "return", "$", "_target", ";", "}" ]
Adds a value to a property array @param array $source @param string $key @param string $subKey @param mixed $value @return array The new array
[ "Adds", "a", "value", "to", "a", "property", "array" ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Option.php#L221-L228
11,572
lucifurious/kisma
src/Kisma/Core/Utility/Option.php
Option.removeFrom
public static function removeFrom( &$source, $key, $subKey ) { $_target = static::clean( static::get( $source, $key, array() ) ); $_result = static::remove( $_target, $subKey ); static::set( $source, $key, $_target ); return $_result; }
php
public static function removeFrom( &$source, $key, $subKey ) { $_target = static::clean( static::get( $source, $key, array() ) ); $_result = static::remove( $_target, $subKey ); static::set( $source, $key, $_target ); return $_result; }
[ "public", "static", "function", "removeFrom", "(", "&", "$", "source", ",", "$", "key", ",", "$", "subKey", ")", "{", "$", "_target", "=", "static", "::", "clean", "(", "static", "::", "get", "(", "$", "source", ",", "$", "key", ",", "array", "(", ")", ")", ")", ";", "$", "_result", "=", "static", "::", "remove", "(", "$", "_target", ",", "$", "subKey", ")", ";", "static", "::", "set", "(", "$", "source", ",", "$", "key", ",", "$", "_target", ")", ";", "return", "$", "_result", ";", "}" ]
Removes a value from a property array @param array $source @param string $key @param string $subKey @return mixed The original value of the removed key
[ "Removes", "a", "value", "from", "a", "property", "array" ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Option.php#L239-L246
11,573
lucifurious/kisma
src/Kisma/Core/Utility/Option.php
Option.set
public static function set( &$options = array(), $key, $value = null ) { if ( is_array( $key ) ) { return static::setMany( $options, $key ); } $_cleanKey = static::_cleanKey( $key ); if ( is_array( $options ) ) { // Check for the original key too if ( !array_key_exists( $key, $options ) && array_key_exists( $_cleanKey, $options ) ) { $key = $_cleanKey; } $options[$key] = $value; return true; } if ( is_object( $options ) ) { $_setter = 'set' . Inflector::deneutralize( $key ); // Prefer setter, if one... if ( method_exists( $options, $_setter ) ) { $options->{$_setter}( $value ); return true; } if ( property_exists( $options, $key ) ) { $options->{$key} = $value; return true; } if ( property_exists( $options, $_cleanKey ) ) { $options->{$_cleanKey} = $value; return true; } return false; } return false; }
php
public static function set( &$options = array(), $key, $value = null ) { if ( is_array( $key ) ) { return static::setMany( $options, $key ); } $_cleanKey = static::_cleanKey( $key ); if ( is_array( $options ) ) { // Check for the original key too if ( !array_key_exists( $key, $options ) && array_key_exists( $_cleanKey, $options ) ) { $key = $_cleanKey; } $options[$key] = $value; return true; } if ( is_object( $options ) ) { $_setter = 'set' . Inflector::deneutralize( $key ); // Prefer setter, if one... if ( method_exists( $options, $_setter ) ) { $options->{$_setter}( $value ); return true; } if ( property_exists( $options, $key ) ) { $options->{$key} = $value; return true; } if ( property_exists( $options, $_cleanKey ) ) { $options->{$_cleanKey} = $value; return true; } return false; } return false; }
[ "public", "static", "function", "set", "(", "&", "$", "options", "=", "array", "(", ")", ",", "$", "key", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "return", "static", "::", "setMany", "(", "$", "options", ",", "$", "key", ")", ";", "}", "$", "_cleanKey", "=", "static", "::", "_cleanKey", "(", "$", "key", ")", ";", "if", "(", "is_array", "(", "$", "options", ")", ")", "{", "//\tCheck for the original key too", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "options", ")", "&&", "array_key_exists", "(", "$", "_cleanKey", ",", "$", "options", ")", ")", "{", "$", "key", "=", "$", "_cleanKey", ";", "}", "$", "options", "[", "$", "key", "]", "=", "$", "value", ";", "return", "true", ";", "}", "if", "(", "is_object", "(", "$", "options", ")", ")", "{", "$", "_setter", "=", "'set'", ".", "Inflector", "::", "deneutralize", "(", "$", "key", ")", ";", "//\tPrefer setter, if one...", "if", "(", "method_exists", "(", "$", "options", ",", "$", "_setter", ")", ")", "{", "$", "options", "->", "{", "$", "_setter", "}", "(", "$", "value", ")", ";", "return", "true", ";", "}", "if", "(", "property_exists", "(", "$", "options", ",", "$", "key", ")", ")", "{", "$", "options", "->", "{", "$", "key", "}", "=", "$", "value", ";", "return", "true", ";", "}", "if", "(", "property_exists", "(", "$", "options", ",", "$", "_cleanKey", ")", ")", "{", "$", "options", "->", "{", "$", "_cleanKey", "}", "=", "$", "value", ";", "return", "true", ";", "}", "return", "false", ";", "}", "return", "false", ";", "}" ]
Sets an value in the given array at key. @param array|\ArrayAccess|object $options The array or object from which to set $key's $value @param string|array $key The array index or property to set @param mixed $value The value to set @return bool|bool[]
[ "Sets", "an", "value", "in", "the", "given", "array", "at", "key", "." ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Option.php#L273-L325
11,574
lucifurious/kisma
src/Kisma/Core/Utility/Option.php
Option.remove
public static function remove( &$options = array(), $key ) { $_originalValue = null; if ( static::contains( $options, $key ) ) { $_cleanedKey = static::_cleanKey( $key ); if ( is_array( $options ) ) { if ( !isset( $options[$key] ) && isset( $options[$_cleanedKey] ) ) { $key = $_cleanedKey; } if ( isset( $options[$key] ) ) { $_originalValue = $options[$key]; unset( $options[$key] ); } } else { if ( !isset( $options->{$key} ) && isset( $options->{$_cleanedKey} ) ) { $key = $_cleanedKey; } if ( isset( $options->{$key} ) ) { $_originalValue = $options->{$key}; } unset( $options->{$key} ); } } return $_originalValue; }
php
public static function remove( &$options = array(), $key ) { $_originalValue = null; if ( static::contains( $options, $key ) ) { $_cleanedKey = static::_cleanKey( $key ); if ( is_array( $options ) ) { if ( !isset( $options[$key] ) && isset( $options[$_cleanedKey] ) ) { $key = $_cleanedKey; } if ( isset( $options[$key] ) ) { $_originalValue = $options[$key]; unset( $options[$key] ); } } else { if ( !isset( $options->{$key} ) && isset( $options->{$_cleanedKey} ) ) { $key = $_cleanedKey; } if ( isset( $options->{$key} ) ) { $_originalValue = $options->{$key}; } unset( $options->{$key} ); } } return $_originalValue; }
[ "public", "static", "function", "remove", "(", "&", "$", "options", "=", "array", "(", ")", ",", "$", "key", ")", "{", "$", "_originalValue", "=", "null", ";", "if", "(", "static", "::", "contains", "(", "$", "options", ",", "$", "key", ")", ")", "{", "$", "_cleanedKey", "=", "static", "::", "_cleanKey", "(", "$", "key", ")", ";", "if", "(", "is_array", "(", "$", "options", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "$", "key", "]", ")", "&&", "isset", "(", "$", "options", "[", "$", "_cleanedKey", "]", ")", ")", "{", "$", "key", "=", "$", "_cleanedKey", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "$", "key", "]", ")", ")", "{", "$", "_originalValue", "=", "$", "options", "[", "$", "key", "]", ";", "unset", "(", "$", "options", "[", "$", "key", "]", ")", ";", "}", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "options", "->", "{", "$", "key", "}", ")", "&&", "isset", "(", "$", "options", "->", "{", "$", "_cleanedKey", "}", ")", ")", "{", "$", "key", "=", "$", "_cleanedKey", ";", "}", "if", "(", "isset", "(", "$", "options", "->", "{", "$", "key", "}", ")", ")", "{", "$", "_originalValue", "=", "$", "options", "->", "{", "$", "key", "}", ";", "}", "unset", "(", "$", "options", "->", "{", "$", "key", "}", ")", ";", "}", "}", "return", "$", "_originalValue", ";", "}" ]
Unsets an option in the given array @param array $options @param string $key @return mixed
[ "Unsets", "an", "option", "in", "the", "given", "array" ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Option.php#L335-L373
11,575
lucifurious/kisma
src/Kisma/Core/Utility/Option.php
Option.clean
public static function clean( $array = null, $callback = null ) { $_result = ( empty( $array ) ? array() : ( !is_array( $array ) ? array($array) : $array ) ); if ( null === $callback || !is_callable( $callback ) ) { return $_result; } $_response = array(); foreach ( $_result as $_item ) { $_response[] = call_user_func( $callback, $_item ); } return $_response; }
php
public static function clean( $array = null, $callback = null ) { $_result = ( empty( $array ) ? array() : ( !is_array( $array ) ? array($array) : $array ) ); if ( null === $callback || !is_callable( $callback ) ) { return $_result; } $_response = array(); foreach ( $_result as $_item ) { $_response[] = call_user_func( $callback, $_item ); } return $_response; }
[ "public", "static", "function", "clean", "(", "$", "array", "=", "null", ",", "$", "callback", "=", "null", ")", "{", "$", "_result", "=", "(", "empty", "(", "$", "array", ")", "?", "array", "(", ")", ":", "(", "!", "is_array", "(", "$", "array", ")", "?", "array", "(", "$", "array", ")", ":", "$", "array", ")", ")", ";", "if", "(", "null", "===", "$", "callback", "||", "!", "is_callable", "(", "$", "callback", ")", ")", "{", "return", "$", "_result", ";", "}", "$", "_response", "=", "array", "(", ")", ";", "foreach", "(", "$", "_result", "as", "$", "_item", ")", "{", "$", "_response", "[", "]", "=", "call_user_func", "(", "$", "callback", ",", "$", "_item", ")", ";", "}", "return", "$", "_response", ";", "}" ]
Ensures the argument passed in is actually an array with optional iteration callback @static @param array $array @param callable|\Closure $callback @return array
[ "Ensures", "the", "argument", "passed", "in", "is", "actually", "an", "array", "with", "optional", "iteration", "callback" ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Option.php#L385-L402
11,576
lucifurious/kisma
src/Kisma/Core/Utility/Option.php
Option.merge
public static function merge( $target ) { $_arrays = static::clean( func_get_args() ); $_target = static::clean( array_shift( $_arrays ) ); foreach ( $_arrays as $_array ) { $_target = array_merge( $_target, static::clean( $_array ) ); unset( $_array ); } unset( $_arrays ); return $_target; }
php
public static function merge( $target ) { $_arrays = static::clean( func_get_args() ); $_target = static::clean( array_shift( $_arrays ) ); foreach ( $_arrays as $_array ) { $_target = array_merge( $_target, static::clean( $_array ) ); unset( $_array ); } unset( $_arrays ); return $_target; }
[ "public", "static", "function", "merge", "(", "$", "target", ")", "{", "$", "_arrays", "=", "static", "::", "clean", "(", "func_get_args", "(", ")", ")", ";", "$", "_target", "=", "static", "::", "clean", "(", "array_shift", "(", "$", "_arrays", ")", ")", ";", "foreach", "(", "$", "_arrays", "as", "$", "_array", ")", "{", "$", "_target", "=", "array_merge", "(", "$", "_target", ",", "static", "::", "clean", "(", "$", "_array", ")", ")", ";", "unset", "(", "$", "_array", ")", ";", "}", "unset", "(", "$", "_arrays", ")", ";", "return", "$", "_target", ";", "}" ]
Merge one or more arrays but ensures each is an array. Basically an idiot-proof array_merge @param array $target The destination array @return array The resulting array @return array
[ "Merge", "one", "or", "more", "arrays", "but", "ensures", "each", "is", "an", "array", ".", "Basically", "an", "idiot", "-", "proof", "array_merge" ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Option.php#L431-L449
11,577
lucifurious/kisma
src/Kisma/Core/Utility/Option.php
Option.prefixKeys
public static function prefixKeys( $prefix, array $data = array() ) { foreach ( static::clean( $data ) as $_key => $_value ) { if ( is_numeric( $_key ) ) { continue; } if ( is_array( $_value ) ) { $_value = static::prefixKeys( $prefix, $_value ); } $data[$prefix . $_key] = $_value; unset( $data[$_key] ); } return $data; }
php
public static function prefixKeys( $prefix, array $data = array() ) { foreach ( static::clean( $data ) as $_key => $_value ) { if ( is_numeric( $_key ) ) { continue; } if ( is_array( $_value ) ) { $_value = static::prefixKeys( $prefix, $_value ); } $data[$prefix . $_key] = $_value; unset( $data[$_key] ); } return $data; }
[ "public", "static", "function", "prefixKeys", "(", "$", "prefix", ",", "array", "$", "data", "=", "array", "(", ")", ")", "{", "foreach", "(", "static", "::", "clean", "(", "$", "data", ")", "as", "$", "_key", "=>", "$", "_value", ")", "{", "if", "(", "is_numeric", "(", "$", "_key", ")", ")", "{", "continue", ";", "}", "if", "(", "is_array", "(", "$", "_value", ")", ")", "{", "$", "_value", "=", "static", "::", "prefixKeys", "(", "$", "prefix", ",", "$", "_value", ")", ";", "}", "$", "data", "[", "$", "prefix", ".", "$", "_key", "]", "=", "$", "_value", ";", "unset", "(", "$", "data", "[", "$", "_key", "]", ")", ";", "}", "return", "$", "data", ";", "}" ]
Spins through an array and prefixes the keys with a string @param string $prefix @param array $data @return mixed
[ "Spins", "through", "an", "array", "and", "prefixes", "the", "keys", "with", "a", "string" ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Option.php#L512-L531
11,578
lucifurious/kisma
src/Kisma/Core/Utility/Option.php
Option._cleanKey
protected static function _cleanKey( $key, $opposite = true ) { if ( !static::$_neutralizeKeys ) { $_cleaned = $key; } elseif ( $key == ( $_cleaned = Inflector::neutralize( $key ) ) ) { if ( $opposite ) { return Inflector::deneutralize( $key, true ); } } return $_cleaned; }
php
protected static function _cleanKey( $key, $opposite = true ) { if ( !static::$_neutralizeKeys ) { $_cleaned = $key; } elseif ( $key == ( $_cleaned = Inflector::neutralize( $key ) ) ) { if ( $opposite ) { return Inflector::deneutralize( $key, true ); } } return $_cleaned; }
[ "protected", "static", "function", "_cleanKey", "(", "$", "key", ",", "$", "opposite", "=", "true", ")", "{", "if", "(", "!", "static", "::", "$", "_neutralizeKeys", ")", "{", "$", "_cleaned", "=", "$", "key", ";", "}", "elseif", "(", "$", "key", "==", "(", "$", "_cleaned", "=", "Inflector", "::", "neutralize", "(", "$", "key", ")", ")", ")", "{", "if", "(", "$", "opposite", ")", "{", "return", "Inflector", "::", "deneutralize", "(", "$", "key", ",", "true", ")", ";", "}", "}", "return", "$", "_cleaned", ";", "}" ]
Converts key to a neutral format if not already... @param string $key @param bool $opposite If true, the key is switched back to it's neutral or non-neutral format @return string
[ "Converts", "key", "to", "a", "neutral", "format", "if", "not", "already", "..." ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Option.php#L573-L588
11,579
Hexmedia/symfony-fake-process
FakeProcessBuilder.php
FakeProcessBuilder.setInput
public function setInput($input) { $this->input = ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input); return $this; }
php
public function setInput($input) { $this->input = ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input); return $this; }
[ "public", "function", "setInput", "(", "$", "input", ")", "{", "$", "this", "->", "input", "=", "ProcessUtils", "::", "validateInput", "(", "sprintf", "(", "'%s::%s'", ",", "__CLASS__", ",", "__FUNCTION__", ")", ",", "$", "input", ")", ";", "return", "$", "this", ";", "}" ]
Sets the input of the process. @param mixed $input The input as a string @return FakeProcessBuilder @throws InvalidArgumentException In case the argument is invalid
[ "Sets", "the", "input", "of", "the", "process", "." ]
6f93863c5d2363555165488de5a44a4beff5337f
https://github.com/Hexmedia/symfony-fake-process/blob/6f93863c5d2363555165488de5a44a4beff5337f/FakeProcessBuilder.php#L178-L183
11,580
jivoo/core
src/Cli/Shell.php
Shell.dump
public function dump($value) { if (is_object($value)) { return get_class($value); } if (is_resource($value)) { return get_resource_type($value); } return var_export($value, true); }
php
public function dump($value) { if (is_object($value)) { return get_class($value); } if (is_resource($value)) { return get_resource_type($value); } return var_export($value, true); }
[ "public", "function", "dump", "(", "$", "value", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "return", "get_class", "(", "$", "value", ")", ";", "}", "if", "(", "is_resource", "(", "$", "value", ")", ")", "{", "return", "get_resource_type", "(", "$", "value", ")", ";", "}", "return", "var_export", "(", "$", "value", ",", "true", ")", ";", "}" ]
Create a string representation of any PHP value. @param mixed $value Any value. @return string String representation.
[ "Create", "a", "string", "representation", "of", "any", "PHP", "value", "." ]
4ef3445068f0ff9c0a6512cb741831a847013b76
https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Cli/Shell.php#L243-L252
11,581
phossa2/libs
src/Phossa2/Cache/Driver/DriverAbstract.php
DriverAbstract.isDeferred
protected function isDeferred(/*# string */ $key)/*# : array */ { $res = []; if (isset($this->defer[$key])) { $res['expire'] = $this->defer[$key]->getExpiration()->getTimestamp(); } return $res; }
php
protected function isDeferred(/*# string */ $key)/*# : array */ { $res = []; if (isset($this->defer[$key])) { $res['expire'] = $this->defer[$key]->getExpiration()->getTimestamp(); } return $res; }
[ "protected", "function", "isDeferred", "(", "/*# string */", "$", "key", ")", "/*# : array */", "{", "$", "res", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "defer", "[", "$", "key", "]", ")", ")", "{", "$", "res", "[", "'expire'", "]", "=", "$", "this", "->", "defer", "[", "$", "key", "]", "->", "getExpiration", "(", ")", "->", "getTimestamp", "(", ")", ";", "}", "return", "$", "res", ";", "}" ]
In deferred array ? @param string $key @return array @access protected
[ "In", "deferred", "array", "?" ]
921e485c8cc29067f279da2cdd06f47a9bddd115
https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Cache/Driver/DriverAbstract.php#L177-L184
11,582
Clastic/AliasBundle
EventListener/FormSubscriber.php
FormSubscriber.validate
public function validate(FormEvent $event) { /** @var Alias $alias */ $alias = $event->getData()->getNode()->alias; if ($alias instanceof ValueHolderInterface) { $alias = $alias->getWrappedValueHolderValue(); } $violations = $this->validator->validate($alias); if (!$violations) { return; } $mapper = new ViolationMapper(); /** @var ConstraintViolationInterface $violation */ foreach ($violations as $violation) { $mapper->mapViolation($violation, $event->getForm(), true); } }
php
public function validate(FormEvent $event) { /** @var Alias $alias */ $alias = $event->getData()->getNode()->alias; if ($alias instanceof ValueHolderInterface) { $alias = $alias->getWrappedValueHolderValue(); } $violations = $this->validator->validate($alias); if (!$violations) { return; } $mapper = new ViolationMapper(); /** @var ConstraintViolationInterface $violation */ foreach ($violations as $violation) { $mapper->mapViolation($violation, $event->getForm(), true); } }
[ "public", "function", "validate", "(", "FormEvent", "$", "event", ")", "{", "/** @var Alias $alias */", "$", "alias", "=", "$", "event", "->", "getData", "(", ")", "->", "getNode", "(", ")", "->", "alias", ";", "if", "(", "$", "alias", "instanceof", "ValueHolderInterface", ")", "{", "$", "alias", "=", "$", "alias", "->", "getWrappedValueHolderValue", "(", ")", ";", "}", "$", "violations", "=", "$", "this", "->", "validator", "->", "validate", "(", "$", "alias", ")", ";", "if", "(", "!", "$", "violations", ")", "{", "return", ";", "}", "$", "mapper", "=", "new", "ViolationMapper", "(", ")", ";", "/** @var ConstraintViolationInterface $violation */", "foreach", "(", "$", "violations", "as", "$", "violation", ")", "{", "$", "mapper", "->", "mapViolation", "(", "$", "violation", ",", "$", "event", "->", "getForm", "(", ")", ",", "true", ")", ";", "}", "}" ]
Validate if the Alias is valid and unique. @param FormEvent $event
[ "Validate", "if", "the", "Alias", "is", "valid", "and", "unique", "." ]
7f5099589561ed4988abab2dcccf5c58ea5edb66
https://github.com/Clastic/AliasBundle/blob/7f5099589561ed4988abab2dcccf5c58ea5edb66/EventListener/FormSubscriber.php#L55-L75
11,583
letrunghieu/taki
src/Traits/TakiRegistration.php
TakiRegistration.getActivate
public function getActivate(Request $request, $token) { $user = User::where('token', $token)->first(); if (!$user) { throw new NotFoundHttpException; } $user->is_activated = true; $user->token = null; $user->save(); if (method_exists($this, 'userActivated')) { $this->userRegistered($request, $token, $user); } return view($this->getUserActivatingView(), ['user' => $user, 'token' => $token]); }
php
public function getActivate(Request $request, $token) { $user = User::where('token', $token)->first(); if (!$user) { throw new NotFoundHttpException; } $user->is_activated = true; $user->token = null; $user->save(); if (method_exists($this, 'userActivated')) { $this->userRegistered($request, $token, $user); } return view($this->getUserActivatingView(), ['user' => $user, 'token' => $token]); }
[ "public", "function", "getActivate", "(", "Request", "$", "request", ",", "$", "token", ")", "{", "$", "user", "=", "User", "::", "where", "(", "'token'", ",", "$", "token", ")", "->", "first", "(", ")", ";", "if", "(", "!", "$", "user", ")", "{", "throw", "new", "NotFoundHttpException", ";", "}", "$", "user", "->", "is_activated", "=", "true", ";", "$", "user", "->", "token", "=", "null", ";", "$", "user", "->", "save", "(", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "'userActivated'", ")", ")", "{", "$", "this", "->", "userRegistered", "(", "$", "request", ",", "$", "token", ",", "$", "user", ")", ";", "}", "return", "view", "(", "$", "this", "->", "getUserActivatingView", "(", ")", ",", "[", "'user'", "=>", "$", "user", ",", "'token'", "=>", "$", "token", "]", ")", ";", "}" ]
Activate a user by a link @param $token @return \Illuminate\View\View @throws NotFoundHttpException
[ "Activate", "a", "user", "by", "a", "link" ]
c4af7345a4a9df6d83c84f04335da92b62debf17
https://github.com/letrunghieu/taki/blob/c4af7345a4a9df6d83c84f04335da92b62debf17/src/Traits/TakiRegistration.php#L64-L81
11,584
letrunghieu/taki
src/Traits/TakiRegistration.php
TakiRegistration.validateCreating
protected function validateCreating() { $rules = config('taki.validator.create', []); if (config('taki.username.required') && !array_get($rules, config('taki.field.username'))) { $rules[config('taki.field.username')] = config('taki.username.validator', 'required'); } return $rules; }
php
protected function validateCreating() { $rules = config('taki.validator.create', []); if (config('taki.username.required') && !array_get($rules, config('taki.field.username'))) { $rules[config('taki.field.username')] = config('taki.username.validator', 'required'); } return $rules; }
[ "protected", "function", "validateCreating", "(", ")", "{", "$", "rules", "=", "config", "(", "'taki.validator.create'", ",", "[", "]", ")", ";", "if", "(", "config", "(", "'taki.username.required'", ")", "&&", "!", "array_get", "(", "$", "rules", ",", "config", "(", "'taki.field.username'", ")", ")", ")", "{", "$", "rules", "[", "config", "(", "'taki.field.username'", ")", "]", "=", "config", "(", "'taki.username.validator'", ",", "'required'", ")", ";", "}", "return", "$", "rules", ";", "}" ]
get the validation rules when creating user @param array $data @return array
[ "get", "the", "validation", "rules", "when", "creating", "user" ]
c4af7345a4a9df6d83c84f04335da92b62debf17
https://github.com/letrunghieu/taki/blob/c4af7345a4a9df6d83c84f04335da92b62debf17/src/Traits/TakiRegistration.php#L104-L113
11,585
tjbp/tablelegs
src/lib/TableFilter.php
TableFilter.getUrl
public function getUrl($option) { if ($this->isActive($option)) { $params = $this->request->all(); unset($params[$this->getKey()]); return '?'.http_build_query($params); } return '?'.http_build_query([$this->key => $option] + $this->request->all()); }
php
public function getUrl($option) { if ($this->isActive($option)) { $params = $this->request->all(); unset($params[$this->getKey()]); return '?'.http_build_query($params); } return '?'.http_build_query([$this->key => $option] + $this->request->all()); }
[ "public", "function", "getUrl", "(", "$", "option", ")", "{", "if", "(", "$", "this", "->", "isActive", "(", "$", "option", ")", ")", "{", "$", "params", "=", "$", "this", "->", "request", "->", "all", "(", ")", ";", "unset", "(", "$", "params", "[", "$", "this", "->", "getKey", "(", ")", "]", ")", ";", "return", "'?'", ".", "http_build_query", "(", "$", "params", ")", ";", "}", "return", "'?'", ".", "http_build_query", "(", "[", "$", "this", "->", "key", "=>", "$", "option", "]", "+", "$", "this", "->", "request", "->", "all", "(", ")", ")", ";", "}" ]
Return the URL parameter string to enable this filter. @return string
[ "Return", "the", "URL", "parameter", "string", "to", "enable", "this", "filter", "." ]
89916f6662ab324a96c62672ed4bb9a6e9cb3360
https://github.com/tjbp/tablelegs/blob/89916f6662ab324a96c62672ed4bb9a6e9cb3360/src/lib/TableFilter.php#L95-L106
11,586
n0m4dz/laracasa
Zend/Gdata/Analytics.php
Zend_Gdata_Analytics.getAccountFeed
public function getAccountFeed($uri = self::ANALYTICS_ACCOUNT_FEED_URI) { if ($uri instanceof Query) { $uri = $uri->getQueryUrl(); } return parent::getFeed($uri, 'Zend_Gdata_Analytics_AccountFeed'); }
php
public function getAccountFeed($uri = self::ANALYTICS_ACCOUNT_FEED_URI) { if ($uri instanceof Query) { $uri = $uri->getQueryUrl(); } return parent::getFeed($uri, 'Zend_Gdata_Analytics_AccountFeed'); }
[ "public", "function", "getAccountFeed", "(", "$", "uri", "=", "self", "::", "ANALYTICS_ACCOUNT_FEED_URI", ")", "{", "if", "(", "$", "uri", "instanceof", "Query", ")", "{", "$", "uri", "=", "$", "uri", "->", "getQueryUrl", "(", ")", ";", "}", "return", "parent", "::", "getFeed", "(", "$", "uri", ",", "'Zend_Gdata_Analytics_AccountFeed'", ")", ";", "}" ]
Retrieve account feed object @param string|Zend_Uri_Uri $uri @return Zend_Gdata_Analytics_AccountFeed
[ "Retrieve", "account", "feed", "object" ]
6141f0c16c7d4453275e3b74be5041f336085c91
https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Analytics.php#L96-L102
11,587
n0m4dz/laracasa
Zend/Gdata/Analytics.php
Zend_Gdata_Analytics.getDataFeed
public function getDataFeed($uri = self::ANALYTICS_FEED_URI) { if ($uri instanceof Query) { $uri = $uri->getQueryUrl(); } return parent::getFeed($uri, 'Zend_Gdata_Analytics_DataFeed'); }
php
public function getDataFeed($uri = self::ANALYTICS_FEED_URI) { if ($uri instanceof Query) { $uri = $uri->getQueryUrl(); } return parent::getFeed($uri, 'Zend_Gdata_Analytics_DataFeed'); }
[ "public", "function", "getDataFeed", "(", "$", "uri", "=", "self", "::", "ANALYTICS_FEED_URI", ")", "{", "if", "(", "$", "uri", "instanceof", "Query", ")", "{", "$", "uri", "=", "$", "uri", "->", "getQueryUrl", "(", ")", ";", "}", "return", "parent", "::", "getFeed", "(", "$", "uri", ",", "'Zend_Gdata_Analytics_DataFeed'", ")", ";", "}" ]
Retrieve data feed object @param string|Zend_Uri_Uri $uri @return Zend_Gdata_Analytics_DataFeed
[ "Retrieve", "data", "feed", "object" ]
6141f0c16c7d4453275e3b74be5041f336085c91
https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Analytics.php#L110-L116
11,588
cherrylabs/arx-utils
src/Arx/Utils/Hook.php
Hook.get
public static function get($name, $default = null){ $dots = null; if ($pos = strpos($name, '.')) { $dots = substr($name, $pos + 1); $name = substr($name, 0, $pos); } if(isset($GLOBALS[ARX_HOOK][$name])){ if ($dots) { return Arr::get($GLOBALS[ARX_HOOK][$name], $dots, $default); } return $GLOBALS[ARX_HOOK][$name]; } if ($default) { return $default; } return false; }
php
public static function get($name, $default = null){ $dots = null; if ($pos = strpos($name, '.')) { $dots = substr($name, $pos + 1); $name = substr($name, 0, $pos); } if(isset($GLOBALS[ARX_HOOK][$name])){ if ($dots) { return Arr::get($GLOBALS[ARX_HOOK][$name], $dots, $default); } return $GLOBALS[ARX_HOOK][$name]; } if ($default) { return $default; } return false; }
[ "public", "static", "function", "get", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "$", "dots", "=", "null", ";", "if", "(", "$", "pos", "=", "strpos", "(", "$", "name", ",", "'.'", ")", ")", "{", "$", "dots", "=", "substr", "(", "$", "name", ",", "$", "pos", "+", "1", ")", ";", "$", "name", "=", "substr", "(", "$", "name", ",", "0", ",", "$", "pos", ")", ";", "}", "if", "(", "isset", "(", "$", "GLOBALS", "[", "ARX_HOOK", "]", "[", "$", "name", "]", ")", ")", "{", "if", "(", "$", "dots", ")", "{", "return", "Arr", "::", "get", "(", "$", "GLOBALS", "[", "ARX_HOOK", "]", "[", "$", "name", "]", ",", "$", "dots", ",", "$", "default", ")", ";", "}", "return", "$", "GLOBALS", "[", "ARX_HOOK", "]", "[", "$", "name", "]", ";", "}", "if", "(", "$", "default", ")", "{", "return", "$", "default", ";", "}", "return", "false", ";", "}" ]
Get registered hook @param $name @param array $param @return bool
[ "Get", "registered", "hook" ]
c3986ef44aee9457ee66d52f5833091ba3c03cee
https://github.com/cherrylabs/arx-utils/blob/c3986ef44aee9457ee66d52f5833091ba3c03cee/src/Arx/Utils/Hook.php#L240-L263
11,589
nonetallt/jinitialize-core
src/JinScript/JinScriptParser.php
JinScriptParser.parse
private function parse() { $handle = fopen($this->filepath, 'r'); if(! $handle) throw new \Exception("Can't read file $this->filepath"); $plugin = null; while(($line = fgets($handle)) !== false) { /* Skip comments and empty lines */ if(starts_with($line, '#') || trim($line) === '') continue; /* Find description setting */ else if(starts_with($line, 'description')) $this->parseDescription($line); /* Find help setting */ else if(starts_with($line, 'help')) $this->parseHelp($line); /* Capture commands */ else if(starts_with_whitespace($line)) $plugin->parseCommand($line); /* Start plugin capture */ else { $plugin = $this->parseCurrentPlugin($line); } } fclose($handle); /* Set state as parsed */ $this->isParsed = true; }
php
private function parse() { $handle = fopen($this->filepath, 'r'); if(! $handle) throw new \Exception("Can't read file $this->filepath"); $plugin = null; while(($line = fgets($handle)) !== false) { /* Skip comments and empty lines */ if(starts_with($line, '#') || trim($line) === '') continue; /* Find description setting */ else if(starts_with($line, 'description')) $this->parseDescription($line); /* Find help setting */ else if(starts_with($line, 'help')) $this->parseHelp($line); /* Capture commands */ else if(starts_with_whitespace($line)) $plugin->parseCommand($line); /* Start plugin capture */ else { $plugin = $this->parseCurrentPlugin($line); } } fclose($handle); /* Set state as parsed */ $this->isParsed = true; }
[ "private", "function", "parse", "(", ")", "{", "$", "handle", "=", "fopen", "(", "$", "this", "->", "filepath", ",", "'r'", ")", ";", "if", "(", "!", "$", "handle", ")", "throw", "new", "\\", "Exception", "(", "\"Can't read file $this->filepath\"", ")", ";", "$", "plugin", "=", "null", ";", "while", "(", "(", "$", "line", "=", "fgets", "(", "$", "handle", ")", ")", "!==", "false", ")", "{", "/* Skip comments and empty lines */", "if", "(", "starts_with", "(", "$", "line", ",", "'#'", ")", "||", "trim", "(", "$", "line", ")", "===", "''", ")", "continue", ";", "/* Find description setting */", "else", "if", "(", "starts_with", "(", "$", "line", ",", "'description'", ")", ")", "$", "this", "->", "parseDescription", "(", "$", "line", ")", ";", "/* Find help setting */", "else", "if", "(", "starts_with", "(", "$", "line", ",", "'help'", ")", ")", "$", "this", "->", "parseHelp", "(", "$", "line", ")", ";", "/* Capture commands */", "else", "if", "(", "starts_with_whitespace", "(", "$", "line", ")", ")", "$", "plugin", "->", "parseCommand", "(", "$", "line", ")", ";", "/* Start plugin capture */", "else", "{", "$", "plugin", "=", "$", "this", "->", "parseCurrentPlugin", "(", "$", "line", ")", ";", "}", "}", "fclose", "(", "$", "handle", ")", ";", "/* Set state as parsed */", "$", "this", "->", "isParsed", "=", "true", ";", "}" ]
Private since files should only be parsed when neccesary
[ "Private", "since", "files", "should", "only", "be", "parsed", "when", "neccesary" ]
284fbd72b7c1d6f5f8f265dfe2589c0d99b6a88f
https://github.com/nonetallt/jinitialize-core/blob/284fbd72b7c1d6f5f8f265dfe2589c0d99b6a88f/src/JinScript/JinScriptParser.php#L42-L73
11,590
Silvestra/Silvestra
src/Silvestra/Bundle/AdminBundle/Twig/Extension/AdminMenuExtension.php
AdminMenuExtension.render
public function render($template = null) { if (null === $template) { $template = 'SilvestraAdminBundle:Menu:vertical_admin_menu.html.twig'; } return $this->helper->render($template, $this->builder->build()); }
php
public function render($template = null) { if (null === $template) { $template = 'SilvestraAdminBundle:Menu:vertical_admin_menu.html.twig'; } return $this->helper->render($template, $this->builder->build()); }
[ "public", "function", "render", "(", "$", "template", "=", "null", ")", "{", "if", "(", "null", "===", "$", "template", ")", "{", "$", "template", "=", "'SilvestraAdminBundle:Menu:vertical_admin_menu.html.twig'", ";", "}", "return", "$", "this", "->", "helper", "->", "render", "(", "$", "template", ",", "$", "this", "->", "builder", "->", "build", "(", ")", ")", ";", "}" ]
Render admin menu. @param null|string $template @return string
[ "Render", "admin", "menu", "." ]
b7367601b01495ae3c492b42042f804dee13ab06
https://github.com/Silvestra/Silvestra/blob/b7367601b01495ae3c492b42042f804dee13ab06/src/Silvestra/Bundle/AdminBundle/Twig/Extension/AdminMenuExtension.php#L67-L74
11,591
bfitech/zapmin
src/AdminStoreInit.php
AdminStoreInit.init
public function init() { if ($this->initialized) return $this; $this->initialized = true; $this->check_tables(); return $this; }
php
public function init() { if ($this->initialized) return $this; $this->initialized = true; $this->check_tables(); return $this; }
[ "public", "function", "init", "(", ")", "{", "if", "(", "$", "this", "->", "initialized", ")", "return", "$", "this", ";", "$", "this", "->", "initialized", "=", "true", ";", "$", "this", "->", "check_tables", "(", ")", ";", "return", "$", "this", ";", "}" ]
Initialize properties, tables, etc.
[ "Initialize", "properties", "tables", "etc", "." ]
4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe
https://github.com/bfitech/zapmin/blob/4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe/src/AdminStoreInit.php#L106-L112
11,592
bfitech/zapmin
src/AdminStoreInit.php
AdminStoreInit.deinit
public function deinit() { if (!$this->initialized) return $this; $this->user_token = null; $this->user_data = null; $this->expiration = 3600 * 2; $this->byway_expiration = 3600 * 24 * 7; $this->initialized = false; return $this; }
php
public function deinit() { if (!$this->initialized) return $this; $this->user_token = null; $this->user_data = null; $this->expiration = 3600 * 2; $this->byway_expiration = 3600 * 24 * 7; $this->initialized = false; return $this; }
[ "public", "function", "deinit", "(", ")", "{", "if", "(", "!", "$", "this", "->", "initialized", ")", "return", "$", "this", ";", "$", "this", "->", "user_token", "=", "null", ";", "$", "this", "->", "user_data", "=", "null", ";", "$", "this", "->", "expiration", "=", "3600", "*", "2", ";", "$", "this", "->", "byway_expiration", "=", "3600", "*", "24", "*", "7", ";", "$", "this", "->", "initialized", "=", "false", ";", "return", "$", "this", ";", "}" ]
Restore properties to default.
[ "Restore", "properties", "to", "default", "." ]
4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe
https://github.com/bfitech/zapmin/blob/4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe/src/AdminStoreInit.php#L117-L130
11,593
bfitech/zapmin
src/AdminStoreInit.php
AdminStoreInit.store_check_expiration
protected function store_check_expiration($expiration=null) { if (!$expiration) return 3600 * 2; $expiration = (int)$expiration; if ($expiration < 600) $expiration = 600; return $expiration; }
php
protected function store_check_expiration($expiration=null) { if (!$expiration) return 3600 * 2; $expiration = (int)$expiration; if ($expiration < 600) $expiration = 600; return $expiration; }
[ "protected", "function", "store_check_expiration", "(", "$", "expiration", "=", "null", ")", "{", "if", "(", "!", "$", "expiration", ")", "return", "3600", "*", "2", ";", "$", "expiration", "=", "(", "int", ")", "$", "expiration", ";", "if", "(", "$", "expiration", "<", "600", ")", "$", "expiration", "=", "600", ";", "return", "$", "expiration", ";", "}" ]
Verify expiration. Do not allow session that's too short. That would annoy users. @param int $expiration Session expiration, in seconds. This can be used for standard or byway session.
[ "Verify", "expiration", "." ]
4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe
https://github.com/bfitech/zapmin/blob/4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe/src/AdminStoreInit.php#L140-L147
11,594
bfitech/zapmin
src/AdminStoreInit.php
AdminStoreInit.check_tables
private function check_tables() { $tab = new AdminStoreTables(); $tab::init($this); $force = $this->force_create_table; if ($tab::exists($force)) { if (!$force) $tab::upgrade(); $tab::deinit(); return; } $tab::install($this->expiration); $tab::deinit(); }
php
private function check_tables() { $tab = new AdminStoreTables(); $tab::init($this); $force = $this->force_create_table; if ($tab::exists($force)) { if (!$force) $tab::upgrade(); $tab::deinit(); return; } $tab::install($this->expiration); $tab::deinit(); }
[ "private", "function", "check_tables", "(", ")", "{", "$", "tab", "=", "new", "AdminStoreTables", "(", ")", ";", "$", "tab", "::", "init", "(", "$", "this", ")", ";", "$", "force", "=", "$", "this", "->", "force_create_table", ";", "if", "(", "$", "tab", "::", "exists", "(", "$", "force", ")", ")", "{", "if", "(", "!", "$", "force", ")", "$", "tab", "::", "upgrade", "(", ")", ";", "$", "tab", "::", "deinit", "(", ")", ";", "return", ";", "}", "$", "tab", "::", "install", "(", "$", "this", "->", "expiration", ")", ";", "$", "tab", "::", "deinit", "(", ")", ";", "}" ]
Check tables. Check table existance and upgradability. If $this->force_create_table is true, old tables will be dropped and old data discarded.
[ "Check", "tables", "." ]
4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe
https://github.com/bfitech/zapmin/blob/4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe/src/AdminStoreInit.php#L156-L168
11,595
bfitech/zapmin
src/AdminStoreInit.php
AdminStoreInit.store_match_password
protected function store_match_password($uname, $upass, $usalt) { $udata = $this->store->query( "SELECT uid, uname " . "FROM udata WHERE upass=? LIMIT 1", [self::hash_password($uname, $upass, $usalt)]); if (!$udata) return false; return $udata; }
php
protected function store_match_password($uname, $upass, $usalt) { $udata = $this->store->query( "SELECT uid, uname " . "FROM udata WHERE upass=? LIMIT 1", [self::hash_password($uname, $upass, $usalt)]); if (!$udata) return false; return $udata; }
[ "protected", "function", "store_match_password", "(", "$", "uname", ",", "$", "upass", ",", "$", "usalt", ")", "{", "$", "udata", "=", "$", "this", "->", "store", "->", "query", "(", "\"SELECT uid, uname \"", ".", "\"FROM udata WHERE upass=? LIMIT 1\"", ",", "[", "self", "::", "hash_password", "(", "$", "uname", ",", "$", "upass", ",", "$", "usalt", ")", "]", ")", ";", "if", "(", "!", "$", "udata", ")", "return", "false", ";", "return", "$", "udata", ";", "}" ]
Match password and return user data on success. @param string $uname Username. @param string $upass User plain text password. @param string $usalt User salt. @return array|bool False on failure, user data on success. User data elements are subset of those returned by AdminStore::adm_get_safe_user_data.
[ "Match", "password", "and", "return", "user", "data", "on", "success", "." ]
4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe
https://github.com/bfitech/zapmin/blob/4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe/src/AdminStoreInit.php#L197-L205
11,596
bfitech/zapmin
src/AdminStoreInit.php
AdminStoreInit.store_redis_cache_read
protected function store_redis_cache_read($token) { if (!$this->redis) return null; $key = sprintf('%s:%s', $this->token_name, $token); $data = $this->redis->get($key); if ($data === false) # key not fund return null; $data = @json_decode($data, true); if (!$data) # cached data is broken $data = ['uid' => -2]; $this->logger->debug(sprintf( "Zapmin: session read from cache: '%s' <- '%s'.", $token, json_encode($data))); return $data; }
php
protected function store_redis_cache_read($token) { if (!$this->redis) return null; $key = sprintf('%s:%s', $this->token_name, $token); $data = $this->redis->get($key); if ($data === false) # key not fund return null; $data = @json_decode($data, true); if (!$data) # cached data is broken $data = ['uid' => -2]; $this->logger->debug(sprintf( "Zapmin: session read from cache: '%s' <- '%s'.", $token, json_encode($data))); return $data; }
[ "protected", "function", "store_redis_cache_read", "(", "$", "token", ")", "{", "if", "(", "!", "$", "this", "->", "redis", ")", "return", "null", ";", "$", "key", "=", "sprintf", "(", "'%s:%s'", ",", "$", "this", "->", "token_name", ",", "$", "token", ")", ";", "$", "data", "=", "$", "this", "->", "redis", "->", "get", "(", "$", "key", ")", ";", "if", "(", "$", "data", "===", "false", ")", "# key not fund", "return", "null", ";", "$", "data", "=", "@", "json_decode", "(", "$", "data", ",", "true", ")", ";", "if", "(", "!", "$", "data", ")", "# cached data is broken", "$", "data", "=", "[", "'uid'", "=>", "-", "2", "]", ";", "$", "this", "->", "logger", "->", "debug", "(", "sprintf", "(", "\"Zapmin: session read from cache: '%s' <- '%s'.\"", ",", "$", "token", ",", "json_encode", "(", "$", "data", ")", ")", ")", ";", "return", "$", "data", ";", "}" ]
Read session data from cache. @param string $token Session token.
[ "Read", "session", "data", "from", "cache", "." ]
4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe
https://github.com/bfitech/zapmin/blob/4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe/src/AdminStoreInit.php#L212-L228
11,597
bfitech/zapmin
src/AdminStoreInit.php
AdminStoreInit.store_redis_cache_write
protected function store_redis_cache_write( $token, $data, $expire_at, $expire=null ) { if (!$this->redis) return; $key = sprintf('%s:%s', $this->token_name, $token); $this->redis->set($key, json_encode($data)); if ($expire === null) { $expire_at = str_replace(' ', 'T', $expire_at) . 'Z'; $expire_at = \DateTime::createFromFormat( \DateTime::ATOM, $expire_at)->format("U"); $expire = $expire_at; } $this->redis->expire($key, $expire); $this->logger->debug(sprintf( "Zapmin: session written to cache: '%s' <- '%s'.", $token, json_encode($data))); }
php
protected function store_redis_cache_write( $token, $data, $expire_at, $expire=null ) { if (!$this->redis) return; $key = sprintf('%s:%s', $this->token_name, $token); $this->redis->set($key, json_encode($data)); if ($expire === null) { $expire_at = str_replace(' ', 'T', $expire_at) . 'Z'; $expire_at = \DateTime::createFromFormat( \DateTime::ATOM, $expire_at)->format("U"); $expire = $expire_at; } $this->redis->expire($key, $expire); $this->logger->debug(sprintf( "Zapmin: session written to cache: '%s' <- '%s'.", $token, json_encode($data))); }
[ "protected", "function", "store_redis_cache_write", "(", "$", "token", ",", "$", "data", ",", "$", "expire_at", ",", "$", "expire", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "redis", ")", "return", ";", "$", "key", "=", "sprintf", "(", "'%s:%s'", ",", "$", "this", "->", "token_name", ",", "$", "token", ")", ";", "$", "this", "->", "redis", "->", "set", "(", "$", "key", ",", "json_encode", "(", "$", "data", ")", ")", ";", "if", "(", "$", "expire", "===", "null", ")", "{", "$", "expire_at", "=", "str_replace", "(", "' '", ",", "'T'", ",", "$", "expire_at", ")", ".", "'Z'", ";", "$", "expire_at", "=", "\\", "DateTime", "::", "createFromFormat", "(", "\\", "DateTime", "::", "ATOM", ",", "$", "expire_at", ")", "->", "format", "(", "\"U\"", ")", ";", "$", "expire", "=", "$", "expire_at", ";", "}", "$", "this", "->", "redis", "->", "expire", "(", "$", "key", ",", "$", "expire", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "sprintf", "(", "\"Zapmin: session written to cache: '%s' <- '%s'.\"", ",", "$", "token", ",", "json_encode", "(", "$", "data", ")", ")", ")", ";", "}" ]
Write session to cache. @param string $token Session token. @param array $data User data. @param string $expire_at Redis expireat parameter, in UTC datetime. @param int $expire Redis expire parameter, in seconds. If this is set, $expire_at is ignored.
[ "Write", "session", "to", "cache", "." ]
4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe
https://github.com/bfitech/zapmin/blob/4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe/src/AdminStoreInit.php#L240-L260
11,598
bfitech/zapmin
src/AdminStoreInit.php
AdminStoreInit.store_redis_cache_del
protected function store_redis_cache_del($token) { if (!$this->redis) return; $key = sprintf('%s:%s', $this->token_name, $token); $this->redis->del($key); $this->logger->debug(sprintf( "Zapmin: session removed from cache: '%s'.", $token)); }
php
protected function store_redis_cache_del($token) { if (!$this->redis) return; $key = sprintf('%s:%s', $this->token_name, $token); $this->redis->del($key); $this->logger->debug(sprintf( "Zapmin: session removed from cache: '%s'.", $token)); }
[ "protected", "function", "store_redis_cache_del", "(", "$", "token", ")", "{", "if", "(", "!", "$", "this", "->", "redis", ")", "return", ";", "$", "key", "=", "sprintf", "(", "'%s:%s'", ",", "$", "this", "->", "token_name", ",", "$", "token", ")", ";", "$", "this", "->", "redis", "->", "del", "(", "$", "key", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "sprintf", "(", "\"Zapmin: session removed from cache: '%s'.\"", ",", "$", "token", ")", ")", ";", "}" ]
Remove session cache. @param string $token Session token.
[ "Remove", "session", "cache", "." ]
4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe
https://github.com/bfitech/zapmin/blob/4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe/src/AdminStoreInit.php#L267-L274
11,599
bfitech/zapmin
src/AdminStoreInit.php
AdminStoreInit.store_get_user_status
protected function store_get_user_status() { $this->init(); if ($this->user_token === null) return null; if ($this->user_data !== null) return $this->user_data; $token = $this->user_token; # cache validation $cached = $this->store_redis_cache_read($token); if ($cached !== null) { if ($cached['uid'] == -1) # cached invalid session return null; # cached valid session return $this->user_data = $cached; } $expire = $this->store->stmt_fragment('datetime'); $session = $this->store->query( sprintf( "SELECT * FROM v_usess " . "WHERE token=? AND expire>%s " . "LIMIT 1", $expire ), [$token]); if (!$session) { # session not found or expired $this->store_reset_status(); # cache invalid session for 10 minutes $this->store_redis_cache_write($token, ['uid' => -1], null, 600); return $this->user_data; } if (!$this->redis) return $this->user_data = $session; $this->store_redis_cache_write($token, $session, $session['expire']); return $this->user_data = $session; }
php
protected function store_get_user_status() { $this->init(); if ($this->user_token === null) return null; if ($this->user_data !== null) return $this->user_data; $token = $this->user_token; # cache validation $cached = $this->store_redis_cache_read($token); if ($cached !== null) { if ($cached['uid'] == -1) # cached invalid session return null; # cached valid session return $this->user_data = $cached; } $expire = $this->store->stmt_fragment('datetime'); $session = $this->store->query( sprintf( "SELECT * FROM v_usess " . "WHERE token=? AND expire>%s " . "LIMIT 1", $expire ), [$token]); if (!$session) { # session not found or expired $this->store_reset_status(); # cache invalid session for 10 minutes $this->store_redis_cache_write($token, ['uid' => -1], null, 600); return $this->user_data; } if (!$this->redis) return $this->user_data = $session; $this->store_redis_cache_write($token, $session, $session['expire']); return $this->user_data = $session; }
[ "protected", "function", "store_get_user_status", "(", ")", "{", "$", "this", "->", "init", "(", ")", ";", "if", "(", "$", "this", "->", "user_token", "===", "null", ")", "return", "null", ";", "if", "(", "$", "this", "->", "user_data", "!==", "null", ")", "return", "$", "this", "->", "user_data", ";", "$", "token", "=", "$", "this", "->", "user_token", ";", "# cache validation", "$", "cached", "=", "$", "this", "->", "store_redis_cache_read", "(", "$", "token", ")", ";", "if", "(", "$", "cached", "!==", "null", ")", "{", "if", "(", "$", "cached", "[", "'uid'", "]", "==", "-", "1", ")", "# cached invalid session", "return", "null", ";", "# cached valid session", "return", "$", "this", "->", "user_data", "=", "$", "cached", ";", "}", "$", "expire", "=", "$", "this", "->", "store", "->", "stmt_fragment", "(", "'datetime'", ")", ";", "$", "session", "=", "$", "this", "->", "store", "->", "query", "(", "sprintf", "(", "\"SELECT * FROM v_usess \"", ".", "\"WHERE token=? AND expire>%s \"", ".", "\"LIMIT 1\"", ",", "$", "expire", ")", ",", "[", "$", "token", "]", ")", ";", "if", "(", "!", "$", "session", ")", "{", "# session not found or expired", "$", "this", "->", "store_reset_status", "(", ")", ";", "# cache invalid session for 10 minutes", "$", "this", "->", "store_redis_cache_write", "(", "$", "token", ",", "[", "'uid'", "=>", "-", "1", "]", ",", "null", ",", "600", ")", ";", "return", "$", "this", "->", "user_data", ";", "}", "if", "(", "!", "$", "this", "->", "redis", ")", "return", "$", "this", "->", "user_data", "=", "$", "session", ";", "$", "this", "->", "store_redis_cache_write", "(", "$", "token", ",", "$", "session", ",", "$", "session", "[", "'expire'", "]", ")", ";", "return", "$", "this", "->", "user_data", "=", "$", "session", ";", "}" ]
Populate session data.
[ "Populate", "session", "data", "." ]
4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe
https://github.com/bfitech/zapmin/blob/4aebbe0e727328a9632f80b2e6ba4aef6a2fabfe/src/AdminStoreInit.php#L279-L322