id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
226,600
|
CedrickOka/oka-pagination
|
src/Util/PaginationQuery.php
|
PaginationQuery.createSelectQuery
|
protected function createSelectQuery(array $fields = [], array $criteria = [], array $orderBy = [], $distinct = true)
{
if ($this->objectManager instanceof \Doctrine\ORM\EntityManager) {
/** @var \Doctrine\ORM\QueryBuilder $builder */
$builder = $this->objectManager->createQueryBuilder();
$builder->select(empty($fields) ? 'p' : 'p.' . implode(', p.', $fields));
if (true === $distinct) {
$builder->distinct();
}
$builder->from($this->className, 'p')
->setFirstResult($this->getItemOffset())
->setMaxResults($this->itemPerPage);
foreach ($orderBy as $key => $value) {
$builder->orderBy(sprintf('p.%s', $key), $value);
}
} elseif ($this->objectManager instanceof \Doctrine\ODM\MongoDB\DocumentManager) {
/** @var \Doctrine\ODM\MongoDB\Query\Builder $builder */
$builder = $this->objectManager->createQueryBuilder($this->className);
if (false === empty($fields)) {
$builder->select($fields);
}
$builder->skip($this->getItemOffset())
->limit($this->itemPerPage);
foreach ($orderBy as $key => $value) {
$builder->sort($key, $value);
}
} else {
throw new ObjectManagerNotSupportedException(sprintf('Doctrine object manager class "%s" is not supported.', get_class($this->objectManager)));
}
$this->qbHandler->applyExprFromArray($builder, 'p', $criteria);
return $builder->getQuery();
}
|
php
|
protected function createSelectQuery(array $fields = [], array $criteria = [], array $orderBy = [], $distinct = true)
{
if ($this->objectManager instanceof \Doctrine\ORM\EntityManager) {
/** @var \Doctrine\ORM\QueryBuilder $builder */
$builder = $this->objectManager->createQueryBuilder();
$builder->select(empty($fields) ? 'p' : 'p.' . implode(', p.', $fields));
if (true === $distinct) {
$builder->distinct();
}
$builder->from($this->className, 'p')
->setFirstResult($this->getItemOffset())
->setMaxResults($this->itemPerPage);
foreach ($orderBy as $key => $value) {
$builder->orderBy(sprintf('p.%s', $key), $value);
}
} elseif ($this->objectManager instanceof \Doctrine\ODM\MongoDB\DocumentManager) {
/** @var \Doctrine\ODM\MongoDB\Query\Builder $builder */
$builder = $this->objectManager->createQueryBuilder($this->className);
if (false === empty($fields)) {
$builder->select($fields);
}
$builder->skip($this->getItemOffset())
->limit($this->itemPerPage);
foreach ($orderBy as $key => $value) {
$builder->sort($key, $value);
}
} else {
throw new ObjectManagerNotSupportedException(sprintf('Doctrine object manager class "%s" is not supported.', get_class($this->objectManager)));
}
$this->qbHandler->applyExprFromArray($builder, 'p', $criteria);
return $builder->getQuery();
}
|
[
"protected",
"function",
"createSelectQuery",
"(",
"array",
"$",
"fields",
"=",
"[",
"]",
",",
"array",
"$",
"criteria",
"=",
"[",
"]",
",",
"array",
"$",
"orderBy",
"=",
"[",
"]",
",",
"$",
"distinct",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"objectManager",
"instanceof",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"EntityManager",
")",
"{",
"/** @var \\Doctrine\\ORM\\QueryBuilder $builder */",
"$",
"builder",
"=",
"$",
"this",
"->",
"objectManager",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"builder",
"->",
"select",
"(",
"empty",
"(",
"$",
"fields",
")",
"?",
"'p'",
":",
"'p.'",
".",
"implode",
"(",
"', p.'",
",",
"$",
"fields",
")",
")",
";",
"if",
"(",
"true",
"===",
"$",
"distinct",
")",
"{",
"$",
"builder",
"->",
"distinct",
"(",
")",
";",
"}",
"$",
"builder",
"->",
"from",
"(",
"$",
"this",
"->",
"className",
",",
"'p'",
")",
"->",
"setFirstResult",
"(",
"$",
"this",
"->",
"getItemOffset",
"(",
")",
")",
"->",
"setMaxResults",
"(",
"$",
"this",
"->",
"itemPerPage",
")",
";",
"foreach",
"(",
"$",
"orderBy",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"builder",
"->",
"orderBy",
"(",
"sprintf",
"(",
"'p.%s'",
",",
"$",
"key",
")",
",",
"$",
"value",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"objectManager",
"instanceof",
"\\",
"Doctrine",
"\\",
"ODM",
"\\",
"MongoDB",
"\\",
"DocumentManager",
")",
"{",
"/** @var \\Doctrine\\ODM\\MongoDB\\Query\\Builder $builder */",
"$",
"builder",
"=",
"$",
"this",
"->",
"objectManager",
"->",
"createQueryBuilder",
"(",
"$",
"this",
"->",
"className",
")",
";",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"builder",
"->",
"select",
"(",
"$",
"fields",
")",
";",
"}",
"$",
"builder",
"->",
"skip",
"(",
"$",
"this",
"->",
"getItemOffset",
"(",
")",
")",
"->",
"limit",
"(",
"$",
"this",
"->",
"itemPerPage",
")",
";",
"foreach",
"(",
"$",
"orderBy",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"builder",
"->",
"sort",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"ObjectManagerNotSupportedException",
"(",
"sprintf",
"(",
"'Doctrine object manager class \"%s\" is not supported.'",
",",
"get_class",
"(",
"$",
"this",
"->",
"objectManager",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"qbHandler",
"->",
"applyExprFromArray",
"(",
"$",
"builder",
",",
"'p'",
",",
"$",
"criteria",
")",
";",
"return",
"$",
"builder",
"->",
"getQuery",
"(",
")",
";",
"}"
] |
Create internal select items query
@param array $fields
@param array $criteria
@param array $orderBy
@param bool $distinct
@return \Doctrine\ORM\AbstractQuery|\Doctrine\ODM\MongoDB\Query\Query
|
[
"Create",
"internal",
"select",
"items",
"query"
] |
d31dcdda62a60cc5e679993c90f02c61e8131c92
|
https://github.com/CedrickOka/oka-pagination/blob/d31dcdda62a60cc5e679993c90f02c61e8131c92/src/Util/PaginationQuery.php#L415-L454
|
226,601
|
jpcercal/environment
|
src/Resource/ArrayResource.php
|
ArrayResource.removeChar
|
protected function removeChar($string, $charStart = null, $charEnd = null)
{
if (!is_null($charStart) && (is_string($charStart) || is_array($charStart))) {
if (is_string($charStart)) {
$charStart = [$charStart];
}
foreach ($charStart as $char) {
if (substr($string, 0, 1) === $char) {
$string = substr($string, 1);
}
}
}
if (!is_null($charEnd) && (is_string($charEnd) || is_array($charEnd))) {
if (is_string($charEnd)) {
$charEnd = [$charEnd];
}
foreach ($charEnd as $char) {
if (substr($string, -1) === $char) {
$string = substr($string, 0, -1);
}
}
}
return $string;
}
|
php
|
protected function removeChar($string, $charStart = null, $charEnd = null)
{
if (!is_null($charStart) && (is_string($charStart) || is_array($charStart))) {
if (is_string($charStart)) {
$charStart = [$charStart];
}
foreach ($charStart as $char) {
if (substr($string, 0, 1) === $char) {
$string = substr($string, 1);
}
}
}
if (!is_null($charEnd) && (is_string($charEnd) || is_array($charEnd))) {
if (is_string($charEnd)) {
$charEnd = [$charEnd];
}
foreach ($charEnd as $char) {
if (substr($string, -1) === $char) {
$string = substr($string, 0, -1);
}
}
}
return $string;
}
|
[
"protected",
"function",
"removeChar",
"(",
"$",
"string",
",",
"$",
"charStart",
"=",
"null",
",",
"$",
"charEnd",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"charStart",
")",
"&&",
"(",
"is_string",
"(",
"$",
"charStart",
")",
"||",
"is_array",
"(",
"$",
"charStart",
")",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"charStart",
")",
")",
"{",
"$",
"charStart",
"=",
"[",
"$",
"charStart",
"]",
";",
"}",
"foreach",
"(",
"$",
"charStart",
"as",
"$",
"char",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"1",
")",
"===",
"$",
"char",
")",
"{",
"$",
"string",
"=",
"substr",
"(",
"$",
"string",
",",
"1",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"charEnd",
")",
"&&",
"(",
"is_string",
"(",
"$",
"charEnd",
")",
"||",
"is_array",
"(",
"$",
"charEnd",
")",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"charEnd",
")",
")",
"{",
"$",
"charEnd",
"=",
"[",
"$",
"charEnd",
"]",
";",
"}",
"foreach",
"(",
"$",
"charEnd",
"as",
"$",
"char",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"string",
",",
"-",
"1",
")",
"===",
"$",
"char",
")",
"{",
"$",
"string",
"=",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"}",
"}",
"return",
"$",
"string",
";",
"}"
] |
Remove char at start or end position of a string.
@param string $string
@param string|null|array $charStart
@param string|null|array $charEnd
@return string
|
[
"Remove",
"char",
"at",
"start",
"or",
"end",
"position",
"of",
"a",
"string",
"."
] |
6be36b0585b1c856a86247e5d335063ba4f150f9
|
https://github.com/jpcercal/environment/blob/6be36b0585b1c856a86247e5d335063ba4f150f9/src/Resource/ArrayResource.php#L21-L48
|
226,602
|
jpcercal/environment
|
src/Resource/ArrayResource.php
|
ArrayResource.handleError
|
protected function handleError($type, $message, $file, $line)
{
throw new ResourceException(sprintf(
'%s: "%s" in %s on line %d',
$type,
$message,
$file,
$line
));
}
|
php
|
protected function handleError($type, $message, $file, $line)
{
throw new ResourceException(sprintf(
'%s: "%s" in %s on line %d',
$type,
$message,
$file,
$line
));
}
|
[
"protected",
"function",
"handleError",
"(",
"$",
"type",
",",
"$",
"message",
",",
"$",
"file",
",",
"$",
"line",
")",
"{",
"throw",
"new",
"ResourceException",
"(",
"sprintf",
"(",
"'%s: \"%s\" in %s on line %d'",
",",
"$",
"type",
",",
"$",
"message",
",",
"$",
"file",
",",
"$",
"line",
")",
")",
";",
"}"
] |
Handle error and throw a new ResourceException.
@param int $type
@param string $message
@param string $file
@param int $line
@throws ResourceException
|
[
"Handle",
"error",
"and",
"throw",
"a",
"new",
"ResourceException",
"."
] |
6be36b0585b1c856a86247e5d335063ba4f150f9
|
https://github.com/jpcercal/environment/blob/6be36b0585b1c856a86247e5d335063ba4f150f9/src/Resource/ArrayResource.php#L60-L69
|
226,603
|
jpcercal/environment
|
src/Resource/ArrayResource.php
|
ArrayResource.filterItems
|
protected function filterItems(array $items)
{
$data = [];
foreach ($items as $item) {
$item = trim($item);
if (empty($item)) {
continue;
}
$item = $this->removeChar($item, '[', ']');
if ($this->itemIsSerialized($item)) {
$data[] = unserialize($item);
continue;
}
if (strpos($item, '=>') !== false) {
$element = explode('=>', $item);
$element[0] = trim($element[0]);
$element[1] = trim($element[1]);
$key = $this->removeChar($element[0], ['"', "'"], ['"', "'"]);
$val = $this->removeChar($element[1], ['"', "'"], ['"', "'"]);
$data[$key] = $val;
} else {
$data[] = $this->removeChar($item, ['"', "'"], ['"', "'"]);
}
}
return $data;
}
|
php
|
protected function filterItems(array $items)
{
$data = [];
foreach ($items as $item) {
$item = trim($item);
if (empty($item)) {
continue;
}
$item = $this->removeChar($item, '[', ']');
if ($this->itemIsSerialized($item)) {
$data[] = unserialize($item);
continue;
}
if (strpos($item, '=>') !== false) {
$element = explode('=>', $item);
$element[0] = trim($element[0]);
$element[1] = trim($element[1]);
$key = $this->removeChar($element[0], ['"', "'"], ['"', "'"]);
$val = $this->removeChar($element[1], ['"', "'"], ['"', "'"]);
$data[$key] = $val;
} else {
$data[] = $this->removeChar($item, ['"', "'"], ['"', "'"]);
}
}
return $data;
}
|
[
"protected",
"function",
"filterItems",
"(",
"array",
"$",
"items",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"trim",
"(",
"$",
"item",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"item",
")",
")",
"{",
"continue",
";",
"}",
"$",
"item",
"=",
"$",
"this",
"->",
"removeChar",
"(",
"$",
"item",
",",
"'['",
",",
"']'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"itemIsSerialized",
"(",
"$",
"item",
")",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"unserialize",
"(",
"$",
"item",
")",
";",
"continue",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"item",
",",
"'=>'",
")",
"!==",
"false",
")",
"{",
"$",
"element",
"=",
"explode",
"(",
"'=>'",
",",
"$",
"item",
")",
";",
"$",
"element",
"[",
"0",
"]",
"=",
"trim",
"(",
"$",
"element",
"[",
"0",
"]",
")",
";",
"$",
"element",
"[",
"1",
"]",
"=",
"trim",
"(",
"$",
"element",
"[",
"1",
"]",
")",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"removeChar",
"(",
"$",
"element",
"[",
"0",
"]",
",",
"[",
"'\"'",
",",
"\"'\"",
"]",
",",
"[",
"'\"'",
",",
"\"'\"",
"]",
")",
";",
"$",
"val",
"=",
"$",
"this",
"->",
"removeChar",
"(",
"$",
"element",
"[",
"1",
"]",
",",
"[",
"'\"'",
",",
"\"'\"",
"]",
",",
"[",
"'\"'",
",",
"\"'\"",
"]",
")",
";",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"this",
"->",
"removeChar",
"(",
"$",
"item",
",",
"[",
"'\"'",
",",
"\"'\"",
"]",
",",
"[",
"'\"'",
",",
"\"'\"",
"]",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Filter the items.
@param array $items
@return array
|
[
"Filter",
"the",
"items",
"."
] |
6be36b0585b1c856a86247e5d335063ba4f150f9
|
https://github.com/jpcercal/environment/blob/6be36b0585b1c856a86247e5d335063ba4f150f9/src/Resource/ArrayResource.php#L90-L123
|
226,604
|
jpcercal/environment
|
src/Resource/ArrayResource.php
|
ArrayResource.parseArray
|
protected function parseArray($data)
{
$pattern = '/(\[[^\[\]]*\])/';
set_error_handler([__CLASS__, 'handleError']);
while (true) {
if (!preg_match($pattern, $data, $matches) > 0) {
break;
}
$stringMatches = trim($matches[0]);
$items = explode(',', $stringMatches);
$currentData = $this->filterItems($items);
$data = str_replace($stringMatches, serialize($currentData), $data);
}
$result = unserialize($data);
restore_error_handler();
return $result;
}
|
php
|
protected function parseArray($data)
{
$pattern = '/(\[[^\[\]]*\])/';
set_error_handler([__CLASS__, 'handleError']);
while (true) {
if (!preg_match($pattern, $data, $matches) > 0) {
break;
}
$stringMatches = trim($matches[0]);
$items = explode(',', $stringMatches);
$currentData = $this->filterItems($items);
$data = str_replace($stringMatches, serialize($currentData), $data);
}
$result = unserialize($data);
restore_error_handler();
return $result;
}
|
[
"protected",
"function",
"parseArray",
"(",
"$",
"data",
")",
"{",
"$",
"pattern",
"=",
"'/(\\[[^\\[\\]]*\\])/'",
";",
"set_error_handler",
"(",
"[",
"__CLASS__",
",",
"'handleError'",
"]",
")",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"data",
",",
"$",
"matches",
")",
">",
"0",
")",
"{",
"break",
";",
"}",
"$",
"stringMatches",
"=",
"trim",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"$",
"items",
"=",
"explode",
"(",
"','",
",",
"$",
"stringMatches",
")",
";",
"$",
"currentData",
"=",
"$",
"this",
"->",
"filterItems",
"(",
"$",
"items",
")",
";",
"$",
"data",
"=",
"str_replace",
"(",
"$",
"stringMatches",
",",
"serialize",
"(",
"$",
"currentData",
")",
",",
"$",
"data",
")",
";",
"}",
"$",
"result",
"=",
"unserialize",
"(",
"$",
"data",
")",
";",
"restore_error_handler",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Parse a string that represents an array statement to create an array data.
@param string $data
@return array
|
[
"Parse",
"a",
"string",
"that",
"represents",
"an",
"array",
"statement",
"to",
"create",
"an",
"array",
"data",
"."
] |
6be36b0585b1c856a86247e5d335063ba4f150f9
|
https://github.com/jpcercal/environment/blob/6be36b0585b1c856a86247e5d335063ba4f150f9/src/Resource/ArrayResource.php#L132-L158
|
226,605
|
phergie/phergie-irc-bot-react
|
src/EventQueueFactory.php
|
EventQueueFactory.getEventQueue
|
public function getEventQueue(ConnectionInterface $connection)
{
if (!isset($this->queues[$connection])) {
$this->queues[$connection] = new EventQueue;
}
return $this->queues[$connection];
}
|
php
|
public function getEventQueue(ConnectionInterface $connection)
{
if (!isset($this->queues[$connection])) {
$this->queues[$connection] = new EventQueue;
}
return $this->queues[$connection];
}
|
[
"public",
"function",
"getEventQueue",
"(",
"ConnectionInterface",
"$",
"connection",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"queues",
"[",
"$",
"connection",
"]",
")",
")",
"{",
"$",
"this",
"->",
"queues",
"[",
"$",
"connection",
"]",
"=",
"new",
"EventQueue",
";",
"}",
"return",
"$",
"this",
"->",
"queues",
"[",
"$",
"connection",
"]",
";",
"}"
] |
Returns the event queue for a specified connection.
@param \Phergie\Irc\ConnectionInterface $connection
@return \Phergie\Irc\Bot\React\EventQueueInterface
|
[
"Returns",
"the",
"event",
"queue",
"for",
"a",
"specified",
"connection",
"."
] |
17745ef6b846513258af3dbd86e5612d3deb19b7
|
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/EventQueueFactory.php#L43-L49
|
226,606
|
gigaai/framework
|
src/Storage/Eloquent/Lead.php
|
Lead.linkedUser
|
public function linkedUser($props = [])
{
if (!$this->isLinked() && isset($props['try_matching']) && $props['try_matching'] === true) {
return Matching::matchCurrentLead();
}
return $this->belongsTo($this->getUserModel(), 'linked_account', $this->getUserModelKey());
}
|
php
|
public function linkedUser($props = [])
{
if (!$this->isLinked() && isset($props['try_matching']) && $props['try_matching'] === true) {
return Matching::matchCurrentLead();
}
return $this->belongsTo($this->getUserModel(), 'linked_account', $this->getUserModelKey());
}
|
[
"public",
"function",
"linkedUser",
"(",
"$",
"props",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isLinked",
"(",
")",
"&&",
"isset",
"(",
"$",
"props",
"[",
"'try_matching'",
"]",
")",
"&&",
"$",
"props",
"[",
"'try_matching'",
"]",
"===",
"true",
")",
"{",
"return",
"Matching",
"::",
"matchCurrentLead",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"belongsTo",
"(",
"$",
"this",
"->",
"getUserModel",
"(",
")",
",",
"'linked_account'",
",",
"$",
"this",
"->",
"getUserModelKey",
"(",
")",
")",
";",
"}"
] |
Laravel linked user
@param $props
@return mixed
|
[
"Laravel",
"linked",
"user"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Storage/Eloquent/Lead.php#L121-L128
|
226,607
|
gigaai/framework
|
src/Storage/Eloquent/Lead.php
|
Lead.user
|
public function user($props = [])
{
if (!$this->isLinked() && isset($props['try_matching']) && $props['try_matching'] === true) {
return Matching::matchCurrentLead();
}
return $this->linkedUser()->first();
}
|
php
|
public function user($props = [])
{
if (!$this->isLinked() && isset($props['try_matching']) && $props['try_matching'] === true) {
return Matching::matchCurrentLead();
}
return $this->linkedUser()->first();
}
|
[
"public",
"function",
"user",
"(",
"$",
"props",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isLinked",
"(",
")",
"&&",
"isset",
"(",
"$",
"props",
"[",
"'try_matching'",
"]",
")",
"&&",
"$",
"props",
"[",
"'try_matching'",
"]",
"===",
"true",
")",
"{",
"return",
"Matching",
"::",
"matchCurrentLead",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"linkedUser",
"(",
")",
"->",
"first",
"(",
")",
";",
"}"
] |
Linked user relationship
@param array $props
@return null
|
[
"Linked",
"user",
"relationship"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Storage/Eloquent/Lead.php#L136-L143
|
226,608
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.run
|
public function run()
{
$received = $this->request->getReceivedData();
if (!$received || empty($received['object']) || $received['object'] != 'page') {
return;
}
$this->received = $received;
if (!isset($received['entry'])) {
return;
}
foreach ($received['entry'] as $entry) {
if (!isset($entry['messaging'])) {
return;
}
foreach ($entry['messaging'] as $event) {
$this->conversation->set([
'lead_id' => $event['sender']['id'],
'page_id' => $event['recipient']['id'],
'timestamp' => $event['timestamp'],
]);
$this->processEvent($event);
}
}
}
|
php
|
public function run()
{
$received = $this->request->getReceivedData();
if (!$received || empty($received['object']) || $received['object'] != 'page') {
return;
}
$this->received = $received;
if (!isset($received['entry'])) {
return;
}
foreach ($received['entry'] as $entry) {
if (!isset($entry['messaging'])) {
return;
}
foreach ($entry['messaging'] as $event) {
$this->conversation->set([
'lead_id' => $event['sender']['id'],
'page_id' => $event['recipient']['id'],
'timestamp' => $event['timestamp'],
]);
$this->processEvent($event);
}
}
}
|
[
"public",
"function",
"run",
"(",
")",
"{",
"$",
"received",
"=",
"$",
"this",
"->",
"request",
"->",
"getReceivedData",
"(",
")",
";",
"if",
"(",
"!",
"$",
"received",
"||",
"empty",
"(",
"$",
"received",
"[",
"'object'",
"]",
")",
"||",
"$",
"received",
"[",
"'object'",
"]",
"!=",
"'page'",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"received",
"=",
"$",
"received",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"received",
"[",
"'entry'",
"]",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"received",
"[",
"'entry'",
"]",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"entry",
"[",
"'messaging'",
"]",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"entry",
"[",
"'messaging'",
"]",
"as",
"$",
"event",
")",
"{",
"$",
"this",
"->",
"conversation",
"->",
"set",
"(",
"[",
"'lead_id'",
"=>",
"$",
"event",
"[",
"'sender'",
"]",
"[",
"'id'",
"]",
",",
"'page_id'",
"=>",
"$",
"event",
"[",
"'recipient'",
"]",
"[",
"'id'",
"]",
",",
"'timestamp'",
"=>",
"$",
"event",
"[",
"'timestamp'",
"]",
",",
"]",
")",
";",
"$",
"this",
"->",
"processEvent",
"(",
"$",
"event",
")",
";",
"}",
"}",
"}"
] |
Run the bot
|
[
"Run",
"the",
"bot"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L152-L181
|
226,609
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.processEvent
|
public function processEvent($event)
{
// Pass thread control to Inbox if Page Administrators move from Done to Inbox
if (isset($event['request_thread_control'])) {
return $this->passToInbox();
}
// Handle Account Linking and Unlinking
if (isset($event['account_linking'])) {
return AccountLinking::process($event);
}
// Handle message and postback
if (!isset($event['message']) && !isset($event['postback'])) {
return null;
}
if (isset($event['message'])) {
$this->message = $event['message'];
// Enabling NLP
$this->initNlp($event['message']);
}
if (isset($event['postback'])) {
$this->postback = $event['postback'];
}
// If current message is sent from Page
if (isset($event['message']['is_echo'])) {
$this->conversation->set('lead_id', $event['recipient']['id']);
$this->conversation->set('page_id', $event['sender']['id']);
}
$this->conversation->set('received_input', $this->getReceivedInput());
$this->setConfigData();
// Save lead data if not exists.
if (!isset($event['message']['is_echo'])) {
$lead = $this->storage->pull();
} else {
$lead = Lead::withTrashed()->where('user_id', $this->getLeadId())->first();
}
$this->conversation->set('lead', $lead);
// Message was sent by page, we don't need to response.
if (isset($event['message']) && isset($event['message']['is_echo']) && $event['message']['is_echo'] == true) {
return null;
}
DynamicParser::support([
'type' => 'callback',
'callback' => function ($content) use ($lead) {
return $this->resolver->bind([
'bot' => $this,
'lead' => $lead,
'input' => $this->getReceivedInput(),
])->resolve($content);
},
]);
$type_pattern = $this->request->getTypeAndPattern($event);
// We'll check to response intended action first
if ($this->responseIntendedAction()) {
return;
}
$nodes = $this->findNodes($type_pattern['type'], $type_pattern['pattern']);
$this->response($nodes);
}
|
php
|
public function processEvent($event)
{
// Pass thread control to Inbox if Page Administrators move from Done to Inbox
if (isset($event['request_thread_control'])) {
return $this->passToInbox();
}
// Handle Account Linking and Unlinking
if (isset($event['account_linking'])) {
return AccountLinking::process($event);
}
// Handle message and postback
if (!isset($event['message']) && !isset($event['postback'])) {
return null;
}
if (isset($event['message'])) {
$this->message = $event['message'];
// Enabling NLP
$this->initNlp($event['message']);
}
if (isset($event['postback'])) {
$this->postback = $event['postback'];
}
// If current message is sent from Page
if (isset($event['message']['is_echo'])) {
$this->conversation->set('lead_id', $event['recipient']['id']);
$this->conversation->set('page_id', $event['sender']['id']);
}
$this->conversation->set('received_input', $this->getReceivedInput());
$this->setConfigData();
// Save lead data if not exists.
if (!isset($event['message']['is_echo'])) {
$lead = $this->storage->pull();
} else {
$lead = Lead::withTrashed()->where('user_id', $this->getLeadId())->first();
}
$this->conversation->set('lead', $lead);
// Message was sent by page, we don't need to response.
if (isset($event['message']) && isset($event['message']['is_echo']) && $event['message']['is_echo'] == true) {
return null;
}
DynamicParser::support([
'type' => 'callback',
'callback' => function ($content) use ($lead) {
return $this->resolver->bind([
'bot' => $this,
'lead' => $lead,
'input' => $this->getReceivedInput(),
])->resolve($content);
},
]);
$type_pattern = $this->request->getTypeAndPattern($event);
// We'll check to response intended action first
if ($this->responseIntendedAction()) {
return;
}
$nodes = $this->findNodes($type_pattern['type'], $type_pattern['pattern']);
$this->response($nodes);
}
|
[
"public",
"function",
"processEvent",
"(",
"$",
"event",
")",
"{",
"// Pass thread control to Inbox if Page Administrators move from Done to Inbox",
"if",
"(",
"isset",
"(",
"$",
"event",
"[",
"'request_thread_control'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"passToInbox",
"(",
")",
";",
"}",
"// Handle Account Linking and Unlinking",
"if",
"(",
"isset",
"(",
"$",
"event",
"[",
"'account_linking'",
"]",
")",
")",
"{",
"return",
"AccountLinking",
"::",
"process",
"(",
"$",
"event",
")",
";",
"}",
"// Handle message and postback",
"if",
"(",
"!",
"isset",
"(",
"$",
"event",
"[",
"'message'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"event",
"[",
"'postback'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"event",
"[",
"'message'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"message",
"=",
"$",
"event",
"[",
"'message'",
"]",
";",
"// Enabling NLP",
"$",
"this",
"->",
"initNlp",
"(",
"$",
"event",
"[",
"'message'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"event",
"[",
"'postback'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"postback",
"=",
"$",
"event",
"[",
"'postback'",
"]",
";",
"}",
"// If current message is sent from Page",
"if",
"(",
"isset",
"(",
"$",
"event",
"[",
"'message'",
"]",
"[",
"'is_echo'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"conversation",
"->",
"set",
"(",
"'lead_id'",
",",
"$",
"event",
"[",
"'recipient'",
"]",
"[",
"'id'",
"]",
")",
";",
"$",
"this",
"->",
"conversation",
"->",
"set",
"(",
"'page_id'",
",",
"$",
"event",
"[",
"'sender'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"conversation",
"->",
"set",
"(",
"'received_input'",
",",
"$",
"this",
"->",
"getReceivedInput",
"(",
")",
")",
";",
"$",
"this",
"->",
"setConfigData",
"(",
")",
";",
"// Save lead data if not exists.",
"if",
"(",
"!",
"isset",
"(",
"$",
"event",
"[",
"'message'",
"]",
"[",
"'is_echo'",
"]",
")",
")",
"{",
"$",
"lead",
"=",
"$",
"this",
"->",
"storage",
"->",
"pull",
"(",
")",
";",
"}",
"else",
"{",
"$",
"lead",
"=",
"Lead",
"::",
"withTrashed",
"(",
")",
"->",
"where",
"(",
"'user_id'",
",",
"$",
"this",
"->",
"getLeadId",
"(",
")",
")",
"->",
"first",
"(",
")",
";",
"}",
"$",
"this",
"->",
"conversation",
"->",
"set",
"(",
"'lead'",
",",
"$",
"lead",
")",
";",
"// Message was sent by page, we don't need to response.",
"if",
"(",
"isset",
"(",
"$",
"event",
"[",
"'message'",
"]",
")",
"&&",
"isset",
"(",
"$",
"event",
"[",
"'message'",
"]",
"[",
"'is_echo'",
"]",
")",
"&&",
"$",
"event",
"[",
"'message'",
"]",
"[",
"'is_echo'",
"]",
"==",
"true",
")",
"{",
"return",
"null",
";",
"}",
"DynamicParser",
"::",
"support",
"(",
"[",
"'type'",
"=>",
"'callback'",
",",
"'callback'",
"=>",
"function",
"(",
"$",
"content",
")",
"use",
"(",
"$",
"lead",
")",
"{",
"return",
"$",
"this",
"->",
"resolver",
"->",
"bind",
"(",
"[",
"'bot'",
"=>",
"$",
"this",
",",
"'lead'",
"=>",
"$",
"lead",
",",
"'input'",
"=>",
"$",
"this",
"->",
"getReceivedInput",
"(",
")",
",",
"]",
")",
"->",
"resolve",
"(",
"$",
"content",
")",
";",
"}",
",",
"]",
")",
";",
"$",
"type_pattern",
"=",
"$",
"this",
"->",
"request",
"->",
"getTypeAndPattern",
"(",
"$",
"event",
")",
";",
"// We'll check to response intended action first",
"if",
"(",
"$",
"this",
"->",
"responseIntendedAction",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"nodes",
"=",
"$",
"this",
"->",
"findNodes",
"(",
"$",
"type_pattern",
"[",
"'type'",
"]",
",",
"$",
"type_pattern",
"[",
"'pattern'",
"]",
")",
";",
"$",
"this",
"->",
"response",
"(",
"$",
"nodes",
")",
";",
"}"
] |
Process the event and response
@param Array $event
@return void
|
[
"Process",
"the",
"event",
"and",
"response"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L190-L263
|
226,610
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.initNlp
|
private function initNlp($message)
{
if (isset($message['nlp']) && is_array($message['nlp'])) {
$this->nlp = new Nlp($message['nlp']);
Conversation::set('nlp', $this->nlp);
}
}
|
php
|
private function initNlp($message)
{
if (isset($message['nlp']) && is_array($message['nlp'])) {
$this->nlp = new Nlp($message['nlp']);
Conversation::set('nlp', $this->nlp);
}
}
|
[
"private",
"function",
"initNlp",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"message",
"[",
"'nlp'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"message",
"[",
"'nlp'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"nlp",
"=",
"new",
"Nlp",
"(",
"$",
"message",
"[",
"'nlp'",
"]",
")",
";",
"Conversation",
"::",
"set",
"(",
"'nlp'",
",",
"$",
"this",
"->",
"nlp",
")",
";",
"}",
"}"
] |
Load NLP Data
@return void
|
[
"Load",
"NLP",
"Data"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L270-L276
|
226,611
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.response
|
public function response($nodes, $lead_id = null)
{
foreach ($nodes as $node) {
// Set intended action if this node has
if (!empty($node->wait)) {
$lead = $this->conversation->get('lead');
$lead->data('_wait', $node->wait);
}
$answers = $this->parse($node->answers);
$this->request->sendMessages($answers, [
'messaging_type' => $node->messaging_type
]);
}
}
|
php
|
public function response($nodes, $lead_id = null)
{
foreach ($nodes as $node) {
// Set intended action if this node has
if (!empty($node->wait)) {
$lead = $this->conversation->get('lead');
$lead->data('_wait', $node->wait);
}
$answers = $this->parse($node->answers);
$this->request->sendMessages($answers, [
'messaging_type' => $node->messaging_type
]);
}
}
|
[
"public",
"function",
"response",
"(",
"$",
"nodes",
",",
"$",
"lead_id",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"// Set intended action if this node has",
"if",
"(",
"!",
"empty",
"(",
"$",
"node",
"->",
"wait",
")",
")",
"{",
"$",
"lead",
"=",
"$",
"this",
"->",
"conversation",
"->",
"get",
"(",
"'lead'",
")",
";",
"$",
"lead",
"->",
"data",
"(",
"'_wait'",
",",
"$",
"node",
"->",
"wait",
")",
";",
"}",
"$",
"answers",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"node",
"->",
"answers",
")",
";",
"$",
"this",
"->",
"request",
"->",
"sendMessages",
"(",
"$",
"answers",
",",
"[",
"'messaging_type'",
"=>",
"$",
"node",
"->",
"messaging_type",
"]",
")",
";",
"}",
"}"
] |
Response sender message
@param $nodes
@param null $lead_id
|
[
"Response",
"sender",
"message"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L296-L312
|
226,612
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.findNodes
|
public function findNodes($message_type, $ask)
{
$nodes = Node::findByTypeAndPattern($message_type, $ask);
if ($nodes->count() === 0) {
$nodes = Node::findByTypeAndPattern('default');
}
return $nodes->filter(function ($node) {
$pageId = Conversation::get('page_id');
return (empty($node['sources']) || (isset($node->sources['global']) && $node->sources['global'] == true)
|| (isset($node->sources[$pageId]) && $node->sources[$pageId] == true));
});
}
|
php
|
public function findNodes($message_type, $ask)
{
$nodes = Node::findByTypeAndPattern($message_type, $ask);
if ($nodes->count() === 0) {
$nodes = Node::findByTypeAndPattern('default');
}
return $nodes->filter(function ($node) {
$pageId = Conversation::get('page_id');
return (empty($node['sources']) || (isset($node->sources['global']) && $node->sources['global'] == true)
|| (isset($node->sources[$pageId]) && $node->sources[$pageId] == true));
});
}
|
[
"public",
"function",
"findNodes",
"(",
"$",
"message_type",
",",
"$",
"ask",
")",
"{",
"$",
"nodes",
"=",
"Node",
"::",
"findByTypeAndPattern",
"(",
"$",
"message_type",
",",
"$",
"ask",
")",
";",
"if",
"(",
"$",
"nodes",
"->",
"count",
"(",
")",
"===",
"0",
")",
"{",
"$",
"nodes",
"=",
"Node",
"::",
"findByTypeAndPattern",
"(",
"'default'",
")",
";",
"}",
"return",
"$",
"nodes",
"->",
"filter",
"(",
"function",
"(",
"$",
"node",
")",
"{",
"$",
"pageId",
"=",
"Conversation",
"::",
"get",
"(",
"'page_id'",
")",
";",
"return",
"(",
"empty",
"(",
"$",
"node",
"[",
"'sources'",
"]",
")",
"||",
"(",
"isset",
"(",
"$",
"node",
"->",
"sources",
"[",
"'global'",
"]",
")",
"&&",
"$",
"node",
"->",
"sources",
"[",
"'global'",
"]",
"==",
"true",
")",
"||",
"(",
"isset",
"(",
"$",
"node",
"->",
"sources",
"[",
"$",
"pageId",
"]",
")",
"&&",
"$",
"node",
"->",
"sources",
"[",
"$",
"pageId",
"]",
"==",
"true",
")",
")",
";",
"}",
")",
";",
"}"
] |
Find a response for current request
@param String $message_type text or payload
@param String $ask Message or Payload name
@return Node[]
|
[
"Find",
"a",
"response",
"for",
"current",
"request"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L322-L336
|
226,613
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.responseIntendedAction
|
private function responseIntendedAction()
{
$lead = $this->conversation->get('lead');
$waiting = $lead->_wait;
// We set previous_waiting to back to support $bot->keep() method
$this->conversation->set('previous_intended_action', $waiting);
if (!empty($waiting)) {
$lead->update([
'_wait' => false
]);
// Get Nodes for intended actions.
if (is_numeric($waiting)) {
$nodes = Node::find($waiting);
if (!empty($nodes)) {
$nodes = [$nodes];
}
} else {
$nodes = Node::findByTypeAndPattern('intended', $waiting);
}
$this->response($nodes);
return true;
}
return false;
}
|
php
|
private function responseIntendedAction()
{
$lead = $this->conversation->get('lead');
$waiting = $lead->_wait;
// We set previous_waiting to back to support $bot->keep() method
$this->conversation->set('previous_intended_action', $waiting);
if (!empty($waiting)) {
$lead->update([
'_wait' => false
]);
// Get Nodes for intended actions.
if (is_numeric($waiting)) {
$nodes = Node::find($waiting);
if (!empty($nodes)) {
$nodes = [$nodes];
}
} else {
$nodes = Node::findByTypeAndPattern('intended', $waiting);
}
$this->response($nodes);
return true;
}
return false;
}
|
[
"private",
"function",
"responseIntendedAction",
"(",
")",
"{",
"$",
"lead",
"=",
"$",
"this",
"->",
"conversation",
"->",
"get",
"(",
"'lead'",
")",
";",
"$",
"waiting",
"=",
"$",
"lead",
"->",
"_wait",
";",
"// We set previous_waiting to back to support $bot->keep() method",
"$",
"this",
"->",
"conversation",
"->",
"set",
"(",
"'previous_intended_action'",
",",
"$",
"waiting",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"waiting",
")",
")",
"{",
"$",
"lead",
"->",
"update",
"(",
"[",
"'_wait'",
"=>",
"false",
"]",
")",
";",
"// Get Nodes for intended actions.",
"if",
"(",
"is_numeric",
"(",
"$",
"waiting",
")",
")",
"{",
"$",
"nodes",
"=",
"Node",
"::",
"find",
"(",
"$",
"waiting",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"nodes",
")",
")",
"{",
"$",
"nodes",
"=",
"[",
"$",
"nodes",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"nodes",
"=",
"Node",
"::",
"findByTypeAndPattern",
"(",
"'intended'",
",",
"$",
"waiting",
")",
";",
"}",
"$",
"this",
"->",
"response",
"(",
"$",
"nodes",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Response for intended actions
@return bool
|
[
"Response",
"for",
"intended",
"actions"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L343-L374
|
226,614
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.getLocation
|
public function getLocation($output = '')
{
$attachments = $this->getAttachments();
$location = new \stdClass();
if (!empty($attachments) && isset($attachments[0]['type']) && $attachments[0]['type'] === 'location') {
$location = $attachments[0]['payload']->coordinates;
}
if (!empty($output)) {
return $location->$output;
}
return $location;
}
|
php
|
public function getLocation($output = '')
{
$attachments = $this->getAttachments();
$location = new \stdClass();
if (!empty($attachments) && isset($attachments[0]['type']) && $attachments[0]['type'] === 'location') {
$location = $attachments[0]['payload']->coordinates;
}
if (!empty($output)) {
return $location->$output;
}
return $location;
}
|
[
"public",
"function",
"getLocation",
"(",
"$",
"output",
"=",
"''",
")",
"{",
"$",
"attachments",
"=",
"$",
"this",
"->",
"getAttachments",
"(",
")",
";",
"$",
"location",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"attachments",
")",
"&&",
"isset",
"(",
"$",
"attachments",
"[",
"0",
"]",
"[",
"'type'",
"]",
")",
"&&",
"$",
"attachments",
"[",
"0",
"]",
"[",
"'type'",
"]",
"===",
"'location'",
")",
"{",
"$",
"location",
"=",
"$",
"attachments",
"[",
"0",
"]",
"[",
"'payload'",
"]",
"->",
"coordinates",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"output",
")",
")",
"{",
"return",
"$",
"location",
"->",
"$",
"output",
";",
"}",
"return",
"$",
"location",
";",
"}"
] |
Get user sent location
@param string $output If provided, returns either `lat` or `long` of current location
@return mixed
|
[
"Get",
"user",
"sent",
"location"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L383-L398
|
226,615
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.getAttachments
|
public function getAttachments()
{
if ($this->isUserMessage() && isset($this->message->attachments)) {
return $this->message->attachments;
}
return null;
}
|
php
|
public function getAttachments()
{
if ($this->isUserMessage() && isset($this->message->attachments)) {
return $this->message->attachments;
}
return null;
}
|
[
"public",
"function",
"getAttachments",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isUserMessage",
"(",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"message",
"->",
"attachments",
")",
")",
"{",
"return",
"$",
"this",
"->",
"message",
"->",
"attachments",
";",
"}",
"return",
"null",
";",
"}"
] |
Get user attachments
@return mixed
|
[
"Get",
"user",
"attachments"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L405-L412
|
226,616
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.getReceivedText
|
public function getReceivedText()
{
if ($this->isUserMessage()) {
return isset($this->message->text) ? $this->message->text : '';
}
return '';
}
|
php
|
public function getReceivedText()
{
if ($this->isUserMessage()) {
return isset($this->message->text) ? $this->message->text : '';
}
return '';
}
|
[
"public",
"function",
"getReceivedText",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isUserMessage",
"(",
")",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"message",
"->",
"text",
")",
"?",
"$",
"this",
"->",
"message",
"->",
"text",
":",
"''",
";",
"}",
"return",
"''",
";",
"}"
] |
Get user sent text
@return string
|
[
"Get",
"user",
"sent",
"text"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L419-L426
|
226,617
|
gigaai/framework
|
src/MessengerBot.php
|
MessengerBot.isUserMessage
|
private function isUserMessage()
{
if (!empty($this->message) && isset($this->message['metadata'])) {
return $this->message['metadata'] != 'SENT_BY_GIGA_AI';
}
return true;
}
|
php
|
private function isUserMessage()
{
if (!empty($this->message) && isset($this->message['metadata'])) {
return $this->message['metadata'] != 'SENT_BY_GIGA_AI';
}
return true;
}
|
[
"private",
"function",
"isUserMessage",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"message",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"message",
"[",
"'metadata'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"message",
"[",
"'metadata'",
"]",
"!=",
"'SENT_BY_GIGA_AI'",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if current message is sent by user
@return boolean
|
[
"Check",
"if",
"current",
"message",
"is",
"sent",
"by",
"user"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/MessengerBot.php#L455-L462
|
226,618
|
gigaai/framework
|
src/Message/Message.php
|
Message.load
|
public static function load($body, $flags = [])
{
$instance = new static($body);
if (!isset($flags['skip_detection']) || !$flags['skip_detection']) {
if (!$instance->expectedFormat()) {
return false;
}
}
return $instance->normalize();
}
|
php
|
public static function load($body, $flags = [])
{
$instance = new static($body);
if (!isset($flags['skip_detection']) || !$flags['skip_detection']) {
if (!$instance->expectedFormat()) {
return false;
}
}
return $instance->normalize();
}
|
[
"public",
"static",
"function",
"load",
"(",
"$",
"body",
",",
"$",
"flags",
"=",
"[",
"]",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
"(",
"$",
"body",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"flags",
"[",
"'skip_detection'",
"]",
")",
"||",
"!",
"$",
"flags",
"[",
"'skip_detection'",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"instance",
"->",
"expectedFormat",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"$",
"instance",
"->",
"normalize",
"(",
")",
";",
"}"
] |
Load the message to parse and return
@param $body
@return mixed
|
[
"Load",
"the",
"message",
"to",
"parse",
"and",
"return"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Message/Message.php#L35-L46
|
226,619
|
gigaai/framework
|
src/Shortcodes/Shortcode.php
|
Shortcode.parse
|
public static function parse($answer)
{
if ( ! is_array($answer)) {
return;
}
foreach ($answer as $key => $value) {
$parsed = is_array($value) ? self::parse($value) : self::process($value);
if ( ! empty($parsed)) {
$answer[$key] = $parsed;
} else {
unset($answer[$key]);
}
}
return $answer;
}
|
php
|
public static function parse($answer)
{
if ( ! is_array($answer)) {
return;
}
foreach ($answer as $key => $value) {
$parsed = is_array($value) ? self::parse($value) : self::process($value);
if ( ! empty($parsed)) {
$answer[$key] = $parsed;
} else {
unset($answer[$key]);
}
}
return $answer;
}
|
[
"public",
"static",
"function",
"parse",
"(",
"$",
"answer",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"answer",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"answer",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"parsed",
"=",
"is_array",
"(",
"$",
"value",
")",
"?",
"self",
"::",
"parse",
"(",
"$",
"value",
")",
":",
"self",
"::",
"process",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"parsed",
")",
")",
"{",
"$",
"answer",
"[",
"$",
"key",
"]",
"=",
"$",
"parsed",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"answer",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"answer",
";",
"}"
] |
Recursive parse shortcode from array
@param $answer
@return mixed
|
[
"Recursive",
"parse",
"shortcode",
"from",
"array"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Shortcodes/Shortcode.php#L86-L103
|
226,620
|
pug-php/js-phpize
|
src/JsPhpize/JsPhpize.php
|
JsPhpize.render
|
public function render($input, $filename = null, array $variables = [])
{
if (is_array($filename)) {
$variables = $filename;
$filename = null;
}
if (!in_array($this->stream, $this->streamsRegistered)) {
$this->streamsRegistered[] = $this->stream;
if (in_array($this->stream, stream_get_wrappers())) {
stream_wrapper_unregister($this->stream);
}
$classParts = explode('\\', get_class($this));
stream_wrapper_register($this->stream, $classParts[0] . '\Stream\ExpressionStream');
}
extract(array_merge($this->sharedVariables, $variables));
try {
$code = '<?php ' . $this->compile($input, $filename);
if (strlen($code) < 4096) {
return include $this->stream . '://data;' . $code;
}
$file = tempnam(sys_get_temp_dir(), 'jsph');
file_put_contents($file, $code);
$result = include $file;
unlink($file);
return $result;
} catch (\JsPhpize\Compiler\Exception $exception) {
throw $exception;
} catch (\JsPhpize\Lexer\Exception $exception) {
throw $exception;
} catch (\JsPhpize\Parser\Exception $exception) {
throw $exception;
} catch (\Exception $exception) {
$summary = $input;
if (mb_strlen($summary) > 50) {
$summary = mb_substr($summary, 0, 47) . '...';
}
throw new Exception(
"An error occur in [$summary]:\n" . $exception->getMessage(),
2,
E_ERROR,
__FILE__,
__LINE__,
$exception
);
}
}
|
php
|
public function render($input, $filename = null, array $variables = [])
{
if (is_array($filename)) {
$variables = $filename;
$filename = null;
}
if (!in_array($this->stream, $this->streamsRegistered)) {
$this->streamsRegistered[] = $this->stream;
if (in_array($this->stream, stream_get_wrappers())) {
stream_wrapper_unregister($this->stream);
}
$classParts = explode('\\', get_class($this));
stream_wrapper_register($this->stream, $classParts[0] . '\Stream\ExpressionStream');
}
extract(array_merge($this->sharedVariables, $variables));
try {
$code = '<?php ' . $this->compile($input, $filename);
if (strlen($code) < 4096) {
return include $this->stream . '://data;' . $code;
}
$file = tempnam(sys_get_temp_dir(), 'jsph');
file_put_contents($file, $code);
$result = include $file;
unlink($file);
return $result;
} catch (\JsPhpize\Compiler\Exception $exception) {
throw $exception;
} catch (\JsPhpize\Lexer\Exception $exception) {
throw $exception;
} catch (\JsPhpize\Parser\Exception $exception) {
throw $exception;
} catch (\Exception $exception) {
$summary = $input;
if (mb_strlen($summary) > 50) {
$summary = mb_substr($summary, 0, 47) . '...';
}
throw new Exception(
"An error occur in [$summary]:\n" . $exception->getMessage(),
2,
E_ERROR,
__FILE__,
__LINE__,
$exception
);
}
}
|
[
"public",
"function",
"render",
"(",
"$",
"input",
",",
"$",
"filename",
"=",
"null",
",",
"array",
"$",
"variables",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"variables",
"=",
"$",
"filename",
";",
"$",
"filename",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"stream",
",",
"$",
"this",
"->",
"streamsRegistered",
")",
")",
"{",
"$",
"this",
"->",
"streamsRegistered",
"[",
"]",
"=",
"$",
"this",
"->",
"stream",
";",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"stream",
",",
"stream_get_wrappers",
"(",
")",
")",
")",
"{",
"stream_wrapper_unregister",
"(",
"$",
"this",
"->",
"stream",
")",
";",
"}",
"$",
"classParts",
"=",
"explode",
"(",
"'\\\\'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"stream_wrapper_register",
"(",
"$",
"this",
"->",
"stream",
",",
"$",
"classParts",
"[",
"0",
"]",
".",
"'\\Stream\\ExpressionStream'",
")",
";",
"}",
"extract",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"sharedVariables",
",",
"$",
"variables",
")",
")",
";",
"try",
"{",
"$",
"code",
"=",
"'<?php '",
".",
"$",
"this",
"->",
"compile",
"(",
"$",
"input",
",",
"$",
"filename",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"code",
")",
"<",
"4096",
")",
"{",
"return",
"include",
"$",
"this",
"->",
"stream",
".",
"'://data;'",
".",
"$",
"code",
";",
"}",
"$",
"file",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'jsph'",
")",
";",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"code",
")",
";",
"$",
"result",
"=",
"include",
"$",
"file",
";",
"unlink",
"(",
"$",
"file",
")",
";",
"return",
"$",
"result",
";",
"}",
"catch",
"(",
"\\",
"JsPhpize",
"\\",
"Compiler",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"catch",
"(",
"\\",
"JsPhpize",
"\\",
"Lexer",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"catch",
"(",
"\\",
"JsPhpize",
"\\",
"Parser",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"summary",
"=",
"$",
"input",
";",
"if",
"(",
"mb_strlen",
"(",
"$",
"summary",
")",
">",
"50",
")",
"{",
"$",
"summary",
"=",
"mb_substr",
"(",
"$",
"summary",
",",
"0",
",",
"47",
")",
".",
"'...'",
";",
"}",
"throw",
"new",
"Exception",
"(",
"\"An error occur in [$summary]:\\n\"",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"2",
",",
"E_ERROR",
",",
"__FILE__",
",",
"__LINE__",
",",
"$",
"exception",
")",
";",
"}",
"}"
] |
Compile and return the code execution result.
@param string $input file or content
@param string $filename if specified, input is used as content and filename as its name
@param array $variables variables to be used in rendered code
@return mixed
|
[
"Compile",
"and",
"return",
"the",
"code",
"execution",
"result",
"."
] |
c41102da1be243ba9439b90af8b7032016585537
|
https://github.com/pug-php/js-phpize/blob/c41102da1be243ba9439b90af8b7032016585537/src/JsPhpize/JsPhpize.php#L140-L189
|
226,621
|
pug-php/js-phpize
|
src/JsPhpize/JsPhpize.php
|
JsPhpize.share
|
public function share($variables, $value = null)
{
if (!is_array($variables)) {
$variables = [strval($variables) => $value];
}
$this->sharedVariables = array_merge($this->sharedVariables, $variables);
}
|
php
|
public function share($variables, $value = null)
{
if (!is_array($variables)) {
$variables = [strval($variables) => $value];
}
$this->sharedVariables = array_merge($this->sharedVariables, $variables);
}
|
[
"public",
"function",
"share",
"(",
"$",
"variables",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"variables",
")",
")",
"{",
"$",
"variables",
"=",
"[",
"strval",
"(",
"$",
"variables",
")",
"=>",
"$",
"value",
"]",
";",
"}",
"$",
"this",
"->",
"sharedVariables",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"sharedVariables",
",",
"$",
"variables",
")",
";",
"}"
] |
Add a variable or an array of variables to be shared with all templates that will be rendered
by the instance of Pug.
@param array|string $variables|$key an associatives array of variable names and values, or a
variable name if you wish to sahre only one
@param mixed $value if you pass an array as first argument, the second
argument will be ignored, else it will used as the
variable value for the variable name you passed as first
argument
|
[
"Add",
"a",
"variable",
"or",
"an",
"array",
"of",
"variables",
"to",
"be",
"shared",
"with",
"all",
"templates",
"that",
"will",
"be",
"rendered",
"by",
"the",
"instance",
"of",
"Pug",
"."
] |
c41102da1be243ba9439b90af8b7032016585537
|
https://github.com/pug-php/js-phpize/blob/c41102da1be243ba9439b90af8b7032016585537/src/JsPhpize/JsPhpize.php#L228-L234
|
226,622
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.fulfillRequest
|
public function fulfillRequest()
{
if (! $this->supportsMethod($this->request->method)) {
throw new Exception(
'Method not allowed',
static::ERROR_SCOPE | static::ERROR_HTTP_METHOD_NOT_ALLOWED,
BaseResponse::HTTP_METHOD_NOT_ALLOWED
);
}
$methodName = static::methodHandlerName($this->request->method);
$models = $this->{$methodName}($this->request);
if (is_null($models)) {
throw new Exception(
'Unknown ID',
static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
BaseResponse::HTTP_NOT_FOUND
);
}
if ($models instanceof Response) {
$response = $models;
} elseif ($models instanceof LengthAwarePaginator) {
$items = new Collection($models->items());
foreach ($items as $model) {
$this->loadRelatedModels($model);
}
$response = new Response($items, static::successfulHttpStatusCode($this->request->method));
$response->links = $this->getPaginationLinks($models);
$response->included = $this->getIncludedModels($items);
$response->errors = $this->getNonBreakingErrors();
} else {
if ($models instanceof Collection) {
foreach ($models as $model) {
$this->loadRelatedModels($model);
}
} else {
$this->loadRelatedModels($models);
}
$response = new Response($models, static::successfulHttpStatusCode($this->request->method, $models));
$response->included = $this->getIncludedModels($models);
$response->errors = $this->getNonBreakingErrors();
}
return $response;
}
|
php
|
public function fulfillRequest()
{
if (! $this->supportsMethod($this->request->method)) {
throw new Exception(
'Method not allowed',
static::ERROR_SCOPE | static::ERROR_HTTP_METHOD_NOT_ALLOWED,
BaseResponse::HTTP_METHOD_NOT_ALLOWED
);
}
$methodName = static::methodHandlerName($this->request->method);
$models = $this->{$methodName}($this->request);
if (is_null($models)) {
throw new Exception(
'Unknown ID',
static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
BaseResponse::HTTP_NOT_FOUND
);
}
if ($models instanceof Response) {
$response = $models;
} elseif ($models instanceof LengthAwarePaginator) {
$items = new Collection($models->items());
foreach ($items as $model) {
$this->loadRelatedModels($model);
}
$response = new Response($items, static::successfulHttpStatusCode($this->request->method));
$response->links = $this->getPaginationLinks($models);
$response->included = $this->getIncludedModels($items);
$response->errors = $this->getNonBreakingErrors();
} else {
if ($models instanceof Collection) {
foreach ($models as $model) {
$this->loadRelatedModels($model);
}
} else {
$this->loadRelatedModels($models);
}
$response = new Response($models, static::successfulHttpStatusCode($this->request->method, $models));
$response->included = $this->getIncludedModels($models);
$response->errors = $this->getNonBreakingErrors();
}
return $response;
}
|
[
"public",
"function",
"fulfillRequest",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"supportsMethod",
"(",
"$",
"this",
"->",
"request",
"->",
"method",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Method not allowed'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_HTTP_METHOD_NOT_ALLOWED",
",",
"BaseResponse",
"::",
"HTTP_METHOD_NOT_ALLOWED",
")",
";",
"}",
"$",
"methodName",
"=",
"static",
"::",
"methodHandlerName",
"(",
"$",
"this",
"->",
"request",
"->",
"method",
")",
";",
"$",
"models",
"=",
"$",
"this",
"->",
"{",
"$",
"methodName",
"}",
"(",
"$",
"this",
"->",
"request",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"models",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unknown ID'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_UNKNOWN_ID",
",",
"BaseResponse",
"::",
"HTTP_NOT_FOUND",
")",
";",
"}",
"if",
"(",
"$",
"models",
"instanceof",
"Response",
")",
"{",
"$",
"response",
"=",
"$",
"models",
";",
"}",
"elseif",
"(",
"$",
"models",
"instanceof",
"LengthAwarePaginator",
")",
"{",
"$",
"items",
"=",
"new",
"Collection",
"(",
"$",
"models",
"->",
"items",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"loadRelatedModels",
"(",
"$",
"model",
")",
";",
"}",
"$",
"response",
"=",
"new",
"Response",
"(",
"$",
"items",
",",
"static",
"::",
"successfulHttpStatusCode",
"(",
"$",
"this",
"->",
"request",
"->",
"method",
")",
")",
";",
"$",
"response",
"->",
"links",
"=",
"$",
"this",
"->",
"getPaginationLinks",
"(",
"$",
"models",
")",
";",
"$",
"response",
"->",
"included",
"=",
"$",
"this",
"->",
"getIncludedModels",
"(",
"$",
"items",
")",
";",
"$",
"response",
"->",
"errors",
"=",
"$",
"this",
"->",
"getNonBreakingErrors",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"models",
"instanceof",
"Collection",
")",
"{",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"loadRelatedModels",
"(",
"$",
"model",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"loadRelatedModels",
"(",
"$",
"models",
")",
";",
"}",
"$",
"response",
"=",
"new",
"Response",
"(",
"$",
"models",
",",
"static",
"::",
"successfulHttpStatusCode",
"(",
"$",
"this",
"->",
"request",
"->",
"method",
",",
"$",
"models",
")",
")",
";",
"$",
"response",
"->",
"included",
"=",
"$",
"this",
"->",
"getIncludedModels",
"(",
"$",
"models",
")",
";",
"$",
"response",
"->",
"errors",
"=",
"$",
"this",
"->",
"getNonBreakingErrors",
"(",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Fulfill the API request and return a response.
@return \EchoIT\JsonApi\Response
@throws Exception
|
[
"Fulfill",
"the",
"API",
"request",
"and",
"return",
"a",
"response",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L63-L113
|
226,623
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.loadRelatedModels
|
protected function loadRelatedModels(Model $model) {
// get the relations to load
$relations = $this->exposedRelationsFromRequest($model);
foreach ($relations as $relation) {
// if this relation is loaded via a method, then call said method
if (in_array($relation, $model->relationsFromMethod())) {
$model->$relation = $model->$relation();
continue;
}
$model->load($relation);
}
}
|
php
|
protected function loadRelatedModels(Model $model) {
// get the relations to load
$relations = $this->exposedRelationsFromRequest($model);
foreach ($relations as $relation) {
// if this relation is loaded via a method, then call said method
if (in_array($relation, $model->relationsFromMethod())) {
$model->$relation = $model->$relation();
continue;
}
$model->load($relation);
}
}
|
[
"protected",
"function",
"loadRelatedModels",
"(",
"Model",
"$",
"model",
")",
"{",
"// get the relations to load",
"$",
"relations",
"=",
"$",
"this",
"->",
"exposedRelationsFromRequest",
"(",
"$",
"model",
")",
";",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"relation",
")",
"{",
"// if this relation is loaded via a method, then call said method",
"if",
"(",
"in_array",
"(",
"$",
"relation",
",",
"$",
"model",
"->",
"relationsFromMethod",
"(",
")",
")",
")",
"{",
"$",
"model",
"->",
"$",
"relation",
"=",
"$",
"model",
"->",
"$",
"relation",
"(",
")",
";",
"continue",
";",
"}",
"$",
"model",
"->",
"load",
"(",
"$",
"relation",
")",
";",
"}",
"}"
] |
Load a model's relations
@param Model $model the model to load relations of
@return void
|
[
"Load",
"a",
"model",
"s",
"relations"
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L121-L134
|
226,624
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.exposedRelationsFromRequest
|
protected function exposedRelationsFromRequest($model = null)
{
$exposedRelations = static::$exposedRelations;
// if no relations are to be included by request
if (count($this->request->include) == 0) {
// and if we have a model
if ($model !== null && $model instanceof Model) {
// then use the relations exposed by default
$exposedRelations = array_intersect($exposedRelations, $model->defaultExposedRelations());
$model->setExposedRelations($exposedRelations);
return $exposedRelations;
}
}
$exposedRelations = array_intersect($exposedRelations, $this->request->include);
if ($model !== null && $model instanceof Model) {
$model->setExposedRelations($exposedRelations);
}
return $exposedRelations;
}
|
php
|
protected function exposedRelationsFromRequest($model = null)
{
$exposedRelations = static::$exposedRelations;
// if no relations are to be included by request
if (count($this->request->include) == 0) {
// and if we have a model
if ($model !== null && $model instanceof Model) {
// then use the relations exposed by default
$exposedRelations = array_intersect($exposedRelations, $model->defaultExposedRelations());
$model->setExposedRelations($exposedRelations);
return $exposedRelations;
}
}
$exposedRelations = array_intersect($exposedRelations, $this->request->include);
if ($model !== null && $model instanceof Model) {
$model->setExposedRelations($exposedRelations);
}
return $exposedRelations;
}
|
[
"protected",
"function",
"exposedRelationsFromRequest",
"(",
"$",
"model",
"=",
"null",
")",
"{",
"$",
"exposedRelations",
"=",
"static",
"::",
"$",
"exposedRelations",
";",
"// if no relations are to be included by request",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"request",
"->",
"include",
")",
"==",
"0",
")",
"{",
"// and if we have a model",
"if",
"(",
"$",
"model",
"!==",
"null",
"&&",
"$",
"model",
"instanceof",
"Model",
")",
"{",
"// then use the relations exposed by default",
"$",
"exposedRelations",
"=",
"array_intersect",
"(",
"$",
"exposedRelations",
",",
"$",
"model",
"->",
"defaultExposedRelations",
"(",
")",
")",
";",
"$",
"model",
"->",
"setExposedRelations",
"(",
"$",
"exposedRelations",
")",
";",
"return",
"$",
"exposedRelations",
";",
"}",
"}",
"$",
"exposedRelations",
"=",
"array_intersect",
"(",
"$",
"exposedRelations",
",",
"$",
"this",
"->",
"request",
"->",
"include",
")",
";",
"if",
"(",
"$",
"model",
"!==",
"null",
"&&",
"$",
"model",
"instanceof",
"Model",
")",
"{",
"$",
"model",
"->",
"setExposedRelations",
"(",
"$",
"exposedRelations",
")",
";",
"}",
"return",
"$",
"exposedRelations",
";",
"}"
] |
Returns which requested resources are available to include.
@param Model $model
@return array
|
[
"Returns",
"which",
"requested",
"resources",
"are",
"available",
"to",
"include",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L142-L164
|
226,625
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.getIncludedModels
|
protected function getIncludedModels($models)
{
$links = new Collection();
$models = $models instanceof Collection ? $models : [$models];
foreach ($models as $model) {
foreach ($this->exposedRelationsFromRequest($model) as $relationName) {
$value = static::getModelsForRelation($model, $relationName);
if (is_null($value)) {
continue;
}
foreach ($value as $obj) {
// Check whether the object is already included in the response on it's ID
$duplicate = false;
$items = $links->where($obj->getKeyName(), '=', $obj->getKey());
if (count($items) > 0) {
foreach ($items as $item) {
if ($item->getResourceType() === $obj->getResourceType()) {
$duplicate = true;
break;
}
}
if ($duplicate) {
continue;
}
}
//add type property
$attributes = $obj->getAttributes();
$attributes['type'] = $obj->getResourceType();
$obj->setRawAttributes($attributes);
$links->push($obj);
}
}
}
return $links->toArray();
}
|
php
|
protected function getIncludedModels($models)
{
$links = new Collection();
$models = $models instanceof Collection ? $models : [$models];
foreach ($models as $model) {
foreach ($this->exposedRelationsFromRequest($model) as $relationName) {
$value = static::getModelsForRelation($model, $relationName);
if (is_null($value)) {
continue;
}
foreach ($value as $obj) {
// Check whether the object is already included in the response on it's ID
$duplicate = false;
$items = $links->where($obj->getKeyName(), '=', $obj->getKey());
if (count($items) > 0) {
foreach ($items as $item) {
if ($item->getResourceType() === $obj->getResourceType()) {
$duplicate = true;
break;
}
}
if ($duplicate) {
continue;
}
}
//add type property
$attributes = $obj->getAttributes();
$attributes['type'] = $obj->getResourceType();
$obj->setRawAttributes($attributes);
$links->push($obj);
}
}
}
return $links->toArray();
}
|
[
"protected",
"function",
"getIncludedModels",
"(",
"$",
"models",
")",
"{",
"$",
"links",
"=",
"new",
"Collection",
"(",
")",
";",
"$",
"models",
"=",
"$",
"models",
"instanceof",
"Collection",
"?",
"$",
"models",
":",
"[",
"$",
"models",
"]",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"exposedRelationsFromRequest",
"(",
"$",
"model",
")",
"as",
"$",
"relationName",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"getModelsForRelation",
"(",
"$",
"model",
",",
"$",
"relationName",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"obj",
")",
"{",
"// Check whether the object is already included in the response on it's ID",
"$",
"duplicate",
"=",
"false",
";",
"$",
"items",
"=",
"$",
"links",
"->",
"where",
"(",
"$",
"obj",
"->",
"getKeyName",
"(",
")",
",",
"'='",
",",
"$",
"obj",
"->",
"getKey",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"items",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getResourceType",
"(",
")",
"===",
"$",
"obj",
"->",
"getResourceType",
"(",
")",
")",
"{",
"$",
"duplicate",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"duplicate",
")",
"{",
"continue",
";",
"}",
"}",
"//add type property",
"$",
"attributes",
"=",
"$",
"obj",
"->",
"getAttributes",
"(",
")",
";",
"$",
"attributes",
"[",
"'type'",
"]",
"=",
"$",
"obj",
"->",
"getResourceType",
"(",
")",
";",
"$",
"obj",
"->",
"setRawAttributes",
"(",
"$",
"attributes",
")",
";",
"$",
"links",
"->",
"push",
"(",
"$",
"obj",
")",
";",
"}",
"}",
"}",
"return",
"$",
"links",
"->",
"toArray",
"(",
")",
";",
"}"
] |
Iterate through result set to fetch the requested resources to include.
@param \Illuminate\Database\Eloquent\Collection|\EchoIT\JsonApi\Model $models
@return array
|
[
"Iterate",
"through",
"result",
"set",
"to",
"fetch",
"the",
"requested",
"resources",
"to",
"include",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L182-L223
|
226,626
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.getPaginationLinks
|
protected function getPaginationLinks($paginator)
{
$links = [];
$links['self'] = urldecode($paginator->url($paginator->currentPage()));
$links['first'] = urldecode($paginator->url(1));
$links['last'] = urldecode($paginator->url($paginator->lastPage()));
$links['prev'] = urldecode($paginator->url($paginator->currentPage() - 1));
if ($links['prev'] === $links['self'] || $links['prev'] === '') {
$links['prev'] = null;
}
$links['next'] = urldecode($paginator->nextPageUrl());
if ($links['next'] === $links['self'] || $links['next'] === '') {
$links['next'] = null;
}
return $links;
}
|
php
|
protected function getPaginationLinks($paginator)
{
$links = [];
$links['self'] = urldecode($paginator->url($paginator->currentPage()));
$links['first'] = urldecode($paginator->url(1));
$links['last'] = urldecode($paginator->url($paginator->lastPage()));
$links['prev'] = urldecode($paginator->url($paginator->currentPage() - 1));
if ($links['prev'] === $links['self'] || $links['prev'] === '') {
$links['prev'] = null;
}
$links['next'] = urldecode($paginator->nextPageUrl());
if ($links['next'] === $links['self'] || $links['next'] === '') {
$links['next'] = null;
}
return $links;
}
|
[
"protected",
"function",
"getPaginationLinks",
"(",
"$",
"paginator",
")",
"{",
"$",
"links",
"=",
"[",
"]",
";",
"$",
"links",
"[",
"'self'",
"]",
"=",
"urldecode",
"(",
"$",
"paginator",
"->",
"url",
"(",
"$",
"paginator",
"->",
"currentPage",
"(",
")",
")",
")",
";",
"$",
"links",
"[",
"'first'",
"]",
"=",
"urldecode",
"(",
"$",
"paginator",
"->",
"url",
"(",
"1",
")",
")",
";",
"$",
"links",
"[",
"'last'",
"]",
"=",
"urldecode",
"(",
"$",
"paginator",
"->",
"url",
"(",
"$",
"paginator",
"->",
"lastPage",
"(",
")",
")",
")",
";",
"$",
"links",
"[",
"'prev'",
"]",
"=",
"urldecode",
"(",
"$",
"paginator",
"->",
"url",
"(",
"$",
"paginator",
"->",
"currentPage",
"(",
")",
"-",
"1",
")",
")",
";",
"if",
"(",
"$",
"links",
"[",
"'prev'",
"]",
"===",
"$",
"links",
"[",
"'self'",
"]",
"||",
"$",
"links",
"[",
"'prev'",
"]",
"===",
"''",
")",
"{",
"$",
"links",
"[",
"'prev'",
"]",
"=",
"null",
";",
"}",
"$",
"links",
"[",
"'next'",
"]",
"=",
"urldecode",
"(",
"$",
"paginator",
"->",
"nextPageUrl",
"(",
")",
")",
";",
"if",
"(",
"$",
"links",
"[",
"'next'",
"]",
"===",
"$",
"links",
"[",
"'self'",
"]",
"||",
"$",
"links",
"[",
"'next'",
"]",
"===",
"''",
")",
"{",
"$",
"links",
"[",
"'next'",
"]",
"=",
"null",
";",
"}",
"return",
"$",
"links",
";",
"}"
] |
Return pagination links as array
@param LengthAwarePaginator $paginator
@return array
|
[
"Return",
"pagination",
"links",
"as",
"array"
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L230-L247
|
226,627
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.getNonBreakingErrors
|
protected function getNonBreakingErrors()
{
$errors = [];
$unknownRelations = $this->unknownRelationsFromRequest();
if (count($unknownRelations) > 0) {
$errors[] = [
'code' => static::ERROR_UNKNOWN_LINKED_RESOURCES,
'title' => 'Unknown included resource requested',
'description' => 'These included resources are not available: ' . implode(', ', $unknownRelations)
];
}
return $errors;
}
|
php
|
protected function getNonBreakingErrors()
{
$errors = [];
$unknownRelations = $this->unknownRelationsFromRequest();
if (count($unknownRelations) > 0) {
$errors[] = [
'code' => static::ERROR_UNKNOWN_LINKED_RESOURCES,
'title' => 'Unknown included resource requested',
'description' => 'These included resources are not available: ' . implode(', ', $unknownRelations)
];
}
return $errors;
}
|
[
"protected",
"function",
"getNonBreakingErrors",
"(",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"$",
"unknownRelations",
"=",
"$",
"this",
"->",
"unknownRelationsFromRequest",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"unknownRelations",
")",
">",
"0",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"[",
"'code'",
"=>",
"static",
"::",
"ERROR_UNKNOWN_LINKED_RESOURCES",
",",
"'title'",
"=>",
"'Unknown included resource requested'",
",",
"'description'",
"=>",
"'These included resources are not available: '",
".",
"implode",
"(",
"', '",
",",
"$",
"unknownRelations",
")",
"]",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Return errors which did not prevent the API from returning a result set.
@return array
|
[
"Return",
"errors",
"which",
"did",
"not",
"prevent",
"the",
"API",
"from",
"returning",
"a",
"result",
"set",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L254-L268
|
226,628
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.successfulHttpStatusCode
|
public static function successfulHttpStatusCode($method, $model = null)
{
// if we did a put request, we need to ensure that the model wasn't
// changed in other ways than those specified by the request
// Ref: http://jsonapi.org/format/#crud-updating-responses-200
if (($method === 'PATCH' || $method === 'PUT') && $model instanceof Model) {
// check if the model has been changed
if ($model->isChanged()) {
// return our response as if there was a GET request
$method = 'GET';
}
}
switch ($method) {
case 'POST':
return BaseResponse::HTTP_CREATED;
case 'PATCH':
case 'PUT':
case 'DELETE':
return BaseResponse::HTTP_NO_CONTENT;
case 'GET':
return BaseResponse::HTTP_OK;
}
// Code shouldn't reach this point, but if it does we assume that the
// client has made a bad request.
return BaseResponse::HTTP_BAD_REQUEST;
}
|
php
|
public static function successfulHttpStatusCode($method, $model = null)
{
// if we did a put request, we need to ensure that the model wasn't
// changed in other ways than those specified by the request
// Ref: http://jsonapi.org/format/#crud-updating-responses-200
if (($method === 'PATCH' || $method === 'PUT') && $model instanceof Model) {
// check if the model has been changed
if ($model->isChanged()) {
// return our response as if there was a GET request
$method = 'GET';
}
}
switch ($method) {
case 'POST':
return BaseResponse::HTTP_CREATED;
case 'PATCH':
case 'PUT':
case 'DELETE':
return BaseResponse::HTTP_NO_CONTENT;
case 'GET':
return BaseResponse::HTTP_OK;
}
// Code shouldn't reach this point, but if it does we assume that the
// client has made a bad request.
return BaseResponse::HTTP_BAD_REQUEST;
}
|
[
"public",
"static",
"function",
"successfulHttpStatusCode",
"(",
"$",
"method",
",",
"$",
"model",
"=",
"null",
")",
"{",
"// if we did a put request, we need to ensure that the model wasn't",
"// changed in other ways than those specified by the request",
"// Ref: http://jsonapi.org/format/#crud-updating-responses-200",
"if",
"(",
"(",
"$",
"method",
"===",
"'PATCH'",
"||",
"$",
"method",
"===",
"'PUT'",
")",
"&&",
"$",
"model",
"instanceof",
"Model",
")",
"{",
"// check if the model has been changed",
"if",
"(",
"$",
"model",
"->",
"isChanged",
"(",
")",
")",
"{",
"// return our response as if there was a GET request",
"$",
"method",
"=",
"'GET'",
";",
"}",
"}",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"'POST'",
":",
"return",
"BaseResponse",
"::",
"HTTP_CREATED",
";",
"case",
"'PATCH'",
":",
"case",
"'PUT'",
":",
"case",
"'DELETE'",
":",
"return",
"BaseResponse",
"::",
"HTTP_NO_CONTENT",
";",
"case",
"'GET'",
":",
"return",
"BaseResponse",
"::",
"HTTP_OK",
";",
"}",
"// Code shouldn't reach this point, but if it does we assume that the",
"// client has made a bad request.",
"return",
"BaseResponse",
"::",
"HTTP_BAD_REQUEST",
";",
"}"
] |
A method for getting the proper HTTP status code for a successful request
@param string $method "PUT", "POST", "DELETE" or "GET"
@param Model|null $model The model that a PUT request was executed against
@return int
|
[
"A",
"method",
"for",
"getting",
"the",
"proper",
"HTTP",
"status",
"code",
"for",
"a",
"successful",
"request"
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L277-L304
|
226,629
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.getModelsForRelation
|
protected static function getModelsForRelation($model, $relationKey)
{
if (!method_exists($model, $relationKey)) {
throw new Exception(
'Relation "' . $relationKey . '" does not exist in model',
static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
BaseResponse::HTTP_INTERNAL_SERVER_ERROR
);
}
$relationModels = $model->{$relationKey};
if (is_null($relationModels)) {
return null;
}
if (! $relationModels instanceof Collection) {
return [ $relationModels ];
}
return $relationModels;
}
|
php
|
protected static function getModelsForRelation($model, $relationKey)
{
if (!method_exists($model, $relationKey)) {
throw new Exception(
'Relation "' . $relationKey . '" does not exist in model',
static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
BaseResponse::HTTP_INTERNAL_SERVER_ERROR
);
}
$relationModels = $model->{$relationKey};
if (is_null($relationModels)) {
return null;
}
if (! $relationModels instanceof Collection) {
return [ $relationModels ];
}
return $relationModels;
}
|
[
"protected",
"static",
"function",
"getModelsForRelation",
"(",
"$",
"model",
",",
"$",
"relationKey",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"model",
",",
"$",
"relationKey",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Relation \"'",
".",
"$",
"relationKey",
".",
"'\" does not exist in model'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_UNKNOWN_ID",
",",
"BaseResponse",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
")",
";",
"}",
"$",
"relationModels",
"=",
"$",
"model",
"->",
"{",
"$",
"relationKey",
"}",
";",
"if",
"(",
"is_null",
"(",
"$",
"relationModels",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"relationModels",
"instanceof",
"Collection",
")",
"{",
"return",
"[",
"$",
"relationModels",
"]",
";",
"}",
"return",
"$",
"relationModels",
";",
"}"
] |
Returns the models from a relationship. Will always return as array.
@param \Illuminate\Database\Eloquent\Model $model
@param string $relationKey
@return array|\Illuminate\Database\Eloquent\Collection
@throws Exception
|
[
"Returns",
"the",
"models",
"from",
"a",
"relationship",
".",
"Will",
"always",
"return",
"as",
"array",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L325-L344
|
226,630
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.handleSortRequest
|
protected function handleSortRequest($cols, $model)
{
foreach ($cols as $col) {
$dir = 'asc';
if (substr($col, 0, 1) == '-') {
$dir = 'desc';
$col = substr($col, 1);
}
$model = $model->orderBy($col, $dir);
}
return $model;
}
|
php
|
protected function handleSortRequest($cols, $model)
{
foreach ($cols as $col) {
$dir = 'asc';
if (substr($col, 0, 1) == '-') {
$dir = 'desc';
$col = substr($col, 1);
}
$model = $model->orderBy($col, $dir);
}
return $model;
}
|
[
"protected",
"function",
"handleSortRequest",
"(",
"$",
"cols",
",",
"$",
"model",
")",
"{",
"foreach",
"(",
"$",
"cols",
"as",
"$",
"col",
")",
"{",
"$",
"dir",
"=",
"'asc'",
";",
"if",
"(",
"substr",
"(",
"$",
"col",
",",
"0",
",",
"1",
")",
"==",
"'-'",
")",
"{",
"$",
"dir",
"=",
"'desc'",
";",
"$",
"col",
"=",
"substr",
"(",
"$",
"col",
",",
"1",
")",
";",
"}",
"$",
"model",
"=",
"$",
"model",
"->",
"orderBy",
"(",
"$",
"col",
",",
"$",
"dir",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] |
Function to handle sorting requests.
@param array $cols list of column names to sort on
@param \EchoIt\JsonApi\Model $model
@return \EchoIt\JsonApi\Model
@throws Exception
|
[
"Function",
"to",
"handle",
"sorting",
"requests",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L384-L397
|
226,631
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.parseRequestContent
|
protected function parseRequestContent($content, $type)
{
$content = json_decode($content, true);
if (empty($content['data'])) {
throw new Exception(
'Payload either contains misformed JSON or missing "data" parameter.',
static::ERROR_SCOPE | static::ERROR_INVALID_ATTRS,
BaseResponse::HTTP_BAD_REQUEST
);
}
$data = $content['data'];
if (!isset($data['type'])) {
throw new Exception(
'"type" parameter not set in request.',
static::ERROR_SCOPE | static::ERROR_INVALID_ATTRS,
BaseResponse::HTTP_BAD_REQUEST
);
}
if ($data['type'] !== $type) {
throw new Exception(
'"type" parameter is not valid. Expecting ' . $type,
static::ERROR_SCOPE | static::ERROR_INVALID_ATTRS,
BaseResponse::HTTP_CONFLICT
);
}
unset($data['type']);
return $data;
}
|
php
|
protected function parseRequestContent($content, $type)
{
$content = json_decode($content, true);
if (empty($content['data'])) {
throw new Exception(
'Payload either contains misformed JSON or missing "data" parameter.',
static::ERROR_SCOPE | static::ERROR_INVALID_ATTRS,
BaseResponse::HTTP_BAD_REQUEST
);
}
$data = $content['data'];
if (!isset($data['type'])) {
throw new Exception(
'"type" parameter not set in request.',
static::ERROR_SCOPE | static::ERROR_INVALID_ATTRS,
BaseResponse::HTTP_BAD_REQUEST
);
}
if ($data['type'] !== $type) {
throw new Exception(
'"type" parameter is not valid. Expecting ' . $type,
static::ERROR_SCOPE | static::ERROR_INVALID_ATTRS,
BaseResponse::HTTP_CONFLICT
);
}
unset($data['type']);
return $data;
}
|
[
"protected",
"function",
"parseRequestContent",
"(",
"$",
"content",
",",
"$",
"type",
")",
"{",
"$",
"content",
"=",
"json_decode",
"(",
"$",
"content",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"content",
"[",
"'data'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Payload either contains misformed JSON or missing \"data\" parameter.'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_INVALID_ATTRS",
",",
"BaseResponse",
"::",
"HTTP_BAD_REQUEST",
")",
";",
"}",
"$",
"data",
"=",
"$",
"content",
"[",
"'data'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'\"type\" parameter not set in request.'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_INVALID_ATTRS",
",",
"BaseResponse",
"::",
"HTTP_BAD_REQUEST",
")",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"'type'",
"]",
"!==",
"$",
"type",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'\"type\" parameter is not valid. Expecting '",
".",
"$",
"type",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_INVALID_ATTRS",
",",
"BaseResponse",
"::",
"HTTP_CONFLICT",
")",
";",
"}",
"unset",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Parses content from request into an array of values.
@param string $content
@param string $type the type the content is expected to be.
@return array
@throws Exception
|
[
"Parses",
"content",
"from",
"request",
"into",
"an",
"array",
"of",
"values",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L407-L436
|
226,632
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.handlePaginationRequest
|
protected function handlePaginationRequest($request, $model, $total = null)
{
$page = $request->pageNumber;
$perPage = $request->pageSize;
if (!$total) {
$total = $model->count();
}
$results = $model->forPage($page, $perPage)->get(array('*'));
$paginator = new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page[number]'
]);
$paginator->appends('page[size]', $perPage);
if (!empty($request->filter)) {
foreach ($request->filter as $key=>$value) {
$paginator->appends($key, $value);
}
}
if (!empty($request->sort)) {
$paginator->appends('sort', implode(',', $request->sort));
}
return $paginator;
}
|
php
|
protected function handlePaginationRequest($request, $model, $total = null)
{
$page = $request->pageNumber;
$perPage = $request->pageSize;
if (!$total) {
$total = $model->count();
}
$results = $model->forPage($page, $perPage)->get(array('*'));
$paginator = new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page[number]'
]);
$paginator->appends('page[size]', $perPage);
if (!empty($request->filter)) {
foreach ($request->filter as $key=>$value) {
$paginator->appends($key, $value);
}
}
if (!empty($request->sort)) {
$paginator->appends('sort', implode(',', $request->sort));
}
return $paginator;
}
|
[
"protected",
"function",
"handlePaginationRequest",
"(",
"$",
"request",
",",
"$",
"model",
",",
"$",
"total",
"=",
"null",
")",
"{",
"$",
"page",
"=",
"$",
"request",
"->",
"pageNumber",
";",
"$",
"perPage",
"=",
"$",
"request",
"->",
"pageSize",
";",
"if",
"(",
"!",
"$",
"total",
")",
"{",
"$",
"total",
"=",
"$",
"model",
"->",
"count",
"(",
")",
";",
"}",
"$",
"results",
"=",
"$",
"model",
"->",
"forPage",
"(",
"$",
"page",
",",
"$",
"perPage",
")",
"->",
"get",
"(",
"array",
"(",
"'*'",
")",
")",
";",
"$",
"paginator",
"=",
"new",
"LengthAwarePaginator",
"(",
"$",
"results",
",",
"$",
"total",
",",
"$",
"perPage",
",",
"$",
"page",
",",
"[",
"'path'",
"=>",
"Paginator",
"::",
"resolveCurrentPath",
"(",
")",
",",
"'pageName'",
"=>",
"'page[number]'",
"]",
")",
";",
"$",
"paginator",
"->",
"appends",
"(",
"'page[size]'",
",",
"$",
"perPage",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"request",
"->",
"filter",
")",
")",
"{",
"foreach",
"(",
"$",
"request",
"->",
"filter",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"paginator",
"->",
"appends",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"request",
"->",
"sort",
")",
")",
"{",
"$",
"paginator",
"->",
"appends",
"(",
"'sort'",
",",
"implode",
"(",
"','",
",",
"$",
"request",
"->",
"sort",
")",
")",
";",
"}",
"return",
"$",
"paginator",
";",
"}"
] |
Function to handle pagination requests.
@param \EchoIt\JsonApi\Request $request
@param \EchoIt\JsonApi\Model $model
@param integer $total the total number of records
@return \Illuminate\Pagination\LengthAwarePaginator
|
[
"Function",
"to",
"handle",
"pagination",
"requests",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L446-L469
|
226,633
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.handleFilterRequest
|
protected function handleFilterRequest($filters, $model)
{
foreach ($filters as $key=>$value) {
$model = $model->where($key, '=', $value);
}
return $model;
}
|
php
|
protected function handleFilterRequest($filters, $model)
{
foreach ($filters as $key=>$value) {
$model = $model->where($key, '=', $value);
}
return $model;
}
|
[
"protected",
"function",
"handleFilterRequest",
"(",
"$",
"filters",
",",
"$",
"model",
")",
"{",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"model",
"=",
"$",
"model",
"->",
"where",
"(",
"$",
"key",
",",
"'='",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] |
Function to handle filtering requests.
@param array $filters key=>value pairs of column and value to filter on
@param \EchoIt\JsonApi\Model $model
@return \EchoIt\JsonApi\Model
|
[
"Function",
"to",
"handle",
"filtering",
"requests",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L478-L484
|
226,634
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.handleGetDefault
|
protected function handleGetDefault(Request $request, $model)
{
$total = null;
if (empty($request->id)) {
if (!empty($request->filter)) {
$model = $this->handleFilterRequest($request->filter, $model);
}
if (!empty($request->sort)) {
//if sorting AND paginating, get total count before sorting!
if ($request->pageNumber) {
$total = $model->count();
}
$model = $this->handleSortRequest($request->sort, $model);
}
} else {
$model = $model->where($model->getKeyName(), '=', $request->id);
}
try {
if ($request->pageNumber && empty($request->id)) {
$results = $this->handlePaginationRequest($request, $model, $total);
} else {
$results = $model->get();
}
} catch (\Illuminate\Database\QueryException $e) {
throw new Exception(
'Database Request Failed',
static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
BaseResponse::HTTP_INTERNAL_SERVER_ERROR,
array('detail' => $e->getMessage())
);
}
return $results;
}
|
php
|
protected function handleGetDefault(Request $request, $model)
{
$total = null;
if (empty($request->id)) {
if (!empty($request->filter)) {
$model = $this->handleFilterRequest($request->filter, $model);
}
if (!empty($request->sort)) {
//if sorting AND paginating, get total count before sorting!
if ($request->pageNumber) {
$total = $model->count();
}
$model = $this->handleSortRequest($request->sort, $model);
}
} else {
$model = $model->where($model->getKeyName(), '=', $request->id);
}
try {
if ($request->pageNumber && empty($request->id)) {
$results = $this->handlePaginationRequest($request, $model, $total);
} else {
$results = $model->get();
}
} catch (\Illuminate\Database\QueryException $e) {
throw new Exception(
'Database Request Failed',
static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
BaseResponse::HTTP_INTERNAL_SERVER_ERROR,
array('detail' => $e->getMessage())
);
}
return $results;
}
|
[
"protected",
"function",
"handleGetDefault",
"(",
"Request",
"$",
"request",
",",
"$",
"model",
")",
"{",
"$",
"total",
"=",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"request",
"->",
"id",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"request",
"->",
"filter",
")",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"handleFilterRequest",
"(",
"$",
"request",
"->",
"filter",
",",
"$",
"model",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"request",
"->",
"sort",
")",
")",
"{",
"//if sorting AND paginating, get total count before sorting!",
"if",
"(",
"$",
"request",
"->",
"pageNumber",
")",
"{",
"$",
"total",
"=",
"$",
"model",
"->",
"count",
"(",
")",
";",
"}",
"$",
"model",
"=",
"$",
"this",
"->",
"handleSortRequest",
"(",
"$",
"request",
"->",
"sort",
",",
"$",
"model",
")",
";",
"}",
"}",
"else",
"{",
"$",
"model",
"=",
"$",
"model",
"->",
"where",
"(",
"$",
"model",
"->",
"getKeyName",
"(",
")",
",",
"'='",
",",
"$",
"request",
"->",
"id",
")",
";",
"}",
"try",
"{",
"if",
"(",
"$",
"request",
"->",
"pageNumber",
"&&",
"empty",
"(",
"$",
"request",
"->",
"id",
")",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"handlePaginationRequest",
"(",
"$",
"request",
",",
"$",
"model",
",",
"$",
"total",
")",
";",
"}",
"else",
"{",
"$",
"results",
"=",
"$",
"model",
"->",
"get",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"QueryException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Database Request Failed'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_UNKNOWN_ID",
",",
"BaseResponse",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
",",
"array",
"(",
"'detail'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] |
Default handling of GET request.
Must be called explicitly in handleGet function.
@param \EchoIt\JsonApi\Request $request
@param \EchoIt\JsonApi\Model $model
@return \EchoIt\JsonApi\Model|\Illuminate\Pagination\LengthAwarePaginator
@throws Exception
|
[
"Default",
"handling",
"of",
"GET",
"request",
".",
"Must",
"be",
"called",
"explicitly",
"in",
"handleGet",
"function",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L495-L528
|
226,635
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.validateModelData
|
protected function validateModelData(Model $model, Array $values)
{
$validationResponse = $model->validateArray($values);
if ($validationResponse === true) {
return true;
}
throw new Exception\Validation(
'Bad Request',
static::ERROR_SCOPE | static::ERROR_HTTP_METHOD_NOT_ALLOWED,
BaseResponse::HTTP_BAD_REQUEST,
$validationResponse
);
}
|
php
|
protected function validateModelData(Model $model, Array $values)
{
$validationResponse = $model->validateArray($values);
if ($validationResponse === true) {
return true;
}
throw new Exception\Validation(
'Bad Request',
static::ERROR_SCOPE | static::ERROR_HTTP_METHOD_NOT_ALLOWED,
BaseResponse::HTTP_BAD_REQUEST,
$validationResponse
);
}
|
[
"protected",
"function",
"validateModelData",
"(",
"Model",
"$",
"model",
",",
"Array",
"$",
"values",
")",
"{",
"$",
"validationResponse",
"=",
"$",
"model",
"->",
"validateArray",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"validationResponse",
"===",
"true",
")",
"{",
"return",
"true",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"Validation",
"(",
"'Bad Request'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_HTTP_METHOD_NOT_ALLOWED",
",",
"BaseResponse",
"::",
"HTTP_BAD_REQUEST",
",",
"$",
"validationResponse",
")",
";",
"}"
] |
Validates passed data against a model
Validation performed safely and only if model provides rules
@param \EchoIt\JsonApi\Model $model model to validate against
@param Array $values passed array of values
@throws Exception\Validation Exception thrown when validation fails
@return Bool true if validation successful
|
[
"Validates",
"passed",
"data",
"against",
"a",
"model",
"Validation",
"performed",
"safely",
"and",
"only",
"if",
"model",
"provides",
"rules"
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L541-L555
|
226,636
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.handlePostDefault
|
public function handlePostDefault(Request $request, $model)
{
$values = $this->parseRequestContent($request->content, $model->getResourceType());
$this->validateModelData($model, $values);
$model->fill($values);
if (!$model->save()) {
throw new Exception(
'An unknown error occurred',
static::ERROR_SCOPE | static::ERROR_UNKNOWN,
BaseResponse::HTTP_INTERNAL_SERVER_ERROR
);
}
return $model;
}
|
php
|
public function handlePostDefault(Request $request, $model)
{
$values = $this->parseRequestContent($request->content, $model->getResourceType());
$this->validateModelData($model, $values);
$model->fill($values);
if (!$model->save()) {
throw new Exception(
'An unknown error occurred',
static::ERROR_SCOPE | static::ERROR_UNKNOWN,
BaseResponse::HTTP_INTERNAL_SERVER_ERROR
);
}
return $model;
}
|
[
"public",
"function",
"handlePostDefault",
"(",
"Request",
"$",
"request",
",",
"$",
"model",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"parseRequestContent",
"(",
"$",
"request",
"->",
"content",
",",
"$",
"model",
"->",
"getResourceType",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateModelData",
"(",
"$",
"model",
",",
"$",
"values",
")",
";",
"$",
"model",
"->",
"fill",
"(",
"$",
"values",
")",
";",
"if",
"(",
"!",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'An unknown error occurred'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_UNKNOWN",
",",
"BaseResponse",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] |
Default handling of POST request.
Must be called explicitly in handlePost function.
@param \EchoIt\JsonApi\Request $request
@param \EchoIt\JsonApi\Model $model
@return \EchoIt\JsonApi\Model
@throws Exception
|
[
"Default",
"handling",
"of",
"POST",
"request",
".",
"Must",
"be",
"called",
"explicitly",
"in",
"handlePost",
"function",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L566-L582
|
226,637
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.handlePutDefault
|
public function handlePutDefault(Request $request, $model)
{
if (empty($request->id)) {
throw new Exception(
'No ID provided',
static::ERROR_SCOPE | static::ERROR_NO_ID,
BaseResponse::HTTP_BAD_REQUEST
);
}
$updates = $this->parseRequestContent($request->content, $model->getResourceType());
$model = $model::find($request->id);
if (is_null($model)) {
return null;
}
// fetch the original attributes
$originalAttributes = $model->getOriginal();
// apply our updates
$model->fill($updates);
// ensure we can get a succesful save
if (!$model->save()) {
throw new Exception(
'An unknown error occurred',
static::ERROR_SCOPE | static::ERROR_UNKNOWN,
BaseResponse::HTTP_INTERNAL_SERVER_ERROR
);
}
// fetch the current attributes (post save)
$newAttributes = $model->getAttributes();
// loop through the new attributes, and ensure they are identical
// to the original ones. if not, then we need to return the model
foreach ($newAttributes as $attribute => $value) {
if (! array_key_exists($attribute, $originalAttributes) || $value !== $originalAttributes[$attribute]) {
$model->markChanged();
break;
}
}
return $model;
}
|
php
|
public function handlePutDefault(Request $request, $model)
{
if (empty($request->id)) {
throw new Exception(
'No ID provided',
static::ERROR_SCOPE | static::ERROR_NO_ID,
BaseResponse::HTTP_BAD_REQUEST
);
}
$updates = $this->parseRequestContent($request->content, $model->getResourceType());
$model = $model::find($request->id);
if (is_null($model)) {
return null;
}
// fetch the original attributes
$originalAttributes = $model->getOriginal();
// apply our updates
$model->fill($updates);
// ensure we can get a succesful save
if (!$model->save()) {
throw new Exception(
'An unknown error occurred',
static::ERROR_SCOPE | static::ERROR_UNKNOWN,
BaseResponse::HTTP_INTERNAL_SERVER_ERROR
);
}
// fetch the current attributes (post save)
$newAttributes = $model->getAttributes();
// loop through the new attributes, and ensure they are identical
// to the original ones. if not, then we need to return the model
foreach ($newAttributes as $attribute => $value) {
if (! array_key_exists($attribute, $originalAttributes) || $value !== $originalAttributes[$attribute]) {
$model->markChanged();
break;
}
}
return $model;
}
|
[
"public",
"function",
"handlePutDefault",
"(",
"Request",
"$",
"request",
",",
"$",
"model",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"request",
"->",
"id",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'No ID provided'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_NO_ID",
",",
"BaseResponse",
"::",
"HTTP_BAD_REQUEST",
")",
";",
"}",
"$",
"updates",
"=",
"$",
"this",
"->",
"parseRequestContent",
"(",
"$",
"request",
"->",
"content",
",",
"$",
"model",
"->",
"getResourceType",
"(",
")",
")",
";",
"$",
"model",
"=",
"$",
"model",
"::",
"find",
"(",
"$",
"request",
"->",
"id",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"model",
")",
")",
"{",
"return",
"null",
";",
"}",
"// fetch the original attributes",
"$",
"originalAttributes",
"=",
"$",
"model",
"->",
"getOriginal",
"(",
")",
";",
"// apply our updates",
"$",
"model",
"->",
"fill",
"(",
"$",
"updates",
")",
";",
"// ensure we can get a succesful save",
"if",
"(",
"!",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'An unknown error occurred'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_UNKNOWN",
",",
"BaseResponse",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
")",
";",
"}",
"// fetch the current attributes (post save)",
"$",
"newAttributes",
"=",
"$",
"model",
"->",
"getAttributes",
"(",
")",
";",
"// loop through the new attributes, and ensure they are identical",
"// to the original ones. if not, then we need to return the model",
"foreach",
"(",
"$",
"newAttributes",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"attribute",
",",
"$",
"originalAttributes",
")",
"||",
"$",
"value",
"!==",
"$",
"originalAttributes",
"[",
"$",
"attribute",
"]",
")",
"{",
"$",
"model",
"->",
"markChanged",
"(",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"model",
";",
"}"
] |
Default handling of PUT request.
Must be called explicitly in handlePut function.
@param \EchoIt\JsonApi\Request $request
@param \EchoIt\JsonApi\Model $model
@return \EchoIt\JsonApi\Model
@throws Exception
|
[
"Default",
"handling",
"of",
"PUT",
"request",
".",
"Must",
"be",
"called",
"explicitly",
"in",
"handlePut",
"function",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L593-L638
|
226,638
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Handler.php
|
Handler.handleDeleteDefault
|
public function handleDeleteDefault(Request $request, $model)
{
if (empty($request->id)) {
throw new Exception(
'No ID provided',
static::ERROR_SCOPE | static::ERROR_NO_ID,
BaseResponse::HTTP_BAD_REQUEST
);
}
$model = $model::find($request->id);
if (is_null($model)) {
return null;
}
$model->delete();
return $model;
}
|
php
|
public function handleDeleteDefault(Request $request, $model)
{
if (empty($request->id)) {
throw new Exception(
'No ID provided',
static::ERROR_SCOPE | static::ERROR_NO_ID,
BaseResponse::HTTP_BAD_REQUEST
);
}
$model = $model::find($request->id);
if (is_null($model)) {
return null;
}
$model->delete();
return $model;
}
|
[
"public",
"function",
"handleDeleteDefault",
"(",
"Request",
"$",
"request",
",",
"$",
"model",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"request",
"->",
"id",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'No ID provided'",
",",
"static",
"::",
"ERROR_SCOPE",
"|",
"static",
"::",
"ERROR_NO_ID",
",",
"BaseResponse",
"::",
"HTTP_BAD_REQUEST",
")",
";",
"}",
"$",
"model",
"=",
"$",
"model",
"::",
"find",
"(",
"$",
"request",
"->",
"id",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"model",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"model",
"->",
"delete",
"(",
")",
";",
"return",
"$",
"model",
";",
"}"
] |
Default handling of DELETE request.
Must be called explicitly in handleDelete function.
@param \EchoIt\JsonApi\Request $request
@param \EchoIt\JsonApi\Model $model
@return \EchoIt\JsonApi\Model
@throws Exception
|
[
"Default",
"handling",
"of",
"DELETE",
"request",
".",
"Must",
"be",
"called",
"explicitly",
"in",
"handleDelete",
"function",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Handler.php#L649-L667
|
226,639
|
kevinkhill/FontAwesomePHP
|
src/FontAwesomeStack.php
|
FontAwesomeStack.on
|
public function on($icon, array $classes = array(), $style='fas')
{
if (is_string($icon) === false) {
throw new \InvalidArgumentException(
'Icon label must be a string.'
);
}
if (is_string($style) === false) {
throw new \InvalidArgumentException(
'The style label must be a string.'
);
}
if (!in_array($style, $this->STYLES)) {
throw new \InvalidArgumentException(
'Invalid style.'
);
}
$iconClasses = $icon . ' fa-stack-1x';
if (count($classes) > 0) {
foreach ($classes as $class) {
$iconClasses .= ' ' . $this->classMapper($class);
}
}
$this->bottomIcon = sprintf(self::ICON_HTML, $style, $iconClasses);
return $this;
}
|
php
|
public function on($icon, array $classes = array(), $style='fas')
{
if (is_string($icon) === false) {
throw new \InvalidArgumentException(
'Icon label must be a string.'
);
}
if (is_string($style) === false) {
throw new \InvalidArgumentException(
'The style label must be a string.'
);
}
if (!in_array($style, $this->STYLES)) {
throw new \InvalidArgumentException(
'Invalid style.'
);
}
$iconClasses = $icon . ' fa-stack-1x';
if (count($classes) > 0) {
foreach ($classes as $class) {
$iconClasses .= ' ' . $this->classMapper($class);
}
}
$this->bottomIcon = sprintf(self::ICON_HTML, $style, $iconClasses);
return $this;
}
|
[
"public",
"function",
"on",
"(",
"$",
"icon",
",",
"array",
"$",
"classes",
"=",
"array",
"(",
")",
",",
"$",
"style",
"=",
"'fas'",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"icon",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Icon label must be a string.'",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"style",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The style label must be a string.'",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"style",
",",
"$",
"this",
"->",
"STYLES",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid style.'",
")",
";",
"}",
"$",
"iconClasses",
"=",
"$",
"icon",
".",
"' fa-stack-1x'",
";",
"if",
"(",
"count",
"(",
"$",
"classes",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"iconClasses",
".=",
"' '",
".",
"$",
"this",
"->",
"classMapper",
"(",
"$",
"class",
")",
";",
"}",
"}",
"$",
"this",
"->",
"bottomIcon",
"=",
"sprintf",
"(",
"self",
"::",
"ICON_HTML",
",",
"$",
"style",
",",
"$",
"iconClasses",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Finishes the stack after created by the main FontAwesome class stack method
creates the stack object.
@param string $icon
@param string $style
@param array $classes
@return self
|
[
"Finishes",
"the",
"stack",
"after",
"created",
"by",
"the",
"main",
"FontAwesome",
"class",
"stack",
"method",
"creates",
"the",
"stack",
"object",
"."
] |
e7d12d7422b23a5c3a09715d9ca3e24ff811c073
|
https://github.com/kevinkhill/FontAwesomePHP/blob/e7d12d7422b23a5c3a09715d9ca3e24ff811c073/src/FontAwesomeStack.php#L88-L117
|
226,640
|
varspool/sphpdox
|
lib/Sphpdox/CommentParser.php
|
CommentParser.parse
|
protected function parse()
{
$content = $this->comment;
// Rewrite newlines
$content = preg_replace('/\r\n/', "\n", $content);
// Rewrite tabs
$content = preg_replace('/\t/', ' ', $content);
// Remove initial whitespace
$content = preg_replace('/^\s*/m', '', $content);
// Remove start and end comment markers
$content = preg_replace('/\s*\/\*\*#?@?\+?\s*/m', '', $content);
$content = preg_replace('/\s*\*\/\s*/m', '', $content);
// Remove start of line comment markers
$content = preg_replace('/^\* ?/m', '', $content);
// Split the comment into parts
$this->split($content);
}
|
php
|
protected function parse()
{
$content = $this->comment;
// Rewrite newlines
$content = preg_replace('/\r\n/', "\n", $content);
// Rewrite tabs
$content = preg_replace('/\t/', ' ', $content);
// Remove initial whitespace
$content = preg_replace('/^\s*/m', '', $content);
// Remove start and end comment markers
$content = preg_replace('/\s*\/\*\*#?@?\+?\s*/m', '', $content);
$content = preg_replace('/\s*\*\/\s*/m', '', $content);
// Remove start of line comment markers
$content = preg_replace('/^\* ?/m', '', $content);
// Split the comment into parts
$this->split($content);
}
|
[
"protected",
"function",
"parse",
"(",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"comment",
";",
"// Rewrite newlines",
"$",
"content",
"=",
"preg_replace",
"(",
"'/\\r\\n/'",
",",
"\"\\n\"",
",",
"$",
"content",
")",
";",
"// Rewrite tabs",
"$",
"content",
"=",
"preg_replace",
"(",
"'/\\t/'",
",",
"' '",
",",
"$",
"content",
")",
";",
"// Remove initial whitespace",
"$",
"content",
"=",
"preg_replace",
"(",
"'/^\\s*/m'",
",",
"''",
",",
"$",
"content",
")",
";",
"// Remove start and end comment markers",
"$",
"content",
"=",
"preg_replace",
"(",
"'/\\s*\\/\\*\\*#?@?\\+?\\s*/m'",
",",
"''",
",",
"$",
"content",
")",
";",
"$",
"content",
"=",
"preg_replace",
"(",
"'/\\s*\\*\\/\\s*/m'",
",",
"''",
",",
"$",
"content",
")",
";",
"// Remove start of line comment markers",
"$",
"content",
"=",
"preg_replace",
"(",
"'/^\\* ?/m'",
",",
"''",
",",
"$",
"content",
")",
";",
"// Split the comment into parts",
"$",
"this",
"->",
"split",
"(",
"$",
"content",
")",
";",
"}"
] |
Parses the docblock
|
[
"Parses",
"the",
"docblock"
] |
7867503e1fc0acc47b4512fbd89bf742e03f79ba
|
https://github.com/varspool/sphpdox/blob/7867503e1fc0acc47b4512fbd89bf742e03f79ba/lib/Sphpdox/CommentParser.php#L35-L57
|
226,641
|
varspool/sphpdox
|
lib/Sphpdox/CommentParser.php
|
CommentParser.getDescription
|
public function getDescription()
{
$description = $this->getShortDescription();
if ($this->hasLongDescription()) {
$description .= "\n\n" . $this->getLongDescription();
}
return $description;
}
|
php
|
public function getDescription()
{
$description = $this->getShortDescription();
if ($this->hasLongDescription()) {
$description .= "\n\n" . $this->getLongDescription();
}
return $description;
}
|
[
"public",
"function",
"getDescription",
"(",
")",
"{",
"$",
"description",
"=",
"$",
"this",
"->",
"getShortDescription",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasLongDescription",
"(",
")",
")",
"{",
"$",
"description",
".=",
"\"\\n\\n\"",
".",
"$",
"this",
"->",
"getLongDescription",
"(",
")",
";",
"}",
"return",
"$",
"description",
";",
"}"
] |
Gets the short and long description in the comment
The full comment if you like. If this docblock were processed,
the former paragraph and this one would be returned.
@return string
|
[
"Gets",
"the",
"short",
"and",
"long",
"description",
"in",
"the",
"comment"
] |
7867503e1fc0acc47b4512fbd89bf742e03f79ba
|
https://github.com/varspool/sphpdox/blob/7867503e1fc0acc47b4512fbd89bf742e03f79ba/lib/Sphpdox/CommentParser.php#L168-L175
|
226,642
|
loco/swizzle
|
src/SwaggerClient.php
|
SwaggerClient.factory
|
public static function factory(array $config = [])
{
// Swagger docs URI is required
$required = ['base_uri'];
if ($missing = array_diff($required, array_keys($config))) {
throw new \InvalidArgumentException('Config is missing the following keys: '.implode(', ', $missing));
}
$serviceConfig = json_decode(file_get_contents(__DIR__.'/Resources/service.json'), true);
// allow override of base_uri after it's been set by service description
if (isset($config['base_uri'])) {
$serviceConfig['baseUri'] = $config['base_uri'];
}
// describe service from included config file.
$description = new Description($serviceConfig);
// Prefix Loco identifier to user agent string
$config['headers']['User-Agent'] = $description->getName().'/'.$description->getApiVersion()
.' '.\GuzzleHttp\default_user_agent();
// Create a new instance of HTTP Client
$client = new Client($config);
// Create a new instance of self
return new self(
$client,
$description,
null,
new Deserializer($description, true)
);
}
|
php
|
public static function factory(array $config = [])
{
// Swagger docs URI is required
$required = ['base_uri'];
if ($missing = array_diff($required, array_keys($config))) {
throw new \InvalidArgumentException('Config is missing the following keys: '.implode(', ', $missing));
}
$serviceConfig = json_decode(file_get_contents(__DIR__.'/Resources/service.json'), true);
// allow override of base_uri after it's been set by service description
if (isset($config['base_uri'])) {
$serviceConfig['baseUri'] = $config['base_uri'];
}
// describe service from included config file.
$description = new Description($serviceConfig);
// Prefix Loco identifier to user agent string
$config['headers']['User-Agent'] = $description->getName().'/'.$description->getApiVersion()
.' '.\GuzzleHttp\default_user_agent();
// Create a new instance of HTTP Client
$client = new Client($config);
// Create a new instance of self
return new self(
$client,
$description,
null,
new Deserializer($description, true)
);
}
|
[
"public",
"static",
"function",
"factory",
"(",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"// Swagger docs URI is required",
"$",
"required",
"=",
"[",
"'base_uri'",
"]",
";",
"if",
"(",
"$",
"missing",
"=",
"array_diff",
"(",
"$",
"required",
",",
"array_keys",
"(",
"$",
"config",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Config is missing the following keys: '",
".",
"implode",
"(",
"', '",
",",
"$",
"missing",
")",
")",
";",
"}",
"$",
"serviceConfig",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"__DIR__",
".",
"'/Resources/service.json'",
")",
",",
"true",
")",
";",
"// allow override of base_uri after it's been set by service description",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'base_uri'",
"]",
")",
")",
"{",
"$",
"serviceConfig",
"[",
"'baseUri'",
"]",
"=",
"$",
"config",
"[",
"'base_uri'",
"]",
";",
"}",
"// describe service from included config file.",
"$",
"description",
"=",
"new",
"Description",
"(",
"$",
"serviceConfig",
")",
";",
"// Prefix Loco identifier to user agent string",
"$",
"config",
"[",
"'headers'",
"]",
"[",
"'User-Agent'",
"]",
"=",
"$",
"description",
"->",
"getName",
"(",
")",
".",
"'/'",
".",
"$",
"description",
"->",
"getApiVersion",
"(",
")",
".",
"' '",
".",
"\\",
"GuzzleHttp",
"\\",
"default_user_agent",
"(",
")",
";",
"// Create a new instance of HTTP Client",
"$",
"client",
"=",
"new",
"Client",
"(",
"$",
"config",
")",
";",
"// Create a new instance of self",
"return",
"new",
"self",
"(",
"$",
"client",
",",
"$",
"description",
",",
"null",
",",
"new",
"Deserializer",
"(",
"$",
"description",
",",
"true",
")",
")",
";",
"}"
] |
Factory method to create a new Swagger Docs client.
@param array $config Configuration data
@return SwaggerClient
@throws \InvalidArgumentException
|
[
"Factory",
"method",
"to",
"create",
"a",
"new",
"Swagger",
"Docs",
"client",
"."
] |
539db44bc2341f3da403582052b770686c86a516
|
https://github.com/loco/swizzle/blob/539db44bc2341f3da403582052b770686c86a516/src/SwaggerClient.php#L28-L58
|
226,643
|
oleglfed/laravel-ddd
|
src/LaravelDddServiceProvider.php
|
LaravelDddServiceProvider.register
|
public function register()
{
$this->config = $this->app->make('config');
$this->packages = $this->config->get('domains.user-binding');
$files = \File::allFiles(config_path('domains'));
foreach ($files as $file) {
if ($bindings = $this->config->get('domains.'.basename($file->getFilename(), '.php'))) {
if (array_has($bindings, 'providers')) {
$this->provideService(array_get($bindings, 'providers'));
}
if (array_has($bindings, 'repositories')) {
$this->provideRepositories(array_get($bindings, 'repositories'));
}
if (array_has($bindings, 'eloquent_repositories')) {
$this->provideEloquentRepositories(array_get($bindings, 'eloquent_repositories'));
}
}
}
if ($this->app->runningInConsole()) {
$this->commands([
GenerateDomain::class,
]);
}
}
|
php
|
public function register()
{
$this->config = $this->app->make('config');
$this->packages = $this->config->get('domains.user-binding');
$files = \File::allFiles(config_path('domains'));
foreach ($files as $file) {
if ($bindings = $this->config->get('domains.'.basename($file->getFilename(), '.php'))) {
if (array_has($bindings, 'providers')) {
$this->provideService(array_get($bindings, 'providers'));
}
if (array_has($bindings, 'repositories')) {
$this->provideRepositories(array_get($bindings, 'repositories'));
}
if (array_has($bindings, 'eloquent_repositories')) {
$this->provideEloquentRepositories(array_get($bindings, 'eloquent_repositories'));
}
}
}
if ($this->app->runningInConsole()) {
$this->commands([
GenerateDomain::class,
]);
}
}
|
[
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'config'",
")",
";",
"$",
"this",
"->",
"packages",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'domains.user-binding'",
")",
";",
"$",
"files",
"=",
"\\",
"File",
"::",
"allFiles",
"(",
"config_path",
"(",
"'domains'",
")",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"bindings",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'domains.'",
".",
"basename",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"'.php'",
")",
")",
")",
"{",
"if",
"(",
"array_has",
"(",
"$",
"bindings",
",",
"'providers'",
")",
")",
"{",
"$",
"this",
"->",
"provideService",
"(",
"array_get",
"(",
"$",
"bindings",
",",
"'providers'",
")",
")",
";",
"}",
"if",
"(",
"array_has",
"(",
"$",
"bindings",
",",
"'repositories'",
")",
")",
"{",
"$",
"this",
"->",
"provideRepositories",
"(",
"array_get",
"(",
"$",
"bindings",
",",
"'repositories'",
")",
")",
";",
"}",
"if",
"(",
"array_has",
"(",
"$",
"bindings",
",",
"'eloquent_repositories'",
")",
")",
"{",
"$",
"this",
"->",
"provideEloquentRepositories",
"(",
"array_get",
"(",
"$",
"bindings",
",",
"'eloquent_repositories'",
")",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"runningInConsole",
"(",
")",
")",
"{",
"$",
"this",
"->",
"commands",
"(",
"[",
"GenerateDomain",
"::",
"class",
",",
"]",
")",
";",
"}",
"}"
] |
Register the API doc commands.
@return void
|
[
"Register",
"the",
"API",
"doc",
"commands",
"."
] |
4e60759d29086fe041b2c158c8ae3a79eeeb70f7
|
https://github.com/oleglfed/laravel-ddd/blob/4e60759d29086fe041b2c158c8ae3a79eeeb70f7/src/LaravelDddServiceProvider.php#L24-L52
|
226,644
|
oleglfed/laravel-ddd
|
src/LaravelDddServiceProvider.php
|
LaravelDddServiceProvider.provideRepositories
|
private function provideRepositories(array $repositories)
{
foreach ($repositories as $name => $provider) {
$this->app->bind($name, $provider);
}
}
|
php
|
private function provideRepositories(array $repositories)
{
foreach ($repositories as $name => $provider) {
$this->app->bind($name, $provider);
}
}
|
[
"private",
"function",
"provideRepositories",
"(",
"array",
"$",
"repositories",
")",
"{",
"foreach",
"(",
"$",
"repositories",
"as",
"$",
"name",
"=>",
"$",
"provider",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"$",
"name",
",",
"$",
"provider",
")",
";",
"}",
"}"
] |
Provide repositories from packages.
@param array $repositories
@return void
|
[
"Provide",
"repositories",
"from",
"packages",
"."
] |
4e60759d29086fe041b2c158c8ae3a79eeeb70f7
|
https://github.com/oleglfed/laravel-ddd/blob/4e60759d29086fe041b2c158c8ae3a79eeeb70f7/src/LaravelDddServiceProvider.php#L85-L90
|
226,645
|
phergie/phergie-irc-bot-react
|
src/PluginProcessor/EventEmitterInjector.php
|
EventEmitterInjector.process
|
public function process(PluginInterface $plugin, Bot $bot)
{
if ($plugin instanceof EventEmitterAwareInterface) {
$plugin->setEventEmitter($bot->getClient());
}
}
|
php
|
public function process(PluginInterface $plugin, Bot $bot)
{
if ($plugin instanceof EventEmitterAwareInterface) {
$plugin->setEventEmitter($bot->getClient());
}
}
|
[
"public",
"function",
"process",
"(",
"PluginInterface",
"$",
"plugin",
",",
"Bot",
"$",
"bot",
")",
"{",
"if",
"(",
"$",
"plugin",
"instanceof",
"EventEmitterAwareInterface",
")",
"{",
"$",
"plugin",
"->",
"setEventEmitter",
"(",
"$",
"bot",
"->",
"getClient",
"(",
")",
")",
";",
"}",
"}"
] |
Injects the bot's event emitter into the plugin if it implements
\Phergie\Irc\Bot\React\EventEmitterAwareInterface.
@param \Phergie\Irc\Bot\React\PluginInterface $plugin Loaded plugin
@param \Phergie\Irc\Bot\React\Bot $bot Bot that loaded the plugin
|
[
"Injects",
"the",
"bot",
"s",
"event",
"emitter",
"into",
"the",
"plugin",
"if",
"it",
"implements",
"\\",
"Phergie",
"\\",
"Irc",
"\\",
"Bot",
"\\",
"React",
"\\",
"EventEmitterAwareInterface",
"."
] |
17745ef6b846513258af3dbd86e5612d3deb19b7
|
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/PluginProcessor/EventEmitterInjector.php#L33-L38
|
226,646
|
oleglfed/laravel-ddd
|
src/Traits/GeneratorTrait.php
|
GeneratorTrait.getAppNamespace
|
protected function getAppNamespace()
{
$composer = json_decode(file_get_contents(base_path().'/composer.json'), true);
foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) {
foreach ((array) $path as $pathChoice) {
if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) {
return $namespace;
}
}
}
throw new \RuntimeException('Unable to detect application namespace.');
}
|
php
|
protected function getAppNamespace()
{
$composer = json_decode(file_get_contents(base_path().'/composer.json'), true);
foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) {
foreach ((array) $path as $pathChoice) {
if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) {
return $namespace;
}
}
}
throw new \RuntimeException('Unable to detect application namespace.');
}
|
[
"protected",
"function",
"getAppNamespace",
"(",
")",
"{",
"$",
"composer",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"base_path",
"(",
")",
".",
"'/composer.json'",
")",
",",
"true",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"data_get",
"(",
"$",
"composer",
",",
"'autoload.psr-4'",
")",
"as",
"$",
"namespace",
"=>",
"$",
"path",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"path",
"as",
"$",
"pathChoice",
")",
"{",
"if",
"(",
"realpath",
"(",
"app_path",
"(",
")",
")",
"==",
"realpath",
"(",
"base_path",
"(",
")",
".",
"'/'",
".",
"$",
"pathChoice",
")",
")",
"{",
"return",
"$",
"namespace",
";",
"}",
"}",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to detect application namespace.'",
")",
";",
"}"
] |
Returns App namespace.
@return int|string
|
[
"Returns",
"App",
"namespace",
"."
] |
4e60759d29086fe041b2c158c8ae3a79eeeb70f7
|
https://github.com/oleglfed/laravel-ddd/blob/4e60759d29086fe041b2c158c8ae3a79eeeb70f7/src/Traits/GeneratorTrait.php#L298-L311
|
226,647
|
phergie/phergie-irc-bot-react
|
src/AbstractPlugin.php
|
AbstractPlugin.escapeParam
|
public function escapeParam($string)
{
foreach ([ "\r\n", "\r", "\n" ] as $badBytes) {
if (false !== strpos($string, $badBytes)) {
$string = str_replace($badBytes, " ", $string);
}
}
if (false !== strpos($string, "\0")) {
$string = str_replace("\0", "", $string);
}
return $string;
}
|
php
|
public function escapeParam($string)
{
foreach ([ "\r\n", "\r", "\n" ] as $badBytes) {
if (false !== strpos($string, $badBytes)) {
$string = str_replace($badBytes, " ", $string);
}
}
if (false !== strpos($string, "\0")) {
$string = str_replace("\0", "", $string);
}
return $string;
}
|
[
"public",
"function",
"escapeParam",
"(",
"$",
"string",
")",
"{",
"foreach",
"(",
"[",
"\"\\r\\n\"",
",",
"\"\\r\"",
",",
"\"\\n\"",
"]",
"as",
"$",
"badBytes",
")",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"string",
",",
"$",
"badBytes",
")",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"badBytes",
",",
"\" \"",
",",
"$",
"string",
")",
";",
"}",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"string",
",",
"\"\\0\"",
")",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"\"\\0\"",
",",
"\"\"",
",",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] |
Replaces bytes in a string that might cause it to be truncated or
otherwise misinterpreted by the server.
@param string $string
@return string
|
[
"Replaces",
"bytes",
"in",
"a",
"string",
"that",
"might",
"cause",
"it",
"to",
"be",
"truncated",
"or",
"otherwise",
"misinterpreted",
"by",
"the",
"server",
"."
] |
17745ef6b846513258af3dbd86e5612d3deb19b7
|
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/AbstractPlugin.php#L178-L191
|
226,648
|
varspool/sphpdox
|
lib/Sphpdox/Element/MethodElement.php
|
MethodElement.getParameterInfo
|
protected function getParameterInfo()
{
$params = array();
$parameters = $this->reflection->getParameters();
foreach ($parameters as $parameter) {
$params[$parameter->getName()] = array(
'name' => $parameter->getName(),
'hint_type' => $parameter->getOriginalTypeHint(),
'type' => $parameter->getOriginalTypeHint(),
'comment' => null
);
if ($parameter->isDefaultValueAvailable()) {
try {
$params[$parameter->getName()]['default'] = trim($parameter->getDefaultValueDefinition());
} catch (\Exception\RuntimeException $e) {
// Just don't provide a default
}
}
}
$annotations = array_filter($this->getParser()->getAnnotations(), function ($v) {
$e = explode(' ', $v);
return isset($e[0]) && $e[0] == '@param';
});
foreach ($annotations as $parameter) {
$parts = explode(' ', $parameter);
if (count($parts) < 3) {
continue;
}
$type = trim($parts[1]);
$name = trim(str_replace('$', '', $parts[2]));
$comment = trim(implode(' ', array_slice($parts, 3)));
if (isset($params[$name])) {
if ($params[$name]['type'] == null && $type) {
$params[$name]['type'] = $type;
}
if ($comment) {
$params[$name]['comment'] = $comment;
}
}
}
return $params;
}
|
php
|
protected function getParameterInfo()
{
$params = array();
$parameters = $this->reflection->getParameters();
foreach ($parameters as $parameter) {
$params[$parameter->getName()] = array(
'name' => $parameter->getName(),
'hint_type' => $parameter->getOriginalTypeHint(),
'type' => $parameter->getOriginalTypeHint(),
'comment' => null
);
if ($parameter->isDefaultValueAvailable()) {
try {
$params[$parameter->getName()]['default'] = trim($parameter->getDefaultValueDefinition());
} catch (\Exception\RuntimeException $e) {
// Just don't provide a default
}
}
}
$annotations = array_filter($this->getParser()->getAnnotations(), function ($v) {
$e = explode(' ', $v);
return isset($e[0]) && $e[0] == '@param';
});
foreach ($annotations as $parameter) {
$parts = explode(' ', $parameter);
if (count($parts) < 3) {
continue;
}
$type = trim($parts[1]);
$name = trim(str_replace('$', '', $parts[2]));
$comment = trim(implode(' ', array_slice($parts, 3)));
if (isset($params[$name])) {
if ($params[$name]['type'] == null && $type) {
$params[$name]['type'] = $type;
}
if ($comment) {
$params[$name]['comment'] = $comment;
}
}
}
return $params;
}
|
[
"protected",
"function",
"getParameterInfo",
"(",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"parameters",
"=",
"$",
"this",
"->",
"reflection",
"->",
"getParameters",
"(",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"$",
"params",
"[",
"$",
"parameter",
"->",
"getName",
"(",
")",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"parameter",
"->",
"getName",
"(",
")",
",",
"'hint_type'",
"=>",
"$",
"parameter",
"->",
"getOriginalTypeHint",
"(",
")",
",",
"'type'",
"=>",
"$",
"parameter",
"->",
"getOriginalTypeHint",
"(",
")",
",",
"'comment'",
"=>",
"null",
")",
";",
"if",
"(",
"$",
"parameter",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"try",
"{",
"$",
"params",
"[",
"$",
"parameter",
"->",
"getName",
"(",
")",
"]",
"[",
"'default'",
"]",
"=",
"trim",
"(",
"$",
"parameter",
"->",
"getDefaultValueDefinition",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"\\",
"RuntimeException",
"$",
"e",
")",
"{",
"// Just don't provide a default",
"}",
"}",
"}",
"$",
"annotations",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"getParser",
"(",
")",
"->",
"getAnnotations",
"(",
")",
",",
"function",
"(",
"$",
"v",
")",
"{",
"$",
"e",
"=",
"explode",
"(",
"' '",
",",
"$",
"v",
")",
";",
"return",
"isset",
"(",
"$",
"e",
"[",
"0",
"]",
")",
"&&",
"$",
"e",
"[",
"0",
"]",
"==",
"'@param'",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"annotations",
"as",
"$",
"parameter",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"' '",
",",
"$",
"parameter",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"<",
"3",
")",
"{",
"continue",
";",
"}",
"$",
"type",
"=",
"trim",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"$",
"name",
"=",
"trim",
"(",
"str_replace",
"(",
"'$'",
",",
"''",
",",
"$",
"parts",
"[",
"2",
"]",
")",
")",
";",
"$",
"comment",
"=",
"trim",
"(",
"implode",
"(",
"' '",
",",
"array_slice",
"(",
"$",
"parts",
",",
"3",
")",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"$",
"params",
"[",
"$",
"name",
"]",
"[",
"'type'",
"]",
"==",
"null",
"&&",
"$",
"type",
")",
"{",
"$",
"params",
"[",
"$",
"name",
"]",
"[",
"'type'",
"]",
"=",
"$",
"type",
";",
"}",
"if",
"(",
"$",
"comment",
")",
"{",
"$",
"params",
"[",
"$",
"name",
"]",
"[",
"'comment'",
"]",
"=",
"$",
"comment",
";",
"}",
"}",
"}",
"return",
"$",
"params",
";",
"}"
] |
Gets an array of simplified information about the parameters of this
method
@return array
|
[
"Gets",
"an",
"array",
"of",
"simplified",
"information",
"about",
"the",
"parameters",
"of",
"this",
"method"
] |
7867503e1fc0acc47b4512fbd89bf742e03f79ba
|
https://github.com/varspool/sphpdox/blob/7867503e1fc0acc47b4512fbd89bf742e03f79ba/lib/Sphpdox/Element/MethodElement.php#L29-L77
|
226,649
|
varspool/sphpdox
|
lib/Sphpdox/Element/MethodElement.php
|
MethodElement.getParameters
|
protected function getParameters()
{
$strings = array();
foreach ($this->getParameterInfo() as $name => $parameter) {
if ($parameter['type']) {
$strings[] = ':type $' . $name . ': ' . $parameter['type'];
}
$string = ':param $' . $name . ':';
if (isset($parameter['comment']) && $parameter['comment']) {
$string .= ' ' . $parameter['comment'];
}
$strings[] = $string;
}
return $strings;
}
|
php
|
protected function getParameters()
{
$strings = array();
foreach ($this->getParameterInfo() as $name => $parameter) {
if ($parameter['type']) {
$strings[] = ':type $' . $name . ': ' . $parameter['type'];
}
$string = ':param $' . $name . ':';
if (isset($parameter['comment']) && $parameter['comment']) {
$string .= ' ' . $parameter['comment'];
}
$strings[] = $string;
}
return $strings;
}
|
[
"protected",
"function",
"getParameters",
"(",
")",
"{",
"$",
"strings",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getParameterInfo",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"parameter",
")",
"{",
"if",
"(",
"$",
"parameter",
"[",
"'type'",
"]",
")",
"{",
"$",
"strings",
"[",
"]",
"=",
"':type $'",
".",
"$",
"name",
".",
"': '",
".",
"$",
"parameter",
"[",
"'type'",
"]",
";",
"}",
"$",
"string",
"=",
"':param $'",
".",
"$",
"name",
".",
"':'",
";",
"if",
"(",
"isset",
"(",
"$",
"parameter",
"[",
"'comment'",
"]",
")",
"&&",
"$",
"parameter",
"[",
"'comment'",
"]",
")",
"{",
"$",
"string",
".=",
"' '",
".",
"$",
"parameter",
"[",
"'comment'",
"]",
";",
"}",
"$",
"strings",
"[",
"]",
"=",
"$",
"string",
";",
"}",
"return",
"$",
"strings",
";",
"}"
] |
Gets an array of parameter information, in ReST format
@return array
|
[
"Gets",
"an",
"array",
"of",
"parameter",
"information",
"in",
"ReST",
"format"
] |
7867503e1fc0acc47b4512fbd89bf742e03f79ba
|
https://github.com/varspool/sphpdox/blob/7867503e1fc0acc47b4512fbd89bf742e03f79ba/lib/Sphpdox/Element/MethodElement.php#L115-L134
|
226,650
|
varspool/sphpdox
|
lib/Sphpdox/Element/MethodElement.php
|
MethodElement.getReturnValue
|
protected function getReturnValue()
{
$annotations = array_filter($this->getParser()->getAnnotations(), function ($v) {
$e = explode(' ', $v);
return isset($e[0]) && $e[0] == '@return';
});
foreach ($annotations as $parameter) {
$parts = explode(' ', $parameter);
if (count($parts) < 2) {
continue;
}
$type = array_slice($parts, 1, 1);
$type = $type[0];
$comment = implode(' ', array_slice($parts, 2));
$string = ':returns:';
return sprintf(
':returns: %s%s',
$type ?: 'unknown',
$comment ? ' ' . $comment : ''
);
}
return false;
}
|
php
|
protected function getReturnValue()
{
$annotations = array_filter($this->getParser()->getAnnotations(), function ($v) {
$e = explode(' ', $v);
return isset($e[0]) && $e[0] == '@return';
});
foreach ($annotations as $parameter) {
$parts = explode(' ', $parameter);
if (count($parts) < 2) {
continue;
}
$type = array_slice($parts, 1, 1);
$type = $type[0];
$comment = implode(' ', array_slice($parts, 2));
$string = ':returns:';
return sprintf(
':returns: %s%s',
$type ?: 'unknown',
$comment ? ' ' . $comment : ''
);
}
return false;
}
|
[
"protected",
"function",
"getReturnValue",
"(",
")",
"{",
"$",
"annotations",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"getParser",
"(",
")",
"->",
"getAnnotations",
"(",
")",
",",
"function",
"(",
"$",
"v",
")",
"{",
"$",
"e",
"=",
"explode",
"(",
"' '",
",",
"$",
"v",
")",
";",
"return",
"isset",
"(",
"$",
"e",
"[",
"0",
"]",
")",
"&&",
"$",
"e",
"[",
"0",
"]",
"==",
"'@return'",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"annotations",
"as",
"$",
"parameter",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"' '",
",",
"$",
"parameter",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"<",
"2",
")",
"{",
"continue",
";",
"}",
"$",
"type",
"=",
"array_slice",
"(",
"$",
"parts",
",",
"1",
",",
"1",
")",
";",
"$",
"type",
"=",
"$",
"type",
"[",
"0",
"]",
";",
"$",
"comment",
"=",
"implode",
"(",
"' '",
",",
"array_slice",
"(",
"$",
"parts",
",",
"2",
")",
")",
";",
"$",
"string",
"=",
"':returns:'",
";",
"return",
"sprintf",
"(",
"':returns: %s%s'",
",",
"$",
"type",
"?",
":",
"'unknown'",
",",
"$",
"comment",
"?",
"' '",
".",
"$",
"comment",
":",
"''",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Gets the return value ReST notation
@return boolean|string
|
[
"Gets",
"the",
"return",
"value",
"ReST",
"notation"
] |
7867503e1fc0acc47b4512fbd89bf742e03f79ba
|
https://github.com/varspool/sphpdox/blob/7867503e1fc0acc47b4512fbd89bf742e03f79ba/lib/Sphpdox/Element/MethodElement.php#L141-L169
|
226,651
|
gigaai/framework
|
src/Storage/Eloquent/Node.php
|
Node.findByTypeAndPattern
|
public static function findByTypeAndPattern($type = '', $pattern = '')
{
$where = '1 = 1';
$where_type = '';
$where_like = '';
$where_rlike = '';
$placeholder = [];
// Check type, pattern is email or phone number when passing from quick replies
if ($type === 'payload') {
$pattern = filter_var($pattern, FILTER_VALIDATE_EMAIL) ? 'user_email' : $pattern;
$pattern = is_phone_number($pattern) ? 'user_phone_number' : $pattern;
}
if (!empty($type)) {
$where_type = ' AND type = :type';
$placeholder[':type'] = $type;
}
if (!empty($pattern)) {
$placeholder[':pattern'] = $pattern;
$where_like = ' AND :pattern LIKE pattern';
$where_rlike = " AND :pattern RLIKE CONCAT('^',pattern,'$')";
}
$columns = ['type', 'pattern', 'answers', 'wait', 'sources', 'messaging_type', 'notification_type'];
// Where Like First
$nodes = self::whereRaw($where . $where_type . $where_like, $placeholder)->get($columns);
// If Not Found. Then Where Rlike
if ($nodes->count() === 0) {
$nodes = self::whereRaw($where . $where_type . $where_rlike, $placeholder)->get($columns);
}
// If still not found, then try NLP and find
if ($nodes->count() === 0 && Conversation::has('nlp')) {
$entities = Conversation::get('nlp')->getNames();
if (! empty($entities)) {
$entities = '#' . ltrim(implode('|#', $entities), '|');
$nodes = self::whereRaw('pattern RLIKE :pattern', [
':pattern' => $entities,
])->get($columns);
// Enable nodes filter. Available types: first, last, any. Default: first
$nodes = $nodes->filter(function ($node) {
return Conversation::get('nlp')->filter($node->pattern)->exists();
});
}
}
return $nodes;
}
|
php
|
public static function findByTypeAndPattern($type = '', $pattern = '')
{
$where = '1 = 1';
$where_type = '';
$where_like = '';
$where_rlike = '';
$placeholder = [];
// Check type, pattern is email or phone number when passing from quick replies
if ($type === 'payload') {
$pattern = filter_var($pattern, FILTER_VALIDATE_EMAIL) ? 'user_email' : $pattern;
$pattern = is_phone_number($pattern) ? 'user_phone_number' : $pattern;
}
if (!empty($type)) {
$where_type = ' AND type = :type';
$placeholder[':type'] = $type;
}
if (!empty($pattern)) {
$placeholder[':pattern'] = $pattern;
$where_like = ' AND :pattern LIKE pattern';
$where_rlike = " AND :pattern RLIKE CONCAT('^',pattern,'$')";
}
$columns = ['type', 'pattern', 'answers', 'wait', 'sources', 'messaging_type', 'notification_type'];
// Where Like First
$nodes = self::whereRaw($where . $where_type . $where_like, $placeholder)->get($columns);
// If Not Found. Then Where Rlike
if ($nodes->count() === 0) {
$nodes = self::whereRaw($where . $where_type . $where_rlike, $placeholder)->get($columns);
}
// If still not found, then try NLP and find
if ($nodes->count() === 0 && Conversation::has('nlp')) {
$entities = Conversation::get('nlp')->getNames();
if (! empty($entities)) {
$entities = '#' . ltrim(implode('|#', $entities), '|');
$nodes = self::whereRaw('pattern RLIKE :pattern', [
':pattern' => $entities,
])->get($columns);
// Enable nodes filter. Available types: first, last, any. Default: first
$nodes = $nodes->filter(function ($node) {
return Conversation::get('nlp')->filter($node->pattern)->exists();
});
}
}
return $nodes;
}
|
[
"public",
"static",
"function",
"findByTypeAndPattern",
"(",
"$",
"type",
"=",
"''",
",",
"$",
"pattern",
"=",
"''",
")",
"{",
"$",
"where",
"=",
"'1 = 1'",
";",
"$",
"where_type",
"=",
"''",
";",
"$",
"where_like",
"=",
"''",
";",
"$",
"where_rlike",
"=",
"''",
";",
"$",
"placeholder",
"=",
"[",
"]",
";",
"// Check type, pattern is email or phone number when passing from quick replies",
"if",
"(",
"$",
"type",
"===",
"'payload'",
")",
"{",
"$",
"pattern",
"=",
"filter_var",
"(",
"$",
"pattern",
",",
"FILTER_VALIDATE_EMAIL",
")",
"?",
"'user_email'",
":",
"$",
"pattern",
";",
"$",
"pattern",
"=",
"is_phone_number",
"(",
"$",
"pattern",
")",
"?",
"'user_phone_number'",
":",
"$",
"pattern",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"$",
"where_type",
"=",
"' AND type = :type'",
";",
"$",
"placeholder",
"[",
"':type'",
"]",
"=",
"$",
"type",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"pattern",
")",
")",
"{",
"$",
"placeholder",
"[",
"':pattern'",
"]",
"=",
"$",
"pattern",
";",
"$",
"where_like",
"=",
"' AND :pattern LIKE pattern'",
";",
"$",
"where_rlike",
"=",
"\" AND :pattern RLIKE CONCAT('^',pattern,'$')\"",
";",
"}",
"$",
"columns",
"=",
"[",
"'type'",
",",
"'pattern'",
",",
"'answers'",
",",
"'wait'",
",",
"'sources'",
",",
"'messaging_type'",
",",
"'notification_type'",
"]",
";",
"// Where Like First",
"$",
"nodes",
"=",
"self",
"::",
"whereRaw",
"(",
"$",
"where",
".",
"$",
"where_type",
".",
"$",
"where_like",
",",
"$",
"placeholder",
")",
"->",
"get",
"(",
"$",
"columns",
")",
";",
"// If Not Found. Then Where Rlike",
"if",
"(",
"$",
"nodes",
"->",
"count",
"(",
")",
"===",
"0",
")",
"{",
"$",
"nodes",
"=",
"self",
"::",
"whereRaw",
"(",
"$",
"where",
".",
"$",
"where_type",
".",
"$",
"where_rlike",
",",
"$",
"placeholder",
")",
"->",
"get",
"(",
"$",
"columns",
")",
";",
"}",
"// If still not found, then try NLP and find",
"if",
"(",
"$",
"nodes",
"->",
"count",
"(",
")",
"===",
"0",
"&&",
"Conversation",
"::",
"has",
"(",
"'nlp'",
")",
")",
"{",
"$",
"entities",
"=",
"Conversation",
"::",
"get",
"(",
"'nlp'",
")",
"->",
"getNames",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"entities",
")",
")",
"{",
"$",
"entities",
"=",
"'#'",
".",
"ltrim",
"(",
"implode",
"(",
"'|#'",
",",
"$",
"entities",
")",
",",
"'|'",
")",
";",
"$",
"nodes",
"=",
"self",
"::",
"whereRaw",
"(",
"'pattern RLIKE :pattern'",
",",
"[",
"':pattern'",
"=>",
"$",
"entities",
",",
"]",
")",
"->",
"get",
"(",
"$",
"columns",
")",
";",
"// Enable nodes filter. Available types: first, last, any. Default: first",
"$",
"nodes",
"=",
"$",
"nodes",
"->",
"filter",
"(",
"function",
"(",
"$",
"node",
")",
"{",
"return",
"Conversation",
"::",
"get",
"(",
"'nlp'",
")",
"->",
"filter",
"(",
"$",
"node",
"->",
"pattern",
")",
"->",
"exists",
"(",
")",
";",
"}",
")",
";",
"}",
"}",
"return",
"$",
"nodes",
";",
"}"
] |
Get node by node type and pattern
@param $type
@param $pattern
@return Node[]
|
[
"Get",
"node",
"by",
"node",
"type",
"and",
"pattern"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Storage/Eloquent/Node.php#L42-L97
|
226,652
|
gigaai/framework
|
src/Storage/Eloquent/Node.php
|
Node.setAnswersAttribute
|
public function setAnswersAttribute($value)
{
if (is_array($value)) {
$value = giga_array_filter($value);
$this->attributes['answers'] = json_encode($value, JSON_UNESCAPED_UNICODE);
} else {
$this->attributes['answers'] = $value;
}
}
|
php
|
public function setAnswersAttribute($value)
{
if (is_array($value)) {
$value = giga_array_filter($value);
$this->attributes['answers'] = json_encode($value, JSON_UNESCAPED_UNICODE);
} else {
$this->attributes['answers'] = $value;
}
}
|
[
"public",
"function",
"setAnswersAttribute",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"giga_array_filter",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"attributes",
"[",
"'answers'",
"]",
"=",
"json_encode",
"(",
"$",
"value",
",",
"JSON_UNESCAPED_UNICODE",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"attributes",
"[",
"'answers'",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] |
Auto json encode the answers attribute
@param $value
|
[
"Auto",
"json",
"encode",
"the",
"answers",
"attribute"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Storage/Eloquent/Node.php#L163-L171
|
226,653
|
netgen/NetgenEzFormsBundle
|
bundle/Form/FieldTypeHandler.php
|
FieldTypeHandler.skipEmptyUpdate
|
protected function skipEmptyUpdate(FormBuilderInterface $formBuilder, $fieldDefinitionIdentifier)
{
$options = array(
'mapped' => false,
'data' => 'yes',
);
$formBuilder->add(
"ezforms_skip_empty_update_{$fieldDefinitionIdentifier}",
HiddenType::class,
$options
);
}
|
php
|
protected function skipEmptyUpdate(FormBuilderInterface $formBuilder, $fieldDefinitionIdentifier)
{
$options = array(
'mapped' => false,
'data' => 'yes',
);
$formBuilder->add(
"ezforms_skip_empty_update_{$fieldDefinitionIdentifier}",
HiddenType::class,
$options
);
}
|
[
"protected",
"function",
"skipEmptyUpdate",
"(",
"FormBuilderInterface",
"$",
"formBuilder",
",",
"$",
"fieldDefinitionIdentifier",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'mapped'",
"=>",
"false",
",",
"'data'",
"=>",
"'yes'",
",",
")",
";",
"$",
"formBuilder",
"->",
"add",
"(",
"\"ezforms_skip_empty_update_{$fieldDefinitionIdentifier}\"",
",",
"HiddenType",
"::",
"class",
",",
"$",
"options",
")",
";",
"}"
] |
Adds a hidden field to the from, indicating that empty value passed
for update should be ignored.
@param \Symfony\Component\Form\FormBuilderInterface $formBuilder
@param string $fieldDefinitionIdentifier
|
[
"Adds",
"a",
"hidden",
"field",
"to",
"the",
"from",
"indicating",
"that",
"empty",
"value",
"passed",
"for",
"update",
"should",
"be",
"ignored",
"."
] |
c4d2355e14a41353ac40eafc386f203b3d94ea9e
|
https://github.com/netgen/NetgenEzFormsBundle/blob/c4d2355e14a41353ac40eafc386f203b3d94ea9e/bundle/Form/FieldTypeHandler.php#L126-L138
|
226,654
|
gigaai/framework
|
src/Core/AccountLinking.php
|
AccountLinking.process
|
public static function process($event)
{
// Link Lead with User
if ($event->account_linking->status === 'linked') {
$authorization_code = $event->account_linking->authorization_code;
$user_id = str_replace('user_id:', '', $authorization_code);
return self::linkWithExistingUser($event->sender->id, $user_id);
} // Unlink, Logout user
return self::unlinkWithExistingUser($event->sender->id);
}
|
php
|
public static function process($event)
{
// Link Lead with User
if ($event->account_linking->status === 'linked') {
$authorization_code = $event->account_linking->authorization_code;
$user_id = str_replace('user_id:', '', $authorization_code);
return self::linkWithExistingUser($event->sender->id, $user_id);
} // Unlink, Logout user
return self::unlinkWithExistingUser($event->sender->id);
}
|
[
"public",
"static",
"function",
"process",
"(",
"$",
"event",
")",
"{",
"// Link Lead with User",
"if",
"(",
"$",
"event",
"->",
"account_linking",
"->",
"status",
"===",
"'linked'",
")",
"{",
"$",
"authorization_code",
"=",
"$",
"event",
"->",
"account_linking",
"->",
"authorization_code",
";",
"$",
"user_id",
"=",
"str_replace",
"(",
"'user_id:'",
",",
"''",
",",
"$",
"authorization_code",
")",
";",
"return",
"self",
"::",
"linkWithExistingUser",
"(",
"$",
"event",
"->",
"sender",
"->",
"id",
",",
"$",
"user_id",
")",
";",
"}",
"// Unlink, Logout user",
"return",
"self",
"::",
"unlinkWithExistingUser",
"(",
"$",
"event",
"->",
"sender",
"->",
"id",
")",
";",
"}"
] |
Process the account linking
@param Array $event
@return bool
|
[
"Process",
"the",
"account",
"linking"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Core/AccountLinking.php#L15-L26
|
226,655
|
gigaai/framework
|
src/Drivers/Driver.php
|
Driver.detect
|
public function detect($request)
{
// Facebook driver by default
$this->driver = new Facebook;
// Loop through all available drivers
foreach ($this->drivers as $driver_class) {
// If driver format matches understand the request, then create new instance
if ((new $driver_class)->expectedFormat($request)) {
$this->driver = new $driver_class;
break;
}
}
}
|
php
|
public function detect($request)
{
// Facebook driver by default
$this->driver = new Facebook;
// Loop through all available drivers
foreach ($this->drivers as $driver_class) {
// If driver format matches understand the request, then create new instance
if ((new $driver_class)->expectedFormat($request)) {
$this->driver = new $driver_class;
break;
}
}
}
|
[
"public",
"function",
"detect",
"(",
"$",
"request",
")",
"{",
"// Facebook driver by default",
"$",
"this",
"->",
"driver",
"=",
"new",
"Facebook",
";",
"// Loop through all available drivers",
"foreach",
"(",
"$",
"this",
"->",
"drivers",
"as",
"$",
"driver_class",
")",
"{",
"// If driver format matches understand the request, then create new instance",
"if",
"(",
"(",
"new",
"$",
"driver_class",
")",
"->",
"expectedFormat",
"(",
"$",
"request",
")",
")",
"{",
"$",
"this",
"->",
"driver",
"=",
"new",
"$",
"driver_class",
";",
"break",
";",
"}",
"}",
"}"
] |
Detect driver based on incoming request
@param Array $request
@return void
|
[
"Detect",
"driver",
"based",
"on",
"incoming",
"request"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Driver.php#L36-L49
|
226,656
|
gigaai/framework
|
src/Drivers/Driver.php
|
Driver.run
|
public function run(&$request)
{
$this->detect($request);
$request = $this->driver->formatIncomingRequest($request);
}
|
php
|
public function run(&$request)
{
$this->detect($request);
$request = $this->driver->formatIncomingRequest($request);
}
|
[
"public",
"function",
"run",
"(",
"&",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"detect",
"(",
"$",
"request",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"driver",
"->",
"formatIncomingRequest",
"(",
"$",
"request",
")",
";",
"}"
] |
Detect the driver and format the request to Facebook format
@param Mixed $request
@return void
|
[
"Detect",
"the",
"driver",
"and",
"format",
"the",
"request",
"to",
"Facebook",
"format"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Drivers/Driver.php#L62-L66
|
226,657
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Model.php
|
Model.validateArray
|
public function validateArray(Array $values)
{
if (count($this->getValidationRules())) {
$validator = Validator::make($values, $this->getValidationRules());
if ($validator->fails()) {
return $validator->errors();
}
}
return True;
}
|
php
|
public function validateArray(Array $values)
{
if (count($this->getValidationRules())) {
$validator = Validator::make($values, $this->getValidationRules());
if ($validator->fails()) {
return $validator->errors();
}
}
return True;
}
|
[
"public",
"function",
"validateArray",
"(",
"Array",
"$",
"values",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"getValidationRules",
"(",
")",
")",
")",
"{",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"values",
",",
"$",
"this",
"->",
"getValidationRules",
"(",
")",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"$",
"validator",
"->",
"errors",
"(",
")",
";",
"}",
"}",
"return",
"True",
";",
"}"
] |
Validate passed values
@param Array $values user passed values (request data)
@return bool|\Illuminate\Support\MessageBag True on pass, MessageBag of errors on fail
|
[
"Validate",
"passed",
"values"
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Model.php#L133-L144
|
226,658
|
egeriis/laravel-jsonapi
|
src/EchoIt/JsonApi/Model.php
|
Model.toArray
|
public function toArray()
{
$relations = [];
$arrayableRelations = [];
// include any relations exposed by default
foreach ($this->exposedRelations as $relation) {
// skip loading a relation if it is from a method
if (in_array($relation, $this->relationsFromMethod)) {
// if the relation hasnt been loaded, then load it
if (!isset($this->$relation)) {
$this->$relation = $this->$relation();
}
$arrayableRelations[$relation] = $this->$relation;
continue;
}
$this->load($relation);
}
// fetch the relations that can be represented as an array
$arrayableRelations = array_merge($this->getArrayableRelations(), $arrayableRelations);
// add the relations to the linked array
foreach ($arrayableRelations as $relation => $value) {
if (in_array($relation, $this->hidden)) {
continue;
}
if ($value instanceof Pivot) {
continue;
}
if ($value instanceof BaseModel) {
$relations[$relation] = array('linkage' => array('id' => (string)$value->getKey(), 'type' => $value->getResourceType()));
} elseif ($value instanceof Collection) {
$relation = \str_plural($relation);
$items = ['linkage' => []];
foreach ($value as $item) {
$items['linkage'][] = array('id' => (string)$item->getKey(), 'type' => $item->getResourceType());
}
$relations[$relation] = $items;
}
// remove models / collections that we loaded from a method
if (in_array($relation, $this->relationsFromMethod)) {
unset($this->$relation);
}
}
//add type parameter
$model_attributes = $this->attributesToArray();
unset($model_attributes[$this->primaryKey]);
$attributes = [
'id' => (string)$this->getKey(),
'type' => $this->getResourceType(),
'attributes' => $model_attributes
];
if (! count($relations)) {
return $attributes;
}
return array_merge(
$attributes,
[ 'links' => $relations ]
);
}
|
php
|
public function toArray()
{
$relations = [];
$arrayableRelations = [];
// include any relations exposed by default
foreach ($this->exposedRelations as $relation) {
// skip loading a relation if it is from a method
if (in_array($relation, $this->relationsFromMethod)) {
// if the relation hasnt been loaded, then load it
if (!isset($this->$relation)) {
$this->$relation = $this->$relation();
}
$arrayableRelations[$relation] = $this->$relation;
continue;
}
$this->load($relation);
}
// fetch the relations that can be represented as an array
$arrayableRelations = array_merge($this->getArrayableRelations(), $arrayableRelations);
// add the relations to the linked array
foreach ($arrayableRelations as $relation => $value) {
if (in_array($relation, $this->hidden)) {
continue;
}
if ($value instanceof Pivot) {
continue;
}
if ($value instanceof BaseModel) {
$relations[$relation] = array('linkage' => array('id' => (string)$value->getKey(), 'type' => $value->getResourceType()));
} elseif ($value instanceof Collection) {
$relation = \str_plural($relation);
$items = ['linkage' => []];
foreach ($value as $item) {
$items['linkage'][] = array('id' => (string)$item->getKey(), 'type' => $item->getResourceType());
}
$relations[$relation] = $items;
}
// remove models / collections that we loaded from a method
if (in_array($relation, $this->relationsFromMethod)) {
unset($this->$relation);
}
}
//add type parameter
$model_attributes = $this->attributesToArray();
unset($model_attributes[$this->primaryKey]);
$attributes = [
'id' => (string)$this->getKey(),
'type' => $this->getResourceType(),
'attributes' => $model_attributes
];
if (! count($relations)) {
return $attributes;
}
return array_merge(
$attributes,
[ 'links' => $relations ]
);
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"relations",
"=",
"[",
"]",
";",
"$",
"arrayableRelations",
"=",
"[",
"]",
";",
"// include any relations exposed by default",
"foreach",
"(",
"$",
"this",
"->",
"exposedRelations",
"as",
"$",
"relation",
")",
"{",
"// skip loading a relation if it is from a method",
"if",
"(",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"relationsFromMethod",
")",
")",
"{",
"// if the relation hasnt been loaded, then load it",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"$",
"relation",
")",
")",
"{",
"$",
"this",
"->",
"$",
"relation",
"=",
"$",
"this",
"->",
"$",
"relation",
"(",
")",
";",
"}",
"$",
"arrayableRelations",
"[",
"$",
"relation",
"]",
"=",
"$",
"this",
"->",
"$",
"relation",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"load",
"(",
"$",
"relation",
")",
";",
"}",
"// fetch the relations that can be represented as an array",
"$",
"arrayableRelations",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getArrayableRelations",
"(",
")",
",",
"$",
"arrayableRelations",
")",
";",
"// add the relations to the linked array",
"foreach",
"(",
"$",
"arrayableRelations",
"as",
"$",
"relation",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"hidden",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"Pivot",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"BaseModel",
")",
"{",
"$",
"relations",
"[",
"$",
"relation",
"]",
"=",
"array",
"(",
"'linkage'",
"=>",
"array",
"(",
"'id'",
"=>",
"(",
"string",
")",
"$",
"value",
"->",
"getKey",
"(",
")",
",",
"'type'",
"=>",
"$",
"value",
"->",
"getResourceType",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"Collection",
")",
"{",
"$",
"relation",
"=",
"\\",
"str_plural",
"(",
"$",
"relation",
")",
";",
"$",
"items",
"=",
"[",
"'linkage'",
"=>",
"[",
"]",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"item",
")",
"{",
"$",
"items",
"[",
"'linkage'",
"]",
"[",
"]",
"=",
"array",
"(",
"'id'",
"=>",
"(",
"string",
")",
"$",
"item",
"->",
"getKey",
"(",
")",
",",
"'type'",
"=>",
"$",
"item",
"->",
"getResourceType",
"(",
")",
")",
";",
"}",
"$",
"relations",
"[",
"$",
"relation",
"]",
"=",
"$",
"items",
";",
"}",
"// remove models / collections that we loaded from a method",
"if",
"(",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"relationsFromMethod",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"$",
"relation",
")",
";",
"}",
"}",
"//add type parameter",
"$",
"model_attributes",
"=",
"$",
"this",
"->",
"attributesToArray",
"(",
")",
";",
"unset",
"(",
"$",
"model_attributes",
"[",
"$",
"this",
"->",
"primaryKey",
"]",
")",
";",
"$",
"attributes",
"=",
"[",
"'id'",
"=>",
"(",
"string",
")",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"'type'",
"=>",
"$",
"this",
"->",
"getResourceType",
"(",
")",
",",
"'attributes'",
"=>",
"$",
"model_attributes",
"]",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"relations",
")",
")",
"{",
"return",
"$",
"attributes",
";",
"}",
"return",
"array_merge",
"(",
"$",
"attributes",
",",
"[",
"'links'",
"=>",
"$",
"relations",
"]",
")",
";",
"}"
] |
Convert the model instance to an array. This method overrides that of
Eloquent to prevent relations to be serialize into output array.
@return array
|
[
"Convert",
"the",
"model",
"instance",
"to",
"an",
"array",
".",
"This",
"method",
"overrides",
"that",
"of",
"Eloquent",
"to",
"prevent",
"relations",
"to",
"be",
"serialize",
"into",
"output",
"array",
"."
] |
6d58e14cba26c0624d38f75273cff86fd4678289
|
https://github.com/egeriis/laravel-jsonapi/blob/6d58e14cba26c0624d38f75273cff86fd4678289/src/EchoIt/JsonApi/Model.php#L163-L232
|
226,659
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.setRelatedEntityColumnInfo
|
protected function setRelatedEntityColumnInfo(array &$association, array $fields) {
$mdataName = implode('.', $fields);
$lastField = Container::camelize(array_pop($fields));
$joinName = $this->tableName;
$entityName = '';
$columnName = '';
// loop through the related entities, checking the associations as we go
$metadata = $this->metadata;
while ($field = array_shift($fields)) {
$columnName .= empty($columnName) ? $field : ".$field";
$entityName = lcfirst(Container::camelize($field));
if ($metadata->hasAssociation($entityName)) {
$joinOn = "$joinName.$entityName";
if ($metadata->isCollectionValuedAssociation($entityName)) {
$association['containsCollections'] = true;
}
$metadata = $this->em->getClassMetadata(
$metadata->getAssociationTargetClass($entityName)
);
$joinName .= '_' . $this->getJoinName(
$metadata,
Container::camelize($metadata->getTableName()),
$entityName
);
// The join required to get to the entity in question
if (!isset($this->assignedJoins[$joinName])) {
$this->assignedJoins[$joinName]['joinOn'] = $joinOn;
$this->assignedJoins[$joinName]['mdataColumn'] = $columnName;
$this->identifiers[$joinName] = $metadata->getIdentifierFieldNames();
}
}
else {
throw new Exception(
"Association '$entityName' not found ($mdataName)",
'404'
);
}
}
// Check the last field on the last related entity of the dotted notation
if (!$metadata->hasField(lcfirst($lastField))) {
throw new Exception(
"Field '$lastField' on association '$entityName' not found ($mdataName)",
'404'
);
}
$association['entityName'] = $entityName;
$association['fieldName'] = $lastField;
$association['joinName'] = $joinName;
$association['fullName'] = $this->getFullName($association);
}
|
php
|
protected function setRelatedEntityColumnInfo(array &$association, array $fields) {
$mdataName = implode('.', $fields);
$lastField = Container::camelize(array_pop($fields));
$joinName = $this->tableName;
$entityName = '';
$columnName = '';
// loop through the related entities, checking the associations as we go
$metadata = $this->metadata;
while ($field = array_shift($fields)) {
$columnName .= empty($columnName) ? $field : ".$field";
$entityName = lcfirst(Container::camelize($field));
if ($metadata->hasAssociation($entityName)) {
$joinOn = "$joinName.$entityName";
if ($metadata->isCollectionValuedAssociation($entityName)) {
$association['containsCollections'] = true;
}
$metadata = $this->em->getClassMetadata(
$metadata->getAssociationTargetClass($entityName)
);
$joinName .= '_' . $this->getJoinName(
$metadata,
Container::camelize($metadata->getTableName()),
$entityName
);
// The join required to get to the entity in question
if (!isset($this->assignedJoins[$joinName])) {
$this->assignedJoins[$joinName]['joinOn'] = $joinOn;
$this->assignedJoins[$joinName]['mdataColumn'] = $columnName;
$this->identifiers[$joinName] = $metadata->getIdentifierFieldNames();
}
}
else {
throw new Exception(
"Association '$entityName' not found ($mdataName)",
'404'
);
}
}
// Check the last field on the last related entity of the dotted notation
if (!$metadata->hasField(lcfirst($lastField))) {
throw new Exception(
"Field '$lastField' on association '$entityName' not found ($mdataName)",
'404'
);
}
$association['entityName'] = $entityName;
$association['fieldName'] = $lastField;
$association['joinName'] = $joinName;
$association['fullName'] = $this->getFullName($association);
}
|
[
"protected",
"function",
"setRelatedEntityColumnInfo",
"(",
"array",
"&",
"$",
"association",
",",
"array",
"$",
"fields",
")",
"{",
"$",
"mdataName",
"=",
"implode",
"(",
"'.'",
",",
"$",
"fields",
")",
";",
"$",
"lastField",
"=",
"Container",
"::",
"camelize",
"(",
"array_pop",
"(",
"$",
"fields",
")",
")",
";",
"$",
"joinName",
"=",
"$",
"this",
"->",
"tableName",
";",
"$",
"entityName",
"=",
"''",
";",
"$",
"columnName",
"=",
"''",
";",
"// loop through the related entities, checking the associations as we go",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadata",
";",
"while",
"(",
"$",
"field",
"=",
"array_shift",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"columnName",
".=",
"empty",
"(",
"$",
"columnName",
")",
"?",
"$",
"field",
":",
"\".$field\"",
";",
"$",
"entityName",
"=",
"lcfirst",
"(",
"Container",
"::",
"camelize",
"(",
"$",
"field",
")",
")",
";",
"if",
"(",
"$",
"metadata",
"->",
"hasAssociation",
"(",
"$",
"entityName",
")",
")",
"{",
"$",
"joinOn",
"=",
"\"$joinName.$entityName\"",
";",
"if",
"(",
"$",
"metadata",
"->",
"isCollectionValuedAssociation",
"(",
"$",
"entityName",
")",
")",
"{",
"$",
"association",
"[",
"'containsCollections'",
"]",
"=",
"true",
";",
"}",
"$",
"metadata",
"=",
"$",
"this",
"->",
"em",
"->",
"getClassMetadata",
"(",
"$",
"metadata",
"->",
"getAssociationTargetClass",
"(",
"$",
"entityName",
")",
")",
";",
"$",
"joinName",
".=",
"'_'",
".",
"$",
"this",
"->",
"getJoinName",
"(",
"$",
"metadata",
",",
"Container",
"::",
"camelize",
"(",
"$",
"metadata",
"->",
"getTableName",
"(",
")",
")",
",",
"$",
"entityName",
")",
";",
"// The join required to get to the entity in question",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"assignedJoins",
"[",
"$",
"joinName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"assignedJoins",
"[",
"$",
"joinName",
"]",
"[",
"'joinOn'",
"]",
"=",
"$",
"joinOn",
";",
"$",
"this",
"->",
"assignedJoins",
"[",
"$",
"joinName",
"]",
"[",
"'mdataColumn'",
"]",
"=",
"$",
"columnName",
";",
"$",
"this",
"->",
"identifiers",
"[",
"$",
"joinName",
"]",
"=",
"$",
"metadata",
"->",
"getIdentifierFieldNames",
"(",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Association '$entityName' not found ($mdataName)\"",
",",
"'404'",
")",
";",
"}",
"}",
"// Check the last field on the last related entity of the dotted notation",
"if",
"(",
"!",
"$",
"metadata",
"->",
"hasField",
"(",
"lcfirst",
"(",
"$",
"lastField",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Field '$lastField' on association '$entityName' not found ($mdataName)\"",
",",
"'404'",
")",
";",
"}",
"$",
"association",
"[",
"'entityName'",
"]",
"=",
"$",
"entityName",
";",
"$",
"association",
"[",
"'fieldName'",
"]",
"=",
"$",
"lastField",
";",
"$",
"association",
"[",
"'joinName'",
"]",
"=",
"$",
"joinName",
";",
"$",
"association",
"[",
"'fullName'",
"]",
"=",
"$",
"this",
"->",
"getFullName",
"(",
"$",
"association",
")",
";",
"}"
] |
Parse a dotted-notation column format from the mData, and sets association
information
@param array Association information for a column (by reference)
@param array The column fields from dotted notation
|
[
"Parse",
"a",
"dotted",
"-",
"notation",
"column",
"format",
"from",
"the",
"mData",
"and",
"sets",
"association",
"information"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L296-L347
|
226,660
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.setSingleFieldColumnInfo
|
protected function setSingleFieldColumnInfo(array &$association, $fieldName) {
$fieldName = Container::camelize($fieldName);
if (!$this->metadata->hasField(lcfirst($fieldName))) {
throw new Exception(
"Field '$fieldName' not found.)",
'404'
);
}
$association['fieldName'] = $fieldName;
$association['entityName'] = $this->tableName;
$association['fullName'] = $this->tableName . '.' . lcfirst($fieldName);
}
|
php
|
protected function setSingleFieldColumnInfo(array &$association, $fieldName) {
$fieldName = Container::camelize($fieldName);
if (!$this->metadata->hasField(lcfirst($fieldName))) {
throw new Exception(
"Field '$fieldName' not found.)",
'404'
);
}
$association['fieldName'] = $fieldName;
$association['entityName'] = $this->tableName;
$association['fullName'] = $this->tableName . '.' . lcfirst($fieldName);
}
|
[
"protected",
"function",
"setSingleFieldColumnInfo",
"(",
"array",
"&",
"$",
"association",
",",
"$",
"fieldName",
")",
"{",
"$",
"fieldName",
"=",
"Container",
"::",
"camelize",
"(",
"$",
"fieldName",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"metadata",
"->",
"hasField",
"(",
"lcfirst",
"(",
"$",
"fieldName",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Field '$fieldName' not found.)\"",
",",
"'404'",
")",
";",
"}",
"$",
"association",
"[",
"'fieldName'",
"]",
"=",
"$",
"fieldName",
";",
"$",
"association",
"[",
"'entityName'",
"]",
"=",
"$",
"this",
"->",
"tableName",
";",
"$",
"association",
"[",
"'fullName'",
"]",
"=",
"$",
"this",
"->",
"tableName",
".",
"'.'",
".",
"lcfirst",
"(",
"$",
"fieldName",
")",
";",
"}"
] |
Configures association information for a single field request from the main entity
@param array The association information as a reference
@param string The field name on the main entity
|
[
"Configures",
"association",
"information",
"for",
"a",
"single",
"field",
"request",
"from",
"the",
"main",
"entity"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L355-L368
|
226,661
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.getJoinName
|
protected function getJoinName(ClassMetadata $metadata, $tableName, $entityName)
{
$joinName = $tableName;
// If it is self-referencing then we must avoid collisions
if ($metadata->getName() == $this->metadata->getName()) {
$joinName .= "_$entityName";
}
return $joinName;
}
|
php
|
protected function getJoinName(ClassMetadata $metadata, $tableName, $entityName)
{
$joinName = $tableName;
// If it is self-referencing then we must avoid collisions
if ($metadata->getName() == $this->metadata->getName()) {
$joinName .= "_$entityName";
}
return $joinName;
}
|
[
"protected",
"function",
"getJoinName",
"(",
"ClassMetadata",
"$",
"metadata",
",",
"$",
"tableName",
",",
"$",
"entityName",
")",
"{",
"$",
"joinName",
"=",
"$",
"tableName",
";",
"// If it is self-referencing then we must avoid collisions",
"if",
"(",
"$",
"metadata",
"->",
"getName",
"(",
")",
"==",
"$",
"this",
"->",
"metadata",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"joinName",
".=",
"\"_$entityName\"",
";",
"}",
"return",
"$",
"joinName",
";",
"}"
] |
Based on association information and metadata, construct the join name
@param ClassMetadata Doctrine metadata for an association
@param string The table name for the join
@param string The entity name of the table
|
[
"Based",
"on",
"association",
"information",
"and",
"metadata",
"construct",
"the",
"join",
"name"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L377-L387
|
226,662
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.setDefaultJoinType
|
public function setDefaultJoinType($joinType)
{
if (defined('self::JOIN_' . strtoupper($joinType))) {
$this->defaultJoinType = constant('self::JOIN_' . strtoupper($joinType));
}
return $this;
}
|
php
|
public function setDefaultJoinType($joinType)
{
if (defined('self::JOIN_' . strtoupper($joinType))) {
$this->defaultJoinType = constant('self::JOIN_' . strtoupper($joinType));
}
return $this;
}
|
[
"public",
"function",
"setDefaultJoinType",
"(",
"$",
"joinType",
")",
"{",
"if",
"(",
"defined",
"(",
"'self::JOIN_'",
".",
"strtoupper",
"(",
"$",
"joinType",
")",
")",
")",
"{",
"$",
"this",
"->",
"defaultJoinType",
"=",
"constant",
"(",
"'self::JOIN_'",
".",
"strtoupper",
"(",
"$",
"joinType",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the default join type to use for associations. Defaults to JOIN_INNER
@param string The join type to use, should be of either constant: JOIN_INNER, JOIN_LEFT
|
[
"Set",
"the",
"default",
"join",
"type",
"to",
"use",
"for",
"associations",
".",
"Defaults",
"to",
"JOIN_INNER"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L405-L412
|
226,663
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.setLimit
|
public function setLimit(QueryBuilder $qb)
{
if (isset($this->offset) && $this->amount != '-1') {
$qb->setFirstResult($this->offset)->setMaxResults($this->amount);
}
}
|
php
|
public function setLimit(QueryBuilder $qb)
{
if (isset($this->offset) && $this->amount != '-1') {
$qb->setFirstResult($this->offset)->setMaxResults($this->amount);
}
}
|
[
"public",
"function",
"setLimit",
"(",
"QueryBuilder",
"$",
"qb",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"offset",
")",
"&&",
"$",
"this",
"->",
"amount",
"!=",
"'-1'",
")",
"{",
"$",
"qb",
"->",
"setFirstResult",
"(",
"$",
"this",
"->",
"offset",
")",
"->",
"setMaxResults",
"(",
"$",
"this",
"->",
"amount",
")",
";",
"}",
"}"
] |
Set the scope of the result set
@param QueryBuilder The Doctrine QueryBuilder object
|
[
"Set",
"the",
"scope",
"of",
"the",
"result",
"set"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L444-L449
|
226,664
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.setOrderBy
|
public function setOrderBy(QueryBuilder $qb)
{
if (isset($this->request['iSortCol_0'])) {
for ($i = 0; $i < intval($this->request['iSortingCols']); $i++) {
if ($this->request['bSortable_'.intval($this->request['iSortCol_'. $i])] == "true") {
$qb->addOrderBy(
$this->associations[$this->request['iSortCol_'.$i]]['fullName'],
$this->request['sSortDir_'.$i]
);
}
}
}
}
|
php
|
public function setOrderBy(QueryBuilder $qb)
{
if (isset($this->request['iSortCol_0'])) {
for ($i = 0; $i < intval($this->request['iSortingCols']); $i++) {
if ($this->request['bSortable_'.intval($this->request['iSortCol_'. $i])] == "true") {
$qb->addOrderBy(
$this->associations[$this->request['iSortCol_'.$i]]['fullName'],
$this->request['sSortDir_'.$i]
);
}
}
}
}
|
[
"public",
"function",
"setOrderBy",
"(",
"QueryBuilder",
"$",
"qb",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"request",
"[",
"'iSortCol_0'",
"]",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"intval",
"(",
"$",
"this",
"->",
"request",
"[",
"'iSortingCols'",
"]",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"[",
"'bSortable_'",
".",
"intval",
"(",
"$",
"this",
"->",
"request",
"[",
"'iSortCol_'",
".",
"$",
"i",
"]",
")",
"]",
"==",
"\"true\"",
")",
"{",
"$",
"qb",
"->",
"addOrderBy",
"(",
"$",
"this",
"->",
"associations",
"[",
"$",
"this",
"->",
"request",
"[",
"'iSortCol_'",
".",
"$",
"i",
"]",
"]",
"[",
"'fullName'",
"]",
",",
"$",
"this",
"->",
"request",
"[",
"'sSortDir_'",
".",
"$",
"i",
"]",
")",
";",
"}",
"}",
"}",
"}"
] |
Set any column ordering that has been requested
@param QueryBuilder The Doctrine QueryBuilder object
|
[
"Set",
"any",
"column",
"ordering",
"that",
"has",
"been",
"requested"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L456-L468
|
226,665
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.setWhere
|
public function setWhere(QueryBuilder $qb)
{
// Global filtering
if ($this->search != '') {
$orExpr = $qb->expr()->orX();
for ($i=0 ; $i < count($this->parameters); $i++) {
if (isset($this->request['bSearchable_'.$i]) && $this->request['bSearchable_'.$i] == "true") {
$qbParam = "sSearch_global_{$this->associations[$i]['entityName']}_{$this->associations[$i]['fieldName']}";
$orExpr->add($qb->expr()->like(
$this->associations[$i]['fullName'],
":$qbParam"
));
$qb->setParameter($qbParam, "%" . $this->request['sSearch'] . "%");
}
}
$qb->where($orExpr);
}
// Individual column filtering
$andExpr = $qb->expr()->andX();
for ($i=0 ; $i < count($this->parameters); $i++) {
if (isset($this->request['bSearchable_'.$i]) && $this->request['bSearchable_'.$i] == "true" && $this->request['sSearch_'.$i] != '') {
$qbParam = "sSearch_single_{$this->associations[$i]['entityName']}_{$this->associations[$i]['fieldName']}";
$andExpr->add($qb->expr()->like(
$this->associations[$i]['fullName'],
":$qbParam"
));
$qb->setParameter($qbParam, "%" . $this->request['sSearch_'.$i] . "%");
}
}
if ($andExpr->count() > 0) {
$qb->andWhere($andExpr);
}
if (!empty($this->callbacks['WhereBuilder'])) {
foreach ($this->callbacks['WhereBuilder'] as $callback) {
$callback($qb);
}
}
}
|
php
|
public function setWhere(QueryBuilder $qb)
{
// Global filtering
if ($this->search != '') {
$orExpr = $qb->expr()->orX();
for ($i=0 ; $i < count($this->parameters); $i++) {
if (isset($this->request['bSearchable_'.$i]) && $this->request['bSearchable_'.$i] == "true") {
$qbParam = "sSearch_global_{$this->associations[$i]['entityName']}_{$this->associations[$i]['fieldName']}";
$orExpr->add($qb->expr()->like(
$this->associations[$i]['fullName'],
":$qbParam"
));
$qb->setParameter($qbParam, "%" . $this->request['sSearch'] . "%");
}
}
$qb->where($orExpr);
}
// Individual column filtering
$andExpr = $qb->expr()->andX();
for ($i=0 ; $i < count($this->parameters); $i++) {
if (isset($this->request['bSearchable_'.$i]) && $this->request['bSearchable_'.$i] == "true" && $this->request['sSearch_'.$i] != '') {
$qbParam = "sSearch_single_{$this->associations[$i]['entityName']}_{$this->associations[$i]['fieldName']}";
$andExpr->add($qb->expr()->like(
$this->associations[$i]['fullName'],
":$qbParam"
));
$qb->setParameter($qbParam, "%" . $this->request['sSearch_'.$i] . "%");
}
}
if ($andExpr->count() > 0) {
$qb->andWhere($andExpr);
}
if (!empty($this->callbacks['WhereBuilder'])) {
foreach ($this->callbacks['WhereBuilder'] as $callback) {
$callback($qb);
}
}
}
|
[
"public",
"function",
"setWhere",
"(",
"QueryBuilder",
"$",
"qb",
")",
"{",
"// Global filtering",
"if",
"(",
"$",
"this",
"->",
"search",
"!=",
"''",
")",
"{",
"$",
"orExpr",
"=",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"orX",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"request",
"[",
"'bSearchable_'",
".",
"$",
"i",
"]",
")",
"&&",
"$",
"this",
"->",
"request",
"[",
"'bSearchable_'",
".",
"$",
"i",
"]",
"==",
"\"true\"",
")",
"{",
"$",
"qbParam",
"=",
"\"sSearch_global_{$this->associations[$i]['entityName']}_{$this->associations[$i]['fieldName']}\"",
";",
"$",
"orExpr",
"->",
"add",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"like",
"(",
"$",
"this",
"->",
"associations",
"[",
"$",
"i",
"]",
"[",
"'fullName'",
"]",
",",
"\":$qbParam\"",
")",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"$",
"qbParam",
",",
"\"%\"",
".",
"$",
"this",
"->",
"request",
"[",
"'sSearch'",
"]",
".",
"\"%\"",
")",
";",
"}",
"}",
"$",
"qb",
"->",
"where",
"(",
"$",
"orExpr",
")",
";",
"}",
"// Individual column filtering",
"$",
"andExpr",
"=",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"request",
"[",
"'bSearchable_'",
".",
"$",
"i",
"]",
")",
"&&",
"$",
"this",
"->",
"request",
"[",
"'bSearchable_'",
".",
"$",
"i",
"]",
"==",
"\"true\"",
"&&",
"$",
"this",
"->",
"request",
"[",
"'sSearch_'",
".",
"$",
"i",
"]",
"!=",
"''",
")",
"{",
"$",
"qbParam",
"=",
"\"sSearch_single_{$this->associations[$i]['entityName']}_{$this->associations[$i]['fieldName']}\"",
";",
"$",
"andExpr",
"->",
"add",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"like",
"(",
"$",
"this",
"->",
"associations",
"[",
"$",
"i",
"]",
"[",
"'fullName'",
"]",
",",
"\":$qbParam\"",
")",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"$",
"qbParam",
",",
"\"%\"",
".",
"$",
"this",
"->",
"request",
"[",
"'sSearch_'",
".",
"$",
"i",
"]",
".",
"\"%\"",
")",
";",
"}",
"}",
"if",
"(",
"$",
"andExpr",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"qb",
"->",
"andWhere",
"(",
"$",
"andExpr",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"callbacks",
"[",
"'WhereBuilder'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"callbacks",
"[",
"'WhereBuilder'",
"]",
"as",
"$",
"callback",
")",
"{",
"$",
"callback",
"(",
"$",
"qb",
")",
";",
"}",
"}",
"}"
] |
Configure the WHERE clause for the Doctrine QueryBuilder if any searches are specified
@param QueryBuilder The Doctrine QueryBuilder object
|
[
"Configure",
"the",
"WHERE",
"clause",
"for",
"the",
"Doctrine",
"QueryBuilder",
"if",
"any",
"searches",
"are",
"specified"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L475-L514
|
226,666
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.setAssociations
|
public function setAssociations(QueryBuilder $qb)
{
foreach ($this->assignedJoins as $joinName => $joinInfo) {
$joinType = isset($this->joinTypes[$joinInfo['mdataColumn']]) ?
$this->joinTypes[$joinInfo['mdataColumn']] : $this->defaultJoinType;
call_user_func_array(array($qb, $joinType . 'Join'), array(
$joinInfo['joinOn'],
$joinName
));
}
}
|
php
|
public function setAssociations(QueryBuilder $qb)
{
foreach ($this->assignedJoins as $joinName => $joinInfo) {
$joinType = isset($this->joinTypes[$joinInfo['mdataColumn']]) ?
$this->joinTypes[$joinInfo['mdataColumn']] : $this->defaultJoinType;
call_user_func_array(array($qb, $joinType . 'Join'), array(
$joinInfo['joinOn'],
$joinName
));
}
}
|
[
"public",
"function",
"setAssociations",
"(",
"QueryBuilder",
"$",
"qb",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"assignedJoins",
"as",
"$",
"joinName",
"=>",
"$",
"joinInfo",
")",
"{",
"$",
"joinType",
"=",
"isset",
"(",
"$",
"this",
"->",
"joinTypes",
"[",
"$",
"joinInfo",
"[",
"'mdataColumn'",
"]",
"]",
")",
"?",
"$",
"this",
"->",
"joinTypes",
"[",
"$",
"joinInfo",
"[",
"'mdataColumn'",
"]",
"]",
":",
"$",
"this",
"->",
"defaultJoinType",
";",
"call_user_func_array",
"(",
"array",
"(",
"$",
"qb",
",",
"$",
"joinType",
".",
"'Join'",
")",
",",
"array",
"(",
"$",
"joinInfo",
"[",
"'joinOn'",
"]",
",",
"$",
"joinName",
")",
")",
";",
"}",
"}"
] |
Configure joins for entity associations
@param QueryBuilder The Doctrine QueryBuilder object
|
[
"Configure",
"joins",
"for",
"entity",
"associations"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L521-L531
|
226,667
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.setSelect
|
public function setSelect(QueryBuilder $qb)
{
$columns = array();
$partials = array();
// Make sure all related joins are added as needed columns. A column many entities deep may rely on a
// column not specifically requested in the mData
foreach (array_keys($this->assignedJoins) as $joinName) {
$columns[$joinName] = array();
}
// Combine all columns to pull
foreach ($this->associations as $column) {
$parts = explode('.', $column['fullName']);
$columns[$parts[0]][] = $parts[1];
}
// Partial column results on entities require that we include the identifier as part of the selection
foreach ($this->identifiers as $joinName => $identifiers) {
if (!in_array($identifiers[0], $columns[$joinName])) {
array_unshift($columns[$joinName], $identifiers[0]);
}
}
// Make sure to include the identifier for the main entity
if (!in_array($this->rootEntityIdentifier, $columns[$this->tableName])) {
array_unshift($columns[$this->tableName], $this->rootEntityIdentifier);
}
foreach ($columns as $columnName => $fields) {
$partials[] = 'partial ' . $columnName . '.{' . implode(',', $fields) . '}';
}
$qb->select(implode(',', $partials));
$qb->from($this->metadata->getName(), $this->tableName);
}
|
php
|
public function setSelect(QueryBuilder $qb)
{
$columns = array();
$partials = array();
// Make sure all related joins are added as needed columns. A column many entities deep may rely on a
// column not specifically requested in the mData
foreach (array_keys($this->assignedJoins) as $joinName) {
$columns[$joinName] = array();
}
// Combine all columns to pull
foreach ($this->associations as $column) {
$parts = explode('.', $column['fullName']);
$columns[$parts[0]][] = $parts[1];
}
// Partial column results on entities require that we include the identifier as part of the selection
foreach ($this->identifiers as $joinName => $identifiers) {
if (!in_array($identifiers[0], $columns[$joinName])) {
array_unshift($columns[$joinName], $identifiers[0]);
}
}
// Make sure to include the identifier for the main entity
if (!in_array($this->rootEntityIdentifier, $columns[$this->tableName])) {
array_unshift($columns[$this->tableName], $this->rootEntityIdentifier);
}
foreach ($columns as $columnName => $fields) {
$partials[] = 'partial ' . $columnName . '.{' . implode(',', $fields) . '}';
}
$qb->select(implode(',', $partials));
$qb->from($this->metadata->getName(), $this->tableName);
}
|
[
"public",
"function",
"setSelect",
"(",
"QueryBuilder",
"$",
"qb",
")",
"{",
"$",
"columns",
"=",
"array",
"(",
")",
";",
"$",
"partials",
"=",
"array",
"(",
")",
";",
"// Make sure all related joins are added as needed columns. A column many entities deep may rely on a",
"// column not specifically requested in the mData",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"assignedJoins",
")",
"as",
"$",
"joinName",
")",
"{",
"$",
"columns",
"[",
"$",
"joinName",
"]",
"=",
"array",
"(",
")",
";",
"}",
"// Combine all columns to pull",
"foreach",
"(",
"$",
"this",
"->",
"associations",
"as",
"$",
"column",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"column",
"[",
"'fullName'",
"]",
")",
";",
"$",
"columns",
"[",
"$",
"parts",
"[",
"0",
"]",
"]",
"[",
"]",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"}",
"// Partial column results on entities require that we include the identifier as part of the selection",
"foreach",
"(",
"$",
"this",
"->",
"identifiers",
"as",
"$",
"joinName",
"=>",
"$",
"identifiers",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"identifiers",
"[",
"0",
"]",
",",
"$",
"columns",
"[",
"$",
"joinName",
"]",
")",
")",
"{",
"array_unshift",
"(",
"$",
"columns",
"[",
"$",
"joinName",
"]",
",",
"$",
"identifiers",
"[",
"0",
"]",
")",
";",
"}",
"}",
"// Make sure to include the identifier for the main entity",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"rootEntityIdentifier",
",",
"$",
"columns",
"[",
"$",
"this",
"->",
"tableName",
"]",
")",
")",
"{",
"array_unshift",
"(",
"$",
"columns",
"[",
"$",
"this",
"->",
"tableName",
"]",
",",
"$",
"this",
"->",
"rootEntityIdentifier",
")",
";",
"}",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"columnName",
"=>",
"$",
"fields",
")",
"{",
"$",
"partials",
"[",
"]",
"=",
"'partial '",
".",
"$",
"columnName",
".",
"'.{'",
".",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
".",
"'}'",
";",
"}",
"$",
"qb",
"->",
"select",
"(",
"implode",
"(",
"','",
",",
"$",
"partials",
")",
")",
";",
"$",
"qb",
"->",
"from",
"(",
"$",
"this",
"->",
"metadata",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"tableName",
")",
";",
"}"
] |
Configure the specific columns to select for the query
@param QueryBuilder The Doctrine QueryBuilder object
|
[
"Configure",
"the",
"specific",
"columns",
"to",
"select",
"for",
"the",
"query"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L538-L573
|
226,668
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.executeSearch
|
public function executeSearch()
{
$output = array("aaData" => array());
$query = $this->qb->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY);
$items = $this->useDoctrinePaginator ?
new Paginator($query, $this->doesQueryContainCollections()) : $query->execute();
foreach ($items as $item) {
if ($this->useDtRowClass && !is_null($this->dtRowClass)) {
$item['DT_RowClass'] = $this->dtRowClass;
}
if ($this->useDtRowId) {
$item['DT_RowId'] = $item[$this->rootEntityIdentifier];
}
// Go through each requested column, transforming the array as needed for DataTables
for ($i = 0 ; $i < count($this->parameters); $i++) {
// Results are already correctly formatted if this is the case...
if (!$this->associations[$i]['containsCollections']) {
continue;
}
$rowRef = &$item;
$fields = explode('.', $this->parameters[$i]);
// Check for collection based entities and format the array as needed
while ($field = array_shift($fields)) {
$rowRef = &$rowRef[$field];
// We ran into a collection based entity. Combine, merge, and continue on...
if (!empty($fields) && !$this->isAssocArray($rowRef)) {
$children = array();
while ($childItem = array_shift($rowRef)) {
$children = array_merge_recursive($children, $childItem);
}
$rowRef = $children;
}
}
}
$output['aaData'][] = $item;
}
$outputHeader = array(
"sEcho" => (int) $this->echo,
"iTotalRecords" => $this->getCountAllResults(),
"iTotalDisplayRecords" => $this->getCountFilteredResults()
);
$this->datatable = array_merge($outputHeader, $output);
return $this;
}
|
php
|
public function executeSearch()
{
$output = array("aaData" => array());
$query = $this->qb->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY);
$items = $this->useDoctrinePaginator ?
new Paginator($query, $this->doesQueryContainCollections()) : $query->execute();
foreach ($items as $item) {
if ($this->useDtRowClass && !is_null($this->dtRowClass)) {
$item['DT_RowClass'] = $this->dtRowClass;
}
if ($this->useDtRowId) {
$item['DT_RowId'] = $item[$this->rootEntityIdentifier];
}
// Go through each requested column, transforming the array as needed for DataTables
for ($i = 0 ; $i < count($this->parameters); $i++) {
// Results are already correctly formatted if this is the case...
if (!$this->associations[$i]['containsCollections']) {
continue;
}
$rowRef = &$item;
$fields = explode('.', $this->parameters[$i]);
// Check for collection based entities and format the array as needed
while ($field = array_shift($fields)) {
$rowRef = &$rowRef[$field];
// We ran into a collection based entity. Combine, merge, and continue on...
if (!empty($fields) && !$this->isAssocArray($rowRef)) {
$children = array();
while ($childItem = array_shift($rowRef)) {
$children = array_merge_recursive($children, $childItem);
}
$rowRef = $children;
}
}
}
$output['aaData'][] = $item;
}
$outputHeader = array(
"sEcho" => (int) $this->echo,
"iTotalRecords" => $this->getCountAllResults(),
"iTotalDisplayRecords" => $this->getCountFilteredResults()
);
$this->datatable = array_merge($outputHeader, $output);
return $this;
}
|
[
"public",
"function",
"executeSearch",
"(",
")",
"{",
"$",
"output",
"=",
"array",
"(",
"\"aaData\"",
"=>",
"array",
"(",
")",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"setHydrationMode",
"(",
"Query",
"::",
"HYDRATE_ARRAY",
")",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"useDoctrinePaginator",
"?",
"new",
"Paginator",
"(",
"$",
"query",
",",
"$",
"this",
"->",
"doesQueryContainCollections",
"(",
")",
")",
":",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"useDtRowClass",
"&&",
"!",
"is_null",
"(",
"$",
"this",
"->",
"dtRowClass",
")",
")",
"{",
"$",
"item",
"[",
"'DT_RowClass'",
"]",
"=",
"$",
"this",
"->",
"dtRowClass",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"useDtRowId",
")",
"{",
"$",
"item",
"[",
"'DT_RowId'",
"]",
"=",
"$",
"item",
"[",
"$",
"this",
"->",
"rootEntityIdentifier",
"]",
";",
"}",
"// Go through each requested column, transforming the array as needed for DataTables",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"$",
"i",
"++",
")",
"{",
"// Results are already correctly formatted if this is the case...",
"if",
"(",
"!",
"$",
"this",
"->",
"associations",
"[",
"$",
"i",
"]",
"[",
"'containsCollections'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"rowRef",
"=",
"&",
"$",
"item",
";",
"$",
"fields",
"=",
"explode",
"(",
"'.'",
",",
"$",
"this",
"->",
"parameters",
"[",
"$",
"i",
"]",
")",
";",
"// Check for collection based entities and format the array as needed",
"while",
"(",
"$",
"field",
"=",
"array_shift",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"rowRef",
"=",
"&",
"$",
"rowRef",
"[",
"$",
"field",
"]",
";",
"// We ran into a collection based entity. Combine, merge, and continue on...",
"if",
"(",
"!",
"empty",
"(",
"$",
"fields",
")",
"&&",
"!",
"$",
"this",
"->",
"isAssocArray",
"(",
"$",
"rowRef",
")",
")",
"{",
"$",
"children",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"childItem",
"=",
"array_shift",
"(",
"$",
"rowRef",
")",
")",
"{",
"$",
"children",
"=",
"array_merge_recursive",
"(",
"$",
"children",
",",
"$",
"childItem",
")",
";",
"}",
"$",
"rowRef",
"=",
"$",
"children",
";",
"}",
"}",
"}",
"$",
"output",
"[",
"'aaData'",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"$",
"outputHeader",
"=",
"array",
"(",
"\"sEcho\"",
"=>",
"(",
"int",
")",
"$",
"this",
"->",
"echo",
",",
"\"iTotalRecords\"",
"=>",
"$",
"this",
"->",
"getCountAllResults",
"(",
")",
",",
"\"iTotalDisplayRecords\"",
"=>",
"$",
"this",
"->",
"getCountFilteredResults",
"(",
")",
")",
";",
"$",
"this",
"->",
"datatable",
"=",
"array_merge",
"(",
"$",
"outputHeader",
",",
"$",
"output",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Execute the QueryBuilder object, parse and save the results
|
[
"Execute",
"the",
"QueryBuilder",
"object",
"parse",
"and",
"save",
"the",
"results"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L604-L654
|
226,669
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.setDefaultResultType
|
public function setDefaultResultType($resultType)
{
if (defined('self::RESULT_' . strtoupper($resultType))) {
$this->defaultResultType = constant('self::RESULT_' . strtoupper($resultType));
}
return $this;
}
|
php
|
public function setDefaultResultType($resultType)
{
if (defined('self::RESULT_' . strtoupper($resultType))) {
$this->defaultResultType = constant('self::RESULT_' . strtoupper($resultType));
}
return $this;
}
|
[
"public",
"function",
"setDefaultResultType",
"(",
"$",
"resultType",
")",
"{",
"if",
"(",
"defined",
"(",
"'self::RESULT_'",
".",
"strtoupper",
"(",
"$",
"resultType",
")",
")",
")",
"{",
"$",
"this",
"->",
"defaultResultType",
"=",
"constant",
"(",
"'self::RESULT_'",
".",
"strtoupper",
"(",
"$",
"resultType",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the default result type to use when calling getSearchResults
@param string The result type to use, should be one of: RESULT_JSON, RESULT_ARRAY, RESULT_RESPONSE
|
[
"Set",
"the",
"default",
"result",
"type",
"to",
"use",
"when",
"calling",
"getSearchResults"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L674-L681
|
226,670
|
LanKit/DatatablesBundle
|
Datatables/Datatable.php
|
Datatable.getSearchResults
|
public function getSearchResults($resultType = '')
{
if (empty($resultType) || !defined('self::RESULT_' . strtoupper($resultType))) {
$resultType = $this->defaultResultType;
}
else {
$resultType = constant('self::RESULT_' . strtoupper($resultType));
}
$this->makeSearch();
$this->executeSearch();
return call_user_func(array(
$this, 'getSearchResults' . $resultType
));
}
|
php
|
public function getSearchResults($resultType = '')
{
if (empty($resultType) || !defined('self::RESULT_' . strtoupper($resultType))) {
$resultType = $this->defaultResultType;
}
else {
$resultType = constant('self::RESULT_' . strtoupper($resultType));
}
$this->makeSearch();
$this->executeSearch();
return call_user_func(array(
$this, 'getSearchResults' . $resultType
));
}
|
[
"public",
"function",
"getSearchResults",
"(",
"$",
"resultType",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"resultType",
")",
"||",
"!",
"defined",
"(",
"'self::RESULT_'",
".",
"strtoupper",
"(",
"$",
"resultType",
")",
")",
")",
"{",
"$",
"resultType",
"=",
"$",
"this",
"->",
"defaultResultType",
";",
"}",
"else",
"{",
"$",
"resultType",
"=",
"constant",
"(",
"'self::RESULT_'",
".",
"strtoupper",
"(",
"$",
"resultType",
")",
")",
";",
"}",
"$",
"this",
"->",
"makeSearch",
"(",
")",
";",
"$",
"this",
"->",
"executeSearch",
"(",
")",
";",
"return",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"'getSearchResults'",
".",
"$",
"resultType",
")",
")",
";",
"}"
] |
Creates and executes the DataTables search, returns data in the requested format
@param string The result type to use, should be one of: RESULT_JSON, RESULT_ARRAY, RESULT_RESPONSE
@return mixed The DataTables data in the requested/default format
|
[
"Creates",
"and",
"executes",
"the",
"DataTables",
"search",
"returns",
"data",
"in",
"the",
"requested",
"format"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/Datatable.php#L689-L704
|
226,671
|
LanKit/DatatablesBundle
|
Datatables/DatatableManager.php
|
DatatableManager.getClassName
|
protected function getClassName($className) {
if (strpos($className, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $className);
$className = $this->doctrine->getManager()->getConfiguration()
->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
}
return $className;
}
|
php
|
protected function getClassName($className) {
if (strpos($className, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $className);
$className = $this->doctrine->getManager()->getConfiguration()
->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
}
return $className;
}
|
[
"protected",
"function",
"getClassName",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"className",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"namespaceAlias",
",",
"$",
"simpleClassName",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"className",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"doctrine",
"->",
"getManager",
"(",
")",
"->",
"getConfiguration",
"(",
")",
"->",
"getEntityNamespace",
"(",
"$",
"namespaceAlias",
")",
".",
"'\\\\'",
".",
"$",
"simpleClassName",
";",
"}",
"return",
"$",
"className",
";",
"}"
] |
Given an entity class name or possible alias, convert it to the full class name
@param string The entity class name or alias
@return string The entity class name
|
[
"Given",
"an",
"entity",
"class",
"name",
"or",
"possible",
"alias",
"convert",
"it",
"to",
"the",
"full",
"class",
"name"
] |
f9cadfeeef4adb152c97e88d539e69ee32512d80
|
https://github.com/LanKit/DatatablesBundle/blob/f9cadfeeef4adb152c97e88d539e69ee32512d80/Datatables/DatatableManager.php#L38-L45
|
226,672
|
gigaai/framework
|
src/Storage/Storage.php
|
Storage.addNode
|
private function addNode($answers, $node_type, $ask = '', array $attributes = [])
{
$node = Node::where(['type' => $node_type, 'pattern' => $ask])->first();
if (is_null($node)) {
$node = Node::create(array_merge([
'type' => $node_type,
'pattern' => $ask,
'answers' => $answers,
], $attributes));
} else {
$node->answers = $answers;
// Allows people set attributes
foreach ($attributes as $key => $value) {
if (!in_array($key, ['type', 'pattern', 'answers'])) {
$node->$key = $value;
}
}
$node->save();
}
return $node;
}
|
php
|
private function addNode($answers, $node_type, $ask = '', array $attributes = [])
{
$node = Node::where(['type' => $node_type, 'pattern' => $ask])->first();
if (is_null($node)) {
$node = Node::create(array_merge([
'type' => $node_type,
'pattern' => $ask,
'answers' => $answers,
], $attributes));
} else {
$node->answers = $answers;
// Allows people set attributes
foreach ($attributes as $key => $value) {
if (!in_array($key, ['type', 'pattern', 'answers'])) {
$node->$key = $value;
}
}
$node->save();
}
return $node;
}
|
[
"private",
"function",
"addNode",
"(",
"$",
"answers",
",",
"$",
"node_type",
",",
"$",
"ask",
"=",
"''",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"node",
"=",
"Node",
"::",
"where",
"(",
"[",
"'type'",
"=>",
"$",
"node_type",
",",
"'pattern'",
"=>",
"$",
"ask",
"]",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"node",
")",
")",
"{",
"$",
"node",
"=",
"Node",
"::",
"create",
"(",
"array_merge",
"(",
"[",
"'type'",
"=>",
"$",
"node_type",
",",
"'pattern'",
"=>",
"$",
"ask",
",",
"'answers'",
"=>",
"$",
"answers",
",",
"]",
",",
"$",
"attributes",
")",
")",
";",
"}",
"else",
"{",
"$",
"node",
"->",
"answers",
"=",
"$",
"answers",
";",
"// Allows people set attributes",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"[",
"'type'",
",",
"'pattern'",
",",
"'answers'",
"]",
")",
")",
"{",
"$",
"node",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"node",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"node",
";",
"}"
] |
Add Answer to the database
@param mixed $answers
@param string $node_type
@param string $ask
@param array $attributes
@return Node
|
[
"Add",
"Answer",
"to",
"the",
"database"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Storage/Storage.php#L156-L180
|
226,673
|
johannesschobel/dingoquerymapper
|
src/JohannesSchobel/DingoQueryMapper/Parser/UriParser.php
|
UriParser.queryParameter
|
public function queryParameter($key)
{
$keys = array_pluck($this->queryParameters, 'key');
$queryParameters = array_combine($keys, $this->queryParameters);
return $queryParameters[$key];
}
|
php
|
public function queryParameter($key)
{
$keys = array_pluck($this->queryParameters, 'key');
$queryParameters = array_combine($keys, $this->queryParameters);
return $queryParameters[$key];
}
|
[
"public",
"function",
"queryParameter",
"(",
"$",
"key",
")",
"{",
"$",
"keys",
"=",
"array_pluck",
"(",
"$",
"this",
"->",
"queryParameters",
",",
"'key'",
")",
";",
"$",
"queryParameters",
"=",
"array_combine",
"(",
"$",
"keys",
",",
"$",
"this",
"->",
"queryParameters",
")",
";",
"return",
"$",
"queryParameters",
"[",
"$",
"key",
"]",
";",
"}"
] |
Gets the respective parameter
@param $key
@return mixed
|
[
"Gets",
"the",
"respective",
"parameter"
] |
0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e
|
https://github.com/johannesschobel/dingoquerymapper/blob/0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e/src/JohannesSchobel/DingoQueryMapper/Parser/UriParser.php#L76-L82
|
226,674
|
johannesschobel/dingoquerymapper
|
src/JohannesSchobel/DingoQueryMapper/Parser/UriParser.php
|
UriParser.whereParameters
|
public function whereParameters()
{
return array_filter(
$this->queryParameters,
function ($queryParameter) {
$key = $queryParameter['key'];
return (! in_array($key, $this->predefinedParams));
}
);
}
|
php
|
public function whereParameters()
{
return array_filter(
$this->queryParameters,
function ($queryParameter) {
$key = $queryParameter['key'];
return (! in_array($key, $this->predefinedParams));
}
);
}
|
[
"public",
"function",
"whereParameters",
"(",
")",
"{",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"queryParameters",
",",
"function",
"(",
"$",
"queryParameter",
")",
"{",
"$",
"key",
"=",
"$",
"queryParameter",
"[",
"'key'",
"]",
";",
"return",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"predefinedParams",
")",
")",
";",
"}",
")",
";",
"}"
] |
Gets the WHERE parameters
@return array
|
[
"Gets",
"the",
"WHERE",
"parameters"
] |
0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e
|
https://github.com/johannesschobel/dingoquerymapper/blob/0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e/src/JohannesSchobel/DingoQueryMapper/Parser/UriParser.php#L99-L108
|
226,675
|
johannesschobel/dingoquerymapper
|
src/JohannesSchobel/DingoQueryMapper/Parser/UriParser.php
|
UriParser.setQueryParameters
|
private function setQueryParameters($query)
{
// escaping
$query = addslashes($query);
$queryParameters = array_filter(explode('&', $query));
array_map([$this, 'appendQueryParameter'], $queryParameters);
}
|
php
|
private function setQueryParameters($query)
{
// escaping
$query = addslashes($query);
$queryParameters = array_filter(explode('&', $query));
array_map([$this, 'appendQueryParameter'], $queryParameters);
}
|
[
"private",
"function",
"setQueryParameters",
"(",
"$",
"query",
")",
"{",
"// escaping",
"$",
"query",
"=",
"addslashes",
"(",
"$",
"query",
")",
";",
"$",
"queryParameters",
"=",
"array_filter",
"(",
"explode",
"(",
"'&'",
",",
"$",
"query",
")",
")",
";",
"array_map",
"(",
"[",
"$",
"this",
",",
"'appendQueryParameter'",
"]",
",",
"$",
"queryParameters",
")",
";",
"}"
] |
Sets the query parameters
@param $query
|
[
"Sets",
"the",
"query",
"parameters"
] |
0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e
|
https://github.com/johannesschobel/dingoquerymapper/blob/0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e/src/JohannesSchobel/DingoQueryMapper/Parser/UriParser.php#L115-L123
|
226,676
|
johannesschobel/dingoquerymapper
|
src/JohannesSchobel/DingoQueryMapper/Parser/UriParser.php
|
UriParser.appendQueryParameter
|
private function appendQueryParameter($parameter)
{
preg_match($this->pattern, $parameter, $matches);
if (empty($matches)) {
return;
}
$operator = $matches[0];
list($key, $value) = explode($operator, $parameter);
if (strlen($value) == 0) {
return;
}
if (( ! $this->isPredefinedParameter($key)) && $this->isLikeQuery($value)) {
if ($operator == '=') {
$operator = 'like';
}
if ($operator == '!=') {
$operator = 'not like';
}
$value = str_replace('*', '%', $value);
}
$this->queryParameters[] = [
'key' => $key,
'operator' => $operator,
'value' => $value
];
}
|
php
|
private function appendQueryParameter($parameter)
{
preg_match($this->pattern, $parameter, $matches);
if (empty($matches)) {
return;
}
$operator = $matches[0];
list($key, $value) = explode($operator, $parameter);
if (strlen($value) == 0) {
return;
}
if (( ! $this->isPredefinedParameter($key)) && $this->isLikeQuery($value)) {
if ($operator == '=') {
$operator = 'like';
}
if ($operator == '!=') {
$operator = 'not like';
}
$value = str_replace('*', '%', $value);
}
$this->queryParameters[] = [
'key' => $key,
'operator' => $operator,
'value' => $value
];
}
|
[
"private",
"function",
"appendQueryParameter",
"(",
"$",
"parameter",
")",
"{",
"preg_match",
"(",
"$",
"this",
"->",
"pattern",
",",
"$",
"parameter",
",",
"$",
"matches",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"matches",
")",
")",
"{",
"return",
";",
"}",
"$",
"operator",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"$",
"operator",
",",
"$",
"parameter",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
"==",
"0",
")",
"{",
"return",
";",
"}",
"if",
"(",
"(",
"!",
"$",
"this",
"->",
"isPredefinedParameter",
"(",
"$",
"key",
")",
")",
"&&",
"$",
"this",
"->",
"isLikeQuery",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"operator",
"==",
"'='",
")",
"{",
"$",
"operator",
"=",
"'like'",
";",
"}",
"if",
"(",
"$",
"operator",
"==",
"'!='",
")",
"{",
"$",
"operator",
"=",
"'not like'",
";",
"}",
"$",
"value",
"=",
"str_replace",
"(",
"'*'",
",",
"'%'",
",",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"queryParameters",
"[",
"]",
"=",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'operator'",
"=>",
"$",
"operator",
",",
"'value'",
"=>",
"$",
"value",
"]",
";",
"}"
] |
Appends one parameter to the builder
@param $parameter
|
[
"Appends",
"one",
"parameter",
"to",
"the",
"builder"
] |
0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e
|
https://github.com/johannesschobel/dingoquerymapper/blob/0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e/src/JohannesSchobel/DingoQueryMapper/Parser/UriParser.php#L130-L162
|
226,677
|
phergie/phergie-irc-bot-react
|
src/EventQueueInternal.php
|
EventQueueInternal.compare
|
public function compare($priority1, $priority2)
{
if (!$priority1 instanceof EventQueuePriority || !$priority2 instanceof EventQueuePriority) {
return parent::compare($priority1, $priority2);
}
$priority = $priority1->value - $priority2->value;
if (!$priority) {
$priority = $priority2->timestamp - $priority1->timestamp;
}
return $priority;
}
|
php
|
public function compare($priority1, $priority2)
{
if (!$priority1 instanceof EventQueuePriority || !$priority2 instanceof EventQueuePriority) {
return parent::compare($priority1, $priority2);
}
$priority = $priority1->value - $priority2->value;
if (!$priority) {
$priority = $priority2->timestamp - $priority1->timestamp;
}
return $priority;
}
|
[
"public",
"function",
"compare",
"(",
"$",
"priority1",
",",
"$",
"priority2",
")",
"{",
"if",
"(",
"!",
"$",
"priority1",
"instanceof",
"EventQueuePriority",
"||",
"!",
"$",
"priority2",
"instanceof",
"EventQueuePriority",
")",
"{",
"return",
"parent",
"::",
"compare",
"(",
"$",
"priority1",
",",
"$",
"priority2",
")",
";",
"}",
"$",
"priority",
"=",
"$",
"priority1",
"->",
"value",
"-",
"$",
"priority2",
"->",
"value",
";",
"if",
"(",
"!",
"$",
"priority",
")",
"{",
"$",
"priority",
"=",
"$",
"priority2",
"->",
"timestamp",
"-",
"$",
"priority1",
"->",
"timestamp",
";",
"}",
"return",
"$",
"priority",
";",
"}"
] |
Overrides native default comparison logic to assign higher priority to
events inserted earlier.
@param \Phergie\Irc\Bot\React\EventQueuePriority $priority1
@param \Phergie\Irc\Bot\React\EventQueuePriority $priority2
@return int
|
[
"Overrides",
"native",
"default",
"comparison",
"logic",
"to",
"assign",
"higher",
"priority",
"to",
"events",
"inserted",
"earlier",
"."
] |
17745ef6b846513258af3dbd86e5612d3deb19b7
|
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/EventQueueInternal.php#L28-L39
|
226,678
|
gigaai/framework
|
src/Storage/Eloquent/Group.php
|
Group.hasPermission
|
public function hasPermission($permission)
{
return (is_array($this->permissions) &&
isset($this->permissions[$permission]) &&
$this->permissions[$permission] == true
) ||
(
isset($this->permissions['administrator']) &&
$this->permissions['administrator'] == true
);
}
|
php
|
public function hasPermission($permission)
{
return (is_array($this->permissions) &&
isset($this->permissions[$permission]) &&
$this->permissions[$permission] == true
) ||
(
isset($this->permissions['administrator']) &&
$this->permissions['administrator'] == true
);
}
|
[
"public",
"function",
"hasPermission",
"(",
"$",
"permission",
")",
"{",
"return",
"(",
"is_array",
"(",
"$",
"this",
"->",
"permissions",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"permissions",
"[",
"$",
"permission",
"]",
")",
"&&",
"$",
"this",
"->",
"permissions",
"[",
"$",
"permission",
"]",
"==",
"true",
")",
"||",
"(",
"isset",
"(",
"$",
"this",
"->",
"permissions",
"[",
"'administrator'",
"]",
")",
"&&",
"$",
"this",
"->",
"permissions",
"[",
"'administrator'",
"]",
"==",
"true",
")",
";",
"}"
] |
Check if group has specified permission
@param String $permission
@return bool
|
[
"Check",
"if",
"group",
"has",
"specified",
"permission"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Storage/Eloquent/Group.php#L31-L41
|
226,679
|
gigaai/framework
|
src/Http/MessengerProfile.php
|
MessengerProfile.updateMessengerProfile
|
public static function updateMessengerProfile()
{
$update = [];
$delete = [];
$irregular = [
'get_started' => 'get_started_button_payload',
];
$resource = self::getResourceUrl();
foreach (self::$fields as $field_name) {
if ( ! isset($irregular[$field_name])) {
$field_value = Instance::get($field_name);
} else {
$field_value = Instance::get($irregular[$field_name]);
}
if ( ! empty($field_value) && ! is_null($field_value)) {
$update[$field_name] = $field_value;
if ($field_name === 'get_started') {
$update['get_started'] = [
'payload' => $field_value
];
}
} else {
$delete[] = $field_name;
}
}
if ( ! empty($update)) {
$messages['update'] = Request::send($resource, $update);
}
if ( ! empty($delete)) {
$messages['delete'] = self::deleteFields($delete);
}
// Update cache
self::getFields(self::$fields);
return $messages;
}
|
php
|
public static function updateMessengerProfile()
{
$update = [];
$delete = [];
$irregular = [
'get_started' => 'get_started_button_payload',
];
$resource = self::getResourceUrl();
foreach (self::$fields as $field_name) {
if ( ! isset($irregular[$field_name])) {
$field_value = Instance::get($field_name);
} else {
$field_value = Instance::get($irregular[$field_name]);
}
if ( ! empty($field_value) && ! is_null($field_value)) {
$update[$field_name] = $field_value;
if ($field_name === 'get_started') {
$update['get_started'] = [
'payload' => $field_value
];
}
} else {
$delete[] = $field_name;
}
}
if ( ! empty($update)) {
$messages['update'] = Request::send($resource, $update);
}
if ( ! empty($delete)) {
$messages['delete'] = self::deleteFields($delete);
}
// Update cache
self::getFields(self::$fields);
return $messages;
}
|
[
"public",
"static",
"function",
"updateMessengerProfile",
"(",
")",
"{",
"$",
"update",
"=",
"[",
"]",
";",
"$",
"delete",
"=",
"[",
"]",
";",
"$",
"irregular",
"=",
"[",
"'get_started'",
"=>",
"'get_started_button_payload'",
",",
"]",
";",
"$",
"resource",
"=",
"self",
"::",
"getResourceUrl",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"fields",
"as",
"$",
"field_name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"irregular",
"[",
"$",
"field_name",
"]",
")",
")",
"{",
"$",
"field_value",
"=",
"Instance",
"::",
"get",
"(",
"$",
"field_name",
")",
";",
"}",
"else",
"{",
"$",
"field_value",
"=",
"Instance",
"::",
"get",
"(",
"$",
"irregular",
"[",
"$",
"field_name",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"field_value",
")",
"&&",
"!",
"is_null",
"(",
"$",
"field_value",
")",
")",
"{",
"$",
"update",
"[",
"$",
"field_name",
"]",
"=",
"$",
"field_value",
";",
"if",
"(",
"$",
"field_name",
"===",
"'get_started'",
")",
"{",
"$",
"update",
"[",
"'get_started'",
"]",
"=",
"[",
"'payload'",
"=>",
"$",
"field_value",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"delete",
"[",
"]",
"=",
"$",
"field_name",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"update",
")",
")",
"{",
"$",
"messages",
"[",
"'update'",
"]",
"=",
"Request",
"::",
"send",
"(",
"$",
"resource",
",",
"$",
"update",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"delete",
")",
")",
"{",
"$",
"messages",
"[",
"'delete'",
"]",
"=",
"self",
"::",
"deleteFields",
"(",
"$",
"delete",
")",
";",
"}",
"// Update cache",
"self",
"::",
"getFields",
"(",
"self",
"::",
"$",
"fields",
")",
";",
"return",
"$",
"messages",
";",
"}"
] |
Update all fields
@return mixed
|
[
"Update",
"all",
"fields"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Http/MessengerProfile.php#L38-L83
|
226,680
|
gigaai/framework
|
src/Http/MessengerProfile.php
|
MessengerProfile.updateField
|
public static function updateField($field_name)
{
$irregular = [
'get_started' => 'get_started_button_payload',
'greeting' => 'greeting_text'
];
if ( ! isset($irregular[$field_name])) {
$field_value = Instance::get($field_name);
} else {
$field_value = Instance::get($irregular[$field_name]);
}
$resource = self::getResourceUrl();
if ( ! empty($field_value) && ! is_null($field_value)) {
$data = [
$field_name => $field_value
];
if ($field_name === 'get_started') {
$data = [
'get_started' => [
'payload' => $field_value,
],
];
}
return Request::send($resource, $data);
}
return self::deleteFields($field_name);
}
|
php
|
public static function updateField($field_name)
{
$irregular = [
'get_started' => 'get_started_button_payload',
'greeting' => 'greeting_text'
];
if ( ! isset($irregular[$field_name])) {
$field_value = Instance::get($field_name);
} else {
$field_value = Instance::get($irregular[$field_name]);
}
$resource = self::getResourceUrl();
if ( ! empty($field_value) && ! is_null($field_value)) {
$data = [
$field_name => $field_value
];
if ($field_name === 'get_started') {
$data = [
'get_started' => [
'payload' => $field_value,
],
];
}
return Request::send($resource, $data);
}
return self::deleteFields($field_name);
}
|
[
"public",
"static",
"function",
"updateField",
"(",
"$",
"field_name",
")",
"{",
"$",
"irregular",
"=",
"[",
"'get_started'",
"=>",
"'get_started_button_payload'",
",",
"'greeting'",
"=>",
"'greeting_text'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"irregular",
"[",
"$",
"field_name",
"]",
")",
")",
"{",
"$",
"field_value",
"=",
"Instance",
"::",
"get",
"(",
"$",
"field_name",
")",
";",
"}",
"else",
"{",
"$",
"field_value",
"=",
"Instance",
"::",
"get",
"(",
"$",
"irregular",
"[",
"$",
"field_name",
"]",
")",
";",
"}",
"$",
"resource",
"=",
"self",
"::",
"getResourceUrl",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"field_value",
")",
"&&",
"!",
"is_null",
"(",
"$",
"field_value",
")",
")",
"{",
"$",
"data",
"=",
"[",
"$",
"field_name",
"=>",
"$",
"field_value",
"]",
";",
"if",
"(",
"$",
"field_name",
"===",
"'get_started'",
")",
"{",
"$",
"data",
"=",
"[",
"'get_started'",
"=>",
"[",
"'payload'",
"=>",
"$",
"field_value",
",",
"]",
",",
"]",
";",
"}",
"return",
"Request",
"::",
"send",
"(",
"$",
"resource",
",",
"$",
"data",
")",
";",
"}",
"return",
"self",
"::",
"deleteFields",
"(",
"$",
"field_name",
")",
";",
"}"
] |
Update each fields separately
@param String $field_name
@return mixed
|
[
"Update",
"each",
"fields",
"separately"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Http/MessengerProfile.php#L114-L147
|
226,681
|
snowplow-archive/symfony2-paypal-ipn
|
src/Orderly/PayPalIpnBundle/Ipn.php
|
Ipn._getCachedIPN
|
function _getCachedIPN()
{
$om = $this->objectManager;
if (!($cache = $om->getRepository($this->clsIpnLog)
->findOneBy(array('listenerName' => 'IPN', 'transactionType' => 'cache')))) {
return FALSE;
} else {
return unserialize($cache->getDetail());
}
}
|
php
|
function _getCachedIPN()
{
$om = $this->objectManager;
if (!($cache = $om->getRepository($this->clsIpnLog)
->findOneBy(array('listenerName' => 'IPN', 'transactionType' => 'cache')))) {
return FALSE;
} else {
return unserialize($cache->getDetail());
}
}
|
[
"function",
"_getCachedIPN",
"(",
")",
"{",
"$",
"om",
"=",
"$",
"this",
"->",
"objectManager",
";",
"if",
"(",
"!",
"(",
"$",
"cache",
"=",
"$",
"om",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"clsIpnLog",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"'listenerName'",
"=>",
"'IPN'",
",",
"'transactionType'",
"=>",
"'cache'",
")",
")",
")",
")",
"{",
"return",
"FALSE",
";",
"}",
"else",
"{",
"return",
"unserialize",
"(",
"$",
"cache",
"->",
"getDetail",
"(",
")",
")",
";",
"}",
"}"
] |
Retrieve the cached IPN record if there is one, false if there isn't
@return array
|
[
"Retrieve",
"the",
"cached",
"IPN",
"record",
"if",
"there",
"is",
"one",
"false",
"if",
"there",
"isn",
"t"
] |
e46d947cda5a11743ff1e215846e7d06ac939d42
|
https://github.com/snowplow-archive/symfony2-paypal-ipn/blob/e46d947cda5a11743ff1e215846e7d06ac939d42/src/Orderly/PayPalIpnBundle/Ipn.php#L463-L473
|
226,682
|
varspool/sphpdox
|
lib/Sphpdox/Element/NamespaceElement.php
|
NamespaceElement.ensureBuildDir
|
protected function ensureBuildDir($path, OutputInterface $output)
{
$parts = explode(DIRECTORY_SEPARATOR, $this->getPath());
foreach ($parts as $part) {
if (!$part) continue;
$path .= DIRECTORY_SEPARATOR . $part;
if (!file_exists($path)) {
$output->writeln(sprintf('<info>Creating namespace build directory: <comment>%s</comment></info>', $path));
mkdir($path);
}
}
return $path;
}
|
php
|
protected function ensureBuildDir($path, OutputInterface $output)
{
$parts = explode(DIRECTORY_SEPARATOR, $this->getPath());
foreach ($parts as $part) {
if (!$part) continue;
$path .= DIRECTORY_SEPARATOR . $part;
if (!file_exists($path)) {
$output->writeln(sprintf('<info>Creating namespace build directory: <comment>%s</comment></info>', $path));
mkdir($path);
}
}
return $path;
}
|
[
"protected",
"function",
"ensureBuildDir",
"(",
"$",
"path",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"this",
"->",
"getPath",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"!",
"$",
"part",
")",
"continue",
";",
"$",
"path",
".=",
"DIRECTORY_SEPARATOR",
".",
"$",
"part",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>Creating namespace build directory: <comment>%s</comment></info>'",
",",
"$",
"path",
")",
")",
";",
"mkdir",
"(",
"$",
"path",
")",
";",
"}",
"}",
"return",
"$",
"path",
";",
"}"
] |
Ensures the build directory is in place
@param string $path
@param OutputInterface $output
@return string The directory
|
[
"Ensures",
"the",
"build",
"directory",
"is",
"in",
"place"
] |
7867503e1fc0acc47b4512fbd89bf742e03f79ba
|
https://github.com/varspool/sphpdox/blob/7867503e1fc0acc47b4512fbd89bf742e03f79ba/lib/Sphpdox/Element/NamespaceElement.php#L75-L91
|
226,683
|
varspool/sphpdox
|
lib/Sphpdox/Element/NamespaceElement.php
|
NamespaceElement.buildClasses
|
public function buildClasses($basedir, OutputInterface $output)
{
$target = $this->ensureBuildDir($basedir, $output);
foreach ($this->getClasses() as $element) {
$element->build($target, $output);
}
}
|
php
|
public function buildClasses($basedir, OutputInterface $output)
{
$target = $this->ensureBuildDir($basedir, $output);
foreach ($this->getClasses() as $element) {
$element->build($target, $output);
}
}
|
[
"public",
"function",
"buildClasses",
"(",
"$",
"basedir",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"ensureBuildDir",
"(",
"$",
"basedir",
",",
"$",
"output",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getClasses",
"(",
")",
"as",
"$",
"element",
")",
"{",
"$",
"element",
"->",
"build",
"(",
"$",
"target",
",",
"$",
"output",
")",
";",
"}",
"}"
] |
Builds the class information
@param unknown $basedir
@param OutputInterface $output
|
[
"Builds",
"the",
"class",
"information"
] |
7867503e1fc0acc47b4512fbd89bf742e03f79ba
|
https://github.com/varspool/sphpdox/blob/7867503e1fc0acc47b4512fbd89bf742e03f79ba/lib/Sphpdox/Element/NamespaceElement.php#L99-L106
|
226,684
|
varspool/sphpdox
|
lib/Sphpdox/Element/NamespaceElement.php
|
NamespaceElement.buildIndex
|
public function buildIndex($basedir, OutputInterface $output, array $options = array())
{
$target = $this->ensureBuildDir($basedir, $output);
$built_iterator = new DirectoryIterator($target);
$index = $target . DIRECTORY_SEPARATOR . 'index.rst';
$title = str_replace('\\', '\\\\', $this->reflection->getName());
if (isset($options['title'])) {
$title = $options['title'];
}
$depth = substr_count($this->reflection->getName(), '\\');
$template = str_repeat($this->titles[$depth], strlen($title)) . "\n";
$template .= $title . "\n";
$template .= str_repeat($this->titles[$depth], strlen($title)) . "\n\n";
$template .= $this->getNamespaceElement();
$template .= ".. toctree::\n\n";
foreach ($built_iterator as $file) {
if ($file->isDot()) continue;
if ($file->isFile() && !$file->getExtension() == 'rst') continue;
if ($file->isFile() && substr($file->getBaseName(), 0, 1) == '.') continue;
if ($file->getBaseName() == 'index.rst') continue;
$template .= ' ' . pathinfo($file->getPathName(), PATHINFO_FILENAME);
if ($file->isDir()) {
$template .= '/index';
}
$template .= "\n";
}
file_put_contents($index, $template);
}
|
php
|
public function buildIndex($basedir, OutputInterface $output, array $options = array())
{
$target = $this->ensureBuildDir($basedir, $output);
$built_iterator = new DirectoryIterator($target);
$index = $target . DIRECTORY_SEPARATOR . 'index.rst';
$title = str_replace('\\', '\\\\', $this->reflection->getName());
if (isset($options['title'])) {
$title = $options['title'];
}
$depth = substr_count($this->reflection->getName(), '\\');
$template = str_repeat($this->titles[$depth], strlen($title)) . "\n";
$template .= $title . "\n";
$template .= str_repeat($this->titles[$depth], strlen($title)) . "\n\n";
$template .= $this->getNamespaceElement();
$template .= ".. toctree::\n\n";
foreach ($built_iterator as $file) {
if ($file->isDot()) continue;
if ($file->isFile() && !$file->getExtension() == 'rst') continue;
if ($file->isFile() && substr($file->getBaseName(), 0, 1) == '.') continue;
if ($file->getBaseName() == 'index.rst') continue;
$template .= ' ' . pathinfo($file->getPathName(), PATHINFO_FILENAME);
if ($file->isDir()) {
$template .= '/index';
}
$template .= "\n";
}
file_put_contents($index, $template);
}
|
[
"public",
"function",
"buildIndex",
"(",
"$",
"basedir",
",",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"ensureBuildDir",
"(",
"$",
"basedir",
",",
"$",
"output",
")",
";",
"$",
"built_iterator",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"target",
")",
";",
"$",
"index",
"=",
"$",
"target",
".",
"DIRECTORY_SEPARATOR",
".",
"'index.rst'",
";",
"$",
"title",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
",",
"$",
"this",
"->",
"reflection",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'title'",
"]",
")",
")",
"{",
"$",
"title",
"=",
"$",
"options",
"[",
"'title'",
"]",
";",
"}",
"$",
"depth",
"=",
"substr_count",
"(",
"$",
"this",
"->",
"reflection",
"->",
"getName",
"(",
")",
",",
"'\\\\'",
")",
";",
"$",
"template",
"=",
"str_repeat",
"(",
"$",
"this",
"->",
"titles",
"[",
"$",
"depth",
"]",
",",
"strlen",
"(",
"$",
"title",
")",
")",
".",
"\"\\n\"",
";",
"$",
"template",
".=",
"$",
"title",
".",
"\"\\n\"",
";",
"$",
"template",
".=",
"str_repeat",
"(",
"$",
"this",
"->",
"titles",
"[",
"$",
"depth",
"]",
",",
"strlen",
"(",
"$",
"title",
")",
")",
".",
"\"\\n\\n\"",
";",
"$",
"template",
".=",
"$",
"this",
"->",
"getNamespaceElement",
"(",
")",
";",
"$",
"template",
".=",
"\".. toctree::\\n\\n\"",
";",
"foreach",
"(",
"$",
"built_iterator",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDot",
"(",
")",
")",
"continue",
";",
"if",
"(",
"$",
"file",
"->",
"isFile",
"(",
")",
"&&",
"!",
"$",
"file",
"->",
"getExtension",
"(",
")",
"==",
"'rst'",
")",
"continue",
";",
"if",
"(",
"$",
"file",
"->",
"isFile",
"(",
")",
"&&",
"substr",
"(",
"$",
"file",
"->",
"getBaseName",
"(",
")",
",",
"0",
",",
"1",
")",
"==",
"'.'",
")",
"continue",
";",
"if",
"(",
"$",
"file",
"->",
"getBaseName",
"(",
")",
"==",
"'index.rst'",
")",
"continue",
";",
"$",
"template",
".=",
"' '",
".",
"pathinfo",
"(",
"$",
"file",
"->",
"getPathName",
"(",
")",
",",
"PATHINFO_FILENAME",
")",
";",
"if",
"(",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"template",
".=",
"'/index'",
";",
"}",
"$",
"template",
".=",
"\"\\n\"",
";",
"}",
"file_put_contents",
"(",
"$",
"index",
",",
"$",
"template",
")",
";",
"}"
] |
Builds the index file
|
[
"Builds",
"the",
"index",
"file"
] |
7867503e1fc0acc47b4512fbd89bf742e03f79ba
|
https://github.com/varspool/sphpdox/blob/7867503e1fc0acc47b4512fbd89bf742e03f79ba/lib/Sphpdox/Element/NamespaceElement.php#L111-L148
|
226,685
|
ivmelo/suap-api-php
|
src/Ivmelo/SUAP/SUAP.php
|
SUAP.getMeuBoletim
|
public function getMeuBoletim($year, $term)
{
$url = $this->endpoint.'minhas-informacoes/boletim/'.$year.'/'.$term.'/';
return $this->doGetRequest($url);
}
|
php
|
public function getMeuBoletim($year, $term)
{
$url = $this->endpoint.'minhas-informacoes/boletim/'.$year.'/'.$term.'/';
return $this->doGetRequest($url);
}
|
[
"public",
"function",
"getMeuBoletim",
"(",
"$",
"year",
",",
"$",
"term",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"endpoint",
".",
"'minhas-informacoes/boletim/'",
".",
"$",
"year",
".",
"'/'",
".",
"$",
"term",
".",
"'/'",
";",
"return",
"$",
"this",
"->",
"doGetRequest",
"(",
"$",
"url",
")",
";",
"}"
] |
Pega o boletim do aluno autenticado.
@param int $year Ano letivo.
@param int $term Período letivo.
@return array $data Boletim do aluno.
|
[
"Pega",
"o",
"boletim",
"do",
"aluno",
"autenticado",
"."
] |
0c1f01ef6afce49c9700246e1e3ddd8b7b34b377
|
https://github.com/ivmelo/suap-api-php/blob/0c1f01ef6afce49c9700246e1e3ddd8b7b34b377/src/Ivmelo/SUAP/SUAP.php#L144-L149
|
226,686
|
ivmelo/suap-api-php
|
src/Ivmelo/SUAP/SUAP.php
|
SUAP.doGetRequest
|
private function doGetRequest($url)
{
$response = $this->client->request('GET', $url, [
'headers' => [
'Authorization' => 'JWT '.$this->token,
],
]);
$data = false;
if ($response->getStatusCode() == 200) {
$data = json_decode($response->getBody(), true);
}
return $data;
}
|
php
|
private function doGetRequest($url)
{
$response = $this->client->request('GET', $url, [
'headers' => [
'Authorization' => 'JWT '.$this->token,
],
]);
$data = false;
if ($response->getStatusCode() == 200) {
$data = json_decode($response->getBody(), true);
}
return $data;
}
|
[
"private",
"function",
"doGetRequest",
"(",
"$",
"url",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'GET'",
",",
"$",
"url",
",",
"[",
"'headers'",
"=>",
"[",
"'Authorization'",
"=>",
"'JWT '",
".",
"$",
"this",
"->",
"token",
",",
"]",
",",
"]",
")",
";",
"$",
"data",
"=",
"false",
";",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"==",
"200",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Faz um request GET para um endpoint definido.
@param string $url Url para fazer o request.
@return array $data Dados retornados pela API.
|
[
"Faz",
"um",
"request",
"GET",
"para",
"um",
"endpoint",
"definido",
"."
] |
0c1f01ef6afce49c9700246e1e3ddd8b7b34b377
|
https://github.com/ivmelo/suap-api-php/blob/0c1f01ef6afce49c9700246e1e3ddd8b7b34b377/src/Ivmelo/SUAP/SUAP.php#L251-L266
|
226,687
|
gigaai/framework
|
src/Storage/Eloquent/WPUser.php
|
WPUser.inGroup
|
public function inGroup($slug)
{
return $this->groups->contains(function ($group) use ($slug) {
return $group->slug === $slug || $group->id === $slug;
});
}
|
php
|
public function inGroup($slug)
{
return $this->groups->contains(function ($group) use ($slug) {
return $group->slug === $slug || $group->id === $slug;
});
}
|
[
"public",
"function",
"inGroup",
"(",
"$",
"slug",
")",
"{",
"return",
"$",
"this",
"->",
"groups",
"->",
"contains",
"(",
"function",
"(",
"$",
"group",
")",
"use",
"(",
"$",
"slug",
")",
"{",
"return",
"$",
"group",
"->",
"slug",
"===",
"$",
"slug",
"||",
"$",
"group",
"->",
"id",
"===",
"$",
"slug",
";",
"}",
")",
";",
"}"
] |
Check if current user in group by id or slug
@param Integer/String $slug
@return bool
|
[
"Check",
"if",
"current",
"user",
"in",
"group",
"by",
"id",
"or",
"slug"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Storage/Eloquent/WPUser.php#L90-L95
|
226,688
|
gigaai/framework
|
src/Storage/Eloquent/WPUser.php
|
WPUser.getFacebookPages
|
public function getFacebookPages()
{
// Returns null if they haven't connected to Facebook
if ($this->isConnectedToFacebook() !== true) {
return null;
}
$response = Facebook::load()->get('/me/accounts', $this->data('access_token'));
$chunks = [];
$edges = [];
// Load data through pagination
for ($i = 0; $i <= 100; $i++) {
if ($i === 0) {
$edges[0] = $response->getGraphEdge();
} else {
$edges[$i] = Facebook::load()->next($edges[$i-1]);
}
$metaData = $edges[$i]->getMetaData();
$chunks[$i] = $edges[$i]->asArray();
if ( ! isset($metaData['paging']['next'])) {
break;
}
}
$pages = [];
foreach ($chunks as $chunk) {
foreach ($chunk as $page) {
$pages[$page['id']] = $page;
}
}
// Returns the list of pages.
return collect($pages);
}
|
php
|
public function getFacebookPages()
{
// Returns null if they haven't connected to Facebook
if ($this->isConnectedToFacebook() !== true) {
return null;
}
$response = Facebook::load()->get('/me/accounts', $this->data('access_token'));
$chunks = [];
$edges = [];
// Load data through pagination
for ($i = 0; $i <= 100; $i++) {
if ($i === 0) {
$edges[0] = $response->getGraphEdge();
} else {
$edges[$i] = Facebook::load()->next($edges[$i-1]);
}
$metaData = $edges[$i]->getMetaData();
$chunks[$i] = $edges[$i]->asArray();
if ( ! isset($metaData['paging']['next'])) {
break;
}
}
$pages = [];
foreach ($chunks as $chunk) {
foreach ($chunk as $page) {
$pages[$page['id']] = $page;
}
}
// Returns the list of pages.
return collect($pages);
}
|
[
"public",
"function",
"getFacebookPages",
"(",
")",
"{",
"// Returns null if they haven't connected to Facebook",
"if",
"(",
"$",
"this",
"->",
"isConnectedToFacebook",
"(",
")",
"!==",
"true",
")",
"{",
"return",
"null",
";",
"}",
"$",
"response",
"=",
"Facebook",
"::",
"load",
"(",
")",
"->",
"get",
"(",
"'/me/accounts'",
",",
"$",
"this",
"->",
"data",
"(",
"'access_token'",
")",
")",
";",
"$",
"chunks",
"=",
"[",
"]",
";",
"$",
"edges",
"=",
"[",
"]",
";",
"// Load data through pagination",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"100",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"i",
"===",
"0",
")",
"{",
"$",
"edges",
"[",
"0",
"]",
"=",
"$",
"response",
"->",
"getGraphEdge",
"(",
")",
";",
"}",
"else",
"{",
"$",
"edges",
"[",
"$",
"i",
"]",
"=",
"Facebook",
"::",
"load",
"(",
")",
"->",
"next",
"(",
"$",
"edges",
"[",
"$",
"i",
"-",
"1",
"]",
")",
";",
"}",
"$",
"metaData",
"=",
"$",
"edges",
"[",
"$",
"i",
"]",
"->",
"getMetaData",
"(",
")",
";",
"$",
"chunks",
"[",
"$",
"i",
"]",
"=",
"$",
"edges",
"[",
"$",
"i",
"]",
"->",
"asArray",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"metaData",
"[",
"'paging'",
"]",
"[",
"'next'",
"]",
")",
")",
"{",
"break",
";",
"}",
"}",
"$",
"pages",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"chunks",
"as",
"$",
"chunk",
")",
"{",
"foreach",
"(",
"$",
"chunk",
"as",
"$",
"page",
")",
"{",
"$",
"pages",
"[",
"$",
"page",
"[",
"'id'",
"]",
"]",
"=",
"$",
"page",
";",
"}",
"}",
"// Returns the list of pages.",
"return",
"collect",
"(",
"$",
"pages",
")",
";",
"}"
] |
Get Facebook Pages of current user if connected to Facebook
@return mixed
|
[
"Get",
"Facebook",
"Pages",
"of",
"current",
"user",
"if",
"connected",
"to",
"Facebook"
] |
57380d93baf57bfdb8067e96c68ba72e4e993d96
|
https://github.com/gigaai/framework/blob/57380d93baf57bfdb8067e96c68ba72e4e993d96/src/Storage/Eloquent/WPUser.php#L110-L148
|
226,689
|
phergie/phergie-irc-bot-react
|
src/PluginProcessor/LoggerInjector.php
|
LoggerInjector.process
|
public function process(PluginInterface $plugin, Bot $bot)
{
if ($plugin instanceof LoggerAwareInterface) {
$plugin->setLogger($bot->getLogger());
}
}
|
php
|
public function process(PluginInterface $plugin, Bot $bot)
{
if ($plugin instanceof LoggerAwareInterface) {
$plugin->setLogger($bot->getLogger());
}
}
|
[
"public",
"function",
"process",
"(",
"PluginInterface",
"$",
"plugin",
",",
"Bot",
"$",
"bot",
")",
"{",
"if",
"(",
"$",
"plugin",
"instanceof",
"LoggerAwareInterface",
")",
"{",
"$",
"plugin",
"->",
"setLogger",
"(",
"$",
"bot",
"->",
"getLogger",
"(",
")",
")",
";",
"}",
"}"
] |
Injects the bot's logger into the plugin if it implements
\Psr\Log\LoggerAwareInterface.
@param \Phergie\Irc\Bot\React\PluginInterface $plugin Loaded plugin
@param \Phergie\Irc\Bot\React\Bot $bot Bot that loaded the plugin
|
[
"Injects",
"the",
"bot",
"s",
"logger",
"into",
"the",
"plugin",
"if",
"it",
"implements",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LoggerAwareInterface",
"."
] |
17745ef6b846513258af3dbd86e5612d3deb19b7
|
https://github.com/phergie/phergie-irc-bot-react/blob/17745ef6b846513258af3dbd86e5612d3deb19b7/src/PluginProcessor/LoggerInjector.php#L32-L37
|
226,690
|
jpcercal/environment
|
src/EnvironmentVariable.php
|
EnvironmentVariable.get
|
public function get($key, $defaultValue = null)
{
$rawValue = $this->getEnvironmentVariable($key);
return $this->getValue($rawValue, $defaultValue);
}
|
php
|
public function get($key, $defaultValue = null)
{
$rawValue = $this->getEnvironmentVariable($key);
return $this->getValue($rawValue, $defaultValue);
}
|
[
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"$",
"rawValue",
"=",
"$",
"this",
"->",
"getEnvironmentVariable",
"(",
"$",
"key",
")",
";",
"return",
"$",
"this",
"->",
"getValue",
"(",
"$",
"rawValue",
",",
"$",
"defaultValue",
")",
";",
"}"
] |
Get value from environment.
@param string $key
@param mixed $defaultValue
@return mixed
|
[
"Get",
"value",
"from",
"environment",
"."
] |
6be36b0585b1c856a86247e5d335063ba4f150f9
|
https://github.com/jpcercal/environment/blob/6be36b0585b1c856a86247e5d335063ba4f150f9/src/EnvironmentVariable.php#L72-L77
|
226,691
|
johannesschobel/dingoquerymapper
|
src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapperBuilder.php
|
DingoQueryMapperBuilder.createFromBuilder
|
public function createFromBuilder(Builder $builder)
{
$this->model = $builder->getModel();
$this->query = $builder;
$this->build();
return $this;
}
|
php
|
public function createFromBuilder(Builder $builder)
{
$this->model = $builder->getModel();
$this->query = $builder;
$this->build();
return $this;
}
|
[
"public",
"function",
"createFromBuilder",
"(",
"Builder",
"$",
"builder",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"builder",
"->",
"getModel",
"(",
")",
";",
"$",
"this",
"->",
"query",
"=",
"$",
"builder",
";",
"$",
"this",
"->",
"build",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Create the Query from an existing builder
@param Builder $builder
@return $this
|
[
"Create",
"the",
"Query",
"from",
"an",
"existing",
"builder"
] |
0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e
|
https://github.com/johannesschobel/dingoquerymapper/blob/0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e/src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapperBuilder.php#L95-L103
|
226,692
|
johannesschobel/dingoquerymapper
|
src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapperBuilder.php
|
DingoQueryMapperBuilder.createFromModel
|
public function createFromModel(Model $model)
{
$this->model = $model;
$this->query = $this->model->newQuery();
return $this;
}
|
php
|
public function createFromModel(Model $model)
{
$this->model = $model;
$this->query = $this->model->newQuery();
return $this;
}
|
[
"public",
"function",
"createFromModel",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"model",
";",
"$",
"this",
"->",
"query",
"=",
"$",
"this",
"->",
"model",
"->",
"newQuery",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Create the query from an empty model
@param Model $model
@return $this
|
[
"Create",
"the",
"query",
"from",
"an",
"empty",
"model"
] |
0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e
|
https://github.com/johannesschobel/dingoquerymapper/blob/0ae2c1a0b5e7e7cf405ced9ced605907a5809c0e/src/JohannesSchobel/DingoQueryMapper/Parser/DingoQueryMapperBuilder.php#L111-L117
|
226,693
|
kevinkhill/FontAwesomePHP
|
src/FontAwesomeHtmlEntity.php
|
FontAwesomeHtmlEntity.setIcon
|
protected function setIcon($icon)
{
if (is_string($icon) === false) {
throw new \InvalidArgumentException(
'The icon label must be a string.'
);
}
$this->icon = $icon;
return $this;
}
|
php
|
protected function setIcon($icon)
{
if (is_string($icon) === false) {
throw new \InvalidArgumentException(
'The icon label must be a string.'
);
}
$this->icon = $icon;
return $this;
}
|
[
"protected",
"function",
"setIcon",
"(",
"$",
"icon",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"icon",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The icon label must be a string.'",
")",
";",
"}",
"$",
"this",
"->",
"icon",
"=",
"$",
"icon",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets icon label
@access protected
@param string $icon Icon label, omitting the "fa-" prefix
@return self
@throws \InvalidArgumentException
|
[
"Sets",
"icon",
"label"
] |
e7d12d7422b23a5c3a09715d9ca3e24ff811c073
|
https://github.com/kevinkhill/FontAwesomePHP/blob/e7d12d7422b23a5c3a09715d9ca3e24ff811c073/src/FontAwesomeHtmlEntity.php#L149-L160
|
226,694
|
kevinkhill/FontAwesomePHP
|
src/FontAwesomeHtmlEntity.php
|
FontAwesomeHtmlEntity.setMask
|
protected function setMask($icon, $style='fas')
{
if (is_string($icon) === false) {
throw new \InvalidArgumentException(
'The mask icon label must be a string.'
);
}
if (is_string($style) === false) {
throw new \InvalidArgumentException(
'The mask style label must be a string.'
);
}
if (!in_array($style, $this->STYLES)) {
throw new \InvalidArgumentException(
'Invalid mask style.'
);
}
$this->mask = $style." fa-".$icon;
return $this;
}
|
php
|
protected function setMask($icon, $style='fas')
{
if (is_string($icon) === false) {
throw new \InvalidArgumentException(
'The mask icon label must be a string.'
);
}
if (is_string($style) === false) {
throw new \InvalidArgumentException(
'The mask style label must be a string.'
);
}
if (!in_array($style, $this->STYLES)) {
throw new \InvalidArgumentException(
'Invalid mask style.'
);
}
$this->mask = $style." fa-".$icon;
return $this;
}
|
[
"protected",
"function",
"setMask",
"(",
"$",
"icon",
",",
"$",
"style",
"=",
"'fas'",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"icon",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The mask icon label must be a string.'",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"style",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The mask style label must be a string.'",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"style",
",",
"$",
"this",
"->",
"STYLES",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid mask style.'",
")",
";",
"}",
"$",
"this",
"->",
"mask",
"=",
"$",
"style",
".",
"\" fa-\"",
".",
"$",
"icon",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets mask label
@access protected
@param string $icon Icon label, omitting the "fa-" prefix
@param string $style Style label
@return self
@throws \InvalidArgumentException
|
[
"Sets",
"mask",
"label"
] |
e7d12d7422b23a5c3a09715d9ca3e24ff811c073
|
https://github.com/kevinkhill/FontAwesomePHP/blob/e7d12d7422b23a5c3a09715d9ca3e24ff811c073/src/FontAwesomeHtmlEntity.php#L171-L192
|
226,695
|
kevinkhill/FontAwesomePHP
|
src/FontAwesomeHtmlEntity.php
|
FontAwesomeHtmlEntity.setStyle
|
protected function setStyle($style)
{
if (is_string($style) === false) {
throw new \InvalidArgumentException(
'The style label must be a string.'
);
}
if (!in_array($style, $this->STYLES)) {
throw new \InvalidArgumentException(
'Invalid style.'
);
}
$this->style = $style;
return $this;
}
|
php
|
protected function setStyle($style)
{
if (is_string($style) === false) {
throw new \InvalidArgumentException(
'The style label must be a string.'
);
}
if (!in_array($style, $this->STYLES)) {
throw new \InvalidArgumentException(
'Invalid style.'
);
}
$this->style = $style;
return $this;
}
|
[
"protected",
"function",
"setStyle",
"(",
"$",
"style",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"style",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The style label must be a string.'",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"style",
",",
"$",
"this",
"->",
"STYLES",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid style.'",
")",
";",
"}",
"$",
"this",
"->",
"style",
"=",
"$",
"style",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets style label
@access protected
@param string $style Font Awesome style ('fas', 'far', 'fal', 'fab')
@return self
@throws \InvalidArgumentException
|
[
"Sets",
"style",
"label"
] |
e7d12d7422b23a5c3a09715d9ca3e24ff811c073
|
https://github.com/kevinkhill/FontAwesomePHP/blob/e7d12d7422b23a5c3a09715d9ca3e24ff811c073/src/FontAwesomeHtmlEntity.php#L202-L218
|
226,696
|
kevinkhill/FontAwesomePHP
|
src/FontAwesomeHtmlEntity.php
|
FontAwesomeHtmlEntity.addAttr
|
public function addAttr($attr, $val)
{
if (is_string($attr) === false) {
throw new \InvalidArgumentException;
}
$this->attributes[$attr] = $val;
return $this;
}
|
php
|
public function addAttr($attr, $val)
{
if (is_string($attr) === false) {
throw new \InvalidArgumentException;
}
$this->attributes[$attr] = $val;
return $this;
}
|
[
"public",
"function",
"addAttr",
"(",
"$",
"attr",
",",
"$",
"val",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"attr",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
";",
"}",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attr",
"]",
"=",
"$",
"val",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds an attribute to the icon, useful for title or id
@since 1.1.0
@param string $attr Which attribute to add
@param mixed $val The value of the attribute
@return self
@throws \InvalidArgumentException
|
[
"Adds",
"an",
"attribute",
"to",
"the",
"icon",
"useful",
"for",
"title",
"or",
"id"
] |
e7d12d7422b23a5c3a09715d9ca3e24ff811c073
|
https://github.com/kevinkhill/FontAwesomePHP/blob/e7d12d7422b23a5c3a09715d9ca3e24ff811c073/src/FontAwesomeHtmlEntity.php#L246-L255
|
226,697
|
kevinkhill/FontAwesomePHP
|
src/FontAwesomeHtmlEntity.php
|
FontAwesomeHtmlEntity.addAttrs
|
public function addAttrs(array $attrs)
{
foreach ($attrs as $attr => $val) {
$this->addAttr($attr, $val);
}
return $this;
}
|
php
|
public function addAttrs(array $attrs)
{
foreach ($attrs as $attr => $val) {
$this->addAttr($attr, $val);
}
return $this;
}
|
[
"public",
"function",
"addAttrs",
"(",
"array",
"$",
"attrs",
")",
"{",
"foreach",
"(",
"$",
"attrs",
"as",
"$",
"attr",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"addAttr",
"(",
"$",
"attr",
",",
"$",
"val",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Batch adds an attributes to the icon
@since 1.1.0
@param array $attrs Array of attributes to add
@return self
@throws \InvalidArgumentException
|
[
"Batch",
"adds",
"an",
"attributes",
"to",
"the",
"icon"
] |
e7d12d7422b23a5c3a09715d9ca3e24ff811c073
|
https://github.com/kevinkhill/FontAwesomePHP/blob/e7d12d7422b23a5c3a09715d9ca3e24ff811c073/src/FontAwesomeHtmlEntity.php#L265-L272
|
226,698
|
oleglfed/laravel-ddd
|
src/Commands/GenerateDomain.php
|
GenerateDomain.createDirectories
|
public function createDirectories()
{
if (!file_exists($this->getDomainPath())) {
mkdir($this->getDomainPath(), 0777);
}
if (!file_exists($this->getInfrastructurePath())) {
mkdir($this->getInfrastructurePath(), 0777);
}
if (!file_exists($this->getTestPath())) {
mkdir($this->getTestPath(), 0777);
}
if (!$this->option('without-abstracts')) {
$this->copyAbstractClasses();
}
$this->setDomainPath($this->getDomainPath(DIRECTORY_SEPARATOR.$this->getDirectory()));
$this->setInfrastructurePath($this->getInfrastructurePath(DIRECTORY_SEPARATOR.$this->getDirectory()));
$this->setTestPath($this->getTestPath(DIRECTORY_SEPARATOR.$this->getDirectory()));
if (!file_exists($this->getDomainPath())) {
mkdir($this->getDomainPath(), 0777);
mkdir($this->getDomainPath('/Contracts'), 0777);
}
if (!file_exists($this->getInfrastructurePath())) {
mkdir($this->getInfrastructurePath(), 0777);
mkdir($this->getInfrastructurePath('/Contracts'), 0777);
}
if (!file_exists($this->getTestPath())) {
mkdir($this->getTestPath(), 0777);
}
return true;
}
|
php
|
public function createDirectories()
{
if (!file_exists($this->getDomainPath())) {
mkdir($this->getDomainPath(), 0777);
}
if (!file_exists($this->getInfrastructurePath())) {
mkdir($this->getInfrastructurePath(), 0777);
}
if (!file_exists($this->getTestPath())) {
mkdir($this->getTestPath(), 0777);
}
if (!$this->option('without-abstracts')) {
$this->copyAbstractClasses();
}
$this->setDomainPath($this->getDomainPath(DIRECTORY_SEPARATOR.$this->getDirectory()));
$this->setInfrastructurePath($this->getInfrastructurePath(DIRECTORY_SEPARATOR.$this->getDirectory()));
$this->setTestPath($this->getTestPath(DIRECTORY_SEPARATOR.$this->getDirectory()));
if (!file_exists($this->getDomainPath())) {
mkdir($this->getDomainPath(), 0777);
mkdir($this->getDomainPath('/Contracts'), 0777);
}
if (!file_exists($this->getInfrastructurePath())) {
mkdir($this->getInfrastructurePath(), 0777);
mkdir($this->getInfrastructurePath('/Contracts'), 0777);
}
if (!file_exists($this->getTestPath())) {
mkdir($this->getTestPath(), 0777);
}
return true;
}
|
[
"public",
"function",
"createDirectories",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
")",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
")",
",",
"0777",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"getInfrastructurePath",
"(",
")",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"getInfrastructurePath",
"(",
")",
",",
"0777",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"getTestPath",
"(",
")",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"getTestPath",
"(",
")",
",",
"0777",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"option",
"(",
"'without-abstracts'",
")",
")",
"{",
"$",
"this",
"->",
"copyAbstractClasses",
"(",
")",
";",
"}",
"$",
"this",
"->",
"setDomainPath",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"getDirectory",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"setInfrastructurePath",
"(",
"$",
"this",
"->",
"getInfrastructurePath",
"(",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"getDirectory",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"setTestPath",
"(",
"$",
"this",
"->",
"getTestPath",
"(",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"getDirectory",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
")",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
")",
",",
"0777",
")",
";",
"mkdir",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
"'/Contracts'",
")",
",",
"0777",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"getInfrastructurePath",
"(",
")",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"getInfrastructurePath",
"(",
")",
",",
"0777",
")",
";",
"mkdir",
"(",
"$",
"this",
"->",
"getInfrastructurePath",
"(",
"'/Contracts'",
")",
",",
"0777",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"getTestPath",
"(",
")",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"getTestPath",
"(",
")",
",",
"0777",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Prepare directories.
@return bool
|
[
"Prepare",
"directories",
"."
] |
4e60759d29086fe041b2c158c8ae3a79eeeb70f7
|
https://github.com/oleglfed/laravel-ddd/blob/4e60759d29086fe041b2c158c8ae3a79eeeb70f7/src/Commands/GenerateDomain.php#L158-L195
|
226,699
|
oleglfed/laravel-ddd
|
src/Commands/GenerateDomain.php
|
GenerateDomain.copyDomain
|
public function copyDomain($name)
{
file_put_contents(
$this->getDomainPath("/Contracts/{$name}Interface.php"),
$this->prepare(file_get_contents($this->domainInterfaceContract))
);
file_put_contents(
$this->getDomainPath("/Contracts/{$name}RepositoryInterface.php"),
$this->prepare(file_get_contents($this->domainRepositoryContract))
);
file_put_contents(
$this->getDomainPath("/Contracts/{$name}ServiceInterface.php"),
$this->prepare(file_get_contents($this->domainServiceContract))
);
file_put_contents($this->getDomainPath("/{$name}Eloquent.php"), $this->prepare(file_get_contents($this->domainEloquent)));
file_put_contents($this->getDomainPath("/{$name}Repository.php"), $this->prepare(file_get_contents($this->domainRepository)));
file_put_contents($this->getDomainPath("/{$name}Service.php"), $this->prepare(file_get_contents($this->domainService)));
return true;
}
|
php
|
public function copyDomain($name)
{
file_put_contents(
$this->getDomainPath("/Contracts/{$name}Interface.php"),
$this->prepare(file_get_contents($this->domainInterfaceContract))
);
file_put_contents(
$this->getDomainPath("/Contracts/{$name}RepositoryInterface.php"),
$this->prepare(file_get_contents($this->domainRepositoryContract))
);
file_put_contents(
$this->getDomainPath("/Contracts/{$name}ServiceInterface.php"),
$this->prepare(file_get_contents($this->domainServiceContract))
);
file_put_contents($this->getDomainPath("/{$name}Eloquent.php"), $this->prepare(file_get_contents($this->domainEloquent)));
file_put_contents($this->getDomainPath("/{$name}Repository.php"), $this->prepare(file_get_contents($this->domainRepository)));
file_put_contents($this->getDomainPath("/{$name}Service.php"), $this->prepare(file_get_contents($this->domainService)));
return true;
}
|
[
"public",
"function",
"copyDomain",
"(",
"$",
"name",
")",
"{",
"file_put_contents",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
"\"/Contracts/{$name}Interface.php\"",
")",
",",
"$",
"this",
"->",
"prepare",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"domainInterfaceContract",
")",
")",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
"\"/Contracts/{$name}RepositoryInterface.php\"",
")",
",",
"$",
"this",
"->",
"prepare",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"domainRepositoryContract",
")",
")",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
"\"/Contracts/{$name}ServiceInterface.php\"",
")",
",",
"$",
"this",
"->",
"prepare",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"domainServiceContract",
")",
")",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
"\"/{$name}Eloquent.php\"",
")",
",",
"$",
"this",
"->",
"prepare",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"domainEloquent",
")",
")",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
"\"/{$name}Repository.php\"",
")",
",",
"$",
"this",
"->",
"prepare",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"domainRepository",
")",
")",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"getDomainPath",
"(",
"\"/{$name}Service.php\"",
")",
",",
"$",
"this",
"->",
"prepare",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"domainService",
")",
")",
")",
";",
"return",
"true",
";",
"}"
] |
Copy domains.
@param $name
@return bool
|
[
"Copy",
"domains",
"."
] |
4e60759d29086fe041b2c158c8ae3a79eeeb70f7
|
https://github.com/oleglfed/laravel-ddd/blob/4e60759d29086fe041b2c158c8ae3a79eeeb70f7/src/Commands/GenerateDomain.php#L278-L300
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.