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
33,000
orchestral/support
src/Support/Concerns/DataContainer.php
DataContainer.allWithRemoved
public function allWithRemoved(): array { $items = $this->all(); foreach ($this->removedItems as $deleted) { Arr::set($items, $deleted, null); } return $items; }
php
public function allWithRemoved(): array { $items = $this->all(); foreach ($this->removedItems as $deleted) { Arr::set($items, $deleted, null); } return $items; }
[ "public", "function", "allWithRemoved", "(", ")", ":", "array", "{", "$", "items", "=", "$", "this", "->", "all", "(", ")", ";", "foreach", "(", "$", "this", "->", "removedItems", "as", "$", "deleted", ")", "{", "Arr", "::", "set", "(", "$", "items", ",", "$", "deleted", ",", "null", ")", ";", "}", "return", "$", "items", ";", "}" ]
Get all available items including deleted. @return array
[ "Get", "all", "available", "items", "including", "deleted", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Concerns/DataContainer.php#L155-L164
33,001
nails/module-invoice
invoice/controllers/Payment.php
Payment.complete
protected function complete($oPayment) { $oPaymentModel = Factory::model('Payment', 'nails/module-invoice'); $this->data['oPayment'] = $oPayment; $this->data['oInvoice'] = $oPayment->invoice; if ($oPayment->status->id === $oPaymentModel::STATUS_FAILED) { // Payments which FAILED should be ignored show404(); } elseif ($oPayment->status->id === $oPaymentModel::STATUS_COMPLETE) { // Payment is already complete redirect($oPayment->urls->thanks); } elseif ($oPayment->status->id === $oPaymentModel::STATUS_PROCESSING) { // Payment is already complete and is being processed redirect($oPayment->urls->processing); } else { try { // Set up CompleteRequest object $oCompleteRequest = Factory::factory('CompleteRequest', 'nails/module-invoice'); // Set the driver to use for the request $oCompleteRequest->setDriver($oPayment->driver->slug); // Set the payment we're completing $oCompleteRequest->setPayment($oPayment->id); // Set the invoice we're completing $oCompleteRequest->setInvoice($oPayment->invoice->id); // Set the complete URL, if there is one $oCompleteRequest->setContinueUrl($oPayment->urls->continue); // Attempt completion $oInput = Factory::service('Input'); $oCompleteResponse = $oCompleteRequest->execute( $oInput->get(), $oInput->post() ); if ($oCompleteResponse->isProcessing()) { // Payment was successful but has not been confirmed if ($oCompleteRequest->getContinueUrl()) { redirect($oCompleteRequest->getContinueUrl()); } else { redirect($oPayment->urls->processing); } } elseif ($oCompleteResponse->isComplete()) { // Payment has completed fully if ($oCompleteRequest->getContinueUrl()) { redirect($oCompleteRequest->getContinueUrl()); } else { redirect($oPayment->urls->thanks); } } elseif ($oCompleteResponse->isFailed()) { throw new NailsException('Payment failed: ' . $oCompleteResponse->getError()->user, 1); } else { throw new NailsException('Payment failed.', 1); } } catch (\Exception $e) { $oSession = Factory::service('Session', 'nails/module-auth'); $oSession->setFlashData('error', $e->getMessage()); redirect($oPayment->invoice->urls->payment); } } }
php
protected function complete($oPayment) { $oPaymentModel = Factory::model('Payment', 'nails/module-invoice'); $this->data['oPayment'] = $oPayment; $this->data['oInvoice'] = $oPayment->invoice; if ($oPayment->status->id === $oPaymentModel::STATUS_FAILED) { // Payments which FAILED should be ignored show404(); } elseif ($oPayment->status->id === $oPaymentModel::STATUS_COMPLETE) { // Payment is already complete redirect($oPayment->urls->thanks); } elseif ($oPayment->status->id === $oPaymentModel::STATUS_PROCESSING) { // Payment is already complete and is being processed redirect($oPayment->urls->processing); } else { try { // Set up CompleteRequest object $oCompleteRequest = Factory::factory('CompleteRequest', 'nails/module-invoice'); // Set the driver to use for the request $oCompleteRequest->setDriver($oPayment->driver->slug); // Set the payment we're completing $oCompleteRequest->setPayment($oPayment->id); // Set the invoice we're completing $oCompleteRequest->setInvoice($oPayment->invoice->id); // Set the complete URL, if there is one $oCompleteRequest->setContinueUrl($oPayment->urls->continue); // Attempt completion $oInput = Factory::service('Input'); $oCompleteResponse = $oCompleteRequest->execute( $oInput->get(), $oInput->post() ); if ($oCompleteResponse->isProcessing()) { // Payment was successful but has not been confirmed if ($oCompleteRequest->getContinueUrl()) { redirect($oCompleteRequest->getContinueUrl()); } else { redirect($oPayment->urls->processing); } } elseif ($oCompleteResponse->isComplete()) { // Payment has completed fully if ($oCompleteRequest->getContinueUrl()) { redirect($oCompleteRequest->getContinueUrl()); } else { redirect($oPayment->urls->thanks); } } elseif ($oCompleteResponse->isFailed()) { throw new NailsException('Payment failed: ' . $oCompleteResponse->getError()->user, 1); } else { throw new NailsException('Payment failed.', 1); } } catch (\Exception $e) { $oSession = Factory::service('Session', 'nails/module-auth'); $oSession->setFlashData('error', $e->getMessage()); redirect($oPayment->invoice->urls->payment); } } }
[ "protected", "function", "complete", "(", "$", "oPayment", ")", "{", "$", "oPaymentModel", "=", "Factory", "::", "model", "(", "'Payment'", ",", "'nails/module-invoice'", ")", ";", "$", "this", "->", "data", "[", "'oPayment'", "]", "=", "$", "oPayment", ";", "$", "this", "->", "data", "[", "'oInvoice'", "]", "=", "$", "oPayment", "->", "invoice", ";", "if", "(", "$", "oPayment", "->", "status", "->", "id", "===", "$", "oPaymentModel", "::", "STATUS_FAILED", ")", "{", "// Payments which FAILED should be ignored", "show404", "(", ")", ";", "}", "elseif", "(", "$", "oPayment", "->", "status", "->", "id", "===", "$", "oPaymentModel", "::", "STATUS_COMPLETE", ")", "{", "// Payment is already complete", "redirect", "(", "$", "oPayment", "->", "urls", "->", "thanks", ")", ";", "}", "elseif", "(", "$", "oPayment", "->", "status", "->", "id", "===", "$", "oPaymentModel", "::", "STATUS_PROCESSING", ")", "{", "// Payment is already complete and is being processed", "redirect", "(", "$", "oPayment", "->", "urls", "->", "processing", ")", ";", "}", "else", "{", "try", "{", "// Set up CompleteRequest object", "$", "oCompleteRequest", "=", "Factory", "::", "factory", "(", "'CompleteRequest'", ",", "'nails/module-invoice'", ")", ";", "// Set the driver to use for the request", "$", "oCompleteRequest", "->", "setDriver", "(", "$", "oPayment", "->", "driver", "->", "slug", ")", ";", "// Set the payment we're completing", "$", "oCompleteRequest", "->", "setPayment", "(", "$", "oPayment", "->", "id", ")", ";", "// Set the invoice we're completing", "$", "oCompleteRequest", "->", "setInvoice", "(", "$", "oPayment", "->", "invoice", "->", "id", ")", ";", "// Set the complete URL, if there is one", "$", "oCompleteRequest", "->", "setContinueUrl", "(", "$", "oPayment", "->", "urls", "->", "continue", ")", ";", "// Attempt completion", "$", "oInput", "=", "Factory", "::", "service", "(", "'Input'", ")", ";", "$", "oCompleteResponse", "=", "$", "oCompleteRequest", "->", "execute", "(", "$", "oInput", "->", "get", "(", ")", ",", "$", "oInput", "->", "post", "(", ")", ")", ";", "if", "(", "$", "oCompleteResponse", "->", "isProcessing", "(", ")", ")", "{", "// Payment was successful but has not been confirmed", "if", "(", "$", "oCompleteRequest", "->", "getContinueUrl", "(", ")", ")", "{", "redirect", "(", "$", "oCompleteRequest", "->", "getContinueUrl", "(", ")", ")", ";", "}", "else", "{", "redirect", "(", "$", "oPayment", "->", "urls", "->", "processing", ")", ";", "}", "}", "elseif", "(", "$", "oCompleteResponse", "->", "isComplete", "(", ")", ")", "{", "// Payment has completed fully", "if", "(", "$", "oCompleteRequest", "->", "getContinueUrl", "(", ")", ")", "{", "redirect", "(", "$", "oCompleteRequest", "->", "getContinueUrl", "(", ")", ")", ";", "}", "else", "{", "redirect", "(", "$", "oPayment", "->", "urls", "->", "thanks", ")", ";", "}", "}", "elseif", "(", "$", "oCompleteResponse", "->", "isFailed", "(", ")", ")", "{", "throw", "new", "NailsException", "(", "'Payment failed: '", ".", "$", "oCompleteResponse", "->", "getError", "(", ")", "->", "user", ",", "1", ")", ";", "}", "else", "{", "throw", "new", "NailsException", "(", "'Payment failed.'", ",", "1", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "oSession", "=", "Factory", "::", "service", "(", "'Session'", ",", "'nails/module-auth'", ")", ";", "$", "oSession", "->", "setFlashData", "(", "'error'", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "redirect", "(", "$", "oPayment", "->", "invoice", "->", "urls", "->", "payment", ")", ";", "}", "}", "}" ]
Completes a payment @param \stdClass $oPayment The invoice object @return void
[ "Completes", "a", "payment" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/invoice/controllers/Payment.php#L26-L103
33,002
nails/module-invoice
invoice/controllers/Payment.php
Payment.thanks
protected function thanks($oPayment) { if ($oPayment->status->id === 'PROCESSING') { redirect($oPayment->urls->processing); } elseif ($oPayment->status->id !== 'COMPLETE') { show404(); } $this->data['oPayment'] = $oPayment; $this->data['headerOverride'] = 'structure/header/blank'; $this->data['footerOverride'] = 'structure/footer/blank'; // -------------------------------------------------------------------------- $oView = Factory::service('View'); $this->loadStyles(NAILS_APP_PATH . 'application/modules/invoice/views/thanks/index.php'); $oView->load('structure/header', $this->data); $oView->load('invoice/thanks/index', $this->data); $oView->load('structure/footer', $this->data); }
php
protected function thanks($oPayment) { if ($oPayment->status->id === 'PROCESSING') { redirect($oPayment->urls->processing); } elseif ($oPayment->status->id !== 'COMPLETE') { show404(); } $this->data['oPayment'] = $oPayment; $this->data['headerOverride'] = 'structure/header/blank'; $this->data['footerOverride'] = 'structure/footer/blank'; // -------------------------------------------------------------------------- $oView = Factory::service('View'); $this->loadStyles(NAILS_APP_PATH . 'application/modules/invoice/views/thanks/index.php'); $oView->load('structure/header', $this->data); $oView->load('invoice/thanks/index', $this->data); $oView->load('structure/footer', $this->data); }
[ "protected", "function", "thanks", "(", "$", "oPayment", ")", "{", "if", "(", "$", "oPayment", "->", "status", "->", "id", "===", "'PROCESSING'", ")", "{", "redirect", "(", "$", "oPayment", "->", "urls", "->", "processing", ")", ";", "}", "elseif", "(", "$", "oPayment", "->", "status", "->", "id", "!==", "'COMPLETE'", ")", "{", "show404", "(", ")", ";", "}", "$", "this", "->", "data", "[", "'oPayment'", "]", "=", "$", "oPayment", ";", "$", "this", "->", "data", "[", "'headerOverride'", "]", "=", "'structure/header/blank'", ";", "$", "this", "->", "data", "[", "'footerOverride'", "]", "=", "'structure/footer/blank'", ";", "// --------------------------------------------------------------------------", "$", "oView", "=", "Factory", "::", "service", "(", "'View'", ")", ";", "$", "this", "->", "loadStyles", "(", "NAILS_APP_PATH", ".", "'application/modules/invoice/views/thanks/index.php'", ")", ";", "$", "oView", "->", "load", "(", "'structure/header'", ",", "$", "this", "->", "data", ")", ";", "$", "oView", "->", "load", "(", "'invoice/thanks/index'", ",", "$", "this", "->", "data", ")", ";", "$", "oView", "->", "load", "(", "'structure/footer'", ",", "$", "this", "->", "data", ")", ";", "}" ]
Shows a thank you page @param \stdClass $oPayment The invoice object @return void
[ "Shows", "a", "thank", "you", "page" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/invoice/controllers/Payment.php#L114-L133
33,003
canihavesomecoffee/theTVDbAPI
src/Exception/ResourceNotFoundException.php
ResourceNotFoundException.createErrorMessage
public static function createErrorMessage(string $baseMessage, string $path = null, array $parameters = []): string { $errorMessage = $baseMessage; if ($path !== null) { $errorMessage .= sprintf( static::PATH_MESSAGE, $path, \GuzzleHttp\Psr7\build_query($parameters) ); } return $errorMessage; }
php
public static function createErrorMessage(string $baseMessage, string $path = null, array $parameters = []): string { $errorMessage = $baseMessage; if ($path !== null) { $errorMessage .= sprintf( static::PATH_MESSAGE, $path, \GuzzleHttp\Psr7\build_query($parameters) ); } return $errorMessage; }
[ "public", "static", "function", "createErrorMessage", "(", "string", "$", "baseMessage", ",", "string", "$", "path", "=", "null", ",", "array", "$", "parameters", "=", "[", "]", ")", ":", "string", "{", "$", "errorMessage", "=", "$", "baseMessage", ";", "if", "(", "$", "path", "!==", "null", ")", "{", "$", "errorMessage", ".=", "sprintf", "(", "static", "::", "PATH_MESSAGE", ",", "$", "path", ",", "\\", "GuzzleHttp", "\\", "Psr7", "\\", "build_query", "(", "$", "parameters", ")", ")", ";", "}", "return", "$", "errorMessage", ";", "}" ]
Creates an error message for a not found exception. @param string $baseMessage The base error message @param string $path The requested path @param array $parameters The query parameters (if defined) @return string
[ "Creates", "an", "error", "message", "for", "a", "not", "found", "exception", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/Exception/ResourceNotFoundException.php#L64-L75
33,004
canihavesomecoffee/theTVDbAPI
src/Exception/ResourceNotFoundException.php
ResourceNotFoundException.notFound
public static function notFound(string $path = null, array $options = []): ResourceNotFoundException { $query = []; if (array_key_exists('query', $options)) { $query = $options['query']; } return new static(static::createErrorMessage(static::NOT_FOUND_MESSAGE, $path, $query)); }
php
public static function notFound(string $path = null, array $options = []): ResourceNotFoundException { $query = []; if (array_key_exists('query', $options)) { $query = $options['query']; } return new static(static::createErrorMessage(static::NOT_FOUND_MESSAGE, $path, $query)); }
[ "public", "static", "function", "notFound", "(", "string", "$", "path", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", ":", "ResourceNotFoundException", "{", "$", "query", "=", "[", "]", ";", "if", "(", "array_key_exists", "(", "'query'", ",", "$", "options", ")", ")", "{", "$", "query", "=", "$", "options", "[", "'query'", "]", ";", "}", "return", "new", "static", "(", "static", "::", "createErrorMessage", "(", "static", "::", "NOT_FOUND_MESSAGE", ",", "$", "path", ",", "$", "query", ")", ")", ";", "}" ]
Returns a new instance for the resource not found exception. @param string $path The requested path @param array $options The options passed to the request @return ResourceNotFoundException
[ "Returns", "a", "new", "instance", "for", "the", "resource", "not", "found", "exception", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/Exception/ResourceNotFoundException.php#L85-L92
33,005
canihavesomecoffee/theTVDbAPI
src/Exception/ResourceNotFoundException.php
ResourceNotFoundException.noTranslationAvailable
public static function noTranslationAvailable(string $path = null, array $options = []): ResourceNotFoundException { $query = []; if (array_key_exists('query', $options)) { $query = $options['query']; } return new static(static::createErrorMessage(static::NO_TRANSLATION_MESSAGE, $path, $query)); }
php
public static function noTranslationAvailable(string $path = null, array $options = []): ResourceNotFoundException { $query = []; if (array_key_exists('query', $options)) { $query = $options['query']; } return new static(static::createErrorMessage(static::NO_TRANSLATION_MESSAGE, $path, $query)); }
[ "public", "static", "function", "noTranslationAvailable", "(", "string", "$", "path", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", ":", "ResourceNotFoundException", "{", "$", "query", "=", "[", "]", ";", "if", "(", "array_key_exists", "(", "'query'", ",", "$", "options", ")", ")", "{", "$", "query", "=", "$", "options", "[", "'query'", "]", ";", "}", "return", "new", "static", "(", "static", "::", "createErrorMessage", "(", "static", "::", "NO_TRANSLATION_MESSAGE", ",", "$", "path", ",", "$", "query", ")", ")", ";", "}" ]
Returns a new instance for the resource not found exception for missing translations @param string $path The requested path @param array $options The options passed to the request @return ResourceNotFoundException
[ "Returns", "a", "new", "instance", "for", "the", "resource", "not", "found", "exception", "for", "missing", "translations" ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/Exception/ResourceNotFoundException.php#L102-L109
33,006
orchestral/support
src/Support/Concerns/Descendible.php
Descendible.descendants
protected function descendants(array $array, ?string $key = null) { if (\is_null($key)) { return $array; } $keys = \explode('.', $key); $first = \array_shift($keys); if (! isset($array[$first])) { return null; } return $this->resolveLastDecendant($array[$first], $keys); }
php
protected function descendants(array $array, ?string $key = null) { if (\is_null($key)) { return $array; } $keys = \explode('.', $key); $first = \array_shift($keys); if (! isset($array[$first])) { return null; } return $this->resolveLastDecendant($array[$first], $keys); }
[ "protected", "function", "descendants", "(", "array", "$", "array", ",", "?", "string", "$", "key", "=", "null", ")", "{", "if", "(", "\\", "is_null", "(", "$", "key", ")", ")", "{", "return", "$", "array", ";", "}", "$", "keys", "=", "\\", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "first", "=", "\\", "array_shift", "(", "$", "keys", ")", ";", "if", "(", "!", "isset", "(", "$", "array", "[", "$", "first", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "resolveLastDecendant", "(", "$", "array", "[", "$", "first", "]", ",", "$", "keys", ")", ";", "}" ]
Get last descendant node from items recursively. @param array $array @param string|null $key @return \Illuminate\Support\Fluent|array|null
[ "Get", "last", "descendant", "node", "from", "items", "recursively", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Concerns/Descendible.php#L17-L31
33,007
orchestral/support
src/Support/Concerns/Descendible.php
Descendible.resolveLastDecendant
protected function resolveLastDecendant($array, array $keys): ?Fluent { $isLastDescendant = function ($array, $segment) { return ! \is_array($array->childs) || ! isset($array->childs[$segment]); }; // To retrieve the array item using dot syntax, we'll iterate through // each segment in the key and look for that value. If it exists, // we will return it, otherwise we will set the depth of the array // and look for the next segment. foreach ($keys as $segment) { if ($isLastDescendant($array, $segment)) { return $array; } $array = $array->childs[$segment]; } return $array; }
php
protected function resolveLastDecendant($array, array $keys): ?Fluent { $isLastDescendant = function ($array, $segment) { return ! \is_array($array->childs) || ! isset($array->childs[$segment]); }; // To retrieve the array item using dot syntax, we'll iterate through // each segment in the key and look for that value. If it exists, // we will return it, otherwise we will set the depth of the array // and look for the next segment. foreach ($keys as $segment) { if ($isLastDescendant($array, $segment)) { return $array; } $array = $array->childs[$segment]; } return $array; }
[ "protected", "function", "resolveLastDecendant", "(", "$", "array", ",", "array", "$", "keys", ")", ":", "?", "Fluent", "{", "$", "isLastDescendant", "=", "function", "(", "$", "array", ",", "$", "segment", ")", "{", "return", "!", "\\", "is_array", "(", "$", "array", "->", "childs", ")", "||", "!", "isset", "(", "$", "array", "->", "childs", "[", "$", "segment", "]", ")", ";", "}", ";", "// To retrieve the array item using dot syntax, we'll iterate through", "// each segment in the key and look for that value. If it exists,", "// we will return it, otherwise we will set the depth of the array", "// and look for the next segment.", "foreach", "(", "$", "keys", "as", "$", "segment", ")", "{", "if", "(", "$", "isLastDescendant", "(", "$", "array", ",", "$", "segment", ")", ")", "{", "return", "$", "array", ";", "}", "$", "array", "=", "$", "array", "->", "childs", "[", "$", "segment", "]", ";", "}", "return", "$", "array", ";", "}" ]
Resolve last descendant node from items. @param mixed $array @param array $keys @return \Orchestra\Support\Fluent|null
[ "Resolve", "last", "descendant", "node", "from", "items", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Concerns/Descendible.php#L41-L60
33,008
silktide/syringe
src/MasterConfig.php
MasterConfig.stableWeightSort
protected function stableWeightSort(array &$array) { foreach ($array as $i => &$value) { $value["key"] = $i; } unset($value); usort($array, function(array $v1, array $v2) { $byWeight = $v1["weight"] - $v2["weight"]; if ($byWeight === 0) { return $v1["key"] - $v2["key"]; } return $byWeight; }); }
php
protected function stableWeightSort(array &$array) { foreach ($array as $i => &$value) { $value["key"] = $i; } unset($value); usort($array, function(array $v1, array $v2) { $byWeight = $v1["weight"] - $v2["weight"]; if ($byWeight === 0) { return $v1["key"] - $v2["key"]; } return $byWeight; }); }
[ "protected", "function", "stableWeightSort", "(", "array", "&", "$", "array", ")", "{", "foreach", "(", "$", "array", "as", "$", "i", "=>", "&", "$", "value", ")", "{", "$", "value", "[", "\"key\"", "]", "=", "$", "i", ";", "}", "unset", "(", "$", "value", ")", ";", "usort", "(", "$", "array", ",", "function", "(", "array", "$", "v1", ",", "array", "$", "v2", ")", "{", "$", "byWeight", "=", "$", "v1", "[", "\"weight\"", "]", "-", "$", "v2", "[", "\"weight\"", "]", ";", "if", "(", "$", "byWeight", "===", "0", ")", "{", "return", "$", "v1", "[", "\"key\"", "]", "-", "$", "v2", "[", "\"key\"", "]", ";", "}", "return", "$", "byWeight", ";", "}", ")", ";", "}" ]
All of these should be ordered by weight, but keep their order if they were equal, aka, a stable sort Unfortunately, all of PHPs underlying sorting is done by QuickSort, so we have to do the sorting ourselves @param array $array @return array
[ "All", "of", "these", "should", "be", "ordered", "by", "weight", "but", "keep", "their", "order", "if", "they", "were", "equal", "aka", "a", "stable", "sort", "Unfortunately", "all", "of", "PHPs", "underlying", "sorting", "is", "done", "by", "QuickSort", "so", "we", "have", "to", "do", "the", "sorting", "ourselves" ]
afff52640aaaacb44e58f65722a5d717648c15fd
https://github.com/silktide/syringe/blob/afff52640aaaacb44e58f65722a5d717648c15fd/src/MasterConfig.php#L76-L90
33,009
canihavesomecoffee/theTVDbAPI
src/Route/UpdatesRoute.php
UpdatesRoute.query
public function query(DateTime $fromTime, DateTime $toTime = null): array { $options = ['query' => ['fromTime' => $fromTime->getTimestamp()]]; if ($toTime !== null) { $options['query']['toTime'] = $toTime->getTimestamp(); } $json = $this->parent->performAPICallWithJsonResponse('get', '/updated/query', $options); return DataParser::parseDataArray($json, UpdateInfo::class); }
php
public function query(DateTime $fromTime, DateTime $toTime = null): array { $options = ['query' => ['fromTime' => $fromTime->getTimestamp()]]; if ($toTime !== null) { $options['query']['toTime'] = $toTime->getTimestamp(); } $json = $this->parent->performAPICallWithJsonResponse('get', '/updated/query', $options); return DataParser::parseDataArray($json, UpdateInfo::class); }
[ "public", "function", "query", "(", "DateTime", "$", "fromTime", ",", "DateTime", "$", "toTime", "=", "null", ")", ":", "array", "{", "$", "options", "=", "[", "'query'", "=>", "[", "'fromTime'", "=>", "$", "fromTime", "->", "getTimestamp", "(", ")", "]", "]", ";", "if", "(", "$", "toTime", "!==", "null", ")", "{", "$", "options", "[", "'query'", "]", "[", "'toTime'", "]", "=", "$", "toTime", "->", "getTimestamp", "(", ")", ";", "}", "$", "json", "=", "$", "this", "->", "parent", "->", "performAPICallWithJsonResponse", "(", "'get'", ",", "'/updated/query'", ",", "$", "options", ")", ";", "return", "DataParser", "::", "parseDataArray", "(", "$", "json", ",", "UpdateInfo", "::", "class", ")", ";", "}" ]
Fetches the series that were updated between the given timestamps. If the toTime variable is left null, the API will take the current timestamp for this. @param DateTime $fromTime Fetch series that were updated after this timestamp. @param DateTime|null $toTime Fetch series that were updated before this timestamp. @return array An array with UpdateInfo instances.
[ "Fetches", "the", "series", "that", "were", "updated", "between", "the", "given", "timestamps", ".", "If", "the", "toTime", "variable", "is", "left", "null", "the", "API", "will", "take", "the", "current", "timestamp", "for", "this", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/Route/UpdatesRoute.php#L54-L63
33,010
nails/module-invoice
admin/controllers/Invoice.php
Invoice.view
public function view() { if (!userHasPermission('admin:invoice:invoice:edit')) { unauthorised(); } $oUri = Factory::service('Uri'); $oModel = $this->oInvoiceModel; $iInvoiceId = (int) $oUri->segment(5); $this->data['invoice'] = $this->oInvoiceModel->getById( $iInvoiceId, ['expand' => $oModel::EXPAND_ALL] ); if (!$this->data['invoice'] || $this->data['invoice']->state->id == 'DRAFT') { show404(); } $this->data['page']->title = 'View Invoice › ' . $this->data['invoice']->ref; $oAsset = Factory::service('Asset'); $oAsset->load('admin.invoice.view.min.js', 'nails/module-invoice'); Helper::loadView('view'); }
php
public function view() { if (!userHasPermission('admin:invoice:invoice:edit')) { unauthorised(); } $oUri = Factory::service('Uri'); $oModel = $this->oInvoiceModel; $iInvoiceId = (int) $oUri->segment(5); $this->data['invoice'] = $this->oInvoiceModel->getById( $iInvoiceId, ['expand' => $oModel::EXPAND_ALL] ); if (!$this->data['invoice'] || $this->data['invoice']->state->id == 'DRAFT') { show404(); } $this->data['page']->title = 'View Invoice › ' . $this->data['invoice']->ref; $oAsset = Factory::service('Asset'); $oAsset->load('admin.invoice.view.min.js', 'nails/module-invoice'); Helper::loadView('view'); }
[ "public", "function", "view", "(", ")", "{", "if", "(", "!", "userHasPermission", "(", "'admin:invoice:invoice:edit'", ")", ")", "{", "unauthorised", "(", ")", ";", "}", "$", "oUri", "=", "Factory", "::", "service", "(", "'Uri'", ")", ";", "$", "oModel", "=", "$", "this", "->", "oInvoiceModel", ";", "$", "iInvoiceId", "=", "(", "int", ")", "$", "oUri", "->", "segment", "(", "5", ")", ";", "$", "this", "->", "data", "[", "'invoice'", "]", "=", "$", "this", "->", "oInvoiceModel", "->", "getById", "(", "$", "iInvoiceId", ",", "[", "'expand'", "=>", "$", "oModel", "::", "EXPAND_ALL", "]", ")", ";", "if", "(", "!", "$", "this", "->", "data", "[", "'invoice'", "]", "||", "$", "this", "->", "data", "[", "'invoice'", "]", "->", "state", "->", "id", "==", "'DRAFT'", ")", "{", "show404", "(", ")", ";", "}", "$", "this", "->", "data", "[", "'page'", "]", "->", "title", "=", "'View Invoice › '", ".", "$", "this", "->", "data", "[", "'invoice'", "]", "->", "ref", ";", "$", "oAsset", "=", "Factory", "::", "service", "(", "'Asset'", ")", ";", "$", "oAsset", "->", "load", "(", "'admin.invoice.view.min.js'", ",", "'nails/module-invoice'", ")", ";", "Helper", "::", "loadView", "(", "'view'", ")", ";", "}" ]
View an invoice @throws \Nails\Common\Exception\FactoryException
[ "View", "an", "invoice" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/admin/controllers/Invoice.php#L447-L471
33,011
nails/module-invoice
admin/controllers/Invoice.php
Invoice._callbackValidCurrency
public function _callbackValidCurrency($sCode) { $oFormValidation = Factory::service('FormValidation'); $oFormValidation->set_message('_callbackValidCurrency', 'Invalid currency.'); $oCurrency = Factory::service('Currency', 'nails/module-currency'); $aEnabled = $oCurrency->getAllEnabled(); foreach ($aEnabled as $oCurrency) { if ($oCurrency->code === $sCode) { return true; } } return false; }
php
public function _callbackValidCurrency($sCode) { $oFormValidation = Factory::service('FormValidation'); $oFormValidation->set_message('_callbackValidCurrency', 'Invalid currency.'); $oCurrency = Factory::service('Currency', 'nails/module-currency'); $aEnabled = $oCurrency->getAllEnabled(); foreach ($aEnabled as $oCurrency) { if ($oCurrency->code === $sCode) { return true; } } return false; }
[ "public", "function", "_callbackValidCurrency", "(", "$", "sCode", ")", "{", "$", "oFormValidation", "=", "Factory", "::", "service", "(", "'FormValidation'", ")", ";", "$", "oFormValidation", "->", "set_message", "(", "'_callbackValidCurrency'", ",", "'Invalid currency.'", ")", ";", "$", "oCurrency", "=", "Factory", "::", "service", "(", "'Currency'", ",", "'nails/module-currency'", ")", ";", "$", "aEnabled", "=", "$", "oCurrency", "->", "getAllEnabled", "(", ")", ";", "foreach", "(", "$", "aEnabled", "as", "$", "oCurrency", ")", "{", "if", "(", "$", "oCurrency", "->", "code", "===", "$", "sCode", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Form validation cal;back to validate currency selection @param string $sCode the currency code @return bool @throws \Nails\Common\Exception\FactoryException
[ "Form", "validation", "cal", ";", "back", "to", "validate", "currency", "selection" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/admin/controllers/Invoice.php#L483-L498
33,012
nails/module-invoice
admin/controllers/Invoice.php
Invoice.make_draft
public function make_draft() { if (!userHasPermission('admin:invoice:invoice:edit')) { unauthorised(); } // -------------------------------------------------------------------------- $oUri = Factory::service('Uri'); $oInvoice = $this->oInvoiceModel->getById($oUri->segment(5)); if (!$oInvoice) { show404(); } // -------------------------------------------------------------------------- // Allow getting a constant $oInvoiceModel = $this->oInvoiceModel; $aData = [ 'state' => $oInvoiceModel::STATE_DRAFT, ]; if ($this->oInvoiceModel->update($oInvoice->id, $aData)) { $sStatus = 'success'; $sMessage = 'Invoice updated successfully!'; } else { $sStatus = 'error'; $sMessage = 'Invoice failed to update invoice. ' . $this->oInvoiceModel->lastError(); } $oSession = Factory::service('Session', 'nails/module-auth'); $oSession->setFlashData($sStatus, $sMessage); redirect('admin/invoice/invoice/edit/' . $oInvoice->id); }
php
public function make_draft() { if (!userHasPermission('admin:invoice:invoice:edit')) { unauthorised(); } // -------------------------------------------------------------------------- $oUri = Factory::service('Uri'); $oInvoice = $this->oInvoiceModel->getById($oUri->segment(5)); if (!$oInvoice) { show404(); } // -------------------------------------------------------------------------- // Allow getting a constant $oInvoiceModel = $this->oInvoiceModel; $aData = [ 'state' => $oInvoiceModel::STATE_DRAFT, ]; if ($this->oInvoiceModel->update($oInvoice->id, $aData)) { $sStatus = 'success'; $sMessage = 'Invoice updated successfully!'; } else { $sStatus = 'error'; $sMessage = 'Invoice failed to update invoice. ' . $this->oInvoiceModel->lastError(); } $oSession = Factory::service('Session', 'nails/module-auth'); $oSession->setFlashData($sStatus, $sMessage); redirect('admin/invoice/invoice/edit/' . $oInvoice->id); }
[ "public", "function", "make_draft", "(", ")", "{", "if", "(", "!", "userHasPermission", "(", "'admin:invoice:invoice:edit'", ")", ")", "{", "unauthorised", "(", ")", ";", "}", "// --------------------------------------------------------------------------", "$", "oUri", "=", "Factory", "::", "service", "(", "'Uri'", ")", ";", "$", "oInvoice", "=", "$", "this", "->", "oInvoiceModel", "->", "getById", "(", "$", "oUri", "->", "segment", "(", "5", ")", ")", ";", "if", "(", "!", "$", "oInvoice", ")", "{", "show404", "(", ")", ";", "}", "// --------------------------------------------------------------------------", "// Allow getting a constant", "$", "oInvoiceModel", "=", "$", "this", "->", "oInvoiceModel", ";", "$", "aData", "=", "[", "'state'", "=>", "$", "oInvoiceModel", "::", "STATE_DRAFT", ",", "]", ";", "if", "(", "$", "this", "->", "oInvoiceModel", "->", "update", "(", "$", "oInvoice", "->", "id", ",", "$", "aData", ")", ")", "{", "$", "sStatus", "=", "'success'", ";", "$", "sMessage", "=", "'Invoice updated successfully!'", ";", "}", "else", "{", "$", "sStatus", "=", "'error'", ";", "$", "sMessage", "=", "'Invoice failed to update invoice. '", ".", "$", "this", "->", "oInvoiceModel", "->", "lastError", "(", ")", ";", "}", "$", "oSession", "=", "Factory", "::", "service", "(", "'Session'", ",", "'nails/module-auth'", ")", ";", "$", "oSession", "->", "setFlashData", "(", "$", "sStatus", ",", "$", "sMessage", ")", ";", "redirect", "(", "'admin/invoice/invoice/edit/'", ".", "$", "oInvoice", "->", "id", ")", ";", "}" ]
Make an invoice a draft @throws \Nails\Common\Exception\FactoryException
[ "Make", "an", "invoice", "a", "draft" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/admin/controllers/Invoice.php#L507-L541
33,013
nails/module-invoice
admin/controllers/Invoice.php
Invoice.delete
public function delete() { if (!userHasPermission('admin:invoice:invoice:delete')) { unauthorised(); } // -------------------------------------------------------------------------- $oUri = Factory::service('Uri'); $oInvoice = $this->oInvoiceModel->getById($oUri->segment(5)); if (!$oInvoice) { show404(); } // -------------------------------------------------------------------------- if ($this->oInvoiceModel->delete($oInvoice->id)) { $sStatus = 'success'; $sMessage = 'Invoice deleted successfully!'; } else { $sStatus = 'error'; $sMessage = 'Invoice failed to delete. ' . $this->oInvoiceModel->lastError(); } $oSession = Factory::service('Session', 'nails/module-auth'); $oSession->setFlashData($sStatus, $sMessage); redirect('admin/invoice/invoice/index'); }
php
public function delete() { if (!userHasPermission('admin:invoice:invoice:delete')) { unauthorised(); } // -------------------------------------------------------------------------- $oUri = Factory::service('Uri'); $oInvoice = $this->oInvoiceModel->getById($oUri->segment(5)); if (!$oInvoice) { show404(); } // -------------------------------------------------------------------------- if ($this->oInvoiceModel->delete($oInvoice->id)) { $sStatus = 'success'; $sMessage = 'Invoice deleted successfully!'; } else { $sStatus = 'error'; $sMessage = 'Invoice failed to delete. ' . $this->oInvoiceModel->lastError(); } $oSession = Factory::service('Session', 'nails/module-auth'); $oSession->setFlashData($sStatus, $sMessage); redirect('admin/invoice/invoice/index'); }
[ "public", "function", "delete", "(", ")", "{", "if", "(", "!", "userHasPermission", "(", "'admin:invoice:invoice:delete'", ")", ")", "{", "unauthorised", "(", ")", ";", "}", "// --------------------------------------------------------------------------", "$", "oUri", "=", "Factory", "::", "service", "(", "'Uri'", ")", ";", "$", "oInvoice", "=", "$", "this", "->", "oInvoiceModel", "->", "getById", "(", "$", "oUri", "->", "segment", "(", "5", ")", ")", ";", "if", "(", "!", "$", "oInvoice", ")", "{", "show404", "(", ")", ";", "}", "// --------------------------------------------------------------------------", "if", "(", "$", "this", "->", "oInvoiceModel", "->", "delete", "(", "$", "oInvoice", "->", "id", ")", ")", "{", "$", "sStatus", "=", "'success'", ";", "$", "sMessage", "=", "'Invoice deleted successfully!'", ";", "}", "else", "{", "$", "sStatus", "=", "'error'", ";", "$", "sMessage", "=", "'Invoice failed to delete. '", ".", "$", "this", "->", "oInvoiceModel", "->", "lastError", "(", ")", ";", "}", "$", "oSession", "=", "Factory", "::", "service", "(", "'Session'", ",", "'nails/module-auth'", ")", ";", "$", "oSession", "->", "setFlashData", "(", "$", "sStatus", ",", "$", "sMessage", ")", ";", "redirect", "(", "'admin/invoice/invoice/index'", ")", ";", "}" ]
Delete an invoice @throws \Nails\Common\Exception\FactoryException
[ "Delete", "an", "invoice" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/admin/controllers/Invoice.php#L593-L621
33,014
nails/module-invoice
admin/controllers/Invoice.php
Invoice.validatePost
protected function validatePost() { $oFormValidation = Factory::service('FormValidation'); $aRules = [ 'ref' => 'trim', 'state' => 'trim|required', 'dated' => 'trim|required|valid_date', 'currency' => 'trim|required|callback__callbackValidCurrency', 'terms' => 'trim|is_natural', 'customer_id' => 'trim', 'additional_text' => 'trim', 'items' => '', ]; $aRulesFV = []; foreach ($aRules as $sKey => $sRules) { $aRulesFV[] = [ 'field' => $sKey, 'label' => '', 'rules' => $sRules, ]; } $oFormValidation->set_rules($aRulesFV); $oFormValidation->set_message('required', lang('fv_required')); $oFormValidation->set_message('valid_date', lang('fv_valid_date')); $oFormValidation->set_message('is_natural', lang('fv_is_natural')); $oFormValidation->set_message('valid_email', lang('fv_valid_email')); return $oFormValidation->run($this); }
php
protected function validatePost() { $oFormValidation = Factory::service('FormValidation'); $aRules = [ 'ref' => 'trim', 'state' => 'trim|required', 'dated' => 'trim|required|valid_date', 'currency' => 'trim|required|callback__callbackValidCurrency', 'terms' => 'trim|is_natural', 'customer_id' => 'trim', 'additional_text' => 'trim', 'items' => '', ]; $aRulesFV = []; foreach ($aRules as $sKey => $sRules) { $aRulesFV[] = [ 'field' => $sKey, 'label' => '', 'rules' => $sRules, ]; } $oFormValidation->set_rules($aRulesFV); $oFormValidation->set_message('required', lang('fv_required')); $oFormValidation->set_message('valid_date', lang('fv_valid_date')); $oFormValidation->set_message('is_natural', lang('fv_is_natural')); $oFormValidation->set_message('valid_email', lang('fv_valid_email')); return $oFormValidation->run($this); }
[ "protected", "function", "validatePost", "(", ")", "{", "$", "oFormValidation", "=", "Factory", "::", "service", "(", "'FormValidation'", ")", ";", "$", "aRules", "=", "[", "'ref'", "=>", "'trim'", ",", "'state'", "=>", "'trim|required'", ",", "'dated'", "=>", "'trim|required|valid_date'", ",", "'currency'", "=>", "'trim|required|callback__callbackValidCurrency'", ",", "'terms'", "=>", "'trim|is_natural'", ",", "'customer_id'", "=>", "'trim'", ",", "'additional_text'", "=>", "'trim'", ",", "'items'", "=>", "''", ",", "]", ";", "$", "aRulesFV", "=", "[", "]", ";", "foreach", "(", "$", "aRules", "as", "$", "sKey", "=>", "$", "sRules", ")", "{", "$", "aRulesFV", "[", "]", "=", "[", "'field'", "=>", "$", "sKey", ",", "'label'", "=>", "''", ",", "'rules'", "=>", "$", "sRules", ",", "]", ";", "}", "$", "oFormValidation", "->", "set_rules", "(", "$", "aRulesFV", ")", ";", "$", "oFormValidation", "->", "set_message", "(", "'required'", ",", "lang", "(", "'fv_required'", ")", ")", ";", "$", "oFormValidation", "->", "set_message", "(", "'valid_date'", ",", "lang", "(", "'fv_valid_date'", ")", ")", ";", "$", "oFormValidation", "->", "set_message", "(", "'is_natural'", ",", "lang", "(", "'fv_is_natural'", ")", ")", ";", "$", "oFormValidation", "->", "set_message", "(", "'valid_email'", ",", "lang", "(", "'fv_valid_email'", ")", ")", ";", "return", "$", "oFormValidation", "->", "run", "(", "$", "this", ")", ";", "}" ]
Validate the POST data @return boolean @throws \Nails\Common\Exception\FactoryException
[ "Validate", "the", "POST", "data" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/admin/controllers/Invoice.php#L631-L663
33,015
nails/module-invoice
admin/controllers/Invoice.php
Invoice.getObjectFromPost
protected function getObjectFromPost() { $oInput = Factory::service('Input'); $oUri = Factory::service('Uri'); $aData = [ 'ref' => $oInput->post('ref') ?: null, 'state' => $oInput->post('state') ?: null, 'dated' => $oInput->post('dated') ?: null, 'currency' => $oInput->post('currency') ?: null, 'terms' => (int) $oInput->post('terms') ?: 0, 'customer_id' => (int) $oInput->post('customer_id') ?: null, 'additional_text' => $oInput->post('additional_text') ?: null, 'items' => [], 'currency' => $oInput->post('currency'), ]; if ($oInput->post('items')) { foreach ($oInput->post('items') as $aItem) { // @todo convert to pence using a model $aData['items'][] = [ 'id' => array_key_exists('id', $aItem) ? $aItem['id'] : null, 'quantity' => array_key_exists('quantity', $aItem) ? $aItem['quantity'] : null, 'unit' => array_key_exists('unit', $aItem) ? $aItem['unit'] : null, 'label' => array_key_exists('label', $aItem) ? $aItem['label'] : null, 'body' => array_key_exists('body', $aItem) ? $aItem['body'] : null, 'unit_cost' => array_key_exists('unit_cost', $aItem) ? intval($aItem['unit_cost'] * 100) : null, 'tax_id' => array_key_exists('tax_id', $aItem) ? $aItem['tax_id'] : null, ]; } } if ($oUri->rsegment(5) == 'edit') { unset($aData['ref']); } return $aData; }
php
protected function getObjectFromPost() { $oInput = Factory::service('Input'); $oUri = Factory::service('Uri'); $aData = [ 'ref' => $oInput->post('ref') ?: null, 'state' => $oInput->post('state') ?: null, 'dated' => $oInput->post('dated') ?: null, 'currency' => $oInput->post('currency') ?: null, 'terms' => (int) $oInput->post('terms') ?: 0, 'customer_id' => (int) $oInput->post('customer_id') ?: null, 'additional_text' => $oInput->post('additional_text') ?: null, 'items' => [], 'currency' => $oInput->post('currency'), ]; if ($oInput->post('items')) { foreach ($oInput->post('items') as $aItem) { // @todo convert to pence using a model $aData['items'][] = [ 'id' => array_key_exists('id', $aItem) ? $aItem['id'] : null, 'quantity' => array_key_exists('quantity', $aItem) ? $aItem['quantity'] : null, 'unit' => array_key_exists('unit', $aItem) ? $aItem['unit'] : null, 'label' => array_key_exists('label', $aItem) ? $aItem['label'] : null, 'body' => array_key_exists('body', $aItem) ? $aItem['body'] : null, 'unit_cost' => array_key_exists('unit_cost', $aItem) ? intval($aItem['unit_cost'] * 100) : null, 'tax_id' => array_key_exists('tax_id', $aItem) ? $aItem['tax_id'] : null, ]; } } if ($oUri->rsegment(5) == 'edit') { unset($aData['ref']); } return $aData; }
[ "protected", "function", "getObjectFromPost", "(", ")", "{", "$", "oInput", "=", "Factory", "::", "service", "(", "'Input'", ")", ";", "$", "oUri", "=", "Factory", "::", "service", "(", "'Uri'", ")", ";", "$", "aData", "=", "[", "'ref'", "=>", "$", "oInput", "->", "post", "(", "'ref'", ")", "?", ":", "null", ",", "'state'", "=>", "$", "oInput", "->", "post", "(", "'state'", ")", "?", ":", "null", ",", "'dated'", "=>", "$", "oInput", "->", "post", "(", "'dated'", ")", "?", ":", "null", ",", "'currency'", "=>", "$", "oInput", "->", "post", "(", "'currency'", ")", "?", ":", "null", ",", "'terms'", "=>", "(", "int", ")", "$", "oInput", "->", "post", "(", "'terms'", ")", "?", ":", "0", ",", "'customer_id'", "=>", "(", "int", ")", "$", "oInput", "->", "post", "(", "'customer_id'", ")", "?", ":", "null", ",", "'additional_text'", "=>", "$", "oInput", "->", "post", "(", "'additional_text'", ")", "?", ":", "null", ",", "'items'", "=>", "[", "]", ",", "'currency'", "=>", "$", "oInput", "->", "post", "(", "'currency'", ")", ",", "]", ";", "if", "(", "$", "oInput", "->", "post", "(", "'items'", ")", ")", "{", "foreach", "(", "$", "oInput", "->", "post", "(", "'items'", ")", "as", "$", "aItem", ")", "{", "// @todo convert to pence using a model", "$", "aData", "[", "'items'", "]", "[", "]", "=", "[", "'id'", "=>", "array_key_exists", "(", "'id'", ",", "$", "aItem", ")", "?", "$", "aItem", "[", "'id'", "]", ":", "null", ",", "'quantity'", "=>", "array_key_exists", "(", "'quantity'", ",", "$", "aItem", ")", "?", "$", "aItem", "[", "'quantity'", "]", ":", "null", ",", "'unit'", "=>", "array_key_exists", "(", "'unit'", ",", "$", "aItem", ")", "?", "$", "aItem", "[", "'unit'", "]", ":", "null", ",", "'label'", "=>", "array_key_exists", "(", "'label'", ",", "$", "aItem", ")", "?", "$", "aItem", "[", "'label'", "]", ":", "null", ",", "'body'", "=>", "array_key_exists", "(", "'body'", ",", "$", "aItem", ")", "?", "$", "aItem", "[", "'body'", "]", ":", "null", ",", "'unit_cost'", "=>", "array_key_exists", "(", "'unit_cost'", ",", "$", "aItem", ")", "?", "intval", "(", "$", "aItem", "[", "'unit_cost'", "]", "*", "100", ")", ":", "null", ",", "'tax_id'", "=>", "array_key_exists", "(", "'tax_id'", ",", "$", "aItem", ")", "?", "$", "aItem", "[", "'tax_id'", "]", ":", "null", ",", "]", ";", "}", "}", "if", "(", "$", "oUri", "->", "rsegment", "(", "5", ")", "==", "'edit'", ")", "{", "unset", "(", "$", "aData", "[", "'ref'", "]", ")", ";", "}", "return", "$", "aData", ";", "}" ]
Get an object generated from the POST data @return array @throws \Nails\Common\Exception\FactoryException
[ "Get", "an", "object", "generated", "from", "the", "POST", "data" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/admin/controllers/Invoice.php#L673-L710
33,016
rinvex/cortex-console
src/Http/Controllers/Adminarea/TerminalController.php
TerminalController.index
public function index(Request $request, Terminal $terminal) { $token = null; if ($request->hasSession() === true) { $token = $request->session()->token(); } $terminal->call('list --ansi'); $options = json_encode([ 'username' => 'LARAVEL', 'hostname' => php_uname('n'), 'os' => PHP_OS, 'csrfToken' => $token, 'helpInfo' => $terminal->output(), 'basePath' => app()->basePath(), 'environment' => app()->environment(), 'version' => app()->version(), 'endpoint' => route('adminarea.console.terminal.execute'), 'interpreters' => [ 'mysql' => 'mysql', 'artisan tinker' => 'tinker', 'tinker' => 'tinker', ], 'confirmToProceed' => [ 'artisan' => [ 'migrate', 'migrate:install', 'migrate:refresh', 'migrate:reset', 'migrate:rollback', 'db:seed', ], ], ]); return view('cortex/console::adminarea.pages.terminal', compact('options')); }
php
public function index(Request $request, Terminal $terminal) { $token = null; if ($request->hasSession() === true) { $token = $request->session()->token(); } $terminal->call('list --ansi'); $options = json_encode([ 'username' => 'LARAVEL', 'hostname' => php_uname('n'), 'os' => PHP_OS, 'csrfToken' => $token, 'helpInfo' => $terminal->output(), 'basePath' => app()->basePath(), 'environment' => app()->environment(), 'version' => app()->version(), 'endpoint' => route('adminarea.console.terminal.execute'), 'interpreters' => [ 'mysql' => 'mysql', 'artisan tinker' => 'tinker', 'tinker' => 'tinker', ], 'confirmToProceed' => [ 'artisan' => [ 'migrate', 'migrate:install', 'migrate:refresh', 'migrate:reset', 'migrate:rollback', 'db:seed', ], ], ]); return view('cortex/console::adminarea.pages.terminal', compact('options')); }
[ "public", "function", "index", "(", "Request", "$", "request", ",", "Terminal", "$", "terminal", ")", "{", "$", "token", "=", "null", ";", "if", "(", "$", "request", "->", "hasSession", "(", ")", "===", "true", ")", "{", "$", "token", "=", "$", "request", "->", "session", "(", ")", "->", "token", "(", ")", ";", "}", "$", "terminal", "->", "call", "(", "'list --ansi'", ")", ";", "$", "options", "=", "json_encode", "(", "[", "'username'", "=>", "'LARAVEL'", ",", "'hostname'", "=>", "php_uname", "(", "'n'", ")", ",", "'os'", "=>", "PHP_OS", ",", "'csrfToken'", "=>", "$", "token", ",", "'helpInfo'", "=>", "$", "terminal", "->", "output", "(", ")", ",", "'basePath'", "=>", "app", "(", ")", "->", "basePath", "(", ")", ",", "'environment'", "=>", "app", "(", ")", "->", "environment", "(", ")", ",", "'version'", "=>", "app", "(", ")", "->", "version", "(", ")", ",", "'endpoint'", "=>", "route", "(", "'adminarea.console.terminal.execute'", ")", ",", "'interpreters'", "=>", "[", "'mysql'", "=>", "'mysql'", ",", "'artisan tinker'", "=>", "'tinker'", ",", "'tinker'", "=>", "'tinker'", ",", "]", ",", "'confirmToProceed'", "=>", "[", "'artisan'", "=>", "[", "'migrate'", ",", "'migrate:install'", ",", "'migrate:refresh'", ",", "'migrate:reset'", ",", "'migrate:rollback'", ",", "'db:seed'", ",", "]", ",", "]", ",", "]", ")", ";", "return", "view", "(", "'cortex/console::adminarea.pages.terminal'", ",", "compact", "(", "'options'", ")", ")", ";", "}" ]
Show terminal index. @param \Illuminate\Http\Request $request @param \Cortex\Console\Services\Terminal $terminal @return \Illuminate\View\View
[ "Show", "terminal", "index", "." ]
218307609effc38f16b00dba46786a296246f3b5
https://github.com/rinvex/cortex-console/blob/218307609effc38f16b00dba46786a296246f3b5/src/Http/Controllers/Adminarea/TerminalController.php#L27-L64
33,017
QoboLtd/qobo-robo
src/Command/Project/DotenvReload.php
DotenvReload.projectDotenvReload
public function projectDotenvReload($envPath = '.env', $opts = ['format' => 'table', 'fields' => '']) { // Reload $result = $this->taskDotenvReload() ->path($envPath) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return new PropertyList($result->getData()); }
php
public function projectDotenvReload($envPath = '.env', $opts = ['format' => 'table', 'fields' => '']) { // Reload $result = $this->taskDotenvReload() ->path($envPath) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return new PropertyList($result->getData()); }
[ "public", "function", "projectDotenvReload", "(", "$", "envPath", "=", "'.env'", ",", "$", "opts", "=", "[", "'format'", "=>", "'table'", ",", "'fields'", "=>", "''", "]", ")", "{", "// Reload", "$", "result", "=", "$", "this", "->", "taskDotenvReload", "(", ")", "->", "path", "(", "$", "envPath", ")", "->", "run", "(", ")", ";", "if", "(", "!", "$", "result", "->", "wasSuccessful", "(", ")", ")", "{", "$", "this", "->", "exitError", "(", "\"Failed to run command\"", ")", ";", "}", "return", "new", "PropertyList", "(", "$", "result", "->", "getData", "(", ")", ")", ";", "}" ]
Reload environment from given dotenv file @param string $envPath Path to dotenv file @option string $format Output format (table, list, csv, json, xml) @option string $fields Limit output to given fields, comma-separated @return PropertyList result
[ "Reload", "environment", "from", "given", "dotenv", "file" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Command/Project/DotenvReload.php#L28-L40
33,018
QoboLtd/qobo-robo
src/Command/Mysql/Export.php
Export.mysqlExport
public function mysqlExport($db, $file = 'etc/mysql.sql', $user = 'root', $pass = null, $host = null, $port = null, $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskMysqlExport() ->db($db) ->file($file) ->user($user) ->pass($pass) ->host($host) ->port($port) ->hide($pass) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
php
public function mysqlExport($db, $file = 'etc/mysql.sql', $user = 'root', $pass = null, $host = null, $port = null, $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskMysqlExport() ->db($db) ->file($file) ->user($user) ->pass($pass) ->host($host) ->port($port) ->hide($pass) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
[ "public", "function", "mysqlExport", "(", "$", "db", ",", "$", "file", "=", "'etc/mysql.sql'", ",", "$", "user", "=", "'root'", ",", "$", "pass", "=", "null", ",", "$", "host", "=", "null", ",", "$", "port", "=", "null", ",", "$", "opts", "=", "[", "'format'", "=>", "'table'", ",", "'fields'", "=>", "''", "]", ")", "{", "$", "result", "=", "$", "this", "->", "taskMysqlExport", "(", ")", "->", "db", "(", "$", "db", ")", "->", "file", "(", "$", "file", ")", "->", "user", "(", "$", "user", ")", "->", "pass", "(", "$", "pass", ")", "->", "host", "(", "$", "host", ")", "->", "port", "(", "$", "port", ")", "->", "hide", "(", "$", "pass", ")", "->", "run", "(", ")", ";", "if", "(", "!", "$", "result", "->", "wasSuccessful", "(", ")", ")", "{", "$", "this", "->", "exitError", "(", "\"Failed to run command\"", ")", ";", "}", "return", "true", ";", "}" ]
Dump mysql database @param string $db Database name @param string $file Destination file for a dump @param string $user MySQL user to bind with @param string $pass (Optional) MySQL user password @param string $host (Optional) MySQL server host @param string $port (Optional) MySQL server port @option string $format Output format (table, list, csv, json, xml) @option string $fields Limit output to given fields, comma-separated @return PropertyList result
[ "Dump", "mysql", "database" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Command/Mysql/Export.php#L33-L50
33,019
doganoo/PHPUtil
src/Util/NumberUtil.php
NumberUtil.format
public static function format($value, int $decimals = 2): ?string { if (!\is_numeric($value)) { return null; } return \number_format($value, $decimals); }
php
public static function format($value, int $decimals = 2): ?string { if (!\is_numeric($value)) { return null; } return \number_format($value, $decimals); }
[ "public", "static", "function", "format", "(", "$", "value", ",", "int", "$", "decimals", "=", "2", ")", ":", "?", "string", "{", "if", "(", "!", "\\", "is_numeric", "(", "$", "value", ")", ")", "{", "return", "null", ";", "}", "return", "\\", "number_format", "(", "$", "value", ",", "$", "decimals", ")", ";", "}" ]
returns the formatted number with grouped thousands @param $value @param int $decimals @return null|string
[ "returns", "the", "formatted", "number", "with", "grouped", "thousands" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Util/NumberUtil.php#L44-L49
33,020
doganoo/PHPUtil
src/Util/NumberUtil.php
NumberUtil.stripNonInteger
public static function stripNonInteger(array $array): array { $newArray = []; foreach ($array as $value) { if (!NumberUtil::isInteger($value)) continue; $newArray[] = \intval($value); } return $newArray; }
php
public static function stripNonInteger(array $array): array { $newArray = []; foreach ($array as $value) { if (!NumberUtil::isInteger($value)) continue; $newArray[] = \intval($value); } return $newArray; }
[ "public", "static", "function", "stripNonInteger", "(", "array", "$", "array", ")", ":", "array", "{", "$", "newArray", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "value", ")", "{", "if", "(", "!", "NumberUtil", "::", "isInteger", "(", "$", "value", ")", ")", "continue", ";", "$", "newArray", "[", "]", "=", "\\", "intval", "(", "$", "value", ")", ";", "}", "return", "$", "newArray", ";", "}" ]
strips all non integer fields from the input and returns all values as integer data type. @param array $array @return array
[ "strips", "all", "non", "integer", "fields", "from", "the", "input", "and", "returns", "all", "values", "as", "integer", "data", "type", "." ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Util/NumberUtil.php#L112-L119
33,021
QoboLtd/qobo-robo
src/Command/Template/Tokens.php
Tokens.templateTokens
public function templateTokens($path, $pre = '%%', $post = '%%', $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskTemplateTokens() ->path($path) ->pre($pre) ->post($post) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } $data = $result->getData(); if (empty($data) || !isset($data['data'])) { return new RowsOfFields([]); } natsort($data['data']); $data['data'] = array_map(function ($item) { return ['Token' => $item]; }, $data['data']); return new RowsOfFields($data['data']); }
php
public function templateTokens($path, $pre = '%%', $post = '%%', $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskTemplateTokens() ->path($path) ->pre($pre) ->post($post) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } $data = $result->getData(); if (empty($data) || !isset($data['data'])) { return new RowsOfFields([]); } natsort($data['data']); $data['data'] = array_map(function ($item) { return ['Token' => $item]; }, $data['data']); return new RowsOfFields($data['data']); }
[ "public", "function", "templateTokens", "(", "$", "path", ",", "$", "pre", "=", "'%%'", ",", "$", "post", "=", "'%%'", ",", "$", "opts", "=", "[", "'format'", "=>", "'table'", ",", "'fields'", "=>", "''", "]", ")", "{", "$", "result", "=", "$", "this", "->", "taskTemplateTokens", "(", ")", "->", "path", "(", "$", "path", ")", "->", "pre", "(", "$", "pre", ")", "->", "post", "(", "$", "post", ")", "->", "run", "(", ")", ";", "if", "(", "!", "$", "result", "->", "wasSuccessful", "(", ")", ")", "{", "$", "this", "->", "exitError", "(", "\"Failed to run command\"", ")", ";", "}", "$", "data", "=", "$", "result", "->", "getData", "(", ")", ";", "if", "(", "empty", "(", "$", "data", ")", "||", "!", "isset", "(", "$", "data", "[", "'data'", "]", ")", ")", "{", "return", "new", "RowsOfFields", "(", "[", "]", ")", ";", "}", "natsort", "(", "$", "data", "[", "'data'", "]", ")", ";", "$", "data", "[", "'data'", "]", "=", "array_map", "(", "function", "(", "$", "item", ")", "{", "return", "[", "'Token'", "=>", "$", "item", "]", ";", "}", ",", "$", "data", "[", "'data'", "]", ")", ";", "return", "new", "RowsOfFields", "(", "$", "data", "[", "'data'", "]", ")", ";", "}" ]
List all present tokens in a given template @param string $path Path to template @param string $pre Token prefix @param string $post Token postfix @option string $format Output format (table, list, csv, json, xml) @option string $fields Limit output to given fields, comma-separated @return RowsOfFields|false on success, false on failure
[ "List", "all", "present", "tokens", "in", "a", "given", "template" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Command/Template/Tokens.php#L30-L53
33,022
g4code/data-mapper
src/Bulk/Solr.php
Solr.markForSetAtomic
public function markForSetAtomic(\G4\DataMapper\Domain\DomainAbstract $domain) { $this->data[] = $this->addMethodToData(self::METHOD_SET, array_filter($domain->getRawData())); return $this; }
php
public function markForSetAtomic(\G4\DataMapper\Domain\DomainAbstract $domain) { $this->data[] = $this->addMethodToData(self::METHOD_SET, array_filter($domain->getRawData())); return $this; }
[ "public", "function", "markForSetAtomic", "(", "\\", "G4", "\\", "DataMapper", "\\", "Domain", "\\", "DomainAbstract", "$", "domain", ")", "{", "$", "this", "->", "data", "[", "]", "=", "$", "this", "->", "addMethodToData", "(", "self", "::", "METHOD_SET", ",", "array_filter", "(", "$", "domain", "->", "getRawData", "(", ")", ")", ")", ";", "return", "$", "this", ";", "}" ]
Atomic update of all fields that are not null @param \G4\DataMapper\Domain\DomainAbstract $domain @return $this
[ "Atomic", "update", "of", "all", "fields", "that", "are", "not", "null" ]
ac794cb5b02d277b524fb9e65f59ba87170afd97
https://github.com/g4code/data-mapper/blob/ac794cb5b02d277b524fb9e65f59ba87170afd97/src/Bulk/Solr.php#L86-L90
33,023
doganoo/PHPUtil
src/HTTP/Session.php
Session.readArray
public function readArray($index) { return isset ($_SESSION [$index]) && is_array($_SESSION [$index]) ? $_SESSION [$index] : []; }
php
public function readArray($index) { return isset ($_SESSION [$index]) && is_array($_SESSION [$index]) ? $_SESSION [$index] : []; }
[ "public", "function", "readArray", "(", "$", "index", ")", "{", "return", "isset", "(", "$", "_SESSION", "[", "$", "index", "]", ")", "&&", "is_array", "(", "$", "_SESSION", "[", "$", "index", "]", ")", "?", "$", "_SESSION", "[", "$", "index", "]", ":", "[", "]", ";", "}" ]
reads an array from the session @param $index @return array
[ "reads", "an", "array", "from", "the", "session" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/HTTP/Session.php#L54-L56
33,024
rinvex/cortex-console
src/Http/Controllers/Adminarea/RoutesController.php
RoutesController.index
public function index(RoutesDataTable $routesDataTable) { $middlewareClosure = function ($middleware) { return $middleware instanceof Closure ? 'Closure' : $middleware; }; return $routesDataTable->with([ 'id' => 'adminarea-routes-index-table', 'middlewareClosure' => $middlewareClosure, ])->render('cortex/foundation::adminarea.pages.datatable-index'); }
php
public function index(RoutesDataTable $routesDataTable) { $middlewareClosure = function ($middleware) { return $middleware instanceof Closure ? 'Closure' : $middleware; }; return $routesDataTable->with([ 'id' => 'adminarea-routes-index-table', 'middlewareClosure' => $middlewareClosure, ])->render('cortex/foundation::adminarea.pages.datatable-index'); }
[ "public", "function", "index", "(", "RoutesDataTable", "$", "routesDataTable", ")", "{", "$", "middlewareClosure", "=", "function", "(", "$", "middleware", ")", "{", "return", "$", "middleware", "instanceof", "Closure", "?", "'Closure'", ":", "$", "middleware", ";", "}", ";", "return", "$", "routesDataTable", "->", "with", "(", "[", "'id'", "=>", "'adminarea-routes-index-table'", ",", "'middlewareClosure'", "=>", "$", "middlewareClosure", ",", "]", ")", "->", "render", "(", "'cortex/foundation::adminarea.pages.datatable-index'", ")", ";", "}" ]
List all routes. @param \Cortex\Console\DataTables\Adminarea\RoutesDataTable $routesDataTable @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
[ "List", "all", "routes", "." ]
218307609effc38f16b00dba46786a296246f3b5
https://github.com/rinvex/cortex-console/blob/218307609effc38f16b00dba46786a296246f3b5/src/Http/Controllers/Adminarea/RoutesController.php#L25-L35
33,025
QoboLtd/qobo-robo
src/Command/Template/Process.php
Process.templateProcess
public function templateProcess($src, $dst, $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskDotenvFileRead() ->path('.env') ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } $data = $result->getData(); if (!isset($data['data'])) { $this->exitError("Failed to run command"); } $result = $this->taskTemplateProcess() ->src($src) ->dst($dst) ->wrap('%%') ->tokens($data['data']) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
php
public function templateProcess($src, $dst, $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskDotenvFileRead() ->path('.env') ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } $data = $result->getData(); if (!isset($data['data'])) { $this->exitError("Failed to run command"); } $result = $this->taskTemplateProcess() ->src($src) ->dst($dst) ->wrap('%%') ->tokens($data['data']) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
[ "public", "function", "templateProcess", "(", "$", "src", ",", "$", "dst", ",", "$", "opts", "=", "[", "'format'", "=>", "'table'", ",", "'fields'", "=>", "''", "]", ")", "{", "$", "result", "=", "$", "this", "->", "taskDotenvFileRead", "(", ")", "->", "path", "(", "'.env'", ")", "->", "run", "(", ")", ";", "if", "(", "!", "$", "result", "->", "wasSuccessful", "(", ")", ")", "{", "$", "this", "->", "exitError", "(", "\"Failed to run command\"", ")", ";", "}", "$", "data", "=", "$", "result", "->", "getData", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "'data'", "]", ")", ")", "{", "$", "this", "->", "exitError", "(", "\"Failed to run command\"", ")", ";", "}", "$", "result", "=", "$", "this", "->", "taskTemplateProcess", "(", ")", "->", "src", "(", "$", "src", ")", "->", "dst", "(", "$", "dst", ")", "->", "wrap", "(", "'%%'", ")", "->", "tokens", "(", "$", "data", "[", "'data'", "]", ")", "->", "run", "(", ")", ";", "if", "(", "!", "$", "result", "->", "wasSuccessful", "(", ")", ")", "{", "$", "this", "->", "exitError", "(", "\"Failed to run command\"", ")", ";", "}", "return", "true", ";", "}" ]
Process given template with tokens from environment variables @param string $src Path to template @param string $dst Path to final file @option string $format Output format (table, list, csv, json, xml) @option string $fields Limit output to given fields, comma-separated @return bool true on success, false on failure
[ "Process", "given", "template", "with", "tokens", "from", "environment", "variables" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Command/Template/Process.php#L29-L55
33,026
orchestral/support
src/Support/Serializer.php
Serializer.serializeBasicDataset
final protected function serializeBasicDataset($dataset): array { $key = $this->resolveSerializerKey($dataset); if ($dataset instanceof Paginator) { $collection = $dataset->toArray(); $collection[$key] = $collection['data']; unset($collection['data']); return $collection; } return [ $key => $dataset->toArray(), ]; }
php
final protected function serializeBasicDataset($dataset): array { $key = $this->resolveSerializerKey($dataset); if ($dataset instanceof Paginator) { $collection = $dataset->toArray(); $collection[$key] = $collection['data']; unset($collection['data']); return $collection; } return [ $key => $dataset->toArray(), ]; }
[ "final", "protected", "function", "serializeBasicDataset", "(", "$", "dataset", ")", ":", "array", "{", "$", "key", "=", "$", "this", "->", "resolveSerializerKey", "(", "$", "dataset", ")", ";", "if", "(", "$", "dataset", "instanceof", "Paginator", ")", "{", "$", "collection", "=", "$", "dataset", "->", "toArray", "(", ")", ";", "$", "collection", "[", "$", "key", "]", "=", "$", "collection", "[", "'data'", "]", ";", "unset", "(", "$", "collection", "[", "'data'", "]", ")", ";", "return", "$", "collection", ";", "}", "return", "[", "$", "key", "=>", "$", "dataset", "->", "toArray", "(", ")", ",", "]", ";", "}" ]
Resolve paginated dataset. @param mixed $dataset @return array
[ "Resolve", "paginated", "dataset", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Serializer.php#L40-L56
33,027
orchestral/support
src/Support/Serializer.php
Serializer.resolveSerializerKey
protected function resolveSerializerKey($dataset): string { if ($dataset instanceof BaseCollection || $dataset instanceof Paginator) { return Str::plural($this->getKey()); } return $this->getKey(); }
php
protected function resolveSerializerKey($dataset): string { if ($dataset instanceof BaseCollection || $dataset instanceof Paginator) { return Str::plural($this->getKey()); } return $this->getKey(); }
[ "protected", "function", "resolveSerializerKey", "(", "$", "dataset", ")", ":", "string", "{", "if", "(", "$", "dataset", "instanceof", "BaseCollection", "||", "$", "dataset", "instanceof", "Paginator", ")", "{", "return", "Str", "::", "plural", "(", "$", "this", "->", "getKey", "(", ")", ")", ";", "}", "return", "$", "this", "->", "getKey", "(", ")", ";", "}" ]
Resolve serializer key. @param mixed $dataset @return string
[ "Resolve", "serializer", "key", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Serializer.php#L75-L82
33,028
doganoo/PHPUtil
src/Log/Logger.php
Logger.log
private static function log(string $message, int $level) { \Logger::configure(self::getConfiguration()); $logger = \Logger::getRootLogger(); $logger->setLevel(self::getLoggerLevel()); switch ($level) { case Logger::DEBUG: $logger->debug($message); break; case Logger::INFO: $logger->info($message); break; case Logger::WARN: $logger->warn($message); break; case Logger::ERROR: $logger->error($message); break; case Logger::FATAL: $logger->fatal($message); break; case Logger::TRACE: $logger->trace($message); break; default: } }
php
private static function log(string $message, int $level) { \Logger::configure(self::getConfiguration()); $logger = \Logger::getRootLogger(); $logger->setLevel(self::getLoggerLevel()); switch ($level) { case Logger::DEBUG: $logger->debug($message); break; case Logger::INFO: $logger->info($message); break; case Logger::WARN: $logger->warn($message); break; case Logger::ERROR: $logger->error($message); break; case Logger::FATAL: $logger->fatal($message); break; case Logger::TRACE: $logger->trace($message); break; default: } }
[ "private", "static", "function", "log", "(", "string", "$", "message", ",", "int", "$", "level", ")", "{", "\\", "Logger", "::", "configure", "(", "self", "::", "getConfiguration", "(", ")", ")", ";", "$", "logger", "=", "\\", "Logger", "::", "getRootLogger", "(", ")", ";", "$", "logger", "->", "setLevel", "(", "self", "::", "getLoggerLevel", "(", ")", ")", ";", "switch", "(", "$", "level", ")", "{", "case", "Logger", "::", "DEBUG", ":", "$", "logger", "->", "debug", "(", "$", "message", ")", ";", "break", ";", "case", "Logger", "::", "INFO", ":", "$", "logger", "->", "info", "(", "$", "message", ")", ";", "break", ";", "case", "Logger", "::", "WARN", ":", "$", "logger", "->", "warn", "(", "$", "message", ")", ";", "break", ";", "case", "Logger", "::", "ERROR", ":", "$", "logger", "->", "error", "(", "$", "message", ")", ";", "break", ";", "case", "Logger", "::", "FATAL", ":", "$", "logger", "->", "fatal", "(", "$", "message", ")", ";", "break", ";", "case", "Logger", "::", "TRACE", ":", "$", "logger", "->", "trace", "(", "$", "message", ")", ";", "break", ";", "default", ":", "}", "}" ]
logs a message to the console @param string $message @param int $level
[ "logs", "a", "message", "to", "the", "console" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Log/Logger.php#L136-L162
33,029
orchestral/support
src/Support/Concerns/Validation.php
Validation.bindToValidation
final public function bindToValidation(array $bindings): self { $this->validationBindings = \array_merge($this->validationBindings, $bindings); return $this; }
php
final public function bindToValidation(array $bindings): self { $this->validationBindings = \array_merge($this->validationBindings, $bindings); return $this; }
[ "final", "public", "function", "bindToValidation", "(", "array", "$", "bindings", ")", ":", "self", "{", "$", "this", "->", "validationBindings", "=", "\\", "array_merge", "(", "$", "this", "->", "validationBindings", ",", "$", "bindings", ")", ";", "return", "$", "this", ";", "}" ]
Add bindings. @param array $bindings @return $this
[ "Add", "bindings", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Concerns/Validation.php#L63-L68
33,030
orchestral/support
src/Support/Concerns/Validation.php
Validation.getBindedRules
protected function getBindedRules(): array { $rules = $this->getValidationRules(); if (! empty($this->validationBindings)) { foreach ($rules as $key => $value) { $rules[$key] = Str::replace($value, $this->validationBindings); } } return $rules; }
php
protected function getBindedRules(): array { $rules = $this->getValidationRules(); if (! empty($this->validationBindings)) { foreach ($rules as $key => $value) { $rules[$key] = Str::replace($value, $this->validationBindings); } } return $rules; }
[ "protected", "function", "getBindedRules", "(", ")", ":", "array", "{", "$", "rules", "=", "$", "this", "->", "getValidationRules", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "validationBindings", ")", ")", "{", "foreach", "(", "$", "rules", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "rules", "[", "$", "key", "]", "=", "Str", "::", "replace", "(", "$", "value", ",", "$", "this", "->", "validationBindings", ")", ";", "}", "}", "return", "$", "rules", ";", "}" ]
Run rules bindings. @return array
[ "Run", "rules", "bindings", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Concerns/Validation.php#L99-L110
33,031
byjg/restserver
src/HttpRequest.php
HttpRequest.request
public function request($value) { if (!isset($this->request[$value])) { return false; } else { return $this->request[$value]; } }
php
public function request($value) { if (!isset($this->request[$value])) { return false; } else { return $this->request[$value]; } }
[ "public", "function", "request", "(", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "request", "[", "$", "value", "]", ")", ")", "{", "return", "false", ";", "}", "else", "{", "return", "$", "this", "->", "request", "[", "$", "value", "]", ";", "}", "}" ]
Get a value from any of get, post, server, cookie or session. If not found return false. @param string $value @return string|boolean
[ "Get", "a", "value", "from", "any", "of", "get", "post", "server", "cookie", "or", "session", ".", "If", "not", "found", "return", "false", "." ]
1fdbd58f414f5d9958de0873d67eea961dc52fda
https://github.com/byjg/restserver/blob/1fdbd58f414f5d9958de0873d67eea961dc52fda/src/HttpRequest.php#L115-L122
33,032
byjg/restserver
src/HttpRequest.php
HttpRequest.getRequestIp
public function getRequestIp() { $headers = [ 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', ]; foreach ($headers as $header) { if ($this->server($header) !== false) { return $this->server($header); } } return 'UNKNOWN'; }
php
public function getRequestIp() { $headers = [ 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', ]; foreach ($headers as $header) { if ($this->server($header) !== false) { return $this->server($header); } } return 'UNKNOWN'; }
[ "public", "function", "getRequestIp", "(", ")", "{", "$", "headers", "=", "[", "'HTTP_CLIENT_IP'", ",", "'HTTP_X_FORWARDED_FOR'", ",", "'HTTP_X_FORWARDED'", ",", "'HTTP_FORWARDED_FOR'", ",", "'HTTP_FORWARDED'", ",", "'REMOTE_ADDR'", ",", "]", ";", "foreach", "(", "$", "headers", "as", "$", "header", ")", "{", "if", "(", "$", "this", "->", "server", "(", "$", "header", ")", "!==", "false", ")", "{", "return", "$", "this", "->", "server", "(", "$", "header", ")", ";", "}", "}", "return", "'UNKNOWN'", ";", "}" ]
Use this method to get the CLIENT REQUEST IP. Note that if you behing a Proxy, the variable REMOTE_ADDR will always have the same IP @return string
[ "Use", "this", "method", "to", "get", "the", "CLIENT", "REQUEST", "IP", ".", "Note", "that", "if", "you", "behing", "a", "Proxy", "the", "variable", "REMOTE_ADDR", "will", "always", "have", "the", "same", "IP" ]
1fdbd58f414f5d9958de0873d67eea961dc52fda
https://github.com/byjg/restserver/blob/1fdbd58f414f5d9958de0873d67eea961dc52fda/src/HttpRequest.php#L145-L162
33,033
hiqdev/hipanel-rbac
src/SetterTrait.php
SetterTrait.setPermission
public function setPermission($name, $description = null) { $permission = $this->getPermission($name) ?: $this->createPermission($name); if ($description) { $permission->description = $description; } $this->add($permission); return $permission; }
php
public function setPermission($name, $description = null) { $permission = $this->getPermission($name) ?: $this->createPermission($name); if ($description) { $permission->description = $description; } $this->add($permission); return $permission; }
[ "public", "function", "setPermission", "(", "$", "name", ",", "$", "description", "=", "null", ")", "{", "$", "permission", "=", "$", "this", "->", "getPermission", "(", "$", "name", ")", "?", ":", "$", "this", "->", "createPermission", "(", "$", "name", ")", ";", "if", "(", "$", "description", ")", "{", "$", "permission", "->", "description", "=", "$", "description", ";", "}", "$", "this", "->", "add", "(", "$", "permission", ")", ";", "return", "$", "permission", ";", "}" ]
Set permission. @param string $name @param string $description @return Item
[ "Set", "permission", "." ]
8fb14f035db3eb7b87bf6c0bcd894535097f14ef
https://github.com/hiqdev/hipanel-rbac/blob/8fb14f035db3eb7b87bf6c0bcd894535097f14ef/src/SetterTrait.php#L31-L40
33,034
hiqdev/hipanel-rbac
src/SetterTrait.php
SetterTrait.setRole
public function setRole($name, $description = null) { $role = $this->getRole($name) ?: $this->createRole($name); if ($description) { $role->description = $description; } $this->add($role); return $role; }
php
public function setRole($name, $description = null) { $role = $this->getRole($name) ?: $this->createRole($name); if ($description) { $role->description = $description; } $this->add($role); return $role; }
[ "public", "function", "setRole", "(", "$", "name", ",", "$", "description", "=", "null", ")", "{", "$", "role", "=", "$", "this", "->", "getRole", "(", "$", "name", ")", "?", ":", "$", "this", "->", "createRole", "(", "$", "name", ")", ";", "if", "(", "$", "description", ")", "{", "$", "role", "->", "description", "=", "$", "description", ";", "}", "$", "this", "->", "add", "(", "$", "role", ")", ";", "return", "$", "role", ";", "}" ]
Set role. @param string $name @param string $description @return Item
[ "Set", "role", "." ]
8fb14f035db3eb7b87bf6c0bcd894535097f14ef
https://github.com/hiqdev/hipanel-rbac/blob/8fb14f035db3eb7b87bf6c0bcd894535097f14ef/src/SetterTrait.php#L48-L57
33,035
hiqdev/hipanel-rbac
src/SetterTrait.php
SetterTrait.setChild
public function setChild($parent, $child) { if (is_string($parent)) { $name = $parent; $parent = $this->getItem($parent); if (is_null($parent)) { throw new Exception("Unknown parent:$name at setChild"); } } if (is_string($child)) { $name = $child; $child = $this->getItem($child); if (is_null($child)) { throw new Exception("Unknown child:$name at setChild"); } } if (isset($this->children[$parent->name][$child->name])) { return false; } return $this->addChild($parent, $child); }
php
public function setChild($parent, $child) { if (is_string($parent)) { $name = $parent; $parent = $this->getItem($parent); if (is_null($parent)) { throw new Exception("Unknown parent:$name at setChild"); } } if (is_string($child)) { $name = $child; $child = $this->getItem($child); if (is_null($child)) { throw new Exception("Unknown child:$name at setChild"); } } if (isset($this->children[$parent->name][$child->name])) { return false; } return $this->addChild($parent, $child); }
[ "public", "function", "setChild", "(", "$", "parent", ",", "$", "child", ")", "{", "if", "(", "is_string", "(", "$", "parent", ")", ")", "{", "$", "name", "=", "$", "parent", ";", "$", "parent", "=", "$", "this", "->", "getItem", "(", "$", "parent", ")", ";", "if", "(", "is_null", "(", "$", "parent", ")", ")", "{", "throw", "new", "Exception", "(", "\"Unknown parent:$name at setChild\"", ")", ";", "}", "}", "if", "(", "is_string", "(", "$", "child", ")", ")", "{", "$", "name", "=", "$", "child", ";", "$", "child", "=", "$", "this", "->", "getItem", "(", "$", "child", ")", ";", "if", "(", "is_null", "(", "$", "child", ")", ")", "{", "throw", "new", "Exception", "(", "\"Unknown child:$name at setChild\"", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "children", "[", "$", "parent", "->", "name", "]", "[", "$", "child", "->", "name", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "addChild", "(", "$", "parent", ",", "$", "child", ")", ";", "}" ]
Set child. @param string|Item $parent @param string|Item $child @return bool
[ "Set", "child", "." ]
8fb14f035db3eb7b87bf6c0bcd894535097f14ef
https://github.com/hiqdev/hipanel-rbac/blob/8fb14f035db3eb7b87bf6c0bcd894535097f14ef/src/SetterTrait.php#L65-L86
33,036
hiqdev/hipanel-rbac
src/SetterTrait.php
SetterTrait.setAssignments
public function setAssignments($items, $userId) { if (is_string($items)) { $items = explode(',', $items); } foreach ($items as $item) { $this->setAssignment($item, $userId); } }
php
public function setAssignments($items, $userId) { if (is_string($items)) { $items = explode(',', $items); } foreach ($items as $item) { $this->setAssignment($item, $userId); } }
[ "public", "function", "setAssignments", "(", "$", "items", ",", "$", "userId", ")", "{", "if", "(", "is_string", "(", "$", "items", ")", ")", "{", "$", "items", "=", "explode", "(", "','", ",", "$", "items", ")", ";", "}", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "this", "->", "setAssignment", "(", "$", "item", ",", "$", "userId", ")", ";", "}", "}" ]
Assigns items to a user. @param string|array $items @param string|integer $userId
[ "Assigns", "items", "to", "a", "user", "." ]
8fb14f035db3eb7b87bf6c0bcd894535097f14ef
https://github.com/hiqdev/hipanel-rbac/blob/8fb14f035db3eb7b87bf6c0bcd894535097f14ef/src/SetterTrait.php#L132-L140
33,037
orchestral/support
src/Support/Concerns/Uploadable.php
Uploadable.getUploadedFilename
protected function getUploadedFilename(UploadedFile $file): string { $extension = $file->getClientOriginalExtension(); return \sprintf('%s.%s', Str::random(10), $extension); }
php
protected function getUploadedFilename(UploadedFile $file): string { $extension = $file->getClientOriginalExtension(); return \sprintf('%s.%s', Str::random(10), $extension); }
[ "protected", "function", "getUploadedFilename", "(", "UploadedFile", "$", "file", ")", ":", "string", "{", "$", "extension", "=", "$", "file", "->", "getClientOriginalExtension", "(", ")", ";", "return", "\\", "sprintf", "(", "'%s.%s'", ",", "Str", "::", "random", "(", "10", ")", ",", "$", "extension", ")", ";", "}" ]
Get uploaded filename. @param \Symfony\Component\HttpFoundation\File\UploadedFile $file @return string
[ "Get", "uploaded", "filename", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Concerns/Uploadable.php#L45-L50
33,038
anomalylabs/variables-module
src/Variable/VariableRepository.php
VariableRepository.presenter
public function presenter($group, $field) { if (!$group = $this->group($group)) { return null; } return (new Decorator())->decorate($group)->{$field}; }
php
public function presenter($group, $field) { if (!$group = $this->group($group)) { return null; } return (new Decorator())->decorate($group)->{$field}; }
[ "public", "function", "presenter", "(", "$", "group", ",", "$", "field", ")", "{", "if", "(", "!", "$", "group", "=", "$", "this", "->", "group", "(", "$", "group", ")", ")", "{", "return", "null", ";", "}", "return", "(", "new", "Decorator", "(", ")", ")", "->", "decorate", "(", "$", "group", ")", "->", "{", "$", "field", "}", ";", "}" ]
Get a variable presenter. @param $group @param $field @return FieldTypePresenter|null
[ "Get", "a", "variable", "presenter", "." ]
bcd903670471a175f07aba3123693cb3a3c07d0b
https://github.com/anomalylabs/variables-module/blob/bcd903670471a175f07aba3123693cb3a3c07d0b/src/Variable/VariableRepository.php#L61-L68
33,039
hiqdev/hipanel-module-domain
src/repositories/DomainTariffRepository.php
DomainTariffRepository.getTariff
public function getTariff() { if ($this->app->user->isGuest) { $seller = $this->app->user->seller; $client_id = null; } else { $seller = $this->app->user->identity->seller; $client_id = $this->app->user->id; } return $this->app->get('cache')->getOrSet([__METHOD__, $seller, $client_id], function () use ($seller, $client_id) { $res = Tariff::find() ->action('get-available-info') ->joinWith('resources') ->andFilterWhere(['type' => 'domain']) ->andFilterWhere(['seller' => $seller]) ->andWhere(['with_resources' => true]) ->all(); if (is_array($res) && !empty($res)) { return reset($res); } return null; }, 3600); }
php
public function getTariff() { if ($this->app->user->isGuest) { $seller = $this->app->user->seller; $client_id = null; } else { $seller = $this->app->user->identity->seller; $client_id = $this->app->user->id; } return $this->app->get('cache')->getOrSet([__METHOD__, $seller, $client_id], function () use ($seller, $client_id) { $res = Tariff::find() ->action('get-available-info') ->joinWith('resources') ->andFilterWhere(['type' => 'domain']) ->andFilterWhere(['seller' => $seller]) ->andWhere(['with_resources' => true]) ->all(); if (is_array($res) && !empty($res)) { return reset($res); } return null; }, 3600); }
[ "public", "function", "getTariff", "(", ")", "{", "if", "(", "$", "this", "->", "app", "->", "user", "->", "isGuest", ")", "{", "$", "seller", "=", "$", "this", "->", "app", "->", "user", "->", "seller", ";", "$", "client_id", "=", "null", ";", "}", "else", "{", "$", "seller", "=", "$", "this", "->", "app", "->", "user", "->", "identity", "->", "seller", ";", "$", "client_id", "=", "$", "this", "->", "app", "->", "user", "->", "id", ";", "}", "return", "$", "this", "->", "app", "->", "get", "(", "'cache'", ")", "->", "getOrSet", "(", "[", "__METHOD__", ",", "$", "seller", ",", "$", "client_id", "]", ",", "function", "(", ")", "use", "(", "$", "seller", ",", "$", "client_id", ")", "{", "$", "res", "=", "Tariff", "::", "find", "(", ")", "->", "action", "(", "'get-available-info'", ")", "->", "joinWith", "(", "'resources'", ")", "->", "andFilterWhere", "(", "[", "'type'", "=>", "'domain'", "]", ")", "->", "andFilterWhere", "(", "[", "'seller'", "=>", "$", "seller", "]", ")", "->", "andWhere", "(", "[", "'with_resources'", "=>", "true", "]", ")", "->", "all", "(", ")", ";", "if", "(", "is_array", "(", "$", "res", ")", "&&", "!", "empty", "(", "$", "res", ")", ")", "{", "return", "reset", "(", "$", "res", ")", ";", "}", "return", "null", ";", "}", ",", "3600", ")", ";", "}" ]
Returns the tariff for the domain operations Caches the API request for 3600 seconds and depends on client id and seller login. @return Tariff|null The domain tariff or boolean `false` when no tariff was found
[ "Returns", "the", "tariff", "for", "the", "domain", "operations", "Caches", "the", "API", "request", "for", "3600", "seconds", "and", "depends", "on", "client", "id", "and", "seller", "login", "." ]
b1b02782fcb69970cacafe6c6ead238b14b54209
https://github.com/hiqdev/hipanel-module-domain/blob/b1b02782fcb69970cacafe6c6ead238b14b54209/src/repositories/DomainTariffRepository.php#L33-L58
33,040
QoboLtd/qobo-robo
src/Command/Mysql/Schema.php
Schema.mysqlSchema
public function mysqlSchema($db, $file = 'etc/mysql.sql', $user = 'root', $pass = null, $host = null, $port = null, $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskMysqlSchema() ->db($db) ->file($file) ->user($user) ->pass($pass) ->host($host) ->port($port) ->hide($pass) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
php
public function mysqlSchema($db, $file = 'etc/mysql.sql', $user = 'root', $pass = null, $host = null, $port = null, $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskMysqlSchema() ->db($db) ->file($file) ->user($user) ->pass($pass) ->host($host) ->port($port) ->hide($pass) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
[ "public", "function", "mysqlSchema", "(", "$", "db", ",", "$", "file", "=", "'etc/mysql.sql'", ",", "$", "user", "=", "'root'", ",", "$", "pass", "=", "null", ",", "$", "host", "=", "null", ",", "$", "port", "=", "null", ",", "$", "opts", "=", "[", "'format'", "=>", "'table'", ",", "'fields'", "=>", "''", "]", ")", "{", "$", "result", "=", "$", "this", "->", "taskMysqlSchema", "(", ")", "->", "db", "(", "$", "db", ")", "->", "file", "(", "$", "file", ")", "->", "user", "(", "$", "user", ")", "->", "pass", "(", "$", "pass", ")", "->", "host", "(", "$", "host", ")", "->", "port", "(", "$", "port", ")", "->", "hide", "(", "$", "pass", ")", "->", "run", "(", ")", ";", "if", "(", "!", "$", "result", "->", "wasSuccessful", "(", ")", ")", "{", "$", "this", "->", "exitError", "(", "\"Failed to run command\"", ")", ";", "}", "return", "true", ";", "}" ]
Dump mysql database schema @param string $db Database name @param string $file Destination file for a dump @param string $user MySQL user to bind with @param string $pass (Optional) MySQL user password @param string $host (Optional) MySQL server host @param string $port (Optional) MySQL server port @option string $format Output format (table, list, csv, json, xml) @option string $fields Limit output to given fields, comma-separated @return PropertyList result
[ "Dump", "mysql", "database", "schema" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Command/Mysql/Schema.php#L33-L50
33,041
QoboLtd/qobo-robo
src/AbstractCmdTask.php
AbstractCmdTask.checkPath
public static function checkPath($path) { if (!is_string($path)) { throw new InvalidArgumentException(sprintf("String expected as path, got '%s' instead", gettype($path))); } if (!file_exists($path)) { throw new InvalidArgumentException(sprintf("'%s' does not exist", $path)); } if (!is_dir($path)) { throw new InvalidArgumentException(sprintf("'%s' is not a directory", $path)); } if (!is_readable($path)) { throw new InvalidArgumentException(sprintf("'%s' is not readable", $path)); } return true; }
php
public static function checkPath($path) { if (!is_string($path)) { throw new InvalidArgumentException(sprintf("String expected as path, got '%s' instead", gettype($path))); } if (!file_exists($path)) { throw new InvalidArgumentException(sprintf("'%s' does not exist", $path)); } if (!is_dir($path)) { throw new InvalidArgumentException(sprintf("'%s' is not a directory", $path)); } if (!is_readable($path)) { throw new InvalidArgumentException(sprintf("'%s' is not readable", $path)); } return true; }
[ "public", "static", "function", "checkPath", "(", "$", "path", ")", "{", "if", "(", "!", "is_string", "(", "$", "path", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"String expected as path, got '%s' instead\"", ",", "gettype", "(", "$", "path", ")", ")", ")", ";", "}", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"'%s' does not exist\"", ",", "$", "path", ")", ")", ";", "}", "if", "(", "!", "is_dir", "(", "$", "path", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"'%s' is not a directory\"", ",", "$", "path", ")", ")", ";", "}", "if", "(", "!", "is_readable", "(", "$", "path", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"'%s' is not readable\"", ",", "$", "path", ")", ")", ";", "}", "return", "true", ";", "}" ]
Check if path is readable
[ "Check", "if", "path", "is", "readable" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/AbstractCmdTask.php#L130-L148
33,042
QoboLtd/qobo-robo
src/AbstractCmdTask.php
AbstractCmdTask.checkCmd
public static function checkCmd($cmd) { // cut out the actual executable part only // and leave args away $cmdParts = preg_split("/\s+/", $cmd); $cmd = $cmdParts[0]; // try to find a command if not absolute path is given if (!preg_match('/^\.?\/.*$/', $cmd)) { $retval = null; $ouput = []; $fullCmd = exec("which $cmd", $output, $retval); if ($retval) { throw new InvalidArgumentException(sprintf("Failed to find full path for '%s'", $cmd)); } $cmd = trim($fullCmd); } if (!file_exists($cmd)) { throw new InvalidArgumentException(sprintf("'%s' does not exist", $cmd)); } if (!is_file($cmd)) { throw new InvalidArgumentException(sprintf("'%s' is not a file", $cmd)); } if (!is_executable($cmd)) { throw new InvalidArgumentException(sprintf("'%s' is not executable", $cmd)); } return true; }
php
public static function checkCmd($cmd) { // cut out the actual executable part only // and leave args away $cmdParts = preg_split("/\s+/", $cmd); $cmd = $cmdParts[0]; // try to find a command if not absolute path is given if (!preg_match('/^\.?\/.*$/', $cmd)) { $retval = null; $ouput = []; $fullCmd = exec("which $cmd", $output, $retval); if ($retval) { throw new InvalidArgumentException(sprintf("Failed to find full path for '%s'", $cmd)); } $cmd = trim($fullCmd); } if (!file_exists($cmd)) { throw new InvalidArgumentException(sprintf("'%s' does not exist", $cmd)); } if (!is_file($cmd)) { throw new InvalidArgumentException(sprintf("'%s' is not a file", $cmd)); } if (!is_executable($cmd)) { throw new InvalidArgumentException(sprintf("'%s' is not executable", $cmd)); } return true; }
[ "public", "static", "function", "checkCmd", "(", "$", "cmd", ")", "{", "// cut out the actual executable part only", "// and leave args away", "$", "cmdParts", "=", "preg_split", "(", "\"/\\s+/\"", ",", "$", "cmd", ")", ";", "$", "cmd", "=", "$", "cmdParts", "[", "0", "]", ";", "// try to find a command if not absolute path is given", "if", "(", "!", "preg_match", "(", "'/^\\.?\\/.*$/'", ",", "$", "cmd", ")", ")", "{", "$", "retval", "=", "null", ";", "$", "ouput", "=", "[", "]", ";", "$", "fullCmd", "=", "exec", "(", "\"which $cmd\"", ",", "$", "output", ",", "$", "retval", ")", ";", "if", "(", "$", "retval", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"Failed to find full path for '%s'\"", ",", "$", "cmd", ")", ")", ";", "}", "$", "cmd", "=", "trim", "(", "$", "fullCmd", ")", ";", "}", "if", "(", "!", "file_exists", "(", "$", "cmd", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"'%s' does not exist\"", ",", "$", "cmd", ")", ")", ";", "}", "if", "(", "!", "is_file", "(", "$", "cmd", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"'%s' is not a file\"", ",", "$", "cmd", ")", ")", ";", "}", "if", "(", "!", "is_executable", "(", "$", "cmd", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"'%s' is not executable\"", ",", "$", "cmd", ")", ")", ";", "}", "return", "true", ";", "}" ]
Check if cmd exists and is an executable file
[ "Check", "if", "cmd", "exists", "and", "is", "an", "executable", "file" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/AbstractCmdTask.php#L153-L183
33,043
orchestral/support
src/Support/Nesty.php
Nesty.addParent
protected function addParent(string $id): Fluent { return $this->items[$id] = $this->toFluent($id); }
php
protected function addParent(string $id): Fluent { return $this->items[$id] = $this->toFluent($id); }
[ "protected", "function", "addParent", "(", "string", "$", "id", ")", ":", "Fluent", "{", "return", "$", "this", "->", "items", "[", "$", "id", "]", "=", "$", "this", "->", "toFluent", "(", "$", "id", ")", ";", "}" ]
Add item as parent. @param string $id @return \Orchestra\Support\Fluent
[ "Add", "item", "as", "parent", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Nesty.php#L149-L152
33,044
anomalylabs/variables-module
src/VariablesModulePlugin.php
VariablesModulePlugin.getFunctions
public function getFunctions() { return [ new \Twig_SimpleFunction( 'variable', function ($group, $field) { return $this->dispatch(new GetValuePresenter($group, $field)); } ), new \Twig_SimpleFunction( 'variable_value', function ($group, $field, $default = null) { return $this->dispatch(new GetVariableValue($group, $field, $default)); } ), new \Twig_SimpleFunction( 'variable_group', function ($group) { return (new Decorator())->decorate($this->dispatch(new GetVariableGroup($group))); } ), ]; }
php
public function getFunctions() { return [ new \Twig_SimpleFunction( 'variable', function ($group, $field) { return $this->dispatch(new GetValuePresenter($group, $field)); } ), new \Twig_SimpleFunction( 'variable_value', function ($group, $field, $default = null) { return $this->dispatch(new GetVariableValue($group, $field, $default)); } ), new \Twig_SimpleFunction( 'variable_group', function ($group) { return (new Decorator())->decorate($this->dispatch(new GetVariableGroup($group))); } ), ]; }
[ "public", "function", "getFunctions", "(", ")", "{", "return", "[", "new", "\\", "Twig_SimpleFunction", "(", "'variable'", ",", "function", "(", "$", "group", ",", "$", "field", ")", "{", "return", "$", "this", "->", "dispatch", "(", "new", "GetValuePresenter", "(", "$", "group", ",", "$", "field", ")", ")", ";", "}", ")", ",", "new", "\\", "Twig_SimpleFunction", "(", "'variable_value'", ",", "function", "(", "$", "group", ",", "$", "field", ",", "$", "default", "=", "null", ")", "{", "return", "$", "this", "->", "dispatch", "(", "new", "GetVariableValue", "(", "$", "group", ",", "$", "field", ",", "$", "default", ")", ")", ";", "}", ")", ",", "new", "\\", "Twig_SimpleFunction", "(", "'variable_group'", ",", "function", "(", "$", "group", ")", "{", "return", "(", "new", "Decorator", "(", ")", ")", "->", "decorate", "(", "$", "this", "->", "dispatch", "(", "new", "GetVariableGroup", "(", "$", "group", ")", ")", ")", ";", "}", ")", ",", "]", ";", "}" ]
Get the functions. @return array
[ "Get", "the", "functions", "." ]
bcd903670471a175f07aba3123693cb3a3c07d0b
https://github.com/anomalylabs/variables-module/blob/bcd903670471a175f07aba3123693cb3a3c07d0b/src/VariablesModulePlugin.php#L24-L46
33,045
nails/module-invoice
src/Factory/RequestBase.php
RequestBase.setDriver
public function setDriver($sDriverSlug) { // Validate the driver $aDrivers = $this->oDriverService->getEnabled(); $oDriver = null; foreach ($aDrivers as $oDriverConfig) { if ($oDriverConfig->slug == $sDriverSlug) { $oDriver = $this->oDriverService->getInstance($oDriverConfig->slug); break; } } if (empty($oDriver)) { throw new RequestException('"' . $sDriverSlug . '" is not a valid payment driver.'); } $this->oDriver = $oDriver; return $this; }
php
public function setDriver($sDriverSlug) { // Validate the driver $aDrivers = $this->oDriverService->getEnabled(); $oDriver = null; foreach ($aDrivers as $oDriverConfig) { if ($oDriverConfig->slug == $sDriverSlug) { $oDriver = $this->oDriverService->getInstance($oDriverConfig->slug); break; } } if (empty($oDriver)) { throw new RequestException('"' . $sDriverSlug . '" is not a valid payment driver.'); } $this->oDriver = $oDriver; return $this; }
[ "public", "function", "setDriver", "(", "$", "sDriverSlug", ")", "{", "// Validate the driver", "$", "aDrivers", "=", "$", "this", "->", "oDriverService", "->", "getEnabled", "(", ")", ";", "$", "oDriver", "=", "null", ";", "foreach", "(", "$", "aDrivers", "as", "$", "oDriverConfig", ")", "{", "if", "(", "$", "oDriverConfig", "->", "slug", "==", "$", "sDriverSlug", ")", "{", "$", "oDriver", "=", "$", "this", "->", "oDriverService", "->", "getInstance", "(", "$", "oDriverConfig", "->", "slug", ")", ";", "break", ";", "}", "}", "if", "(", "empty", "(", "$", "oDriver", ")", ")", "{", "throw", "new", "RequestException", "(", "'\"'", ".", "$", "sDriverSlug", ".", "'\" is not a valid payment driver.'", ")", ";", "}", "$", "this", "->", "oDriver", "=", "$", "oDriver", ";", "return", "$", "this", ";", "}" ]
Set the driver to be used for the request @param string $sDriverSlug The driver's slug @return $this @throws RequestException
[ "Set", "the", "driver", "to", "be", "used", "for", "the", "request" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/RequestBase.php#L52-L71
33,046
nails/module-invoice
src/Factory/RequestBase.php
RequestBase.setInvoice
public function setInvoice($iInvoiceId) { // Validate $oModel = $this->oInvoiceModel; $oInvoice = $oModel->getById( $iInvoiceId, ['expand' => $oModel::EXPAND_ALL] ); if (empty($oInvoice)) { throw new RequestException('Invalid invoice ID.'); } $this->oInvoice = $oInvoice; return $this; }
php
public function setInvoice($iInvoiceId) { // Validate $oModel = $this->oInvoiceModel; $oInvoice = $oModel->getById( $iInvoiceId, ['expand' => $oModel::EXPAND_ALL] ); if (empty($oInvoice)) { throw new RequestException('Invalid invoice ID.'); } $this->oInvoice = $oInvoice; return $this; }
[ "public", "function", "setInvoice", "(", "$", "iInvoiceId", ")", "{", "// Validate", "$", "oModel", "=", "$", "this", "->", "oInvoiceModel", ";", "$", "oInvoice", "=", "$", "oModel", "->", "getById", "(", "$", "iInvoiceId", ",", "[", "'expand'", "=>", "$", "oModel", "::", "EXPAND_ALL", "]", ")", ";", "if", "(", "empty", "(", "$", "oInvoice", ")", ")", "{", "throw", "new", "RequestException", "(", "'Invalid invoice ID.'", ")", ";", "}", "$", "this", "->", "oInvoice", "=", "$", "oInvoice", ";", "return", "$", "this", ";", "}" ]
Set the invoice object @param integer $iInvoiceId The invoice to use for the request @return $this @throws RequestException
[ "Set", "the", "invoice", "object" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/RequestBase.php#L83-L98
33,047
nails/module-invoice
src/Factory/RequestBase.php
RequestBase.setPayment
public function setPayment($iPaymentId) { // Validate $oPayment = $this->oPaymentModel->getById( $iPaymentId, ['expand' => ['invoice']] ); if (empty($oPayment)) { throw new RequestException('Invalid payment ID.'); } $this->oPayment = $oPayment; return $this; }
php
public function setPayment($iPaymentId) { // Validate $oPayment = $this->oPaymentModel->getById( $iPaymentId, ['expand' => ['invoice']] ); if (empty($oPayment)) { throw new RequestException('Invalid payment ID.'); } $this->oPayment = $oPayment; return $this; }
[ "public", "function", "setPayment", "(", "$", "iPaymentId", ")", "{", "// Validate", "$", "oPayment", "=", "$", "this", "->", "oPaymentModel", "->", "getById", "(", "$", "iPaymentId", ",", "[", "'expand'", "=>", "[", "'invoice'", "]", "]", ")", ";", "if", "(", "empty", "(", "$", "oPayment", ")", ")", "{", "throw", "new", "RequestException", "(", "'Invalid payment ID.'", ")", ";", "}", "$", "this", "->", "oPayment", "=", "$", "oPayment", ";", "return", "$", "this", ";", "}" ]
Set the payment object @param integer $iPaymentId The payment to use for the request @return $this @throws RequestException
[ "Set", "the", "payment", "object" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/RequestBase.php#L110-L124
33,048
nails/module-invoice
src/Factory/RequestBase.php
RequestBase.setRefund
public function setRefund($iRefundId) { // Validate $oRefund = $this->oRefundModel->getById($iRefundId); if (empty($oRefund)) { throw new RequestException('Invalid refund ID.'); } $this->oRefund = $oRefund; return $this; }
php
public function setRefund($iRefundId) { // Validate $oRefund = $this->oRefundModel->getById($iRefundId); if (empty($oRefund)) { throw new RequestException('Invalid refund ID.'); } $this->oRefund = $oRefund; return $this; }
[ "public", "function", "setRefund", "(", "$", "iRefundId", ")", "{", "// Validate", "$", "oRefund", "=", "$", "this", "->", "oRefundModel", "->", "getById", "(", "$", "iRefundId", ")", ";", "if", "(", "empty", "(", "$", "oRefund", ")", ")", "{", "throw", "new", "RequestException", "(", "'Invalid refund ID.'", ")", ";", "}", "$", "this", "->", "oRefund", "=", "$", "oRefund", ";", "return", "$", "this", ";", "}" ]
Set the refund object @param integer $iRefundId The refund to use for the request @return $this @throws RequestException
[ "Set", "the", "refund", "object" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/RequestBase.php#L136-L147
33,049
nails/module-invoice
src/Factory/RequestBase.php
RequestBase.setPaymentComplete
protected function setPaymentComplete($sTxnId = null, $iFee = null) { // Ensure we have a payment if (empty($this->oPayment)) { throw new RequestException('No payment selected.'); } // Ensure we have an invoice if (empty($this->oInvoice)) { throw new RequestException('No invoice selected.'); } // Update the payment $aData = ['txn_id' => $sTxnId ? $sTxnId : null]; if (!is_null($iFee)) { $aData['fee'] = $iFee; } if (!$this->oPaymentModel->setComplete($this->oPayment->id, $aData)) { throw new RequestException('Failed to update existing payment.'); } // Has the invoice been paid in full? If so, mark it as paid and fire the invoice.paid event if ($this->oInvoiceModel->isPaid($this->oInvoice->id)) { // Mark Invoice as PAID if (!$this->oInvoiceModel->setPaid($this->oInvoice->id)) { throw new RequestException('Failed to mark invoice as paid.'); } } // Send receipt email $this->oPaymentModel->sendReceipt($this->oPayment->id); return $this; }
php
protected function setPaymentComplete($sTxnId = null, $iFee = null) { // Ensure we have a payment if (empty($this->oPayment)) { throw new RequestException('No payment selected.'); } // Ensure we have an invoice if (empty($this->oInvoice)) { throw new RequestException('No invoice selected.'); } // Update the payment $aData = ['txn_id' => $sTxnId ? $sTxnId : null]; if (!is_null($iFee)) { $aData['fee'] = $iFee; } if (!$this->oPaymentModel->setComplete($this->oPayment->id, $aData)) { throw new RequestException('Failed to update existing payment.'); } // Has the invoice been paid in full? If so, mark it as paid and fire the invoice.paid event if ($this->oInvoiceModel->isPaid($this->oInvoice->id)) { // Mark Invoice as PAID if (!$this->oInvoiceModel->setPaid($this->oInvoice->id)) { throw new RequestException('Failed to mark invoice as paid.'); } } // Send receipt email $this->oPaymentModel->sendReceipt($this->oPayment->id); return $this; }
[ "protected", "function", "setPaymentComplete", "(", "$", "sTxnId", "=", "null", ",", "$", "iFee", "=", "null", ")", "{", "// Ensure we have a payment", "if", "(", "empty", "(", "$", "this", "->", "oPayment", ")", ")", "{", "throw", "new", "RequestException", "(", "'No payment selected.'", ")", ";", "}", "// Ensure we have an invoice", "if", "(", "empty", "(", "$", "this", "->", "oInvoice", ")", ")", "{", "throw", "new", "RequestException", "(", "'No invoice selected.'", ")", ";", "}", "// Update the payment", "$", "aData", "=", "[", "'txn_id'", "=>", "$", "sTxnId", "?", "$", "sTxnId", ":", "null", "]", ";", "if", "(", "!", "is_null", "(", "$", "iFee", ")", ")", "{", "$", "aData", "[", "'fee'", "]", "=", "$", "iFee", ";", "}", "if", "(", "!", "$", "this", "->", "oPaymentModel", "->", "setComplete", "(", "$", "this", "->", "oPayment", "->", "id", ",", "$", "aData", ")", ")", "{", "throw", "new", "RequestException", "(", "'Failed to update existing payment.'", ")", ";", "}", "// Has the invoice been paid in full? If so, mark it as paid and fire the invoice.paid event", "if", "(", "$", "this", "->", "oInvoiceModel", "->", "isPaid", "(", "$", "this", "->", "oInvoice", "->", "id", ")", ")", "{", "// Mark Invoice as PAID", "if", "(", "!", "$", "this", "->", "oInvoiceModel", "->", "setPaid", "(", "$", "this", "->", "oInvoice", "->", "id", ")", ")", "{", "throw", "new", "RequestException", "(", "'Failed to mark invoice as paid.'", ")", ";", "}", "}", "// Send receipt email", "$", "this", "->", "oPaymentModel", "->", "sendReceipt", "(", "$", "this", "->", "oPayment", "->", "id", ")", ";", "return", "$", "this", ";", "}" ]
Set a payment as COMPLETE, and mark the invoice as paid if so @param string $sTxnId The payment's transaction ID @param integer $iFee The fee charged by the processor, if known @return $this @throws RequestException
[ "Set", "a", "payment", "as", "COMPLETE", "and", "mark", "the", "invoice", "as", "paid", "if", "so" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/RequestBase.php#L203-L239
33,050
doganoo/PHPUtil
src/FileSystem/FileHandler.php
FileHandler.forceCreate
public function forceCreate(): bool { if (!$this->isFile()) { return \mkdir($this->path, 0744, true); } if ($this->isFile() && !$this->isWritable()) { $user = \get_current_user(); return \chown($this->path, $user); } return false; }
php
public function forceCreate(): bool { if (!$this->isFile()) { return \mkdir($this->path, 0744, true); } if ($this->isFile() && !$this->isWritable()) { $user = \get_current_user(); return \chown($this->path, $user); } return false; }
[ "public", "function", "forceCreate", "(", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "isFile", "(", ")", ")", "{", "return", "\\", "mkdir", "(", "$", "this", "->", "path", ",", "0744", ",", "true", ")", ";", "}", "if", "(", "$", "this", "->", "isFile", "(", ")", "&&", "!", "$", "this", "->", "isWritable", "(", ")", ")", "{", "$", "user", "=", "\\", "get_current_user", "(", ")", ";", "return", "\\", "chown", "(", "$", "this", "->", "path", ",", "$", "user", ")", ";", "}", "return", "false", ";", "}" ]
forces a file creation @return bool @deprecated Use create() instead
[ "forces", "a", "file", "creation" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/FileSystem/FileHandler.php#L111-L120
33,051
doganoo/PHPUtil
src/FileSystem/FileHandler.php
FileHandler.getContent
public function getContent(): ?string { if (null !== $this->content) return $this->content; if (!$this->isFile()) return null; $content = \file_get_contents($this->path); if (false === $content) return null; return $content; }
php
public function getContent(): ?string { if (null !== $this->content) return $this->content; if (!$this->isFile()) return null; $content = \file_get_contents($this->path); if (false === $content) return null; return $content; }
[ "public", "function", "getContent", "(", ")", ":", "?", "string", "{", "if", "(", "null", "!==", "$", "this", "->", "content", ")", "return", "$", "this", "->", "content", ";", "if", "(", "!", "$", "this", "->", "isFile", "(", ")", ")", "return", "null", ";", "$", "content", "=", "\\", "file_get_contents", "(", "$", "this", "->", "path", ")", ";", "if", "(", "false", "===", "$", "content", ")", "return", "null", ";", "return", "$", "content", ";", "}" ]
returns the file content if file is available. Otherwise null @return null|string
[ "returns", "the", "file", "content", "if", "file", "is", "available", ".", "Otherwise", "null" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/FileSystem/FileHandler.php#L136-L142
33,052
nails/module-invoice
src/Model/Invoice/Item.php
Item.getUnits
public function getUnits() { return [ self::UNIT_NONE => 'None', self::UNIT_MINUTE => 'Minutes', self::UNIT_HOUR => 'Hours', self::UNIT_DAY => 'Days', self::UNIT_WEEK => 'Weeks', self::UNIT_MONTH => 'Months', self::UNIT_YEAR => 'Years', ]; }
php
public function getUnits() { return [ self::UNIT_NONE => 'None', self::UNIT_MINUTE => 'Minutes', self::UNIT_HOUR => 'Hours', self::UNIT_DAY => 'Days', self::UNIT_WEEK => 'Weeks', self::UNIT_MONTH => 'Months', self::UNIT_YEAR => 'Years', ]; }
[ "public", "function", "getUnits", "(", ")", "{", "return", "[", "self", "::", "UNIT_NONE", "=>", "'None'", ",", "self", "::", "UNIT_MINUTE", "=>", "'Minutes'", ",", "self", "::", "UNIT_HOUR", "=>", "'Hours'", ",", "self", "::", "UNIT_DAY", "=>", "'Days'", ",", "self", "::", "UNIT_WEEK", "=>", "'Weeks'", ",", "self", "::", "UNIT_MONTH", "=>", "'Months'", ",", "self", "::", "UNIT_YEAR", "=>", "'Years'", ",", "]", ";", "}" ]
Returns the item quantity units with human friendly names @return array
[ "Returns", "the", "item", "quantity", "units", "with", "human", "friendly", "names" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Invoice/Item.php#L71-L82
33,053
doganoo/PHPUtil
src/Datatype/StringClass.php
StringClass.replace
public function replace($search, $value) { $this->value = str_replace($search, $value, $this->value); }
php
public function replace($search, $value) { $this->value = str_replace($search, $value, $this->value); }
[ "public", "function", "replace", "(", "$", "search", ",", "$", "value", ")", "{", "$", "this", "->", "value", "=", "str_replace", "(", "$", "search", ",", "$", "value", ",", "$", "this", "->", "value", ")", ";", "}" ]
replaces search by value @param $search @param $value
[ "replaces", "search", "by", "value" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Datatype/StringClass.php#L129-L131
33,054
doganoo/PHPUtil
src/Datatype/StringClass.php
StringClass.replaceIgnoreCase
public function replaceIgnoreCase($search, $value) { $this->value = str_ireplace($search, $value, $this->value); }
php
public function replaceIgnoreCase($search, $value) { $this->value = str_ireplace($search, $value, $this->value); }
[ "public", "function", "replaceIgnoreCase", "(", "$", "search", ",", "$", "value", ")", "{", "$", "this", "->", "value", "=", "str_ireplace", "(", "$", "search", ",", "$", "value", ",", "$", "this", "->", "value", ")", ";", "}" ]
replaces search by value and is case insensitive @param $search @param $value
[ "replaces", "search", "by", "value", "and", "is", "case", "insensitive" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Datatype/StringClass.php#L139-L141
33,055
doganoo/PHPUtil
src/Datatype/StringClass.php
StringClass.hasPrefix
public function hasPrefix(string $prefix):bool { if (0 !== $this->getLength() && "" === $prefix) return false; return true === (substr( $this->getValue(), 0, strlen($prefix)) === $prefix); }
php
public function hasPrefix(string $prefix):bool { if (0 !== $this->getLength() && "" === $prefix) return false; return true === (substr( $this->getValue(), 0, strlen($prefix)) === $prefix); }
[ "public", "function", "hasPrefix", "(", "string", "$", "prefix", ")", ":", "bool", "{", "if", "(", "0", "!==", "$", "this", "->", "getLength", "(", ")", "&&", "\"\"", "===", "$", "prefix", ")", "return", "false", ";", "return", "true", "===", "(", "substr", "(", "$", "this", "->", "getValue", "(", ")", ",", "0", ",", "strlen", "(", "$", "prefix", ")", ")", "===", "$", "prefix", ")", ";", "}" ]
checks a prefix have a look here: https://stackoverflow.com/a/2790919 @param string $prefix @return bool
[ "checks", "a", "prefix" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Datatype/StringClass.php#L198-L201
33,056
doganoo/PHPUtil
src/Datatype/StringClass.php
StringClass.hasSuffix
public function hasSuffix(string $suffix):bool { if (0 !== $this->getLength() && "" === $suffix) return false; return (substr($this->getValue(), -1 * strlen($suffix), strlen($suffix)) === $suffix); }
php
public function hasSuffix(string $suffix):bool { if (0 !== $this->getLength() && "" === $suffix) return false; return (substr($this->getValue(), -1 * strlen($suffix), strlen($suffix)) === $suffix); }
[ "public", "function", "hasSuffix", "(", "string", "$", "suffix", ")", ":", "bool", "{", "if", "(", "0", "!==", "$", "this", "->", "getLength", "(", ")", "&&", "\"\"", "===", "$", "suffix", ")", "return", "false", ";", "return", "(", "substr", "(", "$", "this", "->", "getValue", "(", ")", ",", "-", "1", "*", "strlen", "(", "$", "suffix", ")", ",", "strlen", "(", "$", "suffix", ")", ")", "===", "$", "suffix", ")", ";", "}" ]
checks a suffix @param string $suffix @return bool
[ "checks", "a", "suffix" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Datatype/StringClass.php#L209-L212
33,057
nails/module-invoice
invoice/controllers/Invoice.php
Invoice.download
protected function download($oInvoice) { // Business details $this->data['business'] = (object) [ 'name' => appSetting('business_name', 'nails/module-invoice'), 'address' => appSetting('business_address', 'nails/module-invoice'), 'telephone' => appSetting('business_telephone', 'nails/module-invoice'), 'email' => appSetting('business_email', 'nails/module-invoice'), 'vat_number' => appSetting('business_vat_number', 'nails/module-invoice'), ]; $oInvoiceSkinService = Factory::service('InvoiceSkin', 'nails/module-invoice'); $sEnabledSkin = $oInvoiceSkinService->getEnabledSlug() ?: self::DEFAULT_INVOICE_SKIN; $this->data['invoice'] = $oInvoice; $this->data['isPdf'] = true; $sHtml = $oInvoiceSkinService->view($sEnabledSkin, 'render', $this->data, true); $oPdf = Factory::service('Pdf', 'nails/module-pdf'); $oPdf->setPaperSize('A4', 'portrait'); $oPdf->load_html($sHtml); $oPdf->download('INVOICE-' . $oInvoice->ref . '.pdf'); }
php
protected function download($oInvoice) { // Business details $this->data['business'] = (object) [ 'name' => appSetting('business_name', 'nails/module-invoice'), 'address' => appSetting('business_address', 'nails/module-invoice'), 'telephone' => appSetting('business_telephone', 'nails/module-invoice'), 'email' => appSetting('business_email', 'nails/module-invoice'), 'vat_number' => appSetting('business_vat_number', 'nails/module-invoice'), ]; $oInvoiceSkinService = Factory::service('InvoiceSkin', 'nails/module-invoice'); $sEnabledSkin = $oInvoiceSkinService->getEnabledSlug() ?: self::DEFAULT_INVOICE_SKIN; $this->data['invoice'] = $oInvoice; $this->data['isPdf'] = true; $sHtml = $oInvoiceSkinService->view($sEnabledSkin, 'render', $this->data, true); $oPdf = Factory::service('Pdf', 'nails/module-pdf'); $oPdf->setPaperSize('A4', 'portrait'); $oPdf->load_html($sHtml); $oPdf->download('INVOICE-' . $oInvoice->ref . '.pdf'); }
[ "protected", "function", "download", "(", "$", "oInvoice", ")", "{", "// Business details", "$", "this", "->", "data", "[", "'business'", "]", "=", "(", "object", ")", "[", "'name'", "=>", "appSetting", "(", "'business_name'", ",", "'nails/module-invoice'", ")", ",", "'address'", "=>", "appSetting", "(", "'business_address'", ",", "'nails/module-invoice'", ")", ",", "'telephone'", "=>", "appSetting", "(", "'business_telephone'", ",", "'nails/module-invoice'", ")", ",", "'email'", "=>", "appSetting", "(", "'business_email'", ",", "'nails/module-invoice'", ")", ",", "'vat_number'", "=>", "appSetting", "(", "'business_vat_number'", ",", "'nails/module-invoice'", ")", ",", "]", ";", "$", "oInvoiceSkinService", "=", "Factory", "::", "service", "(", "'InvoiceSkin'", ",", "'nails/module-invoice'", ")", ";", "$", "sEnabledSkin", "=", "$", "oInvoiceSkinService", "->", "getEnabledSlug", "(", ")", "?", ":", "self", "::", "DEFAULT_INVOICE_SKIN", ";", "$", "this", "->", "data", "[", "'invoice'", "]", "=", "$", "oInvoice", ";", "$", "this", "->", "data", "[", "'isPdf'", "]", "=", "true", ";", "$", "sHtml", "=", "$", "oInvoiceSkinService", "->", "view", "(", "$", "sEnabledSkin", ",", "'render'", ",", "$", "this", "->", "data", ",", "true", ")", ";", "$", "oPdf", "=", "Factory", "::", "service", "(", "'Pdf'", ",", "'nails/module-pdf'", ")", ";", "$", "oPdf", "->", "setPaperSize", "(", "'A4'", ",", "'portrait'", ")", ";", "$", "oPdf", "->", "load_html", "(", "$", "sHtml", ")", ";", "$", "oPdf", "->", "download", "(", "'INVOICE-'", ".", "$", "oInvoice", "->", "ref", ".", "'.pdf'", ")", ";", "}" ]
Download a single invoice @param \stdClass $oInvoice The invoice object @return void
[ "Download", "a", "single", "invoice" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/invoice/controllers/Invoice.php#L36-L58
33,058
nails/module-invoice
invoice/controllers/Invoice.php
Invoice.view
protected function view($oInvoice) { // Business details $this->data['business'] = (object) [ 'name' => appSetting('business_name', 'nails/module-invoice'), 'address' => appSetting('business_address', 'nails/module-invoice'), 'telephone' => appSetting('business_telephone', 'nails/module-invoice'), 'email' => appSetting('business_email', 'nails/module-invoice'), 'vat_number' => appSetting('business_vat_number', 'nails/module-invoice'), ]; $oInvoiceSkinService = Factory::service('InvoiceSkin', 'nails/module-invoice'); $sEnabledSkin = $oInvoiceSkinService->getEnabledSlug() ?: self::DEFAULT_INVOICE_SKIN; $this->data['invoice'] = $oInvoice; $this->data['isPdf'] = false; $oInvoiceSkinService->view($sEnabledSkin, 'render', $this->data); }
php
protected function view($oInvoice) { // Business details $this->data['business'] = (object) [ 'name' => appSetting('business_name', 'nails/module-invoice'), 'address' => appSetting('business_address', 'nails/module-invoice'), 'telephone' => appSetting('business_telephone', 'nails/module-invoice'), 'email' => appSetting('business_email', 'nails/module-invoice'), 'vat_number' => appSetting('business_vat_number', 'nails/module-invoice'), ]; $oInvoiceSkinService = Factory::service('InvoiceSkin', 'nails/module-invoice'); $sEnabledSkin = $oInvoiceSkinService->getEnabledSlug() ?: self::DEFAULT_INVOICE_SKIN; $this->data['invoice'] = $oInvoice; $this->data['isPdf'] = false; $oInvoiceSkinService->view($sEnabledSkin, 'render', $this->data); }
[ "protected", "function", "view", "(", "$", "oInvoice", ")", "{", "// Business details", "$", "this", "->", "data", "[", "'business'", "]", "=", "(", "object", ")", "[", "'name'", "=>", "appSetting", "(", "'business_name'", ",", "'nails/module-invoice'", ")", ",", "'address'", "=>", "appSetting", "(", "'business_address'", ",", "'nails/module-invoice'", ")", ",", "'telephone'", "=>", "appSetting", "(", "'business_telephone'", ",", "'nails/module-invoice'", ")", ",", "'email'", "=>", "appSetting", "(", "'business_email'", ",", "'nails/module-invoice'", ")", ",", "'vat_number'", "=>", "appSetting", "(", "'business_vat_number'", ",", "'nails/module-invoice'", ")", ",", "]", ";", "$", "oInvoiceSkinService", "=", "Factory", "::", "service", "(", "'InvoiceSkin'", ",", "'nails/module-invoice'", ")", ";", "$", "sEnabledSkin", "=", "$", "oInvoiceSkinService", "->", "getEnabledSlug", "(", ")", "?", ":", "self", "::", "DEFAULT_INVOICE_SKIN", ";", "$", "this", "->", "data", "[", "'invoice'", "]", "=", "$", "oInvoice", ";", "$", "this", "->", "data", "[", "'isPdf'", "]", "=", "false", ";", "$", "oInvoiceSkinService", "->", "view", "(", "$", "sEnabledSkin", ",", "'render'", ",", "$", "this", "->", "data", ")", ";", "}" ]
View a single invoice @param \stdClass $oInvoice The invoice object @return void
[ "View", "a", "single", "invoice" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/invoice/controllers/Invoice.php#L69-L86
33,059
QoboLtd/qobo-robo
src/DataAwareTrait.php
DataAwareTrait.setData
public function setData($name, $value) { if (!isset($this->data)) { throw new RuntimeException("Data property is required for DataAwareTrait to work"); } // we use snake_case field keys // but camelCase setters $name = $this->decamelize($name); // only set values for predefined data keys if (array_key_exists($name, $this->data)) { $this->data[$name] = $value[0]; } return $this; }
php
public function setData($name, $value) { if (!isset($this->data)) { throw new RuntimeException("Data property is required for DataAwareTrait to work"); } // we use snake_case field keys // but camelCase setters $name = $this->decamelize($name); // only set values for predefined data keys if (array_key_exists($name, $this->data)) { $this->data[$name] = $value[0]; } return $this; }
[ "public", "function", "setData", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "data", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Data property is required for DataAwareTrait to work\"", ")", ";", "}", "// we use snake_case field keys", "// but camelCase setters", "$", "name", "=", "$", "this", "->", "decamelize", "(", "$", "name", ")", ";", "// only set values for predefined data keys", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "data", ")", ")", "{", "$", "this", "->", "data", "[", "$", "name", "]", "=", "$", "value", "[", "0", "]", ";", "}", "return", "$", "this", ";", "}" ]
Data setter Make sure only valid data passes through @param string $name data key name @param mixed $value data value name
[ "Data", "setter", "Make", "sure", "only", "valid", "data", "passes", "through" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/DataAwareTrait.php#L29-L45
33,060
QoboLtd/qobo-robo
src/DataAwareTrait.php
DataAwareTrait.checkRequiredData
protected function checkRequiredData() { if (!isset($this->data)) { throw new RuntimeException("'data' property is required for DataAwareTrait to work"); } if (!isset($this->requiredData)) { throw new RuntimeException("'requiredData' property is required for DataAwareTrait to work"); } $missing = []; foreach ($this->requiredData as $key) { if (!isset($this->data[$key])) { $missing []= $key; } } if (!count($missing)) { return true; } throw new RuntimeException( sprintf("Missing required data field(s) [%s]", implode(",", array_map([$this,"camelize"], $missing))) ); }
php
protected function checkRequiredData() { if (!isset($this->data)) { throw new RuntimeException("'data' property is required for DataAwareTrait to work"); } if (!isset($this->requiredData)) { throw new RuntimeException("'requiredData' property is required for DataAwareTrait to work"); } $missing = []; foreach ($this->requiredData as $key) { if (!isset($this->data[$key])) { $missing []= $key; } } if (!count($missing)) { return true; } throw new RuntimeException( sprintf("Missing required data field(s) [%s]", implode(",", array_map([$this,"camelize"], $missing))) ); }
[ "protected", "function", "checkRequiredData", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "data", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"'data' property is required for DataAwareTrait to work\"", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "requiredData", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"'requiredData' property is required for DataAwareTrait to work\"", ")", ";", "}", "$", "missing", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "requiredData", "as", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", ")", "{", "$", "missing", "[", "]", "=", "$", "key", ";", "}", "}", "if", "(", "!", "count", "(", "$", "missing", ")", ")", "{", "return", "true", ";", "}", "throw", "new", "RuntimeException", "(", "sprintf", "(", "\"Missing required data field(s) [%s]\"", ",", "implode", "(", "\",\"", ",", "array_map", "(", "[", "$", "this", ",", "\"camelize\"", "]", ",", "$", "missing", ")", ")", ")", ")", ";", "}" ]
Check that all required data present @return \Robo\Result
[ "Check", "that", "all", "required", "data", "present" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/DataAwareTrait.php#L52-L75
33,061
canihavesomecoffee/theTVDbAPI
src/MultiLanguageWrapper/Route/SeriesRouteLanguageFallback.php
SeriesRouteLanguageFallback.getClosureById
public function getClosureById(int $seriesId): Closure { return function ($language) use ($seriesId) { $json = $this->parent->performAPICallWithJsonResponse( 'get', '/series/'.$seriesId, [ 'headers' => ['Accept-Language' => $language] ] ); return DataParser::parseData($json, Series::class); }; }
php
public function getClosureById(int $seriesId): Closure { return function ($language) use ($seriesId) { $json = $this->parent->performAPICallWithJsonResponse( 'get', '/series/'.$seriesId, [ 'headers' => ['Accept-Language' => $language] ] ); return DataParser::parseData($json, Series::class); }; }
[ "public", "function", "getClosureById", "(", "int", "$", "seriesId", ")", ":", "Closure", "{", "return", "function", "(", "$", "language", ")", "use", "(", "$", "seriesId", ")", "{", "$", "json", "=", "$", "this", "->", "parent", "->", "performAPICallWithJsonResponse", "(", "'get'", ",", "'/series/'", ".", "$", "seriesId", ",", "[", "'headers'", "=>", "[", "'Accept-Language'", "=>", "$", "language", "]", "]", ")", ";", "return", "DataParser", "::", "parseData", "(", "$", "json", ",", "Series", "::", "class", ")", ";", "}", ";", "}" ]
Returns the closure used to retrieve a series with a given id for a single language. @param int $seriesId The ID of the series to retrieve. @return Closure
[ "Returns", "the", "closure", "used", "to", "retrieve", "a", "series", "with", "a", "given", "id", "for", "a", "single", "language", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/MultiLanguageWrapper/Route/SeriesRouteLanguageFallback.php#L74-L87
33,062
canihavesomecoffee/theTVDbAPI
src/MultiLanguageWrapper/Route/SeriesRouteLanguageFallback.php
SeriesRouteLanguageFallback.getClosureForEpisodes
public function getClosureForEpisodes(int $seriesId, array $options): Closure { return function ($language) use ($seriesId, $options) { $options['headers'] = ['Accept-Language' => $language]; $json = $this->parent->performAPICallWithJsonResponse( 'get', '/series/'.$seriesId.'/episodes', $options ); return DataParser::parseDataArray($json, BasicEpisode::class); }; }
php
public function getClosureForEpisodes(int $seriesId, array $options): Closure { return function ($language) use ($seriesId, $options) { $options['headers'] = ['Accept-Language' => $language]; $json = $this->parent->performAPICallWithJsonResponse( 'get', '/series/'.$seriesId.'/episodes', $options ); return DataParser::parseDataArray($json, BasicEpisode::class); }; }
[ "public", "function", "getClosureForEpisodes", "(", "int", "$", "seriesId", ",", "array", "$", "options", ")", ":", "Closure", "{", "return", "function", "(", "$", "language", ")", "use", "(", "$", "seriesId", ",", "$", "options", ")", "{", "$", "options", "[", "'headers'", "]", "=", "[", "'Accept-Language'", "=>", "$", "language", "]", ";", "$", "json", "=", "$", "this", "->", "parent", "->", "performAPICallWithJsonResponse", "(", "'get'", ",", "'/series/'", ".", "$", "seriesId", ".", "'/episodes'", ",", "$", "options", ")", ";", "return", "DataParser", "::", "parseDataArray", "(", "$", "json", ",", "BasicEpisode", "::", "class", ")", ";", "}", ";", "}" ]
Returns the closure used to retrieve a set of episodes for a series for a single language. @param int $seriesId The series id @param array $options The options (pagination, ...) @return Closure
[ "Returns", "the", "closure", "used", "to", "retrieve", "a", "set", "of", "episodes", "for", "a", "series", "for", "a", "single", "language", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/MultiLanguageWrapper/Route/SeriesRouteLanguageFallback.php#L117-L129
33,063
canihavesomecoffee/theTVDbAPI
src/MultiLanguageWrapper/Route/SeriesRouteLanguageFallback.php
SeriesRouteLanguageFallback.getClosureForImagesWithQuery
public function getClosureForImagesWithQuery(int $seriesId, array $options): Closure { return function ($language) use ($seriesId, $options) { $options['headers'] = ['Accept-Language' => $language]; $json = $this->parent->performAPICallWithJsonResponse( 'get', '/series/'.$seriesId.'/images/query', $options ); return DataParser::parseDataArray($json, Image::class); }; }
php
public function getClosureForImagesWithQuery(int $seriesId, array $options): Closure { return function ($language) use ($seriesId, $options) { $options['headers'] = ['Accept-Language' => $language]; $json = $this->parent->performAPICallWithJsonResponse( 'get', '/series/'.$seriesId.'/images/query', $options ); return DataParser::parseDataArray($json, Image::class); }; }
[ "public", "function", "getClosureForImagesWithQuery", "(", "int", "$", "seriesId", ",", "array", "$", "options", ")", ":", "Closure", "{", "return", "function", "(", "$", "language", ")", "use", "(", "$", "seriesId", ",", "$", "options", ")", "{", "$", "options", "[", "'headers'", "]", "=", "[", "'Accept-Language'", "=>", "$", "language", "]", ";", "$", "json", "=", "$", "this", "->", "parent", "->", "performAPICallWithJsonResponse", "(", "'get'", ",", "'/series/'", ".", "$", "seriesId", ".", "'/images/query'", ",", "$", "options", ")", ";", "return", "DataParser", "::", "parseDataArray", "(", "$", "json", ",", "Image", "::", "class", ")", ";", "}", ";", "}" ]
Returns the closure used to retrieve search images for a series with a certain query for a single language. @param int $seriesId The series id @param array $options The options (pagination, ...) @return Closure
[ "Returns", "the", "closure", "used", "to", "retrieve", "search", "images", "for", "a", "series", "with", "a", "certain", "query", "for", "a", "single", "language", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/MultiLanguageWrapper/Route/SeriesRouteLanguageFallback.php#L204-L216
33,064
hiqdev/hipanel-module-domain
src/cart/DomainRenewalProduct.php
DomainRenewalProduct.daysBeforeExpireValidator
public function daysBeforeExpireValidator($attribute) { if (isset($this->daysBeforeExpire[$this->getZone()])) { $minDays = $this->daysBeforeExpire[$this->getZone()]; $interval = (new DateTime())->diff(new DateTime($this->_model->expires)); $diff = $interval->format('%a') - $minDays; if ($diff > 0) { $date = Yii::$app->formatter->asDate((new DateTime())->add(new \DateInterval("P{$diff}D"))); $this->addError('id', Yii::t('hipanel:domain', 'Domains in zone {zone} could be renewed only in last {min, plural, one{# day} other{# days}} before the expiration date. You are able to renew domain {domain} only after {date} (in {days, plural, one{# day} other{# days}})', ['zone' => (string) $this->getZone(), 'min' => (int) $minDays, 'date' => (string) $date, 'days' => (int) $diff, 'domain' => (string) $this->name])); return false; } } return true; }
php
public function daysBeforeExpireValidator($attribute) { if (isset($this->daysBeforeExpire[$this->getZone()])) { $minDays = $this->daysBeforeExpire[$this->getZone()]; $interval = (new DateTime())->diff(new DateTime($this->_model->expires)); $diff = $interval->format('%a') - $minDays; if ($diff > 0) { $date = Yii::$app->formatter->asDate((new DateTime())->add(new \DateInterval("P{$diff}D"))); $this->addError('id', Yii::t('hipanel:domain', 'Domains in zone {zone} could be renewed only in last {min, plural, one{# day} other{# days}} before the expiration date. You are able to renew domain {domain} only after {date} (in {days, plural, one{# day} other{# days}})', ['zone' => (string) $this->getZone(), 'min' => (int) $minDays, 'date' => (string) $date, 'days' => (int) $diff, 'domain' => (string) $this->name])); return false; } } return true; }
[ "public", "function", "daysBeforeExpireValidator", "(", "$", "attribute", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "daysBeforeExpire", "[", "$", "this", "->", "getZone", "(", ")", "]", ")", ")", "{", "$", "minDays", "=", "$", "this", "->", "daysBeforeExpire", "[", "$", "this", "->", "getZone", "(", ")", "]", ";", "$", "interval", "=", "(", "new", "DateTime", "(", ")", ")", "->", "diff", "(", "new", "DateTime", "(", "$", "this", "->", "_model", "->", "expires", ")", ")", ";", "$", "diff", "=", "$", "interval", "->", "format", "(", "'%a'", ")", "-", "$", "minDays", ";", "if", "(", "$", "diff", ">", "0", ")", "{", "$", "date", "=", "Yii", "::", "$", "app", "->", "formatter", "->", "asDate", "(", "(", "new", "DateTime", "(", ")", ")", "->", "add", "(", "new", "\\", "DateInterval", "(", "\"P{$diff}D\"", ")", ")", ")", ";", "$", "this", "->", "addError", "(", "'id'", ",", "Yii", "::", "t", "(", "'hipanel:domain'", ",", "'Domains in zone {zone} could be renewed only in last {min, plural, one{# day} other{# days}} before the expiration date. You are able to renew domain {domain} only after {date} (in {days, plural, one{# day} other{# days}})'", ",", "[", "'zone'", "=>", "(", "string", ")", "$", "this", "->", "getZone", "(", ")", ",", "'min'", "=>", "(", "int", ")", "$", "minDays", ",", "'date'", "=>", "(", "string", ")", "$", "date", ",", "'days'", "=>", "(", "int", ")", "$", "diff", ",", "'domain'", "=>", "(", "string", ")", "$", "this", "->", "name", "]", ")", ")", ";", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks whether domain reached the limit of days before expiration date and can be renewed. @param $attribute @return bool
[ "Checks", "whether", "domain", "reached", "the", "limit", "of", "days", "before", "expiration", "date", "and", "can", "be", "renewed", "." ]
b1b02782fcb69970cacafe6c6ead238b14b54209
https://github.com/hiqdev/hipanel-module-domain/blob/b1b02782fcb69970cacafe6c6ead238b14b54209/src/cart/DomainRenewalProduct.php#L90-L105
33,065
QoboLtd/qobo-robo
src/Command/Project/Changelog.php
Changelog.projectChangelog
public function projectChangelog($opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskProjectChangelog() ->format('--reverse --no-merges --pretty=format:"* %<(72,trunc)%s (%ad, %an)" --date=short') ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } $data = $result->getData(); $data = array_map( function ($str) { if (!preg_match("/^\*\s+(.*?)\((\d{4}-\d{2}-\d{2}), (.*?)\).*$/", $str, $matches)) { return $str; } return [ 'message' => trim($matches[1]), 'data' => $matches[2], 'author' => $matches[3] ]; }, $data['data'][0]['output'] ); return new RowsOfFields($data); }
php
public function projectChangelog($opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskProjectChangelog() ->format('--reverse --no-merges --pretty=format:"* %<(72,trunc)%s (%ad, %an)" --date=short') ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } $data = $result->getData(); $data = array_map( function ($str) { if (!preg_match("/^\*\s+(.*?)\((\d{4}-\d{2}-\d{2}), (.*?)\).*$/", $str, $matches)) { return $str; } return [ 'message' => trim($matches[1]), 'data' => $matches[2], 'author' => $matches[3] ]; }, $data['data'][0]['output'] ); return new RowsOfFields($data); }
[ "public", "function", "projectChangelog", "(", "$", "opts", "=", "[", "'format'", "=>", "'table'", ",", "'fields'", "=>", "''", "]", ")", "{", "$", "result", "=", "$", "this", "->", "taskProjectChangelog", "(", ")", "->", "format", "(", "'--reverse --no-merges --pretty=format:\"* %<(72,trunc)%s (%ad, %an)\" --date=short'", ")", "->", "run", "(", ")", ";", "if", "(", "!", "$", "result", "->", "wasSuccessful", "(", ")", ")", "{", "$", "this", "->", "exitError", "(", "\"Failed to run command\"", ")", ";", "}", "$", "data", "=", "$", "result", "->", "getData", "(", ")", ";", "$", "data", "=", "array_map", "(", "function", "(", "$", "str", ")", "{", "if", "(", "!", "preg_match", "(", "\"/^\\*\\s+(.*?)\\((\\d{4}-\\d{2}-\\d{2}), (.*?)\\).*$/\"", ",", "$", "str", ",", "$", "matches", ")", ")", "{", "return", "$", "str", ";", "}", "return", "[", "'message'", "=>", "trim", "(", "$", "matches", "[", "1", "]", ")", ",", "'data'", "=>", "$", "matches", "[", "2", "]", ",", "'author'", "=>", "$", "matches", "[", "3", "]", "]", ";", "}", ",", "$", "data", "[", "'data'", "]", "[", "0", "]", "[", "'output'", "]", ")", ";", "return", "new", "RowsOfFields", "(", "$", "data", ")", ";", "}" ]
Get project changelog @return \Qobo\Robo\Formatter\RowsOfFields
[ "Get", "project", "changelog" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Command/Project/Changelog.php#L24-L52
33,066
anomalylabs/variables-module
src/VariablesModuleServiceProvider.php
VariablesModuleServiceProvider.map
public function map(FieldRouter $fields, VersionRouter $versions, AssignmentRouter $assignments) { $fields->route($this->addon, FieldsController::class); $versions->route($this->addon, VersionsController::class); $assignments->route($this->addon, AssignmentsController::class, 'admin/variables/groups'); }
php
public function map(FieldRouter $fields, VersionRouter $versions, AssignmentRouter $assignments) { $fields->route($this->addon, FieldsController::class); $versions->route($this->addon, VersionsController::class); $assignments->route($this->addon, AssignmentsController::class, 'admin/variables/groups'); }
[ "public", "function", "map", "(", "FieldRouter", "$", "fields", ",", "VersionRouter", "$", "versions", ",", "AssignmentRouter", "$", "assignments", ")", "{", "$", "fields", "->", "route", "(", "$", "this", "->", "addon", ",", "FieldsController", "::", "class", ")", ";", "$", "versions", "->", "route", "(", "$", "this", "->", "addon", ",", "VersionsController", "::", "class", ")", ";", "$", "assignments", "->", "route", "(", "$", "this", "->", "addon", ",", "AssignmentsController", "::", "class", ",", "'admin/variables/groups'", ")", ";", "}" ]
Map the addon. @param FieldRouter $fields @param VersionRouter $versions @param AssignmentRouter $assignments
[ "Map", "the", "addon", "." ]
bcd903670471a175f07aba3123693cb3a3c07d0b
https://github.com/anomalylabs/variables-module/blob/bcd903670471a175f07aba3123693cb3a3c07d0b/src/VariablesModuleServiceProvider.php#L48-L53
33,067
nails/module-invoice
src/Factory/ChargeResponse.php
ChargeResponse.setRedirectUrl
public function setRedirectUrl($sRedirectUrl) { if (!$this->bIsLocked) { $this->sRedirectUrl = $sRedirectUrl; $this->setIsRedirect(!empty($sRedirectUrl)); } return $this; }
php
public function setRedirectUrl($sRedirectUrl) { if (!$this->bIsLocked) { $this->sRedirectUrl = $sRedirectUrl; $this->setIsRedirect(!empty($sRedirectUrl)); } return $this; }
[ "public", "function", "setRedirectUrl", "(", "$", "sRedirectUrl", ")", "{", "if", "(", "!", "$", "this", "->", "bIsLocked", ")", "{", "$", "this", "->", "sRedirectUrl", "=", "$", "sRedirectUrl", ";", "$", "this", "->", "setIsRedirect", "(", "!", "empty", "(", "$", "sRedirectUrl", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the redirectUrl value @param string $sRedirectUrl The Redirect URL @return $this
[ "Set", "the", "redirectUrl", "value" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/ChargeResponse.php#L75-L82
33,068
nails/module-invoice
src/Factory/ChargeResponse.php
ChargeResponse.setRedirectPostData
public function setRedirectPostData($aRedirectPostData) { if (!$this->bIsLocked) { $this->aRedirectPostData = $aRedirectPostData; $this->setIsRedirect(!empty($aRedirectPostData)); } return $this; }
php
public function setRedirectPostData($aRedirectPostData) { if (!$this->bIsLocked) { $this->aRedirectPostData = $aRedirectPostData; $this->setIsRedirect(!empty($aRedirectPostData)); } return $this; }
[ "public", "function", "setRedirectPostData", "(", "$", "aRedirectPostData", ")", "{", "if", "(", "!", "$", "this", "->", "bIsLocked", ")", "{", "$", "this", "->", "aRedirectPostData", "=", "$", "aRedirectPostData", ";", "$", "this", "->", "setIsRedirect", "(", "!", "empty", "(", "$", "aRedirectPostData", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set any data which should be POST'ed to the endpoint @param array $aRedirectPostData The data to post @return $this
[ "Set", "any", "data", "which", "should", "be", "POST", "ed", "to", "the", "endpoint" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/ChargeResponse.php#L188-L195
33,069
nails/module-invoice
src/Driver/PaymentBase.php
PaymentBase.charge
public function charge( $iAmount, $sCurrency, $oData, $oCustomData, $sDescription, $oPayment, $oInvoice, $sSuccessUrl, $sFailUrl, $sContinueUrl ) { throw new DriverException('Driver must implement the charge() method', 1); }
php
public function charge( $iAmount, $sCurrency, $oData, $oCustomData, $sDescription, $oPayment, $oInvoice, $sSuccessUrl, $sFailUrl, $sContinueUrl ) { throw new DriverException('Driver must implement the charge() method', 1); }
[ "public", "function", "charge", "(", "$", "iAmount", ",", "$", "sCurrency", ",", "$", "oData", ",", "$", "oCustomData", ",", "$", "sDescription", ",", "$", "oPayment", ",", "$", "oInvoice", ",", "$", "sSuccessUrl", ",", "$", "sFailUrl", ",", "$", "sContinueUrl", ")", "{", "throw", "new", "DriverException", "(", "'Driver must implement the charge() method'", ",", "1", ")", ";", "}" ]
Initiate a payment @param integer $iAmount The payment amount @param string $sCurrency The payment currency @param \stdClass $oData An array of driver data @param \stdClass $oCustomData The custom data object @param string $sDescription The charge description @param \stdClass $oPayment The payment object @param \stdClass $oInvoice The invoice object @param string $sSuccessUrl The URL to go to after successful payment @param string $sFailUrl The URL to go to after failed payment @param string $sContinueUrl The URL to go to after payment is completed @throws DriverException @return \Nails\Invoice\Factory\ChargeResponse
[ "Initiate", "a", "payment" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Driver/PaymentBase.php#L87-L100
33,070
canihavesomecoffee/theTVDbAPI
src/MultiLanguageWrapper/MultiLanguageFallbackGenerator.php
MultiLanguageFallbackGenerator.create
public function create( Closure $performRequest, string $returnTypeClass, array $languages, bool $merge = false ) { $languageIdx = 0; $returnValue = null; $langLength = sizeof($languages); do { $result = $performRequest($languages[$languageIdx]); $languageIdx++; if ($languageIdx > 0 && $merge) { $returnValue = $this->validator->merge($returnTypeClass, $returnValue, $result); } else { $returnValue = $result; } } while ($this->validator->isValid($returnTypeClass, $result) === false && $languageIdx < $langLength); return $returnValue; }
php
public function create( Closure $performRequest, string $returnTypeClass, array $languages, bool $merge = false ) { $languageIdx = 0; $returnValue = null; $langLength = sizeof($languages); do { $result = $performRequest($languages[$languageIdx]); $languageIdx++; if ($languageIdx > 0 && $merge) { $returnValue = $this->validator->merge($returnTypeClass, $returnValue, $result); } else { $returnValue = $result; } } while ($this->validator->isValid($returnTypeClass, $result) === false && $languageIdx < $langLength); return $returnValue; }
[ "public", "function", "create", "(", "Closure", "$", "performRequest", ",", "string", "$", "returnTypeClass", ",", "array", "$", "languages", ",", "bool", "$", "merge", "=", "false", ")", "{", "$", "languageIdx", "=", "0", ";", "$", "returnValue", "=", "null", ";", "$", "langLength", "=", "sizeof", "(", "$", "languages", ")", ";", "do", "{", "$", "result", "=", "$", "performRequest", "(", "$", "languages", "[", "$", "languageIdx", "]", ")", ";", "$", "languageIdx", "++", ";", "if", "(", "$", "languageIdx", ">", "0", "&&", "$", "merge", ")", "{", "$", "returnValue", "=", "$", "this", "->", "validator", "->", "merge", "(", "$", "returnTypeClass", ",", "$", "returnValue", ",", "$", "result", ")", ";", "}", "else", "{", "$", "returnValue", "=", "$", "result", ";", "}", "}", "while", "(", "$", "this", "->", "validator", "->", "isValid", "(", "$", "returnTypeClass", ",", "$", "result", ")", "===", "false", "&&", "$", "languageIdx", "<", "$", "langLength", ")", ";", "return", "$", "returnValue", ";", "}" ]
Creates an object using the provided closure, and keeps using fallback languages while the object isn't valid. @param Closure $performRequest The closure that calls the API and returns an object of the provided class. The function call must accept only one parameter: the language for the request. @param string $returnTypeClass The type of class instance that should be returned. @param array $languages The languages that should be tried. @param bool $merge Merge the results in different languages together? @return mixed
[ "Creates", "an", "object", "using", "the", "provided", "closure", "and", "keeps", "using", "fallback", "languages", "while", "the", "object", "isn", "t", "valid", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/MultiLanguageWrapper/MultiLanguageFallbackGenerator.php#L70-L89
33,071
orchestral/support
src/Support/Concerns/Observable.php
Observable.fireObservableEvent
protected function fireObservableEvent(string $event, bool $halt) { if (! isset(static::$dispatcher)) { return true; } $className = \get_class($this); $event = $this->getObservableKey($event); $method = $halt ? 'until' : 'handle'; return static::$dispatcher->$method("{$event}: {$className}", $this); }
php
protected function fireObservableEvent(string $event, bool $halt) { if (! isset(static::$dispatcher)) { return true; } $className = \get_class($this); $event = $this->getObservableKey($event); $method = $halt ? 'until' : 'handle'; return static::$dispatcher->$method("{$event}: {$className}", $this); }
[ "protected", "function", "fireObservableEvent", "(", "string", "$", "event", ",", "bool", "$", "halt", ")", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "dispatcher", ")", ")", "{", "return", "true", ";", "}", "$", "className", "=", "\\", "get_class", "(", "$", "this", ")", ";", "$", "event", "=", "$", "this", "->", "getObservableKey", "(", "$", "event", ")", ";", "$", "method", "=", "$", "halt", "?", "'until'", ":", "'handle'", ";", "return", "static", "::", "$", "dispatcher", "->", "$", "method", "(", "\"{$event}: {$className}\"", ",", "$", "this", ")", ";", "}" ]
Fire the given event. @param string $event @param bool $halt @return mixed
[ "Fire", "the", "given", "event", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Concerns/Observable.php#L85-L97
33,072
orchestral/support
src/Support/Concerns/Observable.php
Observable.flushEventListeners
public static function flushEventListeners(): void { if (! isset(static::$dispatcher)) { return; } $instance = new static(); $className = static::class; foreach ($instance->getObservableEvents() as $event) { $event = $instance->getObservableKey($event); static::$dispatcher->forget("{$event}: {$className}"); } }
php
public static function flushEventListeners(): void { if (! isset(static::$dispatcher)) { return; } $instance = new static(); $className = static::class; foreach ($instance->getObservableEvents() as $event) { $event = $instance->getObservableKey($event); static::$dispatcher->forget("{$event}: {$className}"); } }
[ "public", "static", "function", "flushEventListeners", "(", ")", ":", "void", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "dispatcher", ")", ")", "{", "return", ";", "}", "$", "instance", "=", "new", "static", "(", ")", ";", "$", "className", "=", "static", "::", "class", ";", "foreach", "(", "$", "instance", "->", "getObservableEvents", "(", ")", "as", "$", "event", ")", "{", "$", "event", "=", "$", "instance", "->", "getObservableKey", "(", "$", "event", ")", ";", "static", "::", "$", "dispatcher", "->", "forget", "(", "\"{$event}: {$className}\"", ")", ";", "}", "}" ]
Remove all of the event listeners for the observers. @return void
[ "Remove", "all", "of", "the", "event", "listeners", "for", "the", "observers", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Concerns/Observable.php#L104-L118
33,073
canihavesomecoffee/theTVDbAPI
src/TheTVDbAPI.php
TheTVDbAPI.getDefaultHttpClientOptions
private function getDefaultHttpClientOptions(array $options = []): array { $headers = []; if ($this->token !== null) { $headers['Authorization'] = 'Bearer '.$this->token; } $languagesInOptions = (array_key_exists('headers', $options) && array_key_exists('Accept-Language', $options['headers'])); if ($this->languages !== null && $languagesInOptions === false) { $headers['Accept-Language'] = join(', ', $this->languages); } if ($this->version !== null) { $headers['Accept'] = 'application/vnd.thetvdb.v'.$this->version; } $options['http_errors'] = false; return array_merge_recursive(['headers' => $headers], $options); }
php
private function getDefaultHttpClientOptions(array $options = []): array { $headers = []; if ($this->token !== null) { $headers['Authorization'] = 'Bearer '.$this->token; } $languagesInOptions = (array_key_exists('headers', $options) && array_key_exists('Accept-Language', $options['headers'])); if ($this->languages !== null && $languagesInOptions === false) { $headers['Accept-Language'] = join(', ', $this->languages); } if ($this->version !== null) { $headers['Accept'] = 'application/vnd.thetvdb.v'.$this->version; } $options['http_errors'] = false; return array_merge_recursive(['headers' => $headers], $options); }
[ "private", "function", "getDefaultHttpClientOptions", "(", "array", "$", "options", "=", "[", "]", ")", ":", "array", "{", "$", "headers", "=", "[", "]", ";", "if", "(", "$", "this", "->", "token", "!==", "null", ")", "{", "$", "headers", "[", "'Authorization'", "]", "=", "'Bearer '", ".", "$", "this", "->", "token", ";", "}", "$", "languagesInOptions", "=", "(", "array_key_exists", "(", "'headers'", ",", "$", "options", ")", "&&", "array_key_exists", "(", "'Accept-Language'", ",", "$", "options", "[", "'headers'", "]", ")", ")", ";", "if", "(", "$", "this", "->", "languages", "!==", "null", "&&", "$", "languagesInOptions", "===", "false", ")", "{", "$", "headers", "[", "'Accept-Language'", "]", "=", "join", "(", "', '", ",", "$", "this", "->", "languages", ")", ";", "}", "if", "(", "$", "this", "->", "version", "!==", "null", ")", "{", "$", "headers", "[", "'Accept'", "]", "=", "'application/vnd.thetvdb.v'", ".", "$", "this", "->", "version", ";", "}", "$", "options", "[", "'http_errors'", "]", "=", "false", ";", "return", "array_merge_recursive", "(", "[", "'headers'", "=>", "$", "headers", "]", ",", "$", "options", ")", ";", "}" ]
Returns the default client options. @param array $options A list of options to start with (optional) @return array An array containing the passed in options, as well as the added ones
[ "Returns", "the", "default", "client", "options", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/TheTVDbAPI.php#L254-L275
33,074
canihavesomecoffee/theTVDbAPI
src/TheTVDbAPI.php
TheTVDbAPI.requestHeaders
public function requestHeaders($method, $path, array $options = []): array { $options = $this->getDefaultHttpClientOptions($options); /* @type Response $response */ $response = $this->httpClient->{$method}($path, $options); if ($response->getStatusCode() === 401) { throw UnauthorizedException::invalidToken(); } elseif ($response->getStatusCode() === 404) { throw ResourceNotFoundException::notFound($path, $options); } return $response->getHeaders(); }
php
public function requestHeaders($method, $path, array $options = []): array { $options = $this->getDefaultHttpClientOptions($options); /* @type Response $response */ $response = $this->httpClient->{$method}($path, $options); if ($response->getStatusCode() === 401) { throw UnauthorizedException::invalidToken(); } elseif ($response->getStatusCode() === 404) { throw ResourceNotFoundException::notFound($path, $options); } return $response->getHeaders(); }
[ "public", "function", "requestHeaders", "(", "$", "method", ",", "$", "path", ",", "array", "$", "options", "=", "[", "]", ")", ":", "array", "{", "$", "options", "=", "$", "this", "->", "getDefaultHttpClientOptions", "(", "$", "options", ")", ";", "/* @type Response $response */", "$", "response", "=", "$", "this", "->", "httpClient", "->", "{", "$", "method", "}", "(", "$", "path", ",", "$", "options", ")", ";", "if", "(", "$", "response", "->", "getStatusCode", "(", ")", "===", "401", ")", "{", "throw", "UnauthorizedException", "::", "invalidToken", "(", ")", ";", "}", "elseif", "(", "$", "response", "->", "getStatusCode", "(", ")", "===", "404", ")", "{", "throw", "ResourceNotFoundException", "::", "notFound", "(", "$", "path", ",", "$", "options", ")", ";", "}", "return", "$", "response", "->", "getHeaders", "(", ")", ";", "}" ]
Makes a call to the API and return headers only. @param string $method HTTP Method (post, getUserData, put, etc.) @param string $path Path to the API call @param array $options HTTP Client options @return array @throws ResourceNotFoundException @throws UnauthorizedException
[ "Makes", "a", "call", "to", "the", "API", "and", "return", "headers", "only", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/TheTVDbAPI.php#L288-L302
33,075
canihavesomecoffee/theTVDbAPI
src/TheTVDbAPI.php
TheTVDbAPI.performAPICall
public function performAPICall($method, $path, array $options = []): Response { $options = $this->getDefaultHttpClientOptions($options); // Reset JSON errors. $this->jsonErrors = []; // Reset Link section. $this->links = []; /* @type Response $response */ $response = $this->httpClient->{$method}($path, $options); if ($response->getStatusCode() === 401) { throw UnauthorizedException::invalidToken(); } elseif ($response->getStatusCode() === 404) { throw ResourceNotFoundException::notFound($path, $options); } return $response; }
php
public function performAPICall($method, $path, array $options = []): Response { $options = $this->getDefaultHttpClientOptions($options); // Reset JSON errors. $this->jsonErrors = []; // Reset Link section. $this->links = []; /* @type Response $response */ $response = $this->httpClient->{$method}($path, $options); if ($response->getStatusCode() === 401) { throw UnauthorizedException::invalidToken(); } elseif ($response->getStatusCode() === 404) { throw ResourceNotFoundException::notFound($path, $options); } return $response; }
[ "public", "function", "performAPICall", "(", "$", "method", ",", "$", "path", ",", "array", "$", "options", "=", "[", "]", ")", ":", "Response", "{", "$", "options", "=", "$", "this", "->", "getDefaultHttpClientOptions", "(", "$", "options", ")", ";", "// Reset JSON errors.", "$", "this", "->", "jsonErrors", "=", "[", "]", ";", "// Reset Link section.", "$", "this", "->", "links", "=", "[", "]", ";", "/* @type Response $response */", "$", "response", "=", "$", "this", "->", "httpClient", "->", "{", "$", "method", "}", "(", "$", "path", ",", "$", "options", ")", ";", "if", "(", "$", "response", "->", "getStatusCode", "(", ")", "===", "401", ")", "{", "throw", "UnauthorizedException", "::", "invalidToken", "(", ")", ";", "}", "elseif", "(", "$", "response", "->", "getStatusCode", "(", ")", "===", "404", ")", "{", "throw", "ResourceNotFoundException", "::", "notFound", "(", "$", "path", ",", "$", "options", ")", ";", "}", "return", "$", "response", ";", "}" ]
Perform an API call to theTVDb. @param string $method HTTP Method (post, getUserData, put, etc.) @param string $path Path to the API call @param array $options HTTP Client options @return Response @throws UnauthorizedException @throws ResourceNotFoundException
[ "Perform", "an", "API", "call", "to", "theTVDb", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/TheTVDbAPI.php#L315-L333
33,076
canihavesomecoffee/theTVDbAPI
src/TheTVDbAPI.php
TheTVDbAPI.performAPICallWithJsonResponse
public function performAPICallWithJsonResponse($method, $path, array $options = []) { $response = $this->performAPICall($method, $path, $options); if ($response->getStatusCode() === 200) { $contents = $response->getBody()->getContents(); $json = json_decode($contents, true); if ($json === null) { throw ParseException::decode(); } // Parse errors first, if any. if (array_key_exists('errors', $json)) { // Parse error and throw appropriate exception. $this->parseErrorSection($json['errors']); } // Parse links, if any. if (array_key_exists('links', $json)) { $this->links = $json['links']; } if (array_key_exists('data', $json) === false) { return $json; } return $json['data']; } throw new Exception( sprintf( 'Got status code %d from service at path %s', $response->getStatusCode(), $path ) ); }
php
public function performAPICallWithJsonResponse($method, $path, array $options = []) { $response = $this->performAPICall($method, $path, $options); if ($response->getStatusCode() === 200) { $contents = $response->getBody()->getContents(); $json = json_decode($contents, true); if ($json === null) { throw ParseException::decode(); } // Parse errors first, if any. if (array_key_exists('errors', $json)) { // Parse error and throw appropriate exception. $this->parseErrorSection($json['errors']); } // Parse links, if any. if (array_key_exists('links', $json)) { $this->links = $json['links']; } if (array_key_exists('data', $json) === false) { return $json; } return $json['data']; } throw new Exception( sprintf( 'Got status code %d from service at path %s', $response->getStatusCode(), $path ) ); }
[ "public", "function", "performAPICallWithJsonResponse", "(", "$", "method", ",", "$", "path", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "response", "=", "$", "this", "->", "performAPICall", "(", "$", "method", ",", "$", "path", ",", "$", "options", ")", ";", "if", "(", "$", "response", "->", "getStatusCode", "(", ")", "===", "200", ")", "{", "$", "contents", "=", "$", "response", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ";", "$", "json", "=", "json_decode", "(", "$", "contents", ",", "true", ")", ";", "if", "(", "$", "json", "===", "null", ")", "{", "throw", "ParseException", "::", "decode", "(", ")", ";", "}", "// Parse errors first, if any.", "if", "(", "array_key_exists", "(", "'errors'", ",", "$", "json", ")", ")", "{", "// Parse error and throw appropriate exception.", "$", "this", "->", "parseErrorSection", "(", "$", "json", "[", "'errors'", "]", ")", ";", "}", "// Parse links, if any.", "if", "(", "array_key_exists", "(", "'links'", ",", "$", "json", ")", ")", "{", "$", "this", "->", "links", "=", "$", "json", "[", "'links'", "]", ";", "}", "if", "(", "array_key_exists", "(", "'data'", ",", "$", "json", ")", "===", "false", ")", "{", "return", "$", "json", ";", "}", "return", "$", "json", "[", "'data'", "]", ";", "}", "throw", "new", "Exception", "(", "sprintf", "(", "'Got status code %d from service at path %s'", ",", "$", "response", "->", "getStatusCode", "(", ")", ",", "$", "path", ")", ")", ";", "}" ]
Perform an API call to theTVDb and return a JSON response @param string $method HTTP Method (post, getUserData, put, etc.) @param string $path Path to the API call @param array $options HTTP Client options @return mixed @throws ResourceNotFoundException @throws UnauthorizedException @throws Exception
[ "Perform", "an", "API", "call", "to", "theTVDb", "and", "return", "a", "JSON", "response" ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/TheTVDbAPI.php#L347-L379
33,077
canihavesomecoffee/theTVDbAPI
src/TheTVDbAPI.php
TheTVDbAPI.parseErrorSection
private function parseErrorSection(array $errors) { if (array_key_exists('invalidFilters', $errors)) { $this->jsonErrors[] = new JSONError(JSONError::INVALID_FILTER, $errors['invalidFilters']); } if (array_key_exists('invalidQueryParams', $errors)) { $this->jsonErrors[] = new JSONError(JSONError::INVALID_QUERYPARAMS, $errors['invalidQueryParams']); } if (array_key_exists('invalidLanguage', $errors)) { $this->jsonErrors[] = new JSONError(); } }
php
private function parseErrorSection(array $errors) { if (array_key_exists('invalidFilters', $errors)) { $this->jsonErrors[] = new JSONError(JSONError::INVALID_FILTER, $errors['invalidFilters']); } if (array_key_exists('invalidQueryParams', $errors)) { $this->jsonErrors[] = new JSONError(JSONError::INVALID_QUERYPARAMS, $errors['invalidQueryParams']); } if (array_key_exists('invalidLanguage', $errors)) { $this->jsonErrors[] = new JSONError(); } }
[ "private", "function", "parseErrorSection", "(", "array", "$", "errors", ")", "{", "if", "(", "array_key_exists", "(", "'invalidFilters'", ",", "$", "errors", ")", ")", "{", "$", "this", "->", "jsonErrors", "[", "]", "=", "new", "JSONError", "(", "JSONError", "::", "INVALID_FILTER", ",", "$", "errors", "[", "'invalidFilters'", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "'invalidQueryParams'", ",", "$", "errors", ")", ")", "{", "$", "this", "->", "jsonErrors", "[", "]", "=", "new", "JSONError", "(", "JSONError", "::", "INVALID_QUERYPARAMS", ",", "$", "errors", "[", "'invalidQueryParams'", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "'invalidLanguage'", ",", "$", "errors", ")", ")", "{", "$", "this", "->", "jsonErrors", "[", "]", "=", "new", "JSONError", "(", ")", ";", "}", "}" ]
Parses the errors and stores them in lastJSONErrors. @param array $errors The JSON errors. @return void
[ "Parses", "the", "errors", "and", "stores", "them", "in", "lastJSONErrors", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/TheTVDbAPI.php#L408-L419
33,078
orchestral/support
src/Support/Keyword.php
Keyword.searchIn
public function searchIn(array $items = []) { if (\is_null($slug = $this->slug)) { return \array_search($this->value, $items); } return \array_search($slug, $items); }
php
public function searchIn(array $items = []) { if (\is_null($slug = $this->slug)) { return \array_search($this->value, $items); } return \array_search($slug, $items); }
[ "public", "function", "searchIn", "(", "array", "$", "items", "=", "[", "]", ")", "{", "if", "(", "\\", "is_null", "(", "$", "slug", "=", "$", "this", "->", "slug", ")", ")", "{", "return", "\\", "array_search", "(", "$", "this", "->", "value", ",", "$", "items", ")", ";", "}", "return", "\\", "array_search", "(", "$", "slug", ",", "$", "items", ")", ";", "}" ]
Search slug in given items and return the key. @param array $items @return mixed
[ "Search", "slug", "in", "given", "items", "and", "return", "the", "key", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Keyword.php#L78-L85
33,079
orchestral/support
src/Support/Keyword.php
Keyword.hasIn
public function hasIn(array $items = []) { if (\is_null($slug = $this->slug)) { return isset($items[$this->value]); } return isset($items[$slug]); }
php
public function hasIn(array $items = []) { if (\is_null($slug = $this->slug)) { return isset($items[$this->value]); } return isset($items[$slug]); }
[ "public", "function", "hasIn", "(", "array", "$", "items", "=", "[", "]", ")", "{", "if", "(", "\\", "is_null", "(", "$", "slug", "=", "$", "this", "->", "slug", ")", ")", "{", "return", "isset", "(", "$", "items", "[", "$", "this", "->", "value", "]", ")", ";", "}", "return", "isset", "(", "$", "items", "[", "$", "slug", "]", ")", ";", "}" ]
Search slug in given items and return if the key exist. @param array $items @return bool
[ "Search", "slug", "in", "given", "items", "and", "return", "if", "the", "key", "exist", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Keyword.php#L94-L101
33,080
doganoo/PHPUtil
src/Util/ClassUtil.php
ClassUtil.getClassName
public static function getClassName($object): ?string { $validObject = ClassUtil::isValidObject($object); if (!$validObject) { return null; } return (new \ReflectionClass($object))->getName(); }
php
public static function getClassName($object): ?string { $validObject = ClassUtil::isValidObject($object); if (!$validObject) { return null; } return (new \ReflectionClass($object))->getName(); }
[ "public", "static", "function", "getClassName", "(", "$", "object", ")", ":", "?", "string", "{", "$", "validObject", "=", "ClassUtil", "::", "isValidObject", "(", "$", "object", ")", ";", "if", "(", "!", "$", "validObject", ")", "{", "return", "null", ";", "}", "return", "(", "new", "\\", "ReflectionClass", "(", "$", "object", ")", ")", "->", "getName", "(", ")", ";", "}" ]
returns the name of an object @param $object @return null|string @throws \ReflectionException
[ "returns", "the", "name", "of", "an", "object" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Util/ClassUtil.php#L51-L57
33,081
doganoo/PHPUtil
src/Util/ClassUtil.php
ClassUtil.isSerialized
public static function isSerialized(string $string): bool { $data = @unserialize($string); if (false === $data) { return false; } else { return true; } }
php
public static function isSerialized(string $string): bool { $data = @unserialize($string); if (false === $data) { return false; } else { return true; } }
[ "public", "static", "function", "isSerialized", "(", "string", "$", "string", ")", ":", "bool", "{", "$", "data", "=", "@", "unserialize", "(", "$", "string", ")", ";", "if", "(", "false", "===", "$", "data", ")", "{", "return", "false", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
whether the string is an serialized object or not @param string $string @return bool
[ "whether", "the", "string", "is", "an", "serialized", "object", "or", "not" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Util/ClassUtil.php#L99-L106
33,082
doganoo/PHPUtil
src/Util/ClassUtil.php
ClassUtil.getAllProperties
public static function getAllProperties($object, bool $asString = true) { $validObject = ClassUtil::isValidObject($object); if (!$validObject) { return null; } $reflectionClass = new \ReflectionClass($object); $properties = $reflectionClass->getProperties(); if ($asString) { return ArrayUtil::arrayToString($properties); } else { return $properties; } }
php
public static function getAllProperties($object, bool $asString = true) { $validObject = ClassUtil::isValidObject($object); if (!$validObject) { return null; } $reflectionClass = new \ReflectionClass($object); $properties = $reflectionClass->getProperties(); if ($asString) { return ArrayUtil::arrayToString($properties); } else { return $properties; } }
[ "public", "static", "function", "getAllProperties", "(", "$", "object", ",", "bool", "$", "asString", "=", "true", ")", "{", "$", "validObject", "=", "ClassUtil", "::", "isValidObject", "(", "$", "object", ")", ";", "if", "(", "!", "$", "validObject", ")", "{", "return", "null", ";", "}", "$", "reflectionClass", "=", "new", "\\", "ReflectionClass", "(", "$", "object", ")", ";", "$", "properties", "=", "$", "reflectionClass", "->", "getProperties", "(", ")", ";", "if", "(", "$", "asString", ")", "{", "return", "ArrayUtil", "::", "arrayToString", "(", "$", "properties", ")", ";", "}", "else", "{", "return", "$", "properties", ";", "}", "}" ]
returns all properties of an object TODO let caller define the visibility @param $object @param bool $asString @return null|\ReflectionProperty[]|string @throws \ReflectionException
[ "returns", "all", "properties", "of", "an", "object" ]
4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5
https://github.com/doganoo/PHPUtil/blob/4415a014b4448b1ddf6d2e3f0f0d39cd1a83b8f5/src/Util/ClassUtil.php#L118-L131
33,083
canihavesomecoffee/theTVDbAPI
src/Route/RouteFactory.php
RouteFactory.getRouteInstance
public static function getRouteInstance(TheTVDbAPIInterface $parent, string $routeClassName) { if (array_key_exists($routeClassName, static::$routeInstances) === false) { $classImplements = class_implements($routeClassName); if (in_array('CanIHaveSomeCoffee\TheTVDbAPI\Route\RouteInterface', $classImplements) === false) { throw new InvalidArgumentException('Class does not implement the RouteInterface!'); } $args = [$parent]; static::$routeInstances[$routeClassName] = new $routeClassName(...$args); } return static::$routeInstances[$routeClassName]; }
php
public static function getRouteInstance(TheTVDbAPIInterface $parent, string $routeClassName) { if (array_key_exists($routeClassName, static::$routeInstances) === false) { $classImplements = class_implements($routeClassName); if (in_array('CanIHaveSomeCoffee\TheTVDbAPI\Route\RouteInterface', $classImplements) === false) { throw new InvalidArgumentException('Class does not implement the RouteInterface!'); } $args = [$parent]; static::$routeInstances[$routeClassName] = new $routeClassName(...$args); } return static::$routeInstances[$routeClassName]; }
[ "public", "static", "function", "getRouteInstance", "(", "TheTVDbAPIInterface", "$", "parent", ",", "string", "$", "routeClassName", ")", "{", "if", "(", "array_key_exists", "(", "$", "routeClassName", ",", "static", "::", "$", "routeInstances", ")", "===", "false", ")", "{", "$", "classImplements", "=", "class_implements", "(", "$", "routeClassName", ")", ";", "if", "(", "in_array", "(", "'CanIHaveSomeCoffee\\TheTVDbAPI\\Route\\RouteInterface'", ",", "$", "classImplements", ")", "===", "false", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Class does not implement the RouteInterface!'", ")", ";", "}", "$", "args", "=", "[", "$", "parent", "]", ";", "static", "::", "$", "routeInstances", "[", "$", "routeClassName", "]", "=", "new", "$", "routeClassName", "(", "...", "$", "args", ")", ";", "}", "return", "static", "::", "$", "routeInstances", "[", "$", "routeClassName", "]", ";", "}" ]
Retrieves an instance of the given routeClassName. @param TheTVDbAPIInterface $parent The parent object that is needed for constructing a new object. @param string $routeClassName The name of the instance to retrieve. @return mixed The requested instance @throws InvalidArgumentException If the given class name does not implement the RouteInterface
[ "Retrieves", "an", "instance", "of", "the", "given", "routeClassName", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/Route/RouteFactory.php#L59-L70
33,084
nails/module-invoice
src/Factory/CompleteRequest.php
CompleteRequest.execute
public function execute($aGetVars, $aPostVars) { // Ensure we have a driver if (empty($this->oDriver)) { throw new CompleteRequestException('No driver selected.', 1); } // Ensure we have a payment if (empty($this->oPayment)) { throw new CompleteRequestException('No payment selected.', 1); } if (empty($this->oInvoice)) { throw new CompleteRequestException('No invoice selected.', 1); } // Execute the completion $oCompleteResponse = $this->oDriver->complete( $this->oPayment, $this->oInvoice, $aGetVars, $aPostVars ); // Validate driver response if (empty($oCompleteResponse)) { throw new CompleteRequestException('Response from driver was empty.', 1); } if (!($oCompleteResponse instanceof CompleteResponse)) { throw new CompleteRequestException( 'Response from driver must be an instance of \Nails\Invoice\Factory\CompleteResponse.', 1 ); } // Handle the response if ($oCompleteResponse->isProcessing()) { // Driver has started processing the charge, but it hasn't been confirmed yet $this->setPaymentProcessing( $oCompleteResponse->getTxnId(), $oCompleteResponse->getFee() ); } elseif ($oCompleteResponse->isComplete()) { // Driver has confirmed that payment has been taken. $this->setPaymentComplete( $oCompleteResponse->getTxnId(), $oCompleteResponse->getFee() ); } elseif ($oCompleteResponse->isFailed()) { /** * Payment failed */ // Update the payment $sPaymentClass = get_class($this->oPaymentModel); $bResult = $this->oPaymentModel->update( $this->oPayment->id, [ 'status' => $sPaymentClass::STATUS_FAILED, 'fail_msg' => $oCompleteResponse->getError()->msg, 'fail_code' => $oCompleteResponse->getError()->code, ] ); if (empty($bResult)) { throw new CompleteRequestException('Failed to update existing payment.', 1); } } // Lock the response so it cannot be altered $oCompleteResponse->lock(); return $oCompleteResponse; }
php
public function execute($aGetVars, $aPostVars) { // Ensure we have a driver if (empty($this->oDriver)) { throw new CompleteRequestException('No driver selected.', 1); } // Ensure we have a payment if (empty($this->oPayment)) { throw new CompleteRequestException('No payment selected.', 1); } if (empty($this->oInvoice)) { throw new CompleteRequestException('No invoice selected.', 1); } // Execute the completion $oCompleteResponse = $this->oDriver->complete( $this->oPayment, $this->oInvoice, $aGetVars, $aPostVars ); // Validate driver response if (empty($oCompleteResponse)) { throw new CompleteRequestException('Response from driver was empty.', 1); } if (!($oCompleteResponse instanceof CompleteResponse)) { throw new CompleteRequestException( 'Response from driver must be an instance of \Nails\Invoice\Factory\CompleteResponse.', 1 ); } // Handle the response if ($oCompleteResponse->isProcessing()) { // Driver has started processing the charge, but it hasn't been confirmed yet $this->setPaymentProcessing( $oCompleteResponse->getTxnId(), $oCompleteResponse->getFee() ); } elseif ($oCompleteResponse->isComplete()) { // Driver has confirmed that payment has been taken. $this->setPaymentComplete( $oCompleteResponse->getTxnId(), $oCompleteResponse->getFee() ); } elseif ($oCompleteResponse->isFailed()) { /** * Payment failed */ // Update the payment $sPaymentClass = get_class($this->oPaymentModel); $bResult = $this->oPaymentModel->update( $this->oPayment->id, [ 'status' => $sPaymentClass::STATUS_FAILED, 'fail_msg' => $oCompleteResponse->getError()->msg, 'fail_code' => $oCompleteResponse->getError()->code, ] ); if (empty($bResult)) { throw new CompleteRequestException('Failed to update existing payment.', 1); } } // Lock the response so it cannot be altered $oCompleteResponse->lock(); return $oCompleteResponse; }
[ "public", "function", "execute", "(", "$", "aGetVars", ",", "$", "aPostVars", ")", "{", "// Ensure we have a driver", "if", "(", "empty", "(", "$", "this", "->", "oDriver", ")", ")", "{", "throw", "new", "CompleteRequestException", "(", "'No driver selected.'", ",", "1", ")", ";", "}", "// Ensure we have a payment", "if", "(", "empty", "(", "$", "this", "->", "oPayment", ")", ")", "{", "throw", "new", "CompleteRequestException", "(", "'No payment selected.'", ",", "1", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "oInvoice", ")", ")", "{", "throw", "new", "CompleteRequestException", "(", "'No invoice selected.'", ",", "1", ")", ";", "}", "// Execute the completion", "$", "oCompleteResponse", "=", "$", "this", "->", "oDriver", "->", "complete", "(", "$", "this", "->", "oPayment", ",", "$", "this", "->", "oInvoice", ",", "$", "aGetVars", ",", "$", "aPostVars", ")", ";", "// Validate driver response", "if", "(", "empty", "(", "$", "oCompleteResponse", ")", ")", "{", "throw", "new", "CompleteRequestException", "(", "'Response from driver was empty.'", ",", "1", ")", ";", "}", "if", "(", "!", "(", "$", "oCompleteResponse", "instanceof", "CompleteResponse", ")", ")", "{", "throw", "new", "CompleteRequestException", "(", "'Response from driver must be an instance of \\Nails\\Invoice\\Factory\\CompleteResponse.'", ",", "1", ")", ";", "}", "// Handle the response", "if", "(", "$", "oCompleteResponse", "->", "isProcessing", "(", ")", ")", "{", "// Driver has started processing the charge, but it hasn't been confirmed yet", "$", "this", "->", "setPaymentProcessing", "(", "$", "oCompleteResponse", "->", "getTxnId", "(", ")", ",", "$", "oCompleteResponse", "->", "getFee", "(", ")", ")", ";", "}", "elseif", "(", "$", "oCompleteResponse", "->", "isComplete", "(", ")", ")", "{", "// Driver has confirmed that payment has been taken.", "$", "this", "->", "setPaymentComplete", "(", "$", "oCompleteResponse", "->", "getTxnId", "(", ")", ",", "$", "oCompleteResponse", "->", "getFee", "(", ")", ")", ";", "}", "elseif", "(", "$", "oCompleteResponse", "->", "isFailed", "(", ")", ")", "{", "/**\n * Payment failed\n */", "// Update the payment", "$", "sPaymentClass", "=", "get_class", "(", "$", "this", "->", "oPaymentModel", ")", ";", "$", "bResult", "=", "$", "this", "->", "oPaymentModel", "->", "update", "(", "$", "this", "->", "oPayment", "->", "id", ",", "[", "'status'", "=>", "$", "sPaymentClass", "::", "STATUS_FAILED", ",", "'fail_msg'", "=>", "$", "oCompleteResponse", "->", "getError", "(", ")", "->", "msg", ",", "'fail_code'", "=>", "$", "oCompleteResponse", "->", "getError", "(", ")", "->", "code", ",", "]", ")", ";", "if", "(", "empty", "(", "$", "bResult", ")", ")", "{", "throw", "new", "CompleteRequestException", "(", "'Failed to update existing payment.'", ",", "1", ")", ";", "}", "}", "// Lock the response so it cannot be altered", "$", "oCompleteResponse", "->", "lock", "(", ")", ";", "return", "$", "oCompleteResponse", ";", "}" ]
Complete the payment @param array $aGetVars Any $_GET variables passed from the redirect flow @param array $aPostVars Any $_POST variables passed from the redirect flow @return \Nails\Invoice\Factory\CompleteResponse @throws CompleteRequestException
[ "Complete", "the", "payment" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Factory/CompleteRequest.php#L58-L137
33,085
orchestral/support
src/Support/Str.php
Str.humanize
public static function humanize(string $text): string { $text = \str_replace(['-', '_'], ' ', $text); return Stringy::create($text)->humanize()->titleize(); }
php
public static function humanize(string $text): string { $text = \str_replace(['-', '_'], ' ', $text); return Stringy::create($text)->humanize()->titleize(); }
[ "public", "static", "function", "humanize", "(", "string", "$", "text", ")", ":", "string", "{", "$", "text", "=", "\\", "str_replace", "(", "[", "'-'", ",", "'_'", "]", ",", "' '", ",", "$", "text", ")", ";", "return", "Stringy", "::", "create", "(", "$", "text", ")", "->", "humanize", "(", ")", "->", "titleize", "(", ")", ";", "}" ]
Convert slug type text to human readable text. @param string $text @return string
[ "Convert", "slug", "type", "text", "to", "human", "readable", "text", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Str.php#L17-L22
33,086
orchestral/support
src/Support/Str.php
Str.streamGetContents
public static function streamGetContents($data): string { // check if it's actually a resource, we can directly convert // string without any issue. if (! \is_resource($data)) { return $data; } // Get the content from stream. $hex = \stream_get_contents($data); // For some reason hex would always start with 'x' and if we // don't filter out this char, it would mess up hex to string // conversion. if (\preg_match('/^x(.*)$/', $hex, $matches)) { $hex = $matches[1]; } // Check if it's actually a hex string before trying to convert. if (! \ctype_xdigit($hex)) { return $hex; } return static::fromHex($hex); }
php
public static function streamGetContents($data): string { // check if it's actually a resource, we can directly convert // string without any issue. if (! \is_resource($data)) { return $data; } // Get the content from stream. $hex = \stream_get_contents($data); // For some reason hex would always start with 'x' and if we // don't filter out this char, it would mess up hex to string // conversion. if (\preg_match('/^x(.*)$/', $hex, $matches)) { $hex = $matches[1]; } // Check if it's actually a hex string before trying to convert. if (! \ctype_xdigit($hex)) { return $hex; } return static::fromHex($hex); }
[ "public", "static", "function", "streamGetContents", "(", "$", "data", ")", ":", "string", "{", "// check if it's actually a resource, we can directly convert", "// string without any issue.", "if", "(", "!", "\\", "is_resource", "(", "$", "data", ")", ")", "{", "return", "$", "data", ";", "}", "// Get the content from stream.", "$", "hex", "=", "\\", "stream_get_contents", "(", "$", "data", ")", ";", "// For some reason hex would always start with 'x' and if we", "// don't filter out this char, it would mess up hex to string", "// conversion.", "if", "(", "\\", "preg_match", "(", "'/^x(.*)$/'", ",", "$", "hex", ",", "$", "matches", ")", ")", "{", "$", "hex", "=", "$", "matches", "[", "1", "]", ";", "}", "// Check if it's actually a hex string before trying to convert.", "if", "(", "!", "\\", "ctype_xdigit", "(", "$", "hex", ")", ")", "{", "return", "$", "hex", ";", "}", "return", "static", "::", "fromHex", "(", "$", "hex", ")", ";", "}" ]
Convert filter to string, this process is required to filter stream data return from Postgres where blob type schema would actually use BYTEA and convert the string to stream. @param mixed $data @return string
[ "Convert", "filter", "to", "string", "this", "process", "is", "required", "to", "filter", "stream", "data", "return", "from", "Postgres", "where", "blob", "type", "schema", "would", "actually", "use", "BYTEA", "and", "convert", "the", "string", "to", "stream", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Str.php#L113-L137
33,087
orchestral/support
src/Support/Str.php
Str.fromHex
protected static function fromHex(string $hex): string { $data = ''; // Convert hex to string. for ($i = 0; $i < \strlen($hex) - 1; $i += 2) { $data .= \chr(\hexdec($hex[$i].$hex[$i + 1])); } return $data; }
php
protected static function fromHex(string $hex): string { $data = ''; // Convert hex to string. for ($i = 0; $i < \strlen($hex) - 1; $i += 2) { $data .= \chr(\hexdec($hex[$i].$hex[$i + 1])); } return $data; }
[ "protected", "static", "function", "fromHex", "(", "string", "$", "hex", ")", ":", "string", "{", "$", "data", "=", "''", ";", "// Convert hex to string.", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "\\", "strlen", "(", "$", "hex", ")", "-", "1", ";", "$", "i", "+=", "2", ")", "{", "$", "data", ".=", "\\", "chr", "(", "\\", "hexdec", "(", "$", "hex", "[", "$", "i", "]", ".", "$", "hex", "[", "$", "i", "+", "1", "]", ")", ")", ";", "}", "return", "$", "data", ";", "}" ]
Convert hex to string. @param string $hex @return string
[ "Convert", "hex", "to", "string", "." ]
b56f0469f967737e39fc9a33d40ae7439f4f6884
https://github.com/orchestral/support/blob/b56f0469f967737e39fc9a33d40ae7439f4f6884/src/Support/Str.php#L146-L156
33,088
QoboLtd/qobo-robo
src/Command/Mysql/Import.php
Import.mysqlImport
public function mysqlImport($db, $file = 'etc/mysql.sql', $user = 'root', $pass = null, $host = null, $port = null, $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskMysqlImport() ->db($db) ->file($file) ->user($user) ->pass($pass) ->host($host) ->port($port) ->hide($pass) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
php
public function mysqlImport($db, $file = 'etc/mysql.sql', $user = 'root', $pass = null, $host = null, $port = null, $opts = ['format' => 'table', 'fields' => '']) { $result = $this->taskMysqlImport() ->db($db) ->file($file) ->user($user) ->pass($pass) ->host($host) ->port($port) ->hide($pass) ->run(); if (!$result->wasSuccessful()) { $this->exitError("Failed to run command"); } return true; }
[ "public", "function", "mysqlImport", "(", "$", "db", ",", "$", "file", "=", "'etc/mysql.sql'", ",", "$", "user", "=", "'root'", ",", "$", "pass", "=", "null", ",", "$", "host", "=", "null", ",", "$", "port", "=", "null", ",", "$", "opts", "=", "[", "'format'", "=>", "'table'", ",", "'fields'", "=>", "''", "]", ")", "{", "$", "result", "=", "$", "this", "->", "taskMysqlImport", "(", ")", "->", "db", "(", "$", "db", ")", "->", "file", "(", "$", "file", ")", "->", "user", "(", "$", "user", ")", "->", "pass", "(", "$", "pass", ")", "->", "host", "(", "$", "host", ")", "->", "port", "(", "$", "port", ")", "->", "hide", "(", "$", "pass", ")", "->", "run", "(", ")", ";", "if", "(", "!", "$", "result", "->", "wasSuccessful", "(", ")", ")", "{", "$", "this", "->", "exitError", "(", "\"Failed to run command\"", ")", ";", "}", "return", "true", ";", "}" ]
Import mysql dump @param string $db Database name @param string $file Destination file for a dump @param string $user MySQL user to bind with @param string $pass (Optional) MySQL user password @param string $host (Optional) MySQL server host @param string $port (Optional) MySQL server port @option string $format Output format (table, list, csv, json, xml) @option string $fields Limit output to given fields, comma-separated @return PropertyList result
[ "Import", "mysql", "dump" ]
ea10f778bb046ad41324d22b27fce5a2fb8915ce
https://github.com/QoboLtd/qobo-robo/blob/ea10f778bb046ad41324d22b27fce5a2fb8915ce/src/Command/Mysql/Import.php#L33-L50
33,089
nails/module-invoice
src/Model/Payment.php
Payment.getStatuses
public function getStatuses() { return [ self::STATUS_PENDING, self::STATUS_PROCESSING, self::STATUS_COMPLETE, self::STATUS_FAILED, self::STATUS_REFUNDED, self::STATUS_REFUNDED_PARTIAL, ]; }
php
public function getStatuses() { return [ self::STATUS_PENDING, self::STATUS_PROCESSING, self::STATUS_COMPLETE, self::STATUS_FAILED, self::STATUS_REFUNDED, self::STATUS_REFUNDED_PARTIAL, ]; }
[ "public", "function", "getStatuses", "(", ")", "{", "return", "[", "self", "::", "STATUS_PENDING", ",", "self", "::", "STATUS_PROCESSING", ",", "self", "::", "STATUS_COMPLETE", ",", "self", "::", "STATUS_FAILED", ",", "self", "::", "STATUS_REFUNDED", ",", "self", "::", "STATUS_REFUNDED_PARTIAL", ",", "]", ";", "}" ]
Returns all the statuses as an array @return array
[ "Returns", "all", "the", "statuses", "as", "an", "array" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L82-L92
33,090
nails/module-invoice
src/Model/Payment.php
Payment.getStatusesHuman
public function getStatusesHuman() { return [ self::STATUS_PENDING => 'Pending', self::STATUS_PROCESSING => 'Processing', self::STATUS_COMPLETE => 'Complete', self::STATUS_FAILED => 'Failed', self::STATUS_REFUNDED => 'Refunded', self::STATUS_REFUNDED_PARTIAL => 'Partially Refunded', ]; }
php
public function getStatusesHuman() { return [ self::STATUS_PENDING => 'Pending', self::STATUS_PROCESSING => 'Processing', self::STATUS_COMPLETE => 'Complete', self::STATUS_FAILED => 'Failed', self::STATUS_REFUNDED => 'Refunded', self::STATUS_REFUNDED_PARTIAL => 'Partially Refunded', ]; }
[ "public", "function", "getStatusesHuman", "(", ")", "{", "return", "[", "self", "::", "STATUS_PENDING", "=>", "'Pending'", ",", "self", "::", "STATUS_PROCESSING", "=>", "'Processing'", ",", "self", "::", "STATUS_COMPLETE", "=>", "'Complete'", ",", "self", "::", "STATUS_FAILED", "=>", "'Failed'", ",", "self", "::", "STATUS_REFUNDED", "=>", "'Refunded'", ",", "self", "::", "STATUS_REFUNDED_PARTIAL", "=>", "'Partially Refunded'", ",", "]", ";", "}" ]
Returns an array of statsues with human friendly labels @return array
[ "Returns", "an", "array", "of", "statsues", "with", "human", "friendly", "labels" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L101-L111
33,091
nails/module-invoice
src/Model/Payment.php
Payment.create
public function create(array $aData = [], $bReturnObject = false) { $oDb = Factory::service('Database'); try { $oDb->trans_begin(); if (empty($aData['ref'])) { $aData['ref'] = $this->generateValidRef(); } $aData['token'] = $this->generateToken(); if (array_key_exists('custom_data', $aData)) { $aData['custom_data'] = json_encode($aData['custom_data']); } $mPayment = parent::create($aData, $bReturnObject); if (!$mPayment) { throw new PaymentException('Failed to create payment.'); } $oDb->trans_commit(); $this->triggerEvent( Events::PAYMENT_CREATED, [$this->getPaymentForEvent($bReturnObject ? $mPayment->id : $mPayment)] ); return $mPayment; } catch (\Exception $e) { $oDb->trans_rollback(); $this->setError($e->getMessage()); return false; } }
php
public function create(array $aData = [], $bReturnObject = false) { $oDb = Factory::service('Database'); try { $oDb->trans_begin(); if (empty($aData['ref'])) { $aData['ref'] = $this->generateValidRef(); } $aData['token'] = $this->generateToken(); if (array_key_exists('custom_data', $aData)) { $aData['custom_data'] = json_encode($aData['custom_data']); } $mPayment = parent::create($aData, $bReturnObject); if (!$mPayment) { throw new PaymentException('Failed to create payment.'); } $oDb->trans_commit(); $this->triggerEvent( Events::PAYMENT_CREATED, [$this->getPaymentForEvent($bReturnObject ? $mPayment->id : $mPayment)] ); return $mPayment; } catch (\Exception $e) { $oDb->trans_rollback(); $this->setError($e->getMessage()); return false; } }
[ "public", "function", "create", "(", "array", "$", "aData", "=", "[", "]", ",", "$", "bReturnObject", "=", "false", ")", "{", "$", "oDb", "=", "Factory", "::", "service", "(", "'Database'", ")", ";", "try", "{", "$", "oDb", "->", "trans_begin", "(", ")", ";", "if", "(", "empty", "(", "$", "aData", "[", "'ref'", "]", ")", ")", "{", "$", "aData", "[", "'ref'", "]", "=", "$", "this", "->", "generateValidRef", "(", ")", ";", "}", "$", "aData", "[", "'token'", "]", "=", "$", "this", "->", "generateToken", "(", ")", ";", "if", "(", "array_key_exists", "(", "'custom_data'", ",", "$", "aData", ")", ")", "{", "$", "aData", "[", "'custom_data'", "]", "=", "json_encode", "(", "$", "aData", "[", "'custom_data'", "]", ")", ";", "}", "$", "mPayment", "=", "parent", "::", "create", "(", "$", "aData", ",", "$", "bReturnObject", ")", ";", "if", "(", "!", "$", "mPayment", ")", "{", "throw", "new", "PaymentException", "(", "'Failed to create payment.'", ")", ";", "}", "$", "oDb", "->", "trans_commit", "(", ")", ";", "$", "this", "->", "triggerEvent", "(", "Events", "::", "PAYMENT_CREATED", ",", "[", "$", "this", "->", "getPaymentForEvent", "(", "$", "bReturnObject", "?", "$", "mPayment", "->", "id", ":", "$", "mPayment", ")", "]", ")", ";", "return", "$", "mPayment", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "oDb", "->", "trans_rollback", "(", ")", ";", "$", "this", "->", "setError", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "}" ]
Create a new payment @param array $aData The data to create the payment with @param boolean $bReturnObject Whether to return the complete payment object @return bool|mixed @throws \Nails\Common\Exception\FactoryException
[ "Create", "a", "new", "payment" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L195-L232
33,092
nails/module-invoice
src/Model/Payment.php
Payment.setPending
public function setPending($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_PENDING; return $this->update($iPaymentId, $aData); }
php
public function setPending($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_PENDING; return $this->update($iPaymentId, $aData); }
[ "public", "function", "setPending", "(", "$", "iPaymentId", ",", "$", "aData", "=", "[", "]", ")", ":", "bool", "{", "$", "aData", "[", "'status'", "]", "=", "self", "::", "STATUS_PENDING", ";", "return", "$", "this", "->", "update", "(", "$", "iPaymentId", ",", "$", "aData", ")", ";", "}" ]
Set a payment as PENDING @param integer $iPaymentId The payment to update @param array $aData Any additional data to save to the transaction @return bool @throws \Nails\Common\Exception\FactoryException
[ "Set", "a", "payment", "as", "PENDING" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L318-L322
33,093
nails/module-invoice
src/Model/Payment.php
Payment.setComplete
public function setComplete($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_COMPLETE; return $this->update($iPaymentId, $aData); }
php
public function setComplete($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_COMPLETE; return $this->update($iPaymentId, $aData); }
[ "public", "function", "setComplete", "(", "$", "iPaymentId", ",", "$", "aData", "=", "[", "]", ")", ":", "bool", "{", "$", "aData", "[", "'status'", "]", "=", "self", "::", "STATUS_COMPLETE", ";", "return", "$", "this", "->", "update", "(", "$", "iPaymentId", ",", "$", "aData", ")", ";", "}" ]
Set a payment as COMPLETE @param integer $iPaymentId The payment to update @param array $aData Any additional data to save to the transaction @return bool @throws \Nails\Common\Exception\FactoryException
[ "Set", "a", "payment", "as", "COMPLETE" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L352-L356
33,094
nails/module-invoice
src/Model/Payment.php
Payment.setFailed
public function setFailed($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_FAILED; return $this->update($iPaymentId, $aData); }
php
public function setFailed($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_FAILED; return $this->update($iPaymentId, $aData); }
[ "public", "function", "setFailed", "(", "$", "iPaymentId", ",", "$", "aData", "=", "[", "]", ")", ":", "bool", "{", "$", "aData", "[", "'status'", "]", "=", "self", "::", "STATUS_FAILED", ";", "return", "$", "this", "->", "update", "(", "$", "iPaymentId", ",", "$", "aData", ")", ";", "}" ]
Set a payment as FAILED @param integer $iPaymentId The payment to update @param array $aData Any additional data to save to the transaction @return bool @throws \Nails\Common\Exception\FactoryException
[ "Set", "a", "payment", "as", "FAILED" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L369-L373
33,095
nails/module-invoice
src/Model/Payment.php
Payment.setRefunded
public function setRefunded($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_REFUNDED; return $this->update($iPaymentId, $aData); }
php
public function setRefunded($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_REFUNDED; return $this->update($iPaymentId, $aData); }
[ "public", "function", "setRefunded", "(", "$", "iPaymentId", ",", "$", "aData", "=", "[", "]", ")", ":", "bool", "{", "$", "aData", "[", "'status'", "]", "=", "self", "::", "STATUS_REFUNDED", ";", "return", "$", "this", "->", "update", "(", "$", "iPaymentId", ",", "$", "aData", ")", ";", "}" ]
Set a payment as REFUNDED @param integer $iPaymentId The payment to update @param array $aData Any additional data to save to the transaction @return bool @throws \Nails\Common\Exception\FactoryException
[ "Set", "a", "payment", "as", "REFUNDED" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L386-L390
33,096
nails/module-invoice
src/Model/Payment.php
Payment.setRefundedPartial
public function setRefundedPartial($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_REFUNDED_PARTIAL; return $this->update($iPaymentId, $aData); }
php
public function setRefundedPartial($iPaymentId, $aData = []): bool { $aData['status'] = self::STATUS_REFUNDED_PARTIAL; return $this->update($iPaymentId, $aData); }
[ "public", "function", "setRefundedPartial", "(", "$", "iPaymentId", ",", "$", "aData", "=", "[", "]", ")", ":", "bool", "{", "$", "aData", "[", "'status'", "]", "=", "self", "::", "STATUS_REFUNDED_PARTIAL", ";", "return", "$", "this", "->", "update", "(", "$", "iPaymentId", ",", "$", "aData", ")", ";", "}" ]
Set a payment as REFUNDED_PARTIAL @param integer $iPaymentId The payment to update @param array $aData Any additional data to save to the transaction @return bool @throws \Nails\Common\Exception\FactoryException
[ "Set", "a", "payment", "as", "REFUNDED_PARTIAL" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L403-L407
33,097
nails/module-invoice
src/Model/Payment.php
Payment.refund
public function refund(int $iPaymentId, int $iAmount = null, string $sReason = null): bool { try { // Validate payment $oPayment = $this->getById($iPaymentId, ['expand' => ['invoice']]); if (!$oPayment) { throw new PaymentException('Invalid payment ID.'); } // Set up RefundRequest object /** @var RefundRequest $oRefundRequest */ $oRefundRequest = Factory::factory('RefundRequest', 'nails/module-invoice'); // Set the driver to use for the request $oRefundRequest->setDriver($oPayment->driver->slug); // Describe the charge $oRefundRequest->setReason($sReason); // Set the payment we're refunding against $oRefundRequest->setPayment($oPayment->id); // Attempt the refund /** @var RefundResponse $oRefundResponse */ $oRefundResponse = $oRefundRequest->execute($iAmount); if ($oRefundResponse->isProcessing() || $oRefundResponse->isComplete()) { // It's all good } elseif ($oRefundResponse->isFailed()) { // Refund failed, throw an error which will be caught and displayed to the user throw new PaymentException('Refund failed: ' . $oRefundResponse->getError()->user); } else { //Something which we've not accounted for went wrong. throw new PaymentException('Refund failed.'); } return true; } catch (PaymentException $e) { $this->setError($e->getMessage()); return false; } }
php
public function refund(int $iPaymentId, int $iAmount = null, string $sReason = null): bool { try { // Validate payment $oPayment = $this->getById($iPaymentId, ['expand' => ['invoice']]); if (!$oPayment) { throw new PaymentException('Invalid payment ID.'); } // Set up RefundRequest object /** @var RefundRequest $oRefundRequest */ $oRefundRequest = Factory::factory('RefundRequest', 'nails/module-invoice'); // Set the driver to use for the request $oRefundRequest->setDriver($oPayment->driver->slug); // Describe the charge $oRefundRequest->setReason($sReason); // Set the payment we're refunding against $oRefundRequest->setPayment($oPayment->id); // Attempt the refund /** @var RefundResponse $oRefundResponse */ $oRefundResponse = $oRefundRequest->execute($iAmount); if ($oRefundResponse->isProcessing() || $oRefundResponse->isComplete()) { // It's all good } elseif ($oRefundResponse->isFailed()) { // Refund failed, throw an error which will be caught and displayed to the user throw new PaymentException('Refund failed: ' . $oRefundResponse->getError()->user); } else { //Something which we've not accounted for went wrong. throw new PaymentException('Refund failed.'); } return true; } catch (PaymentException $e) { $this->setError($e->getMessage()); return false; } }
[ "public", "function", "refund", "(", "int", "$", "iPaymentId", ",", "int", "$", "iAmount", "=", "null", ",", "string", "$", "sReason", "=", "null", ")", ":", "bool", "{", "try", "{", "// Validate payment", "$", "oPayment", "=", "$", "this", "->", "getById", "(", "$", "iPaymentId", ",", "[", "'expand'", "=>", "[", "'invoice'", "]", "]", ")", ";", "if", "(", "!", "$", "oPayment", ")", "{", "throw", "new", "PaymentException", "(", "'Invalid payment ID.'", ")", ";", "}", "// Set up RefundRequest object", "/** @var RefundRequest $oRefundRequest */", "$", "oRefundRequest", "=", "Factory", "::", "factory", "(", "'RefundRequest'", ",", "'nails/module-invoice'", ")", ";", "// Set the driver to use for the request", "$", "oRefundRequest", "->", "setDriver", "(", "$", "oPayment", "->", "driver", "->", "slug", ")", ";", "// Describe the charge", "$", "oRefundRequest", "->", "setReason", "(", "$", "sReason", ")", ";", "// Set the payment we're refunding against", "$", "oRefundRequest", "->", "setPayment", "(", "$", "oPayment", "->", "id", ")", ";", "// Attempt the refund", "/** @var RefundResponse $oRefundResponse */", "$", "oRefundResponse", "=", "$", "oRefundRequest", "->", "execute", "(", "$", "iAmount", ")", ";", "if", "(", "$", "oRefundResponse", "->", "isProcessing", "(", ")", "||", "$", "oRefundResponse", "->", "isComplete", "(", ")", ")", "{", "// It's all good", "}", "elseif", "(", "$", "oRefundResponse", "->", "isFailed", "(", ")", ")", "{", "// Refund failed, throw an error which will be caught and displayed to the user", "throw", "new", "PaymentException", "(", "'Refund failed: '", ".", "$", "oRefundResponse", "->", "getError", "(", ")", "->", "user", ")", ";", "}", "else", "{", "//Something which we've not accounted for went wrong.", "throw", "new", "PaymentException", "(", "'Refund failed.'", ")", ";", "}", "return", "true", ";", "}", "catch", "(", "PaymentException", "$", "e", ")", "{", "$", "this", "->", "setError", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "}" ]
Perform a refund @param int $iPaymentId @param int $iAmount @param string $sReason @return bool @throws ModelException @throws \Nails\Common\Exception\FactoryException @throws \Nails\Invoice\Exception\RefundRequestException @throws \Nails\Invoice\Exception\RequestException
[ "Perform", "a", "refund" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L523-L566
33,098
nails/module-invoice
src/Model/Payment.php
Payment.getPaymentForEvent
protected function getPaymentForEvent(int $iPaymentId): Resource { $oPayment = $this->getById($iPaymentId); if (empty($oPayment)) { throw new ModelException('Invalid payment ID'); } return $oPayment; }
php
protected function getPaymentForEvent(int $iPaymentId): Resource { $oPayment = $this->getById($iPaymentId); if (empty($oPayment)) { throw new ModelException('Invalid payment ID'); } return $oPayment; }
[ "protected", "function", "getPaymentForEvent", "(", "int", "$", "iPaymentId", ")", ":", "Resource", "{", "$", "oPayment", "=", "$", "this", "->", "getById", "(", "$", "iPaymentId", ")", ";", "if", "(", "empty", "(", "$", "oPayment", ")", ")", "{", "throw", "new", "ModelException", "(", "'Invalid payment ID'", ")", ";", "}", "return", "$", "oPayment", ";", "}" ]
Get a payment in a suitable format for the event triggers @param int $iPaymentId The payment ID @return Resource @throws \Nails\Common\Exception\ModelException
[ "Get", "a", "payment", "in", "a", "suitable", "format", "for", "the", "event", "triggers" ]
3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716
https://github.com/nails/module-invoice/blob/3e62067f9de1b0ddb6b0ce0eddeb3eea4ee85716/src/Model/Payment.php#L578-L585
33,099
canihavesomecoffee/theTVDbAPI
src/Route/SeriesRoute.php
SeriesRoute.getLastModified
public function getLastModified(int $id): DateTimeImmutable { $headers = $this->parent->requestHeaders('head', '/series/'.$id); if (array_key_exists('Last-Modified', $headers) && array_key_exists(0, $headers['Last-Modified'])) { $lastModified = DateTimeImmutable::createFromFormat( static::LAST_MODIFIED_FORMAT, $headers['Last-Modified'][0] ); if ($lastModified === false) { throw ParseException::lastModified($headers['Last-Modified'][0]); } return $lastModified; } throw ParseException::missingHeader('Last-Modified'); }
php
public function getLastModified(int $id): DateTimeImmutable { $headers = $this->parent->requestHeaders('head', '/series/'.$id); if (array_key_exists('Last-Modified', $headers) && array_key_exists(0, $headers['Last-Modified'])) { $lastModified = DateTimeImmutable::createFromFormat( static::LAST_MODIFIED_FORMAT, $headers['Last-Modified'][0] ); if ($lastModified === false) { throw ParseException::lastModified($headers['Last-Modified'][0]); } return $lastModified; } throw ParseException::missingHeader('Last-Modified'); }
[ "public", "function", "getLastModified", "(", "int", "$", "id", ")", ":", "DateTimeImmutable", "{", "$", "headers", "=", "$", "this", "->", "parent", "->", "requestHeaders", "(", "'head'", ",", "'/series/'", ".", "$", "id", ")", ";", "if", "(", "array_key_exists", "(", "'Last-Modified'", ",", "$", "headers", ")", "&&", "array_key_exists", "(", "0", ",", "$", "headers", "[", "'Last-Modified'", "]", ")", ")", "{", "$", "lastModified", "=", "DateTimeImmutable", "::", "createFromFormat", "(", "static", "::", "LAST_MODIFIED_FORMAT", ",", "$", "headers", "[", "'Last-Modified'", "]", "[", "0", "]", ")", ";", "if", "(", "$", "lastModified", "===", "false", ")", "{", "throw", "ParseException", "::", "lastModified", "(", "$", "headers", "[", "'Last-Modified'", "]", "[", "0", "]", ")", ";", "}", "return", "$", "lastModified", ";", "}", "throw", "ParseException", "::", "missingHeader", "(", "'Last-Modified'", ")", ";", "}" ]
Fetches the last modified parameter for a series through a HEAD request. @param int $id The id of the series. @return DateTimeImmutable The datetime for when the series was last modified. @throws ParseException is thrown when the header is missing or couldn't be parsed.
[ "Fetches", "the", "last", "modified", "parameter", "for", "a", "series", "through", "a", "HEAD", "request", "." ]
f23f544029269fe2a244818209b060d08654eca6
https://github.com/canihavesomecoffee/theTVDbAPI/blob/f23f544029269fe2a244818209b060d08654eca6/src/Route/SeriesRoute.php#L78-L96