repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
josegonzalez/cakephp-sanction | View/Helper/ClearanceHelper.php | ClearanceHelper.parse | public function parse($currentRoute, $permit) {
$route = $permit['route'];
$count = count($route);
if ($count == 0) {
return false;
}
foreach ($route as $key => $value) {
if (isset($currentRoute[$key])) {
$values = (is_array($value)) ? $value : array($value);
foreach ($values as $k => $v) {
if ($currentRoute[$key] == $v) {
$count--;
}
}
}
}
return $count == 0;
} | php | public function parse($currentRoute, $permit) {
$route = $permit['route'];
$count = count($route);
if ($count == 0) {
return false;
}
foreach ($route as $key => $value) {
if (isset($currentRoute[$key])) {
$values = (is_array($value)) ? $value : array($value);
foreach ($values as $k => $v) {
if ($currentRoute[$key] == $v) {
$count--;
}
}
}
}
return $count == 0;
} | [
"public",
"function",
"parse",
"(",
"$",
"currentRoute",
",",
"$",
"permit",
")",
"{",
"$",
"route",
"=",
"$",
"permit",
"[",
"'route'",
"]",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"route",
")",
";",
"if",
"(",
"$",
"count",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"route",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"currentRoute",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"values",
"=",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"?",
"$",
"value",
":",
"array",
"(",
"$",
"value",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"currentRoute",
"[",
"$",
"key",
"]",
"==",
"$",
"v",
")",
"{",
"$",
"count",
"--",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"count",
"==",
"0",
";",
"}"
] | Parses the passed route against a rule
@param string $currentRoute route being testing
@param string $permit Permit variable that contains a route being tested against
@return void
@author Jose Diaz-Gonzalez | [
"Parses",
"the",
"passed",
"route",
"against",
"a",
"rule"
] | train | https://github.com/josegonzalez/cakephp-sanction/blob/df2a8f0c0602c0ace802773db2c2ca6c89555c47/View/Helper/ClearanceHelper.php#L128-L147 |
josegonzalez/cakephp-sanction | View/Helper/ClearanceHelper.php | ClearanceHelper.execute | public function execute($route, $title, $url = null, $options = array(), $confirmMessage = false) {
if (empty($route['rules'])) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
if (isset($route['rules']['deny'])) {
return ($route['rules']['deny'] == true) ? null : $this->Html->link($title, $url, $options, $confirmMessage);
}
if (!isset($route['rules']['auth'])) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
if (is_bool($route['rules']['auth'])) {
$isAuthed = $this->Session->read("{$this->settings['path']}.{$this->settings['check']}");
if ($route['rules']['auth'] == true && !$isAuthed) {
return;
}
if ($route['rules']['auth'] == false && $isAuthed) {
return;
}
return $this->Html->link($title, $url, $options, $confirmMessage);
}
$count = count($route['rules']['auth']);
if ($count == 0) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
if (($user = $this->Session->read("{$this->settings['path']}")) == false) {
return;
}
foreach ($route['rules']['auth'] as $field => $value) {
if (strpos($field, '.') !== false) {
$field = '/' . str_replace('.', '/', $field);
}
if ($field[0] == "/") {
$values = (array)Set::extract($field, $user);
foreach ($value as $condition) {
if (in_array($condition, $values)) {
$count--;
}
}
} else {
if ($user[$field] == $value) {
$count--;
}
}
}
return ($count != 0) ? null : $this->Html->link($title, $url, $options, $confirmMessage);
} | php | public function execute($route, $title, $url = null, $options = array(), $confirmMessage = false) {
if (empty($route['rules'])) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
if (isset($route['rules']['deny'])) {
return ($route['rules']['deny'] == true) ? null : $this->Html->link($title, $url, $options, $confirmMessage);
}
if (!isset($route['rules']['auth'])) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
if (is_bool($route['rules']['auth'])) {
$isAuthed = $this->Session->read("{$this->settings['path']}.{$this->settings['check']}");
if ($route['rules']['auth'] == true && !$isAuthed) {
return;
}
if ($route['rules']['auth'] == false && $isAuthed) {
return;
}
return $this->Html->link($title, $url, $options, $confirmMessage);
}
$count = count($route['rules']['auth']);
if ($count == 0) {
return $this->Html->link($title, $url, $options, $confirmMessage);
}
if (($user = $this->Session->read("{$this->settings['path']}")) == false) {
return;
}
foreach ($route['rules']['auth'] as $field => $value) {
if (strpos($field, '.') !== false) {
$field = '/' . str_replace('.', '/', $field);
}
if ($field[0] == "/") {
$values = (array)Set::extract($field, $user);
foreach ($value as $condition) {
if (in_array($condition, $values)) {
$count--;
}
}
} else {
if ($user[$field] == $value) {
$count--;
}
}
}
return ($count != 0) ? null : $this->Html->link($title, $url, $options, $confirmMessage);
} | [
"public",
"function",
"execute",
"(",
"$",
"route",
",",
"$",
"title",
",",
"$",
"url",
"=",
"null",
",",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"confirmMessage",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"route",
"[",
"'rules'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"route",
"[",
"'rules'",
"]",
"[",
"'deny'",
"]",
")",
")",
"{",
"return",
"(",
"$",
"route",
"[",
"'rules'",
"]",
"[",
"'deny'",
"]",
"==",
"true",
")",
"?",
"null",
":",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"route",
"[",
"'rules'",
"]",
"[",
"'auth'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"route",
"[",
"'rules'",
"]",
"[",
"'auth'",
"]",
")",
")",
"{",
"$",
"isAuthed",
"=",
"$",
"this",
"->",
"Session",
"->",
"read",
"(",
"\"{$this->settings['path']}.{$this->settings['check']}\"",
")",
";",
"if",
"(",
"$",
"route",
"[",
"'rules'",
"]",
"[",
"'auth'",
"]",
"==",
"true",
"&&",
"!",
"$",
"isAuthed",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"route",
"[",
"'rules'",
"]",
"[",
"'auth'",
"]",
"==",
"false",
"&&",
"$",
"isAuthed",
")",
"{",
"return",
";",
"}",
"return",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}",
"$",
"count",
"=",
"count",
"(",
"$",
"route",
"[",
"'rules'",
"]",
"[",
"'auth'",
"]",
")",
";",
"if",
"(",
"$",
"count",
"==",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}",
"if",
"(",
"(",
"$",
"user",
"=",
"$",
"this",
"->",
"Session",
"->",
"read",
"(",
"\"{$this->settings['path']}\"",
")",
")",
"==",
"false",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"route",
"[",
"'rules'",
"]",
"[",
"'auth'",
"]",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"field",
"=",
"'/'",
".",
"str_replace",
"(",
"'.'",
",",
"'/'",
",",
"$",
"field",
")",
";",
"}",
"if",
"(",
"$",
"field",
"[",
"0",
"]",
"==",
"\"/\"",
")",
"{",
"$",
"values",
"=",
"(",
"array",
")",
"Set",
"::",
"extract",
"(",
"$",
"field",
",",
"$",
"user",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"condition",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"condition",
",",
"$",
"values",
")",
")",
"{",
"$",
"count",
"--",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"user",
"[",
"$",
"field",
"]",
"==",
"$",
"value",
")",
"{",
"$",
"count",
"--",
";",
"}",
"}",
"}",
"return",
"(",
"$",
"count",
"!=",
"0",
")",
"?",
"null",
":",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
",",
"$",
"confirmMessage",
")",
";",
"}"
] | Executes the route based on it's rules
@param string $route route being executed
@param string $title The content to be wrapped by <a> tags.
@param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
@param array $options Array of HTML attributes.
@param string $confirmMessage JavaScript confirmation message.
@return string An `<a />` element.
@author Jose Diaz-Gonzalez | [
"Executes",
"the",
"route",
"based",
"on",
"it",
"s",
"rules"
] | train | https://github.com/josegonzalez/cakephp-sanction/blob/df2a8f0c0602c0ace802773db2c2ca6c89555c47/View/Helper/ClearanceHelper.php#L160-L214 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.store | public function store( $id, $data, $attributes = array() )
{
$metaStorage = $this->getMetaDataStorage();
$metaStorage->lock();
$metaData = $this->getMetaData( $metaStorage );
foreach( $this->storageStack as $storageConf )
{
call_user_func(
array(
$this->properties['options']->replacementStrategy,
'store'
),
$storageConf,
$metaData,
$id,
$data,
$attributes
);
}
$metaStorage->storeMetaData( $metaData );
$metaStorage->unlock();
} | php | public function store( $id, $data, $attributes = array() )
{
$metaStorage = $this->getMetaDataStorage();
$metaStorage->lock();
$metaData = $this->getMetaData( $metaStorage );
foreach( $this->storageStack as $storageConf )
{
call_user_func(
array(
$this->properties['options']->replacementStrategy,
'store'
),
$storageConf,
$metaData,
$id,
$data,
$attributes
);
}
$metaStorage->storeMetaData( $metaData );
$metaStorage->unlock();
} | [
"public",
"function",
"store",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"$",
"metaStorage",
"=",
"$",
"this",
"->",
"getMetaDataStorage",
"(",
")",
";",
"$",
"metaStorage",
"->",
"lock",
"(",
")",
";",
"$",
"metaData",
"=",
"$",
"this",
"->",
"getMetaData",
"(",
"$",
"metaStorage",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"storageStack",
"as",
"$",
"storageConf",
")",
"{",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
"->",
"properties",
"[",
"'options'",
"]",
"->",
"replacementStrategy",
",",
"'store'",
")",
",",
"$",
"storageConf",
",",
"$",
"metaData",
",",
"$",
"id",
",",
"$",
"data",
",",
"$",
"attributes",
")",
";",
"}",
"$",
"metaStorage",
"->",
"storeMetaData",
"(",
"$",
"metaData",
")",
";",
"$",
"metaStorage",
"->",
"unlock",
"(",
")",
";",
"}"
] | Stores data in the cache stack.
This method will store the given data across the complete stack. It can
afterwards be restored using the {@link ezcCacheStack::restore()} method
and be deleted through the {@link ezcCacheStack::delete()} method.
The data that can be stored in the cache depends on the configured
storages. Usually it is save to store arrays and scalars. However, some
caches support objects or do not even support arrays. You need to make
sure that the inner caches of the stack *all* support the data you want
to store!
The $attributes array is optional and can be used to describe the stack
further.
@param string $id
@param mixed $data
@param array $attributes | [
"Stores",
"data",
"in",
"the",
"cache",
"stack",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L207-L231 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.getMetaData | private function getMetaData( ezcCacheStackMetaDataStorage $metaStorage )
{
$metaData = $metaStorage->restoreMetaData();
if ( $metaData === null )
{
$metaData = call_user_func(
array(
$this->properties['options']->replacementStrategy,
'createMetaData'
)
);
}
return $metaData;
} | php | private function getMetaData( ezcCacheStackMetaDataStorage $metaStorage )
{
$metaData = $metaStorage->restoreMetaData();
if ( $metaData === null )
{
$metaData = call_user_func(
array(
$this->properties['options']->replacementStrategy,
'createMetaData'
)
);
}
return $metaData;
} | [
"private",
"function",
"getMetaData",
"(",
"ezcCacheStackMetaDataStorage",
"$",
"metaStorage",
")",
"{",
"$",
"metaData",
"=",
"$",
"metaStorage",
"->",
"restoreMetaData",
"(",
")",
";",
"if",
"(",
"$",
"metaData",
"===",
"null",
")",
"{",
"$",
"metaData",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
"->",
"properties",
"[",
"'options'",
"]",
"->",
"replacementStrategy",
",",
"'createMetaData'",
")",
")",
";",
"}",
"return",
"$",
"metaData",
";",
"}"
] | Returns the meta data to use.
Returns the meta data to use with the configured {@link
ezcCacheStackStackReplacementStrategy}.
@param ezcCacheStackMetaDataStorage $metaStorage
@return ezcCacheMetaData | [
"Returns",
"the",
"meta",
"data",
"to",
"use",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L242-L257 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.restore | public function restore( $id, $attributes = array(), $search = false )
{
$metaStorage = $this->getMetaDataStorage();
$metaStorage->lock();
$metaData = $this->getMetaData( $metaStorage );
$item = false;
foreach ( $this->storageStack as $storageConf )
{
$item = call_user_func(
array(
$this->properties['options']->replacementStrategy,
'restore'
),
$storageConf,
$metaData,
$id,
$attributes,
$search
);
if ( $item !== false )
{
if ( $this->properties['options']->bubbleUpOnRestore )
{
$this->bubbleUp( $id, $attributes, $item, $storageConf, $metaData );
}
// Found, so end.
break;
}
}
$metaStorage->storeMetaData( $metaData );
$metaStorage->unlock();
return $item;
} | php | public function restore( $id, $attributes = array(), $search = false )
{
$metaStorage = $this->getMetaDataStorage();
$metaStorage->lock();
$metaData = $this->getMetaData( $metaStorage );
$item = false;
foreach ( $this->storageStack as $storageConf )
{
$item = call_user_func(
array(
$this->properties['options']->replacementStrategy,
'restore'
),
$storageConf,
$metaData,
$id,
$attributes,
$search
);
if ( $item !== false )
{
if ( $this->properties['options']->bubbleUpOnRestore )
{
$this->bubbleUp( $id, $attributes, $item, $storageConf, $metaData );
}
// Found, so end.
break;
}
}
$metaStorage->storeMetaData( $metaData );
$metaStorage->unlock();
return $item;
} | [
"public",
"function",
"restore",
"(",
"$",
"id",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"search",
"=",
"false",
")",
"{",
"$",
"metaStorage",
"=",
"$",
"this",
"->",
"getMetaDataStorage",
"(",
")",
";",
"$",
"metaStorage",
"->",
"lock",
"(",
")",
";",
"$",
"metaData",
"=",
"$",
"this",
"->",
"getMetaData",
"(",
"$",
"metaStorage",
")",
";",
"$",
"item",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"storageStack",
"as",
"$",
"storageConf",
")",
"{",
"$",
"item",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
"->",
"properties",
"[",
"'options'",
"]",
"->",
"replacementStrategy",
",",
"'restore'",
")",
",",
"$",
"storageConf",
",",
"$",
"metaData",
",",
"$",
"id",
",",
"$",
"attributes",
",",
"$",
"search",
")",
";",
"if",
"(",
"$",
"item",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"properties",
"[",
"'options'",
"]",
"->",
"bubbleUpOnRestore",
")",
"{",
"$",
"this",
"->",
"bubbleUp",
"(",
"$",
"id",
",",
"$",
"attributes",
",",
"$",
"item",
",",
"$",
"storageConf",
",",
"$",
"metaData",
")",
";",
"}",
"// Found, so end.",
"break",
";",
"}",
"}",
"$",
"metaStorage",
"->",
"storeMetaData",
"(",
"$",
"metaData",
")",
";",
"$",
"metaStorage",
"->",
"unlock",
"(",
")",
";",
"return",
"$",
"item",
";",
"}"
] | Restores an item from the stack.
This method tries to restore an item from the cache stack and returns
the found data, if any. If no data is found, boolean false is returned.
Given the ID of an object will restore exactly the desired object. If
additional $attributes are given, this may speed up the restore process
for some caches. If only attributes are given, the $search parameter
makes sense, since it will instruct the inner cach storages to search
their content for the given attribute combination and will restore the
first item found. However, this process is much slower then restoring
with an ID and therefore is not recommended.
@param string $id
@param array $attributes
@param bool $search
@return mixed The restored data or false on failure. | [
"Restores",
"an",
"item",
"from",
"the",
"stack",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L277-L313 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.bubbleUp | private function bubbleUp( $id, array $attributes, $item, ezcCacheStackStorageConfiguration $foundStorageConf, ezcCacheStackMetaData $metaData )
{
foreach( $this->storageStack as $storageConf )
{
if ( $storageConf === $foundStorageConf )
{
// This was the storage where we restored
break;
}
call_user_func(
array(
$this->properties['options']->replacementStrategy,
'store'
),
$storageConf,
$metaData,
$id,
$item,
$attributes
);
}
} | php | private function bubbleUp( $id, array $attributes, $item, ezcCacheStackStorageConfiguration $foundStorageConf, ezcCacheStackMetaData $metaData )
{
foreach( $this->storageStack as $storageConf )
{
if ( $storageConf === $foundStorageConf )
{
// This was the storage where we restored
break;
}
call_user_func(
array(
$this->properties['options']->replacementStrategy,
'store'
),
$storageConf,
$metaData,
$id,
$item,
$attributes
);
}
} | [
"private",
"function",
"bubbleUp",
"(",
"$",
"id",
",",
"array",
"$",
"attributes",
",",
"$",
"item",
",",
"ezcCacheStackStorageConfiguration",
"$",
"foundStorageConf",
",",
"ezcCacheStackMetaData",
"$",
"metaData",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"storageStack",
"as",
"$",
"storageConf",
")",
"{",
"if",
"(",
"$",
"storageConf",
"===",
"$",
"foundStorageConf",
")",
"{",
"// This was the storage where we restored",
"break",
";",
"}",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
"->",
"properties",
"[",
"'options'",
"]",
"->",
"replacementStrategy",
",",
"'store'",
")",
",",
"$",
"storageConf",
",",
"$",
"metaData",
",",
"$",
"id",
",",
"$",
"item",
",",
"$",
"attributes",
")",
";",
"}",
"}"
] | Bubbles a restored $item up to all storages above $foundStorageConf.
@param string $id
@param array $attributes
@param mixed $item
@param ezcCacheStackStorageConfiguration $foundStorageConf
@param ezcCacheStackMetaData $metaData | [
"Bubbles",
"a",
"restored",
"$item",
"up",
"to",
"all",
"storages",
"above",
"$foundStorageConf",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L324-L345 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.delete | public function delete( $id = null, $attributes = array(), $search = false )
{
$metaStorage = $this->getMetaDataStorage();
$metaStorage->lock();
$metaData = $metaStorage->restoreMetaData();
$deletedIds = array();
foreach ( $this->storageStack as $storageConf )
{
$deletedIds = array_merge(
$deletedIds,
call_user_func(
array(
$this->properties['options']->replacementStrategy,
'delete'
),
$storageConf,
$metaData,
$id,
$attributes,
$search
)
);
}
$metaStorage->storeMetaData( $metaData );
$metaStorage->unlock();
return array_unique( $deletedIds );
} | php | public function delete( $id = null, $attributes = array(), $search = false )
{
$metaStorage = $this->getMetaDataStorage();
$metaStorage->lock();
$metaData = $metaStorage->restoreMetaData();
$deletedIds = array();
foreach ( $this->storageStack as $storageConf )
{
$deletedIds = array_merge(
$deletedIds,
call_user_func(
array(
$this->properties['options']->replacementStrategy,
'delete'
),
$storageConf,
$metaData,
$id,
$attributes,
$search
)
);
}
$metaStorage->storeMetaData( $metaData );
$metaStorage->unlock();
return array_unique( $deletedIds );
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"search",
"=",
"false",
")",
"{",
"$",
"metaStorage",
"=",
"$",
"this",
"->",
"getMetaDataStorage",
"(",
")",
";",
"$",
"metaStorage",
"->",
"lock",
"(",
")",
";",
"$",
"metaData",
"=",
"$",
"metaStorage",
"->",
"restoreMetaData",
"(",
")",
";",
"$",
"deletedIds",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"storageStack",
"as",
"$",
"storageConf",
")",
"{",
"$",
"deletedIds",
"=",
"array_merge",
"(",
"$",
"deletedIds",
",",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
"->",
"properties",
"[",
"'options'",
"]",
"->",
"replacementStrategy",
",",
"'delete'",
")",
",",
"$",
"storageConf",
",",
"$",
"metaData",
",",
"$",
"id",
",",
"$",
"attributes",
",",
"$",
"search",
")",
")",
";",
"}",
"$",
"metaStorage",
"->",
"storeMetaData",
"(",
"$",
"metaData",
")",
";",
"$",
"metaStorage",
"->",
"unlock",
"(",
")",
";",
"return",
"array_unique",
"(",
"$",
"deletedIds",
")",
";",
"}"
] | Deletes an item from the stack.
This method deletes an item from the cache stack. The item will
afterwards no more be stored in any of the inner cache storages. Giving
the ID of the cache item will delete exactly 1 desired item. Giving an
attribute array, describing the desired item in more detail, can speed
up the deletion in some caches.
Giving null as the ID and just an attribibute array, with the $search
attribute in addition, will delete *all* items that comply to the
attributes from all storages. This might be much slower than just
deleting a single item.
Deleting items from a cache stack is not recommended at all. Instead,
items should expire on their own or be overwritten with more actual
data.
The method returns an array containing all deleted item IDs.
@param string $id
@param array $attributes
@param bool $search
@return array(string) | [
"Deletes",
"an",
"item",
"from",
"the",
"stack",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L372-L402 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.getMetaDataStorage | private function getMetaDataStorage()
{
$metaStorage = $this->options->metaStorage;
if ( $metaStorage === null )
{
$metaStorage = reset( $this->storageStack )->storage;
if ( !( $metaStorage instanceof ezcCacheStackMetaDataStorage ) )
{
throw new ezcBaseValueException(
'metaStorage',
$metaStorage,
'ezcCacheStackMetaDataStorage',
'top of storage stack'
);
}
}
return $metaStorage;
} | php | private function getMetaDataStorage()
{
$metaStorage = $this->options->metaStorage;
if ( $metaStorage === null )
{
$metaStorage = reset( $this->storageStack )->storage;
if ( !( $metaStorage instanceof ezcCacheStackMetaDataStorage ) )
{
throw new ezcBaseValueException(
'metaStorage',
$metaStorage,
'ezcCacheStackMetaDataStorage',
'top of storage stack'
);
}
}
return $metaStorage;
} | [
"private",
"function",
"getMetaDataStorage",
"(",
")",
"{",
"$",
"metaStorage",
"=",
"$",
"this",
"->",
"options",
"->",
"metaStorage",
";",
"if",
"(",
"$",
"metaStorage",
"===",
"null",
")",
"{",
"$",
"metaStorage",
"=",
"reset",
"(",
"$",
"this",
"->",
"storageStack",
")",
"->",
"storage",
";",
"if",
"(",
"!",
"(",
"$",
"metaStorage",
"instanceof",
"ezcCacheStackMetaDataStorage",
")",
")",
"{",
"throw",
"new",
"ezcBaseValueException",
"(",
"'metaStorage'",
",",
"$",
"metaStorage",
",",
"'ezcCacheStackMetaDataStorage'",
",",
"'top of storage stack'",
")",
";",
"}",
"}",
"return",
"$",
"metaStorage",
";",
"}"
] | Returns the meta data storage to be used.
Determines the meta data storage to be used by the stack and returns it.
@return ezcCacheStackMetaData | [
"Returns",
"the",
"meta",
"data",
"storage",
"to",
"be",
"used",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L411-L428 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.countDataItems | public function countDataItems( $id = null, $attributes = array() )
{
$sum = 0;
foreach( $this->storageStack as $storageConf )
{
$sum += $storageConf->storage->countDataItems( $id, $attributes );
}
return $sum;
} | php | public function countDataItems( $id = null, $attributes = array() )
{
$sum = 0;
foreach( $this->storageStack as $storageConf )
{
$sum += $storageConf->storage->countDataItems( $id, $attributes );
}
return $sum;
} | [
"public",
"function",
"countDataItems",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"$",
"sum",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"storageStack",
"as",
"$",
"storageConf",
")",
"{",
"$",
"sum",
"+=",
"$",
"storageConf",
"->",
"storage",
"->",
"countDataItems",
"(",
"$",
"id",
",",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"sum",
";",
"}"
] | Counts how many items are stored, fulfilling certain criteria.
This method counts how many data items fulfilling the given criteria are
stored overall. Note: The items of all contained storages are counted
independantly and summarized.
@param string $id
@param array $attributes
@return int | [
"Counts",
"how",
"many",
"items",
"are",
"stored",
"fulfilling",
"certain",
"criteria",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L441-L449 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.getRemainingLifetime | public function getRemainingLifetime( $id, $attributes = array() )
{
foreach ( $this->storageStack as $storageConf )
{
$lifetime = $storageConf->storage->getRemainingLifetime(
$id,
$attributes
);
if ( $lifetime > 0 )
{
return $lifetime;
}
}
return 0;
} | php | public function getRemainingLifetime( $id, $attributes = array() )
{
foreach ( $this->storageStack as $storageConf )
{
$lifetime = $storageConf->storage->getRemainingLifetime(
$id,
$attributes
);
if ( $lifetime > 0 )
{
return $lifetime;
}
}
return 0;
} | [
"public",
"function",
"getRemainingLifetime",
"(",
"$",
"id",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"storageStack",
"as",
"$",
"storageConf",
")",
"{",
"$",
"lifetime",
"=",
"$",
"storageConf",
"->",
"storage",
"->",
"getRemainingLifetime",
"(",
"$",
"id",
",",
"$",
"attributes",
")",
";",
"if",
"(",
"$",
"lifetime",
">",
"0",
")",
"{",
"return",
"$",
"lifetime",
";",
"}",
"}",
"return",
"0",
";",
"}"
] | Returns the remaining lifetime for the given item ID.
This method returns the lifetime in seconds for the item identified by $item
and optionally described by $attributes. Definining the $attributes
might lead to faster results with some caches.
The first internal storage that is found for the data item is chosen to
detemine the lifetime. If no storage contains the item or the item is
outdated in all found caches, 0 is returned.
@param string $id
@param array $attributes
@return int | [
"Returns",
"the",
"remaining",
"lifetime",
"for",
"the",
"given",
"item",
"ID",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L466-L480 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.pushStorage | public function pushStorage( ezcCacheStackStorageConfiguration $storageConf )
{
if ( isset( $this->storageIdMap[$storageConf->id] ) )
{
throw new ezcCacheStackIdAlreadyUsedException(
$storageConf->id
);
}
if ( in_array( $storageConf->storage, $this->storageIdMap, true ) )
{
throw new ezcCacheStackStorageUsedTwiceException(
$storageConf->storage
);
}
array_unshift( $this->storageStack, $storageConf );
$this->storageIdMap[$storageConf->id] = $storageConf->storage;
} | php | public function pushStorage( ezcCacheStackStorageConfiguration $storageConf )
{
if ( isset( $this->storageIdMap[$storageConf->id] ) )
{
throw new ezcCacheStackIdAlreadyUsedException(
$storageConf->id
);
}
if ( in_array( $storageConf->storage, $this->storageIdMap, true ) )
{
throw new ezcCacheStackStorageUsedTwiceException(
$storageConf->storage
);
}
array_unshift( $this->storageStack, $storageConf );
$this->storageIdMap[$storageConf->id] = $storageConf->storage;
} | [
"public",
"function",
"pushStorage",
"(",
"ezcCacheStackStorageConfiguration",
"$",
"storageConf",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"storageIdMap",
"[",
"$",
"storageConf",
"->",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"ezcCacheStackIdAlreadyUsedException",
"(",
"$",
"storageConf",
"->",
"id",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"storageConf",
"->",
"storage",
",",
"$",
"this",
"->",
"storageIdMap",
",",
"true",
")",
")",
"{",
"throw",
"new",
"ezcCacheStackStorageUsedTwiceException",
"(",
"$",
"storageConf",
"->",
"storage",
")",
";",
"}",
"array_unshift",
"(",
"$",
"this",
"->",
"storageStack",
",",
"$",
"storageConf",
")",
";",
"$",
"this",
"->",
"storageIdMap",
"[",
"$",
"storageConf",
"->",
"id",
"]",
"=",
"$",
"storageConf",
"->",
"storage",
";",
"}"
] | Add a storage to the top of the stack.
This method is used to add a new storage to the top of the cache. The
$storageConf of type {@link ezcCacheStackStorageConfiguration} consists
of the actual {@link ezcCacheStackableStorage} and other information.
Most importantly, the configuration object contains an ID, which must be
unique within the whole storage. The itemLimit setting determines how
many items might be stored in the storage at all. freeRate determines
which fraction of itemLimit will be freed by the {@link
ezcCacheStackStackReplacementStrategy} of the stack, when the storage
runs full.
@param ezcCacheStackStorageConfiguration $storageConf | [
"Add",
"a",
"storage",
"to",
"the",
"top",
"of",
"the",
"stack",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L498-L514 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php | ezcCacheStack.popStorage | public function popStorage()
{
if ( count( $this->storageStack ) === 0 )
{
throw new ezcCacheStackUnderflowException();
}
$storageConf = array_shift( $this->storageStack );
unset( $this->storageIdMap[$storageConf->id] );
return $storageConf;
} | php | public function popStorage()
{
if ( count( $this->storageStack ) === 0 )
{
throw new ezcCacheStackUnderflowException();
}
$storageConf = array_shift( $this->storageStack );
unset( $this->storageIdMap[$storageConf->id] );
return $storageConf;
} | [
"public",
"function",
"popStorage",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"storageStack",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"ezcCacheStackUnderflowException",
"(",
")",
";",
"}",
"$",
"storageConf",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"storageStack",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"storageIdMap",
"[",
"$",
"storageConf",
"->",
"id",
"]",
")",
";",
"return",
"$",
"storageConf",
";",
"}"
] | Removes a storage from the top of the stack.
This method can be used to remove the top most {@link
ezcCacheStackableStorage} from the stack. This is commonly done to
remove caches or to insert new ones into lower positions. In both cases,
it is recommended to {@link ezcCacheStack::reset()} the whole cache
afterwards to avoid any kind of inconsistency.
@return ezcCacheStackStorageConfiguration
@throws ezcCacheStackUnderflowException
if called on an empty stack. | [
"Removes",
"a",
"storage",
"from",
"the",
"top",
"of",
"the",
"stack",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/stack.php#L530-L539 |
oroinc/OroLayoutComponent | Extension/Theme/ResourceProvider/ThemeResourceProvider.php | ThemeResourceProvider.getResources | public function getResources()
{
if (!$this->resources) {
if ($this->cache instanceof Cache && $this->cache->contains(self::CACHE_KEY)) {
$this->resources = $this->cache->fetch(self::CACHE_KEY);
} else {
$this->loadResources();
}
}
return $this->resources;
} | php | public function getResources()
{
if (!$this->resources) {
if ($this->cache instanceof Cache && $this->cache->contains(self::CACHE_KEY)) {
$this->resources = $this->cache->fetch(self::CACHE_KEY);
} else {
$this->loadResources();
}
}
return $this->resources;
} | [
"public",
"function",
"getResources",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"resources",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cache",
"instanceof",
"Cache",
"&&",
"$",
"this",
"->",
"cache",
"->",
"contains",
"(",
"self",
"::",
"CACHE_KEY",
")",
")",
"{",
"$",
"this",
"->",
"resources",
"=",
"$",
"this",
"->",
"cache",
"->",
"fetch",
"(",
"self",
"::",
"CACHE_KEY",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"loadResources",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"resources",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/ResourceProvider/ThemeResourceProvider.php#L62-L73 |
oroinc/OroLayoutComponent | Extension/Theme/ResourceProvider/ThemeResourceProvider.php | ThemeResourceProvider.loadResources | public function loadResources(ContainerBuilder $container = null, array $resources = [])
{
$resources = array_merge($resources, $this->getConfigLoader()->load($container));
foreach ($resources as $resource) {
/**
* $resource->data contains data in following format
* [
* 'directory-where-updates-found' => [
* 'found update absolute filename',
* ...
* ]
* ]
*/
$resourceThemeLayoutUpdates = $this->filterThemeLayoutUpdates($this->excludedPaths, $resource->data);
$resourceThemeLayoutUpdates = $this->sortThemeLayoutUpdates($resourceThemeLayoutUpdates);
$this->resources = array_merge_recursive($this->resources, $resourceThemeLayoutUpdates);
}
if ($this->cache instanceof Cache) {
$this->cache->save(self::CACHE_KEY, $this->resources);
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$this->cache->save(self::CACHE_LAST_MODIFICATION_DATE, $now);
$this->blockViewCache->reset();
}
} | php | public function loadResources(ContainerBuilder $container = null, array $resources = [])
{
$resources = array_merge($resources, $this->getConfigLoader()->load($container));
foreach ($resources as $resource) {
/**
* $resource->data contains data in following format
* [
* 'directory-where-updates-found' => [
* 'found update absolute filename',
* ...
* ]
* ]
*/
$resourceThemeLayoutUpdates = $this->filterThemeLayoutUpdates($this->excludedPaths, $resource->data);
$resourceThemeLayoutUpdates = $this->sortThemeLayoutUpdates($resourceThemeLayoutUpdates);
$this->resources = array_merge_recursive($this->resources, $resourceThemeLayoutUpdates);
}
if ($this->cache instanceof Cache) {
$this->cache->save(self::CACHE_KEY, $this->resources);
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$this->cache->save(self::CACHE_LAST_MODIFICATION_DATE, $now);
$this->blockViewCache->reset();
}
} | [
"public",
"function",
"loadResources",
"(",
"ContainerBuilder",
"$",
"container",
"=",
"null",
",",
"array",
"$",
"resources",
"=",
"[",
"]",
")",
"{",
"$",
"resources",
"=",
"array_merge",
"(",
"$",
"resources",
",",
"$",
"this",
"->",
"getConfigLoader",
"(",
")",
"->",
"load",
"(",
"$",
"container",
")",
")",
";",
"foreach",
"(",
"$",
"resources",
"as",
"$",
"resource",
")",
"{",
"/**\n * $resource->data contains data in following format\n * [\n * 'directory-where-updates-found' => [\n * 'found update absolute filename',\n * ...\n * ]\n * ]\n */",
"$",
"resourceThemeLayoutUpdates",
"=",
"$",
"this",
"->",
"filterThemeLayoutUpdates",
"(",
"$",
"this",
"->",
"excludedPaths",
",",
"$",
"resource",
"->",
"data",
")",
";",
"$",
"resourceThemeLayoutUpdates",
"=",
"$",
"this",
"->",
"sortThemeLayoutUpdates",
"(",
"$",
"resourceThemeLayoutUpdates",
")",
";",
"$",
"this",
"->",
"resources",
"=",
"array_merge_recursive",
"(",
"$",
"this",
"->",
"resources",
",",
"$",
"resourceThemeLayoutUpdates",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"cache",
"instanceof",
"Cache",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"self",
"::",
"CACHE_KEY",
",",
"$",
"this",
"->",
"resources",
")",
";",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
"'now'",
",",
"new",
"\\",
"DateTimeZone",
"(",
"'UTC'",
")",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"self",
"::",
"CACHE_LAST_MODIFICATION_DATE",
",",
"$",
"now",
")",
";",
"$",
"this",
"->",
"blockViewCache",
"->",
"reset",
"(",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/ResourceProvider/ThemeResourceProvider.php#L78-L105 |
oroinc/OroLayoutComponent | Extension/Theme/ResourceProvider/ThemeResourceProvider.php | ThemeResourceProvider.findApplicableResources | public function findApplicableResources(array $paths)
{
$result = [];
foreach ($paths as $path) {
$pathArray = explode(DIRECTORY_SEPARATOR, $path);
$value = $this->getResources();
for ($i = 0, $length = count($pathArray); $i < $length; ++$i) {
$value = $this->readValue($value, $pathArray[$i]);
if (null === $value) {
break;
}
}
if ($value && is_array($value)) {
$result = array_merge($result, array_filter($value, 'is_string'));
}
}
return $result;
} | php | public function findApplicableResources(array $paths)
{
$result = [];
foreach ($paths as $path) {
$pathArray = explode(DIRECTORY_SEPARATOR, $path);
$value = $this->getResources();
for ($i = 0, $length = count($pathArray); $i < $length; ++$i) {
$value = $this->readValue($value, $pathArray[$i]);
if (null === $value) {
break;
}
}
if ($value && is_array($value)) {
$result = array_merge($result, array_filter($value, 'is_string'));
}
}
return $result;
} | [
"public",
"function",
"findApplicableResources",
"(",
"array",
"$",
"paths",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"$",
"pathArray",
"=",
"explode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"path",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getResources",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"length",
"=",
"count",
"(",
"$",
"pathArray",
")",
";",
"$",
"i",
"<",
"$",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"readValue",
"(",
"$",
"value",
",",
"$",
"pathArray",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"value",
"&&",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"array_filter",
"(",
"$",
"value",
",",
"'is_string'",
")",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/ResourceProvider/ThemeResourceProvider.php#L110-L132 |
oroinc/OroLayoutComponent | Extension/Theme/ResourceProvider/ThemeResourceProvider.php | ThemeResourceProvider.filterThemeLayoutUpdates | private function filterThemeLayoutUpdates(array $existThemePaths, array $themes)
{
foreach ($themes as $theme => $themePaths) {
foreach ($themePaths as $pathIndex => $path) {
if (is_string($path) && isset($existThemePaths[$path])) {
unset($themePaths[$pathIndex]);
}
}
if (empty($themePaths)) {
unset($themes[$theme]);
} else {
$themes[$theme] = $themePaths;
}
}
return $themes;
} | php | private function filterThemeLayoutUpdates(array $existThemePaths, array $themes)
{
foreach ($themes as $theme => $themePaths) {
foreach ($themePaths as $pathIndex => $path) {
if (is_string($path) && isset($existThemePaths[$path])) {
unset($themePaths[$pathIndex]);
}
}
if (empty($themePaths)) {
unset($themes[$theme]);
} else {
$themes[$theme] = $themePaths;
}
}
return $themes;
} | [
"private",
"function",
"filterThemeLayoutUpdates",
"(",
"array",
"$",
"existThemePaths",
",",
"array",
"$",
"themes",
")",
"{",
"foreach",
"(",
"$",
"themes",
"as",
"$",
"theme",
"=>",
"$",
"themePaths",
")",
"{",
"foreach",
"(",
"$",
"themePaths",
"as",
"$",
"pathIndex",
"=>",
"$",
"path",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"path",
")",
"&&",
"isset",
"(",
"$",
"existThemePaths",
"[",
"$",
"path",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"themePaths",
"[",
"$",
"pathIndex",
"]",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"themePaths",
")",
")",
"{",
"unset",
"(",
"$",
"themes",
"[",
"$",
"theme",
"]",
")",
";",
"}",
"else",
"{",
"$",
"themes",
"[",
"$",
"theme",
"]",
"=",
"$",
"themePaths",
";",
"}",
"}",
"return",
"$",
"themes",
";",
"}"
] | @param array $existThemePaths
@param array $themes
@return array | [
"@param",
"array",
"$existThemePaths",
"@param",
"array",
"$themes"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/ResourceProvider/ThemeResourceProvider.php#L154-L170 |
oroinc/OroLayoutComponent | Extension/Theme/ResourceProvider/ThemeResourceProvider.php | ThemeResourceProvider.sortThemeLayoutUpdates | private function sortThemeLayoutUpdates(array $updates)
{
$directories = [];
$files = [];
foreach ($updates as $key => $update) {
if (is_array($update)) {
$update = $this->sortThemeLayoutUpdates($update);
$directories[$key] = $update;
} else {
$files[] = $update;
}
}
sort($files);
ksort($directories);
$updates = array_merge($files, $directories);
return $updates;
} | php | private function sortThemeLayoutUpdates(array $updates)
{
$directories = [];
$files = [];
foreach ($updates as $key => $update) {
if (is_array($update)) {
$update = $this->sortThemeLayoutUpdates($update);
$directories[$key] = $update;
} else {
$files[] = $update;
}
}
sort($files);
ksort($directories);
$updates = array_merge($files, $directories);
return $updates;
} | [
"private",
"function",
"sortThemeLayoutUpdates",
"(",
"array",
"$",
"updates",
")",
"{",
"$",
"directories",
"=",
"[",
"]",
";",
"$",
"files",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"updates",
"as",
"$",
"key",
"=>",
"$",
"update",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"update",
")",
")",
"{",
"$",
"update",
"=",
"$",
"this",
"->",
"sortThemeLayoutUpdates",
"(",
"$",
"update",
")",
";",
"$",
"directories",
"[",
"$",
"key",
"]",
"=",
"$",
"update",
";",
"}",
"else",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"update",
";",
"}",
"}",
"sort",
"(",
"$",
"files",
")",
";",
"ksort",
"(",
"$",
"directories",
")",
";",
"$",
"updates",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"directories",
")",
";",
"return",
"$",
"updates",
";",
"}"
] | @param array $updates
@return array | [
"@param",
"array",
"$updates"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/ResourceProvider/ThemeResourceProvider.php#L178-L196 |
zhouyl/mellivora | Mellivora/Http/Cookies.php | Cookies.setCookie | protected function setCookie($key, $value = null, $expire = 0)
{
if ($value === null) {
Arr::forget($_COOKIE, $key);
} else {
if ($this->defaults['encrypt']) {
$value = $this->getEncryption()->encryptBase64($value);
}
Arr::set($_COOKIE, $key, $value);
}
setcookie(
$key,
$value,
$expire,
$this->defaults['path'],
$this->defaults['domain'],
$this->defaults['secure'],
$this->defaults['httponly']
);
} | php | protected function setCookie($key, $value = null, $expire = 0)
{
if ($value === null) {
Arr::forget($_COOKIE, $key);
} else {
if ($this->defaults['encrypt']) {
$value = $this->getEncryption()->encryptBase64($value);
}
Arr::set($_COOKIE, $key, $value);
}
setcookie(
$key,
$value,
$expire,
$this->defaults['path'],
$this->defaults['domain'],
$this->defaults['secure'],
$this->defaults['httponly']
);
} | [
"protected",
"function",
"setCookie",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
",",
"$",
"expire",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"Arr",
"::",
"forget",
"(",
"$",
"_COOKIE",
",",
"$",
"key",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'encrypt'",
"]",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getEncryption",
"(",
")",
"->",
"encryptBase64",
"(",
"$",
"value",
")",
";",
"}",
"Arr",
"::",
"set",
"(",
"$",
"_COOKIE",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"setcookie",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expire",
",",
"$",
"this",
"->",
"defaults",
"[",
"'path'",
"]",
",",
"$",
"this",
"->",
"defaults",
"[",
"'domain'",
"]",
",",
"$",
"this",
"->",
"defaults",
"[",
"'secure'",
"]",
",",
"$",
"this",
"->",
"defaults",
"[",
"'httponly'",
"]",
")",
";",
"}"
] | ookie 设置
@param string $key
@param mixed $value
@param int $expire | [
"ookie",
"设置"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Cookies.php#L93-L114 |
zhouyl/mellivora | Mellivora/Http/Cookies.php | Cookies.set | public function set($key, $value = null, $minutes = null)
{
if ($minutes === null) {
$minutes = $this->defaults['lifetime'];
}
$data = is_array($key) ? $key : [$key => $value];
foreach ($data as $key => $value) {
$this->setCookie($key, $value, time() + $minutes);
}
return $this;
} | php | public function set($key, $value = null, $minutes = null)
{
if ($minutes === null) {
$minutes = $this->defaults['lifetime'];
}
$data = is_array($key) ? $key : [$key => $value];
foreach ($data as $key => $value) {
$this->setCookie($key, $value, time() + $minutes);
}
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
",",
"$",
"minutes",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"minutes",
"===",
"null",
")",
"{",
"$",
"minutes",
"=",
"$",
"this",
"->",
"defaults",
"[",
"'lifetime'",
"]",
";",
"}",
"$",
"data",
"=",
"is_array",
"(",
"$",
"key",
")",
"?",
"$",
"key",
":",
"[",
"$",
"key",
"=>",
"$",
"value",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setCookie",
"(",
"$",
"key",
",",
"$",
"value",
",",
"time",
"(",
")",
"+",
"$",
"minutes",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | 设置 cookie 值
@param string $key
@param mixed $value
@param int $minutes
@return \Mellivora\Http\Cookies | [
"设置",
"cookie",
"值"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Cookies.php#L125-L138 |
zhouyl/mellivora | Mellivora/Http/Cookies.php | Cookies.get | public function get($key, $default = null)
{
$value = Arr::get($_COOKIE, $key);
if ($value === null) {
return $default;
}
return $this->defaults['encrypt']
? $this->getEncryption()->decryptBase64($value)
: $value;
} | php | public function get($key, $default = null)
{
$value = Arr::get($_COOKIE, $key);
if ($value === null) {
return $default;
}
return $this->defaults['encrypt']
? $this->getEncryption()->decryptBase64($value)
: $value;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"Arr",
"::",
"get",
"(",
"$",
"_COOKIE",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"this",
"->",
"defaults",
"[",
"'encrypt'",
"]",
"?",
"$",
"this",
"->",
"getEncryption",
"(",
")",
"->",
"decryptBase64",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"}"
] | 获取 cookie 值
@param array $key
@param mixed $default
@return mixed | [
"获取",
"cookie",
"值"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Cookies.php#L148-L159 |
fccn/oai-pmh-core | src/libs/xml_creater.php | ANDS_XML.addChild | public function addChild($mom_node, $name, $value='')
{
$added_node = $this->doc->createElement($name, $value);
$added_node = $mom_node->appendChild($added_node);
return $added_node;
} | php | public function addChild($mom_node, $name, $value='')
{
$added_node = $this->doc->createElement($name, $value);
$added_node = $mom_node->appendChild($added_node);
return $added_node;
} | [
"public",
"function",
"addChild",
"(",
"$",
"mom_node",
",",
"$",
"name",
",",
"$",
"value",
"=",
"''",
")",
"{",
"$",
"added_node",
"=",
"$",
"this",
"->",
"doc",
"->",
"createElement",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"$",
"added_node",
"=",
"$",
"mom_node",
"->",
"appendChild",
"(",
"$",
"added_node",
")",
";",
"return",
"$",
"added_node",
";",
"}"
] | Add a child node to a parent node on a XML Doc: a worker function.
@param $mom_node
Type: DOMNode. The target node.
@param $name
Type: string. The name of child nade is being added
@param $value
Type: string. Text for the adding node if it is a text node.
@return DOMElement $added_node
The newly created node, can be used for further expansion.
If no further expansion is expected, return value can be igored. | [
"Add",
"a",
"child",
"node",
"to",
"a",
"parent",
"node",
"on",
"a",
"XML",
"Doc",
":",
"a",
"worker",
"function",
"."
] | train | https://github.com/fccn/oai-pmh-core/blob/a9c6852482c7bd7c48911a2165120325ecc27ea2/src/libs/xml_creater.php#L237-L242 |
fccn/oai-pmh-core | src/libs/xml_creater.php | ANDS_XML.create_request | public function create_request($par_array)
{
//debug_var_dump('par_array', $par_array);
$request = $this->addChild($this->doc->documentElement, "request", $this->request_url());
foreach ($par_array as $key => $value) {
$request->setAttribute($key, $value);
}
} | php | public function create_request($par_array)
{
//debug_var_dump('par_array', $par_array);
$request = $this->addChild($this->doc->documentElement, "request", $this->request_url());
foreach ($par_array as $key => $value) {
$request->setAttribute($key, $value);
}
} | [
"public",
"function",
"create_request",
"(",
"$",
"par_array",
")",
"{",
"//debug_var_dump('par_array', $par_array);",
"$",
"request",
"=",
"$",
"this",
"->",
"addChild",
"(",
"$",
"this",
"->",
"doc",
"->",
"documentElement",
",",
"\"request\"",
",",
"$",
"this",
"->",
"request_url",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"par_array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"request",
"->",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Create an OAI request node.
@param $par_array Type: array
The attributes of a request node. They describe the verb of the request and other associated parameters used in the request.
Keys of the array define attributes, and values are their content. | [
"Create",
"an",
"OAI",
"request",
"node",
"."
] | train | https://github.com/fccn/oai-pmh-core/blob/a9c6852482c7bd7c48911a2165120325ecc27ea2/src/libs/xml_creater.php#L253-L260 |
fccn/oai-pmh-core | src/libs/xml_creater.php | ANDS_Response_XML.add2_verbNode | public function add2_verbNode($nodeName, $value=null)
{
return $this->addChild($this->verbNode, $nodeName, $value);
} | php | public function add2_verbNode($nodeName, $value=null)
{
return $this->addChild($this->verbNode, $nodeName, $value);
} | [
"public",
"function",
"add2_verbNode",
"(",
"$",
"nodeName",
",",
"$",
"value",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"addChild",
"(",
"$",
"this",
"->",
"verbNode",
",",
"$",
"nodeName",
",",
"$",
"value",
")",
";",
"}"
] | Add direct child nodes to verb node (OAI-PMH), e.g. response to ListMetadataFormats.
Different verbs can have different required child nodes.
\see create_record, create_header
\see http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm.
\param $nodeName Type: string. The name of appending node.
\param $value Type: string. The content of appending node. | [
"Add",
"direct",
"child",
"nodes",
"to",
"verb",
"node",
"(",
"OAI",
"-",
"PMH",
")",
"e",
".",
"g",
".",
"response",
"to",
"ListMetadataFormats",
".",
"Different",
"verbs",
"can",
"have",
"different",
"required",
"child",
"nodes",
".",
"\\",
"see",
"create_record",
"create_header",
"\\",
"see",
"http",
":",
"//",
"www",
".",
"openarchives",
".",
"org",
"/",
"OAI",
"/",
"2",
".",
"0",
"/",
"openarchivesprotocol",
".",
"htm",
"."
] | train | https://github.com/fccn/oai-pmh-core/blob/a9c6852482c7bd7c48911a2165120325ecc27ea2/src/libs/xml_creater.php#L334-L337 |
fccn/oai-pmh-core | src/libs/xml_creater.php | ANDS_Response_XML.create_header | public function create_header($identifier, $timestamp, $ands_class, $add_to_node=null)
{
if (is_null($add_to_node)) {
$header_node = $this->add2_verbNode("header");
} else {
$header_node = $this->addChild($add_to_node, "header");
}
$this->addChild($header_node, "identifier", $identifier);
$this->addChild($header_node, "datestamp", $timestamp);
if (is_array($ands_class)) {
foreach ($ands_class as $setspec) {
$this->addChild($header_node, "setSpec", $setspec);
}
} else {
$this->addChild($header_node, "setSpec", $ands_class);
}
return $header_node;
} | php | public function create_header($identifier, $timestamp, $ands_class, $add_to_node=null)
{
if (is_null($add_to_node)) {
$header_node = $this->add2_verbNode("header");
} else {
$header_node = $this->addChild($add_to_node, "header");
}
$this->addChild($header_node, "identifier", $identifier);
$this->addChild($header_node, "datestamp", $timestamp);
if (is_array($ands_class)) {
foreach ($ands_class as $setspec) {
$this->addChild($header_node, "setSpec", $setspec);
}
} else {
$this->addChild($header_node, "setSpec", $ands_class);
}
return $header_node;
} | [
"public",
"function",
"create_header",
"(",
"$",
"identifier",
",",
"$",
"timestamp",
",",
"$",
"ands_class",
",",
"$",
"add_to_node",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"add_to_node",
")",
")",
"{",
"$",
"header_node",
"=",
"$",
"this",
"->",
"add2_verbNode",
"(",
"\"header\"",
")",
";",
"}",
"else",
"{",
"$",
"header_node",
"=",
"$",
"this",
"->",
"addChild",
"(",
"$",
"add_to_node",
",",
"\"header\"",
")",
";",
"}",
"$",
"this",
"->",
"addChild",
"(",
"$",
"header_node",
",",
"\"identifier\"",
",",
"$",
"identifier",
")",
";",
"$",
"this",
"->",
"addChild",
"(",
"$",
"header_node",
",",
"\"datestamp\"",
",",
"$",
"timestamp",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"ands_class",
")",
")",
"{",
"foreach",
"(",
"$",
"ands_class",
"as",
"$",
"setspec",
")",
"{",
"$",
"this",
"->",
"addChild",
"(",
"$",
"header_node",
",",
"\"setSpec\"",
",",
"$",
"setspec",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"addChild",
"(",
"$",
"header_node",
",",
"\"setSpec\"",
",",
"$",
"ands_class",
")",
";",
"}",
"return",
"$",
"header_node",
";",
"}"
] | Headers are enclosed inside of \<record\> to the query of ListRecords, ListIdentifiers and etc.
\param $identifier Type: string. The identifier string for node \<identifier\>.
\param $timestamp Type: timestamp. Timestapme in UTC format for node \<datastamp\>.
\param $ands_class Type: mix. Can be an array or just a string. Content of \<setSpec\>.
\param $add_to_node Type: DOMElement. Default value is null.
In normal cases, $add_to_node is the \<record\> node created previously. When it is null, the newly created header node is attatched to $this->verbNode.
Otherwise it will be attatched to the desired node defined in $add_to_node. | [
"Headers",
"are",
"enclosed",
"inside",
"of",
"\\",
"<record",
"\\",
">",
"to",
"the",
"query",
"of",
"ListRecords",
"ListIdentifiers",
"and",
"etc",
"."
] | train | https://github.com/fccn/oai-pmh-core/blob/a9c6852482c7bd7c48911a2165120325ecc27ea2/src/libs/xml_creater.php#L356-L373 |
fccn/oai-pmh-core | src/libs/xml_creater.php | ANDS_Response_XML.create_metadata | public function create_metadata($mom_record_node)
{
debug_message('****** In '.__FILE__.' function '.__FUNCTION__.' was called.');
$meta_node = $this->addChild($mom_record_node, "metadata");
return $meta_node;
} | php | public function create_metadata($mom_record_node)
{
debug_message('****** In '.__FILE__.' function '.__FUNCTION__.' was called.');
$meta_node = $this->addChild($mom_record_node, "metadata");
return $meta_node;
} | [
"public",
"function",
"create_metadata",
"(",
"$",
"mom_record_node",
")",
"{",
"debug_message",
"(",
"'****** In '",
".",
"__FILE__",
".",
"' function '",
".",
"__FUNCTION__",
".",
"' was called.'",
")",
";",
"$",
"meta_node",
"=",
"$",
"this",
"->",
"addChild",
"(",
"$",
"mom_record_node",
",",
"\"metadata\"",
")",
";",
"return",
"$",
"meta_node",
";",
"}"
] | Create metadata node for holding metadata. This is always added to \<record\> node.
\param $mom_record_node DOMElement. A node acts as the parent node.
@return $meta_node Type: DOMElement.
The newly created registryObject node which will be used for further expansion.
metadata node itself is maintained by internally by the Class. | [
"Create",
"metadata",
"node",
"for",
"holding",
"metadata",
".",
"This",
"is",
"always",
"added",
"to",
"\\",
"<record",
"\\",
">",
"node",
"."
] | train | https://github.com/fccn/oai-pmh-core/blob/a9c6852482c7bd7c48911a2165120325ecc27ea2/src/libs/xml_creater.php#L383-L388 |
fccn/oai-pmh-core | src/libs/xml_creater.php | ANDS_Response_XML.create_resumpToken | public function create_resumpToken($token, $expirationdatetime, $num_rows, $cursor=null)
{
$resump_node = $this->addChild($this->verbNode, "resumptionToken", $token);
if (isset($expirationdatetime)) {
$resump_node->setAttribute("expirationDate", $expirationdatetime);
}
$resump_node->setAttribute("completeListSize", $num_rows);
$resump_node->setAttribute("cursor", $cursor);
} | php | public function create_resumpToken($token, $expirationdatetime, $num_rows, $cursor=null)
{
$resump_node = $this->addChild($this->verbNode, "resumptionToken", $token);
if (isset($expirationdatetime)) {
$resump_node->setAttribute("expirationDate", $expirationdatetime);
}
$resump_node->setAttribute("completeListSize", $num_rows);
$resump_node->setAttribute("cursor", $cursor);
} | [
"public",
"function",
"create_resumpToken",
"(",
"$",
"token",
",",
"$",
"expirationdatetime",
",",
"$",
"num_rows",
",",
"$",
"cursor",
"=",
"null",
")",
"{",
"$",
"resump_node",
"=",
"$",
"this",
"->",
"addChild",
"(",
"$",
"this",
"->",
"verbNode",
",",
"\"resumptionToken\"",
",",
"$",
"token",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"expirationdatetime",
")",
")",
"{",
"$",
"resump_node",
"->",
"setAttribute",
"(",
"\"expirationDate\"",
",",
"$",
"expirationdatetime",
")",
";",
"}",
"$",
"resump_node",
"->",
"setAttribute",
"(",
"\"completeListSize\"",
",",
"$",
"num_rows",
")",
";",
"$",
"resump_node",
"->",
"setAttribute",
"(",
"\"cursor\"",
",",
"$",
"cursor",
")",
";",
"}"
] | If there are too many records request could not finished a resumpToken is generated to let harvester know
\param $token Type: string. A random number created somewhere?
\param $expirationdatetime Type: string. A string representing time.
\param $num_rows Type: integer. Number of records retrieved.
\param $cursor Type: string. Cursor can be used for database to retrieve next time. | [
"If",
"there",
"are",
"too",
"many",
"records",
"request",
"could",
"not",
"finished",
"a",
"resumpToken",
"is",
"generated",
"to",
"let",
"harvester",
"know"
] | train | https://github.com/fccn/oai-pmh-core/blob/a9c6852482c7bd7c48911a2165120325ecc27ea2/src/libs/xml_creater.php#L397-L405 |
uniondrug/http | src/ServerRequest.php | ServerRequest.createServerRequestFromGlobals | public static function createServerRequestFromGlobals()
{
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
$headers = function_exists('getallheaders') ? getallheaders() : [];
return new static($method, static::createUriFromGlobal($_SERVER), $headers, new PhpInputStream(), $_SERVER);
} | php | public static function createServerRequestFromGlobals()
{
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
$headers = function_exists('getallheaders') ? getallheaders() : [];
return new static($method, static::createUriFromGlobal($_SERVER), $headers, new PhpInputStream(), $_SERVER);
} | [
"public",
"static",
"function",
"createServerRequestFromGlobals",
"(",
")",
"{",
"$",
"method",
"=",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
":",
"'GET'",
";",
"$",
"headers",
"=",
"function_exists",
"(",
"'getallheaders'",
")",
"?",
"getallheaders",
"(",
")",
":",
"[",
"]",
";",
"return",
"new",
"static",
"(",
"$",
"method",
",",
"static",
"::",
"createUriFromGlobal",
"(",
"$",
"_SERVER",
")",
",",
"$",
"headers",
",",
"new",
"PhpInputStream",
"(",
")",
",",
"$",
"_SERVER",
")",
";",
"}"
] | Create a new server request from PHP globals.
@return ServerRequestInterface | [
"Create",
"a",
"new",
"server",
"request",
"from",
"PHP",
"globals",
"."
] | train | https://github.com/uniondrug/http/blob/d650af25bd4587499befa76081a8fe8275431320/src/ServerRequest.php#L534-L540 |
SporkCode/Spork | src/Mvc/Listener/AccessDeniedStrategy.php | AccessDeniedStrategy.attach | public function attach(EventManagerInterface $events)
{
$sharedEvents = $events->getSharedManager();
// check for 403 at beginning of route and dispatch events
$this->listeners[] = $events->attach(
array(MvcEvent::EVENT_ROUTE, MvcEvent::EVENT_DISPATCH),
array($this, 'detectAccessDenied'),
1000);
// check for 403 immediately after controller dispatch
$this->listeners[] = $sharedEvents->attach(
'Zend\Stdlib\DispatchableInterface',
MvcEvent::EVENT_DISPATCH,
array($this, 'detectAccessDenied'),
0);
// inject access denied view model
$this->listeners[] = $events->attach(
MvcEvent::EVENT_RENDER,
array($this, 'injectAccessDeniedViewModel'),
1);
} | php | public function attach(EventManagerInterface $events)
{
$sharedEvents = $events->getSharedManager();
// check for 403 at beginning of route and dispatch events
$this->listeners[] = $events->attach(
array(MvcEvent::EVENT_ROUTE, MvcEvent::EVENT_DISPATCH),
array($this, 'detectAccessDenied'),
1000);
// check for 403 immediately after controller dispatch
$this->listeners[] = $sharedEvents->attach(
'Zend\Stdlib\DispatchableInterface',
MvcEvent::EVENT_DISPATCH,
array($this, 'detectAccessDenied'),
0);
// inject access denied view model
$this->listeners[] = $events->attach(
MvcEvent::EVENT_RENDER,
array($this, 'injectAccessDeniedViewModel'),
1);
} | [
"public",
"function",
"attach",
"(",
"EventManagerInterface",
"$",
"events",
")",
"{",
"$",
"sharedEvents",
"=",
"$",
"events",
"->",
"getSharedManager",
"(",
")",
";",
"// check for 403 at beginning of route and dispatch events",
"$",
"this",
"->",
"listeners",
"[",
"]",
"=",
"$",
"events",
"->",
"attach",
"(",
"array",
"(",
"MvcEvent",
"::",
"EVENT_ROUTE",
",",
"MvcEvent",
"::",
"EVENT_DISPATCH",
")",
",",
"array",
"(",
"$",
"this",
",",
"'detectAccessDenied'",
")",
",",
"1000",
")",
";",
"// check for 403 immediately after controller dispatch",
"$",
"this",
"->",
"listeners",
"[",
"]",
"=",
"$",
"sharedEvents",
"->",
"attach",
"(",
"'Zend\\Stdlib\\DispatchableInterface'",
",",
"MvcEvent",
"::",
"EVENT_DISPATCH",
",",
"array",
"(",
"$",
"this",
",",
"'detectAccessDenied'",
")",
",",
"0",
")",
";",
"// inject access denied view model",
"$",
"this",
"->",
"listeners",
"[",
"]",
"=",
"$",
"events",
"->",
"attach",
"(",
"MvcEvent",
"::",
"EVENT_RENDER",
",",
"array",
"(",
"$",
"this",
",",
"'injectAccessDeniedViewModel'",
")",
",",
"1",
")",
";",
"}"
] | Attach event
@see \Zend\EventManager\ListenerAggregateInterface::attach()
@param EventManagerInterface $events | [
"Attach",
"event"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/AccessDeniedStrategy.php#L60-L82 |
SporkCode/Spork | src/Mvc/Listener/AccessDeniedStrategy.php | AccessDeniedStrategy.detectAccessDenied | public function detectAccessDenied(MvcEvent $event)
{
$response = $event->getResponse();
if ($response->getStatusCode() == 403) {
$event->setError('Access Denied');
$event->stopPropagation(true);
}
} | php | public function detectAccessDenied(MvcEvent $event)
{
$response = $event->getResponse();
if ($response->getStatusCode() == 403) {
$event->setError('Access Denied');
$event->stopPropagation(true);
}
} | [
"public",
"function",
"detectAccessDenied",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"$",
"response",
"=",
"$",
"event",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"==",
"403",
")",
"{",
"$",
"event",
"->",
"setError",
"(",
"'Access Denied'",
")",
";",
"$",
"event",
"->",
"stopPropagation",
"(",
"true",
")",
";",
"}",
"}"
] | If response status code is 403 set error state and stop event propagation
@param MvcEvent $event | [
"If",
"response",
"status",
"code",
"is",
"403",
"set",
"error",
"state",
"and",
"stop",
"event",
"propagation"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/AccessDeniedStrategy.php#L133-L140 |
SporkCode/Spork | src/Mvc/Listener/AccessDeniedStrategy.php | AccessDeniedStrategy.injectAccessDeniedViewModel | public function injectAccessDeniedViewModel(MvcEvent $event)
{
$this->config($event);
$result = $event->getResult();
if ($result instanceof ResponseInterface) {
return;
}
$response = $event->getResponse();
if ($response->getStatusCode() != 403) {
return;
}
$model = new ViewModel();
$model->setTemplate($this->template);
if ($this->renderLayout == true) {
$layout = $event->getViewModel();
$layout->addChild($model);
} else {
$model->setTerminal(true);
$event->setViewModel($model);
}
} | php | public function injectAccessDeniedViewModel(MvcEvent $event)
{
$this->config($event);
$result = $event->getResult();
if ($result instanceof ResponseInterface) {
return;
}
$response = $event->getResponse();
if ($response->getStatusCode() != 403) {
return;
}
$model = new ViewModel();
$model->setTemplate($this->template);
if ($this->renderLayout == true) {
$layout = $event->getViewModel();
$layout->addChild($model);
} else {
$model->setTerminal(true);
$event->setViewModel($model);
}
} | [
"public",
"function",
"injectAccessDeniedViewModel",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"$",
"this",
"->",
"config",
"(",
"$",
"event",
")",
";",
"$",
"result",
"=",
"$",
"event",
"->",
"getResult",
"(",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"ResponseInterface",
")",
"{",
"return",
";",
"}",
"$",
"response",
"=",
"$",
"event",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"!=",
"403",
")",
"{",
"return",
";",
"}",
"$",
"model",
"=",
"new",
"ViewModel",
"(",
")",
";",
"$",
"model",
"->",
"setTemplate",
"(",
"$",
"this",
"->",
"template",
")",
";",
"if",
"(",
"$",
"this",
"->",
"renderLayout",
"==",
"true",
")",
"{",
"$",
"layout",
"=",
"$",
"event",
"->",
"getViewModel",
"(",
")",
";",
"$",
"layout",
"->",
"addChild",
"(",
"$",
"model",
")",
";",
"}",
"else",
"{",
"$",
"model",
"->",
"setTerminal",
"(",
"true",
")",
";",
"$",
"event",
"->",
"setViewModel",
"(",
"$",
"model",
")",
";",
"}",
"}"
] | Inject access denied View Model is response status is 403
@param MvcEvent $event | [
"Inject",
"access",
"denied",
"View",
"Model",
"is",
"response",
"status",
"is",
"403"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/AccessDeniedStrategy.php#L147-L173 |
SporkCode/Spork | src/Mvc/Listener/AccessDeniedStrategy.php | AccessDeniedStrategy.config | protected function config(MvcEvent $event)
{
$appConfig = $event->getApplication()->getServiceManager()->get('config');
$config = array_key_exists(self::CONFIG_KEY, $appConfig) ? $appConfig[self::CONFIG_KEY] : array();
if (array_key_exists('template', $config)) {
$this->setTemplate($config['template']);
}
if (array_key_exists('renderLayout', $config)) {
$this->setRenderLayout($config['renderLayout']);
}
} | php | protected function config(MvcEvent $event)
{
$appConfig = $event->getApplication()->getServiceManager()->get('config');
$config = array_key_exists(self::CONFIG_KEY, $appConfig) ? $appConfig[self::CONFIG_KEY] : array();
if (array_key_exists('template', $config)) {
$this->setTemplate($config['template']);
}
if (array_key_exists('renderLayout', $config)) {
$this->setRenderLayout($config['renderLayout']);
}
} | [
"protected",
"function",
"config",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"$",
"appConfig",
"=",
"$",
"event",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
"->",
"get",
"(",
"'config'",
")",
";",
"$",
"config",
"=",
"array_key_exists",
"(",
"self",
"::",
"CONFIG_KEY",
",",
"$",
"appConfig",
")",
"?",
"$",
"appConfig",
"[",
"self",
"::",
"CONFIG_KEY",
"]",
":",
"array",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'template'",
",",
"$",
"config",
")",
")",
"{",
"$",
"this",
"->",
"setTemplate",
"(",
"$",
"config",
"[",
"'template'",
"]",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'renderLayout'",
",",
"$",
"config",
")",
")",
"{",
"$",
"this",
"->",
"setRenderLayout",
"(",
"$",
"config",
"[",
"'renderLayout'",
"]",
")",
";",
"}",
"}"
] | Set configuration options from application configuration
@param MvcEvent $event | [
"Set",
"configuration",
"options",
"from",
"application",
"configuration"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/AccessDeniedStrategy.php#L180-L192 |
shabbyrobe/amiss | src/Functions.php | Functions.keyValue | public static function keyValue($list, $keyProperty=null, $valueProperty=null)
{
$index = array();
foreach ($list as $i) {
if ($keyProperty) {
if (!$valueProperty) {
throw new \InvalidArgumentException("Must set value property if setting key property");
}
$index[$i->$keyProperty] = $i->$valueProperty;
}
else {
$key = current($i);
next($i);
$value = current($i);
$index[$key] = $value;
}
}
return $index;
} | php | public static function keyValue($list, $keyProperty=null, $valueProperty=null)
{
$index = array();
foreach ($list as $i) {
if ($keyProperty) {
if (!$valueProperty) {
throw new \InvalidArgumentException("Must set value property if setting key property");
}
$index[$i->$keyProperty] = $i->$valueProperty;
}
else {
$key = current($i);
next($i);
$value = current($i);
$index[$key] = $value;
}
}
return $index;
} | [
"public",
"static",
"function",
"keyValue",
"(",
"$",
"list",
",",
"$",
"keyProperty",
"=",
"null",
",",
"$",
"valueProperty",
"=",
"null",
")",
"{",
"$",
"index",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"keyProperty",
")",
"{",
"if",
"(",
"!",
"$",
"valueProperty",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Must set value property if setting key property\"",
")",
";",
"}",
"$",
"index",
"[",
"$",
"i",
"->",
"$",
"keyProperty",
"]",
"=",
"$",
"i",
"->",
"$",
"valueProperty",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"current",
"(",
"$",
"i",
")",
";",
"next",
"(",
"$",
"i",
")",
";",
"$",
"value",
"=",
"current",
"(",
"$",
"i",
")",
";",
"$",
"index",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"index",
";",
"}"
] | Create a one-dimensional associative array from a list of objects, or a list of 2-tuples.
@param object[]|array $list
@param string $keyProperty
@param string $valueProperty
@return array | [
"Create",
"a",
"one",
"-",
"dimensional",
"associative",
"array",
"from",
"a",
"list",
"of",
"objects",
"or",
"a",
"list",
"of",
"2",
"-",
"tuples",
"."
] | train | https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Functions.php#L14-L32 |
nabab/bbn | src/bbn/user/session.php | session._get_value | private function _get_value($args){
if ( $this->id ){
$var =& $this->data;
foreach ( $args as $a ){
if ( !isset($var[$a]) ){
return null;
}
$var =& $var[$a];
}
return $var;
}
} | php | private function _get_value($args){
if ( $this->id ){
$var =& $this->data;
foreach ( $args as $a ){
if ( !isset($var[$a]) ){
return null;
}
$var =& $var[$a];
}
return $var;
}
} | [
"private",
"function",
"_get_value",
"(",
"$",
"args",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"id",
")",
"{",
"$",
"var",
"=",
"&",
"$",
"this",
"->",
"data",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"a",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"var",
"[",
"$",
"a",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"var",
"=",
"&",
"$",
"var",
"[",
"$",
"a",
"]",
";",
"}",
"return",
"$",
"var",
";",
"}",
"}"
] | Gets a reference to the part of the data corresponding to an array of indexes
```php
$this->_get_value(['index1', 'index2'])
// Will return the content of $this->data['index1']['index2']
```
@param $args
@return null | [
"Gets",
"a",
"reference",
"to",
"the",
"part",
"of",
"the",
"data",
"corresponding",
"to",
"an",
"array",
"of",
"indexes"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/session.php#L54-L65 |
hametuha/wpametu | src/WPametu/File/Path.php | Path.remove_dir | private function remove_dir($path){
if( is_dir($path) ){
foreach( scandir($path) as $file ){
if( $file != '.' && $file != '..' ){
if( is_dir("{$path}/{$file}") ){
$this->remove_dir("{$path}/{$file}");
}else{
@unlink("{$path}/{$file}");
}
}
}
@rmdir($path);
}
} | php | private function remove_dir($path){
if( is_dir($path) ){
foreach( scandir($path) as $file ){
if( $file != '.' && $file != '..' ){
if( is_dir("{$path}/{$file}") ){
$this->remove_dir("{$path}/{$file}");
}else{
@unlink("{$path}/{$file}");
}
}
}
@rmdir($path);
}
} | [
"private",
"function",
"remove_dir",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"foreach",
"(",
"scandir",
"(",
"$",
"path",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"!=",
"'.'",
"&&",
"$",
"file",
"!=",
"'..'",
")",
"{",
"if",
"(",
"is_dir",
"(",
"\"{$path}/{$file}\"",
")",
")",
"{",
"$",
"this",
"->",
"remove_dir",
"(",
"\"{$path}/{$file}\"",
")",
";",
"}",
"else",
"{",
"@",
"unlink",
"(",
"\"{$path}/{$file}\"",
")",
";",
"}",
"}",
"}",
"@",
"rmdir",
"(",
"$",
"path",
")",
";",
"}",
"}"
] | Remove directory recursively
@param string $path | [
"Remove",
"directory",
"recursively"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/File/Path.php#L90-L103 |
zicht/z | src/Zicht/Tool/Container/Declaration.php | Declaration.compileBody | protected function compileBody(Buffer $buffer)
{
$buffer->write('return ');
$this->expr->compile($buffer);
$buffer->raw(';');
} | php | protected function compileBody(Buffer $buffer)
{
$buffer->write('return ');
$this->expr->compile($buffer);
$buffer->raw(';');
} | [
"protected",
"function",
"compileBody",
"(",
"Buffer",
"$",
"buffer",
")",
"{",
"$",
"buffer",
"->",
"write",
"(",
"'return '",
")",
";",
"$",
"this",
"->",
"expr",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"$",
"buffer",
"->",
"raw",
"(",
"';'",
")",
";",
"}"
] | Compiles the definition body
@param \Zicht\Tool\Script\Buffer $buffer
@return void | [
"Compiles",
"the",
"definition",
"body"
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/Declaration.php#L53-L58 |
surebert/surebert-framework | src/sb/Controller/JSON/RPC2/Server.php | Server.useEncryption | public function useEncryption($key)
{
$this->encryptor = new \sb\Encryption\ForTransmission($key);
$this->encryption_key = $key;
//decrypt cookies if sent
foreach (\sb\Gateway::$cookie as $k => $v) {
\sb\Gateway::$cookie[$k] = $this->encryptor->decrypt($v);
}
} | php | public function useEncryption($key)
{
$this->encryptor = new \sb\Encryption\ForTransmission($key);
$this->encryption_key = $key;
//decrypt cookies if sent
foreach (\sb\Gateway::$cookie as $k => $v) {
\sb\Gateway::$cookie[$k] = $this->encryptor->decrypt($v);
}
} | [
"public",
"function",
"useEncryption",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"encryptor",
"=",
"new",
"\\",
"sb",
"\\",
"Encryption",
"\\",
"ForTransmission",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"encryption_key",
"=",
"$",
"key",
";",
"//decrypt cookies if sent",
"foreach",
"(",
"\\",
"sb",
"\\",
"Gateway",
"::",
"$",
"cookie",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"\\",
"sb",
"\\",
"Gateway",
"::",
"$",
"cookie",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"encryptor",
"->",
"decrypt",
"(",
"$",
"v",
")",
";",
"}",
"}"
] | Sets the key that data is encrypted with and turns on encryption,
the client must use the same key
@param $key String | [
"Sets",
"the",
"key",
"that",
"data",
"is",
"encrypted",
"with",
"and",
"turns",
"on",
"encryption",
"the",
"client",
"must",
"use",
"the",
"same",
"key"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/JSON/RPC2/Server.php#L86-L95 |
surebert/surebert-framework | src/sb/Controller/JSON/RPC2/Server.php | Server.getMethods | public function getMethods($html = true)
{
$arr = Array();
foreach($this->served_classes as $class){
foreach (\get_class_methods($class) as $method) {
$reflect = new \ReflectionMethod($class, $method);
if ($reflect) {
if($class == $this){
$docs = $reflect->getDocComment();
$servable = false;
if (!empty($docs)) {
if (\preg_match("~@servable (true|false)~", $docs, $match)) {
$servable = $match[1] == 'true' ? true : false;
}
}
} else if($reflect->isPublic()){
$servable = true;
}
if (!$servable) {
continue;
}
$params = $reflect->getParameters();
$ps = Array();
foreach ($params as $param) {
$ps[] = '$' . $param->getName();
}
$key = $method . '(' . implode(', ', $ps) . ')';
$arr[$key] = $reflect->getDocComment();
}
}
}
if ($html == false) {
return $arr;
} else {
return $this->methodsToHtml($arr);
}
} | php | public function getMethods($html = true)
{
$arr = Array();
foreach($this->served_classes as $class){
foreach (\get_class_methods($class) as $method) {
$reflect = new \ReflectionMethod($class, $method);
if ($reflect) {
if($class == $this){
$docs = $reflect->getDocComment();
$servable = false;
if (!empty($docs)) {
if (\preg_match("~@servable (true|false)~", $docs, $match)) {
$servable = $match[1] == 'true' ? true : false;
}
}
} else if($reflect->isPublic()){
$servable = true;
}
if (!$servable) {
continue;
}
$params = $reflect->getParameters();
$ps = Array();
foreach ($params as $param) {
$ps[] = '$' . $param->getName();
}
$key = $method . '(' . implode(', ', $ps) . ')';
$arr[$key] = $reflect->getDocComment();
}
}
}
if ($html == false) {
return $arr;
} else {
return $this->methodsToHtml($arr);
}
} | [
"public",
"function",
"getMethods",
"(",
"$",
"html",
"=",
"true",
")",
"{",
"$",
"arr",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"served_classes",
"as",
"$",
"class",
")",
"{",
"foreach",
"(",
"\\",
"get_class_methods",
"(",
"$",
"class",
")",
"as",
"$",
"method",
")",
"{",
"$",
"reflect",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"if",
"(",
"$",
"reflect",
")",
"{",
"if",
"(",
"$",
"class",
"==",
"$",
"this",
")",
"{",
"$",
"docs",
"=",
"$",
"reflect",
"->",
"getDocComment",
"(",
")",
";",
"$",
"servable",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"docs",
")",
")",
"{",
"if",
"(",
"\\",
"preg_match",
"(",
"\"~@servable (true|false)~\"",
",",
"$",
"docs",
",",
"$",
"match",
")",
")",
"{",
"$",
"servable",
"=",
"$",
"match",
"[",
"1",
"]",
"==",
"'true'",
"?",
"true",
":",
"false",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"$",
"reflect",
"->",
"isPublic",
"(",
")",
")",
"{",
"$",
"servable",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"servable",
")",
"{",
"continue",
";",
"}",
"$",
"params",
"=",
"$",
"reflect",
"->",
"getParameters",
"(",
")",
";",
"$",
"ps",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"ps",
"[",
"]",
"=",
"'$'",
".",
"$",
"param",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"key",
"=",
"$",
"method",
".",
"'('",
".",
"implode",
"(",
"', '",
",",
"$",
"ps",
")",
".",
"')'",
";",
"$",
"arr",
"[",
"$",
"key",
"]",
"=",
"$",
"reflect",
"->",
"getDocComment",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"html",
"==",
"false",
")",
"{",
"return",
"$",
"arr",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"methodsToHtml",
"(",
"$",
"arr",
")",
";",
"}",
"}"
] | Get the methods available for this \sb\JSON\RPC2_Server instance
@return Array - Object once json_encoded
@servable true | [
"Get",
"the",
"methods",
"available",
"for",
"this",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2_Server",
"instance"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/JSON/RPC2/Server.php#L102-L149 |
surebert/surebert-framework | src/sb/Controller/JSON/RPC2/Server.php | Server.getPhpdoc | protected function getPhpdoc($method)
{
$reflect = false;
foreach($this->served_classes as $class){
if (\method_exists($class, $method)) {
$reflect = new \ReflectionMethod($class, $method);
break;
}
}
$response = new \stdClass();
if(!$reflect){
$response->error = new \sb\JSON\RPC2\Error();
$response->error->code = -32602;
$response->error->message = "Invalid method parameters";
return $response;
}
$response->phpdoc = $reflect->getDocComment();
if (\preg_match("~@return (.*?) (.*?)\*/$~s", $response->phpdoc, $match)) {
$response->return_type = $match[1];
} else {
$response->return_type = 'n/a';
}
return $response;
} | php | protected function getPhpdoc($method)
{
$reflect = false;
foreach($this->served_classes as $class){
if (\method_exists($class, $method)) {
$reflect = new \ReflectionMethod($class, $method);
break;
}
}
$response = new \stdClass();
if(!$reflect){
$response->error = new \sb\JSON\RPC2\Error();
$response->error->code = -32602;
$response->error->message = "Invalid method parameters";
return $response;
}
$response->phpdoc = $reflect->getDocComment();
if (\preg_match("~@return (.*?) (.*?)\*/$~s", $response->phpdoc, $match)) {
$response->return_type = $match[1];
} else {
$response->return_type = 'n/a';
}
return $response;
} | [
"protected",
"function",
"getPhpdoc",
"(",
"$",
"method",
")",
"{",
"$",
"reflect",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"served_classes",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"\\",
"method_exists",
"(",
"$",
"class",
",",
"$",
"method",
")",
")",
"{",
"$",
"reflect",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"break",
";",
"}",
"}",
"$",
"response",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"if",
"(",
"!",
"$",
"reflect",
")",
"{",
"$",
"response",
"->",
"error",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Error",
"(",
")",
";",
"$",
"response",
"->",
"error",
"->",
"code",
"=",
"-",
"32602",
";",
"$",
"response",
"->",
"error",
"->",
"message",
"=",
"\"Invalid method parameters\"",
";",
"return",
"$",
"response",
";",
"}",
"$",
"response",
"->",
"phpdoc",
"=",
"$",
"reflect",
"->",
"getDocComment",
"(",
")",
";",
"if",
"(",
"\\",
"preg_match",
"(",
"\"~@return (.*?) (.*?)\\*/$~s\"",
",",
"$",
"response",
"->",
"phpdoc",
",",
"$",
"match",
")",
")",
"{",
"$",
"response",
"->",
"return_type",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"return_type",
"=",
"'n/a'",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Get php doc and return_type for method by name
@param string $name The name of the method to grab the docs for
@return Object with return_type and phpdoc property | [
"Get",
"php",
"doc",
"and",
"return_type",
"for",
"method",
"by",
"name"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/JSON/RPC2/Server.php#L156-L187 |
surebert/surebert-framework | src/sb/Controller/JSON/RPC2/Server.php | Server.methodsToHtml | protected function methodsToHtml($methods)
{
$html = '<style type="text/css">
li{background-color:#c8c8d4;}
h1{
font-size:1.0em;
padding:3px 0 3px 10px;
color:white;
background-color:#8181bd;
}
pre{
color:#1d1d4d;
}
</style><ol>';
//sorting method alphabetically
ksort($methods);
foreach ($methods as $method => $comments) {
$html .= '<li><h1>$server->' . $method . ';</h1><pre>' . str_repeat(" ", 4) . $comments . '</pre></li>';
}
$html .= '</ol>';
return $html;
} | php | protected function methodsToHtml($methods)
{
$html = '<style type="text/css">
li{background-color:#c8c8d4;}
h1{
font-size:1.0em;
padding:3px 0 3px 10px;
color:white;
background-color:#8181bd;
}
pre{
color:#1d1d4d;
}
</style><ol>';
//sorting method alphabetically
ksort($methods);
foreach ($methods as $method => $comments) {
$html .= '<li><h1>$server->' . $method . ';</h1><pre>' . str_repeat(" ", 4) . $comments . '</pre></li>';
}
$html .= '</ol>';
return $html;
} | [
"protected",
"function",
"methodsToHtml",
"(",
"$",
"methods",
")",
"{",
"$",
"html",
"=",
"'<style type=\"text/css\">\n li{background-color:#c8c8d4;}\n\n h1{\n font-size:1.0em;\n padding:3px 0 3px 10px;\n color:white;\n background-color:#8181bd;\n }\n\n pre{\n color:#1d1d4d;\n }\n </style><ol>'",
";",
"//sorting method alphabetically",
"ksort",
"(",
"$",
"methods",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
"=>",
"$",
"comments",
")",
"{",
"$",
"html",
".=",
"'<li><h1>$server->'",
".",
"$",
"method",
".",
"';</h1><pre>'",
".",
"str_repeat",
"(",
"\" \"",
",",
"4",
")",
".",
"$",
"comments",
".",
"'</pre></li>'",
";",
"}",
"$",
"html",
".=",
"'</ol>'",
";",
"return",
"$",
"html",
";",
"}"
] | Coverts the methods served into an HTML string
@param $arr
@return string HTML | [
"Coverts",
"the",
"methods",
"served",
"into",
"an",
"HTML",
"string"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/JSON/RPC2/Server.php#L194-L221 |
surebert/surebert-framework | src/sb/Controller/JSON/RPC2/Server.php | Server.getResponse | protected function getResponse($json_request_str = '')
{
$response = new \sb\JSON\RPC2\Response();
$request = null;
if (empty($json_request_str)) {
if (isset(\sb\Gateway::$cmd_options) && isset(\sb\Gateway::$cmd_options['json_request'])) {
$json_request_str = \sb\Gateway::$cmd_options['json_request'];
} elseif ($this->method == 'post' || $this->method == 'both') {
$json_request_str = \file_get_contents("php://input");
}
if (is_null($request)
&& ($this->method == 'get' || $this->method == 'both')
&& (isset($this->request->get['method'])
&& isset($this->request->get['params'])
&& isset($this->request->get['id']))) {
$request = new \sb\JSON\RPC2\Request();
$request->id = $this->request->get['id'];
$request->method = $this->request->get['method'];
$params = $this->request->get['params'];
if (!\preg_match("~[\[\{]~", \substr($params, 0, 1))) {
$params = \base64_decode($params);
}
$request->params = \json_decode($params);
$json_request_str = \json_encode($request);
}
}
if ($json_request_str) {
if (isset($this->encryption_key)) {
$json_request_str = $this->encryptor->decrypt($json_request_str);
}
}
$request = new \sb\JSON\RPC2\Request($json_request_str);
if (\is_null($request)) {
$response->error = new \sb\JSON\RPC2\Error(-32700, 'Parse Error', "Data Received: " . $json_request_str);
} else {
$response->id = $request->id;
}
//log the incoming request
$this->logRequest($json_request_str);
$servable = false;
$servedClass = false;
foreach($this->served_classes as $class){
if (\method_exists($class, $request->method)) {
$reflection = new \ReflectionMethod($class, $request->method);
if($class == $this){
//check for phpdocs
$docs = $reflection->getDocComment();
$non_rpc = false;
if (!empty($docs)) {
if (\preg_match("~@servable (true|false)~", $docs, $match)) {
$servable = $match[1] == 'true' ? true : false;
}
}
} else {
$servable = $reflection->isPublic();
}
if($servable){
$servedClass = $class;
break;
}
}
}
//check for requested remote procedure
if ($servedClass) {
if (\is_object($request->params)) {
$answer = \call_user_func(Array($servedClass, $request->method), $request->params);
} else {
if (!\is_array($request->params)) {
$request->params = Array();
}
$answer = \call_user_func_array(Array($servedClass, $request->method), $request->params);
}
//if they return an error from the method call, return that
if ($answer instanceof \sb\JSON\RPC2\Error) {
$response->error = $answer;
} else {
//otherwise return the answer
$response->result = $answer;
}
} else {
if (isset($request->error) && $request->error instanceOf \sb\JSON\RPC2\Error) {
$response->error = $request->error;
} else {
$response->error = new \sb\JSON\RPC2\Error();
$response->error->code = -32601;
$response->error->message = "Procedure not found";
}
}
//remove unnecessary properties
if ($response->error instanceof \sb\JSON\RPC2\Error) {
unset($response->result);
if (\is_null($response->error->data)) {
unset($response->error->data);
}
} else {
unset($response->error);
}
//log the final response
$this->logResponse(json_encode($response));
return $response;
} | php | protected function getResponse($json_request_str = '')
{
$response = new \sb\JSON\RPC2\Response();
$request = null;
if (empty($json_request_str)) {
if (isset(\sb\Gateway::$cmd_options) && isset(\sb\Gateway::$cmd_options['json_request'])) {
$json_request_str = \sb\Gateway::$cmd_options['json_request'];
} elseif ($this->method == 'post' || $this->method == 'both') {
$json_request_str = \file_get_contents("php://input");
}
if (is_null($request)
&& ($this->method == 'get' || $this->method == 'both')
&& (isset($this->request->get['method'])
&& isset($this->request->get['params'])
&& isset($this->request->get['id']))) {
$request = new \sb\JSON\RPC2\Request();
$request->id = $this->request->get['id'];
$request->method = $this->request->get['method'];
$params = $this->request->get['params'];
if (!\preg_match("~[\[\{]~", \substr($params, 0, 1))) {
$params = \base64_decode($params);
}
$request->params = \json_decode($params);
$json_request_str = \json_encode($request);
}
}
if ($json_request_str) {
if (isset($this->encryption_key)) {
$json_request_str = $this->encryptor->decrypt($json_request_str);
}
}
$request = new \sb\JSON\RPC2\Request($json_request_str);
if (\is_null($request)) {
$response->error = new \sb\JSON\RPC2\Error(-32700, 'Parse Error', "Data Received: " . $json_request_str);
} else {
$response->id = $request->id;
}
//log the incoming request
$this->logRequest($json_request_str);
$servable = false;
$servedClass = false;
foreach($this->served_classes as $class){
if (\method_exists($class, $request->method)) {
$reflection = new \ReflectionMethod($class, $request->method);
if($class == $this){
//check for phpdocs
$docs = $reflection->getDocComment();
$non_rpc = false;
if (!empty($docs)) {
if (\preg_match("~@servable (true|false)~", $docs, $match)) {
$servable = $match[1] == 'true' ? true : false;
}
}
} else {
$servable = $reflection->isPublic();
}
if($servable){
$servedClass = $class;
break;
}
}
}
//check for requested remote procedure
if ($servedClass) {
if (\is_object($request->params)) {
$answer = \call_user_func(Array($servedClass, $request->method), $request->params);
} else {
if (!\is_array($request->params)) {
$request->params = Array();
}
$answer = \call_user_func_array(Array($servedClass, $request->method), $request->params);
}
//if they return an error from the method call, return that
if ($answer instanceof \sb\JSON\RPC2\Error) {
$response->error = $answer;
} else {
//otherwise return the answer
$response->result = $answer;
}
} else {
if (isset($request->error) && $request->error instanceOf \sb\JSON\RPC2\Error) {
$response->error = $request->error;
} else {
$response->error = new \sb\JSON\RPC2\Error();
$response->error->code = -32601;
$response->error->message = "Procedure not found";
}
}
//remove unnecessary properties
if ($response->error instanceof \sb\JSON\RPC2\Error) {
unset($response->result);
if (\is_null($response->error->data)) {
unset($response->error->data);
}
} else {
unset($response->error);
}
//log the final response
$this->logResponse(json_encode($response));
return $response;
} | [
"protected",
"function",
"getResponse",
"(",
"$",
"json_request_str",
"=",
"''",
")",
"{",
"$",
"response",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Response",
"(",
")",
";",
"$",
"request",
"=",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"json_request_str",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"\\",
"sb",
"\\",
"Gateway",
"::",
"$",
"cmd_options",
")",
"&&",
"isset",
"(",
"\\",
"sb",
"\\",
"Gateway",
"::",
"$",
"cmd_options",
"[",
"'json_request'",
"]",
")",
")",
"{",
"$",
"json_request_str",
"=",
"\\",
"sb",
"\\",
"Gateway",
"::",
"$",
"cmd_options",
"[",
"'json_request'",
"]",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"method",
"==",
"'post'",
"||",
"$",
"this",
"->",
"method",
"==",
"'both'",
")",
"{",
"$",
"json_request_str",
"=",
"\\",
"file_get_contents",
"(",
"\"php://input\"",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"request",
")",
"&&",
"(",
"$",
"this",
"->",
"method",
"==",
"'get'",
"||",
"$",
"this",
"->",
"method",
"==",
"'both'",
")",
"&&",
"(",
"isset",
"(",
"$",
"this",
"->",
"request",
"->",
"get",
"[",
"'method'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"request",
"->",
"get",
"[",
"'params'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"request",
"->",
"get",
"[",
"'id'",
"]",
")",
")",
")",
"{",
"$",
"request",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Request",
"(",
")",
";",
"$",
"request",
"->",
"id",
"=",
"$",
"this",
"->",
"request",
"->",
"get",
"[",
"'id'",
"]",
";",
"$",
"request",
"->",
"method",
"=",
"$",
"this",
"->",
"request",
"->",
"get",
"[",
"'method'",
"]",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"request",
"->",
"get",
"[",
"'params'",
"]",
";",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"\"~[\\[\\{]~\"",
",",
"\\",
"substr",
"(",
"$",
"params",
",",
"0",
",",
"1",
")",
")",
")",
"{",
"$",
"params",
"=",
"\\",
"base64_decode",
"(",
"$",
"params",
")",
";",
"}",
"$",
"request",
"->",
"params",
"=",
"\\",
"json_decode",
"(",
"$",
"params",
")",
";",
"$",
"json_request_str",
"=",
"\\",
"json_encode",
"(",
"$",
"request",
")",
";",
"}",
"}",
"if",
"(",
"$",
"json_request_str",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"encryption_key",
")",
")",
"{",
"$",
"json_request_str",
"=",
"$",
"this",
"->",
"encryptor",
"->",
"decrypt",
"(",
"$",
"json_request_str",
")",
";",
"}",
"}",
"$",
"request",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Request",
"(",
"$",
"json_request_str",
")",
";",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"request",
")",
")",
"{",
"$",
"response",
"->",
"error",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Error",
"(",
"-",
"32700",
",",
"'Parse Error'",
",",
"\"Data Received: \"",
".",
"$",
"json_request_str",
")",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"id",
"=",
"$",
"request",
"->",
"id",
";",
"}",
"//log the incoming request",
"$",
"this",
"->",
"logRequest",
"(",
"$",
"json_request_str",
")",
";",
"$",
"servable",
"=",
"false",
";",
"$",
"servedClass",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"served_classes",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"\\",
"method_exists",
"(",
"$",
"class",
",",
"$",
"request",
"->",
"method",
")",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"$",
"request",
"->",
"method",
")",
";",
"if",
"(",
"$",
"class",
"==",
"$",
"this",
")",
"{",
"//check for phpdocs",
"$",
"docs",
"=",
"$",
"reflection",
"->",
"getDocComment",
"(",
")",
";",
"$",
"non_rpc",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"docs",
")",
")",
"{",
"if",
"(",
"\\",
"preg_match",
"(",
"\"~@servable (true|false)~\"",
",",
"$",
"docs",
",",
"$",
"match",
")",
")",
"{",
"$",
"servable",
"=",
"$",
"match",
"[",
"1",
"]",
"==",
"'true'",
"?",
"true",
":",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"servable",
"=",
"$",
"reflection",
"->",
"isPublic",
"(",
")",
";",
"}",
"if",
"(",
"$",
"servable",
")",
"{",
"$",
"servedClass",
"=",
"$",
"class",
";",
"break",
";",
"}",
"}",
"}",
"//check for requested remote procedure",
"if",
"(",
"$",
"servedClass",
")",
"{",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"request",
"->",
"params",
")",
")",
"{",
"$",
"answer",
"=",
"\\",
"call_user_func",
"(",
"Array",
"(",
"$",
"servedClass",
",",
"$",
"request",
"->",
"method",
")",
",",
"$",
"request",
"->",
"params",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"request",
"->",
"params",
")",
")",
"{",
"$",
"request",
"->",
"params",
"=",
"Array",
"(",
")",
";",
"}",
"$",
"answer",
"=",
"\\",
"call_user_func_array",
"(",
"Array",
"(",
"$",
"servedClass",
",",
"$",
"request",
"->",
"method",
")",
",",
"$",
"request",
"->",
"params",
")",
";",
"}",
"//if they return an error from the method call, return that",
"if",
"(",
"$",
"answer",
"instanceof",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Error",
")",
"{",
"$",
"response",
"->",
"error",
"=",
"$",
"answer",
";",
"}",
"else",
"{",
"//otherwise return the answer",
"$",
"response",
"->",
"result",
"=",
"$",
"answer",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"request",
"->",
"error",
")",
"&&",
"$",
"request",
"->",
"error",
"instanceOf",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Error",
")",
"{",
"$",
"response",
"->",
"error",
"=",
"$",
"request",
"->",
"error",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"error",
"=",
"new",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Error",
"(",
")",
";",
"$",
"response",
"->",
"error",
"->",
"code",
"=",
"-",
"32601",
";",
"$",
"response",
"->",
"error",
"->",
"message",
"=",
"\"Procedure not found\"",
";",
"}",
"}",
"//remove unnecessary properties",
"if",
"(",
"$",
"response",
"->",
"error",
"instanceof",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Error",
")",
"{",
"unset",
"(",
"$",
"response",
"->",
"result",
")",
";",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"response",
"->",
"error",
"->",
"data",
")",
")",
"{",
"unset",
"(",
"$",
"response",
"->",
"error",
"->",
"data",
")",
";",
"}",
"}",
"else",
"{",
"unset",
"(",
"$",
"response",
"->",
"error",
")",
";",
"}",
"//log the final response",
"$",
"this",
"->",
"logResponse",
"(",
"json_encode",
"(",
"$",
"response",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Parses the request
@param $json_request_str | [
"Parses",
"the",
"request"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/JSON/RPC2/Server.php#L243-L367 |
surebert/surebert-framework | src/sb/Controller/JSON/RPC2/Server.php | Server.render | public function render()
{
$args = \func_get_args();
$json_request_str = isset($args[0]) ? $args[0] : '';
if ($this->onBeforeRender() !== false) {
$response = $this->getResponse($json_request_str);
$message = 'OK';
$status = 200;
//headers from spec here http://json-rpc.googlegroups.com/web/json-rpc-over-http.html
if (isset($response->error) && $response->error instanceof \sb\JSON\RPC2\Error) {
$code = $response->error->code;
if (\in_array($code, Array(-32700, -3260, -32603))
|| ($code <= -32000 && $code >= -32099)) {
$status = 500;
$message = 'Internal Server Error';
} elseif ($code == -32600) {
$message = 'Bad Request';
$status = 400;
} elseif ($code == -32601) {
$override = $this->notFound();
if (!\is_null($override)) {
return $override;
}
$message = 'Not Found';
$status = 404;
}
}
if (!$this->suppress_http_status) {
header("Content-Type: application/json-rpc");
header("HTTP/1.1 " . $status . " " . $message);
}
//serialize PHP to preserve format of hashes if client requests it in headers
if ($this->php_serialize_response) {
$json_response = \serialize($response);
} else {
$json_response = \json_encode($response);
}
if (!empty($this->encryption_key)) {
$json_response = $this->encryptor->encrypt($json_response);
}
if ($this->gz_encode_level !== false) {
$json_response = \gzencode($json_response, $this->gz_encode_level);
}
return $this->filterOutput($json_response);
}
} | php | public function render()
{
$args = \func_get_args();
$json_request_str = isset($args[0]) ? $args[0] : '';
if ($this->onBeforeRender() !== false) {
$response = $this->getResponse($json_request_str);
$message = 'OK';
$status = 200;
//headers from spec here http://json-rpc.googlegroups.com/web/json-rpc-over-http.html
if (isset($response->error) && $response->error instanceof \sb\JSON\RPC2\Error) {
$code = $response->error->code;
if (\in_array($code, Array(-32700, -3260, -32603))
|| ($code <= -32000 && $code >= -32099)) {
$status = 500;
$message = 'Internal Server Error';
} elseif ($code == -32600) {
$message = 'Bad Request';
$status = 400;
} elseif ($code == -32601) {
$override = $this->notFound();
if (!\is_null($override)) {
return $override;
}
$message = 'Not Found';
$status = 404;
}
}
if (!$this->suppress_http_status) {
header("Content-Type: application/json-rpc");
header("HTTP/1.1 " . $status . " " . $message);
}
//serialize PHP to preserve format of hashes if client requests it in headers
if ($this->php_serialize_response) {
$json_response = \serialize($response);
} else {
$json_response = \json_encode($response);
}
if (!empty($this->encryption_key)) {
$json_response = $this->encryptor->encrypt($json_response);
}
if ($this->gz_encode_level !== false) {
$json_response = \gzencode($json_response, $this->gz_encode_level);
}
return $this->filterOutput($json_response);
}
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"$",
"json_request_str",
"=",
"isset",
"(",
"$",
"args",
"[",
"0",
"]",
")",
"?",
"$",
"args",
"[",
"0",
"]",
":",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"onBeforeRender",
"(",
")",
"!==",
"false",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getResponse",
"(",
"$",
"json_request_str",
")",
";",
"$",
"message",
"=",
"'OK'",
";",
"$",
"status",
"=",
"200",
";",
"//headers from spec here http://json-rpc.googlegroups.com/web/json-rpc-over-http.html",
"if",
"(",
"isset",
"(",
"$",
"response",
"->",
"error",
")",
"&&",
"$",
"response",
"->",
"error",
"instanceof",
"\\",
"sb",
"\\",
"JSON",
"\\",
"RPC2",
"\\",
"Error",
")",
"{",
"$",
"code",
"=",
"$",
"response",
"->",
"error",
"->",
"code",
";",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"code",
",",
"Array",
"(",
"-",
"32700",
",",
"-",
"3260",
",",
"-",
"32603",
")",
")",
"||",
"(",
"$",
"code",
"<=",
"-",
"32000",
"&&",
"$",
"code",
">=",
"-",
"32099",
")",
")",
"{",
"$",
"status",
"=",
"500",
";",
"$",
"message",
"=",
"'Internal Server Error'",
";",
"}",
"elseif",
"(",
"$",
"code",
"==",
"-",
"32600",
")",
"{",
"$",
"message",
"=",
"'Bad Request'",
";",
"$",
"status",
"=",
"400",
";",
"}",
"elseif",
"(",
"$",
"code",
"==",
"-",
"32601",
")",
"{",
"$",
"override",
"=",
"$",
"this",
"->",
"notFound",
"(",
")",
";",
"if",
"(",
"!",
"\\",
"is_null",
"(",
"$",
"override",
")",
")",
"{",
"return",
"$",
"override",
";",
"}",
"$",
"message",
"=",
"'Not Found'",
";",
"$",
"status",
"=",
"404",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"suppress_http_status",
")",
"{",
"header",
"(",
"\"Content-Type: application/json-rpc\"",
")",
";",
"header",
"(",
"\"HTTP/1.1 \"",
".",
"$",
"status",
".",
"\" \"",
".",
"$",
"message",
")",
";",
"}",
"//serialize PHP to preserve format of hashes if client requests it in headers",
"if",
"(",
"$",
"this",
"->",
"php_serialize_response",
")",
"{",
"$",
"json_response",
"=",
"\\",
"serialize",
"(",
"$",
"response",
")",
";",
"}",
"else",
"{",
"$",
"json_response",
"=",
"\\",
"json_encode",
"(",
"$",
"response",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"encryption_key",
")",
")",
"{",
"$",
"json_response",
"=",
"$",
"this",
"->",
"encryptor",
"->",
"encrypt",
"(",
"$",
"json_response",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"gz_encode_level",
"!==",
"false",
")",
"{",
"$",
"json_response",
"=",
"\\",
"gzencode",
"(",
"$",
"json_response",
",",
"$",
"this",
"->",
"gz_encode_level",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filterOutput",
"(",
"$",
"json_response",
")",
";",
"}",
"}"
] | Serves data based on the json_request if set, otherwise based on
\sb\Gateway::$cmd_options['json_request']
Had to remove default args being listed to prevent
"should be compatible with that of" when using autoload,
kept them in phpdoc to make it known which exist
@param $json_request_str String This optional argument can be used
for debugging the server. A \sb\JSON\RPC2_Request formatted JSON string
e.g. {"method":"add","params":[1,2],"id":"abc123"}
@return string JSON encoded \sb\JSON\RPC2_Response | [
"Serves",
"data",
"based",
"on",
"the",
"json_request",
"if",
"set",
"otherwise",
"based",
"on",
"\\",
"sb",
"\\",
"Gateway",
"::",
"$cmd_options",
"[",
"json_request",
"]",
"Had",
"to",
"remove",
"default",
"args",
"being",
"listed",
"to",
"prevent",
"should",
"be",
"compatible",
"with",
"that",
"of",
"when",
"using",
"autoload",
"kept",
"them",
"in",
"phpdoc",
"to",
"make",
"it",
"known",
"which",
"exist"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/JSON/RPC2/Server.php#L381-L437 |
surebert/surebert-framework | src/sb/Controller/JSON/RPC2/Server.php | Server.notFound | public function notFound()
{
if (isset($this->request->path_array[1])) {
switch ($this->request->path_array[1]) {
case 'methods':
return $this->getMethods(true);
break;
}
}
return null;
} | php | public function notFound()
{
if (isset($this->request->path_array[1])) {
switch ($this->request->path_array[1]) {
case 'methods':
return $this->getMethods(true);
break;
}
}
return null;
} | [
"public",
"function",
"notFound",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"request",
"->",
"path_array",
"[",
"1",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"request",
"->",
"path_array",
"[",
"1",
"]",
")",
"{",
"case",
"'methods'",
":",
"return",
"$",
"this",
"->",
"getMethods",
"(",
"true",
")",
";",
"break",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | If this returns null when method not found, then deault JSON error object
is returned. Otherwise, the string or object returned from notFound is returned.
Will also server get_methods/methods as HTML list of available calls
@return type | [
"If",
"this",
"returns",
"null",
"when",
"method",
"not",
"found",
"then",
"deault",
"JSON",
"error",
"object",
"is",
"returned",
".",
"Otherwise",
"the",
"string",
"or",
"object",
"returned",
"from",
"notFound",
"is",
"returned",
".",
"Will",
"also",
"server",
"get_methods",
"/",
"methods",
"as",
"HTML",
"list",
"of",
"available",
"calls"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/JSON/RPC2/Server.php#L445-L456 |
primipilus/fileinfo | src/BaseInfo.php | BaseInfo.init | private function init(string $path)
{
$this->_path = $path;
if (!file_exists($this->_path)) {
throw new FileNotExistsException('file ' . $this->_path . ' not exists');
}
$type = FileTool::type($this->_path);
if ('file' !== $type) {
throw new NotFileException('type of ' . $this->_path . ' is ' . $type . ' (not file)');
}
} | php | private function init(string $path)
{
$this->_path = $path;
if (!file_exists($this->_path)) {
throw new FileNotExistsException('file ' . $this->_path . ' not exists');
}
$type = FileTool::type($this->_path);
if ('file' !== $type) {
throw new NotFileException('type of ' . $this->_path . ' is ' . $type . ' (not file)');
}
} | [
"private",
"function",
"init",
"(",
"string",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"_path",
"=",
"$",
"path",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"_path",
")",
")",
"{",
"throw",
"new",
"FileNotExistsException",
"(",
"'file '",
".",
"$",
"this",
"->",
"_path",
".",
"' not exists'",
")",
";",
"}",
"$",
"type",
"=",
"FileTool",
"::",
"type",
"(",
"$",
"this",
"->",
"_path",
")",
";",
"if",
"(",
"'file'",
"!==",
"$",
"type",
")",
"{",
"throw",
"new",
"NotFileException",
"(",
"'type of '",
".",
"$",
"this",
"->",
"_path",
".",
"' is '",
".",
"$",
"type",
".",
"' (not file)'",
")",
";",
"}",
"}"
] | @param string $path
@throws FileNotExistsException
@throws NotFileException | [
"@param",
"string",
"$path"
] | train | https://github.com/primipilus/fileinfo/blob/734fd25b3dfd3b0706f9ef07499663578c0fa56e/src/BaseInfo.php#L49-L61 |
ClementIV/yii-rest-rbac2.0 | controllers/AssignmentController.php | AssignmentController.actionIndex | public function actionIndex()
{
$request = \Yii::$app->request;
if ($request->getIsOptions()) {
return $this->ResponseOptions($this->verbs()['index']);
}
try{
if ($this->searchClass === null) {
$searchModel = new AssignmentSearch;
$dataProvider = $searchModel->search(Yii::$app->getRequest()->getQueryParams(), $this->userClassName, $this->usernameField);
//var_dump(Yii::$app->getRequest()->getQueryParams());die();
} else {
$class = $this->searchClass;
$searchModel = new $class;
$dataProvider = $searchModel->search(Yii::$app->getRequest()->getQueryParams());
}
//
return $dataProvider;
} catch(Exception $e){
throw new Exception($e);
}
} | php | public function actionIndex()
{
$request = \Yii::$app->request;
if ($request->getIsOptions()) {
return $this->ResponseOptions($this->verbs()['index']);
}
try{
if ($this->searchClass === null) {
$searchModel = new AssignmentSearch;
$dataProvider = $searchModel->search(Yii::$app->getRequest()->getQueryParams(), $this->userClassName, $this->usernameField);
//var_dump(Yii::$app->getRequest()->getQueryParams());die();
} else {
$class = $this->searchClass;
$searchModel = new $class;
$dataProvider = $searchModel->search(Yii::$app->getRequest()->getQueryParams());
}
//
return $dataProvider;
} catch(Exception $e){
throw new Exception($e);
}
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"$",
"request",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"request",
";",
"if",
"(",
"$",
"request",
"->",
"getIsOptions",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"ResponseOptions",
"(",
"$",
"this",
"->",
"verbs",
"(",
")",
"[",
"'index'",
"]",
")",
";",
"}",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"searchClass",
"===",
"null",
")",
"{",
"$",
"searchModel",
"=",
"new",
"AssignmentSearch",
";",
"$",
"dataProvider",
"=",
"$",
"searchModel",
"->",
"search",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"getQueryParams",
"(",
")",
",",
"$",
"this",
"->",
"userClassName",
",",
"$",
"this",
"->",
"usernameField",
")",
";",
"//var_dump(Yii::$app->getRequest()->getQueryParams());die();",
"}",
"else",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"searchClass",
";",
"$",
"searchModel",
"=",
"new",
"$",
"class",
";",
"$",
"dataProvider",
"=",
"$",
"searchModel",
"->",
"search",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"getQueryParams",
"(",
")",
")",
";",
"}",
"//",
"return",
"$",
"dataProvider",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"e",
")",
";",
"}",
"}"
] | Lists all Assignment models.
@return mixed | [
"Lists",
"all",
"Assignment",
"models",
"."
] | train | https://github.com/ClementIV/yii-rest-rbac2.0/blob/435ffceca8d51b4d369182db3a06c20f336e9ac4/controllers/AssignmentController.php#L66-L89 |
ClementIV/yii-rest-rbac2.0 | controllers/AssignmentController.php | AssignmentController.actionAssign | public function actionAssign($id)
{
$request = \Yii::$app->request;
if ($request->getIsOptions()) {
return $this->ResponseOptions($this->verbs()['assign']);
}
try{
$items = Yii::$app->getRequest()->post('items', []);
$model = new Assignment($id);
$success = $model->assign($items);
Yii::$app->getResponse()->format = 'json';
return array_merge($model->getItems(), ['success' => $success]);
}catch(Exception $e){
throw new Exception($e);
}
} | php | public function actionAssign($id)
{
$request = \Yii::$app->request;
if ($request->getIsOptions()) {
return $this->ResponseOptions($this->verbs()['assign']);
}
try{
$items = Yii::$app->getRequest()->post('items', []);
$model = new Assignment($id);
$success = $model->assign($items);
Yii::$app->getResponse()->format = 'json';
return array_merge($model->getItems(), ['success' => $success]);
}catch(Exception $e){
throw new Exception($e);
}
} | [
"public",
"function",
"actionAssign",
"(",
"$",
"id",
")",
"{",
"$",
"request",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"request",
";",
"if",
"(",
"$",
"request",
"->",
"getIsOptions",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"ResponseOptions",
"(",
"$",
"this",
"->",
"verbs",
"(",
")",
"[",
"'assign'",
"]",
")",
";",
"}",
"try",
"{",
"$",
"items",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"post",
"(",
"'items'",
",",
"[",
"]",
")",
";",
"$",
"model",
"=",
"new",
"Assignment",
"(",
"$",
"id",
")",
";",
"$",
"success",
"=",
"$",
"model",
"->",
"assign",
"(",
"$",
"items",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
"->",
"format",
"=",
"'json'",
";",
"return",
"array_merge",
"(",
"$",
"model",
"->",
"getItems",
"(",
")",
",",
"[",
"'success'",
"=>",
"$",
"success",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"e",
")",
";",
"}",
"}"
] | Assign items
@param string $id
@return array | [
"Assign",
"items"
] | train | https://github.com/ClementIV/yii-rest-rbac2.0/blob/435ffceca8d51b4d369182db3a06c20f336e9ac4/controllers/AssignmentController.php#L140-L156 |
ShaoZeMing/laravel-merchant | src/Controllers/MenuController.php | MenuController.form | public function form()
{
return Menu::form(function (Form $form) {
$form->display('id', 'ID');
$form->select('parent_id', trans('merchant.parent_id'))->options(Menu::selectOptions());
$form->text('title', trans('merchant.title'))->rules('required');
$form->icon('icon', trans('merchant.icon'))->default('fa-bars')->rules('required')->help($this->iconHelp());
$form->text('uri', trans('merchant.uri'));
$form->multipleSelect('roles', trans('merchant.roles'))->options(Role::all()->pluck('name', 'id'));
$form->display('created_at', trans('merchant.created_at'));
$form->display('updated_at', trans('merchant.updated_at'));
});
} | php | public function form()
{
return Menu::form(function (Form $form) {
$form->display('id', 'ID');
$form->select('parent_id', trans('merchant.parent_id'))->options(Menu::selectOptions());
$form->text('title', trans('merchant.title'))->rules('required');
$form->icon('icon', trans('merchant.icon'))->default('fa-bars')->rules('required')->help($this->iconHelp());
$form->text('uri', trans('merchant.uri'));
$form->multipleSelect('roles', trans('merchant.roles'))->options(Role::all()->pluck('name', 'id'));
$form->display('created_at', trans('merchant.created_at'));
$form->display('updated_at', trans('merchant.updated_at'));
});
} | [
"public",
"function",
"form",
"(",
")",
"{",
"return",
"Menu",
"::",
"form",
"(",
"function",
"(",
"Form",
"$",
"form",
")",
"{",
"$",
"form",
"->",
"display",
"(",
"'id'",
",",
"'ID'",
")",
";",
"$",
"form",
"->",
"select",
"(",
"'parent_id'",
",",
"trans",
"(",
"'merchant.parent_id'",
")",
")",
"->",
"options",
"(",
"Menu",
"::",
"selectOptions",
"(",
")",
")",
";",
"$",
"form",
"->",
"text",
"(",
"'title'",
",",
"trans",
"(",
"'merchant.title'",
")",
")",
"->",
"rules",
"(",
"'required'",
")",
";",
"$",
"form",
"->",
"icon",
"(",
"'icon'",
",",
"trans",
"(",
"'merchant.icon'",
")",
")",
"->",
"default",
"(",
"'fa-bars'",
")",
"->",
"rules",
"(",
"'required'",
")",
"->",
"help",
"(",
"$",
"this",
"->",
"iconHelp",
"(",
")",
")",
";",
"$",
"form",
"->",
"text",
"(",
"'uri'",
",",
"trans",
"(",
"'merchant.uri'",
")",
")",
";",
"$",
"form",
"->",
"multipleSelect",
"(",
"'roles'",
",",
"trans",
"(",
"'merchant.roles'",
")",
")",
"->",
"options",
"(",
"Role",
"::",
"all",
"(",
")",
"->",
"pluck",
"(",
"'name'",
",",
"'id'",
")",
")",
";",
"$",
"form",
"->",
"display",
"(",
"'created_at'",
",",
"trans",
"(",
"'merchant.created_at'",
")",
")",
";",
"$",
"form",
"->",
"display",
"(",
"'updated_at'",
",",
"trans",
"(",
"'merchant.updated_at'",
")",
")",
";",
"}",
")",
";",
"}"
] | Make a form builder.
@return Form | [
"Make",
"a",
"form",
"builder",
"."
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Controllers/MenuController.php#L110-L124 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.type2format | private function type2format( $type ) {
if ( ! isset( self::$_type2format[ $type ] ) ) {
$format = '%s';
switch ( true ) {
case stristr( $type, 'INT' ) !== false:
$format = '%d';
break;
case stristr( $type, 'BIT' ) !== false:
$format = '%d';
break;
case stristr( $type, 'BOOLEAN' ) !== false:
$format = '%d';
break;
case stristr( $type, 'DECIMAL' ) !== false:
$format = '%f';
break;
case stristr( $type, 'FLOAT' ) !== false:
$format = '%f';
break;
case stristr( $type, 'DOUBLE' ) !== false:
$format = '%f';
break;
case stristr( $type, 'REAL' ) !== false:
$format = '%f';
break;
}
self::$_type2format[ $type ] = $this->apply_filters( 'type2format', $format, $type );
}
return self::$_type2format[ $type ];
} | php | private function type2format( $type ) {
if ( ! isset( self::$_type2format[ $type ] ) ) {
$format = '%s';
switch ( true ) {
case stristr( $type, 'INT' ) !== false:
$format = '%d';
break;
case stristr( $type, 'BIT' ) !== false:
$format = '%d';
break;
case stristr( $type, 'BOOLEAN' ) !== false:
$format = '%d';
break;
case stristr( $type, 'DECIMAL' ) !== false:
$format = '%f';
break;
case stristr( $type, 'FLOAT' ) !== false:
$format = '%f';
break;
case stristr( $type, 'DOUBLE' ) !== false:
$format = '%f';
break;
case stristr( $type, 'REAL' ) !== false:
$format = '%f';
break;
}
self::$_type2format[ $type ] = $this->apply_filters( 'type2format', $format, $type );
}
return self::$_type2format[ $type ];
} | [
"private",
"function",
"type2format",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_type2format",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"format",
"=",
"'%s'",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"stristr",
"(",
"$",
"type",
",",
"'INT'",
")",
"!==",
"false",
":",
"$",
"format",
"=",
"'%d'",
";",
"break",
";",
"case",
"stristr",
"(",
"$",
"type",
",",
"'BIT'",
")",
"!==",
"false",
":",
"$",
"format",
"=",
"'%d'",
";",
"break",
";",
"case",
"stristr",
"(",
"$",
"type",
",",
"'BOOLEAN'",
")",
"!==",
"false",
":",
"$",
"format",
"=",
"'%d'",
";",
"break",
";",
"case",
"stristr",
"(",
"$",
"type",
",",
"'DECIMAL'",
")",
"!==",
"false",
":",
"$",
"format",
"=",
"'%f'",
";",
"break",
";",
"case",
"stristr",
"(",
"$",
"type",
",",
"'FLOAT'",
")",
"!==",
"false",
":",
"$",
"format",
"=",
"'%f'",
";",
"break",
";",
"case",
"stristr",
"(",
"$",
"type",
",",
"'DOUBLE'",
")",
"!==",
"false",
":",
"$",
"format",
"=",
"'%f'",
";",
"break",
";",
"case",
"stristr",
"(",
"$",
"type",
",",
"'REAL'",
")",
"!==",
"false",
":",
"$",
"format",
"=",
"'%f'",
";",
"break",
";",
"}",
"self",
"::",
"$",
"_type2format",
"[",
"$",
"type",
"]",
"=",
"$",
"this",
"->",
"apply_filters",
"(",
"'type2format'",
",",
"$",
"format",
",",
"$",
"type",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_type2format",
"[",
"$",
"type",
"]",
";",
"}"
] | @since 2.0.0 Added: Feature to cache result of conversion type format
@param string $type
@return string | [
"@since",
"2",
".",
"0",
".",
"0",
"Added",
":",
"Feature",
"to",
"cache",
"result",
"of",
"conversion",
"type",
"format"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L78-L108 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.load_table_defines | private function load_table_defines() {
if ( ! $this->need_to_update() ) {
$cache = $this->app->get_option( 'table_defines_cache' );
if ( is_array( $cache ) ) {
$this->table_defines = $cache;
return;
}
}
$this->table_defines = $this->app->config->load( 'db' );
empty( $this->table_defines ) and $this->table_defines = [];
foreach ( $this->table_defines as $table => $define ) {
list( $id, $columns ) = $this->setup_table_columns( $table, $define );
if ( empty( $id ) ) {
continue;
}
$this->table_defines[ $table ]['id'] = $id;
$this->table_defines[ $table ]['columns'] = $columns;
$this->table_defines[ $table ]['is_added'] = true;
if ( ! empty( $this->table_defines[ $table ]['comment'] ) ) {
$this->table_defines[ $table ]['comment'] = $this->app->translate( $this->table_defines[ $table ]['comment'] );
}
}
$this->app->option->set( 'table_defines_cache', $this->table_defines );
} | php | private function load_table_defines() {
if ( ! $this->need_to_update() ) {
$cache = $this->app->get_option( 'table_defines_cache' );
if ( is_array( $cache ) ) {
$this->table_defines = $cache;
return;
}
}
$this->table_defines = $this->app->config->load( 'db' );
empty( $this->table_defines ) and $this->table_defines = [];
foreach ( $this->table_defines as $table => $define ) {
list( $id, $columns ) = $this->setup_table_columns( $table, $define );
if ( empty( $id ) ) {
continue;
}
$this->table_defines[ $table ]['id'] = $id;
$this->table_defines[ $table ]['columns'] = $columns;
$this->table_defines[ $table ]['is_added'] = true;
if ( ! empty( $this->table_defines[ $table ]['comment'] ) ) {
$this->table_defines[ $table ]['comment'] = $this->app->translate( $this->table_defines[ $table ]['comment'] );
}
}
$this->app->option->set( 'table_defines_cache', $this->table_defines );
} | [
"private",
"function",
"load_table_defines",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"need_to_update",
"(",
")",
")",
"{",
"$",
"cache",
"=",
"$",
"this",
"->",
"app",
"->",
"get_option",
"(",
"'table_defines_cache'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"cache",
")",
")",
"{",
"$",
"this",
"->",
"table_defines",
"=",
"$",
"cache",
";",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"table_defines",
"=",
"$",
"this",
"->",
"app",
"->",
"config",
"->",
"load",
"(",
"'db'",
")",
";",
"empty",
"(",
"$",
"this",
"->",
"table_defines",
")",
"and",
"$",
"this",
"->",
"table_defines",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"table_defines",
"as",
"$",
"table",
"=>",
"$",
"define",
")",
"{",
"list",
"(",
"$",
"id",
",",
"$",
"columns",
")",
"=",
"$",
"this",
"->",
"setup_table_columns",
"(",
"$",
"table",
",",
"$",
"define",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'id'",
"]",
"=",
"$",
"id",
";",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'columns'",
"]",
"=",
"$",
"columns",
";",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'is_added'",
"]",
"=",
"true",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'comment'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'comment'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"translate",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'comment'",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"app",
"->",
"option",
"->",
"set",
"(",
"'table_defines_cache'",
",",
"$",
"this",
"->",
"table_defines",
")",
";",
"}"
] | load | [
"load"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L113-L139 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.setup_table_columns | protected function setup_table_columns( $table, $define ) {
if ( empty( $define['columns'] ) ) {
return [ false, false ];
}
$id = $table . '_id';
if ( ! empty( $define['id'] ) ) {
$id = $define['id'];
}
$columns = [];
$columns['id'] = [
'name' => $id,
'type' => 'bigint(20)',
'unsigned' => true,
'null' => false,
'format' => '%d',
];
$check = true;
foreach ( $define['columns'] as $key => $column ) {
if ( ! is_array( $column ) ) {
$check = false;
break;
}
$type = trim( $this->app->utility->array_get( $column, 'type' ) );
if ( empty( $type ) ) {
$check = false;
break;
}
$column['name'] = $this->app->utility->array_get( $column, 'name', $key );
$column['format'] = $this->app->utility->array_get( $column, 'format', $this->type2format( $type ) );
$column['length'] = null;
if ( preg_match( '/\(\s*(\d+)\s*\)/', $type, $matches ) ) {
$column['length'] = $matches[1] - 0;
}
$column['is_user_defined'] = true;
if ( ! empty( $column['comment'] ) ) {
$column['comment'] = $this->app->translate( $column['comment'] );
}
$columns[ $key ] = $column;
}
if ( ! $check ) {
return [ false, false ];
}
$columns['created_at'] = [
'name' => 'created_at',
'type' => 'datetime',
'null' => false,
'format' => '%s',
'only_admin' => true,
];
$columns['created_by'] = [
'name' => 'created_by',
'type' => 'varchar(32)',
'null' => false,
'format' => '%s',
'only_admin' => true,
];
$columns['updated_at'] = [
'name' => 'updated_at',
'type' => 'datetime',
'null' => false,
'format' => '%s',
'only_admin' => true,
];
$columns['updated_by'] = [
'name' => 'updated_by',
'type' => 'varchar(32)',
'null' => false,
'format' => '%s',
'only_admin' => true,
];
if ( $this->is_logical( $define ) ) {
$columns['deleted_at'] = [
'name' => 'deleted_at',
'type' => 'datetime',
'format' => '%s',
'only_admin' => true,
];
$columns['deleted_by'] = [
'name' => 'deleted_by',
'type' => 'varchar(32)',
'format' => '%s',
'only_admin' => true,
];
}
return $this->apply_filters( 'setup_table_columns', [ $id, $columns ], $table, $define, $id, $columns );
} | php | protected function setup_table_columns( $table, $define ) {
if ( empty( $define['columns'] ) ) {
return [ false, false ];
}
$id = $table . '_id';
if ( ! empty( $define['id'] ) ) {
$id = $define['id'];
}
$columns = [];
$columns['id'] = [
'name' => $id,
'type' => 'bigint(20)',
'unsigned' => true,
'null' => false,
'format' => '%d',
];
$check = true;
foreach ( $define['columns'] as $key => $column ) {
if ( ! is_array( $column ) ) {
$check = false;
break;
}
$type = trim( $this->app->utility->array_get( $column, 'type' ) );
if ( empty( $type ) ) {
$check = false;
break;
}
$column['name'] = $this->app->utility->array_get( $column, 'name', $key );
$column['format'] = $this->app->utility->array_get( $column, 'format', $this->type2format( $type ) );
$column['length'] = null;
if ( preg_match( '/\(\s*(\d+)\s*\)/', $type, $matches ) ) {
$column['length'] = $matches[1] - 0;
}
$column['is_user_defined'] = true;
if ( ! empty( $column['comment'] ) ) {
$column['comment'] = $this->app->translate( $column['comment'] );
}
$columns[ $key ] = $column;
}
if ( ! $check ) {
return [ false, false ];
}
$columns['created_at'] = [
'name' => 'created_at',
'type' => 'datetime',
'null' => false,
'format' => '%s',
'only_admin' => true,
];
$columns['created_by'] = [
'name' => 'created_by',
'type' => 'varchar(32)',
'null' => false,
'format' => '%s',
'only_admin' => true,
];
$columns['updated_at'] = [
'name' => 'updated_at',
'type' => 'datetime',
'null' => false,
'format' => '%s',
'only_admin' => true,
];
$columns['updated_by'] = [
'name' => 'updated_by',
'type' => 'varchar(32)',
'null' => false,
'format' => '%s',
'only_admin' => true,
];
if ( $this->is_logical( $define ) ) {
$columns['deleted_at'] = [
'name' => 'deleted_at',
'type' => 'datetime',
'format' => '%s',
'only_admin' => true,
];
$columns['deleted_by'] = [
'name' => 'deleted_by',
'type' => 'varchar(32)',
'format' => '%s',
'only_admin' => true,
];
}
return $this->apply_filters( 'setup_table_columns', [ $id, $columns ], $table, $define, $id, $columns );
} | [
"protected",
"function",
"setup_table_columns",
"(",
"$",
"table",
",",
"$",
"define",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"define",
"[",
"'columns'",
"]",
")",
")",
"{",
"return",
"[",
"false",
",",
"false",
"]",
";",
"}",
"$",
"id",
"=",
"$",
"table",
".",
"'_id'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"define",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"id",
"=",
"$",
"define",
"[",
"'id'",
"]",
";",
"}",
"$",
"columns",
"=",
"[",
"]",
";",
"$",
"columns",
"[",
"'id'",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"id",
",",
"'type'",
"=>",
"'bigint(20)'",
",",
"'unsigned'",
"=>",
"true",
",",
"'null'",
"=>",
"false",
",",
"'format'",
"=>",
"'%d'",
",",
"]",
";",
"$",
"check",
"=",
"true",
";",
"foreach",
"(",
"$",
"define",
"[",
"'columns'",
"]",
"as",
"$",
"key",
"=>",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"$",
"check",
"=",
"false",
";",
"break",
";",
"}",
"$",
"type",
"=",
"trim",
"(",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'type'",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"$",
"check",
"=",
"false",
";",
"break",
";",
"}",
"$",
"column",
"[",
"'name'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'name'",
",",
"$",
"key",
")",
";",
"$",
"column",
"[",
"'format'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'format'",
",",
"$",
"this",
"->",
"type2format",
"(",
"$",
"type",
")",
")",
";",
"$",
"column",
"[",
"'length'",
"]",
"=",
"null",
";",
"if",
"(",
"preg_match",
"(",
"'/\\(\\s*(\\d+)\\s*\\)/'",
",",
"$",
"type",
",",
"$",
"matches",
")",
")",
"{",
"$",
"column",
"[",
"'length'",
"]",
"=",
"$",
"matches",
"[",
"1",
"]",
"-",
"0",
";",
"}",
"$",
"column",
"[",
"'is_user_defined'",
"]",
"=",
"true",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"column",
"[",
"'comment'",
"]",
")",
")",
"{",
"$",
"column",
"[",
"'comment'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"translate",
"(",
"$",
"column",
"[",
"'comment'",
"]",
")",
";",
"}",
"$",
"columns",
"[",
"$",
"key",
"]",
"=",
"$",
"column",
";",
"}",
"if",
"(",
"!",
"$",
"check",
")",
"{",
"return",
"[",
"false",
",",
"false",
"]",
";",
"}",
"$",
"columns",
"[",
"'created_at'",
"]",
"=",
"[",
"'name'",
"=>",
"'created_at'",
",",
"'type'",
"=>",
"'datetime'",
",",
"'null'",
"=>",
"false",
",",
"'format'",
"=>",
"'%s'",
",",
"'only_admin'",
"=>",
"true",
",",
"]",
";",
"$",
"columns",
"[",
"'created_by'",
"]",
"=",
"[",
"'name'",
"=>",
"'created_by'",
",",
"'type'",
"=>",
"'varchar(32)'",
",",
"'null'",
"=>",
"false",
",",
"'format'",
"=>",
"'%s'",
",",
"'only_admin'",
"=>",
"true",
",",
"]",
";",
"$",
"columns",
"[",
"'updated_at'",
"]",
"=",
"[",
"'name'",
"=>",
"'updated_at'",
",",
"'type'",
"=>",
"'datetime'",
",",
"'null'",
"=>",
"false",
",",
"'format'",
"=>",
"'%s'",
",",
"'only_admin'",
"=>",
"true",
",",
"]",
";",
"$",
"columns",
"[",
"'updated_by'",
"]",
"=",
"[",
"'name'",
"=>",
"'updated_by'",
",",
"'type'",
"=>",
"'varchar(32)'",
",",
"'null'",
"=>",
"false",
",",
"'format'",
"=>",
"'%s'",
",",
"'only_admin'",
"=>",
"true",
",",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"is_logical",
"(",
"$",
"define",
")",
")",
"{",
"$",
"columns",
"[",
"'deleted_at'",
"]",
"=",
"[",
"'name'",
"=>",
"'deleted_at'",
",",
"'type'",
"=>",
"'datetime'",
",",
"'format'",
"=>",
"'%s'",
",",
"'only_admin'",
"=>",
"true",
",",
"]",
";",
"$",
"columns",
"[",
"'deleted_by'",
"]",
"=",
"[",
"'name'",
"=>",
"'deleted_by'",
",",
"'type'",
"=>",
"'varchar(32)'",
",",
"'format'",
"=>",
"'%s'",
",",
"'only_admin'",
"=>",
"true",
",",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"apply_filters",
"(",
"'setup_table_columns'",
",",
"[",
"$",
"id",
",",
"$",
"columns",
"]",
",",
"$",
"table",
",",
"$",
"define",
",",
"$",
"id",
",",
"$",
"columns",
")",
";",
"}"
] | @param string $table
@param array $define
@return array | [
"@param",
"string",
"$table",
"@param",
"array",
"$define"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L223-L315 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.get_table | public function get_table( $table ) {
if (
! isset( $this->table_defines[ $table ] ) ||
! empty( $this->table_defines[ $table ]['wordpress'] ) ||
! empty( $this->table_defines[ $table ]['global'] )
) {
return $table;
}
return $this->get_table_prefix() . $table;
} | php | public function get_table( $table ) {
if (
! isset( $this->table_defines[ $table ] ) ||
! empty( $this->table_defines[ $table ]['wordpress'] ) ||
! empty( $this->table_defines[ $table ]['global'] )
) {
return $table;
}
return $this->get_table_prefix() . $table;
} | [
"public",
"function",
"get_table",
"(",
"$",
"table",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
"||",
"!",
"empty",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'wordpress'",
"]",
")",
"||",
"!",
"empty",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'global'",
"]",
")",
")",
"{",
"return",
"$",
"table",
";",
"}",
"return",
"$",
"this",
"->",
"get_table_prefix",
"(",
")",
".",
"$",
"table",
";",
"}"
] | @param $table
@return string | [
"@param",
"$table"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L331-L341 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.get_field | public function get_field( $table, $key ) {
return $this->app->utility->array_get( $this->app->utility->array_get( $this->get_columns( $table ), $key, [] ), 'name', $key );
} | php | public function get_field( $table, $key ) {
return $this->app->utility->array_get( $this->app->utility->array_get( $this->get_columns( $table ), $key, [] ), 'name', $key );
} | [
"public",
"function",
"get_field",
"(",
"$",
"table",
",",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"this",
"->",
"get_columns",
"(",
"$",
"table",
")",
",",
"$",
"key",
",",
"[",
"]",
")",
",",
"'name'",
",",
"$",
"key",
")",
";",
"}"
] | @param string $table
@param string $key
@return string | [
"@param",
"string",
"$table",
"@param",
"string",
"$key"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L349-L351 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.db_update | private function db_update() {
if ( ! $this->need_to_update() ) {
return;
}
$this->update_db_version();
if ( empty( $this->table_defines ) ) {
return;
}
set_time_limit( 60 * 5 );
foreach ( $this->table_defines as $table => $define ) {
$results = $this->table_update( $table, $define );
if ( $results ) {
$message = implode( '<br>', array_filter( $results, function ( $d ) {
return ! empty( $d );
} ) );
if ( $message ) {
$this->app->add_message( $message, 'db', false, false );
}
}
}
$this->do_action( 'db_updated' );
} | php | private function db_update() {
if ( ! $this->need_to_update() ) {
return;
}
$this->update_db_version();
if ( empty( $this->table_defines ) ) {
return;
}
set_time_limit( 60 * 5 );
foreach ( $this->table_defines as $table => $define ) {
$results = $this->table_update( $table, $define );
if ( $results ) {
$message = implode( '<br>', array_filter( $results, function ( $d ) {
return ! empty( $d );
} ) );
if ( $message ) {
$this->app->add_message( $message, 'db', false, false );
}
}
}
$this->do_action( 'db_updated' );
} | [
"private",
"function",
"db_update",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"need_to_update",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"update_db_version",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"table_defines",
")",
")",
"{",
"return",
";",
"}",
"set_time_limit",
"(",
"60",
"*",
"5",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"table_defines",
"as",
"$",
"table",
"=>",
"$",
"define",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"table_update",
"(",
"$",
"table",
",",
"$",
"define",
")",
";",
"if",
"(",
"$",
"results",
")",
"{",
"$",
"message",
"=",
"implode",
"(",
"'<br>'",
",",
"array_filter",
"(",
"$",
"results",
",",
"function",
"(",
"$",
"d",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"d",
")",
";",
"}",
")",
")",
";",
"if",
"(",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"add_message",
"(",
"$",
"message",
",",
"'db'",
",",
"false",
",",
"false",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"do_action",
"(",
"'db_updated'",
")",
";",
"}"
] | db update | [
"db",
"update"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L369-L394 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.table_update | protected function table_update( $table, $define ) {
require_once ABSPATH . "wp-admin" . DS . "includes" . DS . "upgrade.php";
$char = $this->app->utility->definedv( 'DB_CHARSET', 'utf8' );
if ( empty( $define['id'] ) ) {
$define['id'] = $table . '_id';
}
$table = $this->get_table( $table );
$sql = "CREATE TABLE {$table} (\n";
foreach ( $define['columns'] as $key => $column ) {
$name = $this->app->utility->array_get( $column, 'name' );
$type = $this->app->utility->array_get( $column, 'type' );
$unsigned = $this->app->utility->array_get( $column, 'unsigned', false );
$null = $this->app->utility->array_get( $column, 'null', true );
$default = $this->app->utility->array_get( $column, 'default', null );
$comment = $this->app->utility->array_get( $column, 'comment', '' );
$sql .= $name . ' ' . strtolower( $type );
if ( $unsigned ) {
$sql .= ' unsigned';
}
if ( $null ) {
$sql .= ' NULL';
} else {
$sql .= ' NOT NULL';
}
if ( $key === 'id' ) {
$sql .= ' AUTO_INCREMENT';
} elseif ( isset( $default ) ) {
$default = str_replace( '\'', '\\\'', $default );
$sql .= " DEFAULT '{$default}'";
}
if ( ! empty( $comment ) ) {
$comment = str_replace( '\'', '\\\'', $comment );
$sql .= " COMMENT '{$comment}'";
}
$sql .= ",\n";
}
$index = [];
$index[] = "PRIMARY KEY ({$define['columns']['id']['name']})";
if ( ! empty( $define['index']['key'] ) ) {
foreach ( $define['index']['key'] as $name => $columns ) {
if ( ! is_array( $columns ) ) {
$columns = [ $columns ];
}
$columns = implode( ', ', $columns );
$index[] = "INDEX {$name} ({$columns})";
}
}
if ( ! empty( $define['index']['unique'] ) ) {
foreach ( $define['index']['unique'] as $name => $columns ) {
if ( ! is_array( $columns ) ) {
$columns = [ $columns ];
}
$columns = implode( ', ', $columns );
$index[] = "UNIQUE KEY {$name} ({$columns})";
}
}
$sql .= implode( ",\n", $index );
$sql .= "\n) ENGINE = InnoDB DEFAULT CHARSET = {$char}";
if ( ! empty( $define['comment'] ) ) {
$define['comment'] = str_replace( '\'', '\\\'', $define['comment'] );
$sql .= " COMMENT '{$define['comment']}'";
}
$sql .= ';';
return dbDelta( $sql );
} | php | protected function table_update( $table, $define ) {
require_once ABSPATH . "wp-admin" . DS . "includes" . DS . "upgrade.php";
$char = $this->app->utility->definedv( 'DB_CHARSET', 'utf8' );
if ( empty( $define['id'] ) ) {
$define['id'] = $table . '_id';
}
$table = $this->get_table( $table );
$sql = "CREATE TABLE {$table} (\n";
foreach ( $define['columns'] as $key => $column ) {
$name = $this->app->utility->array_get( $column, 'name' );
$type = $this->app->utility->array_get( $column, 'type' );
$unsigned = $this->app->utility->array_get( $column, 'unsigned', false );
$null = $this->app->utility->array_get( $column, 'null', true );
$default = $this->app->utility->array_get( $column, 'default', null );
$comment = $this->app->utility->array_get( $column, 'comment', '' );
$sql .= $name . ' ' . strtolower( $type );
if ( $unsigned ) {
$sql .= ' unsigned';
}
if ( $null ) {
$sql .= ' NULL';
} else {
$sql .= ' NOT NULL';
}
if ( $key === 'id' ) {
$sql .= ' AUTO_INCREMENT';
} elseif ( isset( $default ) ) {
$default = str_replace( '\'', '\\\'', $default );
$sql .= " DEFAULT '{$default}'";
}
if ( ! empty( $comment ) ) {
$comment = str_replace( '\'', '\\\'', $comment );
$sql .= " COMMENT '{$comment}'";
}
$sql .= ",\n";
}
$index = [];
$index[] = "PRIMARY KEY ({$define['columns']['id']['name']})";
if ( ! empty( $define['index']['key'] ) ) {
foreach ( $define['index']['key'] as $name => $columns ) {
if ( ! is_array( $columns ) ) {
$columns = [ $columns ];
}
$columns = implode( ', ', $columns );
$index[] = "INDEX {$name} ({$columns})";
}
}
if ( ! empty( $define['index']['unique'] ) ) {
foreach ( $define['index']['unique'] as $name => $columns ) {
if ( ! is_array( $columns ) ) {
$columns = [ $columns ];
}
$columns = implode( ', ', $columns );
$index[] = "UNIQUE KEY {$name} ({$columns})";
}
}
$sql .= implode( ",\n", $index );
$sql .= "\n) ENGINE = InnoDB DEFAULT CHARSET = {$char}";
if ( ! empty( $define['comment'] ) ) {
$define['comment'] = str_replace( '\'', '\\\'', $define['comment'] );
$sql .= " COMMENT '{$define['comment']}'";
}
$sql .= ';';
return dbDelta( $sql );
} | [
"protected",
"function",
"table_update",
"(",
"$",
"table",
",",
"$",
"define",
")",
"{",
"require_once",
"ABSPATH",
".",
"\"wp-admin\"",
".",
"DS",
".",
"\"includes\"",
".",
"DS",
".",
"\"upgrade.php\"",
";",
"$",
"char",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"definedv",
"(",
"'DB_CHARSET'",
",",
"'utf8'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"define",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"define",
"[",
"'id'",
"]",
"=",
"$",
"table",
".",
"'_id'",
";",
"}",
"$",
"table",
"=",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
";",
"$",
"sql",
"=",
"\"CREATE TABLE {$table} (\\n\"",
";",
"foreach",
"(",
"$",
"define",
"[",
"'columns'",
"]",
"as",
"$",
"key",
"=>",
"$",
"column",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'name'",
")",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'type'",
")",
";",
"$",
"unsigned",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'unsigned'",
",",
"false",
")",
";",
"$",
"null",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'null'",
",",
"true",
")",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'default'",
",",
"null",
")",
";",
"$",
"comment",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'comment'",
",",
"''",
")",
";",
"$",
"sql",
".=",
"$",
"name",
".",
"' '",
".",
"strtolower",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"unsigned",
")",
"{",
"$",
"sql",
".=",
"' unsigned'",
";",
"}",
"if",
"(",
"$",
"null",
")",
"{",
"$",
"sql",
".=",
"' NULL'",
";",
"}",
"else",
"{",
"$",
"sql",
".=",
"' NOT NULL'",
";",
"}",
"if",
"(",
"$",
"key",
"===",
"'id'",
")",
"{",
"$",
"sql",
".=",
"' AUTO_INCREMENT'",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"default",
")",
")",
"{",
"$",
"default",
"=",
"str_replace",
"(",
"'\\''",
",",
"'\\\\\\''",
",",
"$",
"default",
")",
";",
"$",
"sql",
".=",
"\" DEFAULT '{$default}'\"",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"comment",
")",
")",
"{",
"$",
"comment",
"=",
"str_replace",
"(",
"'\\''",
",",
"'\\\\\\''",
",",
"$",
"comment",
")",
";",
"$",
"sql",
".=",
"\" COMMENT '{$comment}'\"",
";",
"}",
"$",
"sql",
".=",
"\",\\n\"",
";",
"}",
"$",
"index",
"=",
"[",
"]",
";",
"$",
"index",
"[",
"]",
"=",
"\"PRIMARY KEY ({$define['columns']['id']['name']})\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"define",
"[",
"'index'",
"]",
"[",
"'key'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"define",
"[",
"'index'",
"]",
"[",
"'key'",
"]",
"as",
"$",
"name",
"=>",
"$",
"columns",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"columns",
"=",
"[",
"$",
"columns",
"]",
";",
"}",
"$",
"columns",
"=",
"implode",
"(",
"', '",
",",
"$",
"columns",
")",
";",
"$",
"index",
"[",
"]",
"=",
"\"INDEX {$name} ({$columns})\"",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"define",
"[",
"'index'",
"]",
"[",
"'unique'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"define",
"[",
"'index'",
"]",
"[",
"'unique'",
"]",
"as",
"$",
"name",
"=>",
"$",
"columns",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"columns",
"=",
"[",
"$",
"columns",
"]",
";",
"}",
"$",
"columns",
"=",
"implode",
"(",
"', '",
",",
"$",
"columns",
")",
";",
"$",
"index",
"[",
"]",
"=",
"\"UNIQUE KEY {$name} ({$columns})\"",
";",
"}",
"}",
"$",
"sql",
".=",
"implode",
"(",
"\",\\n\"",
",",
"$",
"index",
")",
";",
"$",
"sql",
".=",
"\"\\n) ENGINE = InnoDB DEFAULT CHARSET = {$char}\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"define",
"[",
"'comment'",
"]",
")",
")",
"{",
"$",
"define",
"[",
"'comment'",
"]",
"=",
"str_replace",
"(",
"'\\''",
",",
"'\\\\\\''",
",",
"$",
"define",
"[",
"'comment'",
"]",
")",
";",
"$",
"sql",
".=",
"\" COMMENT '{$define['comment']}'\"",
";",
"}",
"$",
"sql",
".=",
"';'",
";",
"return",
"dbDelta",
"(",
"$",
"sql",
")",
";",
"}"
] | @param string $table
@param array $define
@return array | [
"@param",
"string",
"$table",
"@param",
"array",
"$define"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L402-L470 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.is_logical | private function is_logical( $define ) {
return $this->apply_filters( 'is_logical', 'physical' !== $this->app->utility->array_get( $define, 'delete', $this->app->get_config( 'config', 'default_delete_rule' ) ), $define );
} | php | private function is_logical( $define ) {
return $this->apply_filters( 'is_logical', 'physical' !== $this->app->utility->array_get( $define, 'delete', $this->app->get_config( 'config', 'default_delete_rule' ) ), $define );
} | [
"private",
"function",
"is_logical",
"(",
"$",
"define",
")",
"{",
"return",
"$",
"this",
"->",
"apply_filters",
"(",
"'is_logical'",
",",
"'physical'",
"!==",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"define",
",",
"'delete'",
",",
"$",
"this",
"->",
"app",
"->",
"get_config",
"(",
"'config'",
",",
"'default_delete_rule'",
")",
")",
",",
"$",
"define",
")",
";",
"}"
] | @param array $define
@return bool | [
"@param",
"array",
"$define"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L509-L511 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.filter | private function filter( $data, $columns ) {
$_format = [];
$_data = [];
$_columns = $columns;
foreach ( $data as $k => $v ) {
$columns = $_columns;
list( $name, $columns ) = $this->get_field_data( $k, $columns );
if ( isset( $columns[ $k ] ) ) {
$_format[] = $columns[ $k ]['format'];
} else {
$_format[] = '%s';
}
$_data[ $name ] = $v;
}
return [ $_data, $_format ];
} | php | private function filter( $data, $columns ) {
$_format = [];
$_data = [];
$_columns = $columns;
foreach ( $data as $k => $v ) {
$columns = $_columns;
list( $name, $columns ) = $this->get_field_data( $k, $columns );
if ( isset( $columns[ $k ] ) ) {
$_format[] = $columns[ $k ]['format'];
} else {
$_format[] = '%s';
}
$_data[ $name ] = $v;
}
return [ $_data, $_format ];
} | [
"private",
"function",
"filter",
"(",
"$",
"data",
",",
"$",
"columns",
")",
"{",
"$",
"_format",
"=",
"[",
"]",
";",
"$",
"_data",
"=",
"[",
"]",
";",
"$",
"_columns",
"=",
"$",
"columns",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"columns",
"=",
"$",
"_columns",
";",
"list",
"(",
"$",
"name",
",",
"$",
"columns",
")",
"=",
"$",
"this",
"->",
"get_field_data",
"(",
"$",
"k",
",",
"$",
"columns",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"columns",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"_format",
"[",
"]",
"=",
"$",
"columns",
"[",
"$",
"k",
"]",
"[",
"'format'",
"]",
";",
"}",
"else",
"{",
"$",
"_format",
"[",
"]",
"=",
"'%s'",
";",
"}",
"$",
"_data",
"[",
"$",
"name",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"[",
"$",
"_data",
",",
"$",
"_format",
"]",
";",
"}"
] | @param $data
@param $columns
@return array | [
"@param",
"$data",
"@param",
"$columns"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L519-L535 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.get_field_data | private function get_field_data( $k, $columns ) {
$table = null;
if ( strpos( $k, '.' ) !== false && strpos( $k, '(' ) === false ) {
$exploded = explode( '.', $k );
$table = trim( $exploded[0], '`' );
$k = trim( $exploded[1], '`' );
if ( isset( $this->table_defines[ $table ]['columns'][ $k ] ) ) {
$name = $this->table_defines[ $table ]['columns'][ $k ]['name'];
$columns = $this->table_defines[ $table ];
$table = $this->get_table( $table );
} else {
$name = $k;
}
} else {
if ( empty( $columns ) ) {
return [ $k, $columns ];
}
$k = trim( $k, '`' );
if ( isset( $columns[ $k ] ) ) {
$name = $columns[ $k ]['name'];
} else {
$name = $k;
}
}
if ( ! empty( $table ) ) {
$name = $table . '.' . $name;
}
return [ $name, $columns ];
} | php | private function get_field_data( $k, $columns ) {
$table = null;
if ( strpos( $k, '.' ) !== false && strpos( $k, '(' ) === false ) {
$exploded = explode( '.', $k );
$table = trim( $exploded[0], '`' );
$k = trim( $exploded[1], '`' );
if ( isset( $this->table_defines[ $table ]['columns'][ $k ] ) ) {
$name = $this->table_defines[ $table ]['columns'][ $k ]['name'];
$columns = $this->table_defines[ $table ];
$table = $this->get_table( $table );
} else {
$name = $k;
}
} else {
if ( empty( $columns ) ) {
return [ $k, $columns ];
}
$k = trim( $k, '`' );
if ( isset( $columns[ $k ] ) ) {
$name = $columns[ $k ]['name'];
} else {
$name = $k;
}
}
if ( ! empty( $table ) ) {
$name = $table . '.' . $name;
}
return [ $name, $columns ];
} | [
"private",
"function",
"get_field_data",
"(",
"$",
"k",
",",
"$",
"columns",
")",
"{",
"$",
"table",
"=",
"null",
";",
"if",
"(",
"strpos",
"(",
"$",
"k",
",",
"'.'",
")",
"!==",
"false",
"&&",
"strpos",
"(",
"$",
"k",
",",
"'('",
")",
"===",
"false",
")",
"{",
"$",
"exploded",
"=",
"explode",
"(",
"'.'",
",",
"$",
"k",
")",
";",
"$",
"table",
"=",
"trim",
"(",
"$",
"exploded",
"[",
"0",
"]",
",",
"'`'",
")",
";",
"$",
"k",
"=",
"trim",
"(",
"$",
"exploded",
"[",
"1",
"]",
",",
"'`'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'columns'",
"]",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'columns'",
"]",
"[",
"$",
"k",
"]",
"[",
"'name'",
"]",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"k",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"columns",
")",
")",
"{",
"return",
"[",
"$",
"k",
",",
"$",
"columns",
"]",
";",
"}",
"$",
"k",
"=",
"trim",
"(",
"$",
"k",
",",
"'`'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"columns",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"columns",
"[",
"$",
"k",
"]",
"[",
"'name'",
"]",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"k",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"table",
")",
")",
"{",
"$",
"name",
"=",
"$",
"table",
".",
"'.'",
".",
"$",
"name",
";",
"}",
"return",
"[",
"$",
"name",
",",
"$",
"columns",
"]",
";",
"}"
] | @param string $k
@param array|null $columns
@return array | [
"@param",
"string",
"$k",
"@param",
"array|null",
"$columns"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L543-L572 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.set_update_params | private function set_update_params( $data, $create, $update, $delete ) {
$now = $this->apply_filters( 'set_update_params_date', date_i18n( 'Y-m-d H:i:s' ), $data, $create, $update, $delete );
$user = $this->apply_filters( 'set_update_params_user', substr( $this->app->user->user_name, 0, 32 ), $data, $create, $update, $delete );
if ( $create ) {
$data['created_at'] = $now;
$data['created_by'] = $user;
}
if ( $update ) {
$data['updated_at'] = $now;
$data['updated_by'] = $user;
}
if ( $delete ) {
$data['deleted_at'] = $now;
$data['deleted_by'] = $user;
}
return $data;
} | php | private function set_update_params( $data, $create, $update, $delete ) {
$now = $this->apply_filters( 'set_update_params_date', date_i18n( 'Y-m-d H:i:s' ), $data, $create, $update, $delete );
$user = $this->apply_filters( 'set_update_params_user', substr( $this->app->user->user_name, 0, 32 ), $data, $create, $update, $delete );
if ( $create ) {
$data['created_at'] = $now;
$data['created_by'] = $user;
}
if ( $update ) {
$data['updated_at'] = $now;
$data['updated_by'] = $user;
}
if ( $delete ) {
$data['deleted_at'] = $now;
$data['deleted_by'] = $user;
}
return $data;
} | [
"private",
"function",
"set_update_params",
"(",
"$",
"data",
",",
"$",
"create",
",",
"$",
"update",
",",
"$",
"delete",
")",
"{",
"$",
"now",
"=",
"$",
"this",
"->",
"apply_filters",
"(",
"'set_update_params_date'",
",",
"date_i18n",
"(",
"'Y-m-d H:i:s'",
")",
",",
"$",
"data",
",",
"$",
"create",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"apply_filters",
"(",
"'set_update_params_user'",
",",
"substr",
"(",
"$",
"this",
"->",
"app",
"->",
"user",
"->",
"user_name",
",",
"0",
",",
"32",
")",
",",
"$",
"data",
",",
"$",
"create",
",",
"$",
"update",
",",
"$",
"delete",
")",
";",
"if",
"(",
"$",
"create",
")",
"{",
"$",
"data",
"[",
"'created_at'",
"]",
"=",
"$",
"now",
";",
"$",
"data",
"[",
"'created_by'",
"]",
"=",
"$",
"user",
";",
"}",
"if",
"(",
"$",
"update",
")",
"{",
"$",
"data",
"[",
"'updated_at'",
"]",
"=",
"$",
"now",
";",
"$",
"data",
"[",
"'updated_by'",
"]",
"=",
"$",
"user",
";",
"}",
"if",
"(",
"$",
"delete",
")",
"{",
"$",
"data",
"[",
"'deleted_at'",
"]",
"=",
"$",
"now",
";",
"$",
"data",
"[",
"'deleted_by'",
"]",
"=",
"$",
"user",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | @since 2.0.0 Changed: return $data
@since 2.9.14 Fixed: prevent cache
@param array $data
@param bool $create
@param bool $update
@param bool $delete
@return array | [
"@since",
"2",
".",
"0",
".",
"0",
"Changed",
":",
"return",
"$data",
"@since",
"2",
".",
"9",
".",
"14",
"Fixed",
":",
"prevent",
"cache"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L595-L613 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.build_fields | private function build_fields( $fields, $columns ) {
if ( ! isset( $fields ) ) {
$fields = [ '*' ];
}
if ( is_string( $fields ) ) {
$fields = [ $fields ];
}
if ( ! empty( $fields ) ) {
foreach ( $fields as $k => $option ) {
$key = $k;
if ( is_int( $key ) ) {
$key = $option;
$option = null;
}
if ( $key === '*' ) {
if ( ! is_array( $option ) ) {
unset ( $fields[ $k ] );
$is_admin = is_admin() && ! $this->app->utility->doing_ajax();
foreach ( $columns as $key => $column ) {
if ( ! $is_admin && ! empty( $column['only_admin'] ) ) {
continue;
}
$name = $this->app->utility->array_get( $column, 'name' );
$fields[] = $name === $key ? $name : $name . ' AS ' . $key;
}
continue;
}
$name = $key;
} elseif ( isset( $columns[ $key ] ) ) {
$name = $columns[ $key ]['name'];
} else {
$name = $key;
}
if ( is_array( $option ) ) {
$group_func = $option[0];
if ( strtoupper( $group_func ) == 'AS' ) {
$fields[ $k ] = $name;
if ( count( $option ) >= 2 ) {
$fields[ $k ] .= ' AS ' . $option[1];
}
} else {
$fields[ $k ] = "$group_func( $name )";
if ( count( $option ) >= 2 ) {
$fields[ $k ] .= ' AS ' . $option[1];
}
}
} elseif ( ! isset( $option ) ) {
$fields[ $k ] = $name === $key ? $name : $name . ' AS ' . $key;
} else {
$fields[ $k ] = $name . ' AS ' . $option;
}
}
}
if ( empty( $fields ) || ! is_array( $fields ) ) {
$fields = [];
$is_admin = is_admin() && ! $this->app->utility->doing_ajax();
foreach ( $columns as $key => $column ) {
if ( ! $is_admin && ! empty( $column['only_admin'] ) ) {
continue;
}
$name = $this->app->utility->array_get( $column, 'name' );
$fields[] = $name === $key ? $name : $name . ' AS ' . $key;
}
}
empty( $fields ) and $fields = [ '*' ];
$fields = implode( ', ', $fields );
return $fields;
} | php | private function build_fields( $fields, $columns ) {
if ( ! isset( $fields ) ) {
$fields = [ '*' ];
}
if ( is_string( $fields ) ) {
$fields = [ $fields ];
}
if ( ! empty( $fields ) ) {
foreach ( $fields as $k => $option ) {
$key = $k;
if ( is_int( $key ) ) {
$key = $option;
$option = null;
}
if ( $key === '*' ) {
if ( ! is_array( $option ) ) {
unset ( $fields[ $k ] );
$is_admin = is_admin() && ! $this->app->utility->doing_ajax();
foreach ( $columns as $key => $column ) {
if ( ! $is_admin && ! empty( $column['only_admin'] ) ) {
continue;
}
$name = $this->app->utility->array_get( $column, 'name' );
$fields[] = $name === $key ? $name : $name . ' AS ' . $key;
}
continue;
}
$name = $key;
} elseif ( isset( $columns[ $key ] ) ) {
$name = $columns[ $key ]['name'];
} else {
$name = $key;
}
if ( is_array( $option ) ) {
$group_func = $option[0];
if ( strtoupper( $group_func ) == 'AS' ) {
$fields[ $k ] = $name;
if ( count( $option ) >= 2 ) {
$fields[ $k ] .= ' AS ' . $option[1];
}
} else {
$fields[ $k ] = "$group_func( $name )";
if ( count( $option ) >= 2 ) {
$fields[ $k ] .= ' AS ' . $option[1];
}
}
} elseif ( ! isset( $option ) ) {
$fields[ $k ] = $name === $key ? $name : $name . ' AS ' . $key;
} else {
$fields[ $k ] = $name . ' AS ' . $option;
}
}
}
if ( empty( $fields ) || ! is_array( $fields ) ) {
$fields = [];
$is_admin = is_admin() && ! $this->app->utility->doing_ajax();
foreach ( $columns as $key => $column ) {
if ( ! $is_admin && ! empty( $column['only_admin'] ) ) {
continue;
}
$name = $this->app->utility->array_get( $column, 'name' );
$fields[] = $name === $key ? $name : $name . ' AS ' . $key;
}
}
empty( $fields ) and $fields = [ '*' ];
$fields = implode( ', ', $fields );
return $fields;
} | [
"private",
"function",
"build_fields",
"(",
"$",
"fields",
",",
"$",
"columns",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"[",
"'*'",
"]",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"[",
"$",
"fields",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"k",
"=>",
"$",
"option",
")",
"{",
"$",
"key",
"=",
"$",
"k",
";",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"$",
"option",
";",
"$",
"option",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"key",
"===",
"'*'",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"option",
")",
")",
"{",
"unset",
"(",
"$",
"fields",
"[",
"$",
"k",
"]",
")",
";",
"$",
"is_admin",
"=",
"is_admin",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"doing_ajax",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"$",
"is_admin",
"&&",
"!",
"empty",
"(",
"$",
"column",
"[",
"'only_admin'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"name",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'name'",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"name",
"===",
"$",
"key",
"?",
"$",
"name",
":",
"$",
"name",
".",
"' AS '",
".",
"$",
"key",
";",
"}",
"continue",
";",
"}",
"$",
"name",
"=",
"$",
"key",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"columns",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"columns",
"[",
"$",
"key",
"]",
"[",
"'name'",
"]",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"key",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"option",
")",
")",
"{",
"$",
"group_func",
"=",
"$",
"option",
"[",
"0",
"]",
";",
"if",
"(",
"strtoupper",
"(",
"$",
"group_func",
")",
"==",
"'AS'",
")",
"{",
"$",
"fields",
"[",
"$",
"k",
"]",
"=",
"$",
"name",
";",
"if",
"(",
"count",
"(",
"$",
"option",
")",
">=",
"2",
")",
"{",
"$",
"fields",
"[",
"$",
"k",
"]",
".=",
"' AS '",
".",
"$",
"option",
"[",
"1",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"fields",
"[",
"$",
"k",
"]",
"=",
"\"$group_func( $name )\"",
";",
"if",
"(",
"count",
"(",
"$",
"option",
")",
">=",
"2",
")",
"{",
"$",
"fields",
"[",
"$",
"k",
"]",
".=",
"' AS '",
".",
"$",
"option",
"[",
"1",
"]",
";",
"}",
"}",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"option",
")",
")",
"{",
"$",
"fields",
"[",
"$",
"k",
"]",
"=",
"$",
"name",
"===",
"$",
"key",
"?",
"$",
"name",
":",
"$",
"name",
".",
"' AS '",
".",
"$",
"key",
";",
"}",
"else",
"{",
"$",
"fields",
"[",
"$",
"k",
"]",
"=",
"$",
"name",
".",
"' AS '",
".",
"$",
"option",
";",
"}",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
"||",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"$",
"is_admin",
"=",
"is_admin",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"doing_ajax",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"$",
"is_admin",
"&&",
"!",
"empty",
"(",
"$",
"column",
"[",
"'only_admin'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"name",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"column",
",",
"'name'",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"name",
"===",
"$",
"key",
"?",
"$",
"name",
":",
"$",
"name",
".",
"' AS '",
".",
"$",
"key",
";",
"}",
"}",
"empty",
"(",
"$",
"fields",
")",
"and",
"$",
"fields",
"=",
"[",
"'*'",
"]",
";",
"$",
"fields",
"=",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
";",
"return",
"$",
"fields",
";",
"}"
] | @param null|array|string $fields
@param array $columns
@return array | [
"@param",
"null|array|string",
"$fields",
"@param",
"array",
"$columns"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L621-L689 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.build_conditions | private function build_conditions( $where, $columns, $glue = 'AND' ) {
list ( $_where, $_where_format ) = $this->filter( $where, $columns );
$conditions = $values = [];
$index = 0;
foreach ( $_where as $field => $value ) {
$field = trim( $field );
$format = $_where_format[ $index ++ ];
if ( is_null( $value ) ) {
$conditions[] = "$field IS NULL";
continue;
}
if ( in_array( strtoupper( $field ), [
'EXISTS',
'NOT EXISTS',
] ) ) {
! is_array( $value ) and $value = [ $value ];
foreach ( $value as $sub_query ) {
$conditions[] = "$field ($sub_query)";
}
continue;
}
$op = '=';
if ( is_array( $value ) ) {
if ( count( $value ) > 1 ) {
$op = trim( $value[0] );
$val = $value[1];
if ( in_array( strtoupper( $op ), [
'OR',
'AND',
] ) ) {
array_shift( $value );
$_conditions = [];
foreach ( $value as $v ) {
if ( ! is_array( $v ) ) {
$_conditions[] = "1=0";
continue;
}
list( $c, $v ) = $this->build_conditions( $v, $columns );
$values = array_merge( $values, $v );
$_conditions[] = "({$c})";
}
$conditions[] = implode( " {$op} ", $_conditions );
continue;
}
if ( is_array( $val ) ) {
if ( empty( $val ) ) {
$conditions[] = "1=0";
} else {
foreach ( $val as $v ) {
$values[] = $v;
}
$conditions[] = "$field $op (" . str_repeat( $format . ',', count( $val ) - 1 ) . $format . ')';
}
continue;
}
if ( count( $value ) > 2 ) {
$val = $this->get_field_name( $val, $columns );
$conditions[] = "$field $op $val";
continue;
}
} else {
$value = reset( $value );
$conditions[] = "$field ($value)";
continue;
}
} else {
$val = $value;
}
$conditions[] = "$field $op $format";
$values[] = $val;
}
$conditions = implode( " {$glue} ", $conditions );
return [ $conditions, $values ];
} | php | private function build_conditions( $where, $columns, $glue = 'AND' ) {
list ( $_where, $_where_format ) = $this->filter( $where, $columns );
$conditions = $values = [];
$index = 0;
foreach ( $_where as $field => $value ) {
$field = trim( $field );
$format = $_where_format[ $index ++ ];
if ( is_null( $value ) ) {
$conditions[] = "$field IS NULL";
continue;
}
if ( in_array( strtoupper( $field ), [
'EXISTS',
'NOT EXISTS',
] ) ) {
! is_array( $value ) and $value = [ $value ];
foreach ( $value as $sub_query ) {
$conditions[] = "$field ($sub_query)";
}
continue;
}
$op = '=';
if ( is_array( $value ) ) {
if ( count( $value ) > 1 ) {
$op = trim( $value[0] );
$val = $value[1];
if ( in_array( strtoupper( $op ), [
'OR',
'AND',
] ) ) {
array_shift( $value );
$_conditions = [];
foreach ( $value as $v ) {
if ( ! is_array( $v ) ) {
$_conditions[] = "1=0";
continue;
}
list( $c, $v ) = $this->build_conditions( $v, $columns );
$values = array_merge( $values, $v );
$_conditions[] = "({$c})";
}
$conditions[] = implode( " {$op} ", $_conditions );
continue;
}
if ( is_array( $val ) ) {
if ( empty( $val ) ) {
$conditions[] = "1=0";
} else {
foreach ( $val as $v ) {
$values[] = $v;
}
$conditions[] = "$field $op (" . str_repeat( $format . ',', count( $val ) - 1 ) . $format . ')';
}
continue;
}
if ( count( $value ) > 2 ) {
$val = $this->get_field_name( $val, $columns );
$conditions[] = "$field $op $val";
continue;
}
} else {
$value = reset( $value );
$conditions[] = "$field ($value)";
continue;
}
} else {
$val = $value;
}
$conditions[] = "$field $op $format";
$values[] = $val;
}
$conditions = implode( " {$glue} ", $conditions );
return [ $conditions, $values ];
} | [
"private",
"function",
"build_conditions",
"(",
"$",
"where",
",",
"$",
"columns",
",",
"$",
"glue",
"=",
"'AND'",
")",
"{",
"list",
"(",
"$",
"_where",
",",
"$",
"_where_format",
")",
"=",
"$",
"this",
"->",
"filter",
"(",
"$",
"where",
",",
"$",
"columns",
")",
";",
"$",
"conditions",
"=",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"index",
"=",
"0",
";",
"foreach",
"(",
"$",
"_where",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"field",
"=",
"trim",
"(",
"$",
"field",
")",
";",
"$",
"format",
"=",
"$",
"_where_format",
"[",
"$",
"index",
"++",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"$field IS NULL\"",
";",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"strtoupper",
"(",
"$",
"field",
")",
",",
"[",
"'EXISTS'",
",",
"'NOT EXISTS'",
",",
"]",
")",
")",
"{",
"!",
"is_array",
"(",
"$",
"value",
")",
"and",
"$",
"value",
"=",
"[",
"$",
"value",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"sub_query",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"$field ($sub_query)\"",
";",
"}",
"continue",
";",
"}",
"$",
"op",
"=",
"'='",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"value",
")",
">",
"1",
")",
"{",
"$",
"op",
"=",
"trim",
"(",
"$",
"value",
"[",
"0",
"]",
")",
";",
"$",
"val",
"=",
"$",
"value",
"[",
"1",
"]",
";",
"if",
"(",
"in_array",
"(",
"strtoupper",
"(",
"$",
"op",
")",
",",
"[",
"'OR'",
",",
"'AND'",
",",
"]",
")",
")",
"{",
"array_shift",
"(",
"$",
"value",
")",
";",
"$",
"_conditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"$",
"_conditions",
"[",
"]",
"=",
"\"1=0\"",
";",
"continue",
";",
"}",
"list",
"(",
"$",
"c",
",",
"$",
"v",
")",
"=",
"$",
"this",
"->",
"build_conditions",
"(",
"$",
"v",
",",
"$",
"columns",
")",
";",
"$",
"values",
"=",
"array_merge",
"(",
"$",
"values",
",",
"$",
"v",
")",
";",
"$",
"_conditions",
"[",
"]",
"=",
"\"({$c})\"",
";",
"}",
"$",
"conditions",
"[",
"]",
"=",
"implode",
"(",
"\" {$op} \"",
",",
"$",
"_conditions",
")",
";",
"continue",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"val",
")",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"1=0\"",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"val",
"as",
"$",
"v",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"$",
"v",
";",
"}",
"$",
"conditions",
"[",
"]",
"=",
"\"$field $op (\"",
".",
"str_repeat",
"(",
"$",
"format",
".",
"','",
",",
"count",
"(",
"$",
"val",
")",
"-",
"1",
")",
".",
"$",
"format",
".",
"')'",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"value",
")",
">",
"2",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"get_field_name",
"(",
"$",
"val",
",",
"$",
"columns",
")",
";",
"$",
"conditions",
"[",
"]",
"=",
"\"$field $op $val\"",
";",
"continue",
";",
"}",
"}",
"else",
"{",
"$",
"value",
"=",
"reset",
"(",
"$",
"value",
")",
";",
"$",
"conditions",
"[",
"]",
"=",
"\"$field ($value)\"",
";",
"continue",
";",
"}",
"}",
"else",
"{",
"$",
"val",
"=",
"$",
"value",
";",
"}",
"$",
"conditions",
"[",
"]",
"=",
"\"$field $op $format\"",
";",
"$",
"values",
"[",
"]",
"=",
"$",
"val",
";",
"}",
"$",
"conditions",
"=",
"implode",
"(",
"\" {$glue} \"",
",",
"$",
"conditions",
")",
";",
"return",
"[",
"$",
"conditions",
",",
"$",
"values",
"]",
";",
"}"
] | @param array $where
@param array $columns
@param string $glue
@return array | [
"@param",
"array",
"$where",
"@param",
"array",
"$columns",
"@param",
"string",
"$glue"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L698-L776 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.build_group_by | private function build_group_by( $group_by, $columns ) {
$sql = '';
if ( ! empty( $group_by ) ) {
$items = [];
foreach ( $group_by as $k ) {
$items[] = $this->get_field_name( $k, $columns );
}
if ( ! empty( $items ) ) {
$sql .= ' GROUP BY ' . implode( ', ', $items );
}
}
return $sql;
} | php | private function build_group_by( $group_by, $columns ) {
$sql = '';
if ( ! empty( $group_by ) ) {
$items = [];
foreach ( $group_by as $k ) {
$items[] = $this->get_field_name( $k, $columns );
}
if ( ! empty( $items ) ) {
$sql .= ' GROUP BY ' . implode( ', ', $items );
}
}
return $sql;
} | [
"private",
"function",
"build_group_by",
"(",
"$",
"group_by",
",",
"$",
"columns",
")",
"{",
"$",
"sql",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"group_by",
")",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"group_by",
"as",
"$",
"k",
")",
"{",
"$",
"items",
"[",
"]",
"=",
"$",
"this",
"->",
"get_field_name",
"(",
"$",
"k",
",",
"$",
"columns",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"items",
")",
")",
"{",
"$",
"sql",
".=",
"' GROUP BY '",
".",
"implode",
"(",
"', '",
",",
"$",
"items",
")",
";",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] | @param null|array $group_by
@param array $columns
@return string | [
"@param",
"null|array",
"$group_by",
"@param",
"array",
"$columns"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L784-L797 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.build_order_by | private function build_order_by( $order_by, $columns ) {
$sql = '';
if ( ! empty( $order_by ) ) {
$items = [];
foreach ( $order_by as $k => $order ) {
if ( is_int( $k ) ) {
$k = $order;
$order = 'ASC';
} else {
$order = trim( strtoupper( $order ) );
}
if ( $order !== 'DESC' && $order !== 'ASC' ) {
continue;
}
$k = $this->get_field_name( $k, $columns );
$items[] = "$k $order";
}
if ( ! empty( $items ) ) {
$sql .= ' ORDER BY ' . implode( ', ', $items );
}
}
return $sql;
} | php | private function build_order_by( $order_by, $columns ) {
$sql = '';
if ( ! empty( $order_by ) ) {
$items = [];
foreach ( $order_by as $k => $order ) {
if ( is_int( $k ) ) {
$k = $order;
$order = 'ASC';
} else {
$order = trim( strtoupper( $order ) );
}
if ( $order !== 'DESC' && $order !== 'ASC' ) {
continue;
}
$k = $this->get_field_name( $k, $columns );
$items[] = "$k $order";
}
if ( ! empty( $items ) ) {
$sql .= ' ORDER BY ' . implode( ', ', $items );
}
}
return $sql;
} | [
"private",
"function",
"build_order_by",
"(",
"$",
"order_by",
",",
"$",
"columns",
")",
"{",
"$",
"sql",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"order_by",
")",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"order_by",
"as",
"$",
"k",
"=>",
"$",
"order",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"k",
")",
")",
"{",
"$",
"k",
"=",
"$",
"order",
";",
"$",
"order",
"=",
"'ASC'",
";",
"}",
"else",
"{",
"$",
"order",
"=",
"trim",
"(",
"strtoupper",
"(",
"$",
"order",
")",
")",
";",
"}",
"if",
"(",
"$",
"order",
"!==",
"'DESC'",
"&&",
"$",
"order",
"!==",
"'ASC'",
")",
"{",
"continue",
";",
"}",
"$",
"k",
"=",
"$",
"this",
"->",
"get_field_name",
"(",
"$",
"k",
",",
"$",
"columns",
")",
";",
"$",
"items",
"[",
"]",
"=",
"\"$k $order\"",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"items",
")",
")",
"{",
"$",
"sql",
".=",
"' ORDER BY '",
".",
"implode",
"(",
"', '",
",",
"$",
"items",
")",
";",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] | @param null|array $order_by
@param array $columns
@return string | [
"@param",
"null|array",
"$order_by",
"@param",
"array",
"$columns"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L805-L828 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.build_join | private function build_join( $join ) {
$sql = '';
if ( ! empty( $join ) ) {
$items = [];
foreach ( $join as $data ) {
if ( ! is_array( $data ) || count( $data ) < 3 ) {
continue;
}
$table = $data[0];
$rule = $data[1];
$rule = strtoupper( $rule );
if ( ! in_array( $rule, [
'JOIN',
'INNER JOIN',
'LEFT JOIN',
'RIGHT JOIN',
] ) ) {
continue;
}
$conditions = $data[2];
if ( empty( $conditions ) ) {
continue;
}
$check = reset( $conditions );
if ( ! is_array( $check ) ) {
$conditions = [ $conditions ];
}
$values = [];
foreach ( $conditions as $condition ) {
if ( ! is_array( $condition ) || count( $condition ) < 3 ) {
continue;
}
$left = $condition[0];
$op = $condition[1];
$right = $condition[2];
$values[] = $this->get_field_name( $left, null ) . " $op " . $this->get_field_name( $right, null );
}
if ( ! empty( $values ) ) {
$as = null;
if ( is_array( $table ) && count( $table ) > 1 ) {
$as = $table[1];
$table = $table[0];
}
$items[] = $rule . ' ' . $this->get_table( $table ) . ( isset( $as ) ? " AS $as" : '' ) . ' ON ' . implode( ' AND ', $values );
}
}
if ( ! empty( $items ) ) {
$sql .= ' ' . implode( ' ', $items );
}
}
return $sql;
} | php | private function build_join( $join ) {
$sql = '';
if ( ! empty( $join ) ) {
$items = [];
foreach ( $join as $data ) {
if ( ! is_array( $data ) || count( $data ) < 3 ) {
continue;
}
$table = $data[0];
$rule = $data[1];
$rule = strtoupper( $rule );
if ( ! in_array( $rule, [
'JOIN',
'INNER JOIN',
'LEFT JOIN',
'RIGHT JOIN',
] ) ) {
continue;
}
$conditions = $data[2];
if ( empty( $conditions ) ) {
continue;
}
$check = reset( $conditions );
if ( ! is_array( $check ) ) {
$conditions = [ $conditions ];
}
$values = [];
foreach ( $conditions as $condition ) {
if ( ! is_array( $condition ) || count( $condition ) < 3 ) {
continue;
}
$left = $condition[0];
$op = $condition[1];
$right = $condition[2];
$values[] = $this->get_field_name( $left, null ) . " $op " . $this->get_field_name( $right, null );
}
if ( ! empty( $values ) ) {
$as = null;
if ( is_array( $table ) && count( $table ) > 1 ) {
$as = $table[1];
$table = $table[0];
}
$items[] = $rule . ' ' . $this->get_table( $table ) . ( isset( $as ) ? " AS $as" : '' ) . ' ON ' . implode( ' AND ', $values );
}
}
if ( ! empty( $items ) ) {
$sql .= ' ' . implode( ' ', $items );
}
}
return $sql;
} | [
"private",
"function",
"build_join",
"(",
"$",
"join",
")",
"{",
"$",
"sql",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"join",
")",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"join",
"as",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"||",
"count",
"(",
"$",
"data",
")",
"<",
"3",
")",
"{",
"continue",
";",
"}",
"$",
"table",
"=",
"$",
"data",
"[",
"0",
"]",
";",
"$",
"rule",
"=",
"$",
"data",
"[",
"1",
"]",
";",
"$",
"rule",
"=",
"strtoupper",
"(",
"$",
"rule",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"rule",
",",
"[",
"'JOIN'",
",",
"'INNER JOIN'",
",",
"'LEFT JOIN'",
",",
"'RIGHT JOIN'",
",",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"conditions",
"=",
"$",
"data",
"[",
"2",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"continue",
";",
"}",
"$",
"check",
"=",
"reset",
"(",
"$",
"conditions",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"check",
")",
")",
"{",
"$",
"conditions",
"=",
"[",
"$",
"conditions",
"]",
";",
"}",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"conditions",
"as",
"$",
"condition",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"condition",
")",
"||",
"count",
"(",
"$",
"condition",
")",
"<",
"3",
")",
"{",
"continue",
";",
"}",
"$",
"left",
"=",
"$",
"condition",
"[",
"0",
"]",
";",
"$",
"op",
"=",
"$",
"condition",
"[",
"1",
"]",
";",
"$",
"right",
"=",
"$",
"condition",
"[",
"2",
"]",
";",
"$",
"values",
"[",
"]",
"=",
"$",
"this",
"->",
"get_field_name",
"(",
"$",
"left",
",",
"null",
")",
".",
"\" $op \"",
".",
"$",
"this",
"->",
"get_field_name",
"(",
"$",
"right",
",",
"null",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"$",
"as",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"table",
")",
"&&",
"count",
"(",
"$",
"table",
")",
">",
"1",
")",
"{",
"$",
"as",
"=",
"$",
"table",
"[",
"1",
"]",
";",
"$",
"table",
"=",
"$",
"table",
"[",
"0",
"]",
";",
"}",
"$",
"items",
"[",
"]",
"=",
"$",
"rule",
".",
"' '",
".",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
".",
"(",
"isset",
"(",
"$",
"as",
")",
"?",
"\" AS $as\"",
":",
"''",
")",
".",
"' ON '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"values",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"items",
")",
")",
"{",
"$",
"sql",
".=",
"' '",
".",
"implode",
"(",
"' '",
",",
"$",
"items",
")",
";",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] | @param null|array $join
@return string | [
"@param",
"null|array",
"$join"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L835-L888 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.build_limit | private function build_limit( $limit, $offset ) {
$sql = '';
if ( isset( $limit ) && $limit > 0 ) {
if ( isset( $offset ) && $offset > 0 ) {
$sql .= " LIMIT {$offset}, {$limit}";
} else {
$sql .= " LIMIT {$limit}";
}
}
return $sql;
} | php | private function build_limit( $limit, $offset ) {
$sql = '';
if ( isset( $limit ) && $limit > 0 ) {
if ( isset( $offset ) && $offset > 0 ) {
$sql .= " LIMIT {$offset}, {$limit}";
} else {
$sql .= " LIMIT {$limit}";
}
}
return $sql;
} | [
"private",
"function",
"build_limit",
"(",
"$",
"limit",
",",
"$",
"offset",
")",
"{",
"$",
"sql",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"limit",
")",
"&&",
"$",
"limit",
">",
"0",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"offset",
")",
"&&",
"$",
"offset",
">",
"0",
")",
"{",
"$",
"sql",
".=",
"\" LIMIT {$offset}, {$limit}\"",
";",
"}",
"else",
"{",
"$",
"sql",
".=",
"\" LIMIT {$limit}\"",
";",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] | @param null|int $limit
@param null|int $offset
@return string | [
"@param",
"null|int",
"$limit",
"@param",
"null|int",
"$offset"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L896-L907 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.get_select_sql | public function get_select_sql( $tables, $where = null, $fields = null, $limit = null, $offset = null, $order_by = null, $group_by = null, $for_update = false ) {
$as = null;
if ( is_array( $tables ) ) {
if ( empty( $tables ) ) {
return false;
}
$table = array_shift( $tables );
$join = $tables;
if ( count( $table ) > 1 ) {
$as = $table[1];
}
$table = $table[0];
} else {
$table = $tables;
$join = null;
}
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
$columns = $this->table_defines[ $table ]['columns'];
! is_array( $where ) and $where = [];
if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
$where['deleted_at'] = null;
}
list( $conditions, $values ) = $this->build_conditions( $where, $columns );
$table = $this->get_table( $table );
$fields = $this->build_fields( $fields, $columns );
$sql = "SELECT {$fields} FROM $table";
if ( isset( $as ) ) {
$sql .= " AS $as";
}
$sql .= $this->build_join( $join );
if ( ! empty( $conditions ) ) {
$sql .= " WHERE $conditions";
}
$sql .= $this->build_group_by( $group_by, $columns );
$sql .= $this->build_order_by( $order_by, $columns );
$sql .= $this->build_limit( $limit, $offset );
if ( $for_update ) {
$sql .= ' FOR UPDATE';
}
return $this->prepare( $sql, $values );
} | php | public function get_select_sql( $tables, $where = null, $fields = null, $limit = null, $offset = null, $order_by = null, $group_by = null, $for_update = false ) {
$as = null;
if ( is_array( $tables ) ) {
if ( empty( $tables ) ) {
return false;
}
$table = array_shift( $tables );
$join = $tables;
if ( count( $table ) > 1 ) {
$as = $table[1];
}
$table = $table[0];
} else {
$table = $tables;
$join = null;
}
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
$columns = $this->table_defines[ $table ]['columns'];
! is_array( $where ) and $where = [];
if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
$where['deleted_at'] = null;
}
list( $conditions, $values ) = $this->build_conditions( $where, $columns );
$table = $this->get_table( $table );
$fields = $this->build_fields( $fields, $columns );
$sql = "SELECT {$fields} FROM $table";
if ( isset( $as ) ) {
$sql .= " AS $as";
}
$sql .= $this->build_join( $join );
if ( ! empty( $conditions ) ) {
$sql .= " WHERE $conditions";
}
$sql .= $this->build_group_by( $group_by, $columns );
$sql .= $this->build_order_by( $order_by, $columns );
$sql .= $this->build_limit( $limit, $offset );
if ( $for_update ) {
$sql .= ' FOR UPDATE';
}
return $this->prepare( $sql, $values );
} | [
"public",
"function",
"get_select_sql",
"(",
"$",
"tables",
",",
"$",
"where",
"=",
"null",
",",
"$",
"fields",
"=",
"null",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
",",
"$",
"order_by",
"=",
"null",
",",
"$",
"group_by",
"=",
"null",
",",
"$",
"for_update",
"=",
"false",
")",
"{",
"$",
"as",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"tables",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"tables",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"table",
"=",
"array_shift",
"(",
"$",
"tables",
")",
";",
"$",
"join",
"=",
"$",
"tables",
";",
"if",
"(",
"count",
"(",
"$",
"table",
")",
">",
"1",
")",
"{",
"$",
"as",
"=",
"$",
"table",
"[",
"1",
"]",
";",
"}",
"$",
"table",
"=",
"$",
"table",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"table",
"=",
"$",
"tables",
";",
"$",
"join",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"columns",
"=",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'columns'",
"]",
";",
"!",
"is_array",
"(",
"$",
"where",
")",
"and",
"$",
"where",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"is_logical",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"$",
"where",
"[",
"'deleted_at'",
"]",
"=",
"null",
";",
"}",
"list",
"(",
"$",
"conditions",
",",
"$",
"values",
")",
"=",
"$",
"this",
"->",
"build_conditions",
"(",
"$",
"where",
",",
"$",
"columns",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"build_fields",
"(",
"$",
"fields",
",",
"$",
"columns",
")",
";",
"$",
"sql",
"=",
"\"SELECT {$fields} FROM $table\"",
";",
"if",
"(",
"isset",
"(",
"$",
"as",
")",
")",
"{",
"$",
"sql",
".=",
"\" AS $as\"",
";",
"}",
"$",
"sql",
".=",
"$",
"this",
"->",
"build_join",
"(",
"$",
"join",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"sql",
".=",
"\" WHERE $conditions\"",
";",
"}",
"$",
"sql",
".=",
"$",
"this",
"->",
"build_group_by",
"(",
"$",
"group_by",
",",
"$",
"columns",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"build_order_by",
"(",
"$",
"order_by",
",",
"$",
"columns",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"build_limit",
"(",
"$",
"limit",
",",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"for_update",
")",
"{",
"$",
"sql",
".=",
"' FOR UPDATE'",
";",
"}",
"return",
"$",
"this",
"->",
"prepare",
"(",
"$",
"sql",
",",
"$",
"values",
")",
";",
"}"
] | @param array|string $tables
@param null|array $where
@param null|array|string $fields
@param null|int $limit
@param null|int $offset
@param null|array $order_by
@param null|array $group_by
@param bool $for_update
@return string|false | [
"@param",
"array|string",
"$tables",
"@param",
"null|array",
"$where",
"@param",
"null|array|string",
"$fields",
"@param",
"null|int",
"$limit",
"@param",
"null|int",
"$offset",
"@param",
"null|array",
"$order_by",
"@param",
"null|array",
"$group_by",
"@param",
"bool",
"$for_update"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L921-L967 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.select | public function select( $tables, $where = [], $fields = null, $limit = null, $offset = null, $order_by = null, $group_by = null, $output = null, $for_update = false ) {
$sql = $this->get_select_sql( $tables, $where, $fields, $limit, $offset, $order_by, $group_by, $for_update );
if ( false === $sql ) {
return false;
}
/** @var \wpdb $wpdb */
global $wpdb;
! isset( $output ) and $output = ARRAY_A;
return $wpdb->get_results( $sql, $output );
} | php | public function select( $tables, $where = [], $fields = null, $limit = null, $offset = null, $order_by = null, $group_by = null, $output = null, $for_update = false ) {
$sql = $this->get_select_sql( $tables, $where, $fields, $limit, $offset, $order_by, $group_by, $for_update );
if ( false === $sql ) {
return false;
}
/** @var \wpdb $wpdb */
global $wpdb;
! isset( $output ) and $output = ARRAY_A;
return $wpdb->get_results( $sql, $output );
} | [
"public",
"function",
"select",
"(",
"$",
"tables",
",",
"$",
"where",
"=",
"[",
"]",
",",
"$",
"fields",
"=",
"null",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
",",
"$",
"order_by",
"=",
"null",
",",
"$",
"group_by",
"=",
"null",
",",
"$",
"output",
"=",
"null",
",",
"$",
"for_update",
"=",
"false",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"get_select_sql",
"(",
"$",
"tables",
",",
"$",
"where",
",",
"$",
"fields",
",",
"$",
"limit",
",",
"$",
"offset",
",",
"$",
"order_by",
",",
"$",
"group_by",
",",
"$",
"for_update",
")",
";",
"if",
"(",
"false",
"===",
"$",
"sql",
")",
"{",
"return",
"false",
";",
"}",
"/** @var \\wpdb $wpdb */",
"global",
"$",
"wpdb",
";",
"!",
"isset",
"(",
"$",
"output",
")",
"and",
"$",
"output",
"=",
"ARRAY_A",
";",
"return",
"$",
"wpdb",
"->",
"get_results",
"(",
"$",
"sql",
",",
"$",
"output",
")",
";",
"}"
] | @since 2.0.0 Changed: default value of $output
@param array|string $tables
@param array $where
@param null|array|string $fields
@param null|int $limit
@param null|int $offset
@param null|array $order_by
@param null|array $group_by
@param null|string $output
@param bool $for_update
@return array|bool|null | [
"@since",
"2",
".",
"0",
".",
"0",
"Changed",
":",
"default",
"value",
"of",
"$output"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L984-L995 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.select_row | public function select_row( $tables, $where = [], $fields = null, $offset = null, $order_by = null, $group_by = null, $output = null, $for_update = false ) {
$sql = $this->get_select_sql( $tables, $where, $fields, 1, $offset, $order_by, $group_by, $for_update );
if ( false === $sql ) {
return false;
}
/** @var \wpdb $wpdb */
global $wpdb;
! isset( $output ) and $output = ARRAY_A;
return $wpdb->get_row( $sql, $output );
} | php | public function select_row( $tables, $where = [], $fields = null, $offset = null, $order_by = null, $group_by = null, $output = null, $for_update = false ) {
$sql = $this->get_select_sql( $tables, $where, $fields, 1, $offset, $order_by, $group_by, $for_update );
if ( false === $sql ) {
return false;
}
/** @var \wpdb $wpdb */
global $wpdb;
! isset( $output ) and $output = ARRAY_A;
return $wpdb->get_row( $sql, $output );
} | [
"public",
"function",
"select_row",
"(",
"$",
"tables",
",",
"$",
"where",
"=",
"[",
"]",
",",
"$",
"fields",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
",",
"$",
"order_by",
"=",
"null",
",",
"$",
"group_by",
"=",
"null",
",",
"$",
"output",
"=",
"null",
",",
"$",
"for_update",
"=",
"false",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"get_select_sql",
"(",
"$",
"tables",
",",
"$",
"where",
",",
"$",
"fields",
",",
"1",
",",
"$",
"offset",
",",
"$",
"order_by",
",",
"$",
"group_by",
",",
"$",
"for_update",
")",
";",
"if",
"(",
"false",
"===",
"$",
"sql",
")",
"{",
"return",
"false",
";",
"}",
"/** @var \\wpdb $wpdb */",
"global",
"$",
"wpdb",
";",
"!",
"isset",
"(",
"$",
"output",
")",
"and",
"$",
"output",
"=",
"ARRAY_A",
";",
"return",
"$",
"wpdb",
"->",
"get_row",
"(",
"$",
"sql",
",",
"$",
"output",
")",
";",
"}"
] | @since 2.0.0 Changed: default value of $output
@param array|string $tables
@param array $where
@param null|array|string $fields
@param null|int $offset
@param null|array $order_by
@param null|array $group_by
@param null|string $output
@param bool $for_update
@return array|bool|null | [
"@since",
"2",
".",
"0",
".",
"0",
"Changed",
":",
"default",
"value",
"of",
"$output"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1011-L1022 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.select_count | public function select_count( $table, $field = '*', $where = [], $limit = null, $offset = null, $order_by = null, $group_by = null, $for_update = false ) {
empty( $field ) and $field = '*';
$result = $this->select( $table, $where, [
$field => [
'COUNT',
'num',
],
], $limit, $offset, $order_by, $group_by, ARRAY_A, $for_update );
if ( empty( $result ) ) {
return 0;
}
return isset( $result[0]['num'] ) ? $result[0]['num'] - 0 : 0;
} | php | public function select_count( $table, $field = '*', $where = [], $limit = null, $offset = null, $order_by = null, $group_by = null, $for_update = false ) {
empty( $field ) and $field = '*';
$result = $this->select( $table, $where, [
$field => [
'COUNT',
'num',
],
], $limit, $offset, $order_by, $group_by, ARRAY_A, $for_update );
if ( empty( $result ) ) {
return 0;
}
return isset( $result[0]['num'] ) ? $result[0]['num'] - 0 : 0;
} | [
"public",
"function",
"select_count",
"(",
"$",
"table",
",",
"$",
"field",
"=",
"'*'",
",",
"$",
"where",
"=",
"[",
"]",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
",",
"$",
"order_by",
"=",
"null",
",",
"$",
"group_by",
"=",
"null",
",",
"$",
"for_update",
"=",
"false",
")",
"{",
"empty",
"(",
"$",
"field",
")",
"and",
"$",
"field",
"=",
"'*'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"select",
"(",
"$",
"table",
",",
"$",
"where",
",",
"[",
"$",
"field",
"=>",
"[",
"'COUNT'",
",",
"'num'",
",",
"]",
",",
"]",
",",
"$",
"limit",
",",
"$",
"offset",
",",
"$",
"order_by",
",",
"$",
"group_by",
",",
"ARRAY_A",
",",
"$",
"for_update",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"isset",
"(",
"$",
"result",
"[",
"0",
"]",
"[",
"'num'",
"]",
")",
"?",
"$",
"result",
"[",
"0",
"]",
"[",
"'num'",
"]",
"-",
"0",
":",
"0",
";",
"}"
] | @since 2.0.0 Changed: default values of $offset, $order_by, $group_by
@param $table
@param string $field
@param array $where
@param null|int $limit
@param null|int $offset
@param null|array $order_by
@param null|array $group_by
@param bool $for_update
@return int | [
"@since",
"2",
".",
"0",
".",
"0",
"Changed",
":",
"default",
"values",
"of",
"$offset",
"$order_by",
"$group_by"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1038-L1051 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db._insert_replace | private function _insert_replace( $table, $data, $method ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
if ( $method !== 'insert' && $method !== 'replace' ) {
return false;
}
if ( $method === 'replace' && ! isset( $data['id'] ) ) {
return false;
}
/** @var \wpdb $wpdb */
global $wpdb;
$columns = $this->table_defines[ $table ]['columns'];
$data = $this->set_update_params( $data, $method === 'insert', true, false );
list ( $_data, $_format ) = $this->filter( $data, $columns );
return $wpdb->$method( $this->get_table( $table ), $_data, $_format );
} | php | private function _insert_replace( $table, $data, $method ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
if ( $method !== 'insert' && $method !== 'replace' ) {
return false;
}
if ( $method === 'replace' && ! isset( $data['id'] ) ) {
return false;
}
/** @var \wpdb $wpdb */
global $wpdb;
$columns = $this->table_defines[ $table ]['columns'];
$data = $this->set_update_params( $data, $method === 'insert', true, false );
list ( $_data, $_format ) = $this->filter( $data, $columns );
return $wpdb->$method( $this->get_table( $table ), $_data, $_format );
} | [
"private",
"function",
"_insert_replace",
"(",
"$",
"table",
",",
"$",
"data",
",",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"method",
"!==",
"'insert'",
"&&",
"$",
"method",
"!==",
"'replace'",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"method",
"===",
"'replace'",
"&&",
"!",
"isset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"/** @var \\wpdb $wpdb */",
"global",
"$",
"wpdb",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'columns'",
"]",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"set_update_params",
"(",
"$",
"data",
",",
"$",
"method",
"===",
"'insert'",
",",
"true",
",",
"false",
")",
";",
"list",
"(",
"$",
"_data",
",",
"$",
"_format",
")",
"=",
"$",
"this",
"->",
"filter",
"(",
"$",
"data",
",",
"$",
"columns",
")",
";",
"return",
"$",
"wpdb",
"->",
"$",
"method",
"(",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
",",
"$",
"_data",
",",
"$",
"_format",
")",
";",
"}"
] | @param string $table
@param array $data
@param string $method
@return false|int | [
"@param",
"string",
"$table",
"@param",
"array",
"$data",
"@param",
"string",
"$method"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1060-L1079 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.bulk_insert | public function bulk_insert( $table, $fields, $data_list ) {
if ( ! isset( $this->table_defines[ $table ] ) || empty( $fields ) || empty( $data_list ) ) {
return false;
}
$columns = $this->table_defines[ $table ]['columns'];
$table = $this->get_table( $table );
$sql = "INSERT INTO {$table} ";
$names = [];
$placeholder = [];
$time = $this->set_update_params( [], true, true, false );
foreach ( $fields as $field ) {
if ( ! isset( $columns[ $field ] ) ) {
return false;
}
$names[] = $columns[ $field ]['name'];
$placeholder[] = $columns[ $field ]['format'];
}
foreach ( $time as $k => $v ) {
$names[] = $columns[ $k ]['name'];
$placeholder[] = $columns[ $k ]['format'];
}
$placeholder = '(' . implode( ', ', $placeholder ) . ')';
$sql .= '(' . implode( ', ', $names ) . ') VALUES ';
$values = [];
foreach ( $data_list as $data ) {
$data += $time;
if ( count( $names ) != count( $data ) ) {
return false;
}
$values[] = $this->prepare( $placeholder, $data );
}
$sql .= implode( ', ', $values );
return $this->query( $sql );
} | php | public function bulk_insert( $table, $fields, $data_list ) {
if ( ! isset( $this->table_defines[ $table ] ) || empty( $fields ) || empty( $data_list ) ) {
return false;
}
$columns = $this->table_defines[ $table ]['columns'];
$table = $this->get_table( $table );
$sql = "INSERT INTO {$table} ";
$names = [];
$placeholder = [];
$time = $this->set_update_params( [], true, true, false );
foreach ( $fields as $field ) {
if ( ! isset( $columns[ $field ] ) ) {
return false;
}
$names[] = $columns[ $field ]['name'];
$placeholder[] = $columns[ $field ]['format'];
}
foreach ( $time as $k => $v ) {
$names[] = $columns[ $k ]['name'];
$placeholder[] = $columns[ $k ]['format'];
}
$placeholder = '(' . implode( ', ', $placeholder ) . ')';
$sql .= '(' . implode( ', ', $names ) . ') VALUES ';
$values = [];
foreach ( $data_list as $data ) {
$data += $time;
if ( count( $names ) != count( $data ) ) {
return false;
}
$values[] = $this->prepare( $placeholder, $data );
}
$sql .= implode( ', ', $values );
return $this->query( $sql );
} | [
"public",
"function",
"bulk_insert",
"(",
"$",
"table",
",",
"$",
"fields",
",",
"$",
"data_list",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
"||",
"empty",
"(",
"$",
"fields",
")",
"||",
"empty",
"(",
"$",
"data_list",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"columns",
"=",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'columns'",
"]",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
";",
"$",
"sql",
"=",
"\"INSERT INTO {$table} \"",
";",
"$",
"names",
"=",
"[",
"]",
";",
"$",
"placeholder",
"=",
"[",
"]",
";",
"$",
"time",
"=",
"$",
"this",
"->",
"set_update_params",
"(",
"[",
"]",
",",
"true",
",",
"true",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"columns",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"names",
"[",
"]",
"=",
"$",
"columns",
"[",
"$",
"field",
"]",
"[",
"'name'",
"]",
";",
"$",
"placeholder",
"[",
"]",
"=",
"$",
"columns",
"[",
"$",
"field",
"]",
"[",
"'format'",
"]",
";",
"}",
"foreach",
"(",
"$",
"time",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"names",
"[",
"]",
"=",
"$",
"columns",
"[",
"$",
"k",
"]",
"[",
"'name'",
"]",
";",
"$",
"placeholder",
"[",
"]",
"=",
"$",
"columns",
"[",
"$",
"k",
"]",
"[",
"'format'",
"]",
";",
"}",
"$",
"placeholder",
"=",
"'('",
".",
"implode",
"(",
"', '",
",",
"$",
"placeholder",
")",
".",
"')'",
";",
"$",
"sql",
".=",
"'('",
".",
"implode",
"(",
"', '",
",",
"$",
"names",
")",
".",
"') VALUES '",
";",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data_list",
"as",
"$",
"data",
")",
"{",
"$",
"data",
"+=",
"$",
"time",
";",
"if",
"(",
"count",
"(",
"$",
"names",
")",
"!=",
"count",
"(",
"$",
"data",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"values",
"[",
"]",
"=",
"$",
"this",
"->",
"prepare",
"(",
"$",
"placeholder",
",",
"$",
"data",
")",
";",
"}",
"$",
"sql",
".=",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
";",
"return",
"$",
"this",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"}"
] | @param string $table
@param array $fields
@param array $data_list
@return false|int | [
"@param",
"string",
"$table",
"@param",
"array",
"$fields",
"@param",
"array",
"$data_list"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1127-L1163 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.insert_or_update | public function insert_or_update( $table, $data, $where ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
$where['deleted_at'] = null;
}
$row = $this->select_row( $table, $where, 'id' );
if ( empty( $row ) ) {
$this->insert( $table, $data );
if ( $this->get_last_error() ) {
return false;
}
return $this->get_insert_id();
}
$where = [ 'id' => $row['id'] ];
$this->update( $table, $data, $where );
if ( $this->get_last_error() ) {
return false;
}
return $row['id'];
} | php | public function insert_or_update( $table, $data, $where ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
$where['deleted_at'] = null;
}
$row = $this->select_row( $table, $where, 'id' );
if ( empty( $row ) ) {
$this->insert( $table, $data );
if ( $this->get_last_error() ) {
return false;
}
return $this->get_insert_id();
}
$where = [ 'id' => $row['id'] ];
$this->update( $table, $data, $where );
if ( $this->get_last_error() ) {
return false;
}
return $row['id'];
} | [
"public",
"function",
"insert_or_update",
"(",
"$",
"table",
",",
"$",
"data",
",",
"$",
"where",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is_logical",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"$",
"where",
"[",
"'deleted_at'",
"]",
"=",
"null",
";",
"}",
"$",
"row",
"=",
"$",
"this",
"->",
"select_row",
"(",
"$",
"table",
",",
"$",
"where",
",",
"'id'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"row",
")",
")",
"{",
"$",
"this",
"->",
"insert",
"(",
"$",
"table",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get_last_error",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"get_insert_id",
"(",
")",
";",
"}",
"$",
"where",
"=",
"[",
"'id'",
"=>",
"$",
"row",
"[",
"'id'",
"]",
"]",
";",
"$",
"this",
"->",
"update",
"(",
"$",
"table",
",",
"$",
"data",
",",
"$",
"where",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get_last_error",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"row",
"[",
"'id'",
"]",
";",
"}"
] | @param $table
@param $data
@param $where
@return int|false | [
"@param",
"$table",
"@param",
"$data",
"@param",
"$where"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1209-L1234 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.delete | public function delete( $table, $where ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
$data = $this->set_update_params( [], false, false, true );
return $this->update( $table, $data, $where );
}
/** @var \wpdb $wpdb */
global $wpdb;
$columns = $this->table_defines[ $table ]['columns'];
list ( $_where, $_where_format ) = $this->filter( $where, $columns );
return $wpdb->delete( $this->get_table( $table ), $_where, $_where_format );
} | php | public function delete( $table, $where ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
$data = $this->set_update_params( [], false, false, true );
return $this->update( $table, $data, $where );
}
/** @var \wpdb $wpdb */
global $wpdb;
$columns = $this->table_defines[ $table ]['columns'];
list ( $_where, $_where_format ) = $this->filter( $where, $columns );
return $wpdb->delete( $this->get_table( $table ), $_where, $_where_format );
} | [
"public",
"function",
"delete",
"(",
"$",
"table",
",",
"$",
"where",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is_logical",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"set_update_params",
"(",
"[",
"]",
",",
"false",
",",
"false",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"update",
"(",
"$",
"table",
",",
"$",
"data",
",",
"$",
"where",
")",
";",
"}",
"/** @var \\wpdb $wpdb */",
"global",
"$",
"wpdb",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
"[",
"'columns'",
"]",
";",
"list",
"(",
"$",
"_where",
",",
"$",
"_where_format",
")",
"=",
"$",
"this",
"->",
"filter",
"(",
"$",
"where",
",",
"$",
"columns",
")",
";",
"return",
"$",
"wpdb",
"->",
"delete",
"(",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
",",
"$",
"_where",
",",
"$",
"_where_format",
")",
";",
"}"
] | @param string $table
@param array $where
@return bool|false|int | [
"@param",
"string",
"$table",
"@param",
"array",
"$where"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1242-L1260 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.truncate | public function truncate( $table ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
return $this->delete( $table, [] );
}
$sql = 'TRUNCATE TABLE `' . $this->get_table( $table ) . '`';
return $this->query( $sql );
} | php | public function truncate( $table ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
return $this->delete( $table, [] );
}
$sql = 'TRUNCATE TABLE `' . $this->get_table( $table ) . '`';
return $this->query( $sql );
} | [
"public",
"function",
"truncate",
"(",
"$",
"table",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is_logical",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"delete",
"(",
"$",
"table",
",",
"[",
"]",
")",
";",
"}",
"$",
"sql",
"=",
"'TRUNCATE TABLE `'",
".",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
".",
"'`'",
";",
"return",
"$",
"this",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"}"
] | @param $table
@return bool|false|int | [
"@param",
"$table"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1267-L1279 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.prepare | public function prepare( $sql, $values ) {
/** @var \wpdb $wpdb */
global $wpdb;
return empty( $values ) ? $sql : $wpdb->prepare( $sql, $values );
} | php | public function prepare( $sql, $values ) {
/** @var \wpdb $wpdb */
global $wpdb;
return empty( $values ) ? $sql : $wpdb->prepare( $sql, $values );
} | [
"public",
"function",
"prepare",
"(",
"$",
"sql",
",",
"$",
"values",
")",
"{",
"/** @var \\wpdb $wpdb */",
"global",
"$",
"wpdb",
";",
"return",
"empty",
"(",
"$",
"values",
")",
"?",
"$",
"sql",
":",
"$",
"wpdb",
"->",
"prepare",
"(",
"$",
"sql",
",",
"$",
"values",
")",
";",
"}"
] | @param string $sql
@param array $values
@return string | [
"@param",
"string",
"$sql",
"@param",
"array",
"$values"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1299-L1304 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.lock | public function lock( $table, $write ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
return $this->query( 'LOCK TABLES `' . $this->get_table( $table ) ) . '` ' . ( $write ? 'WRITE' : 'READ' );
} | php | public function lock( $table, $write ) {
if ( ! isset( $this->table_defines[ $table ] ) ) {
return false;
}
return $this->query( 'LOCK TABLES `' . $this->get_table( $table ) ) . '` ' . ( $write ? 'WRITE' : 'READ' );
} | [
"public",
"function",
"lock",
"(",
"$",
"table",
",",
"$",
"write",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"table_defines",
"[",
"$",
"table",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"query",
"(",
"'LOCK TABLES `'",
".",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
")",
".",
"'` '",
".",
"(",
"$",
"write",
"?",
"'WRITE'",
":",
"'READ'",
")",
";",
"}"
] | @param string $table
@param bool $write
@return false|int | [
"@param",
"string",
"$table",
"@param",
"bool",
"$write"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1319-L1325 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.transaction | public function transaction( $func ) {
$level = $this->_transaction_level;
$this->_transaction_level ++;
if ( $level === 0 ) {
$this->_error = null;
try {
$this->begin();
$func();
$this->commit();
return true;
} catch ( \Exception $e ) {
$this->rollback();
$this->app->log( $e );
$this->_error = $e;
} finally {
$this->_transaction_level = $level;
}
} else {
try {
$func();
return true;
} finally {
$this->_transaction_level = $level;
}
}
return false;
} | php | public function transaction( $func ) {
$level = $this->_transaction_level;
$this->_transaction_level ++;
if ( $level === 0 ) {
$this->_error = null;
try {
$this->begin();
$func();
$this->commit();
return true;
} catch ( \Exception $e ) {
$this->rollback();
$this->app->log( $e );
$this->_error = $e;
} finally {
$this->_transaction_level = $level;
}
} else {
try {
$func();
return true;
} finally {
$this->_transaction_level = $level;
}
}
return false;
} | [
"public",
"function",
"transaction",
"(",
"$",
"func",
")",
"{",
"$",
"level",
"=",
"$",
"this",
"->",
"_transaction_level",
";",
"$",
"this",
"->",
"_transaction_level",
"++",
";",
"if",
"(",
"$",
"level",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"_error",
"=",
"null",
";",
"try",
"{",
"$",
"this",
"->",
"begin",
"(",
")",
";",
"$",
"func",
"(",
")",
";",
"$",
"this",
"->",
"commit",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"rollback",
"(",
")",
";",
"$",
"this",
"->",
"app",
"->",
"log",
"(",
"$",
"e",
")",
";",
"$",
"this",
"->",
"_error",
"=",
"$",
"e",
";",
"}",
"finally",
"{",
"$",
"this",
"->",
"_transaction_level",
"=",
"$",
"level",
";",
"}",
"}",
"else",
"{",
"try",
"{",
"$",
"func",
"(",
")",
";",
"return",
"true",
";",
"}",
"finally",
"{",
"$",
"this",
"->",
"_transaction_level",
"=",
"$",
"level",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param callable $func
@return bool | [
"@param",
"callable",
"$func"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1353-L1382 |
technote-space/wordpress-plugin-base | src/classes/models/lib/db.php | Db.uninstall | public function uninstall() {
foreach ( $this->table_defines as $table => $define ) {
if ( ! empty( $define['is_added'] ) ) {
$sql = 'DROP TABLE IF EXISTS `' . $this->get_table( $table ) . '`';
$this->query( $sql );
}
}
} | php | public function uninstall() {
foreach ( $this->table_defines as $table => $define ) {
if ( ! empty( $define['is_added'] ) ) {
$sql = 'DROP TABLE IF EXISTS `' . $this->get_table( $table ) . '`';
$this->query( $sql );
}
}
} | [
"public",
"function",
"uninstall",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"table_defines",
"as",
"$",
"table",
"=>",
"$",
"define",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"define",
"[",
"'is_added'",
"]",
")",
")",
"{",
"$",
"sql",
"=",
"'DROP TABLE IF EXISTS `'",
".",
"$",
"this",
"->",
"get_table",
"(",
"$",
"table",
")",
".",
"'`'",
";",
"$",
"this",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"}",
"}",
"}"
] | uninstall | [
"uninstall"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/db.php#L1387-L1394 |
mekras/atompub | src/Element/Collection.php | Collection.getAcceptedTypes | public function getAcceptedTypes()
{
return $this->getCachedProperty(
'accept',
function () {
$result = [];
/** @var \DOMNodeList $nodes */
// No REQUIRED — no exception.
$nodes = $this->query('app:accept');
foreach ($nodes as $value) {
$result[] = trim($value->textContent);
}
return $result;
}
);
} | php | public function getAcceptedTypes()
{
return $this->getCachedProperty(
'accept',
function () {
$result = [];
/** @var \DOMNodeList $nodes */
// No REQUIRED — no exception.
$nodes = $this->query('app:accept');
foreach ($nodes as $value) {
$result[] = trim($value->textContent);
}
return $result;
}
);
} | [
"public",
"function",
"getAcceptedTypes",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"getCachedProperty",
"(",
"'accept'",
",",
"function",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"/** @var \\DOMNodeList $nodes */",
"// No REQUIRED — no exception.",
"$",
"nodes",
"=",
"$",
"this",
"->",
"query",
"(",
"'app:accept'",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"value",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"trim",
"(",
"$",
"value",
"->",
"textContent",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
")",
";",
"}"
] | Return types of representations accepted by the Collection.
@return string[]
@since 1.0 | [
"Return",
"types",
"of",
"representations",
"accepted",
"by",
"the",
"Collection",
"."
] | train | https://github.com/mekras/atompub/blob/cfc9aab97cff7a822b720e1dd84ef16733183dbb/src/Element/Collection.php#L56-L72 |
mekras/atompub | src/Element/Collection.php | Collection.setAcceptedTypes | public function setAcceptedTypes(array $types)
{
/** @var \DOMNodeList $nodes */
// No REQUIRED — no exception.
$nodes = $this->query('app:accept');
foreach ($nodes as $node) {
$this->getDomElement()->removeChild($node);
}
foreach ($types as $type) {
$element = $this->getDomElement()->ownerDocument
->createElementNS($this->ns(), 'accept', $type);
$this->getDomElement()->appendChild($element);
}
$this->setCachedProperty('accept', $types);
} | php | public function setAcceptedTypes(array $types)
{
/** @var \DOMNodeList $nodes */
// No REQUIRED — no exception.
$nodes = $this->query('app:accept');
foreach ($nodes as $node) {
$this->getDomElement()->removeChild($node);
}
foreach ($types as $type) {
$element = $this->getDomElement()->ownerDocument
->createElementNS($this->ns(), 'accept', $type);
$this->getDomElement()->appendChild($element);
}
$this->setCachedProperty('accept', $types);
} | [
"public",
"function",
"setAcceptedTypes",
"(",
"array",
"$",
"types",
")",
"{",
"/** @var \\DOMNodeList $nodes */",
"// No REQUIRED — no exception.",
"$",
"nodes",
"=",
"$",
"this",
"->",
"query",
"(",
"'app:accept'",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"this",
"->",
"getDomElement",
"(",
")",
"->",
"removeChild",
"(",
"$",
"node",
")",
";",
"}",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"getDomElement",
"(",
")",
"->",
"ownerDocument",
"->",
"createElementNS",
"(",
"$",
"this",
"->",
"ns",
"(",
")",
",",
"'accept'",
",",
"$",
"type",
")",
";",
"$",
"this",
"->",
"getDomElement",
"(",
")",
"->",
"appendChild",
"(",
"$",
"element",
")",
";",
"}",
"$",
"this",
"->",
"setCachedProperty",
"(",
"'accept'",
",",
"$",
"types",
")",
";",
"}"
] | Set types of representations accepted by the Collection.
@param string[] $types
@since 1.0 | [
"Set",
"types",
"of",
"representations",
"accepted",
"by",
"the",
"Collection",
"."
] | train | https://github.com/mekras/atompub/blob/cfc9aab97cff7a822b720e1dd84ef16733183dbb/src/Element/Collection.php#L81-L95 |
netzmacht/contao-leaflet-geocode-widget | src/Widget/RadiusWidget.php | RadiusWidget.validator | protected function validator($varInput)
{
if (is_numeric($varInput) && $this->steps > 0) {
$steps = (int) $this->steps;
$varInput = (int) $varInput;
$varInput = ($steps * round($varInput / $steps));
}
return parent::validator($varInput);
} | php | protected function validator($varInput)
{
if (is_numeric($varInput) && $this->steps > 0) {
$steps = (int) $this->steps;
$varInput = (int) $varInput;
$varInput = ($steps * round($varInput / $steps));
}
return parent::validator($varInput);
} | [
"protected",
"function",
"validator",
"(",
"$",
"varInput",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"varInput",
")",
"&&",
"$",
"this",
"->",
"steps",
">",
"0",
")",
"{",
"$",
"steps",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"steps",
";",
"$",
"varInput",
"=",
"(",
"int",
")",
"$",
"varInput",
";",
"$",
"varInput",
"=",
"(",
"$",
"steps",
"*",
"round",
"(",
"$",
"varInput",
"/",
"$",
"steps",
")",
")",
";",
"}",
"return",
"parent",
"::",
"validator",
"(",
"$",
"varInput",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/08acfbc473696f385d7c6aed6148e51c91443e12/src/Widget/RadiusWidget.php#L89-L98 |
WellCommerce/AppBundle | Controller/RedirectingController.php | RedirectingController.removeTrailingSlashAction | public function removeTrailingSlashAction(Request $request)
{
$pathInfo = $request->getPathInfo();
$requestUri = $request->getRequestUri();
$url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri);
return $this->redirect($url, 301);
} | php | public function removeTrailingSlashAction(Request $request)
{
$pathInfo = $request->getPathInfo();
$requestUri = $request->getRequestUri();
$url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri);
return $this->redirect($url, 301);
} | [
"public",
"function",
"removeTrailingSlashAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"pathInfo",
"=",
"$",
"request",
"->",
"getPathInfo",
"(",
")",
";",
"$",
"requestUri",
"=",
"$",
"request",
"->",
"getRequestUri",
"(",
")",
";",
"$",
"url",
"=",
"str_replace",
"(",
"$",
"pathInfo",
",",
"rtrim",
"(",
"$",
"pathInfo",
",",
"' /'",
")",
",",
"$",
"requestUri",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"url",
",",
"301",
")",
";",
"}"
] | Action used to remove trailing slash in url
@param Request $request
@return \Symfony\Component\HttpFoundation\RedirectResponse | [
"Action",
"used",
"to",
"remove",
"trailing",
"slash",
"in",
"url"
] | train | https://github.com/WellCommerce/AppBundle/blob/2add687d1c898dd0b24afd611d896e3811a0eac3/Controller/RedirectingController.php#L32-L40 |
SergioMadness/query-builder | src/abstraction/InsertBuilder.php | InsertBuilder.generate | public function generate()
{
$result = '';
$table = $this->buildTable();
$fields = $this->buildFields();
$result.='INSERT INTO '.$table.' '.$fields;
return $result;
} | php | public function generate()
{
$result = '';
$table = $this->buildTable();
$fields = $this->buildFields();
$result.='INSERT INTO '.$table.' '.$fields;
return $result;
} | [
"public",
"function",
"generate",
"(",
")",
"{",
"$",
"result",
"=",
"''",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"buildTable",
"(",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"buildFields",
"(",
")",
";",
"$",
"result",
".=",
"'INSERT INTO '",
".",
"$",
"table",
".",
"' '",
".",
"$",
"fields",
";",
"return",
"$",
"result",
";",
"}"
] | Generate query
@return string | [
"Generate",
"query"
] | train | https://github.com/SergioMadness/query-builder/blob/95b7a46bba4c4d369101c6f0d37f133fecb3956d/src/abstraction/InsertBuilder.php#L27-L37 |
antaresproject/notifications | src/Http/Presenters/IndexPresenter.php | IndexPresenter.table | public function table($type = null)
{
$this->breadcrumb->onTable($type);
return $this->datatables->render('antares/notifications::admin.index.index');
} | php | public function table($type = null)
{
$this->breadcrumb->onTable($type);
return $this->datatables->render('antares/notifications::admin.index.index');
} | [
"public",
"function",
"table",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"breadcrumb",
"->",
"onTable",
"(",
"$",
"type",
")",
";",
"return",
"$",
"this",
"->",
"datatables",
"->",
"render",
"(",
"'antares/notifications::admin.index.index'",
")",
";",
"}"
] | Table View Generator
@param String $type
@return View | [
"Table",
"View",
"Generator"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Http/Presenters/IndexPresenter.php#L69-L73 |
antaresproject/notifications | src/Http/Presenters/IndexPresenter.php | IndexPresenter.edit | public function edit($eloquent, $locale)
{
$this->breadcrumb->onEdit($eloquent);
$form = $this->getForm($eloquent);
return $this->view('edit', compact('form'));
} | php | public function edit($eloquent, $locale)
{
$this->breadcrumb->onEdit($eloquent);
$form = $this->getForm($eloquent);
return $this->view('edit', compact('form'));
} | [
"public",
"function",
"edit",
"(",
"$",
"eloquent",
",",
"$",
"locale",
")",
"{",
"$",
"this",
"->",
"breadcrumb",
"->",
"onEdit",
"(",
"$",
"eloquent",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"getForm",
"(",
"$",
"eloquent",
")",
";",
"return",
"$",
"this",
"->",
"view",
"(",
"'edit'",
",",
"compact",
"(",
"'form'",
")",
")",
";",
"}"
] | shows form edit job
@param Model $eloquent
@param String $locale
@return View | [
"shows",
"form",
"edit",
"job"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Http/Presenters/IndexPresenter.php#L82-L87 |
antaresproject/notifications | src/Http/Presenters/IndexPresenter.php | IndexPresenter.getForm | public function getForm($eloquent, $type = null)
{
$classname = $eloquent->classname;
$model = $eloquent->contents->first();
$configuration = [
'content' => $model !== null ? $model->content : null,
'title' => $model !== null ? $model->title : '',
'type' => $eloquent->exists ? $eloquent->type->name : '',
'form_name' => $eloquent->name
];
$notification = app($classname ?: Notification::class);
$fluent = new Fluent(array_merge($configuration, array_except($eloquent->toArray(), ['type'])));
if (!is_null($fluent->type) && $type) {
$fluent->type = $type;
}
return $this->form($fluent, $notification);
} | php | public function getForm($eloquent, $type = null)
{
$classname = $eloquent->classname;
$model = $eloquent->contents->first();
$configuration = [
'content' => $model !== null ? $model->content : null,
'title' => $model !== null ? $model->title : '',
'type' => $eloquent->exists ? $eloquent->type->name : '',
'form_name' => $eloquent->name
];
$notification = app($classname ?: Notification::class);
$fluent = new Fluent(array_merge($configuration, array_except($eloquent->toArray(), ['type'])));
if (!is_null($fluent->type) && $type) {
$fluent->type = $type;
}
return $this->form($fluent, $notification);
} | [
"public",
"function",
"getForm",
"(",
"$",
"eloquent",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"classname",
"=",
"$",
"eloquent",
"->",
"classname",
";",
"$",
"model",
"=",
"$",
"eloquent",
"->",
"contents",
"->",
"first",
"(",
")",
";",
"$",
"configuration",
"=",
"[",
"'content'",
"=>",
"$",
"model",
"!==",
"null",
"?",
"$",
"model",
"->",
"content",
":",
"null",
",",
"'title'",
"=>",
"$",
"model",
"!==",
"null",
"?",
"$",
"model",
"->",
"title",
":",
"''",
",",
"'type'",
"=>",
"$",
"eloquent",
"->",
"exists",
"?",
"$",
"eloquent",
"->",
"type",
"->",
"name",
":",
"''",
",",
"'form_name'",
"=>",
"$",
"eloquent",
"->",
"name",
"]",
";",
"$",
"notification",
"=",
"app",
"(",
"$",
"classname",
"?",
":",
"Notification",
"::",
"class",
")",
";",
"$",
"fluent",
"=",
"new",
"Fluent",
"(",
"array_merge",
"(",
"$",
"configuration",
",",
"array_except",
"(",
"$",
"eloquent",
"->",
"toArray",
"(",
")",
",",
"[",
"'type'",
"]",
")",
")",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"fluent",
"->",
"type",
")",
"&&",
"$",
"type",
")",
"{",
"$",
"fluent",
"->",
"type",
"=",
"$",
"type",
";",
"}",
"return",
"$",
"this",
"->",
"form",
"(",
"$",
"fluent",
",",
"$",
"notification",
")",
";",
"}"
] | gets form instance
@param Model $eloquent
@return FormBuilder
@throws Exception | [
"gets",
"form",
"instance"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Http/Presenters/IndexPresenter.php#L96-L114 |
antaresproject/notifications | src/Http/Presenters/IndexPresenter.php | IndexPresenter.form | protected function form(Fluent $fluent, $notification = null)
{
publish('notifications', 'scripts.resources-default');
Event::fire('antares.forms', 'notification.' . $fluent->form_name);
$fluent->type = $fluent->type === '' ? 'email' : $fluent->type;
return new Form($notification, $fluent);
} | php | protected function form(Fluent $fluent, $notification = null)
{
publish('notifications', 'scripts.resources-default');
Event::fire('antares.forms', 'notification.' . $fluent->form_name);
$fluent->type = $fluent->type === '' ? 'email' : $fluent->type;
return new Form($notification, $fluent);
} | [
"protected",
"function",
"form",
"(",
"Fluent",
"$",
"fluent",
",",
"$",
"notification",
"=",
"null",
")",
"{",
"publish",
"(",
"'notifications'",
",",
"'scripts.resources-default'",
")",
";",
"Event",
"::",
"fire",
"(",
"'antares.forms'",
",",
"'notification.'",
".",
"$",
"fluent",
"->",
"form_name",
")",
";",
"$",
"fluent",
"->",
"type",
"=",
"$",
"fluent",
"->",
"type",
"===",
"''",
"?",
"'email'",
":",
"$",
"fluent",
"->",
"type",
";",
"return",
"new",
"Form",
"(",
"$",
"notification",
",",
"$",
"fluent",
")",
";",
"}"
] | gets instance of command form
@param Fluent $fluent
@param mixed $notification
@return FormBuilder | [
"gets",
"instance",
"of",
"command",
"form"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Http/Presenters/IndexPresenter.php#L123-L130 |
antaresproject/notifications | src/Http/Presenters/IndexPresenter.php | IndexPresenter.create | public function create(Model $model, $type = null)
{
$this->breadcrumb->onCreate($type);
$form = $this->getForm($model, $type)->onCreate();
return $this->view('create', ['form' => $form]);
} | php | public function create(Model $model, $type = null)
{
$this->breadcrumb->onCreate($type);
$form = $this->getForm($model, $type)->onCreate();
return $this->view('create', ['form' => $form]);
} | [
"public",
"function",
"create",
"(",
"Model",
"$",
"model",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"breadcrumb",
"->",
"onCreate",
"(",
"$",
"type",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"getForm",
"(",
"$",
"model",
",",
"$",
"type",
")",
"->",
"onCreate",
"(",
")",
";",
"return",
"$",
"this",
"->",
"view",
"(",
"'create'",
",",
"[",
"'form'",
"=>",
"$",
"form",
"]",
")",
";",
"}"
] | create new notification notification
@param Model $model
@param String $type
@return View | [
"create",
"new",
"notification",
"notification"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Http/Presenters/IndexPresenter.php#L150-L156 |
antaresproject/notifications | src/Processor/IndexProcessor.php | IndexProcessor.edit | public function edit($id, $locale, IndexListener $listener)
{
app('antares.asset')->container('antares/foundation::application')->add('ckeditor', '/packages/ckeditor/ckeditor.js', ['webpack_forms_basic']);
$model = $this->repository->findByLocale($id, $locale);
if (is_null($model)) {
throw new ModelNotFoundException('Model not found');
}
return $this->presenter->edit($model, $locale);
} | php | public function edit($id, $locale, IndexListener $listener)
{
app('antares.asset')->container('antares/foundation::application')->add('ckeditor', '/packages/ckeditor/ckeditor.js', ['webpack_forms_basic']);
$model = $this->repository->findByLocale($id, $locale);
if (is_null($model)) {
throw new ModelNotFoundException('Model not found');
}
return $this->presenter->edit($model, $locale);
} | [
"public",
"function",
"edit",
"(",
"$",
"id",
",",
"$",
"locale",
",",
"IndexListener",
"$",
"listener",
")",
"{",
"app",
"(",
"'antares.asset'",
")",
"->",
"container",
"(",
"'antares/foundation::application'",
")",
"->",
"add",
"(",
"'ckeditor'",
",",
"'/packages/ckeditor/ckeditor.js'",
",",
"[",
"'webpack_forms_basic'",
"]",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"repository",
"->",
"findByLocale",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"model",
")",
")",
"{",
"throw",
"new",
"ModelNotFoundException",
"(",
"'Model not found'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"presenter",
"->",
"edit",
"(",
"$",
"model",
",",
"$",
"locale",
")",
";",
"}"
] | shows edit form
@param mixed $id
@param String $locale
@param IndexListener $listener
@return View | [
"shows",
"edit",
"form"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Processor/IndexProcessor.php#L89-L97 |
antaresproject/notifications | src/Processor/IndexProcessor.php | IndexProcessor.update | public function update(IndexListener $listener)
{
$id = Input::get('id');
$model = $this->repository->find($id);
$form = $this->presenter->getForm($model);
if (!$form->isValid()) {
return $listener->updateValidationFailed($id, $form->getMessageBag());
}
try {
$this->repository->updateNotification($id, Input::all());
} catch (Exception $ex) {
return $listener->updateFailed();
}
return $listener->updateSuccess();
} | php | public function update(IndexListener $listener)
{
$id = Input::get('id');
$model = $this->repository->find($id);
$form = $this->presenter->getForm($model);
if (!$form->isValid()) {
return $listener->updateValidationFailed($id, $form->getMessageBag());
}
try {
$this->repository->updateNotification($id, Input::all());
} catch (Exception $ex) {
return $listener->updateFailed();
}
return $listener->updateSuccess();
} | [
"public",
"function",
"update",
"(",
"IndexListener",
"$",
"listener",
")",
"{",
"$",
"id",
"=",
"Input",
"::",
"get",
"(",
"'id'",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"presenter",
"->",
"getForm",
"(",
"$",
"model",
")",
";",
"if",
"(",
"!",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"$",
"listener",
"->",
"updateValidationFailed",
"(",
"$",
"id",
",",
"$",
"form",
"->",
"getMessageBag",
"(",
")",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"repository",
"->",
"updateNotification",
"(",
"$",
"id",
",",
"Input",
"::",
"all",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"$",
"listener",
"->",
"updateFailed",
"(",
")",
";",
"}",
"return",
"$",
"listener",
"->",
"updateSuccess",
"(",
")",
";",
"}"
] | updates notification notification
@param IndexListener $listener
@return RedirectResponse | [
"updates",
"notification",
"notification"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Processor/IndexProcessor.php#L105-L120 |
antaresproject/notifications | src/Processor/IndexProcessor.php | IndexProcessor.preview | public function preview()
{
$inputs = Input::all();
$content = str_replace("'", '"', $inputs['content']);
$content = $this->variablesAdapter->get($content);
if( isset($inputs['subject']) ) {
$subject = str_replace("'", '"', $inputs['subject']);
$subject = $this->variablesAdapter->get($subject);
array_set($inputs, 'subject', $subject);
}
preg_match_all('/\[\[(.*?)\]\]/', $content, $matches);
$view = str_replace($matches[0], $matches[1], $content);
if (array_get($inputs, 'type') === 'email') {
event('antares.notifier.before_send_email', [&$view]);
}
$brandTemplate = BrandOptions::query()->where('brand_id', brand_id())->first();
$header = str_replace('</head>', '<style>' . $brandTemplate->styles . '</style></head>', $brandTemplate->header);
$html = preg_replace("/<body[^>]*>(.*?)<\/body>/is", '<body>' . $view . '</body>', $header . $brandTemplate->footer);
array_set($inputs, 'content', $html);
return $this->presenter->preview($inputs);
} | php | public function preview()
{
$inputs = Input::all();
$content = str_replace("'", '"', $inputs['content']);
$content = $this->variablesAdapter->get($content);
if( isset($inputs['subject']) ) {
$subject = str_replace("'", '"', $inputs['subject']);
$subject = $this->variablesAdapter->get($subject);
array_set($inputs, 'subject', $subject);
}
preg_match_all('/\[\[(.*?)\]\]/', $content, $matches);
$view = str_replace($matches[0], $matches[1], $content);
if (array_get($inputs, 'type') === 'email') {
event('antares.notifier.before_send_email', [&$view]);
}
$brandTemplate = BrandOptions::query()->where('brand_id', brand_id())->first();
$header = str_replace('</head>', '<style>' . $brandTemplate->styles . '</style></head>', $brandTemplate->header);
$html = preg_replace("/<body[^>]*>(.*?)<\/body>/is", '<body>' . $view . '</body>', $header . $brandTemplate->footer);
array_set($inputs, 'content', $html);
return $this->presenter->preview($inputs);
} | [
"public",
"function",
"preview",
"(",
")",
"{",
"$",
"inputs",
"=",
"Input",
"::",
"all",
"(",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"\"'\"",
",",
"'\"'",
",",
"$",
"inputs",
"[",
"'content'",
"]",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"variablesAdapter",
"->",
"get",
"(",
"$",
"content",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"inputs",
"[",
"'subject'",
"]",
")",
")",
"{",
"$",
"subject",
"=",
"str_replace",
"(",
"\"'\"",
",",
"'\"'",
",",
"$",
"inputs",
"[",
"'subject'",
"]",
")",
";",
"$",
"subject",
"=",
"$",
"this",
"->",
"variablesAdapter",
"->",
"get",
"(",
"$",
"subject",
")",
";",
"array_set",
"(",
"$",
"inputs",
",",
"'subject'",
",",
"$",
"subject",
")",
";",
"}",
"preg_match_all",
"(",
"'/\\[\\[(.*?)\\]\\]/'",
",",
"$",
"content",
",",
"$",
"matches",
")",
";",
"$",
"view",
"=",
"str_replace",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"content",
")",
";",
"if",
"(",
"array_get",
"(",
"$",
"inputs",
",",
"'type'",
")",
"===",
"'email'",
")",
"{",
"event",
"(",
"'antares.notifier.before_send_email'",
",",
"[",
"&",
"$",
"view",
"]",
")",
";",
"}",
"$",
"brandTemplate",
"=",
"BrandOptions",
"::",
"query",
"(",
")",
"->",
"where",
"(",
"'brand_id'",
",",
"brand_id",
"(",
")",
")",
"->",
"first",
"(",
")",
";",
"$",
"header",
"=",
"str_replace",
"(",
"'</head>'",
",",
"'<style>'",
".",
"$",
"brandTemplate",
"->",
"styles",
".",
"'</style></head>'",
",",
"$",
"brandTemplate",
"->",
"header",
")",
";",
"$",
"html",
"=",
"preg_replace",
"(",
"\"/<body[^>]*>(.*?)<\\/body>/is\"",
",",
"'<body>'",
".",
"$",
"view",
".",
"'</body>'",
",",
"$",
"header",
".",
"$",
"brandTemplate",
"->",
"footer",
")",
";",
"array_set",
"(",
"$",
"inputs",
",",
"'content'",
",",
"$",
"html",
")",
";",
"return",
"$",
"this",
"->",
"presenter",
"->",
"preview",
"(",
"$",
"inputs",
")",
";",
"}"
] | preview notification notification
@return View | [
"preview",
"notification",
"notification"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Processor/IndexProcessor.php#L180-L207 |
antaresproject/notifications | src/Processor/IndexProcessor.php | IndexProcessor.changeStatus | public function changeStatus(IndexListener $listener, $id)
{
$model = $this->repository->find($id);
if (is_null($model)) {
return $listener->changeStatusFailed();
}
$model->active = $model->active ? 0 : 1;
$model->save();
return $listener->changeStatusSuccess();
} | php | public function changeStatus(IndexListener $listener, $id)
{
$model = $this->repository->find($id);
if (is_null($model)) {
return $listener->changeStatusFailed();
}
$model->active = $model->active ? 0 : 1;
$model->save();
return $listener->changeStatusSuccess();
} | [
"public",
"function",
"changeStatus",
"(",
"IndexListener",
"$",
"listener",
",",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"model",
")",
")",
"{",
"return",
"$",
"listener",
"->",
"changeStatusFailed",
"(",
")",
";",
"}",
"$",
"model",
"->",
"active",
"=",
"$",
"model",
"->",
"active",
"?",
"0",
":",
"1",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"return",
"$",
"listener",
"->",
"changeStatusSuccess",
"(",
")",
";",
"}"
] | change notification notification status
@param IndexListener $listener
@param mixed $id
@return RedirectResponse | [
"change",
"notification",
"notification",
"status"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Processor/IndexProcessor.php#L216-L225 |
antaresproject/notifications | src/Processor/IndexProcessor.php | IndexProcessor.create | public function create($type = null)
{
app('antares.asset')->container('antares/foundation::application')->add('ckeditor', '/packages/ckeditor/ckeditor.js', ['webpack_forms_basic']);
return $this->presenter->create($this->repository->makeModel()->getModel(), $type);
} | php | public function create($type = null)
{
app('antares.asset')->container('antares/foundation::application')->add('ckeditor', '/packages/ckeditor/ckeditor.js', ['webpack_forms_basic']);
return $this->presenter->create($this->repository->makeModel()->getModel(), $type);
} | [
"public",
"function",
"create",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"app",
"(",
"'antares.asset'",
")",
"->",
"container",
"(",
"'antares/foundation::application'",
")",
"->",
"add",
"(",
"'ckeditor'",
",",
"'/packages/ckeditor/ckeditor.js'",
",",
"[",
"'webpack_forms_basic'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"presenter",
"->",
"create",
"(",
"$",
"this",
"->",
"repository",
"->",
"makeModel",
"(",
")",
"->",
"getModel",
"(",
")",
",",
"$",
"type",
")",
";",
"}"
] | Create notification notification form
@param String $type
@return View | [
"Create",
"notification",
"notification",
"form"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Processor/IndexProcessor.php#L233-L237 |
antaresproject/notifications | src/Processor/IndexProcessor.php | IndexProcessor.store | public function store(IndexListener $listener)
{
$model = $this->repository->makeModel()->getModel();
$form = $this->presenter->getForm($model)->onCreate();
if (!$form->isValid()) {
return $listener->storeValidationFailed($form->getMessageBag());
}
try {
$this->repository->store(Input::all());
} catch (Exception $ex) {
return $listener->createFailed();
}
return $listener->createSuccess();
} | php | public function store(IndexListener $listener)
{
$model = $this->repository->makeModel()->getModel();
$form = $this->presenter->getForm($model)->onCreate();
if (!$form->isValid()) {
return $listener->storeValidationFailed($form->getMessageBag());
}
try {
$this->repository->store(Input::all());
} catch (Exception $ex) {
return $listener->createFailed();
}
return $listener->createSuccess();
} | [
"public",
"function",
"store",
"(",
"IndexListener",
"$",
"listener",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"repository",
"->",
"makeModel",
"(",
")",
"->",
"getModel",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"presenter",
"->",
"getForm",
"(",
"$",
"model",
")",
"->",
"onCreate",
"(",
")",
";",
"if",
"(",
"!",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"$",
"listener",
"->",
"storeValidationFailed",
"(",
"$",
"form",
"->",
"getMessageBag",
"(",
")",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"repository",
"->",
"store",
"(",
"Input",
"::",
"all",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"$",
"listener",
"->",
"createFailed",
"(",
")",
";",
"}",
"return",
"$",
"listener",
"->",
"createSuccess",
"(",
")",
";",
"}"
] | store new notification notification
@param IndexListener $listener
@return RedirectResponse | [
"store",
"new",
"notification",
"notification"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Processor/IndexProcessor.php#L245-L258 |
antaresproject/notifications | src/Processor/IndexProcessor.php | IndexProcessor.delete | public function delete($id, IndexListener $listener)
{
try {
$model = $this->repository->makeModel()->findOrFail($id);
$model->delete();
return $listener->deleteSuccess();
} catch (Exception $ex) {
return $listener->deleteFailed();
}
} | php | public function delete($id, IndexListener $listener)
{
try {
$model = $this->repository->makeModel()->findOrFail($id);
$model->delete();
return $listener->deleteSuccess();
} catch (Exception $ex) {
return $listener->deleteFailed();
}
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
",",
"IndexListener",
"$",
"listener",
")",
"{",
"try",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"repository",
"->",
"makeModel",
"(",
")",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"$",
"model",
"->",
"delete",
"(",
")",
";",
"return",
"$",
"listener",
"->",
"deleteSuccess",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"$",
"listener",
"->",
"deleteFailed",
"(",
")",
";",
"}",
"}"
] | deletes custom notification
@param mixed $id
@param IndexListener $listener
@return RedirectResponse | [
"deletes",
"custom",
"notification"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Processor/IndexProcessor.php#L267-L276 |
i-lateral/silverstripe-modeladminplus | src/ModelAdminPlus.php | ModelAdminPlus.getSnippets | public function getSnippets()
{
$snippets = ArrayList::create();
// Setup any model admin plus snippets
foreach ($this->config()->registered_snippets as $snippet) {
$snippet = Injector::inst()->create($snippet);
$snippet->setParent($this);
$snippets->add($snippet);
}
$snippets = $snippets->sort("Order", "DESC");
$this->extend("updateSnippets", $snippets);
return $snippets;
} | php | public function getSnippets()
{
$snippets = ArrayList::create();
// Setup any model admin plus snippets
foreach ($this->config()->registered_snippets as $snippet) {
$snippet = Injector::inst()->create($snippet);
$snippet->setParent($this);
$snippets->add($snippet);
}
$snippets = $snippets->sort("Order", "DESC");
$this->extend("updateSnippets", $snippets);
return $snippets;
} | [
"public",
"function",
"getSnippets",
"(",
")",
"{",
"$",
"snippets",
"=",
"ArrayList",
"::",
"create",
"(",
")",
";",
"// Setup any model admin plus snippets",
"foreach",
"(",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"registered_snippets",
"as",
"$",
"snippet",
")",
"{",
"$",
"snippet",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"$",
"snippet",
")",
";",
"$",
"snippet",
"->",
"setParent",
"(",
"$",
"this",
")",
";",
"$",
"snippets",
"->",
"add",
"(",
"$",
"snippet",
")",
";",
"}",
"$",
"snippets",
"=",
"$",
"snippets",
"->",
"sort",
"(",
"\"Order\"",
",",
"\"DESC\"",
")",
";",
"$",
"this",
"->",
"extend",
"(",
"\"updateSnippets\"",
",",
"$",
"snippets",
")",
";",
"return",
"$",
"snippets",
";",
"}"
] | Setup | [
"Setup"
] | train | https://github.com/i-lateral/silverstripe-modeladminplus/blob/c5209d9610cdb36ddc7b9231fad342df7e75ffc0/src/ModelAdminPlus.php#L72-L88 |
i-lateral/silverstripe-modeladminplus | src/ModelAdminPlus.php | ModelAdminPlus.getExportFields | public function getExportFields()
{
$export_fields = Config::inst()->get(
$this->modelClass,
self::EXPORT_FIELDS
);
if (isset($export_fields) && is_array($export_fields)) {
$fields = $export_fields;
} else {
$fields = parent::getExportFields();
}
$this->extend("updateExportFields", $fields);
return $fields;
} | php | public function getExportFields()
{
$export_fields = Config::inst()->get(
$this->modelClass,
self::EXPORT_FIELDS
);
if (isset($export_fields) && is_array($export_fields)) {
$fields = $export_fields;
} else {
$fields = parent::getExportFields();
}
$this->extend("updateExportFields", $fields);
return $fields;
} | [
"public",
"function",
"getExportFields",
"(",
")",
"{",
"$",
"export_fields",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"modelClass",
",",
"self",
"::",
"EXPORT_FIELDS",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"export_fields",
")",
"&&",
"is_array",
"(",
"$",
"export_fields",
")",
")",
"{",
"$",
"fields",
"=",
"$",
"export_fields",
";",
"}",
"else",
"{",
"$",
"fields",
"=",
"parent",
"::",
"getExportFields",
"(",
")",
";",
"}",
"$",
"this",
"->",
"extend",
"(",
"\"updateExportFields\"",
",",
"$",
"fields",
")",
";",
"return",
"$",
"fields",
";",
"}"
] | Get the default export fields for the current model.
First this checks if there is an `export_fields` config variable set on
the model class, if not, it reverts to the default behaviour.
@return array | [
"Get",
"the",
"default",
"export",
"fields",
"for",
"the",
"current",
"model",
"."
] | train | https://github.com/i-lateral/silverstripe-modeladminplus/blob/c5209d9610cdb36ddc7b9231fad342df7e75ffc0/src/ModelAdminPlus.php#L118-L134 |
i-lateral/silverstripe-modeladminplus | src/ModelAdminPlus.php | ModelAdminPlus.getSearchSessionName | public function getSearchSessionName()
{
$curr = $this->sanitiseClassName(self::class);
$model = $this->sanitiseClassName($this->modelClass);
return $curr . "." . $model;
} | php | public function getSearchSessionName()
{
$curr = $this->sanitiseClassName(self::class);
$model = $this->sanitiseClassName($this->modelClass);
return $curr . "." . $model;
} | [
"public",
"function",
"getSearchSessionName",
"(",
")",
"{",
"$",
"curr",
"=",
"$",
"this",
"->",
"sanitiseClassName",
"(",
"self",
"::",
"class",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"sanitiseClassName",
"(",
"$",
"this",
"->",
"modelClass",
")",
";",
"return",
"$",
"curr",
".",
"\".\"",
".",
"$",
"model",
";",
"}"
] | Get the name of the session to be useed by this model admin's search
form.
@return string | [
"Get",
"the",
"name",
"of",
"the",
"session",
"to",
"be",
"useed",
"by",
"this",
"model",
"admin",
"s",
"search",
"form",
"."
] | train | https://github.com/i-lateral/silverstripe-modeladminplus/blob/c5209d9610cdb36ddc7b9231fad342df7e75ffc0/src/ModelAdminPlus.php#L142-L147 |
i-lateral/silverstripe-modeladminplus | src/ModelAdminPlus.php | ModelAdminPlus.setSearchSession | public function setSearchSession($data)
{
$session = $this->getRequest()->getSession();
return $session->set($this->getSearchSessionName(), $data);
} | php | public function setSearchSession($data)
{
$session = $this->getRequest()->getSession();
return $session->set($this->getSearchSessionName(), $data);
} | [
"public",
"function",
"setSearchSession",
"(",
"$",
"data",
")",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getSession",
"(",
")",
";",
"return",
"$",
"session",
"->",
"set",
"(",
"$",
"this",
"->",
"getSearchSessionName",
"(",
")",
",",
"$",
"data",
")",
";",
"}"
] | Set some data to a search session. This needs to be an array of
data (like the data submitted by a form).
@param array $data An array of data to store in the session
@return self | [
"Set",
"some",
"data",
"to",
"a",
"search",
"session",
".",
"This",
"needs",
"to",
"be",
"an",
"array",
"of",
"data",
"(",
"like",
"the",
"data",
"submitted",
"by",
"a",
"form",
")",
"."
] | train | https://github.com/i-lateral/silverstripe-modeladminplus/blob/c5209d9610cdb36ddc7b9231fad342df7e75ffc0/src/ModelAdminPlus.php#L179-L183 |
i-lateral/silverstripe-modeladminplus | src/ModelAdminPlus.php | ModelAdminPlus.getSearchData | public function getSearchData()
{
$data = $this->getSearchSession();
if (!$data || $data && !is_array($data)) {
$data = [];
}
return $data;
} | php | public function getSearchData()
{
$data = $this->getSearchSession();
if (!$data || $data && !is_array($data)) {
$data = [];
}
return $data;
} | [
"public",
"function",
"getSearchData",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getSearchSession",
"(",
")",
";",
"if",
"(",
"!",
"$",
"data",
"||",
"$",
"data",
"&&",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Get the current search results, combined with any saved
search results and resturn (as an array).
@return array | [
"Get",
"the",
"current",
"search",
"results",
"combined",
"with",
"any",
"saved",
"search",
"results",
"and",
"resturn",
"(",
"as",
"an",
"array",
")",
"."
] | train | https://github.com/i-lateral/silverstripe-modeladminplus/blob/c5209d9610cdb36ddc7b9231fad342df7e75ffc0/src/ModelAdminPlus.php#L191-L200 |
i-lateral/silverstripe-modeladminplus | src/ModelAdminPlus.php | ModelAdminPlus.getEditForm | public function getEditForm($id = null, $fields = null)
{
$form = parent::getEditForm($id, $fields);
$grid_field = $form
->Fields()
->fieldByName($this->sanitiseClassName($this->modelClass));
// Add bulk editing to gridfield
$manager = new BulkManager();
$manager->removeBulkAction(UnlinkHandler::class);
$config = $grid_field->getConfig();
$config
->removeComponentsByType(GridFieldPaginator::class)
->addComponent($manager)
->addComponent(new GridFieldConfigurablePaginator());
// Switch to custom filter header
$config
->removeComponentsByType(SSGridFieldFilterHeader::class)
->addComponent(new GridFieldFilterHeader(
false,
function ($context) {
$this->extend('updateSearchContext', $context);
},
function ($form) {
$this->extend('updateSearchForm', $form);
}
));
if (!$this->showSearchForm ||
(is_array($this->showSearchForm) && !in_array($this->modelClass, $this->showSearchForm))
) {
$config->removeComponentsByType(GridFieldFilterHeader::class);
}
if ($this->config()->auto_convert_dates) {
GridFieldDateFinder::create($grid_field)->convertDateFields();
}
return $form;
} | php | public function getEditForm($id = null, $fields = null)
{
$form = parent::getEditForm($id, $fields);
$grid_field = $form
->Fields()
->fieldByName($this->sanitiseClassName($this->modelClass));
// Add bulk editing to gridfield
$manager = new BulkManager();
$manager->removeBulkAction(UnlinkHandler::class);
$config = $grid_field->getConfig();
$config
->removeComponentsByType(GridFieldPaginator::class)
->addComponent($manager)
->addComponent(new GridFieldConfigurablePaginator());
// Switch to custom filter header
$config
->removeComponentsByType(SSGridFieldFilterHeader::class)
->addComponent(new GridFieldFilterHeader(
false,
function ($context) {
$this->extend('updateSearchContext', $context);
},
function ($form) {
$this->extend('updateSearchForm', $form);
}
));
if (!$this->showSearchForm ||
(is_array($this->showSearchForm) && !in_array($this->modelClass, $this->showSearchForm))
) {
$config->removeComponentsByType(GridFieldFilterHeader::class);
}
if ($this->config()->auto_convert_dates) {
GridFieldDateFinder::create($grid_field)->convertDateFields();
}
return $form;
} | [
"public",
"function",
"getEditForm",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"$",
"form",
"=",
"parent",
"::",
"getEditForm",
"(",
"$",
"id",
",",
"$",
"fields",
")",
";",
"$",
"grid_field",
"=",
"$",
"form",
"->",
"Fields",
"(",
")",
"->",
"fieldByName",
"(",
"$",
"this",
"->",
"sanitiseClassName",
"(",
"$",
"this",
"->",
"modelClass",
")",
")",
";",
"// Add bulk editing to gridfield",
"$",
"manager",
"=",
"new",
"BulkManager",
"(",
")",
";",
"$",
"manager",
"->",
"removeBulkAction",
"(",
"UnlinkHandler",
"::",
"class",
")",
";",
"$",
"config",
"=",
"$",
"grid_field",
"->",
"getConfig",
"(",
")",
";",
"$",
"config",
"->",
"removeComponentsByType",
"(",
"GridFieldPaginator",
"::",
"class",
")",
"->",
"addComponent",
"(",
"$",
"manager",
")",
"->",
"addComponent",
"(",
"new",
"GridFieldConfigurablePaginator",
"(",
")",
")",
";",
"// Switch to custom filter header",
"$",
"config",
"->",
"removeComponentsByType",
"(",
"SSGridFieldFilterHeader",
"::",
"class",
")",
"->",
"addComponent",
"(",
"new",
"GridFieldFilterHeader",
"(",
"false",
",",
"function",
"(",
"$",
"context",
")",
"{",
"$",
"this",
"->",
"extend",
"(",
"'updateSearchContext'",
",",
"$",
"context",
")",
";",
"}",
",",
"function",
"(",
"$",
"form",
")",
"{",
"$",
"this",
"->",
"extend",
"(",
"'updateSearchForm'",
",",
"$",
"form",
")",
";",
"}",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"showSearchForm",
"||",
"(",
"is_array",
"(",
"$",
"this",
"->",
"showSearchForm",
")",
"&&",
"!",
"in_array",
"(",
"$",
"this",
"->",
"modelClass",
",",
"$",
"this",
"->",
"showSearchForm",
")",
")",
")",
"{",
"$",
"config",
"->",
"removeComponentsByType",
"(",
"GridFieldFilterHeader",
"::",
"class",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"auto_convert_dates",
")",
"{",
"GridFieldDateFinder",
"::",
"create",
"(",
"$",
"grid_field",
")",
"->",
"convertDateFields",
"(",
")",
";",
"}",
"return",
"$",
"form",
";",
"}"
] | Add bulk editor to Edit Form
@param int|null $id
@param FieldList $fields
@return Form A Form object | [
"Add",
"bulk",
"editor",
"to",
"Edit",
"Form"
] | train | https://github.com/i-lateral/silverstripe-modeladminplus/blob/c5209d9610cdb36ddc7b9231fad342df7e75ffc0/src/ModelAdminPlus.php#L210-L252 |
i-lateral/silverstripe-modeladminplus | src/ModelAdminPlus.php | ModelAdminPlus.search | public function search($data, $form)
{
foreach ($data as $key => $value) {
// Ensure we clear any null values
// so they don't mess up the list
if (empty($data[$key])) {
unset($data[$key]);
}
// Ensure we clear any null values
// so they don't mess up the list
if (strpos($key, "action_") !== false) {
unset($data[$key]);
}
}
$this->setSearchSession($data);
return $this->redirectBack();
} | php | public function search($data, $form)
{
foreach ($data as $key => $value) {
// Ensure we clear any null values
// so they don't mess up the list
if (empty($data[$key])) {
unset($data[$key]);
}
// Ensure we clear any null values
// so they don't mess up the list
if (strpos($key, "action_") !== false) {
unset($data[$key]);
}
}
$this->setSearchSession($data);
return $this->redirectBack();
} | [
"public",
"function",
"search",
"(",
"$",
"data",
",",
"$",
"form",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Ensure we clear any null values",
"// so they don't mess up the list",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"// Ensure we clear any null values",
"// so they don't mess up the list",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"\"action_\"",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"setSearchSession",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"redirectBack",
"(",
")",
";",
"}"
] | Set the session from the submitted form data (and redirect back)
@param array $data Submitted form
@param Form $form The current form
@return HTTPResponse | [
"Set",
"the",
"session",
"from",
"the",
"submitted",
"form",
"data",
"(",
"and",
"redirect",
"back",
")"
] | train | https://github.com/i-lateral/silverstripe-modeladminplus/blob/c5209d9610cdb36ddc7b9231fad342df7e75ffc0/src/ModelAdminPlus.php#L262-L281 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.