id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
3,200
crip-laravel/core
src/Data/PaginationRepository.php
PaginationRepository.paginate
public function paginate(Model $model, $per_page = 15, array $filters = [], array $columns = ['*']) { $this->onlyTrashed($model); $this->model = $this->relation->apply($this->model, $this); $this->model = $this->filter->apply($this->model, $this, $filters); return $this->model->order()->paginate($per_page, $columns)->toArray(); }
php
public function paginate(Model $model, $per_page = 15, array $filters = [], array $columns = ['*']) { $this->onlyTrashed($model); $this->model = $this->relation->apply($this->model, $this); $this->model = $this->filter->apply($this->model, $this, $filters); return $this->model->order()->paginate($per_page, $columns)->toArray(); }
[ "public", "function", "paginate", "(", "Model", "$", "model", ",", "$", "per_page", "=", "15", ",", "array", "$", "filters", "=", "[", "]", ",", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "this", "->", "onlyTrashed", "(", "$", "model", ")", ";", "$", "this", "->", "model", "=", "$", "this", "->", "relation", "->", "apply", "(", "$", "this", "->", "model", ",", "$", "this", ")", ";", "$", "this", "->", "model", "=", "$", "this", "->", "filter", "->", "apply", "(", "$", "this", "->", "model", ",", "$", "this", ",", "$", "filters", ")", ";", "return", "$", "this", "->", "model", "->", "order", "(", ")", "->", "paginate", "(", "$", "per_page", ",", "$", "columns", ")", "->", "toArray", "(", ")", ";", "}" ]
Eager relations can be taken from request input Filters taken from request @param Model $model @param int $per_page @param array $filters @param array $columns @return array
[ "Eager", "relations", "can", "be", "taken", "from", "request", "input", "Filters", "taken", "from", "request" ]
d58cef97d97fba8b01bec33801452ecbd7c992de
https://github.com/crip-laravel/core/blob/d58cef97d97fba8b01bec33801452ecbd7c992de/src/Data/PaginationRepository.php#L29-L36
3,201
infusephp/rest-api
src/Route/AbstractModelRoute.php
AbstractModelRoute.setModelId
public function setModelId($id) { if (is_array($id)) { $this->modelId = $id; } else { $this->modelId = [$id]; } // rebuild the model instance with ID if ($this->model) { $model = (is_object($this->model)) ? get_class($this->model) : $this->model; $this->model = new $model($id); } return $this; }
php
public function setModelId($id) { if (is_array($id)) { $this->modelId = $id; } else { $this->modelId = [$id]; } // rebuild the model instance with ID if ($this->model) { $model = (is_object($this->model)) ? get_class($this->model) : $this->model; $this->model = new $model($id); } return $this; }
[ "public", "function", "setModelId", "(", "$", "id", ")", "{", "if", "(", "is_array", "(", "$", "id", ")", ")", "{", "$", "this", "->", "modelId", "=", "$", "id", ";", "}", "else", "{", "$", "this", "->", "modelId", "=", "[", "$", "id", "]", ";", "}", "// rebuild the model instance with ID", "if", "(", "$", "this", "->", "model", ")", "{", "$", "model", "=", "(", "is_object", "(", "$", "this", "->", "model", ")", ")", "?", "get_class", "(", "$", "this", "->", "model", ")", ":", "$", "this", "->", "model", ";", "$", "this", "->", "model", "=", "new", "$", "model", "(", "$", "id", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the model ID. @param mixed $id @return $this
[ "Sets", "the", "model", "ID", "." ]
3a02152048ea38ec5f0adaed3f10a17730086ec7
https://github.com/infusephp/rest-api/blob/3a02152048ea38ec5f0adaed3f10a17730086ec7/src/Route/AbstractModelRoute.php#L40-L56
3,202
infusephp/rest-api
src/Route/AbstractModelRoute.php
AbstractModelRoute.setModel
public function setModel($model) { // convert the model class into an instance if (!is_object($model)) { $this->modelClass = $model; $model = new $model($this->modelId); } else { $this->modelId = $model->ids(); $this->modelClass = get_class($model); } $this->model = $model; return $this; }
php
public function setModel($model) { // convert the model class into an instance if (!is_object($model)) { $this->modelClass = $model; $model = new $model($this->modelId); } else { $this->modelId = $model->ids(); $this->modelClass = get_class($model); } $this->model = $model; return $this; }
[ "public", "function", "setModel", "(", "$", "model", ")", "{", "// convert the model class into an instance", "if", "(", "!", "is_object", "(", "$", "model", ")", ")", "{", "$", "this", "->", "modelClass", "=", "$", "model", ";", "$", "model", "=", "new", "$", "model", "(", "$", "this", "->", "modelId", ")", ";", "}", "else", "{", "$", "this", "->", "modelId", "=", "$", "model", "->", "ids", "(", ")", ";", "$", "this", "->", "modelClass", "=", "get_class", "(", "$", "model", ")", ";", "}", "$", "this", "->", "model", "=", "$", "model", ";", "return", "$", "this", ";", "}" ]
Sets the model for this route. @param \Pulsar\Model|string $model @return $this
[ "Sets", "the", "model", "for", "this", "route", "." ]
3a02152048ea38ec5f0adaed3f10a17730086ec7
https://github.com/infusephp/rest-api/blob/3a02152048ea38ec5f0adaed3f10a17730086ec7/src/Route/AbstractModelRoute.php#L75-L89
3,203
infusephp/rest-api
src/Route/AbstractModelRoute.php
AbstractModelRoute.getFirstError
public function getFirstError() { if (!$this->model) { return false; } $errors = $this->model->getErrors()->errors(); return (count($errors) > 0) ? $errors[0] : false; }
php
public function getFirstError() { if (!$this->model) { return false; } $errors = $this->model->getErrors()->errors(); return (count($errors) > 0) ? $errors[0] : false; }
[ "public", "function", "getFirstError", "(", ")", "{", "if", "(", "!", "$", "this", "->", "model", ")", "{", "return", "false", ";", "}", "$", "errors", "=", "$", "this", "->", "model", "->", "getErrors", "(", ")", "->", "errors", "(", ")", ";", "return", "(", "count", "(", "$", "errors", ")", ">", "0", ")", "?", "$", "errors", "[", "0", "]", ":", "false", ";", "}" ]
Gets the first error off the error stack. @return array|false
[ "Gets", "the", "first", "error", "off", "the", "error", "stack", "." ]
3a02152048ea38ec5f0adaed3f10a17730086ec7
https://github.com/infusephp/rest-api/blob/3a02152048ea38ec5f0adaed3f10a17730086ec7/src/Route/AbstractModelRoute.php#L121-L130
3,204
infusephp/rest-api
src/Route/AbstractModelRoute.php
AbstractModelRoute.modelValidationError
protected function modelValidationError(array $error) { $code = ('no_permission' == $error['error']) ? 403 : 400; $param = array_value($error, 'params.field'); return new InvalidRequest($error['message'], $code, $param); }
php
protected function modelValidationError(array $error) { $code = ('no_permission' == $error['error']) ? 403 : 400; $param = array_value($error, 'params.field'); return new InvalidRequest($error['message'], $code, $param); }
[ "protected", "function", "modelValidationError", "(", "array", "$", "error", ")", "{", "$", "code", "=", "(", "'no_permission'", "==", "$", "error", "[", "'error'", "]", ")", "?", "403", ":", "400", ";", "$", "param", "=", "array_value", "(", "$", "error", ",", "'params.field'", ")", ";", "return", "new", "InvalidRequest", "(", "$", "error", "[", "'message'", "]", ",", "$", "code", ",", "$", "param", ")", ";", "}" ]
Builds a validation error from a CRUD operation. @param array $error @return InvalidRequest
[ "Builds", "a", "validation", "error", "from", "a", "CRUD", "operation", "." ]
3a02152048ea38ec5f0adaed3f10a17730086ec7
https://github.com/infusephp/rest-api/blob/3a02152048ea38ec5f0adaed3f10a17730086ec7/src/Route/AbstractModelRoute.php#L139-L145
3,205
infusephp/rest-api
src/Route/AbstractModelRoute.php
AbstractModelRoute.retrieveModel
public function retrieveModel() { if ($this->model->persisted()) { return; } $modelClass = $this->modelClass; $this->model = $modelClass::find($this->modelId); if (!$this->model) { throw $this->modelNotFoundError(); } }
php
public function retrieveModel() { if ($this->model->persisted()) { return; } $modelClass = $this->modelClass; $this->model = $modelClass::find($this->modelId); if (!$this->model) { throw $this->modelNotFoundError(); } }
[ "public", "function", "retrieveModel", "(", ")", "{", "if", "(", "$", "this", "->", "model", "->", "persisted", "(", ")", ")", "{", "return", ";", "}", "$", "modelClass", "=", "$", "this", "->", "modelClass", ";", "$", "this", "->", "model", "=", "$", "modelClass", "::", "find", "(", "$", "this", "->", "modelId", ")", ";", "if", "(", "!", "$", "this", "->", "model", ")", "{", "throw", "$", "this", "->", "modelNotFoundError", "(", ")", ";", "}", "}" ]
Retrieves the model associated on this class with the persisted version from the data layer. @throws InvalidRequest if the model cannot be found
[ "Retrieves", "the", "model", "associated", "on", "this", "class", "with", "the", "persisted", "version", "from", "the", "data", "layer", "." ]
3a02152048ea38ec5f0adaed3f10a17730086ec7
https://github.com/infusephp/rest-api/blob/3a02152048ea38ec5f0adaed3f10a17730086ec7/src/Route/AbstractModelRoute.php#L153-L165
3,206
charsme/simple-http
src/Uri.php
Uri.withString
protected function withString ($string, $name = 'query') { if (!is_string($string) && !method_exists($string, '__toString')) { throw new InvalidArgumentException('Uri fragment must be a string'); } $string = ltrim((string) $string, '#'); $clone = clone $this; $clone->$name = $this->filterQuery($string); return $clone; }
php
protected function withString ($string, $name = 'query') { if (!is_string($string) && !method_exists($string, '__toString')) { throw new InvalidArgumentException('Uri fragment must be a string'); } $string = ltrim((string) $string, '#'); $clone = clone $this; $clone->$name = $this->filterQuery($string); return $clone; }
[ "protected", "function", "withString", "(", "$", "string", ",", "$", "name", "=", "'query'", ")", "{", "if", "(", "!", "is_string", "(", "$", "string", ")", "&&", "!", "method_exists", "(", "$", "string", ",", "'__toString'", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Uri fragment must be a string'", ")", ";", "}", "$", "string", "=", "ltrim", "(", "(", "string", ")", "$", "string", ",", "'#'", ")", ";", "$", "clone", "=", "clone", "$", "this", ";", "$", "clone", "->", "$", "name", "=", "$", "this", "->", "filterQuery", "(", "$", "string", ")", ";", "return", "$", "clone", ";", "}" ]
withString function. @access protected @param string $string @param string $name (default: 'query') @return Uri
[ "withString", "function", "." ]
b811338f12d3303d63eb4f6b2f2ffab931cc7906
https://github.com/charsme/simple-http/blob/b811338f12d3303d63eb4f6b2f2ffab931cc7906/src/Uri.php#L248-L258
3,207
monetise/money
library/Money/MoneyTrait.php
MoneyTrait.setAmount
public function setAmount($amount) { if ($amount === null) { $this->amount = 0; return $this; } if (!is_int($amount)) { throw new InvalidArgumentException(sprintf( 'Amount must be an integer, "%s" given', is_object($amount) ? get_class($amount) : gettype($amount) )); } // Overflow check is not necessary because we have an integer $this->amount = $amount; return $this; }
php
public function setAmount($amount) { if ($amount === null) { $this->amount = 0; return $this; } if (!is_int($amount)) { throw new InvalidArgumentException(sprintf( 'Amount must be an integer, "%s" given', is_object($amount) ? get_class($amount) : gettype($amount) )); } // Overflow check is not necessary because we have an integer $this->amount = $amount; return $this; }
[ "public", "function", "setAmount", "(", "$", "amount", ")", "{", "if", "(", "$", "amount", "===", "null", ")", "{", "$", "this", "->", "amount", "=", "0", ";", "return", "$", "this", ";", "}", "if", "(", "!", "is_int", "(", "$", "amount", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Amount must be an integer, \"%s\" given'", ",", "is_object", "(", "$", "amount", ")", "?", "get_class", "(", "$", "amount", ")", ":", "gettype", "(", "$", "amount", ")", ")", ")", ";", "}", "// Overflow check is not necessary because we have an integer", "$", "this", "->", "amount", "=", "$", "amount", ";", "return", "$", "this", ";", "}" ]
Set the monetary value represented by this object @param int|null $amount @return $this
[ "Set", "the", "monetary", "value", "represented", "by", "this", "object" ]
f1c2e6fef3099dded16cc70f0cee449575952b5b
https://github.com/monetise/money/blob/f1c2e6fef3099dded16cc70f0cee449575952b5b/library/Money/MoneyTrait.php#L47-L64
3,208
monetise/money
library/Money/MoneyTrait.php
MoneyTrait.setCurrency
public function setCurrency($currency) { if ($currency) { $currency = strtoupper($currency); Currency::getNumericCode($currency); // ensure currency support $this->currency = $currency; } else { $this->currency = null; } return $this; }
php
public function setCurrency($currency) { if ($currency) { $currency = strtoupper($currency); Currency::getNumericCode($currency); // ensure currency support $this->currency = $currency; } else { $this->currency = null; } return $this; }
[ "public", "function", "setCurrency", "(", "$", "currency", ")", "{", "if", "(", "$", "currency", ")", "{", "$", "currency", "=", "strtoupper", "(", "$", "currency", ")", ";", "Currency", "::", "getNumericCode", "(", "$", "currency", ")", ";", "// ensure currency support", "$", "this", "->", "currency", "=", "$", "currency", ";", "}", "else", "{", "$", "this", "->", "currency", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
Set the currency of the monetary value represented by this object @param string|null $currency @return $this
[ "Set", "the", "currency", "of", "the", "monetary", "value", "represented", "by", "this", "object" ]
f1c2e6fef3099dded16cc70f0cee449575952b5b
https://github.com/monetise/money/blob/f1c2e6fef3099dded16cc70f0cee449575952b5b/library/Money/MoneyTrait.php#L100-L111
3,209
monetise/money
library/Money/MoneyTrait.php
MoneyTrait.compareTo
public function compareTo(MoneyInterface $money) { if ($this->currency !== $money->getCurrency()) { throw new CurrencyMismatchException('Operations between different currencies are not supported.'); } if ($this->amount == $money->getAmount()) { return 0; } return $this->amount < $money->getAmount() ? -1 : 1; }
php
public function compareTo(MoneyInterface $money) { if ($this->currency !== $money->getCurrency()) { throw new CurrencyMismatchException('Operations between different currencies are not supported.'); } if ($this->amount == $money->getAmount()) { return 0; } return $this->amount < $money->getAmount() ? -1 : 1; }
[ "public", "function", "compareTo", "(", "MoneyInterface", "$", "money", ")", "{", "if", "(", "$", "this", "->", "currency", "!==", "$", "money", "->", "getCurrency", "(", ")", ")", "{", "throw", "new", "CurrencyMismatchException", "(", "'Operations between different currencies are not supported.'", ")", ";", "}", "if", "(", "$", "this", "->", "amount", "==", "$", "money", "->", "getAmount", "(", ")", ")", "{", "return", "0", ";", "}", "return", "$", "this", "->", "amount", "<", "$", "money", "->", "getAmount", "(", ")", "?", "-", "1", ":", "1", ";", "}" ]
Compares this object with another Returns an integer less than, equal to, or greater than zero if the value of this MoneyInterface object is considered to be respectively less than, equal to, or greater than the other MoneyInterface object. @param MoneyInterface $money @throws InvalidArgumentException @return int
[ "Compares", "this", "object", "with", "another" ]
f1c2e6fef3099dded16cc70f0cee449575952b5b
https://github.com/monetise/money/blob/f1c2e6fef3099dded16cc70f0cee449575952b5b/library/Money/MoneyTrait.php#L134-L145
3,210
monetise/money
library/Money/MoneyTrait.php
MoneyTrait.add
public function add(MoneyInterface $money) { if ($this->currency !== $money->getCurrency()) { throw new CurrencyMismatchException('Operations between different currencies are not supported'); } $this->amount = $this->toInt($this->amount + $money->getAmount()); return $this; }
php
public function add(MoneyInterface $money) { if ($this->currency !== $money->getCurrency()) { throw new CurrencyMismatchException('Operations between different currencies are not supported'); } $this->amount = $this->toInt($this->amount + $money->getAmount()); return $this; }
[ "public", "function", "add", "(", "MoneyInterface", "$", "money", ")", "{", "if", "(", "$", "this", "->", "currency", "!==", "$", "money", "->", "getCurrency", "(", ")", ")", "{", "throw", "new", "CurrencyMismatchException", "(", "'Operations between different currencies are not supported'", ")", ";", "}", "$", "this", "->", "amount", "=", "$", "this", "->", "toInt", "(", "$", "this", "->", "amount", "+", "$", "money", "->", "getAmount", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Add the monetary value of another MoneyInterface object to this object @param MoneyInterface $money @return $this
[ "Add", "the", "monetary", "value", "of", "another", "MoneyInterface", "object", "to", "this", "object" ]
f1c2e6fef3099dded16cc70f0cee449575952b5b
https://github.com/monetise/money/blob/f1c2e6fef3099dded16cc70f0cee449575952b5b/library/Money/MoneyTrait.php#L177-L185
3,211
monetise/money
library/Money/MoneyTrait.php
MoneyTrait.multiply
public function multiply($factor, $roundingMode = PHP_ROUND_HALF_UP) { if ($factor instanceof DecimalNumberInterface) { $factor = $factor->toFloat(); } $this->amount = $this->toInt( round($factor * $this->amount, 0, $roundingMode) ); return $this; }
php
public function multiply($factor, $roundingMode = PHP_ROUND_HALF_UP) { if ($factor instanceof DecimalNumberInterface) { $factor = $factor->toFloat(); } $this->amount = $this->toInt( round($factor * $this->amount, 0, $roundingMode) ); return $this; }
[ "public", "function", "multiply", "(", "$", "factor", ",", "$", "roundingMode", "=", "PHP_ROUND_HALF_UP", ")", "{", "if", "(", "$", "factor", "instanceof", "DecimalNumberInterface", ")", "{", "$", "factor", "=", "$", "factor", "->", "toFloat", "(", ")", ";", "}", "$", "this", "->", "amount", "=", "$", "this", "->", "toInt", "(", "round", "(", "$", "factor", "*", "$", "this", "->", "amount", ",", "0", ",", "$", "roundingMode", ")", ")", ";", "return", "$", "this", ";", "}" ]
Multiply the monetary value of this object by a given factor @param float|DecimalNumberInterface $factor @param int $roundingMode @return $this
[ "Multiply", "the", "monetary", "value", "of", "this", "object", "by", "a", "given", "factor" ]
f1c2e6fef3099dded16cc70f0cee449575952b5b
https://github.com/monetise/money/blob/f1c2e6fef3099dded16cc70f0cee449575952b5b/library/Money/MoneyTrait.php#L210-L220
3,212
monetise/money
library/Money/MoneyTrait.php
MoneyTrait.fromFloat
public function fromFloat($amount, $currency = null) { if ($currency) { $this->setCurrency($currency); } if (!is_float($amount)) { throw new InvalidArgumentException(sprintf( 'Amount must be a float, %s given', gettype($amount) )); } $this->amount = $this->toInt( round( $this->getSubUnit() * round($amount, $this->getFractionDigits(), PHP_ROUND_HALF_UP), 0, PHP_ROUND_HALF_UP ) ); return $this; }
php
public function fromFloat($amount, $currency = null) { if ($currency) { $this->setCurrency($currency); } if (!is_float($amount)) { throw new InvalidArgumentException(sprintf( 'Amount must be a float, %s given', gettype($amount) )); } $this->amount = $this->toInt( round( $this->getSubUnit() * round($amount, $this->getFractionDigits(), PHP_ROUND_HALF_UP), 0, PHP_ROUND_HALF_UP ) ); return $this; }
[ "public", "function", "fromFloat", "(", "$", "amount", ",", "$", "currency", "=", "null", ")", "{", "if", "(", "$", "currency", ")", "{", "$", "this", "->", "setCurrency", "(", "$", "currency", ")", ";", "}", "if", "(", "!", "is_float", "(", "$", "amount", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Amount must be a float, %s given'", ",", "gettype", "(", "$", "amount", ")", ")", ")", ";", "}", "$", "this", "->", "amount", "=", "$", "this", "->", "toInt", "(", "round", "(", "$", "this", "->", "getSubUnit", "(", ")", "*", "round", "(", "$", "amount", ",", "$", "this", "->", "getFractionDigits", "(", ")", ",", "PHP_ROUND_HALF_UP", ")", ",", "0", ",", "PHP_ROUND_HALF_UP", ")", ")", ";", "return", "$", "this", ";", "}" ]
Populate current amount from a given float value @param float $amount @param string $currency @return $this
[ "Populate", "current", "amount", "from", "a", "given", "float", "value" ]
f1c2e6fef3099dded16cc70f0cee449575952b5b
https://github.com/monetise/money/blob/f1c2e6fef3099dded16cc70f0cee449575952b5b/library/Money/MoneyTrait.php#L239-L260
3,213
calgamo/kernel
src/Bootstrap/MountedBootstrap.php
MountedBootstrap.newApp
public function newApp(string $app_type, ApplicationFactoryInterface $app_factory) : ApplicationInterface { return $app_factory->createApplication($app_type, $this->fs); }
php
public function newApp(string $app_type, ApplicationFactoryInterface $app_factory) : ApplicationInterface { return $app_factory->createApplication($app_type, $this->fs); }
[ "public", "function", "newApp", "(", "string", "$", "app_type", ",", "ApplicationFactoryInterface", "$", "app_factory", ")", ":", "ApplicationInterface", "{", "return", "$", "app_factory", "->", "createApplication", "(", "$", "app_type", ",", "$", "this", "->", "fs", ")", ";", "}" ]
Create new application @param string $app_type @param ApplicationFactoryInterface $app_factory @return ApplicationInterface
[ "Create", "new", "application" ]
e57fa7a6283afdca4a6a72b205306ed1e3a4b6c5
https://github.com/calgamo/kernel/blob/e57fa7a6283afdca4a6a72b205306ed1e3a4b6c5/src/Bootstrap/MountedBootstrap.php#L35-L38
3,214
fabsgc/framework
Core/Security/Spam.php
Spam._exception
protected function _exception() { $url = '.' . $this->request->src . '.' . $this->request->controller . '.' . $this->request->action; if (in_array($url, $this->config['user']['security']['spam']['config']['exception'])) { $this->_exception = true; } return $this->_exception; }
php
protected function _exception() { $url = '.' . $this->request->src . '.' . $this->request->controller . '.' . $this->request->action; if (in_array($url, $this->config['user']['security']['spam']['config']['exception'])) { $this->_exception = true; } return $this->_exception; }
[ "protected", "function", "_exception", "(", ")", "{", "$", "url", "=", "'.'", ".", "$", "this", "->", "request", "->", "src", ".", "'.'", ".", "$", "this", "->", "request", "->", "controller", ".", "'.'", ".", "$", "this", "->", "request", "->", "action", ";", "if", "(", "in_array", "(", "$", "url", ",", "$", "this", "->", "config", "[", "'user'", "]", "[", "'security'", "]", "[", "'spam'", "]", "[", "'config'", "]", "[", "'exception'", "]", ")", ")", "{", "$", "this", "->", "_exception", "=", "true", ";", "}", "return", "$", "this", "->", "_exception", ";", "}" ]
check if the url is a spam exception @access public @return boolean @since 3.0 @package Gcs\Framework\Core\Security
[ "check", "if", "the", "url", "is", "a", "spam", "exception" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Security/Spam.php#L135-L143
3,215
fabsgc/framework
Core/Security/Spam.php
Spam._ips
protected function _ips() { if ($this->_cache->isExist()) { $this->_ips = $this->_cache->getCache(); } else { $this->_ips = [$this->_ip => ['time' => time(), 'number' => 1]]; } }
php
protected function _ips() { if ($this->_cache->isExist()) { $this->_ips = $this->_cache->getCache(); } else { $this->_ips = [$this->_ip => ['time' => time(), 'number' => 1]]; } }
[ "protected", "function", "_ips", "(", ")", "{", "if", "(", "$", "this", "->", "_cache", "->", "isExist", "(", ")", ")", "{", "$", "this", "->", "_ips", "=", "$", "this", "->", "_cache", "->", "getCache", "(", ")", ";", "}", "else", "{", "$", "this", "->", "_ips", "=", "[", "$", "this", "->", "_ip", "=>", "[", "'time'", "=>", "time", "(", ")", ",", "'number'", "=>", "1", "]", "]", ";", "}", "}" ]
get the the list of IPs @access public @return void @since 3.0 @package Gcs\Framework\Core\Security
[ "get", "the", "the", "list", "of", "IPs" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Security/Spam.php#L153-L160
3,216
fabsgc/framework
Core/Security/Spam.php
Spam._updateIp
protected function _updateIp($time = 0, $number = 1) { $this->_ips[$this->_ip] = ['time' => $time, 'number' => $number]; $this->_cache->setContent($this->_ips); $this->_cache->setCache(); }
php
protected function _updateIp($time = 0, $number = 1) { $this->_ips[$this->_ip] = ['time' => $time, 'number' => $number]; $this->_cache->setContent($this->_ips); $this->_cache->setCache(); }
[ "protected", "function", "_updateIp", "(", "$", "time", "=", "0", ",", "$", "number", "=", "1", ")", "{", "$", "this", "->", "_ips", "[", "$", "this", "->", "_ip", "]", "=", "[", "'time'", "=>", "$", "time", ",", "'number'", "=>", "$", "number", "]", ";", "$", "this", "->", "_cache", "->", "setContent", "(", "$", "this", "->", "_ips", ")", ";", "$", "this", "->", "_cache", "->", "setCache", "(", ")", ";", "}" ]
update time and number attribute from IP @access public @param int $time @param int $number @return void @since 3.0 @package Gcs\Framework\Core\Security
[ "update", "time", "and", "number", "attribute", "from", "IP" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Security/Spam.php#L172-L177
3,217
rafaelnajera/matcher
Matcher/ParallelMatcher.php
ParallelMatcher.match
public function match($input) { $noMatch = true; foreach ($this->matchers as $matcher) { if ($matcher->noMatch()) { continue; } if ($matcher->match($input)) { $noMatch = false; } if ($matcher->matchFound()) { $this->matched[] = $matcher->matched; $this->resetMatchers(); break; } } if ($noMatch) { return false; } return true; }
php
public function match($input) { $noMatch = true; foreach ($this->matchers as $matcher) { if ($matcher->noMatch()) { continue; } if ($matcher->match($input)) { $noMatch = false; } if ($matcher->matchFound()) { $this->matched[] = $matcher->matched; $this->resetMatchers(); break; } } if ($noMatch) { return false; } return true; }
[ "public", "function", "match", "(", "$", "input", ")", "{", "$", "noMatch", "=", "true", ";", "foreach", "(", "$", "this", "->", "matchers", "as", "$", "matcher", ")", "{", "if", "(", "$", "matcher", "->", "noMatch", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "matcher", "->", "match", "(", "$", "input", ")", ")", "{", "$", "noMatch", "=", "false", ";", "}", "if", "(", "$", "matcher", "->", "matchFound", "(", ")", ")", "{", "$", "this", "->", "matched", "[", "]", "=", "$", "matcher", "->", "matched", ";", "$", "this", "->", "resetMatchers", "(", ")", ";", "break", ";", "}", "}", "if", "(", "$", "noMatch", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Attempts to match an input token with the patterns @param any|Token $input
[ "Attempts", "to", "match", "an", "input", "token", "with", "the", "patterns" ]
f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf
https://github.com/rafaelnajera/matcher/blob/f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf/Matcher/ParallelMatcher.php#L85-L106
3,218
rafaelnajera/matcher
Matcher/ParallelMatcher.php
ParallelMatcher.matchArray
public function matchArray(array $tokens, $reset = true) { if ($reset) { $this->reset(); } foreach ($tokens as $t) { if (!$this->match($t)) { return false; } } return true; }
php
public function matchArray(array $tokens, $reset = true) { if ($reset) { $this->reset(); } foreach ($tokens as $t) { if (!$this->match($t)) { return false; } } return true; }
[ "public", "function", "matchArray", "(", "array", "$", "tokens", ",", "$", "reset", "=", "true", ")", "{", "if", "(", "$", "reset", ")", "{", "$", "this", "->", "reset", "(", ")", ";", "}", "foreach", "(", "$", "tokens", "as", "$", "t", ")", "{", "if", "(", "!", "$", "this", "->", "match", "(", "$", "t", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Matches an array of tokens against the configured patterns Returns true if there were no mismatches in the input array. The total number of matches can be found with numMatches() @param array $tokens @param boolean $reset @return boolean
[ "Matches", "an", "array", "of", "tokens", "against", "the", "configured", "patterns" ]
f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf
https://github.com/rafaelnajera/matcher/blob/f8fb4cf5c4969d8ef7b7377384e972fc3ef9e2cf/Matcher/ParallelMatcher.php#L119-L130
3,219
Webiny/Hrc
src/Webiny/Hrc/CacheStorage/Mongo.php
Mongo.installCollections
public function installCollections() { $collections = $this->mongoInstance->listCollections(); foreach ($collections as $collection) { /* @var $collection CollectionInfo */ if ($collection->getName() == self::collection) { return true; } } $this->mongoInstance->createCollection(self::collection); $this->mongoInstance->createIndex(self::collection, new SingleIndex('key', 'key', false, true)); $this->mongoInstance->createIndex(self::collection, new SingleIndex('ttl', 'ttl', false, false, false, 0)); return true; }
php
public function installCollections() { $collections = $this->mongoInstance->listCollections(); foreach ($collections as $collection) { /* @var $collection CollectionInfo */ if ($collection->getName() == self::collection) { return true; } } $this->mongoInstance->createCollection(self::collection); $this->mongoInstance->createIndex(self::collection, new SingleIndex('key', 'key', false, true)); $this->mongoInstance->createIndex(self::collection, new SingleIndex('ttl', 'ttl', false, false, false, 0)); return true; }
[ "public", "function", "installCollections", "(", ")", "{", "$", "collections", "=", "$", "this", "->", "mongoInstance", "->", "listCollections", "(", ")", ";", "foreach", "(", "$", "collections", "as", "$", "collection", ")", "{", "/* @var $collection CollectionInfo */", "if", "(", "$", "collection", "->", "getName", "(", ")", "==", "self", "::", "collection", ")", "{", "return", "true", ";", "}", "}", "$", "this", "->", "mongoInstance", "->", "createCollection", "(", "self", "::", "collection", ")", ";", "$", "this", "->", "mongoInstance", "->", "createIndex", "(", "self", "::", "collection", ",", "new", "SingleIndex", "(", "'key'", ",", "'key'", ",", "false", ",", "true", ")", ")", ";", "$", "this", "->", "mongoInstance", "->", "createIndex", "(", "self", "::", "collection", ",", "new", "SingleIndex", "(", "'ttl'", ",", "'ttl'", ",", "false", ",", "false", ",", "false", ",", "0", ")", ")", ";", "return", "true", ";", "}" ]
Installs the required mongo collection for cache storage and creates the required indexes. @return bool
[ "Installs", "the", "required", "mongo", "collection", "for", "cache", "storage", "and", "creates", "the", "required", "indexes", "." ]
2594d645dd79a579916d90ec93ce815bd413558f
https://github.com/Webiny/Hrc/blob/2594d645dd79a579916d90ec93ce815bd413558f/src/Webiny/Hrc/CacheStorage/Mongo.php#L103-L120
3,220
railsphp/framework
src/Rails/ActiveRecord/Schema/Column/Boolean.php
Boolean.getExpressionData
public function getExpressionData() { $data = parent::getExpressionData(); if ($this->default !== null) { $data[0][0] .= ' DEFAULT %s'; $data[0][1][] = $this->default; $data[0][2][] = self::TYPE_VALUE; } return $data; }
php
public function getExpressionData() { $data = parent::getExpressionData(); if ($this->default !== null) { $data[0][0] .= ' DEFAULT %s'; $data[0][1][] = $this->default; $data[0][2][] = self::TYPE_VALUE; } return $data; }
[ "public", "function", "getExpressionData", "(", ")", "{", "$", "data", "=", "parent", "::", "getExpressionData", "(", ")", ";", "if", "(", "$", "this", "->", "default", "!==", "null", ")", "{", "$", "data", "[", "0", "]", "[", "0", "]", ".=", "' DEFAULT %s'", ";", "$", "data", "[", "0", "]", "[", "1", "]", "[", "]", "=", "$", "this", "->", "default", ";", "$", "data", "[", "0", "]", "[", "2", "]", "[", "]", "=", "self", "::", "TYPE_VALUE", ";", "}", "return", "$", "data", ";", "}" ]
Adds default option.
[ "Adds", "default", "option", "." ]
2ac9d3e493035dcc68f3c3812423327127327cd5
https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActiveRecord/Schema/Column/Boolean.php#L11-L22
3,221
tsufeki/kayo-json-mapper
src/Tsufeki/KayoJsonMapper/MetadataProvider/CallableUtils.php
CallableUtils.getKey
public static function getKey($callable) { /** @var string|null $class */ $class = null; /** @var string|null $method */ $method = null; if (is_string($callable)) { $method = $callable; // works for 'Cls::method' case as well } elseif (is_array($callable)) { $class = is_object($callable[0]) ? get_class($callable[0]) : $callable[0]; $method = $callable[1]; } elseif (is_object($callable)) { if ($callable instanceof \ReflectionFunctionAbstract) { if ($callable->isClosure()) { return null; } $class = $callable instanceof \ReflectionMethod ? $callable->class : null; $method = $callable->name; } else { if ($callable instanceof \Closure) { return null; } $class = get_class($callable); $method = '__invoke'; } } return strtolower(($class ? $class . '::' : '') . $method); }
php
public static function getKey($callable) { /** @var string|null $class */ $class = null; /** @var string|null $method */ $method = null; if (is_string($callable)) { $method = $callable; // works for 'Cls::method' case as well } elseif (is_array($callable)) { $class = is_object($callable[0]) ? get_class($callable[0]) : $callable[0]; $method = $callable[1]; } elseif (is_object($callable)) { if ($callable instanceof \ReflectionFunctionAbstract) { if ($callable->isClosure()) { return null; } $class = $callable instanceof \ReflectionMethod ? $callable->class : null; $method = $callable->name; } else { if ($callable instanceof \Closure) { return null; } $class = get_class($callable); $method = '__invoke'; } } return strtolower(($class ? $class . '::' : '') . $method); }
[ "public", "static", "function", "getKey", "(", "$", "callable", ")", "{", "/** @var string|null $class */", "$", "class", "=", "null", ";", "/** @var string|null $method */", "$", "method", "=", "null", ";", "if", "(", "is_string", "(", "$", "callable", ")", ")", "{", "$", "method", "=", "$", "callable", ";", "// works for 'Cls::method' case as well", "}", "elseif", "(", "is_array", "(", "$", "callable", ")", ")", "{", "$", "class", "=", "is_object", "(", "$", "callable", "[", "0", "]", ")", "?", "get_class", "(", "$", "callable", "[", "0", "]", ")", ":", "$", "callable", "[", "0", "]", ";", "$", "method", "=", "$", "callable", "[", "1", "]", ";", "}", "elseif", "(", "is_object", "(", "$", "callable", ")", ")", "{", "if", "(", "$", "callable", "instanceof", "\\", "ReflectionFunctionAbstract", ")", "{", "if", "(", "$", "callable", "->", "isClosure", "(", ")", ")", "{", "return", "null", ";", "}", "$", "class", "=", "$", "callable", "instanceof", "\\", "ReflectionMethod", "?", "$", "callable", "->", "class", ":", "null", ";", "$", "method", "=", "$", "callable", "->", "name", ";", "}", "else", "{", "if", "(", "$", "callable", "instanceof", "\\", "Closure", ")", "{", "return", "null", ";", "}", "$", "class", "=", "get_class", "(", "$", "callable", ")", ";", "$", "method", "=", "'__invoke'", ";", "}", "}", "return", "strtolower", "(", "(", "$", "class", "?", "$", "class", ".", "'::'", ":", "''", ")", ".", "$", "method", ")", ";", "}" ]
Return unique string key for given callable or null for closures. @param callable|\ReflectionFunctionAbstract $callable @return string|null
[ "Return", "unique", "string", "key", "for", "given", "callable", "or", "null", "for", "closures", "." ]
e1ef374883fb97ebc7c2c4e0a6699b89e0ab6c01
https://github.com/tsufeki/kayo-json-mapper/blob/e1ef374883fb97ebc7c2c4e0a6699b89e0ab6c01/src/Tsufeki/KayoJsonMapper/MetadataProvider/CallableUtils.php#L14-L45
3,222
acplo/AcploLog
src/AcploLog/Log/StaticLogger.php
StaticLogger.save
public static function save($message, $logFile = 'static.log', $logDir = 'data/logs') { if ($logFile === null) { // Useful for just Z-Ray logging return; } $logger = static::getInstance($logFile, $logDir); if (is_object($message) && $message instanceof LoggableObject) { $message = json_encode($message->acploLogMe()); } $logger->debug($message); }
php
public static function save($message, $logFile = 'static.log', $logDir = 'data/logs') { if ($logFile === null) { // Useful for just Z-Ray logging return; } $logger = static::getInstance($logFile, $logDir); if (is_object($message) && $message instanceof LoggableObject) { $message = json_encode($message->acploLogMe()); } $logger->debug($message); }
[ "public", "static", "function", "save", "(", "$", "message", ",", "$", "logFile", "=", "'static.log'", ",", "$", "logDir", "=", "'data/logs'", ")", "{", "if", "(", "$", "logFile", "===", "null", ")", "{", "// Useful for just Z-Ray logging", "return", ";", "}", "$", "logger", "=", "static", "::", "getInstance", "(", "$", "logFile", ",", "$", "logDir", ")", ";", "if", "(", "is_object", "(", "$", "message", ")", "&&", "$", "message", "instanceof", "LoggableObject", ")", "{", "$", "message", "=", "json_encode", "(", "$", "message", "->", "acploLogMe", "(", ")", ")", ";", "}", "$", "logger", "->", "debug", "(", "$", "message", ")", ";", "}" ]
Saves a message to a logfile @param mixed $message @param string $logFile @param string $logDir
[ "Saves", "a", "message", "to", "a", "logfile" ]
9cebcd92ccfaf5dcd67f77ecba358ad5d6cee2a2
https://github.com/acplo/AcploLog/blob/9cebcd92ccfaf5dcd67f77ecba358ad5d6cee2a2/src/AcploLog/Log/StaticLogger.php#L40-L51
3,223
acplo/AcploLog
src/AcploLog/Log/StaticLogger.php
StaticLogger.getInstance
public static function getInstance($logFile = 'static.log', $logDir = 'data/logs') { if (static::$instance instanceof StaticLogger) { return static::$instance; } static::$instance = new self($logFile, $logDir); return static::$instance; }
php
public static function getInstance($logFile = 'static.log', $logDir = 'data/logs') { if (static::$instance instanceof StaticLogger) { return static::$instance; } static::$instance = new self($logFile, $logDir); return static::$instance; }
[ "public", "static", "function", "getInstance", "(", "$", "logFile", "=", "'static.log'", ",", "$", "logDir", "=", "'data/logs'", ")", "{", "if", "(", "static", "::", "$", "instance", "instanceof", "StaticLogger", ")", "{", "return", "static", "::", "$", "instance", ";", "}", "static", "::", "$", "instance", "=", "new", "self", "(", "$", "logFile", ",", "$", "logDir", ")", ";", "return", "static", "::", "$", "instance", ";", "}" ]
Gets an instance of this logger and sets the log directory and filename @param string $logFile @param string $logDir @return \AcploLog\Log\StaticLogger
[ "Gets", "an", "instance", "of", "this", "logger", "and", "sets", "the", "log", "directory", "and", "filename" ]
9cebcd92ccfaf5dcd67f77ecba358ad5d6cee2a2
https://github.com/acplo/AcploLog/blob/9cebcd92ccfaf5dcd67f77ecba358ad5d6cee2a2/src/AcploLog/Log/StaticLogger.php#L60-L68
3,224
liip/LiipDrupalRegistryModule
src/Liip/Drupal/Modules/Registry/Registry.php
Registry.verifySectionName
protected function verifySectionName($section) { $this->assertion->notEmpty( $section, 'The name of the section must not be empty.' ); $this->assertion->string( $section, 'The name of the section must be a string.' ); }
php
protected function verifySectionName($section) { $this->assertion->notEmpty( $section, 'The name of the section must not be empty.' ); $this->assertion->string( $section, 'The name of the section must be a string.' ); }
[ "protected", "function", "verifySectionName", "(", "$", "section", ")", "{", "$", "this", "->", "assertion", "->", "notEmpty", "(", "$", "section", ",", "'The name of the section must not be empty.'", ")", ";", "$", "this", "->", "assertion", "->", "string", "(", "$", "section", ",", "'The name of the section must be a string.'", ")", ";", "}" ]
Verifies the validity of the section to be managed. @param $section @throws InvalidArgumentException
[ "Verifies", "the", "validity", "of", "the", "section", "to", "be", "managed", "." ]
2d860c1f88ef91d9af91909d8711ffbb6e2a1eab
https://github.com/liip/LiipDrupalRegistryModule/blob/2d860c1f88ef91d9af91909d8711ffbb6e2a1eab/src/Liip/Drupal/Modules/Registry/Registry.php#L46-L56
3,225
liip/LiipDrupalRegistryModule
src/Liip/Drupal/Modules/Registry/Registry.php
Registry.getContentByIds
public function getContentByIds(array $identifiers) { $items = array(); foreach ($identifiers as $id) { $items[$id] = $this->getContentById($id); } return $items; }
php
public function getContentByIds(array $identifiers) { $items = array(); foreach ($identifiers as $id) { $items[$id] = $this->getContentById($id); } return $items; }
[ "public", "function", "getContentByIds", "(", "array", "$", "identifiers", ")", "{", "$", "items", "=", "array", "(", ")", ";", "foreach", "(", "$", "identifiers", "as", "$", "id", ")", "{", "$", "items", "[", "$", "id", "]", "=", "$", "this", "->", "getContentById", "(", "$", "id", ")", ";", "}", "return", "$", "items", ";", "}" ]
Shall find the registry items corresponding to the provided list of identifiers. @param array $identifiers @return \Liip\Drupal\Modules\CrudAdmin\Entities\EntityInterface[]
[ "Shall", "find", "the", "registry", "items", "corresponding", "to", "the", "provided", "list", "of", "identifiers", "." ]
2d860c1f88ef91d9af91909d8711ffbb6e2a1eab
https://github.com/liip/LiipDrupalRegistryModule/blob/2d860c1f88ef91d9af91909d8711ffbb6e2a1eab/src/Liip/Drupal/Modules/Registry/Registry.php#L83-L93
3,226
mszewcz/php-light-framework
src/Db/MySQL/Drivers/MySQLi.php
MySQLi.loadConfig
public function loadConfig($config = null): void { $baseClass = Base::getInstance(); $this->errorLevel = (string)$baseClass->Database->MySQL->errorLevel; if (\is_null($config)) { $config = $baseClass->Database->MySQL->defaultConnection; } if (!($config instanceof AbstractConfig)) { throw new RuntimeException('$config must be an instance of MS\LightFramework\Config\AbstractConfig'); } $this->databaseHost = (string)$config->databaseHost; $this->databaseUser = (string)$config->databaseUser; $this->databasePass = (string)$config->databasePass; $this->databaseName = (string)$config->databaseName; $this->connectionCharset = (string)$config->connectionCharset; $this->connectionCollation = (string)$config->connectionCollation; $this->openConnection(); $this->selectDatabase($this->databaseName); $this->setConnectionCharset($this->connectionCharset); $this->setConnectionCollation($this->connectionCollation); }
php
public function loadConfig($config = null): void { $baseClass = Base::getInstance(); $this->errorLevel = (string)$baseClass->Database->MySQL->errorLevel; if (\is_null($config)) { $config = $baseClass->Database->MySQL->defaultConnection; } if (!($config instanceof AbstractConfig)) { throw new RuntimeException('$config must be an instance of MS\LightFramework\Config\AbstractConfig'); } $this->databaseHost = (string)$config->databaseHost; $this->databaseUser = (string)$config->databaseUser; $this->databasePass = (string)$config->databasePass; $this->databaseName = (string)$config->databaseName; $this->connectionCharset = (string)$config->connectionCharset; $this->connectionCollation = (string)$config->connectionCollation; $this->openConnection(); $this->selectDatabase($this->databaseName); $this->setConnectionCharset($this->connectionCharset); $this->setConnectionCollation($this->connectionCollation); }
[ "public", "function", "loadConfig", "(", "$", "config", "=", "null", ")", ":", "void", "{", "$", "baseClass", "=", "Base", "::", "getInstance", "(", ")", ";", "$", "this", "->", "errorLevel", "=", "(", "string", ")", "$", "baseClass", "->", "Database", "->", "MySQL", "->", "errorLevel", ";", "if", "(", "\\", "is_null", "(", "$", "config", ")", ")", "{", "$", "config", "=", "$", "baseClass", "->", "Database", "->", "MySQL", "->", "defaultConnection", ";", "}", "if", "(", "!", "(", "$", "config", "instanceof", "AbstractConfig", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'$config must be an instance of MS\\LightFramework\\Config\\AbstractConfig'", ")", ";", "}", "$", "this", "->", "databaseHost", "=", "(", "string", ")", "$", "config", "->", "databaseHost", ";", "$", "this", "->", "databaseUser", "=", "(", "string", ")", "$", "config", "->", "databaseUser", ";", "$", "this", "->", "databasePass", "=", "(", "string", ")", "$", "config", "->", "databasePass", ";", "$", "this", "->", "databaseName", "=", "(", "string", ")", "$", "config", "->", "databaseName", ";", "$", "this", "->", "connectionCharset", "=", "(", "string", ")", "$", "config", "->", "connectionCharset", ";", "$", "this", "->", "connectionCollation", "=", "(", "string", ")", "$", "config", "->", "connectionCollation", ";", "$", "this", "->", "openConnection", "(", ")", ";", "$", "this", "->", "selectDatabase", "(", "$", "this", "->", "databaseName", ")", ";", "$", "this", "->", "setConnectionCharset", "(", "$", "this", "->", "connectionCharset", ")", ";", "$", "this", "->", "setConnectionCollation", "(", "$", "this", "->", "connectionCollation", ")", ";", "}" ]
Loads configuration, opens new connection, selects database and sets connection charset & collation. @param mixed $config
[ "Loads", "configuration", "opens", "new", "connection", "selects", "database", "and", "sets", "connection", "charset", "&", "collation", "." ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Db/MySQL/Drivers/MySQLi.php#L82-L105
3,227
mszewcz/php-light-framework
src/Db/MySQL/Drivers/MySQLi.php
MySQLi.openConnection
public function openConnection(): void { $this->closeConnection(); $this->currentLink = @new \mysqli($this->databaseHost, $this->databaseUser, $this->databasePass); if (!$this->currentLink->connect_error) { $this->isConnected = true; $this->connectionCount += 1; } else { $this->setError(AbstractMySQL::E_NO_CONNECTION, __CLASS__); } }
php
public function openConnection(): void { $this->closeConnection(); $this->currentLink = @new \mysqli($this->databaseHost, $this->databaseUser, $this->databasePass); if (!$this->currentLink->connect_error) { $this->isConnected = true; $this->connectionCount += 1; } else { $this->setError(AbstractMySQL::E_NO_CONNECTION, __CLASS__); } }
[ "public", "function", "openConnection", "(", ")", ":", "void", "{", "$", "this", "->", "closeConnection", "(", ")", ";", "$", "this", "->", "currentLink", "=", "@", "new", "\\", "mysqli", "(", "$", "this", "->", "databaseHost", ",", "$", "this", "->", "databaseUser", ",", "$", "this", "->", "databasePass", ")", ";", "if", "(", "!", "$", "this", "->", "currentLink", "->", "connect_error", ")", "{", "$", "this", "->", "isConnected", "=", "true", ";", "$", "this", "->", "connectionCount", "+=", "1", ";", "}", "else", "{", "$", "this", "->", "setError", "(", "AbstractMySQL", "::", "E_NO_CONNECTION", ",", "__CLASS__", ")", ";", "}", "}" ]
Opens new database connection. @return void
[ "Opens", "new", "database", "connection", "." ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Db/MySQL/Drivers/MySQLi.php#L112-L123
3,228
mszewcz/php-light-framework
src/Db/MySQL/Drivers/MySQLi.php
MySQLi.closeConnection
public function closeConnection(): void { if ($this->isConnected) { @$this->currentLink->close(); $this->isConnected = false; $this->currentLink = null; $this->currentDB = null; $this->selectedDB = ''; } }
php
public function closeConnection(): void { if ($this->isConnected) { @$this->currentLink->close(); $this->isConnected = false; $this->currentLink = null; $this->currentDB = null; $this->selectedDB = ''; } }
[ "public", "function", "closeConnection", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "isConnected", ")", "{", "@", "$", "this", "->", "currentLink", "->", "close", "(", ")", ";", "$", "this", "->", "isConnected", "=", "false", ";", "$", "this", "->", "currentLink", "=", "null", ";", "$", "this", "->", "currentDB", "=", "null", ";", "$", "this", "->", "selectedDB", "=", "''", ";", "}", "}" ]
Closes existing database connection. @return void
[ "Closes", "existing", "database", "connection", "." ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Db/MySQL/Drivers/MySQLi.php#L130-L139
3,229
mszewcz/php-light-framework
src/Db/MySQL/Drivers/MySQLi.php
MySQLi.selectDatabase
public function selectDatabase(string $databaseName = ''): void { $this->selectedDB = $databaseName; $this->currentDB = $this->currentLink->select_db($databaseName); if (!$this->currentDB) { $this->setError(AbstractMySQL::E_NO_DB_SELECTED, __CLASS__); } }
php
public function selectDatabase(string $databaseName = ''): void { $this->selectedDB = $databaseName; $this->currentDB = $this->currentLink->select_db($databaseName); if (!$this->currentDB) { $this->setError(AbstractMySQL::E_NO_DB_SELECTED, __CLASS__); } }
[ "public", "function", "selectDatabase", "(", "string", "$", "databaseName", "=", "''", ")", ":", "void", "{", "$", "this", "->", "selectedDB", "=", "$", "databaseName", ";", "$", "this", "->", "currentDB", "=", "$", "this", "->", "currentLink", "->", "select_db", "(", "$", "databaseName", ")", ";", "if", "(", "!", "$", "this", "->", "currentDB", ")", "{", "$", "this", "->", "setError", "(", "AbstractMySQL", "::", "E_NO_DB_SELECTED", ",", "__CLASS__", ")", ";", "}", "}" ]
Selects a database. @param string $databaseName @return void
[ "Selects", "a", "database", "." ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Db/MySQL/Drivers/MySQLi.php#L147-L155
3,230
mszewcz/php-light-framework
src/Db/MySQL/Drivers/MySQLi.php
MySQLi.setConnectionCollation
public function setConnectionCollation(string $collationName = ''): void { if ($collationName !== '') { $this->connectionCollation = $collationName; $this->execute('SET SESSION collation_connection = '.$collationName); } }
php
public function setConnectionCollation(string $collationName = ''): void { if ($collationName !== '') { $this->connectionCollation = $collationName; $this->execute('SET SESSION collation_connection = '.$collationName); } }
[ "public", "function", "setConnectionCollation", "(", "string", "$", "collationName", "=", "''", ")", ":", "void", "{", "if", "(", "$", "collationName", "!==", "''", ")", "{", "$", "this", "->", "connectionCollation", "=", "$", "collationName", ";", "$", "this", "->", "execute", "(", "'SET SESSION collation_connection = '", ".", "$", "collationName", ")", ";", "}", "}" ]
Sets connection's collation. @param string $collationName @return void
[ "Sets", "connection", "s", "collation", "." ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Db/MySQL/Drivers/MySQLi.php#L186-L192
3,231
hirnsturm/typo3-extbase-services
TYPO3/Extbase/Security/FeUser.php
FeUser.getUser
public static function getUser($key = null) { if (null == $key) { return $GLOBALS['TSFE']->fe_user->user; } else { return (isset($GLOBALS['TSFE']->fe_user->user[$key])) ? $GLOBALS['TSFE']->fe_user->user[$key] : false; } }
php
public static function getUser($key = null) { if (null == $key) { return $GLOBALS['TSFE']->fe_user->user; } else { return (isset($GLOBALS['TSFE']->fe_user->user[$key])) ? $GLOBALS['TSFE']->fe_user->user[$key] : false; } }
[ "public", "static", "function", "getUser", "(", "$", "key", "=", "null", ")", "{", "if", "(", "null", "==", "$", "key", ")", "{", "return", "$", "GLOBALS", "[", "'TSFE'", "]", "->", "fe_user", "->", "user", ";", "}", "else", "{", "return", "(", "isset", "(", "$", "GLOBALS", "[", "'TSFE'", "]", "->", "fe_user", "->", "user", "[", "$", "key", "]", ")", ")", "?", "$", "GLOBALS", "[", "'TSFE'", "]", "->", "fe_user", "->", "user", "[", "$", "key", "]", ":", "false", ";", "}", "}" ]
Returns fe_user data @param null $key - If null you get the whole user data array @return mixed - false if key not exists
[ "Returns", "fe_user", "data" ]
1cdb97eb260267ea5e5610e802d20a5453296bb1
https://github.com/hirnsturm/typo3-extbase-services/blob/1cdb97eb260267ea5e5610e802d20a5453296bb1/TYPO3/Extbase/Security/FeUser.php#L51-L59
3,232
hirnsturm/typo3-extbase-services
TYPO3/Extbase/Security/FeUser.php
FeUser.hasRoleId
public static function hasRoleId($role) { return (self::isFeUser() && self::isAuthenticated() && in_array($role, $GLOBALS['TSFE']->fe_user->groupData['uid']) ); }
php
public static function hasRoleId($role) { return (self::isFeUser() && self::isAuthenticated() && in_array($role, $GLOBALS['TSFE']->fe_user->groupData['uid']) ); }
[ "public", "static", "function", "hasRoleId", "(", "$", "role", ")", "{", "return", "(", "self", "::", "isFeUser", "(", ")", "&&", "self", "::", "isAuthenticated", "(", ")", "&&", "in_array", "(", "$", "role", ",", "$", "GLOBALS", "[", "'TSFE'", "]", "->", "fe_user", "->", "groupData", "[", "'uid'", "]", ")", ")", ";", "}" ]
Checks whether fe_user is authenticated and has given role id @param int $role @return bool
[ "Checks", "whether", "fe_user", "is", "authenticated", "and", "has", "given", "role", "id" ]
1cdb97eb260267ea5e5610e802d20a5453296bb1
https://github.com/hirnsturm/typo3-extbase-services/blob/1cdb97eb260267ea5e5610e802d20a5453296bb1/TYPO3/Extbase/Security/FeUser.php#L101-L107
3,233
vinala/kernel
src/Lumos/Response/ConfigSetting.php
ConfigSetting.database
public static function database() { $args = func_get_args(); // switch ($args[0]) { case 'mysql': return self::mysql($args[1], $args[2], $args[3], $args[4], $args[5]); break; default: // code... break; } }
php
public static function database() { $args = func_get_args(); // switch ($args[0]) { case 'mysql': return self::mysql($args[1], $args[2], $args[3], $args[4], $args[5]); break; default: // code... break; } }
[ "public", "static", "function", "database", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "//", "switch", "(", "$", "args", "[", "0", "]", ")", "{", "case", "'mysql'", ":", "return", "self", "::", "mysql", "(", "$", "args", "[", "1", "]", ",", "$", "args", "[", "2", "]", ",", "$", "args", "[", "3", "]", ",", "$", "args", "[", "4", "]", ",", "$", "args", "[", "5", "]", ")", ";", "break", ";", "default", ":", "// code...", "break", ";", "}", "}" ]
configure database. @param string $server @param string $database @param string $user @param string $password @return bool
[ "configure", "database", "." ]
346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a
https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Lumos/Response/ConfigSetting.php#L23-L34
3,234
vinala/kernel
src/Lumos/Response/ConfigSetting.php
ConfigSetting.mysql
public static function mysql($host, $database, $user, $password, $prefix = null) { if (is_null($prefix)) { $prefixing = 'false'; $prefix = 'ysf'; } else { $prefixing = 'true'; } // $content = Database::set('mysql', $host, $database, $user, $password, $prefixing, $prefix); // file_put_contents(Application::$root.'config/database.php', $content, 0); // return true; }
php
public static function mysql($host, $database, $user, $password, $prefix = null) { if (is_null($prefix)) { $prefixing = 'false'; $prefix = 'ysf'; } else { $prefixing = 'true'; } // $content = Database::set('mysql', $host, $database, $user, $password, $prefixing, $prefix); // file_put_contents(Application::$root.'config/database.php', $content, 0); // return true; }
[ "public", "static", "function", "mysql", "(", "$", "host", ",", "$", "database", ",", "$", "user", ",", "$", "password", ",", "$", "prefix", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "prefix", ")", ")", "{", "$", "prefixing", "=", "'false'", ";", "$", "prefix", "=", "'ysf'", ";", "}", "else", "{", "$", "prefixing", "=", "'true'", ";", "}", "//", "$", "content", "=", "Database", "::", "set", "(", "'mysql'", ",", "$", "host", ",", "$", "database", ",", "$", "user", ",", "$", "password", ",", "$", "prefixing", ",", "$", "prefix", ")", ";", "//", "file_put_contents", "(", "Application", "::", "$", "root", ".", "'config/database.php'", ",", "$", "content", ",", "0", ")", ";", "//", "return", "true", ";", "}" ]
function to set Mysql server config params. @param string $host @param string $database @param string $user @param string $password @param string $prefix @return
[ "function", "to", "set", "Mysql", "server", "config", "params", "." ]
346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a
https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Lumos/Response/ConfigSetting.php#L47-L61
3,235
Thuata/ComponentBundle
Command/OutputCommand.php
OutputCommand.getFilePath
private function getFilePath() { $tmpDir = realpath($this->getContainer()->get('kernel')->getRootDir() . '/../var/tmp/'); $fileName = '/' . str_replace(':', '--', $this->getName()) . '.sock'; if (!file_exists($tmpDir)) { mkdir($tmpDir); } return $tmpDir . $fileName; }
php
private function getFilePath() { $tmpDir = realpath($this->getContainer()->get('kernel')->getRootDir() . '/../var/tmp/'); $fileName = '/' . str_replace(':', '--', $this->getName()) . '.sock'; if (!file_exists($tmpDir)) { mkdir($tmpDir); } return $tmpDir . $fileName; }
[ "private", "function", "getFilePath", "(", ")", "{", "$", "tmpDir", "=", "realpath", "(", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'kernel'", ")", "->", "getRootDir", "(", ")", ".", "'/../var/tmp/'", ")", ";", "$", "fileName", "=", "'/'", ".", "str_replace", "(", "':'", ",", "'--'", ",", "$", "this", "->", "getName", "(", ")", ")", ".", "'.sock'", ";", "if", "(", "!", "file_exists", "(", "$", "tmpDir", ")", ")", "{", "mkdir", "(", "$", "tmpDir", ")", ";", "}", "return", "$", "tmpDir", ".", "$", "fileName", ";", "}" ]
Gets the file path holding the port number @return string
[ "Gets", "the", "file", "path", "holding", "the", "port", "number" ]
1001aaf585d177daa4b2fef4989c530ff5963df0
https://github.com/Thuata/ComponentBundle/blob/1001aaf585d177daa4b2fef4989c530ff5963df0/Command/OutputCommand.php#L101-L112
3,236
Thuata/ComponentBundle
Command/OutputCommand.php
OutputCommand.executeSend
private function executeSend(InputInterface $input, OutputInterface $output) { $message = $input->getOption(self::OPTION_SEND); $output->writeln(sprintf(self::WELCOME_SEND, $message, $this->getName())); $port = file_get_contents($this->getFilePath()); $pingSock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_sendto($pingSock, $message . PHP_EOL, strlen($message), 0, '127.0.0.1', $port); }
php
private function executeSend(InputInterface $input, OutputInterface $output) { $message = $input->getOption(self::OPTION_SEND); $output->writeln(sprintf(self::WELCOME_SEND, $message, $this->getName())); $port = file_get_contents($this->getFilePath()); $pingSock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_sendto($pingSock, $message . PHP_EOL, strlen($message), 0, '127.0.0.1', $port); }
[ "private", "function", "executeSend", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "message", "=", "$", "input", "->", "getOption", "(", "self", "::", "OPTION_SEND", ")", ";", "$", "output", "->", "writeln", "(", "sprintf", "(", "self", "::", "WELCOME_SEND", ",", "$", "message", ",", "$", "this", "->", "getName", "(", ")", ")", ")", ";", "$", "port", "=", "file_get_contents", "(", "$", "this", "->", "getFilePath", "(", ")", ")", ";", "$", "pingSock", "=", "socket_create", "(", "AF_INET", ",", "SOCK_DGRAM", ",", "SOL_UDP", ")", ";", "socket_sendto", "(", "$", "pingSock", ",", "$", "message", ".", "PHP_EOL", ",", "strlen", "(", "$", "message", ")", ",", "0", ",", "'127.0.0.1'", ",", "$", "port", ")", ";", "}" ]
Execute send mode with send option @param \Symfony\Component\Console\Input\InputInterface $input @param \Symfony\Component\Console\Output\OutputInterface $output
[ "Execute", "send", "mode", "with", "send", "option" ]
1001aaf585d177daa4b2fef4989c530ff5963df0
https://github.com/Thuata/ComponentBundle/blob/1001aaf585d177daa4b2fef4989c530ff5963df0/Command/OutputCommand.php#L120-L129
3,237
wollanup/php-api-rest
src/Slim/Handlers/Strategies/ActionStrategy.php
ActionStrategy.callAction
public function callAction( callable $callable, ServerRequestInterface $request, ResponseInterface $response, array $routeArguments ) { try { return call_user_func_array($callable, $this->buildParams($callable, $request, $routeArguments)); } catch (Exception $e) { $handler = $this->container->getActionErrorHandler(); return $handler($e, $request, $response); } }
php
public function callAction( callable $callable, ServerRequestInterface $request, ResponseInterface $response, array $routeArguments ) { try { return call_user_func_array($callable, $this->buildParams($callable, $request, $routeArguments)); } catch (Exception $e) { $handler = $this->container->getActionErrorHandler(); return $handler($e, $request, $response); } }
[ "public", "function", "callAction", "(", "callable", "$", "callable", ",", "ServerRequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ",", "array", "$", "routeArguments", ")", "{", "try", "{", "return", "call_user_func_array", "(", "$", "callable", ",", "$", "this", "->", "buildParams", "(", "$", "callable", ",", "$", "request", ",", "$", "routeArguments", ")", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "handler", "=", "$", "this", "->", "container", "->", "getActionErrorHandler", "(", ")", ";", "return", "$", "handler", "(", "$", "e", ",", "$", "request", ",", "$", "response", ")", ";", "}", "}" ]
Call a method in an Action class May be overriden to add some logic before or after call @param callable $callable @param ServerRequestInterface $request @param ResponseInterface $response @param array $routeArguments @return mixed
[ "Call", "a", "method", "in", "an", "Action", "class" ]
185eac8a8412e5997d8e292ebd0e38787ae4b949
https://github.com/wollanup/php-api-rest/blob/185eac8a8412e5997d8e292ebd0e38787ae4b949/src/Slim/Handlers/Strategies/ActionStrategy.php#L82-L96
3,238
wollanup/php-api-rest
src/Slim/Handlers/Strategies/ActionStrategy.php
ActionStrategy.callHandler
protected function callHandler( callable $callable, ServerRequestInterface $request, ResponseInterface $response, array $routeArguments ) { # Action is a closure if ($callable instanceof Closure) { array_unshift($routeArguments, $request, $response); $result = call_user_func_array($callable, $routeArguments); } else { # Action is a method of an Action class if (is_array($callable) && $callable[0] instanceof Action\ActionInterface) { $callable[0]->setResponse($response); $callable[0]->setRequest($request); } # Call Action method $result = $this->callAction($callable, $request, $response, $routeArguments); /** @var Action\ActionInterface $action */ $action = $callable[0]; $response = $action->getResponse(); } if (($result instanceof ResponseInterface)) { $response = $result; } else { $response = $this->buildResponse($result, $response, $request); } return $response; }
php
protected function callHandler( callable $callable, ServerRequestInterface $request, ResponseInterface $response, array $routeArguments ) { # Action is a closure if ($callable instanceof Closure) { array_unshift($routeArguments, $request, $response); $result = call_user_func_array($callable, $routeArguments); } else { # Action is a method of an Action class if (is_array($callable) && $callable[0] instanceof Action\ActionInterface) { $callable[0]->setResponse($response); $callable[0]->setRequest($request); } # Call Action method $result = $this->callAction($callable, $request, $response, $routeArguments); /** @var Action\ActionInterface $action */ $action = $callable[0]; $response = $action->getResponse(); } if (($result instanceof ResponseInterface)) { $response = $result; } else { $response = $this->buildResponse($result, $response, $request); } return $response; }
[ "protected", "function", "callHandler", "(", "callable", "$", "callable", ",", "ServerRequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ",", "array", "$", "routeArguments", ")", "{", "# Action is a closure", "if", "(", "$", "callable", "instanceof", "Closure", ")", "{", "array_unshift", "(", "$", "routeArguments", ",", "$", "request", ",", "$", "response", ")", ";", "$", "result", "=", "call_user_func_array", "(", "$", "callable", ",", "$", "routeArguments", ")", ";", "}", "else", "{", "# Action is a method of an Action class", "if", "(", "is_array", "(", "$", "callable", ")", "&&", "$", "callable", "[", "0", "]", "instanceof", "Action", "\\", "ActionInterface", ")", "{", "$", "callable", "[", "0", "]", "->", "setResponse", "(", "$", "response", ")", ";", "$", "callable", "[", "0", "]", "->", "setRequest", "(", "$", "request", ")", ";", "}", "# Call Action method", "$", "result", "=", "$", "this", "->", "callAction", "(", "$", "callable", ",", "$", "request", ",", "$", "response", ",", "$", "routeArguments", ")", ";", "/** @var Action\\ActionInterface $action */", "$", "action", "=", "$", "callable", "[", "0", "]", ";", "$", "response", "=", "$", "action", "->", "getResponse", "(", ")", ";", "}", "if", "(", "(", "$", "result", "instanceof", "ResponseInterface", ")", ")", "{", "$", "response", "=", "$", "result", ";", "}", "else", "{", "$", "response", "=", "$", "this", "->", "buildResponse", "(", "$", "result", ",", "$", "response", ",", "$", "request", ")", ";", "}", "return", "$", "response", ";", "}" ]
Call action with built params @param callable $callable @param ServerRequestInterface $request @param ResponseInterface $response @param array $routeArguments @return mixed @throws Exception
[ "Call", "action", "with", "built", "params" ]
185eac8a8412e5997d8e292ebd0e38787ae4b949
https://github.com/wollanup/php-api-rest/blob/185eac8a8412e5997d8e292ebd0e38787ae4b949/src/Slim/Handlers/Strategies/ActionStrategy.php#L217-L248
3,239
simplecomplex/php-config
src/EnvConfig.php
EnvConfig.get
public function get(string $key, $default = null) { $k = $this->keyConvert($key); $v = getenv($k); return $v !== false ? $v : $default; }
php
public function get(string $key, $default = null) { $k = $this->keyConvert($key); $v = getenv($k); return $v !== false ? $v : $default; }
[ "public", "function", "get", "(", "string", "$", "key", ",", "$", "default", "=", "null", ")", "{", "$", "k", "=", "$", "this", "->", "keyConvert", "(", "$", "key", ")", ";", "$", "v", "=", "getenv", "(", "$", "k", ")", ";", "return", "$", "v", "!==", "false", "?", "$", "v", ":", "$", "default", ";", "}" ]
Fetches an environment variable. @param string $key @param mixed $default @return mixed|null Environment vars are always string. The default may be of any type. @throws InvalidArgumentException Propagated.
[ "Fetches", "an", "environment", "variable", "." ]
0d8450bc7523e8991452ef70f4f57f3d3e67f0d4
https://github.com/simplecomplex/php-config/blob/0d8450bc7523e8991452ef70f4f57f3d3e67f0d4/src/EnvConfig.php#L68-L73
3,240
simplecomplex/php-config
src/EnvConfig.php
EnvConfig.has
public function has(string $key) : bool { $k = $this->keyConvert($key); return getenv($k) !== false; }
php
public function has(string $key) : bool { $k = $this->keyConvert($key); return getenv($k) !== false; }
[ "public", "function", "has", "(", "string", "$", "key", ")", ":", "bool", "{", "$", "k", "=", "$", "this", "->", "keyConvert", "(", "$", "key", ")", ";", "return", "getenv", "(", "$", "k", ")", "!==", "false", ";", "}" ]
Check if an environment var is set. @param string $key @return bool @throws InvalidArgumentException Propagated.
[ "Check", "if", "an", "environment", "var", "is", "set", "." ]
0d8450bc7523e8991452ef70f4f57f3d3e67f0d4
https://github.com/simplecomplex/php-config/blob/0d8450bc7523e8991452ef70f4f57f3d3e67f0d4/src/EnvConfig.php#L152-L156
3,241
simplecomplex/php-config
src/EnvConfig.php
EnvConfig.keyConvert
public function keyConvert(string $key) : string { $key = str_replace(ConfigKey::VALID_NON_ALPHANUM, '_', $key); if (!ConfigKey::validate($key)) { throw new InvalidArgumentException('Arg key contains invalid character(s).'); } return $key; }
php
public function keyConvert(string $key) : string { $key = str_replace(ConfigKey::VALID_NON_ALPHANUM, '_', $key); if (!ConfigKey::validate($key)) { throw new InvalidArgumentException('Arg key contains invalid character(s).'); } return $key; }
[ "public", "function", "keyConvert", "(", "string", "$", "key", ")", ":", "string", "{", "$", "key", "=", "str_replace", "(", "ConfigKey", "::", "VALID_NON_ALPHANUM", ",", "'_'", ",", "$", "key", ")", ";", "if", "(", "!", "ConfigKey", "::", "validate", "(", "$", "key", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Arg key contains invalid character(s).'", ")", ";", "}", "return", "$", "key", ";", "}" ]
Replaces all legal non-alphanumeric chars with underscore. @param string $key @return string @throws InvalidArgumentException
[ "Replaces", "all", "legal", "non", "-", "alphanumeric", "chars", "with", "underscore", "." ]
0d8450bc7523e8991452ef70f4f57f3d3e67f0d4
https://github.com/simplecomplex/php-config/blob/0d8450bc7523e8991452ef70f4f57f3d3e67f0d4/src/EnvConfig.php#L222-L229
3,242
kiler129/CherryHttp
src/_legacyCode/HttpMessage.php
HttpMessage.getHeaderLines
public function getHeaderLines($name) { $name = strtolower($name); if (!isset($this->headers[$name])) { return array(); } return $this->headers[$name][1]; }
php
public function getHeaderLines($name) { $name = strtolower($name); if (!isset($this->headers[$name])) { return array(); } return $this->headers[$name][1]; }
[ "public", "function", "getHeaderLines", "(", "$", "name", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "headers", "[", "$", "name", "]", ")", ")", "{", "return", "array", "(", ")", ";", "}", "return", "$", "this", "->", "headers", "[", "$", "name", "]", "[", "1", "]", ";", "}" ]
Provides value for specified header name. If header doesn't exists it will return empty array. @param string $name Name of header @return string[]
[ "Provides", "value", "for", "specified", "header", "name", ".", "If", "header", "doesn", "t", "exists", "it", "will", "return", "empty", "array", "." ]
05927f26183cbd6fd5ccb0853befecdea279308d
https://github.com/kiler129/CherryHttp/blob/05927f26183cbd6fd5ccb0853befecdea279308d/src/_legacyCode/HttpMessage.php#L124-L133
3,243
kiler129/CherryHttp
src/_legacyCode/HttpMessage.php
HttpMessage.setHeader
public function setHeader($name, $value, $replace = true) { $lowercaseName = strtolower($name); if ($replace || !isset($this->headers[$lowercaseName])) { $this->headers[$lowercaseName] = array($name, array($value)); } else { $this->headers[$lowercaseName][1][] .= $value; } $this->messageCache = null; }
php
public function setHeader($name, $value, $replace = true) { $lowercaseName = strtolower($name); if ($replace || !isset($this->headers[$lowercaseName])) { $this->headers[$lowercaseName] = array($name, array($value)); } else { $this->headers[$lowercaseName][1][] .= $value; } $this->messageCache = null; }
[ "public", "function", "setHeader", "(", "$", "name", ",", "$", "value", ",", "$", "replace", "=", "true", ")", "{", "$", "lowercaseName", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "$", "replace", "||", "!", "isset", "(", "$", "this", "->", "headers", "[", "$", "lowercaseName", "]", ")", ")", "{", "$", "this", "->", "headers", "[", "$", "lowercaseName", "]", "=", "array", "(", "$", "name", ",", "array", "(", "$", "value", ")", ")", ";", "}", "else", "{", "$", "this", "->", "headers", "[", "$", "lowercaseName", "]", "[", "1", "]", "[", "]", ".=", "$", "value", ";", "}", "$", "this", "->", "messageCache", "=", "null", ";", "}" ]
Adds or replace header with given name with given value. @param string $name Header name @param string|array $value Header value. In case of multiple headers with the same name (eg. Set-Cookie) it's possible to pass an array. @param bool $replace Indicates if current call should replace header (default) with the same name or just add another with the same name
[ "Adds", "or", "replace", "header", "with", "given", "name", "with", "given", "value", "." ]
05927f26183cbd6fd5ccb0853befecdea279308d
https://github.com/kiler129/CherryHttp/blob/05927f26183cbd6fd5ccb0853befecdea279308d/src/_legacyCode/HttpMessage.php#L144-L154
3,244
kiler129/CherryHttp
src/_legacyCode/HttpMessage.php
HttpMessage.isConnectionClose
public function isConnectionClose() { $connection = $this->getHeader('connection'); if ($this->protocolVersion === '1.1') { return ($connection[0] === 'C' || $connection[0] === 'c'); } else { return ($connection[0] !== 'K' && $connection[0] !== 'k'); } }
php
public function isConnectionClose() { $connection = $this->getHeader('connection'); if ($this->protocolVersion === '1.1') { return ($connection[0] === 'C' || $connection[0] === 'c'); } else { return ($connection[0] !== 'K' && $connection[0] !== 'k'); } }
[ "public", "function", "isConnectionClose", "(", ")", "{", "$", "connection", "=", "$", "this", "->", "getHeader", "(", "'connection'", ")", ";", "if", "(", "$", "this", "->", "protocolVersion", "===", "'1.1'", ")", "{", "return", "(", "$", "connection", "[", "0", "]", "===", "'C'", "||", "$", "connection", "[", "0", "]", "===", "'c'", ")", ";", "}", "else", "{", "return", "(", "$", "connection", "[", "0", "]", "!==", "'K'", "&&", "$", "connection", "[", "0", "]", "!==", "'k'", ")", ";", "}", "}" ]
Provides information is TCP connection should be terminated after sending this request. @return bool
[ "Provides", "information", "is", "TCP", "connection", "should", "be", "terminated", "after", "sending", "this", "request", "." ]
05927f26183cbd6fd5ccb0853befecdea279308d
https://github.com/kiler129/CherryHttp/blob/05927f26183cbd6fd5ccb0853befecdea279308d/src/_legacyCode/HttpMessage.php#L183-L192
3,245
kiler129/CherryHttp
src/_legacyCode/HttpMessage.php
HttpMessage.getHeadersAsText
protected function getHeadersAsText() { $headers = ''; foreach ($this->headers as $header) { foreach ($header[1] as $headerValue) { $headers .= $header[0] . ': ' . $headerValue . "\r\n"; } } return $headers; }
php
protected function getHeadersAsText() { $headers = ''; foreach ($this->headers as $header) { foreach ($header[1] as $headerValue) { $headers .= $header[0] . ': ' . $headerValue . "\r\n"; } } return $headers; }
[ "protected", "function", "getHeadersAsText", "(", ")", "{", "$", "headers", "=", "''", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "header", ")", "{", "foreach", "(", "$", "header", "[", "1", "]", "as", "$", "headerValue", ")", "{", "$", "headers", ".=", "$", "header", "[", "0", "]", ".", "': '", ".", "$", "headerValue", ".", "\"\\r\\n\"", ";", "}", "}", "return", "$", "headers", ";", "}" ]
Returns all headers in text form to embed into HTTP message. @return string
[ "Returns", "all", "headers", "in", "text", "form", "to", "embed", "into", "HTTP", "message", "." ]
05927f26183cbd6fd5ccb0853befecdea279308d
https://github.com/kiler129/CherryHttp/blob/05927f26183cbd6fd5ccb0853befecdea279308d/src/_legacyCode/HttpMessage.php#L199-L210
3,246
synapsestudios/synapse-base
src/Synapse/Email/AbstractSender.php
AbstractSender.filterThroughWhitelist
protected function filterThroughWhitelist($address) { $whitelist = Arr::path($this->config, 'whitelist.list'); $trapAddress = Arr::path($this->config, 'whitelist.trap'); if (! is_array($whitelist)) { return $address; } list($name, $domain) = explode('@', $address); $addressWhitelisted = in_array($address, $whitelist); $domainWhitelisted = in_array($domain, $whitelist); $whitelisted = ($addressWhitelisted or $domainWhitelisted); return $whitelisted ? $address : $this->injectIntoTrapAddress($address); }
php
protected function filterThroughWhitelist($address) { $whitelist = Arr::path($this->config, 'whitelist.list'); $trapAddress = Arr::path($this->config, 'whitelist.trap'); if (! is_array($whitelist)) { return $address; } list($name, $domain) = explode('@', $address); $addressWhitelisted = in_array($address, $whitelist); $domainWhitelisted = in_array($domain, $whitelist); $whitelisted = ($addressWhitelisted or $domainWhitelisted); return $whitelisted ? $address : $this->injectIntoTrapAddress($address); }
[ "protected", "function", "filterThroughWhitelist", "(", "$", "address", ")", "{", "$", "whitelist", "=", "Arr", "::", "path", "(", "$", "this", "->", "config", ",", "'whitelist.list'", ")", ";", "$", "trapAddress", "=", "Arr", "::", "path", "(", "$", "this", "->", "config", ",", "'whitelist.trap'", ")", ";", "if", "(", "!", "is_array", "(", "$", "whitelist", ")", ")", "{", "return", "$", "address", ";", "}", "list", "(", "$", "name", ",", "$", "domain", ")", "=", "explode", "(", "'@'", ",", "$", "address", ")", ";", "$", "addressWhitelisted", "=", "in_array", "(", "$", "address", ",", "$", "whitelist", ")", ";", "$", "domainWhitelisted", "=", "in_array", "(", "$", "domain", ",", "$", "whitelist", ")", ";", "$", "whitelisted", "=", "(", "$", "addressWhitelisted", "or", "$", "domainWhitelisted", ")", ";", "return", "$", "whitelisted", "?", "$", "address", ":", "$", "this", "->", "injectIntoTrapAddress", "(", "$", "address", ")", ";", "}" ]
Filter an email address through the domain and email address whitelists If the email address is valid according to the whitelists, it is returned unchanged. Otherwise the whitelist trap email address is returned. @param string $address Email address to filter @return string Filtered email address
[ "Filter", "an", "email", "address", "through", "the", "domain", "and", "email", "address", "whitelists" ]
60c830550491742a077ab063f924e2f0b63825da
https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Email/AbstractSender.php#L39-L56
3,247
synapsestudios/synapse-base
src/Synapse/Email/AbstractSender.php
AbstractSender.injectIntoTrapAddress
protected function injectIntoTrapAddress($address) { $trapAddress = Arr::path($this->config, 'whitelist.trap'); if (! $trapAddress) { throw new RuntimeException('Email address not whitelisted but no email trap exists'); } $address = str_ireplace('@', '+', $address); list($trapName, $trapDomain) = explode('@', $trapAddress); return sprintf( '%s+%s@%s', $trapName, $address, $trapDomain ); }
php
protected function injectIntoTrapAddress($address) { $trapAddress = Arr::path($this->config, 'whitelist.trap'); if (! $trapAddress) { throw new RuntimeException('Email address not whitelisted but no email trap exists'); } $address = str_ireplace('@', '+', $address); list($trapName, $trapDomain) = explode('@', $trapAddress); return sprintf( '%s+%s@%s', $trapName, $address, $trapDomain ); }
[ "protected", "function", "injectIntoTrapAddress", "(", "$", "address", ")", "{", "$", "trapAddress", "=", "Arr", "::", "path", "(", "$", "this", "->", "config", ",", "'whitelist.trap'", ")", ";", "if", "(", "!", "$", "trapAddress", ")", "{", "throw", "new", "RuntimeException", "(", "'Email address not whitelisted but no email trap exists'", ")", ";", "}", "$", "address", "=", "str_ireplace", "(", "'@'", ",", "'+'", ",", "$", "address", ")", ";", "list", "(", "$", "trapName", ",", "$", "trapDomain", ")", "=", "explode", "(", "'@'", ",", "$", "trapAddress", ")", ";", "return", "sprintf", "(", "'%s+%s@%s'", ",", "$", "trapName", ",", "$", "address", ",", "$", "trapDomain", ")", ";", "}" ]
Return the whitelist trap address with the specified email injected as a suffix Example: Email to transform : [email protected] Trap email : [email protected] Result : [email protected] @param string $address Email address to transform @return string Transformed address
[ "Return", "the", "whitelist", "trap", "address", "with", "the", "specified", "email", "injected", "as", "a", "suffix" ]
60c830550491742a077ab063f924e2f0b63825da
https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Email/AbstractSender.php#L69-L87
3,248
marando/phpSOFA
src/Marando/IAU/iauTcgtt.php
iauTcgtt.Tcgtt
public static function Tcgtt($tcg1, $tcg2, &$tt1, &$tt2) { /* 1977 Jan 1 00:00:32.184 TT, as MJD */ $t77t = DJM77 + TTMTAI / DAYSEC; /* Result, safeguarding precision. */ if ($tcg1 > $tcg2) { $tt1 = $tcg1; $tt2 = $tcg2 - ( ( $tcg1 - DJM0 ) + ( $tcg2 - $t77t ) ) * ELG; } else { $tt1 = $tcg1 - ( ( $tcg2 - DJM0 ) + ( $tcg1 - $t77t ) ) * ELG; $tt2 = $tcg2; } /* OK status. */ return 0; }
php
public static function Tcgtt($tcg1, $tcg2, &$tt1, &$tt2) { /* 1977 Jan 1 00:00:32.184 TT, as MJD */ $t77t = DJM77 + TTMTAI / DAYSEC; /* Result, safeguarding precision. */ if ($tcg1 > $tcg2) { $tt1 = $tcg1; $tt2 = $tcg2 - ( ( $tcg1 - DJM0 ) + ( $tcg2 - $t77t ) ) * ELG; } else { $tt1 = $tcg1 - ( ( $tcg2 - DJM0 ) + ( $tcg1 - $t77t ) ) * ELG; $tt2 = $tcg2; } /* OK status. */ return 0; }
[ "public", "static", "function", "Tcgtt", "(", "$", "tcg1", ",", "$", "tcg2", ",", "&", "$", "tt1", ",", "&", "$", "tt2", ")", "{", "/* 1977 Jan 1 00:00:32.184 TT, as MJD */", "$", "t77t", "=", "DJM77", "+", "TTMTAI", "/", "DAYSEC", ";", "/* Result, safeguarding precision. */", "if", "(", "$", "tcg1", ">", "$", "tcg2", ")", "{", "$", "tt1", "=", "$", "tcg1", ";", "$", "tt2", "=", "$", "tcg2", "-", "(", "(", "$", "tcg1", "-", "DJM0", ")", "+", "(", "$", "tcg2", "-", "$", "t77t", ")", ")", "*", "ELG", ";", "}", "else", "{", "$", "tt1", "=", "$", "tcg1", "-", "(", "(", "$", "tcg2", "-", "DJM0", ")", "+", "(", "$", "tcg1", "-", "$", "t77t", ")", ")", "*", "ELG", ";", "$", "tt2", "=", "$", "tcg2", ";", "}", "/* OK status. */", "return", "0", ";", "}" ]
- - - - - - - - - i a u T c g t t - - - - - - - - - Time scale transformation: Geocentric Coordinate Time, TCG, to Terrestrial Time, TT. This function is part of the International Astronomical Union's SOFA (Standards of Fundamental Astronomy) software collection. Status: canonical. Given: tcg1,tcg2 double TCG as a 2-part Julian Date Returned: tt1,tt2 double TT as a 2-part Julian Date Returned (function value): int status: 0 = OK Note: tcg1+tcg2 is Julian Date, apportioned in any convenient way between the two arguments, for example where tcg1 is the Julian Day Number and tcg22 is the fraction of a day. The returned tt1,tt2 follow suit. References: McCarthy, D. D., Petit, G. (eds.), IERS Conventions (2003),. IERS Technical Note No. 32, BKG (2004) IAU 2000 Resolution B1.9 This revision: 2013 June 18 SOFA release 2015-02-09 Copyright (C) 2015 IAU SOFA Board. See notes at end.
[ "-", "-", "-", "-", "-", "-", "-", "-", "-", "i", "a", "u", "T", "c", "g", "t", "t", "-", "-", "-", "-", "-", "-", "-", "-", "-" ]
757fa49fe335ae1210eaa7735473fd4388b13f07
https://github.com/marando/phpSOFA/blob/757fa49fe335ae1210eaa7735473fd4388b13f07/src/Marando/IAU/iauTcgtt.php#L49-L65
3,249
nerd-framework/nerd-http
src/Nerd/Framework/Http/Request/Request.php
Request.parametersToHeaders
private static function parametersToHeaders($parameters) { $filtered = array_filter(array_keys($parameters), function ($key) { return strpos($key, 'HTTP_') === 0; }); $transformKey = function ($key) { $parts = explode('_', $key); $lowerCase = array_map('strtolower', array_slice($parts, 1)); $firstUpper = array_map('ucfirst', $lowerCase); return implode('-', $firstUpper); }; return array_reduce($filtered, function ($acc, $key) use ($parameters, $transformKey) { $headerKey = $transformKey($key); return array_merge( $acc, [$headerKey => $parameters[$key]] ); }, []); }
php
private static function parametersToHeaders($parameters) { $filtered = array_filter(array_keys($parameters), function ($key) { return strpos($key, 'HTTP_') === 0; }); $transformKey = function ($key) { $parts = explode('_', $key); $lowerCase = array_map('strtolower', array_slice($parts, 1)); $firstUpper = array_map('ucfirst', $lowerCase); return implode('-', $firstUpper); }; return array_reduce($filtered, function ($acc, $key) use ($parameters, $transformKey) { $headerKey = $transformKey($key); return array_merge( $acc, [$headerKey => $parameters[$key]] ); }, []); }
[ "private", "static", "function", "parametersToHeaders", "(", "$", "parameters", ")", "{", "$", "filtered", "=", "array_filter", "(", "array_keys", "(", "$", "parameters", ")", ",", "function", "(", "$", "key", ")", "{", "return", "strpos", "(", "$", "key", ",", "'HTTP_'", ")", "===", "0", ";", "}", ")", ";", "$", "transformKey", "=", "function", "(", "$", "key", ")", "{", "$", "parts", "=", "explode", "(", "'_'", ",", "$", "key", ")", ";", "$", "lowerCase", "=", "array_map", "(", "'strtolower'", ",", "array_slice", "(", "$", "parts", ",", "1", ")", ")", ";", "$", "firstUpper", "=", "array_map", "(", "'ucfirst'", ",", "$", "lowerCase", ")", ";", "return", "implode", "(", "'-'", ",", "$", "firstUpper", ")", ";", "}", ";", "return", "array_reduce", "(", "$", "filtered", ",", "function", "(", "$", "acc", ",", "$", "key", ")", "use", "(", "$", "parameters", ",", "$", "transformKey", ")", "{", "$", "headerKey", "=", "$", "transformKey", "(", "$", "key", ")", ";", "return", "array_merge", "(", "$", "acc", ",", "[", "$", "headerKey", "=>", "$", "parameters", "[", "$", "key", "]", "]", ")", ";", "}", ",", "[", "]", ")", ";", "}" ]
Convert HTTP_ parameters to headers map. @param $parameters @return mixed
[ "Convert", "HTTP_", "parameters", "to", "headers", "map", "." ]
ce1b2baeeda89b20cdf49c742d0337a41473ad27
https://github.com/nerd-framework/nerd-http/blob/ce1b2baeeda89b20cdf49c742d0337a41473ad27/src/Nerd/Framework/Http/Request/Request.php#L111-L131
3,250
nerd-framework/nerd-http
src/Nerd/Framework/Http/Request/Request.php
Request.encapsulateFiles
private static function encapsulateFiles($files) { $validFiles = array_filter($files, function ($file) { return $file['error'] == UPLOAD_ERR_OK; }); return array_map(function ($file) { return new File($file['name'], $file['size'], $file['tmp_name']); }, $validFiles); }
php
private static function encapsulateFiles($files) { $validFiles = array_filter($files, function ($file) { return $file['error'] == UPLOAD_ERR_OK; }); return array_map(function ($file) { return new File($file['name'], $file['size'], $file['tmp_name']); }, $validFiles); }
[ "private", "static", "function", "encapsulateFiles", "(", "$", "files", ")", "{", "$", "validFiles", "=", "array_filter", "(", "$", "files", ",", "function", "(", "$", "file", ")", "{", "return", "$", "file", "[", "'error'", "]", "==", "UPLOAD_ERR_OK", ";", "}", ")", ";", "return", "array_map", "(", "function", "(", "$", "file", ")", "{", "return", "new", "File", "(", "$", "file", "[", "'name'", "]", ",", "$", "file", "[", "'size'", "]", ",", "$", "file", "[", "'tmp_name'", "]", ")", ";", "}", ",", "$", "validFiles", ")", ";", "}" ]
Encapsulate files into File objects. @param array $files @return File[]
[ "Encapsulate", "files", "into", "File", "objects", "." ]
ce1b2baeeda89b20cdf49c742d0337a41473ad27
https://github.com/nerd-framework/nerd-http/blob/ce1b2baeeda89b20cdf49c742d0337a41473ad27/src/Nerd/Framework/Http/Request/Request.php#L139-L148
3,251
gourmet/common
Model/CommonDetailModel.php
CommonDetailModel.createDefaults
public function createDefaults($assocId) { $i = 1; $data = array(); $foreignModel = current(Hash::extract($this->getAssociated('Parent'), 'conditions')); foreach ($this->defaults as $entry) { $data[$this->alias] = $entry; $data[$this->alias]['foreign_key'] = $assocId; $data[$this->alias]['foreign_model'] = $foreignModel; $data[$this->alias]['position'] = $i++; $this->create(); $this->save($data); } }
php
public function createDefaults($assocId) { $i = 1; $data = array(); $foreignModel = current(Hash::extract($this->getAssociated('Parent'), 'conditions')); foreach ($this->defaults as $entry) { $data[$this->alias] = $entry; $data[$this->alias]['foreign_key'] = $assocId; $data[$this->alias]['foreign_model'] = $foreignModel; $data[$this->alias]['position'] = $i++; $this->create(); $this->save($data); } }
[ "public", "function", "createDefaults", "(", "$", "assocId", ")", "{", "$", "i", "=", "1", ";", "$", "data", "=", "array", "(", ")", ";", "$", "foreignModel", "=", "current", "(", "Hash", "::", "extract", "(", "$", "this", "->", "getAssociated", "(", "'Parent'", ")", ",", "'conditions'", ")", ")", ";", "foreach", "(", "$", "this", "->", "defaults", "as", "$", "entry", ")", "{", "$", "data", "[", "$", "this", "->", "alias", "]", "=", "$", "entry", ";", "$", "data", "[", "$", "this", "->", "alias", "]", "[", "'foreign_key'", "]", "=", "$", "assocId", ";", "$", "data", "[", "$", "this", "->", "alias", "]", "[", "'foreign_model'", "]", "=", "$", "foreignModel", ";", "$", "data", "[", "$", "this", "->", "alias", "]", "[", "'position'", "]", "=", "$", "i", "++", ";", "$", "this", "->", "create", "(", ")", ";", "$", "this", "->", "save", "(", "$", "data", ")", ";", "}", "}" ]
Creates default "details" entries for associated model's record. @param integer|string $assocId Associated record ID. @return void
[ "Creates", "default", "details", "entries", "for", "associated", "model", "s", "record", "." ]
53ad4e919c51606dc81f2c716267d01ee768ade5
https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/Model/CommonDetailModel.php#L71-L85
3,252
gourmet/common
Model/CommonDetailModel.php
CommonDetailModel.getSection
public function getSection($id, $section = null, $schema = false, $format = true) { $foreignKey = $this->belongsTo[$this->parentModel]['foreignKey']; $conditions = array("{$this->alias}.{$foreignKey}" => $id); if (!is_null($section)) { $conditions["{$this->alias}.field LIKE"] = "$section.%"; } $fields = array("{$this->alias}.field", "{$this->alias}.value"); if (true === $schema) { $fields = array("{$this->alias}.field", "{$this->alias}.input", "{$this->alias}.data_type", "{$this->alias}.label"); } $results = $this->find( 'all', array( 'conditions' => $conditions, 'fields' => $fields, 'order' => array("{$this->alias}.position ASC"), 'recursive' => -1 ) ); return $this->extractSection($results, $section, $schema, $format); }
php
public function getSection($id, $section = null, $schema = false, $format = true) { $foreignKey = $this->belongsTo[$this->parentModel]['foreignKey']; $conditions = array("{$this->alias}.{$foreignKey}" => $id); if (!is_null($section)) { $conditions["{$this->alias}.field LIKE"] = "$section.%"; } $fields = array("{$this->alias}.field", "{$this->alias}.value"); if (true === $schema) { $fields = array("{$this->alias}.field", "{$this->alias}.input", "{$this->alias}.data_type", "{$this->alias}.label"); } $results = $this->find( 'all', array( 'conditions' => $conditions, 'fields' => $fields, 'order' => array("{$this->alias}.position ASC"), 'recursive' => -1 ) ); return $this->extractSection($results, $section, $schema, $format); }
[ "public", "function", "getSection", "(", "$", "id", ",", "$", "section", "=", "null", ",", "$", "schema", "=", "false", ",", "$", "format", "=", "true", ")", "{", "$", "foreignKey", "=", "$", "this", "->", "belongsTo", "[", "$", "this", "->", "parentModel", "]", "[", "'foreignKey'", "]", ";", "$", "conditions", "=", "array", "(", "\"{$this->alias}.{$foreignKey}\"", "=>", "$", "id", ")", ";", "if", "(", "!", "is_null", "(", "$", "section", ")", ")", "{", "$", "conditions", "[", "\"{$this->alias}.field LIKE\"", "]", "=", "\"$section.%\"", ";", "}", "$", "fields", "=", "array", "(", "\"{$this->alias}.field\"", ",", "\"{$this->alias}.value\"", ")", ";", "if", "(", "true", "===", "$", "schema", ")", "{", "$", "fields", "=", "array", "(", "\"{$this->alias}.field\"", ",", "\"{$this->alias}.input\"", ",", "\"{$this->alias}.data_type\"", ",", "\"{$this->alias}.label\"", ")", ";", "}", "$", "results", "=", "$", "this", "->", "find", "(", "'all'", ",", "array", "(", "'conditions'", "=>", "$", "conditions", ",", "'fields'", "=>", "$", "fields", ",", "'order'", "=>", "array", "(", "\"{$this->alias}.position ASC\"", ")", ",", "'recursive'", "=>", "-", "1", ")", ")", ";", "return", "$", "this", "->", "extractSection", "(", "$", "results", ",", "$", "section", ",", "$", "schema", ",", "$", "format", ")", ";", "}" ]
Gets detailed model record's associated details by section. Example: $result = array( 'address' => array('street-number' => '4820', 'street-name' => 'St Marc') 'interior' => array('bathroom' => 3, 'bedroom' => 5, 'kitchen' => 1, 'other' => '') ); @param integer|string $id Associated record ID. @param string $section Name of section. @param boolean $schema TRUE to return the section's schema. @param boolean $format FALSE if you don't want to format the resultset. @return array
[ "Gets", "detailed", "model", "record", "s", "associated", "details", "by", "section", "." ]
53ad4e919c51606dc81f2c716267d01ee768ade5
https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/Model/CommonDetailModel.php#L139-L161
3,253
gourmet/common
Model/CommonDetailModel.php
CommonDetailModel.save
public function save($data = null, $validate = true, $fieldList = array()) { if (!is_array($validate)) { $validate = compact('validate', 'fieldList'); } $defaults = array('validate' => true, 'fieldList' => $fieldList, 'callbacks' => true, 'bypass' => true); $options = array_merge($defaults, $validate); if ($options['bypass']) { return true; } return parent::save($data, $options); }
php
public function save($data = null, $validate = true, $fieldList = array()) { if (!is_array($validate)) { $validate = compact('validate', 'fieldList'); } $defaults = array('validate' => true, 'fieldList' => $fieldList, 'callbacks' => true, 'bypass' => true); $options = array_merge($defaults, $validate); if ($options['bypass']) { return true; } return parent::save($data, $options); }
[ "public", "function", "save", "(", "$", "data", "=", "null", ",", "$", "validate", "=", "true", ",", "$", "fieldList", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "validate", ")", ")", "{", "$", "validate", "=", "compact", "(", "'validate'", ",", "'fieldList'", ")", ";", "}", "$", "defaults", "=", "array", "(", "'validate'", "=>", "true", ",", "'fieldList'", "=>", "$", "fieldList", ",", "'callbacks'", "=>", "true", ",", "'bypass'", "=>", "true", ")", ";", "$", "options", "=", "array_merge", "(", "$", "defaults", ",", "$", "validate", ")", ";", "if", "(", "$", "options", "[", "'bypass'", "]", ")", "{", "return", "true", ";", "}", "return", "parent", "::", "save", "(", "$", "data", ",", "$", "options", ")", ";", "}" ]
By-pass the save operation by default. This is a workaround so only the `DetailableBehavior` can save records after settings the required fields. @param array $data Data to save. @param boolean|array $validate Either a boolean, or an array. If a boolean, indicates whether or not to validate before saving. If an array, can have following keys: - validate: Set to true/false to enable or disable validation. - fieldList: An array of fields you want to allow for saving. - callbacks: Set to false to disable callbacks. Using 'before' or 'after' will enable only those callbacks. - bypass: Set to false to force the save operation. @param array $fieldList List of fields to allow to be saved @return mixed On success Model::$data if its not empty or true, false on failure
[ "By", "-", "pass", "the", "save", "operation", "by", "default", ".", "This", "is", "a", "workaround", "so", "only", "the", "DetailableBehavior", "can", "save", "records", "after", "settings", "the", "required", "fields", "." ]
53ad4e919c51606dc81f2c716267d01ee768ade5
https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/Model/CommonDetailModel.php#L181-L193
3,254
gourmet/common
Model/CommonDetailModel.php
CommonDetailModel.validateSection
public function validateSection($data, $section) { $pass = true; if (!empty($this->sectionValidation[$section])) { $modelValidation = $this->validate; $this->validate = $this->sectionValidation[$section]; $this->set($data); if (!$this->validates()) { $pass = false; } $this->validate = $modelValidation; } return $pass; }
php
public function validateSection($data, $section) { $pass = true; if (!empty($this->sectionValidation[$section])) { $modelValidation = $this->validate; $this->validate = $this->sectionValidation[$section]; $this->set($data); if (!$this->validates()) { $pass = false; } $this->validate = $modelValidation; } return $pass; }
[ "public", "function", "validateSection", "(", "$", "data", ",", "$", "section", ")", "{", "$", "pass", "=", "true", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "sectionValidation", "[", "$", "section", "]", ")", ")", "{", "$", "modelValidation", "=", "$", "this", "->", "validate", ";", "$", "this", "->", "validate", "=", "$", "this", "->", "sectionValidation", "[", "$", "section", "]", ";", "$", "this", "->", "set", "(", "$", "data", ")", ";", "if", "(", "!", "$", "this", "->", "validates", "(", ")", ")", "{", "$", "pass", "=", "false", ";", "}", "$", "this", "->", "validate", "=", "$", "modelValidation", ";", "}", "return", "$", "pass", ";", "}" ]
Validates data for a given section. @param array $data Record data. @param string $section Name of the section. @return boolean
[ "Validates", "data", "for", "a", "given", "section", "." ]
53ad4e919c51606dc81f2c716267d01ee768ade5
https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/Model/CommonDetailModel.php#L307-L319
3,255
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.getMbAssets
public function getMbAssets($wordpress = false) { return $wordpress ? $this->mbAssets->get('wordpress') : $this->mbAssets->get('plugin'); }
php
public function getMbAssets($wordpress = false) { return $wordpress ? $this->mbAssets->get('wordpress') : $this->mbAssets->get('plugin'); }
[ "public", "function", "getMbAssets", "(", "$", "wordpress", "=", "false", ")", "{", "return", "$", "wordpress", "?", "$", "this", "->", "mbAssets", "->", "get", "(", "'wordpress'", ")", ":", "$", "this", "->", "mbAssets", "->", "get", "(", "'plugin'", ")", ";", "}" ]
Get either MbAsset from the plugin or from Wordpress @param bool $wordpress If it's true, then it'll return the wordpress' MbAsset. If it's false, then it'll return the plugin's MbAsset. @return MbAsset
[ "Get", "either", "MbAsset", "from", "the", "plugin", "or", "from", "Wordpress" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L137-L140
3,256
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.setMbAssets
public function setMbAssets(MbAsset $mbAsset, $wordpress = false) { $this->mbAssets->put($wordpress ? 'wordpress' : 'plugin', $mbAsset); return $this; }
php
public function setMbAssets(MbAsset $mbAsset, $wordpress = false) { $this->mbAssets->put($wordpress ? 'wordpress' : 'plugin', $mbAsset); return $this; }
[ "public", "function", "setMbAssets", "(", "MbAsset", "$", "mbAsset", ",", "$", "wordpress", "=", "false", ")", "{", "$", "this", "->", "mbAssets", "->", "put", "(", "$", "wordpress", "?", "'wordpress'", ":", "'plugin'", ",", "$", "mbAsset", ")", ";", "return", "$", "this", ";", "}" ]
Set either MbAsset to the plugin or to the Wordpress @param MbAsset $mbAsset @param bool $wordpress If it's true, then it'll set MbAssets to the Wordpress. If it's false, then it'll set MbAssets to the plugin. @return MocaBonita current instance of MocaBonita
[ "Set", "either", "MbAsset", "to", "the", "plugin", "or", "to", "the", "Wordpress" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L171-L176
3,257
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.setMbEvent
public function setMbEvent(MbEvent $mbEvent, $dispatch) { if (is_array($dispatch)) { foreach ($dispatch as $event) { $this->setMbEvent($mbEvent, $event); } } else { if (!$this->mbEvents->has($dispatch)) { $this->mbEvents->put($dispatch, new Collection()); } $this->mbEvents->get($dispatch)->push($mbEvent); } return $this; }
php
public function setMbEvent(MbEvent $mbEvent, $dispatch) { if (is_array($dispatch)) { foreach ($dispatch as $event) { $this->setMbEvent($mbEvent, $event); } } else { if (!$this->mbEvents->has($dispatch)) { $this->mbEvents->put($dispatch, new Collection()); } $this->mbEvents->get($dispatch)->push($mbEvent); } return $this; }
[ "public", "function", "setMbEvent", "(", "MbEvent", "$", "mbEvent", ",", "$", "dispatch", ")", "{", "if", "(", "is_array", "(", "$", "dispatch", ")", ")", "{", "foreach", "(", "$", "dispatch", "as", "$", "event", ")", "{", "$", "this", "->", "setMbEvent", "(", "$", "mbEvent", ",", "$", "event", ")", ";", "}", "}", "else", "{", "if", "(", "!", "$", "this", "->", "mbEvents", "->", "has", "(", "$", "dispatch", ")", ")", "{", "$", "this", "->", "mbEvents", "->", "put", "(", "$", "dispatch", ",", "new", "Collection", "(", ")", ")", ";", "}", "$", "this", "->", "mbEvents", "->", "get", "(", "$", "dispatch", ")", "->", "push", "(", "$", "mbEvent", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set a MbEvent to a dispatcher type @param MbEvent $mbEvent @param string|array $dispatch name of dispatcher @return MocaBonita current instance of MocaBonita
[ "Set", "a", "MbEvent", "to", "a", "dispatcher", "type" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L223-L238
3,258
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.init
protected function init() { if (!defined('ABSPATH')) { die('MocaBonita must be loaded along with Wordpress!' . PHP_EOL); } $timezone = get_option('timezone_string'); if (!empty($timezone)) { date_default_timezone_set($timezone); } $mbAudit = new MbAudit(); $mbRequest = MbRequest::capture(); $mbResponse = MbResponse::create(); $mbRequest->ajax(); $mbRequest->setBlogAdmin(is_blog_admin()); $mbAudit->setRequest($mbRequest); $mbResponse->setMbRequest($mbRequest); $mbResponse->setMbAudit($mbAudit); $this->setPage($mbRequest->query('page')); $this->setAction($mbRequest->query('action', 'index')); $this->setMbRequest($mbRequest); $this->setMbResponse($mbResponse); $this->setMbAudit($mbAudit); $this->mbAssets = new Collection([ 'plugin' => new MbAsset(), 'wordpress' => new MbAsset(), ]); $this->mbEvents = new Collection(); $this->mbShortCodes = new Collection(); $this->mbPages = new Collection(); MbMigration::enableWpdbConnection(); }
php
protected function init() { if (!defined('ABSPATH')) { die('MocaBonita must be loaded along with Wordpress!' . PHP_EOL); } $timezone = get_option('timezone_string'); if (!empty($timezone)) { date_default_timezone_set($timezone); } $mbAudit = new MbAudit(); $mbRequest = MbRequest::capture(); $mbResponse = MbResponse::create(); $mbRequest->ajax(); $mbRequest->setBlogAdmin(is_blog_admin()); $mbAudit->setRequest($mbRequest); $mbResponse->setMbRequest($mbRequest); $mbResponse->setMbAudit($mbAudit); $this->setPage($mbRequest->query('page')); $this->setAction($mbRequest->query('action', 'index')); $this->setMbRequest($mbRequest); $this->setMbResponse($mbResponse); $this->setMbAudit($mbAudit); $this->mbAssets = new Collection([ 'plugin' => new MbAsset(), 'wordpress' => new MbAsset(), ]); $this->mbEvents = new Collection(); $this->mbShortCodes = new Collection(); $this->mbPages = new Collection(); MbMigration::enableWpdbConnection(); }
[ "protected", "function", "init", "(", ")", "{", "if", "(", "!", "defined", "(", "'ABSPATH'", ")", ")", "{", "die", "(", "'MocaBonita must be loaded along with Wordpress!'", ".", "PHP_EOL", ")", ";", "}", "$", "timezone", "=", "get_option", "(", "'timezone_string'", ")", ";", "if", "(", "!", "empty", "(", "$", "timezone", ")", ")", "{", "date_default_timezone_set", "(", "$", "timezone", ")", ";", "}", "$", "mbAudit", "=", "new", "MbAudit", "(", ")", ";", "$", "mbRequest", "=", "MbRequest", "::", "capture", "(", ")", ";", "$", "mbResponse", "=", "MbResponse", "::", "create", "(", ")", ";", "$", "mbRequest", "->", "ajax", "(", ")", ";", "$", "mbRequest", "->", "setBlogAdmin", "(", "is_blog_admin", "(", ")", ")", ";", "$", "mbAudit", "->", "setRequest", "(", "$", "mbRequest", ")", ";", "$", "mbResponse", "->", "setMbRequest", "(", "$", "mbRequest", ")", ";", "$", "mbResponse", "->", "setMbAudit", "(", "$", "mbAudit", ")", ";", "$", "this", "->", "setPage", "(", "$", "mbRequest", "->", "query", "(", "'page'", ")", ")", ";", "$", "this", "->", "setAction", "(", "$", "mbRequest", "->", "query", "(", "'action'", ",", "'index'", ")", ")", ";", "$", "this", "->", "setMbRequest", "(", "$", "mbRequest", ")", ";", "$", "this", "->", "setMbResponse", "(", "$", "mbResponse", ")", ";", "$", "this", "->", "setMbAudit", "(", "$", "mbAudit", ")", ";", "$", "this", "->", "mbAssets", "=", "new", "Collection", "(", "[", "'plugin'", "=>", "new", "MbAsset", "(", ")", ",", "'wordpress'", "=>", "new", "MbAsset", "(", ")", ",", "]", ")", ";", "$", "this", "->", "mbEvents", "=", "new", "Collection", "(", ")", ";", "$", "this", "->", "mbShortCodes", "=", "new", "Collection", "(", ")", ";", "$", "this", "->", "mbPages", "=", "new", "Collection", "(", ")", ";", "MbMigration", "::", "enableWpdbConnection", "(", ")", ";", "}" ]
Function that's called when MocaBonita is started. @return void
[ "Function", "that", "s", "called", "when", "MocaBonita", "is", "started", "." ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L313-L354
3,259
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.enableFlash
public function enableFlash($session = null) { if (!$this->getMbRequest()->hasSession()) { $this->enableSession($session); } $this->getMbRequest()->session()->getFlashBag(); return $this; }
php
public function enableFlash($session = null) { if (!$this->getMbRequest()->hasSession()) { $this->enableSession($session); } $this->getMbRequest()->session()->getFlashBag(); return $this; }
[ "public", "function", "enableFlash", "(", "$", "session", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "getMbRequest", "(", ")", "->", "hasSession", "(", ")", ")", "{", "$", "this", "->", "enableSession", "(", "$", "session", ")", ";", "}", "$", "this", "->", "getMbRequest", "(", ")", "->", "session", "(", ")", "->", "getFlashBag", "(", ")", ";", "return", "$", "this", ";", "}" ]
Enable flash session @param Session $session @return MocaBonita
[ "Enable", "flash", "session" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L378-L387
3,260
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.plugin
public static function plugin(\Closure $pluginStructure, $audit = false, $tag = "plugins_loaded") { $mocaBonita = self::getInstance(); $mocaBonita->audit = (bool) $audit; if ($mocaBonita->audit) { MbWPActionHook::addActionCallback('plugins_loaded', function () use ($mocaBonita) { try { MbDatabase::enableQueryLog(); $mocaBonita->getMbAudit()->setMocaBonita($mocaBonita); $mocaBonita->getMbAudit()->setUser(MbWpUser::getCurrentUser(true)); } catch (\Exception $e) { $mocaBonita->getMbResponse()->setContent($e); } }); MbWPActionHook::addActionCallback('shutdown', function () use ($mocaBonita) { try { $mocaBonita->getMbAudit()->run(); } catch (\Exception $e) { error_log($e->getMessage()); } finally { MbDatabase::disableQueryLog(); } }); } MbWPActionHook::addActionCallback($tag, function () use ($pluginStructure, $mocaBonita) { try { call_user_func_array($pluginStructure, [$mocaBonita]); $mocaBonita->runPlugin(); } catch (\Exception $e) { $mocaBonita->mbResponse->setContent($e); } finally { $mocaBonita->runHookCurrentAction(); $mocaBonita->getMbAudit()->setResponseStatusCode($mocaBonita->mbResponse->status()); $mocaBonita->getMbAudit()->setResponseHeader($mocaBonita->mbResponse->headers->all()); $mocaBonita->mbResponse->sendHeaders(); } }); }
php
public static function plugin(\Closure $pluginStructure, $audit = false, $tag = "plugins_loaded") { $mocaBonita = self::getInstance(); $mocaBonita->audit = (bool) $audit; if ($mocaBonita->audit) { MbWPActionHook::addActionCallback('plugins_loaded', function () use ($mocaBonita) { try { MbDatabase::enableQueryLog(); $mocaBonita->getMbAudit()->setMocaBonita($mocaBonita); $mocaBonita->getMbAudit()->setUser(MbWpUser::getCurrentUser(true)); } catch (\Exception $e) { $mocaBonita->getMbResponse()->setContent($e); } }); MbWPActionHook::addActionCallback('shutdown', function () use ($mocaBonita) { try { $mocaBonita->getMbAudit()->run(); } catch (\Exception $e) { error_log($e->getMessage()); } finally { MbDatabase::disableQueryLog(); } }); } MbWPActionHook::addActionCallback($tag, function () use ($pluginStructure, $mocaBonita) { try { call_user_func_array($pluginStructure, [$mocaBonita]); $mocaBonita->runPlugin(); } catch (\Exception $e) { $mocaBonita->mbResponse->setContent($e); } finally { $mocaBonita->runHookCurrentAction(); $mocaBonita->getMbAudit()->setResponseStatusCode($mocaBonita->mbResponse->status()); $mocaBonita->getMbAudit()->setResponseHeader($mocaBonita->mbResponse->headers->all()); $mocaBonita->mbResponse->sendHeaders(); } }); }
[ "public", "static", "function", "plugin", "(", "\\", "Closure", "$", "pluginStructure", ",", "$", "audit", "=", "false", ",", "$", "tag", "=", "\"plugins_loaded\"", ")", "{", "$", "mocaBonita", "=", "self", "::", "getInstance", "(", ")", ";", "$", "mocaBonita", "->", "audit", "=", "(", "bool", ")", "$", "audit", ";", "if", "(", "$", "mocaBonita", "->", "audit", ")", "{", "MbWPActionHook", "::", "addActionCallback", "(", "'plugins_loaded'", ",", "function", "(", ")", "use", "(", "$", "mocaBonita", ")", "{", "try", "{", "MbDatabase", "::", "enableQueryLog", "(", ")", ";", "$", "mocaBonita", "->", "getMbAudit", "(", ")", "->", "setMocaBonita", "(", "$", "mocaBonita", ")", ";", "$", "mocaBonita", "->", "getMbAudit", "(", ")", "->", "setUser", "(", "MbWpUser", "::", "getCurrentUser", "(", "true", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "mocaBonita", "->", "getMbResponse", "(", ")", "->", "setContent", "(", "$", "e", ")", ";", "}", "}", ")", ";", "MbWPActionHook", "::", "addActionCallback", "(", "'shutdown'", ",", "function", "(", ")", "use", "(", "$", "mocaBonita", ")", "{", "try", "{", "$", "mocaBonita", "->", "getMbAudit", "(", ")", "->", "run", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "error_log", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "finally", "{", "MbDatabase", "::", "disableQueryLog", "(", ")", ";", "}", "}", ")", ";", "}", "MbWPActionHook", "::", "addActionCallback", "(", "$", "tag", ",", "function", "(", ")", "use", "(", "$", "pluginStructure", ",", "$", "mocaBonita", ")", "{", "try", "{", "call_user_func_array", "(", "$", "pluginStructure", ",", "[", "$", "mocaBonita", "]", ")", ";", "$", "mocaBonita", "->", "runPlugin", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "mocaBonita", "->", "mbResponse", "->", "setContent", "(", "$", "e", ")", ";", "}", "finally", "{", "$", "mocaBonita", "->", "runHookCurrentAction", "(", ")", ";", "$", "mocaBonita", "->", "getMbAudit", "(", ")", "->", "setResponseStatusCode", "(", "$", "mocaBonita", "->", "mbResponse", "->", "status", "(", ")", ")", ";", "$", "mocaBonita", "->", "getMbAudit", "(", ")", "->", "setResponseHeader", "(", "$", "mocaBonita", "->", "mbResponse", "->", "headers", "->", "all", "(", ")", ")", ";", "$", "mocaBonita", "->", "mbResponse", "->", "sendHeaders", "(", ")", ";", "}", "}", ")", ";", "}" ]
Set the callback that has the plugin's structure @param $pluginStructure \Closure Callback that will be called @param bool $audit Set status audit @param string $tag @return void
[ "Set", "the", "callback", "that", "has", "the", "plugin", "s", "structure" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L399-L441
3,261
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.active
public static function active(\Closure $active) { $mocaBonita = self::getInstance(); register_activation_hook(MbPath::pBaseN(), function () use ($active, $mocaBonita) { try { MbMigration::enablePdoConnection(); call_user_func_array($active, [$mocaBonita]); } catch (\Exception $e) { deactivate_plugins(basename(MbPath::pBaseN())); wp_die($e->getMessage()); } }); }
php
public static function active(\Closure $active) { $mocaBonita = self::getInstance(); register_activation_hook(MbPath::pBaseN(), function () use ($active, $mocaBonita) { try { MbMigration::enablePdoConnection(); call_user_func_array($active, [$mocaBonita]); } catch (\Exception $e) { deactivate_plugins(basename(MbPath::pBaseN())); wp_die($e->getMessage()); } }); }
[ "public", "static", "function", "active", "(", "\\", "Closure", "$", "active", ")", "{", "$", "mocaBonita", "=", "self", "::", "getInstance", "(", ")", ";", "register_activation_hook", "(", "MbPath", "::", "pBaseN", "(", ")", ",", "function", "(", ")", "use", "(", "$", "active", ",", "$", "mocaBonita", ")", "{", "try", "{", "MbMigration", "::", "enablePdoConnection", "(", ")", ";", "call_user_func_array", "(", "$", "active", ",", "[", "$", "mocaBonita", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "deactivate_plugins", "(", "basename", "(", "MbPath", "::", "pBaseN", "(", ")", ")", ")", ";", "wp_die", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", ")", ";", "}" ]
Set the callback that will be called when the plugin is activated @param $active \Closure Callback that will be called @return void
[ "Set", "the", "callback", "that", "will", "be", "called", "when", "the", "plugin", "is", "activated" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L450-L463
3,262
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.deactive
public static function deactive(\Closure $deactive) { $mocaBonita = self::getInstance(); register_deactivation_hook(MbPath::pBaseN(), function () use ($deactive, $mocaBonita) { try { MbMigration::enablePdoConnection(); call_user_func_array($deactive, [$mocaBonita]); } catch (\Exception $e) { MbException::registerError($e); wp_die($e->getMessage()); } }); }
php
public static function deactive(\Closure $deactive) { $mocaBonita = self::getInstance(); register_deactivation_hook(MbPath::pBaseN(), function () use ($deactive, $mocaBonita) { try { MbMigration::enablePdoConnection(); call_user_func_array($deactive, [$mocaBonita]); } catch (\Exception $e) { MbException::registerError($e); wp_die($e->getMessage()); } }); }
[ "public", "static", "function", "deactive", "(", "\\", "Closure", "$", "deactive", ")", "{", "$", "mocaBonita", "=", "self", "::", "getInstance", "(", ")", ";", "register_deactivation_hook", "(", "MbPath", "::", "pBaseN", "(", ")", ",", "function", "(", ")", "use", "(", "$", "deactive", ",", "$", "mocaBonita", ")", "{", "try", "{", "MbMigration", "::", "enablePdoConnection", "(", ")", ";", "call_user_func_array", "(", "$", "deactive", ",", "[", "$", "mocaBonita", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "MbException", "::", "registerError", "(", "$", "e", ")", ";", "wp_die", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", ")", ";", "}" ]
Set the callback that will be called when the plugin is deactivated @param $deactive \Closure Callback that will be called @return void
[ "Set", "the", "callback", "that", "will", "be", "called", "when", "the", "plugin", "is", "deactivated" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L472-L485
3,263
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.runPlugin
private function runPlugin() { //Call MbEvent from wordpress (START_WORDPRESS) MbEvent::callEvents($this, MbEvent::START_WORDPRESS, $this); if (!$this->getMbResponse()->isRedirection()) { //Call the MbAsset from WordPress $this->getMbAssets(true)->runAssets('*'); //Get all query params from url $paramsQuery = $this->mbRequest->query(); //Check if there is a pagination attribute if (isset($paramsQuery[MbDatabaseQueryBuilder::getPagination()])) { $pagination = $paramsQuery[MbDatabaseQueryBuilder::getPagination()]; unset($paramsQuery[MbDatabaseQueryBuilder::getPagination()]); } else { $pagination = 1; } //Get url without pagination query $urlWihtouPagination = $this->mbRequest->urlQuery($paramsQuery); //Set url without pagination query to the Paginator Resolver Paginator::currentPathResolver(function () use ($urlWihtouPagination) { return $urlWihtouPagination; }); //Set current pagination to the Paginator Resolver Paginator::currentPageResolver(function () use ($pagination) { return is_numeric($pagination) ? (int) $pagination : 1; }); //Call the Shortcode from plugin foreach ($this->mbShortCodes as $shortcode) { $shortcode->runShortcode($this->getMbAssets(), $this->mbRequest, $this->mbResponse); } //Add wordpress administrative menu if needed if ($this->getMbRequest()->isBlogAdmin()) { MbWPActionHook::addAction('admin_menu', $this, 'addAdminMenuToWordpress'); } if ($this->isMocabonitaPage()) { //Get current MbPage $mbPage = $this->getMbPage($this->page); //Set current MbPage to MbRequest $this->getMbRequest()->setMbPage($mbPage); try { //Call MvEvent from page (BEFORE_PAGE) MbEvent::callEvents($this, MbEvent::BEFORE_PAGE, $mbPage); //Call the MbAsset from plugin $this->getMbAssets()->runAssets('plugin'); //Call the MbAsset from page $mbPage->getMbAsset()->runAssets($this->page); //Run current page $this->runCurrentPage($mbPage); //Call MvEvent from page (AFTER_PAGE) MbEvent::callEvents($this, MbEvent::AFTER_PAGE, $mbPage); } catch (\Exception $e) { //Call MvEvent from page (EXCEPTION_PAGE) MbEvent::callEvents($this, MbEvent::EXCEPTION_PAGE, $e); throw $e; } finally { //Call MvEvent from page (FINISH_PAGE) MbEvent::callEvents($this, MbEvent::FINISH_PAGE, $mbPage); } } } //Call MbEvent from wordpress (FINISH_WORDPRESS) MbEvent::callEvents($this, MbEvent::FINISH_WORDPRESS, $this); }
php
private function runPlugin() { //Call MbEvent from wordpress (START_WORDPRESS) MbEvent::callEvents($this, MbEvent::START_WORDPRESS, $this); if (!$this->getMbResponse()->isRedirection()) { //Call the MbAsset from WordPress $this->getMbAssets(true)->runAssets('*'); //Get all query params from url $paramsQuery = $this->mbRequest->query(); //Check if there is a pagination attribute if (isset($paramsQuery[MbDatabaseQueryBuilder::getPagination()])) { $pagination = $paramsQuery[MbDatabaseQueryBuilder::getPagination()]; unset($paramsQuery[MbDatabaseQueryBuilder::getPagination()]); } else { $pagination = 1; } //Get url without pagination query $urlWihtouPagination = $this->mbRequest->urlQuery($paramsQuery); //Set url without pagination query to the Paginator Resolver Paginator::currentPathResolver(function () use ($urlWihtouPagination) { return $urlWihtouPagination; }); //Set current pagination to the Paginator Resolver Paginator::currentPageResolver(function () use ($pagination) { return is_numeric($pagination) ? (int) $pagination : 1; }); //Call the Shortcode from plugin foreach ($this->mbShortCodes as $shortcode) { $shortcode->runShortcode($this->getMbAssets(), $this->mbRequest, $this->mbResponse); } //Add wordpress administrative menu if needed if ($this->getMbRequest()->isBlogAdmin()) { MbWPActionHook::addAction('admin_menu', $this, 'addAdminMenuToWordpress'); } if ($this->isMocabonitaPage()) { //Get current MbPage $mbPage = $this->getMbPage($this->page); //Set current MbPage to MbRequest $this->getMbRequest()->setMbPage($mbPage); try { //Call MvEvent from page (BEFORE_PAGE) MbEvent::callEvents($this, MbEvent::BEFORE_PAGE, $mbPage); //Call the MbAsset from plugin $this->getMbAssets()->runAssets('plugin'); //Call the MbAsset from page $mbPage->getMbAsset()->runAssets($this->page); //Run current page $this->runCurrentPage($mbPage); //Call MvEvent from page (AFTER_PAGE) MbEvent::callEvents($this, MbEvent::AFTER_PAGE, $mbPage); } catch (\Exception $e) { //Call MvEvent from page (EXCEPTION_PAGE) MbEvent::callEvents($this, MbEvent::EXCEPTION_PAGE, $e); throw $e; } finally { //Call MvEvent from page (FINISH_PAGE) MbEvent::callEvents($this, MbEvent::FINISH_PAGE, $mbPage); } } } //Call MbEvent from wordpress (FINISH_WORDPRESS) MbEvent::callEvents($this, MbEvent::FINISH_WORDPRESS, $this); }
[ "private", "function", "runPlugin", "(", ")", "{", "//Call MbEvent from wordpress (START_WORDPRESS)", "MbEvent", "::", "callEvents", "(", "$", "this", ",", "MbEvent", "::", "START_WORDPRESS", ",", "$", "this", ")", ";", "if", "(", "!", "$", "this", "->", "getMbResponse", "(", ")", "->", "isRedirection", "(", ")", ")", "{", "//Call the MbAsset from WordPress", "$", "this", "->", "getMbAssets", "(", "true", ")", "->", "runAssets", "(", "'*'", ")", ";", "//Get all query params from url", "$", "paramsQuery", "=", "$", "this", "->", "mbRequest", "->", "query", "(", ")", ";", "//Check if there is a pagination attribute", "if", "(", "isset", "(", "$", "paramsQuery", "[", "MbDatabaseQueryBuilder", "::", "getPagination", "(", ")", "]", ")", ")", "{", "$", "pagination", "=", "$", "paramsQuery", "[", "MbDatabaseQueryBuilder", "::", "getPagination", "(", ")", "]", ";", "unset", "(", "$", "paramsQuery", "[", "MbDatabaseQueryBuilder", "::", "getPagination", "(", ")", "]", ")", ";", "}", "else", "{", "$", "pagination", "=", "1", ";", "}", "//Get url without pagination query", "$", "urlWihtouPagination", "=", "$", "this", "->", "mbRequest", "->", "urlQuery", "(", "$", "paramsQuery", ")", ";", "//Set url without pagination query to the Paginator Resolver", "Paginator", "::", "currentPathResolver", "(", "function", "(", ")", "use", "(", "$", "urlWihtouPagination", ")", "{", "return", "$", "urlWihtouPagination", ";", "}", ")", ";", "//Set current pagination to the Paginator Resolver", "Paginator", "::", "currentPageResolver", "(", "function", "(", ")", "use", "(", "$", "pagination", ")", "{", "return", "is_numeric", "(", "$", "pagination", ")", "?", "(", "int", ")", "$", "pagination", ":", "1", ";", "}", ")", ";", "//Call the Shortcode from plugin", "foreach", "(", "$", "this", "->", "mbShortCodes", "as", "$", "shortcode", ")", "{", "$", "shortcode", "->", "runShortcode", "(", "$", "this", "->", "getMbAssets", "(", ")", ",", "$", "this", "->", "mbRequest", ",", "$", "this", "->", "mbResponse", ")", ";", "}", "//Add wordpress administrative menu if needed", "if", "(", "$", "this", "->", "getMbRequest", "(", ")", "->", "isBlogAdmin", "(", ")", ")", "{", "MbWPActionHook", "::", "addAction", "(", "'admin_menu'", ",", "$", "this", ",", "'addAdminMenuToWordpress'", ")", ";", "}", "if", "(", "$", "this", "->", "isMocabonitaPage", "(", ")", ")", "{", "//Get current MbPage", "$", "mbPage", "=", "$", "this", "->", "getMbPage", "(", "$", "this", "->", "page", ")", ";", "//Set current MbPage to MbRequest", "$", "this", "->", "getMbRequest", "(", ")", "->", "setMbPage", "(", "$", "mbPage", ")", ";", "try", "{", "//Call MvEvent from page (BEFORE_PAGE)", "MbEvent", "::", "callEvents", "(", "$", "this", ",", "MbEvent", "::", "BEFORE_PAGE", ",", "$", "mbPage", ")", ";", "//Call the MbAsset from plugin", "$", "this", "->", "getMbAssets", "(", ")", "->", "runAssets", "(", "'plugin'", ")", ";", "//Call the MbAsset from page", "$", "mbPage", "->", "getMbAsset", "(", ")", "->", "runAssets", "(", "$", "this", "->", "page", ")", ";", "//Run current page", "$", "this", "->", "runCurrentPage", "(", "$", "mbPage", ")", ";", "//Call MvEvent from page (AFTER_PAGE)", "MbEvent", "::", "callEvents", "(", "$", "this", ",", "MbEvent", "::", "AFTER_PAGE", ",", "$", "mbPage", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "//Call MvEvent from page (EXCEPTION_PAGE)", "MbEvent", "::", "callEvents", "(", "$", "this", ",", "MbEvent", "::", "EXCEPTION_PAGE", ",", "$", "e", ")", ";", "throw", "$", "e", ";", "}", "finally", "{", "//Call MvEvent from page (FINISH_PAGE)", "MbEvent", "::", "callEvents", "(", "$", "this", ",", "MbEvent", "::", "FINISH_PAGE", ",", "$", "mbPage", ")", ";", "}", "}", "}", "//Call MbEvent from wordpress (FINISH_WORDPRESS)", "MbEvent", "::", "callEvents", "(", "$", "this", ",", "MbEvent", "::", "FINISH_WORDPRESS", ",", "$", "this", ")", ";", "}" ]
Initialize the processing of the plugin and its resources. @throws \Exception @return void
[ "Initialize", "the", "processing", "of", "the", "plugin", "and", "its", "resources", "." ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L512-L595
3,264
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.runHookCurrentAction
private function runHookCurrentAction() { //Check if needed add the hook if (!$this->getMbRequest()->isMocaBonitaPage() || $this->getMbRequest()->isBlogAdmin()) { return false; } //Check if a user is logged in Wordpress if ($this->mbRequest->isLogged()) { //Check if the current request is ajax if ($this->mbRequest->isAjax()) { //add hook admin_ajax $actionHook = "wp_ajax_{$this->getAction()}"; } else { //add hook admin_post $actionHook = "admin_post_{$this->getAction()}"; } } else { //Check if the current request is ajax if ($this->mbRequest->isAjax()) { //add hook nopriv_ajax $actionHook = "wp_ajax_nopriv_{$this->getAction()}"; } else { //add hook nopriv_post $actionHook = "admin_post_nopriv_{$this->getAction()}"; } } //Register WordpressHook MbWPActionHook::addAction($actionHook, $this, 'sendContent'); return true; }
php
private function runHookCurrentAction() { //Check if needed add the hook if (!$this->getMbRequest()->isMocaBonitaPage() || $this->getMbRequest()->isBlogAdmin()) { return false; } //Check if a user is logged in Wordpress if ($this->mbRequest->isLogged()) { //Check if the current request is ajax if ($this->mbRequest->isAjax()) { //add hook admin_ajax $actionHook = "wp_ajax_{$this->getAction()}"; } else { //add hook admin_post $actionHook = "admin_post_{$this->getAction()}"; } } else { //Check if the current request is ajax if ($this->mbRequest->isAjax()) { //add hook nopriv_ajax $actionHook = "wp_ajax_nopriv_{$this->getAction()}"; } else { //add hook nopriv_post $actionHook = "admin_post_nopriv_{$this->getAction()}"; } } //Register WordpressHook MbWPActionHook::addAction($actionHook, $this, 'sendContent'); return true; }
[ "private", "function", "runHookCurrentAction", "(", ")", "{", "//Check if needed add the hook", "if", "(", "!", "$", "this", "->", "getMbRequest", "(", ")", "->", "isMocaBonitaPage", "(", ")", "||", "$", "this", "->", "getMbRequest", "(", ")", "->", "isBlogAdmin", "(", ")", ")", "{", "return", "false", ";", "}", "//Check if a user is logged in Wordpress", "if", "(", "$", "this", "->", "mbRequest", "->", "isLogged", "(", ")", ")", "{", "//Check if the current request is ajax", "if", "(", "$", "this", "->", "mbRequest", "->", "isAjax", "(", ")", ")", "{", "//add hook admin_ajax", "$", "actionHook", "=", "\"wp_ajax_{$this->getAction()}\"", ";", "}", "else", "{", "//add hook admin_post", "$", "actionHook", "=", "\"admin_post_{$this->getAction()}\"", ";", "}", "}", "else", "{", "//Check if the current request is ajax", "if", "(", "$", "this", "->", "mbRequest", "->", "isAjax", "(", ")", ")", "{", "//add hook nopriv_ajax", "$", "actionHook", "=", "\"wp_ajax_nopriv_{$this->getAction()}\"", ";", "}", "else", "{", "//add hook nopriv_post", "$", "actionHook", "=", "\"admin_post_nopriv_{$this->getAction()}\"", ";", "}", "}", "//Register WordpressHook", "MbWPActionHook", "::", "addAction", "(", "$", "actionHook", ",", "$", "this", ",", "'sendContent'", ")", ";", "return", "true", ";", "}" ]
Add Wordpress Hook for current action if needed @return boolean
[ "Add", "Wordpress", "Hook", "for", "current", "action", "if", "needed" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L768-L801
3,265
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.isMocabonitaPage
protected function isMocabonitaPage() { if (is_null($this->page)) { $this->getMbRequest()->setMocaBonitaPage(false); return false; } if (is_null($this->getMbRequest()->isMocaBonitaPage())) { $this->getMbRequest()->setMocaBonitaPage($this->mbPages->has($this->page)); } return $this->getMbRequest()->isMocaBonitaPage(); }
php
protected function isMocabonitaPage() { if (is_null($this->page)) { $this->getMbRequest()->setMocaBonitaPage(false); return false; } if (is_null($this->getMbRequest()->isMocaBonitaPage())) { $this->getMbRequest()->setMocaBonitaPage($this->mbPages->has($this->page)); } return $this->getMbRequest()->isMocaBonitaPage(); }
[ "protected", "function", "isMocabonitaPage", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "page", ")", ")", "{", "$", "this", "->", "getMbRequest", "(", ")", "->", "setMocaBonitaPage", "(", "false", ")", ";", "return", "false", ";", "}", "if", "(", "is_null", "(", "$", "this", "->", "getMbRequest", "(", ")", "->", "isMocaBonitaPage", "(", ")", ")", ")", "{", "$", "this", "->", "getMbRequest", "(", ")", "->", "setMocaBonitaPage", "(", "$", "this", "->", "mbPages", "->", "has", "(", "$", "this", "->", "page", ")", ")", ";", "}", "return", "$", "this", "->", "getMbRequest", "(", ")", "->", "isMocaBonitaPage", "(", ")", ";", "}" ]
Check if the current page is a Mocabonita page @return bool
[ "Check", "if", "the", "current", "page", "is", "a", "Mocabonita", "page" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L818-L831
3,266
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.getMbPage
public function getMbPage($slugPage) { if (!$this->mbPages->has($slugPage)) { throw new MbException("The page {$slugPage} has not been added to MocaBonita's list of pages!"); } return $this->mbPages->get($slugPage); }
php
public function getMbPage($slugPage) { if (!$this->mbPages->has($slugPage)) { throw new MbException("The page {$slugPage} has not been added to MocaBonita's list of pages!"); } return $this->mbPages->get($slugPage); }
[ "public", "function", "getMbPage", "(", "$", "slugPage", ")", "{", "if", "(", "!", "$", "this", "->", "mbPages", "->", "has", "(", "$", "slugPage", ")", ")", "{", "throw", "new", "MbException", "(", "\"The page {$slugPage} has not been added to MocaBonita's list of pages!\"", ")", ";", "}", "return", "$", "this", "->", "mbPages", "->", "get", "(", "$", "slugPage", ")", ";", "}" ]
Get MbPage of slug @param string $slugPage slug of the MbPage @throws MbException @return MbPage
[ "Get", "MbPage", "of", "slug" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L842-L849
3,267
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.getMbShortcode
public function getMbShortcode($shortcodeName) { if (!$this->mbShortCodes->has($shortcodeName)) { throw new MbException("The shortcode {$shortcodeName} has not been added to the MocaBonita shortcode list!"); } return $this->mbShortCodes->get($shortcodeName); }
php
public function getMbShortcode($shortcodeName) { if (!$this->mbShortCodes->has($shortcodeName)) { throw new MbException("The shortcode {$shortcodeName} has not been added to the MocaBonita shortcode list!"); } return $this->mbShortCodes->get($shortcodeName); }
[ "public", "function", "getMbShortcode", "(", "$", "shortcodeName", ")", "{", "if", "(", "!", "$", "this", "->", "mbShortCodes", "->", "has", "(", "$", "shortcodeName", ")", ")", "{", "throw", "new", "MbException", "(", "\"The shortcode {$shortcodeName} has not been added to the MocaBonita shortcode list!\"", ")", ";", "}", "return", "$", "this", "->", "mbShortCodes", "->", "get", "(", "$", "shortcodeName", ")", ";", "}" ]
Get MbShortcode of name @param string $shortcodeName Name of shortcode @throws MbException @return MbShortCode
[ "Get", "MbShortcode", "of", "name" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L860-L867
3,268
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.addMbPageStructure
public function addMbPageStructure($pageName, MbPageStructure $mbPageStructure) { $mbPageStructure->setMbPage(MbPage::create($pageName)); $mbPageStructure->enablePage(); $mbPageStructure->execute($this->getMbRequest(), $this->getMbResponse(), $this); }
php
public function addMbPageStructure($pageName, MbPageStructure $mbPageStructure) { $mbPageStructure->setMbPage(MbPage::create($pageName)); $mbPageStructure->enablePage(); $mbPageStructure->execute($this->getMbRequest(), $this->getMbResponse(), $this); }
[ "public", "function", "addMbPageStructure", "(", "$", "pageName", ",", "MbPageStructure", "$", "mbPageStructure", ")", "{", "$", "mbPageStructure", "->", "setMbPage", "(", "MbPage", "::", "create", "(", "$", "pageName", ")", ")", ";", "$", "mbPageStructure", "->", "enablePage", "(", ")", ";", "$", "mbPageStructure", "->", "execute", "(", "$", "this", "->", "getMbRequest", "(", ")", ",", "$", "this", "->", "getMbResponse", "(", ")", ",", "$", "this", ")", ";", "}" ]
Add page structure @param $pageName @param MbPageStructure $mbPageStructure
[ "Add", "page", "structure" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L875-L880
3,269
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.addMbPage
public function addMbPage(MbPage $mbPage) { $mbPage->setSubMenu(false); $mbPage->setMainMenu(true); $this->mbPages->put($mbPage->getSlug(), $mbPage); foreach ($mbPage->getSubPages() as $subPage) { $this->addSubMbPage($subPage); $subPage->setParentPage($mbPage); } return $this; }
php
public function addMbPage(MbPage $mbPage) { $mbPage->setSubMenu(false); $mbPage->setMainMenu(true); $this->mbPages->put($mbPage->getSlug(), $mbPage); foreach ($mbPage->getSubPages() as $subPage) { $this->addSubMbPage($subPage); $subPage->setParentPage($mbPage); } return $this; }
[ "public", "function", "addMbPage", "(", "MbPage", "$", "mbPage", ")", "{", "$", "mbPage", "->", "setSubMenu", "(", "false", ")", ";", "$", "mbPage", "->", "setMainMenu", "(", "true", ")", ";", "$", "this", "->", "mbPages", "->", "put", "(", "$", "mbPage", "->", "getSlug", "(", ")", ",", "$", "mbPage", ")", ";", "foreach", "(", "$", "mbPage", "->", "getSubPages", "(", ")", "as", "$", "subPage", ")", "{", "$", "this", "->", "addSubMbPage", "(", "$", "subPage", ")", ";", "$", "subPage", "->", "setParentPage", "(", "$", "mbPage", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a MbPage to MocaBonita as main menu @param MbPage $mbPage @return MocaBonita current instance of MocaBonita
[ "Add", "a", "MbPage", "to", "MocaBonita", "as", "main", "menu" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L889-L903
3,270
jhorlima/wp-mocabonita
src/MocaBonita.php
MocaBonita.addSubMbPage
public function addSubMbPage(MbPage $mbPage) { $mbPage->setMainMenu(false); $mbPage->setSubMenu(true); $this->mbPages->put($mbPage->getSlug(), $mbPage); return $this; }
php
public function addSubMbPage(MbPage $mbPage) { $mbPage->setMainMenu(false); $mbPage->setSubMenu(true); $this->mbPages->put($mbPage->getSlug(), $mbPage); return $this; }
[ "public", "function", "addSubMbPage", "(", "MbPage", "$", "mbPage", ")", "{", "$", "mbPage", "->", "setMainMenu", "(", "false", ")", ";", "$", "mbPage", "->", "setSubMenu", "(", "true", ")", ";", "$", "this", "->", "mbPages", "->", "put", "(", "$", "mbPage", "->", "getSlug", "(", ")", ",", "$", "mbPage", ")", ";", "return", "$", "this", ";", "}" ]
Add a MbPage to MocaBonita as submenu @param MbPage $mbPage @return MocaBonita current instance of MocaBonita
[ "Add", "a", "MbPage", "to", "MocaBonita", "as", "submenu" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/MocaBonita.php#L912-L921
3,271
GrupaZero/core
src/Gzero/Core/Models/Route.php
Route.buildUniquePath
public static function buildUniquePath($path, $languageCode) { $count = self::query() ->where('language_code', $languageCode) ->whereRaw("path ~ '^$path($|-[0-9]+$)'") ->count(); return ($count) ? $path . '-' . $count : $path; }
php
public static function buildUniquePath($path, $languageCode) { $count = self::query() ->where('language_code', $languageCode) ->whereRaw("path ~ '^$path($|-[0-9]+$)'") ->count(); return ($count) ? $path . '-' . $count : $path; }
[ "public", "static", "function", "buildUniquePath", "(", "$", "path", ",", "$", "languageCode", ")", "{", "$", "count", "=", "self", "::", "query", "(", ")", "->", "where", "(", "'language_code'", ",", "$", "languageCode", ")", "->", "whereRaw", "(", "\"path ~ '^$path($|-[0-9]+$)'\"", ")", "->", "count", "(", ")", ";", "return", "(", "$", "count", ")", "?", "$", "path", ".", "'-'", ".", "$", "count", ":", "$", "path", ";", "}" ]
Function returns an unique path address from given path in specific language @param string $path string path address to search for @param string $languageCode translation language code @return string an unique path address
[ "Function", "returns", "an", "unique", "path", "address", "from", "given", "path", "in", "specific", "language" ]
093e515234fa0385b259ba4d8bc7832174a44eab
https://github.com/GrupaZero/core/blob/093e515234fa0385b259ba4d8bc7832174a44eab/src/Gzero/Core/Models/Route.php#L67-L75
3,272
laradic/service-provider
src/Plugins/Events.php
Events.startEventsPlugin
protected function startEventsPlugin($app) { $this->onRegister('events', function ($app) { $events = $this->app->make(Dispatcher::class); foreach ($this->events() as $event => $listeners) { foreach ($listeners as $listener) { $events->listen($event, $listener); } } // }) // $this->onBoot('events', function ($app) { // $events = $this->app->make('events'); foreach ($this->listens() as $event => $listeners) { foreach ($listeners as $listener) { $events->listen($event, $listener); } } foreach ($this->subscribe as $subscriber) { $events->subscribe($subscriber); } }); }
php
protected function startEventsPlugin($app) { $this->onRegister('events', function ($app) { $events = $this->app->make(Dispatcher::class); foreach ($this->events() as $event => $listeners) { foreach ($listeners as $listener) { $events->listen($event, $listener); } } // }) // $this->onBoot('events', function ($app) { // $events = $this->app->make('events'); foreach ($this->listens() as $event => $listeners) { foreach ($listeners as $listener) { $events->listen($event, $listener); } } foreach ($this->subscribe as $subscriber) { $events->subscribe($subscriber); } }); }
[ "protected", "function", "startEventsPlugin", "(", "$", "app", ")", "{", "$", "this", "->", "onRegister", "(", "'events'", ",", "function", "(", "$", "app", ")", "{", "$", "events", "=", "$", "this", "->", "app", "->", "make", "(", "Dispatcher", "::", "class", ")", ";", "foreach", "(", "$", "this", "->", "events", "(", ")", "as", "$", "event", "=>", "$", "listeners", ")", "{", "foreach", "(", "$", "listeners", "as", "$", "listener", ")", "{", "$", "events", "->", "listen", "(", "$", "event", ",", "$", "listener", ")", ";", "}", "}", "// })", "// $this->onBoot('events', function ($app) {", "// $events = $this->app->make('events');", "foreach", "(", "$", "this", "->", "listens", "(", ")", "as", "$", "event", "=>", "$", "listeners", ")", "{", "foreach", "(", "$", "listeners", "as", "$", "listener", ")", "{", "$", "events", "->", "listen", "(", "$", "event", ",", "$", "listener", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "subscribe", "as", "$", "subscriber", ")", "{", "$", "events", "->", "subscribe", "(", "$", "subscriber", ")", ";", "}", "}", ")", ";", "}" ]
startEventsPlugin method. @param \Illuminate\Foundation\Application $app
[ "startEventsPlugin", "method", "." ]
b1428d566b97b3662b405c64ff0cad8a89102033
https://github.com/laradic/service-provider/blob/b1428d566b97b3662b405c64ff0cad8a89102033/src/Plugins/Events.php#L56-L80
3,273
laradic/service-provider
src/Plugins/Events.php
Events.on
protected function on($events, $handler) { $dispatcher = $this->app->make('events'); $dispatcher->listen($events, $handler); }
php
protected function on($events, $handler) { $dispatcher = $this->app->make('events'); $dispatcher->listen($events, $handler); }
[ "protected", "function", "on", "(", "$", "events", ",", "$", "handler", ")", "{", "$", "dispatcher", "=", "$", "this", "->", "app", "->", "make", "(", "'events'", ")", ";", "$", "dispatcher", "->", "listen", "(", "$", "events", ",", "$", "handler", ")", ";", "}" ]
on method. @param $events @param $handler
[ "on", "method", "." ]
b1428d566b97b3662b405c64ff0cad8a89102033
https://github.com/laradic/service-provider/blob/b1428d566b97b3662b405c64ff0cad8a89102033/src/Plugins/Events.php#L88-L92
3,274
donbidon/core
src/Friendlification.php
Friendlification.getConstNameByValue
public static function getConstNameByValue($class, $value) { $constants = static::getReflection($class)->getConstants(); $result = array_search($value, $constants); return $result; }
php
public static function getConstNameByValue($class, $value) { $constants = static::getReflection($class)->getConstants(); $result = array_search($value, $constants); return $result; }
[ "public", "static", "function", "getConstNameByValue", "(", "$", "class", ",", "$", "value", ")", "{", "$", "constants", "=", "static", "::", "getReflection", "(", "$", "class", ")", "->", "getConstants", "(", ")", ";", "$", "result", "=", "array_search", "(", "$", "value", ",", "$", "constants", ")", ";", "return", "$", "result", ";", "}" ]
Returns class const name by its value. ```php use donbidon\Core\Friendlification; class Foo { const ONE = 1; const TWO = 2; } var_dump(Friendlification::getConstNameByValue('Foo', 1)); var_dump(Friendlification::getConstNameByValue('Foo', 2)); var_dump(Friendlification::getConstNameByValue('Foo', 3)); ``` will output: ``` string(3) "ONE" string(3) "TWO" bool(false) ``` @param string $class @param mixed $value @return string|false @throws \ReflectionException Risen from static::getReflection().
[ "Returns", "class", "const", "name", "by", "its", "value", "." ]
a22030c98ffb2dcbb8eb7a12f0498d88fb7531fe
https://github.com/donbidon/core/blob/a22030c98ffb2dcbb8eb7a12f0498d88fb7531fe/src/Friendlification.php#L57-L63
3,275
donbidon/core
src/Friendlification.php
Friendlification.getReflection
protected static function getReflection($class) { if (!isset(self::$reflections[$class])) { self::$reflections[$class] = new ReflectionClass($class); } $result = self::$reflections[$class]; return $result; }
php
protected static function getReflection($class) { if (!isset(self::$reflections[$class])) { self::$reflections[$class] = new ReflectionClass($class); } $result = self::$reflections[$class]; return $result; }
[ "protected", "static", "function", "getReflection", "(", "$", "class", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "reflections", "[", "$", "class", "]", ")", ")", "{", "self", "::", "$", "reflections", "[", "$", "class", "]", "=", "new", "ReflectionClass", "(", "$", "class", ")", ";", "}", "$", "result", "=", "self", "::", "$", "reflections", "[", "$", "class", "]", ";", "return", "$", "result", ";", "}" ]
Returns reflection by class name. @param string $class @return ReflectionClass @throws \ReflectionException Risen from ReflectionClass::__construct(). @internal
[ "Returns", "reflection", "by", "class", "name", "." ]
a22030c98ffb2dcbb8eb7a12f0498d88fb7531fe
https://github.com/donbidon/core/blob/a22030c98ffb2dcbb8eb7a12f0498d88fb7531fe/src/Friendlification.php#L73-L81
3,276
MehrAlsNix/Notifier
src/Notification.php
Notification.execute
protected function execute($command) { $status = null; $result = array(); exec($command, $result, $status); return !$status ? $result : null; }
php
protected function execute($command) { $status = null; $result = array(); exec($command, $result, $status); return !$status ? $result : null; }
[ "protected", "function", "execute", "(", "$", "command", ")", "{", "$", "status", "=", "null", ";", "$", "result", "=", "array", "(", ")", ";", "exec", "(", "$", "command", ",", "$", "result", ",", "$", "status", ")", ";", "return", "!", "$", "status", "?", "$", "result", ":", "null", ";", "}" ]
Executes a shell command. @param string $command @return array|null
[ "Executes", "a", "shell", "command", "." ]
9ac9fed8880537157091ac0607965b30dab20bca
https://github.com/MehrAlsNix/Notifier/blob/9ac9fed8880537157091ac0607965b30dab20bca/src/Notification.php#L82-L88
3,277
GrupaZero/core
src/Gzero/Core/UrlParamsProcessor.php
UrlParamsProcessor.buildQueryBuilder
public function buildQueryBuilder() { $builder = new QueryBuilder(); foreach ($this->parsers as $parser) { if ($parser->wasApplied()) { $parser->apply($builder); } } foreach ($this->sorts as $sort) { $builder->orderBy($sort[0], $sort[1]); } if (!empty($this->perPage)) { $builder->setPageSize($this->perPage); } if (!empty($this->page)) { $builder->setPage($this->page); } if (!empty($this->searchQuery)) { $builder->setSearchQuery($this->searchQuery); } return $builder; }
php
public function buildQueryBuilder() { $builder = new QueryBuilder(); foreach ($this->parsers as $parser) { if ($parser->wasApplied()) { $parser->apply($builder); } } foreach ($this->sorts as $sort) { $builder->orderBy($sort[0], $sort[1]); } if (!empty($this->perPage)) { $builder->setPageSize($this->perPage); } if (!empty($this->page)) { $builder->setPage($this->page); } if (!empty($this->searchQuery)) { $builder->setSearchQuery($this->searchQuery); } return $builder; }
[ "public", "function", "buildQueryBuilder", "(", ")", "{", "$", "builder", "=", "new", "QueryBuilder", "(", ")", ";", "foreach", "(", "$", "this", "->", "parsers", "as", "$", "parser", ")", "{", "if", "(", "$", "parser", "->", "wasApplied", "(", ")", ")", "{", "$", "parser", "->", "apply", "(", "$", "builder", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "sorts", "as", "$", "sort", ")", "{", "$", "builder", "->", "orderBy", "(", "$", "sort", "[", "0", "]", ",", "$", "sort", "[", "1", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "perPage", ")", ")", "{", "$", "builder", "->", "setPageSize", "(", "$", "this", "->", "perPage", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "page", ")", ")", "{", "$", "builder", "->", "setPage", "(", "$", "this", "->", "page", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "searchQuery", ")", ")", "{", "$", "builder", "->", "setSearchQuery", "(", "$", "this", "->", "searchQuery", ")", ";", "}", "return", "$", "builder", ";", "}" ]
Builds QueryBuilder instance based on parsed filters & sorts @return QueryBuilder
[ "Builds", "QueryBuilder", "instance", "based", "on", "parsed", "filters", "&", "sorts" ]
093e515234fa0385b259ba4d8bc7832174a44eab
https://github.com/GrupaZero/core/blob/093e515234fa0385b259ba4d8bc7832174a44eab/src/Gzero/Core/UrlParamsProcessor.php#L151-L178
3,278
GrupaZero/core
src/Gzero/Core/UrlParamsProcessor.php
UrlParamsProcessor.reset
public function reset() { $this->page = 1; $this->perPage = null; $this->parsers = []; $this->sorts = []; $this->searchQuery = null; $this->rules = [ 'page' => 'numeric', 'per_page' => 'numeric', 'sort' => 'string', 'q' => 'string', ]; }
php
public function reset() { $this->page = 1; $this->perPage = null; $this->parsers = []; $this->sorts = []; $this->searchQuery = null; $this->rules = [ 'page' => 'numeric', 'per_page' => 'numeric', 'sort' => 'string', 'q' => 'string', ]; }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "page", "=", "1", ";", "$", "this", "->", "perPage", "=", "null", ";", "$", "this", "->", "parsers", "=", "[", "]", ";", "$", "this", "->", "sorts", "=", "[", "]", ";", "$", "this", "->", "searchQuery", "=", "null", ";", "$", "this", "->", "rules", "=", "[", "'page'", "=>", "'numeric'", ",", "'per_page'", "=>", "'numeric'", ",", "'sort'", "=>", "'string'", ",", "'q'", "=>", "'string'", ",", "]", ";", "}" ]
Resets processor params to default values @return void
[ "Resets", "processor", "params", "to", "default", "values" ]
093e515234fa0385b259ba4d8bc7832174a44eab
https://github.com/GrupaZero/core/blob/093e515234fa0385b259ba4d8bc7832174a44eab/src/Gzero/Core/UrlParamsProcessor.php#L185-L198
3,279
phlexible/phlexible
src/Phlexible/Component/MediaCache/Worker/WorkerResolver.php
WorkerResolver.resolve
public function resolve(TemplateInterface $template, InputDescriptor $input, MediaType $mediaType) { foreach ($this->workers as $worker) { if ($worker->accept($template, $input, $mediaType)) { return $worker; } } return null; }
php
public function resolve(TemplateInterface $template, InputDescriptor $input, MediaType $mediaType) { foreach ($this->workers as $worker) { if ($worker->accept($template, $input, $mediaType)) { return $worker; } } return null; }
[ "public", "function", "resolve", "(", "TemplateInterface", "$", "template", ",", "InputDescriptor", "$", "input", ",", "MediaType", "$", "mediaType", ")", "{", "foreach", "(", "$", "this", "->", "workers", "as", "$", "worker", ")", "{", "if", "(", "$", "worker", "->", "accept", "(", "$", "template", ",", "$", "input", ",", "$", "mediaType", ")", ")", "{", "return", "$", "worker", ";", "}", "}", "return", "null", ";", "}" ]
Determine and return worker. @param TemplateInterface $template @param InputDescriptor $input @param MediaType $mediaType @return WorkerInterface
[ "Determine", "and", "return", "worker", "." ]
132f24924c9bb0dbb6c1ea84db0a463f97fa3893
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Component/MediaCache/Worker/WorkerResolver.php#L60-L69
3,280
belgattitude/soluble-datatype
src/Soluble/Datatype/Column/Definition/AbstractColumnDefinition.php
AbstractColumnDefinition.setTableName
public function setTableName($tableName) { if (trim($tableName) == '') { $tableName = null; } $this->tableName = $tableName; return $this; }
php
public function setTableName($tableName) { if (trim($tableName) == '') { $tableName = null; } $this->tableName = $tableName; return $this; }
[ "public", "function", "setTableName", "(", "$", "tableName", ")", "{", "if", "(", "trim", "(", "$", "tableName", ")", "==", "''", ")", "{", "$", "tableName", "=", "null", ";", "}", "$", "this", "->", "tableName", "=", "$", "tableName", ";", "return", "$", "this", ";", "}" ]
Set table name. @param string $tableName @return AbstractColumnDefinition
[ "Set", "table", "name", "." ]
f6dc0b1730053ac306497d11a4323bddc9ae89e1
https://github.com/belgattitude/soluble-datatype/blob/f6dc0b1730053ac306497d11a4323bddc9ae89e1/src/Soluble/Datatype/Column/Definition/AbstractColumnDefinition.php#L127-L135
3,281
belgattitude/soluble-datatype
src/Soluble/Datatype/Column/Definition/AbstractColumnDefinition.php
AbstractColumnDefinition.setSchemaName
public function setSchemaName($schemaName) { if (trim($schemaName) == '') { $schemaName = null; } $this->schemaName = $schemaName; return $this; }
php
public function setSchemaName($schemaName) { if (trim($schemaName) == '') { $schemaName = null; } $this->schemaName = $schemaName; return $this; }
[ "public", "function", "setSchemaName", "(", "$", "schemaName", ")", "{", "if", "(", "trim", "(", "$", "schemaName", ")", "==", "''", ")", "{", "$", "schemaName", "=", "null", ";", "}", "$", "this", "->", "schemaName", "=", "$", "schemaName", ";", "return", "$", "this", ";", "}" ]
Set schema name. @param string $schemaName @return AbstractColumnDefinition
[ "Set", "schema", "name", "." ]
f6dc0b1730053ac306497d11a4323bddc9ae89e1
https://github.com/belgattitude/soluble-datatype/blob/f6dc0b1730053ac306497d11a4323bddc9ae89e1/src/Soluble/Datatype/Column/Definition/AbstractColumnDefinition.php#L144-L152
3,282
phossa2/libs
src/Phossa2/Route/Parser/ParserAbstract.php
ParserAbstract.doneProcess
protected function doneProcess( /*# string */ $routeName, /*# string */ $routePattern, /*# string */ $regex ) { $this->regex[$routeName] = $regex; $this->modified = true; // debug message $this->debug(Message::get( Message::RTE_PARSER_PATTERN, $routePattern, $regex )); }
php
protected function doneProcess( /*# string */ $routeName, /*# string */ $routePattern, /*# string */ $regex ) { $this->regex[$routeName] = $regex; $this->modified = true; // debug message $this->debug(Message::get( Message::RTE_PARSER_PATTERN, $routePattern, $regex )); }
[ "protected", "function", "doneProcess", "(", "/*# string */", "$", "routeName", ",", "/*# string */", "$", "routePattern", ",", "/*# string */", "$", "regex", ")", "{", "$", "this", "->", "regex", "[", "$", "routeName", "]", "=", "$", "regex", ";", "$", "this", "->", "modified", "=", "true", ";", "// debug message", "$", "this", "->", "debug", "(", "Message", "::", "get", "(", "Message", "::", "RTE_PARSER_PATTERN", ",", "$", "routePattern", ",", "$", "regex", ")", ")", ";", "}" ]
Update regex pool etc. @param string $routeName @param string $routePattern @param string $regex @access protected
[ "Update", "regex", "pool", "etc", "." ]
921e485c8cc29067f279da2cdd06f47a9bddd115
https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Route/Parser/ParserAbstract.php#L96-L110
3,283
roydejong/Enlighten
lib/Context.php
Context.registerInstance
public function registerInstance($object) { if (!is_object($object)) { throw new \InvalidArgumentException('registerInstance(): Cannot pass primitive types, can only register an object instance; use registerVariable() instead'); } $reflectionObject = new \ReflectionObject($object); $className = $reflectionObject->getName(); // Register strong link in $instance $this->instances[$className] = $object; // Recursively determine and register weak links $determineParent = function (\ReflectionClass $class) use ($className, &$determineParent) { $parentClass = $class->getParentClass(); if (!empty($parentClass)) { $this->weakLinks[$parentClass->getName()] = $className; $determineParent($parentClass); } }; $determineParent($reflectionObject); }
php
public function registerInstance($object) { if (!is_object($object)) { throw new \InvalidArgumentException('registerInstance(): Cannot pass primitive types, can only register an object instance; use registerVariable() instead'); } $reflectionObject = new \ReflectionObject($object); $className = $reflectionObject->getName(); // Register strong link in $instance $this->instances[$className] = $object; // Recursively determine and register weak links $determineParent = function (\ReflectionClass $class) use ($className, &$determineParent) { $parentClass = $class->getParentClass(); if (!empty($parentClass)) { $this->weakLinks[$parentClass->getName()] = $className; $determineParent($parentClass); } }; $determineParent($reflectionObject); }
[ "public", "function", "registerInstance", "(", "$", "object", ")", "{", "if", "(", "!", "is_object", "(", "$", "object", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'registerInstance(): Cannot pass primitive types, can only register an object instance; use registerVariable() instead'", ")", ";", "}", "$", "reflectionObject", "=", "new", "\\", "ReflectionObject", "(", "$", "object", ")", ";", "$", "className", "=", "$", "reflectionObject", "->", "getName", "(", ")", ";", "// Register strong link in $instance", "$", "this", "->", "instances", "[", "$", "className", "]", "=", "$", "object", ";", "// Recursively determine and register weak links", "$", "determineParent", "=", "function", "(", "\\", "ReflectionClass", "$", "class", ")", "use", "(", "$", "className", ",", "&", "$", "determineParent", ")", "{", "$", "parentClass", "=", "$", "class", "->", "getParentClass", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "parentClass", ")", ")", "{", "$", "this", "->", "weakLinks", "[", "$", "parentClass", "->", "getName", "(", ")", "]", "=", "$", "className", ";", "$", "determineParent", "(", "$", "parentClass", ")", ";", "}", "}", ";", "$", "determineParent", "(", "$", "reflectionObject", ")", ";", "}" ]
Registers an object instance to the context. If an instance with the same type is already registered, this will override it. @param object $object
[ "Registers", "an", "object", "instance", "to", "the", "context", ".", "If", "an", "instance", "with", "the", "same", "type", "is", "already", "registered", "this", "will", "override", "it", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Context.php#L55-L78
3,284
roydejong/Enlighten
lib/Context.php
Context.registerVariable
public function registerVariable($name, $value) { if (is_object($value)) { throw new \InvalidArgumentException('registerVariable(): Cannot pass objects, can only register primitive types; use registerInstance() instead'); } $this->variablesByName[$name] = $value; }
php
public function registerVariable($name, $value) { if (is_object($value)) { throw new \InvalidArgumentException('registerVariable(): Cannot pass objects, can only register primitive types; use registerInstance() instead'); } $this->variablesByName[$name] = $value; }
[ "public", "function", "registerVariable", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'registerVariable(): Cannot pass objects, can only register primitive types; use registerInstance() instead'", ")", ";", "}", "$", "this", "->", "variablesByName", "[", "$", "name", "]", "=", "$", "value", ";", "}" ]
Registers a primitive variable type by its name to the context. If a variable with the same name is already registered, this will override it. @param string $name @param mixed $value
[ "Registers", "a", "primitive", "variable", "type", "by", "its", "name", "to", "the", "context", ".", "If", "a", "variable", "with", "the", "same", "name", "is", "already", "registered", "this", "will", "override", "it", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Context.php#L87-L94
3,285
roydejong/Enlighten
lib/Context.php
Context.getReflectionParameters
private function getReflectionParameters(callable $callable) { $reflectionParams = []; if (is_array($callable)) { // Callable array $reflector = new \ReflectionMethod($callable[0], $callable[1]); $reflectionParams = $reflector->getParameters(); } else if (is_string($callable)) { // Callable function string $reflector = new \ReflectionFunction($callable); $reflectionParams = $reflector->getParameters(); } else if (is_a($callable, 'Closure') || is_callable($callable, '__invoke')) { /** @var \Closure $callable */ $reflector = new \ReflectionObject($callable); $reflectionParams = $reflector->getMethod('__invoke')->getParameters(); } return $reflectionParams; }
php
private function getReflectionParameters(callable $callable) { $reflectionParams = []; if (is_array($callable)) { // Callable array $reflector = new \ReflectionMethod($callable[0], $callable[1]); $reflectionParams = $reflector->getParameters(); } else if (is_string($callable)) { // Callable function string $reflector = new \ReflectionFunction($callable); $reflectionParams = $reflector->getParameters(); } else if (is_a($callable, 'Closure') || is_callable($callable, '__invoke')) { /** @var \Closure $callable */ $reflector = new \ReflectionObject($callable); $reflectionParams = $reflector->getMethod('__invoke')->getParameters(); } return $reflectionParams; }
[ "private", "function", "getReflectionParameters", "(", "callable", "$", "callable", ")", "{", "$", "reflectionParams", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "callable", ")", ")", "{", "// Callable array", "$", "reflector", "=", "new", "\\", "ReflectionMethod", "(", "$", "callable", "[", "0", "]", ",", "$", "callable", "[", "1", "]", ")", ";", "$", "reflectionParams", "=", "$", "reflector", "->", "getParameters", "(", ")", ";", "}", "else", "if", "(", "is_string", "(", "$", "callable", ")", ")", "{", "// Callable function string", "$", "reflector", "=", "new", "\\", "ReflectionFunction", "(", "$", "callable", ")", ";", "$", "reflectionParams", "=", "$", "reflector", "->", "getParameters", "(", ")", ";", "}", "else", "if", "(", "is_a", "(", "$", "callable", ",", "'Closure'", ")", "||", "is_callable", "(", "$", "callable", ",", "'__invoke'", ")", ")", "{", "/** @var \\Closure $callable */", "$", "reflector", "=", "new", "\\", "ReflectionObject", "(", "$", "callable", ")", ";", "$", "reflectionParams", "=", "$", "reflector", "->", "getMethod", "(", "'__invoke'", ")", "->", "getParameters", "(", ")", ";", "}", "return", "$", "reflectionParams", ";", "}" ]
Given a callable function, attempts to determine the reflection parameters. @param callable $callable @return \ReflectionParameter[]
[ "Given", "a", "callable", "function", "attempts", "to", "determine", "the", "reflection", "parameters", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Context.php#L122-L141
3,286
roydejong/Enlighten
lib/Context.php
Context.determineParamValues
public function determineParamValues(callable $callable) { $reflectionParams = $this->getReflectionParameters($callable); $paramList = []; foreach ($reflectionParams as $reflectionParam) { $paramList[] = $this->determineParamValue($reflectionParam); } return $paramList; }
php
public function determineParamValues(callable $callable) { $reflectionParams = $this->getReflectionParameters($callable); $paramList = []; foreach ($reflectionParams as $reflectionParam) { $paramList[] = $this->determineParamValue($reflectionParam); } return $paramList; }
[ "public", "function", "determineParamValues", "(", "callable", "$", "callable", ")", "{", "$", "reflectionParams", "=", "$", "this", "->", "getReflectionParameters", "(", "$", "callable", ")", ";", "$", "paramList", "=", "[", "]", ";", "foreach", "(", "$", "reflectionParams", "as", "$", "reflectionParam", ")", "{", "$", "paramList", "[", "]", "=", "$", "this", "->", "determineParamValue", "(", "$", "reflectionParam", ")", ";", "}", "return", "$", "paramList", ";", "}" ]
Given a callable function and the current context, attempt to determine the appropriate list of parameters to pass to the function when it is called. @param callable $callable @return array A list of parameter values to be passed to the function, in the appropriate order.
[ "Given", "a", "callable", "function", "and", "the", "current", "context", "attempt", "to", "determine", "the", "appropriate", "list", "of", "parameters", "to", "pass", "to", "the", "function", "when", "it", "is", "called", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Context.php#L150-L161
3,287
roydejong/Enlighten
lib/Context.php
Context.determineParamValuesForConstructor
public function determineParamValuesForConstructor($className) { $reflection = new \ReflectionClass($className); $instance = $reflection->newInstanceWithoutConstructor(); $callable = [$instance, '__construct']; if (!is_callable($callable)) { // This class does not have a constructor function return []; } return $this->determineParamValues($callable); }
php
public function determineParamValuesForConstructor($className) { $reflection = new \ReflectionClass($className); $instance = $reflection->newInstanceWithoutConstructor(); $callable = [$instance, '__construct']; if (!is_callable($callable)) { // This class does not have a constructor function return []; } return $this->determineParamValues($callable); }
[ "public", "function", "determineParamValuesForConstructor", "(", "$", "className", ")", "{", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "className", ")", ";", "$", "instance", "=", "$", "reflection", "->", "newInstanceWithoutConstructor", "(", ")", ";", "$", "callable", "=", "[", "$", "instance", ",", "'__construct'", "]", ";", "if", "(", "!", "is_callable", "(", "$", "callable", ")", ")", "{", "// This class does not have a constructor function", "return", "[", "]", ";", "}", "return", "$", "this", "->", "determineParamValues", "(", "$", "callable", ")", ";", "}" ]
Given a class and the current context, attempt to determine the appropriate list of parameters to pass to the constructor when it is called. @param $className @return array
[ "Given", "a", "class", "and", "the", "current", "context", "attempt", "to", "determine", "the", "appropriate", "list", "of", "parameters", "to", "pass", "to", "the", "constructor", "when", "it", "is", "called", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Context.php#L170-L182
3,288
roydejong/Enlighten
lib/Context.php
Context.determineParamValue
private function determineParamValue(\ReflectionParameter $parameter) { $class = $parameter->getClass(); if (!empty($class)) { // If this is a object we may be able to map it to something in our context $className = $class->getName(); // Determine strong type-based link if (isset($this->instances[$className])) { return $this->instances[$className]; } // Determine weak type-based link if (isset($this->weakLinks[$className])) { $lowerClassName = $this->weakLinks[$className]; return $this->instances[$lowerClassName]; } } else { // If this is a primitive type, attempt to determine it by its name $varName = $parameter->getName(); if (isset($this->variablesByName[$varName])) { return $this->variablesByName[$varName]; } } // We were unable to determine a suitable value based on this context. Pass back its default value if possible. if ($parameter->isDefaultValueAvailable()) { return $parameter->getDefaultValue(); } // As a final fallback we will primitive pass NULL and let the function deal with it. return null; }
php
private function determineParamValue(\ReflectionParameter $parameter) { $class = $parameter->getClass(); if (!empty($class)) { // If this is a object we may be able to map it to something in our context $className = $class->getName(); // Determine strong type-based link if (isset($this->instances[$className])) { return $this->instances[$className]; } // Determine weak type-based link if (isset($this->weakLinks[$className])) { $lowerClassName = $this->weakLinks[$className]; return $this->instances[$lowerClassName]; } } else { // If this is a primitive type, attempt to determine it by its name $varName = $parameter->getName(); if (isset($this->variablesByName[$varName])) { return $this->variablesByName[$varName]; } } // We were unable to determine a suitable value based on this context. Pass back its default value if possible. if ($parameter->isDefaultValueAvailable()) { return $parameter->getDefaultValue(); } // As a final fallback we will primitive pass NULL and let the function deal with it. return null; }
[ "private", "function", "determineParamValue", "(", "\\", "ReflectionParameter", "$", "parameter", ")", "{", "$", "class", "=", "$", "parameter", "->", "getClass", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "class", ")", ")", "{", "// If this is a object we may be able to map it to something in our context", "$", "className", "=", "$", "class", "->", "getName", "(", ")", ";", "// Determine strong type-based link", "if", "(", "isset", "(", "$", "this", "->", "instances", "[", "$", "className", "]", ")", ")", "{", "return", "$", "this", "->", "instances", "[", "$", "className", "]", ";", "}", "// Determine weak type-based link", "if", "(", "isset", "(", "$", "this", "->", "weakLinks", "[", "$", "className", "]", ")", ")", "{", "$", "lowerClassName", "=", "$", "this", "->", "weakLinks", "[", "$", "className", "]", ";", "return", "$", "this", "->", "instances", "[", "$", "lowerClassName", "]", ";", "}", "}", "else", "{", "// If this is a primitive type, attempt to determine it by its name", "$", "varName", "=", "$", "parameter", "->", "getName", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "variablesByName", "[", "$", "varName", "]", ")", ")", "{", "return", "$", "this", "->", "variablesByName", "[", "$", "varName", "]", ";", "}", "}", "// We were unable to determine a suitable value based on this context. Pass back its default value if possible.", "if", "(", "$", "parameter", "->", "isDefaultValueAvailable", "(", ")", ")", "{", "return", "$", "parameter", "->", "getDefaultValue", "(", ")", ";", "}", "// As a final fallback we will primitive pass NULL and let the function deal with it.", "return", "null", ";", "}" ]
Based on the current context, attempts to determine an appropriate value for a given parameter. @param \ReflectionParameter The function parameter to analyze and determine a value for. @return mixed
[ "Based", "on", "the", "current", "context", "attempts", "to", "determine", "an", "appropriate", "value", "for", "a", "given", "parameter", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Context.php#L190-L224
3,289
phlexible/phlexible
src/Phlexible/Bundle/MediaTemplateBundle/Controller/PreviewController.php
PreviewController.imageAction
public function imageAction(Request $request) { $params = $request->request->all(); unset($params['module']); unset($params['controller']); unset($params['action']); if (empty($params['width'])) { $params['width'] = 100; } if (empty($params['height'])) { $params['height'] = 100; } if (empty($params['xmethod'])) { $params['xmethod'] = 'fit'; } $previewer = $this->get('phlexible_media_template.previewer.image'); $locator = $this->get('file_locator'); $previewImage = 'test_1000_600.jpg'; if (isset($params['preview_image'])) { $previewImage = $params['preview_image']; unset($params['preview_image']); if ($previewImage === '800_600') { $previewImage = "test_$previewImage.png"; } else { $previewImage = "test_$previewImage.jpg"; } } $filePath = $locator->locate("@PhlexibleMediaTemplateBundle/Resources/public/images/$previewImage", null, true); $data = $previewer->create($filePath, $params); return new ResultResponse(true, 'Preview created', $data); }
php
public function imageAction(Request $request) { $params = $request->request->all(); unset($params['module']); unset($params['controller']); unset($params['action']); if (empty($params['width'])) { $params['width'] = 100; } if (empty($params['height'])) { $params['height'] = 100; } if (empty($params['xmethod'])) { $params['xmethod'] = 'fit'; } $previewer = $this->get('phlexible_media_template.previewer.image'); $locator = $this->get('file_locator'); $previewImage = 'test_1000_600.jpg'; if (isset($params['preview_image'])) { $previewImage = $params['preview_image']; unset($params['preview_image']); if ($previewImage === '800_600') { $previewImage = "test_$previewImage.png"; } else { $previewImage = "test_$previewImage.jpg"; } } $filePath = $locator->locate("@PhlexibleMediaTemplateBundle/Resources/public/images/$previewImage", null, true); $data = $previewer->create($filePath, $params); return new ResultResponse(true, 'Preview created', $data); }
[ "public", "function", "imageAction", "(", "Request", "$", "request", ")", "{", "$", "params", "=", "$", "request", "->", "request", "->", "all", "(", ")", ";", "unset", "(", "$", "params", "[", "'module'", "]", ")", ";", "unset", "(", "$", "params", "[", "'controller'", "]", ")", ";", "unset", "(", "$", "params", "[", "'action'", "]", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "'width'", "]", ")", ")", "{", "$", "params", "[", "'width'", "]", "=", "100", ";", "}", "if", "(", "empty", "(", "$", "params", "[", "'height'", "]", ")", ")", "{", "$", "params", "[", "'height'", "]", "=", "100", ";", "}", "if", "(", "empty", "(", "$", "params", "[", "'xmethod'", "]", ")", ")", "{", "$", "params", "[", "'xmethod'", "]", "=", "'fit'", ";", "}", "$", "previewer", "=", "$", "this", "->", "get", "(", "'phlexible_media_template.previewer.image'", ")", ";", "$", "locator", "=", "$", "this", "->", "get", "(", "'file_locator'", ")", ";", "$", "previewImage", "=", "'test_1000_600.jpg'", ";", "if", "(", "isset", "(", "$", "params", "[", "'preview_image'", "]", ")", ")", "{", "$", "previewImage", "=", "$", "params", "[", "'preview_image'", "]", ";", "unset", "(", "$", "params", "[", "'preview_image'", "]", ")", ";", "if", "(", "$", "previewImage", "===", "'800_600'", ")", "{", "$", "previewImage", "=", "\"test_$previewImage.png\"", ";", "}", "else", "{", "$", "previewImage", "=", "\"test_$previewImage.jpg\"", ";", "}", "}", "$", "filePath", "=", "$", "locator", "->", "locate", "(", "\"@PhlexibleMediaTemplateBundle/Resources/public/images/$previewImage\"", ",", "null", ",", "true", ")", ";", "$", "data", "=", "$", "previewer", "->", "create", "(", "$", "filePath", ",", "$", "params", ")", ";", "return", "new", "ResultResponse", "(", "true", ",", "'Preview created'", ",", "$", "data", ")", ";", "}" ]
List Image Mediatemplates. @param Request $request @return ResultResponse @Route("/image", name="mediatemplates_preview_image")
[ "List", "Image", "Mediatemplates", "." ]
132f24924c9bb0dbb6c1ea84db0a463f97fa3893
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/MediaTemplateBundle/Controller/PreviewController.php#L40-L76
3,290
neutron-project/datagrid-bundle
Controller/DataGridController.php
DataGridController.massAction
public function massAction ($name) { $dataGrid = $this->getDataGrid($name); $action = $this->getRequest()->get('action'); if (!$action){ throw new \InvalidArgumentException('Parameter "action" in not valid'); } $handler = $this->container->get('neutron_data_grid.handler.datagrid'); $handler ->setDataGrid($dataGrid) ->resolveOptions($this->getRequestParameters()) ->buildQuery() ; $ids = $this->getRequest()->get('ids', array()); $selectAll = ($this->getRequest()->get('selectAll') === 'true'); $event = new MassActionEvent($name, $action, $ids, $selectAll, $handler->getQuery()); $this->container->get('event_dispatcher')->dispatch(DataGridEvents::onMassAction, $event); return new JsonResponse($event->getExtraData()); }
php
public function massAction ($name) { $dataGrid = $this->getDataGrid($name); $action = $this->getRequest()->get('action'); if (!$action){ throw new \InvalidArgumentException('Parameter "action" in not valid'); } $handler = $this->container->get('neutron_data_grid.handler.datagrid'); $handler ->setDataGrid($dataGrid) ->resolveOptions($this->getRequestParameters()) ->buildQuery() ; $ids = $this->getRequest()->get('ids', array()); $selectAll = ($this->getRequest()->get('selectAll') === 'true'); $event = new MassActionEvent($name, $action, $ids, $selectAll, $handler->getQuery()); $this->container->get('event_dispatcher')->dispatch(DataGridEvents::onMassAction, $event); return new JsonResponse($event->getExtraData()); }
[ "public", "function", "massAction", "(", "$", "name", ")", "{", "$", "dataGrid", "=", "$", "this", "->", "getDataGrid", "(", "$", "name", ")", ";", "$", "action", "=", "$", "this", "->", "getRequest", "(", ")", "->", "get", "(", "'action'", ")", ";", "if", "(", "!", "$", "action", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Parameter \"action\" in not valid'", ")", ";", "}", "$", "handler", "=", "$", "this", "->", "container", "->", "get", "(", "'neutron_data_grid.handler.datagrid'", ")", ";", "$", "handler", "->", "setDataGrid", "(", "$", "dataGrid", ")", "->", "resolveOptions", "(", "$", "this", "->", "getRequestParameters", "(", ")", ")", "->", "buildQuery", "(", ")", ";", "$", "ids", "=", "$", "this", "->", "getRequest", "(", ")", "->", "get", "(", "'ids'", ",", "array", "(", ")", ")", ";", "$", "selectAll", "=", "(", "$", "this", "->", "getRequest", "(", ")", "->", "get", "(", "'selectAll'", ")", "===", "'true'", ")", ";", "$", "event", "=", "new", "MassActionEvent", "(", "$", "name", ",", "$", "action", ",", "$", "ids", ",", "$", "selectAll", ",", "$", "handler", "->", "getQuery", "(", ")", ")", ";", "$", "this", "->", "container", "->", "get", "(", "'event_dispatcher'", ")", "->", "dispatch", "(", "DataGridEvents", "::", "onMassAction", ",", "$", "event", ")", ";", "return", "new", "JsonResponse", "(", "$", "event", "->", "getExtraData", "(", ")", ")", ";", "}" ]
This action handles mass actions @param string $name @return \Symfony\Component\HttpFoundation\Response
[ "This", "action", "handles", "mass", "actions" ]
44b05eeb1ce9cf8527e9031a449fef780512521c
https://github.com/neutron-project/datagrid-bundle/blob/44b05eeb1ce9cf8527e9031a449fef780512521c/Controller/DataGridController.php#L84-L108
3,291
neutron-project/datagrid-bundle
Controller/DataGridController.php
DataGridController.rowAction
public function rowAction ($name) { $oper = $this->getRequest()->get('oper', false); if (!in_array($oper, array('add', 'edit', 'del'))){ throw new \InvalidArgumentException(sprintf('Event type: %s is not valid', $oper)); } $eventType = 'neutron_datagrid.onRow' . ucfirst($oper); $event = new RowEvent($name, $this->getRequest()->get('id')); $this->container->get('event_dispatcher')->dispatch($eventType, $event); return new JsonResponse(array( 'errors' => $event->getErrors(), 'success' => $event->getSuccess(), 'id' => $event->getId(), 'data' => $event->getData() )); }
php
public function rowAction ($name) { $oper = $this->getRequest()->get('oper', false); if (!in_array($oper, array('add', 'edit', 'del'))){ throw new \InvalidArgumentException(sprintf('Event type: %s is not valid', $oper)); } $eventType = 'neutron_datagrid.onRow' . ucfirst($oper); $event = new RowEvent($name, $this->getRequest()->get('id')); $this->container->get('event_dispatcher')->dispatch($eventType, $event); return new JsonResponse(array( 'errors' => $event->getErrors(), 'success' => $event->getSuccess(), 'id' => $event->getId(), 'data' => $event->getData() )); }
[ "public", "function", "rowAction", "(", "$", "name", ")", "{", "$", "oper", "=", "$", "this", "->", "getRequest", "(", ")", "->", "get", "(", "'oper'", ",", "false", ")", ";", "if", "(", "!", "in_array", "(", "$", "oper", ",", "array", "(", "'add'", ",", "'edit'", ",", "'del'", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Event type: %s is not valid'", ",", "$", "oper", ")", ")", ";", "}", "$", "eventType", "=", "'neutron_datagrid.onRow'", ".", "ucfirst", "(", "$", "oper", ")", ";", "$", "event", "=", "new", "RowEvent", "(", "$", "name", ",", "$", "this", "->", "getRequest", "(", ")", "->", "get", "(", "'id'", ")", ")", ";", "$", "this", "->", "container", "->", "get", "(", "'event_dispatcher'", ")", "->", "dispatch", "(", "$", "eventType", ",", "$", "event", ")", ";", "return", "new", "JsonResponse", "(", "array", "(", "'errors'", "=>", "$", "event", "->", "getErrors", "(", ")", ",", "'success'", "=>", "$", "event", "->", "getSuccess", "(", ")", ",", "'id'", "=>", "$", "event", "->", "getId", "(", ")", ",", "'data'", "=>", "$", "event", "->", "getData", "(", ")", ")", ")", ";", "}" ]
This action handles manipulating of record @param string $name @return \Symfony\Component\HttpFoundation\Response
[ "This", "action", "handles", "manipulating", "of", "record" ]
44b05eeb1ce9cf8527e9031a449fef780512521c
https://github.com/neutron-project/datagrid-bundle/blob/44b05eeb1ce9cf8527e9031a449fef780512521c/Controller/DataGridController.php#L116-L135
3,292
neutron-project/datagrid-bundle
Controller/DataGridController.php
DataGridController.getDataGrid
public function getDataGrid ($name) { if (! $this->getRequest()->isXmlHttpRequest()) { throw new \RuntimeException('Request must be XmlHttpRequest'); } $provider = $this->container->get('neutron_data_grid.provider'); if (!$provider->has($name)) { throw new \InvalidArgumentException(sprintf('The datagrid %s is not defined', $name)); } return $provider->get($name); }
php
public function getDataGrid ($name) { if (! $this->getRequest()->isXmlHttpRequest()) { throw new \RuntimeException('Request must be XmlHttpRequest'); } $provider = $this->container->get('neutron_data_grid.provider'); if (!$provider->has($name)) { throw new \InvalidArgumentException(sprintf('The datagrid %s is not defined', $name)); } return $provider->get($name); }
[ "public", "function", "getDataGrid", "(", "$", "name", ")", "{", "if", "(", "!", "$", "this", "->", "getRequest", "(", ")", "->", "isXmlHttpRequest", "(", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Request must be XmlHttpRequest'", ")", ";", "}", "$", "provider", "=", "$", "this", "->", "container", "->", "get", "(", "'neutron_data_grid.provider'", ")", ";", "if", "(", "!", "$", "provider", "->", "has", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'The datagrid %s is not defined'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "provider", "->", "get", "(", "$", "name", ")", ";", "}" ]
This method retrieves datagrid by name @param string $name @return \Neutron\DataGridBundle\DataGrid\DataGridInterface @throws \RuntimeException @throws \InvalidArgumentException
[ "This", "method", "retrieves", "datagrid", "by", "name" ]
44b05eeb1ce9cf8527e9031a449fef780512521c
https://github.com/neutron-project/datagrid-bundle/blob/44b05eeb1ce9cf8527e9031a449fef780512521c/Controller/DataGridController.php#L145-L158
3,293
drmvc/database
src/Database/Model.php
Model.getConfigDB
private function getConfigDB(ConfigInterface $config): ConfigInterface { // get current connection $connection = $this->getConnection(); // Get config of required connection $config_db = $config->get($connection); try { if (null === $config_db) { throw new Exception("Connection \"$connection\" is not found in database config"); } } catch (Exception $e) { // __constructor } return $config_db; }
php
private function getConfigDB(ConfigInterface $config): ConfigInterface { // get current connection $connection = $this->getConnection(); // Get config of required connection $config_db = $config->get($connection); try { if (null === $config_db) { throw new Exception("Connection \"$connection\" is not found in database config"); } } catch (Exception $e) { // __constructor } return $config_db; }
[ "private", "function", "getConfigDB", "(", "ConfigInterface", "$", "config", ")", ":", "ConfigInterface", "{", "// get current connection", "$", "connection", "=", "$", "this", "->", "getConnection", "(", ")", ";", "// Get config of required connection", "$", "config_db", "=", "$", "config", "->", "get", "(", "$", "connection", ")", ";", "try", "{", "if", "(", "null", "===", "$", "config_db", ")", "{", "throw", "new", "Exception", "(", "\"Connection \\\"$connection\\\" is not found in database config\"", ")", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// __constructor", "}", "return", "$", "config_db", ";", "}" ]
Extract configuration of current database @param ConfigInterface $config @return ConfigInterface
[ "Extract", "configuration", "of", "current", "database" ]
c6b4589d37743edef71b851c9176365956a73c80
https://github.com/drmvc/database/blob/c6b4589d37743edef71b851c9176365956a73c80/src/Database/Model.php#L77-L91
3,294
drmvc/database
src/Database/Model.php
Model.classToShake
private function classToShake(): string { $className = \get_class($this); $classArray = explode('\\', $className); $class = end($classArray); try { $class = Stringy::create($class)->underscored(); } catch (\InvalidArgumentException $e) { new Exception('Invalid argument provided'); } return $class; }
php
private function classToShake(): string { $className = \get_class($this); $classArray = explode('\\', $className); $class = end($classArray); try { $class = Stringy::create($class)->underscored(); } catch (\InvalidArgumentException $e) { new Exception('Invalid argument provided'); } return $class; }
[ "private", "function", "classToShake", "(", ")", ":", "string", "{", "$", "className", "=", "\\", "get_class", "(", "$", "this", ")", ";", "$", "classArray", "=", "explode", "(", "'\\\\'", ",", "$", "className", ")", ";", "$", "class", "=", "end", "(", "$", "classArray", ")", ";", "try", "{", "$", "class", "=", "Stringy", "::", "create", "(", "$", "class", ")", "->", "underscored", "(", ")", ";", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "e", ")", "{", "new", "Exception", "(", "'Invalid argument provided'", ")", ";", "}", "return", "$", "class", ";", "}" ]
Convert class name for snake case @return string
[ "Convert", "class", "name", "for", "snake", "case" ]
c6b4589d37743edef71b851c9176365956a73c80
https://github.com/drmvc/database/blob/c6b4589d37743edef71b851c9176365956a73c80/src/Database/Model.php#L108-L119
3,295
yongtiger/yii2-admin
src/controllers/LogController.php
LogController.actionIndex
public function actionIndex() { $searchModel = new \yongtiger\admin\models\searchs\Log(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
php
public function actionIndex() { $searchModel = new \yongtiger\admin\models\searchs\Log(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
[ "public", "function", "actionIndex", "(", ")", "{", "$", "searchModel", "=", "new", "\\", "yongtiger", "\\", "admin", "\\", "models", "\\", "searchs", "\\", "Log", "(", ")", ";", "$", "dataProvider", "=", "$", "searchModel", "->", "search", "(", "Yii", "::", "$", "app", "->", "request", "->", "queryParams", ")", ";", "return", "$", "this", "->", "render", "(", "'index'", ",", "[", "'searchModel'", "=>", "$", "searchModel", ",", "'dataProvider'", "=>", "$", "dataProvider", ",", "]", ")", ";", "}" ]
Lists all Log models. @return mixed
[ "Lists", "all", "Log", "models", "." ]
1a28b1649c12a4739c4e149fd67d1d1e566372f8
https://github.com/yongtiger/yii2-admin/blob/1a28b1649c12a4739c4e149fd67d1d1e566372f8/src/controllers/LogController.php#L59-L68
3,296
yongtiger/yii2-admin
src/controllers/LogController.php
LogController.actionCreate
public function actionCreate() { $model = new \yongtiger\admin\models\Log(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Module::t('message', 'Successfully created.')); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } }
php
public function actionCreate() { $model = new \yongtiger\admin\models\Log(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Module::t('message', 'Successfully created.')); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } }
[ "public", "function", "actionCreate", "(", ")", "{", "$", "model", "=", "new", "\\", "yongtiger", "\\", "admin", "\\", "models", "\\", "Log", "(", ")", ";", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", "&&", "$", "model", "->", "save", "(", ")", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "'success'", ",", "Module", "::", "t", "(", "'message'", ",", "'Successfully created.'", ")", ")", ";", "return", "$", "this", "->", "redirect", "(", "[", "'view'", ",", "'id'", "=>", "$", "model", "->", "id", "]", ")", ";", "}", "else", "{", "return", "$", "this", "->", "render", "(", "'create'", ",", "[", "'model'", "=>", "$", "model", ",", "]", ")", ";", "}", "}" ]
Creates a new Log model. If creation is successful, the browser will be redirected to the 'view' page. @return mixed
[ "Creates", "a", "new", "Log", "model", ".", "If", "creation", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "view", "page", "." ]
1a28b1649c12a4739c4e149fd67d1d1e566372f8
https://github.com/yongtiger/yii2-admin/blob/1a28b1649c12a4739c4e149fd67d1d1e566372f8/src/controllers/LogController.php#L87-L99
3,297
yongtiger/yii2-admin
src/controllers/LogController.php
LogController.actionDelete
public function actionDelete($id) { $ret = $this->findModel($id)->delete(); if($ret === false) { Yii::$app->session->setFlash('error', Module::t('message', 'Failed to delete!') . ' (ID = '.$id.')'); }else{ Yii::$app->session->setFlash('success', Module::t('message', 'Successfully deleted.') . ' (ID = '.$id.')'); } return $this->redirect(['index']); }
php
public function actionDelete($id) { $ret = $this->findModel($id)->delete(); if($ret === false) { Yii::$app->session->setFlash('error', Module::t('message', 'Failed to delete!') . ' (ID = '.$id.')'); }else{ Yii::$app->session->setFlash('success', Module::t('message', 'Successfully deleted.') . ' (ID = '.$id.')'); } return $this->redirect(['index']); }
[ "public", "function", "actionDelete", "(", "$", "id", ")", "{", "$", "ret", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", "->", "delete", "(", ")", ";", "if", "(", "$", "ret", "===", "false", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "'error'", ",", "Module", "::", "t", "(", "'message'", ",", "'Failed to delete!'", ")", ".", "' (ID = '", ".", "$", "id", ".", "')'", ")", ";", "}", "else", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "'success'", ",", "Module", "::", "t", "(", "'message'", ",", "'Successfully deleted.'", ")", ".", "' (ID = '", ".", "$", "id", ".", "')'", ")", ";", "}", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}" ]
Deletes an existing Log model. If deletion is successful, the browser will be redirected to the 'index' page. @param integer $id @return mixed
[ "Deletes", "an", "existing", "Log", "model", ".", "If", "deletion", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "index", "page", "." ]
1a28b1649c12a4739c4e149fd67d1d1e566372f8
https://github.com/yongtiger/yii2-admin/blob/1a28b1649c12a4739c4e149fd67d1d1e566372f8/src/controllers/LogController.php#L127-L138
3,298
yongtiger/yii2-admin
src/controllers/LogController.php
LogController.actionDeleteIn
public function actionDeleteIn() { $selected = Yii::$app->request->post('selected' , []); $ret = \yongtiger\admin\models\Log::deleteAll(['id' => explode(',', $selected)]); $str = $ret > 0 ? ' (IDs [' . $selected . '])' : ''; Yii::$app->session->setFlash('info', Module::t('message', 'Deleted {0} logs.', $ret) . $str); return $this->redirect(['index']); }
php
public function actionDeleteIn() { $selected = Yii::$app->request->post('selected' , []); $ret = \yongtiger\admin\models\Log::deleteAll(['id' => explode(',', $selected)]); $str = $ret > 0 ? ' (IDs [' . $selected . '])' : ''; Yii::$app->session->setFlash('info', Module::t('message', 'Deleted {0} logs.', $ret) . $str); return $this->redirect(['index']); }
[ "public", "function", "actionDeleteIn", "(", ")", "{", "$", "selected", "=", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", "'selected'", ",", "[", "]", ")", ";", "$", "ret", "=", "\\", "yongtiger", "\\", "admin", "\\", "models", "\\", "Log", "::", "deleteAll", "(", "[", "'id'", "=>", "explode", "(", "','", ",", "$", "selected", ")", "]", ")", ";", "$", "str", "=", "$", "ret", ">", "0", "?", "' (IDs ['", ".", "$", "selected", ".", "'])'", ":", "''", ";", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "'info'", ",", "Module", "::", "t", "(", "'message'", ",", "'Deleted {0} logs.'", ",", "$", "ret", ")", ".", "$", "str", ")", ";", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}" ]
Deletes selected in post. If deletion is successful, the browser will be redirected to the 'index' page. @return mixed
[ "Deletes", "selected", "in", "post", ".", "If", "deletion", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "index", "page", "." ]
1a28b1649c12a4739c4e149fd67d1d1e566372f8
https://github.com/yongtiger/yii2-admin/blob/1a28b1649c12a4739c4e149fd67d1d1e566372f8/src/controllers/LogController.php#L145-L154
3,299
yongtiger/yii2-admin
src/controllers/LogController.php
LogController.findModel
protected function findModel($id) { if (($model = \yongtiger\admin\models\Log::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
php
protected function findModel($id) { if (($model = \yongtiger\admin\models\Log::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
[ "protected", "function", "findModel", "(", "$", "id", ")", "{", "if", "(", "(", "$", "model", "=", "\\", "yongtiger", "\\", "admin", "\\", "models", "\\", "Log", "::", "findOne", "(", "$", "id", ")", ")", "!==", "null", ")", "{", "return", "$", "model", ";", "}", "else", "{", "throw", "new", "NotFoundHttpException", "(", "'The requested page does not exist.'", ")", ";", "}", "}" ]
Finds the Log model based on its primary key value. If the model is not found, a 404 HTTP exception will be thrown. @param integer $id @return Log the loaded model @throws NotFoundHttpException if the model cannot be found
[ "Finds", "the", "Log", "model", "based", "on", "its", "primary", "key", "value", ".", "If", "the", "model", "is", "not", "found", "a", "404", "HTTP", "exception", "will", "be", "thrown", "." ]
1a28b1649c12a4739c4e149fd67d1d1e566372f8
https://github.com/yongtiger/yii2-admin/blob/1a28b1649c12a4739c4e149fd67d1d1e566372f8/src/controllers/LogController.php#L164-L171