repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
dailymotion/dailymotion-sdk-php
Dailymotion.php
Dailymotion.getCurrentUrl
protected function getCurrentUrl() { $filters = array( 'HTTPS' => FILTER_VALIDATE_BOOLEAN, 'HTTP_SSL_HTTPS' => FILTER_VALIDATE_BOOLEAN, 'HTTP_X_FORWARDED_PROTO' => FILTER_SANITIZE_STRING, 'HTTP_HOST' => FILTER_SANITIZE_STRING, 'REQUEST_URI' => FILTER_SANITIZE_STRING, ); // FastCGI seems to cause strange side-effects with unexpected NULL values when using INPUT_SERVER and // INPUT_ENV with the filter_input() and filter_input_array() functions, so we're using a workaround there. // See: http://fr2.php.net/manual/en/function.filter-input.php#77307 if (PHP_SAPI === 'cgi-fcgi') { $values = $filters; array_walk($values, function (&$value, $key) { $value = isset($_SERVER[$key]) ? $_SERVER[$key] : null; }); $values = filter_var_array($values, $filters); } else { $values = filter_input_array(INPUT_SERVER, $filters); } $secure = ($values['HTTPS'] || $values['HTTP_SSL_HTTPS'] || (strtolower($values['HTTP_X_FORWARDED_PROTO']) === 'https')); $scheme = $secure ? 'https://' : 'http://'; $currentUrl = $scheme . $values['HTTP_HOST'] . $values['REQUEST_URI']; $parts = parse_url($currentUrl); // Remove OAuth callback params $query = null; if (!empty($parts['query'])) { $parameters = array(); parse_str($parts['query'], $parameters); foreach(self::$DROP_QUERY_PARAMS as $name) { unset($parameters[$name]); } if (count($parameters) > 0) { $query = '?' . http_build_query($parameters, null, '&'); } } // Use port if non default $port = (!empty($parts['port']) && (($secure) ? ($parts['port'] !== 80) : ($parts['port'] !== 443))) ? ":{$parts['port']}" : null; // Rebuild return $scheme . $parts['host'] . $port . $parts['path'] . $query; }
php
protected function getCurrentUrl() { $filters = array( 'HTTPS' => FILTER_VALIDATE_BOOLEAN, 'HTTP_SSL_HTTPS' => FILTER_VALIDATE_BOOLEAN, 'HTTP_X_FORWARDED_PROTO' => FILTER_SANITIZE_STRING, 'HTTP_HOST' => FILTER_SANITIZE_STRING, 'REQUEST_URI' => FILTER_SANITIZE_STRING, ); // FastCGI seems to cause strange side-effects with unexpected NULL values when using INPUT_SERVER and // INPUT_ENV with the filter_input() and filter_input_array() functions, so we're using a workaround there. // See: http://fr2.php.net/manual/en/function.filter-input.php#77307 if (PHP_SAPI === 'cgi-fcgi') { $values = $filters; array_walk($values, function (&$value, $key) { $value = isset($_SERVER[$key]) ? $_SERVER[$key] : null; }); $values = filter_var_array($values, $filters); } else { $values = filter_input_array(INPUT_SERVER, $filters); } $secure = ($values['HTTPS'] || $values['HTTP_SSL_HTTPS'] || (strtolower($values['HTTP_X_FORWARDED_PROTO']) === 'https')); $scheme = $secure ? 'https://' : 'http://'; $currentUrl = $scheme . $values['HTTP_HOST'] . $values['REQUEST_URI']; $parts = parse_url($currentUrl); // Remove OAuth callback params $query = null; if (!empty($parts['query'])) { $parameters = array(); parse_str($parts['query'], $parameters); foreach(self::$DROP_QUERY_PARAMS as $name) { unset($parameters[$name]); } if (count($parameters) > 0) { $query = '?' . http_build_query($parameters, null, '&'); } } // Use port if non default $port = (!empty($parts['port']) && (($secure) ? ($parts['port'] !== 80) : ($parts['port'] !== 443))) ? ":{$parts['port']}" : null; // Rebuild return $scheme . $parts['host'] . $port . $parts['path'] . $query; }
[ "protected", "function", "getCurrentUrl", "(", ")", "{", "$", "filters", "=", "array", "(", "'HTTPS'", "=>", "FILTER_VALIDATE_BOOLEAN", ",", "'HTTP_SSL_HTTPS'", "=>", "FILTER_VALIDATE_BOOLEAN", ",", "'HTTP_X_FORWARDED_PROTO'", "=>", "FILTER_SANITIZE_STRING", ",", "'HTTP...
Returns the current URL, stripping if of known OAuth parameters that should not persist. @return string Current URL.
[ "Returns", "the", "current", "URL", "stripping", "if", "of", "known", "OAuth", "parameters", "that", "should", "not", "persist", "." ]
0f558978785f9a6ab9e59c393041d4896550973b
https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L901-L952
train
dailymotion/dailymotion-sdk-php
Dailymotion.php
Dailymotion.debugRequest
protected function debugRequest($url, $payload, array $headers) { if ($this->debug) { // debug for xterm-compliant cli if (php_sapi_name() === 'cli') { echo PHP_EOL; echo "\e[1;33m>>>\e[0;33m [{$url}] \e[1;33m>>>\e[00m" . PHP_EOL; foreach ($headers as $value) { $matches = array(); preg_match('#^(?P<key>[^:\s]+)\s*:\s*(?P<value>.*)$#S', $value, $matches); echo "\e[1;34m{$matches['key']}: \e[0;34m{$matches['value']}\e[00m" . PHP_EOL; } echo PHP_EOL; echo (is_array($payload)) ? json_encode($payload, JSON_PRETTY_PRINT) : ((is_null($json = json_decode($payload))) ? $payload : json_encode($json, JSON_PRETTY_PRINT) ); echo PHP_EOL; } // debug for the rest else { echo ">>> [{$url}] >>>" . PHP_EOL; $message = print_r(is_null($json = json_decode($payload)) ? $payload : $json, true); echo $message . (strpos($message, PHP_EOL) ? null : PHP_EOL); } } }
php
protected function debugRequest($url, $payload, array $headers) { if ($this->debug) { // debug for xterm-compliant cli if (php_sapi_name() === 'cli') { echo PHP_EOL; echo "\e[1;33m>>>\e[0;33m [{$url}] \e[1;33m>>>\e[00m" . PHP_EOL; foreach ($headers as $value) { $matches = array(); preg_match('#^(?P<key>[^:\s]+)\s*:\s*(?P<value>.*)$#S', $value, $matches); echo "\e[1;34m{$matches['key']}: \e[0;34m{$matches['value']}\e[00m" . PHP_EOL; } echo PHP_EOL; echo (is_array($payload)) ? json_encode($payload, JSON_PRETTY_PRINT) : ((is_null($json = json_decode($payload))) ? $payload : json_encode($json, JSON_PRETTY_PRINT) ); echo PHP_EOL; } // debug for the rest else { echo ">>> [{$url}] >>>" . PHP_EOL; $message = print_r(is_null($json = json_decode($payload)) ? $payload : $json, true); echo $message . (strpos($message, PHP_EOL) ? null : PHP_EOL); } } }
[ "protected", "function", "debugRequest", "(", "$", "url", ",", "$", "payload", ",", "array", "$", "headers", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "{", "// debug for xterm-compliant cli", "if", "(", "php_sapi_name", "(", ")", "===", "'cli'"...
Debug an HTTP request on the current output. @param string $url URL of the request. @param mixed $payload Payload sent with the request. @param array $headers Headers sent with the request.
[ "Debug", "an", "HTTP", "request", "on", "the", "current", "output", "." ]
0f558978785f9a6ab9e59c393041d4896550973b
https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L961-L995
train
dailymotion/dailymotion-sdk-php
Dailymotion.php
Dailymotion.debugResponse
protected function debugResponse($url, $payload, array $headers) { if ($this->debug) { // debug for xterm-compliant cli if (php_sapi_name() === 'cli') { echo PHP_EOL; echo "\e[1;33m<<<\e[0;33m [{$url}] \e[1;33m<<<\e[00m" . PHP_EOL; foreach ($headers as $key => $value) { echo "\e[1;34m{$key}: \e[0;34m{$value}\e[00m" . PHP_EOL; } echo PHP_EOL; echo ($json = json_decode($payload, true)) == NULL ? $payload : json_encode($json, JSON_PRETTY_PRINT); echo PHP_EOL; } // debug for the rest else { echo "<<< [{$url}] <<<" . PHP_EOL; print_r(($json = json_decode($payload)) == NULL ? $payload : $json); echo PHP_EOL; } } }
php
protected function debugResponse($url, $payload, array $headers) { if ($this->debug) { // debug for xterm-compliant cli if (php_sapi_name() === 'cli') { echo PHP_EOL; echo "\e[1;33m<<<\e[0;33m [{$url}] \e[1;33m<<<\e[00m" . PHP_EOL; foreach ($headers as $key => $value) { echo "\e[1;34m{$key}: \e[0;34m{$value}\e[00m" . PHP_EOL; } echo PHP_EOL; echo ($json = json_decode($payload, true)) == NULL ? $payload : json_encode($json, JSON_PRETTY_PRINT); echo PHP_EOL; } // debug for the rest else { echo "<<< [{$url}] <<<" . PHP_EOL; print_r(($json = json_decode($payload)) == NULL ? $payload : $json); echo PHP_EOL; } } }
[ "protected", "function", "debugResponse", "(", "$", "url", ",", "$", "payload", ",", "array", "$", "headers", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "{", "// debug for xterm-compliant cli", "if", "(", "php_sapi_name", "(", ")", "===", "'cli'...
Debug an HTTP response on the current output. @param string $url URL of the request. @param mixed $payload Payload sent with the request. @param array $headers Headers sent with the request.
[ "Debug", "an", "HTTP", "response", "on", "the", "current", "output", "." ]
0f558978785f9a6ab9e59c393041d4896550973b
https://github.com/dailymotion/dailymotion-sdk-php/blob/0f558978785f9a6ab9e59c393041d4896550973b/Dailymotion.php#L1004-L1029
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.setOptions
public function setOptions($options) { if ($this->step !== null) { throw new \RuntimeException('Cannot change encoding options during encoding'); } $this->options = (int) $options; return $this; }
php
public function setOptions($options) { if ($this->step !== null) { throw new \RuntimeException('Cannot change encoding options during encoding'); } $this->options = (int) $options; return $this; }
[ "public", "function", "setOptions", "(", "$", "options", ")", "{", "if", "(", "$", "this", "->", "step", "!==", "null", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot change encoding options during encoding'", ")", ";", "}", "$", "this", "...
Sets the JSON encoding options. @param int $options The JSON encoding options that are used by json_encode @return $this Returns self for call chaining @throws \RuntimeException If changing encoding options during encoding operation
[ "Sets", "the", "JSON", "encoding", "options", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L68-L76
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.setIndent
public function setIndent($indent) { if ($this->step !== null) { throw new \RuntimeException('Cannot change indent during encoding'); } $this->indent = is_int($indent) ? str_repeat(' ', $indent) : (string) $indent; return $this; }
php
public function setIndent($indent) { if ($this->step !== null) { throw new \RuntimeException('Cannot change indent during encoding'); } $this->indent = is_int($indent) ? str_repeat(' ', $indent) : (string) $indent; return $this; }
[ "public", "function", "setIndent", "(", "$", "indent", ")", "{", "if", "(", "$", "this", "->", "step", "!==", "null", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Cannot change indent during encoding'", ")", ";", "}", "$", "this", "->", "inde...
Sets the indent for the JSON output. @param string|int $indent A string to use as indent or the number of spaces @return $this Returns self for call chaining @throws \RuntimeException If changing indent during encoding operation
[ "Sets", "the", "indent", "for", "the", "JSON", "output", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L84-L92
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.rewind
public function rewind() { if ($this->step === 0) { return; } $this->stack = []; $this->stackType = []; $this->valueStack = []; $this->errors = []; $this->newLine = false; $this->first = true; $this->line = 1; $this->column = 1; $this->step = 0; $this->processValue($this->initialValue); }
php
public function rewind() { if ($this->step === 0) { return; } $this->stack = []; $this->stackType = []; $this->valueStack = []; $this->errors = []; $this->newLine = false; $this->first = true; $this->line = 1; $this->column = 1; $this->step = 0; $this->processValue($this->initialValue); }
[ "public", "function", "rewind", "(", ")", "{", "if", "(", "$", "this", "->", "step", "===", "0", ")", "{", "return", ";", "}", "$", "this", "->", "stack", "=", "[", "]", ";", "$", "this", "->", "stackType", "=", "[", "]", ";", "$", "this", "-...
Returns the JSON encoding to the beginning.
[ "Returns", "the", "JSON", "encoding", "to", "the", "beginning", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L153-L170
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.next
public function next() { $this->initialize(); if (!empty($this->stack)) { $this->step++; $iterator = end($this->stack); if ($iterator->valid()) { $this->processStack($iterator, end($this->stackType)); $iterator->next(); } else { $this->popStack(); } } else { $this->step = null; } }
php
public function next() { $this->initialize(); if (!empty($this->stack)) { $this->step++; $iterator = end($this->stack); if ($iterator->valid()) { $this->processStack($iterator, end($this->stackType)); $iterator->next(); } else { $this->popStack(); } } else { $this->step = null; } }
[ "public", "function", "next", "(", ")", "{", "$", "this", "->", "initialize", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "stack", ")", ")", "{", "$", "this", "->", "step", "++", ";", "$", "iterator", "=", "end", "(", "$", ...
Iterates the next token or tokens to the output stream.
[ "Iterates", "the", "next", "token", "or", "tokens", "to", "the", "output", "stream", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L175-L192
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.processStack
private function processStack(\Iterator $iterator, $isObject) { if ($isObject) { if (!$this->processKey($iterator->key())) { return; } } elseif (!$this->first) { $this->outputLine(',', JsonToken::T_COMMA); } $this->first = false; $this->processValue($iterator->current()); }
php
private function processStack(\Iterator $iterator, $isObject) { if ($isObject) { if (!$this->processKey($iterator->key())) { return; } } elseif (!$this->first) { $this->outputLine(',', JsonToken::T_COMMA); } $this->first = false; $this->processValue($iterator->current()); }
[ "private", "function", "processStack", "(", "\\", "Iterator", "$", "iterator", ",", "$", "isObject", ")", "{", "if", "(", "$", "isObject", ")", "{", "if", "(", "!", "$", "this", "->", "processKey", "(", "$", "iterator", "->", "key", "(", ")", ")", ...
Handles the next value from the iterator to be encoded as JSON. @param \Iterator $iterator The iterator used to generate the next value @param bool $isObject True if the iterator is being handled as an object, false if not
[ "Handles", "the", "next", "value", "from", "the", "iterator", "to", "be", "encoded", "as", "JSON", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L199-L211
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.processKey
private function processKey($key) { if (!is_int($key) && !is_string($key)) { $this->addError('Only string or integer keys are supported'); return false; } if (!$this->first) { $this->outputLine(',', JsonToken::T_COMMA); } $this->outputJson((string) $key, JsonToken::T_NAME); $this->output(':', JsonToken::T_COLON); if ($this->options & JSON_PRETTY_PRINT) { $this->output(' ', JsonToken::T_WHITESPACE); } return true; }
php
private function processKey($key) { if (!is_int($key) && !is_string($key)) { $this->addError('Only string or integer keys are supported'); return false; } if (!$this->first) { $this->outputLine(',', JsonToken::T_COMMA); } $this->outputJson((string) $key, JsonToken::T_NAME); $this->output(':', JsonToken::T_COLON); if ($this->options & JSON_PRETTY_PRINT) { $this->output(' ', JsonToken::T_WHITESPACE); } return true; }
[ "private", "function", "processKey", "(", "$", "key", ")", "{", "if", "(", "!", "is_int", "(", "$", "key", ")", "&&", "!", "is_string", "(", "$", "key", ")", ")", "{", "$", "this", "->", "addError", "(", "'Only string or integer keys are supported'", ")"...
Handles the given value key into JSON. @param mixed $key The key to process @return bool True if the key is valid, false if not
[ "Handles", "the", "given", "value", "key", "into", "JSON", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L218-L237
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.processValue
private function processValue($value) { $this->valueStack[] = $value; $value = $this->resolveValue($value); if (is_array($value) || is_object($value)) { $this->pushStack($value); } else { $this->outputJson($value, JsonToken::T_VALUE); array_pop($this->valueStack); } }
php
private function processValue($value) { $this->valueStack[] = $value; $value = $this->resolveValue($value); if (is_array($value) || is_object($value)) { $this->pushStack($value); } else { $this->outputJson($value, JsonToken::T_VALUE); array_pop($this->valueStack); } }
[ "private", "function", "processValue", "(", "$", "value", ")", "{", "$", "this", "->", "valueStack", "[", "]", "=", "$", "value", ";", "$", "value", "=", "$", "this", "->", "resolveValue", "(", "$", "value", ")", ";", "if", "(", "is_array", "(", "$...
Handles the given JSON value appropriately depending on it's type. @param mixed $value The value that should be encoded as JSON
[ "Handles", "the", "given", "JSON", "value", "appropriately", "depending", "on", "it", "s", "type", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L243-L254
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.resolveValue
protected function resolveValue($value) { do { if ($value instanceof \JsonSerializable) { $value = $value->jsonSerialize(); } elseif ($value instanceof \Closure) { $value = $value(); } else { break; } } while (true); return $value; }
php
protected function resolveValue($value) { do { if ($value instanceof \JsonSerializable) { $value = $value->jsonSerialize(); } elseif ($value instanceof \Closure) { $value = $value(); } else { break; } } while (true); return $value; }
[ "protected", "function", "resolveValue", "(", "$", "value", ")", "{", "do", "{", "if", "(", "$", "value", "instanceof", "\\", "JsonSerializable", ")", "{", "$", "value", "=", "$", "value", "->", "jsonSerialize", "(", ")", ";", "}", "elseif", "(", "$", ...
Resolves the actual value of any given value that is about to be processed. @param mixed $value The value to resolve @return mixed The resolved value
[ "Resolves", "the", "actual", "value", "of", "any", "given", "value", "that", "is", "about", "to", "be", "processed", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L261-L274
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.addError
private function addError($message) { $errorMessage = sprintf('Line %d, column %d: %s', $this->line, $this->column, $message); $this->errors[] = $errorMessage; if ($this->options & JSON_PARTIAL_OUTPUT_ON_ERROR) { return; } $this->stack = []; $this->step = null; throw new EncodingException($errorMessage); }
php
private function addError($message) { $errorMessage = sprintf('Line %d, column %d: %s', $this->line, $this->column, $message); $this->errors[] = $errorMessage; if ($this->options & JSON_PARTIAL_OUTPUT_ON_ERROR) { return; } $this->stack = []; $this->step = null; throw new EncodingException($errorMessage); }
[ "private", "function", "addError", "(", "$", "message", ")", "{", "$", "errorMessage", "=", "sprintf", "(", "'Line %d, column %d: %s'", ",", "$", "this", "->", "line", ",", "$", "this", "->", "column", ",", "$", "message", ")", ";", "$", "this", "->", ...
Adds an JSON encoding error to the list of errors. @param string $message The error message to add @throws EncodingException If the encoding should not continue due to the error
[ "Adds", "an", "JSON", "encoding", "error", "to", "the", "list", "of", "errors", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L281-L294
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.pushStack
private function pushStack($iterable) { $iterator = $this->getIterator($iterable); $isObject = $this->isObject($iterable, $iterator); if ($isObject) { $this->outputLine('{', JsonToken::T_LEFT_BRACE); } else { $this->outputLine('[', JsonToken::T_LEFT_BRACKET); } $this->first = true; $this->stack[] = $iterator; $this->stackType[] = $isObject; }
php
private function pushStack($iterable) { $iterator = $this->getIterator($iterable); $isObject = $this->isObject($iterable, $iterator); if ($isObject) { $this->outputLine('{', JsonToken::T_LEFT_BRACE); } else { $this->outputLine('[', JsonToken::T_LEFT_BRACKET); } $this->first = true; $this->stack[] = $iterator; $this->stackType[] = $isObject; }
[ "private", "function", "pushStack", "(", "$", "iterable", ")", "{", "$", "iterator", "=", "$", "this", "->", "getIterator", "(", "$", "iterable", ")", ";", "$", "isObject", "=", "$", "this", "->", "isObject", "(", "$", "iterable", ",", "$", "iterator",...
Pushes the given iterable to the value stack. @param object|array $iterable The iterable value to push to the stack
[ "Pushes", "the", "given", "iterable", "to", "the", "value", "stack", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L300-L314
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.isObject
private function isObject($iterable, \Iterator $iterator) { if ($this->options & JSON_FORCE_OBJECT) { return true; } if ($iterable instanceof \Traversable) { return $iterator->valid() && $iterator->key() !== 0; } return is_object($iterable) || $this->isAssociative($iterable); }
php
private function isObject($iterable, \Iterator $iterator) { if ($this->options & JSON_FORCE_OBJECT) { return true; } if ($iterable instanceof \Traversable) { return $iterator->valid() && $iterator->key() !== 0; } return is_object($iterable) || $this->isAssociative($iterable); }
[ "private", "function", "isObject", "(", "$", "iterable", ",", "\\", "Iterator", "$", "iterator", ")", "{", "if", "(", "$", "this", "->", "options", "&", "JSON_FORCE_OBJECT", ")", "{", "return", "true", ";", "}", "if", "(", "$", "iterable", "instanceof", ...
Tells if the given iterable should be handled as a JSON object or not. @param object|array $iterable The iterable value to test @param \Iterator $iterator An Iterator created from the iterable value @return bool True if the given iterable should be treated as object, false if not
[ "Tells", "if", "the", "given", "iterable", "should", "be", "handled", "as", "a", "JSON", "object", "or", "not", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L334-L345
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.isAssociative
private function isAssociative(array $array) { if ($array === []) { return false; } $expected = 0; foreach ($array as $key => $_) { if ($key !== $expected++) { return true; } } return false; }
php
private function isAssociative(array $array) { if ($array === []) { return false; } $expected = 0; foreach ($array as $key => $_) { if ($key !== $expected++) { return true; } } return false; }
[ "private", "function", "isAssociative", "(", "array", "$", "array", ")", "{", "if", "(", "$", "array", "===", "[", "]", ")", "{", "return", "false", ";", "}", "$", "expected", "=", "0", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "...
Tells if the given array is an associative array. @param array $array The array to test @return bool True if the array is associative, false if not
[ "Tells", "if", "the", "given", "array", "is", "an", "associative", "array", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L352-L367
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.popStack
private function popStack() { if (!$this->first) { $this->newLine = true; } $this->first = false; array_pop($this->stack); if (array_pop($this->stackType)) { $this->output('}', JsonToken::T_RIGHT_BRACE); } else { $this->output(']', JsonToken::T_RIGHT_BRACKET); } array_pop($this->valueStack); }
php
private function popStack() { if (!$this->first) { $this->newLine = true; } $this->first = false; array_pop($this->stack); if (array_pop($this->stackType)) { $this->output('}', JsonToken::T_RIGHT_BRACE); } else { $this->output(']', JsonToken::T_RIGHT_BRACKET); } array_pop($this->valueStack); }
[ "private", "function", "popStack", "(", ")", "{", "if", "(", "!", "$", "this", "->", "first", ")", "{", "$", "this", "->", "newLine", "=", "true", ";", "}", "$", "this", "->", "first", "=", "false", ";", "array_pop", "(", "$", "this", "->", "stac...
Removes the top element of the value stack.
[ "Removes", "the", "top", "element", "of", "the", "value", "stack", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L372-L388
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.outputJson
private function outputJson($value, $token) { $encoded = json_encode($value, $this->options); $error = json_last_error(); if ($error !== JSON_ERROR_NONE) { $this->addError(sprintf('%s (%s)', json_last_error_msg(), $this->getJsonErrorName($error))); } $this->output($encoded, $token); }
php
private function outputJson($value, $token) { $encoded = json_encode($value, $this->options); $error = json_last_error(); if ($error !== JSON_ERROR_NONE) { $this->addError(sprintf('%s (%s)', json_last_error_msg(), $this->getJsonErrorName($error))); } $this->output($encoded, $token); }
[ "private", "function", "outputJson", "(", "$", "value", ",", "$", "token", ")", "{", "$", "encoded", "=", "json_encode", "(", "$", "value", ",", "$", "this", "->", "options", ")", ";", "$", "error", "=", "json_last_error", "(", ")", ";", "if", "(", ...
Encodes the given value as JSON and passes it to output stream. @param mixed $value The value to output as JSON @param int $token The token type of the value
[ "Encodes", "the", "given", "value", "as", "JSON", "and", "passes", "it", "to", "output", "stream", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L395-L405
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.getJsonErrorName
private function getJsonErrorName($error) { $matches = array_keys(get_defined_constants(), $error, true); $prefix = 'JSON_ERROR_'; $prefixLength = strlen($prefix); $name = 'UNKNOWN_ERROR'; foreach ($matches as $match) { if (is_string($match) && strncmp($match, $prefix, $prefixLength) === 0) { $name = $match; break; } } return $name; }
php
private function getJsonErrorName($error) { $matches = array_keys(get_defined_constants(), $error, true); $prefix = 'JSON_ERROR_'; $prefixLength = strlen($prefix); $name = 'UNKNOWN_ERROR'; foreach ($matches as $match) { if (is_string($match) && strncmp($match, $prefix, $prefixLength) === 0) { $name = $match; break; } } return $name; }
[ "private", "function", "getJsonErrorName", "(", "$", "error", ")", "{", "$", "matches", "=", "array_keys", "(", "get_defined_constants", "(", ")", ",", "$", "error", ",", "true", ")", ";", "$", "prefix", "=", "'JSON_ERROR_'", ";", "$", "prefixLength", "=",...
Returns the name of the JSON error constant. @param int $error The error code to find @return string The name for the error code
[ "Returns", "the", "name", "of", "the", "JSON", "error", "constant", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L412-L427
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.outputLine
private function outputLine($string, $token) { $this->output($string, $token); $this->newLine = true; }
php
private function outputLine($string, $token) { $this->output($string, $token); $this->newLine = true; }
[ "private", "function", "outputLine", "(", "$", "string", ",", "$", "token", ")", "{", "$", "this", "->", "output", "(", "$", "string", ",", "$", "token", ")", ";", "$", "this", "->", "newLine", "=", "true", ";", "}" ]
Passes the given token to the output stream and ensures the next token is preceded by a newline. @param string $string The token to write to the output stream @param int $token The type of the token
[ "Passes", "the", "given", "token", "to", "the", "output", "stream", "and", "ensures", "the", "next", "token", "is", "preceded", "by", "a", "newline", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L434-L438
train
violet-php/streaming-json-encoder
src/AbstractJsonEncoder.php
AbstractJsonEncoder.output
private function output($string, $token) { if ($this->newLine && $this->options & JSON_PRETTY_PRINT) { $indent = str_repeat($this->indent, count($this->stack)); $this->write("\n", JsonToken::T_WHITESPACE); if ($indent !== '') { $this->write($indent, JsonToken::T_WHITESPACE); } $this->line++; $this->column = strlen($indent) + 1; } $this->newLine = false; $this->write($string, $token); $this->column += strlen($string); }
php
private function output($string, $token) { if ($this->newLine && $this->options & JSON_PRETTY_PRINT) { $indent = str_repeat($this->indent, count($this->stack)); $this->write("\n", JsonToken::T_WHITESPACE); if ($indent !== '') { $this->write($indent, JsonToken::T_WHITESPACE); } $this->line++; $this->column = strlen($indent) + 1; } $this->newLine = false; $this->write($string, $token); $this->column += strlen($string); }
[ "private", "function", "output", "(", "$", "string", ",", "$", "token", ")", "{", "if", "(", "$", "this", "->", "newLine", "&&", "$", "this", "->", "options", "&", "JSON_PRETTY_PRINT", ")", "{", "$", "indent", "=", "str_repeat", "(", "$", "this", "->...
Passes the given token to the output stream. @param string $string The token to write to the output stream @param int $token The type of the token
[ "Passes", "the", "given", "token", "to", "the", "output", "stream", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/AbstractJsonEncoder.php#L445-L462
train
violet-php/streaming-json-encoder
src/JsonStream.php
JsonStream.seek
public function seek($offset, $whence = SEEK_SET) { $position = $this->calculatePosition($offset, $whence); if (!isset($this->cursor) || $position < $this->cursor) { $this->getEncoder()->rewind(); $this->buffer = ''; $this->cursor = 0; } $this->forward($position); }
php
public function seek($offset, $whence = SEEK_SET) { $position = $this->calculatePosition($offset, $whence); if (!isset($this->cursor) || $position < $this->cursor) { $this->getEncoder()->rewind(); $this->buffer = ''; $this->cursor = 0; } $this->forward($position); }
[ "public", "function", "seek", "(", "$", "offset", ",", "$", "whence", "=", "SEEK_SET", ")", "{", "$", "position", "=", "$", "this", "->", "calculatePosition", "(", "$", "offset", ",", "$", "whence", ")", ";", "if", "(", "!", "isset", "(", "$", "thi...
Seeks the given cursor position in the JSON stream. If the provided seek position is less than the current cursor position, a rewind operation is performed on the underlying JSON encoder. Whether this works or not depends on whether the encoded value supports rewinding. Note that since it's not possible to determine the end of the JSON stream without encoding the entire value, it's not possible to set the cursor using SEEK_END constant and doing so will result in an exception. @param int $offset The offset for the cursor @param int $whence Either SEEK_CUR or SEEK_SET to determine new cursor position @throws \RuntimeException If SEEK_END is used to determine the cursor position
[ "Seeks", "the", "given", "cursor", "position", "in", "the", "JSON", "stream", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/JsonStream.php#L143-L154
train
violet-php/streaming-json-encoder
src/JsonStream.php
JsonStream.calculatePosition
private function calculatePosition($offset, $whence) { if ($whence === SEEK_CUR) { return max(0, $this->cursor + (int) $offset); } elseif ($whence === SEEK_SET) { return max(0, (int) $offset); } elseif ($whence === SEEK_END) { throw new \RuntimeException('Cannot set cursor position from the end of a JSON stream'); } throw new \InvalidArgumentException("Invalid cursor relative position '$whence'"); }
php
private function calculatePosition($offset, $whence) { if ($whence === SEEK_CUR) { return max(0, $this->cursor + (int) $offset); } elseif ($whence === SEEK_SET) { return max(0, (int) $offset); } elseif ($whence === SEEK_END) { throw new \RuntimeException('Cannot set cursor position from the end of a JSON stream'); } throw new \InvalidArgumentException("Invalid cursor relative position '$whence'"); }
[ "private", "function", "calculatePosition", "(", "$", "offset", ",", "$", "whence", ")", "{", "if", "(", "$", "whence", "===", "SEEK_CUR", ")", "{", "return", "max", "(", "0", ",", "$", "this", "->", "cursor", "+", "(", "int", ")", "$", "offset", "...
Calculates new position for the cursor based on offset and whence. @param int $offset The cursor offset @param int $whence One of the SEEK_* constants @return int The new cursor position @throws \RuntimeException If SEEK_END is used to determine the cursor position
[ "Calculates", "new", "position", "for", "the", "cursor", "based", "on", "offset", "and", "whence", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/JsonStream.php#L163-L174
train
violet-php/streaming-json-encoder
src/JsonStream.php
JsonStream.forward
private function forward($position) { $encoder = $this->getEncoder(); while ($this->cursor < $position) { $length = strlen($this->buffer); if ($this->cursor + $length > $position) { $this->buffer = substr($this->buffer, $position - $this->cursor); $this->cursor = $position; break; } $this->cursor += $length; $this->buffer = ''; if (!$encoder->valid()) { $this->buffer = null; break; } $this->buffer = $encoder->current(); $encoder->next(); } }
php
private function forward($position) { $encoder = $this->getEncoder(); while ($this->cursor < $position) { $length = strlen($this->buffer); if ($this->cursor + $length > $position) { $this->buffer = substr($this->buffer, $position - $this->cursor); $this->cursor = $position; break; } $this->cursor += $length; $this->buffer = ''; if (!$encoder->valid()) { $this->buffer = null; break; } $this->buffer = $encoder->current(); $encoder->next(); } }
[ "private", "function", "forward", "(", "$", "position", ")", "{", "$", "encoder", "=", "$", "this", "->", "getEncoder", "(", ")", ";", "while", "(", "$", "this", "->", "cursor", "<", "$", "position", ")", "{", "$", "length", "=", "strlen", "(", "$"...
Forwards the JSON stream reading cursor to the given position or to the end of stream. @param int $position The new position of the cursor
[ "Forwards", "the", "JSON", "stream", "reading", "cursor", "to", "the", "given", "position", "or", "to", "the", "end", "of", "stream", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/JsonStream.php#L180-L204
train
violet-php/streaming-json-encoder
src/JsonStream.php
JsonStream.read
public function read($length) { $length = max(0, (int) $length); $encoder = $this->getEncoder(); while (strlen($this->buffer) < $length && $encoder->valid()) { $this->buffer .= $encoder->current(); $encoder->next(); } if (strlen($this->buffer) > $length || $encoder->valid()) { $output = substr($this->buffer, 0, $length); $this->buffer = substr($this->buffer, $length); } else { $output = (string) $this->buffer; $this->buffer = null; } $this->cursor += strlen($output); return $output; }
php
public function read($length) { $length = max(0, (int) $length); $encoder = $this->getEncoder(); while (strlen($this->buffer) < $length && $encoder->valid()) { $this->buffer .= $encoder->current(); $encoder->next(); } if (strlen($this->buffer) > $length || $encoder->valid()) { $output = substr($this->buffer, 0, $length); $this->buffer = substr($this->buffer, $length); } else { $output = (string) $this->buffer; $this->buffer = null; } $this->cursor += strlen($output); return $output; }
[ "public", "function", "read", "(", "$", "length", ")", "{", "$", "length", "=", "max", "(", "0", ",", "(", "int", ")", "$", "length", ")", ";", "$", "encoder", "=", "$", "this", "->", "getEncoder", "(", ")", ";", "while", "(", "strlen", "(", "$...
Returns the given number of bytes from the JSON stream. The underlying value is encoded into JSON until enough bytes have been generated to fulfill the requested number of bytes. The extraneous bytes are then buffered for the next read from the JSON stream. The stream may return fewer number of bytes if the entire value has been encoded and there are no more bytes to return. @param int $length The number of bytes to return @return string The bytes read from the JSON stream
[ "Returns", "the", "given", "number", "of", "bytes", "from", "the", "JSON", "stream", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/JsonStream.php#L262-L283
train
violet-php/streaming-json-encoder
src/JsonStream.php
JsonStream.getContents
public function getContents() { $encoder = $this->getEncoder(); $output = ''; while ($encoder->valid()) { $output .= $encoder->current(); $encoder->next(); } $this->cursor += strlen($output); $this->buffer = null; return $output; }
php
public function getContents() { $encoder = $this->getEncoder(); $output = ''; while ($encoder->valid()) { $output .= $encoder->current(); $encoder->next(); } $this->cursor += strlen($output); $this->buffer = null; return $output; }
[ "public", "function", "getContents", "(", ")", "{", "$", "encoder", "=", "$", "this", "->", "getEncoder", "(", ")", ";", "$", "output", "=", "''", ";", "while", "(", "$", "encoder", "->", "valid", "(", ")", ")", "{", "$", "output", ".=", "$", "en...
Returns the remaining bytes from the JSON stream. @return string The remaining bytes from JSON stream
[ "Returns", "the", "remaining", "bytes", "from", "the", "JSON", "stream", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/JsonStream.php#L289-L303
train
violet-php/streaming-json-encoder
src/JsonStream.php
JsonStream.getMetadata
public function getMetadata($key = null) { $meta = [ 'timed_out' => false, 'blocked' => true, 'eof' => $this->eof(), 'unread_bytes' => strlen($this->buffer), 'stream_type' => get_class($this->encoder), 'wrapper_type' => 'OBJECT', 'wrapper_data' => [ 'step' => $this->encoder->key(), 'errors' => $this->encoder->getErrors(), ], 'mode' => 'r', 'seekable' => true, 'uri' => '', ]; return $key === null ? $meta : (isset($meta[$key]) ? $meta[$key] : null); }
php
public function getMetadata($key = null) { $meta = [ 'timed_out' => false, 'blocked' => true, 'eof' => $this->eof(), 'unread_bytes' => strlen($this->buffer), 'stream_type' => get_class($this->encoder), 'wrapper_type' => 'OBJECT', 'wrapper_data' => [ 'step' => $this->encoder->key(), 'errors' => $this->encoder->getErrors(), ], 'mode' => 'r', 'seekable' => true, 'uri' => '', ]; return $key === null ? $meta : (isset($meta[$key]) ? $meta[$key] : null); }
[ "public", "function", "getMetadata", "(", "$", "key", "=", "null", ")", "{", "$", "meta", "=", "[", "'timed_out'", "=>", "false", ",", "'blocked'", "=>", "true", ",", "'eof'", "=>", "$", "this", "->", "eof", "(", ")", ",", "'unread_bytes'", "=>", "st...
Returns the metadata related to the JSON stream. No underlying PHP resource exists for the stream, but this method will still return relevant information regarding the stream that is similar to PHP stream meta data. @param string|null $key The key of the value to return @return array|mixed|null The meta data array, a specific value or null if not defined
[ "Returns", "the", "metadata", "related", "to", "the", "JSON", "stream", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/JsonStream.php#L315-L334
train
violet-php/streaming-json-encoder
src/StreamJsonEncoder.php
StreamJsonEncoder.write
protected function write($string, $token) { if ($this->stream === null) { echo $string; } else { $callback = $this->stream; $callback($string, $token); } $this->bytes += strlen($string); }
php
protected function write($string, $token) { if ($this->stream === null) { echo $string; } else { $callback = $this->stream; $callback($string, $token); } $this->bytes += strlen($string); }
[ "protected", "function", "write", "(", "$", "string", ",", "$", "token", ")", "{", "if", "(", "$", "this", "->", "stream", "===", "null", ")", "{", "echo", "$", "string", ";", "}", "else", "{", "$", "callback", "=", "$", "this", "->", "stream", "...
Echoes to given string or passes it to the stream callback. @param string $string The string to output @param int $token The type of the string
[ "Echoes", "to", "given", "string", "or", "passes", "it", "to", "the", "stream", "callback", "." ]
12b3b808b1f9d0fae74b5be38255aca1846836ce
https://github.com/violet-php/streaming-json-encoder/blob/12b3b808b1f9d0fae74b5be38255aca1846836ce/src/StreamJsonEncoder.php#L85-L95
train
leroy-merlin-br/mongolid-laravel
src/Validation/Rules.php
Rules.message
public function message(string $message, string $attribute, string $rule): string { if ("validation.{$rule}" !== $message) { return $message; } return $this->getTranslatedMessageFallback( str_replace('mongolid_', '', $rule), $attribute ); }
php
public function message(string $message, string $attribute, string $rule): string { if ("validation.{$rule}" !== $message) { return $message; } return $this->getTranslatedMessageFallback( str_replace('mongolid_', '', $rule), $attribute ); }
[ "public", "function", "message", "(", "string", "$", "message", ",", "string", "$", "attribute", ",", "string", "$", "rule", ")", ":", "string", "{", "if", "(", "\"validation.{$rule}\"", "!==", "$", "message", ")", "{", "return", "$", "message", ";", "}"...
Error message with fallback from Laravel rules 'unique' and 'exists'.
[ "Error", "message", "with", "fallback", "from", "Laravel", "rules", "unique", "and", "exists", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/Validation/Rules.php#L80-L90
train
leroy-merlin-br/mongolid-laravel
src/Validation/Rules.php
Rules.requireParameterCount
private function requireParameterCount(int $count, array $parameters, string $rule): void { if (count($parameters) < $count) { throw new InvalidArgumentException("Validation rule {$rule} requires at least {$count} parameters."); } }
php
private function requireParameterCount(int $count, array $parameters, string $rule): void { if (count($parameters) < $count) { throw new InvalidArgumentException("Validation rule {$rule} requires at least {$count} parameters."); } }
[ "private", "function", "requireParameterCount", "(", "int", "$", "count", ",", "array", "$", "parameters", ",", "string", "$", "rule", ")", ":", "void", "{", "if", "(", "count", "(", "$", "parameters", ")", "<", "$", "count", ")", "{", "throw", "new", ...
Require a certain number of parameters to be present. @throws InvalidArgumentException
[ "Require", "a", "certain", "number", "of", "parameters", "to", "be", "present", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/Validation/Rules.php#L126-L131
train
leroy-merlin-br/mongolid-laravel
src/Validation/Rules.php
Rules.hasResults
private function hasResults(string $collection, array $query): bool { $mongolidConnection = $this->pool->getConnection(); $connection = $mongolidConnection->getRawConnection(); $database = $mongolidConnection->defaultDatabase; return (bool) $connection->$database->$collection->count($query); }
php
private function hasResults(string $collection, array $query): bool { $mongolidConnection = $this->pool->getConnection(); $connection = $mongolidConnection->getRawConnection(); $database = $mongolidConnection->defaultDatabase; return (bool) $connection->$database->$collection->count($query); }
[ "private", "function", "hasResults", "(", "string", "$", "collection", ",", "array", "$", "query", ")", ":", "bool", "{", "$", "mongolidConnection", "=", "$", "this", "->", "pool", "->", "getConnection", "(", ")", ";", "$", "connection", "=", "$", "mongo...
Run query on database and check for a result count.
[ "Run", "query", "on", "database", "and", "check", "for", "a", "result", "count", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/Validation/Rules.php#L136-L143
train
leroy-merlin-br/mongolid-laravel
src/Validation/Rules.php
Rules.getTranslatedMessageFallback
private function getTranslatedMessageFallback(string $rule, string $attribute): string { $attributeKey = "validation.attributes.$attribute"; $attributeTranslation = trans($attributeKey); $attribute = $attributeTranslation === $attributeKey ? $attribute : $attributeTranslation; return trans("validation.{$rule}", compact('attribute')); }
php
private function getTranslatedMessageFallback(string $rule, string $attribute): string { $attributeKey = "validation.attributes.$attribute"; $attributeTranslation = trans($attributeKey); $attribute = $attributeTranslation === $attributeKey ? $attribute : $attributeTranslation; return trans("validation.{$rule}", compact('attribute')); }
[ "private", "function", "getTranslatedMessageFallback", "(", "string", "$", "rule", ",", "string", "$", "attribute", ")", ":", "string", "{", "$", "attributeKey", "=", "\"validation.attributes.$attribute\"", ";", "$", "attributeTranslation", "=", "trans", "(", "$", ...
If the user has not created a translation for 'mongolid_unique' rule, this method will attempt to get the translation for 'unique' rule. The same with 'mongolid_exists' and 'exists'. Since it is not easy to use the framework to make this message, this is a simple approach.
[ "If", "the", "user", "has", "not", "created", "a", "translation", "for", "mongolid_unique", "rule", "this", "method", "will", "attempt", "to", "get", "the", "translation", "for", "unique", "rule", ".", "The", "same", "with", "mongolid_exists", "and", "exists",...
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/Validation/Rules.php#L166-L174
train
leroy-merlin-br/mongolid-laravel
src/FailedJobsService.php
FailedJobsService.rawCollection
protected function rawCollection(): Collection { $conn = $this->connPool->getConnection(); $database = $conn->defaultDatabase; return $conn->getRawConnection()->$database->{$this->collection}; }
php
protected function rawCollection(): Collection { $conn = $this->connPool->getConnection(); $database = $conn->defaultDatabase; return $conn->getRawConnection()->$database->{$this->collection}; }
[ "protected", "function", "rawCollection", "(", ")", ":", "Collection", "{", "$", "conn", "=", "$", "this", "->", "connPool", "->", "getConnection", "(", ")", ";", "$", "database", "=", "$", "conn", "->", "defaultDatabase", ";", "return", "$", "conn", "->...
Get the actual MongoDB Collection object.
[ "Get", "the", "actual", "MongoDB", "Collection", "object", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/FailedJobsService.php#L89-L95
train
leroy-merlin-br/mongolid-laravel
src/MongolidFailedJobProvider.php
MongolidFailedJobProvider.all
public function all() { foreach ($this->failedJobs->all() as $job) { $jobs[] = $this->presentJob($job); } return $jobs ?? []; }
php
public function all() { foreach ($this->failedJobs->all() as $job) { $jobs[] = $this->presentJob($job); } return $jobs ?? []; }
[ "public", "function", "all", "(", ")", "{", "foreach", "(", "$", "this", "->", "failedJobs", "->", "all", "(", ")", "as", "$", "job", ")", "{", "$", "jobs", "[", "]", "=", "$", "this", "->", "presentJob", "(", "$", "job", ")", ";", "}", "return...
Get a list of all of the failed jobs. @return array
[ "Get", "a", "list", "of", "all", "of", "the", "failed", "jobs", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/MongolidFailedJobProvider.php#L54-L61
train
leroy-merlin-br/mongolid-laravel
src/MongolidFailedJobProvider.php
MongolidFailedJobProvider.presentJob
private function presentJob($job) { $job = (array) $job; return (object) [ 'id' => (string) $job['_id'], 'connection' => $job['connection'], 'queue' => $job['queue'], 'payload' => $job['payload'], 'exception' => $job['exception'], 'failed_at' => LocalDateTime::format($job['failed_at'], DateTime::ATOM), ]; }
php
private function presentJob($job) { $job = (array) $job; return (object) [ 'id' => (string) $job['_id'], 'connection' => $job['connection'], 'queue' => $job['queue'], 'payload' => $job['payload'], 'exception' => $job['exception'], 'failed_at' => LocalDateTime::format($job['failed_at'], DateTime::ATOM), ]; }
[ "private", "function", "presentJob", "(", "$", "job", ")", "{", "$", "job", "=", "(", "array", ")", "$", "job", ";", "return", "(", "object", ")", "[", "'id'", "=>", "(", "string", ")", "$", "job", "[", "'_id'", "]", ",", "'connection'", "=>", "$...
Prepare job to be consumed by Laravel Commands. @param object $job @return object
[ "Prepare", "job", "to", "be", "consumed", "by", "Laravel", "Commands", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/MongolidFailedJobProvider.php#L104-L116
train
leroy-merlin-br/mongolid-laravel
src/MongolidModel.php
MongolidModel.save
public function save(bool $force = false) { if ($this->localMockHasExpectationsFor('save')) { return $this->getLocalMock()->save(); } if ($force || $this->isValid()) { $this->hashAttributes(); return parent::save(); } return false; }
php
public function save(bool $force = false) { if ($this->localMockHasExpectationsFor('save')) { return $this->getLocalMock()->save(); } if ($force || $this->isValid()) { $this->hashAttributes(); return parent::save(); } return false; }
[ "public", "function", "save", "(", "bool", "$", "force", "=", "false", ")", "{", "if", "(", "$", "this", "->", "localMockHasExpectationsFor", "(", "'save'", ")", ")", "{", "return", "$", "this", "->", "getLocalMock", "(", ")", "->", "save", "(", ")", ...
Save the model to the database if it's valid. This method also checks for the presence of the localMock in order to call the save method into the existing Mock in order not to touch the database. @param bool $force force save even if the object is invalid @return bool
[ "Save", "the", "model", "to", "the", "database", "if", "it", "s", "valid", ".", "This", "method", "also", "checks", "for", "the", "presence", "of", "the", "localMock", "in", "order", "to", "call", "the", "save", "method", "into", "the", "existing", "Mock...
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/MongolidModel.php#L74-L87
train
leroy-merlin-br/mongolid-laravel
src/MongolidModel.php
MongolidModel.hashAttributes
protected function hashAttributes() { foreach ($this->hashedAttributes as $attr) { // Hash attribute if changed if (!isset($this->original[$attr]) || $this->$attr != $this->original[$attr]) { $this->$attr = app(Hasher::class)->make($this->$attr); } // Removes any confirmation field before saving it into the database $confirmationField = $attr.'_confirmation'; if ($this->$confirmationField) { unset($this->$confirmationField); } } }
php
protected function hashAttributes() { foreach ($this->hashedAttributes as $attr) { // Hash attribute if changed if (!isset($this->original[$attr]) || $this->$attr != $this->original[$attr]) { $this->$attr = app(Hasher::class)->make($this->$attr); } // Removes any confirmation field before saving it into the database $confirmationField = $attr.'_confirmation'; if ($this->$confirmationField) { unset($this->$confirmationField); } } }
[ "protected", "function", "hashAttributes", "(", ")", "{", "foreach", "(", "$", "this", "->", "hashedAttributes", "as", "$", "attr", ")", "{", "// Hash attribute if changed", "if", "(", "!", "isset", "(", "$", "this", "->", "original", "[", "$", "attr", "]"...
Hashes the attributes specified in the hashedAttributes array.
[ "Hashes", "the", "attributes", "specified", "in", "the", "hashedAttributes", "array", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/MongolidModel.php#L202-L216
train
leroy-merlin-br/mongolid-laravel
src/MongolidModel.php
MongolidModel.localMockHasExpectationsFor
protected function localMockHasExpectationsFor(string $method): bool { return $this->hasLocalMock() && $this->getLocalMock()->mockery_getExpectationsFor($method); }
php
protected function localMockHasExpectationsFor(string $method): bool { return $this->hasLocalMock() && $this->getLocalMock()->mockery_getExpectationsFor($method); }
[ "protected", "function", "localMockHasExpectationsFor", "(", "string", "$", "method", ")", ":", "bool", "{", "return", "$", "this", "->", "hasLocalMock", "(", ")", "&&", "$", "this", "->", "getLocalMock", "(", ")", "->", "mockery_getExpectationsFor", "(", "$",...
Check for a expectation for given method on local mock. @param string $method name of the method being checked
[ "Check", "for", "a", "expectation", "for", "given", "method", "on", "local", "mock", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/MongolidModel.php#L295-L298
train
leroy-merlin-br/mongolid-laravel
src/MongolidModel.php
MongolidModel.callMockOrParent
protected static function callMockOrParent(string $method, array $arguments) { $classToCall = 'parent'; $class = get_called_class(); $mock = static::$mock[$class] ?? null; if ($mock && $mock->mockery_getExpectationsFor($method)) { $classToCall = $mock; } return call_user_func_array([$classToCall, $method], $arguments); }
php
protected static function callMockOrParent(string $method, array $arguments) { $classToCall = 'parent'; $class = get_called_class(); $mock = static::$mock[$class] ?? null; if ($mock && $mock->mockery_getExpectationsFor($method)) { $classToCall = $mock; } return call_user_func_array([$classToCall, $method], $arguments); }
[ "protected", "static", "function", "callMockOrParent", "(", "string", "$", "method", ",", "array", "$", "arguments", ")", "{", "$", "classToCall", "=", "'parent'", ";", "$", "class", "=", "get_called_class", "(", ")", ";", "$", "mock", "=", "static", "::",...
Calls mock method if its have expectations. Calls parent method otherwise. @param string $method name of the method being called @param array $arguments arguments to pass in method call @return mixed See parent implementation
[ "Calls", "mock", "method", "if", "its", "have", "expectations", ".", "Calls", "parent", "method", "otherwise", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/MongolidModel.php#L385-L396
train
leroy-merlin-br/mongolid-laravel
src/MongolidServiceProvider.php
MongolidServiceProvider.registerConnector
public function registerConnector() { MongolidIoc::setContainer($this->app); $this->app->singleton( Pool::class, function ($app) { $config = $app['config']->get('database.mongodb.default') ?? []; $connectionString = $this->buildConnectionString($config); $options = $config['options'] ?? []; $driverOptions = $config['driver_options'] ?? []; $connection = new Connection($connectionString, $options, $driverOptions); $connection->defaultDatabase = $config['database'] ?? 'mongolid'; $pool = new Pool(); $pool->addConnection($connection); return $pool; } ); $this->app->singleton( EventTriggerService::class, function ($app) { $eventService = new EventTriggerService(); $eventService->registerEventDispatcher($app->make(LaravelEventTrigger::class)); return $eventService; } ); $this->app->singleton( CacheComponentInterface::class, function ($app) { return new LaravelCacheComponent($app[CacheRepository::class]); } ); }
php
public function registerConnector() { MongolidIoc::setContainer($this->app); $this->app->singleton( Pool::class, function ($app) { $config = $app['config']->get('database.mongodb.default') ?? []; $connectionString = $this->buildConnectionString($config); $options = $config['options'] ?? []; $driverOptions = $config['driver_options'] ?? []; $connection = new Connection($connectionString, $options, $driverOptions); $connection->defaultDatabase = $config['database'] ?? 'mongolid'; $pool = new Pool(); $pool->addConnection($connection); return $pool; } ); $this->app->singleton( EventTriggerService::class, function ($app) { $eventService = new EventTriggerService(); $eventService->registerEventDispatcher($app->make(LaravelEventTrigger::class)); return $eventService; } ); $this->app->singleton( CacheComponentInterface::class, function ($app) { return new LaravelCacheComponent($app[CacheRepository::class]); } ); }
[ "public", "function", "registerConnector", "(", ")", "{", "MongolidIoc", "::", "setContainer", "(", "$", "this", "->", "app", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "Pool", "::", "class", ",", "function", "(", "$", "app", ")", "{",...
Register MongoDbConnector within the application.
[ "Register", "MongoDbConnector", "within", "the", "application", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/MongolidServiceProvider.php#L47-L83
train
leroy-merlin-br/mongolid-laravel
src/MongolidServiceProvider.php
MongolidServiceProvider.replaceQueueFailer
private function replaceQueueFailer() { $this->app->extend( 'queue.failer', function ($concrete, $app) { $collection = $app['config']['queue.failed.collection']; return isset($collection) ? $this->buildMongolidFailedJobProvider($app, $collection) : new NullFailedJobProvider(); } ); }
php
private function replaceQueueFailer() { $this->app->extend( 'queue.failer', function ($concrete, $app) { $collection = $app['config']['queue.failed.collection']; return isset($collection) ? $this->buildMongolidFailedJobProvider($app, $collection) : new NullFailedJobProvider(); } ); }
[ "private", "function", "replaceQueueFailer", "(", ")", "{", "$", "this", "->", "app", "->", "extend", "(", "'queue.failer'", ",", "function", "(", "$", "concrete", ",", "$", "app", ")", "{", "$", "collection", "=", "$", "app", "[", "'config'", "]", "["...
Rebind Laravel Failed Queue Job Provider to use Mongolid.
[ "Rebind", "Laravel", "Failed", "Queue", "Job", "Provider", "to", "use", "Mongolid", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/MongolidServiceProvider.php#L173-L185
train
leroy-merlin-br/mongolid-laravel
src/Migrations/Commands/FreshCommand.php
FreshCommand.dropDatabase
protected function dropDatabase($database) { $connection = $this->pool->getConnection(); $database = $database ?? $connection->defaultDatabase; $connection->getRawConnection()->dropDatabase($database); }
php
protected function dropDatabase($database) { $connection = $this->pool->getConnection(); $database = $database ?? $connection->defaultDatabase; $connection->getRawConnection()->dropDatabase($database); }
[ "protected", "function", "dropDatabase", "(", "$", "database", ")", "{", "$", "connection", "=", "$", "this", "->", "pool", "->", "getConnection", "(", ")", ";", "$", "database", "=", "$", "database", "??", "$", "connection", "->", "defaultDatabase", ";", ...
Drop all of the database collections. @param string $database
[ "Drop", "all", "of", "the", "database", "collections", "." ]
ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf
https://github.com/leroy-merlin-br/mongolid-laravel/blob/ac0998085ea95fe58c7d0b76bc8e8a714f6eadcf/src/Migrations/Commands/FreshCommand.php#L79-L85
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Entities/TraceEntry.php
TraceEntry.assignAttributes
protected function assignAttributes() { $parsed = $this->parser->parseTraceEntry($this->content); foreach ($parsed as $key => $value) { $this->{$key} = $value; } }
php
protected function assignAttributes() { $parsed = $this->parser->parseTraceEntry($this->content); foreach ($parsed as $key => $value) { $this->{$key} = $value; } }
[ "protected", "function", "assignAttributes", "(", ")", "{", "$", "parsed", "=", "$", "this", "->", "parser", "->", "parseTraceEntry", "(", "$", "this", "->", "content", ")", ";", "foreach", "(", "$", "parsed", "as", "$", "key", "=>", "$", "value", ")",...
Parses content of the trace entry and assigns each information to the corresponding attribute in the trace entry. @return void
[ "Parses", "content", "of", "the", "trace", "entry", "and", "assigns", "each", "information", "to", "the", "corresponding", "attribute", "in", "the", "trace", "entry", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Entities/TraceEntry.php#L82-L89
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Entities/LogEntry.php
LogEntry.getAttribute
public function getAttribute($key) { $key = $this->reFormatForCompatibility($key); return (property_exists($this, $key)) ? $this->{$key} : null; }
php
public function getAttribute($key) { $key = $this->reFormatForCompatibility($key); return (property_exists($this, $key)) ? $this->{$key} : null; }
[ "public", "function", "getAttribute", "(", "$", "key", ")", "{", "$", "key", "=", "$", "this", "->", "reFormatForCompatibility", "(", "$", "key", ")", ";", "return", "(", "property_exists", "(", "$", "this", ",", "$", "key", ")", ")", "?", "$", "this...
Retrieves an attribute of the log entry @param $key @return mixed
[ "Retrieves", "an", "attribute", "of", "the", "log", "entry" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Entities/LogEntry.php#L127-L132
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Entities/LogEntry.php
LogEntry.getOriginal
public function getOriginal($key) { $key = $this->reFormatForCompatibility($key); return (array_key_exists($key, $this->attributes)) ? $this->attributes[$key] : null; }
php
public function getOriginal($key) { $key = $this->reFormatForCompatibility($key); return (array_key_exists($key, $this->attributes)) ? $this->attributes[$key] : null; }
[ "public", "function", "getOriginal", "(", "$", "key", ")", "{", "$", "key", "=", "$", "this", "->", "reFormatForCompatibility", "(", "$", "key", ")", ";", "return", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "attributes", ")", ")...
Get original value of an property of the log entry @param string $key @return void
[ "Get", "original", "value", "of", "an", "property", "of", "the", "log", "entry" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Entities/LogEntry.php#L141-L146
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Entities/LogEntry.php
LogEntry.delete
public function delete() { $rawContent = $this->getRawContent(); $filePath = $this->attributes['file_path']; $logContent = file_get_contents($filePath); $logContent = str_replace($rawContent, '', $logContent); file_put_contents($filePath, $logContent); return true; }
php
public function delete() { $rawContent = $this->getRawContent(); $filePath = $this->attributes['file_path']; $logContent = file_get_contents($filePath); $logContent = str_replace($rawContent, '', $logContent); file_put_contents($filePath, $logContent); return true; }
[ "public", "function", "delete", "(", ")", "{", "$", "rawContent", "=", "$", "this", "->", "getRawContent", "(", ")", ";", "$", "filePath", "=", "$", "this", "->", "attributes", "[", "'file_path'", "]", ";", "$", "logContent", "=", "file_get_contents", "(...
Removes the current entry from the log file. @return bool
[ "Removes", "the", "current", "entry", "from", "the", "log", "file", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Entities/LogEntry.php#L191-L201
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Entities/LogEntry.php
LogEntry.setContext
protected function setContext($context = null) { if ($context) { $this->context = new LogContext($this->parser, $context); } }
php
protected function setContext($context = null) { if ($context) { $this->context = new LogContext($this->parser, $context); } }
[ "protected", "function", "setContext", "(", "$", "context", "=", "null", ")", "{", "if", "(", "$", "context", ")", "{", "$", "this", "->", "context", "=", "new", "LogContext", "(", "$", "this", "->", "parser", ",", "$", "context", ")", ";", "}", "}...
Sets the log entry's context property. @param string $context @return void
[ "Sets", "the", "log", "entry", "s", "context", "property", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Entities/LogEntry.php#L310-L315
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Entities/LogEntry.php
LogEntry.setStackTraces
protected function setStackTraces($stackTraces = null) { $traces = $this->parser->parseStackTrace($stackTraces); $output = []; foreach ($traces as $trace) { $output[] = new TraceEntry($this->parser, $trace); } $this->stack_traces = new Collection($output); }
php
protected function setStackTraces($stackTraces = null) { $traces = $this->parser->parseStackTrace($stackTraces); $output = []; foreach ($traces as $trace) { $output[] = new TraceEntry($this->parser, $trace); } $this->stack_traces = new Collection($output); }
[ "protected", "function", "setStackTraces", "(", "$", "stackTraces", "=", "null", ")", "{", "$", "traces", "=", "$", "this", "->", "parser", "->", "parseStackTrace", "(", "$", "stackTraces", ")", ";", "$", "output", "=", "[", "]", ";", "foreach", "(", "...
Sets the log entry's level property. @param $stackTraces @return void
[ "Sets", "the", "log", "entry", "s", "level", "property", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Entities/LogEntry.php#L324-L335
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Entities/LogEntry.php
LogEntry.assignAttributes
protected function assignAttributes() { $bodyParsed = $this->parser->parseLogBody($this->attributes['body']); $this->attributes['context'] = $bodyParsed['context']; $this->attributes['stack_traces'] = $bodyParsed['stack_traces']; $this->setId($this->generateId()); $this->setDate($this->attributes['date']); $this->setEnvironment($this->attributes['environment']); $this->setLevel($this->attributes['level']); $this->setFilePath($this->attributes['file_path']); $this->setContext($this->attributes['context']); $this->setStackTraces($this->attributes['stack_traces']); }
php
protected function assignAttributes() { $bodyParsed = $this->parser->parseLogBody($this->attributes['body']); $this->attributes['context'] = $bodyParsed['context']; $this->attributes['stack_traces'] = $bodyParsed['stack_traces']; $this->setId($this->generateId()); $this->setDate($this->attributes['date']); $this->setEnvironment($this->attributes['environment']); $this->setLevel($this->attributes['level']); $this->setFilePath($this->attributes['file_path']); $this->setContext($this->attributes['context']); $this->setStackTraces($this->attributes['stack_traces']); }
[ "protected", "function", "assignAttributes", "(", ")", "{", "$", "bodyParsed", "=", "$", "this", "->", "parser", "->", "parseLogBody", "(", "$", "this", "->", "attributes", "[", "'body'", "]", ")", ";", "$", "this", "->", "attributes", "[", "'context'", ...
Assigns the valid keys in the attributes array to the properties in the log entry. @return void
[ "Assigns", "the", "valid", "keys", "in", "the", "attributes", "array", "to", "the", "properties", "in", "the", "log", "entry", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Entities/LogEntry.php#L357-L370
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Entities/LogEntry.php
LogEntry.reFormatForCompatibility
protected function reFormatForCompatibility($property) { switch (true) { case ($property == 'header'): $property = 'context'; break; case ($property == 'stack'): $property = 'stack_traces'; break; case ($property == 'filePath'): $property = 'file_path'; break; default: # code... break; } return $property; }
php
protected function reFormatForCompatibility($property) { switch (true) { case ($property == 'header'): $property = 'context'; break; case ($property == 'stack'): $property = 'stack_traces'; break; case ($property == 'filePath'): $property = 'file_path'; break; default: # code... break; } return $property; }
[ "protected", "function", "reFormatForCompatibility", "(", "$", "property", ")", "{", "switch", "(", "true", ")", "{", "case", "(", "$", "property", "==", "'header'", ")", ":", "$", "property", "=", "'context'", ";", "break", ";", "case", "(", "$", "prope...
Convert the property strings to be compatible with older version @param string $property @return string
[ "Convert", "the", "property", "strings", "to", "be", "compatible", "with", "older", "version" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Entities/LogEntry.php#L379-L400
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Levelable.php
Levelable.filter
public function filter($level, $allowed) { if (empty($allowed)) { return true; } if (is_array($allowed)) { $merges = array_values(array_uintersect($this->levels, $allowed, "strcasecmp")); if (in_array(strtolower($level), $merges)) { return true; } } return false; }
php
public function filter($level, $allowed) { if (empty($allowed)) { return true; } if (is_array($allowed)) { $merges = array_values(array_uintersect($this->levels, $allowed, "strcasecmp")); if (in_array(strtolower($level), $merges)) { return true; } } return false; }
[ "public", "function", "filter", "(", "$", "level", ",", "$", "allowed", ")", "{", "if", "(", "empty", "(", "$", "allowed", ")", ")", "{", "return", "true", ";", "}", "if", "(", "is_array", "(", "$", "allowed", ")", ")", "{", "$", "merges", "=", ...
Filter logs by level @param string $level Level need to check @param array $allowed Strict levels to filter @return bool
[ "Filter", "logs", "by", "level" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Levelable.php#L49-L63
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.level
public function level($level) { if (empty($level)) { $level = []; } elseif (is_string($level)) { $level = explode(',', str_replace(' ', '', $level)); } else { $level = is_array($level) ? $level : func_get_args(); } $this->setLevel($level); return $this; }
php
public function level($level) { if (empty($level)) { $level = []; } elseif (is_string($level)) { $level = explode(',', str_replace(' ', '', $level)); } else { $level = is_array($level) ? $level : func_get_args(); } $this->setLevel($level); return $this; }
[ "public", "function", "level", "(", "$", "level", ")", "{", "if", "(", "empty", "(", "$", "level", ")", ")", "{", "$", "level", "=", "[", "]", ";", "}", "elseif", "(", "is_string", "(", "$", "level", ")", ")", "{", "$", "level", "=", "explode",...
Sets the level to sort the log entries by. @param mixed $level @return \Jackiedo\LogReader\LogReader
[ "Sets", "the", "level", "to", "sort", "the", "log", "entries", "by", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L264-L277
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.orderBy
public function orderBy($field, $direction = 'asc') { $this->setOrderByField($field); $this->setOrderByDirection($direction); return $this; }
php
public function orderBy($field, $direction = 'asc') { $this->setOrderByField($field); $this->setOrderByDirection($direction); return $this; }
[ "public", "function", "orderBy", "(", "$", "field", ",", "$", "direction", "=", "'asc'", ")", "{", "$", "this", "->", "setOrderByField", "(", "$", "field", ")", ";", "$", "this", "->", "setOrderByDirection", "(", "$", "direction", ")", ";", "return", "...
Sets the direction to return the log entries in. @param string $field @param string $direction @return \Jackiedo\LogReader\LogReader
[ "Sets", "the", "direction", "to", "return", "the", "log", "entries", "in", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L323-L329
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.get
public function get() { $entries = []; $files = $this->getLogFiles(); if (! is_array($files)) { throw new UnableToRetrieveLogFilesException('Unable to retrieve files from path: '.$this->getLogPath()); } foreach ($files as $log) { /* * Set the current log path for easy manipulation * of the file if needed */ $this->setCurrentLogPath($log['path']); /* * Parse the log into an array of entries, passing in the level * so it can be filtered */ $parsedLog = $this->parseLog($log['contents'], $this->getEnvironment(), $this->getLevel()); /* * Create a new LogEntry object for each parsed log entry */ foreach ($parsedLog as $entry) { $newEntry = new LogEntry($this->parser, $this->cache, $entry); /* * Check if the entry has already been read, * and if read entries should be included. * * If includeRead is false, and the entry is read, * then continue processing. */ if (!$this->includeRead && $newEntry->isRead()) { continue; } $entries[$newEntry->id] = $newEntry; } } return $this->postCollectionModifiers(new Collection($entries)); }
php
public function get() { $entries = []; $files = $this->getLogFiles(); if (! is_array($files)) { throw new UnableToRetrieveLogFilesException('Unable to retrieve files from path: '.$this->getLogPath()); } foreach ($files as $log) { /* * Set the current log path for easy manipulation * of the file if needed */ $this->setCurrentLogPath($log['path']); /* * Parse the log into an array of entries, passing in the level * so it can be filtered */ $parsedLog = $this->parseLog($log['contents'], $this->getEnvironment(), $this->getLevel()); /* * Create a new LogEntry object for each parsed log entry */ foreach ($parsedLog as $entry) { $newEntry = new LogEntry($this->parser, $this->cache, $entry); /* * Check if the entry has already been read, * and if read entries should be included. * * If includeRead is false, and the entry is read, * then continue processing. */ if (!$this->includeRead && $newEntry->isRead()) { continue; } $entries[$newEntry->id] = $newEntry; } } return $this->postCollectionModifiers(new Collection($entries)); }
[ "public", "function", "get", "(", ")", "{", "$", "entries", "=", "[", "]", ";", "$", "files", "=", "$", "this", "->", "getLogFiles", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "files", ")", ")", "{", "throw", "new", "UnableToRetrieveLogFi...
Returns a Laravel collection of log entries. @throws \Jackiedo\LogReader\Exceptions\UnableToRetrieveLogFilesException @return Collection
[ "Returns", "a", "Laravel", "collection", "of", "log", "entries", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L338-L383
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.markAsRead
public function markAsRead() { $entries = $this->get(); $count = 0; foreach ($entries as $entry) { if ($entry->markAsRead()) { ++$count; } } return $count; }
php
public function markAsRead() { $entries = $this->get(); $count = 0; foreach ($entries as $entry) { if ($entry->markAsRead()) { ++$count; } } return $count; }
[ "public", "function", "markAsRead", "(", ")", "{", "$", "entries", "=", "$", "this", "->", "get", "(", ")", ";", "$", "count", "=", "0", ";", "foreach", "(", "$", "entries", "as", "$", "entry", ")", "{", "if", "(", "$", "entry", "->", "markAsRead...
Marks all retrieved log entries as read and returns the number of entries that have been marked. @return int
[ "Marks", "all", "retrieved", "log", "entries", "as", "read", "and", "returns", "the", "number", "of", "entries", "that", "have", "been", "marked", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L413-L426
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.paginate
public function paginate($perPage = 25, $currentPage = null, array $options = []) { $currentPage = $this->getPageFromInput($currentPage, $options); $offset = ($currentPage - 1) * $perPage; $total = $this->count(); $entries = $this->get()->slice($offset, $perPage)->all(); return new LengthAwarePaginator($entries, $total, $perPage, $currentPage, $options); }
php
public function paginate($perPage = 25, $currentPage = null, array $options = []) { $currentPage = $this->getPageFromInput($currentPage, $options); $offset = ($currentPage - 1) * $perPage; $total = $this->count(); $entries = $this->get()->slice($offset, $perPage)->all(); return new LengthAwarePaginator($entries, $total, $perPage, $currentPage, $options); }
[ "public", "function", "paginate", "(", "$", "perPage", "=", "25", ",", "$", "currentPage", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "currentPage", "=", "$", "this", "->", "getPageFromInput", "(", "$", "currentPage", ",",...
Paginates the returned log entries. @param int $perPage @param int $currentPage @param array $options [path => '', query => [], fragment => '', pageName => ''] @return mixed
[ "Paginates", "the", "returned", "log", "entries", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L489-L497
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.getLogFilenameList
public function getLogFilenameList($filename = null) { $data = []; if (empty($filename)) { $filename = '*.*'; } $files = $this->getLogFileList($filename); if (is_array($files)) { foreach ($files as $file) { $basename = pathinfo($file, PATHINFO_BASENAME); $data[$basename] = $file; } } return $data; }
php
public function getLogFilenameList($filename = null) { $data = []; if (empty($filename)) { $filename = '*.*'; } $files = $this->getLogFileList($filename); if (is_array($files)) { foreach ($files as $file) { $basename = pathinfo($file, PATHINFO_BASENAME); $data[$basename] = $file; } } return $data; }
[ "public", "function", "getLogFilenameList", "(", "$", "filename", "=", "null", ")", "{", "$", "data", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "filename", ")", ")", "{", "$", "filename", "=", "'*.*'", ";", "}", "$", "files", "=", "$", "t...
Returns an array of log filenames. @param null|string $filename @return array
[ "Returns", "an", "array", "of", "log", "filenames", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L506-L524
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.setOrderByField
protected function setOrderByField($field) { $field = strtolower($field); $acceptedFields = [ 'id', 'date', 'level', 'environment', 'file_path' ]; if (in_array($field, $acceptedFields)) { $this->orderByField = $field; } }
php
protected function setOrderByField($field) { $field = strtolower($field); $acceptedFields = [ 'id', 'date', 'level', 'environment', 'file_path' ]; if (in_array($field, $acceptedFields)) { $this->orderByField = $field; } }
[ "protected", "function", "setOrderByField", "(", "$", "field", ")", "{", "$", "field", "=", "strtolower", "(", "$", "field", ")", ";", "$", "acceptedFields", "=", "[", "'id'", ",", "'date'", ",", "'level'", ",", "'environment'", ",", "'file_path'", "]", ...
Sets the orderByField property to the specified field. @param string $field @return void
[ "Sets", "the", "orderByField", "property", "to", "the", "specified", "field", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L562-L577
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.setOrderByDirection
protected function setOrderByDirection($direction) { $direction = strtolower($direction); if ($direction == 'desc' || $direction == 'asc') { $this->orderByDirection = $direction; } }
php
protected function setOrderByDirection($direction) { $direction = strtolower($direction); if ($direction == 'desc' || $direction == 'asc') { $this->orderByDirection = $direction; } }
[ "protected", "function", "setOrderByDirection", "(", "$", "direction", ")", "{", "$", "direction", "=", "strtolower", "(", "$", "direction", ")", ";", "if", "(", "$", "direction", "==", "'desc'", "||", "$", "direction", "==", "'asc'", ")", "{", "$", "thi...
Sets the orderByDirection property to the specified direction. @param string $direction @return void
[ "Sets", "the", "orderByDirection", "property", "to", "the", "specified", "direction", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L586-L593
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.postCollectionModifiers
protected function postCollectionModifiers(Collection $collection) { if ($this->getOrderByField() && $this->getOrderByDirection()) { $field = $this->getOrderByField(); $desc = false; if ($this->getOrderByDirection() === 'desc') { $desc = true; } $sorted = $collection->sortBy(function ($entry) use ($field) { if (property_exists($entry, $field)) { return $entry->{$field}; } }, SORT_NATURAL, $desc); return $sorted; } return $collection; }
php
protected function postCollectionModifiers(Collection $collection) { if ($this->getOrderByField() && $this->getOrderByDirection()) { $field = $this->getOrderByField(); $desc = false; if ($this->getOrderByDirection() === 'desc') { $desc = true; } $sorted = $collection->sortBy(function ($entry) use ($field) { if (property_exists($entry, $field)) { return $entry->{$field}; } }, SORT_NATURAL, $desc); return $sorted; } return $collection; }
[ "protected", "function", "postCollectionModifiers", "(", "Collection", "$", "collection", ")", "{", "if", "(", "$", "this", "->", "getOrderByField", "(", ")", "&&", "$", "this", "->", "getOrderByDirection", "(", ")", ")", "{", "$", "field", "=", "$", "this...
Modifies and returns the collection result if modifiers are set such as an orderBy. @param Collection $collection @return Collection
[ "Modifies", "and", "returns", "the", "collection", "result", "if", "modifiers", "are", "set", "such", "as", "an", "orderBy", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L641-L661
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.getPageFromInput
protected function getPageFromInput($currentPage = null, array $options = []) { if (is_numeric($currentPage)) { return intval($currentPage); } $pageName = (array_key_exists('pageName', $options)) ? $options['pageName'] : 'page'; $page = $this->request->input($pageName); if (is_numeric($page)) { return intval($page); } return 1; }
php
protected function getPageFromInput($currentPage = null, array $options = []) { if (is_numeric($currentPage)) { return intval($currentPage); } $pageName = (array_key_exists('pageName', $options)) ? $options['pageName'] : 'page'; $page = $this->request->input($pageName); if (is_numeric($page)) { return intval($page); } return 1; }
[ "protected", "function", "getPageFromInput", "(", "$", "currentPage", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "is_numeric", "(", "$", "currentPage", ")", ")", "{", "return", "intval", "(", "$", "currentPage", ")", ...
Returns the current page from the current input. Used for pagination. @param int $currentPage @param array $options [path => '', query => [], fragment => '', pageName => ''] @return int
[ "Returns", "the", "current", "page", "from", "the", "current", "input", ".", "Used", "for", "pagination", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L671-L686
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.parseLog
protected function parseLog($content, $allowedEnvironment = null, $allowedLevel = []) { $log = []; $parsed = $this->parser->parseLogContent($content); extract($parsed, EXTR_PREFIX_ALL, 'parsed'); if (empty($parsed_headerSet)) { return $log; } $needReFormat = in_array('Next', $parsed_headerSet); $newContent = null; foreach ($parsed_headerSet as $key => $header) { if (empty($parsed_dateSet[$key])) { $parsed_dateSet[$key] = $parsed_dateSet[$key-1]; $parsed_envSet[$key] = $parsed_envSet[$key-1]; $parsed_levelSet[$key] = $parsed_levelSet[$key-1]; $header = str_replace("Next", $parsed_headerSet[$key-1], $header); } $newContent .= $header.' '.$parsed_bodySet[$key]; if ((empty($allowedEnvironment) || $allowedEnvironment == $parsed_envSet[$key]) && $this->levelable->filter($parsed_levelSet[$key], $allowedLevel)) { $log[] = [ 'environment' => $parsed_envSet[$key], 'level' => $parsed_levelSet[$key], 'date' => $parsed_dateSet[$key], 'file_path' => $this->getCurrentLogPath(), 'header' => $header, 'body' => $parsed_bodySet[$key] ]; } } if ($needReFormat) { file_put_contents($this->getCurrentLogPath(), $newContent); } return $log; }
php
protected function parseLog($content, $allowedEnvironment = null, $allowedLevel = []) { $log = []; $parsed = $this->parser->parseLogContent($content); extract($parsed, EXTR_PREFIX_ALL, 'parsed'); if (empty($parsed_headerSet)) { return $log; } $needReFormat = in_array('Next', $parsed_headerSet); $newContent = null; foreach ($parsed_headerSet as $key => $header) { if (empty($parsed_dateSet[$key])) { $parsed_dateSet[$key] = $parsed_dateSet[$key-1]; $parsed_envSet[$key] = $parsed_envSet[$key-1]; $parsed_levelSet[$key] = $parsed_levelSet[$key-1]; $header = str_replace("Next", $parsed_headerSet[$key-1], $header); } $newContent .= $header.' '.$parsed_bodySet[$key]; if ((empty($allowedEnvironment) || $allowedEnvironment == $parsed_envSet[$key]) && $this->levelable->filter($parsed_levelSet[$key], $allowedLevel)) { $log[] = [ 'environment' => $parsed_envSet[$key], 'level' => $parsed_levelSet[$key], 'date' => $parsed_dateSet[$key], 'file_path' => $this->getCurrentLogPath(), 'header' => $header, 'body' => $parsed_bodySet[$key] ]; } } if ($needReFormat) { file_put_contents($this->getCurrentLogPath(), $newContent); } return $log; }
[ "protected", "function", "parseLog", "(", "$", "content", ",", "$", "allowedEnvironment", "=", "null", ",", "$", "allowedLevel", "=", "[", "]", ")", "{", "$", "log", "=", "[", "]", ";", "$", "parsed", "=", "$", "this", "->", "parser", "->", "parseLog...
Parses the content of the file separating the errors into a single array. @param string $content @param string $allowedEnvironment @param array $allowedLevel @return array
[ "Parses", "the", "content", "of", "the", "file", "separating", "the", "errors", "into", "a", "single", "array", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L697-L739
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogReader.php
LogReader.getLogFileList
protected function getLogFileList($forceName = null) { $path = $this->getLogPath(); if (is_dir($path)) { /* * Matches files in the log directory with the special name' */ $logPath = sprintf('%s%s%s', $path, DIRECTORY_SEPARATOR, $this->getLogFilename()); /* * Force matches all files in the log directory' */ if (!is_null($forceName)) { $logPath = sprintf('%s%s%s', $path, DIRECTORY_SEPARATOR, $forceName); } return glob($logPath, GLOB_BRACE); } return false; }
php
protected function getLogFileList($forceName = null) { $path = $this->getLogPath(); if (is_dir($path)) { /* * Matches files in the log directory with the special name' */ $logPath = sprintf('%s%s%s', $path, DIRECTORY_SEPARATOR, $this->getLogFilename()); /* * Force matches all files in the log directory' */ if (!is_null($forceName)) { $logPath = sprintf('%s%s%s', $path, DIRECTORY_SEPARATOR, $forceName); } return glob($logPath, GLOB_BRACE); } return false; }
[ "protected", "function", "getLogFileList", "(", "$", "forceName", "=", "null", ")", "{", "$", "path", "=", "$", "this", "->", "getLogPath", "(", ")", ";", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "/*\n * Matches files in the log dire...
Returns an array of log file paths. @param null|string $forceName @return bool|array
[ "Returns", "an", "array", "of", "log", "file", "paths", "." ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogReader.php#L774-L796
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogParser.php
LogParser.parseLogContent
public function parseLogContent($content) { $headerSet = $dateSet = $envSet = $levelSet = $bodySet = []; $pattern = "/^" .self::LOG_DATE_PATTERN. "\s" .self::LOG_ENVIRONMENT_PATTERN. "\." .self::LOG_LEVEL_PATTERN. "\:|Next/m"; preg_match_all($pattern, $content, $matchs); if (is_array($matchs)) { $bodySet = array_map('ltrim', preg_split($pattern, $content)); if (empty($bodySet[0]) && count($bodySet) > count($matchs[0])) { array_shift($bodySet); } $headerSet = $matchs[0]; $dateSet = $matchs[1]; $envSet = $matchs[2]; $levelSet = $matchs[3]; $bodySet = $bodySet; } return compact('headerSet', 'dateSet', 'envSet', 'levelSet', 'bodySet'); }
php
public function parseLogContent($content) { $headerSet = $dateSet = $envSet = $levelSet = $bodySet = []; $pattern = "/^" .self::LOG_DATE_PATTERN. "\s" .self::LOG_ENVIRONMENT_PATTERN. "\." .self::LOG_LEVEL_PATTERN. "\:|Next/m"; preg_match_all($pattern, $content, $matchs); if (is_array($matchs)) { $bodySet = array_map('ltrim', preg_split($pattern, $content)); if (empty($bodySet[0]) && count($bodySet) > count($matchs[0])) { array_shift($bodySet); } $headerSet = $matchs[0]; $dateSet = $matchs[1]; $envSet = $matchs[2]; $levelSet = $matchs[3]; $bodySet = $bodySet; } return compact('headerSet', 'dateSet', 'envSet', 'levelSet', 'bodySet'); }
[ "public", "function", "parseLogContent", "(", "$", "content", ")", "{", "$", "headerSet", "=", "$", "dateSet", "=", "$", "envSet", "=", "$", "levelSet", "=", "$", "bodySet", "=", "[", "]", ";", "$", "pattern", "=", "\"/^\"", ".", "self", "::", "LOG_D...
Parses content of the log file into an array containing the necessary information @param string $content @return array Structure is ['headerSet' => [], 'dateSet' => [], 'envSet' => [], 'levelSet' => [], 'bodySet' => []]
[ "Parses", "content", "of", "the", "log", "file", "into", "an", "array", "containing", "the", "necessary", "information" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogParser.php#L33-L56
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogParser.php
LogParser.parseLogBody
public function parseLogBody($content) { $pattern = "/^".self::STACK_TRACE_DIVIDER_PATTERN."/m"; $parts = array_map('ltrim', preg_split($pattern, $content)); $context = $parts[0]; $stack_traces = (isset($parts[1])) ? $parts[1] : null; return compact('context', 'stack_traces'); }
php
public function parseLogBody($content) { $pattern = "/^".self::STACK_TRACE_DIVIDER_PATTERN."/m"; $parts = array_map('ltrim', preg_split($pattern, $content)); $context = $parts[0]; $stack_traces = (isset($parts[1])) ? $parts[1] : null; return compact('context', 'stack_traces'); }
[ "public", "function", "parseLogBody", "(", "$", "content", ")", "{", "$", "pattern", "=", "\"/^\"", ".", "self", "::", "STACK_TRACE_DIVIDER_PATTERN", ".", "\"/m\"", ";", "$", "parts", "=", "array_map", "(", "'ltrim'", ",", "preg_split", "(", "$", "pattern", ...
Parses the body part of the log entry into an array containing the necessary information @param string $content @return array Structure is ['context' => '', 'stack_traces' => '']
[ "Parses", "the", "body", "part", "of", "the", "log", "entry", "into", "an", "array", "containing", "the", "necessary", "information" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogParser.php#L65-L73
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogParser.php
LogParser.parseLogContext
public function parseLogContext($content) { $content = trim($content); $pattern = "/^".self::CONTEXT_EXCEPTION_PATTERN.self::CONTEXT_MESSAGE_PATTERN.self::CONTEXT_IN_PATTERN."$/ms"; preg_match($pattern, $content, $matchs); $exception = isset($matchs[1]) ? $matchs[1] : null; $message = isset($matchs[2]) ? $matchs[3] : $content; $in = isset($matchs[4]) ? $matchs[4] : null; $line = isset($matchs[5]) ? $matchs[5] : null; return compact('message', 'exception', 'in', 'line'); }
php
public function parseLogContext($content) { $content = trim($content); $pattern = "/^".self::CONTEXT_EXCEPTION_PATTERN.self::CONTEXT_MESSAGE_PATTERN.self::CONTEXT_IN_PATTERN."$/ms"; preg_match($pattern, $content, $matchs); $exception = isset($matchs[1]) ? $matchs[1] : null; $message = isset($matchs[2]) ? $matchs[3] : $content; $in = isset($matchs[4]) ? $matchs[4] : null; $line = isset($matchs[5]) ? $matchs[5] : null; return compact('message', 'exception', 'in', 'line'); }
[ "public", "function", "parseLogContext", "(", "$", "content", ")", "{", "$", "content", "=", "trim", "(", "$", "content", ")", ";", "$", "pattern", "=", "\"/^\"", ".", "self", "::", "CONTEXT_EXCEPTION_PATTERN", ".", "self", "::", "CONTEXT_MESSAGE_PATTERN", "...
Parses the context part of the log entry into an array containing the necessary information @param string $content @return array Structure is ['message' => '', 'exception' => '', 'in' => '', 'line' => '']
[ "Parses", "the", "context", "part", "of", "the", "log", "entry", "into", "an", "array", "containing", "the", "necessary", "information" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogParser.php#L82-L95
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogParser.php
LogParser.parseStackTrace
public function parseStackTrace($content) { $content = trim($content); $pattern = "/^".self::STACK_TRACE_INDEX_PATTERN."/m"; if (empty($content)) { return []; } $traces = preg_split($pattern, $content); if (empty($trace[0])) { array_shift($traces); } return $traces; }
php
public function parseStackTrace($content) { $content = trim($content); $pattern = "/^".self::STACK_TRACE_INDEX_PATTERN."/m"; if (empty($content)) { return []; } $traces = preg_split($pattern, $content); if (empty($trace[0])) { array_shift($traces); } return $traces; }
[ "public", "function", "parseStackTrace", "(", "$", "content", ")", "{", "$", "content", "=", "trim", "(", "$", "content", ")", ";", "$", "pattern", "=", "\"/^\"", ".", "self", "::", "STACK_TRACE_INDEX_PATTERN", ".", "\"/m\"", ";", "if", "(", "empty", "("...
Parses the stack trace part of the log entry into an array containing the necessary information @param string $content @return array
[ "Parses", "the", "stack", "trace", "part", "of", "the", "log", "entry", "into", "an", "array", "containing", "the", "necessary", "information" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogParser.php#L104-L120
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/LogParser.php
LogParser.parseTraceEntry
public function parseTraceEntry($content) { $content = trim($content); $caught_at = $content; $in = $line = null; if (!empty($content) && preg_match("/.*".self::TRACE_IN_DIVIDER_PATTERN.".*/", $content)) { $split = array_map('trim', preg_split("/".self::TRACE_IN_DIVIDER_PATTERN."/", $content)); $in = trim($split[0]); $caught_at = (isset($split[1])) ? $split[1] : null; if (preg_match("/^".self::TRACE_FILE_PATTERN."$/", $in, $matchs)) { $in = trim($matchs[1]); $line = $matchs[2]; } } return compact('caught_at', 'in', 'line'); }
php
public function parseTraceEntry($content) { $content = trim($content); $caught_at = $content; $in = $line = null; if (!empty($content) && preg_match("/.*".self::TRACE_IN_DIVIDER_PATTERN.".*/", $content)) { $split = array_map('trim', preg_split("/".self::TRACE_IN_DIVIDER_PATTERN."/", $content)); $in = trim($split[0]); $caught_at = (isset($split[1])) ? $split[1] : null; if (preg_match("/^".self::TRACE_FILE_PATTERN."$/", $in, $matchs)) { $in = trim($matchs[1]); $line = $matchs[2]; } } return compact('caught_at', 'in', 'line'); }
[ "public", "function", "parseTraceEntry", "(", "$", "content", ")", "{", "$", "content", "=", "trim", "(", "$", "content", ")", ";", "$", "caught_at", "=", "$", "content", ";", "$", "in", "=", "$", "line", "=", "null", ";", "if", "(", "!", "empty", ...
Parses the content of the trace entry into an array containing the necessary information @param string $content @return array Structure is ['caught_at' => '', 'in' => '', 'line' => '']
[ "Parses", "the", "content", "of", "the", "trace", "entry", "into", "an", "array", "containing", "the", "necessary", "information" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/LogParser.php#L129-L149
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Console/Traits/SetLogReaderParamTrait.php
SetLogReaderParamTrait.setLogReaderParam
protected function setLogReaderParam() { if (array_key_exists('log-path', $this->option()) && ! empty($this->option('log-path'))) { $this->reader->setLogPath($this->option('log-path')); } if (array_key_exists('order-by', $this->option()) && ! empty($this->option('order-by'))) { if (array_key_exists('order-direction', $this->option()) && ! empty($this->option('order-direction'))) { $this->reader->orderBy($this->option('order-by'), $this->option('order-direction')); } else { $this->reader->orderBy($this->option('order-by')); } } if (array_key_exists('with-read', $this->option()) && $this->option('with-read')) { $this->reader->withRead(); } if (array_key_exists('file-name', $this->option())) { $this->reader->filename($this->option('file-name')); } if (array_key_exists('env', $this->option())) { $this->reader->environment($this->option('env')); } if (array_key_exists('level', $this->option())) { $this->reader->level($this->option('level')); } }
php
protected function setLogReaderParam() { if (array_key_exists('log-path', $this->option()) && ! empty($this->option('log-path'))) { $this->reader->setLogPath($this->option('log-path')); } if (array_key_exists('order-by', $this->option()) && ! empty($this->option('order-by'))) { if (array_key_exists('order-direction', $this->option()) && ! empty($this->option('order-direction'))) { $this->reader->orderBy($this->option('order-by'), $this->option('order-direction')); } else { $this->reader->orderBy($this->option('order-by')); } } if (array_key_exists('with-read', $this->option()) && $this->option('with-read')) { $this->reader->withRead(); } if (array_key_exists('file-name', $this->option())) { $this->reader->filename($this->option('file-name')); } if (array_key_exists('env', $this->option())) { $this->reader->environment($this->option('env')); } if (array_key_exists('level', $this->option())) { $this->reader->level($this->option('level')); } }
[ "protected", "function", "setLogReaderParam", "(", ")", "{", "if", "(", "array_key_exists", "(", "'log-path'", ",", "$", "this", "->", "option", "(", ")", ")", "&&", "!", "empty", "(", "$", "this", "->", "option", "(", "'log-path'", ")", ")", ")", "{",...
Set parameters for LogReader @return void
[ "Set", "parameters", "for", "LogReader" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Console/Traits/SetLogReaderParamTrait.php#L10-L39
train
JackieDo/Laravel-Log-Reader
src/Jackiedo/LogReader/Console/Commands/LogReaderGetCommand.php
LogReaderGetCommand.getLogEntries
protected function getLogEntries() { if ($this->option('paginate')) { $logs = $this->reader->paginate($this->option('per-page'), $this->option('page')); $total = $logs->total(); $this->line("You have total ".$total." log ".(($total > 1) ? 'entries' : 'entry')."."); $this->line("You are viewing page ".$logs->currentPage()."/".$logs->lastPage()." as follow:\r\n"); } else { $logs = $this->reader->get(); $total = $logs->count(); $this->line("You have total ".$total." log ".(($total > 1) ? 'entries' : 'entry')." as follow:\r\n"); } return $logs; }
php
protected function getLogEntries() { if ($this->option('paginate')) { $logs = $this->reader->paginate($this->option('per-page'), $this->option('page')); $total = $logs->total(); $this->line("You have total ".$total." log ".(($total > 1) ? 'entries' : 'entry')."."); $this->line("You are viewing page ".$logs->currentPage()."/".$logs->lastPage()." as follow:\r\n"); } else { $logs = $this->reader->get(); $total = $logs->count(); $this->line("You have total ".$total." log ".(($total > 1) ? 'entries' : 'entry')." as follow:\r\n"); } return $logs; }
[ "protected", "function", "getLogEntries", "(", ")", "{", "if", "(", "$", "this", "->", "option", "(", "'paginate'", ")", ")", "{", "$", "logs", "=", "$", "this", "->", "reader", "->", "paginate", "(", "$", "this", "->", "option", "(", "'per-page'", "...
Reading log files and get log entries @return mixed
[ "Reading", "log", "files", "and", "get", "log", "entries" ]
10c6b52b52cde4250e40bae83d7a17f0532adfc2
https://github.com/JackieDo/Laravel-Log-Reader/blob/10c6b52b52cde4250e40bae83d7a17f0532adfc2/src/Jackiedo/LogReader/Console/Commands/LogReaderGetCommand.php#L60-L76
train
silinternational/email-service-php-client
src/EmailServiceClient.php
EmailServiceClient.email
public function email(array $config = []) { $result = $this->emailInternal($config); $statusCode = (int)$result['statusCode']; if ($statusCode >= 200 && $statusCode < 300) { return $this->getResultAsArrayWithoutStatusCode($result); } $this->reportUnexpectedResponse($result, 1503511660); }
php
public function email(array $config = []) { $result = $this->emailInternal($config); $statusCode = (int)$result['statusCode']; if ($statusCode >= 200 && $statusCode < 300) { return $this->getResultAsArrayWithoutStatusCode($result); } $this->reportUnexpectedResponse($result, 1503511660); }
[ "public", "function", "email", "(", "array", "$", "config", "=", "[", "]", ")", "{", "$", "result", "=", "$", "this", "->", "emailInternal", "(", "$", "config", ")", ";", "$", "statusCode", "=", "(", "int", ")", "$", "result", "[", "'statusCode'", ...
Create an email with the given information. @param array $config An array key/value pairs of attributes for the new email. @return array An array of information about the email. @throws EmailServiceClientException
[ "Create", "an", "email", "with", "the", "given", "information", "." ]
02f438d133a2ccbf057a6d4d24b8fcdab8c2d63e
https://github.com/silinternational/email-service-php-client/blob/02f438d133a2ccbf057a6d4d24b8fcdab8c2d63e/src/EmailServiceClient.php#L148-L158
train
silinternational/email-service-php-client
src/EmailServiceClient.php
EmailServiceClient.assertTrustedIp
private function assertTrustedIp() { $baseHost = parse_url($this->serviceUri, PHP_URL_HOST); $serviceIp = gethostbyname( $baseHost ); if ( ! $this->isTrustedIpAddress($serviceIp)) { throw new EmailServiceClientException( 'The service has an IP that is not trusted ... ' . $serviceIp, 1503511662 ); } }
php
private function assertTrustedIp() { $baseHost = parse_url($this->serviceUri, PHP_URL_HOST); $serviceIp = gethostbyname( $baseHost ); if ( ! $this->isTrustedIpAddress($serviceIp)) { throw new EmailServiceClientException( 'The service has an IP that is not trusted ... ' . $serviceIp, 1503511662 ); } }
[ "private", "function", "assertTrustedIp", "(", ")", "{", "$", "baseHost", "=", "parse_url", "(", "$", "this", "->", "serviceUri", ",", "PHP_URL_HOST", ")", ";", "$", "serviceIp", "=", "gethostbyname", "(", "$", "baseHost", ")", ";", "if", "(", "!", "$", ...
Determine whether any of the service's IPs are not in the trusted ranges @throws Exception
[ "Determine", "whether", "any", "of", "the", "service", "s", "IPs", "are", "not", "in", "the", "trusted", "ranges" ]
02f438d133a2ccbf057a6d4d24b8fcdab8c2d63e
https://github.com/silinternational/email-service-php-client/blob/02f438d133a2ccbf057a6d4d24b8fcdab8c2d63e/src/EmailServiceClient.php#L207-L220
train
silinternational/email-service-php-client
src/EmailServiceClient.php
EmailServiceClient.isTrustedIpAddress
private function isTrustedIpAddress($ipAddress) { foreach ($this->trustedIpRanges as $trustedIpBlock) { if ($trustedIpBlock->containsIP($ipAddress)) { return true; } } return false; }
php
private function isTrustedIpAddress($ipAddress) { foreach ($this->trustedIpRanges as $trustedIpBlock) { if ($trustedIpBlock->containsIP($ipAddress)) { return true; } } return false; }
[ "private", "function", "isTrustedIpAddress", "(", "$", "ipAddress", ")", "{", "foreach", "(", "$", "this", "->", "trustedIpRanges", "as", "$", "trustedIpBlock", ")", "{", "if", "(", "$", "trustedIpBlock", "->", "containsIP", "(", "$", "ipAddress", ")", ")", ...
Determine whether the service's IP address is in a trusted range. @param string $ipAddress The IP address in question. @return bool
[ "Determine", "whether", "the", "service", "s", "IP", "address", "is", "in", "a", "trusted", "range", "." ]
02f438d133a2ccbf057a6d4d24b8fcdab8c2d63e
https://github.com/silinternational/email-service-php-client/blob/02f438d133a2ccbf057a6d4d24b8fcdab8c2d63e/src/EmailServiceClient.php#L228-L237
train
QoboLtd/qobo-robo
src/Command/Mysql/DbFindReplace.php
DbFindReplace.mysqlDbFindReplace
public function mysqlDbFindReplace( $search, $replace, $db, $user = 'root', $pass = '', $host = 'localhost', $port = null, $opts = ['format' => 'table', 'fields' => ''] ) { $result = $this->taskMysqlDbFindReplace() ->search($search) ->replace($replace) ->db($db) ->user($user) ->pass($pass) ->host($host) ->port($port) ->hide($pass) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
php
public function mysqlDbFindReplace( $search, $replace, $db, $user = 'root', $pass = '', $host = 'localhost', $port = null, $opts = ['format' => 'table', 'fields' => ''] ) { $result = $this->taskMysqlDbFindReplace() ->search($search) ->replace($replace) ->db($db) ->user($user) ->pass($pass) ->host($host) ->port($port) ->hide($pass) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
[ "public", "function", "mysqlDbFindReplace", "(", "$", "search", ",", "$", "replace", ",", "$", "db", ",", "$", "user", "=", "'root'", ",", "$", "pass", "=", "''", ",", "$", "host", "=", "'localhost'", ",", "$", "port", "=", "null", ",", "$", "opts"...
Run find-replace on MySQL database @param string $search Search string @param string $replace Replacement string @param string $db Database name @param string $user MySQL user to bind with @param string $pass (Optional) MySQL user password @param string $host (Optional) MySQL server host @param string $port (Optional) MySQL server port @option string $format Output format (table, list, csv, json, xml) @option string $fields Limit output to given fields, comma-separated @return bool
[ "Run", "find", "-", "replace", "on", "MySQL", "database" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Command/Mysql/DbFindReplace.php#L34-L60
train
doganoo/PHPUtil
src/Util/DateTimeUtil.php
DateTimeUtil.valid
public static function valid(string $date, string $format): bool { return date($format, strtotime($date)) === $date; }
php
public static function valid(string $date, string $format): bool { return date($format, strtotime($date)) === $date; }
[ "public", "static", "function", "valid", "(", "string", "$", "date", ",", "string", "$", "format", ")", ":", "bool", "{", "return", "date", "(", "$", "format", ",", "strtotime", "(", "$", "date", ")", ")", "===", "$", "date", ";", "}" ]
Whether string is a valid date or not @param string $date @param string $format @return bool
[ "Whether", "string", "is", "a", "valid", "date", "or", "not" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Util/DateTimeUtil.php#L85-L88
train
orchestral/support
src/Support/Transformer.php
Transformer.handle
public function handle($instance) { if ($instance instanceof Paginator) { return $instance->setCollection( $instance->getCollection()->transform($this) ); } elseif ($instance instanceof Transformable || $instance instanceof BaseCollection) { $transformable = $instance; } elseif ($instance instanceof BaseFluent) { $transformable = new Fluent($instance->getAttributes()); } else { throw new InvalidArgumentException("Unable to transform {get_class($instance)}."); } return $transformable->transform($this); }
php
public function handle($instance) { if ($instance instanceof Paginator) { return $instance->setCollection( $instance->getCollection()->transform($this) ); } elseif ($instance instanceof Transformable || $instance instanceof BaseCollection) { $transformable = $instance; } elseif ($instance instanceof BaseFluent) { $transformable = new Fluent($instance->getAttributes()); } else { throw new InvalidArgumentException("Unable to transform {get_class($instance)}."); } return $transformable->transform($this); }
[ "public", "function", "handle", "(", "$", "instance", ")", "{", "if", "(", "$", "instance", "instanceof", "Paginator", ")", "{", "return", "$", "instance", "->", "setCollection", "(", "$", "instance", "->", "getCollection", "(", ")", "->", "transform", "("...
Handle transformation. @param mixed $instance @return mixed
[ "Handle", "transformation", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Transformer.php#L20-L35
train
doganoo/PHPUtil
src/Util/StringUtil.php
StringUtil.stringToArray
public static function stringToArray(?string $string): array { $result = []; $strLen = \strlen($string); if (null === $string) return $result; if (1 === $strLen) { $result[] = $string; return $result; } for ($i = 0; $i < $strLen; $i++) { $result[] = $string[$i]; } return $result; }
php
public static function stringToArray(?string $string): array { $result = []; $strLen = \strlen($string); if (null === $string) return $result; if (1 === $strLen) { $result[] = $string; return $result; } for ($i = 0; $i < $strLen; $i++) { $result[] = $string[$i]; } return $result; }
[ "public", "static", "function", "stringToArray", "(", "?", "string", "$", "string", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "$", "strLen", "=", "\\", "strlen", "(", "$", "string", ")", ";", "if", "(", "null", "===", "$", "string"...
returns an array of elements of the string @param null|string $string @return array
[ "returns", "an", "array", "of", "elements", "of", "the", "string" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Util/StringUtil.php#L45-L57
train
QoboLtd/qobo-robo
src/Runner.php
Runner.handleError
public function handleError() { // get error info list ($errno, $message, $file, $line) = func_get_args(); // construct error message $msg = "ERROR ($errno): $message"; if ($line !== null) { $file = "$file:$line"; } if ($file !== null) { $msg .= " [$file]"; } static::$lastErrno = $errno; // throw the exception throw new RuntimeException($msg, $errno); }
php
public function handleError() { // get error info list ($errno, $message, $file, $line) = func_get_args(); // construct error message $msg = "ERROR ($errno): $message"; if ($line !== null) { $file = "$file:$line"; } if ($file !== null) { $msg .= " [$file]"; } static::$lastErrno = $errno; // throw the exception throw new RuntimeException($msg, $errno); }
[ "public", "function", "handleError", "(", ")", "{", "// get error info", "list", "(", "$", "errno", ",", "$", "message", ",", "$", "file", ",", "$", "line", ")", "=", "func_get_args", "(", ")", ";", "// construct error message", "$", "msg", "=", "\"ERROR (...
Custom error handler that will throw an exception on any errors
[ "Custom", "error", "handler", "that", "will", "throw", "an", "exception", "on", "any", "errors" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Runner.php#L48-L67
train
emgiezet/errbitPHP
src/Errbit/Exception/Notice.php
Notice.buildRequestUrl
private function buildRequestUrl() { if (!empty($_SERVER['REQUEST_URI'])) { return sprintf( '%s://%s%s%s', $this->guessProtocol(), $this->guessHost(), $this->guessPort(), $_SERVER['REQUEST_URI'] ); } }
php
private function buildRequestUrl() { if (!empty($_SERVER['REQUEST_URI'])) { return sprintf( '%s://%s%s%s', $this->guessProtocol(), $this->guessHost(), $this->guessPort(), $_SERVER['REQUEST_URI'] ); } }
[ "private", "function", "buildRequestUrl", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ")", "{", "return", "sprintf", "(", "'%s://%s%s%s'", ",", "$", "this", "->", "guessProtocol", "(", ")", ",", "$", "th...
Building request url @return string url
[ "Building", "request", "url" ]
cc634f8d6b0d2cd4a29648662119310afc73fa7b
https://github.com/emgiezet/errbitPHP/blob/cc634f8d6b0d2cd4a29648662119310afc73fa7b/src/Errbit/Exception/Notice.php#L397-L408
train
doganoo/PHPUtil
src/FileSystem/DirHandler.php
DirHandler._list
private function _list(string $path): array { $result = []; $scan = glob($path . '/*'); foreach ($scan as $item) { if (is_dir($item)) { $result[basename($item)] = $this->_list($item); } else { $result[] = basename($item); } } return $result; }
php
private function _list(string $path): array { $result = []; $scan = glob($path . '/*'); foreach ($scan as $item) { if (is_dir($item)) { $result[basename($item)] = $this->_list($item); } else { $result[] = basename($item); } } return $result; }
[ "private", "function", "_list", "(", "string", "$", "path", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "$", "scan", "=", "glob", "(", "$", "path", ".", "'/*'", ")", ";", "foreach", "(", "$", "scan", "as", "$", "item", ")", "{", ...
lists every item in a given dir see here: https://stackoverflow.com/a/49066335/1966490 @param string $path @return array
[ "lists", "every", "item", "in", "a", "given", "dir" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/FileSystem/DirHandler.php#L112-L123
train
doganoo/PHPUtil
src/FileSystem/DirHandler.php
DirHandler._findFile
private function _findFile(string $dirName, string $fileName): ?FileHandler { $dirs = glob($dirName . '*'); $file = null; foreach ($dirs as $d) { if (is_file($d)) { $pathInfo = \pathinfo($d); $pathInfo2 = \pathinfo($fileName); if (isset($pathInfo2["extension"])) { $condition = $pathInfo["basename"] === $pathInfo2["basename"]; } else { $condition = $pathInfo["filename"] === $pathInfo2["filename"]; } if ($condition) { return new FileHandler($dirName . "/" . $pathInfo["basename"]); } } else if (is_dir($d)) { $tmp = $this->_findFile($d . "/", $fileName); if (null !== $tmp) { $file = $tmp; } } } return $file; }
php
private function _findFile(string $dirName, string $fileName): ?FileHandler { $dirs = glob($dirName . '*'); $file = null; foreach ($dirs as $d) { if (is_file($d)) { $pathInfo = \pathinfo($d); $pathInfo2 = \pathinfo($fileName); if (isset($pathInfo2["extension"])) { $condition = $pathInfo["basename"] === $pathInfo2["basename"]; } else { $condition = $pathInfo["filename"] === $pathInfo2["filename"]; } if ($condition) { return new FileHandler($dirName . "/" . $pathInfo["basename"]); } } else if (is_dir($d)) { $tmp = $this->_findFile($d . "/", $fileName); if (null !== $tmp) { $file = $tmp; } } } return $file; }
[ "private", "function", "_findFile", "(", "string", "$", "dirName", ",", "string", "$", "fileName", ")", ":", "?", "FileHandler", "{", "$", "dirs", "=", "glob", "(", "$", "dirName", ".", "'*'", ")", ";", "$", "file", "=", "null", ";", "foreach", "(", ...
finds a file in the given dir @param $dirName @param $fileName @return string
[ "finds", "a", "file", "in", "the", "given", "dir" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/FileSystem/DirHandler.php#L193-L218
train
doganoo/PHPUtil
src/Util/ArrayUtil.php
ArrayUtil.hasSum
public static function hasSum(array $numbers, int $target): bool { $collection = ArrayUtil::sumCollection($numbers, $target); if (null === $collection) return false; if (0 === \count($collection)) return false; return true; }
php
public static function hasSum(array $numbers, int $target): bool { $collection = ArrayUtil::sumCollection($numbers, $target); if (null === $collection) return false; if (0 === \count($collection)) return false; return true; }
[ "public", "static", "function", "hasSum", "(", "array", "$", "numbers", ",", "int", "$", "target", ")", ":", "bool", "{", "$", "collection", "=", "ArrayUtil", "::", "sumCollection", "(", "$", "numbers", ",", "$", "target", ")", ";", "if", "(", "null", ...
returns a boolean that indicates whether a sequence sums up to a value or not @param array $numbers @param int $target @return bool
[ "returns", "a", "boolean", "that", "indicates", "whether", "a", "sequence", "sums", "up", "to", "a", "value", "or", "not" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Util/ArrayUtil.php#L67-L72
train
nails/module-invoice
src/Factory/ChargeRequest.php
ChargeRequest.setCardNumber
public function setCardNumber($sCardNumber) { // Validate if (preg_match('/[^\d ]/', $sCardNumber)) { throw new ChargeRequestException('Invalid card number; can only contain digits and spaces.', 1); } $this->oCard->number = $sCardNumber; return $this; }
php
public function setCardNumber($sCardNumber) { // Validate if (preg_match('/[^\d ]/', $sCardNumber)) { throw new ChargeRequestException('Invalid card number; can only contain digits and spaces.', 1); } $this->oCard->number = $sCardNumber; return $this; }
[ "public", "function", "setCardNumber", "(", "$", "sCardNumber", ")", "{", "// Validate", "if", "(", "preg_match", "(", "'/[^\\d ]/'", ",", "$", "sCardNumber", ")", ")", "{", "throw", "new", "ChargeRequestException", "(", "'Invalid card number; can only contain digits...
Set the card's number @param string $sCardNumber The card's number @throws ChargeRequestException @return $this
[ "Set", "the", "card", "s", "number" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/ChargeRequest.php#L91-L100
train
nails/module-invoice
src/Factory/ChargeRequest.php
ChargeRequest.setCardExpMonth
public function setCardExpMonth($sCardExpMonth) { // Validate if (is_numeric($sCardExpMonth)) { $iMonth = (int) $sCardExpMonth; if ($iMonth < 1 || $iMonth > 12) { throw new ChargeRequestException( '"' . $sCardExpMonth . '" is an invalid expiry month; must be in the range 1-12.', 1 ); } else { $this->oCard->exp->month = $iMonth < 10 ? '0' . $iMonth : (string) $iMonth; return $this; } } else { throw new ChargeRequestException( '"' . $sCardExpMonth . '" is an invalid expiry month; must be numeric.', 1 ); } }
php
public function setCardExpMonth($sCardExpMonth) { // Validate if (is_numeric($sCardExpMonth)) { $iMonth = (int) $sCardExpMonth; if ($iMonth < 1 || $iMonth > 12) { throw new ChargeRequestException( '"' . $sCardExpMonth . '" is an invalid expiry month; must be in the range 1-12.', 1 ); } else { $this->oCard->exp->month = $iMonth < 10 ? '0' . $iMonth : (string) $iMonth; return $this; } } else { throw new ChargeRequestException( '"' . $sCardExpMonth . '" is an invalid expiry month; must be numeric.', 1 ); } }
[ "public", "function", "setCardExpMonth", "(", "$", "sCardExpMonth", ")", "{", "// Validate", "if", "(", "is_numeric", "(", "$", "sCardExpMonth", ")", ")", "{", "$", "iMonth", "=", "(", "int", ")", "$", "sCardExpMonth", ";", "if", "(", "$", "iMonth", "<"...
Set the card's expiry month @param string $sCardExpMonth The card's expiry month @throws ChargeRequestException @return $this
[ "Set", "the", "card", "s", "expiry", "month" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/ChargeRequest.php#L123-L147
train
nails/module-invoice
src/Factory/ChargeRequest.php
ChargeRequest.setCardExpYear
public function setCardExpYear($sCardExpYear) { // Validate if (is_numeric($sCardExpYear)) { // Accept two digits or 4 digits only if (strlen($sCardExpYear) == 2 || strlen($sCardExpYear) == 4) { // Two digit values should be turned into a 4 digit value if (strlen($sCardExpYear) == 2) { // Sorry people living in the 2100's, I'm very sorry everything is broken. $sCardExpYear = '20' . $sCardExpYear; } $iYear = (int) $sCardExpYear; $oNow = Factory::factory('DateTime'); if ($oNow->format('Y') > $iYear) { throw new ChargeRequestException( '"' . $sCardExpYear . '" is an invalid expiry year; must be ' . $oNow->format('Y') . ' or later.', 1 ); } $this->oCard->exp->year = (string) $iYear; return $this; } else { throw new ChargeRequestException( '"' . $sCardExpYear . '" is an invalid expiry year; must be 2 or 4 digits.', 1 ); } } else { throw new ChargeRequestException( '"' . $sCardExpYear . '" is an invalid expiry year; must be numeric.', 1 ); } }
php
public function setCardExpYear($sCardExpYear) { // Validate if (is_numeric($sCardExpYear)) { // Accept two digits or 4 digits only if (strlen($sCardExpYear) == 2 || strlen($sCardExpYear) == 4) { // Two digit values should be turned into a 4 digit value if (strlen($sCardExpYear) == 2) { // Sorry people living in the 2100's, I'm very sorry everything is broken. $sCardExpYear = '20' . $sCardExpYear; } $iYear = (int) $sCardExpYear; $oNow = Factory::factory('DateTime'); if ($oNow->format('Y') > $iYear) { throw new ChargeRequestException( '"' . $sCardExpYear . '" is an invalid expiry year; must be ' . $oNow->format('Y') . ' or later.', 1 ); } $this->oCard->exp->year = (string) $iYear; return $this; } else { throw new ChargeRequestException( '"' . $sCardExpYear . '" is an invalid expiry year; must be 2 or 4 digits.', 1 ); } } else { throw new ChargeRequestException( '"' . $sCardExpYear . '" is an invalid expiry year; must be numeric.', 1 ); } }
[ "public", "function", "setCardExpYear", "(", "$", "sCardExpYear", ")", "{", "// Validate", "if", "(", "is_numeric", "(", "$", "sCardExpYear", ")", ")", "{", "// Accept two digits or 4 digits only", "if", "(", "strlen", "(", "$", "sCardExpYear", ")", "==", "2",...
Set the card's expiry year @param string $sCardExpYear The card's expiry year @throws ChargeRequestException @return $this
[ "Set", "the", "card", "s", "expiry", "year" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/ChargeRequest.php#L170-L211
train
nails/module-invoice
src/Factory/ChargeRequest.php
ChargeRequest.getCustomField
public function getCustomField($sProperty) { return property_exists($this->oCustomField, $sProperty) ? $this->oCustomField->{$sProperty} : null; }
php
public function getCustomField($sProperty) { return property_exists($this->oCustomField, $sProperty) ? $this->oCustomField->{$sProperty} : null; }
[ "public", "function", "getCustomField", "(", "$", "sProperty", ")", "{", "return", "property_exists", "(", "$", "this", "->", "oCustomField", ",", "$", "sProperty", ")", "?", "$", "this", "->", "oCustomField", "->", "{", "$", "sProperty", "}", ":", "null",...
Retrieve a custom field @param string $sProperty The property to retrieve @return mixed
[ "Retrieve", "a", "custom", "field" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/ChargeRequest.php#L276-L279
train
nails/module-invoice
src/Factory/ChargeRequest.php
ChargeRequest.getCustomData
public function getCustomData($sProperty) { return property_exists($this->oCustomData, $sProperty) ? $this->oCustomData->{$sProperty} : null; }
php
public function getCustomData($sProperty) { return property_exists($this->oCustomData, $sProperty) ? $this->oCustomData->{$sProperty} : null; }
[ "public", "function", "getCustomData", "(", "$", "sProperty", ")", "{", "return", "property_exists", "(", "$", "this", "->", "oCustomData", ",", "$", "sProperty", ")", "?", "$", "this", "->", "oCustomData", "->", "{", "$", "sProperty", "}", ":", "null", ...
Retrieve a custom value @param string $sProperty The property to retrieve @return mixed
[ "Retrieve", "a", "custom", "value" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/ChargeRequest.php#L306-L309
train
QoboLtd/qobo-robo
src/App.php
App.getCommands
protected function getCommands() { // construct command classes path depending on grp_cmd flag $cmdPath = rtrim(__DIR__ . "/" . $this->data['cmd_path'], '/') . '/'; $cmdPath .= ($this->data['grp_cmd']) ? "*/*.php" : "*.php"; // construct commad path regex depending on grp_cmd flag $cmdPattern = ($this->data['grp_cmd']) ? '/^.*\/([^\/]+)\/([^\/]+)\.php$/' : '/^.*\/([^\/]+)\.php$/'; // find all command files and commands $commands = []; foreach (glob($cmdPath) as $file) { // match only php files, extract group dir name if (!preg_match($cmdPattern, $file, $matches)) { continue; } // construct a class name from our namespace, optional // command group subdir and actual class file name $className = __NAMESPACE__ . "\\" . str_replace("/", "\\", $this->data['cmd_path']) . $matches[1]; $className .= ($this->data['grp_cmd']) ? "\\" . $matches[2] : ""; // skip if class doesn't exist if (!class_exists($className)) { continue; } // add to our commands list $commands []= $className; } if (!empty($this->data['config']['extra_commands']) && is_array($this->data['config']['extra_commands'])) { $commands = array_merge($commands, $this->data['config']['extra_commands']); } return $commands; }
php
protected function getCommands() { // construct command classes path depending on grp_cmd flag $cmdPath = rtrim(__DIR__ . "/" . $this->data['cmd_path'], '/') . '/'; $cmdPath .= ($this->data['grp_cmd']) ? "*/*.php" : "*.php"; // construct commad path regex depending on grp_cmd flag $cmdPattern = ($this->data['grp_cmd']) ? '/^.*\/([^\/]+)\/([^\/]+)\.php$/' : '/^.*\/([^\/]+)\.php$/'; // find all command files and commands $commands = []; foreach (glob($cmdPath) as $file) { // match only php files, extract group dir name if (!preg_match($cmdPattern, $file, $matches)) { continue; } // construct a class name from our namespace, optional // command group subdir and actual class file name $className = __NAMESPACE__ . "\\" . str_replace("/", "\\", $this->data['cmd_path']) . $matches[1]; $className .= ($this->data['grp_cmd']) ? "\\" . $matches[2] : ""; // skip if class doesn't exist if (!class_exists($className)) { continue; } // add to our commands list $commands []= $className; } if (!empty($this->data['config']['extra_commands']) && is_array($this->data['config']['extra_commands'])) { $commands = array_merge($commands, $this->data['config']['extra_commands']); } return $commands; }
[ "protected", "function", "getCommands", "(", ")", "{", "// construct command classes path depending on grp_cmd flag", "$", "cmdPath", "=", "rtrim", "(", "__DIR__", ".", "\"/\"", ".", "$", "this", "->", "data", "[", "'cmd_path'", "]", ",", "'/'", ")", ".", "'/'",...
Get list of available command classes @return array List of command classes
[ "Get", "list", "of", "available", "command", "classes" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/App.php#L112-L150
train
QoboLtd/qobo-robo
src/Command/Project/Branch.php
Branch.projectBranch
public function projectBranch($opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskProjectBranch() ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } $data = $result->getData(); return new PropertyList(['branch' => $data['data'][0]['message']]); }
php
public function projectBranch($opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskProjectBranch() ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } $data = $result->getData(); return new PropertyList(['branch' => $data['data'][0]['message']]); }
[ "public", "function", "projectBranch", "(", "$", "opts", "=", "[", "'format'", "=>", "'table'", ",", "'fields'", "=>", "''", "]", ")", "{", "$", "result", "=", "$", "this", "->", "taskProjectBranch", "(", ")", "->", "run", "(", ")", ";", "if", "(", ...
Get current project branch @return \Qobo\Robo\Formatter\PropertyList
[ "Get", "current", "project", "branch" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Command/Project/Branch.php#L24-L35
train
hiqdev/hipanel-module-domain
src/models/Domain.php
Domain.isZone
public function isZone($zones) { $zone = $this->getZone(); return is_array($zones) ? in_array($this->getZone(), $zones, true) : $zone === $zones; }
php
public function isZone($zones) { $zone = $this->getZone(); return is_array($zones) ? in_array($this->getZone(), $zones, true) : $zone === $zones; }
[ "public", "function", "isZone", "(", "$", "zones", ")", "{", "$", "zone", "=", "$", "this", "->", "getZone", "(", ")", ";", "return", "is_array", "(", "$", "zones", ")", "?", "in_array", "(", "$", "this", "->", "getZone", "(", ")", ",", "$", "zon...
a Returns true if the zone is among given list of zones. @param array|string $zones zone or list of zones @return bool
[ "a", "Returns", "true", "if", "the", "zone", "is", "among", "given", "list", "of", "zones", "." ]
b1b02782fcb69970cacafe6c6ead238b14b54209
https://github.com/hiqdev/hipanel-module-domain/blob/b1b02782fcb69970cacafe6c6ead238b14b54209/src/models/Domain.php#L707-L712
train
SimpleBus/Serialization
src/Envelope/Serializer/StandardMessageInEnvelopeSerializer.php
StandardMessageInEnvelopeSerializer.wrapAndSerialize
public function wrapAndSerialize($message) { $envelope = $this->envelopeFactory->wrapMessageInEnvelope($message); $serializedMessage = $this->objectSerializer->serialize($message); return $this->objectSerializer->serialize($envelope->withSerializedMessage($serializedMessage)); }
php
public function wrapAndSerialize($message) { $envelope = $this->envelopeFactory->wrapMessageInEnvelope($message); $serializedMessage = $this->objectSerializer->serialize($message); return $this->objectSerializer->serialize($envelope->withSerializedMessage($serializedMessage)); }
[ "public", "function", "wrapAndSerialize", "(", "$", "message", ")", "{", "$", "envelope", "=", "$", "this", "->", "envelopeFactory", "->", "wrapMessageInEnvelope", "(", "$", "message", ")", ";", "$", "serializedMessage", "=", "$", "this", "->", "objectSerializ...
Serialize a Message by wrapping it in an Envelope and serializing the envelope @{inheritdoc}
[ "Serialize", "a", "Message", "by", "wrapping", "it", "in", "an", "Envelope", "and", "serializing", "the", "envelope" ]
b69f896cfdbd798b8e83d79c6c87a051f0469183
https://github.com/SimpleBus/Serialization/blob/b69f896cfdbd798b8e83d79c6c87a051f0469183/src/Envelope/Serializer/StandardMessageInEnvelopeSerializer.php#L34-L41
train
SimpleBus/Serialization
src/Envelope/Serializer/StandardMessageInEnvelopeSerializer.php
StandardMessageInEnvelopeSerializer.unwrapAndDeserialize
public function unwrapAndDeserialize($serializedEnvelope) { $envelope = $this->deserializeEnvelope($serializedEnvelope); $message = $this->deserializeMessage($envelope->serializedMessage(), $envelope->messageType()); return $envelope->withMessage($message); }
php
public function unwrapAndDeserialize($serializedEnvelope) { $envelope = $this->deserializeEnvelope($serializedEnvelope); $message = $this->deserializeMessage($envelope->serializedMessage(), $envelope->messageType()); return $envelope->withMessage($message); }
[ "public", "function", "unwrapAndDeserialize", "(", "$", "serializedEnvelope", ")", "{", "$", "envelope", "=", "$", "this", "->", "deserializeEnvelope", "(", "$", "serializedEnvelope", ")", ";", "$", "message", "=", "$", "this", "->", "deserializeMessage", "(", ...
Deserialize a Message that was wrapped in an Envelope @{inheritdoc}
[ "Deserialize", "a", "Message", "that", "was", "wrapped", "in", "an", "Envelope" ]
b69f896cfdbd798b8e83d79c6c87a051f0469183
https://github.com/SimpleBus/Serialization/blob/b69f896cfdbd798b8e83d79c6c87a051f0469183/src/Envelope/Serializer/StandardMessageInEnvelopeSerializer.php#L48-L55
train
SimpleBus/Serialization
src/Envelope/Serializer/StandardMessageInEnvelopeSerializer.php
StandardMessageInEnvelopeSerializer.deserializeEnvelope
private function deserializeEnvelope($serializedEnvelope) { $envelopeClass = $this->envelopeFactory->envelopeClass(); $envelope = $this->objectSerializer->deserialize( $serializedEnvelope, $envelopeClass ); if (!($envelope instanceof $envelopeClass)) { throw new \LogicException( sprintf( 'Expected deserialized object to be an instance of "%s"', $envelopeClass ) ); } return $envelope; }
php
private function deserializeEnvelope($serializedEnvelope) { $envelopeClass = $this->envelopeFactory->envelopeClass(); $envelope = $this->objectSerializer->deserialize( $serializedEnvelope, $envelopeClass ); if (!($envelope instanceof $envelopeClass)) { throw new \LogicException( sprintf( 'Expected deserialized object to be an instance of "%s"', $envelopeClass ) ); } return $envelope; }
[ "private", "function", "deserializeEnvelope", "(", "$", "serializedEnvelope", ")", "{", "$", "envelopeClass", "=", "$", "this", "->", "envelopeFactory", "->", "envelopeClass", "(", ")", ";", "$", "envelope", "=", "$", "this", "->", "objectSerializer", "->", "d...
Deserialize the message Envelope @param string $serializedEnvelope @return Envelope
[ "Deserialize", "the", "message", "Envelope" ]
b69f896cfdbd798b8e83d79c6c87a051f0469183
https://github.com/SimpleBus/Serialization/blob/b69f896cfdbd798b8e83d79c6c87a051f0469183/src/Envelope/Serializer/StandardMessageInEnvelopeSerializer.php#L63-L81
train
SimpleBus/Serialization
src/Envelope/Serializer/StandardMessageInEnvelopeSerializer.php
StandardMessageInEnvelopeSerializer.deserializeMessage
private function deserializeMessage($serializedMessage, $messageClass) { $message = $this->objectSerializer->deserialize($serializedMessage, $messageClass); if (!($message instanceof $messageClass)) { throw new \LogicException( sprintf( 'Expected deserialized message to be an instance of "%s"', $messageClass ) ); } return $message; }
php
private function deserializeMessage($serializedMessage, $messageClass) { $message = $this->objectSerializer->deserialize($serializedMessage, $messageClass); if (!($message instanceof $messageClass)) { throw new \LogicException( sprintf( 'Expected deserialized message to be an instance of "%s"', $messageClass ) ); } return $message; }
[ "private", "function", "deserializeMessage", "(", "$", "serializedMessage", ",", "$", "messageClass", ")", "{", "$", "message", "=", "$", "this", "->", "objectSerializer", "->", "deserialize", "(", "$", "serializedMessage", ",", "$", "messageClass", ")", ";", ...
Deserialize the Message @param string $serializedMessage @param string $messageClass @return object Of type $messageClass
[ "Deserialize", "the", "Message" ]
b69f896cfdbd798b8e83d79c6c87a051f0469183
https://github.com/SimpleBus/Serialization/blob/b69f896cfdbd798b8e83d79c6c87a051f0469183/src/Envelope/Serializer/StandardMessageInEnvelopeSerializer.php#L90-L104
train
canihavesomecoffee/theTVDbAPI
src/MultiLanguageWrapper/Route/SearchRouteLanguageFallback.php
SearchRouteLanguageFallback.getClosureForSearch
public function getClosureForSearch(array $options): Closure { return function ($language) use ($options) { $json = $this->parent->performAPICallWithJsonResponse( 'get', '/search/series', array_merge($options, ['headers' => ['Accept-Language' => $language]]) ); return DataParser::parseDataArray($json, BasicSeries::class); }; }
php
public function getClosureForSearch(array $options): Closure { return function ($language) use ($options) { $json = $this->parent->performAPICallWithJsonResponse( 'get', '/search/series', array_merge($options, ['headers' => ['Accept-Language' => $language]]) ); return DataParser::parseDataArray($json, BasicSeries::class); }; }
[ "public", "function", "getClosureForSearch", "(", "array", "$", "options", ")", ":", "Closure", "{", "return", "function", "(", "$", "language", ")", "use", "(", "$", "options", ")", "{", "$", "json", "=", "$", "this", "->", "parent", "->", "performAPICa...
Returns the closure used to execute a search for a single language. @param array $options The options for the search. @return Closure
[ "Returns", "the", "closure", "used", "to", "execute", "a", "search", "for", "a", "single", "language", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/MultiLanguageWrapper/Route/SearchRouteLanguageFallback.php#L81-L91
train
orchestral/support
src/Support/Collection.php
Collection.streamCsv
public function streamCsv() { $delimiter = ','; $enclosure = '"'; $header = $this->resolveCsvHeader(); $stream = \fopen('php://output', 'r+'); \fputcsv($stream, $header, $delimiter, $enclosure); foreach ($this->items as $key => $item) { \fputcsv($stream, Arr::dot($item), $delimiter, $enclosure); } return $stream; }
php
public function streamCsv() { $delimiter = ','; $enclosure = '"'; $header = $this->resolveCsvHeader(); $stream = \fopen('php://output', 'r+'); \fputcsv($stream, $header, $delimiter, $enclosure); foreach ($this->items as $key => $item) { \fputcsv($stream, Arr::dot($item), $delimiter, $enclosure); } return $stream; }
[ "public", "function", "streamCsv", "(", ")", "{", "$", "delimiter", "=", "','", ";", "$", "enclosure", "=", "'\"'", ";", "$", "header", "=", "$", "this", "->", "resolveCsvHeader", "(", ")", ";", "$", "stream", "=", "\\", "fopen", "(", "'php://output'",...
Stream CSV output. @return object
[ "Stream", "CSV", "output", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Collection.php#L29-L44
train
QoboLtd/qobo-robo
src/Utility/File.php
File.readLines
public static function readLines($path, $skipEmpty = false) { if (!is_file($path) || !is_readable($path)) { throw new RuntimeException("File '$path' doesn't exist or is not a readable file"); } $lines = ($skipEmpty) ? file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : file($path, FILE_IGNORE_NEW_LINES); if ($lines === false) { throw new RuntimeException("Something went wrong while reading '$path' file content"); } return $lines; }
php
public static function readLines($path, $skipEmpty = false) { if (!is_file($path) || !is_readable($path)) { throw new RuntimeException("File '$path' doesn't exist or is not a readable file"); } $lines = ($skipEmpty) ? file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : file($path, FILE_IGNORE_NEW_LINES); if ($lines === false) { throw new RuntimeException("Something went wrong while reading '$path' file content"); } return $lines; }
[ "public", "static", "function", "readLines", "(", "$", "path", ",", "$", "skipEmpty", "=", "false", ")", "{", "if", "(", "!", "is_file", "(", "$", "path", ")", "||", "!", "is_readable", "(", "$", "path", ")", ")", "{", "throw", "new", "RuntimeExcepti...
Read file content into array of lines without trailing newlines @param string $path Path to file @param bool $skipEmpty Flag to skip empty lines @return array Lines of file content
[ "Read", "file", "content", "into", "array", "of", "lines", "without", "trailing", "newlines" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Utility/File.php#L29-L45
train
QoboLtd/qobo-robo
src/Utility/File.php
File.writeLines
public static function writeLines($path, $lines) { if (is_file($path) && !is_writable($path)) { throw new RuntimeException("File '$path' is not a writable file"); } // make sure every line has only one newline at the end $lines = array_map(function ($line) { return rtrim($line); }, $lines); $bytes = file_put_contents($path, implode("\n", $lines)); if ($bytes === false) { throw new RuntimeException("Something went wrong while writing content to '$path'"); } return true; }
php
public static function writeLines($path, $lines) { if (is_file($path) && !is_writable($path)) { throw new RuntimeException("File '$path' is not a writable file"); } // make sure every line has only one newline at the end $lines = array_map(function ($line) { return rtrim($line); }, $lines); $bytes = file_put_contents($path, implode("\n", $lines)); if ($bytes === false) { throw new RuntimeException("Something went wrong while writing content to '$path'"); } return true; }
[ "public", "static", "function", "writeLines", "(", "$", "path", ",", "$", "lines", ")", "{", "if", "(", "is_file", "(", "$", "path", ")", "&&", "!", "is_writable", "(", "$", "path", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"File '$path...
Write array of lines into file @param string $path Path to file @param array $lines Content array @return bool true on success
[ "Write", "array", "of", "lines", "into", "file" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Utility/File.php#L67-L84
train
anomalylabs/variables-module
src/Variable/Form/VariableFormBuilder.php
VariableFormBuilder.onReady
public function onReady(Container $container) { /* @var EntryModel $model */ $model = $container->make($this->getModel()); if ($model->isVersionable()) { $this->setButtons( [ 'versions' => [ 'href' => 'admin/variables/versions/{entry.id}?group={request.route.parameters.id}', ], 'cancel', ] ); } }
php
public function onReady(Container $container) { /* @var EntryModel $model */ $model = $container->make($this->getModel()); if ($model->isVersionable()) { $this->setButtons( [ 'versions' => [ 'href' => 'admin/variables/versions/{entry.id}?group={request.route.parameters.id}', ], 'cancel', ] ); } }
[ "public", "function", "onReady", "(", "Container", "$", "container", ")", "{", "/* @var EntryModel $model */", "$", "model", "=", "$", "container", "->", "make", "(", "$", "this", "->", "getModel", "(", ")", ")", ";", "if", "(", "$", "model", "->", "isVe...
Fired just before building. @param Container $container
[ "Fired", "just", "before", "building", "." ]
bcd903670471a175f07aba3123693cb3a3c07d0b
https://github.com/anomalylabs/variables-module/blob/bcd903670471a175f07aba3123693cb3a3c07d0b/src/Variable/Form/VariableFormBuilder.php#L22-L38
train
pxgamer/arionum-php
src/Arionum.php
Arionum.sendTransaction
public function sendTransaction(Transaction $transaction): string { $data = array_merge((array)$transaction, [ 'q' => 'send', ]); return $this->getJson($data); }
php
public function sendTransaction(Transaction $transaction): string { $data = array_merge((array)$transaction, [ 'q' => 'send', ]); return $this->getJson($data); }
[ "public", "function", "sendTransaction", "(", "Transaction", "$", "transaction", ")", ":", "string", "{", "$", "data", "=", "array_merge", "(", "(", "array", ")", "$", "transaction", ",", "[", "'q'", "=>", "'send'", ",", "]", ")", ";", "return", "$", "...
Send a transaction. @param Transaction $transaction @return string @throws ApiException @api
[ "Send", "a", "transaction", "." ]
1d3e73f7b661878b864b3a910faad540e6af47bb
https://github.com/pxgamer/arionum-php/blob/1d3e73f7b661878b864b3a910faad540e6af47bb/src/Arionum.php#L281-L288
train
pxgamer/arionum-php
src/Arionum.php
Arionum.getRandomNumber
public function getRandomNumber(int $height, int $minimum, int $maximum, string $seed = null): int { return $this->getJson([ 'q' => 'randomNumber', 'height' => $height, 'min' => $minimum, 'max' => $maximum, 'seed' => $seed, ]); }
php
public function getRandomNumber(int $height, int $minimum, int $maximum, string $seed = null): int { return $this->getJson([ 'q' => 'randomNumber', 'height' => $height, 'min' => $minimum, 'max' => $maximum, 'seed' => $seed, ]); }
[ "public", "function", "getRandomNumber", "(", "int", "$", "height", ",", "int", "$", "minimum", ",", "int", "$", "maximum", ",", "string", "$", "seed", "=", "null", ")", ":", "int", "{", "return", "$", "this", "->", "getJson", "(", "[", "'q'", "=>", ...
Retrieve a random number based on a specified block. @param int $height @param int $minimum @param int $maximum @param string|null $seed @return int @throws ApiException @api
[ "Retrieve", "a", "random", "number", "based", "on", "a", "specified", "block", "." ]
1d3e73f7b661878b864b3a910faad540e6af47bb
https://github.com/pxgamer/arionum-php/blob/1d3e73f7b661878b864b3a910faad540e6af47bb/src/Arionum.php#L315-L324
train