id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
35,100
hail-framework/framework
src/Database/Migration/Generator.php
Generator.diff
protected function diff($array1, $array2) { $difference = []; foreach ($array1 as $key => $value) { if (is_array($value)) { if (!isset($array2[$key]) || !is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = $this->diff($value, $array2[$key]); if (!empty($new_diff)) { $difference[$key] = $new_diff; } } } else { if (!array_key_exists($key, $array2) || $array2[$key] !== $value) { $difference[$key] = $value; } } } return $difference; }
php
protected function diff($array1, $array2) { $difference = []; foreach ($array1 as $key => $value) { if (is_array($value)) { if (!isset($array2[$key]) || !is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = $this->diff($value, $array2[$key]); if (!empty($new_diff)) { $difference[$key] = $new_diff; } } } else { if (!array_key_exists($key, $array2) || $array2[$key] !== $value) { $difference[$key] = $value; } } } return $difference; }
[ "protected", "function", "diff", "(", "$", "array1", ",", "$", "array2", ")", "{", "$", "difference", "=", "[", "]", ";", "foreach", "(", "$", "array1", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "array2", "[", "$", "key", "]", ")", "||", "!", "is_array", "(", "$", "array2", "[", "$", "key", "]", ")", ")", "{", "$", "difference", "[", "$", "key", "]", "=", "$", "value", ";", "}", "else", "{", "$", "new_diff", "=", "$", "this", "->", "diff", "(", "$", "value", ",", "$", "array2", "[", "$", "key", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "new_diff", ")", ")", "{", "$", "difference", "[", "$", "key", "]", "=", "$", "new_diff", ";", "}", "}", "}", "else", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "array2", ")", "||", "$", "array2", "[", "$", "key", "]", "!==", "$", "value", ")", "{", "$", "difference", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "}", "return", "$", "difference", ";", "}" ]
Intersect of recursive arrays. @param array $array1 @param array $array2 @return array
[ "Intersect", "of", "recursive", "arrays", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator.php#L270-L291
35,101
hail-framework/framework
src/Console/Component/Table/CellAttribute.php
CellAttribute.handleTextOverflow
public function handleTextOverflow($cell, $maxWidth) { $lines = explode("\n", $cell); if ($this->textOverflow == self::WRAP) { $maxLineWidth = max(array_map('mb_strlen', $lines)); if ($maxLineWidth > $maxWidth) { $cell = wordwrap($cell, $maxWidth, "\n"); // Re-explode the lines $lines = explode("\n", $cell); } } elseif ($this->textOverflow == self::ELLIPSIS) { if (mb_strlen($lines[0]) > $maxWidth) { $lines = [mb_substr($lines[0], 0, $maxWidth - 2) . '..']; } } elseif ($this->textOverflow == self::CLIP) { if (mb_strlen($lines[0]) > $maxWidth) { $lines = [mb_substr($lines[0], 0, $maxWidth)]; } } return $lines; }
php
public function handleTextOverflow($cell, $maxWidth) { $lines = explode("\n", $cell); if ($this->textOverflow == self::WRAP) { $maxLineWidth = max(array_map('mb_strlen', $lines)); if ($maxLineWidth > $maxWidth) { $cell = wordwrap($cell, $maxWidth, "\n"); // Re-explode the lines $lines = explode("\n", $cell); } } elseif ($this->textOverflow == self::ELLIPSIS) { if (mb_strlen($lines[0]) > $maxWidth) { $lines = [mb_substr($lines[0], 0, $maxWidth - 2) . '..']; } } elseif ($this->textOverflow == self::CLIP) { if (mb_strlen($lines[0]) > $maxWidth) { $lines = [mb_substr($lines[0], 0, $maxWidth)]; } } return $lines; }
[ "public", "function", "handleTextOverflow", "(", "$", "cell", ",", "$", "maxWidth", ")", "{", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "cell", ")", ";", "if", "(", "$", "this", "->", "textOverflow", "==", "self", "::", "WRAP", ")", "{", "$", "maxLineWidth", "=", "max", "(", "array_map", "(", "'mb_strlen'", ",", "$", "lines", ")", ")", ";", "if", "(", "$", "maxLineWidth", ">", "$", "maxWidth", ")", "{", "$", "cell", "=", "wordwrap", "(", "$", "cell", ",", "$", "maxWidth", ",", "\"\\n\"", ")", ";", "// Re-explode the lines", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "cell", ")", ";", "}", "}", "elseif", "(", "$", "this", "->", "textOverflow", "==", "self", "::", "ELLIPSIS", ")", "{", "if", "(", "mb_strlen", "(", "$", "lines", "[", "0", "]", ")", ">", "$", "maxWidth", ")", "{", "$", "lines", "=", "[", "mb_substr", "(", "$", "lines", "[", "0", "]", ",", "0", ",", "$", "maxWidth", "-", "2", ")", ".", "'..'", "]", ";", "}", "}", "elseif", "(", "$", "this", "->", "textOverflow", "==", "self", "::", "CLIP", ")", "{", "if", "(", "mb_strlen", "(", "$", "lines", "[", "0", "]", ")", ">", "$", "maxWidth", ")", "{", "$", "lines", "=", "[", "mb_substr", "(", "$", "lines", "[", "0", "]", ",", "0", ",", "$", "maxWidth", ")", "]", ";", "}", "}", "return", "$", "lines", ";", "}" ]
When inserting rows, we pre-explode the lines to extra rows from Table hence this method is separated for pre-processing..
[ "When", "inserting", "rows", "we", "pre", "-", "explode", "the", "lines", "to", "extra", "rows", "from", "Table", "hence", "this", "method", "is", "separated", "for", "pre", "-", "processing", ".." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Component/Table/CellAttribute.php#L92-L113
35,102
DoSomething/gateway
src/Common/RestApiClient.php
RestApiClient.get
public function get($path, $query = [], $withAuthorization = true) { $options = [ 'query' => $query, ]; return $this->send('GET', $path, $options, $withAuthorization); }
php
public function get($path, $query = [], $withAuthorization = true) { $options = [ 'query' => $query, ]; return $this->send('GET', $path, $options, $withAuthorization); }
[ "public", "function", "get", "(", "$", "path", ",", "$", "query", "=", "[", "]", ",", "$", "withAuthorization", "=", "true", ")", "{", "$", "options", "=", "[", "'query'", "=>", "$", "query", ",", "]", ";", "return", "$", "this", "->", "send", "(", "'GET'", ",", "$", "path", ",", "$", "options", ",", "$", "withAuthorization", ")", ";", "}" ]
Send a GET request to the given URL. @param string $path - URL to make request to (relative to base URL) @param array $query - Key-value array of query string values @param bool $withAuthorization - Should this request be authorized? @return array
[ "Send", "a", "GET", "request", "to", "the", "given", "URL", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/RestApiClient.php#L86-L93
35,103
DoSomething/gateway
src/Common/RestApiClient.php
RestApiClient.post
public function post($path, $payload = [], $withAuthorization = true) { $options = [ 'json' => $payload, ]; return $this->send('POST', $path, $options, $withAuthorization); }
php
public function post($path, $payload = [], $withAuthorization = true) { $options = [ 'json' => $payload, ]; return $this->send('POST', $path, $options, $withAuthorization); }
[ "public", "function", "post", "(", "$", "path", ",", "$", "payload", "=", "[", "]", ",", "$", "withAuthorization", "=", "true", ")", "{", "$", "options", "=", "[", "'json'", "=>", "$", "payload", ",", "]", ";", "return", "$", "this", "->", "send", "(", "'POST'", ",", "$", "path", ",", "$", "options", ",", "$", "withAuthorization", ")", ";", "}" ]
Send a POST request to the given URL. @param string $path - URL to make request to (relative to base URL) @param array $payload - Body of the POST request @param bool $withAuthorization - Should this request be authorized? @return array
[ "Send", "a", "POST", "request", "to", "the", "given", "URL", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/RestApiClient.php#L103-L110
35,104
DoSomething/gateway
src/Common/RestApiClient.php
RestApiClient.put
public function put($path, $payload = [], $withAuthorization = true) { $options = [ 'json' => $payload, ]; return $this->send('PUT', $path, $options, $withAuthorization); }
php
public function put($path, $payload = [], $withAuthorization = true) { $options = [ 'json' => $payload, ]; return $this->send('PUT', $path, $options, $withAuthorization); }
[ "public", "function", "put", "(", "$", "path", ",", "$", "payload", "=", "[", "]", ",", "$", "withAuthorization", "=", "true", ")", "{", "$", "options", "=", "[", "'json'", "=>", "$", "payload", ",", "]", ";", "return", "$", "this", "->", "send", "(", "'PUT'", ",", "$", "path", ",", "$", "options", ",", "$", "withAuthorization", ")", ";", "}" ]
Send a PUT request to the given URL. @param string $path - URL to make request to (relative to base URL) @param array $payload - Body of the PUT request @param bool $withAuthorization - Should this request be authorized? @return array
[ "Send", "a", "PUT", "request", "to", "the", "given", "URL", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/RestApiClient.php#L120-L127
35,105
DoSomething/gateway
src/Common/RestApiClient.php
RestApiClient.patch
public function patch($path, $payload = [], $withAuthorization = true) { $options = [ 'json' => $payload, ]; return $this->send('PATCH', $path, $options, $withAuthorization); }
php
public function patch($path, $payload = [], $withAuthorization = true) { $options = [ 'json' => $payload, ]; return $this->send('PATCH', $path, $options, $withAuthorization); }
[ "public", "function", "patch", "(", "$", "path", ",", "$", "payload", "=", "[", "]", ",", "$", "withAuthorization", "=", "true", ")", "{", "$", "options", "=", "[", "'json'", "=>", "$", "payload", ",", "]", ";", "return", "$", "this", "->", "send", "(", "'PATCH'", ",", "$", "path", ",", "$", "options", ",", "$", "withAuthorization", ")", ";", "}" ]
Send a PATCH request to the given URL. @param string $path - URL to make request to (relative to base URL) @param array $payload - Body of the PUT request @param bool $withAuthorization - Should this request be authorized? @return array
[ "Send", "a", "PATCH", "request", "to", "the", "given", "URL", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/RestApiClient.php#L137-L144
35,106
DoSomething/gateway
src/Common/RestApiClient.php
RestApiClient.delete
public function delete($path, $withAuthorization = true) { $response = $this->send('DELETE', $path, [], $withAuthorization); return $this->responseSuccessful($response); }
php
public function delete($path, $withAuthorization = true) { $response = $this->send('DELETE', $path, [], $withAuthorization); return $this->responseSuccessful($response); }
[ "public", "function", "delete", "(", "$", "path", ",", "$", "withAuthorization", "=", "true", ")", "{", "$", "response", "=", "$", "this", "->", "send", "(", "'DELETE'", ",", "$", "path", ",", "[", "]", ",", "$", "withAuthorization", ")", ";", "return", "$", "this", "->", "responseSuccessful", "(", "$", "response", ")", ";", "}" ]
Send a DELETE request to the given URL. @param string $path - URL to make request to (relative to base URL) @param bool $withAuthorization - Should this request be authorized? @return bool
[ "Send", "a", "DELETE", "request", "to", "the", "given", "URL", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/RestApiClient.php#L153-L158
35,107
DoSomething/gateway
src/Common/RestApiClient.php
RestApiClient.handleValidationException
public function handleValidationException($endpoint, $response, $method, $path, $options) { $errors = $response['error']['fields']; throw new ValidationException($errors, $endpoint); }
php
public function handleValidationException($endpoint, $response, $method, $path, $options) { $errors = $response['error']['fields']; throw new ValidationException($errors, $endpoint); }
[ "public", "function", "handleValidationException", "(", "$", "endpoint", ",", "$", "response", ",", "$", "method", ",", "$", "path", ",", "$", "options", ")", "{", "$", "errors", "=", "$", "response", "[", "'error'", "]", "[", "'fields'", "]", ";", "throw", "new", "ValidationException", "(", "$", "errors", ",", "$", "endpoint", ")", ";", "}" ]
Handle validation exceptions. @param string $endpoint - The human-readable route that triggered the error. @param array $response - The body of the response. @param string $method - The HTTP method for the request that triggered the error, for optionally resending. @param string $path - The path for the request that triggered the error, for optionally resending. @param array $options - The options for the request that triggered the error, for optionally resending. @return \GuzzleHttp\Psr7\Response|void @throws UnauthorizedException
[ "Handle", "validation", "exceptions", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/RestApiClient.php#L209-L213
35,108
DoSomething/gateway
src/Common/RestApiClient.php
RestApiClient.send
public function send($method, $path, $options = [], $withAuthorization = true) { try { // Increment the number of attempts so we can eventually give up. $this->attempts++; // Make the request. Any error code will send us to the 'catch' below. $response = $this->raw($method, $path, $options, $withAuthorization); // Reset the number of attempts back to zero once we've had a successful // response, and then perform any other clean-up. $this->attempts = 0; $this->cleanUp(); return json_decode($response->getBody()->getContents(), true); } catch (\GuzzleHttp\Exception\ClientException $e) { $endpoint = strtoupper($method).' '.$path; $response = json_decode($e->getResponse()->getBody()->getContents(), true); switch ($e->getCode()) { // If the request is bad, throw a generic bad request exception. case 400: throw new BadRequestException($endpoint, json_encode($response)); // If the request is unauthorized, handle it. case 401: return $this->handleUnauthorizedException($endpoint, $response, $method, $path, $options); // If the request is forbidden, throw a generic forbidden exception. case 403: throw new ForbiddenException($endpoint, json_encode($response)); // If the resource doesn't exist, return null. case 404: return null; // If it's a validation error, throw a generic validation error. case 422: return $this->handleValidationException($endpoint, $response, $method, $path, $options); default: throw new InternalException($endpoint, $e->getCode(), $e->getMessage()); } } }
php
public function send($method, $path, $options = [], $withAuthorization = true) { try { // Increment the number of attempts so we can eventually give up. $this->attempts++; // Make the request. Any error code will send us to the 'catch' below. $response = $this->raw($method, $path, $options, $withAuthorization); // Reset the number of attempts back to zero once we've had a successful // response, and then perform any other clean-up. $this->attempts = 0; $this->cleanUp(); return json_decode($response->getBody()->getContents(), true); } catch (\GuzzleHttp\Exception\ClientException $e) { $endpoint = strtoupper($method).' '.$path; $response = json_decode($e->getResponse()->getBody()->getContents(), true); switch ($e->getCode()) { // If the request is bad, throw a generic bad request exception. case 400: throw new BadRequestException($endpoint, json_encode($response)); // If the request is unauthorized, handle it. case 401: return $this->handleUnauthorizedException($endpoint, $response, $method, $path, $options); // If the request is forbidden, throw a generic forbidden exception. case 403: throw new ForbiddenException($endpoint, json_encode($response)); // If the resource doesn't exist, return null. case 404: return null; // If it's a validation error, throw a generic validation error. case 422: return $this->handleValidationException($endpoint, $response, $method, $path, $options); default: throw new InternalException($endpoint, $e->getCode(), $e->getMessage()); } } }
[ "public", "function", "send", "(", "$", "method", ",", "$", "path", ",", "$", "options", "=", "[", "]", ",", "$", "withAuthorization", "=", "true", ")", "{", "try", "{", "// Increment the number of attempts so we can eventually give up.", "$", "this", "->", "attempts", "++", ";", "// Make the request. Any error code will send us to the 'catch' below.", "$", "response", "=", "$", "this", "->", "raw", "(", "$", "method", ",", "$", "path", ",", "$", "options", ",", "$", "withAuthorization", ")", ";", "// Reset the number of attempts back to zero once we've had a successful", "// response, and then perform any other clean-up.", "$", "this", "->", "attempts", "=", "0", ";", "$", "this", "->", "cleanUp", "(", ")", ";", "return", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ",", "true", ")", ";", "}", "catch", "(", "\\", "GuzzleHttp", "\\", "Exception", "\\", "ClientException", "$", "e", ")", "{", "$", "endpoint", "=", "strtoupper", "(", "$", "method", ")", ".", "' '", ".", "$", "path", ";", "$", "response", "=", "json_decode", "(", "$", "e", "->", "getResponse", "(", ")", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ",", "true", ")", ";", "switch", "(", "$", "e", "->", "getCode", "(", ")", ")", "{", "// If the request is bad, throw a generic bad request exception.", "case", "400", ":", "throw", "new", "BadRequestException", "(", "$", "endpoint", ",", "json_encode", "(", "$", "response", ")", ")", ";", "// If the request is unauthorized, handle it.", "case", "401", ":", "return", "$", "this", "->", "handleUnauthorizedException", "(", "$", "endpoint", ",", "$", "response", ",", "$", "method", ",", "$", "path", ",", "$", "options", ")", ";", "// If the request is forbidden, throw a generic forbidden exception.", "case", "403", ":", "throw", "new", "ForbiddenException", "(", "$", "endpoint", ",", "json_encode", "(", "$", "response", ")", ")", ";", "// If the resource doesn't exist, return null.", "case", "404", ":", "return", "null", ";", "// If it's a validation error, throw a generic validation error.", "case", "422", ":", "return", "$", "this", "->", "handleValidationException", "(", "$", "endpoint", ",", "$", "response", ",", "$", "method", ",", "$", "path", ",", "$", "options", ")", ";", "default", ":", "throw", "new", "InternalException", "(", "$", "endpoint", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", "}" ]
Send a Northstar API request, and parse any returned validation errors or status codes to present to the user. @param string $method - 'GET', 'POST', 'PUT', or 'DELETE' @param string $path - URL to make request to (relative to base URL) @param array $options - Guzzle options (http://guzzle.readthedocs.org/en/latest/request-options.html) @param bool $withAuthorization - Should this request be authorized? @return \GuzzleHttp\Psr7\Response|void @throws BadRequestException @throws ForbiddenException @throws InternalException @throws UnauthorizedException @throws ValidationException
[ "Send", "a", "Northstar", "API", "request", "and", "parse", "any", "returned", "validation", "errors", "or", "status", "codes", "to", "present", "to", "the", "user", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/RestApiClient.php#L230-L274
35,109
DoSomething/gateway
src/Common/RestApiClient.php
RestApiClient.raw
public function raw($method, $path, $options, $withAuthorization = true) { // Find what traits this class is using. $class = get_called_class(); $traits = Introspector::getAllClassTraits($class); if (empty($options['headers'])) { // Guzzle doesn't merge default headers with $options array $options['headers'] = $this->defaultHeaders ?: []; } // If these traits have a "hook" (uh oh!), run that before making a request. foreach ($traits as $trait) { $function = 'run'.Introspector::baseName($trait).'Tasks'; if (method_exists($class, $method)) { $this->{$function}($method, $path, $options, $withAuthorization); } } return $this->client->request($method, $path, $options); }
php
public function raw($method, $path, $options, $withAuthorization = true) { // Find what traits this class is using. $class = get_called_class(); $traits = Introspector::getAllClassTraits($class); if (empty($options['headers'])) { // Guzzle doesn't merge default headers with $options array $options['headers'] = $this->defaultHeaders ?: []; } // If these traits have a "hook" (uh oh!), run that before making a request. foreach ($traits as $trait) { $function = 'run'.Introspector::baseName($trait).'Tasks'; if (method_exists($class, $method)) { $this->{$function}($method, $path, $options, $withAuthorization); } } return $this->client->request($method, $path, $options); }
[ "public", "function", "raw", "(", "$", "method", ",", "$", "path", ",", "$", "options", ",", "$", "withAuthorization", "=", "true", ")", "{", "// Find what traits this class is using.", "$", "class", "=", "get_called_class", "(", ")", ";", "$", "traits", "=", "Introspector", "::", "getAllClassTraits", "(", "$", "class", ")", ";", "if", "(", "empty", "(", "$", "options", "[", "'headers'", "]", ")", ")", "{", "// Guzzle doesn't merge default headers with $options array", "$", "options", "[", "'headers'", "]", "=", "$", "this", "->", "defaultHeaders", "?", ":", "[", "]", ";", "}", "// If these traits have a \"hook\" (uh oh!), run that before making a request.", "foreach", "(", "$", "traits", "as", "$", "trait", ")", "{", "$", "function", "=", "'run'", ".", "Introspector", "::", "baseName", "(", "$", "trait", ")", ".", "'Tasks'", ";", "if", "(", "method_exists", "(", "$", "class", ",", "$", "method", ")", ")", "{", "$", "this", "->", "{", "$", "function", "}", "(", "$", "method", ",", "$", "path", ",", "$", "options", ",", "$", "withAuthorization", ")", ";", "}", "}", "return", "$", "this", "->", "client", "->", "request", "(", "$", "method", ",", "$", "path", ",", "$", "options", ")", ";", "}" ]
Send a raw API request, without attempting to handle error responses. @param $method @param $path @param array $options @param bool $withAuthorization @return Response
[ "Send", "a", "raw", "API", "request", "without", "attempting", "to", "handle", "error", "responses", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/RestApiClient.php#L285-L305
35,110
hail-framework/framework
src/Filesystem/Adapter/GridFS.php
GridFS.writeObject
protected function writeObject($path, $content, array $metadata) { try { if (\is_resource($content)) { $id = $this->client->storeFile($content, $metadata); } else { $id = $this->client->storeBytes($content, $metadata); } } catch (MongoGridFSException $e) { return false; } $file = $this->client->findOne(['_id' => $id]); return $this->normalizeGridFSFile($file, $path); }
php
protected function writeObject($path, $content, array $metadata) { try { if (\is_resource($content)) { $id = $this->client->storeFile($content, $metadata); } else { $id = $this->client->storeBytes($content, $metadata); } } catch (MongoGridFSException $e) { return false; } $file = $this->client->findOne(['_id' => $id]); return $this->normalizeGridFSFile($file, $path); }
[ "protected", "function", "writeObject", "(", "$", "path", ",", "$", "content", ",", "array", "$", "metadata", ")", "{", "try", "{", "if", "(", "\\", "is_resource", "(", "$", "content", ")", ")", "{", "$", "id", "=", "$", "this", "->", "client", "->", "storeFile", "(", "$", "content", ",", "$", "metadata", ")", ";", "}", "else", "{", "$", "id", "=", "$", "this", "->", "client", "->", "storeBytes", "(", "$", "content", ",", "$", "metadata", ")", ";", "}", "}", "catch", "(", "MongoGridFSException", "$", "e", ")", "{", "return", "false", ";", "}", "$", "file", "=", "$", "this", "->", "client", "->", "findOne", "(", "[", "'_id'", "=>", "$", "id", "]", ")", ";", "return", "$", "this", "->", "normalizeGridFSFile", "(", "$", "file", ",", "$", "path", ")", ";", "}" ]
Write an object to GridFS. @param array $metadata @return array|false normalized file representation
[ "Write", "an", "object", "to", "GridFS", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Filesystem/Adapter/GridFS.php#L216-L231
35,111
hail-framework/framework
src/Filesystem/Adapter/GridFS.php
GridFS.normalizeGridFSFile
protected function normalizeGridFSFile(MongoGridFSFile $file, $path = null) { $result = [ 'path' => \trim($path ?: $file->getFilename(), '/'), 'type' => 'file', 'size' => $file->getSize(), 'timestamp' => $file->file['uploadDate']->sec, ]; $result['dirname'] = Util::dirname($result['path']); if (isset($file->file['metadata']) && !empty($file->file['metadata']['mimetype'])) { $result['mimetype'] = $file->file['metadata']['mimetype']; } return $result; }
php
protected function normalizeGridFSFile(MongoGridFSFile $file, $path = null) { $result = [ 'path' => \trim($path ?: $file->getFilename(), '/'), 'type' => 'file', 'size' => $file->getSize(), 'timestamp' => $file->file['uploadDate']->sec, ]; $result['dirname'] = Util::dirname($result['path']); if (isset($file->file['metadata']) && !empty($file->file['metadata']['mimetype'])) { $result['mimetype'] = $file->file['metadata']['mimetype']; } return $result; }
[ "protected", "function", "normalizeGridFSFile", "(", "MongoGridFSFile", "$", "file", ",", "$", "path", "=", "null", ")", "{", "$", "result", "=", "[", "'path'", "=>", "\\", "trim", "(", "$", "path", "?", ":", "$", "file", "->", "getFilename", "(", ")", ",", "'/'", ")", ",", "'type'", "=>", "'file'", ",", "'size'", "=>", "$", "file", "->", "getSize", "(", ")", ",", "'timestamp'", "=>", "$", "file", "->", "file", "[", "'uploadDate'", "]", "->", "sec", ",", "]", ";", "$", "result", "[", "'dirname'", "]", "=", "Util", "::", "dirname", "(", "$", "result", "[", "'path'", "]", ")", ";", "if", "(", "isset", "(", "$", "file", "->", "file", "[", "'metadata'", "]", ")", "&&", "!", "empty", "(", "$", "file", "->", "file", "[", "'metadata'", "]", "[", "'mimetype'", "]", ")", ")", "{", "$", "result", "[", "'mimetype'", "]", "=", "$", "file", "->", "file", "[", "'metadata'", "]", "[", "'mimetype'", "]", ";", "}", "return", "$", "result", ";", "}" ]
Normalize a MongoGridFs file to a response. @param MongoGridFSFile $file @param string $path @return array
[ "Normalize", "a", "MongoGridFs", "file", "to", "a", "response", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Filesystem/Adapter/GridFS.php#L241-L257
35,112
hail-framework/framework
src/I18n/Gettext/Languages/FormulaConverter.php
FormulaConverter.convertFormula
public static function convertFormula($cldrFormula) { if (\strpbrk($cldrFormula, '()') !== false) { throw new \InvalidArgumentException("Unable to convert the formula '$cldrFormula': parenthesis handling not implemented"); } $orSeparatedChunks = []; foreach (\explode(' or ', $cldrFormula) as $cldrFormulaChunk) { $gettextFormulaChunk = null; $andSeparatedChunks = []; foreach (\explode(' and ', $cldrFormulaChunk) as $cldrAtom) { $gettextAtom = self::convertAtom($cldrAtom); if ($gettextAtom === false) { // One atom joined by 'and' always evaluates to false => the whole 'and' group is always false $gettextFormulaChunk = false; break; } if ($gettextAtom !== true) { $andSeparatedChunks[] = $gettextAtom; } } if (!isset($gettextFormulaChunk)) { if (empty($andSeparatedChunks)) { // All the atoms joined by 'and' always evaluate to true => the whole 'and' group is always true $gettextFormulaChunk = true; } else { $gettextFormulaChunk = \implode(' && ', $andSeparatedChunks); // Special cases simplification switch ($gettextFormulaChunk) { case 'n >= 0 && n <= 2 && n != 2': $gettextFormulaChunk = 'n == 0 || n == 1'; break; } } } if ($gettextFormulaChunk === true) { // One part of the formula joined with the others by 'or' always evaluates to true => the whole formula always evaluates to true return true; } if ($gettextFormulaChunk !== false) { $orSeparatedChunks[] = $gettextFormulaChunk; } } if (empty($orSeparatedChunks)) { // All the parts joined by 'or' always evaluate to false => the whole formula always evaluates to false return false; } return \implode(' || ', $orSeparatedChunks); }
php
public static function convertFormula($cldrFormula) { if (\strpbrk($cldrFormula, '()') !== false) { throw new \InvalidArgumentException("Unable to convert the formula '$cldrFormula': parenthesis handling not implemented"); } $orSeparatedChunks = []; foreach (\explode(' or ', $cldrFormula) as $cldrFormulaChunk) { $gettextFormulaChunk = null; $andSeparatedChunks = []; foreach (\explode(' and ', $cldrFormulaChunk) as $cldrAtom) { $gettextAtom = self::convertAtom($cldrAtom); if ($gettextAtom === false) { // One atom joined by 'and' always evaluates to false => the whole 'and' group is always false $gettextFormulaChunk = false; break; } if ($gettextAtom !== true) { $andSeparatedChunks[] = $gettextAtom; } } if (!isset($gettextFormulaChunk)) { if (empty($andSeparatedChunks)) { // All the atoms joined by 'and' always evaluate to true => the whole 'and' group is always true $gettextFormulaChunk = true; } else { $gettextFormulaChunk = \implode(' && ', $andSeparatedChunks); // Special cases simplification switch ($gettextFormulaChunk) { case 'n >= 0 && n <= 2 && n != 2': $gettextFormulaChunk = 'n == 0 || n == 1'; break; } } } if ($gettextFormulaChunk === true) { // One part of the formula joined with the others by 'or' always evaluates to true => the whole formula always evaluates to true return true; } if ($gettextFormulaChunk !== false) { $orSeparatedChunks[] = $gettextFormulaChunk; } } if (empty($orSeparatedChunks)) { // All the parts joined by 'or' always evaluate to false => the whole formula always evaluates to false return false; } return \implode(' || ', $orSeparatedChunks); }
[ "public", "static", "function", "convertFormula", "(", "$", "cldrFormula", ")", "{", "if", "(", "\\", "strpbrk", "(", "$", "cldrFormula", ",", "'()'", ")", "!==", "false", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Unable to convert the formula '$cldrFormula': parenthesis handling not implemented\"", ")", ";", "}", "$", "orSeparatedChunks", "=", "[", "]", ";", "foreach", "(", "\\", "explode", "(", "' or '", ",", "$", "cldrFormula", ")", "as", "$", "cldrFormulaChunk", ")", "{", "$", "gettextFormulaChunk", "=", "null", ";", "$", "andSeparatedChunks", "=", "[", "]", ";", "foreach", "(", "\\", "explode", "(", "' and '", ",", "$", "cldrFormulaChunk", ")", "as", "$", "cldrAtom", ")", "{", "$", "gettextAtom", "=", "self", "::", "convertAtom", "(", "$", "cldrAtom", ")", ";", "if", "(", "$", "gettextAtom", "===", "false", ")", "{", "// One atom joined by 'and' always evaluates to false => the whole 'and' group is always false", "$", "gettextFormulaChunk", "=", "false", ";", "break", ";", "}", "if", "(", "$", "gettextAtom", "!==", "true", ")", "{", "$", "andSeparatedChunks", "[", "]", "=", "$", "gettextAtom", ";", "}", "}", "if", "(", "!", "isset", "(", "$", "gettextFormulaChunk", ")", ")", "{", "if", "(", "empty", "(", "$", "andSeparatedChunks", ")", ")", "{", "// All the atoms joined by 'and' always evaluate to true => the whole 'and' group is always true", "$", "gettextFormulaChunk", "=", "true", ";", "}", "else", "{", "$", "gettextFormulaChunk", "=", "\\", "implode", "(", "' && '", ",", "$", "andSeparatedChunks", ")", ";", "// Special cases simplification", "switch", "(", "$", "gettextFormulaChunk", ")", "{", "case", "'n >= 0 && n <= 2 && n != 2'", ":", "$", "gettextFormulaChunk", "=", "'n == 0 || n == 1'", ";", "break", ";", "}", "}", "}", "if", "(", "$", "gettextFormulaChunk", "===", "true", ")", "{", "// One part of the formula joined with the others by 'or' always evaluates to true => the whole formula always evaluates to true", "return", "true", ";", "}", "if", "(", "$", "gettextFormulaChunk", "!==", "false", ")", "{", "$", "orSeparatedChunks", "[", "]", "=", "$", "gettextFormulaChunk", ";", "}", "}", "if", "(", "empty", "(", "$", "orSeparatedChunks", ")", ")", "{", "// All the parts joined by 'or' always evaluate to false => the whole formula always evaluates to false", "return", "false", ";", "}", "return", "\\", "implode", "(", "' || '", ",", "$", "orSeparatedChunks", ")", ";", "}" ]
Converts a formula from the CLDR representation to the gettext representation. @param string $cldrFormula The CLDR formula to convert. @throws \InvalidArgumentException @return bool|string Returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise.
[ "Converts", "a", "formula", "from", "the", "CLDR", "representation", "to", "the", "gettext", "representation", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Languages/FormulaConverter.php#L18-L69
35,113
hail-framework/framework
src/I18n/Gettext/Languages/FormulaConverter.php
FormulaConverter.convertAtom
private static function convertAtom($cldrAtom) { $m = null; $gettextAtom = $cldrAtom; $gettextAtom = \str_replace([' = ', 'i'], [' == ', 'n'], $gettextAtom); if (\preg_match('/^n( % \d+)? (!=|==) \d+$/', $gettextAtom)) { return $gettextAtom; } if (\preg_match('/^n( % \d+)? (!=|==) \d+(,\d+|\.\.\d+)+$/', $gettextAtom)) { return self::expandAtom($gettextAtom); } if (\preg_match('/^(?:v|w)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 return ((int) $m[1]) === 0; } if (\preg_match('/^(?:v|w)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 return ((int) $m[1]) !== 0; } if (\preg_match('/^(?:f|t)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty return ((int) $m[1]) === 0; } if (\preg_match('/^(?:f|t)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty return ((int) $m[1]) !== 0; } throw new \InvalidArgumentException("Unable to convert the formula chunk '$cldrAtom' from CLDR to gettext"); }
php
private static function convertAtom($cldrAtom) { $m = null; $gettextAtom = $cldrAtom; $gettextAtom = \str_replace([' = ', 'i'], [' == ', 'n'], $gettextAtom); if (\preg_match('/^n( % \d+)? (!=|==) \d+$/', $gettextAtom)) { return $gettextAtom; } if (\preg_match('/^n( % \d+)? (!=|==) \d+(,\d+|\.\.\d+)+$/', $gettextAtom)) { return self::expandAtom($gettextAtom); } if (\preg_match('/^(?:v|w)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 return ((int) $m[1]) === 0; } if (\preg_match('/^(?:v|w)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 return ((int) $m[1]) !== 0; } if (\preg_match('/^(?:f|t)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty return ((int) $m[1]) === 0; } if (\preg_match('/^(?:f|t)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty return ((int) $m[1]) !== 0; } throw new \InvalidArgumentException("Unable to convert the formula chunk '$cldrAtom' from CLDR to gettext"); }
[ "private", "static", "function", "convertAtom", "(", "$", "cldrAtom", ")", "{", "$", "m", "=", "null", ";", "$", "gettextAtom", "=", "$", "cldrAtom", ";", "$", "gettextAtom", "=", "\\", "str_replace", "(", "[", "' = '", ",", "'i'", "]", ",", "[", "' == '", ",", "'n'", "]", ",", "$", "gettextAtom", ")", ";", "if", "(", "\\", "preg_match", "(", "'/^n( % \\d+)? (!=|==) \\d+$/'", ",", "$", "gettextAtom", ")", ")", "{", "return", "$", "gettextAtom", ";", "}", "if", "(", "\\", "preg_match", "(", "'/^n( % \\d+)? (!=|==) \\d+(,\\d+|\\.\\.\\d+)+$/'", ",", "$", "gettextAtom", ")", ")", "{", "return", "self", "::", "expandAtom", "(", "$", "gettextAtom", ")", ";", "}", "if", "(", "\\", "preg_match", "(", "'/^(?:v|w)(?: % 10+)? == (\\d+)(?:\\.\\.\\d+)?$/'", ",", "$", "gettextAtom", ",", "$", "m", ")", ")", "{", "// For gettext: v == 0, w == 0", "return", "(", "(", "int", ")", "$", "m", "[", "1", "]", ")", "===", "0", ";", "}", "if", "(", "\\", "preg_match", "(", "'/^(?:v|w)(?: % 10+)? != (\\d+)(?:\\.\\.\\d+)?$/'", ",", "$", "gettextAtom", ",", "$", "m", ")", ")", "{", "// For gettext: v == 0, w == 0", "return", "(", "(", "int", ")", "$", "m", "[", "1", "]", ")", "!==", "0", ";", "}", "if", "(", "\\", "preg_match", "(", "'/^(?:f|t)(?: % 10+)? == (\\d+)(?:\\.\\.\\d+)?$/'", ",", "$", "gettextAtom", ",", "$", "m", ")", ")", "{", "// f == empty, t == empty", "return", "(", "(", "int", ")", "$", "m", "[", "1", "]", ")", "===", "0", ";", "}", "if", "(", "\\", "preg_match", "(", "'/^(?:f|t)(?: % 10+)? != (\\d+)(?:\\.\\.\\d+)?$/'", ",", "$", "gettextAtom", ",", "$", "m", ")", ")", "{", "// f == empty, t == empty", "return", "(", "(", "int", ")", "$", "m", "[", "1", "]", ")", "!==", "0", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Unable to convert the formula chunk '$cldrAtom' from CLDR to gettext\"", ")", ";", "}" ]
Converts an atomic part of the CLDR formula to its gettext representation. @param string $cldrAtom The CLDR formula atom to convert. @throws \InvalidArgumentException @return bool|string Returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise.
[ "Converts", "an", "atomic", "part", "of", "the", "CLDR", "formula", "to", "its", "gettext", "representation", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Languages/FormulaConverter.php#L79-L107
35,114
hail-framework/framework
src/I18n/Gettext/Translations.php
Translations.setLanguage
public function setLanguage($language) { $this->setHeader(self::HEADER_LANGUAGE, trim($language)); if ($info = Language::getById($language)) { return $this->setPluralForms(\count($info->categories), $info->formula); } throw new InvalidArgumentException(sprintf('The language "%s" is not valid', $language)); }
php
public function setLanguage($language) { $this->setHeader(self::HEADER_LANGUAGE, trim($language)); if ($info = Language::getById($language)) { return $this->setPluralForms(\count($info->categories), $info->formula); } throw new InvalidArgumentException(sprintf('The language "%s" is not valid', $language)); }
[ "public", "function", "setLanguage", "(", "$", "language", ")", "{", "$", "this", "->", "setHeader", "(", "self", "::", "HEADER_LANGUAGE", ",", "trim", "(", "$", "language", ")", ")", ";", "if", "(", "$", "info", "=", "Language", "::", "getById", "(", "$", "language", ")", ")", "{", "return", "$", "this", "->", "setPluralForms", "(", "\\", "count", "(", "$", "info", "->", "categories", ")", ",", "$", "info", "->", "formula", ")", ";", "}", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'The language \"%s\" is not valid'", ",", "$", "language", ")", ")", ";", "}" ]
Sets the language and the plural forms. @param string $language @throws InvalidArgumentException if the language hasn't been recognized @return self
[ "Sets", "the", "language", "and", "the", "plural", "forms", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Translations.php#L350-L359
35,115
hail-framework/framework
src/I18n/Gettext/Translations.php
Translations.countTranslated
public function countTranslated() { $callback = function (Translation $v) { return $v->hasTranslation() ? $v->getTranslation() : null; }; return \count(\array_filter(\get_object_vars($this), $callback)); }
php
public function countTranslated() { $callback = function (Translation $v) { return $v->hasTranslation() ? $v->getTranslation() : null; }; return \count(\array_filter(\get_object_vars($this), $callback)); }
[ "public", "function", "countTranslated", "(", ")", "{", "$", "callback", "=", "function", "(", "Translation", "$", "v", ")", "{", "return", "$", "v", "->", "hasTranslation", "(", ")", "?", "$", "v", "->", "getTranslation", "(", ")", ":", "null", ";", "}", ";", "return", "\\", "count", "(", "\\", "array_filter", "(", "\\", "get_object_vars", "(", "$", "this", ")", ",", "$", "callback", ")", ")", ";", "}" ]
Count all elements translated @return integer
[ "Count", "all", "elements", "translated" ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Translations.php#L433-L440
35,116
cfxmarkets/php-public-models
src/Brokerage/AssetIntent.php
AssetIntent.validateStatus
public function validateStatus() { if ($this->getStatus() === 'closed') { $this->setError('global', 'status-final', $this->getFactory()->newError([ "status" => 400, "title" => "Updates No Longer Permitted", "detail" => "This intent's status is in a final state and you can no longer update it. If you need to update the asset information, create a new intent with the new data." ])); return false; } else { $this->clearError('global', 'status-final'); return true; } }
php
public function validateStatus() { if ($this->getStatus() === 'closed') { $this->setError('global', 'status-final', $this->getFactory()->newError([ "status" => 400, "title" => "Updates No Longer Permitted", "detail" => "This intent's status is in a final state and you can no longer update it. If you need to update the asset information, create a new intent with the new data." ])); return false; } else { $this->clearError('global', 'status-final'); return true; } }
[ "public", "function", "validateStatus", "(", ")", "{", "if", "(", "$", "this", "->", "getStatus", "(", ")", "===", "'closed'", ")", "{", "$", "this", "->", "setError", "(", "'global'", ",", "'status-final'", ",", "$", "this", "->", "getFactory", "(", ")", "->", "newError", "(", "[", "\"status\"", "=>", "400", ",", "\"title\"", "=>", "\"Updates No Longer Permitted\"", ",", "\"detail\"", "=>", "\"This intent's status is in a final state and you can no longer update it. If you need to update the asset information, create a new intent with the new data.\"", "]", ")", ")", ";", "return", "false", ";", "}", "else", "{", "$", "this", "->", "clearError", "(", "'global'", ",", "'status-final'", ")", ";", "return", "true", ";", "}", "}" ]
Check to see if the status of this asset intent permits further updates @return bool
[ "Check", "to", "see", "if", "the", "status", "of", "this", "asset", "intent", "permits", "further", "updates" ]
b91a58f7d9519b98b29c58f0911e976e361a5f65
https://github.com/cfxmarkets/php-public-models/blob/b91a58f7d9519b98b29c58f0911e976e361a5f65/src/Brokerage/AssetIntent.php#L227-L239
35,117
DoSomething/gateway
src/Server/Token.php
Token.getClaim
protected function getClaim($claim) { $token = $this->parseToken(); return $token ? $token->getClaim($claim) : null; }
php
protected function getClaim($claim) { $token = $this->parseToken(); return $token ? $token->getClaim($claim) : null; }
[ "protected", "function", "getClaim", "(", "$", "claim", ")", "{", "$", "token", "=", "$", "this", "->", "parseToken", "(", ")", ";", "return", "$", "token", "?", "$", "token", "->", "getClaim", "(", "$", "claim", ")", ":", "null", ";", "}" ]
Get the given claim from the JWT. @return mixed|null
[ "Get", "the", "given", "claim", "from", "the", "JWT", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Server/Token.php#L128-L133
35,118
DoSomething/gateway
src/Server/Token.php
Token.parseToken
protected function parseToken() { $request = $this->requestHandler->getRequest(); if (! $request->hasHeader('Authorization')) { return null; } try { // Attempt to parse and validate the JWT $jwt = $request->bearerToken(); $token = (new Parser())->parse($jwt); if (! $token->verify(new Sha256(), file_get_contents($this->publicKey))) { throw new AccessDeniedException( 'Access token could not be verified.', 'Check authorization and resource environment match & that token has not been tampered with.' ); } // Ensure access token hasn't expired $data = new ValidationData(); $data->setCurrentTime(Carbon::now()->timestamp); if ($token->validate($data) === false) { throw new AccessDeniedException('Access token is invalid or expired.'); } // We've made it! Save the details on the validator. return $token; } catch (\InvalidArgumentException $exception) { throw new AccessDeniedException('Could not parse JWT.', $exception->getMessage()); } catch (\RuntimeException $exception) { throw new AccessDeniedException('Error while decoding JWT contents.'); } }
php
protected function parseToken() { $request = $this->requestHandler->getRequest(); if (! $request->hasHeader('Authorization')) { return null; } try { // Attempt to parse and validate the JWT $jwt = $request->bearerToken(); $token = (new Parser())->parse($jwt); if (! $token->verify(new Sha256(), file_get_contents($this->publicKey))) { throw new AccessDeniedException( 'Access token could not be verified.', 'Check authorization and resource environment match & that token has not been tampered with.' ); } // Ensure access token hasn't expired $data = new ValidationData(); $data->setCurrentTime(Carbon::now()->timestamp); if ($token->validate($data) === false) { throw new AccessDeniedException('Access token is invalid or expired.'); } // We've made it! Save the details on the validator. return $token; } catch (\InvalidArgumentException $exception) { throw new AccessDeniedException('Could not parse JWT.', $exception->getMessage()); } catch (\RuntimeException $exception) { throw new AccessDeniedException('Error while decoding JWT contents.'); } }
[ "protected", "function", "parseToken", "(", ")", "{", "$", "request", "=", "$", "this", "->", "requestHandler", "->", "getRequest", "(", ")", ";", "if", "(", "!", "$", "request", "->", "hasHeader", "(", "'Authorization'", ")", ")", "{", "return", "null", ";", "}", "try", "{", "// Attempt to parse and validate the JWT", "$", "jwt", "=", "$", "request", "->", "bearerToken", "(", ")", ";", "$", "token", "=", "(", "new", "Parser", "(", ")", ")", "->", "parse", "(", "$", "jwt", ")", ";", "if", "(", "!", "$", "token", "->", "verify", "(", "new", "Sha256", "(", ")", ",", "file_get_contents", "(", "$", "this", "->", "publicKey", ")", ")", ")", "{", "throw", "new", "AccessDeniedException", "(", "'Access token could not be verified.'", ",", "'Check authorization and resource environment match & that token has not been tampered with.'", ")", ";", "}", "// Ensure access token hasn't expired", "$", "data", "=", "new", "ValidationData", "(", ")", ";", "$", "data", "->", "setCurrentTime", "(", "Carbon", "::", "now", "(", ")", "->", "timestamp", ")", ";", "if", "(", "$", "token", "->", "validate", "(", "$", "data", ")", "===", "false", ")", "{", "throw", "new", "AccessDeniedException", "(", "'Access token is invalid or expired.'", ")", ";", "}", "// We've made it! Save the details on the validator.", "return", "$", "token", ";", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "exception", ")", "{", "throw", "new", "AccessDeniedException", "(", "'Could not parse JWT.'", ",", "$", "exception", "->", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "\\", "RuntimeException", "$", "exception", ")", "{", "throw", "new", "AccessDeniedException", "(", "'Error while decoding JWT contents.'", ")", ";", "}", "}" ]
Parse and validate the token from the request. @throws AccessDeniedHttpException @return JwtToken|null
[ "Parse", "and", "validate", "the", "token", "from", "the", "request", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Server/Token.php#L141-L173
35,119
hail-framework/framework
src/Http/Client/AbstractClient.php
AbstractClient.doValidateOptions
private function doValidateOptions(array $options = []): array { if ( isset($this->options['curl'], $options['curl']) && \is_array($this->options['curl']) && \is_array($options['curl']) ) { $parameters['curl'] = \array_replace($this->options['curl'], $options['curl']); } $options = \array_replace($this->options, $options); foreach (static::$types as $k => $v) { $type = \gettype($options[$k]); $v = (array) $v; $checked = false; foreach ($v as $t) { if ($t === $type || ($t === 'callable' && \is_callable($options[$k]))) { $checked = true; break; } } if (!$checked) { $should = \implode(', ', $v); throw new InvalidArgumentException("'$k' options should be '$should', but get '$type'"); } } return $options; }
php
private function doValidateOptions(array $options = []): array { if ( isset($this->options['curl'], $options['curl']) && \is_array($this->options['curl']) && \is_array($options['curl']) ) { $parameters['curl'] = \array_replace($this->options['curl'], $options['curl']); } $options = \array_replace($this->options, $options); foreach (static::$types as $k => $v) { $type = \gettype($options[$k]); $v = (array) $v; $checked = false; foreach ($v as $t) { if ($t === $type || ($t === 'callable' && \is_callable($options[$k]))) { $checked = true; break; } } if (!$checked) { $should = \implode(', ', $v); throw new InvalidArgumentException("'$k' options should be '$should', but get '$type'"); } } return $options; }
[ "private", "function", "doValidateOptions", "(", "array", "$", "options", "=", "[", "]", ")", ":", "array", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'curl'", "]", ",", "$", "options", "[", "'curl'", "]", ")", "&&", "\\", "is_array", "(", "$", "this", "->", "options", "[", "'curl'", "]", ")", "&&", "\\", "is_array", "(", "$", "options", "[", "'curl'", "]", ")", ")", "{", "$", "parameters", "[", "'curl'", "]", "=", "\\", "array_replace", "(", "$", "this", "->", "options", "[", "'curl'", "]", ",", "$", "options", "[", "'curl'", "]", ")", ";", "}", "$", "options", "=", "\\", "array_replace", "(", "$", "this", "->", "options", ",", "$", "options", ")", ";", "foreach", "(", "static", "::", "$", "types", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "type", "=", "\\", "gettype", "(", "$", "options", "[", "$", "k", "]", ")", ";", "$", "v", "=", "(", "array", ")", "$", "v", ";", "$", "checked", "=", "false", ";", "foreach", "(", "$", "v", "as", "$", "t", ")", "{", "if", "(", "$", "t", "===", "$", "type", "||", "(", "$", "t", "===", "'callable'", "&&", "\\", "is_callable", "(", "$", "options", "[", "$", "k", "]", ")", ")", ")", "{", "$", "checked", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "checked", ")", "{", "$", "should", "=", "\\", "implode", "(", "', '", ",", "$", "v", ")", ";", "throw", "new", "InvalidArgumentException", "(", "\"'$k' options should be '$should', but get '$type'\"", ")", ";", "}", "}", "return", "$", "options", ";", "}" ]
Validate a set of options and return a array. @param array $options @return array
[ "Validate", "a", "set", "of", "options", "and", "return", "a", "array", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Client/AbstractClient.php#L61-L92
35,120
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getTableMigration
public function getTableMigration($output, $new, $old) { if (!empty($this->options['foreign_keys'])) { $output[] = $this->getSetUniqueChecks(0); $output[] = $this->getSetForeignKeyCheck(0); } $output = $this->getTableMigrationNewDatabase($output, $new, $old); $output = $this->getTableMigrationNewTables($output, $new, $old); if (!empty($this->options['foreign_keys'])) { $lines = $this->getForeignKeysMigrations($new, $old); $output = $this->appendLines($output, $lines); } $output = $this->getTableMigrationOldTables($output, $new, $old); if (!empty($this->options['foreign_keys'])) { $output[] = $this->getSetForeignKeyCheck(1); $output[] = $this->getSetUniqueChecks(1); } return $output; }
php
public function getTableMigration($output, $new, $old) { if (!empty($this->options['foreign_keys'])) { $output[] = $this->getSetUniqueChecks(0); $output[] = $this->getSetForeignKeyCheck(0); } $output = $this->getTableMigrationNewDatabase($output, $new, $old); $output = $this->getTableMigrationNewTables($output, $new, $old); if (!empty($this->options['foreign_keys'])) { $lines = $this->getForeignKeysMigrations($new, $old); $output = $this->appendLines($output, $lines); } $output = $this->getTableMigrationOldTables($output, $new, $old); if (!empty($this->options['foreign_keys'])) { $output[] = $this->getSetForeignKeyCheck(1); $output[] = $this->getSetUniqueChecks(1); } return $output; }
[ "public", "function", "getTableMigration", "(", "$", "output", ",", "$", "new", ",", "$", "old", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'foreign_keys'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "$", "this", "->", "getSetUniqueChecks", "(", "0", ")", ";", "$", "output", "[", "]", "=", "$", "this", "->", "getSetForeignKeyCheck", "(", "0", ")", ";", "}", "$", "output", "=", "$", "this", "->", "getTableMigrationNewDatabase", "(", "$", "output", ",", "$", "new", ",", "$", "old", ")", ";", "$", "output", "=", "$", "this", "->", "getTableMigrationNewTables", "(", "$", "output", ",", "$", "new", ",", "$", "old", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'foreign_keys'", "]", ")", ")", "{", "$", "lines", "=", "$", "this", "->", "getForeignKeysMigrations", "(", "$", "new", ",", "$", "old", ")", ";", "$", "output", "=", "$", "this", "->", "appendLines", "(", "$", "output", ",", "$", "lines", ")", ";", "}", "$", "output", "=", "$", "this", "->", "getTableMigrationOldTables", "(", "$", "output", ",", "$", "new", ",", "$", "old", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'foreign_keys'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "$", "this", "->", "getSetForeignKeyCheck", "(", "1", ")", ";", "$", "output", "[", "]", "=", "$", "this", "->", "getSetUniqueChecks", "(", "1", ")", ";", "}", "return", "$", "output", ";", "}" ]
Get table migration. @param string[] $output Output @param array $new New schema @param array $old Old schema @return array Output
[ "Get", "table", "migration", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L125-L148
35,121
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getAlterDatabaseCharset
protected function getAlterDatabaseCharset($charset, $database = null) { if ($database !== null) { $database = ' ' . $this->dba->ident($database); } $charset = $this->dba->quote($charset); return sprintf("%s\$this->execute(\"ALTER DATABASE%s CHARACTER SET %s;\");", $this->ind2, $database, $charset); }
php
protected function getAlterDatabaseCharset($charset, $database = null) { if ($database !== null) { $database = ' ' . $this->dba->ident($database); } $charset = $this->dba->quote($charset); return sprintf("%s\$this->execute(\"ALTER DATABASE%s CHARACTER SET %s;\");", $this->ind2, $database, $charset); }
[ "protected", "function", "getAlterDatabaseCharset", "(", "$", "charset", ",", "$", "database", "=", "null", ")", "{", "if", "(", "$", "database", "!==", "null", ")", "{", "$", "database", "=", "' '", ".", "$", "this", "->", "dba", "->", "ident", "(", "$", "database", ")", ";", "}", "$", "charset", "=", "$", "this", "->", "dba", "->", "quote", "(", "$", "charset", ")", ";", "return", "sprintf", "(", "\"%s\\$this->execute(\\\"ALTER DATABASE%s CHARACTER SET %s;\\\");\"", ",", "$", "this", "->", "ind2", ",", "$", "database", ",", "$", "charset", ")", ";", "}" ]
Generate alter database charset. @param string $charset @param string $database @return string
[ "Generate", "alter", "database", "charset", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L258-L266
35,122
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getAlterDatabaseCollate
protected function getAlterDatabaseCollate($collate, $database = null) { if ($database) { $database = ' ' . $this->dba->ident($database); } $collate = $this->dba->quote($collate); return sprintf("%s\$this->execute(\"ALTER DATABASE%s COLLATE=%s;\");", $this->ind2, $database, $collate); }
php
protected function getAlterDatabaseCollate($collate, $database = null) { if ($database) { $database = ' ' . $this->dba->ident($database); } $collate = $this->dba->quote($collate); return sprintf("%s\$this->execute(\"ALTER DATABASE%s COLLATE=%s;\");", $this->ind2, $database, $collate); }
[ "protected", "function", "getAlterDatabaseCollate", "(", "$", "collate", ",", "$", "database", "=", "null", ")", "{", "if", "(", "$", "database", ")", "{", "$", "database", "=", "' '", ".", "$", "this", "->", "dba", "->", "ident", "(", "$", "database", ")", ";", "}", "$", "collate", "=", "$", "this", "->", "dba", "->", "quote", "(", "$", "collate", ")", ";", "return", "sprintf", "(", "\"%s\\$this->execute(\\\"ALTER DATABASE%s COLLATE=%s;\\\");\"", ",", "$", "this", "->", "ind2", ",", "$", "database", ",", "$", "collate", ")", ";", "}" ]
Generate alter database collate. @param string $collate @param string $database @return string
[ "Generate", "alter", "database", "collate", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L276-L284
35,123
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getCreateTable
protected function getCreateTable($output, $table, $tableName, $forceSave = false) { $output[] = $this->getTableVariable($table, $tableName); $alternatePrimaryKeys = $this->getAlternatePrimaryKeys($table); if (empty($alternatePrimaryKeys) || $forceSave) { $output[] = sprintf("%s\$table->save();", $this->ind2); } return $output; }
php
protected function getCreateTable($output, $table, $tableName, $forceSave = false) { $output[] = $this->getTableVariable($table, $tableName); $alternatePrimaryKeys = $this->getAlternatePrimaryKeys($table); if (empty($alternatePrimaryKeys) || $forceSave) { $output[] = sprintf("%s\$table->save();", $this->ind2); } return $output; }
[ "protected", "function", "getCreateTable", "(", "$", "output", ",", "$", "table", ",", "$", "tableName", ",", "$", "forceSave", "=", "false", ")", "{", "$", "output", "[", "]", "=", "$", "this", "->", "getTableVariable", "(", "$", "table", ",", "$", "tableName", ")", ";", "$", "alternatePrimaryKeys", "=", "$", "this", "->", "getAlternatePrimaryKeys", "(", "$", "table", ")", ";", "if", "(", "empty", "(", "$", "alternatePrimaryKeys", ")", "||", "$", "forceSave", ")", "{", "$", "output", "[", "]", "=", "sprintf", "(", "\"%s\\$table->save();\"", ",", "$", "this", "->", "ind2", ")", ";", "}", "return", "$", "output", ";", "}" ]
Generate create table. @param array $output @param array $table @param bool $forceSave (false) @return array
[ "Generate", "create", "table", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L328-L338
35,124
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getTableVariable
protected function getTableVariable($table, $tableName) { $options = $this->getTableOptions($table); $result = sprintf("%s\$table = \$this->table(\"%s\", %s);", $this->ind2, $tableName, $options); return $result; }
php
protected function getTableVariable($table, $tableName) { $options = $this->getTableOptions($table); $result = sprintf("%s\$table = \$this->table(\"%s\", %s);", $this->ind2, $tableName, $options); return $result; }
[ "protected", "function", "getTableVariable", "(", "$", "table", ",", "$", "tableName", ")", "{", "$", "options", "=", "$", "this", "->", "getTableOptions", "(", "$", "table", ")", ";", "$", "result", "=", "sprintf", "(", "\"%s\\$table = \\$this->table(\\\"%s\\\", %s);\"", ",", "$", "this", "->", "ind2", ",", "$", "tableName", ",", "$", "options", ")", ";", "return", "$", "result", ";", "}" ]
Generate create table variable. @param array $table @param string $tableName @return string
[ "Generate", "create", "table", "variable", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L348-L354
35,125
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getPhinxTablePrimaryKey
protected function getPhinxTablePrimaryKey($attributes, $table) { $alternatePrimaryKeys = $this->getAlternatePrimaryKeys($table); if (!empty($alternatePrimaryKeys)) { $attributes[] = "'id' => false"; $valueString = '[' . implode(', ', $alternatePrimaryKeys) . ']'; $attributes[] = "'primary_key' => " . $valueString; } return $attributes; }
php
protected function getPhinxTablePrimaryKey($attributes, $table) { $alternatePrimaryKeys = $this->getAlternatePrimaryKeys($table); if (!empty($alternatePrimaryKeys)) { $attributes[] = "'id' => false"; $valueString = '[' . implode(', ', $alternatePrimaryKeys) . ']'; $attributes[] = "'primary_key' => " . $valueString; } return $attributes; }
[ "protected", "function", "getPhinxTablePrimaryKey", "(", "$", "attributes", ",", "$", "table", ")", "{", "$", "alternatePrimaryKeys", "=", "$", "this", "->", "getAlternatePrimaryKeys", "(", "$", "table", ")", ";", "if", "(", "!", "empty", "(", "$", "alternatePrimaryKeys", ")", ")", "{", "$", "attributes", "[", "]", "=", "\"'id' => false\"", ";", "$", "valueString", "=", "'['", ".", "implode", "(", "', '", ",", "$", "alternatePrimaryKeys", ")", ".", "']'", ";", "$", "attributes", "[", "]", "=", "\"'primary_key' => \"", ".", "$", "valueString", ";", "}", "return", "$", "attributes", ";", "}" ]
Define table id value @param array $attributes @param array $table @return array Attributes
[ "Define", "table", "id", "value" ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L394-L404
35,126
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getAlternatePrimaryKeys
protected function getAlternatePrimaryKeys($table) { $alternatePrimaryKey = false; $primaryKeys = []; foreach ($table['columns'] as $column) { $columnName = $column['COLUMN_NAME']; $columnKey = $column['COLUMN_KEY']; if ($columnKey !== 'PRI') { continue; } if ($columnName !== 'id') { $alternatePrimaryKey = true; } $primaryKeys[] = '"' . $columnName . '"'; } if ($alternatePrimaryKey) { return $primaryKeys; } return null; }
php
protected function getAlternatePrimaryKeys($table) { $alternatePrimaryKey = false; $primaryKeys = []; foreach ($table['columns'] as $column) { $columnName = $column['COLUMN_NAME']; $columnKey = $column['COLUMN_KEY']; if ($columnKey !== 'PRI') { continue; } if ($columnName !== 'id') { $alternatePrimaryKey = true; } $primaryKeys[] = '"' . $columnName . '"'; } if ($alternatePrimaryKey) { return $primaryKeys; } return null; }
[ "protected", "function", "getAlternatePrimaryKeys", "(", "$", "table", ")", "{", "$", "alternatePrimaryKey", "=", "false", ";", "$", "primaryKeys", "=", "[", "]", ";", "foreach", "(", "$", "table", "[", "'columns'", "]", "as", "$", "column", ")", "{", "$", "columnName", "=", "$", "column", "[", "'COLUMN_NAME'", "]", ";", "$", "columnKey", "=", "$", "column", "[", "'COLUMN_KEY'", "]", ";", "if", "(", "$", "columnKey", "!==", "'PRI'", ")", "{", "continue", ";", "}", "if", "(", "$", "columnName", "!==", "'id'", ")", "{", "$", "alternatePrimaryKey", "=", "true", ";", "}", "$", "primaryKeys", "[", "]", "=", "'\"'", ".", "$", "columnName", ".", "'\"'", ";", "}", "if", "(", "$", "alternatePrimaryKey", ")", "{", "return", "$", "primaryKeys", ";", "}", "return", "null", ";", "}" ]
Collect alternate primary keys @param array $table @return array|null
[ "Collect", "alternate", "primary", "keys" ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L413-L433
35,127
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getPhinxTableComment
protected function getPhinxTableComment($attributes, $table) { if (!empty($table['table']['table_comment'])) { $attributes[] = '\'comment\' => "' . addslashes($table['table']['table_comment']) . '"'; } else { $attributes[] = '\'comment\' => ""'; } return $attributes; }
php
protected function getPhinxTableComment($attributes, $table) { if (!empty($table['table']['table_comment'])) { $attributes[] = '\'comment\' => "' . addslashes($table['table']['table_comment']) . '"'; } else { $attributes[] = '\'comment\' => ""'; } return $attributes; }
[ "protected", "function", "getPhinxTableComment", "(", "$", "attributes", ",", "$", "table", ")", "{", "if", "(", "!", "empty", "(", "$", "table", "[", "'table'", "]", "[", "'table_comment'", "]", ")", ")", "{", "$", "attributes", "[", "]", "=", "'\\'comment\\' => \"'", ".", "addslashes", "(", "$", "table", "[", "'table'", "]", "[", "'table_comment'", "]", ")", ".", "'\"'", ";", "}", "else", "{", "$", "attributes", "[", "]", "=", "'\\'comment\\' => \"\"'", ";", "}", "return", "$", "attributes", ";", "}" ]
Set a text comment on the table. @param array $attributes @param array $table @return array Attributes
[ "Set", "a", "text", "comment", "on", "the", "table", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L500-L509
35,128
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getColumnCreateId
protected function getColumnCreateId($schema, $table, $columnName) { $result = $this->getColumnCreate($schema, $table, $columnName); $output = []; $output[] = sprintf("%sif (\$this->table('%s')->hasColumn('%s')) {", $this->ind2, $result[0], $result[1]); $output[] = sprintf("%s\$this->table(\"%s\")->changeColumn('%s', '%s', %s)->update();", $this->ind3, $result[0], $result[1], $result[2], $result[3]); $output[] = sprintf("%s} else {", $this->ind2); $output[] = sprintf("%s\$this->table(\"%s\")->addColumn('%s', '%s', %s)->update();", $this->ind3, $result[0], $result[1], $result[2], $result[3]); $output[] = sprintf("%s}", $this->ind2); return implode($this->nl, $output); }
php
protected function getColumnCreateId($schema, $table, $columnName) { $result = $this->getColumnCreate($schema, $table, $columnName); $output = []; $output[] = sprintf("%sif (\$this->table('%s')->hasColumn('%s')) {", $this->ind2, $result[0], $result[1]); $output[] = sprintf("%s\$this->table(\"%s\")->changeColumn('%s', '%s', %s)->update();", $this->ind3, $result[0], $result[1], $result[2], $result[3]); $output[] = sprintf("%s} else {", $this->ind2); $output[] = sprintf("%s\$this->table(\"%s\")->addColumn('%s', '%s', %s)->update();", $this->ind3, $result[0], $result[1], $result[2], $result[3]); $output[] = sprintf("%s}", $this->ind2); return implode($this->nl, $output); }
[ "protected", "function", "getColumnCreateId", "(", "$", "schema", ",", "$", "table", ",", "$", "columnName", ")", "{", "$", "result", "=", "$", "this", "->", "getColumnCreate", "(", "$", "schema", ",", "$", "table", ",", "$", "columnName", ")", ";", "$", "output", "=", "[", "]", ";", "$", "output", "[", "]", "=", "sprintf", "(", "\"%sif (\\$this->table('%s')->hasColumn('%s')) {\"", ",", "$", "this", "->", "ind2", ",", "$", "result", "[", "0", "]", ",", "$", "result", "[", "1", "]", ")", ";", "$", "output", "[", "]", "=", "sprintf", "(", "\"%s\\$this->table(\\\"%s\\\")->changeColumn('%s', '%s', %s)->update();\"", ",", "$", "this", "->", "ind3", ",", "$", "result", "[", "0", "]", ",", "$", "result", "[", "1", "]", ",", "$", "result", "[", "2", "]", ",", "$", "result", "[", "3", "]", ")", ";", "$", "output", "[", "]", "=", "sprintf", "(", "\"%s} else {\"", ",", "$", "this", "->", "ind2", ")", ";", "$", "output", "[", "]", "=", "sprintf", "(", "\"%s\\$this->table(\\\"%s\\\")->addColumn('%s', '%s', %s)->update();\"", ",", "$", "this", "->", "ind3", ",", "$", "result", "[", "0", "]", ",", "$", "result", "[", "1", "]", ",", "$", "result", "[", "2", "]", ",", "$", "result", "[", "3", "]", ")", ";", "$", "output", "[", "]", "=", "sprintf", "(", "\"%s}\"", ",", "$", "this", "->", "ind2", ")", ";", "return", "implode", "(", "$", "this", "->", "nl", ",", "$", "output", ")", ";", "}" ]
Get primary key column update commands. @param array $schema @param string $table @param string $columnName @return string
[ "Get", "primary", "key", "column", "update", "commands", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L571-L584
35,129
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getMySQLColumnType
protected function getMySQLColumnType($columnData) { $type = $columnData['COLUMN_TYPE']; $pattern = '/^[a-z]+/'; $match = null; preg_match($pattern, $type, $match); return $match[0]; }
php
protected function getMySQLColumnType($columnData) { $type = $columnData['COLUMN_TYPE']; $pattern = '/^[a-z]+/'; $match = null; preg_match($pattern, $type, $match); return $match[0]; }
[ "protected", "function", "getMySQLColumnType", "(", "$", "columnData", ")", "{", "$", "type", "=", "$", "columnData", "[", "'COLUMN_TYPE'", "]", ";", "$", "pattern", "=", "'/^[a-z]+/'", ";", "$", "match", "=", "null", ";", "preg_match", "(", "$", "pattern", ",", "$", "type", ",", "$", "match", ")", ";", "return", "$", "match", "[", "0", "]", ";", "}" ]
Get column type. @param array $columnData @return string
[ "Get", "column", "type", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L649-L657
35,130
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getPhinxColumnOptions
protected function getPhinxColumnOptions($phinxType, $columnData, $columns) { $attributes = []; $attributes = $this->getPhinxColumnOptionsNull($attributes, $columnData); // default value $attributes = $this->getPhinxColumnOptionsDefault($attributes, $columnData); // For timestamp columns: $attributes = $this->getPhinxColumnOptionsTimestamp($attributes, $columnData); // limit / length $attributes = $this->getPhinxColumnOptionsLimit($attributes, $columnData); // numeric attributes $attributes = $this->getPhinxColumnOptionsNumeric($attributes, $columnData); // enum values if ($phinxType === 'enum') { $attributes = $this->getOptionEnumValue($attributes, $columnData); } // Collation $attributes = $this->getPhinxColumnCollation($phinxType, $attributes, $columnData); // Encoding $attributes = $this->getPhinxColumnEncoding($phinxType, $attributes, $columnData); // Comment $attributes = $this->getPhinxColumnOptionsComment($attributes, $columnData); // after: specify the column that a new column should be placed after $attributes = $this->getPhinxColumnOptionsAfter($attributes, $columnData, $columns); // @todo // update set an action to be triggered when the row is updated (use with CURRENT_TIMESTAMP) // // For foreign key definitions: // update set an action to be triggered when the row is updated // delete set an action to be triggered when the row is deleted $result = '[' . implode(', ', $attributes) . ']'; return $result; }
php
protected function getPhinxColumnOptions($phinxType, $columnData, $columns) { $attributes = []; $attributes = $this->getPhinxColumnOptionsNull($attributes, $columnData); // default value $attributes = $this->getPhinxColumnOptionsDefault($attributes, $columnData); // For timestamp columns: $attributes = $this->getPhinxColumnOptionsTimestamp($attributes, $columnData); // limit / length $attributes = $this->getPhinxColumnOptionsLimit($attributes, $columnData); // numeric attributes $attributes = $this->getPhinxColumnOptionsNumeric($attributes, $columnData); // enum values if ($phinxType === 'enum') { $attributes = $this->getOptionEnumValue($attributes, $columnData); } // Collation $attributes = $this->getPhinxColumnCollation($phinxType, $attributes, $columnData); // Encoding $attributes = $this->getPhinxColumnEncoding($phinxType, $attributes, $columnData); // Comment $attributes = $this->getPhinxColumnOptionsComment($attributes, $columnData); // after: specify the column that a new column should be placed after $attributes = $this->getPhinxColumnOptionsAfter($attributes, $columnData, $columns); // @todo // update set an action to be triggered when the row is updated (use with CURRENT_TIMESTAMP) // // For foreign key definitions: // update set an action to be triggered when the row is updated // delete set an action to be triggered when the row is deleted $result = '[' . implode(', ', $attributes) . ']'; return $result; }
[ "protected", "function", "getPhinxColumnOptions", "(", "$", "phinxType", ",", "$", "columnData", ",", "$", "columns", ")", "{", "$", "attributes", "=", "[", "]", ";", "$", "attributes", "=", "$", "this", "->", "getPhinxColumnOptionsNull", "(", "$", "attributes", ",", "$", "columnData", ")", ";", "// default value", "$", "attributes", "=", "$", "this", "->", "getPhinxColumnOptionsDefault", "(", "$", "attributes", ",", "$", "columnData", ")", ";", "// For timestamp columns:", "$", "attributes", "=", "$", "this", "->", "getPhinxColumnOptionsTimestamp", "(", "$", "attributes", ",", "$", "columnData", ")", ";", "// limit / length", "$", "attributes", "=", "$", "this", "->", "getPhinxColumnOptionsLimit", "(", "$", "attributes", ",", "$", "columnData", ")", ";", "// numeric attributes", "$", "attributes", "=", "$", "this", "->", "getPhinxColumnOptionsNumeric", "(", "$", "attributes", ",", "$", "columnData", ")", ";", "// enum values", "if", "(", "$", "phinxType", "===", "'enum'", ")", "{", "$", "attributes", "=", "$", "this", "->", "getOptionEnumValue", "(", "$", "attributes", ",", "$", "columnData", ")", ";", "}", "// Collation", "$", "attributes", "=", "$", "this", "->", "getPhinxColumnCollation", "(", "$", "phinxType", ",", "$", "attributes", ",", "$", "columnData", ")", ";", "// Encoding", "$", "attributes", "=", "$", "this", "->", "getPhinxColumnEncoding", "(", "$", "phinxType", ",", "$", "attributes", ",", "$", "columnData", ")", ";", "// Comment", "$", "attributes", "=", "$", "this", "->", "getPhinxColumnOptionsComment", "(", "$", "attributes", ",", "$", "columnData", ")", ";", "// after: specify the column that a new column should be placed after", "$", "attributes", "=", "$", "this", "->", "getPhinxColumnOptionsAfter", "(", "$", "attributes", ",", "$", "columnData", ",", "$", "columns", ")", ";", "// @todo", "// update set an action to be triggered when the row is updated (use with CURRENT_TIMESTAMP)", "//", "// For foreign key definitions:", "// update set an action to be triggered when the row is updated", "// delete set an action to be triggered when the row is deleted", "$", "result", "=", "'['", ".", "implode", "(", "', '", ",", "$", "attributes", ")", ".", "']'", ";", "return", "$", "result", ";", "}" ]
Generate phinx column options. https://media.readthedocs.org/pdf/phinx/latest/phinx.pdf @param string $phinxType @param array $columnData @param array $columns @return string
[ "Generate", "phinx", "column", "options", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L670-L715
35,131
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getColumnLimit
public function getColumnLimit($columnData) { $limit = 0; $type = $this->getMySQLColumnType($columnData); switch ($type) { case 'int': $limit = 'MysqlAdapter::INT_REGULAR'; break; case 'tinyint': $limit = 'MysqlAdapter::INT_TINY'; break; case 'smallint': $limit = 'MysqlAdapter::INT_SMALL'; break; case 'mediumint': $limit = 'MysqlAdapter::INT_MEDIUM'; break; case 'bigint': $limit = 'MysqlAdapter::INT_BIG'; break; case 'tinytext': $limit = 'MysqlAdapter::TEXT_TINY'; break; case 'mediumtext': $limit = 'MysqlAdapter::TEXT_MEDIUM'; break; case 'longtext': $limit = 'MysqlAdapter::TEXT_LONG'; break; case 'longblob': $limit = 'MysqlAdapter::BLOB_LONG'; break; case 'mediumblob': $limit = 'MysqlAdapter::BLOB_MEDIUM'; break; case 'blob': $limit = 'MysqlAdapter::BLOB_REGULAR'; break; case 'tinyblob': $limit = 'MysqlAdapter::BLOB_TINY'; break; default: if (!empty($columnData['CHARACTER_MAXIMUM_LENGTH'])) { $limit = $columnData['CHARACTER_MAXIMUM_LENGTH']; } else { $pattern = '/\((\d+)\)/'; if (preg_match($pattern, $columnData['COLUMN_TYPE'], $match) === 1) { $limit = $match[1]; } } } return $limit; }
php
public function getColumnLimit($columnData) { $limit = 0; $type = $this->getMySQLColumnType($columnData); switch ($type) { case 'int': $limit = 'MysqlAdapter::INT_REGULAR'; break; case 'tinyint': $limit = 'MysqlAdapter::INT_TINY'; break; case 'smallint': $limit = 'MysqlAdapter::INT_SMALL'; break; case 'mediumint': $limit = 'MysqlAdapter::INT_MEDIUM'; break; case 'bigint': $limit = 'MysqlAdapter::INT_BIG'; break; case 'tinytext': $limit = 'MysqlAdapter::TEXT_TINY'; break; case 'mediumtext': $limit = 'MysqlAdapter::TEXT_MEDIUM'; break; case 'longtext': $limit = 'MysqlAdapter::TEXT_LONG'; break; case 'longblob': $limit = 'MysqlAdapter::BLOB_LONG'; break; case 'mediumblob': $limit = 'MysqlAdapter::BLOB_MEDIUM'; break; case 'blob': $limit = 'MysqlAdapter::BLOB_REGULAR'; break; case 'tinyblob': $limit = 'MysqlAdapter::BLOB_TINY'; break; default: if (!empty($columnData['CHARACTER_MAXIMUM_LENGTH'])) { $limit = $columnData['CHARACTER_MAXIMUM_LENGTH']; } else { $pattern = '/\((\d+)\)/'; if (preg_match($pattern, $columnData['COLUMN_TYPE'], $match) === 1) { $limit = $match[1]; } } } return $limit; }
[ "public", "function", "getColumnLimit", "(", "$", "columnData", ")", "{", "$", "limit", "=", "0", ";", "$", "type", "=", "$", "this", "->", "getMySQLColumnType", "(", "$", "columnData", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "'int'", ":", "$", "limit", "=", "'MysqlAdapter::INT_REGULAR'", ";", "break", ";", "case", "'tinyint'", ":", "$", "limit", "=", "'MysqlAdapter::INT_TINY'", ";", "break", ";", "case", "'smallint'", ":", "$", "limit", "=", "'MysqlAdapter::INT_SMALL'", ";", "break", ";", "case", "'mediumint'", ":", "$", "limit", "=", "'MysqlAdapter::INT_MEDIUM'", ";", "break", ";", "case", "'bigint'", ":", "$", "limit", "=", "'MysqlAdapter::INT_BIG'", ";", "break", ";", "case", "'tinytext'", ":", "$", "limit", "=", "'MysqlAdapter::TEXT_TINY'", ";", "break", ";", "case", "'mediumtext'", ":", "$", "limit", "=", "'MysqlAdapter::TEXT_MEDIUM'", ";", "break", ";", "case", "'longtext'", ":", "$", "limit", "=", "'MysqlAdapter::TEXT_LONG'", ";", "break", ";", "case", "'longblob'", ":", "$", "limit", "=", "'MysqlAdapter::BLOB_LONG'", ";", "break", ";", "case", "'mediumblob'", ":", "$", "limit", "=", "'MysqlAdapter::BLOB_MEDIUM'", ";", "break", ";", "case", "'blob'", ":", "$", "limit", "=", "'MysqlAdapter::BLOB_REGULAR'", ";", "break", ";", "case", "'tinyblob'", ":", "$", "limit", "=", "'MysqlAdapter::BLOB_TINY'", ";", "break", ";", "default", ":", "if", "(", "!", "empty", "(", "$", "columnData", "[", "'CHARACTER_MAXIMUM_LENGTH'", "]", ")", ")", "{", "$", "limit", "=", "$", "columnData", "[", "'CHARACTER_MAXIMUM_LENGTH'", "]", ";", "}", "else", "{", "$", "pattern", "=", "'/\\((\\d+)\\)/'", ";", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "columnData", "[", "'COLUMN_TYPE'", "]", ",", "$", "match", ")", "===", "1", ")", "{", "$", "limit", "=", "$", "match", "[", "1", "]", ";", "}", "}", "}", "return", "$", "limit", ";", "}" ]
Generate column limit. @param array $columnData @return string
[ "Generate", "column", "limit", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L799-L852
35,132
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getUpdateTable
protected function getUpdateTable($output, $table, $tableName) { $output = $this->getCreateTable($output, $table, $tableName, true); return $output; }
php
protected function getUpdateTable($output, $table, $tableName) { $output = $this->getCreateTable($output, $table, $tableName, true); return $output; }
[ "protected", "function", "getUpdateTable", "(", "$", "output", ",", "$", "table", ",", "$", "tableName", ")", "{", "$", "output", "=", "$", "this", "->", "getCreateTable", "(", "$", "output", ",", "$", "table", ",", "$", "tableName", ",", "true", ")", ";", "return", "$", "output", ";", "}" ]
Generate update table. @param array $output @param array $table @param string $tableName @return array
[ "Generate", "update", "table", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L1455-L1460
35,133
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getAlterTableEngine
protected function getAlterTableEngine($table, $engine) { $engine = $this->dba->quote($engine); return sprintf("%s\$this->execute(\"ALTER TABLE `%s` ENGINE=%s;\");", $this->ind2, $table, $engine); }
php
protected function getAlterTableEngine($table, $engine) { $engine = $this->dba->quote($engine); return sprintf("%s\$this->execute(\"ALTER TABLE `%s` ENGINE=%s;\");", $this->ind2, $table, $engine); }
[ "protected", "function", "getAlterTableEngine", "(", "$", "table", ",", "$", "engine", ")", "{", "$", "engine", "=", "$", "this", "->", "dba", "->", "quote", "(", "$", "engine", ")", ";", "return", "sprintf", "(", "\"%s\\$this->execute(\\\"ALTER TABLE `%s` ENGINE=%s;\\\");\"", ",", "$", "this", "->", "ind2", ",", "$", "table", ",", "$", "engine", ")", ";", "}" ]
Generate Alter Table Engine. @param string $table @param string $engine @return string
[ "Generate", "Alter", "Table", "Engine", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L1470-L1475
35,134
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getAlterTableCharset
protected function getAlterTableCharset($table, $charset) { $table = $this->dba->ident($table); $charset = $this->dba->quote($charset); return sprintf("%s\$this->execute(\"ALTER TABLE %s CHARSET=%s;\");", $this->ind2, $table, $charset); }
php
protected function getAlterTableCharset($table, $charset) { $table = $this->dba->ident($table); $charset = $this->dba->quote($charset); return sprintf("%s\$this->execute(\"ALTER TABLE %s CHARSET=%s;\");", $this->ind2, $table, $charset); }
[ "protected", "function", "getAlterTableCharset", "(", "$", "table", ",", "$", "charset", ")", "{", "$", "table", "=", "$", "this", "->", "dba", "->", "ident", "(", "$", "table", ")", ";", "$", "charset", "=", "$", "this", "->", "dba", "->", "quote", "(", "$", "charset", ")", ";", "return", "sprintf", "(", "\"%s\\$this->execute(\\\"ALTER TABLE %s CHARSET=%s;\\\");\"", ",", "$", "this", "->", "ind2", ",", "$", "table", ",", "$", "charset", ")", ";", "}" ]
Generate Alter Table Charset. @param string $table @param string $charset @return string
[ "Generate", "Alter", "Table", "Charset", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L1485-L1491
35,135
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getAlterTableCollate
protected function getAlterTableCollate($table, $collate) { $table = $this->dba->ident($table); $collate = $this->dba->quote($collate); return sprintf("%s\$this->execute(\"ALTER TABLE %s COLLATE=%s;\");", $this->ind2, $table, $collate); }
php
protected function getAlterTableCollate($table, $collate) { $table = $this->dba->ident($table); $collate = $this->dba->quote($collate); return sprintf("%s\$this->execute(\"ALTER TABLE %s COLLATE=%s;\");", $this->ind2, $table, $collate); }
[ "protected", "function", "getAlterTableCollate", "(", "$", "table", ",", "$", "collate", ")", "{", "$", "table", "=", "$", "this", "->", "dba", "->", "ident", "(", "$", "table", ")", ";", "$", "collate", "=", "$", "this", "->", "dba", "->", "quote", "(", "$", "collate", ")", ";", "return", "sprintf", "(", "\"%s\\$this->execute(\\\"ALTER TABLE %s COLLATE=%s;\\\");\"", ",", "$", "this", "->", "ind2", ",", "$", "table", ",", "$", "collate", ")", ";", "}" ]
Generate Alter Table Collate @param string $table @param string $collate @return string
[ "Generate", "Alter", "Table", "Collate" ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L1501-L1507
35,136
hail-framework/framework
src/Database/Migration/Generator/MySqlGenerator.php
MySqlGenerator.getAlterTableComment
protected function getAlterTableComment($table, $comment) { $table = $this->dba->ident($table); $commentSave = $this->dba->quote($comment); return sprintf("%s\$this->execute(\"ALTER TABLE %s COMMENT=%s;\");", $this->ind2, $table, $commentSave); }
php
protected function getAlterTableComment($table, $comment) { $table = $this->dba->ident($table); $commentSave = $this->dba->quote($comment); return sprintf("%s\$this->execute(\"ALTER TABLE %s COMMENT=%s;\");", $this->ind2, $table, $commentSave); }
[ "protected", "function", "getAlterTableComment", "(", "$", "table", ",", "$", "comment", ")", "{", "$", "table", "=", "$", "this", "->", "dba", "->", "ident", "(", "$", "table", ")", ";", "$", "commentSave", "=", "$", "this", "->", "dba", "->", "quote", "(", "$", "comment", ")", ";", "return", "sprintf", "(", "\"%s\\$this->execute(\\\"ALTER TABLE %s COMMENT=%s;\\\");\"", ",", "$", "this", "->", "ind2", ",", "$", "table", ",", "$", "commentSave", ")", ";", "}" ]
Generate alter table comment. @param string $table @param string $comment @return string
[ "Generate", "alter", "table", "comment", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlGenerator.php#L1517-L1523
35,137
hail-framework/framework
src/I18n/Gettext/Generators/Po.php
Po.multilineQuote
private static function multilineQuote($string) { $lines = \explode("\n", $string); $last = \count($lines) - 1; foreach ($lines as $k => $line) { if ($k === $last) { $lines[$k] = self::convertString($line); } else { $lines[$k] = self::convertString($line . "\n"); } } return $lines; }
php
private static function multilineQuote($string) { $lines = \explode("\n", $string); $last = \count($lines) - 1; foreach ($lines as $k => $line) { if ($k === $last) { $lines[$k] = self::convertString($line); } else { $lines[$k] = self::convertString($line . "\n"); } } return $lines; }
[ "private", "static", "function", "multilineQuote", "(", "$", "string", ")", "{", "$", "lines", "=", "\\", "explode", "(", "\"\\n\"", ",", "$", "string", ")", ";", "$", "last", "=", "\\", "count", "(", "$", "lines", ")", "-", "1", ";", "foreach", "(", "$", "lines", "as", "$", "k", "=>", "$", "line", ")", "{", "if", "(", "$", "k", "===", "$", "last", ")", "{", "$", "lines", "[", "$", "k", "]", "=", "self", "::", "convertString", "(", "$", "line", ")", ";", "}", "else", "{", "$", "lines", "[", "$", "k", "]", "=", "self", "::", "convertString", "(", "$", "line", ".", "\"\\n\"", ")", ";", "}", "}", "return", "$", "lines", ";", "}" ]
Escapes and adds double quotes to a string. @param string $string @return array
[ "Escapes", "and", "adds", "double", "quotes", "to", "a", "string", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Generators/Po.php#L86-L100
35,138
hail-framework/framework
src/I18n/Gettext/Generators/Po.php
Po.addLines
private static function addLines(array &$lines, $name, $value) { $newLines = self::multilineQuote($value); if (\count($newLines) === 1) { $lines[] = $name . ' ' . $newLines[0]; } else { $lines[] = $name . ' ""'; foreach ($newLines as $line) { $lines[] = $line; } } }
php
private static function addLines(array &$lines, $name, $value) { $newLines = self::multilineQuote($value); if (\count($newLines) === 1) { $lines[] = $name . ' ' . $newLines[0]; } else { $lines[] = $name . ' ""'; foreach ($newLines as $line) { $lines[] = $line; } } }
[ "private", "static", "function", "addLines", "(", "array", "&", "$", "lines", ",", "$", "name", ",", "$", "value", ")", "{", "$", "newLines", "=", "self", "::", "multilineQuote", "(", "$", "value", ")", ";", "if", "(", "\\", "count", "(", "$", "newLines", ")", "===", "1", ")", "{", "$", "lines", "[", "]", "=", "$", "name", ".", "' '", ".", "$", "newLines", "[", "0", "]", ";", "}", "else", "{", "$", "lines", "[", "]", "=", "$", "name", ".", "' \"\"'", ";", "foreach", "(", "$", "newLines", "as", "$", "line", ")", "{", "$", "lines", "[", "]", "=", "$", "line", ";", "}", "}", "}" ]
Add one or more lines depending whether the string is multiline or not. @param array &$lines @param string $name @param string $value
[ "Add", "one", "or", "more", "lines", "depending", "whether", "the", "string", "is", "multiline", "or", "not", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Generators/Po.php#L109-L122
35,139
hail-framework/framework
src/Image/Commands/PolygonCommand.php
PolygonCommand.execute
public function execute($image) { $points = $this->argument(0)->type('array')->required()->value(); $callback = $this->argument(1)->type('closure')->value(); $vertices_count = count($points); // check if number if coordinates is even if ($vertices_count % 2 !== 0) { throw new \Hail\Image\Exception\InvalidArgumentException( "The number of given polygon vertices must be even." ); } if ($vertices_count < 6) { throw new \Hail\Image\Exception\InvalidArgumentException( "You must have at least 3 points in your array." ); } $namespace = $image->getDriver()->getNamespace(); $polygon_classname = "\{$namespace}\Shapes\PolygonShape"; $polygon = new $polygon_classname($points); if ($callback instanceof Closure) { $callback($polygon); } $polygon->applyToImage($image); return true; }
php
public function execute($image) { $points = $this->argument(0)->type('array')->required()->value(); $callback = $this->argument(1)->type('closure')->value(); $vertices_count = count($points); // check if number if coordinates is even if ($vertices_count % 2 !== 0) { throw new \Hail\Image\Exception\InvalidArgumentException( "The number of given polygon vertices must be even." ); } if ($vertices_count < 6) { throw new \Hail\Image\Exception\InvalidArgumentException( "You must have at least 3 points in your array." ); } $namespace = $image->getDriver()->getNamespace(); $polygon_classname = "\{$namespace}\Shapes\PolygonShape"; $polygon = new $polygon_classname($points); if ($callback instanceof Closure) { $callback($polygon); } $polygon->applyToImage($image); return true; }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "$", "points", "=", "$", "this", "->", "argument", "(", "0", ")", "->", "type", "(", "'array'", ")", "->", "required", "(", ")", "->", "value", "(", ")", ";", "$", "callback", "=", "$", "this", "->", "argument", "(", "1", ")", "->", "type", "(", "'closure'", ")", "->", "value", "(", ")", ";", "$", "vertices_count", "=", "count", "(", "$", "points", ")", ";", "// check if number if coordinates is even", "if", "(", "$", "vertices_count", "%", "2", "!==", "0", ")", "{", "throw", "new", "\\", "Hail", "\\", "Image", "\\", "Exception", "\\", "InvalidArgumentException", "(", "\"The number of given polygon vertices must be even.\"", ")", ";", "}", "if", "(", "$", "vertices_count", "<", "6", ")", "{", "throw", "new", "\\", "Hail", "\\", "Image", "\\", "Exception", "\\", "InvalidArgumentException", "(", "\"You must have at least 3 points in your array.\"", ")", ";", "}", "$", "namespace", "=", "$", "image", "->", "getDriver", "(", ")", "->", "getNamespace", "(", ")", ";", "$", "polygon_classname", "=", "\"\\{$namespace}\\Shapes\\PolygonShape\"", ";", "$", "polygon", "=", "new", "$", "polygon_classname", "(", "$", "points", ")", ";", "if", "(", "$", "callback", "instanceof", "Closure", ")", "{", "$", "callback", "(", "$", "polygon", ")", ";", "}", "$", "polygon", "->", "applyToImage", "(", "$", "image", ")", ";", "return", "true", ";", "}" ]
Draw a polygon on given image @param \Hail\Image\image $image @return bool
[ "Draw", "a", "polygon", "on", "given", "image" ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/Commands/PolygonCommand.php#L16-L48
35,140
hail-framework/framework
src/Application.php
Application.param
public function param(string $name, $value = null) { if ($value === null) { return $this->params[$name] ?? null; } return $this->params[$name] = $value; }
php
public function param(string $name, $value = null) { if ($value === null) { return $this->params[$name] ?? null; } return $this->params[$name] = $value; }
[ "public", "function", "param", "(", "string", "$", "name", ",", "$", "value", "=", "null", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "$", "this", "->", "params", "[", "$", "name", "]", "??", "null", ";", "}", "return", "$", "this", "->", "params", "[", "$", "name", "]", "=", "$", "value", ";", "}" ]
Get param from router @param string $name @param mixed $value @return mixed|null
[ "Get", "param", "from", "router" ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Application.php#L258-L265
35,141
hail-framework/framework
src/Util/Closure/Serializer.php
Serializer.serialize
public static function serialize(\Closure $closure, string $type = null): string { self::$serializeType = $type; $serialized = Serialize::encode(new SerializableClosure($closure), $type); if ($serialized === null) { throw new \RuntimeException('The closure could not be serialized.'); } return $serialized; }
php
public static function serialize(\Closure $closure, string $type = null): string { self::$serializeType = $type; $serialized = Serialize::encode(new SerializableClosure($closure), $type); if ($serialized === null) { throw new \RuntimeException('The closure could not be serialized.'); } return $serialized; }
[ "public", "static", "function", "serialize", "(", "\\", "Closure", "$", "closure", ",", "string", "$", "type", "=", "null", ")", ":", "string", "{", "self", "::", "$", "serializeType", "=", "$", "type", ";", "$", "serialized", "=", "Serialize", "::", "encode", "(", "new", "SerializableClosure", "(", "$", "closure", ")", ",", "$", "type", ")", ";", "if", "(", "$", "serialized", "===", "null", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'The closure could not be serialized.'", ")", ";", "}", "return", "$", "serialized", ";", "}" ]
Takes a Closure object, decorates it with a SerializableClosure object, then performs the serialization. @param \Closure $closure Closure to serialize. @param string|null $type @return string Serialized closure. @throws \RuntimeException
[ "Takes", "a", "Closure", "object", "decorates", "it", "with", "a", "SerializableClosure", "object", "then", "performs", "the", "serialization", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/Serializer.php#L55-L66
35,142
hail-framework/framework
src/Util/Closure/Serializer.php
Serializer.unserialize
public static function unserialize($serialized, string $type = null): \Closure { self::$serializeType = $type; $unserialized = Serialize::decode($serialized, $type); if (!$unserialized instanceof SerializableClosure) { throw new \RuntimeException( 'The closure did not unserialize to a SuperClosure.' ); } return $unserialized->getClosure(); }
php
public static function unserialize($serialized, string $type = null): \Closure { self::$serializeType = $type; $unserialized = Serialize::decode($serialized, $type); if (!$unserialized instanceof SerializableClosure) { throw new \RuntimeException( 'The closure did not unserialize to a SuperClosure.' ); } return $unserialized->getClosure(); }
[ "public", "static", "function", "unserialize", "(", "$", "serialized", ",", "string", "$", "type", "=", "null", ")", ":", "\\", "Closure", "{", "self", "::", "$", "serializeType", "=", "$", "type", ";", "$", "unserialized", "=", "Serialize", "::", "decode", "(", "$", "serialized", ",", "$", "type", ")", ";", "if", "(", "!", "$", "unserialized", "instanceof", "SerializableClosure", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'The closure did not unserialize to a SuperClosure.'", ")", ";", "}", "return", "$", "unserialized", "->", "getClosure", "(", ")", ";", "}" ]
Takes a serialized closure, performs the unserialization, and then extracts and returns a the Closure object. @param string $serialized Serialized closure. @param string|null $type @throws \RuntimeException if unserialization fails. @return \Closure Unserialized closure.
[ "Takes", "a", "serialized", "closure", "performs", "the", "unserialization", "and", "then", "extracts", "and", "returns", "a", "the", "Closure", "object", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/Serializer.php#L78-L90
35,143
hail-framework/framework
src/Util/Closure/Serializer.php
Serializer.analyze
private static function analyze(\Closure $closure) { $reflection = new ReflectionClosure($closure); $scope = $reflection->getClosureScopeClass(); $data = [ 'reflection' => $reflection, 'code' => $reflection->getCode(), 'hasThis' => $reflection->isBindingRequired(), 'context' => $reflection->getUseVariables(), 'hasRefs' => false, 'binding' => $reflection->getClosureThis(), 'scope' => $scope ? $scope->getName() : null, 'isStatic' => $reflection->isStatic(), ]; return $data; }
php
private static function analyze(\Closure $closure) { $reflection = new ReflectionClosure($closure); $scope = $reflection->getClosureScopeClass(); $data = [ 'reflection' => $reflection, 'code' => $reflection->getCode(), 'hasThis' => $reflection->isBindingRequired(), 'context' => $reflection->getUseVariables(), 'hasRefs' => false, 'binding' => $reflection->getClosureThis(), 'scope' => $scope ? $scope->getName() : null, 'isStatic' => $reflection->isStatic(), ]; return $data; }
[ "private", "static", "function", "analyze", "(", "\\", "Closure", "$", "closure", ")", "{", "$", "reflection", "=", "new", "ReflectionClosure", "(", "$", "closure", ")", ";", "$", "scope", "=", "$", "reflection", "->", "getClosureScopeClass", "(", ")", ";", "$", "data", "=", "[", "'reflection'", "=>", "$", "reflection", ",", "'code'", "=>", "$", "reflection", "->", "getCode", "(", ")", ",", "'hasThis'", "=>", "$", "reflection", "->", "isBindingRequired", "(", ")", ",", "'context'", "=>", "$", "reflection", "->", "getUseVariables", "(", ")", ",", "'hasRefs'", "=>", "false", ",", "'binding'", "=>", "$", "reflection", "->", "getClosureThis", "(", ")", ",", "'scope'", "=>", "$", "scope", "?", "$", "scope", "->", "getName", "(", ")", ":", "null", ",", "'isStatic'", "=>", "$", "reflection", "->", "isStatic", "(", ")", ",", "]", ";", "return", "$", "data", ";", "}" ]
Analyzer a given closure. @param \Closure $closure @return array
[ "Analyzer", "a", "given", "closure", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/Serializer.php#L184-L201
35,144
hail-framework/framework
src/I18n/I18n.php
I18n.translator
public function translator(string $locale, string $domain, string $directory): ?TranslatorInterface { $class = GETTEXT_EXTENSION ? GettextTranslator::class : Translator::class; $previous = self::$translator; self::$translator = new $class($locale, $domain, $directory); if ($previous === null) { require __DIR__ . DIRECTORY_SEPARATOR . 'helpers.php'; } $this->locale = $locale; return $previous; }
php
public function translator(string $locale, string $domain, string $directory): ?TranslatorInterface { $class = GETTEXT_EXTENSION ? GettextTranslator::class : Translator::class; $previous = self::$translator; self::$translator = new $class($locale, $domain, $directory); if ($previous === null) { require __DIR__ . DIRECTORY_SEPARATOR . 'helpers.php'; } $this->locale = $locale; return $previous; }
[ "public", "function", "translator", "(", "string", "$", "locale", ",", "string", "$", "domain", ",", "string", "$", "directory", ")", ":", "?", "TranslatorInterface", "{", "$", "class", "=", "GETTEXT_EXTENSION", "?", "GettextTranslator", "::", "class", ":", "Translator", "::", "class", ";", "$", "previous", "=", "self", "::", "$", "translator", ";", "self", "::", "$", "translator", "=", "new", "$", "class", "(", "$", "locale", ",", "$", "domain", ",", "$", "directory", ")", ";", "if", "(", "$", "previous", "===", "null", ")", "{", "require", "__DIR__", ".", "DIRECTORY_SEPARATOR", ".", "'helpers.php'", ";", "}", "$", "this", "->", "locale", "=", "$", "locale", ";", "return", "$", "previous", ";", "}" ]
Initialize a new gettext class @param string $directory @param string $domain @param string $locale @return TranslatorInterface|null
[ "Initialize", "a", "new", "gettext", "class" ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/I18n.php#L44-L58
35,145
Kajna/K-Core
Core/Database/MSSqlDatabase.php
MSSqlDatabase.query
public function query($query, array $params = []) { // Execute query $stmt = $this->connection->prepare($query); $stmt->execute($params); // Return result resource variable return $stmt; }
php
public function query($query, array $params = []) { // Execute query $stmt = $this->connection->prepare($query); $stmt->execute($params); // Return result resource variable return $stmt; }
[ "public", "function", "query", "(", "$", "query", ",", "array", "$", "params", "=", "[", "]", ")", "{", "// Execute query", "$", "stmt", "=", "$", "this", "->", "connection", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "$", "params", ")", ";", "// Return result resource variable", "return", "$", "stmt", ";", "}" ]
Classic query method using prepared statements. @param string $query @param array $params @return \PDOStatement|resource
[ "Classic", "query", "method", "using", "prepared", "statements", "." ]
6a354056cf95e471b9b1eb372c5626123fd77df2
https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Database/MSSqlDatabase.php#L71-L78
35,146
Kajna/K-Core
Core/Database/MSSqlDatabase.php
MSSqlDatabase.delete
public function delete($query, array $params = []) { $stmt = $this->connection->prepare($query); $stmt->execute($params); return $stmt->rowCount(); }
php
public function delete($query, array $params = []) { $stmt = $this->connection->prepare($query); $stmt->execute($params); return $stmt->rowCount(); }
[ "public", "function", "delete", "(", "$", "query", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "stmt", "=", "$", "this", "->", "connection", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "$", "params", ")", ";", "return", "$", "stmt", "->", "rowCount", "(", ")", ";", "}" ]
Delete query. @param string $query @param array $params @return int
[ "Delete", "query", "." ]
6a354056cf95e471b9b1eb372c5626123fd77df2
https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Database/MSSqlDatabase.php#L156-L161
35,147
Kajna/K-Core
Core/Database/MSSqlDatabase.php
MSSqlDatabase.count
public function count($query, array $params = []) { $stmt = $this->connection->prepare($query); $stmt->execute($params); return $stmt->fetchColumn(); }
php
public function count($query, array $params = []) { $stmt = $this->connection->prepare($query); $stmt->execute($params); return $stmt->fetchColumn(); }
[ "public", "function", "count", "(", "$", "query", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "stmt", "=", "$", "this", "->", "connection", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "$", "params", ")", ";", "return", "$", "stmt", "->", "fetchColumn", "(", ")", ";", "}" ]
Count query. @param string $query @param array $params @return int
[ "Count", "query", "." ]
6a354056cf95e471b9b1eb372c5626123fd77df2
https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Database/MSSqlDatabase.php#L170-L175
35,148
Kajna/K-Core
Core/Database/MSSqlDatabase.php
MSSqlDatabase.addIndex
public function addIndex($table, $column, $name) { $sql = sprintf('ALTER TABLE %s ADD INDEX %s(%s)', $table, $name, $column); // Execute query $stmt = $this->connection->prepare($sql); return $stmt->execute(); }
php
public function addIndex($table, $column, $name) { $sql = sprintf('ALTER TABLE %s ADD INDEX %s(%s)', $table, $name, $column); // Execute query $stmt = $this->connection->prepare($sql); return $stmt->execute(); }
[ "public", "function", "addIndex", "(", "$", "table", ",", "$", "column", ",", "$", "name", ")", "{", "$", "sql", "=", "sprintf", "(", "'ALTER TABLE %s ADD INDEX %s(%s)'", ",", "$", "table", ",", "$", "name", ",", "$", "column", ")", ";", "// Execute query", "$", "stmt", "=", "$", "this", "->", "connection", "->", "prepare", "(", "$", "sql", ")", ";", "return", "$", "stmt", "->", "execute", "(", ")", ";", "}" ]
Add index to table column. @param string $table @param string $column @param string $name @return bool
[ "Add", "index", "to", "table", "column", "." ]
6a354056cf95e471b9b1eb372c5626123fd77df2
https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Database/MSSqlDatabase.php#L220-L227
35,149
hail-framework/framework
src/Template/Template.php
Template.start
public function start($name) { if ($name === 'content') { throw new \LogicException('The section name "content" is reserved.'); } if ($this->sectionName) { throw new \LogicException('You cannot nest sections within other sections.'); } $this->sectionName = $name; ob_start(); }
php
public function start($name) { if ($name === 'content') { throw new \LogicException('The section name "content" is reserved.'); } if ($this->sectionName) { throw new \LogicException('You cannot nest sections within other sections.'); } $this->sectionName = $name; ob_start(); }
[ "public", "function", "start", "(", "$", "name", ")", "{", "if", "(", "$", "name", "===", "'content'", ")", "{", "throw", "new", "\\", "LogicException", "(", "'The section name \"content\" is reserved.'", ")", ";", "}", "if", "(", "$", "this", "->", "sectionName", ")", "{", "throw", "new", "\\", "LogicException", "(", "'You cannot nest sections within other sections.'", ")", ";", "}", "$", "this", "->", "sectionName", "=", "$", "name", ";", "ob_start", "(", ")", ";", "}" ]
Start a new section block. @param string $name @throws \LogicException
[ "Start", "a", "new", "section", "block", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Template.php#L208-L221
35,150
systemson/collection
src/Base/Statements.php
Statements.where
public function where(string $column, $value): CollectionInterface { return $this->filter( function ($item) use ($column, $value) { if (isset($item[$column])) { return $item[$column] === $value; } } ); }
php
public function where(string $column, $value): CollectionInterface { return $this->filter( function ($item) use ($column, $value) { if (isset($item[$column])) { return $item[$column] === $value; } } ); }
[ "public", "function", "where", "(", "string", "$", "column", ",", "$", "value", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "filter", "(", "function", "(", "$", "item", ")", "use", "(", "$", "column", ",", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "item", "[", "$", "column", "]", ")", ")", "{", "return", "$", "item", "[", "$", "column", "]", "===", "$", "value", ";", "}", "}", ")", ";", "}" ]
Returns a new Collection containing the items in the specified column that are equal to the especified value. @param string $column The columns to filter by. @param mixed $value The value to compare each item. @return Collection A new collection instance.
[ "Returns", "a", "new", "Collection", "containing", "the", "items", "in", "the", "specified", "column", "that", "are", "equal", "to", "the", "especified", "value", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/Statements.php#L52-L61
35,151
systemson/collection
src/Base/Statements.php
Statements.orderBy
public function orderBy(string $column, string $order = 'ASC'): CollectionInterface { return $this->sort( function ($a, $b) use ($column, $order) { if (strtoupper($order) == 'ASC') { return $a[$column] <=> $b[$column]; } elseif (strtoupper($order) == 'DESC') { return $b[$column] <=> $a[$column]; } // Must throw exception if item column does not exists } ); }
php
public function orderBy(string $column, string $order = 'ASC'): CollectionInterface { return $this->sort( function ($a, $b) use ($column, $order) { if (strtoupper($order) == 'ASC') { return $a[$column] <=> $b[$column]; } elseif (strtoupper($order) == 'DESC') { return $b[$column] <=> $a[$column]; } // Must throw exception if item column does not exists } ); }
[ "public", "function", "orderBy", "(", "string", "$", "column", ",", "string", "$", "order", "=", "'ASC'", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "sort", "(", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "column", ",", "$", "order", ")", "{", "if", "(", "strtoupper", "(", "$", "order", ")", "==", "'ASC'", ")", "{", "return", "$", "a", "[", "$", "column", "]", "<=>", "$", "b", "[", "$", "column", "]", ";", "}", "elseif", "(", "strtoupper", "(", "$", "order", ")", "==", "'DESC'", ")", "{", "return", "$", "b", "[", "$", "column", "]", "<=>", "$", "a", "[", "$", "column", "]", ";", "}", "// Must throw exception if item column does not exists", "}", ")", ";", "}" ]
Returns a new Collection containing the items ordered by the especified column. @todo MUST throw exception if the column does not exists @param string $column The column to order by. @param string $order The order to sort the items. @return Collection A new collection instance.
[ "Returns", "a", "new", "Collection", "containing", "the", "items", "ordered", "by", "the", "especified", "column", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/Statements.php#L131-L143
35,152
systemson/collection
src/Base/Statements.php
Statements.join
public function join(array $array, string $pkey, string $fkey): CollectionInterface { return $this->map( function ($item) use ($array, $pkey, $fkey) { foreach ($array as $value) { if ($item[$pkey] == $value[$fkey]) { return array_merge($item, $value); } } } ); }
php
public function join(array $array, string $pkey, string $fkey): CollectionInterface { return $this->map( function ($item) use ($array, $pkey, $fkey) { foreach ($array as $value) { if ($item[$pkey] == $value[$fkey]) { return array_merge($item, $value); } } } ); }
[ "public", "function", "join", "(", "array", "$", "array", ",", "string", "$", "pkey", ",", "string", "$", "fkey", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "map", "(", "function", "(", "$", "item", ")", "use", "(", "$", "array", ",", "$", "pkey", ",", "$", "fkey", ")", "{", "foreach", "(", "$", "array", "as", "$", "value", ")", "{", "if", "(", "$", "item", "[", "$", "pkey", "]", "==", "$", "value", "[", "$", "fkey", "]", ")", "{", "return", "array_merge", "(", "$", "item", ",", "$", "value", ")", ";", "}", "}", "}", ")", ";", "}" ]
Returns a new Collection joined by the specified column. @param array $array The array to merge @param string $pkey The key to compare on the current collection. @param string $fkey The key to compare on the provided array. @return Collection A new collection instance.
[ "Returns", "a", "new", "Collection", "joined", "by", "the", "specified", "column", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/Statements.php#L178-L189
35,153
systemson/collection
src/Base/Statements.php
Statements.sum
public function sum(string $column = null): int { if (!is_null($column)) { return $this->column($column)->sum(); } return array_sum($this->toArray()); }
php
public function sum(string $column = null): int { if (!is_null($column)) { return $this->column($column)->sum(); } return array_sum($this->toArray()); }
[ "public", "function", "sum", "(", "string", "$", "column", "=", "null", ")", ":", "int", "{", "if", "(", "!", "is_null", "(", "$", "column", ")", ")", "{", "return", "$", "this", "->", "column", "(", "$", "column", ")", "->", "sum", "(", ")", ";", "}", "return", "array_sum", "(", "$", "this", "->", "toArray", "(", ")", ")", ";", "}" ]
Calculates the sum of values in the collection. @param string $column The column. @return int The collection sum.
[ "Calculates", "the", "sum", "of", "values", "in", "the", "collection", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/Statements.php#L198-L205
35,154
railken/amethyst-common
src/CommonServiceProvider.php
CommonServiceProvider.loadTranslations
public function loadTranslations() { $directory = $this->getDirectory().'/../../resources/lang'; $this->loadTranslationsFrom($directory, 'amethyst-'.$this->getPackageName()); $this->publishes([ $directory => resource_path('lang/vendor/amethyst'), ], 'resources'); }
php
public function loadTranslations() { $directory = $this->getDirectory().'/../../resources/lang'; $this->loadTranslationsFrom($directory, 'amethyst-'.$this->getPackageName()); $this->publishes([ $directory => resource_path('lang/vendor/amethyst'), ], 'resources'); }
[ "public", "function", "loadTranslations", "(", ")", "{", "$", "directory", "=", "$", "this", "->", "getDirectory", "(", ")", ".", "'/../../resources/lang'", ";", "$", "this", "->", "loadTranslationsFrom", "(", "$", "directory", ",", "'amethyst-'", ".", "$", "this", "->", "getPackageName", "(", ")", ")", ";", "$", "this", "->", "publishes", "(", "[", "$", "directory", "=>", "resource_path", "(", "'lang/vendor/amethyst'", ")", ",", "]", ",", "'resources'", ")", ";", "}" ]
Load translations.
[ "Load", "translations", "." ]
ee89a31531e267d454352e2caf02fd73be5babfe
https://github.com/railken/amethyst-common/blob/ee89a31531e267d454352e2caf02fd73be5babfe/src/CommonServiceProvider.php#L58-L67
35,155
railken/amethyst-common
src/CommonServiceProvider.php
CommonServiceProvider.loadConfigs
public function loadConfigs() { $directory = $this->getDirectory().'/../../config/*'; foreach (glob($directory) as $file) { $this->publishes([$file => config_path(basename($file))], 'config'); $this->mergeConfigFrom($file, basename($file, '.php')); } }
php
public function loadConfigs() { $directory = $this->getDirectory().'/../../config/*'; foreach (glob($directory) as $file) { $this->publishes([$file => config_path(basename($file))], 'config'); $this->mergeConfigFrom($file, basename($file, '.php')); } }
[ "public", "function", "loadConfigs", "(", ")", "{", "$", "directory", "=", "$", "this", "->", "getDirectory", "(", ")", ".", "'/../../config/*'", ";", "foreach", "(", "glob", "(", "$", "directory", ")", "as", "$", "file", ")", "{", "$", "this", "->", "publishes", "(", "[", "$", "file", "=>", "config_path", "(", "basename", "(", "$", "file", ")", ")", "]", ",", "'config'", ")", ";", "$", "this", "->", "mergeConfigFrom", "(", "$", "file", ",", "basename", "(", "$", "file", ",", "'.php'", ")", ")", ";", "}", "}" ]
Load configs-.
[ "Load", "configs", "-", "." ]
ee89a31531e267d454352e2caf02fd73be5babfe
https://github.com/railken/amethyst-common/blob/ee89a31531e267d454352e2caf02fd73be5babfe/src/CommonServiceProvider.php#L84-L92
35,156
railken/amethyst-common
src/CommonServiceProvider.php
CommonServiceProvider.getPackageName
public function getPackageName() { $reflection = new \ReflectionClass($this); $inflector = new Inflector(); return str_replace('_', '-', $inflector->tableize(str_replace('ServiceProvider', '', $reflection->getShortName()))); }
php
public function getPackageName() { $reflection = new \ReflectionClass($this); $inflector = new Inflector(); return str_replace('_', '-', $inflector->tableize(str_replace('ServiceProvider', '', $reflection->getShortName()))); }
[ "public", "function", "getPackageName", "(", ")", "{", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "this", ")", ";", "$", "inflector", "=", "new", "Inflector", "(", ")", ";", "return", "str_replace", "(", "'_'", ",", "'-'", ",", "$", "inflector", "->", "tableize", "(", "str_replace", "(", "'ServiceProvider'", ",", "''", ",", "$", "reflection", "->", "getShortName", "(", ")", ")", ")", ")", ";", "}" ]
Return package name.
[ "Return", "package", "name", "." ]
ee89a31531e267d454352e2caf02fd73be5babfe
https://github.com/railken/amethyst-common/blob/ee89a31531e267d454352e2caf02fd73be5babfe/src/CommonServiceProvider.php#L97-L103
35,157
railken/amethyst-common
src/CommonServiceProvider.php
CommonServiceProvider.loadRoutes
public function loadRoutes() { $packageName = $this->getPackageName(); foreach (Config::get('amethyst.'.$packageName.'.http') as $groupName => $group) { foreach ($group as $configName => $config) { if (Arr::get($config, 'enabled')) { Router::group($groupName, Arr::get($config, 'router'), function ($router) use ($config) { $controller = Arr::get($config, 'controller'); $reflection = new \ReflectionClass($controller); if ($reflection->hasMethod('index')) { $router->get('/', ['as' => 'index', 'uses' => $controller.'@index']); } if ($reflection->hasMethod('store')) { $router->put('/', ['as' => 'store', 'uses' => $controller.'@store']); } if ($reflection->hasMethod('erase')) { $router->delete('/', ['as' => 'erase', 'uses' => $controller.'@erase']); } if ($reflection->hasMethod('create')) { $router->post('/', ['as' => 'create', 'uses' => $controller.'@create']); } if ($reflection->hasMethod('update')) { $router->put('/{id}', ['as' => 'update', 'uses' => $controller.'@update']); } if ($reflection->hasMethod('remove')) { $router->delete('/{id}', ['as' => 'remove', 'uses' => $controller.'@remove']); } if ($reflection->hasMethod('show')) { $router->get('/{id}', ['as' => 'show', 'uses' => $controller.'@show']); } }); } } } }
php
public function loadRoutes() { $packageName = $this->getPackageName(); foreach (Config::get('amethyst.'.$packageName.'.http') as $groupName => $group) { foreach ($group as $configName => $config) { if (Arr::get($config, 'enabled')) { Router::group($groupName, Arr::get($config, 'router'), function ($router) use ($config) { $controller = Arr::get($config, 'controller'); $reflection = new \ReflectionClass($controller); if ($reflection->hasMethod('index')) { $router->get('/', ['as' => 'index', 'uses' => $controller.'@index']); } if ($reflection->hasMethod('store')) { $router->put('/', ['as' => 'store', 'uses' => $controller.'@store']); } if ($reflection->hasMethod('erase')) { $router->delete('/', ['as' => 'erase', 'uses' => $controller.'@erase']); } if ($reflection->hasMethod('create')) { $router->post('/', ['as' => 'create', 'uses' => $controller.'@create']); } if ($reflection->hasMethod('update')) { $router->put('/{id}', ['as' => 'update', 'uses' => $controller.'@update']); } if ($reflection->hasMethod('remove')) { $router->delete('/{id}', ['as' => 'remove', 'uses' => $controller.'@remove']); } if ($reflection->hasMethod('show')) { $router->get('/{id}', ['as' => 'show', 'uses' => $controller.'@show']); } }); } } } }
[ "public", "function", "loadRoutes", "(", ")", "{", "$", "packageName", "=", "$", "this", "->", "getPackageName", "(", ")", ";", "foreach", "(", "Config", "::", "get", "(", "'amethyst.'", ".", "$", "packageName", ".", "'.http'", ")", "as", "$", "groupName", "=>", "$", "group", ")", "{", "foreach", "(", "$", "group", "as", "$", "configName", "=>", "$", "config", ")", "{", "if", "(", "Arr", "::", "get", "(", "$", "config", ",", "'enabled'", ")", ")", "{", "Router", "::", "group", "(", "$", "groupName", ",", "Arr", "::", "get", "(", "$", "config", ",", "'router'", ")", ",", "function", "(", "$", "router", ")", "use", "(", "$", "config", ")", "{", "$", "controller", "=", "Arr", "::", "get", "(", "$", "config", ",", "'controller'", ")", ";", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "controller", ")", ";", "if", "(", "$", "reflection", "->", "hasMethod", "(", "'index'", ")", ")", "{", "$", "router", "->", "get", "(", "'/'", ",", "[", "'as'", "=>", "'index'", ",", "'uses'", "=>", "$", "controller", ".", "'@index'", "]", ")", ";", "}", "if", "(", "$", "reflection", "->", "hasMethod", "(", "'store'", ")", ")", "{", "$", "router", "->", "put", "(", "'/'", ",", "[", "'as'", "=>", "'store'", ",", "'uses'", "=>", "$", "controller", ".", "'@store'", "]", ")", ";", "}", "if", "(", "$", "reflection", "->", "hasMethod", "(", "'erase'", ")", ")", "{", "$", "router", "->", "delete", "(", "'/'", ",", "[", "'as'", "=>", "'erase'", ",", "'uses'", "=>", "$", "controller", ".", "'@erase'", "]", ")", ";", "}", "if", "(", "$", "reflection", "->", "hasMethod", "(", "'create'", ")", ")", "{", "$", "router", "->", "post", "(", "'/'", ",", "[", "'as'", "=>", "'create'", ",", "'uses'", "=>", "$", "controller", ".", "'@create'", "]", ")", ";", "}", "if", "(", "$", "reflection", "->", "hasMethod", "(", "'update'", ")", ")", "{", "$", "router", "->", "put", "(", "'/{id}'", ",", "[", "'as'", "=>", "'update'", ",", "'uses'", "=>", "$", "controller", ".", "'@update'", "]", ")", ";", "}", "if", "(", "$", "reflection", "->", "hasMethod", "(", "'remove'", ")", ")", "{", "$", "router", "->", "delete", "(", "'/{id}'", ",", "[", "'as'", "=>", "'remove'", ",", "'uses'", "=>", "$", "controller", ".", "'@remove'", "]", ")", ";", "}", "if", "(", "$", "reflection", "->", "hasMethod", "(", "'show'", ")", ")", "{", "$", "router", "->", "get", "(", "'/{id}'", ",", "[", "'as'", "=>", "'show'", ",", "'uses'", "=>", "$", "controller", ".", "'@show'", "]", ")", ";", "}", "}", ")", ";", "}", "}", "}", "}" ]
Load routes based on configs.
[ "Load", "routes", "based", "on", "configs", "." ]
ee89a31531e267d454352e2caf02fd73be5babfe
https://github.com/railken/amethyst-common/blob/ee89a31531e267d454352e2caf02fd73be5babfe/src/CommonServiceProvider.php#L108-L151
35,158
DoSomething/gateway
src/Common/HasAttributes.php
HasAttributes.hasGetMutator
public function hasGetMutator($key) { $TitleCase = ucwords(str_replace(['-', '_'], ' ', $key)); $StudlyCase = str_replace(' ', '', $TitleCase); return method_exists($this, 'get'.$StudlyCase.'Attribute'); }
php
public function hasGetMutator($key) { $TitleCase = ucwords(str_replace(['-', '_'], ' ', $key)); $StudlyCase = str_replace(' ', '', $TitleCase); return method_exists($this, 'get'.$StudlyCase.'Attribute'); }
[ "public", "function", "hasGetMutator", "(", "$", "key", ")", "{", "$", "TitleCase", "=", "ucwords", "(", "str_replace", "(", "[", "'-'", ",", "'_'", "]", ",", "' '", ",", "$", "key", ")", ")", ";", "$", "StudlyCase", "=", "str_replace", "(", "' '", ",", "''", ",", "$", "TitleCase", ")", ";", "return", "method_exists", "(", "$", "this", ",", "'get'", ".", "$", "StudlyCase", ".", "'Attribute'", ")", ";", "}" ]
Determine if a get mutator exists for an attribute. @param string $key @return bool
[ "Determine", "if", "a", "get", "mutator", "exists", "for", "an", "attribute", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/HasAttributes.php#L99-L105
35,159
hail-framework/framework
src/Image/AbstractDecoder.php
AbstractDecoder.isStream
public function isStream() { if ($this->data instanceof StreamInterface) { return true; } if (!is_resource($this->data)) { return false; } if (get_resource_type($this->data) !== 'stream') { return false; } return true; }
php
public function isStream() { if ($this->data instanceof StreamInterface) { return true; } if (!is_resource($this->data)) { return false; } if (get_resource_type($this->data) !== 'stream') { return false; } return true; }
[ "public", "function", "isStream", "(", ")", "{", "if", "(", "$", "this", "->", "data", "instanceof", "StreamInterface", ")", "{", "return", "true", ";", "}", "if", "(", "!", "is_resource", "(", "$", "this", "->", "data", ")", ")", "{", "return", "false", ";", "}", "if", "(", "get_resource_type", "(", "$", "this", "->", "data", ")", "!==", "'stream'", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Determines if current source data is a stream resource @return bool
[ "Determines", "if", "current", "source", "data", "is", "a", "stream", "resource" ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/AbstractDecoder.php#L209-L224
35,160
DoSomething/gateway
src/Laravel/LaravelOAuthBridge.php
LaravelOAuthBridge.persistUserToken
public function persistUserToken(AccessToken $token) { $northstarId = $token->getResourceOwnerId(); /** @var NorthstarUserContract $user */ $user = $this->getUser($northstarId); // If user hasn't tried to log in before, make them a local record. if (! $user) { $user = $this->createModel(); $user->setNorthstarIdentifier($northstarId); } // And then update their token details. $user->setOAuthToken($token); $user->save(); // Finally, tell the guard about the new token if this is the currently // logged-in user. (Otherwise, they wouldn't get the new token until // the following page load.) if (auth()->user() && auth()->user()->getNorthstarIdentifier() === $northstarId) { auth()->setUser($user); } }
php
public function persistUserToken(AccessToken $token) { $northstarId = $token->getResourceOwnerId(); /** @var NorthstarUserContract $user */ $user = $this->getUser($northstarId); // If user hasn't tried to log in before, make them a local record. if (! $user) { $user = $this->createModel(); $user->setNorthstarIdentifier($northstarId); } // And then update their token details. $user->setOAuthToken($token); $user->save(); // Finally, tell the guard about the new token if this is the currently // logged-in user. (Otherwise, they wouldn't get the new token until // the following page load.) if (auth()->user() && auth()->user()->getNorthstarIdentifier() === $northstarId) { auth()->setUser($user); } }
[ "public", "function", "persistUserToken", "(", "AccessToken", "$", "token", ")", "{", "$", "northstarId", "=", "$", "token", "->", "getResourceOwnerId", "(", ")", ";", "/** @var NorthstarUserContract $user */", "$", "user", "=", "$", "this", "->", "getUser", "(", "$", "northstarId", ")", ";", "// If user hasn't tried to log in before, make them a local record.", "if", "(", "!", "$", "user", ")", "{", "$", "user", "=", "$", "this", "->", "createModel", "(", ")", ";", "$", "user", "->", "setNorthstarIdentifier", "(", "$", "northstarId", ")", ";", "}", "// And then update their token details.", "$", "user", "->", "setOAuthToken", "(", "$", "token", ")", ";", "$", "user", "->", "save", "(", ")", ";", "// Finally, tell the guard about the new token if this is the currently", "// logged-in user. (Otherwise, they wouldn't get the new token until", "// the following page load.)", "if", "(", "auth", "(", ")", "->", "user", "(", ")", "&&", "auth", "(", ")", "->", "user", "(", ")", "->", "getNorthstarIdentifier", "(", ")", "===", "$", "northstarId", ")", "{", "auth", "(", ")", "->", "setUser", "(", "$", "user", ")", ";", "}", "}" ]
Save the access & refresh tokens for an authorized user. @param \League\OAuth2\Client\Token\AccessToken $token @return void
[ "Save", "the", "access", "&", "refresh", "tokens", "for", "an", "authorized", "user", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/LaravelOAuthBridge.php#L68-L91
35,161
DoSomething/gateway
src/Laravel/LaravelOAuthBridge.php
LaravelOAuthBridge.getClientToken
public function getClientToken() { $client = app('db')->connection()->table('clients') ->where('client_id', config('services.northstar.client_credentials.client_id')) ->first(); // If any of the required fields are empty, return null. if (empty($client->access_token) || empty($client->access_token_expiration)) { return null; } return new AccessToken([ 'access_token' => $client->access_token, 'expires' => $client->access_token_expiration, ]); }
php
public function getClientToken() { $client = app('db')->connection()->table('clients') ->where('client_id', config('services.northstar.client_credentials.client_id')) ->first(); // If any of the required fields are empty, return null. if (empty($client->access_token) || empty($client->access_token_expiration)) { return null; } return new AccessToken([ 'access_token' => $client->access_token, 'expires' => $client->access_token_expiration, ]); }
[ "public", "function", "getClientToken", "(", ")", "{", "$", "client", "=", "app", "(", "'db'", ")", "->", "connection", "(", ")", "->", "table", "(", "'clients'", ")", "->", "where", "(", "'client_id'", ",", "config", "(", "'services.northstar.client_credentials.client_id'", ")", ")", "->", "first", "(", ")", ";", "// If any of the required fields are empty, return null.", "if", "(", "empty", "(", "$", "client", "->", "access_token", ")", "||", "empty", "(", "$", "client", "->", "access_token_expiration", ")", ")", "{", "return", "null", ";", "}", "return", "new", "AccessToken", "(", "[", "'access_token'", "=>", "$", "client", "->", "access_token", ",", "'expires'", "=>", "$", "client", "->", "access_token_expiration", ",", "]", ")", ";", "}" ]
Get the OAuth client's token.
[ "Get", "the", "OAuth", "client", "s", "token", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/LaravelOAuthBridge.php#L114-L129
35,162
DoSomething/gateway
src/Laravel/LaravelOAuthBridge.php
LaravelOAuthBridge.persistClientToken
public function persistClientToken($clientId, $accessToken, $expiration, $role) { /** @var \Illuminate\Database\Query\Builder $table */ $table = app('db')->connection()->table('clients'); // If the record doesn't already exist, add it. if (! $table->where(['client_id' => $clientId])->exists()) { $table->insert(['client_id' => $clientId]); } // Update record with the new access token & expiration. $table->where(['client_id' => $clientId])->update([ 'access_token' => $accessToken, 'access_token_expiration' => $expiration, ]); }
php
public function persistClientToken($clientId, $accessToken, $expiration, $role) { /** @var \Illuminate\Database\Query\Builder $table */ $table = app('db')->connection()->table('clients'); // If the record doesn't already exist, add it. if (! $table->where(['client_id' => $clientId])->exists()) { $table->insert(['client_id' => $clientId]); } // Update record with the new access token & expiration. $table->where(['client_id' => $clientId])->update([ 'access_token' => $accessToken, 'access_token_expiration' => $expiration, ]); }
[ "public", "function", "persistClientToken", "(", "$", "clientId", ",", "$", "accessToken", ",", "$", "expiration", ",", "$", "role", ")", "{", "/** @var \\Illuminate\\Database\\Query\\Builder $table */", "$", "table", "=", "app", "(", "'db'", ")", "->", "connection", "(", ")", "->", "table", "(", "'clients'", ")", ";", "// If the record doesn't already exist, add it.", "if", "(", "!", "$", "table", "->", "where", "(", "[", "'client_id'", "=>", "$", "clientId", "]", ")", "->", "exists", "(", ")", ")", "{", "$", "table", "->", "insert", "(", "[", "'client_id'", "=>", "$", "clientId", "]", ")", ";", "}", "// Update record with the new access token & expiration.", "$", "table", "->", "where", "(", "[", "'client_id'", "=>", "$", "clientId", "]", ")", "->", "update", "(", "[", "'access_token'", "=>", "$", "accessToken", ",", "'access_token_expiration'", "=>", "$", "expiration", ",", "]", ")", ";", "}" ]
Save the access token for an authorized client. @param $clientId - OAuth client ID @param $accessToken - Encoded OAuth access token @param $expiration - Access token expiration as UNIX timestamp @return void
[ "Save", "the", "access", "token", "for", "an", "authorized", "client", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/LaravelOAuthBridge.php#L139-L154
35,163
DoSomething/gateway
src/Laravel/LaravelOAuthBridge.php
LaravelOAuthBridge.login
public function login(NorthstarUserContract $user, AccessToken $token) { // Save the user's role to their local account (for easy permission checking). $user->setRole($token->getValues()['role']); $user->save(); auth()->login($user, true); }
php
public function login(NorthstarUserContract $user, AccessToken $token) { // Save the user's role to their local account (for easy permission checking). $user->setRole($token->getValues()['role']); $user->save(); auth()->login($user, true); }
[ "public", "function", "login", "(", "NorthstarUserContract", "$", "user", ",", "AccessToken", "$", "token", ")", "{", "// Save the user's role to their local account (for easy permission checking).", "$", "user", "->", "setRole", "(", "$", "token", "->", "getValues", "(", ")", "[", "'role'", "]", ")", ";", "$", "user", "->", "save", "(", ")", ";", "auth", "(", ")", "->", "login", "(", "$", "user", ",", "true", ")", ";", "}" ]
Log a user in to the application & update their locally cached role. @param NorthstarUserContract|\Illuminate\Contracts\Auth\Authenticatable $user @param AccessToken $token @return void
[ "Log", "a", "user", "in", "to", "the", "application", "&", "update", "their", "locally", "cached", "role", "." ]
89c1c59c6af038dff790df6d5aaa9fc703246568
https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/LaravelOAuthBridge.php#L184-L191
35,164
hail-framework/framework
src/Database/Migration/Adapter/SQLiteAdapter.php
SQLiteAdapter.getColumnSqlDefinition
protected function getColumnSqlDefinition(Column $column) { $sqlType = $this->getSqlType($column->getType()); $def = ''; $def .= strtoupper($sqlType['name']); if ($column->getPrecision() && $column->getScale()) { $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } $limitable = in_array(strtoupper($sqlType['name']), $this->definitionsWithLimits); if (($column->getLimit() || isset($sqlType['limit'])) && $limitable) { $def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')'; } if (($values = $column->getValues()) && is_array($values)) { $def .= " CHECK({$column->getName()} IN ('" . implode("', '", $values) . "'))"; } $default = $column->getDefault(); $def .= ($column->isNull() || is_null($default)) ? ' NULL' : ' NOT NULL'; $def .= $this->getDefaultValueDefinition($default); $def .= ($column->isIdentity()) ? ' PRIMARY KEY AUTOINCREMENT' : ''; if ($column->getUpdate()) { $def .= ' ON UPDATE ' . $column->getUpdate(); } $def .= $this->getCommentDefinition($column); return $def; }
php
protected function getColumnSqlDefinition(Column $column) { $sqlType = $this->getSqlType($column->getType()); $def = ''; $def .= strtoupper($sqlType['name']); if ($column->getPrecision() && $column->getScale()) { $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } $limitable = in_array(strtoupper($sqlType['name']), $this->definitionsWithLimits); if (($column->getLimit() || isset($sqlType['limit'])) && $limitable) { $def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')'; } if (($values = $column->getValues()) && is_array($values)) { $def .= " CHECK({$column->getName()} IN ('" . implode("', '", $values) . "'))"; } $default = $column->getDefault(); $def .= ($column->isNull() || is_null($default)) ? ' NULL' : ' NOT NULL'; $def .= $this->getDefaultValueDefinition($default); $def .= ($column->isIdentity()) ? ' PRIMARY KEY AUTOINCREMENT' : ''; if ($column->getUpdate()) { $def .= ' ON UPDATE ' . $column->getUpdate(); } $def .= $this->getCommentDefinition($column); return $def; }
[ "protected", "function", "getColumnSqlDefinition", "(", "Column", "$", "column", ")", "{", "$", "sqlType", "=", "$", "this", "->", "getSqlType", "(", "$", "column", "->", "getType", "(", ")", ")", ";", "$", "def", "=", "''", ";", "$", "def", ".=", "strtoupper", "(", "$", "sqlType", "[", "'name'", "]", ")", ";", "if", "(", "$", "column", "->", "getPrecision", "(", ")", "&&", "$", "column", "->", "getScale", "(", ")", ")", "{", "$", "def", ".=", "'('", ".", "$", "column", "->", "getPrecision", "(", ")", ".", "','", ".", "$", "column", "->", "getScale", "(", ")", ".", "')'", ";", "}", "$", "limitable", "=", "in_array", "(", "strtoupper", "(", "$", "sqlType", "[", "'name'", "]", ")", ",", "$", "this", "->", "definitionsWithLimits", ")", ";", "if", "(", "(", "$", "column", "->", "getLimit", "(", ")", "||", "isset", "(", "$", "sqlType", "[", "'limit'", "]", ")", ")", "&&", "$", "limitable", ")", "{", "$", "def", ".=", "'('", ".", "(", "$", "column", "->", "getLimit", "(", ")", "?", ":", "$", "sqlType", "[", "'limit'", "]", ")", ".", "')'", ";", "}", "if", "(", "(", "$", "values", "=", "$", "column", "->", "getValues", "(", ")", ")", "&&", "is_array", "(", "$", "values", ")", ")", "{", "$", "def", ".=", "\" CHECK({$column->getName()} IN ('\"", ".", "implode", "(", "\"', '\"", ",", "$", "values", ")", ".", "\"'))\"", ";", "}", "$", "default", "=", "$", "column", "->", "getDefault", "(", ")", ";", "$", "def", ".=", "(", "$", "column", "->", "isNull", "(", ")", "||", "is_null", "(", "$", "default", ")", ")", "?", "' NULL'", ":", "' NOT NULL'", ";", "$", "def", ".=", "$", "this", "->", "getDefaultValueDefinition", "(", "$", "default", ")", ";", "$", "def", ".=", "(", "$", "column", "->", "isIdentity", "(", ")", ")", "?", "' PRIMARY KEY AUTOINCREMENT'", ":", "''", ";", "if", "(", "$", "column", "->", "getUpdate", "(", ")", ")", "{", "$", "def", ".=", "' ON UPDATE '", ".", "$", "column", "->", "getUpdate", "(", ")", ";", "}", "$", "def", ".=", "$", "this", "->", "getCommentDefinition", "(", "$", "column", ")", ";", "return", "$", "def", ";", "}" ]
Gets the SQLite Column Definition for a Column object. @param Column $column Column @return string
[ "Gets", "the", "SQLite", "Column", "Definition", "for", "a", "Column", "object", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Adapter/SQLiteAdapter.php#L985-L1014
35,165
systemson/collection
src/Base/EssentialTrait.php
EssentialTrait.max
public function max(string $column = null) { if ($this->isNotEmpty()) { return max($this->toArray()); } return false; }
php
public function max(string $column = null) { if ($this->isNotEmpty()) { return max($this->toArray()); } return false; }
[ "public", "function", "max", "(", "string", "$", "column", "=", "null", ")", "{", "if", "(", "$", "this", "->", "isNotEmpty", "(", ")", ")", "{", "return", "max", "(", "$", "this", "->", "toArray", "(", ")", ")", ";", "}", "return", "false", ";", "}" ]
Returns the max value of the collection. @param string $column The column to get the max value. @return mixed
[ "Returns", "the", "max", "value", "of", "the", "collection", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/EssentialTrait.php#L91-L98
35,166
systemson/collection
src/Base/EssentialTrait.php
EssentialTrait.min
public function min(string $column = null) { if ($this->isNotEmpty()) { return min($this->toArray()); } return false; }
php
public function min(string $column = null) { if ($this->isNotEmpty()) { return min($this->toArray()); } return false; }
[ "public", "function", "min", "(", "string", "$", "column", "=", "null", ")", "{", "if", "(", "$", "this", "->", "isNotEmpty", "(", ")", ")", "{", "return", "min", "(", "$", "this", "->", "toArray", "(", ")", ")", ";", "}", "return", "false", ";", "}" ]
Returns the min value of the collection. @param string $column The column to get the min value. @return mixed
[ "Returns", "the", "min", "value", "of", "the", "collection", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/EssentialTrait.php#L107-L114
35,167
systemson/collection
src/Base/EssentialTrait.php
EssentialTrait.only
public function only(array $values): self { return $this->filter(function ($value) use ($values) { return in_array($value, $values); }); }
php
public function only(array $values): self { return $this->filter(function ($value) use ($values) { return in_array($value, $values); }); }
[ "public", "function", "only", "(", "array", "$", "values", ")", ":", "self", "{", "return", "$", "this", "->", "filter", "(", "function", "(", "$", "value", ")", "use", "(", "$", "values", ")", "{", "return", "in_array", "(", "$", "value", ",", "$", "values", ")", ";", "}", ")", ";", "}" ]
Returns the items of the collection that match the specified array. @param array $values @return self
[ "Returns", "the", "items", "of", "the", "collection", "that", "match", "the", "specified", "array", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/EssentialTrait.php#L148-L153
35,168
systemson/collection
src/Base/EssentialTrait.php
EssentialTrait.except
public function except(array $values): self { return $this->filter(function ($value) use ($values) { return !in_array($value, $values); }); }
php
public function except(array $values): self { return $this->filter(function ($value) use ($values) { return !in_array($value, $values); }); }
[ "public", "function", "except", "(", "array", "$", "values", ")", ":", "self", "{", "return", "$", "this", "->", "filter", "(", "function", "(", "$", "value", ")", "use", "(", "$", "values", ")", "{", "return", "!", "in_array", "(", "$", "value", ",", "$", "values", ")", ";", "}", ")", ";", "}" ]
Returns the items of the collections that do not match the specified array. @param array $values @return self
[ "Returns", "the", "items", "of", "the", "collections", "that", "do", "not", "match", "the", "specified", "array", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/EssentialTrait.php#L162-L167
35,169
hail-framework/framework
src/Util/Closure/SerializableClosure.php
SerializableClosure.serialize
public function serialize() { try { $this->data = $this->data ?: Serializer::getData($this->closure, true); return Serialize::encode($this->data, Serializer::getSerializeType()); } catch (\Exception $e) { \trigger_error('Serialization of closure failed: ' . $e->getMessage()); // Note: The serialize() method of Serializable must return a string // or null and cannot throw exceptions. return null; } }
php
public function serialize() { try { $this->data = $this->data ?: Serializer::getData($this->closure, true); return Serialize::encode($this->data, Serializer::getSerializeType()); } catch (\Exception $e) { \trigger_error('Serialization of closure failed: ' . $e->getMessage()); // Note: The serialize() method of Serializable must return a string // or null and cannot throw exceptions. return null; } }
[ "public", "function", "serialize", "(", ")", "{", "try", "{", "$", "this", "->", "data", "=", "$", "this", "->", "data", "?", ":", "Serializer", "::", "getData", "(", "$", "this", "->", "closure", ",", "true", ")", ";", "return", "Serialize", "::", "encode", "(", "$", "this", "->", "data", ",", "Serializer", "::", "getSerializeType", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "\\", "trigger_error", "(", "'Serialization of closure failed: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "// Note: The serialize() method of Serializable must return a string", "// or null and cannot throw exceptions.", "return", "null", ";", "}", "}" ]
Serializes the code, context, and binding of the closure. @return string|null @link http://php.net/manual/en/serializable.serialize.php
[ "Serializes", "the", "code", "context", "and", "binding", "of", "the", "closure", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/SerializableClosure.php#L99-L111
35,170
hail-framework/framework
src/Util/Closure/SerializableClosure.php
SerializableClosure.unserialize
public function unserialize($serialized) { // Unserialize the closure data and reconstruct the closure object. $this->data = Serialize::decode($serialized, Serializer::getSerializeType()); $this->closure = __reconstruct_closure($this->data); // Throw an exception if the closure could not be reconstructed. if (!$this->closure instanceof \Closure) { throw new \RuntimeException( 'The closure is corrupted and cannot be unserialized.' ); } // Rebind the closure to its former binding and scope. if ($this->data['binding'] || $this->data['isStatic']) { $this->closure = $this->closure->bindTo( $this->data['binding'], $this->data['scope'] ); } }
php
public function unserialize($serialized) { // Unserialize the closure data and reconstruct the closure object. $this->data = Serialize::decode($serialized, Serializer::getSerializeType()); $this->closure = __reconstruct_closure($this->data); // Throw an exception if the closure could not be reconstructed. if (!$this->closure instanceof \Closure) { throw new \RuntimeException( 'The closure is corrupted and cannot be unserialized.' ); } // Rebind the closure to its former binding and scope. if ($this->data['binding'] || $this->data['isStatic']) { $this->closure = $this->closure->bindTo( $this->data['binding'], $this->data['scope'] ); } }
[ "public", "function", "unserialize", "(", "$", "serialized", ")", "{", "// Unserialize the closure data and reconstruct the closure object.", "$", "this", "->", "data", "=", "Serialize", "::", "decode", "(", "$", "serialized", ",", "Serializer", "::", "getSerializeType", "(", ")", ")", ";", "$", "this", "->", "closure", "=", "__reconstruct_closure", "(", "$", "this", "->", "data", ")", ";", "// Throw an exception if the closure could not be reconstructed.", "if", "(", "!", "$", "this", "->", "closure", "instanceof", "\\", "Closure", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'The closure is corrupted and cannot be unserialized.'", ")", ";", "}", "// Rebind the closure to its former binding and scope.", "if", "(", "$", "this", "->", "data", "[", "'binding'", "]", "||", "$", "this", "->", "data", "[", "'isStatic'", "]", ")", "{", "$", "this", "->", "closure", "=", "$", "this", "->", "closure", "->", "bindTo", "(", "$", "this", "->", "data", "[", "'binding'", "]", ",", "$", "this", "->", "data", "[", "'scope'", "]", ")", ";", "}", "}" ]
Unserializes the closure. Unserializes the closure's data and recreates the closure using a simulation of its original context. The used variables (context) are extracted into a fresh scope prior to redefining the closure. The closure is also rebound to its former object and scope. @param string $serialized @throws \RuntimeException @link http://php.net/manual/en/serializable.unserialize.php
[ "Unserializes", "the", "closure", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/SerializableClosure.php#L126-L146
35,171
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.enableStatistics
public function enableStatistics($enable = true, $sortBy = 'averageTime') { if (!\in_array($sortBy, ['count', 'deltaTime', 'averageTime'], true)) { throw new \InvalidArgumentException("Cannot sort statistics by '$sortBy' column."); } $this->performStatistics = (bool) $enable; $this->sortBy = $sortBy; return $this; }
php
public function enableStatistics($enable = true, $sortBy = 'averageTime') { if (!\in_array($sortBy, ['count', 'deltaTime', 'averageTime'], true)) { throw new \InvalidArgumentException("Cannot sort statistics by '$sortBy' column."); } $this->performStatistics = (bool) $enable; $this->sortBy = $sortBy; return $this; }
[ "public", "function", "enableStatistics", "(", "$", "enable", "=", "true", ",", "$", "sortBy", "=", "'averageTime'", ")", "{", "if", "(", "!", "\\", "in_array", "(", "$", "sortBy", ",", "[", "'count'", ",", "'deltaTime'", ",", "'averageTime'", "]", ",", "true", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Cannot sort statistics by '$sortBy' column.\"", ")", ";", "}", "$", "this", "->", "performStatistics", "=", "(", "bool", ")", "$", "enable", ";", "$", "this", "->", "sortBy", "=", "$", "sortBy", ";", "return", "$", "this", ";", "}" ]
Enable or disable function time statistics. @param bool enable statistics @param string sort by column 'count', 'deltaTime' or 'averageTime' @return TracePanel @throws \InvalidArgumentException
[ "Enable", "or", "disable", "function", "time", "statistics", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L193-L203
35,172
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.start
public function start($title = null) { if (!$this->isError) { if ($this->state === self::STATE_RUN) { $this->pause(); } if ($this->state === self::STATE_STOP) { $this->titles = [$title]; \xdebug_start_trace($this->traceFile, XDEBUG_TRACE_COMPUTERIZED); } elseif ($this->state === self::STATE_PAUSE) { $this->titles[] = $title; \xdebug_start_trace($this->traceFile, XDEBUG_TRACE_COMPUTERIZED | XDEBUG_TRACE_APPEND); } $this->state = self::STATE_RUN; } }
php
public function start($title = null) { if (!$this->isError) { if ($this->state === self::STATE_RUN) { $this->pause(); } if ($this->state === self::STATE_STOP) { $this->titles = [$title]; \xdebug_start_trace($this->traceFile, XDEBUG_TRACE_COMPUTERIZED); } elseif ($this->state === self::STATE_PAUSE) { $this->titles[] = $title; \xdebug_start_trace($this->traceFile, XDEBUG_TRACE_COMPUTERIZED | XDEBUG_TRACE_APPEND); } $this->state = self::STATE_RUN; } }
[ "public", "function", "start", "(", "$", "title", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "isError", ")", "{", "if", "(", "$", "this", "->", "state", "===", "self", "::", "STATE_RUN", ")", "{", "$", "this", "->", "pause", "(", ")", ";", "}", "if", "(", "$", "this", "->", "state", "===", "self", "::", "STATE_STOP", ")", "{", "$", "this", "->", "titles", "=", "[", "$", "title", "]", ";", "\\", "xdebug_start_trace", "(", "$", "this", "->", "traceFile", ",", "XDEBUG_TRACE_COMPUTERIZED", ")", ";", "}", "elseif", "(", "$", "this", "->", "state", "===", "self", "::", "STATE_PAUSE", ")", "{", "$", "this", "->", "titles", "[", "]", "=", "$", "title", ";", "\\", "xdebug_start_trace", "(", "$", "this", "->", "traceFile", ",", "XDEBUG_TRACE_COMPUTERIZED", "|", "XDEBUG_TRACE_APPEND", ")", ";", "}", "$", "this", "->", "state", "=", "self", "::", "STATE_RUN", ";", "}", "}" ]
Start or continue tracing. @param string|NULL trace title
[ "Start", "or", "continue", "tracing", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L213-L230
35,173
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.pause
public function pause() { if ($this->state === self::STATE_RUN) { \xdebug_stop_trace(); $this->state = self::STATE_PAUSE; } }
php
public function pause() { if ($this->state === self::STATE_RUN) { \xdebug_stop_trace(); $this->state = self::STATE_PAUSE; } }
[ "public", "function", "pause", "(", ")", "{", "if", "(", "$", "this", "->", "state", "===", "self", "::", "STATE_RUN", ")", "{", "\\", "xdebug_stop_trace", "(", ")", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_PAUSE", ";", "}", "}" ]
Pause tracing.
[ "Pause", "tracing", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L236-L242
35,174
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.stop
public function stop() { if ($this->state === self::STATE_RUN) { \xdebug_stop_trace(); } $this->state = self::STATE_STOP; }
php
public function stop() { if ($this->state === self::STATE_RUN) { \xdebug_stop_trace(); } $this->state = self::STATE_STOP; }
[ "public", "function", "stop", "(", ")", "{", "if", "(", "$", "this", "->", "state", "===", "self", "::", "STATE_RUN", ")", "{", "\\", "xdebug_stop_trace", "(", ")", ";", "}", "$", "this", "->", "state", "=", "self", "::", "STATE_STOP", ";", "}" ]
Stop tracing.
[ "Stop", "tracing", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L248-L255
35,175
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.time
public function time($time, $precision = 0) { $units = 's'; if ($time < 1e-6) { // <1us $units = 'ns'; $time *= 1e9; } elseif ($time < 1e-3) { // <1ms $units = "\xc2\xb5s"; $time *= 1e6; } elseif ($time < 1) { // <1s $units = 'ms'; $time *= 1e3; } return \round($time, $precision) . ' ' . $units; }
php
public function time($time, $precision = 0) { $units = 's'; if ($time < 1e-6) { // <1us $units = 'ns'; $time *= 1e9; } elseif ($time < 1e-3) { // <1ms $units = "\xc2\xb5s"; $time *= 1e6; } elseif ($time < 1) { // <1s $units = 'ms'; $time *= 1e3; } return \round($time, $precision) . ' ' . $units; }
[ "public", "function", "time", "(", "$", "time", ",", "$", "precision", "=", "0", ")", "{", "$", "units", "=", "'s'", ";", "if", "(", "$", "time", "<", "1e-6", ")", "{", "// <1us", "$", "units", "=", "'ns'", ";", "$", "time", "*=", "1e9", ";", "}", "elseif", "(", "$", "time", "<", "1e-3", ")", "{", "// <1ms", "$", "units", "=", "\"\\xc2\\xb5s\"", ";", "$", "time", "*=", "1e6", ";", "}", "elseif", "(", "$", "time", "<", "1", ")", "{", "// <1s", "$", "units", "=", "'ms'", ";", "$", "time", "*=", "1e3", ";", "}", "return", "\\", "round", "(", "$", "time", ",", "$", "precision", ")", ".", "' '", ".", "$", "units", ";", "}" ]
Template helper converts seconds to ns, us, ms, s. @param float $time time interval in seconds @param int $precision part precision @return string formated time
[ "Template", "helper", "converts", "seconds", "to", "ns", "us", "ms", "s", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L269-L286
35,176
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.timeClass
public function timeClass($time, $slow = null, $fast = null) { $slow = $slow ?: 0.02; // 20ms $fast = $fast ?: 1e-3; // 1ms if ($time <= $fast) { return 'timeFast'; } if ($time <= $slow) { return 'timeMedian'; } return 'timeSlow'; }
php
public function timeClass($time, $slow = null, $fast = null) { $slow = $slow ?: 0.02; // 20ms $fast = $fast ?: 1e-3; // 1ms if ($time <= $fast) { return 'timeFast'; } if ($time <= $slow) { return 'timeMedian'; } return 'timeSlow'; }
[ "public", "function", "timeClass", "(", "$", "time", ",", "$", "slow", "=", "null", ",", "$", "fast", "=", "null", ")", "{", "$", "slow", "=", "$", "slow", "?", ":", "0.02", ";", "// 20ms", "$", "fast", "=", "$", "fast", "?", ":", "1e-3", ";", "// 1ms", "if", "(", "$", "time", "<=", "$", "fast", ")", "{", "return", "'timeFast'", ";", "}", "if", "(", "$", "time", "<=", "$", "slow", ")", "{", "return", "'timeMedian'", ";", "}", "return", "'timeSlow'", ";", "}" ]
Template helper converts seconds to HTML class string. @param float $time time interval in seconds @param float $slow over this value is interval classified as slow @param float $fast under this value is interval classified as fast @return string
[ "Template", "helper", "converts", "seconds", "to", "HTML", "class", "string", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L298-L312
35,177
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.bytes
public function bytes($bytes, $precision = 2) { $bytes = \round($bytes); $units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB']; foreach ($units as $unit) { if (\abs($bytes) < 1024 || $unit === \end($units)) { break; } $bytes = $bytes / 1024; } return \round($bytes, $precision) . ' ' . $unit; }
php
public function bytes($bytes, $precision = 2) { $bytes = \round($bytes); $units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB']; foreach ($units as $unit) { if (\abs($bytes) < 1024 || $unit === \end($units)) { break; } $bytes = $bytes / 1024; } return \round($bytes, $precision) . ' ' . $unit; }
[ "public", "function", "bytes", "(", "$", "bytes", ",", "$", "precision", "=", "2", ")", "{", "$", "bytes", "=", "\\", "round", "(", "$", "bytes", ")", ";", "$", "units", "=", "[", "'B'", ",", "'kB'", ",", "'MB'", ",", "'GB'", ",", "'TB'", ",", "'PB'", "]", ";", "foreach", "(", "$", "units", "as", "$", "unit", ")", "{", "if", "(", "\\", "abs", "(", "$", "bytes", ")", "<", "1024", "||", "$", "unit", "===", "\\", "end", "(", "$", "units", ")", ")", "{", "break", ";", "}", "$", "bytes", "=", "$", "bytes", "/", "1024", ";", "}", "return", "\\", "round", "(", "$", "bytes", ",", "$", "precision", ")", ".", "' '", ".", "$", "unit", ";", "}" ]
Converts to human readable file size. @param int @param int @return string
[ "Converts", "to", "human", "readable", "file", "size", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L322-L334
35,178
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.setError
protected function setError($message, array $lastError = null) { $this->isError = true; $this->errMessage = $message; if ($lastError !== null) { $this->errMessage .= ': ' . $lastError['message']; $this->errFile = $lastError['file']; $this->errLine = $lastError['line']; } }
php
protected function setError($message, array $lastError = null) { $this->isError = true; $this->errMessage = $message; if ($lastError !== null) { $this->errMessage .= ': ' . $lastError['message']; $this->errFile = $lastError['file']; $this->errLine = $lastError['line']; } }
[ "protected", "function", "setError", "(", "$", "message", ",", "array", "$", "lastError", "=", "null", ")", "{", "$", "this", "->", "isError", "=", "true", ";", "$", "this", "->", "errMessage", "=", "$", "message", ";", "if", "(", "$", "lastError", "!==", "null", ")", "{", "$", "this", "->", "errMessage", ".=", "': '", ".", "$", "lastError", "[", "'message'", "]", ";", "$", "this", "->", "errFile", "=", "$", "lastError", "[", "'file'", "]", ";", "$", "this", "->", "errLine", "=", "$", "lastError", "[", "'line'", "]", ";", "}", "}" ]
Sets internal error variables. @param string $message error message @param array $lastError error_get_last()
[ "Sets", "internal", "error", "variables", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L343-L353
35,179
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.renderError
protected function renderError() { $errMessage = $this->errMessage; $errFile = $this->errFile; $errLine = $this->errLine; \ob_start(); require __DIR__ . '/templates/trace.error.phtml'; return \ob_get_clean(); }
php
protected function renderError() { $errMessage = $this->errMessage; $errFile = $this->errFile; $errLine = $this->errLine; \ob_start(); require __DIR__ . '/templates/trace.error.phtml'; return \ob_get_clean(); }
[ "protected", "function", "renderError", "(", ")", "{", "$", "errMessage", "=", "$", "this", "->", "errMessage", ";", "$", "errFile", "=", "$", "this", "->", "errFile", ";", "$", "errLine", "=", "$", "this", "->", "errLine", ";", "\\", "ob_start", "(", ")", ";", "require", "__DIR__", ".", "'/templates/trace.error.phtml'", ";", "return", "\\", "ob_get_clean", "(", ")", ";", "}" ]
Render error message. @return string rendered error template
[ "Render", "error", "message", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L361-L371
35,180
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.openTrace
protected function openTrace() { $index = \count($this->traces); $this->traces[$index] = []; $this->trace =& $this->traces[$index]; $this->indents[$index] = []; $this->indent =& $this->indents[$index]; if ($this->performStatistics) { $this->statistics[$index] = []; $this->statistic =& $this->statistics[$index]; } }
php
protected function openTrace() { $index = \count($this->traces); $this->traces[$index] = []; $this->trace =& $this->traces[$index]; $this->indents[$index] = []; $this->indent =& $this->indents[$index]; if ($this->performStatistics) { $this->statistics[$index] = []; $this->statistic =& $this->statistics[$index]; } }
[ "protected", "function", "openTrace", "(", ")", "{", "$", "index", "=", "\\", "count", "(", "$", "this", "->", "traces", ")", ";", "$", "this", "->", "traces", "[", "$", "index", "]", "=", "[", "]", ";", "$", "this", "->", "trace", "=", "&", "$", "this", "->", "traces", "[", "$", "index", "]", ";", "$", "this", "->", "indents", "[", "$", "index", "]", "=", "[", "]", ";", "$", "this", "->", "indent", "=", "&", "$", "this", "->", "indents", "[", "$", "index", "]", ";", "if", "(", "$", "this", "->", "performStatistics", ")", "{", "$", "this", "->", "statistics", "[", "$", "index", "]", "=", "[", "]", ";", "$", "this", "->", "statistic", "=", "&", "$", "this", "->", "statistics", "[", "$", "index", "]", ";", "}", "}" ]
Sets trace and indent references.
[ "Sets", "trace", "and", "indent", "references", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L488-L502
35,181
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.closeTrace
protected function closeTrace() { if ($this->trace !== null) { foreach ($this->trace as $id => $record) { if (!$record->exited) { // last chance to filter non-exited records by FILTER_EXIT callback $remove = false; foreach ($this->filterExitCallbacks as $callback) { $result = (int) $callback($record, false, $this); if ($result & self::SKIP) { $remove = true; } if ($result & self::STOP) { break; } } if ($remove) { unset($this->trace[$id]); continue; } } $this->indent[$record->level] = 1; } if (null !== $this->indent) { \ksort($this->indent); $keys = \array_keys($this->indent); $this->indent = \array_combine($keys, \array_keys($keys)); } $null = null; $this->trace =& $null; $this->indent =& $null; if ($this->performStatistics) { foreach ($this->statistic as $statistic) { $statistic->averageTime = $statistic->deltaTime / $statistic->count; } $sortBy = $this->sortBy; \uasort($this->statistic, function ($a, $b) use ($sortBy) { return $a->{$sortBy} < $b->{$sortBy}; }); $this->statistic =& $null; } } }
php
protected function closeTrace() { if ($this->trace !== null) { foreach ($this->trace as $id => $record) { if (!$record->exited) { // last chance to filter non-exited records by FILTER_EXIT callback $remove = false; foreach ($this->filterExitCallbacks as $callback) { $result = (int) $callback($record, false, $this); if ($result & self::SKIP) { $remove = true; } if ($result & self::STOP) { break; } } if ($remove) { unset($this->trace[$id]); continue; } } $this->indent[$record->level] = 1; } if (null !== $this->indent) { \ksort($this->indent); $keys = \array_keys($this->indent); $this->indent = \array_combine($keys, \array_keys($keys)); } $null = null; $this->trace =& $null; $this->indent =& $null; if ($this->performStatistics) { foreach ($this->statistic as $statistic) { $statistic->averageTime = $statistic->deltaTime / $statistic->count; } $sortBy = $this->sortBy; \uasort($this->statistic, function ($a, $b) use ($sortBy) { return $a->{$sortBy} < $b->{$sortBy}; }); $this->statistic =& $null; } } }
[ "protected", "function", "closeTrace", "(", ")", "{", "if", "(", "$", "this", "->", "trace", "!==", "null", ")", "{", "foreach", "(", "$", "this", "->", "trace", "as", "$", "id", "=>", "$", "record", ")", "{", "if", "(", "!", "$", "record", "->", "exited", ")", "{", "// last chance to filter non-exited records by FILTER_EXIT callback", "$", "remove", "=", "false", ";", "foreach", "(", "$", "this", "->", "filterExitCallbacks", "as", "$", "callback", ")", "{", "$", "result", "=", "(", "int", ")", "$", "callback", "(", "$", "record", ",", "false", ",", "$", "this", ")", ";", "if", "(", "$", "result", "&", "self", "::", "SKIP", ")", "{", "$", "remove", "=", "true", ";", "}", "if", "(", "$", "result", "&", "self", "::", "STOP", ")", "{", "break", ";", "}", "}", "if", "(", "$", "remove", ")", "{", "unset", "(", "$", "this", "->", "trace", "[", "$", "id", "]", ")", ";", "continue", ";", "}", "}", "$", "this", "->", "indent", "[", "$", "record", "->", "level", "]", "=", "1", ";", "}", "if", "(", "null", "!==", "$", "this", "->", "indent", ")", "{", "\\", "ksort", "(", "$", "this", "->", "indent", ")", ";", "$", "keys", "=", "\\", "array_keys", "(", "$", "this", "->", "indent", ")", ";", "$", "this", "->", "indent", "=", "\\", "array_combine", "(", "$", "keys", ",", "\\", "array_keys", "(", "$", "keys", ")", ")", ";", "}", "$", "null", "=", "null", ";", "$", "this", "->", "trace", "=", "&", "$", "null", ";", "$", "this", "->", "indent", "=", "&", "$", "null", ";", "if", "(", "$", "this", "->", "performStatistics", ")", "{", "foreach", "(", "$", "this", "->", "statistic", "as", "$", "statistic", ")", "{", "$", "statistic", "->", "averageTime", "=", "$", "statistic", "->", "deltaTime", "/", "$", "statistic", "->", "count", ";", "}", "$", "sortBy", "=", "$", "this", "->", "sortBy", ";", "\\", "uasort", "(", "$", "this", "->", "statistic", ",", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "sortBy", ")", "{", "return", "$", "a", "->", "{", "$", "sortBy", "}", "<", "$", "b", "->", "{", "$", "sortBy", "}", ";", "}", ")", ";", "$", "this", "->", "statistic", "=", "&", "$", "null", ";", "}", "}", "}" ]
Unset trace and indent references and compute indents.
[ "Unset", "trace", "and", "indent", "references", "and", "compute", "indents", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L508-L557
35,182
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.addRecord
protected function addRecord(\stdClass $record) { if ($record->isEntry) { $add = true; foreach ($this->filterEntryCallbacks as $callback) { $result = (int) $callback($record, true, $this); if ($result & self::SKIP) { $add = false; } if ($result & self::STOP) { break; } } if ($add) { $this->trace[$record->id] = $record; } } elseif (isset($this->trace[$record->id])) { $entryRecord = $this->trace[$record->id]; $entryRecord->exited = true; $entryRecord->exitTime = $record->time; $entryRecord->deltaTime = $record->time - $entryRecord->time; $entryRecord->exitMemory = $record->memory; $entryRecord->deltaMemory = $record->memory - $entryRecord->memory; $remove = false; foreach ($this->filterExitCallbacks as $callback) { $result = (int) $callback($entryRecord, false, $this); if ($result & self::SKIP) { $remove = true; } if ($result & self::STOP) { break; } } if ($remove) { unset($this->trace[$record->id]); } elseif ($this->performStatistics) { if (!isset($this->statistic[$entryRecord->function])) { $this->statistic[$entryRecord->function] = (object) [ 'count' => 1, 'deltaTime' => $entryRecord->deltaTime, ]; } else { $this->statistic[$entryRecord->function]->count += 1; $this->statistic[$entryRecord->function]->deltaTime += $entryRecord->deltaTime; } } } }
php
protected function addRecord(\stdClass $record) { if ($record->isEntry) { $add = true; foreach ($this->filterEntryCallbacks as $callback) { $result = (int) $callback($record, true, $this); if ($result & self::SKIP) { $add = false; } if ($result & self::STOP) { break; } } if ($add) { $this->trace[$record->id] = $record; } } elseif (isset($this->trace[$record->id])) { $entryRecord = $this->trace[$record->id]; $entryRecord->exited = true; $entryRecord->exitTime = $record->time; $entryRecord->deltaTime = $record->time - $entryRecord->time; $entryRecord->exitMemory = $record->memory; $entryRecord->deltaMemory = $record->memory - $entryRecord->memory; $remove = false; foreach ($this->filterExitCallbacks as $callback) { $result = (int) $callback($entryRecord, false, $this); if ($result & self::SKIP) { $remove = true; } if ($result & self::STOP) { break; } } if ($remove) { unset($this->trace[$record->id]); } elseif ($this->performStatistics) { if (!isset($this->statistic[$entryRecord->function])) { $this->statistic[$entryRecord->function] = (object) [ 'count' => 1, 'deltaTime' => $entryRecord->deltaTime, ]; } else { $this->statistic[$entryRecord->function]->count += 1; $this->statistic[$entryRecord->function]->deltaTime += $entryRecord->deltaTime; } } } }
[ "protected", "function", "addRecord", "(", "\\", "stdClass", "$", "record", ")", "{", "if", "(", "$", "record", "->", "isEntry", ")", "{", "$", "add", "=", "true", ";", "foreach", "(", "$", "this", "->", "filterEntryCallbacks", "as", "$", "callback", ")", "{", "$", "result", "=", "(", "int", ")", "$", "callback", "(", "$", "record", ",", "true", ",", "$", "this", ")", ";", "if", "(", "$", "result", "&", "self", "::", "SKIP", ")", "{", "$", "add", "=", "false", ";", "}", "if", "(", "$", "result", "&", "self", "::", "STOP", ")", "{", "break", ";", "}", "}", "if", "(", "$", "add", ")", "{", "$", "this", "->", "trace", "[", "$", "record", "->", "id", "]", "=", "$", "record", ";", "}", "}", "elseif", "(", "isset", "(", "$", "this", "->", "trace", "[", "$", "record", "->", "id", "]", ")", ")", "{", "$", "entryRecord", "=", "$", "this", "->", "trace", "[", "$", "record", "->", "id", "]", ";", "$", "entryRecord", "->", "exited", "=", "true", ";", "$", "entryRecord", "->", "exitTime", "=", "$", "record", "->", "time", ";", "$", "entryRecord", "->", "deltaTime", "=", "$", "record", "->", "time", "-", "$", "entryRecord", "->", "time", ";", "$", "entryRecord", "->", "exitMemory", "=", "$", "record", "->", "memory", ";", "$", "entryRecord", "->", "deltaMemory", "=", "$", "record", "->", "memory", "-", "$", "entryRecord", "->", "memory", ";", "$", "remove", "=", "false", ";", "foreach", "(", "$", "this", "->", "filterExitCallbacks", "as", "$", "callback", ")", "{", "$", "result", "=", "(", "int", ")", "$", "callback", "(", "$", "entryRecord", ",", "false", ",", "$", "this", ")", ";", "if", "(", "$", "result", "&", "self", "::", "SKIP", ")", "{", "$", "remove", "=", "true", ";", "}", "if", "(", "$", "result", "&", "self", "::", "STOP", ")", "{", "break", ";", "}", "}", "if", "(", "$", "remove", ")", "{", "unset", "(", "$", "this", "->", "trace", "[", "$", "record", "->", "id", "]", ")", ";", "}", "elseif", "(", "$", "this", "->", "performStatistics", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "statistic", "[", "$", "entryRecord", "->", "function", "]", ")", ")", "{", "$", "this", "->", "statistic", "[", "$", "entryRecord", "->", "function", "]", "=", "(", "object", ")", "[", "'count'", "=>", "1", ",", "'deltaTime'", "=>", "$", "entryRecord", "->", "deltaTime", ",", "]", ";", "}", "else", "{", "$", "this", "->", "statistic", "[", "$", "entryRecord", "->", "function", "]", "->", "count", "+=", "1", ";", "$", "this", "->", "statistic", "[", "$", "entryRecord", "->", "function", "]", "->", "deltaTime", "+=", "$", "entryRecord", "->", "deltaTime", ";", "}", "}", "}", "}" ]
Push parsed trace file line into trace stack. @param \stdClass parsed trace file line
[ "Push", "parsed", "trace", "file", "line", "into", "trace", "stack", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L576-L632
35,183
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.defaultFilterCb
protected function defaultFilterCb(\stdClass $record) { if ($this->skipOver['phpInternals'] && $record->isInternal) { return self::SKIP; } if ($this->skipOver['XDebugTrace']) { if ($record->filename === __FILE__) { return self::SKIP; } if (\strpos($record->function, 'XDebug::') === 0) { return self::SKIP; } } if ($this->skipOver['Hail'] && \strpos($record->function, 'Hail\\') === 0) { return self::SKIP; } if ($this->skipOver['Composer'] && \strpos($record->function, 'Composer\\') === 0) { return self::SKIP; } if ($this->skipOver['callbacks'] && ($record->function === 'callback' || $record->function === '{closure}')) { return self::SKIP; } if ($this->skipOver['includes'] && $record->includeFile !== null) { return self::SKIP; } return 0; }
php
protected function defaultFilterCb(\stdClass $record) { if ($this->skipOver['phpInternals'] && $record->isInternal) { return self::SKIP; } if ($this->skipOver['XDebugTrace']) { if ($record->filename === __FILE__) { return self::SKIP; } if (\strpos($record->function, 'XDebug::') === 0) { return self::SKIP; } } if ($this->skipOver['Hail'] && \strpos($record->function, 'Hail\\') === 0) { return self::SKIP; } if ($this->skipOver['Composer'] && \strpos($record->function, 'Composer\\') === 0) { return self::SKIP; } if ($this->skipOver['callbacks'] && ($record->function === 'callback' || $record->function === '{closure}')) { return self::SKIP; } if ($this->skipOver['includes'] && $record->includeFile !== null) { return self::SKIP; } return 0; }
[ "protected", "function", "defaultFilterCb", "(", "\\", "stdClass", "$", "record", ")", "{", "if", "(", "$", "this", "->", "skipOver", "[", "'phpInternals'", "]", "&&", "$", "record", "->", "isInternal", ")", "{", "return", "self", "::", "SKIP", ";", "}", "if", "(", "$", "this", "->", "skipOver", "[", "'XDebugTrace'", "]", ")", "{", "if", "(", "$", "record", "->", "filename", "===", "__FILE__", ")", "{", "return", "self", "::", "SKIP", ";", "}", "if", "(", "\\", "strpos", "(", "$", "record", "->", "function", ",", "'XDebug::'", ")", "===", "0", ")", "{", "return", "self", "::", "SKIP", ";", "}", "}", "if", "(", "$", "this", "->", "skipOver", "[", "'Hail'", "]", "&&", "\\", "strpos", "(", "$", "record", "->", "function", ",", "'Hail\\\\'", ")", "===", "0", ")", "{", "return", "self", "::", "SKIP", ";", "}", "if", "(", "$", "this", "->", "skipOver", "[", "'Composer'", "]", "&&", "\\", "strpos", "(", "$", "record", "->", "function", ",", "'Composer\\\\'", ")", "===", "0", ")", "{", "return", "self", "::", "SKIP", ";", "}", "if", "(", "$", "this", "->", "skipOver", "[", "'callbacks'", "]", "&&", "(", "$", "record", "->", "function", "===", "'callback'", "||", "$", "record", "->", "function", "===", "'{closure}'", ")", ")", "{", "return", "self", "::", "SKIP", ";", "}", "if", "(", "$", "this", "->", "skipOver", "[", "'includes'", "]", "&&", "$", "record", "->", "includeFile", "!==", "null", ")", "{", "return", "self", "::", "SKIP", ";", "}", "return", "0", ";", "}" ]
Default filtering callback. @param \stdClass trace file record @return int bitmask of self::SKIP, self::STOP
[ "Default", "filtering", "callback", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L680-L713
35,184
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.addFilterCallback
public function addFilterCallback($callback, $flags = null) { $flags = (int) $flags; if ($flags & self::FILTER_REPLACE_ENTRY) { $this->filterEntryCallbacks = []; } if ($flags & self::FILTER_REPLACE_EXIT) { $this->filterExitCallbacks = []; } // Called when entry records came if (($flags & self::FILTER_ENTRY) || !($flags & self::FILTER_EXIT)) { if ($flags & self::FILTER_APPEND_ENTRY) { $this->filterEntryCallbacks[] = $callback; } else { \array_unshift($this->filterEntryCallbacks, $callback); } } // Called when exit records came if ($flags & self::FILTER_EXIT) { if ($flags & self::FILTER_APPEND_EXIT) { $this->filterExitCallbacks[] = $callback; } else { \array_unshift($this->filterExitCallbacks, $callback); } } }
php
public function addFilterCallback($callback, $flags = null) { $flags = (int) $flags; if ($flags & self::FILTER_REPLACE_ENTRY) { $this->filterEntryCallbacks = []; } if ($flags & self::FILTER_REPLACE_EXIT) { $this->filterExitCallbacks = []; } // Called when entry records came if (($flags & self::FILTER_ENTRY) || !($flags & self::FILTER_EXIT)) { if ($flags & self::FILTER_APPEND_ENTRY) { $this->filterEntryCallbacks[] = $callback; } else { \array_unshift($this->filterEntryCallbacks, $callback); } } // Called when exit records came if ($flags & self::FILTER_EXIT) { if ($flags & self::FILTER_APPEND_EXIT) { $this->filterExitCallbacks[] = $callback; } else { \array_unshift($this->filterExitCallbacks, $callback); } } }
[ "public", "function", "addFilterCallback", "(", "$", "callback", ",", "$", "flags", "=", "null", ")", "{", "$", "flags", "=", "(", "int", ")", "$", "flags", ";", "if", "(", "$", "flags", "&", "self", "::", "FILTER_REPLACE_ENTRY", ")", "{", "$", "this", "->", "filterEntryCallbacks", "=", "[", "]", ";", "}", "if", "(", "$", "flags", "&", "self", "::", "FILTER_REPLACE_EXIT", ")", "{", "$", "this", "->", "filterExitCallbacks", "=", "[", "]", ";", "}", "// Called when entry records came", "if", "(", "(", "$", "flags", "&", "self", "::", "FILTER_ENTRY", ")", "||", "!", "(", "$", "flags", "&", "self", "::", "FILTER_EXIT", ")", ")", "{", "if", "(", "$", "flags", "&", "self", "::", "FILTER_APPEND_ENTRY", ")", "{", "$", "this", "->", "filterEntryCallbacks", "[", "]", "=", "$", "callback", ";", "}", "else", "{", "\\", "array_unshift", "(", "$", "this", "->", "filterEntryCallbacks", ",", "$", "callback", ")", ";", "}", "}", "// Called when exit records came", "if", "(", "$", "flags", "&", "self", "::", "FILTER_EXIT", ")", "{", "if", "(", "$", "flags", "&", "self", "::", "FILTER_APPEND_EXIT", ")", "{", "$", "this", "->", "filterExitCallbacks", "[", "]", "=", "$", "callback", ";", "}", "else", "{", "\\", "array_unshift", "(", "$", "this", "->", "filterExitCallbacks", ",", "$", "callback", ")", ";", "}", "}", "}" ]
Register own filter callback. @param callback (\stdClass $record, bool $isEntry, XDebugPanel $this) @param int $flags bitmask of self::FILTER_*
[ "Register", "own", "filter", "callback", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L722-L753
35,185
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.setFilterCallback
public function setFilterCallback($callback, $flags = null) { $flags = ((int) $flags) | self::FILTER_REPLACE; $this->addFilterCallback($callback, $flags); }
php
public function setFilterCallback($callback, $flags = null) { $flags = ((int) $flags) | self::FILTER_REPLACE; $this->addFilterCallback($callback, $flags); }
[ "public", "function", "setFilterCallback", "(", "$", "callback", ",", "$", "flags", "=", "null", ")", "{", "$", "flags", "=", "(", "(", "int", ")", "$", "flags", ")", "|", "self", "::", "FILTER_REPLACE", ";", "$", "this", "->", "addFilterCallback", "(", "$", "callback", ",", "$", "flags", ")", ";", "}" ]
Replace all filter callbacks by this one. @param callback (\stdClass $record, bool $isEntry, XDebugPanel $this) @param int $flags bitmask of self::FILTER_*
[ "Replace", "all", "filter", "callbacks", "by", "this", "one", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L762-L766
35,186
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.traceFunction
public function traceFunction($name, $deep = false, $showInternals = false) { if (\is_array($name)) { $name1 = \implode('::', $name); $name2 = \implode('->', $name); } else { $name1 = $name2 = (string) $name; } $cb = function (\stdClass $record, $isEntry) use ($name1, $name2, $deep, $showInternals) { static $cnt = 0; if ($record->function === $name1 || $record->function === $name2) { $cnt += $isEntry ? 1 : -1; return null; } return ($deep && $cnt && ($showInternals || !$record->isInternal)) ? null : self::SKIP; }; $this->setFilterCallback($cb, self::FILTER_BOTH); }
php
public function traceFunction($name, $deep = false, $showInternals = false) { if (\is_array($name)) { $name1 = \implode('::', $name); $name2 = \implode('->', $name); } else { $name1 = $name2 = (string) $name; } $cb = function (\stdClass $record, $isEntry) use ($name1, $name2, $deep, $showInternals) { static $cnt = 0; if ($record->function === $name1 || $record->function === $name2) { $cnt += $isEntry ? 1 : -1; return null; } return ($deep && $cnt && ($showInternals || !$record->isInternal)) ? null : self::SKIP; }; $this->setFilterCallback($cb, self::FILTER_BOTH); }
[ "public", "function", "traceFunction", "(", "$", "name", ",", "$", "deep", "=", "false", ",", "$", "showInternals", "=", "false", ")", "{", "if", "(", "\\", "is_array", "(", "$", "name", ")", ")", "{", "$", "name1", "=", "\\", "implode", "(", "'::'", ",", "$", "name", ")", ";", "$", "name2", "=", "\\", "implode", "(", "'->'", ",", "$", "name", ")", ";", "}", "else", "{", "$", "name1", "=", "$", "name2", "=", "(", "string", ")", "$", "name", ";", "}", "$", "cb", "=", "function", "(", "\\", "stdClass", "$", "record", ",", "$", "isEntry", ")", "use", "(", "$", "name1", ",", "$", "name2", ",", "$", "deep", ",", "$", "showInternals", ")", "{", "static", "$", "cnt", "=", "0", ";", "if", "(", "$", "record", "->", "function", "===", "$", "name1", "||", "$", "record", "->", "function", "===", "$", "name2", ")", "{", "$", "cnt", "+=", "$", "isEntry", "?", "1", ":", "-", "1", ";", "return", "null", ";", "}", "return", "(", "$", "deep", "&&", "$", "cnt", "&&", "(", "$", "showInternals", "||", "!", "$", "record", "->", "isInternal", ")", ")", "?", "null", ":", "self", "::", "SKIP", ";", "}", ";", "$", "this", "->", "setFilterCallback", "(", "$", "cb", ",", "self", "::", "FILTER_BOTH", ")", ";", "}" ]
Trace function by name. @param string|array $name name of function or pair [class, method] @param bool $deep show inside function trace too @param bool $showInternals show internals in inside function trace
[ "Trace", "function", "by", "name", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L788-L810
35,187
hail-framework/framework
src/Debugger/Bar/TracePanel.php
TracePanel.traceFunctionRe
public function traceFunctionRe($re, $deep = false, $showInternals = false) { $cb = function (\stdClass $record, $isEntry) use ($re, $deep, $showInternals) { static $cnt = 0; if (\preg_match($re, $record->function)) { $cnt += $isEntry ? 1 : -1; return null; } return ($deep && $cnt && ($showInternals || !$record->isInternal)) ? null : self::SKIP; }; $this->setFilterCallback($cb, self::FILTER_BOTH); }
php
public function traceFunctionRe($re, $deep = false, $showInternals = false) { $cb = function (\stdClass $record, $isEntry) use ($re, $deep, $showInternals) { static $cnt = 0; if (\preg_match($re, $record->function)) { $cnt += $isEntry ? 1 : -1; return null; } return ($deep && $cnt && ($showInternals || !$record->isInternal)) ? null : self::SKIP; }; $this->setFilterCallback($cb, self::FILTER_BOTH); }
[ "public", "function", "traceFunctionRe", "(", "$", "re", ",", "$", "deep", "=", "false", ",", "$", "showInternals", "=", "false", ")", "{", "$", "cb", "=", "function", "(", "\\", "stdClass", "$", "record", ",", "$", "isEntry", ")", "use", "(", "$", "re", ",", "$", "deep", ",", "$", "showInternals", ")", "{", "static", "$", "cnt", "=", "0", ";", "if", "(", "\\", "preg_match", "(", "$", "re", ",", "$", "record", "->", "function", ")", ")", "{", "$", "cnt", "+=", "$", "isEntry", "?", "1", ":", "-", "1", ";", "return", "null", ";", "}", "return", "(", "$", "deep", "&&", "$", "cnt", "&&", "(", "$", "showInternals", "||", "!", "$", "record", "->", "isInternal", ")", ")", "?", "null", ":", "self", "::", "SKIP", ";", "}", ";", "$", "this", "->", "setFilterCallback", "(", "$", "cb", ",", "self", "::", "FILTER_BOTH", ")", ";", "}" ]
Trace function which name is expressed by PCRE reqular expression. @param string $re regular expression @param bool $deep show inside function trace too @param bool $showInternals show internals in inside function trace
[ "Trace", "function", "which", "name", "is", "expressed", "by", "PCRE", "reqular", "expression", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L820-L835
35,188
hail-framework/framework
src/Console/Formatter.php
Formatter.format
public function format($text = '', string $style = 'none') { return $this->getStartMark($style) . $text . $this->getClearMark(); }
php
public function format($text = '', string $style = 'none') { return $this->getStartMark($style) . $text . $this->getClearMark(); }
[ "public", "function", "format", "(", "$", "text", "=", "''", ",", "string", "$", "style", "=", "'none'", ")", "{", "return", "$", "this", "->", "getStartMark", "(", "$", "style", ")", ".", "$", "text", ".", "$", "this", "->", "getClearMark", "(", ")", ";", "}" ]
Formats a text according to the given style or parameters. @param string $text The text to style @param string $style A style name @return string The styled text
[ "Formats", "a", "text", "according", "to", "the", "given", "style", "or", "parameters", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Formatter.php#L171-L174
35,189
hiqdev/hipanel-module-dns
src/widgets/DnsZoneEditWidget.php
DnsZoneEditWidget.registerClientScript
public function registerClientScript() { $id = $this->pjaxOptions['id']; $url = Json::encode($this->buildUrl()); $js = " $.pjax({ url: $url, push: false, replace: false, container: '#$id', }); $('#$id').on('pjax:error', function (event, xhr, textStatus, error, options) { $(this).text(xhr.responseText); }); "; if ($this->clientScriptWrap instanceof Closure) { $js = call_user_func($this->clientScriptWrap, $js); } Yii::$app->view->registerJs($js); }
php
public function registerClientScript() { $id = $this->pjaxOptions['id']; $url = Json::encode($this->buildUrl()); $js = " $.pjax({ url: $url, push: false, replace: false, container: '#$id', }); $('#$id').on('pjax:error', function (event, xhr, textStatus, error, options) { $(this).text(xhr.responseText); }); "; if ($this->clientScriptWrap instanceof Closure) { $js = call_user_func($this->clientScriptWrap, $js); } Yii::$app->view->registerJs($js); }
[ "public", "function", "registerClientScript", "(", ")", "{", "$", "id", "=", "$", "this", "->", "pjaxOptions", "[", "'id'", "]", ";", "$", "url", "=", "Json", "::", "encode", "(", "$", "this", "->", "buildUrl", "(", ")", ")", ";", "$", "js", "=", "\"\n $.pjax({\n url: $url,\n push: false,\n replace: false,\n container: '#$id',\n });\n $('#$id').on('pjax:error', function (event, xhr, textStatus, error, options) {\n $(this).text(xhr.responseText);\n });\n \"", ";", "if", "(", "$", "this", "->", "clientScriptWrap", "instanceof", "Closure", ")", "{", "$", "js", "=", "call_user_func", "(", "$", "this", "->", "clientScriptWrap", ",", "$", "js", ")", ";", "}", "Yii", "::", "$", "app", "->", "view", "->", "registerJs", "(", "$", "js", ")", ";", "}" ]
Registers JS.
[ "Registers", "JS", "." ]
7e9199c95d91a979b7bd4fd07fe801dbe9e69183
https://github.com/hiqdev/hipanel-module-dns/blob/7e9199c95d91a979b7bd4fd07fe801dbe9e69183/src/widgets/DnsZoneEditWidget.php#L76-L96
35,190
hail-framework/framework
src/Util/Arrays.php
Arrays.searchKey
public static function searchKey(array $arr, $key) { $foo = [$key => null]; return ($tmp = \array_search(\key($foo), \array_keys($arr), true)) === false ? null : $tmp; }
php
public static function searchKey(array $arr, $key) { $foo = [$key => null]; return ($tmp = \array_search(\key($foo), \array_keys($arr), true)) === false ? null : $tmp; }
[ "public", "static", "function", "searchKey", "(", "array", "$", "arr", ",", "$", "key", ")", "{", "$", "foo", "=", "[", "$", "key", "=>", "null", "]", ";", "return", "(", "$", "tmp", "=", "\\", "array_search", "(", "\\", "key", "(", "$", "foo", ")", ",", "\\", "array_keys", "(", "$", "arr", ")", ",", "true", ")", ")", "===", "false", "?", "null", ":", "$", "tmp", ";", "}" ]
Searches the array for a given key and returns the offset if successful. @param array $arr @param int|string $key @return int|null|string offset if it is found, null otherwise
[ "Searches", "the", "array", "for", "a", "given", "key", "and", "returns", "the", "offset", "if", "successful", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L208-L213
35,191
hail-framework/framework
src/Util/Arrays.php
Arrays.insertBefore
public static function insertBefore(array &$arr, $key, array $inserted): void { $offset = (int) self::searchKey($arr, $key); $arr = \array_slice($arr, 0, $offset, true) + $inserted + \array_slice($arr, $offset, null, true); }
php
public static function insertBefore(array &$arr, $key, array $inserted): void { $offset = (int) self::searchKey($arr, $key); $arr = \array_slice($arr, 0, $offset, true) + $inserted + \array_slice($arr, $offset, null, true); }
[ "public", "static", "function", "insertBefore", "(", "array", "&", "$", "arr", ",", "$", "key", ",", "array", "$", "inserted", ")", ":", "void", "{", "$", "offset", "=", "(", "int", ")", "self", "::", "searchKey", "(", "$", "arr", ",", "$", "key", ")", ";", "$", "arr", "=", "\\", "array_slice", "(", "$", "arr", ",", "0", ",", "$", "offset", ",", "true", ")", "+", "$", "inserted", "+", "\\", "array_slice", "(", "$", "arr", ",", "$", "offset", ",", "null", ",", "true", ")", ";", "}" ]
Inserts new array before item specified by key. @param array $arr @param int|string $key @param array $inserted
[ "Inserts", "new", "array", "before", "item", "specified", "by", "key", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L222-L226
35,192
hail-framework/framework
src/Util/Arrays.php
Arrays.insertAfter
public static function insertAfter(array &$arr, $key, array $inserted): void { $offset = self::searchKey($arr, $key); if ($offset === null) { $arr += $inserted; } else { ++$offset; $arr = \array_slice($arr, 0, $offset, true) + $inserted + \array_slice($arr, $offset, null, true); } }
php
public static function insertAfter(array &$arr, $key, array $inserted): void { $offset = self::searchKey($arr, $key); if ($offset === null) { $arr += $inserted; } else { ++$offset; $arr = \array_slice($arr, 0, $offset, true) + $inserted + \array_slice($arr, $offset, null, true); } }
[ "public", "static", "function", "insertAfter", "(", "array", "&", "$", "arr", ",", "$", "key", ",", "array", "$", "inserted", ")", ":", "void", "{", "$", "offset", "=", "self", "::", "searchKey", "(", "$", "arr", ",", "$", "key", ")", ";", "if", "(", "$", "offset", "===", "null", ")", "{", "$", "arr", "+=", "$", "inserted", ";", "}", "else", "{", "++", "$", "offset", ";", "$", "arr", "=", "\\", "array_slice", "(", "$", "arr", ",", "0", ",", "$", "offset", ",", "true", ")", "+", "$", "inserted", "+", "\\", "array_slice", "(", "$", "arr", ",", "$", "offset", ",", "null", ",", "true", ")", ";", "}", "}" ]
Inserts new array after item specified by key. @param array $arr @param int|string $key @param array $inserted
[ "Inserts", "new", "array", "after", "item", "specified", "by", "key", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L236-L245
35,193
hail-framework/framework
src/Util/Arrays.php
Arrays.renameKey
public static function renameKey(array &$arr, $oldKey, $newKey): void { $offset = self::searchKey($arr, $oldKey); if ($offset !== null) { $keys = \array_keys($arr); $keys[$offset] = $newKey; $arr = \array_combine($keys, $arr); } }
php
public static function renameKey(array &$arr, $oldKey, $newKey): void { $offset = self::searchKey($arr, $oldKey); if ($offset !== null) { $keys = \array_keys($arr); $keys[$offset] = $newKey; $arr = \array_combine($keys, $arr); } }
[ "public", "static", "function", "renameKey", "(", "array", "&", "$", "arr", ",", "$", "oldKey", ",", "$", "newKey", ")", ":", "void", "{", "$", "offset", "=", "self", "::", "searchKey", "(", "$", "arr", ",", "$", "oldKey", ")", ";", "if", "(", "$", "offset", "!==", "null", ")", "{", "$", "keys", "=", "\\", "array_keys", "(", "$", "arr", ")", ";", "$", "keys", "[", "$", "offset", "]", "=", "$", "newKey", ";", "$", "arr", "=", "\\", "array_combine", "(", "$", "keys", ",", "$", "arr", ")", ";", "}", "}" ]
Renames key in array. @param array $arr @param int|string $oldKey @param int|string $newKey
[ "Renames", "key", "in", "array", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L254-L262
35,194
hail-framework/framework
src/Util/Arrays.php
Arrays.grep
public static function grep(array $arr, string $pattern, int $flags = 0): array { return Strings::pcre('\preg_grep', [$pattern, $arr, $flags]); }
php
public static function grep(array $arr, string $pattern, int $flags = 0): array { return Strings::pcre('\preg_grep', [$pattern, $arr, $flags]); }
[ "public", "static", "function", "grep", "(", "array", "$", "arr", ",", "string", "$", "pattern", ",", "int", "$", "flags", "=", "0", ")", ":", "array", "{", "return", "Strings", "::", "pcre", "(", "'\\preg_grep'", ",", "[", "$", "pattern", ",", "$", "arr", ",", "$", "flags", "]", ")", ";", "}" ]
Returns array entries that match the pattern. @param array $arr @param string $pattern @param int $flags @return array
[ "Returns", "array", "entries", "that", "match", "the", "pattern", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L273-L276
35,195
hail-framework/framework
src/Util/Arrays.php
Arrays.pick
public static function pick(array &$arr, $key) { if (\array_key_exists($key, $arr)) { $value = $arr[$key]; unset($arr[$key]); return $value; } return null; }
php
public static function pick(array &$arr, $key) { if (\array_key_exists($key, $arr)) { $value = $arr[$key]; unset($arr[$key]); return $value; } return null; }
[ "public", "static", "function", "pick", "(", "array", "&", "$", "arr", ",", "$", "key", ")", "{", "if", "(", "\\", "array_key_exists", "(", "$", "key", ",", "$", "arr", ")", ")", "{", "$", "value", "=", "$", "arr", "[", "$", "key", "]", ";", "unset", "(", "$", "arr", "[", "$", "key", "]", ")", ";", "return", "$", "value", ";", "}", "return", "null", ";", "}" ]
Picks element from the array by key and return its value. @param array $arr @param string|int $key array key @return mixed
[ "Picks", "element", "from", "the", "array", "by", "key", "and", "return", "its", "value", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L286-L296
35,196
systemson/collection
src/MultilevelCollection.php
MultilevelCollection.has
public function has(string $key): bool { $slug = $this->splitKey($key); if (is_string($slug)) { return isset($this[$slug]); } $collection = $this->all(); foreach ($this->splitKey($key) as $search) { if (!isset($collection[$search])) { return false; } $collection = $collection[$search]; } return true; }
php
public function has(string $key): bool { $slug = $this->splitKey($key); if (is_string($slug)) { return isset($this[$slug]); } $collection = $this->all(); foreach ($this->splitKey($key) as $search) { if (!isset($collection[$search])) { return false; } $collection = $collection[$search]; } return true; }
[ "public", "function", "has", "(", "string", "$", "key", ")", ":", "bool", "{", "$", "slug", "=", "$", "this", "->", "splitKey", "(", "$", "key", ")", ";", "if", "(", "is_string", "(", "$", "slug", ")", ")", "{", "return", "isset", "(", "$", "this", "[", "$", "slug", "]", ")", ";", "}", "$", "collection", "=", "$", "this", "->", "all", "(", ")", ";", "foreach", "(", "$", "this", "->", "splitKey", "(", "$", "key", ")", "as", "$", "search", ")", "{", "if", "(", "!", "isset", "(", "$", "collection", "[", "$", "search", "]", ")", ")", "{", "return", "false", ";", "}", "$", "collection", "=", "$", "collection", "[", "$", "search", "]", ";", "}", "return", "true", ";", "}" ]
Whether an item is present it the collection @param string $key The item's key @return bool
[ "Whether", "an", "item", "is", "present", "it", "the", "collection" ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/MultilevelCollection.php#L106-L125
35,197
systemson/collection
src/MultilevelCollection.php
MultilevelCollection.get
public function get(string $key) { $slug = $this->splitKey($key); if (is_string($slug)) { if (isset($this[$slug])) { return $this[$slug]; } return null; } $array = $this->toArray(); foreach ($slug as $search) { if (isset($array[$search])) { $array = $array[$search]; } else { return; } } return $array; }
php
public function get(string $key) { $slug = $this->splitKey($key); if (is_string($slug)) { if (isset($this[$slug])) { return $this[$slug]; } return null; } $array = $this->toArray(); foreach ($slug as $search) { if (isset($array[$search])) { $array = $array[$search]; } else { return; } } return $array; }
[ "public", "function", "get", "(", "string", "$", "key", ")", "{", "$", "slug", "=", "$", "this", "->", "splitKey", "(", "$", "key", ")", ";", "if", "(", "is_string", "(", "$", "slug", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "[", "$", "slug", "]", ")", ")", "{", "return", "$", "this", "[", "$", "slug", "]", ";", "}", "return", "null", ";", "}", "$", "array", "=", "$", "this", "->", "toArray", "(", ")", ";", "foreach", "(", "$", "slug", "as", "$", "search", ")", "{", "if", "(", "isset", "(", "$", "array", "[", "$", "search", "]", ")", ")", "{", "$", "array", "=", "$", "array", "[", "$", "search", "]", ";", "}", "else", "{", "return", ";", "}", "}", "return", "$", "array", ";", "}" ]
Gets an item from collection. @param string $key The item's key @return mixed|void The item's value or void if the key doesn't exists.
[ "Gets", "an", "item", "from", "collection", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/MultilevelCollection.php#L134-L156
35,198
systemson/collection
src/MultilevelCollection.php
MultilevelCollection.unset
public function unset(string $key): void { $slug = $this->splitKey($key); if (is_string($slug)) { if (isset($this[$slug])) { unset($this[$slug]); } } else { if ($this->has($key)) { $this->set($key, null); } } }
php
public function unset(string $key): void { $slug = $this->splitKey($key); if (is_string($slug)) { if (isset($this[$slug])) { unset($this[$slug]); } } else { if ($this->has($key)) { $this->set($key, null); } } }
[ "public", "function", "unset", "(", "string", "$", "key", ")", ":", "void", "{", "$", "slug", "=", "$", "this", "->", "splitKey", "(", "$", "key", ")", ";", "if", "(", "is_string", "(", "$", "slug", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "[", "$", "slug", "]", ")", ")", "{", "unset", "(", "$", "this", "[", "$", "slug", "]", ")", ";", "}", "}", "else", "{", "if", "(", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "$", "this", "->", "set", "(", "$", "key", ",", "null", ")", ";", "}", "}", "}" ]
Unsets an item from collection. @param string $key The item's key @return void
[ "Unsets", "an", "item", "from", "collection", "." ]
fb3ae1a78806aafabc0562db96822e8b99dc2a64
https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/MultilevelCollection.php#L165-L178
35,199
hail-framework/framework
src/Database/Migration/Table.php
Table.insert
public function insert($data) { // handle array of array situations if (isset($data[0]) && is_array($data[0])) { foreach ($data as $row) { $this->data[] = $row; } return $this; } $this->data[] = $data; return $this; }
php
public function insert($data) { // handle array of array situations if (isset($data[0]) && is_array($data[0])) { foreach ($data as $row) { $this->data[] = $row; } return $this; } $this->data[] = $data; return $this; }
[ "public", "function", "insert", "(", "$", "data", ")", "{", "// handle array of array situations", "if", "(", "isset", "(", "$", "data", "[", "0", "]", ")", "&&", "is_array", "(", "$", "data", "[", "0", "]", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "row", ")", "{", "$", "this", "->", "data", "[", "]", "=", "$", "row", ";", "}", "return", "$", "this", ";", "}", "$", "this", "->", "data", "[", "]", "=", "$", "data", ";", "return", "$", "this", ";", "}" ]
Insert data into the table. @param array $data array of data in the form: array( array("col1" => "value1", "col2" => "anotherValue1"), array("col2" => "value2", "col2" => "anotherValue2"), ) or array("col1" => "value1", "col2" => "anotherValue1") @return Table
[ "Insert", "data", "into", "the", "table", "." ]
d419e6c098d29ef9b62192b74050e51985b94f90
https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Table.php#L629-L642