repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
FriendsOfCake/crud | src/Action/BaseAction.php | BaseAction._deriveResourceName | protected function _deriveResourceName()
{
$inflectionType = $this->getConfig('inflection');
if ($inflectionType === null) {
$inflectionType = $this->scope() === 'entity' ? 'singular' : 'plural';
}
if ($inflectionType === 'singular') {
return strtolower(Inflector::humanize(
Inflector::singularize(Inflector::underscore($this->_table()->getAlias()))
));
}
return strtolower(Inflector::humanize(Inflector::underscore($this->_table()->getAlias())));
} | php | protected function _deriveResourceName()
{
$inflectionType = $this->getConfig('inflection');
if ($inflectionType === null) {
$inflectionType = $this->scope() === 'entity' ? 'singular' : 'plural';
}
if ($inflectionType === 'singular') {
return strtolower(Inflector::humanize(
Inflector::singularize(Inflector::underscore($this->_table()->getAlias()))
));
}
return strtolower(Inflector::humanize(Inflector::underscore($this->_table()->getAlias())));
} | [
"protected",
"function",
"_deriveResourceName",
"(",
")",
"{",
"$",
"inflectionType",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'inflection'",
")",
";",
"if",
"(",
"$",
"inflectionType",
"===",
"null",
")",
"{",
"$",
"inflectionType",
"=",
"$",
"this",
"-... | Derive resource name
@return string | [
"Derive",
"resource",
"name"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/BaseAction.php#L293-L308 | train |
FriendsOfCake/crud | src/Action/BaseAction.php | BaseAction.implementedEvents | public function implementedEvents()
{
$events = parent::implementedEvents();
$events['Crud.beforeRender'][] = ['callable' => [$this, 'publishSuccess']];
if (method_exists($this, 'viewVar')) {
$events['Crud.beforeRender'][] = ['callable' => [$this, 'publishViewVar']];
}
return $events;
} | php | public function implementedEvents()
{
$events = parent::implementedEvents();
$events['Crud.beforeRender'][] = ['callable' => [$this, 'publishSuccess']];
if (method_exists($this, 'viewVar')) {
$events['Crud.beforeRender'][] = ['callable' => [$this, 'publishViewVar']];
}
return $events;
} | [
"public",
"function",
"implementedEvents",
"(",
")",
"{",
"$",
"events",
"=",
"parent",
"::",
"implementedEvents",
"(",
")",
";",
"$",
"events",
"[",
"'Crud.beforeRender'",
"]",
"[",
"]",
"=",
"[",
"'callable'",
"=>",
"[",
"$",
"this",
",",
"'publishSucces... | Additional auxiliary events emitted if certain traits are loaded
@return array | [
"Additional",
"auxiliary",
"events",
"emitted",
"if",
"certain",
"traits",
"are",
"loaded"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/BaseAction.php#L315-L326 | train |
FriendsOfCake/crud | src/Listener/ApiListener.php | ApiListener._checkRequestMethods | protected function _checkRequestMethods()
{
$action = $this->_action();
$apiConfig = $action->getConfig('api');
if (!isset($apiConfig['methods'])) {
return false;
}
$request = $this->_request();
foreach ($apiConfig['methods'] as $method) {
if ($request->is($method)) {
return true;
}
}
throw new MethodNotAllowedException();
} | php | protected function _checkRequestMethods()
{
$action = $this->_action();
$apiConfig = $action->getConfig('api');
if (!isset($apiConfig['methods'])) {
return false;
}
$request = $this->_request();
foreach ($apiConfig['methods'] as $method) {
if ($request->is($method)) {
return true;
}
}
throw new MethodNotAllowedException();
} | [
"protected",
"function",
"_checkRequestMethods",
"(",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"_action",
"(",
")",
";",
"$",
"apiConfig",
"=",
"$",
"action",
"->",
"getConfig",
"(",
"'api'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"apiC... | Check for allowed HTTP request types
@throws \Cake\Http\Exception\MethodNotAllowedException
@return bool | [
"Check",
"for",
"allowed",
"HTTP",
"request",
"types"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/ApiListener.php#L144-L161 | train |
FriendsOfCake/crud | src/Listener/ApiListener.php | ApiListener._exceptionResponse | protected function _exceptionResponse(Event $Event, $exceptionConfig)
{
$exceptionConfig = array_merge($this->getConfig('exception'), $exceptionConfig);
$class = $exceptionConfig['class'];
if ($exceptionConfig['type'] === 'validate') {
$exception = new $class($Event->getSubject()->entity);
throw $exception;
}
$exception = new $class($exceptionConfig['message'], $exceptionConfig['code']);
throw $exception;
} | php | protected function _exceptionResponse(Event $Event, $exceptionConfig)
{
$exceptionConfig = array_merge($this->getConfig('exception'), $exceptionConfig);
$class = $exceptionConfig['class'];
if ($exceptionConfig['type'] === 'validate') {
$exception = new $class($Event->getSubject()->entity);
throw $exception;
}
$exception = new $class($exceptionConfig['message'], $exceptionConfig['code']);
throw $exception;
} | [
"protected",
"function",
"_exceptionResponse",
"(",
"Event",
"$",
"Event",
",",
"$",
"exceptionConfig",
")",
"{",
"$",
"exceptionConfig",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'exception'",
")",
",",
"$",
"exceptionConfig",
")",
";",
... | Throw an exception based on API configuration
@param \Cake\Event\Event $Event Event
@param array $exceptionConfig Exception config
@return void
@throws \Exception | [
"Throw",
"an",
"exception",
"based",
"on",
"API",
"configuration"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/ApiListener.php#L182-L195 | train |
FriendsOfCake/crud | src/Listener/ApiListener.php | ApiListener.render | public function render(Subject $subject)
{
$this->injectViewClasses();
$this->_ensureSuccess($subject);
$this->_ensureData($subject);
$this->_ensureSerialize();
return $this->_controller()->render();
} | php | public function render(Subject $subject)
{
$this->injectViewClasses();
$this->_ensureSuccess($subject);
$this->_ensureData($subject);
$this->_ensureSerialize();
return $this->_controller()->render();
} | [
"public",
"function",
"render",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"this",
"->",
"injectViewClasses",
"(",
")",
";",
"$",
"this",
"->",
"_ensureSuccess",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"_ensureData",
"(",
"$",
"subject",
... | Selects an specific Crud view class to render the output
@param \Crud\Event\Subject $subject Subject
@return \Cake\Http\Response | [
"Selects",
"an",
"specific",
"Crud",
"view",
"class",
"to",
"render",
"the",
"output"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/ApiListener.php#L203-L211 | train |
FriendsOfCake/crud | src/Listener/ApiListener.php | ApiListener._ensureSerialize | protected function _ensureSerialize()
{
$controller = $this->_controller();
if (isset($controller->viewVars['_serialize'])) {
return;
}
$serialize = [];
$serialize[] = 'success';
$action = $this->_action();
if (method_exists($action, 'viewVar')) {
$serialize['data'] = $action->viewVar();
} else {
$serialize[] = 'data';
}
$serialize = array_merge($serialize, (array)$action->getConfig('serialize'));
$controller->set('_serialize', $serialize);
} | php | protected function _ensureSerialize()
{
$controller = $this->_controller();
if (isset($controller->viewVars['_serialize'])) {
return;
}
$serialize = [];
$serialize[] = 'success';
$action = $this->_action();
if (method_exists($action, 'viewVar')) {
$serialize['data'] = $action->viewVar();
} else {
$serialize[] = 'data';
}
$serialize = array_merge($serialize, (array)$action->getConfig('serialize'));
$controller->set('_serialize', $serialize);
} | [
"protected",
"function",
"_ensureSerialize",
"(",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"_controller",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"controller",
"->",
"viewVars",
"[",
"'_serialize'",
"]",
")",
")",
"{",
"return",
";",
"... | Ensure _serialize is set in the view
@return void | [
"Ensure",
"_serialize",
"is",
"set",
"in",
"the",
"view"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/ApiListener.php#L218-L238 | train |
FriendsOfCake/crud | src/Listener/ApiListener.php | ApiListener.injectViewClasses | public function injectViewClasses()
{
$controller = $this->_controller();
foreach ($this->getConfig('viewClasses') as $type => $class) {
$controller->RequestHandler->setConfig('viewClassMap', [$type => $class]);
}
} | php | public function injectViewClasses()
{
$controller = $this->_controller();
foreach ($this->getConfig('viewClasses') as $type => $class) {
$controller->RequestHandler->setConfig('viewClassMap', [$type => $class]);
}
} | [
"public",
"function",
"injectViewClasses",
"(",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"_controller",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'viewClasses'",
")",
"as",
"$",
"type",
"=>",
"$",
"class",
")",
"{... | Inject view classes into RequestHandler
@return void | [
"Inject",
"view",
"classes",
"into",
"RequestHandler"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/ApiListener.php#L362-L368 | train |
FriendsOfCake/crud | src/Listener/ApiListener.php | ApiListener.viewClass | public function viewClass($type, $class = null)
{
if ($class === null) {
return $this->getConfig('viewClasses.' . $type);
}
return $this->setConfig('viewClasses.' . $type, $class);
} | php | public function viewClass($type, $class = null)
{
if ($class === null) {
return $this->getConfig('viewClasses.' . $type);
}
return $this->setConfig('viewClasses.' . $type, $class);
} | [
"public",
"function",
"viewClass",
"(",
"$",
"type",
",",
"$",
"class",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"class",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getConfig",
"(",
"'viewClasses.'",
".",
"$",
"type",
")",
";",
"}",
"retu... | Get or set a viewClass
`$type` could be `json`, `xml` or any other valid type
defined by the `RequestHandler`
`$class` could be any View class capable of handling
the response format for the `$type`. Normal
CakePHP plugin "dot" notation is supported
@param string $type Type
@param string|null $class Class name
@return mixed | [
"Get",
"or",
"set",
"a",
"viewClass"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/ApiListener.php#L384-L391 | train |
FriendsOfCake/crud | src/Action/Bulk/SetValueAction.php | SetValueAction._bulk | protected function _bulk(Query $query = null)
{
$field = $this->getConfig('field');
$value = $this->getConfig('value');
$query->update()->set([$field => $value]);
$statement = $query->execute();
$statement->closeCursor();
return (bool)$statement->rowCount();
} | php | protected function _bulk(Query $query = null)
{
$field = $this->getConfig('field');
$value = $this->getConfig('value');
$query->update()->set([$field => $value]);
$statement = $query->execute();
$statement->closeCursor();
return (bool)$statement->rowCount();
} | [
"protected",
"function",
"_bulk",
"(",
"Query",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'field'",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'value'",
")",
";",
"$",
"que... | Handle a bulk value set
@param \Cake\ORM\Query|null $query The query to act upon
@return bool | [
"Handle",
"a",
"bulk",
"value",
"set"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/Bulk/SetValueAction.php#L60-L69 | train |
FriendsOfCake/crud | src/Core/ProxyTrait.php | ProxyTrait._table | protected function _table()
{
return $this->_controller()
->loadModel(
null,
$this->getConfig('modelFactory') ?: $this->_controller()->getModelType()
);
} | php | protected function _table()
{
return $this->_controller()
->loadModel(
null,
$this->getConfig('modelFactory') ?: $this->_controller()->getModelType()
);
} | [
"protected",
"function",
"_table",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"_controller",
"(",
")",
"->",
"loadModel",
"(",
"null",
",",
"$",
"this",
"->",
"getConfig",
"(",
"'modelFactory'",
")",
"?",
":",
"$",
"this",
"->",
"_controller",
"(",
")... | Get a table instance
@return \Cake\ORM\Table | [
"Get",
"a",
"table",
"instance"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Core/ProxyTrait.php#L114-L121 | train |
FriendsOfCake/crud | src/Core/ProxyTrait.php | ProxyTrait._entity | protected function _entity(array $data = null, array $options = [])
{
if ($this->_entity && empty($data)) {
return $this->_entity;
}
return $this->_table()->newEntity($data, $options);
} | php | protected function _entity(array $data = null, array $options = [])
{
if ($this->_entity && empty($data)) {
return $this->_entity;
}
return $this->_table()->newEntity($data, $options);
} | [
"protected",
"function",
"_entity",
"(",
"array",
"$",
"data",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_entity",
"&&",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->... | Get a fresh entity instance from the primary Table
@param array $data Data array
@param array $options A list of options for the object hydration.
@return \Cake\ORM\Entity | [
"Get",
"a",
"fresh",
"entity",
"instance",
"from",
"the",
"primary",
"Table"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Core/ProxyTrait.php#L130-L137 | train |
FriendsOfCake/crud | src/Listener/SearchListener.php | SearchListener.injectSearch | public function injectSearch(Event $event)
{
if (!in_array($event->getName(), $this->getConfig('enabled'))) {
return;
}
$repository = $this->_table();
if ($repository instanceof Table && !$repository->behaviors()->has('Search')) {
throw new RuntimeException(sprintf(
'Missing Search.Search behavior on %s',
get_class($repository)
));
}
if ($repository instanceof Table && $repository->behaviors()->hasMethod('filterParams')) {
$filterParams = $repository->filterParams($this->_request()->getQuery());
} else {
$filterParams = ['search' => $this->_request()->getQuery()];
}
$filterParams['collection'] = $this->getConfig('collection');
$event->getSubject()->query->find('search', $filterParams);
} | php | public function injectSearch(Event $event)
{
if (!in_array($event->getName(), $this->getConfig('enabled'))) {
return;
}
$repository = $this->_table();
if ($repository instanceof Table && !$repository->behaviors()->has('Search')) {
throw new RuntimeException(sprintf(
'Missing Search.Search behavior on %s',
get_class($repository)
));
}
if ($repository instanceof Table && $repository->behaviors()->hasMethod('filterParams')) {
$filterParams = $repository->filterParams($this->_request()->getQuery());
} else {
$filterParams = ['search' => $this->_request()->getQuery()];
}
$filterParams['collection'] = $this->getConfig('collection');
$event->getSubject()->query->find('search', $filterParams);
} | [
"public",
"function",
"injectSearch",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"event",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"getConfig",
"(",
"'enabled'",
")",
")",
")",
"{",
"return",
";",
"}",
"$"... | Inject search conditions into the query object.
@param \Cake\Event\Event $event Event
@return void | [
"Inject",
"search",
"conditions",
"into",
"the",
"query",
"object",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/SearchListener.php#L44-L66 | train |
FriendsOfCake/crud | src/Traits/ViewTrait.php | ViewTrait.view | public function view($view = null)
{
if (empty($view)) {
return $this->getConfig('view') ?: $this->_request()->getParam('action');
}
return $this->setConfig('view', $view);
} | php | public function view($view = null)
{
if (empty($view)) {
return $this->getConfig('view') ?: $this->_request()->getParam('action');
}
return $this->setConfig('view', $view);
} | [
"public",
"function",
"view",
"(",
"$",
"view",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"view",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getConfig",
"(",
"'view'",
")",
"?",
":",
"$",
"this",
"->",
"_request",
"(",
")",
"->",
"... | Change the view to be rendered
If `$view` is NULL the current view is returned
else the `$view` is changed
If no view is configured, it will use the action
name from the request object
@param mixed $view View name
@return mixed | [
"Change",
"the",
"view",
"to",
"be",
"rendered"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/ViewTrait.php#L19-L26 | train |
FriendsOfCake/crud | src/Traits/FindMethodTrait.php | FindMethodTrait._extractFinder | protected function _extractFinder()
{
$finder = $this->findMethod();
$options = [];
if (is_array($finder)) {
$options = (array)current($finder);
$finder = key($finder);
}
return [$finder, $options];
} | php | protected function _extractFinder()
{
$finder = $this->findMethod();
$options = [];
if (is_array($finder)) {
$options = (array)current($finder);
$finder = key($finder);
}
return [$finder, $options];
} | [
"protected",
"function",
"_extractFinder",
"(",
")",
"{",
"$",
"finder",
"=",
"$",
"this",
"->",
"findMethod",
"(",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"finder",
")",
")",
"{",
"$",
"options",
"=",
"(",
... | Extracts the finder name and options out of the "findMethod" option.
@return array An array containing in the first position the finder name
and in the second the options to be passed to it. | [
"Extracts",
"the",
"finder",
"name",
"and",
"options",
"out",
"of",
"the",
"findMethod",
"option",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/FindMethodTrait.php#L34-L44 | train |
FriendsOfCake/crud | src/Traits/FindMethodTrait.php | FindMethodTrait._findRecord | protected function _findRecord($id, Subject $subject)
{
$repository = $this->_table();
list($finder, $options) = $this->_extractFinder();
$query = $repository->find($finder, $options);
$query->where([current($query->aliasField($repository->getPrimaryKey())) => $id]);
$subject->set([
'repository' => $repository,
'query' => $query
]);
$this->_trigger('beforeFind', $subject);
$entity = $subject->query->first();
if (!$entity) {
$this->_notFound($id, $subject);
}
$subject->set(['entity' => $entity, 'success' => true]);
$this->_trigger('afterFind', $subject);
return $entity;
} | php | protected function _findRecord($id, Subject $subject)
{
$repository = $this->_table();
list($finder, $options) = $this->_extractFinder();
$query = $repository->find($finder, $options);
$query->where([current($query->aliasField($repository->getPrimaryKey())) => $id]);
$subject->set([
'repository' => $repository,
'query' => $query
]);
$this->_trigger('beforeFind', $subject);
$entity = $subject->query->first();
if (!$entity) {
$this->_notFound($id, $subject);
}
$subject->set(['entity' => $entity, 'success' => true]);
$this->_trigger('afterFind', $subject);
return $entity;
} | [
"protected",
"function",
"_findRecord",
"(",
"$",
"id",
",",
"Subject",
"$",
"subject",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"_table",
"(",
")",
";",
"list",
"(",
"$",
"finder",
",",
"$",
"options",
")",
"=",
"$",
"this",
"->",
"_ex... | Find a record from the ID
@param string $id Record id
@param \Crud\Event\Subject $subject Event subject
@return \Cake\ORM\Entity
@throws \Exception | [
"Find",
"a",
"record",
"from",
"the",
"ID"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/FindMethodTrait.php#L54-L78 | train |
FriendsOfCake/crud | src/Traits/FindMethodTrait.php | FindMethodTrait._notFound | protected function _notFound($id, Subject $subject)
{
$subject->set(['success' => false]);
$this->_trigger('recordNotFound', $subject);
$message = $this->message('recordNotFound', compact('id'));
$exceptionClass = $message['class'];
throw new $exceptionClass($message['text'], $message['code']);
} | php | protected function _notFound($id, Subject $subject)
{
$subject->set(['success' => false]);
$this->_trigger('recordNotFound', $subject);
$message = $this->message('recordNotFound', compact('id'));
$exceptionClass = $message['class'];
throw new $exceptionClass($message['text'], $message['code']);
} | [
"protected",
"function",
"_notFound",
"(",
"$",
"id",
",",
"Subject",
"$",
"subject",
")",
"{",
"$",
"subject",
"->",
"set",
"(",
"[",
"'success'",
"=>",
"false",
"]",
")",
";",
"$",
"this",
"->",
"_trigger",
"(",
"'recordNotFound'",
",",
"$",
"subject... | Throw exception if a record is not found
@param string $id Record id
@param \Crud\Event\Subject $subject Event subject
@return void
@throws \Exception | [
"Throw",
"exception",
"if",
"a",
"record",
"is",
"not",
"found"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/FindMethodTrait.php#L88-L96 | train |
FriendsOfCake/crud | src/Listener/ApiQueryLogListener.php | ApiQueryLogListener.setupLogging | public function setupLogging(Event $event)
{
foreach ($this->_getSources() as $connectionName) {
try {
$connection = $this->_getSource($connectionName);
if (method_exists($connection, 'enableQueryLogging')) {
$connection->enableQueryLogging(true);
} else {
$connection->logQueries(true);
}
$connection->setLogger(new QueryLogger());
} catch (MissingDatasourceConfigException $e) {
//Safe to ignore this :-)
}
}
} | php | public function setupLogging(Event $event)
{
foreach ($this->_getSources() as $connectionName) {
try {
$connection = $this->_getSource($connectionName);
if (method_exists($connection, 'enableQueryLogging')) {
$connection->enableQueryLogging(true);
} else {
$connection->logQueries(true);
}
$connection->setLogger(new QueryLogger());
} catch (MissingDatasourceConfigException $e) {
//Safe to ignore this :-)
}
}
} | [
"public",
"function",
"setupLogging",
"(",
"Event",
"$",
"event",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_getSources",
"(",
")",
"as",
"$",
"connectionName",
")",
"{",
"try",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"_getSource",
"(",
"$"... | Setup logging for all connections
@param \Cake\Event\Event $event Event
@return void | [
"Setup",
"logging",
"for",
"all",
"connections"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/ApiQueryLogListener.php#L50-L67 | train |
FriendsOfCake/crud | src/Listener/ApiQueryLogListener.php | ApiQueryLogListener.beforeRender | public function beforeRender(Event $event)
{
if (!Configure::read('debug')) {
return;
}
$this->_action()->setConfig('serialize.queryLog', 'queryLog');
$this->_controller()->set('queryLog', $this->_getQueryLogs());
} | php | public function beforeRender(Event $event)
{
if (!Configure::read('debug')) {
return;
}
$this->_action()->setConfig('serialize.queryLog', 'queryLog');
$this->_controller()->set('queryLog', $this->_getQueryLogs());
} | [
"public",
"function",
"beforeRender",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"Configure",
"::",
"read",
"(",
"'debug'",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_action",
"(",
")",
"->",
"setConfig",
"(",
"'serialize.queryL... | Appends the query log to the JSON or XML output
@param \Cake\Event\Event $event Event
@return void | [
"Appends",
"the",
"query",
"log",
"to",
"the",
"JSON",
"or",
"XML",
"output"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/ApiQueryLogListener.php#L75-L83 | train |
FriendsOfCake/crud | src/Listener/ApiQueryLogListener.php | ApiQueryLogListener._getQueryLogs | protected function _getQueryLogs()
{
$sources = $this->_getSources();
$queryLog = [];
foreach ($sources as $source) {
$logger = $this->_getSource($source)->getLogger();
if (method_exists($logger, 'getLogs')) {
$queryLog[$source] = $logger->getLogs();
}
}
return $queryLog;
} | php | protected function _getQueryLogs()
{
$sources = $this->_getSources();
$queryLog = [];
foreach ($sources as $source) {
$logger = $this->_getSource($source)->getLogger();
if (method_exists($logger, 'getLogs')) {
$queryLog[$source] = $logger->getLogs();
}
}
return $queryLog;
} | [
"protected",
"function",
"_getQueryLogs",
"(",
")",
"{",
"$",
"sources",
"=",
"$",
"this",
"->",
"_getSources",
"(",
")",
";",
"$",
"queryLog",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sources",
"as",
"$",
"source",
")",
"{",
"$",
"logger",
"=",
"... | Get the query logs for all sources
@return array | [
"Get",
"the",
"query",
"logs",
"for",
"all",
"sources"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/ApiQueryLogListener.php#L90-L103 | train |
FriendsOfCake/crud | src/Action/Bulk/BaseAction.php | BaseAction._handle | protected function _handle()
{
$ids = $this->_processIds();
$subject = $this->_constructSubject($ids);
$event = $this->_trigger('beforeBulk', $subject);
if ($event->isStopped()) {
return $this->_stopped($subject);
}
if ($this->_bulk($subject->query)) {
$this->_success($subject);
} else {
$this->_error($subject);
}
return $this->_redirect($subject, ['action' => 'index']);
} | php | protected function _handle()
{
$ids = $this->_processIds();
$subject = $this->_constructSubject($ids);
$event = $this->_trigger('beforeBulk', $subject);
if ($event->isStopped()) {
return $this->_stopped($subject);
}
if ($this->_bulk($subject->query)) {
$this->_success($subject);
} else {
$this->_error($subject);
}
return $this->_redirect($subject, ['action' => 'index']);
} | [
"protected",
"function",
"_handle",
"(",
")",
"{",
"$",
"ids",
"=",
"$",
"this",
"->",
"_processIds",
"(",
")",
";",
"$",
"subject",
"=",
"$",
"this",
"->",
"_constructSubject",
"(",
"$",
"ids",
")",
";",
"$",
"event",
"=",
"$",
"this",
"->",
"_tri... | Handle a bulk event
@return \Cake\Http\Response | [
"Handle",
"a",
"bulk",
"event"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/Bulk/BaseAction.php#L48-L65 | train |
FriendsOfCake/crud | src/Action/Bulk/BaseAction.php | BaseAction._processIds | protected function _processIds()
{
$ids = $this->_controller()->request->getData('id');
$all = false;
if (is_array($ids)) {
$all = Hash::get($ids, '_all', false);
unset($ids['_all']);
}
if (!is_array($ids)) {
throw new BadRequestException('Bad request data');
}
if ($all) {
foreach ($ids as $key => $value) {
$ids[$key] = 1;
}
$ids = array_keys($ids);
}
$ids = array_filter($ids);
return array_values($ids);
} | php | protected function _processIds()
{
$ids = $this->_controller()->request->getData('id');
$all = false;
if (is_array($ids)) {
$all = Hash::get($ids, '_all', false);
unset($ids['_all']);
}
if (!is_array($ids)) {
throw new BadRequestException('Bad request data');
}
if ($all) {
foreach ($ids as $key => $value) {
$ids[$key] = 1;
}
$ids = array_keys($ids);
}
$ids = array_filter($ids);
return array_values($ids);
} | [
"protected",
"function",
"_processIds",
"(",
")",
"{",
"$",
"ids",
"=",
"$",
"this",
"->",
"_controller",
"(",
")",
"->",
"request",
"->",
"getData",
"(",
"'id'",
")",
";",
"$",
"all",
"=",
"false",
";",
"if",
"(",
"is_array",
"(",
"$",
"ids",
")",... | Retrieves a list of ids to process
@return array | [
"Retrieves",
"a",
"list",
"of",
"ids",
"to",
"process"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/Bulk/BaseAction.php#L72-L96 | train |
FriendsOfCake/crud | src/Action/Bulk/BaseAction.php | BaseAction._constructSubject | protected function _constructSubject(array $ids)
{
$repository = $this->_table();
list($finder, $options) = $this->_extractFinder();
$options = array_merge($options, $this->_getFindConfig($ids));
$query = $repository->find($finder, $options);
$subject = $this->_subject();
$subject->set([
'ids' => $ids,
'query' => $query,
'repository' => $repository,
]);
return $subject;
} | php | protected function _constructSubject(array $ids)
{
$repository = $this->_table();
list($finder, $options) = $this->_extractFinder();
$options = array_merge($options, $this->_getFindConfig($ids));
$query = $repository->find($finder, $options);
$subject = $this->_subject();
$subject->set([
'ids' => $ids,
'query' => $query,
'repository' => $repository,
]);
return $subject;
} | [
"protected",
"function",
"_constructSubject",
"(",
"array",
"$",
"ids",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"_table",
"(",
")",
";",
"list",
"(",
"$",
"finder",
",",
"$",
"options",
")",
"=",
"$",
"this",
"->",
"_extractFinder",
"(",
... | Setup a query object for retrieving entities
@param array $ids An array of ids to retrieve
@return \Crud\Event\Subject | [
"Setup",
"a",
"query",
"object",
"for",
"retrieving",
"entities"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/Bulk/BaseAction.php#L104-L120 | train |
FriendsOfCake/crud | src/Action/Bulk/DeleteAction.php | DeleteAction._bulk | protected function _bulk(Query $query = null)
{
$query = $query->delete();
$statement = $query->execute();
$statement->closeCursor();
return (bool)$statement->rowCount();
} | php | protected function _bulk(Query $query = null)
{
$query = $query->delete();
$statement = $query->execute();
$statement->closeCursor();
return (bool)$statement->rowCount();
} | [
"protected",
"function",
"_bulk",
"(",
"Query",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"delete",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"$",
"statement",
"->",
"close... | Handle a bulk delete
@param \Cake\ORM\Query|null $query The query to act upon
@return bool | [
"Handle",
"a",
"bulk",
"delete"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/Bulk/DeleteAction.php#L42-L49 | train |
FriendsOfCake/crud | src/Action/Bulk/ToggleAction.php | ToggleAction._bulk | protected function _bulk(Query $query = null)
{
$field = $this->getConfig('field');
$expression = [new QueryExpression(sprintf('%1$s= NOT %1$s', $field))];
$query->update()->set($expression);
$statement = $query->execute();
$statement->closeCursor();
return (bool)$statement->rowCount();
} | php | protected function _bulk(Query $query = null)
{
$field = $this->getConfig('field');
$expression = [new QueryExpression(sprintf('%1$s= NOT %1$s', $field))];
$query->update()->set($expression);
$statement = $query->execute();
$statement->closeCursor();
return (bool)$statement->rowCount();
} | [
"protected",
"function",
"_bulk",
"(",
"Query",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'field'",
")",
";",
"$",
"expression",
"=",
"[",
"new",
"QueryExpression",
"(",
"sprintf",
"(",
"'%1$s= NOT %1$s... | Handle a bulk toggle
@param \Cake\ORM\Query|null $query The query to act upon
@return bool | [
"Handle",
"a",
"bulk",
"toggle"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Action/Bulk/ToggleAction.php#L60-L69 | train |
FriendsOfCake/crud | src/Listener/RelatedModelsListener.php | RelatedModelsListener.beforePaginate | public function beforePaginate(Event $event)
{
$method = 'contain';
if (method_exists($event->getSubject()->query, 'getContain')) {
$method = 'getContain';
}
$contained = $event->getSubject()->query->$method();
if (!empty($contained)) {
return;
}
$models = $this->models();
if (empty($models)) {
return;
}
$event->getSubject()->query->contain(array_keys($models));
} | php | public function beforePaginate(Event $event)
{
$method = 'contain';
if (method_exists($event->getSubject()->query, 'getContain')) {
$method = 'getContain';
}
$contained = $event->getSubject()->query->$method();
if (!empty($contained)) {
return;
}
$models = $this->models();
if (empty($models)) {
return;
}
$event->getSubject()->query->contain(array_keys($models));
} | [
"public",
"function",
"beforePaginate",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"method",
"=",
"'contain'",
";",
"if",
"(",
"method_exists",
"(",
"$",
"event",
"->",
"getSubject",
"(",
")",
"->",
"query",
",",
"'getContain'",
")",
")",
"{",
"$",
"me... | Automatically parse and contain related table classes
@param \Cake\Event\Event $event Before paginate event
@return void | [
"Automatically",
"parse",
"and",
"contain",
"related",
"table",
"classes"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/RelatedModelsListener.php#L38-L56 | train |
FriendsOfCake/crud | src/Listener/RelatedModelsListener.php | RelatedModelsListener.beforeRender | public function beforeRender(Event $event)
{
$entity = null;
if (isset($event->getSubject()->entity)) {
$entity = $event->getSubject()->entity;
}
$this->publishRelatedModels(null, $entity);
} | php | public function beforeRender(Event $event)
{
$entity = null;
if (isset($event->getSubject()->entity)) {
$entity = $event->getSubject()->entity;
}
$this->publishRelatedModels(null, $entity);
} | [
"public",
"function",
"beforeRender",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"entity",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"event",
"->",
"getSubject",
"(",
")",
"->",
"entity",
")",
")",
"{",
"$",
"entity",
"=",
"$",
"event",
"->",... | Fetches related models' list and sets them to a variable for the view
@param Event $event Event
@return void
@codeCoverageIgnore | [
"Fetches",
"related",
"models",
"list",
"and",
"sets",
"them",
"to",
"a",
"variable",
"for",
"the",
"view"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/RelatedModelsListener.php#L65-L72 | train |
FriendsOfCake/crud | src/Listener/RelatedModelsListener.php | RelatedModelsListener.publishRelatedModels | public function publishRelatedModels($action = null, $entity = null)
{
$models = $this->models($action);
if (empty($models)) {
return;
}
$controller = $this->_controller();
foreach ($models as $name => $association) {
list(, $associationName) = pluginSplit($association->getName());
$viewVar = Inflector::variable($associationName);
if (array_key_exists($viewVar, $controller->viewVars)) {
continue;
}
$finder = $this->finder($association);
$query = $association->find()->find($finder, $this->_findOptions($association));
$subject = $this->_subject(compact('name', 'viewVar', 'query', 'association', 'entity'));
$event = $this->_trigger('relatedModel', $subject);
$controller->set($event->getSubject()->viewVar, $event->getSubject()->query->toArray());
}
} | php | public function publishRelatedModels($action = null, $entity = null)
{
$models = $this->models($action);
if (empty($models)) {
return;
}
$controller = $this->_controller();
foreach ($models as $name => $association) {
list(, $associationName) = pluginSplit($association->getName());
$viewVar = Inflector::variable($associationName);
if (array_key_exists($viewVar, $controller->viewVars)) {
continue;
}
$finder = $this->finder($association);
$query = $association->find()->find($finder, $this->_findOptions($association));
$subject = $this->_subject(compact('name', 'viewVar', 'query', 'association', 'entity'));
$event = $this->_trigger('relatedModel', $subject);
$controller->set($event->getSubject()->viewVar, $event->getSubject()->query->toArray());
}
} | [
"public",
"function",
"publishRelatedModels",
"(",
"$",
"action",
"=",
"null",
",",
"$",
"entity",
"=",
"null",
")",
"{",
"$",
"models",
"=",
"$",
"this",
"->",
"models",
"(",
"$",
"action",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"models",
")",
")... | Find and publish all related models to the view
for an action
@param null|string $action If NULL the current action will be used
@param null|\Cake\ORM\Entity $entity The optional entity for which we we trying to find related
@return void | [
"Find",
"and",
"publish",
"all",
"related",
"models",
"to",
"the",
"view",
"for",
"an",
"action"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/RelatedModelsListener.php#L82-L106 | train |
FriendsOfCake/crud | src/Listener/RelatedModelsListener.php | RelatedModelsListener.models | public function models($action = null)
{
$settings = $this->relatedModels(null, $action);
if ($settings === true) {
return $this->getAssociatedByType(['oneToOne', 'manyToMany', 'manyToOne']);
}
if (empty($settings)) {
return [];
}
if (is_string($settings)) {
$settings = [$settings];
}
return $this->getAssociatedByName($settings);
} | php | public function models($action = null)
{
$settings = $this->relatedModels(null, $action);
if ($settings === true) {
return $this->getAssociatedByType(['oneToOne', 'manyToMany', 'manyToOne']);
}
if (empty($settings)) {
return [];
}
if (is_string($settings)) {
$settings = [$settings];
}
return $this->getAssociatedByName($settings);
} | [
"public",
"function",
"models",
"(",
"$",
"action",
"=",
"null",
")",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"relatedModels",
"(",
"null",
",",
"$",
"action",
")",
";",
"if",
"(",
"$",
"settings",
"===",
"true",
")",
"{",
"return",
"$",
"thi... | Gets the list of associated model lists to be fetched for an action
@param string|null $action name of the action
@return array | [
"Gets",
"the",
"list",
"of",
"associated",
"model",
"lists",
"to",
"be",
"fetched",
"for",
"an",
"action"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/RelatedModelsListener.php#L145-L162 | train |
FriendsOfCake/crud | src/Listener/RelatedModelsListener.php | RelatedModelsListener.relatedModels | public function relatedModels($related = null, $action = null)
{
if ($related === null) {
return $this->_action($action)->getConfig('relatedModels');
}
return $this->_action($action)->setConfig('relatedModels', $related, false);
} | php | public function relatedModels($related = null, $action = null)
{
if ($related === null) {
return $this->_action($action)->getConfig('relatedModels');
}
return $this->_action($action)->setConfig('relatedModels', $related, false);
} | [
"public",
"function",
"relatedModels",
"(",
"$",
"related",
"=",
"null",
",",
"$",
"action",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"related",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_action",
"(",
"$",
"action",
")",
"->",
"getConfig"... | Set or get the related models that should be found
for the action
@param mixed $related Everything but `null` will change the configuration
@param string|null $action The action to configure
@return mixed | [
"Set",
"or",
"get",
"the",
"related",
"models",
"that",
"should",
"be",
"found",
"for",
"the",
"action"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/RelatedModelsListener.php#L172-L179 | train |
FriendsOfCake/crud | src/Listener/RelatedModelsListener.php | RelatedModelsListener.getAssociatedByType | public function getAssociatedByType($types = [])
{
$return = [];
$table = $this->_table();
foreach ($table->associations()->keys() as $association) {
$associationClass = $table->associations()->get($association);
if (!in_array($associationClass->type(), $types)) {
continue;
}
$return[$associationClass->getName()] = $associationClass;
}
return $return;
} | php | public function getAssociatedByType($types = [])
{
$return = [];
$table = $this->_table();
foreach ($table->associations()->keys() as $association) {
$associationClass = $table->associations()->get($association);
if (!in_array($associationClass->type(), $types)) {
continue;
}
$return[$associationClass->getName()] = $associationClass;
}
return $return;
} | [
"public",
"function",
"getAssociatedByType",
"(",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"_table",
"(",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"associations",
"(",
")",... | Get associated tables based on the current table instance based on their
association type
@param array $types Association types
@return array | [
"Get",
"associated",
"tables",
"based",
"on",
"the",
"current",
"table",
"instance",
"based",
"on",
"their",
"association",
"type"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/RelatedModelsListener.php#L188-L203 | train |
FriendsOfCake/crud | src/Listener/RelatedModelsListener.php | RelatedModelsListener.getAssociatedByName | public function getAssociatedByName($names)
{
$return = [];
$table = $this->_table();
foreach ($names as $association) {
$associationClass = $table->associations()->get($association);
if (!$associationClass) {
throw new RuntimeException(sprintf(
'Table "%s" is not associated with "%s"',
get_class($table),
$association
));
}
$return[$associationClass->getName()] = $associationClass;
}
return $return;
} | php | public function getAssociatedByName($names)
{
$return = [];
$table = $this->_table();
foreach ($names as $association) {
$associationClass = $table->associations()->get($association);
if (!$associationClass) {
throw new RuntimeException(sprintf(
'Table "%s" is not associated with "%s"',
get_class($table),
$association
));
}
$return[$associationClass->getName()] = $associationClass;
}
return $return;
} | [
"public",
"function",
"getAssociatedByName",
"(",
"$",
"names",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"_table",
"(",
")",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"association",
")",
"{",
"$",
"asso... | Get associated tables based on the current table instance based on their
association name
@param array $names Association names
@return array
@throws \RuntimeException when association not found. | [
"Get",
"associated",
"tables",
"based",
"on",
"the",
"current",
"table",
"instance",
"based",
"on",
"their",
"association",
"name"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/RelatedModelsListener.php#L213-L231 | train |
FriendsOfCake/crud | src/Traits/ViewVarTrait.php | ViewVarTrait.viewVar | public function viewVar($name = null)
{
if (empty($name)) {
return $this->getConfig('viewVar') ?: $this->_deriveViewVar();
}
return $this->setConfig('viewVar', $name);
} | php | public function viewVar($name = null)
{
if (empty($name)) {
return $this->getConfig('viewVar') ?: $this->_deriveViewVar();
}
return $this->setConfig('viewVar', $name);
} | [
"public",
"function",
"viewVar",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getConfig",
"(",
"'viewVar'",
")",
"?",
":",
"$",
"this",
"->",
"_deriveViewVar",
"(",
")",... | Change the name of the view variable name
of the data when its sent to the view
@param mixed $name Var name
@return mixed
@throws \Exception | [
"Change",
"the",
"name",
"of",
"the",
"view",
"variable",
"name",
"of",
"the",
"data",
"when",
"its",
"sent",
"to",
"the",
"view"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/ViewVarTrait.php#L40-L47 | train |
FriendsOfCake/crud | src/Traits/ViewVarTrait.php | ViewVarTrait._deriveViewVar | protected function _deriveViewVar()
{
if ($this->scope() === 'table') {
return Inflector::variable($this->_controller()->getName());
}
if ($this->scope() === 'entity') {
return Inflector::variable(Inflector::singularize($this->_controller()->getName()));
}
throw new Exception('Unknown action scope: ' . $this->scope());
} | php | protected function _deriveViewVar()
{
if ($this->scope() === 'table') {
return Inflector::variable($this->_controller()->getName());
}
if ($this->scope() === 'entity') {
return Inflector::variable(Inflector::singularize($this->_controller()->getName()));
}
throw new Exception('Unknown action scope: ' . $this->scope());
} | [
"protected",
"function",
"_deriveViewVar",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scope",
"(",
")",
"===",
"'table'",
")",
"{",
"return",
"Inflector",
"::",
"variable",
"(",
"$",
"this",
"->",
"_controller",
"(",
")",
"->",
"getName",
"(",
")",
... | Derive the viewVar based on the scope of the action
Actions working on a single entity will use singular name,
and actions working on a full table will use plural name
@throws Exception
@return string | [
"Derive",
"the",
"viewVar",
"based",
"on",
"the",
"scope",
"of",
"the",
"action"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/ViewVarTrait.php#L58-L69 | train |
FriendsOfCake/crud | src/Traits/ViewVarTrait.php | ViewVarTrait._deriveViewValue | protected function _deriveViewValue(Event $event)
{
$key = $this->_action()->subjectEntityKey();
return $event->getSubject()->{$key};
} | php | protected function _deriveViewValue(Event $event)
{
$key = $this->_action()->subjectEntityKey();
return $event->getSubject()->{$key};
} | [
"protected",
"function",
"_deriveViewValue",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"_action",
"(",
")",
"->",
"subjectEntityKey",
"(",
")",
";",
"return",
"$",
"event",
"->",
"getSubject",
"(",
")",
"->",
"{",
"$",
... | Derive the viewVar value based on the scope of the action
as well as the Event being handled
@param \Cake\Event\Event $event Event
@return mixed
@throws Exception | [
"Derive",
"the",
"viewVar",
"value",
"based",
"on",
"the",
"scope",
"of",
"the",
"action",
"as",
"well",
"as",
"the",
"Event",
"being",
"handled"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Traits/ViewVarTrait.php#L79-L84 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.normalizeArray | public function normalizeArray(array $array)
{
$normal = [];
foreach ($array as $action => $config) {
if (is_string($config)) {
$config = ['className' => $config];
}
if (is_int($action)) {
list(, $action) = pluginSplit($config['className']);
}
$action = Inflector::variable($action);
$normal[$action] = $config;
}
return $normal;
} | php | public function normalizeArray(array $array)
{
$normal = [];
foreach ($array as $action => $config) {
if (is_string($config)) {
$config = ['className' => $config];
}
if (is_int($action)) {
list(, $action) = pluginSplit($config['className']);
}
$action = Inflector::variable($action);
$normal[$action] = $config;
}
return $normal;
} | [
"public",
"function",
"normalizeArray",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"normal",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"action",
"=>",
"$",
"config",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"config",
")",
")",... | Normalize config array
@param array $array List to normalize
@return array | [
"Normalize",
"config",
"array"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L156-L174 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.initialize | public function initialize(array $config)
{
parent::initialize($config);
$this->_action = $this->_controller->request->getParam('action');
$this->_request = $this->_controller->request;
if (!isset($this->_controller->dispatchComponents)) {
$this->_controller->dispatchComponents = [];
}
$this->_controller->dispatchComponents['Crud'] = true;
} | php | public function initialize(array $config)
{
parent::initialize($config);
$this->_action = $this->_controller->request->getParam('action');
$this->_request = $this->_controller->request;
if (!isset($this->_controller->dispatchComponents)) {
$this->_controller->dispatchComponents = [];
}
$this->_controller->dispatchComponents['Crud'] = true;
} | [
"public",
"function",
"initialize",
"(",
"array",
"$",
"config",
")",
"{",
"parent",
"::",
"initialize",
"(",
"$",
"config",
")",
";",
"$",
"this",
"->",
"_action",
"=",
"$",
"this",
"->",
"_controller",
"->",
"request",
"->",
"getParam",
"(",
"'action'"... | Add self to list of components capable of dispatching an action.
@param array $config Configuration values for component.
@return void | [
"Add",
"self",
"to",
"list",
"of",
"components",
"capable",
"of",
"dispatching",
"an",
"action",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L182-L194 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.execute | public function execute($controllerAction = null, $args = [])
{
$this->_loadListeners();
$this->_action = $controllerAction ?: $this->_action;
$action = $this->_action;
if (empty($args)) {
$args = $this->_request->getParam('pass');
}
try {
$event = $this->trigger('beforeHandle', $this->getSubject(compact('args', 'action')));
$response = $this->action($event->getSubject()->action)->handle($event->getSubject()->args);
if ($response instanceof Response) {
return $response;
}
} catch (Exception $e) {
if (isset($e->response)) {
return $e->response;
}
throw $e;
}
$view = null;
$crudAction = $this->action($action);
if (method_exists($crudAction, 'view')) {
$view = $crudAction->view();
}
return $this->_controller->response = $this->_controller->render($view);
} | php | public function execute($controllerAction = null, $args = [])
{
$this->_loadListeners();
$this->_action = $controllerAction ?: $this->_action;
$action = $this->_action;
if (empty($args)) {
$args = $this->_request->getParam('pass');
}
try {
$event = $this->trigger('beforeHandle', $this->getSubject(compact('args', 'action')));
$response = $this->action($event->getSubject()->action)->handle($event->getSubject()->args);
if ($response instanceof Response) {
return $response;
}
} catch (Exception $e) {
if (isset($e->response)) {
return $e->response;
}
throw $e;
}
$view = null;
$crudAction = $this->action($action);
if (method_exists($crudAction, 'view')) {
$view = $crudAction->view();
}
return $this->_controller->response = $this->_controller->render($view);
} | [
"public",
"function",
"execute",
"(",
"$",
"controllerAction",
"=",
"null",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"_loadListeners",
"(",
")",
";",
"$",
"this",
"->",
"_action",
"=",
"$",
"controllerAction",
"?",
":",
"$",
"thi... | Execute a Crud action
@param string $controllerAction Override the controller action to execute as.
@param array $args List of arguments to pass to the CRUD action (Usually an ID to edit / delete).
@return \Cake\Http\Response
@throws Exception If an action is not mapped. | [
"Execute",
"a",
"Crud",
"action"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L230-L263 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.action | public function action($name = null)
{
if (empty($name)) {
$name = $this->_action;
}
$name = Inflector::variable($name);
return $this->_loadAction($name);
} | php | public function action($name = null)
{
if (empty($name)) {
$name = $this->_action;
}
$name = Inflector::variable($name);
return $this->_loadAction($name);
} | [
"public",
"function",
"action",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"_action",
";",
"}",
"$",
"name",
"=",
"Inflector",
"::",
"variable",
"(",
"$",
"... | Get a CrudAction object by action name.
@param string|null $name The controller action name.
@return \Crud\Action\BaseAction
@throws \Crud\Error\Exception\ActionNotConfiguredException
@throws \Crud\Error\Exception\MissingActionException | [
"Get",
"a",
"CrudAction",
"object",
"by",
"action",
"name",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L273-L282 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.view | public function view($action, $view = null)
{
if (is_array($action)) {
foreach ($action as $realAction => $realView) {
$this->action($realAction)->view($realView);
}
return;
}
$this->action($action)->view($view);
} | php | public function view($action, $view = null)
{
if (is_array($action)) {
foreach ($action as $realAction => $realView) {
$this->action($realAction)->view($realView);
}
return;
}
$this->action($action)->view($view);
} | [
"public",
"function",
"view",
"(",
"$",
"action",
",",
"$",
"view",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"action",
")",
")",
"{",
"foreach",
"(",
"$",
"action",
"as",
"$",
"realAction",
"=>",
"$",
"realView",
")",
"{",
"$",
"th... | Map the view file to use for a controller action.
To map multiple action views in one go pass an array as first argument and no second argument.
@param string|array $action Action or array of actions
@param string|null $view View name
@return void
@throws \Crud\Error\Exception\ActionNotConfiguredException
@throws \Crud\Error\Exception\MissingActionException | [
"Map",
"the",
"view",
"file",
"to",
"use",
"for",
"a",
"controller",
"action",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L325-L336 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.viewVar | public function viewVar($action, $viewVar = null)
{
if (is_array($action)) {
foreach ($action as $realAction => $realViewVar) {
$this->action($realAction)->viewVar($realViewVar);
}
return;
}
$this->action($action)->viewVar($viewVar);
} | php | public function viewVar($action, $viewVar = null)
{
if (is_array($action)) {
foreach ($action as $realAction => $realViewVar) {
$this->action($realAction)->viewVar($realViewVar);
}
return;
}
$this->action($action)->viewVar($viewVar);
} | [
"public",
"function",
"viewVar",
"(",
"$",
"action",
",",
"$",
"viewVar",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"action",
")",
")",
"{",
"foreach",
"(",
"$",
"action",
"as",
"$",
"realAction",
"=>",
"$",
"realViewVar",
")",
"{",
"... | Change the viewVar name for one or multiple actions.
To map multiple action viewVars in one go pass an array as first argument and no second argument.
@param string|array $action Action or array of actions.
@param string|null $viewVar View var name.
@return void
@throws \Crud\Error\Exception\ActionNotConfiguredException
@throws \Crud\Error\Exception\MissingActionException | [
"Change",
"the",
"viewVar",
"name",
"for",
"one",
"or",
"multiple",
"actions",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L349-L360 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.mapAction | public function mapAction($action, $config = [], $enable = true)
{
if (is_string($config)) {
$config = ['className' => $config];
}
$action = Inflector::variable($action);
$this->setConfig('actions.' . $action, $config);
if ($enable) {
$this->enable($action);
}
} | php | public function mapAction($action, $config = [], $enable = true)
{
if (is_string($config)) {
$config = ['className' => $config];
}
$action = Inflector::variable($action);
$this->setConfig('actions.' . $action, $config);
if ($enable) {
$this->enable($action);
}
} | [
"public",
"function",
"mapAction",
"(",
"$",
"action",
",",
"$",
"config",
"=",
"[",
"]",
",",
"$",
"enable",
"=",
"true",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"[",
"'className'",
"=>",
"$",
"co... | Map action to an internal request type.
@param string $action The Controller action to provide an implementation for.
@param string|array $config Config array or class name like Crud.Index.
@param bool $enable Should the mapping be enabled right away?
@return void
@throws \Crud\Error\Exception\ActionNotConfiguredException
@throws \Crud\Error\Exception\MissingActionException | [
"Map",
"action",
"to",
"an",
"internal",
"request",
"type",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L396-L407 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.on | public function on($events, $callback, $options = [])
{
foreach ((array)$events as $event) {
if (!strpos($event, '.')) {
$event = $this->_config['eventPrefix'] . '.' . $event;
}
$this->_eventManager->on($event, $options, $callback);
}
} | php | public function on($events, $callback, $options = [])
{
foreach ((array)$events as $event) {
if (!strpos($event, '.')) {
$event = $this->_config['eventPrefix'] . '.' . $event;
}
$this->_eventManager->on($event, $options, $callback);
}
} | [
"public",
"function",
"on",
"(",
"$",
"events",
",",
"$",
"callback",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"events",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"strpos",
"(",
"$",
"event",
","... | Attaches an event listener function to the controller for Crud Events.
@param string|array $events Name of the Crud Event you want to attach to controller.
@param callable $callback Callable method or closure to be executed on event.
@param array $options Used to set the `priority` and `passParams` flags to the listener.
@return void | [
"Attaches",
"an",
"event",
"listener",
"function",
"to",
"the",
"controller",
"for",
"Crud",
"Events",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L440-L449 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.addListener | public function addListener($name, $className = null, $config = [])
{
if (strpos($name, '.') !== false) {
list($plugin, $name) = pluginSplit($name);
$className = $plugin . '.' . Inflector::camelize($name);
}
$name = Inflector::variable($name);
$this->setConfig(sprintf('listeners.%s', $name), compact('className') + $config);
} | php | public function addListener($name, $className = null, $config = [])
{
if (strpos($name, '.') !== false) {
list($plugin, $name) = pluginSplit($name);
$className = $plugin . '.' . Inflector::camelize($name);
}
$name = Inflector::variable($name);
$this->setConfig(sprintf('listeners.%s', $name), compact('className') + $config);
} | [
"public",
"function",
"addListener",
"(",
"$",
"name",
",",
"$",
"className",
"=",
"null",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"plugin",
... | Add a new listener to Crud
This will not load or initialize the listener, only lazy-load it.
If `$name` is provided but no `$class` argument, the className will
be derived from the `$name`.
CakePHP Plugin.ClassName format for `$name` and `$class` is supported.
@param string $name Name
@param string $className Normal CakePHP plugin-dot annotation supported.
@param array $config Any default settings for a listener.
@return void | [
"Add",
"a",
"new",
"listener",
"to",
"Crud"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L479-L488 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.removeListener | public function removeListener($name)
{
$listeners = $this->getConfig('listeners');
if (!array_key_exists($name, $listeners)) {
return false;
}
if (isset($this->_listenerInstances[$name])) {
$this->_eventManager->off($this->_listenerInstances[$name]);
unset($this->_listenerInstances[$name]);
}
unset($listeners[$name]);
$this->_config['listeners'] = $listeners;
} | php | public function removeListener($name)
{
$listeners = $this->getConfig('listeners');
if (!array_key_exists($name, $listeners)) {
return false;
}
if (isset($this->_listenerInstances[$name])) {
$this->_eventManager->off($this->_listenerInstances[$name]);
unset($this->_listenerInstances[$name]);
}
unset($listeners[$name]);
$this->_config['listeners'] = $listeners;
} | [
"public",
"function",
"removeListener",
"(",
"$",
"name",
")",
"{",
"$",
"listeners",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'listeners'",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"listeners",
")",
")",
"{",
"return... | Remove a listener from Crud.
This will also detach it from the EventManager if it's attached.
@param string $name Name
@return bool|null | [
"Remove",
"a",
"listener",
"from",
"Crud",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L498-L512 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.defaults | public function defaults($type, $name, $config = null)
{
if ($config !== null) {
if (!is_array($name)) {
$name = [$name];
}
foreach ($name as $realName) {
$this->setConfig(sprintf('%s.%s', $type, $realName), $config);
}
return null;
}
return $this->getConfig(sprintf('%s.%s', $type, $name));
} | php | public function defaults($type, $name, $config = null)
{
if ($config !== null) {
if (!is_array($name)) {
$name = [$name];
}
foreach ($name as $realName) {
$this->setConfig(sprintf('%s.%s', $type, $realName), $config);
}
return null;
}
return $this->getConfig(sprintf('%s.%s', $type, $name));
} | [
"public",
"function",
"defaults",
"(",
"$",
"type",
",",
"$",
"name",
",",
"$",
"config",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"config",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
... | Set or get defaults for listeners and actions.
@param string $type Can be anything, but 'listeners' or 'actions' is currently only used.
@param string|array $name The name of the $type - e.g. 'api', 'relatedModels'
or an array ('api', 'relatedModels'). If $name is an array, the $config will be applied
to each entry in the $name array.
@param mixed $config If NULL, the defaults is returned, else the defaults are changed.
@return mixed | [
"Set",
"or",
"get",
"defaults",
"for",
"listeners",
"and",
"actions",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L573-L588 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent.useModel | public function useModel($modelName)
{
$this->_controller->loadModel($modelName);
list(, $this->_modelName) = pluginSplit($modelName);
} | php | public function useModel($modelName)
{
$this->_controller->loadModel($modelName);
list(, $this->_modelName) = pluginSplit($modelName);
} | [
"public",
"function",
"useModel",
"(",
"$",
"modelName",
")",
"{",
"$",
"this",
"->",
"_controller",
"->",
"loadModel",
"(",
"$",
"modelName",
")",
";",
"list",
"(",
",",
"$",
"this",
"->",
"_modelName",
")",
"=",
"pluginSplit",
"(",
"$",
"modelName",
... | Sets the model class to be used during the action execution.
@param string $modelName The name of the model to load.
@return void | [
"Sets",
"the",
"model",
"class",
"to",
"be",
"used",
"during",
"the",
"action",
"execution",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L606-L610 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent._loadListener | protected function _loadListener($name)
{
if (!isset($this->_listenerInstances[$name])) {
$config = $this->getConfig('listeners.' . $name);
if (empty($config)) {
throw new ListenerNotConfiguredException(sprintf('Listener "%s" is not configured', $name));
}
$className = App::className($config['className'], 'Listener', 'Listener');
if (empty($className)) {
throw new MissingListenerException('Could not find listener class: ' . $config['className']);
}
$this->_listenerInstances[$name] = new $className($this->_controller);
unset($config['className']);
$this->_listenerInstances[$name]->setConfig($config);
$this->_eventManager->on($this->_listenerInstances[$name]);
if (is_callable([$this->_listenerInstances[$name], 'setup'])) {
$this->_listenerInstances[$name]->setup();
}
}
return $this->_listenerInstances[$name];
} | php | protected function _loadListener($name)
{
if (!isset($this->_listenerInstances[$name])) {
$config = $this->getConfig('listeners.' . $name);
if (empty($config)) {
throw new ListenerNotConfiguredException(sprintf('Listener "%s" is not configured', $name));
}
$className = App::className($config['className'], 'Listener', 'Listener');
if (empty($className)) {
throw new MissingListenerException('Could not find listener class: ' . $config['className']);
}
$this->_listenerInstances[$name] = new $className($this->_controller);
unset($config['className']);
$this->_listenerInstances[$name]->setConfig($config);
$this->_eventManager->on($this->_listenerInstances[$name]);
if (is_callable([$this->_listenerInstances[$name], 'setup'])) {
$this->_listenerInstances[$name]->setup();
}
}
return $this->_listenerInstances[$name];
} | [
"protected",
"function",
"_loadListener",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_listenerInstances",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'listeners.'",
... | Load a single event class attached to Crud.
@param string $name Name
@return \Crud\Listener\BaseListener
@throws \Crud\Error\Exception\ListenerNotConfiguredException
@throws \Crud\Error\Exception\MissingListenerException | [
"Load",
"a",
"single",
"event",
"class",
"attached",
"to",
"Crud",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L679-L705 | train |
FriendsOfCake/crud | src/Controller/Component/CrudComponent.php | CrudComponent._loadAction | protected function _loadAction($name)
{
if (!isset($this->_actionInstances[$name])) {
$config = $this->getConfig('actions.' . $name);
if (empty($config)) {
throw new ActionNotConfiguredException(sprintf('Action "%s" has not been mapped', $name));
}
$className = App::className($config['className'], 'Action', 'Action');
if (empty($className)) {
throw new MissingActionException('Could not find action class: ' . $config['className']);
}
$this->_actionInstances[$name] = new $className($this->_controller);
unset($config['className']);
$this->_actionInstances[$name]->setConfig($config);
}
return $this->_actionInstances[$name];
} | php | protected function _loadAction($name)
{
if (!isset($this->_actionInstances[$name])) {
$config = $this->getConfig('actions.' . $name);
if (empty($config)) {
throw new ActionNotConfiguredException(sprintf('Action "%s" has not been mapped', $name));
}
$className = App::className($config['className'], 'Action', 'Action');
if (empty($className)) {
throw new MissingActionException('Could not find action class: ' . $config['className']);
}
$this->_actionInstances[$name] = new $className($this->_controller);
unset($config['className']);
$this->_actionInstances[$name]->setConfig($config);
}
return $this->_actionInstances[$name];
} | [
"protected",
"function",
"_loadAction",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_actionInstances",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'actions.'",
".",... | Load a CrudAction instance.
@param string $name The controller action name.
@return \Crud\Action\BaseAction
@throws \Crud\Error\Exception\ActionNotConfiguredException
@throws \Crud\Error\Exception\MissingActionException | [
"Load",
"a",
"CrudAction",
"instance",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/Component/CrudComponent.php#L715-L735 | train |
FriendsOfCake/crud | src/Controller/ControllerTrait.php | ControllerTrait._isActionMapped | protected function _isActionMapped()
{
if (!empty($this->dispatchComponents)) {
foreach ($this->dispatchComponents as $component => $enabled) {
if (empty($enabled)) {
continue;
}
// Skip if isActionMapped isn't defined in the Component
if (!method_exists($this->{$component}, 'isActionMapped')) {
continue;
}
// Skip if the action isn't mapped
if (!$this->{$component}->isActionMapped()) {
continue;
}
// Skip if execute isn't defined in the Component
if (!method_exists($this->{$component}, 'execute')) {
continue;
}
// Return the component instance.
return $this->{$component};
}
}
return false;
} | php | protected function _isActionMapped()
{
if (!empty($this->dispatchComponents)) {
foreach ($this->dispatchComponents as $component => $enabled) {
if (empty($enabled)) {
continue;
}
// Skip if isActionMapped isn't defined in the Component
if (!method_exists($this->{$component}, 'isActionMapped')) {
continue;
}
// Skip if the action isn't mapped
if (!$this->{$component}->isActionMapped()) {
continue;
}
// Skip if execute isn't defined in the Component
if (!method_exists($this->{$component}, 'execute')) {
continue;
}
// Return the component instance.
return $this->{$component};
}
}
return false;
} | [
"protected",
"function",
"_isActionMapped",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"dispatchComponents",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dispatchComponents",
"as",
"$",
"component",
"=>",
"$",
"enabled",
")",
"... | Check if an action can be dispatched using CRUD.
@return bool|\Cake\Controller\Component The component instance if action is
mapped else `false`. | [
"Check",
"if",
"an",
"action",
"can",
"be",
"dispatched",
"using",
"CRUD",
"."
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Controller/ControllerTrait.php#L106-L135 | train |
FriendsOfCake/crud | src/Listener/RedirectListener.php | RedirectListener.reader | public function reader($key, $reader = null)
{
if ($reader === null) {
return $this->getConfig('readers.' . $key);
}
return $this->setConfig('readers.' . $key, $reader);
} | php | public function reader($key, $reader = null)
{
if ($reader === null) {
return $this->getConfig('readers.' . $key);
}
return $this->setConfig('readers.' . $key, $reader);
} | [
"public",
"function",
"reader",
"(",
"$",
"key",
",",
"$",
"reader",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"reader",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getConfig",
"(",
"'readers.'",
".",
"$",
"key",
")",
";",
"}",
"return",
... | Add or replace a reader
@param string $key Key
@param mixed $reader Reader
@return mixed | [
"Add",
"or",
"replace",
"a",
"reader"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/RedirectListener.php#L90-L97 | train |
FriendsOfCake/crud | src/Listener/RedirectListener.php | RedirectListener._getUrl | protected function _getUrl(Subject $subject, array $url)
{
foreach ($url as $key => $value) {
if (!is_array($value)) {
continue;
}
if ($key === '?') {
$url[$key] = $this->_getUrl($subject, $value);
continue;
}
$url[$key] = $this->_getKey($subject, $value[0], $value[1]);
}
return $url;
} | php | protected function _getUrl(Subject $subject, array $url)
{
foreach ($url as $key => $value) {
if (!is_array($value)) {
continue;
}
if ($key === '?') {
$url[$key] = $this->_getUrl($subject, $value);
continue;
}
$url[$key] = $this->_getKey($subject, $value[0], $value[1]);
}
return $url;
} | [
"protected",
"function",
"_getUrl",
"(",
"Subject",
"$",
"subject",
",",
"array",
"$",
"url",
")",
"{",
"foreach",
"(",
"$",
"url",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"con... | Get the new redirect URL
Expand configurations where possible and replace the
placeholder with the actual value
@param \Crud\Event\Subject $subject Subject
@param array $url URL
@return array
@throws \Exception | [
"Get",
"the",
"new",
"redirect",
"URL"
] | fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057 | https://github.com/FriendsOfCake/crud/blob/fd6e1a6eaa49f5aea7ff3e1ab76c45c122c4e057/src/Listener/RedirectListener.php#L139-L155 | train |
wirecard/paymentSDK-php | src/Entity/Basket.php | Basket.parseFromXml | public function parseFromXml($simpleXml)
{
if (!isset($simpleXml->{'order-items'})) {
return;
}
if ($simpleXml->{'order-items'}->children()->count() < 1) {
return;
}
$basketVersion = '';
switch ((string)$simpleXml->{'payment-methods'}->{'payment-method'}['name']) {
case PayPalTransaction::NAME:
$basketVersion = PayPalTransaction::class;
break;
case RatepayInvoiceTransaction::NAME:
case RatepayInstallmentTransaction::NAME:
$basketVersion = RatepayTransaction::class;
break;
}
foreach ($simpleXml->{'order-items'}->children() as $orderItem) {
$amountAttrs = $orderItem->amount->attributes();
$amount = new Amount(
(float)$orderItem->amount,
(string)$amountAttrs->currency
);
$basketItem = new Item((string)$orderItem->name, $amount, (int)$orderItem->quantity);
if (isset($orderItem->{'tax-amount'})) {
$taxAmountAttrs = $orderItem->{'tax-amount'}->attributes();
$taxAmount = new Amount(
(float)$orderItem->{'tax-amount'},
(string)$taxAmountAttrs->currency
);
$basketItem->setTaxAmount($taxAmount);
}
$basketItem->setVersion($basketVersion)
->setDescription((string)$orderItem->description)
->setArticleNumber((string)$orderItem->{'article-number'});
$this->add($basketItem);
}
return $this;
} | php | public function parseFromXml($simpleXml)
{
if (!isset($simpleXml->{'order-items'})) {
return;
}
if ($simpleXml->{'order-items'}->children()->count() < 1) {
return;
}
$basketVersion = '';
switch ((string)$simpleXml->{'payment-methods'}->{'payment-method'}['name']) {
case PayPalTransaction::NAME:
$basketVersion = PayPalTransaction::class;
break;
case RatepayInvoiceTransaction::NAME:
case RatepayInstallmentTransaction::NAME:
$basketVersion = RatepayTransaction::class;
break;
}
foreach ($simpleXml->{'order-items'}->children() as $orderItem) {
$amountAttrs = $orderItem->amount->attributes();
$amount = new Amount(
(float)$orderItem->amount,
(string)$amountAttrs->currency
);
$basketItem = new Item((string)$orderItem->name, $amount, (int)$orderItem->quantity);
if (isset($orderItem->{'tax-amount'})) {
$taxAmountAttrs = $orderItem->{'tax-amount'}->attributes();
$taxAmount = new Amount(
(float)$orderItem->{'tax-amount'},
(string)$taxAmountAttrs->currency
);
$basketItem->setTaxAmount($taxAmount);
}
$basketItem->setVersion($basketVersion)
->setDescription((string)$orderItem->description)
->setArticleNumber((string)$orderItem->{'article-number'});
$this->add($basketItem);
}
return $this;
} | [
"public",
"function",
"parseFromXml",
"(",
"$",
"simpleXml",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"simpleXml",
"->",
"{",
"'order-items'",
"}",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"simpleXml",
"->",
"{",
"'order-items'",
"}",
"... | Parse simplexml and create basket object
@param SimpleXMLElement $simpleXml
@return Basket
@since 3.2.0 | [
"Parse",
"simplexml",
"and",
"create",
"basket",
"object"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Entity/Basket.php#L161-L207 | train |
wirecard/paymentSDK-php | src/Entity/Card.php | Card.parseFromXml | private function parseFromXml($simpleXml)
{
if (isset($simpleXml->{'card-token'}->{'masked-account-number'})) {
$this->maskedPan = $simpleXml->{'card-token'}->{'masked-account-number'};
}
if (isset($simpleXml->{'card-token'}->{'token-id'})) {
$this->token = $simpleXml->{'card-token'}->{'token-id'};
}
} | php | private function parseFromXml($simpleXml)
{
if (isset($simpleXml->{'card-token'}->{'masked-account-number'})) {
$this->maskedPan = $simpleXml->{'card-token'}->{'masked-account-number'};
}
if (isset($simpleXml->{'card-token'}->{'token-id'})) {
$this->token = $simpleXml->{'card-token'}->{'token-id'};
}
} | [
"private",
"function",
"parseFromXml",
"(",
"$",
"simpleXml",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"simpleXml",
"->",
"{",
"'card-token'",
"}",
"->",
"{",
"'masked-account-number'",
"}",
")",
")",
"{",
"$",
"this",
"->",
"maskedPan",
"=",
"$",
"simple... | Parse card from response xml
@param SimpleXMLElement $simpleXml
@since 3.2.0 | [
"Parse",
"card",
"from",
"response",
"xml"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Entity/Card.php#L117-L125 | train |
wirecard/paymentSDK-php | src/TransactionService.php | TransactionService.getCreditCardUiWithData | public function getCreditCardUiWithData(
$transaction,
$paymentAction,
$language = 'en'
) {
$config = $this->config->get($transaction::NAME);
$merchantAccountId = $config->getMerchantAccountId();
$secret = $config->getSecret();
$isThreeD = false;
$amount = $transaction->getAmount();
if ($transaction instanceof CreditCardTransaction) {
$isThreeD = is_null($config->getMerchantAccountId()) || ($config->getThreeDMerchantAccountId() &&
($transaction->isFallback() || $transaction->getThreeD())) ? true : false;
$merchantAccountId = $isThreeD ? $config->getThreeDMerchantAccountId() : $config->getMerchantAccountId();
$secret = $isThreeD ? $config->getThreeDSecret() : $config->getSecret();
}
$transactionType = 'tokenize';
if (!is_null($amount) && $amount->getValue() > 0) {
$transactionType = $paymentAction;
}
$requestData = array(
'request_time_stamp' => gmdate('YmdHis'),
self::REQUEST_ID => call_user_func($this->requestIdGenerator, 64),
'transaction_type' => $transactionType,
'merchant_account_id' => $merchantAccountId,
'requested_amount' => is_null($amount) ? 0 : $amount->getValue(),
'requested_amount_currency' => is_null($amount) ? 'EUR' : $amount->getCurrency(),
'locale' => $language,
'payment_method' => 'creditcard',
'attempt_three_d' => $isThreeD ? true : false,
);
$requestData = $this->requestMapper->mapSeamlessRequest($transaction, $requestData);
$requestData['request_signature'] = $this->toSha256($requestData, $secret);
$this->getLogger()->debug('Seamless request body: ' . json_encode($requestData));
return json_encode($requestData);
} | php | public function getCreditCardUiWithData(
$transaction,
$paymentAction,
$language = 'en'
) {
$config = $this->config->get($transaction::NAME);
$merchantAccountId = $config->getMerchantAccountId();
$secret = $config->getSecret();
$isThreeD = false;
$amount = $transaction->getAmount();
if ($transaction instanceof CreditCardTransaction) {
$isThreeD = is_null($config->getMerchantAccountId()) || ($config->getThreeDMerchantAccountId() &&
($transaction->isFallback() || $transaction->getThreeD())) ? true : false;
$merchantAccountId = $isThreeD ? $config->getThreeDMerchantAccountId() : $config->getMerchantAccountId();
$secret = $isThreeD ? $config->getThreeDSecret() : $config->getSecret();
}
$transactionType = 'tokenize';
if (!is_null($amount) && $amount->getValue() > 0) {
$transactionType = $paymentAction;
}
$requestData = array(
'request_time_stamp' => gmdate('YmdHis'),
self::REQUEST_ID => call_user_func($this->requestIdGenerator, 64),
'transaction_type' => $transactionType,
'merchant_account_id' => $merchantAccountId,
'requested_amount' => is_null($amount) ? 0 : $amount->getValue(),
'requested_amount_currency' => is_null($amount) ? 'EUR' : $amount->getCurrency(),
'locale' => $language,
'payment_method' => 'creditcard',
'attempt_three_d' => $isThreeD ? true : false,
);
$requestData = $this->requestMapper->mapSeamlessRequest($transaction, $requestData);
$requestData['request_signature'] = $this->toSha256($requestData, $secret);
$this->getLogger()->debug('Seamless request body: ' . json_encode($requestData));
return json_encode($requestData);
} | [
"public",
"function",
"getCreditCardUiWithData",
"(",
"$",
"transaction",
",",
"$",
"paymentAction",
",",
"$",
"language",
"=",
"'en'",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"transaction",
"::",
"NAME",
")",
";... | Get CreditCard Ui for Transaction
@param Transaction $transaction
@param string $paymentAction
@param string $language
@return string | [
"Get",
"CreditCard",
"Ui",
"for",
"Transaction"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/TransactionService.php#L281-L324 | train |
wirecard/paymentSDK-php | src/TransactionService.php | TransactionService.toSha256 | private function toSha256($fields, $secret)
{
$hasData = '';
foreach ($this->getHashKeys() as $key) {
if (isset($fields[$key])) {
$hasData .= $fields[$key];
}
}
$hasData .= $secret;
return hash('sha256', trim($hasData));
} | php | private function toSha256($fields, $secret)
{
$hasData = '';
foreach ($this->getHashKeys() as $key) {
if (isset($fields[$key])) {
$hasData .= $fields[$key];
}
}
$hasData .= $secret;
return hash('sha256', trim($hasData));
} | [
"private",
"function",
"toSha256",
"(",
"$",
"fields",
",",
"$",
"secret",
")",
"{",
"$",
"hasData",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"getHashKeys",
"(",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"fields",
"... | Get calculated signature
@param array $fields
@param string $secret
@return string
@since 2.3.1 | [
"Get",
"calculated",
"signature"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/TransactionService.php#L334-L345 | train |
wirecard/paymentSDK-php | src/TransactionService.php | TransactionService.cancel | public function cancel(Transaction $transaction)
{
$cancelResult = $this->process($transaction, Operation::CANCEL);
if ($transaction instanceof CreditCardTransaction
&& $cancelResult->getStatusCollection()->hasStatusCodes(['500.1057'])
) {
return $this->process($transaction, Operation::REFUND);
}
return $cancelResult;
} | php | public function cancel(Transaction $transaction)
{
$cancelResult = $this->process($transaction, Operation::CANCEL);
if ($transaction instanceof CreditCardTransaction
&& $cancelResult->getStatusCollection()->hasStatusCodes(['500.1057'])
) {
return $this->process($transaction, Operation::REFUND);
}
return $cancelResult;
} | [
"public",
"function",
"cancel",
"(",
"Transaction",
"$",
"transaction",
")",
"{",
"$",
"cancelResult",
"=",
"$",
"this",
"->",
"process",
"(",
"$",
"transaction",
",",
"Operation",
"::",
"CANCEL",
")",
";",
"if",
"(",
"$",
"transaction",
"instanceof",
"Cre... | If a failureResponse returns from the cancel process call
with a specific status code which declares that the credit card amount has already been settled,
we try a refund process call.
@param Transaction $transaction
@throws MalformedResponseException
@throws UnconfiguredPaymentMethodException
@throws \RuntimeException
@throws \InvalidArgumentException
@throws MandatoryFieldMissingException
@return FailureResponse|InteractionResponse|Response|SuccessResponse | [
"If",
"a",
"failureResponse",
"returns",
"from",
"the",
"cancel",
"process",
"call",
"with",
"a",
"specific",
"status",
"code",
"which",
"declares",
"that",
"the",
"credit",
"card",
"amount",
"has",
"already",
"been",
"settled",
"we",
"try",
"a",
"refund",
"... | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/TransactionService.php#L524-L535 | train |
wirecard/paymentSDK-php | src/TransactionService.php | TransactionService.processFallback | private function processFallback(CreditCardTransaction $transaction, Response $response)
{
if (!$response->getStatusCollection()->hasStatusCodes(['500.1072', '500.1073', '500.1074'])) {
return $response;
}
$transaction->setThreeD(false);
$requestBody = $this->requestMapper->map($transaction);
$endpoint = $this->config->getBaseUrl() . $transaction->getEndpoint();
$responseContent = $this->sendPostRequest($endpoint, $requestBody);
return $this->responseMapper->map($responseContent, $transaction);
} | php | private function processFallback(CreditCardTransaction $transaction, Response $response)
{
if (!$response->getStatusCollection()->hasStatusCodes(['500.1072', '500.1073', '500.1074'])) {
return $response;
}
$transaction->setThreeD(false);
$requestBody = $this->requestMapper->map($transaction);
$endpoint = $this->config->getBaseUrl() . $transaction->getEndpoint();
$responseContent = $this->sendPostRequest($endpoint, $requestBody);
return $this->responseMapper->map($responseContent, $transaction);
} | [
"private",
"function",
"processFallback",
"(",
"CreditCardTransaction",
"$",
"transaction",
",",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"!",
"$",
"response",
"->",
"getStatusCollection",
"(",
")",
"->",
"hasStatusCodes",
"(",
"[",
"'500.1072'",
",",
... | If specific status codes which indicate an error during the credit card enrollment check are found in response,
we do a fallback from a 3-D to an SSL credit card transaction
@param CreditCardTransaction $transaction
@param Response $response
@throws UnconfiguredPaymentMethodException
@throws MandatoryFieldMissingException
@throws \RuntimeException
@throws MalformedResponseException
@throws \InvalidArgumentException
@return Response | [
"If",
"specific",
"status",
"codes",
"which",
"indicate",
"an",
"error",
"during",
"the",
"credit",
"card",
"enrollment",
"check",
"are",
"found",
"in",
"response",
"we",
"do",
"a",
"fallback",
"from",
"a",
"3",
"-",
"D",
"to",
"an",
"SSL",
"credit",
"ca... | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/TransactionService.php#L691-L703 | train |
wirecard/paymentSDK-php | src/TransactionService.php | TransactionService.checkCredentials | public function checkCredentials()
{
try {
$requestHeader = array_merge_recursive($this->httpHeader, $this->config->getShopHeader());
$request = $this->messageFactory->createRequest(
'GET',
$this->config->getBaseUrl() . '/engine/rest/merchants/',
$requestHeader
);
$request = $this->basicAuth->authenticate($request);
$responseCode = $this->httpClient->sendRequest($request)->getStatusCode();
} catch (TransferException $e) {
$this->getLogger()->debug('Check credentials: Error - ' . $e->getMessage());
return false;
}
if ($responseCode === 404) {
$this->getLogger()->debug('Check credentials: Valid');
return true;
}
$this->getLogger()->debug('Check credentials: Invalid - Received status code: ' . $responseCode);
return false;
} | php | public function checkCredentials()
{
try {
$requestHeader = array_merge_recursive($this->httpHeader, $this->config->getShopHeader());
$request = $this->messageFactory->createRequest(
'GET',
$this->config->getBaseUrl() . '/engine/rest/merchants/',
$requestHeader
);
$request = $this->basicAuth->authenticate($request);
$responseCode = $this->httpClient->sendRequest($request)->getStatusCode();
} catch (TransferException $e) {
$this->getLogger()->debug('Check credentials: Error - ' . $e->getMessage());
return false;
}
if ($responseCode === 404) {
$this->getLogger()->debug('Check credentials: Valid');
return true;
}
$this->getLogger()->debug('Check credentials: Invalid - Received status code: ' . $responseCode);
return false;
} | [
"public",
"function",
"checkCredentials",
"(",
")",
"{",
"try",
"{",
"$",
"requestHeader",
"=",
"array_merge_recursive",
"(",
"$",
"this",
"->",
"httpHeader",
",",
"$",
"this",
"->",
"config",
"->",
"getShopHeader",
"(",
")",
")",
";",
"$",
"request",
"=",... | We expect status code 404 for a successful authentication, otherwise the endpoint will return 401 unauthorized
@return boolean
@throws \Http\Client\Exception | [
"We",
"expect",
"status",
"code",
"404",
"for",
"a",
"successful",
"authentication",
"otherwise",
"the",
"endpoint",
"will",
"return",
"401",
"unauthorized"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/TransactionService.php#L710-L734 | train |
wirecard/paymentSDK-php | src/TransactionService.php | TransactionService.getGroupOfTransactions | public function getGroupOfTransactions($transactionId, $paymentMethod)
{
$transaction = $this->getTransactionByTransactionId($transactionId, $paymentMethod);
if (isset($transaction['payment'])) {
$transaction = $transaction['payment'];
}
if (isset($transaction['parent-transaction-id'])) {
return $this->getGroupOfTransactions($transaction['parent-transaction-id'], $paymentMethod);
} else {
$endpoint =
$this->config->getBaseUrl() .
'/engine/rest/merchants/' .
$transaction['merchant-account-id']['value'] .
'/payments/?group_transaction_id=' . $transactionId;
$xml = (array)simplexml_load_string($this->sendGetRequest($endpoint));
$ret = [];
if (isset($xml['payment'])) {
foreach ($xml['payment'] as $response) {
$ret[] = $response;
}
usort($ret, function ($item1, $item2) {
$date1 = new \DateTime($item1->{'completion-time-stamp'});
$date2 = new \DateTime($item2->{'completion-time-stamp'});
return $date1 == $date2 ? 0 : ($date1 < $date2 ? -1 : 1);
});
}
return $ret;
}
} | php | public function getGroupOfTransactions($transactionId, $paymentMethod)
{
$transaction = $this->getTransactionByTransactionId($transactionId, $paymentMethod);
if (isset($transaction['payment'])) {
$transaction = $transaction['payment'];
}
if (isset($transaction['parent-transaction-id'])) {
return $this->getGroupOfTransactions($transaction['parent-transaction-id'], $paymentMethod);
} else {
$endpoint =
$this->config->getBaseUrl() .
'/engine/rest/merchants/' .
$transaction['merchant-account-id']['value'] .
'/payments/?group_transaction_id=' . $transactionId;
$xml = (array)simplexml_load_string($this->sendGetRequest($endpoint));
$ret = [];
if (isset($xml['payment'])) {
foreach ($xml['payment'] as $response) {
$ret[] = $response;
}
usort($ret, function ($item1, $item2) {
$date1 = new \DateTime($item1->{'completion-time-stamp'});
$date2 = new \DateTime($item2->{'completion-time-stamp'});
return $date1 == $date2 ? 0 : ($date1 < $date2 ? -1 : 1);
});
}
return $ret;
}
} | [
"public",
"function",
"getGroupOfTransactions",
"(",
"$",
"transactionId",
",",
"$",
"paymentMethod",
")",
"{",
"$",
"transaction",
"=",
"$",
"this",
"->",
"getTransactionByTransactionId",
"(",
"$",
"transactionId",
",",
"$",
"paymentMethod",
")",
";",
"if",
"("... | Recursively search for a parent transaction until it finds no parent-transaction-id anymore. Aggregate all of the
results received in the group transaction and return them in ascending order by date.
@since 3.1.0
@param $transactionId
@param $paymentMethod
@return array | [
"Recursively",
"search",
"for",
"a",
"parent",
"transaction",
"until",
"it",
"finds",
"no",
"parent",
"-",
"transaction",
"-",
"id",
"anymore",
".",
"Aggregate",
"all",
"of",
"the",
"results",
"received",
"in",
"the",
"group",
"transaction",
"and",
"return",
... | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/TransactionService.php#L851-L881 | train |
wirecard/paymentSDK-php | src/Entity/Device.php | Device.parseUserAgent | protected function parseUserAgent($userAgentString)
{
$parser = new WhichBrowser\Parser($userAgentString);
if (!$parser->isDetected()) {
return;
}
if ($parser->isType('mobile')) {
$this->setType('mobile');
} elseif ($parser->isType('tablet')) {
$this->setType('tablet');
} elseif ($parser->isType('desktop')) {
$this->setType('pc');
} else {
$this->setType('other');
}
if ($parser->isOs('Android')) {
$this->setOperatingSystem('android');
} elseif ($parser->isOs('iOS')) {
$this->setOperatingSystem('ios');
} elseif ($parser->isOs('Windows')) {
$this->setOperatingSystem('windows');
} elseif ($parser->isOs('Windows Phone')) {
$this->setOperatingSystem('windows-mobile');
} else {
$this->setOperatingSystem('other');
}
} | php | protected function parseUserAgent($userAgentString)
{
$parser = new WhichBrowser\Parser($userAgentString);
if (!$parser->isDetected()) {
return;
}
if ($parser->isType('mobile')) {
$this->setType('mobile');
} elseif ($parser->isType('tablet')) {
$this->setType('tablet');
} elseif ($parser->isType('desktop')) {
$this->setType('pc');
} else {
$this->setType('other');
}
if ($parser->isOs('Android')) {
$this->setOperatingSystem('android');
} elseif ($parser->isOs('iOS')) {
$this->setOperatingSystem('ios');
} elseif ($parser->isOs('Windows')) {
$this->setOperatingSystem('windows');
} elseif ($parser->isOs('Windows Phone')) {
$this->setOperatingSystem('windows-mobile');
} else {
$this->setOperatingSystem('other');
}
} | [
"protected",
"function",
"parseUserAgent",
"(",
"$",
"userAgentString",
")",
"{",
"$",
"parser",
"=",
"new",
"WhichBrowser",
"\\",
"Parser",
"(",
"$",
"userAgentString",
")",
";",
"if",
"(",
"!",
"$",
"parser",
"->",
"isDetected",
"(",
")",
")",
"{",
"re... | parse and map device type and os from user agent string
@param $userAgentString | [
"parse",
"and",
"map",
"device",
"type",
"and",
"os",
"from",
"user",
"agent",
"string"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Entity/Device.php#L124-L153 | train |
wirecard/paymentSDK-php | src/Response/Response.php | Response.generateStatusCollection | private function generateStatusCollection()
{
$collection = new StatusCollection();
/**
* @var $statuses \SimpleXMLElement
*/
if (!isset($this->simpleXml->{'statuses'})) {
throw new MalformedResponseException('Missing statuses in response.');
}
$statuses = $this->simpleXml->{'statuses'};
if (count($statuses->{'status'}) > 0) {
foreach ($statuses->{'status'} as $statusNode) {
/**
* @var $statusNode \SimpleXMLElement
*/
$attributes = $statusNode->attributes();
if ((string)$attributes['code'] !== '') {
$code = (string)$attributes['code'];
} else {
throw new MalformedResponseException('Missing status code in response.');
}
if ((string)$attributes['description'] !== '') {
$description = (string)$attributes['description'];
} else {
throw new MalformedResponseException('Missing status description in response.');
}
if ((string)$attributes['severity'] !== '') {
$severity = (string)$attributes['severity'];
} else {
throw new MalformedResponseException('Missing status severity in response.');
}
$status = new Status($code, $description, $severity);
$collection->add($status);
}
}
return $collection;
} | php | private function generateStatusCollection()
{
$collection = new StatusCollection();
/**
* @var $statuses \SimpleXMLElement
*/
if (!isset($this->simpleXml->{'statuses'})) {
throw new MalformedResponseException('Missing statuses in response.');
}
$statuses = $this->simpleXml->{'statuses'};
if (count($statuses->{'status'}) > 0) {
foreach ($statuses->{'status'} as $statusNode) {
/**
* @var $statusNode \SimpleXMLElement
*/
$attributes = $statusNode->attributes();
if ((string)$attributes['code'] !== '') {
$code = (string)$attributes['code'];
} else {
throw new MalformedResponseException('Missing status code in response.');
}
if ((string)$attributes['description'] !== '') {
$description = (string)$attributes['description'];
} else {
throw new MalformedResponseException('Missing status description in response.');
}
if ((string)$attributes['severity'] !== '') {
$severity = (string)$attributes['severity'];
} else {
throw new MalformedResponseException('Missing status severity in response.');
}
$status = new Status($code, $description, $severity);
$collection->add($status);
}
}
return $collection;
} | [
"private",
"function",
"generateStatusCollection",
"(",
")",
"{",
"$",
"collection",
"=",
"new",
"StatusCollection",
"(",
")",
";",
"/**\n * @var $statuses \\SimpleXMLElement\n */",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"simpleXml",
"->",
... | get the collection of status returned by Wirecard's Payment Processing Gateway
@return StatusCollection
@throws MalformedResponseException | [
"get",
"the",
"collection",
"of",
"status",
"returned",
"by",
"Wirecard",
"s",
"Payment",
"Processing",
"Gateway"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Response/Response.php#L204-L243 | train |
wirecard/paymentSDK-php | src/Response/Response.php | Response.arrayFlatten | private static function arrayFlatten($array, $prefix = '')
{
$result = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$result = $result + self::arrayFlatten($value, $prefix . $key . '.');
} else {
$result[$prefix . $key] = trim(preg_replace('/\s+/', ' ', $value));
}
}
return $result;
} | php | private static function arrayFlatten($array, $prefix = '')
{
$result = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$result = $result + self::arrayFlatten($value, $prefix . $key . '.');
} else {
$result[$prefix . $key] = trim(preg_replace('/\s+/', ' ', $value));
}
}
return $result;
} | [
"private",
"static",
"function",
"arrayFlatten",
"(",
"$",
"array",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_... | convert a multidimensional array into a simple one-dimensional array
@param array $array
@return array | [
"convert",
"a",
"multidimensional",
"array",
"into",
"a",
"simple",
"one",
"-",
"dimensional",
"array"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Response/Response.php#L280-L291 | train |
wirecard/paymentSDK-php | src/Response/Response.php | Response.setRequestedAmount | private function setRequestedAmount()
{
if ($this->simpleXml->{'requested-amount'}->count() < 1) {
return;
}
$this->requestedAmount = new Amount(
(float)$this->simpleXml->{'requested-amount'},
(string)$this->simpleXml->{'requested-amount'}->attributes()->currency
);
} | php | private function setRequestedAmount()
{
if ($this->simpleXml->{'requested-amount'}->count() < 1) {
return;
}
$this->requestedAmount = new Amount(
(float)$this->simpleXml->{'requested-amount'},
(string)$this->simpleXml->{'requested-amount'}->attributes()->currency
);
} | [
"private",
"function",
"setRequestedAmount",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"simpleXml",
"->",
"{",
"'requested-amount'",
"}",
"->",
"count",
"(",
")",
"<",
"1",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"requestedAmount",
"=",
"ne... | Parse simplexml and create requestedAmount object
@since 3.0.0 | [
"Parse",
"simplexml",
"and",
"create",
"requestedAmount",
"object"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Response/Response.php#L356-L366 | train |
wirecard/paymentSDK-php | src/Response/Response.php | Response.setCustomFields | private function setCustomFields()
{
$customFieldCollection = new CustomFieldCollection();
if (isset($this->simpleXml->{'custom-fields'})) {
/** @var SimpleXMLElement $field */
foreach ($this->simpleXml->{'custom-fields'}->children() as $field) {
$customField = $this->convertToCustomField($field);
if (!is_null($customField)) {
$customFieldCollection->add($customField);
}
}
}
$this->customFields = $customFieldCollection;
} | php | private function setCustomFields()
{
$customFieldCollection = new CustomFieldCollection();
if (isset($this->simpleXml->{'custom-fields'})) {
/** @var SimpleXMLElement $field */
foreach ($this->simpleXml->{'custom-fields'}->children() as $field) {
$customField = $this->convertToCustomField($field);
if (!is_null($customField)) {
$customFieldCollection->add($customField);
}
}
}
$this->customFields = $customFieldCollection;
} | [
"private",
"function",
"setCustomFields",
"(",
")",
"{",
"$",
"customFieldCollection",
"=",
"new",
"CustomFieldCollection",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"simpleXml",
"->",
"{",
"'custom-fields'",
"}",
")",
")",
"{",
"/** @var Si... | parse simplexml to load all custom fields
@since 3.0.0 | [
"parse",
"simplexml",
"to",
"load",
"all",
"custom",
"fields"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Response/Response.php#L398-L412 | train |
wirecard/paymentSDK-php | src/Response/Response.php | Response.convertToCustomField | private function convertToCustomField($field)
{
if (!empty($field->attributes())) {
if (isset($field->attributes()->{'field-name'}) && isset($field->attributes()->{'field-value'})) {
$rawName = (string)$field->attributes()->{'field-name'};
list($normalizedName, $prefix) = $this->splitFieldNameAndPrefix($rawName);
$value = (string)$field->attributes()->{'field-value'};
if (!empty($normalizedName)) {
return new CustomField($normalizedName, $value, $prefix);
}
}
}
return null;
} | php | private function convertToCustomField($field)
{
if (!empty($field->attributes())) {
if (isset($field->attributes()->{'field-name'}) && isset($field->attributes()->{'field-value'})) {
$rawName = (string)$field->attributes()->{'field-name'};
list($normalizedName, $prefix) = $this->splitFieldNameAndPrefix($rawName);
$value = (string)$field->attributes()->{'field-value'};
if (!empty($normalizedName)) {
return new CustomField($normalizedName, $value, $prefix);
}
}
}
return null;
} | [
"private",
"function",
"convertToCustomField",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"field",
"->",
"attributes",
"(",
")",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"->",
"attributes",
"(",
")",
"->",
"{",
"'f... | Convert the xml field into a CustomField object
Return null if field name is empty or xml object does not provides field name/field value as attribute
@param SimpleXMLElement $field
@return null|CustomField | [
"Convert",
"the",
"xml",
"field",
"into",
"a",
"CustomField",
"object"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Response/Response.php#L422-L435 | train |
wirecard/paymentSDK-php | src/Response/Response.php | Response.splitFieldNameAndPrefix | private function splitFieldNameAndPrefix($rawName)
{
$normalizedName = '';
$prefix = '';
if (!empty($rawName)) {
if (strpos($rawName, CustomField::DEFAULT_PREFIX) === 0) {
$normalizedName = substr($rawName, strlen(CustomField::DEFAULT_PREFIX));
$prefix = CustomField::DEFAULT_PREFIX;
} else {
$normalizedName = $rawName;
}
}
return [$normalizedName, $prefix];
} | php | private function splitFieldNameAndPrefix($rawName)
{
$normalizedName = '';
$prefix = '';
if (!empty($rawName)) {
if (strpos($rawName, CustomField::DEFAULT_PREFIX) === 0) {
$normalizedName = substr($rawName, strlen(CustomField::DEFAULT_PREFIX));
$prefix = CustomField::DEFAULT_PREFIX;
} else {
$normalizedName = $rawName;
}
}
return [$normalizedName, $prefix];
} | [
"private",
"function",
"splitFieldNameAndPrefix",
"(",
"$",
"rawName",
")",
"{",
"$",
"normalizedName",
"=",
"''",
";",
"$",
"prefix",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"rawName",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"rawNam... | Auto detect the PHPSDK prefix for customfields
@param string $rawName
@return array | [
"Auto",
"detect",
"the",
"PHPSDK",
"prefix",
"for",
"customfields"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Response/Response.php#L443-L458 | train |
wirecard/paymentSDK-php | src/Mapper/ResponseMapper.php | ResponseMapper.map | public function map($response, Transaction $transaction = null)
{
$this->transaction = $transaction;
// If the response is encoded, we need to first decode it.
$decodedResponse = base64_decode($response);
$this->xmlResponse = (base64_encode($decodedResponse) === $response) ? $decodedResponse : $response;
//we need to use internal_errors, because we don't want to throw errors on invalid xml responses
$oldErrorHandling = libxml_use_internal_errors(true);
$this->simpleXml = simplexml_load_string($this->xmlResponse);
//reset to old value after string is loaded
libxml_use_internal_errors($oldErrorHandling);
if (!$this->simpleXml instanceof \SimpleXMLElement) {
throw new MalformedResponseException('Response is not a valid xml string.');
}
if (isset($this->simpleXml->{'transaction-state'})) {
$state = (string)$this->simpleXml->{'transaction-state'};
} else {
throw new MalformedResponseException('Missing transaction-state in response.');
}
switch ($state) {
case 'success':
return $this->mapSuccessResponse();
case 'in-progress':
return new PendingResponse($this->simpleXml);
default:
return new FailureResponse($this->simpleXml);
}
} | php | public function map($response, Transaction $transaction = null)
{
$this->transaction = $transaction;
// If the response is encoded, we need to first decode it.
$decodedResponse = base64_decode($response);
$this->xmlResponse = (base64_encode($decodedResponse) === $response) ? $decodedResponse : $response;
//we need to use internal_errors, because we don't want to throw errors on invalid xml responses
$oldErrorHandling = libxml_use_internal_errors(true);
$this->simpleXml = simplexml_load_string($this->xmlResponse);
//reset to old value after string is loaded
libxml_use_internal_errors($oldErrorHandling);
if (!$this->simpleXml instanceof \SimpleXMLElement) {
throw new MalformedResponseException('Response is not a valid xml string.');
}
if (isset($this->simpleXml->{'transaction-state'})) {
$state = (string)$this->simpleXml->{'transaction-state'};
} else {
throw new MalformedResponseException('Missing transaction-state in response.');
}
switch ($state) {
case 'success':
return $this->mapSuccessResponse();
case 'in-progress':
return new PendingResponse($this->simpleXml);
default:
return new FailureResponse($this->simpleXml);
}
} | [
"public",
"function",
"map",
"(",
"$",
"response",
",",
"Transaction",
"$",
"transaction",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"transaction",
"=",
"$",
"transaction",
";",
"// If the response is encoded, we need to first decode it.",
"$",
"decodedResponse",
"=... | map the xml Response from Wirecard's Payment Processing Gateway to ResponseObjects
@param string $response
@param Transaction $transaction
@throws \InvalidArgumentException
@throws MalformedResponseException
@return Response | [
"map",
"the",
"xml",
"Response",
"from",
"Wirecard",
"s",
"Payment",
"Processing",
"Gateway",
"to",
"ResponseObjects"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Mapper/ResponseMapper.php#L108-L139 | train |
wirecard/paymentSDK-php | src/Transaction/CustomFieldTransaction.php | CustomFieldTransaction.setRawCustomField | public function setRawCustomField($customFieldKey, $customFieldValue = null)
{
$customFields = $this->getCustomFields();
if (empty($customFields)) {
$customFields = new CustomFieldCollection();
}
$it = $customFields->getIterator();
foreach ($it as $index => $existingField) {
if ($existingField->getName() === $customFieldKey) {
$it->offsetUnset($index);
}
}
$customFields->add(new CustomField($customFieldKey, $customFieldValue, self::RAW_PREFIX));
$this->setCustomFields($customFields);
} | php | public function setRawCustomField($customFieldKey, $customFieldValue = null)
{
$customFields = $this->getCustomFields();
if (empty($customFields)) {
$customFields = new CustomFieldCollection();
}
$it = $customFields->getIterator();
foreach ($it as $index => $existingField) {
if ($existingField->getName() === $customFieldKey) {
$it->offsetUnset($index);
}
}
$customFields->add(new CustomField($customFieldKey, $customFieldValue, self::RAW_PREFIX));
$this->setCustomFields($customFields);
} | [
"public",
"function",
"setRawCustomField",
"(",
"$",
"customFieldKey",
",",
"$",
"customFieldValue",
"=",
"null",
")",
"{",
"$",
"customFields",
"=",
"$",
"this",
"->",
"getCustomFields",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"customFields",
")",
")... | Add a custom field without default prefix to the customfields
If a custom field with $customFieldKey exists, it will be overridden.
@param string $customFieldKey
@param string|null $customFieldValue | [
"Add",
"a",
"custom",
"field",
"without",
"default",
"prefix",
"to",
"the",
"customfields"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Transaction/CustomFieldTransaction.php#L52-L68 | train |
wirecard/paymentSDK-php | src/Entity/AccountHolder.php | AccountHolder.getAllSetData | private function getAllSetData()
{
$data = $this->mappedProperties();
if (isset($data['address'])) {
$address = $data['address'];
unset(
$data['address']
);
$data = array_merge($data, $address);
}
return $data;
} | php | private function getAllSetData()
{
$data = $this->mappedProperties();
if (isset($data['address'])) {
$address = $data['address'];
unset(
$data['address']
);
$data = array_merge($data, $address);
}
return $data;
} | [
"private",
"function",
"getAllSetData",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"mappedProperties",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'address'",
"]",
")",
")",
"{",
"$",
"address",
"=",
"$",
"data",
"[",
"'addr... | Get all set data
@return array
@since 3.2.0 | [
"Get",
"all",
"set",
"data"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/Entity/AccountHolder.php#L349-L362 | train |
wirecard/paymentSDK-php | src/BackendService.php | BackendService.process | public function process(Transaction $transaction, $operation)
{
$response = parent::process($transaction, $operation);
if ($response instanceof FailureResponse && $operation == Operation::CANCEL
&& $transaction->getBackendOperationForRefund()) {
return parent::process($transaction, Operation::REFUND);
} else {
return $response;
}
} | php | public function process(Transaction $transaction, $operation)
{
$response = parent::process($transaction, $operation);
if ($response instanceof FailureResponse && $operation == Operation::CANCEL
&& $transaction->getBackendOperationForRefund()) {
return parent::process($transaction, Operation::REFUND);
} else {
return $response;
}
} | [
"public",
"function",
"process",
"(",
"Transaction",
"$",
"transaction",
",",
"$",
"operation",
")",
"{",
"$",
"response",
"=",
"parent",
"::",
"process",
"(",
"$",
"transaction",
",",
"$",
"operation",
")",
";",
"if",
"(",
"$",
"response",
"instanceof",
... | Build in fallback for refund
@param Transaction $transaction
@param string $operation
@return FailureResponse|Response\InteractionResponse|Response\Response|Response\SuccessResponse | [
"Build",
"in",
"fallback",
"for",
"refund"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/BackendService.php#L121-L131 | train |
wirecard/paymentSDK-php | src/BackendService.php | BackendService.getOrderState | public function getOrderState($transaction_type)
{
switch ($transaction_type) {
case Transaction::TYPE_PENDING_CREDIT:
case Transaction::TYPE_PENDING_DEBIT:
$state = self::TYPE_PENDING;
break;
case Transaction::TYPE_CAPTURE_AUTHORIZATION:
case Transaction::TYPE_DEBIT:
case Transaction::TYPE_PURCHASE:
case Transaction::TYPE_DEPOSIT:
$state = self::TYPE_PROCESSING;
break;
case Transaction::TYPE_VOID_AUTHORIZATION:
$state = self::TYPE_CANCELLED;
break;
case Transaction::TYPE_REFUND_CAPTURE:
case Transaction::TYPE_REFUND_DEBIT:
case Transaction::TYPE_REFUND_PURCHASE:
case Transaction::TYPE_CREDIT:
case Transaction::TYPE_VOID_CAPTURE:
case Transaction::TYPE_VOID_PURCHASE:
$state = self::TYPE_REFUNDED;
break;
case Transaction::TYPE_AUTHORIZATION:
default:
$state = self::TYPE_AUTHORIZED;
break;
}
return $state;
} | php | public function getOrderState($transaction_type)
{
switch ($transaction_type) {
case Transaction::TYPE_PENDING_CREDIT:
case Transaction::TYPE_PENDING_DEBIT:
$state = self::TYPE_PENDING;
break;
case Transaction::TYPE_CAPTURE_AUTHORIZATION:
case Transaction::TYPE_DEBIT:
case Transaction::TYPE_PURCHASE:
case Transaction::TYPE_DEPOSIT:
$state = self::TYPE_PROCESSING;
break;
case Transaction::TYPE_VOID_AUTHORIZATION:
$state = self::TYPE_CANCELLED;
break;
case Transaction::TYPE_REFUND_CAPTURE:
case Transaction::TYPE_REFUND_DEBIT:
case Transaction::TYPE_REFUND_PURCHASE:
case Transaction::TYPE_CREDIT:
case Transaction::TYPE_VOID_CAPTURE:
case Transaction::TYPE_VOID_PURCHASE:
$state = self::TYPE_REFUNDED;
break;
case Transaction::TYPE_AUTHORIZATION:
default:
$state = self::TYPE_AUTHORIZED;
break;
}
return $state;
} | [
"public",
"function",
"getOrderState",
"(",
"$",
"transaction_type",
")",
"{",
"switch",
"(",
"$",
"transaction_type",
")",
"{",
"case",
"Transaction",
"::",
"TYPE_PENDING_CREDIT",
":",
"case",
"Transaction",
"::",
"TYPE_PENDING_DEBIT",
":",
"$",
"state",
"=",
"... | Return order state of the transaction
@param $transaction_type
@return string | [
"Return",
"order",
"state",
"of",
"the",
"transaction"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/BackendService.php#L139-L170 | train |
wirecard/paymentSDK-php | src/BackendService.php | BackendService.isFinal | public function isFinal($transaction_type)
{
if (in_array($transaction_type, [
Transaction::TYPE_CAPTURE_AUTHORIZATION,
Transaction::TYPE_DEBIT,
Transaction::TYPE_PURCHASE,
Transaction::TYPE_AUTHORIZATION,
Transaction::TYPE_PENDING_CREDIT,
Transaction::TYPE_PENDING_DEBIT,
Transaction::TYPE_AUTHORIZATION_ONLY,
Transaction::TYPE_CHECK_ENROLLMENT,
Transaction::TYPE_REFERENCED_AUTHORIZATION
])) {
return false;
}
return true;
} | php | public function isFinal($transaction_type)
{
if (in_array($transaction_type, [
Transaction::TYPE_CAPTURE_AUTHORIZATION,
Transaction::TYPE_DEBIT,
Transaction::TYPE_PURCHASE,
Transaction::TYPE_AUTHORIZATION,
Transaction::TYPE_PENDING_CREDIT,
Transaction::TYPE_PENDING_DEBIT,
Transaction::TYPE_AUTHORIZATION_ONLY,
Transaction::TYPE_CHECK_ENROLLMENT,
Transaction::TYPE_REFERENCED_AUTHORIZATION
])) {
return false;
}
return true;
} | [
"public",
"function",
"isFinal",
"(",
"$",
"transaction_type",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"transaction_type",
",",
"[",
"Transaction",
"::",
"TYPE_CAPTURE_AUTHORIZATION",
",",
"Transaction",
"::",
"TYPE_DEBIT",
",",
"Transaction",
"::",
"TYPE_PURCH... | Check if the transaction is final
@param $transaction_type
@return bool | [
"Check",
"if",
"the",
"transaction",
"is",
"final"
] | ec21aae9db51e84bb78c04c0192f1138d6fa57e2 | https://github.com/wirecard/paymentSDK-php/blob/ec21aae9db51e84bb78c04c0192f1138d6fa57e2/src/BackendService.php#L178-L195 | train |
GrahamCampbell/Laravel-Exceptions | src/Displayers/ViewDisplayer.php | ViewDisplayer.render | protected function render(Exception $exception, array $info, int $code)
{
$view = $this->factory->make("errors.{$code}", $info);
return $view->with('exception', $exception)->render();
} | php | protected function render(Exception $exception, array $info, int $code)
{
$view = $this->factory->make("errors.{$code}", $info);
return $view->with('exception', $exception)->render();
} | [
"protected",
"function",
"render",
"(",
"Exception",
"$",
"exception",
",",
"array",
"$",
"info",
",",
"int",
"$",
"code",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"factory",
"->",
"make",
"(",
"\"errors.{$code}\"",
",",
"$",
"info",
")",
";",
... | Render the page with given info and exception.
@param \Exception $exception
@param array $info
@param int $code
@return string | [
"Render",
"the",
"page",
"with",
"given",
"info",
"and",
"exception",
"."
] | 75cf28f6358ea43cbc257694879849f34b8b408a | https://github.com/GrahamCampbell/Laravel-Exceptions/blob/75cf28f6358ea43cbc257694879849f34b8b408a/src/Displayers/ViewDisplayer.php#L82-L87 | train |
GrahamCampbell/Laravel-Exceptions | src/ExceptionHandler.php | ExceptionHandler.getConfigItem | protected function getConfigItem(string $key)
{
if ($this->config === null) {
$this->config = $this->container->config->get('exceptions', []);
}
return array_get($this->config, $key);
} | php | protected function getConfigItem(string $key)
{
if ($this->config === null) {
$this->config = $this->container->config->get('exceptions', []);
}
return array_get($this->config, $key);
} | [
"protected",
"function",
"getConfigItem",
"(",
"string",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"$",
"this",
"->",
"container",
"->",
"config",
"->",
"get",
"(",
"'exce... | Get an item from the config.
@param string $key
@return mixed | [
"Get",
"an",
"item",
"from",
"the",
"config",
"."
] | 75cf28f6358ea43cbc257694879849f34b8b408a | https://github.com/GrahamCampbell/Laravel-Exceptions/blob/75cf28f6358ea43cbc257694879849f34b8b408a/src/ExceptionHandler.php#L144-L151 | train |
GrahamCampbell/Laravel-Exceptions | src/ExceptionHandler.php | ExceptionHandler.getResponse | protected function getResponse(Request $request, Exception $exception, Exception $transformed)
{
$id = $this->container->make(ExceptionIdentifier::class)->identify($exception);
$flattened = FlattenException::create($transformed);
$code = $flattened->getStatusCode();
$headers = $flattened->getHeaders();
return $this->getDisplayer($request, $exception, $transformed, $code)->display($transformed, $id, $code, $headers);
} | php | protected function getResponse(Request $request, Exception $exception, Exception $transformed)
{
$id = $this->container->make(ExceptionIdentifier::class)->identify($exception);
$flattened = FlattenException::create($transformed);
$code = $flattened->getStatusCode();
$headers = $flattened->getHeaders();
return $this->getDisplayer($request, $exception, $transformed, $code)->display($transformed, $id, $code, $headers);
} | [
"protected",
"function",
"getResponse",
"(",
"Request",
"$",
"request",
",",
"Exception",
"$",
"exception",
",",
"Exception",
"$",
"transformed",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"ExceptionIdentifier",
"::",
"class... | Get the approprate response object.
@param \Illuminate\Http\Request $request
@param \Exception $transformed
@param \Exception $exception
@return \Illuminate\Http\Response | [
"Get",
"the",
"approprate",
"response",
"object",
"."
] | 75cf28f6358ea43cbc257694879849f34b8b408a | https://github.com/GrahamCampbell/Laravel-Exceptions/blob/75cf28f6358ea43cbc257694879849f34b8b408a/src/ExceptionHandler.php#L232-L241 | train |
GrahamCampbell/Laravel-Exceptions | src/ExceptionHandler.php | ExceptionHandler.getFiltered | protected function getFiltered(array $displayers, Request $request, Exception $original, Exception $transformed, $code)
{
foreach ($this->make((array) $this->getConfigItem('filters')) as $filter) {
$displayers = $filter->filter($displayers, $request, $original, $transformed, $code);
}
return array_values($displayers);
} | php | protected function getFiltered(array $displayers, Request $request, Exception $original, Exception $transformed, $code)
{
foreach ($this->make((array) $this->getConfigItem('filters')) as $filter) {
$displayers = $filter->filter($displayers, $request, $original, $transformed, $code);
}
return array_values($displayers);
} | [
"protected",
"function",
"getFiltered",
"(",
"array",
"$",
"displayers",
",",
"Request",
"$",
"request",
",",
"Exception",
"$",
"original",
",",
"Exception",
"$",
"transformed",
",",
"$",
"code",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"make",
"(",
... | Get the filtered list of displayers.
@param \GrahamCampbell\Exceptions\Displayers\DisplayerInterface[] $displayers
@param \Illuminate\Http\Request $request
@param \Exception $original
@param \Exception $transformed
@param int $code
@return \GrahamCampbell\Exceptions\Displayers\DisplayerInterface[] | [
"Get",
"the",
"filtered",
"list",
"of",
"displayers",
"."
] | 75cf28f6358ea43cbc257694879849f34b8b408a | https://github.com/GrahamCampbell/Laravel-Exceptions/blob/75cf28f6358ea43cbc257694879849f34b8b408a/src/ExceptionHandler.php#L291-L298 | train |
GrahamCampbell/Laravel-Exceptions | src/ExceptionIdentifier.php | ExceptionIdentifier.identify | public function identify(Exception $exception)
{
$hash = spl_object_hash($exception);
// if we know about the exception, return it's id
if (isset($this->identification[$hash])) {
return $this->identification[$hash];
}
// cleanup in preparation for the identification
if (count($this->identification) >= 16) {
array_shift($this->identification);
}
// generate, store, and return the id
return $this->identification[$hash] = $this->generate();
} | php | public function identify(Exception $exception)
{
$hash = spl_object_hash($exception);
// if we know about the exception, return it's id
if (isset($this->identification[$hash])) {
return $this->identification[$hash];
}
// cleanup in preparation for the identification
if (count($this->identification) >= 16) {
array_shift($this->identification);
}
// generate, store, and return the id
return $this->identification[$hash] = $this->generate();
} | [
"public",
"function",
"identify",
"(",
"Exception",
"$",
"exception",
")",
"{",
"$",
"hash",
"=",
"spl_object_hash",
"(",
"$",
"exception",
")",
";",
"// if we know about the exception, return it's id",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"identification",... | Identify the given exception.
@param \Exception $exception
@return string | [
"Identify",
"the",
"given",
"exception",
"."
] | 75cf28f6358ea43cbc257694879849f34b8b408a | https://github.com/GrahamCampbell/Laravel-Exceptions/blob/75cf28f6358ea43cbc257694879849f34b8b408a/src/ExceptionIdentifier.php#L43-L59 | train |
GrahamCampbell/Laravel-Exceptions | src/ExceptionIdentifier.php | ExceptionIdentifier.generate | protected function generate()
{
$hash = bin2hex(random_bytes(16));
$timeHi = hexdec(substr($hash, 12, 4)) & 0x0fff;
$timeHi &= ~(0xf000);
$timeHi |= 4 << 12;
$clockSeqHi = hexdec(substr($hash, 16, 2)) & 0x3f;
$clockSeqHi &= ~(0xc0);
$clockSeqHi |= 0x80;
$params = [substr($hash, 0, 8), substr($hash, 8, 4), sprintf('%04x', $timeHi), sprintf('%02x', $clockSeqHi), substr($hash, 18, 2), substr($hash, 20, 12)];
return vsprintf('%08s-%04s-%04s-%02s%02s-%012s', $params);
} | php | protected function generate()
{
$hash = bin2hex(random_bytes(16));
$timeHi = hexdec(substr($hash, 12, 4)) & 0x0fff;
$timeHi &= ~(0xf000);
$timeHi |= 4 << 12;
$clockSeqHi = hexdec(substr($hash, 16, 2)) & 0x3f;
$clockSeqHi &= ~(0xc0);
$clockSeqHi |= 0x80;
$params = [substr($hash, 0, 8), substr($hash, 8, 4), sprintf('%04x', $timeHi), sprintf('%02x', $clockSeqHi), substr($hash, 18, 2), substr($hash, 20, 12)];
return vsprintf('%08s-%04s-%04s-%02s%02s-%012s', $params);
} | [
"protected",
"function",
"generate",
"(",
")",
"{",
"$",
"hash",
"=",
"bin2hex",
"(",
"random_bytes",
"(",
"16",
")",
")",
";",
"$",
"timeHi",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"hash",
",",
"12",
",",
"4",
")",
")",
"&",
"0x0fff",
";",
"$",... | Generate a new uuid.
We're generating uuids according to the official v4 spec.
@return string | [
"Generate",
"a",
"new",
"uuid",
"."
] | 75cf28f6358ea43cbc257694879849f34b8b408a | https://github.com/GrahamCampbell/Laravel-Exceptions/blob/75cf28f6358ea43cbc257694879849f34b8b408a/src/ExceptionIdentifier.php#L68-L83 | train |
wp-cli/wp-cli-bundle | utils/maintenance/GitHub.php | GitHub.get_project_milestones | public static function get_project_milestones(
$project,
$args = []
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/milestones',
$project
);
$args['per_page'] = 100;
list( $body, $headers ) = self::request( $request_url, $args );
return $body;
} | php | public static function get_project_milestones(
$project,
$args = []
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/milestones',
$project
);
$args['per_page'] = 100;
list( $body, $headers ) = self::request( $request_url, $args );
return $body;
} | [
"public",
"static",
"function",
"get_project_milestones",
"(",
"$",
"project",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"request_url",
"=",
"sprintf",
"(",
"self",
"::",
"API_ROOT",
".",
"'repos/%s/milestones'",
",",
"$",
"project",
")",
";",
"$",
... | Gets the milestones for a given project.
@param string $project
@return array | [
"Gets",
"the",
"milestones",
"for",
"a",
"given",
"project",
"."
] | 30645be4b1f00060bf68d0e8277cf7bf93e84850 | https://github.com/wp-cli/wp-cli-bundle/blob/30645be4b1f00060bf68d0e8277cf7bf93e84850/utils/maintenance/GitHub.php#L17-L31 | train |
wp-cli/wp-cli-bundle | utils/maintenance/GitHub.php | GitHub.get_release_by_tag | public static function get_release_by_tag(
$project,
$tag,
$args = []
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/releases/tags/%s',
$project,
$tag
);
$args['per_page'] = 100;
list( $body, $headers ) = self::request( $request_url, $args );
return $body;
} | php | public static function get_release_by_tag(
$project,
$tag,
$args = []
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/releases/tags/%s',
$project,
$tag
);
$args['per_page'] = 100;
list( $body, $headers ) = self::request( $request_url, $args );
return $body;
} | [
"public",
"static",
"function",
"get_release_by_tag",
"(",
"$",
"project",
",",
"$",
"tag",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"request_url",
"=",
"sprintf",
"(",
"self",
"::",
"API_ROOT",
".",
"'repos/%s/releases/tags/%s'",
",",
"$",
"project... | Gets a release for a given project by its tag name.
@param string $project
@param string $tag
@param array $args
@return array|false | [
"Gets",
"a",
"release",
"for",
"a",
"given",
"project",
"by",
"its",
"tag",
"name",
"."
] | 30645be4b1f00060bf68d0e8277cf7bf93e84850 | https://github.com/wp-cli/wp-cli-bundle/blob/30645be4b1f00060bf68d0e8277cf7bf93e84850/utils/maintenance/GitHub.php#L42-L58 | train |
wp-cli/wp-cli-bundle | utils/maintenance/GitHub.php | GitHub.remove_label | public static function remove_label(
$project,
$issue,
$label,
$args = []
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/issues/%s/labels/%s',
$project,
$issue,
$label
);
$headers['http_verb'] = 'DELETE';
list( $body, $headers ) = self::request( $request_url, $args, $headers );
return $body;
} | php | public static function remove_label(
$project,
$issue,
$label,
$args = []
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/issues/%s/labels/%s',
$project,
$issue,
$label
);
$headers['http_verb'] = 'DELETE';
list( $body, $headers ) = self::request( $request_url, $args, $headers );
return $body;
} | [
"public",
"static",
"function",
"remove_label",
"(",
"$",
"project",
",",
"$",
"issue",
",",
"$",
"label",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"request_url",
"=",
"sprintf",
"(",
"self",
"::",
"API_ROOT",
".",
"'repos/%s/issues/%s/labels/%s'",
... | Removes a label from an issue.
@param string $project
@param string $issue
@param string $label
@param array $args
@return array|false | [
"Removes",
"a",
"label",
"from",
"an",
"issue",
"."
] | 30645be4b1f00060bf68d0e8277cf7bf93e84850 | https://github.com/wp-cli/wp-cli-bundle/blob/30645be4b1f00060bf68d0e8277cf7bf93e84850/utils/maintenance/GitHub.php#L97-L115 | train |
wp-cli/wp-cli-bundle | utils/maintenance/GitHub.php | GitHub.delete_label | public static function delete_label(
$project,
$label,
$args = []
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/labels/%s',
$project,
$label
);
$headers['http_verb'] = 'DELETE';
list( $body, $headers ) = self::request( $request_url, $args, $headers );
return $body;
} | php | public static function delete_label(
$project,
$label,
$args = []
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/labels/%s',
$project,
$label
);
$headers['http_verb'] = 'DELETE';
list( $body, $headers ) = self::request( $request_url, $args, $headers );
return $body;
} | [
"public",
"static",
"function",
"delete_label",
"(",
"$",
"project",
",",
"$",
"label",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"request_url",
"=",
"sprintf",
"(",
"self",
"::",
"API_ROOT",
".",
"'repos/%s/labels/%s'",
",",
"$",
"project",
",",
... | Delete a label from a repository.
@param string $project
@param string $label
@param array $args
@return array|false | [
"Delete",
"a",
"label",
"from",
"a",
"repository",
"."
] | 30645be4b1f00060bf68d0e8277cf7bf93e84850 | https://github.com/wp-cli/wp-cli-bundle/blob/30645be4b1f00060bf68d0e8277cf7bf93e84850/utils/maintenance/GitHub.php#L158-L174 | train |
wp-cli/wp-cli-bundle | utils/maintenance/GitHub.php | GitHub.get_project_milestone_pull_requests | public static function get_project_milestone_pull_requests(
$project,
$milestone_id
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/issues',
$project
);
$args = [
'per_page' => 100,
'milestone' => $milestone_id,
'state' => 'all',
];
$pull_requests = [];
do {
list( $body, $headers ) = self::request( $request_url, $args );
foreach ( $body as $issue ) {
if ( ! empty( $issue->pull_request ) ) {
$pull_requests[] = $issue;
}
}
$args = [];
$request_url = false;
// Set $request_url to 'rel="next" if present'
if ( ! empty( $headers['Link'] ) ) {
$bits = explode( ',', $headers['Link'] );
foreach ( $bits as $bit ) {
if ( false !== stripos( $bit, 'rel="next"' ) ) {
$hrefandrel = explode( '; ', $bit );
$request_url = trim( trim( $hrefandrel[0] ), '<>' );
break;
}
}
}
} while ( $request_url );
return $pull_requests;
} | php | public static function get_project_milestone_pull_requests(
$project,
$milestone_id
) {
$request_url = sprintf(
self::API_ROOT . 'repos/%s/issues',
$project
);
$args = [
'per_page' => 100,
'milestone' => $milestone_id,
'state' => 'all',
];
$pull_requests = [];
do {
list( $body, $headers ) = self::request( $request_url, $args );
foreach ( $body as $issue ) {
if ( ! empty( $issue->pull_request ) ) {
$pull_requests[] = $issue;
}
}
$args = [];
$request_url = false;
// Set $request_url to 'rel="next" if present'
if ( ! empty( $headers['Link'] ) ) {
$bits = explode( ',', $headers['Link'] );
foreach ( $bits as $bit ) {
if ( false !== stripos( $bit, 'rel="next"' ) ) {
$hrefandrel = explode( '; ', $bit );
$request_url = trim( trim( $hrefandrel[0] ), '<>' );
break;
}
}
}
} while ( $request_url );
return $pull_requests;
} | [
"public",
"static",
"function",
"get_project_milestone_pull_requests",
"(",
"$",
"project",
",",
"$",
"milestone_id",
")",
"{",
"$",
"request_url",
"=",
"sprintf",
"(",
"self",
"::",
"API_ROOT",
".",
"'repos/%s/issues'",
",",
"$",
"project",
")",
";",
"$",
"ar... | Gets the pull requests assigned to a milestone of a given project.
@param string $project
@param integer $milestone_id
@return array | [
"Gets",
"the",
"pull",
"requests",
"assigned",
"to",
"a",
"milestone",
"of",
"a",
"given",
"project",
"."
] | 30645be4b1f00060bf68d0e8277cf7bf93e84850 | https://github.com/wp-cli/wp-cli-bundle/blob/30645be4b1f00060bf68d0e8277cf7bf93e84850/utils/maintenance/GitHub.php#L184-L223 | train |
wp-cli/wp-cli-bundle | utils/maintenance/GitHub.php | GitHub.request | public static function request(
$url,
$args = [],
$headers = []
) {
$headers = array_merge(
$headers,
[
'Accept' => 'application/vnd.github.v3+json',
'User-Agent' => 'WP-CLI',
]
);
$token = getenv( 'GITHUB_TOKEN' );
if ( $token ) {
$headers['Authorization'] = 'token ' . $token;
}
$verb = 'GET';
if ( isset( $headers['http_verb'] ) ) {
$verb = $headers['http_verb'];
unset( $headers['http_verb'] );
}
if ( 'POST' === $verb ) {
$args = json_encode( $args );
}
$response = Utils\http_request( $verb, $url, $args, $headers );
if ( 20 !== (int) substr( $response->status_code, 0, 2 ) ) {
if ( isset( $args['throw_errors'] ) && false === $args['throw_errors'] ) {
return false;
}
WP_CLI::error(
sprintf(
"Failed request to $url\nGitHub API returned: %s (HTTP code %d)",
$response->body,
$response->status_code
)
);
}
return [ json_decode( $response->body ), $response->headers ];
} | php | public static function request(
$url,
$args = [],
$headers = []
) {
$headers = array_merge(
$headers,
[
'Accept' => 'application/vnd.github.v3+json',
'User-Agent' => 'WP-CLI',
]
);
$token = getenv( 'GITHUB_TOKEN' );
if ( $token ) {
$headers['Authorization'] = 'token ' . $token;
}
$verb = 'GET';
if ( isset( $headers['http_verb'] ) ) {
$verb = $headers['http_verb'];
unset( $headers['http_verb'] );
}
if ( 'POST' === $verb ) {
$args = json_encode( $args );
}
$response = Utils\http_request( $verb, $url, $args, $headers );
if ( 20 !== (int) substr( $response->status_code, 0, 2 ) ) {
if ( isset( $args['throw_errors'] ) && false === $args['throw_errors'] ) {
return false;
}
WP_CLI::error(
sprintf(
"Failed request to $url\nGitHub API returned: %s (HTTP code %d)",
$response->body,
$response->status_code
)
);
}
return [ json_decode( $response->body ), $response->headers ];
} | [
"public",
"static",
"function",
"request",
"(",
"$",
"url",
",",
"$",
"args",
"=",
"[",
"]",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"$",
"headers",
"=",
"array_merge",
"(",
"$",
"headers",
",",
"[",
"'Accept'",
"=>",
"'application/vnd.github.v3+... | Makes a request to the GitHub API.
@param string $url
@param array $args
@param array $headers
@return array|false | [
"Makes",
"a",
"request",
"to",
"the",
"GitHub",
"API",
"."
] | 30645be4b1f00060bf68d0e8277cf7bf93e84850 | https://github.com/wp-cli/wp-cli-bundle/blob/30645be4b1f00060bf68d0e8277cf7bf93e84850/utils/maintenance/GitHub.php#L254-L299 | train |
jbroadway/analog | lib/Analog/Handler/FirePHP.php | FirePHP.format_header | public static function format_header ($info) {
if (is_array ($info['message'])) {
$extra = array (
'Type' => self::$log_levels[$info['level']],
'File' => $info['message'][1],
'Line' => $info['message'][2]
);
$info['message'] = $info['message'][0];
} else {
$extra = array ('Type' => self::$log_levels[$info['level']]);
}
$json = json_encode (array ($extra, $info['message']));
return sprintf ('X-Wf-1-1-1-%d: %s|%s|', self::$message_index++, strlen ($json), $json);
} | php | public static function format_header ($info) {
if (is_array ($info['message'])) {
$extra = array (
'Type' => self::$log_levels[$info['level']],
'File' => $info['message'][1],
'Line' => $info['message'][2]
);
$info['message'] = $info['message'][0];
} else {
$extra = array ('Type' => self::$log_levels[$info['level']]);
}
$json = json_encode (array ($extra, $info['message']));
return sprintf ('X-Wf-1-1-1-%d: %s|%s|', self::$message_index++, strlen ($json), $json);
} | [
"public",
"static",
"function",
"format_header",
"(",
"$",
"info",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"info",
"[",
"'message'",
"]",
")",
")",
"{",
"$",
"extra",
"=",
"array",
"(",
"'Type'",
"=>",
"self",
"::",
"$",
"log_levels",
"[",
"$",
... | Formats a log header to be sent. | [
"Formats",
"a",
"log",
"header",
"to",
"be",
"sent",
"."
] | 4ac87ac59555db6eaba734b2b022fcc296e8729d | https://github.com/jbroadway/analog/blob/4ac87ac59555db6eaba734b2b022fcc296e8729d/lib/Analog/Handler/FirePHP.php#L42-L57 | train |
jbroadway/analog | lib/Analog/Handler/FirePHP.php | FirePHP.init | public static function init () {
if (! isset ($_SERVER['HTTP_USER_AGENT'])
|| preg_match ('{\bFirePHP/\d+\.\d+\b}', $_SERVER['HTTP_USER_AGENT'])
|| isset ($_SERVER['HTTP_X_FIREPHP_VERSION'])) {
header ('X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
header ('X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3');
header ('X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
}
return function ($info) {
header (FirePHP::format_header ($info));
};
} | php | public static function init () {
if (! isset ($_SERVER['HTTP_USER_AGENT'])
|| preg_match ('{\bFirePHP/\d+\.\d+\b}', $_SERVER['HTTP_USER_AGENT'])
|| isset ($_SERVER['HTTP_X_FIREPHP_VERSION'])) {
header ('X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
header ('X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3');
header ('X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
}
return function ($info) {
header (FirePHP::format_header ($info));
};
} | [
"public",
"static",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
"||",
"preg_match",
"(",
"'{\\bFirePHP/\\d+\\.\\d+\\b}'",
",",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
"||",
... | Sends the initial headers if FirePHP is available then returns a
closure that handles sending log messages. | [
"Sends",
"the",
"initial",
"headers",
"if",
"FirePHP",
"is",
"available",
"then",
"returns",
"a",
"closure",
"that",
"handles",
"sending",
"log",
"messages",
"."
] | 4ac87ac59555db6eaba734b2b022fcc296e8729d | https://github.com/jbroadway/analog/blob/4ac87ac59555db6eaba734b2b022fcc296e8729d/lib/Analog/Handler/FirePHP.php#L63-L76 | train |
jbroadway/analog | lib/Analog/Logger.php | Logger.convert_log_level | public function convert_log_level ($level, $reverse = false) {
if ($reverse) {
switch ($level) {
case Analog::URGENT:
return LogLevel::EMERGENCY;
case Analog::ALERT:
return LogLevel::ALERT;
case Analog::CRITICAL:
return LogLevel::CRITICAL;
case Analog::ERROR:
return LogLevel::ERROR;
case Analog::WARNING:
return LogLevel::WARNING;
case Analog::NOTICE:
return LogLevel::NOTICE;
case Analog::INFO:
return LogLevel::INFO;
case Analog::DEBUG:
return LogLevel::DEBUG;
}
throw new InvalidArgumentException ('Level "' . $level . '" is not defined.');
} else {
switch ($level) {
case LogLevel::EMERGENCY:
return Analog::URGENT;
case LogLevel::ALERT:
return Analog::ALERT;
case LogLevel::CRITICAL:
return Analog::CRITICAL;
case LogLevel::ERROR:
return Analog::ERROR;
case LogLevel::WARNING:
return Analog::WARNING;
case LogLevel::NOTICE:
return Analog::NOTICE;
case LogLevel::INFO:
return Analog::INFO;
case LogLevel::DEBUG:
return Analog::DEBUG;
}
throw new InvalidArgumentException ('Level "' . $level . '" is not defined.');
}
} | php | public function convert_log_level ($level, $reverse = false) {
if ($reverse) {
switch ($level) {
case Analog::URGENT:
return LogLevel::EMERGENCY;
case Analog::ALERT:
return LogLevel::ALERT;
case Analog::CRITICAL:
return LogLevel::CRITICAL;
case Analog::ERROR:
return LogLevel::ERROR;
case Analog::WARNING:
return LogLevel::WARNING;
case Analog::NOTICE:
return LogLevel::NOTICE;
case Analog::INFO:
return LogLevel::INFO;
case Analog::DEBUG:
return LogLevel::DEBUG;
}
throw new InvalidArgumentException ('Level "' . $level . '" is not defined.');
} else {
switch ($level) {
case LogLevel::EMERGENCY:
return Analog::URGENT;
case LogLevel::ALERT:
return Analog::ALERT;
case LogLevel::CRITICAL:
return Analog::CRITICAL;
case LogLevel::ERROR:
return Analog::ERROR;
case LogLevel::WARNING:
return Analog::WARNING;
case LogLevel::NOTICE:
return Analog::NOTICE;
case LogLevel::INFO:
return Analog::INFO;
case LogLevel::DEBUG:
return Analog::DEBUG;
}
throw new InvalidArgumentException ('Level "' . $level . '" is not defined.');
}
} | [
"public",
"function",
"convert_log_level",
"(",
"$",
"level",
",",
"$",
"reverse",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"reverse",
")",
"{",
"switch",
"(",
"$",
"level",
")",
"{",
"case",
"Analog",
"::",
"URGENT",
":",
"return",
"LogLevel",
"::",
... | Converts from PSR-3 log levels to Analog log levels. | [
"Converts",
"from",
"PSR",
"-",
"3",
"log",
"levels",
"to",
"Analog",
"log",
"levels",
"."
] | 4ac87ac59555db6eaba734b2b022fcc296e8729d | https://github.com/jbroadway/analog/blob/4ac87ac59555db6eaba734b2b022fcc296e8729d/lib/Analog/Logger.php#L58-L100 | train |
jbroadway/analog | lib/Analog/Logger.php | Logger._log | private function _log ($level, $message, $context) {
Analog::log (
$this->interpolate ($message, $context),
$level
);
} | php | private function _log ($level, $message, $context) {
Analog::log (
$this->interpolate ($message, $context),
$level
);
} | [
"private",
"function",
"_log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
")",
"{",
"Analog",
"::",
"log",
"(",
"$",
"this",
"->",
"interpolate",
"(",
"$",
"message",
",",
"$",
"context",
")",
",",
"$",
"level",
")",
";",
"}"
] | Perform the logging to Analog after the log level has been converted. | [
"Perform",
"the",
"logging",
"to",
"Analog",
"after",
"the",
"log",
"level",
"has",
"been",
"converted",
"."
] | 4ac87ac59555db6eaba734b2b022fcc296e8729d | https://github.com/jbroadway/analog/blob/4ac87ac59555db6eaba734b2b022fcc296e8729d/lib/Analog/Logger.php#L214-L219 | train |
jbroadway/analog | lib/ChromePhp.php | ChromePhp.addSettings | public function addSettings(array $settings)
{
foreach ($settings as $key => $value) {
$this->addSetting($key, $value);
}
} | php | public function addSettings(array $settings)
{
foreach ($settings as $key => $value) {
$this->addSetting($key, $value);
}
} | [
"public",
"function",
"addSettings",
"(",
"array",
"$",
"settings",
")",
"{",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"addSetting",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] | add ability to set multiple settings in one call
@param array $settings
@return void | [
"add",
"ability",
"to",
"set",
"multiple",
"settings",
"in",
"one",
"call"
] | 4ac87ac59555db6eaba734b2b022fcc296e8729d | https://github.com/jbroadway/analog/blob/4ac87ac59555db6eaba734b2b022fcc296e8729d/lib/ChromePhp.php#L403-L408 | train |
jbroadway/analog | lib/ChromePhp.php | ChromePhp.getSetting | public function getSetting($key)
{
if (!isset($this->_settings[$key])) {
return null;
}
return $this->_settings[$key];
} | php | public function getSetting($key)
{
if (!isset($this->_settings[$key])) {
return null;
}
return $this->_settings[$key];
} | [
"public",
"function",
"getSetting",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_settings",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"_settings",
"[",
"$",
"key... | gets a setting
@param string key
@return mixed | [
"gets",
"a",
"setting"
] | 4ac87ac59555db6eaba734b2b022fcc296e8729d | https://github.com/jbroadway/analog/blob/4ac87ac59555db6eaba734b2b022fcc296e8729d/lib/ChromePhp.php#L416-L422 | train |
jbroadway/analog | lib/Analog/Analog.php | Analog.get_struct | private static function get_struct ($message, $level) {
if (self::$machine === null) {
self::$machine = (isset ($_SERVER['SERVER_ADDR'])) ? $_SERVER['SERVER_ADDR'] : 'localhost';
}
$dt = new \DateTime ('now', new \DateTimeZone (self::$timezone));
return array (
'machine' => self::$machine,
'date' => $dt->format (self::$date_format),
'level' => $level,
'message' => $message
);
} | php | private static function get_struct ($message, $level) {
if (self::$machine === null) {
self::$machine = (isset ($_SERVER['SERVER_ADDR'])) ? $_SERVER['SERVER_ADDR'] : 'localhost';
}
$dt = new \DateTime ('now', new \DateTimeZone (self::$timezone));
return array (
'machine' => self::$machine,
'date' => $dt->format (self::$date_format),
'level' => $level,
'message' => $message
);
} | [
"private",
"static",
"function",
"get_struct",
"(",
"$",
"message",
",",
"$",
"level",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"machine",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"machine",
"=",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SERVER_ADD... | Get the log info as an associative array. | [
"Get",
"the",
"log",
"info",
"as",
"an",
"associative",
"array",
"."
] | 4ac87ac59555db6eaba734b2b022fcc296e8729d | https://github.com/jbroadway/analog/blob/4ac87ac59555db6eaba734b2b022fcc296e8729d/lib/Analog/Analog.php#L154-L167 | train |
jbroadway/analog | lib/Analog/Analog.php | Analog.write | private static function write ($struct) {
$handler = self::handler ();
if (! $handler instanceof \Closure) {
$handler = \Analog\Handler\File::init ($handler);
}
return $handler ($struct);
} | php | private static function write ($struct) {
$handler = self::handler ();
if (! $handler instanceof \Closure) {
$handler = \Analog\Handler\File::init ($handler);
}
return $handler ($struct);
} | [
"private",
"static",
"function",
"write",
"(",
"$",
"struct",
")",
"{",
"$",
"handler",
"=",
"self",
"::",
"handler",
"(",
")",
";",
"if",
"(",
"!",
"$",
"handler",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"handler",
"=",
"\\",
"Analog",
"\\",
... | Write a raw message to the log using a function or the default
file logging. | [
"Write",
"a",
"raw",
"message",
"to",
"the",
"log",
"using",
"a",
"function",
"or",
"the",
"default",
"file",
"logging",
"."
] | 4ac87ac59555db6eaba734b2b022fcc296e8729d | https://github.com/jbroadway/analog/blob/4ac87ac59555db6eaba734b2b022fcc296e8729d/lib/Analog/Analog.php#L173-L180 | train |
yoeunes/toastr | src/Toastr.php | Toastr.error | public function error(string $message, string $title = '', array $options = []): self
{
return $this->addNotification(self::ERROR, $message, $title, $options);
} | php | public function error(string $message, string $title = '', array $options = []): self
{
return $this->addNotification(self::ERROR, $message, $title, $options);
} | [
"public",
"function",
"error",
"(",
"string",
"$",
"message",
",",
"string",
"$",
"title",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addNotification",
"(",
"self",
"::",
"ERROR",
",",... | Shortcut for adding an error notification.
@param string $message The notification's message
@param string $title The notification's title
@param array $options
@return Toastr | [
"Shortcut",
"for",
"adding",
"an",
"error",
"notification",
"."
] | 84aebbae7eb6c14e854fc54425bab1748a8ae021 | https://github.com/yoeunes/toastr/blob/84aebbae7eb6c14e854fc54425bab1748a8ae021/src/Toastr.php#L78-L81 | train |
yoeunes/toastr | src/Toastr.php | Toastr.info | public function info(string $message, string $title = '', array $options = []): self
{
return $this->addNotification(self::INFO, $message, $title, $options);
} | php | public function info(string $message, string $title = '', array $options = []): self
{
return $this->addNotification(self::INFO, $message, $title, $options);
} | [
"public",
"function",
"info",
"(",
"string",
"$",
"message",
",",
"string",
"$",
"title",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addNotification",
"(",
"self",
"::",
"INFO",
",",
... | Shortcut for adding an info notification.
@param string $message The notification's message
@param string $title The notification's title
@param array $options
@return Toastr | [
"Shortcut",
"for",
"adding",
"an",
"info",
"notification",
"."
] | 84aebbae7eb6c14e854fc54425bab1748a8ae021 | https://github.com/yoeunes/toastr/blob/84aebbae7eb6c14e854fc54425bab1748a8ae021/src/Toastr.php#L92-L95 | train |
yoeunes/toastr | src/Toastr.php | Toastr.success | public function success(string $message, string $title = '', array $options = []): self
{
return $this->addNotification(self::SUCCESS, $message, $title, $options);
} | php | public function success(string $message, string $title = '', array $options = []): self
{
return $this->addNotification(self::SUCCESS, $message, $title, $options);
} | [
"public",
"function",
"success",
"(",
"string",
"$",
"message",
",",
"string",
"$",
"title",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addNotification",
"(",
"self",
"::",
"SUCCESS",
... | Shortcut for adding a success notification.
@param string $message The notification's message
@param string $title The notification's title
@param array $options
@return Toastr | [
"Shortcut",
"for",
"adding",
"a",
"success",
"notification",
"."
] | 84aebbae7eb6c14e854fc54425bab1748a8ae021 | https://github.com/yoeunes/toastr/blob/84aebbae7eb6c14e854fc54425bab1748a8ae021/src/Toastr.php#L106-L109 | train |
yoeunes/toastr | src/Toastr.php | Toastr.warning | public function warning(string $message, string $title = '', array $options = []): self
{
return $this->addNotification(self::WARNING, $message, $title, $options);
} | php | public function warning(string $message, string $title = '', array $options = []): self
{
return $this->addNotification(self::WARNING, $message, $title, $options);
} | [
"public",
"function",
"warning",
"(",
"string",
"$",
"message",
",",
"string",
"$",
"title",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addNotification",
"(",
"self",
"::",
"WARNING",
... | Shortcut for adding a warning notification.
@param string $message The notification's message
@param string $title The notification's title
@param array $options
@return Toastr | [
"Shortcut",
"for",
"adding",
"a",
"warning",
"notification",
"."
] | 84aebbae7eb6c14e854fc54425bab1748a8ae021 | https://github.com/yoeunes/toastr/blob/84aebbae7eb6c14e854fc54425bab1748a8ae021/src/Toastr.php#L120-L123 | train |
yoeunes/toastr | src/Toastr.php | Toastr.addNotification | public function addNotification(string $type, string $message, string $title = '', array $options = []): self
{
$this->notifications[] = [
'type' => in_array($type, $this->allowedTypes, true) ? $type : self::WARNING,
'title' => $this->escapeSingleQuote($title),
'message' => $this->escapeSingleQuote($message),
'options' => json_encode($options),
];
$this->session->flash(self::TOASTR_NOTIFICATIONS, $this->notifications);
return $this;
} | php | public function addNotification(string $type, string $message, string $title = '', array $options = []): self
{
$this->notifications[] = [
'type' => in_array($type, $this->allowedTypes, true) ? $type : self::WARNING,
'title' => $this->escapeSingleQuote($title),
'message' => $this->escapeSingleQuote($message),
'options' => json_encode($options),
];
$this->session->flash(self::TOASTR_NOTIFICATIONS, $this->notifications);
return $this;
} | [
"public",
"function",
"addNotification",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"message",
",",
"string",
"$",
"title",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"self",
"{",
"$",
"this",
"->",
"notifications",
"[",
"... | Add a notification.
@param string $type Could be error, info, success, or warning.
@param string $message The notification's message
@param string $title The notification's title
@param array $options
@return Toastr | [
"Add",
"a",
"notification",
"."
] | 84aebbae7eb6c14e854fc54425bab1748a8ae021 | https://github.com/yoeunes/toastr/blob/84aebbae7eb6c14e854fc54425bab1748a8ae021/src/Toastr.php#L135-L147 | train |
yoeunes/toastr | src/Toastr.php | Toastr.render | public function render(): string
{
$toastr = '<script type="text/javascript">'.$this->options().$this->notificationsAsString().'</script>';
$this->session->forget(self::TOASTR_NOTIFICATIONS);
return $toastr;
} | php | public function render(): string
{
$toastr = '<script type="text/javascript">'.$this->options().$this->notificationsAsString().'</script>';
$this->session->forget(self::TOASTR_NOTIFICATIONS);
return $toastr;
} | [
"public",
"function",
"render",
"(",
")",
":",
"string",
"{",
"$",
"toastr",
"=",
"'<script type=\"text/javascript\">'",
".",
"$",
"this",
"->",
"options",
"(",
")",
".",
"$",
"this",
"->",
"notificationsAsString",
"(",
")",
".",
"'</script>'",
";",
"$",
"... | Render the notifications' script tag.
@return string | [
"Render",
"the",
"notifications",
"script",
"tag",
"."
] | 84aebbae7eb6c14e854fc54425bab1748a8ae021 | https://github.com/yoeunes/toastr/blob/84aebbae7eb6c14e854fc54425bab1748a8ae021/src/Toastr.php#L154-L161 | train |
yoeunes/toastr | src/Toastr.php | Toastr.notifications | public function notifications(): array
{
return array_map(
function ($n) {
return $this->toastr($n['type'], $n['message'], $n['title'], $n['options']);
},
$this->session->get(self::TOASTR_NOTIFICATIONS, [])
);
} | php | public function notifications(): array
{
return array_map(
function ($n) {
return $this->toastr($n['type'], $n['message'], $n['title'], $n['options']);
},
$this->session->get(self::TOASTR_NOTIFICATIONS, [])
);
} | [
"public",
"function",
"notifications",
"(",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"n",
")",
"{",
"return",
"$",
"this",
"->",
"toastr",
"(",
"$",
"n",
"[",
"'type'",
"]",
",",
"$",
"n",
"[",
"'message'",
"]",
","... | map over all notifications and create an array of toastrs.
@return array | [
"map",
"over",
"all",
"notifications",
"and",
"create",
"an",
"array",
"of",
"toastrs",
"."
] | 84aebbae7eb6c14e854fc54425bab1748a8ae021 | https://github.com/yoeunes/toastr/blob/84aebbae7eb6c14e854fc54425bab1748a8ae021/src/Toastr.php#L186-L194 | train |
yoeunes/toastr | src/Toastr.php | Toastr.toastr | public function toastr(string $type, string $message = '', string $title = '', string $options = ''): string
{
return "toastr.$type('$message', '$title', $options);";
} | php | public function toastr(string $type, string $message = '', string $title = '', string $options = ''): string
{
return "toastr.$type('$message', '$title', $options);";
} | [
"public",
"function",
"toastr",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"message",
"=",
"''",
",",
"string",
"$",
"title",
"=",
"''",
",",
"string",
"$",
"options",
"=",
"''",
")",
":",
"string",
"{",
"return",
"\"toastr.$type('$message', '$title',... | Create a single toastr.
@param string $type
@param string $message
@param string|null $title
@param string|null $options
@return string | [
"Create",
"a",
"single",
"toastr",
"."
] | 84aebbae7eb6c14e854fc54425bab1748a8ae021 | https://github.com/yoeunes/toastr/blob/84aebbae7eb6c14e854fc54425bab1748a8ae021/src/Toastr.php#L206-L209 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.