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
|
---|---|---|---|---|---|---|---|---|---|---|---|
17,800 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.last | public function last(callable $callback = null, $default = null)
{
$collection = $callback ? $this->filter($callback) : $this;
foreach ($collection->all() as $key => $value) {
// Nothing needed here
}
return isset($value) ? $value : $default;
} | php | public function last(callable $callback = null, $default = null)
{
$collection = $callback ? $this->filter($callback) : $this;
foreach ($collection->all() as $key => $value) {
// Nothing needed here
}
return isset($value) ? $value : $default;
} | [
"public",
"function",
"last",
"(",
"callable",
"$",
"callback",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"collection",
"=",
"$",
"callback",
"?",
"$",
"this",
"->",
"filter",
"(",
"$",
"callback",
")",
":",
"$",
"this",
";",
"foreach",
"(",
"$",
"collection",
"->",
"all",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Nothing needed here",
"}",
"return",
"isset",
"(",
"$",
"value",
")",
"?",
"$",
"value",
":",
"$",
"default",
";",
"}"
]
| Return the last element
@param callable|null $callback if a callback is provided, we will filter the collection using that callback
@param mixed $defualt
@return mixed | [
"Return",
"the",
"last",
"element"
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L556-L565 |
17,801 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.accessKey | private function accessKey($mixed, $key, $givenKey = null)
{
// Handle callable keys, just pass in the mixed and return the result.
if (is_callable($key)) {
return $key($mixed, $givenKey);
}
// If it's a string, an array, or accessible through []
if (is_string($mixed) || is_array($mixed) || $mixed instanceof ArrayAccess) {
return $mixed[$key];
}
// If it's an object
if (is_object($mixed)) {
return $mixed->{$key};
}
// Give up
throw new InvalidArgumentException('Invalid object type provided, cannot access key.');
} | php | private function accessKey($mixed, $key, $givenKey = null)
{
// Handle callable keys, just pass in the mixed and return the result.
if (is_callable($key)) {
return $key($mixed, $givenKey);
}
// If it's a string, an array, or accessible through []
if (is_string($mixed) || is_array($mixed) || $mixed instanceof ArrayAccess) {
return $mixed[$key];
}
// If it's an object
if (is_object($mixed)) {
return $mixed->{$key};
}
// Give up
throw new InvalidArgumentException('Invalid object type provided, cannot access key.');
} | [
"private",
"function",
"accessKey",
"(",
"$",
"mixed",
",",
"$",
"key",
",",
"$",
"givenKey",
"=",
"null",
")",
"{",
"// Handle callable keys, just pass in the mixed and return the result.",
"if",
"(",
"is_callable",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"key",
"(",
"$",
"mixed",
",",
"$",
"givenKey",
")",
";",
"}",
"// If it's a string, an array, or accessible through []",
"if",
"(",
"is_string",
"(",
"$",
"mixed",
")",
"||",
"is_array",
"(",
"$",
"mixed",
")",
"||",
"$",
"mixed",
"instanceof",
"ArrayAccess",
")",
"{",
"return",
"$",
"mixed",
"[",
"$",
"key",
"]",
";",
"}",
"// If it's an object",
"if",
"(",
"is_object",
"(",
"$",
"mixed",
")",
")",
"{",
"return",
"$",
"mixed",
"->",
"{",
"$",
"key",
"}",
";",
"}",
"// Give up",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid object type provided, cannot access key.'",
")",
";",
"}"
]
| Get a value from a mixed key
@param mixed $mixed
@param mixed $key
@param null|string $givenKey
@return mixed
@throws \InvalidArgumentException | [
"Get",
"a",
"value",
"from",
"a",
"mixed",
"key"
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L596-L615 |
17,802 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.append | public function append($items, bool $preserveKeys = true): CollectionInterface
{
return $this->wrap(function (Iterator $data) use ($items, $preserveKeys) {
$lists = [$data, self::make($items)];
foreach ($lists as $list) {
foreach ($list as $key => $item) {
if ($preserveKeys) {
yield $key => $item;
} else {
yield $item;
}
}
}
});
} | php | public function append($items, bool $preserveKeys = true): CollectionInterface
{
return $this->wrap(function (Iterator $data) use ($items, $preserveKeys) {
$lists = [$data, self::make($items)];
foreach ($lists as $list) {
foreach ($list as $key => $item) {
if ($preserveKeys) {
yield $key => $item;
} else {
yield $item;
}
}
}
});
} | [
"public",
"function",
"append",
"(",
"$",
"items",
",",
"bool",
"$",
"preserveKeys",
"=",
"true",
")",
":",
"CollectionInterface",
"{",
"return",
"$",
"this",
"->",
"wrap",
"(",
"function",
"(",
"Iterator",
"$",
"data",
")",
"use",
"(",
"$",
"items",
",",
"$",
"preserveKeys",
")",
"{",
"$",
"lists",
"=",
"[",
"$",
"data",
",",
"self",
"::",
"make",
"(",
"$",
"items",
")",
"]",
";",
"foreach",
"(",
"$",
"lists",
"as",
"$",
"list",
")",
"{",
"foreach",
"(",
"$",
"list",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"preserveKeys",
")",
"{",
"yield",
"$",
"key",
"=>",
"$",
"item",
";",
"}",
"else",
"{",
"yield",
"$",
"item",
";",
"}",
"}",
"}",
"}",
")",
";",
"}"
]
| Append items onto this collection
@param mixed $items
@param bool $preserveKeys
@return \Buttress\Collection\CollectionInterface | [
"Append",
"items",
"onto",
"this",
"collection"
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L704-L719 |
17,803 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.combine | public function combine($values): CollectionInterface
{
if ($values instanceof IteratorAggregate) {
$values = $values->getIterator();
} elseif (is_array($values)) {
$values = new ArrayIterator($values);
}
return $this->wrap(function (Iterator $keys) use ($values) {
foreach ($keys as $key) {
yield $key => $values->current();
$values->next();
}
});
} | php | public function combine($values): CollectionInterface
{
if ($values instanceof IteratorAggregate) {
$values = $values->getIterator();
} elseif (is_array($values)) {
$values = new ArrayIterator($values);
}
return $this->wrap(function (Iterator $keys) use ($values) {
foreach ($keys as $key) {
yield $key => $values->current();
$values->next();
}
});
} | [
"public",
"function",
"combine",
"(",
"$",
"values",
")",
":",
"CollectionInterface",
"{",
"if",
"(",
"$",
"values",
"instanceof",
"IteratorAggregate",
")",
"{",
"$",
"values",
"=",
"$",
"values",
"->",
"getIterator",
"(",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"new",
"ArrayIterator",
"(",
"$",
"values",
")",
";",
"}",
"return",
"$",
"this",
"->",
"wrap",
"(",
"function",
"(",
"Iterator",
"$",
"keys",
")",
"use",
"(",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"yield",
"$",
"key",
"=>",
"$",
"values",
"->",
"current",
"(",
")",
";",
"$",
"values",
"->",
"next",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Create a collection by using this collection for keys and another for its values.
@param mixed $values
@return CollectionInterface | [
"Create",
"a",
"collection",
"by",
"using",
"this",
"collection",
"for",
"keys",
"and",
"another",
"for",
"its",
"values",
"."
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L727-L741 |
17,804 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.put | public function put($key, $value): CollectionInterface
{
return $this->wrap(function (Iterator $data) use ($key, $value) {
$replaced = false;
foreach ($data as $dataKey => $datum) {
if ($key === $dataKey) {
yield $key => $value;
$replaced = true;
} else {
yield $dataKey => $datum;
}
}
if (!$replaced) {
yield $key => $value;
}
});
} | php | public function put($key, $value): CollectionInterface
{
return $this->wrap(function (Iterator $data) use ($key, $value) {
$replaced = false;
foreach ($data as $dataKey => $datum) {
if ($key === $dataKey) {
yield $key => $value;
$replaced = true;
} else {
yield $dataKey => $datum;
}
}
if (!$replaced) {
yield $key => $value;
}
});
} | [
"public",
"function",
"put",
"(",
"$",
"key",
",",
"$",
"value",
")",
":",
"CollectionInterface",
"{",
"return",
"$",
"this",
"->",
"wrap",
"(",
"function",
"(",
"Iterator",
"$",
"data",
")",
"use",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"replaced",
"=",
"false",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"dataKey",
"=>",
"$",
"datum",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"$",
"dataKey",
")",
"{",
"yield",
"$",
"key",
"=>",
"$",
"value",
";",
"$",
"replaced",
"=",
"true",
";",
"}",
"else",
"{",
"yield",
"$",
"dataKey",
"=>",
"$",
"datum",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"replaced",
")",
"{",
"yield",
"$",
"key",
"=>",
"$",
"value",
";",
"}",
"}",
")",
";",
"}"
]
| Put an item in the collection by key.
@param mixed $key
@param mixed $value
@return CollectionInterface | [
"Put",
"an",
"item",
"in",
"the",
"collection",
"by",
"key",
"."
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L925-L943 |
17,805 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.reduce | public function reduce(callable $callback, $initial = null)
{
foreach ($this->generator as $key => $value) {
$initial = $callback($initial, $value, $key);
}
return $initial;
} | php | public function reduce(callable $callback, $initial = null)
{
foreach ($this->generator as $key => $value) {
$initial = $callback($initial, $value, $key);
}
return $initial;
} | [
"public",
"function",
"reduce",
"(",
"callable",
"$",
"callback",
",",
"$",
"initial",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"generator",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"initial",
"=",
"$",
"callback",
"(",
"$",
"initial",
",",
"$",
"value",
",",
"$",
"key",
")",
";",
"}",
"return",
"$",
"initial",
";",
"}"
]
| Reduce the collection to a single value.
@param callable $callback
@param mixed $initial
@return mixed | [
"Reduce",
"the",
"collection",
"to",
"a",
"single",
"value",
"."
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L952-L959 |
17,806 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.slice | public function slice($offset, $length = null): CollectionInterface
{
if ($length < 0) {
throw new InvalidArgumentException('Negative slice lengths are not supported');
}
$result = $this;
if ($offset < 0) {
$result = $this->take($offset);
} elseif ($offset > 0) {
$result = $this->offset($offset);
}
if ($length !== null) {
$result = $result->take($length);
}
return $result;
} | php | public function slice($offset, $length = null): CollectionInterface
{
if ($length < 0) {
throw new InvalidArgumentException('Negative slice lengths are not supported');
}
$result = $this;
if ($offset < 0) {
$result = $this->take($offset);
} elseif ($offset > 0) {
$result = $this->offset($offset);
}
if ($length !== null) {
$result = $result->take($length);
}
return $result;
} | [
"public",
"function",
"slice",
"(",
"$",
"offset",
",",
"$",
"length",
"=",
"null",
")",
":",
"CollectionInterface",
"{",
"if",
"(",
"$",
"length",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Negative slice lengths are not supported'",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
";",
"if",
"(",
"$",
"offset",
"<",
"0",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"take",
"(",
"$",
"offset",
")",
";",
"}",
"elseif",
"(",
"$",
"offset",
">",
"0",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"offset",
"(",
"$",
"offset",
")",
";",
"}",
"if",
"(",
"$",
"length",
"!==",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"result",
"->",
"take",
"(",
"$",
"length",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Slice the underlying collection array.
@param int $offset
@param int $length
@return CollectionInterface
@throws \InvalidArgumentException | [
"Slice",
"the",
"underlying",
"collection",
"array",
"."
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L991-L1009 |
17,807 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.offset | private function offset($offset): CollectionInterface
{
return $this->wrap(function (Iterator $iterator) use ($offset) {
while ($offset-- > 0 && $iterator->valid()) {
$iterator->next();
}
while ($iterator->valid()) {
yield $iterator->key() => $iterator->current();
$iterator->next();
}
});
} | php | private function offset($offset): CollectionInterface
{
return $this->wrap(function (Iterator $iterator) use ($offset) {
while ($offset-- > 0 && $iterator->valid()) {
$iterator->next();
}
while ($iterator->valid()) {
yield $iterator->key() => $iterator->current();
$iterator->next();
}
});
} | [
"private",
"function",
"offset",
"(",
"$",
"offset",
")",
":",
"CollectionInterface",
"{",
"return",
"$",
"this",
"->",
"wrap",
"(",
"function",
"(",
"Iterator",
"$",
"iterator",
")",
"use",
"(",
"$",
"offset",
")",
"{",
"while",
"(",
"$",
"offset",
"--",
">",
"0",
"&&",
"$",
"iterator",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"iterator",
"->",
"next",
"(",
")",
";",
"}",
"while",
"(",
"$",
"iterator",
"->",
"valid",
"(",
")",
")",
"{",
"yield",
"$",
"iterator",
"->",
"key",
"(",
")",
"=>",
"$",
"iterator",
"->",
"current",
"(",
")",
";",
"$",
"iterator",
"->",
"next",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Get items past an offset
@param $offset
@return CollectionInterface | [
"Get",
"items",
"past",
"an",
"offset"
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1016-L1028 |
17,808 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.takeFirst | public function takeFirst(int $count)
{
return $this->wrap(function (Iterator $data) use ($count) {
$first = true;
while ($count-- && $data->valid()) {
if (!$first) {
$data->next();
}
yield $data->key() => $data->current();
$first = false;
}
});
} | php | public function takeFirst(int $count)
{
return $this->wrap(function (Iterator $data) use ($count) {
$first = true;
while ($count-- && $data->valid()) {
if (!$first) {
$data->next();
}
yield $data->key() => $data->current();
$first = false;
}
});
} | [
"public",
"function",
"takeFirst",
"(",
"int",
"$",
"count",
")",
"{",
"return",
"$",
"this",
"->",
"wrap",
"(",
"function",
"(",
"Iterator",
"$",
"data",
")",
"use",
"(",
"$",
"count",
")",
"{",
"$",
"first",
"=",
"true",
";",
"while",
"(",
"$",
"count",
"--",
"&&",
"$",
"data",
"->",
"valid",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"first",
")",
"{",
"$",
"data",
"->",
"next",
"(",
")",
";",
"}",
"yield",
"$",
"data",
"->",
"key",
"(",
")",
"=>",
"$",
"data",
"->",
"current",
"(",
")",
";",
"$",
"first",
"=",
"false",
";",
"}",
"}",
")",
";",
"}"
]
| Take items from the beginning of the collection
@param int $count
@return \Buttress\Collection\CollectionInterface | [
"Take",
"items",
"from",
"the",
"beginning",
"of",
"the",
"collection"
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1143-L1157 |
17,809 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.takeLast | public function takeLast(int $count)
{
return $this->wrap(function (Iterator $data) use ($count) {
// From the end of the collection
$limit = max(0, $count);
$chunk = [];
foreach ($data as $key => $datum) {
$chunk[] = [$key, $datum];
if (count($chunk) > $limit) {
array_shift($chunk);
}
}
foreach ($chunk as $item) {
[$key, $datum] = $item;
yield $key => $datum;
}
});
} | php | public function takeLast(int $count)
{
return $this->wrap(function (Iterator $data) use ($count) {
// From the end of the collection
$limit = max(0, $count);
$chunk = [];
foreach ($data as $key => $datum) {
$chunk[] = [$key, $datum];
if (count($chunk) > $limit) {
array_shift($chunk);
}
}
foreach ($chunk as $item) {
[$key, $datum] = $item;
yield $key => $datum;
}
});
} | [
"public",
"function",
"takeLast",
"(",
"int",
"$",
"count",
")",
"{",
"return",
"$",
"this",
"->",
"wrap",
"(",
"function",
"(",
"Iterator",
"$",
"data",
")",
"use",
"(",
"$",
"count",
")",
"{",
"// From the end of the collection",
"$",
"limit",
"=",
"max",
"(",
"0",
",",
"$",
"count",
")",
";",
"$",
"chunk",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"datum",
")",
"{",
"$",
"chunk",
"[",
"]",
"=",
"[",
"$",
"key",
",",
"$",
"datum",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"chunk",
")",
">",
"$",
"limit",
")",
"{",
"array_shift",
"(",
"$",
"chunk",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"chunk",
"as",
"$",
"item",
")",
"{",
"[",
"$",
"key",
",",
"$",
"datum",
"]",
"=",
"$",
"item",
";",
"yield",
"$",
"key",
"=>",
"$",
"datum",
";",
"}",
"}",
")",
";",
"}"
]
| Take items from the end of the collection
@param int $count
@return \Buttress\Collection\CollectionInterface | [
"Take",
"items",
"from",
"the",
"end",
"of",
"the",
"collection"
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1165-L1184 |
17,810 | buttress/collecterator | src/GeneratorCollection.php | GeneratorCollection.values | public function values(): CollectionInterface
{
return $this->wrap(function (Iterator $data) {
foreach ($data as $item) {
yield $item;
}
});
} | php | public function values(): CollectionInterface
{
return $this->wrap(function (Iterator $data) {
foreach ($data as $item) {
yield $item;
}
});
} | [
"public",
"function",
"values",
"(",
")",
":",
"CollectionInterface",
"{",
"return",
"$",
"this",
"->",
"wrap",
"(",
"function",
"(",
"Iterator",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"item",
")",
"{",
"yield",
"$",
"item",
";",
"}",
"}",
")",
";",
"}"
]
| Reset the keys on the underlying array.
@return CollectionInterface | [
"Reset",
"the",
"keys",
"on",
"the",
"underlying",
"array",
"."
]
| 21e761c9c0457d85b5ec62d11051de2a62c3ee34 | https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1240-L1247 |
17,811 | iocaste/microservice-foundation | src/Http/Responds.php | Responds.respond | public function respond(array $data = [], array $headers = []): JsonResponse
{
$meta = [
'meta' => [
'server_time' => time(),
'server_timezone' => date_default_timezone_get(),
'api_version' => 'v1',
],
];
return response()->json(array_merge($data, $meta), $this->getStatusCode(), $headers);
} | php | public function respond(array $data = [], array $headers = []): JsonResponse
{
$meta = [
'meta' => [
'server_time' => time(),
'server_timezone' => date_default_timezone_get(),
'api_version' => 'v1',
],
];
return response()->json(array_merge($data, $meta), $this->getStatusCode(), $headers);
} | [
"public",
"function",
"respond",
"(",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"JsonResponse",
"{",
"$",
"meta",
"=",
"[",
"'meta'",
"=>",
"[",
"'server_time'",
"=>",
"time",
"(",
")",
",",
"'server_timezone'",
"=>",
"date_default_timezone_get",
"(",
")",
",",
"'api_version'",
"=>",
"'v1'",
",",
"]",
",",
"]",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"array_merge",
"(",
"$",
"data",
",",
"$",
"meta",
")",
",",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"headers",
")",
";",
"}"
]
| Return JSON encoded response.
@param array $data
@param array $headers
@return \Illuminate\Http\JsonResponse | [
"Return",
"JSON",
"encoded",
"response",
"."
]
| 274a154de4299e8a57314bab972e09f6d8cdae9e | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L53-L64 |
17,812 | iocaste/microservice-foundation | src/Http/Responds.php | Responds.respondWithError | public function respondWithError($code = null, $message = null, array $data = []): JsonResponse
{
return $this->respond([
'status' => [
'type' => 'error',
'message' => $this->getDefaultMessage($code, $message),
'code' => $code,
'http_code' => $this->getStatusCode(),
],
'exception' => $data,
]);
} | php | public function respondWithError($code = null, $message = null, array $data = []): JsonResponse
{
return $this->respond([
'status' => [
'type' => 'error',
'message' => $this->getDefaultMessage($code, $message),
'code' => $code,
'http_code' => $this->getStatusCode(),
],
'exception' => $data,
]);
} | [
"public",
"function",
"respondWithError",
"(",
"$",
"code",
"=",
"null",
",",
"$",
"message",
"=",
"null",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
":",
"JsonResponse",
"{",
"return",
"$",
"this",
"->",
"respond",
"(",
"[",
"'status'",
"=>",
"[",
"'type'",
"=>",
"'error'",
",",
"'message'",
"=>",
"$",
"this",
"->",
"getDefaultMessage",
"(",
"$",
"code",
",",
"$",
"message",
")",
",",
"'code'",
"=>",
"$",
"code",
",",
"'http_code'",
"=>",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
",",
"]",
",",
"'exception'",
"=>",
"$",
"data",
",",
"]",
")",
";",
"}"
]
| Return response with error.
@param null $code
@param null $message
@param array $data
@return JsonResponse | [
"Return",
"response",
"with",
"error",
"."
]
| 274a154de4299e8a57314bab972e09f6d8cdae9e | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L75-L86 |
17,813 | iocaste/microservice-foundation | src/Http/Responds.php | Responds.respondWithSuccess | public function respondWithSuccess(array $data = []): JsonResponse
{
return $this->setStatusCode(IlluminateResponse::HTTP_OK)->respond([
'status' => [
'http_code' => $this->getStatusCode(),
],
'data' => $data,
]);
} | php | public function respondWithSuccess(array $data = []): JsonResponse
{
return $this->setStatusCode(IlluminateResponse::HTTP_OK)->respond([
'status' => [
'http_code' => $this->getStatusCode(),
],
'data' => $data,
]);
} | [
"public",
"function",
"respondWithSuccess",
"(",
"array",
"$",
"data",
"=",
"[",
"]",
")",
":",
"JsonResponse",
"{",
"return",
"$",
"this",
"->",
"setStatusCode",
"(",
"IlluminateResponse",
"::",
"HTTP_OK",
")",
"->",
"respond",
"(",
"[",
"'status'",
"=>",
"[",
"'http_code'",
"=>",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
",",
"]",
",",
"'data'",
"=>",
"$",
"data",
",",
"]",
")",
";",
"}"
]
| Returns 200 response with data.
@param array $data
@return \Illuminate\Http\JsonResponse | [
"Returns",
"200",
"response",
"with",
"data",
"."
]
| 274a154de4299e8a57314bab972e09f6d8cdae9e | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L197-L205 |
17,814 | iocaste/microservice-foundation | src/Http/Responds.php | Responds.respondCreated | public function respondCreated($code = ApiResponse::CODE_SUCCESS, array $data = [], $message = null): JsonResponse
{
return $this->setStatusCode(IlluminateResponse::HTTP_CREATED)->respond([
'status' => [
'type' => 'success',
'message' => $this->getDefaultMessage($code, $message),
'code' => $code,
'http_code' => $this->getStatusCode(),
],
'data' => $data,
]);
} | php | public function respondCreated($code = ApiResponse::CODE_SUCCESS, array $data = [], $message = null): JsonResponse
{
return $this->setStatusCode(IlluminateResponse::HTTP_CREATED)->respond([
'status' => [
'type' => 'success',
'message' => $this->getDefaultMessage($code, $message),
'code' => $code,
'http_code' => $this->getStatusCode(),
],
'data' => $data,
]);
} | [
"public",
"function",
"respondCreated",
"(",
"$",
"code",
"=",
"ApiResponse",
"::",
"CODE_SUCCESS",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"message",
"=",
"null",
")",
":",
"JsonResponse",
"{",
"return",
"$",
"this",
"->",
"setStatusCode",
"(",
"IlluminateResponse",
"::",
"HTTP_CREATED",
")",
"->",
"respond",
"(",
"[",
"'status'",
"=>",
"[",
"'type'",
"=>",
"'success'",
",",
"'message'",
"=>",
"$",
"this",
"->",
"getDefaultMessage",
"(",
"$",
"code",
",",
"$",
"message",
")",
",",
"'code'",
"=>",
"$",
"code",
",",
"'http_code'",
"=>",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
",",
"]",
",",
"'data'",
"=>",
"$",
"data",
",",
"]",
")",
";",
"}"
]
| Returns 201 response with data.
@param int $code
@param array $data
@param null $message
@return \Illuminate\Http\JsonResponse | [
"Returns",
"201",
"response",
"with",
"data",
"."
]
| 274a154de4299e8a57314bab972e09f6d8cdae9e | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L216-L227 |
17,815 | iocaste/microservice-foundation | src/Http/Responds.php | Responds.respondDeleted | public function respondDeleted($code = ApiResponse::CODE_DELETED, array $data = [], $message = null): JsonResponse
{
return $this->setStatusCode(IlluminateResponse::HTTP_NO_CONTENT)->respond([
'status' => [
'type' => 'success',
'message' => $this->getDefaultMessage($code, $message),
'code' => $code,
'http_code' => $this->getStatusCode(),
],
'data' => $data,
]);
} | php | public function respondDeleted($code = ApiResponse::CODE_DELETED, array $data = [], $message = null): JsonResponse
{
return $this->setStatusCode(IlluminateResponse::HTTP_NO_CONTENT)->respond([
'status' => [
'type' => 'success',
'message' => $this->getDefaultMessage($code, $message),
'code' => $code,
'http_code' => $this->getStatusCode(),
],
'data' => $data,
]);
} | [
"public",
"function",
"respondDeleted",
"(",
"$",
"code",
"=",
"ApiResponse",
"::",
"CODE_DELETED",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"message",
"=",
"null",
")",
":",
"JsonResponse",
"{",
"return",
"$",
"this",
"->",
"setStatusCode",
"(",
"IlluminateResponse",
"::",
"HTTP_NO_CONTENT",
")",
"->",
"respond",
"(",
"[",
"'status'",
"=>",
"[",
"'type'",
"=>",
"'success'",
",",
"'message'",
"=>",
"$",
"this",
"->",
"getDefaultMessage",
"(",
"$",
"code",
",",
"$",
"message",
")",
",",
"'code'",
"=>",
"$",
"code",
",",
"'http_code'",
"=>",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
",",
"]",
",",
"'data'",
"=>",
"$",
"data",
",",
"]",
")",
";",
"}"
]
| Returns 204 response, enacted but the response does not include an entity.
@param int $code
@param array $data
@param string $message
@return \Illuminate\Http\JsonResponse | [
"Returns",
"204",
"response",
"enacted",
"but",
"the",
"response",
"does",
"not",
"include",
"an",
"entity",
"."
]
| 274a154de4299e8a57314bab972e09f6d8cdae9e | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L238-L249 |
17,816 | iocaste/microservice-foundation | src/Http/Responds.php | Responds.getDefaultMessage | protected function getDefaultMessage($code, $message): string
{
if ($code !== null && $message === null) {
return ApiResponse::$statusTexts[$code]['message'];
}
return $message;
} | php | protected function getDefaultMessage($code, $message): string
{
if ($code !== null && $message === null) {
return ApiResponse::$statusTexts[$code]['message'];
}
return $message;
} | [
"protected",
"function",
"getDefaultMessage",
"(",
"$",
"code",
",",
"$",
"message",
")",
":",
"string",
"{",
"if",
"(",
"$",
"code",
"!==",
"null",
"&&",
"$",
"message",
"===",
"null",
")",
"{",
"return",
"ApiResponse",
"::",
"$",
"statusTexts",
"[",
"$",
"code",
"]",
"[",
"'message'",
"]",
";",
"}",
"return",
"$",
"message",
";",
"}"
]
| Checks if specified code already has default message.
@param $code
@param $message
@return string | [
"Checks",
"if",
"specified",
"code",
"already",
"has",
"default",
"message",
"."
]
| 274a154de4299e8a57314bab972e09f6d8cdae9e | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L259-L266 |
17,817 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatAttributes | public function formatAttributes(array $attributes) {
foreach ($attributes as $key => $attr) {
if ($attr instanceof Closure) {
$attributes[$key] = call_user_func($attr, $this);
} else if ($this->hasKeyword($attr)) {
$attributes[$key] = $this->getKeyword($attr);
} else if ($attr === true) {
$attributes[$key] = $this->getKeyword($key);
} else {
$attributes[$key] = (string) $attr;
}
}
return $attributes;
} | php | public function formatAttributes(array $attributes) {
foreach ($attributes as $key => $attr) {
if ($attr instanceof Closure) {
$attributes[$key] = call_user_func($attr, $this);
} else if ($this->hasKeyword($attr)) {
$attributes[$key] = $this->getKeyword($attr);
} else if ($attr === true) {
$attributes[$key] = $this->getKeyword($key);
} else {
$attributes[$key] = (string) $attr;
}
}
return $attributes;
} | [
"public",
"function",
"formatAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"attr",
")",
"{",
"if",
"(",
"$",
"attr",
"instanceof",
"Closure",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"call_user_func",
"(",
"$",
"attr",
",",
"$",
"this",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"hasKeyword",
"(",
"$",
"attr",
")",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"attr",
")",
";",
"}",
"else",
"if",
"(",
"$",
"attr",
"===",
"true",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"key",
")",
";",
"}",
"else",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"attr",
";",
"}",
"}",
"return",
"$",
"attributes",
";",
"}"
]
| Prepare the list of attributes for rendering.
If an attribute is found within a keyword, use the keyword.
@param array $attributes
@return array | [
"Prepare",
"the",
"list",
"of",
"attributes",
"for",
"rendering",
".",
"If",
"an",
"attribute",
"is",
"found",
"within",
"a",
"keyword",
"use",
"the",
"keyword",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L230-L247 |
17,818 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatColumns | public function formatColumns(Schema $schema) {
$columns = [];
foreach ($schema->getColumns() as $column => $options) {
$dataType = $this->getDriver()->getType($options['type']);
$options = $options + $dataType->getDefaultOptions();
$type = $options['type'];
if (!empty($options['length'])) {
$type .= '(' . $options['length'] . ')';
}
$output = [$this->quote($column), strtoupper($type)];
// Integers
if (!empty($options['unsigned'])) {
$output[] = $this->getKeyword(self::UNSIGNED);
}
if (!empty($options['zerofill'])) {
$output[] = $this->getKeyword(self::ZEROFILL);
}
// Strings
if (!empty($options['charset'])) {
$output[] = sprintf($this->getClause(self::CHARACTER_SET), $options['charset']);
}
if (!empty($options['collate'])) {
$output[] = sprintf($this->getClause(self::COLLATE), $options['collate']);
}
// Primary and uniques can't be null
if (!empty($options['primary']) || !empty($options['unique'])) {
$output[] = $this->getKeyword(self::NOT_NULL);
} else {
$output[] = $this->getKeyword(empty($options['null']) ? self::NOT_NULL : self::NULL);
}
if (array_key_exists('default', $options)) {
$output[] = $this->formatDefault($options['default']);
}
if (!empty($options['ai'])) {
$output[] = $this->getKeyword(self::AUTO_INCREMENT);
}
if (!empty($options['comment'])) {
$output[] = sprintf($this->getClause(self::COMMENT), $this->getDriver()->escape(substr($options['comment'], 0, 255)));
}
$columns[] = trim(implode(' ', $output));
}
return implode(",\n", $columns);
} | php | public function formatColumns(Schema $schema) {
$columns = [];
foreach ($schema->getColumns() as $column => $options) {
$dataType = $this->getDriver()->getType($options['type']);
$options = $options + $dataType->getDefaultOptions();
$type = $options['type'];
if (!empty($options['length'])) {
$type .= '(' . $options['length'] . ')';
}
$output = [$this->quote($column), strtoupper($type)];
// Integers
if (!empty($options['unsigned'])) {
$output[] = $this->getKeyword(self::UNSIGNED);
}
if (!empty($options['zerofill'])) {
$output[] = $this->getKeyword(self::ZEROFILL);
}
// Strings
if (!empty($options['charset'])) {
$output[] = sprintf($this->getClause(self::CHARACTER_SET), $options['charset']);
}
if (!empty($options['collate'])) {
$output[] = sprintf($this->getClause(self::COLLATE), $options['collate']);
}
// Primary and uniques can't be null
if (!empty($options['primary']) || !empty($options['unique'])) {
$output[] = $this->getKeyword(self::NOT_NULL);
} else {
$output[] = $this->getKeyword(empty($options['null']) ? self::NOT_NULL : self::NULL);
}
if (array_key_exists('default', $options)) {
$output[] = $this->formatDefault($options['default']);
}
if (!empty($options['ai'])) {
$output[] = $this->getKeyword(self::AUTO_INCREMENT);
}
if (!empty($options['comment'])) {
$output[] = sprintf($this->getClause(self::COMMENT), $this->getDriver()->escape(substr($options['comment'], 0, 255)));
}
$columns[] = trim(implode(' ', $output));
}
return implode(",\n", $columns);
} | [
"public",
"function",
"formatColumns",
"(",
"Schema",
"$",
"schema",
")",
"{",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"schema",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
"=>",
"$",
"options",
")",
"{",
"$",
"dataType",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"getType",
"(",
"$",
"options",
"[",
"'type'",
"]",
")",
";",
"$",
"options",
"=",
"$",
"options",
"+",
"$",
"dataType",
"->",
"getDefaultOptions",
"(",
")",
";",
"$",
"type",
"=",
"$",
"options",
"[",
"'type'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'length'",
"]",
")",
")",
"{",
"$",
"type",
".=",
"'('",
".",
"$",
"options",
"[",
"'length'",
"]",
".",
"')'",
";",
"}",
"$",
"output",
"=",
"[",
"$",
"this",
"->",
"quote",
"(",
"$",
"column",
")",
",",
"strtoupper",
"(",
"$",
"type",
")",
"]",
";",
"// Integers",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'unsigned'",
"]",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"self",
"::",
"UNSIGNED",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'zerofill'",
"]",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"self",
"::",
"ZEROFILL",
")",
";",
"}",
"// Strings",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'charset'",
"]",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"CHARACTER_SET",
")",
",",
"$",
"options",
"[",
"'charset'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'collate'",
"]",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"COLLATE",
")",
",",
"$",
"options",
"[",
"'collate'",
"]",
")",
";",
"}",
"// Primary and uniques can't be null",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'primary'",
"]",
")",
"||",
"!",
"empty",
"(",
"$",
"options",
"[",
"'unique'",
"]",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"self",
"::",
"NOT_NULL",
")",
";",
"}",
"else",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"empty",
"(",
"$",
"options",
"[",
"'null'",
"]",
")",
"?",
"self",
"::",
"NOT_NULL",
":",
"self",
"::",
"NULL",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'default'",
",",
"$",
"options",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"formatDefault",
"(",
"$",
"options",
"[",
"'default'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'ai'",
"]",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"self",
"::",
"AUTO_INCREMENT",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'comment'",
"]",
")",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"COMMENT",
")",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"escape",
"(",
"substr",
"(",
"$",
"options",
"[",
"'comment'",
"]",
",",
"0",
",",
"255",
")",
")",
")",
";",
"}",
"$",
"columns",
"[",
"]",
"=",
"trim",
"(",
"implode",
"(",
"' '",
",",
"$",
"output",
")",
")",
";",
"}",
"return",
"implode",
"(",
"\",\\n\"",
",",
"$",
"columns",
")",
";",
"}"
]
| Format columns for a table schema.
@param \Titon\Db\Driver\Schema $schema
@return string | [
"Format",
"columns",
"for",
"a",
"table",
"schema",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L255-L311 |
17,819 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatDefault | public function formatDefault($value) {
if ($value === '') {
return '';
}
if ($value instanceof Closure) {
$value = call_user_func($value, $this);
} else if (is_string($value) || $value === null) {
$value = $this->getDriver()->escape($value);
}
return sprintf($this->getClause(self::DEFAULT_TO), $value);
} | php | public function formatDefault($value) {
if ($value === '') {
return '';
}
if ($value instanceof Closure) {
$value = call_user_func($value, $this);
} else if (is_string($value) || $value === null) {
$value = $this->getDriver()->escape($value);
}
return sprintf($this->getClause(self::DEFAULT_TO), $value);
} | [
"public",
"function",
"formatDefault",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"Closure",
")",
"{",
"$",
"value",
"=",
"call_user_func",
"(",
"$",
"value",
",",
"$",
"this",
")",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"escape",
"(",
"$",
"value",
")",
";",
"}",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"DEFAULT_TO",
")",
",",
"$",
"value",
")",
";",
"}"
]
| Format the default value of a column.
@param mixed $value
@return string | [
"Format",
"the",
"default",
"value",
"of",
"a",
"column",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L355-L368 |
17,820 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatExpression | public function formatExpression(Expr $expr) {
$field = $expr->getField();
$operator = $expr->getOperator();
$value = $expr->getValue();
if ($operator === Expr::AS_ALIAS) {
return sprintf($this->getClause(self::AS_ALIAS), $this->quote($field), $this->quote($value));
// No value to use so exit early
} else if (!$expr->useValue() && !($operator === Expr::NULL || $operator === Expr::NOT_NULL)) {
return $this->quote($field);
}
$isSubQuery = ($value instanceof SubQuery);
// Function as field
if ($field instanceof Func) {
$field = $this->formatFunction($field);
// Raw expression as field
} else if ($field instanceof RawExpr) {
$field = $field->getValue();
// Regular clause
} else {
$field = $this->quote($field);
}
// IN has special case
if ($operator === Expr::IN || $operator === Expr::NOT_IN) {
if ($isSubQuery) {
$clause = sprintf($this->getClause($operator), $field, '?');
$clause = str_replace(['(', ')'], '', $clause);
} else {
$clause = sprintf($this->getClause($operator), $field, implode(', ', array_fill(0, count($value), '?')));
}
// Operators with clauses
} else if ($this->hasClause($operator)) {
$clause = sprintf($this->getClause($operator), $field);
// Basic operator
} else {
$clause = sprintf($this->getClause(self::EXPRESSION), $field, $operator);
}
// Replace ? with sub-query statement
if ($isSubQuery) {
/** @type \Titon\Db\Query\SubQuery $value */
// EXISTS and NOT EXISTS doesn't have a field or operator
if (in_array($value->getFilter(), [SubQuery::EXISTS, SubQuery::NOT_EXISTS], true)) {
$clause = $this->formatSubQuery($value);
} else {
$clause = str_replace('?', $this->formatSubQuery($value), $clause);
}
}
return $clause;
} | php | public function formatExpression(Expr $expr) {
$field = $expr->getField();
$operator = $expr->getOperator();
$value = $expr->getValue();
if ($operator === Expr::AS_ALIAS) {
return sprintf($this->getClause(self::AS_ALIAS), $this->quote($field), $this->quote($value));
// No value to use so exit early
} else if (!$expr->useValue() && !($operator === Expr::NULL || $operator === Expr::NOT_NULL)) {
return $this->quote($field);
}
$isSubQuery = ($value instanceof SubQuery);
// Function as field
if ($field instanceof Func) {
$field = $this->formatFunction($field);
// Raw expression as field
} else if ($field instanceof RawExpr) {
$field = $field->getValue();
// Regular clause
} else {
$field = $this->quote($field);
}
// IN has special case
if ($operator === Expr::IN || $operator === Expr::NOT_IN) {
if ($isSubQuery) {
$clause = sprintf($this->getClause($operator), $field, '?');
$clause = str_replace(['(', ')'], '', $clause);
} else {
$clause = sprintf($this->getClause($operator), $field, implode(', ', array_fill(0, count($value), '?')));
}
// Operators with clauses
} else if ($this->hasClause($operator)) {
$clause = sprintf($this->getClause($operator), $field);
// Basic operator
} else {
$clause = sprintf($this->getClause(self::EXPRESSION), $field, $operator);
}
// Replace ? with sub-query statement
if ($isSubQuery) {
/** @type \Titon\Db\Query\SubQuery $value */
// EXISTS and NOT EXISTS doesn't have a field or operator
if (in_array($value->getFilter(), [SubQuery::EXISTS, SubQuery::NOT_EXISTS], true)) {
$clause = $this->formatSubQuery($value);
} else {
$clause = str_replace('?', $this->formatSubQuery($value), $clause);
}
}
return $clause;
} | [
"public",
"function",
"formatExpression",
"(",
"Expr",
"$",
"expr",
")",
"{",
"$",
"field",
"=",
"$",
"expr",
"->",
"getField",
"(",
")",
";",
"$",
"operator",
"=",
"$",
"expr",
"->",
"getOperator",
"(",
")",
";",
"$",
"value",
"=",
"$",
"expr",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"$",
"operator",
"===",
"Expr",
"::",
"AS_ALIAS",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"AS_ALIAS",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"field",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"value",
")",
")",
";",
"// No value to use so exit early",
"}",
"else",
"if",
"(",
"!",
"$",
"expr",
"->",
"useValue",
"(",
")",
"&&",
"!",
"(",
"$",
"operator",
"===",
"Expr",
"::",
"NULL",
"||",
"$",
"operator",
"===",
"Expr",
"::",
"NOT_NULL",
")",
")",
"{",
"return",
"$",
"this",
"->",
"quote",
"(",
"$",
"field",
")",
";",
"}",
"$",
"isSubQuery",
"=",
"(",
"$",
"value",
"instanceof",
"SubQuery",
")",
";",
"// Function as field",
"if",
"(",
"$",
"field",
"instanceof",
"Func",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"formatFunction",
"(",
"$",
"field",
")",
";",
"// Raw expression as field",
"}",
"else",
"if",
"(",
"$",
"field",
"instanceof",
"RawExpr",
")",
"{",
"$",
"field",
"=",
"$",
"field",
"->",
"getValue",
"(",
")",
";",
"// Regular clause",
"}",
"else",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"field",
")",
";",
"}",
"// IN has special case",
"if",
"(",
"$",
"operator",
"===",
"Expr",
"::",
"IN",
"||",
"$",
"operator",
"===",
"Expr",
"::",
"NOT_IN",
")",
"{",
"if",
"(",
"$",
"isSubQuery",
")",
"{",
"$",
"clause",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"$",
"operator",
")",
",",
"$",
"field",
",",
"'?'",
")",
";",
"$",
"clause",
"=",
"str_replace",
"(",
"[",
"'('",
",",
"')'",
"]",
",",
"''",
",",
"$",
"clause",
")",
";",
"}",
"else",
"{",
"$",
"clause",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"$",
"operator",
")",
",",
"$",
"field",
",",
"implode",
"(",
"', '",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"value",
")",
",",
"'?'",
")",
")",
")",
";",
"}",
"// Operators with clauses",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"hasClause",
"(",
"$",
"operator",
")",
")",
"{",
"$",
"clause",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"$",
"operator",
")",
",",
"$",
"field",
")",
";",
"// Basic operator",
"}",
"else",
"{",
"$",
"clause",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"EXPRESSION",
")",
",",
"$",
"field",
",",
"$",
"operator",
")",
";",
"}",
"// Replace ? with sub-query statement",
"if",
"(",
"$",
"isSubQuery",
")",
"{",
"/** @type \\Titon\\Db\\Query\\SubQuery $value */",
"// EXISTS and NOT EXISTS doesn't have a field or operator",
"if",
"(",
"in_array",
"(",
"$",
"value",
"->",
"getFilter",
"(",
")",
",",
"[",
"SubQuery",
"::",
"EXISTS",
",",
"SubQuery",
"::",
"NOT_EXISTS",
"]",
",",
"true",
")",
")",
"{",
"$",
"clause",
"=",
"$",
"this",
"->",
"formatSubQuery",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"clause",
"=",
"str_replace",
"(",
"'?'",
",",
"$",
"this",
"->",
"formatSubQuery",
"(",
"$",
"value",
")",
",",
"$",
"clause",
")",
";",
"}",
"}",
"return",
"$",
"clause",
";",
"}"
]
| Format database expressions.
@param \Titon\Db\Query\Expr $expr
@return string | [
"Format",
"database",
"expressions",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L376-L436 |
17,821 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatFunction | public function formatFunction(Func $func) {
$arguments = [];
foreach ($func->getArguments() as $arg) {
$type = $arg['type'];
$value = $arg['value'];
if ($value instanceof Func) {
$value = $this->formatFunction($value);
} else if ($value instanceof SubQuery) {
$value = $this->formatSubQuery($value);
} else if ($type === Func::FIELD) {
$value = $this->quote($value);
} else if ($type === Func::LITERAL) {
// Do nothing
} else if (is_string($value) || $value === null) {
$value = $this->getDriver()->escape($value);
}
$arguments[] = $value;
}
$output = sprintf($this->getClause(self::FUNC),
$func->getName(),
implode($func->getSeparator(), $arguments)
);
if ($alias = $func->getAlias()) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
return $output;
} | php | public function formatFunction(Func $func) {
$arguments = [];
foreach ($func->getArguments() as $arg) {
$type = $arg['type'];
$value = $arg['value'];
if ($value instanceof Func) {
$value = $this->formatFunction($value);
} else if ($value instanceof SubQuery) {
$value = $this->formatSubQuery($value);
} else if ($type === Func::FIELD) {
$value = $this->quote($value);
} else if ($type === Func::LITERAL) {
// Do nothing
} else if (is_string($value) || $value === null) {
$value = $this->getDriver()->escape($value);
}
$arguments[] = $value;
}
$output = sprintf($this->getClause(self::FUNC),
$func->getName(),
implode($func->getSeparator(), $arguments)
);
if ($alias = $func->getAlias()) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
return $output;
} | [
"public",
"function",
"formatFunction",
"(",
"Func",
"$",
"func",
")",
"{",
"$",
"arguments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"func",
"->",
"getArguments",
"(",
")",
"as",
"$",
"arg",
")",
"{",
"$",
"type",
"=",
"$",
"arg",
"[",
"'type'",
"]",
";",
"$",
"value",
"=",
"$",
"arg",
"[",
"'value'",
"]",
";",
"if",
"(",
"$",
"value",
"instanceof",
"Func",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"formatFunction",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"instanceof",
"SubQuery",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"formatSubQuery",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"Func",
"::",
"FIELD",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"Func",
"::",
"LITERAL",
")",
"{",
"// Do nothing",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"escape",
"(",
"$",
"value",
")",
";",
"}",
"$",
"arguments",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"FUNC",
")",
",",
"$",
"func",
"->",
"getName",
"(",
")",
",",
"implode",
"(",
"$",
"func",
"->",
"getSeparator",
"(",
")",
",",
"$",
"arguments",
")",
")",
";",
"if",
"(",
"$",
"alias",
"=",
"$",
"func",
"->",
"getAlias",
"(",
")",
")",
"{",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"AS_ALIAS",
")",
",",
"$",
"output",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"alias",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
]
| Format a database function.
@param \Titon\Db\Query\Func $func
@return string | [
"Format",
"a",
"database",
"function",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L624-L660 |
17,822 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatGroupBy | public function formatGroupBy(array $groupBy) {
if ($groupBy) {
return sprintf($this->getClause(self::GROUP_BY), $this->quoteList($groupBy));
}
return '';
} | php | public function formatGroupBy(array $groupBy) {
if ($groupBy) {
return sprintf($this->getClause(self::GROUP_BY), $this->quoteList($groupBy));
}
return '';
} | [
"public",
"function",
"formatGroupBy",
"(",
"array",
"$",
"groupBy",
")",
"{",
"if",
"(",
"$",
"groupBy",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"GROUP_BY",
")",
",",
"$",
"this",
"->",
"quoteList",
"(",
"$",
"groupBy",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the group by.
@param array $groupBy
@return string | [
"Format",
"the",
"group",
"by",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L668-L674 |
17,823 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatHaving | public function formatHaving(Predicate $having) {
if ($having->getParams()) {
return sprintf($this->getClause(self::HAVING), $this->formatPredicate($having));
}
return '';
} | php | public function formatHaving(Predicate $having) {
if ($having->getParams()) {
return sprintf($this->getClause(self::HAVING), $this->formatPredicate($having));
}
return '';
} | [
"public",
"function",
"formatHaving",
"(",
"Predicate",
"$",
"having",
")",
"{",
"if",
"(",
"$",
"having",
"->",
"getParams",
"(",
")",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"HAVING",
")",
",",
"$",
"this",
"->",
"formatPredicate",
"(",
"$",
"having",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the having clause.
@param \Titon\Db\Query\Predicate $having
@return string | [
"Format",
"the",
"having",
"clause",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L682-L688 |
17,824 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatJoins | public function formatJoins(array $joins) {
if ($joins) {
$output = [];
foreach ($joins as $join) {
$conditions = [];
foreach ($join->getOn() as $pfk => $rfk) {
$conditions[] = $this->quote($pfk) . ' = ' . $this->quote($rfk);
}
$output[] = sprintf($this->getClause($join->getType()),
$this->formatTable($join->getTable(), $join->getAlias()),
implode(' ' . $this->getKeyword(self::ALSO) . ' ', $conditions));
}
return implode(' ', $output);
}
return '';
} | php | public function formatJoins(array $joins) {
if ($joins) {
$output = [];
foreach ($joins as $join) {
$conditions = [];
foreach ($join->getOn() as $pfk => $rfk) {
$conditions[] = $this->quote($pfk) . ' = ' . $this->quote($rfk);
}
$output[] = sprintf($this->getClause($join->getType()),
$this->formatTable($join->getTable(), $join->getAlias()),
implode(' ' . $this->getKeyword(self::ALSO) . ' ', $conditions));
}
return implode(' ', $output);
}
return '';
} | [
"public",
"function",
"formatJoins",
"(",
"array",
"$",
"joins",
")",
"{",
"if",
"(",
"$",
"joins",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"joins",
"as",
"$",
"join",
")",
"{",
"$",
"conditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"join",
"->",
"getOn",
"(",
")",
"as",
"$",
"pfk",
"=>",
"$",
"rfk",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"pfk",
")",
".",
"' = '",
".",
"$",
"this",
"->",
"quote",
"(",
"$",
"rfk",
")",
";",
"}",
"$",
"output",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"$",
"join",
"->",
"getType",
"(",
")",
")",
",",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"join",
"->",
"getTable",
"(",
")",
",",
"$",
"join",
"->",
"getAlias",
"(",
")",
")",
",",
"implode",
"(",
"' '",
".",
"$",
"this",
"->",
"getKeyword",
"(",
"self",
"::",
"ALSO",
")",
".",
"' '",
",",
"$",
"conditions",
")",
")",
";",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"output",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the list of joins.
@param \Titon\Db\Query\Join[] $joins
@return string | [
"Format",
"the",
"list",
"of",
"joins",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L696-L716 |
17,825 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatLimit | public function formatLimit($limit) {
if ($limit) {
return sprintf($this->getClause(self::LIMIT), (int) $limit);
}
return '';
} | php | public function formatLimit($limit) {
if ($limit) {
return sprintf($this->getClause(self::LIMIT), (int) $limit);
}
return '';
} | [
"public",
"function",
"formatLimit",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"$",
"limit",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"LIMIT",
")",
",",
"(",
"int",
")",
"$",
"limit",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the limit.
@param int $limit
@return string | [
"Format",
"the",
"limit",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L724-L730 |
17,826 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatLimitOffset | public function formatLimitOffset($limit, $offset = 0) {
if ($limit && $offset) {
return sprintf($this->getClause(self::LIMIT_OFFSET), (int) $limit, (int) $offset);
}
return $this->formatLimit($limit);
} | php | public function formatLimitOffset($limit, $offset = 0) {
if ($limit && $offset) {
return sprintf($this->getClause(self::LIMIT_OFFSET), (int) $limit, (int) $offset);
}
return $this->formatLimit($limit);
} | [
"public",
"function",
"formatLimitOffset",
"(",
"$",
"limit",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"limit",
"&&",
"$",
"offset",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"LIMIT_OFFSET",
")",
",",
"(",
"int",
")",
"$",
"limit",
",",
"(",
"int",
")",
"$",
"offset",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatLimit",
"(",
"$",
"limit",
")",
";",
"}"
]
| Format the limit and offset.
@param int $limit
@param int $offset
@return string | [
"Format",
"the",
"limit",
"and",
"offset",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L739-L745 |
17,827 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatOrderBy | public function formatOrderBy(array $orderBy) {
if ($orderBy) {
$output = [];
foreach ($orderBy as $field => $direction) {
if ($direction instanceof Func) {
$output[] = $this->formatFunction($direction);
} else {
$output[] = $this->quote($field) . ' ' . $this->getKeyword($direction);
}
}
return sprintf($this->getClause(self::ORDER_BY), implode(', ', $output));
}
return '';
} | php | public function formatOrderBy(array $orderBy) {
if ($orderBy) {
$output = [];
foreach ($orderBy as $field => $direction) {
if ($direction instanceof Func) {
$output[] = $this->formatFunction($direction);
} else {
$output[] = $this->quote($field) . ' ' . $this->getKeyword($direction);
}
}
return sprintf($this->getClause(self::ORDER_BY), implode(', ', $output));
}
return '';
} | [
"public",
"function",
"formatOrderBy",
"(",
"array",
"$",
"orderBy",
")",
"{",
"if",
"(",
"$",
"orderBy",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"orderBy",
"as",
"$",
"field",
"=>",
"$",
"direction",
")",
"{",
"if",
"(",
"$",
"direction",
"instanceof",
"Func",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"formatFunction",
"(",
"$",
"direction",
")",
";",
"}",
"else",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"field",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"direction",
")",
";",
"}",
"}",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"ORDER_BY",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"output",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the order by.
@param array $orderBy
@return string | [
"Format",
"the",
"order",
"by",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L753-L769 |
17,828 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatPredicate | public function formatPredicate(Predicate $predicate) {
$output = [];
foreach ($predicate->getParams() as $param) {
if ($param instanceof Predicate) {
$output[] = sprintf($this->getClause(self::GROUP), $this->formatPredicate($param));
} else if ($param instanceof Expr) {
$output[] = $this->formatExpression($param);
}
}
return implode(' ' . $this->getKeyword($predicate->getType()) . ' ', $output);
} | php | public function formatPredicate(Predicate $predicate) {
$output = [];
foreach ($predicate->getParams() as $param) {
if ($param instanceof Predicate) {
$output[] = sprintf($this->getClause(self::GROUP), $this->formatPredicate($param));
} else if ($param instanceof Expr) {
$output[] = $this->formatExpression($param);
}
}
return implode(' ' . $this->getKeyword($predicate->getType()) . ' ', $output);
} | [
"public",
"function",
"formatPredicate",
"(",
"Predicate",
"$",
"predicate",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"predicate",
"->",
"getParams",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"instanceof",
"Predicate",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"GROUP",
")",
",",
"$",
"this",
"->",
"formatPredicate",
"(",
"$",
"param",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"param",
"instanceof",
"Expr",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"formatExpression",
"(",
"$",
"param",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"' '",
".",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"predicate",
"->",
"getType",
"(",
")",
")",
".",
"' '",
",",
"$",
"output",
")",
";",
"}"
]
| Format the predicate object by grouping nested predicates and parameters.
@param \Titon\Db\Query\Predicate $predicate
@return string | [
"Format",
"the",
"predicate",
"object",
"by",
"grouping",
"nested",
"predicates",
"and",
"parameters",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L777-L790 |
17,829 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatSubQuery | public function formatSubQuery(SubQuery $query) {
// Reset the alias since statement would have double aliasing
$alias = $query->getAlias();
$query->asAlias(null);
// @codeCoverageIgnoreStart
if (method_exists($this, 'buildSelect')) {
$output = sprintf($this->getClause(self::SUB_QUERY), trim($this->buildSelect($query), ';'));
} else {
throw new UnsupportedQueryStatementException('Sub-query building requires a buildSelect() method');
}
// @codeCoverageIgnoreEnd
if ($alias) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
if ($filter = $query->getFilter()) {
$output = $this->getKeyword($filter) . ' ' . $output;
}
return $output;
} | php | public function formatSubQuery(SubQuery $query) {
// Reset the alias since statement would have double aliasing
$alias = $query->getAlias();
$query->asAlias(null);
// @codeCoverageIgnoreStart
if (method_exists($this, 'buildSelect')) {
$output = sprintf($this->getClause(self::SUB_QUERY), trim($this->buildSelect($query), ';'));
} else {
throw new UnsupportedQueryStatementException('Sub-query building requires a buildSelect() method');
}
// @codeCoverageIgnoreEnd
if ($alias) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
if ($filter = $query->getFilter()) {
$output = $this->getKeyword($filter) . ' ' . $output;
}
return $output;
} | [
"public",
"function",
"formatSubQuery",
"(",
"SubQuery",
"$",
"query",
")",
"{",
"// Reset the alias since statement would have double aliasing",
"$",
"alias",
"=",
"$",
"query",
"->",
"getAlias",
"(",
")",
";",
"$",
"query",
"->",
"asAlias",
"(",
"null",
")",
";",
"// @codeCoverageIgnoreStart",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'buildSelect'",
")",
")",
"{",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"SUB_QUERY",
")",
",",
"trim",
"(",
"$",
"this",
"->",
"buildSelect",
"(",
"$",
"query",
")",
",",
"';'",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"UnsupportedQueryStatementException",
"(",
"'Sub-query building requires a buildSelect() method'",
")",
";",
"}",
"// @codeCoverageIgnoreEnd",
"if",
"(",
"$",
"alias",
")",
"{",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"AS_ALIAS",
")",
",",
"$",
"output",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"alias",
")",
")",
";",
"}",
"if",
"(",
"$",
"filter",
"=",
"$",
"query",
"->",
"getFilter",
"(",
")",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"filter",
")",
".",
"' '",
".",
"$",
"output",
";",
"}",
"return",
"$",
"output",
";",
"}"
]
| Format a sub-query.
@param \Titon\Db\Query\SubQuery $query
@return string
@throws \Titon\Db\Exception\UnsupportedQueryStatementException | [
"Format",
"a",
"sub",
"-",
"query",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L799-L822 |
17,830 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTable | public function formatTable($table, $alias = null) {
if (!$table) {
throw new InvalidTableException('Missing table name for query');
}
$output = $this->quote($table);
if ($alias && $table !== $alias) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
return $output;
} | php | public function formatTable($table, $alias = null) {
if (!$table) {
throw new InvalidTableException('Missing table name for query');
}
$output = $this->quote($table);
if ($alias && $table !== $alias) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
return $output;
} | [
"public",
"function",
"formatTable",
"(",
"$",
"table",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"table",
")",
"{",
"throw",
"new",
"InvalidTableException",
"(",
"'Missing table name for query'",
")",
";",
"}",
"$",
"output",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"table",
")",
";",
"if",
"(",
"$",
"alias",
"&&",
"$",
"table",
"!==",
"$",
"alias",
")",
"{",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"AS_ALIAS",
")",
",",
"$",
"output",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"alias",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
]
| Format the table name and alias name.
@param string $table
@param string $alias
@return string
@throws \Titon\Db\Exception\InvalidTableException | [
"Format",
"the",
"table",
"name",
"and",
"alias",
"name",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L832-L844 |
17,831 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTableForeign | public function formatTableForeign(array $data) {
$ref = explode('.', $data['references']);
$key = sprintf($this->getClause(self::FOREIGN_KEY), $this->quote($data['column']), $this->quote($ref[0]), $this->quote($ref[1]));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
$actions = $data;
unset($actions['references'], $actions['constraint'], $actions['column']);
foreach ($actions as $clause => $action) {
$value = '';
if ($this->hasKeyword($action)) {
$value = $this->getKeyword($action);
}
$key .= ' ' . sprintf($this->getClause($clause), $value);
}
return $key;
} | php | public function formatTableForeign(array $data) {
$ref = explode('.', $data['references']);
$key = sprintf($this->getClause(self::FOREIGN_KEY), $this->quote($data['column']), $this->quote($ref[0]), $this->quote($ref[1]));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
$actions = $data;
unset($actions['references'], $actions['constraint'], $actions['column']);
foreach ($actions as $clause => $action) {
$value = '';
if ($this->hasKeyword($action)) {
$value = $this->getKeyword($action);
}
$key .= ' ' . sprintf($this->getClause($clause), $value);
}
return $key;
} | [
"public",
"function",
"formatTableForeign",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"ref",
"=",
"explode",
"(",
"'.'",
",",
"$",
"data",
"[",
"'references'",
"]",
")",
";",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"FOREIGN_KEY",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'column'",
"]",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"ref",
"[",
"0",
"]",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"ref",
"[",
"1",
"]",
")",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"CONSTRAINT",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
")",
".",
"' '",
".",
"$",
"key",
";",
"}",
"$",
"actions",
"=",
"$",
"data",
";",
"unset",
"(",
"$",
"actions",
"[",
"'references'",
"]",
",",
"$",
"actions",
"[",
"'constraint'",
"]",
",",
"$",
"actions",
"[",
"'column'",
"]",
")",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"clause",
"=>",
"$",
"action",
")",
"{",
"$",
"value",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"hasKeyword",
"(",
"$",
"action",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"action",
")",
";",
"}",
"$",
"key",
".=",
"' '",
".",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"$",
"clause",
")",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"key",
";",
"}"
]
| Format a table foreign key.
@param array $data
@return string | [
"Format",
"a",
"table",
"foreign",
"key",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L852-L874 |
17,832 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTableIndex | public function formatTableIndex($index, array $columns) {
return sprintf($this->getClause(self::INDEX), $this->quote($index), $this->quoteList($columns));
} | php | public function formatTableIndex($index, array $columns) {
return sprintf($this->getClause(self::INDEX), $this->quote($index), $this->quoteList($columns));
} | [
"public",
"function",
"formatTableIndex",
"(",
"$",
"index",
",",
"array",
"$",
"columns",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"INDEX",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"index",
")",
",",
"$",
"this",
"->",
"quoteList",
"(",
"$",
"columns",
")",
")",
";",
"}"
]
| Format a table index key.
@param string $index
@param array $columns
@return string | [
"Format",
"a",
"table",
"index",
"key",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L883-L885 |
17,833 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTableOptions | public function formatTableOptions(array $options) {
$output = [];
foreach ($this->formatAttributes($options) as $key => $value) {
if ($this->hasClause($key)) {
$option = sprintf($this->getClause($key), $value);
} else {
$option = $this->getKeyword($key);
if ($value !== true) {
$option .= ' ' . $value;
}
}
$output[] = $option;
}
return implode(' ', $output);
} | php | public function formatTableOptions(array $options) {
$output = [];
foreach ($this->formatAttributes($options) as $key => $value) {
if ($this->hasClause($key)) {
$option = sprintf($this->getClause($key), $value);
} else {
$option = $this->getKeyword($key);
if ($value !== true) {
$option .= ' ' . $value;
}
}
$output[] = $option;
}
return implode(' ', $output);
} | [
"public",
"function",
"formatTableOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"options",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasClause",
"(",
"$",
"key",
")",
")",
"{",
"$",
"option",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"$",
"key",
")",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"option",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"true",
")",
"{",
"$",
"option",
".=",
"' '",
".",
"$",
"value",
";",
"}",
"}",
"$",
"output",
"[",
"]",
"=",
"$",
"option",
";",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"output",
")",
";",
"}"
]
| Format the table options for a create table statement.
@param array $options
@return string | [
"Format",
"the",
"table",
"options",
"for",
"a",
"create",
"table",
"statement",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L923-L942 |
17,834 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTablePrimary | public function formatTablePrimary(array $data) {
$key = sprintf($this->getClause(self::PRIMARY_KEY), $this->quoteList($data['columns']));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
return $key;
} | php | public function formatTablePrimary(array $data) {
$key = sprintf($this->getClause(self::PRIMARY_KEY), $this->quoteList($data['columns']));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
return $key;
} | [
"public",
"function",
"formatTablePrimary",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"PRIMARY_KEY",
")",
",",
"$",
"this",
"->",
"quoteList",
"(",
"$",
"data",
"[",
"'columns'",
"]",
")",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"CONSTRAINT",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
")",
".",
"' '",
".",
"$",
"key",
";",
"}",
"return",
"$",
"key",
";",
"}"
]
| Format a table primary key.
@param array $data
@return string | [
"Format",
"a",
"table",
"primary",
"key",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L950-L958 |
17,835 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTableUnique | public function formatTableUnique(array $data) {
$key = sprintf($this->getClause(self::UNIQUE_KEY), $this->quote($data['index']), $this->quoteList($data['columns']));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
return $key;
} | php | public function formatTableUnique(array $data) {
$key = sprintf($this->getClause(self::UNIQUE_KEY), $this->quote($data['index']), $this->quoteList($data['columns']));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
return $key;
} | [
"public",
"function",
"formatTableUnique",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"UNIQUE_KEY",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'index'",
"]",
")",
",",
"$",
"this",
"->",
"quoteList",
"(",
"$",
"data",
"[",
"'columns'",
"]",
")",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"CONSTRAINT",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
")",
".",
"' '",
".",
"$",
"key",
";",
"}",
"return",
"$",
"key",
";",
"}"
]
| Format a table unique key.
@param array $data
@return string | [
"Format",
"a",
"table",
"unique",
"key",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L966-L974 |
17,836 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatValues | public function formatValues(Query $query) {
$fields = $query->getData();
switch ($query->getType()) {
case Query::INSERT:
return sprintf($this->getClause(self::GROUP), implode(', ', array_fill(0, count($fields), '?')));
break;
case Query::MULTI_INSERT:
$value = sprintf($this->getClause(self::GROUP), implode(', ', array_fill(0, count($fields[0]), '?')));
return implode(', ', array_fill(0, count($fields), $value));
break;
}
return '';
} | php | public function formatValues(Query $query) {
$fields = $query->getData();
switch ($query->getType()) {
case Query::INSERT:
return sprintf($this->getClause(self::GROUP), implode(', ', array_fill(0, count($fields), '?')));
break;
case Query::MULTI_INSERT:
$value = sprintf($this->getClause(self::GROUP), implode(', ', array_fill(0, count($fields[0]), '?')));
return implode(', ', array_fill(0, count($fields), $value));
break;
}
return '';
} | [
"public",
"function",
"formatValues",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"fields",
"=",
"$",
"query",
"->",
"getData",
"(",
")",
";",
"switch",
"(",
"$",
"query",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"Query",
"::",
"INSERT",
":",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"GROUP",
")",
",",
"implode",
"(",
"', '",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"fields",
")",
",",
"'?'",
")",
")",
")",
";",
"break",
";",
"case",
"Query",
"::",
"MULTI_INSERT",
":",
"$",
"value",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"GROUP",
")",
",",
"implode",
"(",
"', '",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"fields",
"[",
"0",
"]",
")",
",",
"'?'",
")",
")",
")",
";",
"return",
"implode",
"(",
"', '",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"fields",
")",
",",
"$",
"value",
")",
")",
";",
"break",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the fields values structure depending on the type of query.
@param \Titon\Db\Query $query
@return string | [
"Format",
"the",
"fields",
"values",
"structure",
"depending",
"on",
"the",
"type",
"of",
"query",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L982-L997 |
17,837 | titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatWhere | public function formatWhere(Predicate $where) {
if ($where->getParams()) {
return sprintf($this->getClause(self::WHERE), $this->formatPredicate($where));
}
return '';
} | php | public function formatWhere(Predicate $where) {
if ($where->getParams()) {
return sprintf($this->getClause(self::WHERE), $this->formatPredicate($where));
}
return '';
} | [
"public",
"function",
"formatWhere",
"(",
"Predicate",
"$",
"where",
")",
"{",
"if",
"(",
"$",
"where",
"->",
"getParams",
"(",
")",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"WHERE",
")",
",",
"$",
"this",
"->",
"formatPredicate",
"(",
"$",
"where",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the where clause.
@param \Titon\Db\Query\Predicate $where
@return string | [
"Format",
"the",
"where",
"clause",
"."
]
| fbc5159d1ce9d2139759c9367565986981485604 | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L1005-L1011 |
17,838 | lode/fem | src/request.php | request.redirect | public static function redirect($location, $stop_execution=true, $code=null) {
if (preg_match('{^(http(s)?:)?//}', $location) == false) {
$base_url = 'http';
$base_url .= !empty($_SERVER['HTTPS']) ? 's' : '';
$base_url .= '://'.$_SERVER['SERVER_NAME'];
if (strpos($location, '/') !== 0) {
$base_url .= '/';
}
$location = $base_url.$location;
}
header('Location: '.$location, $replace=true, $code);
if ($stop_execution == false) {
return;
}
exit;
} | php | public static function redirect($location, $stop_execution=true, $code=null) {
if (preg_match('{^(http(s)?:)?//}', $location) == false) {
$base_url = 'http';
$base_url .= !empty($_SERVER['HTTPS']) ? 's' : '';
$base_url .= '://'.$_SERVER['SERVER_NAME'];
if (strpos($location, '/') !== 0) {
$base_url .= '/';
}
$location = $base_url.$location;
}
header('Location: '.$location, $replace=true, $code);
if ($stop_execution == false) {
return;
}
exit;
} | [
"public",
"static",
"function",
"redirect",
"(",
"$",
"location",
",",
"$",
"stop_execution",
"=",
"true",
",",
"$",
"code",
"=",
"null",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'{^(http(s)?:)?//}'",
",",
"$",
"location",
")",
"==",
"false",
")",
"{",
"$",
"base_url",
"=",
"'http'",
";",
"$",
"base_url",
".=",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"?",
"'s'",
":",
"''",
";",
"$",
"base_url",
".=",
"'://'",
".",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"location",
",",
"'/'",
")",
"!==",
"0",
")",
"{",
"$",
"base_url",
".=",
"'/'",
";",
"}",
"$",
"location",
"=",
"$",
"base_url",
".",
"$",
"location",
";",
"}",
"header",
"(",
"'Location: '",
".",
"$",
"location",
",",
"$",
"replace",
"=",
"true",
",",
"$",
"code",
")",
";",
"if",
"(",
"$",
"stop_execution",
"==",
"false",
")",
"{",
"return",
";",
"}",
"exit",
";",
"}"
]
| redirect a browser session to a new url
also exists flow
@param string $location relative to the host
@param boolean $stop_execution defaults to true
@param int $code optional, status code instead of default 302
@return void | [
"redirect",
"a",
"browser",
"session",
"to",
"a",
"new",
"url",
"also",
"exists",
"flow"
]
| c1c466c1a904d99452b341c5ae7cbc3e22b106e1 | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L16-L36 |
17,839 | lode/fem | src/request.php | request.get_method | public static function get_method() {
if (empty($_SERVER['REQUEST_METHOD'])) {
return 'GET';
}
$allowed_methods = ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];
if (in_array($_SERVER['REQUEST_METHOD'], $allowed_methods) == false) {
return false;
}
return $_SERVER['REQUEST_METHOD'];
} | php | public static function get_method() {
if (empty($_SERVER['REQUEST_METHOD'])) {
return 'GET';
}
$allowed_methods = ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];
if (in_array($_SERVER['REQUEST_METHOD'], $allowed_methods) == false) {
return false;
}
return $_SERVER['REQUEST_METHOD'];
} | [
"public",
"static",
"function",
"get_method",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
")",
"{",
"return",
"'GET'",
";",
"}",
"$",
"allowed_methods",
"=",
"[",
"'GET'",
",",
"'PUT'",
",",
"'POST'",
",",
"'PATCH'",
",",
"'DELETE'",
",",
"'OPTIONS'",
",",
"'HEAD'",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
",",
"$",
"allowed_methods",
")",
"==",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
";",
"}"
]
| get the http method used for the current session
@return string|boolean one of GET|PUT|POST|PATCH|DELETE|OPTIONS|HEAD
or false for unknown types | [
"get",
"the",
"http",
"method",
"used",
"for",
"the",
"current",
"session"
]
| c1c466c1a904d99452b341c5ae7cbc3e22b106e1 | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L57-L68 |
17,840 | lode/fem | src/request.php | request.get_primary_accept | public static function get_primary_accept() {
if (empty($_SERVER['HTTP_ACCEPT'])) {
return '*';
}
// catch the most common formats
if (strpos($_SERVER['HTTP_ACCEPT'], 'text/html,') === 0) {
return 'html';
}
if (strpos($_SERVER['HTTP_ACCEPT'], 'application/json,') === 0) {
return 'json';
}
// use a generic method
return self::get_primary_mime_type($_SERVER['HTTP_ACCEPT']);
} | php | public static function get_primary_accept() {
if (empty($_SERVER['HTTP_ACCEPT'])) {
return '*';
}
// catch the most common formats
if (strpos($_SERVER['HTTP_ACCEPT'], 'text/html,') === 0) {
return 'html';
}
if (strpos($_SERVER['HTTP_ACCEPT'], 'application/json,') === 0) {
return 'json';
}
// use a generic method
return self::get_primary_mime_type($_SERVER['HTTP_ACCEPT']);
} | [
"public",
"static",
"function",
"get_primary_accept",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
")",
")",
"{",
"return",
"'*'",
";",
"}",
"// catch the most common formats",
"if",
"(",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
",",
"'text/html,'",
")",
"===",
"0",
")",
"{",
"return",
"'html'",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
",",
"'application/json,'",
")",
"===",
"0",
")",
"{",
"return",
"'json'",
";",
"}",
"// use a generic method",
"return",
"self",
"::",
"get_primary_mime_type",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
")",
";",
"}"
]
| get the primary http accepted output format for the current session
@return string @see ::get_primary_mime_type() | [
"get",
"the",
"primary",
"http",
"accepted",
"output",
"format",
"for",
"the",
"current",
"session"
]
| c1c466c1a904d99452b341c5ae7cbc3e22b106e1 | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L136-L151 |
17,841 | lode/fem | src/request.php | request.get_basic_auth | public static function get_basic_auth() {
// normally it just works
if (!empty($_SERVER['PHP_AUTH_USER'])) {
return [
'USER' => $_SERVER['PHP_AUTH_USER'],
'PW' => $_SERVER['PHP_AUTH_PW'],
];
}
// php cgi mode requires a work around
if (!empty($_SERVER['REDIRECT_REMOTE_USER']) && strpos($_SERVER['REDIRECT_REMOTE_USER'], 'Basic ') === 0) {
$credentials = substr($_SERVER['REDIRECT_REMOTE_USER'], strlen('Basic '));
$credentials = base64_decode($credentials);
if (strpos($credentials, ':')) {
$credentials = explode(':', $credentials);
return [
'USER' => $credentials[0],
'PW' => $credentials[1],
];
}
}
return null;
} | php | public static function get_basic_auth() {
// normally it just works
if (!empty($_SERVER['PHP_AUTH_USER'])) {
return [
'USER' => $_SERVER['PHP_AUTH_USER'],
'PW' => $_SERVER['PHP_AUTH_PW'],
];
}
// php cgi mode requires a work around
if (!empty($_SERVER['REDIRECT_REMOTE_USER']) && strpos($_SERVER['REDIRECT_REMOTE_USER'], 'Basic ') === 0) {
$credentials = substr($_SERVER['REDIRECT_REMOTE_USER'], strlen('Basic '));
$credentials = base64_decode($credentials);
if (strpos($credentials, ':')) {
$credentials = explode(':', $credentials);
return [
'USER' => $credentials[0],
'PW' => $credentials[1],
];
}
}
return null;
} | [
"public",
"static",
"function",
"get_basic_auth",
"(",
")",
"{",
"// normally it just works",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
")",
")",
"{",
"return",
"[",
"'USER'",
"=>",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
",",
"'PW'",
"=>",
"$",
"_SERVER",
"[",
"'PHP_AUTH_PW'",
"]",
",",
"]",
";",
"}",
"// php cgi mode requires a work around",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REDIRECT_REMOTE_USER'",
"]",
")",
"&&",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'REDIRECT_REMOTE_USER'",
"]",
",",
"'Basic '",
")",
"===",
"0",
")",
"{",
"$",
"credentials",
"=",
"substr",
"(",
"$",
"_SERVER",
"[",
"'REDIRECT_REMOTE_USER'",
"]",
",",
"strlen",
"(",
"'Basic '",
")",
")",
";",
"$",
"credentials",
"=",
"base64_decode",
"(",
"$",
"credentials",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"credentials",
",",
"':'",
")",
")",
"{",
"$",
"credentials",
"=",
"explode",
"(",
"':'",
",",
"$",
"credentials",
")",
";",
"return",
"[",
"'USER'",
"=>",
"$",
"credentials",
"[",
"0",
"]",
",",
"'PW'",
"=>",
"$",
"credentials",
"[",
"1",
"]",
",",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| returns basic auth credentials
this works around php cgi mode not passing them directly
@note this requires a change in the htaccess as well
@see example-project/public_html/.htaccess
@return array|null with 'USER' and 'PW' keys | [
"returns",
"basic",
"auth",
"credentials",
"this",
"works",
"around",
"php",
"cgi",
"mode",
"not",
"passing",
"them",
"directly"
]
| c1c466c1a904d99452b341c5ae7cbc3e22b106e1 | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L162-L185 |
17,842 | lode/fem | src/request.php | request.get_primary_mime_type | private static function get_primary_mime_type($type) {
if (strpos($type, ',')) {
$type = substr($type, 0, strpos($type, ','));
}
if (strpos($type, '/')) {
$type = substr($type, strpos($type, '/')+1);
}
if (strpos($type, ';')) {
$type = substr($type, 0, strpos($type, ';'));
}
if (strpos($type, '+')) {
$type = substr($type, strpos($type, '+')+1);
}
return $type;
} | php | private static function get_primary_mime_type($type) {
if (strpos($type, ',')) {
$type = substr($type, 0, strpos($type, ','));
}
if (strpos($type, '/')) {
$type = substr($type, strpos($type, '/')+1);
}
if (strpos($type, ';')) {
$type = substr($type, 0, strpos($type, ';'));
}
if (strpos($type, '+')) {
$type = substr($type, strpos($type, '+')+1);
}
return $type;
} | [
"private",
"static",
"function",
"get_primary_mime_type",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"','",
")",
")",
"{",
"$",
"type",
"=",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"strpos",
"(",
"$",
"type",
",",
"','",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"'/'",
")",
")",
"{",
"$",
"type",
"=",
"substr",
"(",
"$",
"type",
",",
"strpos",
"(",
"$",
"type",
",",
"'/'",
")",
"+",
"1",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"';'",
")",
")",
"{",
"$",
"type",
"=",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"strpos",
"(",
"$",
"type",
",",
"';'",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"'+'",
")",
")",
"{",
"$",
"type",
"=",
"substr",
"(",
"$",
"type",
",",
"strpos",
"(",
"$",
"type",
",",
"'+'",
")",
"+",
"1",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
]
| gets a friendly version of a mime type
@param string $type
@return string the most interesting part of the mime type ..
.. only the first format, and only the most determinating part ..
i.e. 'text/html, ...' returns 'html'
i.e. 'application/json, ...' returns 'json' | [
"gets",
"a",
"friendly",
"version",
"of",
"a",
"mime",
"type"
]
| c1c466c1a904d99452b341c5ae7cbc3e22b106e1 | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L196-L211 |
17,843 | jfusion/org.jfusion.framework | src/Authentication/Cookies.php | Cookies.executeRedirect | function executeRedirect($source_url = null, $return = null) {
if (!$this->secret) {
if(count($this->cookies)) {
if (empty($return)) {
$return = Application::getInstance()->input->getBase64('return', '');
if ($return) {
$return = base64_decode($return);
if( stripos($return, 'http://') === false && stripos($return, 'https://') === false ) {
$return = ltrim($return, '/');
$return = $source_url . $return;
}
}
}
$api = null;
$data = array();
foreach($this->cookies as $key => $cookies) {
$api = new Api($key, $this->secret);
if ($api->set('Cookie', 'Cookies', $cookies)) {
$data['url'][$api->url] = $api->sid;
}
}
if ($api) {
unset($data['url'][$api->url]);
$api->execute('cookie', 'cookies', $data, $return);
}
}
if (!empty($return)) {
Framework::redirect($return);
}
}
} | php | function executeRedirect($source_url = null, $return = null) {
if (!$this->secret) {
if(count($this->cookies)) {
if (empty($return)) {
$return = Application::getInstance()->input->getBase64('return', '');
if ($return) {
$return = base64_decode($return);
if( stripos($return, 'http://') === false && stripos($return, 'https://') === false ) {
$return = ltrim($return, '/');
$return = $source_url . $return;
}
}
}
$api = null;
$data = array();
foreach($this->cookies as $key => $cookies) {
$api = new Api($key, $this->secret);
if ($api->set('Cookie', 'Cookies', $cookies)) {
$data['url'][$api->url] = $api->sid;
}
}
if ($api) {
unset($data['url'][$api->url]);
$api->execute('cookie', 'cookies', $data, $return);
}
}
if (!empty($return)) {
Framework::redirect($return);
}
}
} | [
"function",
"executeRedirect",
"(",
"$",
"source_url",
"=",
"null",
",",
"$",
"return",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"secret",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"cookies",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"return",
")",
")",
"{",
"$",
"return",
"=",
"Application",
"::",
"getInstance",
"(",
")",
"->",
"input",
"->",
"getBase64",
"(",
"'return'",
",",
"''",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"$",
"return",
"=",
"base64_decode",
"(",
"$",
"return",
")",
";",
"if",
"(",
"stripos",
"(",
"$",
"return",
",",
"'http://'",
")",
"===",
"false",
"&&",
"stripos",
"(",
"$",
"return",
",",
"'https://'",
")",
"===",
"false",
")",
"{",
"$",
"return",
"=",
"ltrim",
"(",
"$",
"return",
",",
"'/'",
")",
";",
"$",
"return",
"=",
"$",
"source_url",
".",
"$",
"return",
";",
"}",
"}",
"}",
"$",
"api",
"=",
"null",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"cookies",
"as",
"$",
"key",
"=>",
"$",
"cookies",
")",
"{",
"$",
"api",
"=",
"new",
"Api",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"secret",
")",
";",
"if",
"(",
"$",
"api",
"->",
"set",
"(",
"'Cookie'",
",",
"'Cookies'",
",",
"$",
"cookies",
")",
")",
"{",
"$",
"data",
"[",
"'url'",
"]",
"[",
"$",
"api",
"->",
"url",
"]",
"=",
"$",
"api",
"->",
"sid",
";",
"}",
"}",
"if",
"(",
"$",
"api",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"'url'",
"]",
"[",
"$",
"api",
"->",
"url",
"]",
")",
";",
"$",
"api",
"->",
"execute",
"(",
"'cookie'",
",",
"'cookies'",
",",
"$",
"data",
",",
"$",
"return",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"return",
")",
")",
"{",
"Framework",
"::",
"redirect",
"(",
"$",
"return",
")",
";",
"}",
"}",
"}"
]
| Execute the cross domain login redirects
@param string $source_url
@param string $return | [
"Execute",
"the",
"cross",
"domain",
"login",
"redirects"
]
| 65771963f23ccabcf1f867eb17c9452299cfe683 | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Authentication/Cookies.php#L104-L135 |
17,844 | redaigbaria/oauth2 | src/Entity/AuthCodeEntity.php | AuthCodeEntity.generateRedirectUri | public function generateRedirectUri($state = null, $queryDelimeter = '?')
{
$uri = $this->getRedirectUri();
$uri .= (strstr($this->getRedirectUri(), $queryDelimeter) === false) ? $queryDelimeter : '&';
return $uri.http_build_query([
'code' => $this->getId(),
'state' => $state,
]);
} | php | public function generateRedirectUri($state = null, $queryDelimeter = '?')
{
$uri = $this->getRedirectUri();
$uri .= (strstr($this->getRedirectUri(), $queryDelimeter) === false) ? $queryDelimeter : '&';
return $uri.http_build_query([
'code' => $this->getId(),
'state' => $state,
]);
} | [
"public",
"function",
"generateRedirectUri",
"(",
"$",
"state",
"=",
"null",
",",
"$",
"queryDelimeter",
"=",
"'?'",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"getRedirectUri",
"(",
")",
";",
"$",
"uri",
".=",
"(",
"strstr",
"(",
"$",
"this",
"->",
"getRedirectUri",
"(",
")",
",",
"$",
"queryDelimeter",
")",
"===",
"false",
")",
"?",
"$",
"queryDelimeter",
":",
"'&'",
";",
"return",
"$",
"uri",
".",
"http_build_query",
"(",
"[",
"'code'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'state'",
"=>",
"$",
"state",
",",
"]",
")",
";",
"}"
]
| Generate a redirect URI
@param string $state The state parameter if set by the client
@param string $queryDelimeter The query delimiter ('?' for auth code grant, '#' for implicit grant)
@return string | [
"Generate",
"a",
"redirect",
"URI"
]
| 54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AuthCodeEntity.php#L58-L67 |
17,845 | anime-db/app-bundle | src/Util/Filesystem.php | Filesystem.scandir | public static function scandir($path, $filter = 0, $order = SCANDIR_SORT_ASCENDING)
{
if (!$filter || (
($filter & self::FILE) != self::FILE &&
($filter & self::DIRECTORY) != self::DIRECTORY
)) {
$filter = self::FILE | self::DIRECTORY;
}
// add slash if need
$path = self::getRealPath($path);
// wrap path for current fs
$wrap = Utf8::wrapPath($path);
// scan directory
$folders = [];
foreach (new \DirectoryIterator($wrap) as $file) {
/* @var $file \SplFileInfo */
try {
if (
$file->getFilename()[0] != '.' &&
substr($file->getFilename(), -1) != '~' &&
$file->getFilename() != 'pagefile.sys' && // failed read C:\pagefile.sys
$file->isReadable() &&
(
(($filter & self::FILE) == self::FILE && $file->isFile()) ||
(($filter & self::DIRECTORY) == self::DIRECTORY && $file->isDir())
)
) {
$folders[$file->getFilename()] = [
'name' => $file->getFilename(),
'path' => $path.$file->getFilename().DIRECTORY_SEPARATOR,
];
}
} catch (\Exception $e) {
// ignore all errors
}
}
// order files
if ($order == SCANDIR_SORT_ASCENDING) {
ksort($folders);
} elseif ($order == SCANDIR_SORT_DESCENDING) {
ksort($folders);
$folders = array_reverse($folders);
}
// add link on parent folder
if (substr_count($path, DIRECTORY_SEPARATOR) > 1) {
$pos = strrpos(substr($path, 0, -1), DIRECTORY_SEPARATOR) + 1;
array_unshift($folders, [
'name' => '..',
'path' => substr($path, 0, $pos),
]);
}
return array_values($folders);
} | php | public static function scandir($path, $filter = 0, $order = SCANDIR_SORT_ASCENDING)
{
if (!$filter || (
($filter & self::FILE) != self::FILE &&
($filter & self::DIRECTORY) != self::DIRECTORY
)) {
$filter = self::FILE | self::DIRECTORY;
}
// add slash if need
$path = self::getRealPath($path);
// wrap path for current fs
$wrap = Utf8::wrapPath($path);
// scan directory
$folders = [];
foreach (new \DirectoryIterator($wrap) as $file) {
/* @var $file \SplFileInfo */
try {
if (
$file->getFilename()[0] != '.' &&
substr($file->getFilename(), -1) != '~' &&
$file->getFilename() != 'pagefile.sys' && // failed read C:\pagefile.sys
$file->isReadable() &&
(
(($filter & self::FILE) == self::FILE && $file->isFile()) ||
(($filter & self::DIRECTORY) == self::DIRECTORY && $file->isDir())
)
) {
$folders[$file->getFilename()] = [
'name' => $file->getFilename(),
'path' => $path.$file->getFilename().DIRECTORY_SEPARATOR,
];
}
} catch (\Exception $e) {
// ignore all errors
}
}
// order files
if ($order == SCANDIR_SORT_ASCENDING) {
ksort($folders);
} elseif ($order == SCANDIR_SORT_DESCENDING) {
ksort($folders);
$folders = array_reverse($folders);
}
// add link on parent folder
if (substr_count($path, DIRECTORY_SEPARATOR) > 1) {
$pos = strrpos(substr($path, 0, -1), DIRECTORY_SEPARATOR) + 1;
array_unshift($folders, [
'name' => '..',
'path' => substr($path, 0, $pos),
]);
}
return array_values($folders);
} | [
"public",
"static",
"function",
"scandir",
"(",
"$",
"path",
",",
"$",
"filter",
"=",
"0",
",",
"$",
"order",
"=",
"SCANDIR_SORT_ASCENDING",
")",
"{",
"if",
"(",
"!",
"$",
"filter",
"||",
"(",
"(",
"$",
"filter",
"&",
"self",
"::",
"FILE",
")",
"!=",
"self",
"::",
"FILE",
"&&",
"(",
"$",
"filter",
"&",
"self",
"::",
"DIRECTORY",
")",
"!=",
"self",
"::",
"DIRECTORY",
")",
")",
"{",
"$",
"filter",
"=",
"self",
"::",
"FILE",
"|",
"self",
"::",
"DIRECTORY",
";",
"}",
"// add slash if need",
"$",
"path",
"=",
"self",
"::",
"getRealPath",
"(",
"$",
"path",
")",
";",
"// wrap path for current fs",
"$",
"wrap",
"=",
"Utf8",
"::",
"wrapPath",
"(",
"$",
"path",
")",
";",
"// scan directory",
"$",
"folders",
"=",
"[",
"]",
";",
"foreach",
"(",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"wrap",
")",
"as",
"$",
"file",
")",
"{",
"/* @var $file \\SplFileInfo */",
"try",
"{",
"if",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
"[",
"0",
"]",
"!=",
"'.'",
"&&",
"substr",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"-",
"1",
")",
"!=",
"'~'",
"&&",
"$",
"file",
"->",
"getFilename",
"(",
")",
"!=",
"'pagefile.sys'",
"&&",
"// failed read C:\\pagefile.sys",
"$",
"file",
"->",
"isReadable",
"(",
")",
"&&",
"(",
"(",
"(",
"$",
"filter",
"&",
"self",
"::",
"FILE",
")",
"==",
"self",
"::",
"FILE",
"&&",
"$",
"file",
"->",
"isFile",
"(",
")",
")",
"||",
"(",
"(",
"$",
"filter",
"&",
"self",
"::",
"DIRECTORY",
")",
"==",
"self",
"::",
"DIRECTORY",
"&&",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
")",
")",
"{",
"$",
"folders",
"[",
"$",
"file",
"->",
"getFilename",
"(",
")",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"'path'",
"=>",
"$",
"path",
".",
"$",
"file",
"->",
"getFilename",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
",",
"]",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// ignore all errors",
"}",
"}",
"// order files",
"if",
"(",
"$",
"order",
"==",
"SCANDIR_SORT_ASCENDING",
")",
"{",
"ksort",
"(",
"$",
"folders",
")",
";",
"}",
"elseif",
"(",
"$",
"order",
"==",
"SCANDIR_SORT_DESCENDING",
")",
"{",
"ksort",
"(",
"$",
"folders",
")",
";",
"$",
"folders",
"=",
"array_reverse",
"(",
"$",
"folders",
")",
";",
"}",
"// add link on parent folder",
"if",
"(",
"substr_count",
"(",
"$",
"path",
",",
"DIRECTORY_SEPARATOR",
")",
">",
"1",
")",
"{",
"$",
"pos",
"=",
"strrpos",
"(",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"-",
"1",
")",
",",
"DIRECTORY_SEPARATOR",
")",
"+",
"1",
";",
"array_unshift",
"(",
"$",
"folders",
",",
"[",
"'name'",
"=>",
"'..'",
",",
"'path'",
"=>",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"$",
"pos",
")",
",",
"]",
")",
";",
"}",
"return",
"array_values",
"(",
"$",
"folders",
")",
";",
"}"
]
| List files and directories inside the specified path.
@param string $path
@param int $filter
@param int $order
@return array | [
"List",
"files",
"and",
"directories",
"inside",
"the",
"specified",
"path",
"."
]
| ca3b342081719d41ba018792a75970cbb1f1fe22 | https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Util/Filesystem.php#L93-L149 |
17,846 | aryelgois/yasql-php | src/Populator.php | Populator.load | public function load(string $file)
{
$this->data = Yaml::parse(file_get_contents($file));
$this->filename = basename($file);
} | php | public function load(string $file)
{
$this->data = Yaml::parse(file_get_contents($file));
$this->filename = basename($file);
} | [
"public",
"function",
"load",
"(",
"string",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"$",
"this",
"->",
"filename",
"=",
"basename",
"(",
"$",
"file",
")",
";",
"}"
]
| Loads a YAML file to be processed
@param string $file Path to YAML source file | [
"Loads",
"a",
"YAML",
"file",
"to",
"be",
"processed"
]
| f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7 | https://github.com/aryelgois/yasql-php/blob/f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7/src/Populator.php#L57-L61 |
17,847 | left-right/center | src/libraries/Trail.php | Trail.manage | public static function manage() {
$back = (Session::has('back')) ? Session::get('back') : [];
if (URL::current() == end($back)) {
//going back down the stack
array_pop($back);
} elseif (URL::previous() != end($back)) {
//going up the stack
$back[] = URL::previous();
}
//persist
if (count($back)) {
Session::set('back', $back);
} elseif (Session::has('back')) {
Session::forget('back');
}
} | php | public static function manage() {
$back = (Session::has('back')) ? Session::get('back') : [];
if (URL::current() == end($back)) {
//going back down the stack
array_pop($back);
} elseif (URL::previous() != end($back)) {
//going up the stack
$back[] = URL::previous();
}
//persist
if (count($back)) {
Session::set('back', $back);
} elseif (Session::has('back')) {
Session::forget('back');
}
} | [
"public",
"static",
"function",
"manage",
"(",
")",
"{",
"$",
"back",
"=",
"(",
"Session",
"::",
"has",
"(",
"'back'",
")",
")",
"?",
"Session",
"::",
"get",
"(",
"'back'",
")",
":",
"[",
"]",
";",
"if",
"(",
"URL",
"::",
"current",
"(",
")",
"==",
"end",
"(",
"$",
"back",
")",
")",
"{",
"//going back down the stack",
"array_pop",
"(",
"$",
"back",
")",
";",
"}",
"elseif",
"(",
"URL",
"::",
"previous",
"(",
")",
"!=",
"end",
"(",
"$",
"back",
")",
")",
"{",
"//going up the stack",
"$",
"back",
"[",
"]",
"=",
"URL",
"::",
"previous",
"(",
")",
";",
"}",
"//persist",
"if",
"(",
"count",
"(",
"$",
"back",
")",
")",
"{",
"Session",
"::",
"set",
"(",
"'back'",
",",
"$",
"back",
")",
";",
"}",
"elseif",
"(",
"Session",
"::",
"has",
"(",
"'back'",
")",
")",
"{",
"Session",
"::",
"forget",
"(",
"'back'",
")",
";",
"}",
"}"
]
| manage the return stack | [
"manage",
"the",
"return",
"stack"
]
| 47c225538475ca3e87fa49f31a323b6e6bd4eff2 | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/libraries/Trail.php#L9-L28 |
17,848 | ClanCats/Core | src/classes/CCError/Handler.php | CCError_Handler.log | protected function log()
{
if ( class_exists( 'CCLog' ) )
{
try {
\CCLog::add(
$this->inspector->exception()->getMessage()." - ".
str_replace( CCROOT, '', $this->inspector->exception()->getFile() ).":".
$this->inspector->exception()->getLine(), 'exception'
);
\CCLog::write();
} catch( \Exception $e ) {}
}
} | php | protected function log()
{
if ( class_exists( 'CCLog' ) )
{
try {
\CCLog::add(
$this->inspector->exception()->getMessage()." - ".
str_replace( CCROOT, '', $this->inspector->exception()->getFile() ).":".
$this->inspector->exception()->getLine(), 'exception'
);
\CCLog::write();
} catch( \Exception $e ) {}
}
} | [
"protected",
"function",
"log",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'CCLog'",
")",
")",
"{",
"try",
"{",
"\\",
"CCLog",
"::",
"add",
"(",
"$",
"this",
"->",
"inspector",
"->",
"exception",
"(",
")",
"->",
"getMessage",
"(",
")",
".",
"\" - \"",
".",
"str_replace",
"(",
"CCROOT",
",",
"''",
",",
"$",
"this",
"->",
"inspector",
"->",
"exception",
"(",
")",
"->",
"getFile",
"(",
")",
")",
".",
"\":\"",
".",
"$",
"this",
"->",
"inspector",
"->",
"exception",
"(",
")",
"->",
"getLine",
"(",
")",
",",
"'exception'",
")",
";",
"\\",
"CCLog",
"::",
"write",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"}",
"}"
]
| Try to log that something went wrong
@return void | [
"Try",
"to",
"log",
"that",
"something",
"went",
"wrong"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Handler.php#L39-L52 |
17,849 | ClanCats/Core | src/classes/CCError/Handler.php | CCError_Handler.handle | public function handle()
{
$this->log();
// when not in development we respond using a route
if ( !ClanCats::in_development() && !ClanCats::is_cli() )
{
CCResponse::error(500)->send( true );
}
// when in development continue with the default responder
else
{
$this->respond();
}
} | php | public function handle()
{
$this->log();
// when not in development we respond using a route
if ( !ClanCats::in_development() && !ClanCats::is_cli() )
{
CCResponse::error(500)->send( true );
}
// when in development continue with the default responder
else
{
$this->respond();
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"this",
"->",
"log",
"(",
")",
";",
"// when not in development we respond using a route",
"if",
"(",
"!",
"ClanCats",
"::",
"in_development",
"(",
")",
"&&",
"!",
"ClanCats",
"::",
"is_cli",
"(",
")",
")",
"{",
"CCResponse",
"::",
"error",
"(",
"500",
")",
"->",
"send",
"(",
"true",
")",
";",
"}",
"// when in development continue with the default responder",
"else",
"{",
"$",
"this",
"->",
"respond",
"(",
")",
";",
"}",
"}"
]
| trigger the handler
@return void | [
"trigger",
"the",
"handler"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Handler.php#L59-L73 |
17,850 | webforge-labs/psc-cms | lib/Psc/CMS/Item/TabButtonableValueObject.php | TabButtonableValueObject.copyFromTabButtonable | public static function copyFromTabButtonable(TabButtonable $tabButtonable) {
$valueObject = new static();
// ugly, but fast
$valueObject->setButtonLabel($tabButtonable->getButtonLabel());
$valueObject->setFullButtonLabel($tabButtonable->getFullButtonLabel());
$valueObject->setButtonLeftIcon($tabButtonable->getButtonLeftIcon());
$valueObject->setButtonRightIcon($tabButtonable->getButtonRightIcon());
$valueObject->setButtonMode($tabButtonable->getButtonMode());
$valueObject->setTabLabel($tabButtonable->getTabLabel());
$valueObject->setTabRequestMeta($tabButtonable->getTabRequestMeta());
return $valueObject;
} | php | public static function copyFromTabButtonable(TabButtonable $tabButtonable) {
$valueObject = new static();
// ugly, but fast
$valueObject->setButtonLabel($tabButtonable->getButtonLabel());
$valueObject->setFullButtonLabel($tabButtonable->getFullButtonLabel());
$valueObject->setButtonLeftIcon($tabButtonable->getButtonLeftIcon());
$valueObject->setButtonRightIcon($tabButtonable->getButtonRightIcon());
$valueObject->setButtonMode($tabButtonable->getButtonMode());
$valueObject->setTabLabel($tabButtonable->getTabLabel());
$valueObject->setTabRequestMeta($tabButtonable->getTabRequestMeta());
return $valueObject;
} | [
"public",
"static",
"function",
"copyFromTabButtonable",
"(",
"TabButtonable",
"$",
"tabButtonable",
")",
"{",
"$",
"valueObject",
"=",
"new",
"static",
"(",
")",
";",
"// ugly, but fast",
"$",
"valueObject",
"->",
"setButtonLabel",
"(",
"$",
"tabButtonable",
"->",
"getButtonLabel",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setFullButtonLabel",
"(",
"$",
"tabButtonable",
"->",
"getFullButtonLabel",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setButtonLeftIcon",
"(",
"$",
"tabButtonable",
"->",
"getButtonLeftIcon",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setButtonRightIcon",
"(",
"$",
"tabButtonable",
"->",
"getButtonRightIcon",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setButtonMode",
"(",
"$",
"tabButtonable",
"->",
"getButtonMode",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setTabLabel",
"(",
"$",
"tabButtonable",
"->",
"getTabLabel",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setTabRequestMeta",
"(",
"$",
"tabButtonable",
"->",
"getTabRequestMeta",
"(",
")",
")",
";",
"return",
"$",
"valueObject",
";",
"}"
]
| Creates a copy of an tabButtonable
use this to have a modified Version of the interface
@return TabButtonableValueObject | [
"Creates",
"a",
"copy",
"of",
"an",
"tabButtonable"
]
| 467bfa2547e6b4fa487d2d7f35fa6cc618dbc763 | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/Item/TabButtonableValueObject.php#L18-L31 |
17,851 | discordier/justtextwidgets | src/Widgets/JustAnExplanation.php | JustAnExplanation.generateLabel | public function generateLabel()
{
if ($this->strLabel === '') {
return '';
}
return sprintf(
'<span %s>%s%s</span>',
('' !== $this->strClass ? ' class="' . $this->strClass . '"' : ''),
$this->strLabel,
($this->required ? '<span class="mandatory">*</span>' : '')
);
} | php | public function generateLabel()
{
if ($this->strLabel === '') {
return '';
}
return sprintf(
'<span %s>%s%s</span>',
('' !== $this->strClass ? ' class="' . $this->strClass . '"' : ''),
$this->strLabel,
($this->required ? '<span class="mandatory">*</span>' : '')
);
} | [
"public",
"function",
"generateLabel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"strLabel",
"===",
"''",
")",
"{",
"return",
"''",
";",
"}",
"return",
"sprintf",
"(",
"'<span %s>%s%s</span>'",
",",
"(",
"''",
"!==",
"$",
"this",
"->",
"strClass",
"?",
"' class=\"'",
".",
"$",
"this",
"->",
"strClass",
".",
"'\"'",
":",
"''",
")",
",",
"$",
"this",
"->",
"strLabel",
",",
"(",
"$",
"this",
"->",
"required",
"?",
"'<span class=\"mandatory\">*</span>'",
":",
"''",
")",
")",
";",
"}"
]
| Generate the label and return it as string.
@return string | [
"Generate",
"the",
"label",
"and",
"return",
"it",
"as",
"string",
"."
]
| 585f20eec05d592bb13281ca8ef0972e956d3f06 | https://github.com/discordier/justtextwidgets/blob/585f20eec05d592bb13281ca8ef0972e956d3f06/src/Widgets/JustAnExplanation.php#L53-L65 |
17,852 | iamapen/dbunit-ExcelFriendlyDataSet | src/lib/Iamapen/ExcelFriendlyDataSet/Database/DataSet/CommentableCsvDataSet.php | CommentableCsvDataSet.getCsvRow | protected function getCsvRow($fh)
{
if (version_compare(PHP_VERSION, '5.3.0', '>')) {
$rows = fgetcsv($fh, NULL, $this->delimiter, $this->enclosure, $this->escape);
} else {
$rows = fgetcsv($fh, NULL, $this->delimiter, $this->enclosure);
}
if ($rows === false) {
return false;
}
for ($i = 0; $i < $this->ignoreColumnCount; $i++) {
array_shift($rows);
}
return $rows;
} | php | protected function getCsvRow($fh)
{
if (version_compare(PHP_VERSION, '5.3.0', '>')) {
$rows = fgetcsv($fh, NULL, $this->delimiter, $this->enclosure, $this->escape);
} else {
$rows = fgetcsv($fh, NULL, $this->delimiter, $this->enclosure);
}
if ($rows === false) {
return false;
}
for ($i = 0; $i < $this->ignoreColumnCount; $i++) {
array_shift($rows);
}
return $rows;
} | [
"protected",
"function",
"getCsvRow",
"(",
"$",
"fh",
")",
"{",
"if",
"(",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.3.0'",
",",
"'>'",
")",
")",
"{",
"$",
"rows",
"=",
"fgetcsv",
"(",
"$",
"fh",
",",
"NULL",
",",
"$",
"this",
"->",
"delimiter",
",",
"$",
"this",
"->",
"enclosure",
",",
"$",
"this",
"->",
"escape",
")",
";",
"}",
"else",
"{",
"$",
"rows",
"=",
"fgetcsv",
"(",
"$",
"fh",
",",
"NULL",
",",
"$",
"this",
"->",
"delimiter",
",",
"$",
"this",
"->",
"enclosure",
")",
";",
"}",
"if",
"(",
"$",
"rows",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"ignoreColumnCount",
";",
"$",
"i",
"++",
")",
"{",
"array_shift",
"(",
"$",
"rows",
")",
";",
"}",
"return",
"$",
"rows",
";",
"}"
]
| Returns a row from the csv file in an indexed array.
@param resource $fh
@return array | [
"Returns",
"a",
"row",
"from",
"the",
"csv",
"file",
"in",
"an",
"indexed",
"array",
"."
]
| 036103cb2a2a75608f0a00448301cd3f4a5c4e19 | https://github.com/iamapen/dbunit-ExcelFriendlyDataSet/blob/036103cb2a2a75608f0a00448301cd3f4a5c4e19/src/lib/Iamapen/ExcelFriendlyDataSet/Database/DataSet/CommentableCsvDataSet.php#L37-L53 |
17,853 | aedart/laravel-helpers | src/Traits/Database/DBTrait.php | DBTrait.getDefaultDb | public function getDefaultDb(): ?ConnectionInterface
{
// By default, the DB Facade does not return the
// any actual database connection, but rather an
// instance of \Illuminate\Database\DatabaseManager.
// Therefore, we make sure only to obtain its
// "connection", to make sure that its only the connection
// instance that we obtain.
$manager = DB::getFacadeRoot();
if (isset($manager)) {
return $manager->connection();
}
return $manager;
} | php | public function getDefaultDb(): ?ConnectionInterface
{
// By default, the DB Facade does not return the
// any actual database connection, but rather an
// instance of \Illuminate\Database\DatabaseManager.
// Therefore, we make sure only to obtain its
// "connection", to make sure that its only the connection
// instance that we obtain.
$manager = DB::getFacadeRoot();
if (isset($manager)) {
return $manager->connection();
}
return $manager;
} | [
"public",
"function",
"getDefaultDb",
"(",
")",
":",
"?",
"ConnectionInterface",
"{",
"// By default, the DB Facade does not return the",
"// any actual database connection, but rather an",
"// instance of \\Illuminate\\Database\\DatabaseManager.",
"// Therefore, we make sure only to obtain its",
"// \"connection\", to make sure that its only the connection",
"// instance that we obtain.",
"$",
"manager",
"=",
"DB",
"::",
"getFacadeRoot",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"manager",
")",
")",
"{",
"return",
"$",
"manager",
"->",
"connection",
"(",
")",
";",
"}",
"return",
"$",
"manager",
";",
"}"
]
| Get a default db value, if any is available
@return ConnectionInterface|null A default db value or Null if no default value is available | [
"Get",
"a",
"default",
"db",
"value",
"if",
"any",
"is",
"available"
]
| 8b81a2d6658f3f8cb62b6be2c34773aaa2df219a | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Database/DBTrait.php#L76-L89 |
17,854 | ivory-php/fbi | src/Fbi.php | Fbi.showStatusBar | public function showStatusBar()
{
return $this;
/**
* In case the without status bar has been set, remove it first.
*/
if( array_key_exists('noverbose', $this->options) ) unset($this->options['noverbose']);
$this->options['v'] = '';
return $this;
} | php | public function showStatusBar()
{
return $this;
/**
* In case the without status bar has been set, remove it first.
*/
if( array_key_exists('noverbose', $this->options) ) unset($this->options['noverbose']);
$this->options['v'] = '';
return $this;
} | [
"public",
"function",
"showStatusBar",
"(",
")",
"{",
"return",
"$",
"this",
";",
"/**\n\t\t * In case the without status bar has been set, remove it first.\n\t\t */",
"if",
"(",
"array_key_exists",
"(",
"'noverbose'",
",",
"$",
"this",
"->",
"options",
")",
")",
"unset",
"(",
"$",
"this",
"->",
"options",
"[",
"'noverbose'",
"]",
")",
";",
"$",
"this",
"->",
"options",
"[",
"'v'",
"]",
"=",
"''",
";",
"return",
"$",
"this",
";",
"}"
]
| This shows the status bar at the bottom of the screen with image
about the file being displayed in it.
@return $this | [
"This",
"shows",
"the",
"status",
"bar",
"at",
"the",
"bottom",
"of",
"the",
"screen",
"with",
"image",
"about",
"the",
"file",
"being",
"displayed",
"in",
"it",
"."
]
| fce0839ed4d5693bd161fe45260311cc27f46cef | https://github.com/ivory-php/fbi/blob/fce0839ed4d5693bd161fe45260311cc27f46cef/src/Fbi.php#L88-L100 |
17,855 | ivory-php/fbi | src/Fbi.php | Fbi.withoutStatusBar | public function withoutStatusBar()
{
return $this;
if( array_key_exists('v', $this->options) ) unset($this->options['v']);
$this->options['noverbose'] = '';
return $this;
} | php | public function withoutStatusBar()
{
return $this;
if( array_key_exists('v', $this->options) ) unset($this->options['v']);
$this->options['noverbose'] = '';
return $this;
} | [
"public",
"function",
"withoutStatusBar",
"(",
")",
"{",
"return",
"$",
"this",
";",
"if",
"(",
"array_key_exists",
"(",
"'v'",
",",
"$",
"this",
"->",
"options",
")",
")",
"unset",
"(",
"$",
"this",
"->",
"options",
"[",
"'v'",
"]",
")",
";",
"$",
"this",
"->",
"options",
"[",
"'noverbose'",
"]",
"=",
"''",
";",
"return",
"$",
"this",
";",
"}"
]
| Don't display the status bar at the bottom of the screen
@return $this | [
"Don",
"t",
"display",
"the",
"status",
"bar",
"at",
"the",
"bottom",
"of",
"the",
"screen"
]
| fce0839ed4d5693bd161fe45260311cc27f46cef | https://github.com/ivory-php/fbi/blob/fce0839ed4d5693bd161fe45260311cc27f46cef/src/Fbi.php#L106-L114 |
17,856 | ivory-php/fbi | src/Fbi.php | Fbi.display | public function display()
{
$options = $this->_compileOptions();
$command = system('sudo fbi --noverbose ' . $this->_compileOptions() . ' ' .$this->file . ' > /dev/null 2>&1');
/**
* If $displayFor is set to 0, then the application doesn't need to be terminated. It's showing
* indefinetly.
*/
if( $this->displayFor > 0 )
{
sleep($this->displayFor);
$this->terminate();
}
} | php | public function display()
{
$options = $this->_compileOptions();
$command = system('sudo fbi --noverbose ' . $this->_compileOptions() . ' ' .$this->file . ' > /dev/null 2>&1');
/**
* If $displayFor is set to 0, then the application doesn't need to be terminated. It's showing
* indefinetly.
*/
if( $this->displayFor > 0 )
{
sleep($this->displayFor);
$this->terminate();
}
} | [
"public",
"function",
"display",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_compileOptions",
"(",
")",
";",
"$",
"command",
"=",
"system",
"(",
"'sudo fbi --noverbose '",
".",
"$",
"this",
"->",
"_compileOptions",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"file",
".",
"' > /dev/null 2>&1'",
")",
";",
"/**\n\t\t * If $displayFor is set to 0, then the application doesn't need to be terminated. It's showing\n\t\t * indefinetly. \n\t\t */",
"if",
"(",
"$",
"this",
"->",
"displayFor",
">",
"0",
")",
"{",
"sleep",
"(",
"$",
"this",
"->",
"displayFor",
")",
";",
"$",
"this",
"->",
"terminate",
"(",
")",
";",
"}",
"}"
]
| Display The Image
@return | [
"Display",
"The",
"Image"
]
| fce0839ed4d5693bd161fe45260311cc27f46cef | https://github.com/ivory-php/fbi/blob/fce0839ed4d5693bd161fe45260311cc27f46cef/src/Fbi.php#L315-L329 |
17,857 | ivory-php/fbi | src/Fbi.php | Fbi._compileOptions | public function _compileOptions()
{
$compiled = '';
/**
* We'll cycle through the options. If the option has only one
* character, it needs a hash, multiple characters needs two hashes.
*/
foreach( $this->options as $option => $value ) :
if( strlen($option) > 1 ) $compiled.= "--{$option} {$value} ";
else $compiled.= "-{$option} {$value}";
endforeach;
return $compiled;
} | php | public function _compileOptions()
{
$compiled = '';
/**
* We'll cycle through the options. If the option has only one
* character, it needs a hash, multiple characters needs two hashes.
*/
foreach( $this->options as $option => $value ) :
if( strlen($option) > 1 ) $compiled.= "--{$option} {$value} ";
else $compiled.= "-{$option} {$value}";
endforeach;
return $compiled;
} | [
"public",
"function",
"_compileOptions",
"(",
")",
"{",
"$",
"compiled",
"=",
"''",
";",
"/**\n\t\t * We'll cycle through the options. If the option has only one \n\t\t * character, it needs a hash, multiple characters needs two hashes. \n\t\t */",
"foreach",
"(",
"$",
"this",
"->",
"options",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
":",
"if",
"(",
"strlen",
"(",
"$",
"option",
")",
">",
"1",
")",
"$",
"compiled",
".=",
"\"--{$option} {$value} \"",
";",
"else",
"$",
"compiled",
".=",
"\"-{$option} {$value}\"",
";",
"endforeach",
";",
"return",
"$",
"compiled",
";",
"}"
]
| Compile the options to a string passable to the command
@return string | [
"Compile",
"the",
"options",
"to",
"a",
"string",
"passable",
"to",
"the",
"command"
]
| fce0839ed4d5693bd161fe45260311cc27f46cef | https://github.com/ivory-php/fbi/blob/fce0839ed4d5693bd161fe45260311cc27f46cef/src/Fbi.php#L335-L349 |
17,858 | vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasGroup | public function hasGroup($group)
{
if ($this->user() === null) {
return null;
}
return in_array($group, $this->groups, true);
} | php | public function hasGroup($group)
{
if ($this->user() === null) {
return null;
}
return in_array($group, $this->groups, true);
} | [
"public",
"function",
"hasGroup",
"(",
"$",
"group",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"in_array",
"(",
"$",
"group",
",",
"$",
"this",
"->",
"groups",
",",
"true",
")",
";",
"}"
]
| Check if authenticate user has group
@param string $group
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticate",
"user",
"has",
"group"
]
| 501c20128f43347a2ca271a53435297f9ef7f567 | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L49-L56 |
17,859 | vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasGroups | public function hasGroups($groups)
{
if ($this->user() === null) {
return null;
}
if (!is_array($groups)) {
$groups = func_get_args();
}
// Count roles because user need user to have all roles passed as parameter
return count(array_intersect($groups, $this->groups)) === count($groups);
} | php | public function hasGroups($groups)
{
if ($this->user() === null) {
return null;
}
if (!is_array($groups)) {
$groups = func_get_args();
}
// Count roles because user need user to have all roles passed as parameter
return count(array_intersect($groups, $this->groups)) === count($groups);
} | [
"public",
"function",
"hasGroups",
"(",
"$",
"groups",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"groups",
")",
")",
"{",
"$",
"groups",
"=",
"func_get_args",
"(",
")",
";",
"}",
"// Count roles because user need user to have all roles passed as parameter",
"return",
"count",
"(",
"array_intersect",
"(",
"$",
"groups",
",",
"$",
"this",
"->",
"groups",
")",
")",
"===",
"count",
"(",
"$",
"groups",
")",
";",
"}"
]
| Check if authenticated user has all groups passed by parameter
@param string[] $groups
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticated",
"user",
"has",
"all",
"groups",
"passed",
"by",
"parameter"
]
| 501c20128f43347a2ca271a53435297f9ef7f567 | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L65-L77 |
17,860 | vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasRole | public function hasRole($role)
{
if ($this->user() === null) {
return null;
}
return in_array($role, $this->roles, true);
} | php | public function hasRole($role)
{
if ($this->user() === null) {
return null;
}
return in_array($role, $this->roles, true);
} | [
"public",
"function",
"hasRole",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"in_array",
"(",
"$",
"role",
",",
"$",
"this",
"->",
"roles",
",",
"true",
")",
";",
"}"
]
| Check if authenticate user has role
@param string $role
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticate",
"user",
"has",
"role"
]
| 501c20128f43347a2ca271a53435297f9ef7f567 | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L86-L93 |
17,861 | vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasRoles | public function hasRoles($roles)
{
if ($this->user() === null) {
return null;
}
if (!is_array($roles)) {
$roles = func_get_args();
}
// Count roles because user need user to have all roles passed as parameter
return count(array_intersect($roles, $this->roles)) === count($roles);
} | php | public function hasRoles($roles)
{
if ($this->user() === null) {
return null;
}
if (!is_array($roles)) {
$roles = func_get_args();
}
// Count roles because user need user to have all roles passed as parameter
return count(array_intersect($roles, $this->roles)) === count($roles);
} | [
"public",
"function",
"hasRoles",
"(",
"$",
"roles",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"roles",
")",
")",
"{",
"$",
"roles",
"=",
"func_get_args",
"(",
")",
";",
"}",
"// Count roles because user need user to have all roles passed as parameter",
"return",
"count",
"(",
"array_intersect",
"(",
"$",
"roles",
",",
"$",
"this",
"->",
"roles",
")",
")",
"===",
"count",
"(",
"$",
"roles",
")",
";",
"}"
]
| Check if authenticated user has all roles passed by parameter
@param string[] $roles
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticated",
"user",
"has",
"all",
"roles",
"passed",
"by",
"parameter"
]
| 501c20128f43347a2ca271a53435297f9ef7f567 | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L102-L114 |
17,862 | vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasPermission | public function hasPermission($permission)
{
if ($this->user() === null) {
return null;
}
return in_array($permission, $this->permissions, true);
} | php | public function hasPermission($permission)
{
if ($this->user() === null) {
return null;
}
return in_array($permission, $this->permissions, true);
} | [
"public",
"function",
"hasPermission",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"in_array",
"(",
"$",
"permission",
",",
"$",
"this",
"->",
"permissions",
",",
"true",
")",
";",
"}"
]
| Check if authenticated user has permission
@param string $permission
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticated",
"user",
"has",
"permission"
]
| 501c20128f43347a2ca271a53435297f9ef7f567 | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L123-L130 |
17,863 | vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasPermissions | public function hasPermissions($permissions)
{
if ($this->user() === null) {
return null;
}
if (!is_array($permissions)) {
$permissions = func_get_args();
}
// Count permissions because user need user to have all permissions passed as parameter
return count(array_intersect($permissions, $this->permissions)) === count($permissions);
} | php | public function hasPermissions($permissions)
{
if ($this->user() === null) {
return null;
}
if (!is_array($permissions)) {
$permissions = func_get_args();
}
// Count permissions because user need user to have all permissions passed as parameter
return count(array_intersect($permissions, $this->permissions)) === count($permissions);
} | [
"public",
"function",
"hasPermissions",
"(",
"$",
"permissions",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"permissions",
")",
")",
"{",
"$",
"permissions",
"=",
"func_get_args",
"(",
")",
";",
"}",
"// Count permissions because user need user to have all permissions passed as parameter",
"return",
"count",
"(",
"array_intersect",
"(",
"$",
"permissions",
",",
"$",
"this",
"->",
"permissions",
")",
")",
"===",
"count",
"(",
"$",
"permissions",
")",
";",
"}"
]
| Check if authenticated user has all permission passed by parameter
@param string[] $permissions
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticated",
"user",
"has",
"all",
"permission",
"passed",
"by",
"parameter"
]
| 501c20128f43347a2ca271a53435297f9ef7f567 | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L139-L151 |
17,864 | vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.isBlocked | public function isBlocked()
{
if ($this->user() === null) {
return null;
}
// Check user blocking status only if User model is role based user
if ($this->user instanceof User) {
return $this->user->blocked;
}
return false;
} | php | public function isBlocked()
{
if ($this->user() === null) {
return null;
}
// Check user blocking status only if User model is role based user
if ($this->user instanceof User) {
return $this->user->blocked;
}
return false;
} | [
"public",
"function",
"isBlocked",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"// Check user blocking status only if User model is role based user",
"if",
"(",
"$",
"this",
"->",
"user",
"instanceof",
"User",
")",
"{",
"return",
"$",
"this",
"->",
"user",
"->",
"blocked",
";",
"}",
"return",
"false",
";",
"}"
]
| Return if current user is blocked
If user is not role based user, then always return false
@return bool|null return NULL if user is not authenticated | [
"Return",
"if",
"current",
"user",
"is",
"blocked"
]
| 501c20128f43347a2ca271a53435297f9ef7f567 | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L201-L213 |
17,865 | maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/Match.php | Match.addPlayerInTeam | function addPlayerInTeam($login, $teamId)
{
switch($teamId)
{
case 0:
if(array_search($login, $this->team2))
{
throw new \InvalidArgumentException();
}
if(!array_search($login, $this->team1))
{
$this->team1[] = $login;
}
break;
case 1:
if(array_search($login, $this->team1))
{
throw new \InvalidArgumentException();
}
if(!array_search($login, $this->team2))
{
$this->team2[] = $login;
}
break;
default:
throw new \InvalidArgumentException();
}
} | php | function addPlayerInTeam($login, $teamId)
{
switch($teamId)
{
case 0:
if(array_search($login, $this->team2))
{
throw new \InvalidArgumentException();
}
if(!array_search($login, $this->team1))
{
$this->team1[] = $login;
}
break;
case 1:
if(array_search($login, $this->team1))
{
throw new \InvalidArgumentException();
}
if(!array_search($login, $this->team2))
{
$this->team2[] = $login;
}
break;
default:
throw new \InvalidArgumentException();
}
} | [
"function",
"addPlayerInTeam",
"(",
"$",
"login",
",",
"$",
"teamId",
")",
"{",
"switch",
"(",
"$",
"teamId",
")",
"{",
"case",
"0",
":",
"if",
"(",
"array_search",
"(",
"$",
"login",
",",
"$",
"this",
"->",
"team2",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_search",
"(",
"$",
"login",
",",
"$",
"this",
"->",
"team1",
")",
")",
"{",
"$",
"this",
"->",
"team1",
"[",
"]",
"=",
"$",
"login",
";",
"}",
"break",
";",
"case",
"1",
":",
"if",
"(",
"array_search",
"(",
"$",
"login",
",",
"$",
"this",
"->",
"team1",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_search",
"(",
"$",
"login",
",",
"$",
"this",
"->",
"team2",
")",
")",
"{",
"$",
"this",
"->",
"team2",
"[",
"]",
"=",
"$",
"login",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"}"
]
| add a login in a team, throw an exception if the login is already teamed or if the team does not exist
@param string $login
@param int $teamId
@throws \InvalidArgumentException | [
"add",
"a",
"login",
"in",
"a",
"team",
"throw",
"an",
"exception",
"if",
"the",
"login",
"is",
"already",
"teamed",
"or",
"if",
"the",
"team",
"does",
"not",
"exist"
]
| 384f22cdd2cfb0204a071810549eaf1eb01d8b7f | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/Match.php#L112-L139 |
17,866 | accgit/single-web | src/Single/Configurator.php | Configurator.enableTracy | public function enableTracy($logDirectory = null, $email = null)
{
Tracy\Debugger::$strictMode = true;
Tracy\Debugger::enable($this->mode, $logDirectory, $email);
} | php | public function enableTracy($logDirectory = null, $email = null)
{
Tracy\Debugger::$strictMode = true;
Tracy\Debugger::enable($this->mode, $logDirectory, $email);
} | [
"public",
"function",
"enableTracy",
"(",
"$",
"logDirectory",
"=",
"null",
",",
"$",
"email",
"=",
"null",
")",
"{",
"Tracy",
"\\",
"Debugger",
"::",
"$",
"strictMode",
"=",
"true",
";",
"Tracy",
"\\",
"Debugger",
"::",
"enable",
"(",
"$",
"this",
"->",
"mode",
",",
"$",
"logDirectory",
",",
"$",
"email",
")",
";",
"}"
]
| Enable Tracy Tools.
@param string $logDirectory
@param string $email | [
"Enable",
"Tracy",
"Tools",
"."
]
| 5d0dce3313df9e22ab60749bcf01f1753de8c143 | https://github.com/accgit/single-web/blob/5d0dce3313df9e22ab60749bcf01f1753de8c143/src/Single/Configurator.php#L52-L56 |
17,867 | accgit/single-web | src/Single/Configurator.php | Configurator.createAutoload | public function createAutoload($path)
{
$loader = new Loaders\RobotLoader;
$loader->setCacheStorage(new Caching\Storages\FileStorage($this->temp));
$loader->addDirectory($path)->register();
return $loader;
} | php | public function createAutoload($path)
{
$loader = new Loaders\RobotLoader;
$loader->setCacheStorage(new Caching\Storages\FileStorage($this->temp));
$loader->addDirectory($path)->register();
return $loader;
} | [
"public",
"function",
"createAutoload",
"(",
"$",
"path",
")",
"{",
"$",
"loader",
"=",
"new",
"Loaders",
"\\",
"RobotLoader",
";",
"$",
"loader",
"->",
"setCacheStorage",
"(",
"new",
"Caching",
"\\",
"Storages",
"\\",
"FileStorage",
"(",
"$",
"this",
"->",
"temp",
")",
")",
";",
"$",
"loader",
"->",
"addDirectory",
"(",
"$",
"path",
")",
"->",
"register",
"(",
")",
";",
"return",
"$",
"loader",
";",
"}"
]
| Autoloading classes.
@param string|array $path
@return Loaders\RobotLoader | [
"Autoloading",
"classes",
"."
]
| 5d0dce3313df9e22ab60749bcf01f1753de8c143 | https://github.com/accgit/single-web/blob/5d0dce3313df9e22ab60749bcf01f1753de8c143/src/Single/Configurator.php#L63-L69 |
17,868 | qcubed/orm | src/Query/ModelTrait.php | ModelTrait.buildQueryStatement | protected static function buildQueryStatement(
&$objQueryBuilder,
iCondition $objConditions,
$objOptionalClauses,
$mixParameterArray,
$blnCountOnly
) {
// Get the Database Object for this Class
$objDatabase = static::getDatabase();
$strTableName = static::getTableName();
// Create/Build out the QueryBuilder object with class-specific SELECT and FROM fields
$objQueryBuilder = new Builder($objDatabase, $strTableName);
$blnAddAllFieldsToSelect = true;
if ($objDatabase->OnlyFullGroupBy) {
// see if we have any group by or aggregation clauses, if yes, don't add all the fields to select clause by default
// because these databases post an error instead of just choosing a value to return when a select item could
// have multiple values
if ($objOptionalClauses instanceof iClause) {
if ($objOptionalClauses instanceof Clause\AggregationBase || $objOptionalClauses instanceof Clause\GroupBy) {
$blnAddAllFieldsToSelect = false;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
if ($objClause instanceof Clause\AggregationBase || $objClause instanceof Clause\GroupBy) {
$blnAddAllFieldsToSelect = false;
break;
}
}
}
}
}
$objQueryBuilder->addFromItem($strTableName);
// Set "CountOnly" option (if applicable)
if ($blnCountOnly) {
$objQueryBuilder->setCountOnlyFlag();
}
// Apply Any Conditions
if ($objConditions) {
try {
$objConditions->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
}
// Iterate through all the Optional Clauses (if any) and perform accordingly
if ($objOptionalClauses) {
if ($objOptionalClauses instanceof iClause) {
try {
$objOptionalClauses->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
try {
$objClause->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
}
} else {
throw new Caller('Optional Clauses must be a iClause object or an array of iClause objects');
}
}
}
// Do this here because it needs to know if distinct clause is included, and that is determined above
$objSelectClauses = QQ::extractSelectClause($objOptionalClauses);
if ($objSelectClauses || $blnAddAllFieldsToSelect) {
static::baseNode()->putSelectFields($objQueryBuilder, null, $objSelectClauses);
}
// Get the SQL Statement
$strQuery = $objQueryBuilder->getStatement();
// Substitute the correct sql variable names for the placeholders specified in the query, if any.
if ($mixParameterArray) {
if (is_array($mixParameterArray)) {
if (count($mixParameterArray)) {
$strQuery = $objDatabase->prepareStatement($strQuery, $mixParameterArray);
}
// Ensure that there are no other Unresolved Named Parameters
if (strpos($strQuery, chr(Node\NamedValue::DELIMITER_CODE) . '{') !== false) {
throw new Caller('Unresolved named parameters in the query');
}
} else {
throw new Caller('Parameter Array must be an array of name-value parameter pairs');
}
}
// Return the Objects
return $strQuery;
} | php | protected static function buildQueryStatement(
&$objQueryBuilder,
iCondition $objConditions,
$objOptionalClauses,
$mixParameterArray,
$blnCountOnly
) {
// Get the Database Object for this Class
$objDatabase = static::getDatabase();
$strTableName = static::getTableName();
// Create/Build out the QueryBuilder object with class-specific SELECT and FROM fields
$objQueryBuilder = new Builder($objDatabase, $strTableName);
$blnAddAllFieldsToSelect = true;
if ($objDatabase->OnlyFullGroupBy) {
// see if we have any group by or aggregation clauses, if yes, don't add all the fields to select clause by default
// because these databases post an error instead of just choosing a value to return when a select item could
// have multiple values
if ($objOptionalClauses instanceof iClause) {
if ($objOptionalClauses instanceof Clause\AggregationBase || $objOptionalClauses instanceof Clause\GroupBy) {
$blnAddAllFieldsToSelect = false;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
if ($objClause instanceof Clause\AggregationBase || $objClause instanceof Clause\GroupBy) {
$blnAddAllFieldsToSelect = false;
break;
}
}
}
}
}
$objQueryBuilder->addFromItem($strTableName);
// Set "CountOnly" option (if applicable)
if ($blnCountOnly) {
$objQueryBuilder->setCountOnlyFlag();
}
// Apply Any Conditions
if ($objConditions) {
try {
$objConditions->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
}
// Iterate through all the Optional Clauses (if any) and perform accordingly
if ($objOptionalClauses) {
if ($objOptionalClauses instanceof iClause) {
try {
$objOptionalClauses->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
try {
$objClause->updateQueryBuilder($objQueryBuilder);
} catch (Caller $objExc) {
$objExc->incrementOffset();
$objExc->incrementOffset();
throw $objExc;
}
}
} else {
throw new Caller('Optional Clauses must be a iClause object or an array of iClause objects');
}
}
}
// Do this here because it needs to know if distinct clause is included, and that is determined above
$objSelectClauses = QQ::extractSelectClause($objOptionalClauses);
if ($objSelectClauses || $blnAddAllFieldsToSelect) {
static::baseNode()->putSelectFields($objQueryBuilder, null, $objSelectClauses);
}
// Get the SQL Statement
$strQuery = $objQueryBuilder->getStatement();
// Substitute the correct sql variable names for the placeholders specified in the query, if any.
if ($mixParameterArray) {
if (is_array($mixParameterArray)) {
if (count($mixParameterArray)) {
$strQuery = $objDatabase->prepareStatement($strQuery, $mixParameterArray);
}
// Ensure that there are no other Unresolved Named Parameters
if (strpos($strQuery, chr(Node\NamedValue::DELIMITER_CODE) . '{') !== false) {
throw new Caller('Unresolved named parameters in the query');
}
} else {
throw new Caller('Parameter Array must be an array of name-value parameter pairs');
}
}
// Return the Objects
return $strQuery;
} | [
"protected",
"static",
"function",
"buildQueryStatement",
"(",
"&",
"$",
"objQueryBuilder",
",",
"iCondition",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
",",
"$",
"mixParameterArray",
",",
"$",
"blnCountOnly",
")",
"{",
"// Get the Database Object for this Class",
"$",
"objDatabase",
"=",
"static",
"::",
"getDatabase",
"(",
")",
";",
"$",
"strTableName",
"=",
"static",
"::",
"getTableName",
"(",
")",
";",
"// Create/Build out the QueryBuilder object with class-specific SELECT and FROM fields",
"$",
"objQueryBuilder",
"=",
"new",
"Builder",
"(",
"$",
"objDatabase",
",",
"$",
"strTableName",
")",
";",
"$",
"blnAddAllFieldsToSelect",
"=",
"true",
";",
"if",
"(",
"$",
"objDatabase",
"->",
"OnlyFullGroupBy",
")",
"{",
"// see if we have any group by or aggregation clauses, if yes, don't add all the fields to select clause by default",
"// because these databases post an error instead of just choosing a value to return when a select item could",
"// have multiple values",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"iClause",
")",
"{",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"Clause",
"\\",
"AggregationBase",
"||",
"$",
"objOptionalClauses",
"instanceof",
"Clause",
"\\",
"GroupBy",
")",
"{",
"$",
"blnAddAllFieldsToSelect",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"objOptionalClauses",
")",
")",
"{",
"foreach",
"(",
"$",
"objOptionalClauses",
"as",
"$",
"objClause",
")",
"{",
"if",
"(",
"$",
"objClause",
"instanceof",
"Clause",
"\\",
"AggregationBase",
"||",
"$",
"objClause",
"instanceof",
"Clause",
"\\",
"GroupBy",
")",
"{",
"$",
"blnAddAllFieldsToSelect",
"=",
"false",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"$",
"objQueryBuilder",
"->",
"addFromItem",
"(",
"$",
"strTableName",
")",
";",
"// Set \"CountOnly\" option (if applicable)",
"if",
"(",
"$",
"blnCountOnly",
")",
"{",
"$",
"objQueryBuilder",
"->",
"setCountOnlyFlag",
"(",
")",
";",
"}",
"// Apply Any Conditions",
"if",
"(",
"$",
"objConditions",
")",
"{",
"try",
"{",
"$",
"objConditions",
"->",
"updateQueryBuilder",
"(",
"$",
"objQueryBuilder",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"}",
"// Iterate through all the Optional Clauses (if any) and perform accordingly",
"if",
"(",
"$",
"objOptionalClauses",
")",
"{",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"iClause",
")",
"{",
"try",
"{",
"$",
"objOptionalClauses",
"->",
"updateQueryBuilder",
"(",
"$",
"objQueryBuilder",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"objOptionalClauses",
")",
")",
"{",
"foreach",
"(",
"$",
"objOptionalClauses",
"as",
"$",
"objClause",
")",
"{",
"try",
"{",
"$",
"objClause",
"->",
"updateQueryBuilder",
"(",
"$",
"objQueryBuilder",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"Caller",
"(",
"'Optional Clauses must be a iClause object or an array of iClause objects'",
")",
";",
"}",
"}",
"}",
"// Do this here because it needs to know if distinct clause is included, and that is determined above",
"$",
"objSelectClauses",
"=",
"QQ",
"::",
"extractSelectClause",
"(",
"$",
"objOptionalClauses",
")",
";",
"if",
"(",
"$",
"objSelectClauses",
"||",
"$",
"blnAddAllFieldsToSelect",
")",
"{",
"static",
"::",
"baseNode",
"(",
")",
"->",
"putSelectFields",
"(",
"$",
"objQueryBuilder",
",",
"null",
",",
"$",
"objSelectClauses",
")",
";",
"}",
"// Get the SQL Statement",
"$",
"strQuery",
"=",
"$",
"objQueryBuilder",
"->",
"getStatement",
"(",
")",
";",
"// Substitute the correct sql variable names for the placeholders specified in the query, if any.",
"if",
"(",
"$",
"mixParameterArray",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mixParameterArray",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"mixParameterArray",
")",
")",
"{",
"$",
"strQuery",
"=",
"$",
"objDatabase",
"->",
"prepareStatement",
"(",
"$",
"strQuery",
",",
"$",
"mixParameterArray",
")",
";",
"}",
"// Ensure that there are no other Unresolved Named Parameters",
"if",
"(",
"strpos",
"(",
"$",
"strQuery",
",",
"chr",
"(",
"Node",
"\\",
"NamedValue",
"::",
"DELIMITER_CODE",
")",
".",
"'{'",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"Caller",
"(",
"'Unresolved named parameters in the query'",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Caller",
"(",
"'Parameter Array must be an array of name-value parameter pairs'",
")",
";",
"}",
"}",
"// Return the Objects",
"return",
"$",
"strQuery",
";",
"}"
]
| Takes a query builder object and outputs the sql query that corresponds to its structure and the given parameters.
@param Builder &$objQueryBuilder the QueryBuilder object that will be created
@param iCondition $objConditions any conditions on the query, itself
@param iClause[] $objOptionalClauses additional optional iClause object or array of iClause objects for this query
@param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
@param boolean $blnCountOnly only select a rowcount
@return string the query statement
@throws Caller | [
"Takes",
"a",
"query",
"builder",
"object",
"and",
"outputs",
"the",
"sql",
"query",
"that",
"corresponds",
"to",
"its",
"structure",
"and",
"the",
"given",
"parameters",
"."
]
| f320eba671f20874b1f3809c5293f8c02d5b1204 | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L89-L199 |
17,869 | qcubed/orm | src/Query/ModelTrait.php | ModelTrait._QueryArray | protected static function _QueryArray(
iCondition $objConditions,
$objOptionalClauses = null,
$mixParameterArray = null
) {
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query and Instantiate the Array Result
$objDbResult = $objQueryBuilder->Database->query($strQuery);
return static::instantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNode,
$objQueryBuilder->ColumnAliasArray);
} | php | protected static function _QueryArray(
iCondition $objConditions,
$objOptionalClauses = null,
$mixParameterArray = null
) {
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query and Instantiate the Array Result
$objDbResult = $objQueryBuilder->Database->query($strQuery);
return static::instantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNode,
$objQueryBuilder->ColumnAliasArray);
} | [
"protected",
"static",
"function",
"_QueryArray",
"(",
"iCondition",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
"=",
"null",
",",
"$",
"mixParameterArray",
"=",
"null",
")",
"{",
"// Get the Query Statement",
"try",
"{",
"$",
"strQuery",
"=",
"static",
"::",
"buildQueryStatement",
"(",
"$",
"objQueryBuilder",
",",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
",",
"$",
"mixParameterArray",
",",
"false",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"// Perform the Query and Instantiate the Array Result",
"$",
"objDbResult",
"=",
"$",
"objQueryBuilder",
"->",
"Database",
"->",
"query",
"(",
"$",
"strQuery",
")",
";",
"return",
"static",
"::",
"instantiateDbResult",
"(",
"$",
"objDbResult",
",",
"$",
"objQueryBuilder",
"->",
"ExpandAsArrayNode",
",",
"$",
"objQueryBuilder",
"->",
"ColumnAliasArray",
")",
";",
"}"
]
| Static Qcubed Query method to query for an array of objects.
Uses BuildQueryStatment to perform most of the work.
Is called by QueryArray function of each object so that the correct return type will be put in the comments.
@param iCondition $objConditions any conditions on the query, itself
@param iClause[]|null $objOptionalClauses additional optional iClause objects for this query
@param mixed[]|null $mixParameterArray an array of name-value pairs to substitute in to the placeholders in the query, if needed
@return mixed[] an array of objects
@throws Caller | [
"Static",
"Qcubed",
"Query",
"method",
"to",
"query",
"for",
"an",
"array",
"of",
"objects",
".",
"Uses",
"BuildQueryStatment",
"to",
"perform",
"most",
"of",
"the",
"work",
".",
"Is",
"called",
"by",
"QueryArray",
"function",
"of",
"each",
"object",
"so",
"that",
"the",
"correct",
"return",
"type",
"will",
"be",
"put",
"in",
"the",
"comments",
"."
]
| f320eba671f20874b1f3809c5293f8c02d5b1204 | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L274-L292 |
17,870 | qcubed/orm | src/Query/ModelTrait.php | ModelTrait.queryCursor | public static function queryCursor(iCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null)
{
// Get the query statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Pull Expansions
$objExpandAsArrayNode = $objQueryBuilder->ExpandAsArrayNode;
if (!empty ($objExpandAsArrayNode)) {
throw new Caller ("Cannot use QueryCursor with ExpandAsArray");
}
// Perform the query
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Get the alias array so we know how to instantiate a row from the result
$objDbResult->ColumnAliasArray = $objQueryBuilder->ColumnAliasArray;
return $objDbResult;
} | php | public static function queryCursor(iCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null)
{
// Get the query statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, false);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Pull Expansions
$objExpandAsArrayNode = $objQueryBuilder->ExpandAsArrayNode;
if (!empty ($objExpandAsArrayNode)) {
throw new Caller ("Cannot use QueryCursor with ExpandAsArray");
}
// Perform the query
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Get the alias array so we know how to instantiate a row from the result
$objDbResult->ColumnAliasArray = $objQueryBuilder->ColumnAliasArray;
return $objDbResult;
} | [
"public",
"static",
"function",
"queryCursor",
"(",
"iCondition",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
"=",
"null",
",",
"$",
"mixParameterArray",
"=",
"null",
")",
"{",
"// Get the query statement",
"try",
"{",
"$",
"strQuery",
"=",
"static",
"::",
"buildQueryStatement",
"(",
"$",
"objQueryBuilder",
",",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
",",
"$",
"mixParameterArray",
",",
"false",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"// Pull Expansions",
"$",
"objExpandAsArrayNode",
"=",
"$",
"objQueryBuilder",
"->",
"ExpandAsArrayNode",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"objExpandAsArrayNode",
")",
")",
"{",
"throw",
"new",
"Caller",
"(",
"\"Cannot use QueryCursor with ExpandAsArray\"",
")",
";",
"}",
"// Perform the query",
"$",
"objDbResult",
"=",
"$",
"objQueryBuilder",
"->",
"Database",
"->",
"query",
"(",
"$",
"strQuery",
")",
";",
"// Get the alias array so we know how to instantiate a row from the result",
"$",
"objDbResult",
"->",
"ColumnAliasArray",
"=",
"$",
"objQueryBuilder",
"->",
"ColumnAliasArray",
";",
"return",
"$",
"objDbResult",
";",
"}"
]
| Static Qcubed query method to issue a query and get a cursor to progressively fetch its results.
Uses BuildQueryStatment to perform most of the work.
@param iCondition $objConditions any conditions on the query, itself
@param iClause[] $objOptionalClauses additional optional iClause objects for this query
@param mixed[] $mixParameterArray an array of name-value pairs to substitute in to the placeholders in the query, if needed
@return Database\ResultBase the cursor resource instance
@throws Exception
@throws Caller | [
"Static",
"Qcubed",
"query",
"method",
"to",
"issue",
"a",
"query",
"and",
"get",
"a",
"cursor",
"to",
"progressively",
"fetch",
"its",
"results",
".",
"Uses",
"BuildQueryStatment",
"to",
"perform",
"most",
"of",
"the",
"work",
"."
]
| f320eba671f20874b1f3809c5293f8c02d5b1204 | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L305-L328 |
17,871 | qcubed/orm | src/Query/ModelTrait.php | ModelTrait.queryCount | public static function queryCount(iCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null)
{
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, true);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query and return the row_count
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Figure out if the query is using GroupBy
$blnGrouped = false;
if ($objOptionalClauses) {
if ($objOptionalClauses instanceof iClause) {
if ($objOptionalClauses instanceof Clause\GroupBy) {
$blnGrouped = true;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
if ($objClause instanceof Clause\GroupBy) {
$blnGrouped = true;
break;
}
}
} else {
throw new Caller('Optional Clauses must be a iClause object or an array of iClause objects');
}
}
}
if ($blnGrouped) // Groups in this query - return the count of Groups (which is the count of all rows)
{
return $objDbResult->countRows();
} else {
// No Groups - return the sql-calculated count(*) value
$strDbRow = $objDbResult->fetchRow();
return (integer)$strDbRow[0];
}
} | php | public static function queryCount(iCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null)
{
// Get the Query Statement
try {
$strQuery = static::buildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses,
$mixParameterArray, true);
} catch (Caller $objExc) {
$objExc->incrementOffset();
throw $objExc;
}
// Perform the Query and return the row_count
$objDbResult = $objQueryBuilder->Database->query($strQuery);
// Figure out if the query is using GroupBy
$blnGrouped = false;
if ($objOptionalClauses) {
if ($objOptionalClauses instanceof iClause) {
if ($objOptionalClauses instanceof Clause\GroupBy) {
$blnGrouped = true;
}
} else {
if (is_array($objOptionalClauses)) {
foreach ($objOptionalClauses as $objClause) {
if ($objClause instanceof Clause\GroupBy) {
$blnGrouped = true;
break;
}
}
} else {
throw new Caller('Optional Clauses must be a iClause object or an array of iClause objects');
}
}
}
if ($blnGrouped) // Groups in this query - return the count of Groups (which is the count of all rows)
{
return $objDbResult->countRows();
} else {
// No Groups - return the sql-calculated count(*) value
$strDbRow = $objDbResult->fetchRow();
return (integer)$strDbRow[0];
}
} | [
"public",
"static",
"function",
"queryCount",
"(",
"iCondition",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
"=",
"null",
",",
"$",
"mixParameterArray",
"=",
"null",
")",
"{",
"// Get the Query Statement",
"try",
"{",
"$",
"strQuery",
"=",
"static",
"::",
"buildQueryStatement",
"(",
"$",
"objQueryBuilder",
",",
"$",
"objConditions",
",",
"$",
"objOptionalClauses",
",",
"$",
"mixParameterArray",
",",
"true",
")",
";",
"}",
"catch",
"(",
"Caller",
"$",
"objExc",
")",
"{",
"$",
"objExc",
"->",
"incrementOffset",
"(",
")",
";",
"throw",
"$",
"objExc",
";",
"}",
"// Perform the Query and return the row_count",
"$",
"objDbResult",
"=",
"$",
"objQueryBuilder",
"->",
"Database",
"->",
"query",
"(",
"$",
"strQuery",
")",
";",
"// Figure out if the query is using GroupBy",
"$",
"blnGrouped",
"=",
"false",
";",
"if",
"(",
"$",
"objOptionalClauses",
")",
"{",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"iClause",
")",
"{",
"if",
"(",
"$",
"objOptionalClauses",
"instanceof",
"Clause",
"\\",
"GroupBy",
")",
"{",
"$",
"blnGrouped",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"objOptionalClauses",
")",
")",
"{",
"foreach",
"(",
"$",
"objOptionalClauses",
"as",
"$",
"objClause",
")",
"{",
"if",
"(",
"$",
"objClause",
"instanceof",
"Clause",
"\\",
"GroupBy",
")",
"{",
"$",
"blnGrouped",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"Caller",
"(",
"'Optional Clauses must be a iClause object or an array of iClause objects'",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"blnGrouped",
")",
"// Groups in this query - return the count of Groups (which is the count of all rows)",
"{",
"return",
"$",
"objDbResult",
"->",
"countRows",
"(",
")",
";",
"}",
"else",
"{",
"// No Groups - return the sql-calculated count(*) value",
"$",
"strDbRow",
"=",
"$",
"objDbResult",
"->",
"fetchRow",
"(",
")",
";",
"return",
"(",
"integer",
")",
"$",
"strDbRow",
"[",
"0",
"]",
";",
"}",
"}"
]
| Static Qcubed Query method to query for a count of objects.
Uses BuildQueryStatment to perform most of the work.
@param iCondition $objConditions any conditions on the query, itself
@param iClause[] $objOptionalClauses additional optional iClause objects for this query
@param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
@return integer the count of queried objects as an integer
@throws Caller | [
"Static",
"Qcubed",
"Query",
"method",
"to",
"query",
"for",
"a",
"count",
"of",
"objects",
".",
"Uses",
"BuildQueryStatment",
"to",
"perform",
"most",
"of",
"the",
"work",
"."
]
| f320eba671f20874b1f3809c5293f8c02d5b1204 | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L340-L384 |
17,872 | qcubed/orm | src/Query/ModelTrait.php | ModelTrait.expandArray | public static function expandArray(
$objDbRow,
$strAliasPrefix,
$objNode,
$objPreviousItemArray,
$strColumnAliasArray
) {
if (!$objNode->ChildNodeArray) {
return null;
}
$blnExpanded = null;
$pk = static::getRowPrimaryKey($objDbRow, $strAliasPrefix, $strColumnAliasArray);
foreach ($objPreviousItemArray as $objPreviousItem) {
if ($pk != $objPreviousItem->primaryKey()) {
continue;
}
foreach ($objNode->ChildNodeArray as $objChildNode) {
$strPropName = $objChildNode->_PropertyName;
$strClassName = $objChildNode->_ClassName;
$strLongAlias = $objChildNode->fullAlias();
$blnExpandAsArray = false;
if ($objChildNode->ExpandAsArray) {
$strPostfix = 'Array';
$blnExpandAsArray = true;
} else {
$strPostfix = '';
}
$nodeType = $objChildNode->_Type;
if ($nodeType == 'reverse_reference') {
$strPrefix = '_obj';
} elseif ($nodeType == 'association') {
$objChildNode = $objChildNode->firstChild();
if ($objChildNode->IsType) {
$strPrefix = '_int';
} else {
$strPrefix = '_obj';
}
} else {
$strPrefix = 'obj';
}
$strVarName = $strPrefix . $strPropName . $strPostfix;
if ($blnExpandAsArray) {
if (null === $objPreviousItem->$strVarName) {
$objPreviousItem->$strVarName = array();
}
if (count($objPreviousItem->$strVarName)) {
$objPreviousChildItems = $objPreviousItem->$strVarName;
$nextAlias = $objChildNode->fullAlias() . '__';
$objChildItem = $strClassName::instantiateDbRow($objDbRow, $nextAlias, $objChildNode,
$objPreviousChildItems, $strColumnAliasArray, true);
if ($objChildItem) {
$objPreviousItem->{$strVarName}[] = $objChildItem;
$blnExpanded = true;
} elseif ($objChildItem === false) {
$blnExpanded = true;
}
}
} elseif (!$objChildNode->IsType) {
// Follow single node if keys match
if (null === $objPreviousItem->$strVarName) {
return false;
}
$objPreviousChildItems = array($objPreviousItem->$strVarName);
$blnResult = $strClassName::expandArray($objDbRow, $strLongAlias . '__', $objChildNode,
$objPreviousChildItems, $strColumnAliasArray);
if ($blnResult) {
$blnExpanded = true;
}
}
}
}
return $blnExpanded;
} | php | public static function expandArray(
$objDbRow,
$strAliasPrefix,
$objNode,
$objPreviousItemArray,
$strColumnAliasArray
) {
if (!$objNode->ChildNodeArray) {
return null;
}
$blnExpanded = null;
$pk = static::getRowPrimaryKey($objDbRow, $strAliasPrefix, $strColumnAliasArray);
foreach ($objPreviousItemArray as $objPreviousItem) {
if ($pk != $objPreviousItem->primaryKey()) {
continue;
}
foreach ($objNode->ChildNodeArray as $objChildNode) {
$strPropName = $objChildNode->_PropertyName;
$strClassName = $objChildNode->_ClassName;
$strLongAlias = $objChildNode->fullAlias();
$blnExpandAsArray = false;
if ($objChildNode->ExpandAsArray) {
$strPostfix = 'Array';
$blnExpandAsArray = true;
} else {
$strPostfix = '';
}
$nodeType = $objChildNode->_Type;
if ($nodeType == 'reverse_reference') {
$strPrefix = '_obj';
} elseif ($nodeType == 'association') {
$objChildNode = $objChildNode->firstChild();
if ($objChildNode->IsType) {
$strPrefix = '_int';
} else {
$strPrefix = '_obj';
}
} else {
$strPrefix = 'obj';
}
$strVarName = $strPrefix . $strPropName . $strPostfix;
if ($blnExpandAsArray) {
if (null === $objPreviousItem->$strVarName) {
$objPreviousItem->$strVarName = array();
}
if (count($objPreviousItem->$strVarName)) {
$objPreviousChildItems = $objPreviousItem->$strVarName;
$nextAlias = $objChildNode->fullAlias() . '__';
$objChildItem = $strClassName::instantiateDbRow($objDbRow, $nextAlias, $objChildNode,
$objPreviousChildItems, $strColumnAliasArray, true);
if ($objChildItem) {
$objPreviousItem->{$strVarName}[] = $objChildItem;
$blnExpanded = true;
} elseif ($objChildItem === false) {
$blnExpanded = true;
}
}
} elseif (!$objChildNode->IsType) {
// Follow single node if keys match
if (null === $objPreviousItem->$strVarName) {
return false;
}
$objPreviousChildItems = array($objPreviousItem->$strVarName);
$blnResult = $strClassName::expandArray($objDbRow, $strLongAlias . '__', $objChildNode,
$objPreviousChildItems, $strColumnAliasArray);
if ($blnResult) {
$blnExpanded = true;
}
}
}
}
return $blnExpanded;
} | [
"public",
"static",
"function",
"expandArray",
"(",
"$",
"objDbRow",
",",
"$",
"strAliasPrefix",
",",
"$",
"objNode",
",",
"$",
"objPreviousItemArray",
",",
"$",
"strColumnAliasArray",
")",
"{",
"if",
"(",
"!",
"$",
"objNode",
"->",
"ChildNodeArray",
")",
"{",
"return",
"null",
";",
"}",
"$",
"blnExpanded",
"=",
"null",
";",
"$",
"pk",
"=",
"static",
"::",
"getRowPrimaryKey",
"(",
"$",
"objDbRow",
",",
"$",
"strAliasPrefix",
",",
"$",
"strColumnAliasArray",
")",
";",
"foreach",
"(",
"$",
"objPreviousItemArray",
"as",
"$",
"objPreviousItem",
")",
"{",
"if",
"(",
"$",
"pk",
"!=",
"$",
"objPreviousItem",
"->",
"primaryKey",
"(",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"objNode",
"->",
"ChildNodeArray",
"as",
"$",
"objChildNode",
")",
"{",
"$",
"strPropName",
"=",
"$",
"objChildNode",
"->",
"_PropertyName",
";",
"$",
"strClassName",
"=",
"$",
"objChildNode",
"->",
"_ClassName",
";",
"$",
"strLongAlias",
"=",
"$",
"objChildNode",
"->",
"fullAlias",
"(",
")",
";",
"$",
"blnExpandAsArray",
"=",
"false",
";",
"if",
"(",
"$",
"objChildNode",
"->",
"ExpandAsArray",
")",
"{",
"$",
"strPostfix",
"=",
"'Array'",
";",
"$",
"blnExpandAsArray",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"strPostfix",
"=",
"''",
";",
"}",
"$",
"nodeType",
"=",
"$",
"objChildNode",
"->",
"_Type",
";",
"if",
"(",
"$",
"nodeType",
"==",
"'reverse_reference'",
")",
"{",
"$",
"strPrefix",
"=",
"'_obj'",
";",
"}",
"elseif",
"(",
"$",
"nodeType",
"==",
"'association'",
")",
"{",
"$",
"objChildNode",
"=",
"$",
"objChildNode",
"->",
"firstChild",
"(",
")",
";",
"if",
"(",
"$",
"objChildNode",
"->",
"IsType",
")",
"{",
"$",
"strPrefix",
"=",
"'_int'",
";",
"}",
"else",
"{",
"$",
"strPrefix",
"=",
"'_obj'",
";",
"}",
"}",
"else",
"{",
"$",
"strPrefix",
"=",
"'obj'",
";",
"}",
"$",
"strVarName",
"=",
"$",
"strPrefix",
".",
"$",
"strPropName",
".",
"$",
"strPostfix",
";",
"if",
"(",
"$",
"blnExpandAsArray",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
")",
"{",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
")",
")",
"{",
"$",
"objPreviousChildItems",
"=",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
";",
"$",
"nextAlias",
"=",
"$",
"objChildNode",
"->",
"fullAlias",
"(",
")",
".",
"'__'",
";",
"$",
"objChildItem",
"=",
"$",
"strClassName",
"::",
"instantiateDbRow",
"(",
"$",
"objDbRow",
",",
"$",
"nextAlias",
",",
"$",
"objChildNode",
",",
"$",
"objPreviousChildItems",
",",
"$",
"strColumnAliasArray",
",",
"true",
")",
";",
"if",
"(",
"$",
"objChildItem",
")",
"{",
"$",
"objPreviousItem",
"->",
"{",
"$",
"strVarName",
"}",
"[",
"]",
"=",
"$",
"objChildItem",
";",
"$",
"blnExpanded",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"objChildItem",
"===",
"false",
")",
"{",
"$",
"blnExpanded",
"=",
"true",
";",
"}",
"}",
"}",
"elseif",
"(",
"!",
"$",
"objChildNode",
"->",
"IsType",
")",
"{",
"// Follow single node if keys match",
"if",
"(",
"null",
"===",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
")",
"{",
"return",
"false",
";",
"}",
"$",
"objPreviousChildItems",
"=",
"array",
"(",
"$",
"objPreviousItem",
"->",
"$",
"strVarName",
")",
";",
"$",
"blnResult",
"=",
"$",
"strClassName",
"::",
"expandArray",
"(",
"$",
"objDbRow",
",",
"$",
"strLongAlias",
".",
"'__'",
",",
"$",
"objChildNode",
",",
"$",
"objPreviousChildItems",
",",
"$",
"strColumnAliasArray",
")",
";",
"if",
"(",
"$",
"blnResult",
")",
"{",
"$",
"blnExpanded",
"=",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"blnExpanded",
";",
"}"
]
| Do a possible array expansion on the given node. If the node is an ExpandAsArray node,
it will add to the corresponding array in the object. Otherwise, it will follow the node
so that any leaf expansions can be handled.
@param \QCubed\Database\RowBase $objDbRow
@param string $strAliasPrefix
@param Node\NodeBase $objNode
@param array $objPreviousItemArray
@param string[] $strColumnAliasArray
@return boolean|null Returns true if the we used the row for an expansion, false if we already expanded this node in a previous row, or null if no expansion data was found | [
"Do",
"a",
"possible",
"array",
"expansion",
"on",
"the",
"given",
"node",
".",
"If",
"the",
"node",
"is",
"an",
"ExpandAsArray",
"node",
"it",
"will",
"add",
"to",
"the",
"corresponding",
"array",
"in",
"the",
"object",
".",
"Otherwise",
"it",
"will",
"follow",
"the",
"node",
"so",
"that",
"any",
"leaf",
"expansions",
"can",
"be",
"handled",
"."
]
| f320eba671f20874b1f3809c5293f8c02d5b1204 | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/ModelTrait.php#L416-L498 |
17,873 | flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.getTableFields | protected function getTableFields(Table $table)
{
$fileds = [];
foreach ($table->getColumns() as $column) {
$fileds[] = [
'name' => $column->getName(),
'type' => $column->getType()->getName(),
'not_null' => $column->getNotnull(),
'length' => $column->getLength(),
'unsigned' => $column->getUnsigned(),
'autoincrement' => $column->getAutoincrement(),
'primary_key' => $this->isPrimaryKey($table, $column),
'foreign_key' => $this->isForeignKey($table, $column)
];
}
return $fileds;
} | php | protected function getTableFields(Table $table)
{
$fileds = [];
foreach ($table->getColumns() as $column) {
$fileds[] = [
'name' => $column->getName(),
'type' => $column->getType()->getName(),
'not_null' => $column->getNotnull(),
'length' => $column->getLength(),
'unsigned' => $column->getUnsigned(),
'autoincrement' => $column->getAutoincrement(),
'primary_key' => $this->isPrimaryKey($table, $column),
'foreign_key' => $this->isForeignKey($table, $column)
];
}
return $fileds;
} | [
"protected",
"function",
"getTableFields",
"(",
"Table",
"$",
"table",
")",
"{",
"$",
"fileds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"fileds",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"column",
"->",
"getName",
"(",
")",
",",
"'type'",
"=>",
"$",
"column",
"->",
"getType",
"(",
")",
"->",
"getName",
"(",
")",
",",
"'not_null'",
"=>",
"$",
"column",
"->",
"getNotnull",
"(",
")",
",",
"'length'",
"=>",
"$",
"column",
"->",
"getLength",
"(",
")",
",",
"'unsigned'",
"=>",
"$",
"column",
"->",
"getUnsigned",
"(",
")",
",",
"'autoincrement'",
"=>",
"$",
"column",
"->",
"getAutoincrement",
"(",
")",
",",
"'primary_key'",
"=>",
"$",
"this",
"->",
"isPrimaryKey",
"(",
"$",
"table",
",",
"$",
"column",
")",
",",
"'foreign_key'",
"=>",
"$",
"this",
"->",
"isForeignKey",
"(",
"$",
"table",
",",
"$",
"column",
")",
"]",
";",
"}",
"return",
"$",
"fileds",
";",
"}"
]
| get database fileds
@param Table $table
@return array | [
"get",
"database",
"fileds"
]
| 4288426517f53d05177b8729c4ba94c5beca9a98 | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L100-L118 |
17,874 | flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.isPrimaryKey | protected function isPrimaryKey(Table $table, Column $column)
{
if ($table->hasPrimaryKey()) {
$primaryKeys = $table->getPrimaryKey()->getColumns();
return in_array($column->getName(), $primaryKeys);
}
return false;
} | php | protected function isPrimaryKey(Table $table, Column $column)
{
if ($table->hasPrimaryKey()) {
$primaryKeys = $table->getPrimaryKey()->getColumns();
return in_array($column->getName(), $primaryKeys);
}
return false;
} | [
"protected",
"function",
"isPrimaryKey",
"(",
"Table",
"$",
"table",
",",
"Column",
"$",
"column",
")",
"{",
"if",
"(",
"$",
"table",
"->",
"hasPrimaryKey",
"(",
")",
")",
"{",
"$",
"primaryKeys",
"=",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
"->",
"getColumns",
"(",
")",
";",
"return",
"in_array",
"(",
"$",
"column",
"->",
"getName",
"(",
")",
",",
"$",
"primaryKeys",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| check is column primary key
@param Table $table
@param Column $column
@return bool | [
"check",
"is",
"column",
"primary",
"key"
]
| 4288426517f53d05177b8729c4ba94c5beca9a98 | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L127-L136 |
17,875 | flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.isForeignKey | protected function isForeignKey(Table $table, Column $column)
{
$foreignKey = false;
foreach ($table->getIndexes() as $key => $index) {
if ($key !== 'primary') {
try {
$fkConstrain = $table->getForeignkey($key);
$foreignKey = in_array($column->getName(), $fkConstrain->getColumns());
} catch (Exception $e) {
//do noting
}
}
}
return $foreignKey;
} | php | protected function isForeignKey(Table $table, Column $column)
{
$foreignKey = false;
foreach ($table->getIndexes() as $key => $index) {
if ($key !== 'primary') {
try {
$fkConstrain = $table->getForeignkey($key);
$foreignKey = in_array($column->getName(), $fkConstrain->getColumns());
} catch (Exception $e) {
//do noting
}
}
}
return $foreignKey;
} | [
"protected",
"function",
"isForeignKey",
"(",
"Table",
"$",
"table",
",",
"Column",
"$",
"column",
")",
"{",
"$",
"foreignKey",
"=",
"false",
";",
"foreach",
"(",
"$",
"table",
"->",
"getIndexes",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"'primary'",
")",
"{",
"try",
"{",
"$",
"fkConstrain",
"=",
"$",
"table",
"->",
"getForeignkey",
"(",
"$",
"key",
")",
";",
"$",
"foreignKey",
"=",
"in_array",
"(",
"$",
"column",
"->",
"getName",
"(",
")",
",",
"$",
"fkConstrain",
"->",
"getColumns",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"//do noting",
"}",
"}",
"}",
"return",
"$",
"foreignKey",
";",
"}"
]
| check is column foreign key
@param Table $table
@param Column $column
@return bool | [
"check",
"is",
"column",
"foreign",
"key"
]
| 4288426517f53d05177b8729c4ba94c5beca9a98 | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L145-L161 |
17,876 | flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.getFields | public function getFields($table)
{
if (isset($this->tables[$table])) {
return new Collection($this->tables[$table]);
}
} | php | public function getFields($table)
{
if (isset($this->tables[$table])) {
return new Collection($this->tables[$table]);
}
} | [
"public",
"function",
"getFields",
"(",
"$",
"table",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"tables",
"[",
"$",
"table",
"]",
")",
")",
"{",
"return",
"new",
"Collection",
"(",
"$",
"this",
"->",
"tables",
"[",
"$",
"table",
"]",
")",
";",
"}",
"}"
]
| get table fields
@param string $table
@return array | [
"get",
"table",
"fields"
]
| 4288426517f53d05177b8729c4ba94c5beca9a98 | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L189-L194 |
17,877 | flipboxstudio/orm-manager | src/Flipbox/OrmManager/DatabaseConnection.php | DatabaseConnection.isFieldExists | public function isFieldExists($table, $field)
{
if (isset($this->tables[$table])) {
$fields = $this->getFields($table);
return $fields->where('name', $field)->count() > 0;
}
return false;
} | php | public function isFieldExists($table, $field)
{
if (isset($this->tables[$table])) {
$fields = $this->getFields($table);
return $fields->where('name', $field)->count() > 0;
}
return false;
} | [
"public",
"function",
"isFieldExists",
"(",
"$",
"table",
",",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"tables",
"[",
"$",
"table",
"]",
")",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFields",
"(",
"$",
"table",
")",
";",
"return",
"$",
"fields",
"->",
"where",
"(",
"'name'",
",",
"$",
"field",
")",
"->",
"count",
"(",
")",
">",
"0",
";",
"}",
"return",
"false",
";",
"}"
]
| check is model table exists
@param string $table
@param string $field
@return bool | [
"check",
"is",
"model",
"table",
"exists"
]
| 4288426517f53d05177b8729c4ba94c5beca9a98 | https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/DatabaseConnection.php#L214-L223 |
17,878 | ARCANEDEV/Sanitizer | src/Filters/UrlFilter.php | UrlFilter.filter | public function filter($value, array $options = [])
{
if ( ! is_string($value)) return $value;
$value = trim($value);
if ( ! Str::startsWith($value, ['http://', 'https://'])) {
$value = "http://$value";
}
return filter_var($value, FILTER_SANITIZE_URL);
} | php | public function filter($value, array $options = [])
{
if ( ! is_string($value)) return $value;
$value = trim($value);
if ( ! Str::startsWith($value, ['http://', 'https://'])) {
$value = "http://$value";
}
return filter_var($value, FILTER_SANITIZE_URL);
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"return",
"$",
"value",
";",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"Str",
"::",
"startsWith",
"(",
"$",
"value",
",",
"[",
"'http://'",
",",
"'https://'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"\"http://$value\"",
";",
"}",
"return",
"filter_var",
"(",
"$",
"value",
",",
"FILTER_SANITIZE_URL",
")",
";",
"}"
]
| Sanitize url of the given string.
@param mixed $value
@param array $options
@return string|mixed | [
"Sanitize",
"url",
"of",
"the",
"given",
"string",
"."
]
| e21990ce6d881366d52a7f4e5040b07cc3ecca96 | https://github.com/ARCANEDEV/Sanitizer/blob/e21990ce6d881366d52a7f4e5040b07cc3ecca96/src/Filters/UrlFilter.php#L26-L37 |
17,879 | amostajo/wordpress-plugin-core | src/psr4/Cache.php | Cache.add | public static function add( $key, $value, $expires )
{
$cache = self::instance();
if ( $cache && $value != null) {
$cache->set( $key, $value, $expires * 60 );
}
} | php | public static function add( $key, $value, $expires )
{
$cache = self::instance();
if ( $cache && $value != null) {
$cache->set( $key, $value, $expires * 60 );
}
} | [
"public",
"static",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expires",
")",
"{",
"$",
"cache",
"=",
"self",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"cache",
"&&",
"$",
"value",
"!=",
"null",
")",
"{",
"$",
"cache",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expires",
"*",
"60",
")",
";",
"}",
"}"
]
| Adds a value to cache.
@since 1.0
@param string $key Main plugin object as reference.
@param mixed $value Value to cache.
@param int $expires Expiration time in minutes. | [
"Adds",
"a",
"value",
"to",
"cache",
"."
]
| 63aba30b07057df540c3af4dc50b92bd5501d6fd | https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Cache.php#L89-L95 |
17,880 | amostajo/wordpress-plugin-core | src/psr4/Cache.php | Cache.has | public static function has( $key )
{
$cache = self::instance();
if ( $cache ) {
return $cache->isExisting( $key );
}
return false;
} | php | public static function has( $key )
{
$cache = self::instance();
if ( $cache ) {
return $cache->isExisting( $key );
}
return false;
} | [
"public",
"static",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"$",
"cache",
"=",
"self",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"return",
"$",
"cache",
"->",
"isExisting",
"(",
"$",
"key",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Returns flag if a given key has a value in cache or not.
@since 1.0
@param string $key Cache key name.
@return bool | [
"Returns",
"flag",
"if",
"a",
"given",
"key",
"has",
"a",
"value",
"in",
"cache",
"or",
"not",
"."
]
| 63aba30b07057df540c3af4dc50b92bd5501d6fd | https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Cache.php#L103-L110 |
17,881 | amostajo/wordpress-plugin-core | src/psr4/Cache.php | Cache.remember | public static function remember( $key, $expires, Closure $closure )
{
$cache = self::instance();
if ( $cache ) {
if ( $cache->isExisting( $key ) ) {
return $cache->get( $key );
} else if ( $closure != null ) {
$value = $closure();
$cache->set( $key, $value, $expires * 60 );
return $value;
}
}
return $closure();
} | php | public static function remember( $key, $expires, Closure $closure )
{
$cache = self::instance();
if ( $cache ) {
if ( $cache->isExisting( $key ) ) {
return $cache->get( $key );
} else if ( $closure != null ) {
$value = $closure();
$cache->set( $key, $value, $expires * 60 );
return $value;
}
}
return $closure();
} | [
"public",
"static",
"function",
"remember",
"(",
"$",
"key",
",",
"$",
"expires",
",",
"Closure",
"$",
"closure",
")",
"{",
"$",
"cache",
"=",
"self",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"if",
"(",
"$",
"cache",
"->",
"isExisting",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"cache",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"else",
"if",
"(",
"$",
"closure",
"!=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"closure",
"(",
")",
";",
"$",
"cache",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expires",
"*",
"60",
")",
";",
"return",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"closure",
"(",
")",
";",
"}"
]
| Returns the value of a given key.
If it doesn't exist, then the value pass by is returned.
@since 1.0
@param string $key Main plugin object as reference.
@param int $expires Expiration time in minutes.
@param Closure $value Value to cache.
@return mixed | [
"Returns",
"the",
"value",
"of",
"a",
"given",
"key",
".",
"If",
"it",
"doesn",
"t",
"exist",
"then",
"the",
"value",
"pass",
"by",
"is",
"returned",
"."
]
| 63aba30b07057df540c3af4dc50b92bd5501d6fd | https://github.com/amostajo/wordpress-plugin-core/blob/63aba30b07057df540c3af4dc50b92bd5501d6fd/src/psr4/Cache.php#L121-L134 |
17,882 | dashifen/wordpress-php7-plugin-boilerplate | src/Controller/AbstractController.php | AbstractController.defineActivationHooks | protected function defineActivationHooks(): void {
$backend = $this->getBackend();
$pluginName = $this->getFilename();
$handlers = ["activate", "deactivate", "uninstall"];
foreach ($handlers as $handler) {
// for each of our handlers, we hook an action handler to our
// backend component. the purpose of the BackendInterface is
// to guarantee that we have three methods, one for each of
// these hooks.
$hook = $handler . "_" . $pluginName;
$this->loader->addAction($hook, $backend, $handler);
}
} | php | protected function defineActivationHooks(): void {
$backend = $this->getBackend();
$pluginName = $this->getFilename();
$handlers = ["activate", "deactivate", "uninstall"];
foreach ($handlers as $handler) {
// for each of our handlers, we hook an action handler to our
// backend component. the purpose of the BackendInterface is
// to guarantee that we have three methods, one for each of
// these hooks.
$hook = $handler . "_" . $pluginName;
$this->loader->addAction($hook, $backend, $handler);
}
} | [
"protected",
"function",
"defineActivationHooks",
"(",
")",
":",
"void",
"{",
"$",
"backend",
"=",
"$",
"this",
"->",
"getBackend",
"(",
")",
";",
"$",
"pluginName",
"=",
"$",
"this",
"->",
"getFilename",
"(",
")",
";",
"$",
"handlers",
"=",
"[",
"\"activate\"",
",",
"\"deactivate\"",
",",
"\"uninstall\"",
"]",
";",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"handler",
")",
"{",
"// for each of our handlers, we hook an action handler to our",
"// backend component. the purpose of the BackendInterface is",
"// to guarantee that we have three methods, one for each of",
"// these hooks.",
"$",
"hook",
"=",
"$",
"handler",
".",
"\"_\"",
".",
"$",
"pluginName",
";",
"$",
"this",
"->",
"loader",
"->",
"addAction",
"(",
"$",
"hook",
",",
"$",
"backend",
",",
"$",
"handler",
")",
";",
"}",
"}"
]
| Defines hooks using the Backend object for the activate,
deactivate, and uninstall actions of this plugin.
@return void | [
"Defines",
"hooks",
"using",
"the",
"Backend",
"object",
"for",
"the",
"activate",
"deactivate",
"and",
"uninstall",
"actions",
"of",
"this",
"plugin",
"."
]
| c7875deb403d311efca72dc3c8beb566972a56cb | https://github.com/dashifen/wordpress-php7-plugin-boilerplate/blob/c7875deb403d311efca72dc3c8beb566972a56cb/src/Controller/AbstractController.php#L115-L129 |
17,883 | nyeholt/silverstripe-external-content | thirdparty/Zend/Feed/Builder.php | Zend_Feed_Builder._createEntries | private function _createEntries(array $data)
{
foreach ($data as $row) {
$mandatories = array('title', 'link', 'description');
foreach ($mandatories as $mandatory) {
if (!isset($row[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$entry = new Zend_Feed_Builder_Entry($row['title'], $row['link'], $row['description']);
if (isset($row['author'])) {
$entry->setAuthor($row['author']);
}
if (isset($row['guid'])) {
$entry->setId($row['guid']);
}
if (isset($row['content'])) {
$entry->setContent($row['content']);
}
if (isset($row['lastUpdate'])) {
$entry->setLastUpdate($row['lastUpdate']);
}
if (isset($row['comments'])) {
$entry->setCommentsUrl($row['comments']);
}
if (isset($row['commentRss'])) {
$entry->setCommentsRssUrl($row['commentRss']);
}
if (isset($row['source'])) {
$mandatories = array('title', 'url');
foreach ($mandatories as $mandatory) {
if (!isset($row['source'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key of source property is missing");
}
}
$entry->setSource($row['source']['title'], $row['source']['url']);
}
if (isset($row['category'])) {
$entry->setCategories($row['category']);
}
if (isset($row['enclosure'])) {
$entry->setEnclosures($row['enclosure']);
}
$this->_entries[] = $entry;
}
} | php | private function _createEntries(array $data)
{
foreach ($data as $row) {
$mandatories = array('title', 'link', 'description');
foreach ($mandatories as $mandatory) {
if (!isset($row[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$entry = new Zend_Feed_Builder_Entry($row['title'], $row['link'], $row['description']);
if (isset($row['author'])) {
$entry->setAuthor($row['author']);
}
if (isset($row['guid'])) {
$entry->setId($row['guid']);
}
if (isset($row['content'])) {
$entry->setContent($row['content']);
}
if (isset($row['lastUpdate'])) {
$entry->setLastUpdate($row['lastUpdate']);
}
if (isset($row['comments'])) {
$entry->setCommentsUrl($row['comments']);
}
if (isset($row['commentRss'])) {
$entry->setCommentsRssUrl($row['commentRss']);
}
if (isset($row['source'])) {
$mandatories = array('title', 'url');
foreach ($mandatories as $mandatory) {
if (!isset($row['source'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key of source property is missing");
}
}
$entry->setSource($row['source']['title'], $row['source']['url']);
}
if (isset($row['category'])) {
$entry->setCategories($row['category']);
}
if (isset($row['enclosure'])) {
$entry->setEnclosures($row['enclosure']);
}
$this->_entries[] = $entry;
}
} | [
"private",
"function",
"_createEntries",
"(",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"row",
")",
"{",
"$",
"mandatories",
"=",
"array",
"(",
"'title'",
",",
"'link'",
",",
"'description'",
")",
";",
"foreach",
"(",
"$",
"mandatories",
"as",
"$",
"mandatory",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"$",
"mandatory",
"]",
")",
")",
"{",
"/**\n * @see Zend_Feed_Builder_Exception\n */",
"require_once",
"'Zend/Feed/Builder/Exception.php'",
";",
"throw",
"new",
"Zend_Feed_Builder_Exception",
"(",
"\"$mandatory key is missing\"",
")",
";",
"}",
"}",
"$",
"entry",
"=",
"new",
"Zend_Feed_Builder_Entry",
"(",
"$",
"row",
"[",
"'title'",
"]",
",",
"$",
"row",
"[",
"'link'",
"]",
",",
"$",
"row",
"[",
"'description'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'author'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setAuthor",
"(",
"$",
"row",
"[",
"'author'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'guid'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setId",
"(",
"$",
"row",
"[",
"'guid'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'content'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setContent",
"(",
"$",
"row",
"[",
"'content'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'lastUpdate'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setLastUpdate",
"(",
"$",
"row",
"[",
"'lastUpdate'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'comments'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setCommentsUrl",
"(",
"$",
"row",
"[",
"'comments'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'commentRss'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setCommentsRssUrl",
"(",
"$",
"row",
"[",
"'commentRss'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'source'",
"]",
")",
")",
"{",
"$",
"mandatories",
"=",
"array",
"(",
"'title'",
",",
"'url'",
")",
";",
"foreach",
"(",
"$",
"mandatories",
"as",
"$",
"mandatory",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"'source'",
"]",
"[",
"$",
"mandatory",
"]",
")",
")",
"{",
"/**\n * @see Zend_Feed_Builder_Exception\n */",
"require_once",
"'Zend/Feed/Builder/Exception.php'",
";",
"throw",
"new",
"Zend_Feed_Builder_Exception",
"(",
"\"$mandatory key of source property is missing\"",
")",
";",
"}",
"}",
"$",
"entry",
"->",
"setSource",
"(",
"$",
"row",
"[",
"'source'",
"]",
"[",
"'title'",
"]",
",",
"$",
"row",
"[",
"'source'",
"]",
"[",
"'url'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'category'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setCategories",
"(",
"$",
"row",
"[",
"'category'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'enclosure'",
"]",
")",
")",
"{",
"$",
"entry",
"->",
"setEnclosures",
"(",
"$",
"row",
"[",
"'enclosure'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_entries",
"[",
"]",
"=",
"$",
"entry",
";",
"}",
"}"
]
| Create the array of article entries
@param array $data
@throws Zend_Feed_Builder_Exception
@return void | [
"Create",
"the",
"array",
"of",
"article",
"entries"
]
| 1c6da8c56ef717225ff904e1522aff94ed051601 | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder.php#L343-L397 |
17,884 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getAttrAsArray | private function getAttrAsArray(\DOMElement $element)
{
$return = [];
for ($i = 0; $i < $element->attributes->length; ++$i) {
$return[$element->attributes->item($i)->nodeName] = $element->attributes->item($i)->nodeValue;
}
return $return;
} | php | private function getAttrAsArray(\DOMElement $element)
{
$return = [];
for ($i = 0; $i < $element->attributes->length; ++$i) {
$return[$element->attributes->item($i)->nodeName] = $element->attributes->item($i)->nodeValue;
}
return $return;
} | [
"private",
"function",
"getAttrAsArray",
"(",
"\\",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"element",
"->",
"attributes",
"->",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"return",
"[",
"$",
"element",
"->",
"attributes",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeName",
"]",
"=",
"$",
"element",
"->",
"attributes",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeValue",
";",
"}",
"return",
"$",
"return",
";",
"}"
]
| Get element attributes as array.
@param \DOMElement $element
@return array | [
"Get",
"element",
"attributes",
"as",
"array",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L447-L455 |
17,885 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.setCover | private function setCover(Item $item, $id, $type)
{
$item->setCover(self::NAME.'/'.$id.'/1.jpg');
return $this->uploadImage($this->getCoverUrl($id, $type), $item);
} | php | private function setCover(Item $item, $id, $type)
{
$item->setCover(self::NAME.'/'.$id.'/1.jpg');
return $this->uploadImage($this->getCoverUrl($id, $type), $item);
} | [
"private",
"function",
"setCover",
"(",
"Item",
"$",
"item",
",",
"$",
"id",
",",
"$",
"type",
")",
"{",
"$",
"item",
"->",
"setCover",
"(",
"self",
"::",
"NAME",
".",
"'/'",
".",
"$",
"id",
".",
"'/1.jpg'",
")",
";",
"return",
"$",
"this",
"->",
"uploadImage",
"(",
"$",
"this",
"->",
"getCoverUrl",
"(",
"$",
"id",
",",
"$",
"type",
")",
",",
"$",
"item",
")",
";",
"}"
]
| Get cover from source id.
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@param string $id
@param string $type
@return bool | [
"Get",
"cover",
"from",
"source",
"id",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L466-L471 |
17,886 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getGenreByName | private function getGenreByName($name)
{
if (isset($this->genres[$name])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Genre')
->findOneByName($this->genres[$name]);
}
} | php | private function getGenreByName($name)
{
if (isset($this->genres[$name])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Genre')
->findOneByName($this->genres[$name]);
}
} | [
"private",
"function",
"getGenreByName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"genres",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"doctrine",
"->",
"getRepository",
"(",
"'AnimeDbCatalogBundle:Genre'",
")",
"->",
"findOneByName",
"(",
"$",
"this",
"->",
"genres",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}"
]
| Get real genre by name.
@param string $name
@return \AnimeDb\Bundle\CatalogBundle\Entity\Genre|null | [
"Get",
"real",
"genre",
"by",
"name",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L696-L703 |
17,887 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getTypeByName | private function getTypeByName($name)
{
if (isset($this->types[$name])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Type')
->find($this->types[$name]);
}
} | php | private function getTypeByName($name)
{
if (isset($this->types[$name])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Type')
->find($this->types[$name]);
}
} | [
"private",
"function",
"getTypeByName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"doctrine",
"->",
"getRepository",
"(",
"'AnimeDbCatalogBundle:Type'",
")",
"->",
"find",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}"
]
| Get real type by name.
@param string $name
@return \AnimeDb\Bundle\CatalogBundle\Entity\Type|null | [
"Get",
"real",
"type",
"by",
"name",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L712-L719 |
17,888 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getFrames | public function getFrames($id, $type)
{
$dom = $this->browser->getDom('/'.$type.'/'.$type.'_photos.php?id='.$id);
if (!$dom) {
return [];
}
$images = (new \DOMXPath($dom))->query('//table//table//table//img');
$frames = [];
foreach ($images as $image) {
$src = $this->getAttrAsArray($image)['src'];
$entity = new Image();
if ($type == self::ITEM_TYPE_ANIMATION) {
$src = str_replace('optimize_b', 'optimize_d', $src);
if (strpos($src, 'http://') === false) {
$src = $this->browser->getHost().'/'.$type.'/'.$src;
}
if (preg_match('/\-(?<image>\d+)\-optimize_d(?<ext>\.jpe?g|png|gif)/', $src, $mat)) {
$entity->setSource(self::NAME.'/'.$id.'/'.$mat['image'].$mat['ext']);
if ($this->uploadImage($src, $entity)) {
$frames[] = $entity;
}
}
} elseif (preg_match('/_(?<round>\d+)\/.+\/(?<id>\d+)-(?<image>\d+)-.+(?<ext>\.jpe?g|png|gif)/', $src, $mat)) {
$src = $this->browser->getHost().'/'.$type.'/img/'.$mat['round'].'/'.$mat['id'].'/'.$mat['image'].$mat['ext'];
$entity->setSource(self::NAME.'/'.$id.'/'.$mat['image'].$mat['ext']);
if ($this->uploadImage($src, $entity)) {
$frames[] = $entity;
}
}
}
return $frames;
} | php | public function getFrames($id, $type)
{
$dom = $this->browser->getDom('/'.$type.'/'.$type.'_photos.php?id='.$id);
if (!$dom) {
return [];
}
$images = (new \DOMXPath($dom))->query('//table//table//table//img');
$frames = [];
foreach ($images as $image) {
$src = $this->getAttrAsArray($image)['src'];
$entity = new Image();
if ($type == self::ITEM_TYPE_ANIMATION) {
$src = str_replace('optimize_b', 'optimize_d', $src);
if (strpos($src, 'http://') === false) {
$src = $this->browser->getHost().'/'.$type.'/'.$src;
}
if (preg_match('/\-(?<image>\d+)\-optimize_d(?<ext>\.jpe?g|png|gif)/', $src, $mat)) {
$entity->setSource(self::NAME.'/'.$id.'/'.$mat['image'].$mat['ext']);
if ($this->uploadImage($src, $entity)) {
$frames[] = $entity;
}
}
} elseif (preg_match('/_(?<round>\d+)\/.+\/(?<id>\d+)-(?<image>\d+)-.+(?<ext>\.jpe?g|png|gif)/', $src, $mat)) {
$src = $this->browser->getHost().'/'.$type.'/img/'.$mat['round'].'/'.$mat['id'].'/'.$mat['image'].$mat['ext'];
$entity->setSource(self::NAME.'/'.$id.'/'.$mat['image'].$mat['ext']);
if ($this->uploadImage($src, $entity)) {
$frames[] = $entity;
}
}
}
return $frames;
} | [
"public",
"function",
"getFrames",
"(",
"$",
"id",
",",
"$",
"type",
")",
"{",
"$",
"dom",
"=",
"$",
"this",
"->",
"browser",
"->",
"getDom",
"(",
"'/'",
".",
"$",
"type",
".",
"'/'",
".",
"$",
"type",
".",
"'_photos.php?id='",
".",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"dom",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"images",
"=",
"(",
"new",
"\\",
"DOMXPath",
"(",
"$",
"dom",
")",
")",
"->",
"query",
"(",
"'//table//table//table//img'",
")",
";",
"$",
"frames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"images",
"as",
"$",
"image",
")",
"{",
"$",
"src",
"=",
"$",
"this",
"->",
"getAttrAsArray",
"(",
"$",
"image",
")",
"[",
"'src'",
"]",
";",
"$",
"entity",
"=",
"new",
"Image",
"(",
")",
";",
"if",
"(",
"$",
"type",
"==",
"self",
"::",
"ITEM_TYPE_ANIMATION",
")",
"{",
"$",
"src",
"=",
"str_replace",
"(",
"'optimize_b'",
",",
"'optimize_d'",
",",
"$",
"src",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"src",
",",
"'http://'",
")",
"===",
"false",
")",
"{",
"$",
"src",
"=",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
".",
"'/'",
".",
"$",
"type",
".",
"'/'",
".",
"$",
"src",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/\\-(?<image>\\d+)\\-optimize_d(?<ext>\\.jpe?g|png|gif)/'",
",",
"$",
"src",
",",
"$",
"mat",
")",
")",
"{",
"$",
"entity",
"->",
"setSource",
"(",
"self",
"::",
"NAME",
".",
"'/'",
".",
"$",
"id",
".",
"'/'",
".",
"$",
"mat",
"[",
"'image'",
"]",
".",
"$",
"mat",
"[",
"'ext'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"uploadImage",
"(",
"$",
"src",
",",
"$",
"entity",
")",
")",
"{",
"$",
"frames",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"}",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/_(?<round>\\d+)\\/.+\\/(?<id>\\d+)-(?<image>\\d+)-.+(?<ext>\\.jpe?g|png|gif)/'",
",",
"$",
"src",
",",
"$",
"mat",
")",
")",
"{",
"$",
"src",
"=",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
".",
"'/'",
".",
"$",
"type",
".",
"'/img/'",
".",
"$",
"mat",
"[",
"'round'",
"]",
".",
"'/'",
".",
"$",
"mat",
"[",
"'id'",
"]",
".",
"'/'",
".",
"$",
"mat",
"[",
"'image'",
"]",
".",
"$",
"mat",
"[",
"'ext'",
"]",
";",
"$",
"entity",
"->",
"setSource",
"(",
"self",
"::",
"NAME",
".",
"'/'",
".",
"$",
"id",
".",
"'/'",
".",
"$",
"mat",
"[",
"'image'",
"]",
".",
"$",
"mat",
"[",
"'ext'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"uploadImage",
"(",
"$",
"src",
",",
"$",
"entity",
")",
")",
"{",
"$",
"frames",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"}",
"}",
"return",
"$",
"frames",
";",
"}"
]
| Get item frames.
@param int $id
@param string $type
@return array | [
"Get",
"item",
"frames",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L729-L761 |
17,889 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getNodeValueAsText | private function getNodeValueAsText(\DOMNode $node)
{
$text = $node->ownerDocument->saveHTML($node);
$text = str_replace(["<br>\n", "\n", '<br>'], ['<br>', ' ', "\n"], $text);
return trim(strip_tags($text));
} | php | private function getNodeValueAsText(\DOMNode $node)
{
$text = $node->ownerDocument->saveHTML($node);
$text = str_replace(["<br>\n", "\n", '<br>'], ['<br>', ' ', "\n"], $text);
return trim(strip_tags($text));
} | [
"private",
"function",
"getNodeValueAsText",
"(",
"\\",
"DOMNode",
"$",
"node",
")",
"{",
"$",
"text",
"=",
"$",
"node",
"->",
"ownerDocument",
"->",
"saveHTML",
"(",
"$",
"node",
")",
";",
"$",
"text",
"=",
"str_replace",
"(",
"[",
"\"<br>\\n\"",
",",
"\"\\n\"",
",",
"'<br>'",
"]",
",",
"[",
"'<br>'",
",",
"' '",
",",
"\"\\n\"",
"]",
",",
"$",
"text",
")",
";",
"return",
"trim",
"(",
"strip_tags",
"(",
"$",
"text",
")",
")",
";",
"}"
]
| Get node value as text.
@param \DOMNode $node
@return string | [
"Get",
"node",
"value",
"as",
"text",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L770-L776 |
17,890 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getStudio | private function getStudio(\DOMXPath $xpath, \DOMNode $body)
{
$studios = $xpath->query('//img[starts-with(@src,"http://www.world-art.ru/img/company_new/")]', $body);
if ($studios->length) {
foreach ($studios as $studio) {
$url = $studio->attributes->getNamedItem('src')->nodeValue;
if (preg_match('/\/(\d+)\./', $url, $mat) && isset($this->studios[$mat[1]])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Studio')
->findOneByName($this->studios[$mat[1]]);
}
}
}
} | php | private function getStudio(\DOMXPath $xpath, \DOMNode $body)
{
$studios = $xpath->query('//img[starts-with(@src,"http://www.world-art.ru/img/company_new/")]', $body);
if ($studios->length) {
foreach ($studios as $studio) {
$url = $studio->attributes->getNamedItem('src')->nodeValue;
if (preg_match('/\/(\d+)\./', $url, $mat) && isset($this->studios[$mat[1]])) {
return $this->doctrine
->getRepository('AnimeDbCatalogBundle:Studio')
->findOneByName($this->studios[$mat[1]]);
}
}
}
} | [
"private",
"function",
"getStudio",
"(",
"\\",
"DOMXPath",
"$",
"xpath",
",",
"\\",
"DOMNode",
"$",
"body",
")",
"{",
"$",
"studios",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'//img[starts-with(@src,\"http://www.world-art.ru/img/company_new/\")]'",
",",
"$",
"body",
")",
";",
"if",
"(",
"$",
"studios",
"->",
"length",
")",
"{",
"foreach",
"(",
"$",
"studios",
"as",
"$",
"studio",
")",
"{",
"$",
"url",
"=",
"$",
"studio",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"'src'",
")",
"->",
"nodeValue",
";",
"if",
"(",
"preg_match",
"(",
"'/\\/(\\d+)\\./'",
",",
"$",
"url",
",",
"$",
"mat",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"studios",
"[",
"$",
"mat",
"[",
"1",
"]",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"doctrine",
"->",
"getRepository",
"(",
"'AnimeDbCatalogBundle:Studio'",
")",
"->",
"findOneByName",
"(",
"$",
"this",
"->",
"studios",
"[",
"$",
"mat",
"[",
"1",
"]",
"]",
")",
";",
"}",
"}",
"}",
"}"
]
| Get item studio.
@param \DOMXPath $xpath
@param \DOMNode $body
@return \AnimeDb\Bundle\CatalogBundle\Entity\Studio|null | [
"Get",
"item",
"studio",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L786-L799 |
17,891 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getItemType | public function getItemType($url)
{
if (strpos($url, self::ITEM_TYPE_ANIMATION.'/'.self::ITEM_TYPE_ANIMATION) !== false) {
return self::ITEM_TYPE_ANIMATION;
} elseif (strpos($url, self::ITEM_TYPE_CINEMA.'/'.self::ITEM_TYPE_CINEMA) !== false) {
return self::ITEM_TYPE_CINEMA;
} else {
return;
}
} | php | public function getItemType($url)
{
if (strpos($url, self::ITEM_TYPE_ANIMATION.'/'.self::ITEM_TYPE_ANIMATION) !== false) {
return self::ITEM_TYPE_ANIMATION;
} elseif (strpos($url, self::ITEM_TYPE_CINEMA.'/'.self::ITEM_TYPE_CINEMA) !== false) {
return self::ITEM_TYPE_CINEMA;
} else {
return;
}
} | [
"public",
"function",
"getItemType",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"url",
",",
"self",
"::",
"ITEM_TYPE_ANIMATION",
".",
"'/'",
".",
"self",
"::",
"ITEM_TYPE_ANIMATION",
")",
"!==",
"false",
")",
"{",
"return",
"self",
"::",
"ITEM_TYPE_ANIMATION",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"url",
",",
"self",
"::",
"ITEM_TYPE_CINEMA",
".",
"'/'",
".",
"self",
"::",
"ITEM_TYPE_CINEMA",
")",
"!==",
"false",
")",
"{",
"return",
"self",
"::",
"ITEM_TYPE_CINEMA",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}"
]
| Get item type by URL.
@param string $url
@return string | [
"Get",
"item",
"type",
"by",
"URL",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L808-L817 |
17,892 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.fillAnimationNames | protected function fillAnimationNames(Item $item, \DOMXPath $xpath, \DOMElement $head)
{
// add main name
$names = $xpath->query('table[1]/tr/td', $head)->item(0)->nodeValue;
$names = explode("\n", trim($names));
// clear
$name = preg_replace('/\[\d{4}\]/', '', array_shift($names)); // example: [2011]
$name = preg_replace('/\[?(ТВ|OVA|ONA)(\-\d)?\]?/', '', $name); // example: [TV-1]
$name = preg_replace('/\(фильм \w+\)/u', '', $name); // example: (фильм седьмой)
$name = preg_replace('/ - Фильм$/iu', '', $name); // example: - Фильм
$item->setName(trim($name));
// add other names
foreach ($names as $name) {
$name = trim(preg_replace('/(\(\d+\))?/', '', $name));
$item->addName((new Name())->setName($name));
}
return $item;
} | php | protected function fillAnimationNames(Item $item, \DOMXPath $xpath, \DOMElement $head)
{
// add main name
$names = $xpath->query('table[1]/tr/td', $head)->item(0)->nodeValue;
$names = explode("\n", trim($names));
// clear
$name = preg_replace('/\[\d{4}\]/', '', array_shift($names)); // example: [2011]
$name = preg_replace('/\[?(ТВ|OVA|ONA)(\-\d)?\]?/', '', $name); // example: [TV-1]
$name = preg_replace('/\(фильм \w+\)/u', '', $name); // example: (фильм седьмой)
$name = preg_replace('/ - Фильм$/iu', '', $name); // example: - Фильм
$item->setName(trim($name));
// add other names
foreach ($names as $name) {
$name = trim(preg_replace('/(\(\d+\))?/', '', $name));
$item->addName((new Name())->setName($name));
}
return $item;
} | [
"protected",
"function",
"fillAnimationNames",
"(",
"Item",
"$",
"item",
",",
"\\",
"DOMXPath",
"$",
"xpath",
",",
"\\",
"DOMElement",
"$",
"head",
")",
"{",
"// add main name",
"$",
"names",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'table[1]/tr/td'",
",",
"$",
"head",
")",
"->",
"item",
"(",
"0",
")",
"->",
"nodeValue",
";",
"$",
"names",
"=",
"explode",
"(",
"\"\\n\"",
",",
"trim",
"(",
"$",
"names",
")",
")",
";",
"// clear",
"$",
"name",
"=",
"preg_replace",
"(",
"'/\\[\\d{4}\\]/'",
",",
"''",
",",
"array_shift",
"(",
"$",
"names",
")",
")",
";",
"// example: [2011]",
"$",
"name",
"=",
"preg_replace",
"(",
"'/\\[?(ТВ|OVA|ONA)(\\-\\d)?\\]?/', ",
"'",
", ",
"$",
"a",
"me);",
" ",
"/",
" example: [TV-1]",
"$",
"name",
"=",
"preg_replace",
"(",
"'/\\(фильм \\w+\\)/u', '',",
" ",
"na",
"m",
")",
"; //",
" ",
"e",
"ample: (фильм седьмой)",
"$",
"name",
"=",
"preg_replace",
"(",
"'/ - Фильм$/iu', '',",
" ",
"na",
"m",
")",
"; //",
" ",
"e",
"ample: - Фильм",
"$",
"item",
"->",
"setName",
"(",
"trim",
"(",
"$",
"name",
")",
")",
";",
"// add other names",
"foreach",
"(",
"$",
"names",
"as",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"trim",
"(",
"preg_replace",
"(",
"'/(\\(\\d+\\))?/'",
",",
"''",
",",
"$",
"name",
")",
")",
";",
"$",
"item",
"->",
"addName",
"(",
"(",
"new",
"Name",
"(",
")",
")",
"->",
"setName",
"(",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"item",
";",
"}"
]
| Fill names for Animation type.
@param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
@param \DOMXPath $xpath
@param \DOMElement $head
@return \AnimeDb\Bundle\CatalogBundle\Entity\Item | [
"Fill",
"names",
"for",
"Animation",
"type",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L828-L848 |
17,893 | anime-db/world-art-filler-bundle | src/Service/Filler.php | Filler.getCoverUrl | public function getCoverUrl($id, $type)
{
switch ($type) {
case self::ITEM_TYPE_ANIMATION:
return $this->browser->getHost().'/'.$type.'/img/'.(ceil($id / 1000) * 1000).'/'.$id.'/1.jpg';
case self::ITEM_TYPE_CINEMA:
return $this->browser->getHost().'/'.$type.'/img/'.(ceil($id / 10000) * 10000).'/'.$id.'/1.jpg';
default:
return;
}
} | php | public function getCoverUrl($id, $type)
{
switch ($type) {
case self::ITEM_TYPE_ANIMATION:
return $this->browser->getHost().'/'.$type.'/img/'.(ceil($id / 1000) * 1000).'/'.$id.'/1.jpg';
case self::ITEM_TYPE_CINEMA:
return $this->browser->getHost().'/'.$type.'/img/'.(ceil($id / 10000) * 10000).'/'.$id.'/1.jpg';
default:
return;
}
} | [
"public",
"function",
"getCoverUrl",
"(",
"$",
"id",
",",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"self",
"::",
"ITEM_TYPE_ANIMATION",
":",
"return",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
".",
"'/'",
".",
"$",
"type",
".",
"'/img/'",
".",
"(",
"ceil",
"(",
"$",
"id",
"/",
"1000",
")",
"*",
"1000",
")",
".",
"'/'",
".",
"$",
"id",
".",
"'/1.jpg'",
";",
"case",
"self",
"::",
"ITEM_TYPE_CINEMA",
":",
"return",
"$",
"this",
"->",
"browser",
"->",
"getHost",
"(",
")",
".",
"'/'",
".",
"$",
"type",
".",
"'/img/'",
".",
"(",
"ceil",
"(",
"$",
"id",
"/",
"10000",
")",
"*",
"10000",
")",
".",
"'/'",
".",
"$",
"id",
".",
"'/1.jpg'",
";",
"default",
":",
"return",
";",
"}",
"}"
]
| Get cover URL.
@param string $id
@param string $type
@return string|null | [
"Get",
"cover",
"URL",
"."
]
| f2ef4dbd12fe39c18183d1628b5049b8d381e42c | https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Filler.php#L890-L900 |
17,894 | EvanDotPro/EdpGithub | src/EdpGithub/Listener/Auth/UrlToken.php | UrlToken.preSend | public function preSend(Event $e)
{
$validator = new NotEmpty();
if (!isset($this->options['tokenOrLogin'])
|| !$validator->isValid($this->options['tokenOrLogin'])
) {
throw new Exception\InvalidArgumentException('You need to set OAuth token!');
}
/* @var Http\Request $request */
$request = $e->getTarget();
$query = $request->getQuery();
$query->set('access_token', $this->options['tokenOrLogin']);
} | php | public function preSend(Event $e)
{
$validator = new NotEmpty();
if (!isset($this->options['tokenOrLogin'])
|| !$validator->isValid($this->options['tokenOrLogin'])
) {
throw new Exception\InvalidArgumentException('You need to set OAuth token!');
}
/* @var Http\Request $request */
$request = $e->getTarget();
$query = $request->getQuery();
$query->set('access_token', $this->options['tokenOrLogin']);
} | [
"public",
"function",
"preSend",
"(",
"Event",
"$",
"e",
")",
"{",
"$",
"validator",
"=",
"new",
"NotEmpty",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'tokenOrLogin'",
"]",
")",
"||",
"!",
"$",
"validator",
"->",
"isValid",
"(",
"$",
"this",
"->",
"options",
"[",
"'tokenOrLogin'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'You need to set OAuth token!'",
")",
";",
"}",
"/* @var Http\\Request $request */",
"$",
"request",
"=",
"$",
"e",
"->",
"getTarget",
"(",
")",
";",
"$",
"query",
"=",
"$",
"request",
"->",
"getQuery",
"(",
")",
";",
"$",
"query",
"->",
"set",
"(",
"'access_token'",
",",
"$",
"this",
"->",
"options",
"[",
"'tokenOrLogin'",
"]",
")",
";",
"}"
]
| Add access token to Request Parameters
@throws Exception\InvalidArgumentException | [
"Add",
"access",
"token",
"to",
"Request",
"Parameters"
]
| 51f3e33e02edbef011103e3c2c1629d46af011a3 | https://github.com/EvanDotPro/EdpGithub/blob/51f3e33e02edbef011103e3c2c1629d46af011a3/src/EdpGithub/Listener/Auth/UrlToken.php#L16-L31 |
17,895 | dashifen/wordpress-php7-plugin-boilerplate | src/Controller/ControllerTraits/PostStatusesTrait.php | PostStatusesTrait.initPostStatusesTrait | final protected function initPostStatusesTrait(): void {
$postStatuses = $this->getPostStatuses();
// first, we register our statuses. notice that we directly call the
// WordPress add_action() function because we want to use anonymous
// functions here, and there's no good way to add these actions to a
// LoaderInterface object as a result. plus, we want these actions to
// "just happen" without a programmer having to think about them.
$options = [];
foreach ($postStatuses as $postStatus) {
$args = $this->getPostStatusArguments($postStatus);
add_action("init", function () use ($postStatus, $args) {
register_post_status($postStatus, $args);
});
$options[$postStatus] = $args["label"];
}
add_action("post_submitbox_misc_actions",
function (\WP_Post $post) use ($options) {
// registering our post status tells WordPress all about it,
// but WordPress doesn't automatically add them to the <select>
// elements in the DOM. so, we do that here. for more info
// see https://core.trac.wordpress.org/ticket/12706.
$jsonOptions = "{";
$optionFormat = '"%s": { "display": "%s", "selected": %d },';
foreach ($options as $status => $display) {
$selected = (int)$post->post_status === $status;
// for each of our options, we use the above format to
// create a series of JSON strings which we can inject
// into our JavaScript below.
$jsonOptions .= sprintf($optionFormat, $status, $display, $selected);
}
// the loop above adds an extra comma to our JSON string.
// we'll replace that comma with a the closing curly brace
// to end said string.
$jsonOptions = preg_replace("/,$/", "}", $jsonOptions);
ob_start(); ?>
<script id="php7BoilerplateAddPostStatuses">
(function ($) {
// we'll add our statuses into the scope of this
// anonymous functions. that way, it's accessible
// to the other functions, anonymous or otherwise,
// herein. but, it won't conflict with any other
// variable named statuses outside this scope.
var statuses = <?= $jsonOptions ?>;
$(document).ready(function () {
var statusSelect = $("#post_status");
if (statusSelect.length > 0) {
// as long as we have a status <select> in
// the DOM, we'll want to do some work to make
// our custom statuses work.
setDisplayedStatus(statusSelect);
$(".save-post-status").click(setHiddenStatus);
addCustomStatuses(statusSelect);
}
});
function setDisplayedStatus(statusSelect) {
var status = statusSelect.val();
// as long as our status is in our list of custom
// statuses, we want to make sure that the on-
// screen display of the posts's status matches
// the display of the selected option.
if ($.inArray(status, statuses)) {
var display = statusSelect.find("option[value=" + status + "]").text();
$("#post-status-display").text(display);
}
}
function setHiddenStatus() {
var status = $("#post_status").val();
// as long as the status that's selected is a part
// of our list of statuses, we'll want to set the
// the value of the #hidden_post_status field to
// the selected status.
if ($.inArray(status, statuses)) {
$("#hidden_post_status").val(status);
}
}
function addCustomStatuses(statusSelect) {
for(status in statuses) {
if (statuses.hasOwnProperty(status)) {
// for each of our custom statuses, we
// create an <option>. if our status is
// selected, then we set that property.
// otherwise, we set various attributes
// and then append it to our <select>
// element.
var option = $("<option>")
.prop("selected", statuses[status].selected)
.text(statuses[status].display)
.attr("value", status)
.data("custom", true);
statusSelect.append(option);
}
}
// in case we need to do anything else after we've
// changed the DOM, we fire this event, too. then,
// other JS can watch for it and handle any clean
// up or whatever when it's caught.
var event = new jQuery.Event("postStatusesAdded");
statusSelect.trigger(event);
}
})(jQuery);
</script>
<?php echo ob_get_clean();
}
);
} | php | final protected function initPostStatusesTrait(): void {
$postStatuses = $this->getPostStatuses();
// first, we register our statuses. notice that we directly call the
// WordPress add_action() function because we want to use anonymous
// functions here, and there's no good way to add these actions to a
// LoaderInterface object as a result. plus, we want these actions to
// "just happen" without a programmer having to think about them.
$options = [];
foreach ($postStatuses as $postStatus) {
$args = $this->getPostStatusArguments($postStatus);
add_action("init", function () use ($postStatus, $args) {
register_post_status($postStatus, $args);
});
$options[$postStatus] = $args["label"];
}
add_action("post_submitbox_misc_actions",
function (\WP_Post $post) use ($options) {
// registering our post status tells WordPress all about it,
// but WordPress doesn't automatically add them to the <select>
// elements in the DOM. so, we do that here. for more info
// see https://core.trac.wordpress.org/ticket/12706.
$jsonOptions = "{";
$optionFormat = '"%s": { "display": "%s", "selected": %d },';
foreach ($options as $status => $display) {
$selected = (int)$post->post_status === $status;
// for each of our options, we use the above format to
// create a series of JSON strings which we can inject
// into our JavaScript below.
$jsonOptions .= sprintf($optionFormat, $status, $display, $selected);
}
// the loop above adds an extra comma to our JSON string.
// we'll replace that comma with a the closing curly brace
// to end said string.
$jsonOptions = preg_replace("/,$/", "}", $jsonOptions);
ob_start(); ?>
<script id="php7BoilerplateAddPostStatuses">
(function ($) {
// we'll add our statuses into the scope of this
// anonymous functions. that way, it's accessible
// to the other functions, anonymous or otherwise,
// herein. but, it won't conflict with any other
// variable named statuses outside this scope.
var statuses = <?= $jsonOptions ?>;
$(document).ready(function () {
var statusSelect = $("#post_status");
if (statusSelect.length > 0) {
// as long as we have a status <select> in
// the DOM, we'll want to do some work to make
// our custom statuses work.
setDisplayedStatus(statusSelect);
$(".save-post-status").click(setHiddenStatus);
addCustomStatuses(statusSelect);
}
});
function setDisplayedStatus(statusSelect) {
var status = statusSelect.val();
// as long as our status is in our list of custom
// statuses, we want to make sure that the on-
// screen display of the posts's status matches
// the display of the selected option.
if ($.inArray(status, statuses)) {
var display = statusSelect.find("option[value=" + status + "]").text();
$("#post-status-display").text(display);
}
}
function setHiddenStatus() {
var status = $("#post_status").val();
// as long as the status that's selected is a part
// of our list of statuses, we'll want to set the
// the value of the #hidden_post_status field to
// the selected status.
if ($.inArray(status, statuses)) {
$("#hidden_post_status").val(status);
}
}
function addCustomStatuses(statusSelect) {
for(status in statuses) {
if (statuses.hasOwnProperty(status)) {
// for each of our custom statuses, we
// create an <option>. if our status is
// selected, then we set that property.
// otherwise, we set various attributes
// and then append it to our <select>
// element.
var option = $("<option>")
.prop("selected", statuses[status].selected)
.text(statuses[status].display)
.attr("value", status)
.data("custom", true);
statusSelect.append(option);
}
}
// in case we need to do anything else after we've
// changed the DOM, we fire this event, too. then,
// other JS can watch for it and handle any clean
// up or whatever when it's caught.
var event = new jQuery.Event("postStatusesAdded");
statusSelect.trigger(event);
}
})(jQuery);
</script>
<?php echo ob_get_clean();
}
);
} | [
"final",
"protected",
"function",
"initPostStatusesTrait",
"(",
")",
":",
"void",
"{",
"$",
"postStatuses",
"=",
"$",
"this",
"->",
"getPostStatuses",
"(",
")",
";",
"// first, we register our statuses. notice that we directly call the",
"// WordPress add_action() function because we want to use anonymous",
"// functions here, and there's no good way to add these actions to a",
"// LoaderInterface object as a result. plus, we want these actions to",
"// \"just happen\" without a programmer having to think about them.",
"$",
"options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"postStatuses",
"as",
"$",
"postStatus",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"getPostStatusArguments",
"(",
"$",
"postStatus",
")",
";",
"add_action",
"(",
"\"init\"",
",",
"function",
"(",
")",
"use",
"(",
"$",
"postStatus",
",",
"$",
"args",
")",
"{",
"register_post_status",
"(",
"$",
"postStatus",
",",
"$",
"args",
")",
";",
"}",
")",
";",
"$",
"options",
"[",
"$",
"postStatus",
"]",
"=",
"$",
"args",
"[",
"\"label\"",
"]",
";",
"}",
"add_action",
"(",
"\"post_submitbox_misc_actions\"",
",",
"function",
"(",
"\\",
"WP_Post",
"$",
"post",
")",
"use",
"(",
"$",
"options",
")",
"{",
"// registering our post status tells WordPress all about it,",
"// but WordPress doesn't automatically add them to the <select>",
"// elements in the DOM. so, we do that here. for more info",
"// see https://core.trac.wordpress.org/ticket/12706.",
"$",
"jsonOptions",
"=",
"\"{\"",
";",
"$",
"optionFormat",
"=",
"'\"%s\": { \"display\": \"%s\", \"selected\": %d },'",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"status",
"=>",
"$",
"display",
")",
"{",
"$",
"selected",
"=",
"(",
"int",
")",
"$",
"post",
"->",
"post_status",
"===",
"$",
"status",
";",
"// for each of our options, we use the above format to",
"// create a series of JSON strings which we can inject",
"// into our JavaScript below.",
"$",
"jsonOptions",
".=",
"sprintf",
"(",
"$",
"optionFormat",
",",
"$",
"status",
",",
"$",
"display",
",",
"$",
"selected",
")",
";",
"}",
"// the loop above adds an extra comma to our JSON string.",
"// we'll replace that comma with a the closing curly brace",
"// to end said string.",
"$",
"jsonOptions",
"=",
"preg_replace",
"(",
"\"/,$/\"",
",",
"\"}\"",
",",
"$",
"jsonOptions",
")",
";",
"ob_start",
"(",
")",
";",
"?>\n\n <script id=\"php7BoilerplateAddPostStatuses\">\n\t\t\t\t\t(function ($) {\n\n\t\t\t\t\t\t// we'll add our statuses into the scope of this\n\t\t\t\t\t\t// anonymous functions. that way, it's accessible\n\t\t\t\t\t\t// to the other functions, anonymous or otherwise,\n\t\t\t\t\t\t// herein. but, it won't conflict with any other\n\t\t\t\t\t\t// variable named statuses outside this scope.\n\n\t\t\t\t\t\tvar statuses = <?=",
"$",
"jsonOptions",
"?>;\n\n\t\t\t\t\t\t$(document).ready(function () {\n\t\t\t\t\t\t\tvar statusSelect = $(\"#post_status\");\n\t\t\t\t\t\t\tif (statusSelect.length > 0) {\n\n\t\t\t\t\t\t\t\t// as long as we have a status <select> in\n\t\t\t\t\t\t\t\t// the DOM, we'll want to do some work to make\n // our custom statuses work.\n\n\t\t\t\t\t\t\t\tsetDisplayedStatus(statusSelect);\n\t\t\t\t\t\t\t\t$(\".save-post-status\").click(setHiddenStatus);\n\t\t\t\t\t\t\t\taddCustomStatuses(statusSelect);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t\tfunction setDisplayedStatus(statusSelect) {\n\t\t\t\t\t\t\tvar status = statusSelect.val();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t// as long as our status is in our list of custom\n // statuses, we want to make sure that the on-\n // screen display of the posts's status matches\n // the display of the selected option.\n \n if ($.inArray(status, statuses)) {\n var display = statusSelect.find(\"option[value=\" + status + \"]\").text();\n $(\"#post-status-display\").text(display);\n }\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tfunction setHiddenStatus() {\n\t\t\t\t\t\t\tvar status = $(\"#post_status\").val();\n\n\t\t\t\t\t\t\t// as long as the status that's selected is a part\n\t\t\t\t\t\t\t// of our list of statuses, we'll want to set the\n\t\t\t\t\t\t\t// the value of the #hidden_post_status field to\n\t\t\t\t\t\t\t// the selected status.\n\n\t\t\t\t\t\t\tif ($.inArray(status, statuses)) {\n\t\t\t\t\t\t\t\t$(\"#hidden_post_status\").val(status);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tfunction addCustomStatuses(statusSelect) {\n\t\t\t\t\t\t\tfor(status in statuses) {\n\t\t\t\t\t\t\t\tif (statuses.hasOwnProperty(status)) {\n\n\t\t\t\t\t\t\t\t\t// for each of our custom statuses, we\n\t\t\t\t\t\t\t\t\t// create an <option>. if our status is\n\t\t\t\t\t\t\t\t\t// selected, then we set that property.\n\t\t\t\t\t\t\t\t\t// otherwise, we set various attributes\n\t\t\t\t\t\t\t\t\t// and then append it to our <select>\n\t\t\t\t\t\t\t\t\t// element.\n\n\t\t\t\t\t\t\t\t\tvar option = $(\"<option>\")\n\t\t\t\t\t\t\t\t\t\t.prop(\"selected\", statuses[status].selected)\n\t\t\t\t\t\t\t\t\t\t.text(statuses[status].display)\n\t\t\t\t\t\t\t\t\t\t.attr(\"value\", status)\n\t\t\t\t\t\t\t\t\t\t.data(\"custom\", true);\n\n\t\t\t\t\t\t\t\t\tstatusSelect.append(option);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// in case we need to do anything else after we've\n\t\t\t\t\t\t\t// changed the DOM, we fire this event, too. then,\n\t\t\t\t\t\t\t// other JS can watch for it and handle any clean\n\t\t\t\t\t\t\t// up or whatever when it's caught.\n\n\t\t\t\t\t\t\tvar event = new jQuery.Event(\"postStatusesAdded\");\n\t\t\t\t\t\t\tstatusSelect.trigger(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t})(jQuery);\n </script>\n\t\t\t\t\n\t\t\t\t<?php",
"echo",
"ob_get_clean",
"(",
")",
";",
"}",
")",
";",
"}"
]
| When we initialize this trait, we want to register our post statuses
and ensure that they appear in the status drop-downs throughout Word-
Press core.
@return void | [
"When",
"we",
"initialize",
"this",
"trait",
"we",
"want",
"to",
"register",
"our",
"post",
"statuses",
"and",
"ensure",
"that",
"they",
"appear",
"in",
"the",
"status",
"drop",
"-",
"downs",
"throughout",
"Word",
"-",
"Press",
"core",
"."
]
| c7875deb403d311efca72dc3c8beb566972a56cb | https://github.com/dashifen/wordpress-php7-plugin-boilerplate/blob/c7875deb403d311efca72dc3c8beb566972a56cb/src/Controller/ControllerTraits/PostStatusesTrait.php#L38-L171 |
17,896 | ClanCats/Core | src/bundles/Database/Query.php | Query.insert | public static function insert( $table, $values = array(), $handler = null )
{
return Query_Insert::create( $table, $handler )->values( $values );
} | php | public static function insert( $table, $values = array(), $handler = null )
{
return Query_Insert::create( $table, $handler )->values( $values );
} | [
"public",
"static",
"function",
"insert",
"(",
"$",
"table",
",",
"$",
"values",
"=",
"array",
"(",
")",
",",
"$",
"handler",
"=",
"null",
")",
"{",
"return",
"Query_Insert",
"::",
"create",
"(",
"$",
"table",
",",
"$",
"handler",
")",
"->",
"values",
"(",
"$",
"values",
")",
";",
"}"
]
| Create an insert
@param string $table
@param array $values
@param string $handler
@return DB\Query | [
"Create",
"an",
"insert"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query.php#L50-L53 |
17,897 | ClanCats/Core | src/bundles/Database/Query.php | Query.or_where | public function or_where( $column, $param1 = null, $param2 = null )
{
return $this->where( $column, $param1, $param2, 'or' );
} | php | public function or_where( $column, $param1 = null, $param2 = null )
{
return $this->where( $column, $param1, $param2, 'or' );
} | [
"public",
"function",
"or_where",
"(",
"$",
"column",
",",
"$",
"param1",
"=",
"null",
",",
"$",
"param2",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"where",
"(",
"$",
"column",
",",
"$",
"param1",
",",
"$",
"param2",
",",
"'or'",
")",
";",
"}"
]
| Create an or where statement
This is the same as the normal where just with a fixed type
@param string $column The SQL column
@param mixed $param1
@param mixed $param2
@return self | [
"Create",
"an",
"or",
"where",
"statement"
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query.php#L237-L240 |
17,898 | aedart/laravel-helpers | src/Traits/Logging/LogManagerTrait.php | LogManagerTrait.getLogManager | public function getLogManager(): ?LogManager
{
if (!$this->hasLogManager()) {
$this->setLogManager($this->getDefaultLogManager());
}
return $this->logManager;
} | php | public function getLogManager(): ?LogManager
{
if (!$this->hasLogManager()) {
$this->setLogManager($this->getDefaultLogManager());
}
return $this->logManager;
} | [
"public",
"function",
"getLogManager",
"(",
")",
":",
"?",
"LogManager",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLogManager",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setLogManager",
"(",
"$",
"this",
"->",
"getDefaultLogManager",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"logManager",
";",
"}"
]
| Get log manager
If no log manager has been set, this method will
set and return a default log manager, if any such
value is available
@see getDefaultLogManager()
@return LogManager|null log manager or null if none log manager has been set | [
"Get",
"log",
"manager"
]
| 8b81a2d6658f3f8cb62b6be2c34773aaa2df219a | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Logging/LogManagerTrait.php#L52-L58 |
17,899 | ClanCats/Core | src/classes/CCFinder.php | CCFinder.bundle | public static function bundle( $name, $path = null )
{
static::$bundles[$name] = $path;
static::$namespaces[$name] = $path.CCDIR_CLASS;
} | php | public static function bundle( $name, $path = null )
{
static::$bundles[$name] = $path;
static::$namespaces[$name] = $path.CCDIR_CLASS;
} | [
"public",
"static",
"function",
"bundle",
"(",
"$",
"name",
",",
"$",
"path",
"=",
"null",
")",
"{",
"static",
"::",
"$",
"bundles",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
";",
"static",
"::",
"$",
"namespaces",
"[",
"$",
"name",
"]",
"=",
"$",
"path",
".",
"CCDIR_CLASS",
";",
"}"
]
| Add a bundle
A bundle is a CCF style package with classes, controllers, views etc.
@param string|array $name
@param path $path
@return void | [
"Add",
"a",
"bundle",
"A",
"bundle",
"is",
"a",
"CCF",
"style",
"package",
"with",
"classes",
"controllers",
"views",
"etc",
"."
]
| 9f6ec72c1a439de4b253d0223f1029f7f85b6ef8 | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFinder.php#L68-L72 |
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.