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
|
---|---|---|---|---|---|---|---|---|---|---|
netzmacht-archive/subcolumns_bootstrap_customizable | src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php | ColumnSet.getAllColumnsets | public function getAllColumnsets($dc)
{
$collection = ColumnsetModel::findBy('published=1 AND columns', $dc->activeRecord->sc_type, array('order' => 'title'));
$set = array();
if($collection !== null)
{
while($collection->next()) {
$set[$collection->id] = $collection->title;
}
}
return $set;
} | php | public function getAllColumnsets($dc)
{
$collection = ColumnsetModel::findBy('published=1 AND columns', $dc->activeRecord->sc_type, array('order' => 'title'));
$set = array();
if($collection !== null)
{
while($collection->next()) {
$set[$collection->id] = $collection->title;
}
}
return $set;
} | [
"public",
"function",
"getAllColumnsets",
"(",
"$",
"dc",
")",
"{",
"$",
"collection",
"=",
"ColumnsetModel",
"::",
"findBy",
"(",
"'published=1 AND columns'",
",",
"$",
"dc",
"->",
"activeRecord",
"->",
"sc_type",
",",
"array",
"(",
"'order'",
"=>",
"'title'",
")",
")",
";",
"$",
"set",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"collection",
"!==",
"null",
")",
"{",
"while",
"(",
"$",
"collection",
"->",
"next",
"(",
")",
")",
"{",
"$",
"set",
"[",
"$",
"collection",
"->",
"id",
"]",
"=",
"$",
"collection",
"->",
"title",
";",
"}",
"}",
"return",
"$",
"set",
";",
"}"
] | get all columnsets which fits to the selected type
@param $dc
@return array | [
"get",
"all",
"columnsets",
"which",
"fits",
"to",
"the",
"selected",
"type"
] | train | https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/ColumnSet.php#L225-L238 |
fulgurio/LightCMSBundle | Entity/PageMeta.php | PageMeta.setPage | public function setPage(\Fulgurio\LightCMSBundle\Entity\Page $page = null)
{
$this->page = $page;
return $this;
} | php | public function setPage(\Fulgurio\LightCMSBundle\Entity\Page $page = null)
{
$this->page = $page;
return $this;
} | [
"public",
"function",
"setPage",
"(",
"\\",
"Fulgurio",
"\\",
"LightCMSBundle",
"\\",
"Entity",
"\\",
"Page",
"$",
"page",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"page",
"=",
"$",
"page",
";",
"return",
"$",
"this",
";",
"}"
] | Set page
@param \Fulgurio\LightCMSBundle\Entity\Page $page
@return PageMeta | [
"Set",
"page"
] | train | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Entity/PageMeta.php#L103-L108 |
MindyPHP/OrmBundle | DependencyInjection/OrmExtension.php | OrmExtension.load | public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$connectionManagerDefinition = $container->getDefinition(ConnectionManager::class);
$connectionManagerDefinition->setArguments([
$config['connections'],
$config['default_connection'],
]);
} | php | public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$connectionManagerDefinition = $container->getDefinition(ConnectionManager::class);
$connectionManagerDefinition->setArguments([
$config['connections'],
$config['default_connection'],
]);
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"loader",
"=",
"new",
"YamlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/../Resources/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services.yaml'",
")",
";",
"$",
"configuration",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
"$",
"configs",
",",
"$",
"container",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"processConfiguration",
"(",
"$",
"configuration",
",",
"$",
"configs",
")",
";",
"$",
"connectionManagerDefinition",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"ConnectionManager",
"::",
"class",
")",
";",
"$",
"connectionManagerDefinition",
"->",
"setArguments",
"(",
"[",
"$",
"config",
"[",
"'connections'",
"]",
",",
"$",
"config",
"[",
"'default_connection'",
"]",
",",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/MindyPHP/OrmBundle/blob/54dec3bbe78d45efafc4258cc47206846330c519/DependencyInjection/OrmExtension.php#L25-L38 |
WellCommerce/CartBundle | Visitor/CartShippingMethodVisitor.php | CartShippingMethodVisitor.visitCart | public function visitCart(CartInterface $cart)
{
$cartShippingMethodCost = $cart->getShippingMethodCost();
if (null === $cartShippingMethodCost) {
$shippingMethodCostCollection = $this->getShippingMethodCostCollection($cart);
if ($shippingMethodCostCollection->count()) {
$cart->setShippingMethodCost($shippingMethodCostCollection->first());
}
}
} | php | public function visitCart(CartInterface $cart)
{
$cartShippingMethodCost = $cart->getShippingMethodCost();
if (null === $cartShippingMethodCost) {
$shippingMethodCostCollection = $this->getShippingMethodCostCollection($cart);
if ($shippingMethodCostCollection->count()) {
$cart->setShippingMethodCost($shippingMethodCostCollection->first());
}
}
} | [
"public",
"function",
"visitCart",
"(",
"CartInterface",
"$",
"cart",
")",
"{",
"$",
"cartShippingMethodCost",
"=",
"$",
"cart",
"->",
"getShippingMethodCost",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"cartShippingMethodCost",
")",
"{",
"$",
"shippingMethodCostCollection",
"=",
"$",
"this",
"->",
"getShippingMethodCostCollection",
"(",
"$",
"cart",
")",
";",
"if",
"(",
"$",
"shippingMethodCostCollection",
"->",
"count",
"(",
")",
")",
"{",
"$",
"cart",
"->",
"setShippingMethodCost",
"(",
"$",
"shippingMethodCostCollection",
"->",
"first",
"(",
")",
")",
";",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/WellCommerce/CartBundle/blob/77c1e12b36bde008dca61260481b21135e339396/Visitor/CartShippingMethodVisitor.php#L43-L53 |
leprephp/di | src/ExtensionQueue.php | ExtensionQueue.getService | public function getService($service)
{
foreach ($this->queue as $extension) {
$new = call_user_func($extension, $service, $this->container);
if ($new) {
$service = $new;
}
}
return $service;
} | php | public function getService($service)
{
foreach ($this->queue as $extension) {
$new = call_user_func($extension, $service, $this->container);
if ($new) {
$service = $new;
}
}
return $service;
} | [
"public",
"function",
"getService",
"(",
"$",
"service",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"queue",
"as",
"$",
"extension",
")",
"{",
"$",
"new",
"=",
"call_user_func",
"(",
"$",
"extension",
",",
"$",
"service",
",",
"$",
"this",
"->",
"container",
")",
";",
"if",
"(",
"$",
"new",
")",
"{",
"$",
"service",
"=",
"$",
"new",
";",
"}",
"}",
"return",
"$",
"service",
";",
"}"
] | Gets the extended version of the service.
@param mixed $service
@return mixed | [
"Gets",
"the",
"extended",
"version",
"of",
"the",
"service",
"."
] | train | https://github.com/leprephp/di/blob/d7de90c0d44714abd70c4f5bd5341a1a87203a7e/src/ExtensionQueue.php#L60-L71 |
SandratraRM/mora-core | src/cli/Manager/Controller/ControllerEdit.php | ControllerEdit.refactorRoute | private static function refactorRoute($old, $new)
{
$confPath = CustomRoutesManager::$path;
$conf = new ArrayConfigManager($confPath);
$routes = $conf->getConfigsArray();
while($key = array_search($old,$routes)){
$routes[$key] = $new;
}
$conf->setConfigsArray($routes);
$conf->writeConfig();
} | php | private static function refactorRoute($old, $new)
{
$confPath = CustomRoutesManager::$path;
$conf = new ArrayConfigManager($confPath);
$routes = $conf->getConfigsArray();
while($key = array_search($old,$routes)){
$routes[$key] = $new;
}
$conf->setConfigsArray($routes);
$conf->writeConfig();
} | [
"private",
"static",
"function",
"refactorRoute",
"(",
"$",
"old",
",",
"$",
"new",
")",
"{",
"$",
"confPath",
"=",
"CustomRoutesManager",
"::",
"$",
"path",
";",
"$",
"conf",
"=",
"new",
"ArrayConfigManager",
"(",
"$",
"confPath",
")",
";",
"$",
"routes",
"=",
"$",
"conf",
"->",
"getConfigsArray",
"(",
")",
";",
"while",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"old",
",",
"$",
"routes",
")",
")",
"{",
"$",
"routes",
"[",
"$",
"key",
"]",
"=",
"$",
"new",
";",
"}",
"$",
"conf",
"->",
"setConfigsArray",
"(",
"$",
"routes",
")",
";",
"$",
"conf",
"->",
"writeConfig",
"(",
")",
";",
"}"
] | TODO Rename Refactors | [
"TODO",
"Rename",
"Refactors"
] | train | https://github.com/SandratraRM/mora-core/blob/9cd8e16e4b619798a51dc2ac66ddd8d22caf7baa/src/cli/Manager/Controller/ControllerEdit.php#L72-L82 |
eureka-framework/component-template | src/Template/Pattern/PatternEcho.php | PatternEcho.render | public function render()
{
//~ Search echo
$pattern = '`{{@((i|f|s|e)[|])?(.+?)}}`is';
$replace = array();
$matches = array();
if ((bool) preg_match_all($pattern, $this->templateContent, $matches)) {
foreach ($matches[0] as $index => $replaceString) {
$cast = $matches[2][$index];
$content = $matches[3][$index];
switch ($cast) {
case 'i':
$cast = '(int) ';
break;
case 'f':
$cast = '(float) ';
break;
case 's':
$cast = '(string) ';
break;
case 'e':
$cast = 'htmle(';
$content .= ')';
break;
default:
$cast = '';
}
$replace[$replaceString] = '<?=' . $cast . $content . '?>';
}
$this->templateContent = trim(str_replace(array_keys($replace), $replace, $this->templateContent));
}
return $this->templateContent;
} | php | public function render()
{
//~ Search echo
$pattern = '`{{@((i|f|s|e)[|])?(.+?)}}`is';
$replace = array();
$matches = array();
if ((bool) preg_match_all($pattern, $this->templateContent, $matches)) {
foreach ($matches[0] as $index => $replaceString) {
$cast = $matches[2][$index];
$content = $matches[3][$index];
switch ($cast) {
case 'i':
$cast = '(int) ';
break;
case 'f':
$cast = '(float) ';
break;
case 's':
$cast = '(string) ';
break;
case 'e':
$cast = 'htmle(';
$content .= ')';
break;
default:
$cast = '';
}
$replace[$replaceString] = '<?=' . $cast . $content . '?>';
}
$this->templateContent = trim(str_replace(array_keys($replace), $replace, $this->templateContent));
}
return $this->templateContent;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"//~ Search echo",
"$",
"pattern",
"=",
"'`{{@((i|f|s|e)[|])?(.+?)}}`is'",
";",
"$",
"replace",
"=",
"array",
"(",
")",
";",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"(",
"bool",
")",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"templateContent",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"index",
"=>",
"$",
"replaceString",
")",
"{",
"$",
"cast",
"=",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"index",
"]",
";",
"$",
"content",
"=",
"$",
"matches",
"[",
"3",
"]",
"[",
"$",
"index",
"]",
";",
"switch",
"(",
"$",
"cast",
")",
"{",
"case",
"'i'",
":",
"$",
"cast",
"=",
"'(int) '",
";",
"break",
";",
"case",
"'f'",
":",
"$",
"cast",
"=",
"'(float) '",
";",
"break",
";",
"case",
"'s'",
":",
"$",
"cast",
"=",
"'(string) '",
";",
"break",
";",
"case",
"'e'",
":",
"$",
"cast",
"=",
"'htmle('",
";",
"$",
"content",
".=",
"')'",
";",
"break",
";",
"default",
":",
"$",
"cast",
"=",
"''",
";",
"}",
"$",
"replace",
"[",
"$",
"replaceString",
"]",
"=",
"'<?='",
".",
"$",
"cast",
".",
"$",
"content",
".",
"'?>'",
";",
"}",
"$",
"this",
"->",
"templateContent",
"=",
"trim",
"(",
"str_replace",
"(",
"array_keys",
"(",
"$",
"replace",
")",
",",
"$",
"replace",
",",
"$",
"this",
"->",
"templateContent",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"templateContent",
";",
"}"
] | Search & replace current defined pattern for template.
Example of template:
<code>
# In Template:
#
# ({@i|$intVar}}
# ({@f|$floatVar}}
# ({@s|$stringVar}}
# ({@e|$stringVar}}
# ({@$stringVar}}
#
# In Compiled template:
<=(int) $intVar?>
<=(float) $intVar?>
<=(string) $intVar?>
<=htmle($intVar)?>
<=$intVar?>
</code>
@return string Compiled template | [
"Search",
"&",
"replace",
"current",
"defined",
"pattern",
"for",
"template",
".",
"Example",
"of",
"template",
":"
] | train | https://github.com/eureka-framework/component-template/blob/42e9b3954b79892ba340ba7ca909f03ee99c36fe/src/Template/Pattern/PatternEcho.php#L42-L81 |
Nicklas766/Comment | src/Comment/HTMLForm/Admin/EditUserForm.php | EditUserForm.callbackSubmit | public function callbackSubmit()
{
// Get values from the submitted form
$email = $this->form->value("email");
if (strpos($email, '%') !== false) {
$this->form->addOutput("% is not allowed");
return false;
}
$user = $this->user;
$user->email = $email;
$user->authority = $this->form->value("select") ?: "user";
$user->save();
$this->form->addOutput("Du uppdaterade användaren");
return true;
} | php | public function callbackSubmit()
{
// Get values from the submitted form
$email = $this->form->value("email");
if (strpos($email, '%') !== false) {
$this->form->addOutput("% is not allowed");
return false;
}
$user = $this->user;
$user->email = $email;
$user->authority = $this->form->value("select") ?: "user";
$user->save();
$this->form->addOutput("Du uppdaterade användaren");
return true;
} | [
"public",
"function",
"callbackSubmit",
"(",
")",
"{",
"// Get values from the submitted form",
"$",
"email",
"=",
"$",
"this",
"->",
"form",
"->",
"value",
"(",
"\"email\"",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"email",
",",
"'%'",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"form",
"->",
"addOutput",
"(",
"\"% is not allowed\"",
")",
";",
"return",
"false",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"user",
";",
"$",
"user",
"->",
"email",
"=",
"$",
"email",
";",
"$",
"user",
"->",
"authority",
"=",
"$",
"this",
"->",
"form",
"->",
"value",
"(",
"\"select\"",
")",
"?",
":",
"\"user\"",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"form",
"->",
"addOutput",
"(",
"\"Du uppdaterade användaren\")",
";",
"",
"return",
"true",
";",
"}"
] | Callback for submit-button which should return true if it could
carry out its work and false if something failed.
@return boolean true if okey, false if something went wrong. | [
"Callback",
"for",
"submit",
"-",
"button",
"which",
"should",
"return",
"true",
"if",
"it",
"could",
"carry",
"out",
"its",
"work",
"and",
"false",
"if",
"something",
"failed",
"."
] | train | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/HTMLForm/Admin/EditUserForm.php#L65-L82 |
MichaelJ2324/PHP-REST-Client | src/Endpoint/Abstracts/AbstractCollectionEndpoint.php | AbstractCollectionEndpoint.update | public function update(array $collection){
foreach($collection as $key => $value){
$this->collection[$key] = $value;
}
return $this;
} | php | public function update(array $collection){
foreach($collection as $key => $value){
$this->collection[$key] = $value;
}
return $this;
} | [
"public",
"function",
"update",
"(",
"array",
"$",
"collection",
")",
"{",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"collection",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Update and append to Collection array
@param array $collection
@return self | [
"Update",
"and",
"append",
"to",
"Collection",
"array"
] | train | https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractCollectionEndpoint.php#L112-L117 |
MichaelJ2324/PHP-REST-Client | src/Endpoint/Abstracts/AbstractCollectionEndpoint.php | AbstractCollectionEndpoint.at | public function at($index){
$return = NULL;
$index = intval($index);
$data = $this->asArray();
reset($data);
if ($index < 0){
$index += $this->length();
}
$c = 1;
while ($c <= $index){
next($data);
$c++;
}
$return = current($data);
$Model = $this->buildModel($return);
if ($Model !== NULL){
$return = $Model;
}
return $return;
} | php | public function at($index){
$return = NULL;
$index = intval($index);
$data = $this->asArray();
reset($data);
if ($index < 0){
$index += $this->length();
}
$c = 1;
while ($c <= $index){
next($data);
$c++;
}
$return = current($data);
$Model = $this->buildModel($return);
if ($Model !== NULL){
$return = $Model;
}
return $return;
} | [
"public",
"function",
"at",
"(",
"$",
"index",
")",
"{",
"$",
"return",
"=",
"NULL",
";",
"$",
"index",
"=",
"intval",
"(",
"$",
"index",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"asArray",
"(",
")",
";",
"reset",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"index",
"<",
"0",
")",
"{",
"$",
"index",
"+=",
"$",
"this",
"->",
"length",
"(",
")",
";",
"}",
"$",
"c",
"=",
"1",
";",
"while",
"(",
"$",
"c",
"<=",
"$",
"index",
")",
"{",
"next",
"(",
"$",
"data",
")",
";",
"$",
"c",
"++",
";",
"}",
"$",
"return",
"=",
"current",
"(",
"$",
"data",
")",
";",
"$",
"Model",
"=",
"$",
"this",
"->",
"buildModel",
"(",
"$",
"return",
")",
";",
"if",
"(",
"$",
"Model",
"!==",
"NULL",
")",
"{",
"$",
"return",
"=",
"$",
"Model",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Get a model based on numerical index
@param int $index
@return array|ModelInterface | [
"Get",
"a",
"model",
"based",
"on",
"numerical",
"index"
] | train | https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractCollectionEndpoint.php#L149-L168 |
MichaelJ2324/PHP-REST-Client | src/Endpoint/Abstracts/AbstractCollectionEndpoint.php | AbstractCollectionEndpoint.updateCollection | protected function updateCollection(){
$responseBody = $this->Response->getBody();
if (is_array($responseBody)){
if (isset($this->model)){
$modelIdKey = $this->buildModel()->modelIdKey();
foreach($responseBody as $key => $model){
if (isset($model[$modelIdKey])){
$this->collection[$model[$modelIdKey]] = $model;
} else {
$this->collection[] = $model;
}
}
} else {
$this->collection = $responseBody;
}
}
} | php | protected function updateCollection(){
$responseBody = $this->Response->getBody();
if (is_array($responseBody)){
if (isset($this->model)){
$modelIdKey = $this->buildModel()->modelIdKey();
foreach($responseBody as $key => $model){
if (isset($model[$modelIdKey])){
$this->collection[$model[$modelIdKey]] = $model;
} else {
$this->collection[] = $model;
}
}
} else {
$this->collection = $responseBody;
}
}
} | [
"protected",
"function",
"updateCollection",
"(",
")",
"{",
"$",
"responseBody",
"=",
"$",
"this",
"->",
"Response",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"responseBody",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"model",
")",
")",
"{",
"$",
"modelIdKey",
"=",
"$",
"this",
"->",
"buildModel",
"(",
")",
"->",
"modelIdKey",
"(",
")",
";",
"foreach",
"(",
"$",
"responseBody",
"as",
"$",
"key",
"=>",
"$",
"model",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"model",
"[",
"$",
"modelIdKey",
"]",
")",
")",
"{",
"$",
"this",
"->",
"collection",
"[",
"$",
"model",
"[",
"$",
"modelIdKey",
"]",
"]",
"=",
"$",
"model",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"collection",
"[",
"]",
"=",
"$",
"model",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"collection",
"=",
"$",
"responseBody",
";",
"}",
"}",
"}"
] | Configures the collection based on the Response Body | [
"Configures",
"the",
"collection",
"based",
"on",
"the",
"Response",
"Body"
] | train | https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractCollectionEndpoint.php#L229-L245 |
MichaelJ2324/PHP-REST-Client | src/Endpoint/Abstracts/AbstractCollectionEndpoint.php | AbstractCollectionEndpoint.buildModel | protected function buildModel(array $data = array()){
$Model = NULL;
if (isset($this->model)){
$Model = new $this->model();
$Model->setBaseUrl($this->getBaseUrl());
if ($this->getAuth() !== NULL) {
$Model->setAuth($this->getAuth());
}
if (!empty($data)){
foreach($data as $key => $value){
$Model->set($key,$value);
}
}
}
return $Model;
} | php | protected function buildModel(array $data = array()){
$Model = NULL;
if (isset($this->model)){
$Model = new $this->model();
$Model->setBaseUrl($this->getBaseUrl());
if ($this->getAuth() !== NULL) {
$Model->setAuth($this->getAuth());
}
if (!empty($data)){
foreach($data as $key => $value){
$Model->set($key,$value);
}
}
}
return $Model;
} | [
"protected",
"function",
"buildModel",
"(",
"array",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"$",
"Model",
"=",
"NULL",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"model",
")",
")",
"{",
"$",
"Model",
"=",
"new",
"$",
"this",
"->",
"model",
"(",
")",
";",
"$",
"Model",
"->",
"setBaseUrl",
"(",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getAuth",
"(",
")",
"!==",
"NULL",
")",
"{",
"$",
"Model",
"->",
"setAuth",
"(",
"$",
"this",
"->",
"getAuth",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"Model",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"return",
"$",
"Model",
";",
"}"
] | Build the ModelEndpoint
@param array $data
@return AbstractModelEndpoint | [
"Build",
"the",
"ModelEndpoint"
] | train | https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractCollectionEndpoint.php#L252-L267 |
Gendoria/command-queue | src/Gendoria/CommandQueue/QueueManager/MultipleQueueManager.php | MultipleQueueManager.addSendDriver | public function addSendDriver(
$pool, SendDriverInterface $sendDriver, $isDefault = false
)
{
$this->sendDrivers[$pool] = $sendDriver;
if (!$this->defaultPool || $isDefault) {
$this->defaultPool = $pool;
$this->poolDetector->setDefault($pool);
}
} | php | public function addSendDriver(
$pool, SendDriverInterface $sendDriver, $isDefault = false
)
{
$this->sendDrivers[$pool] = $sendDriver;
if (!$this->defaultPool || $isDefault) {
$this->defaultPool = $pool;
$this->poolDetector->setDefault($pool);
}
} | [
"public",
"function",
"addSendDriver",
"(",
"$",
"pool",
",",
"SendDriverInterface",
"$",
"sendDriver",
",",
"$",
"isDefault",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"sendDrivers",
"[",
"$",
"pool",
"]",
"=",
"$",
"sendDriver",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"defaultPool",
"||",
"$",
"isDefault",
")",
"{",
"$",
"this",
"->",
"defaultPool",
"=",
"$",
"pool",
";",
"$",
"this",
"->",
"poolDetector",
"->",
"setDefault",
"(",
"$",
"pool",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/QueueManager/MultipleQueueManager.php#L74-L83 |
Gendoria/command-queue | src/Gendoria/CommandQueue/QueueManager/MultipleQueueManager.php | MultipleQueueManager.sendCommand | public function sendCommand(CommandInterface $command)
{
$poolName = $this->detectPool($command);
if (!$poolName || empty($this->sendDrivers[$poolName])) {
$this->logger->critical("Send driver not set for given command class, or no default send driver set.",
array($command, $this));
throw new RuntimeException("Send driver not set");
}
$this->logger->debug(sprintf("Sending command class %s to pool %s",
get_class($command), $poolName), array($command, $this));
$this->sendDrivers[$poolName]->send($command);
} | php | public function sendCommand(CommandInterface $command)
{
$poolName = $this->detectPool($command);
if (!$poolName || empty($this->sendDrivers[$poolName])) {
$this->logger->critical("Send driver not set for given command class, or no default send driver set.",
array($command, $this));
throw new RuntimeException("Send driver not set");
}
$this->logger->debug(sprintf("Sending command class %s to pool %s",
get_class($command), $poolName), array($command, $this));
$this->sendDrivers[$poolName]->send($command);
} | [
"public",
"function",
"sendCommand",
"(",
"CommandInterface",
"$",
"command",
")",
"{",
"$",
"poolName",
"=",
"$",
"this",
"->",
"detectPool",
"(",
"$",
"command",
")",
";",
"if",
"(",
"!",
"$",
"poolName",
"||",
"empty",
"(",
"$",
"this",
"->",
"sendDrivers",
"[",
"$",
"poolName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"critical",
"(",
"\"Send driver not set for given command class, or no default send driver set.\"",
",",
"array",
"(",
"$",
"command",
",",
"$",
"this",
")",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"\"Send driver not set\"",
")",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"\"Sending command class %s to pool %s\"",
",",
"get_class",
"(",
"$",
"command",
")",
",",
"$",
"poolName",
")",
",",
"array",
"(",
"$",
"command",
",",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"sendDrivers",
"[",
"$",
"poolName",
"]",
"->",
"send",
"(",
"$",
"command",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/QueueManager/MultipleQueueManager.php#L88-L99 |
Gendoria/command-queue | src/Gendoria/CommandQueue/QueueManager/MultipleQueueManager.php | MultipleQueueManager.detectPool | private function detectPool(CommandInterface $command)
{
$commandClass = get_class($command);
return $this->poolDetector->detect($commandClass);
} | php | private function detectPool(CommandInterface $command)
{
$commandClass = get_class($command);
return $this->poolDetector->detect($commandClass);
} | [
"private",
"function",
"detectPool",
"(",
"CommandInterface",
"$",
"command",
")",
"{",
"$",
"commandClass",
"=",
"get_class",
"(",
"$",
"command",
")",
";",
"return",
"$",
"this",
"->",
"poolDetector",
"->",
"detect",
"(",
"$",
"commandClass",
")",
";",
"}"
] | Detect correct pool for given command.
@param CommandInterface $command
@return string | [
"Detect",
"correct",
"pool",
"for",
"given",
"command",
"."
] | train | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/QueueManager/MultipleQueueManager.php#L117-L121 |
PieterScheffers/upperscore | src/Path.php | Path.combine | public function combine()
{
$paths = array_values( arrayFlatten(func_get_args()) );
$newPaths = array();
$nrOfPaths = count($paths);
for ($i=0; $i < $nrOfPaths; $i++) {
$path = $paths[$i];
$path = str_replace("\\", "/", $path);
if( $i > 0 ) {
$path = ltrim($path, "/");
}
if( $i < ($nrOfPaths - 1) ) {
$path = rtrim($path, "/");
}
$newPaths[] = $path;
}
return implode("/", $newPaths);
} | php | public function combine()
{
$paths = array_values( arrayFlatten(func_get_args()) );
$newPaths = array();
$nrOfPaths = count($paths);
for ($i=0; $i < $nrOfPaths; $i++) {
$path = $paths[$i];
$path = str_replace("\\", "/", $path);
if( $i > 0 ) {
$path = ltrim($path, "/");
}
if( $i < ($nrOfPaths - 1) ) {
$path = rtrim($path, "/");
}
$newPaths[] = $path;
}
return implode("/", $newPaths);
} | [
"public",
"function",
"combine",
"(",
")",
"{",
"$",
"paths",
"=",
"array_values",
"(",
"arrayFlatten",
"(",
"func_get_args",
"(",
")",
")",
")",
";",
"$",
"newPaths",
"=",
"array",
"(",
")",
";",
"$",
"nrOfPaths",
"=",
"count",
"(",
"$",
"paths",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"nrOfPaths",
";",
"$",
"i",
"++",
")",
"{",
"$",
"path",
"=",
"$",
"paths",
"[",
"$",
"i",
"]",
";",
"$",
"path",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"$",
"path",
")",
";",
"if",
"(",
"$",
"i",
">",
"0",
")",
"{",
"$",
"path",
"=",
"ltrim",
"(",
"$",
"path",
",",
"\"/\"",
")",
";",
"}",
"if",
"(",
"$",
"i",
"<",
"(",
"$",
"nrOfPaths",
"-",
"1",
")",
")",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"path",
",",
"\"/\"",
")",
";",
"}",
"$",
"newPaths",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"return",
"implode",
"(",
"\"/\"",
",",
"$",
"newPaths",
")",
";",
"}"
] | /*
Takes one or more paths as arguments and puts them together,
so there are no slash conflicts between path-parts
@param string/array Variable number of arguments. Arguments must be a path string or an array of path strings
@return string combined path | [
"/",
"*",
"Takes",
"one",
"or",
"more",
"paths",
"as",
"arguments",
"and",
"puts",
"them",
"together",
"so",
"there",
"are",
"no",
"slash",
"conflicts",
"between",
"path",
"-",
"parts"
] | train | https://github.com/PieterScheffers/upperscore/blob/c020ea7e0fe2fd4b8dcfbc3159611b87c8337b15/src/Path.php#L14-L36 |
PieterScheffers/upperscore | src/Path.php | Path.sanitize | public function sanitize($path, $replacement = "_")
{
if($path === '') return $path;
// make sure replacement isn't a bad character
$replacement = $this->sanitize($replacement);
// https://msdn.microsoft.com/en-us/library/aa365247
$forbidden = array(
"\0", // NULL
"<",
">",
":",
"\"",
"/",
"\\",
"|",
"?",
"*"
);
$path = str_replace($forbidden, $replacement, $path); // replace forbidden characters
$forbidden_filenames = array(
"CON",
"PRN",
"AUX",
"NUL",
"COM1",
"COM2",
"COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
"COM9",
"LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
"LPT6",
"LPT7",
"LPT8",
"LPT9"
);
if( in_array(strtoupper(basename($path)), $forbidden_filenames) ) {
$dirs = explode('/', $path);
$lastdir = array_pop($dirs);
$fileparts = explode('.', $lastdir);
$base = array_shift($fileparts);
$base = $base . randomString(20); // add random string to basename
array_unshift($fileparts, $base);
$lastdir = implode('.', $fileparts);
array_push($dirs, $lastdir);
$path = implode('/', $dirs);
}
$path = rtrim($path, '.'); // file not ending with a period
$path = trim($path); // file not ending with a space
return $path;
} | php | public function sanitize($path, $replacement = "_")
{
if($path === '') return $path;
// make sure replacement isn't a bad character
$replacement = $this->sanitize($replacement);
// https://msdn.microsoft.com/en-us/library/aa365247
$forbidden = array(
"\0", // NULL
"<",
">",
":",
"\"",
"/",
"\\",
"|",
"?",
"*"
);
$path = str_replace($forbidden, $replacement, $path); // replace forbidden characters
$forbidden_filenames = array(
"CON",
"PRN",
"AUX",
"NUL",
"COM1",
"COM2",
"COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
"COM9",
"LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
"LPT6",
"LPT7",
"LPT8",
"LPT9"
);
if( in_array(strtoupper(basename($path)), $forbidden_filenames) ) {
$dirs = explode('/', $path);
$lastdir = array_pop($dirs);
$fileparts = explode('.', $lastdir);
$base = array_shift($fileparts);
$base = $base . randomString(20); // add random string to basename
array_unshift($fileparts, $base);
$lastdir = implode('.', $fileparts);
array_push($dirs, $lastdir);
$path = implode('/', $dirs);
}
$path = rtrim($path, '.'); // file not ending with a period
$path = trim($path); // file not ending with a space
return $path;
} | [
"public",
"function",
"sanitize",
"(",
"$",
"path",
",",
"$",
"replacement",
"=",
"\"_\"",
")",
"{",
"if",
"(",
"$",
"path",
"===",
"''",
")",
"return",
"$",
"path",
";",
"// make sure replacement isn't a bad character",
"$",
"replacement",
"=",
"$",
"this",
"->",
"sanitize",
"(",
"$",
"replacement",
")",
";",
"// https://msdn.microsoft.com/en-us/library/aa365247",
"$",
"forbidden",
"=",
"array",
"(",
"\"\\0\"",
",",
"// NULL",
"\"<\"",
",",
"\">\"",
",",
"\":\"",
",",
"\"\\\"\"",
",",
"\"/\"",
",",
"\"\\\\\"",
",",
"\"|\"",
",",
"\"?\"",
",",
"\"*\"",
")",
";",
"$",
"path",
"=",
"str_replace",
"(",
"$",
"forbidden",
",",
"$",
"replacement",
",",
"$",
"path",
")",
";",
"// replace forbidden characters",
"$",
"forbidden_filenames",
"=",
"array",
"(",
"\"CON\"",
",",
"\"PRN\"",
",",
"\"AUX\"",
",",
"\"NUL\"",
",",
"\"COM1\"",
",",
"\"COM2\"",
",",
"\"COM3\"",
",",
"\"COM4\"",
",",
"\"COM5\"",
",",
"\"COM6\"",
",",
"\"COM7\"",
",",
"\"COM8\"",
",",
"\"COM9\"",
",",
"\"LPT1\"",
",",
"\"LPT2\"",
",",
"\"LPT3\"",
",",
"\"LPT4\"",
",",
"\"LPT5\"",
",",
"\"LPT6\"",
",",
"\"LPT7\"",
",",
"\"LPT8\"",
",",
"\"LPT9\"",
")",
";",
"if",
"(",
"in_array",
"(",
"strtoupper",
"(",
"basename",
"(",
"$",
"path",
")",
")",
",",
"$",
"forbidden_filenames",
")",
")",
"{",
"$",
"dirs",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"lastdir",
"=",
"array_pop",
"(",
"$",
"dirs",
")",
";",
"$",
"fileparts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"lastdir",
")",
";",
"$",
"base",
"=",
"array_shift",
"(",
"$",
"fileparts",
")",
";",
"$",
"base",
"=",
"$",
"base",
".",
"randomString",
"(",
"20",
")",
";",
"// add random string to basename",
"array_unshift",
"(",
"$",
"fileparts",
",",
"$",
"base",
")",
";",
"$",
"lastdir",
"=",
"implode",
"(",
"'.'",
",",
"$",
"fileparts",
")",
";",
"array_push",
"(",
"$",
"dirs",
",",
"$",
"lastdir",
")",
";",
"$",
"path",
"=",
"implode",
"(",
"'/'",
",",
"$",
"dirs",
")",
";",
"}",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"path",
",",
"'.'",
")",
";",
"// file not ending with a period",
"$",
"path",
"=",
"trim",
"(",
"$",
"path",
")",
";",
"// file not ending with a space",
"return",
"$",
"path",
";",
"}"
] | /*
Sanitizes a path, so it is a valid path in Windows & Linux
It replaces all bad characters with a character of choice
@param string $path string of a path
@param string $replacement character to use for replacement of bad characters
@return string sanitized path | [
"/",
"*",
"Sanitizes",
"a",
"path",
"so",
"it",
"is",
"a",
"valid",
"path",
"in",
"Windows",
"&",
"Linux",
"It",
"replaces",
"all",
"bad",
"characters",
"with",
"a",
"character",
"of",
"choice"
] | train | https://github.com/PieterScheffers/upperscore/blob/c020ea7e0fe2fd4b8dcfbc3159611b87c8337b15/src/Path.php#L46-L113 |
OxfordInfoLabs/kinikit-core | src/Util/ArrayUtils.php | ArrayUtils.prefixArrayKeys | public static function prefixArrayKeys($array, $prefix) {
$prefixedArray = array();
foreach ($array as $key => $value) {
$prefixedArray [$prefix . $key] = $value;
}
return $prefixedArray;
} | php | public static function prefixArrayKeys($array, $prefix) {
$prefixedArray = array();
foreach ($array as $key => $value) {
$prefixedArray [$prefix . $key] = $value;
}
return $prefixedArray;
} | [
"public",
"static",
"function",
"prefixArrayKeys",
"(",
"$",
"array",
",",
"$",
"prefix",
")",
"{",
"$",
"prefixedArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"prefixedArray",
"[",
"$",
"prefix",
".",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"prefixedArray",
";",
"}"
] | Take an associative array as input and return a new array with all the original keys prefixed by the
passed prefix.
@param array $array
@param string $prefix
@return array | [
"Take",
"an",
"associative",
"array",
"as",
"input",
"and",
"return",
"a",
"new",
"array",
"with",
"all",
"the",
"original",
"keys",
"prefixed",
"by",
"the",
"passed",
"prefix",
"."
] | train | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L35-L44 |
OxfordInfoLabs/kinikit-core | src/Util/ArrayUtils.php | ArrayUtils.getAllArrayItemsByKeyPrefix | public static function getAllArrayItemsByKeyPrefix($array, $prefix, $stripPrefix = false) {
$returnValues = array();
foreach ($array as $key => $value) {
$positionOfPrefix = strpos($key, $prefix);
if (is_numeric($positionOfPrefix) && $positionOfPrefix == 0) {
if ($stripPrefix) $key = substr($key, strlen($prefix));
$returnValues [$key] = $value;
}
}
return $returnValues;
} | php | public static function getAllArrayItemsByKeyPrefix($array, $prefix, $stripPrefix = false) {
$returnValues = array();
foreach ($array as $key => $value) {
$positionOfPrefix = strpos($key, $prefix);
if (is_numeric($positionOfPrefix) && $positionOfPrefix == 0) {
if ($stripPrefix) $key = substr($key, strlen($prefix));
$returnValues [$key] = $value;
}
}
return $returnValues;
} | [
"public",
"static",
"function",
"getAllArrayItemsByKeyPrefix",
"(",
"$",
"array",
",",
"$",
"prefix",
",",
"$",
"stripPrefix",
"=",
"false",
")",
"{",
"$",
"returnValues",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"positionOfPrefix",
"=",
"strpos",
"(",
"$",
"key",
",",
"$",
"prefix",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"positionOfPrefix",
")",
"&&",
"$",
"positionOfPrefix",
"==",
"0",
")",
"{",
"if",
"(",
"$",
"stripPrefix",
")",
"$",
"key",
"=",
"substr",
"(",
"$",
"key",
",",
"strlen",
"(",
"$",
"prefix",
")",
")",
";",
"$",
"returnValues",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"returnValues",
";",
"}"
] | Find all parameters in the passed array with a key starting with the supplied prefix.
Return them as an associative array by key.
@param array $array
@param string $prefix
@return array | [
"Find",
"all",
"parameters",
"in",
"the",
"passed",
"array",
"with",
"a",
"key",
"starting",
"with",
"the",
"supplied",
"prefix",
".",
"Return",
"them",
"as",
"an",
"associative",
"array",
"by",
"key",
"."
] | train | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L55-L66 |
OxfordInfoLabs/kinikit-core | src/Util/ArrayUtils.php | ArrayUtils.arrayDiff | public static function arrayDiff($array1, $array2) {
return array_udiff($array1, $array2,
function ($a, $b) {
if (is_object($a)) {
return strcmp(spl_object_hash($a), spl_object_hash($b));
} else if (is_array($a)) {
return ArrayUtils::arrayDiff($a, $b);
} else {
return strcmp($a, $b);
}
}
);
} | php | public static function arrayDiff($array1, $array2) {
return array_udiff($array1, $array2,
function ($a, $b) {
if (is_object($a)) {
return strcmp(spl_object_hash($a), spl_object_hash($b));
} else if (is_array($a)) {
return ArrayUtils::arrayDiff($a, $b);
} else {
return strcmp($a, $b);
}
}
);
} | [
"public",
"static",
"function",
"arrayDiff",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"return",
"array_udiff",
"(",
"$",
"array1",
",",
"$",
"array2",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"a",
")",
")",
"{",
"return",
"strcmp",
"(",
"spl_object_hash",
"(",
"$",
"a",
")",
",",
"spl_object_hash",
"(",
"$",
"b",
")",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"a",
")",
")",
"{",
"return",
"ArrayUtils",
"::",
"arrayDiff",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"}",
"else",
"{",
"return",
"strcmp",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"}",
"}",
")",
";",
"}"
] | Diff function for arrays which works with arrays of objects as well as string comparables.
@param $array1
@param $array2 | [
"Diff",
"function",
"for",
"arrays",
"which",
"works",
"with",
"arrays",
"of",
"objects",
"as",
"well",
"as",
"string",
"comparables",
"."
] | train | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L87-L99 |
OxfordInfoLabs/kinikit-core | src/Util/ArrayUtils.php | ArrayUtils.recursiveMerge | public static function recursiveMerge($array1, $array2) {
if ($array1 instanceof AssociativeArray) {
$array1 = $array1->toArray();
}
if ($array2 instanceof AssociativeArray) {
$array2 = $array2->toArray();
}
if (ArrayUtils::isAssociative($array1) != ArrayUtils::isAssociative($array2)) {
if (ArrayUtils::isAssociative($array1)) {
$array1 = array($array1);
} else {
$array2 = array($array2);
}
}
$combinedKeys = array_unique(array_merge(array_keys($array1), array_keys($array2)));
$mergedArray = array();
foreach ($combinedKeys as $key) {
if (isset($array1[$key]) && isset($array2[$key])) {
if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
$mergedArray[$key] = ArrayUtils::recursiveMerge($array1[$key], $array2[$key]);
} else {
$mergedArray[$key] = $array1[$key];
}
} else {
$mergedArray[$key] = isset($array1[$key]) ? $array1[$key] : $array2[$key];
}
}
return $mergedArray;
} | php | public static function recursiveMerge($array1, $array2) {
if ($array1 instanceof AssociativeArray) {
$array1 = $array1->toArray();
}
if ($array2 instanceof AssociativeArray) {
$array2 = $array2->toArray();
}
if (ArrayUtils::isAssociative($array1) != ArrayUtils::isAssociative($array2)) {
if (ArrayUtils::isAssociative($array1)) {
$array1 = array($array1);
} else {
$array2 = array($array2);
}
}
$combinedKeys = array_unique(array_merge(array_keys($array1), array_keys($array2)));
$mergedArray = array();
foreach ($combinedKeys as $key) {
if (isset($array1[$key]) && isset($array2[$key])) {
if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
$mergedArray[$key] = ArrayUtils::recursiveMerge($array1[$key], $array2[$key]);
} else {
$mergedArray[$key] = $array1[$key];
}
} else {
$mergedArray[$key] = isset($array1[$key]) ? $array1[$key] : $array2[$key];
}
}
return $mergedArray;
} | [
"public",
"static",
"function",
"recursiveMerge",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"if",
"(",
"$",
"array1",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array1",
"=",
"$",
"array1",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"$",
"array2",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array2",
"=",
"$",
"array2",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"ArrayUtils",
"::",
"isAssociative",
"(",
"$",
"array1",
")",
"!=",
"ArrayUtils",
"::",
"isAssociative",
"(",
"$",
"array2",
")",
")",
"{",
"if",
"(",
"ArrayUtils",
"::",
"isAssociative",
"(",
"$",
"array1",
")",
")",
"{",
"$",
"array1",
"=",
"array",
"(",
"$",
"array1",
")",
";",
"}",
"else",
"{",
"$",
"array2",
"=",
"array",
"(",
"$",
"array2",
")",
";",
"}",
"}",
"$",
"combinedKeys",
"=",
"array_unique",
"(",
"array_merge",
"(",
"array_keys",
"(",
"$",
"array1",
")",
",",
"array_keys",
"(",
"$",
"array2",
")",
")",
")",
";",
"$",
"mergedArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"combinedKeys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
"&&",
"isset",
"(",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"(",
"is_array",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"array1",
"[",
"$",
"key",
"]",
"instanceof",
"AssociativeArray",
")",
"&&",
"(",
"is_array",
"(",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"array2",
"[",
"$",
"key",
"]",
"instanceof",
"AssociativeArray",
")",
")",
"{",
"$",
"mergedArray",
"[",
"$",
"key",
"]",
"=",
"ArrayUtils",
"::",
"recursiveMerge",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
",",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"$",
"mergedArray",
"[",
"$",
"key",
"]",
"=",
"$",
"array1",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"mergedArray",
"[",
"$",
"key",
"]",
"=",
"isset",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"array1",
"[",
"$",
"key",
"]",
":",
"$",
"array2",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"$",
"mergedArray",
";",
"}"
] | Recursively merge array1 and array2. If keys exist in both arrays at any level, take the value from array1 in preference.
@param $array1
@param $array2 | [
"Recursively",
"merge",
"array1",
"and",
"array2",
".",
"If",
"keys",
"exist",
"in",
"both",
"arrays",
"at",
"any",
"level",
"take",
"the",
"value",
"from",
"array1",
"in",
"preference",
"."
] | train | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L107-L148 |
OxfordInfoLabs/kinikit-core | src/Util/ArrayUtils.php | ArrayUtils.recursiveDiff | public static function recursiveDiff($array1, $array2, $caseInsensitive = true, $matchingKeysOnly = true) {
if ($array1 instanceof AssociativeArray) {
$array1 = $array1->toArray();
}
if ($array2 instanceof AssociativeArray) {
$array2 = $array2->toArray();
}
$sharedKeys = array_intersect(array_keys($array1), array_keys($array2));
$diffArray = array();
// Only care about shared keys
foreach ($sharedKeys as $key) {
if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
$diffArray[$key] = ArrayUtils::recursiveDiff($array1[$key], $array2[$key], $caseInsensitive, $matchingKeysOnly);
} else {
$value1 = $caseInsensitive ? strtolower($array1[$key]) : $array1[$key];
$value2 = $caseInsensitive ? strtolower($array2[$key]) : $array2[$key];
if ($value1 != $value2) {
$diffArray[$key] = array("value1" => $array1[$key], "value2" => $array2[$key]);
}
}
}
return $diffArray;
} | php | public static function recursiveDiff($array1, $array2, $caseInsensitive = true, $matchingKeysOnly = true) {
if ($array1 instanceof AssociativeArray) {
$array1 = $array1->toArray();
}
if ($array2 instanceof AssociativeArray) {
$array2 = $array2->toArray();
}
$sharedKeys = array_intersect(array_keys($array1), array_keys($array2));
$diffArray = array();
// Only care about shared keys
foreach ($sharedKeys as $key) {
if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
$diffArray[$key] = ArrayUtils::recursiveDiff($array1[$key], $array2[$key], $caseInsensitive, $matchingKeysOnly);
} else {
$value1 = $caseInsensitive ? strtolower($array1[$key]) : $array1[$key];
$value2 = $caseInsensitive ? strtolower($array2[$key]) : $array2[$key];
if ($value1 != $value2) {
$diffArray[$key] = array("value1" => $array1[$key], "value2" => $array2[$key]);
}
}
}
return $diffArray;
} | [
"public",
"static",
"function",
"recursiveDiff",
"(",
"$",
"array1",
",",
"$",
"array2",
",",
"$",
"caseInsensitive",
"=",
"true",
",",
"$",
"matchingKeysOnly",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"array1",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array1",
"=",
"$",
"array1",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"$",
"array2",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array2",
"=",
"$",
"array2",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"sharedKeys",
"=",
"array_intersect",
"(",
"array_keys",
"(",
"$",
"array1",
")",
",",
"array_keys",
"(",
"$",
"array2",
")",
")",
";",
"$",
"diffArray",
"=",
"array",
"(",
")",
";",
"// Only care about shared keys",
"foreach",
"(",
"$",
"sharedKeys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"(",
"is_array",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"array1",
"[",
"$",
"key",
"]",
"instanceof",
"AssociativeArray",
")",
"&&",
"(",
"is_array",
"(",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"array2",
"[",
"$",
"key",
"]",
"instanceof",
"AssociativeArray",
")",
")",
"{",
"$",
"diffArray",
"[",
"$",
"key",
"]",
"=",
"ArrayUtils",
"::",
"recursiveDiff",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
",",
"$",
"array2",
"[",
"$",
"key",
"]",
",",
"$",
"caseInsensitive",
",",
"$",
"matchingKeysOnly",
")",
";",
"}",
"else",
"{",
"$",
"value1",
"=",
"$",
"caseInsensitive",
"?",
"strtolower",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
":",
"$",
"array1",
"[",
"$",
"key",
"]",
";",
"$",
"value2",
"=",
"$",
"caseInsensitive",
"?",
"strtolower",
"(",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
":",
"$",
"array2",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"value1",
"!=",
"$",
"value2",
")",
"{",
"$",
"diffArray",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"\"value1\"",
"=>",
"$",
"array1",
"[",
"$",
"key",
"]",
",",
"\"value2\"",
"=>",
"$",
"array2",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"diffArray",
";",
"}"
] | Return an array of different elements within the 2 arrays. If matching keys only is supplied, only elements which exist in both but which are different are included.
The returned array contains an associative array for each differing value with a "value1" and "value2" element.
@param $array1
@param $array2
@param bool $matchingKeysOnly | [
"Return",
"an",
"array",
"of",
"different",
"elements",
"within",
"the",
"2",
"arrays",
".",
"If",
"matching",
"keys",
"only",
"is",
"supplied",
"only",
"elements",
"which",
"exist",
"in",
"both",
"but",
"which",
"are",
"different",
"are",
"included",
"."
] | train | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L161-L194 |
OxfordInfoLabs/kinikit-core | src/Util/ArrayUtils.php | ArrayUtils.reduceToElementsWithKey | public static function reduceToElementsWithKey($array, $key) {
if ($array instanceof AssociativeArray) {
$array = $array->toArray();
}
$targetArray = array();
foreach ($array as $itemKey => $value) {
if ($itemKey == $key) {
$targetArray[$key] = $value;
} else if (is_array($value) || $value instanceof AssociativeArray) {
$subArray = ArrayUtils::reduceToElementsWithKey($value, $key);
if (sizeof($subArray) > 0) {
$targetArray[$itemKey] = $subArray;
}
}
}
return $targetArray;
} | php | public static function reduceToElementsWithKey($array, $key) {
if ($array instanceof AssociativeArray) {
$array = $array->toArray();
}
$targetArray = array();
foreach ($array as $itemKey => $value) {
if ($itemKey == $key) {
$targetArray[$key] = $value;
} else if (is_array($value) || $value instanceof AssociativeArray) {
$subArray = ArrayUtils::reduceToElementsWithKey($value, $key);
if (sizeof($subArray) > 0) {
$targetArray[$itemKey] = $subArray;
}
}
}
return $targetArray;
} | [
"public",
"static",
"function",
"reduceToElementsWithKey",
"(",
"$",
"array",
",",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"array",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array",
"=",
"$",
"array",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"targetArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"itemKey",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"itemKey",
"==",
"$",
"key",
")",
"{",
"$",
"targetArray",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"subArray",
"=",
"ArrayUtils",
"::",
"reduceToElementsWithKey",
"(",
"$",
"value",
",",
"$",
"key",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"subArray",
")",
">",
"0",
")",
"{",
"$",
"targetArray",
"[",
"$",
"itemKey",
"]",
"=",
"$",
"subArray",
";",
"}",
"}",
"}",
"return",
"$",
"targetArray",
";",
"}"
] | Reduce the array to only elements with the passed key at any depth.
@param $array
@param $key | [
"Reduce",
"the",
"array",
"to",
"only",
"elements",
"with",
"the",
"passed",
"key",
"at",
"any",
"depth",
"."
] | train | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L203-L226 |
OxfordInfoLabs/kinikit-core | src/Util/ArrayUtils.php | ArrayUtils.findElementsByKey | public static function findElementsByKey($array, $key, &$targetArray = null, $prefix = "") {
if ($array instanceof AssociativeArray) {
$array = $array->toArray();
}
if (!$targetArray)
$targetArray = array();
foreach ($array as $itemKey => $value) {
if ($itemKey === $key) {
$targetArray[substr($prefix . "." . $key, 1)] = $value;
} else if (is_array($value) || $value instanceof AssociativeArray) {
if (is_numeric($itemKey)) {
$newPrefix = $prefix . "[" . $itemKey . "]";
} else {
$newPrefix = $prefix . "." . $itemKey;
}
ArrayUtils::findElementsByKey($value, $key, $targetArray, $newPrefix);
}
}
return $targetArray;
} | php | public static function findElementsByKey($array, $key, &$targetArray = null, $prefix = "") {
if ($array instanceof AssociativeArray) {
$array = $array->toArray();
}
if (!$targetArray)
$targetArray = array();
foreach ($array as $itemKey => $value) {
if ($itemKey === $key) {
$targetArray[substr($prefix . "." . $key, 1)] = $value;
} else if (is_array($value) || $value instanceof AssociativeArray) {
if (is_numeric($itemKey)) {
$newPrefix = $prefix . "[" . $itemKey . "]";
} else {
$newPrefix = $prefix . "." . $itemKey;
}
ArrayUtils::findElementsByKey($value, $key, $targetArray, $newPrefix);
}
}
return $targetArray;
} | [
"public",
"static",
"function",
"findElementsByKey",
"(",
"$",
"array",
",",
"$",
"key",
",",
"&",
"$",
"targetArray",
"=",
"null",
",",
"$",
"prefix",
"=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"array",
"instanceof",
"AssociativeArray",
")",
"{",
"$",
"array",
"=",
"$",
"array",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"targetArray",
")",
"$",
"targetArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"itemKey",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"itemKey",
"===",
"$",
"key",
")",
"{",
"$",
"targetArray",
"[",
"substr",
"(",
"$",
"prefix",
".",
"\".\"",
".",
"$",
"key",
",",
"1",
")",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"instanceof",
"AssociativeArray",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"itemKey",
")",
")",
"{",
"$",
"newPrefix",
"=",
"$",
"prefix",
".",
"\"[\"",
".",
"$",
"itemKey",
".",
"\"]\"",
";",
"}",
"else",
"{",
"$",
"newPrefix",
"=",
"$",
"prefix",
".",
"\".\"",
".",
"$",
"itemKey",
";",
"}",
"ArrayUtils",
"::",
"findElementsByKey",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"targetArray",
",",
"$",
"newPrefix",
")",
";",
"}",
"}",
"return",
"$",
"targetArray",
";",
"}"
] | Find elements by key.
@param $array
@param $key | [
"Find",
"elements",
"by",
"key",
"."
] | train | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L235-L262 |
OxfordInfoLabs/kinikit-core | src/Util/ArrayUtils.php | ArrayUtils.groupElementsByValueKeys | public static function groupElementsByValueKeys($array, $groupKeys) {
if (!is_array($groupKeys)) {
$groupKeys = array($groupKeys);
}
$newArray = new AssociativeArray();
foreach ($array as $element) {
$applyObject = $newArray;
foreach ($groupKeys as $index => $groupKey) {
if ($index < sizeof($groupKeys) - 1) {
$subArray = $applyObject[$element[$groupKeys[$index]]];
if (!$subArray) {
$subArray = new AssociativeArray();
$applyObject[$element[$groupKeys[$index]]] = $subArray;
}
$applyObject = $subArray;
} else {
if (!is_array($applyObject[$element[$groupKeys[$index]]])) {
$applyObject[$element[$groupKeys[$index]]] = array();
}
$applyObject[$element[$groupKeys[$index]]][] = $element;
}
}
}
return $newArray->toArray();
} | php | public static function groupElementsByValueKeys($array, $groupKeys) {
if (!is_array($groupKeys)) {
$groupKeys = array($groupKeys);
}
$newArray = new AssociativeArray();
foreach ($array as $element) {
$applyObject = $newArray;
foreach ($groupKeys as $index => $groupKey) {
if ($index < sizeof($groupKeys) - 1) {
$subArray = $applyObject[$element[$groupKeys[$index]]];
if (!$subArray) {
$subArray = new AssociativeArray();
$applyObject[$element[$groupKeys[$index]]] = $subArray;
}
$applyObject = $subArray;
} else {
if (!is_array($applyObject[$element[$groupKeys[$index]]])) {
$applyObject[$element[$groupKeys[$index]]] = array();
}
$applyObject[$element[$groupKeys[$index]]][] = $element;
}
}
}
return $newArray->toArray();
} | [
"public",
"static",
"function",
"groupElementsByValueKeys",
"(",
"$",
"array",
",",
"$",
"groupKeys",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"groupKeys",
")",
")",
"{",
"$",
"groupKeys",
"=",
"array",
"(",
"$",
"groupKeys",
")",
";",
"}",
"$",
"newArray",
"=",
"new",
"AssociativeArray",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"element",
")",
"{",
"$",
"applyObject",
"=",
"$",
"newArray",
";",
"foreach",
"(",
"$",
"groupKeys",
"as",
"$",
"index",
"=>",
"$",
"groupKey",
")",
"{",
"if",
"(",
"$",
"index",
"<",
"sizeof",
"(",
"$",
"groupKeys",
")",
"-",
"1",
")",
"{",
"$",
"subArray",
"=",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
";",
"if",
"(",
"!",
"$",
"subArray",
")",
"{",
"$",
"subArray",
"=",
"new",
"AssociativeArray",
"(",
")",
";",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
"=",
"$",
"subArray",
";",
"}",
"$",
"applyObject",
"=",
"$",
"subArray",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
")",
")",
"{",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"applyObject",
"[",
"$",
"element",
"[",
"$",
"groupKeys",
"[",
"$",
"index",
"]",
"]",
"]",
"[",
"]",
"=",
"$",
"element",
";",
"}",
"}",
"}",
"return",
"$",
"newArray",
"->",
"toArray",
"(",
")",
";",
"}"
] | Group an array of elements by one or more of it's keys. Essentially convert into an indexed array for each key type.
@param $array
@param $groupKeys | [
"Group",
"an",
"array",
"of",
"elements",
"by",
"one",
"or",
"more",
"of",
"it",
"s",
"keys",
".",
"Essentially",
"convert",
"into",
"an",
"indexed",
"array",
"for",
"each",
"key",
"type",
"."
] | train | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ArrayUtils.php#L271-L302 |
phossa/phossa-config | src/Phossa/Config/Reference/TreeTrait.php | TreeTrait.& | protected function &searchTree(
/*# string */ $key,
/*# array */ &$tree,
/*# bool */ $create = false
) {
$found = &$tree;
$parts = explode($this->field_splitter, $key);
while (null !== ($part = array_shift($parts))) {
if (!isset($found[$part])) {
if ($create) {
$found[$part] = [];
} else {
$bad = null;
return $bad;
}
}
$found = &$found[$part];
}
return $found;
} | php | protected function &searchTree(
/*# string */ $key,
/*# array */ &$tree,
/*# bool */ $create = false
) {
$found = &$tree;
$parts = explode($this->field_splitter, $key);
while (null !== ($part = array_shift($parts))) {
if (!isset($found[$part])) {
if ($create) {
$found[$part] = [];
} else {
$bad = null;
return $bad;
}
}
$found = &$found[$part];
}
return $found;
} | [
"protected",
"function",
"&",
"searchTree",
"(",
"/*# string */",
"$",
"key",
",",
"/*# array */",
"&",
"$",
"tree",
",",
"/*# bool */",
"$",
"create",
"=",
"false",
")",
"{",
"$",
"found",
"=",
"&",
"$",
"tree",
";",
"$",
"parts",
"=",
"explode",
"(",
"$",
"this",
"->",
"field_splitter",
",",
"$",
"key",
")",
";",
"while",
"(",
"null",
"!==",
"(",
"$",
"part",
"=",
"array_shift",
"(",
"$",
"parts",
")",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"found",
"[",
"$",
"part",
"]",
")",
")",
"{",
"if",
"(",
"$",
"create",
")",
"{",
"$",
"found",
"[",
"$",
"part",
"]",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"bad",
"=",
"null",
";",
"return",
"$",
"bad",
";",
"}",
"}",
"$",
"found",
"=",
"&",
"$",
"found",
"[",
"$",
"part",
"]",
";",
"}",
"return",
"$",
"found",
";",
"}"
] | Return a node in an array structure
@param string $key something like 'db.auth.host'
@param array &$tree the array tree
@param bool $create create the node if missing
@return null|array|string the matching node
@access protected | [
"Return",
"a",
"node",
"in",
"an",
"array",
"structure"
] | train | https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Reference/TreeTrait.php#L57-L76 |
phossa/phossa-config | src/Phossa/Config/Reference/TreeTrait.php | TreeTrait.fixValue | protected function fixValue(array $value)/*# : array */
{
$result = [];
foreach ($value as $k => $v) {
if (false !== strpos($k, $this->field_splitter)) {
$res = &$this->searchTree($k, $result, true);
$res = is_array($v) ? $this->fixValue($v) : $v;
} else {
$result[$k] = is_array($v) ? $this->fixValue($v) : $v;
}
}
return $result;
} | php | protected function fixValue(array $value)/*# : array */
{
$result = [];
foreach ($value as $k => $v) {
if (false !== strpos($k, $this->field_splitter)) {
$res = &$this->searchTree($k, $result, true);
$res = is_array($v) ? $this->fixValue($v) : $v;
} else {
$result[$k] = is_array($v) ? $this->fixValue($v) : $v;
}
}
return $result;
} | [
"protected",
"function",
"fixValue",
"(",
"array",
"$",
"value",
")",
"/*# : array */",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"k",
",",
"$",
"this",
"->",
"field_splitter",
")",
")",
"{",
"$",
"res",
"=",
"&",
"$",
"this",
"->",
"searchTree",
"(",
"$",
"k",
",",
"$",
"result",
",",
"true",
")",
";",
"$",
"res",
"=",
"is_array",
"(",
"$",
"v",
")",
"?",
"$",
"this",
"->",
"fixValue",
"(",
"$",
"v",
")",
":",
"$",
"v",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"k",
"]",
"=",
"is_array",
"(",
"$",
"v",
")",
"?",
"$",
"this",
"->",
"fixValue",
"(",
"$",
"v",
")",
":",
"$",
"v",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | convert [ 'database.dsn' => 'xxx' ] to ['database' => [ 'dsn' => 'xxx' ]]
@param array $value
@return array
@access protected | [
"convert",
"[",
"database",
".",
"dsn",
"=",
">",
"xxx",
"]",
"to",
"[",
"database",
"=",
">",
"[",
"dsn",
"=",
">",
"xxx",
"]]"
] | train | https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Reference/TreeTrait.php#L85-L97 |
honey-comb/resources | src/Console/HCGenerateDefaultPreviewThumbnails.php | HCGenerateDefaultPreviewThumbnails.handle | public function handle(): void
{
$start = $this->argument('start');
$end = $this->argument('end');
$disk = $this->argument('disk');
$resources = $this->resourceService->getRepository()->makeQuery()
->select('id', 'path', 'mime_type')
->setEagerLoads([])
->skip($start)
->take($end)
->get();
foreach ($resources as $resource) {
$this->resourceService->createPreviewThumb(
$resource->id,
$resource->path,
$resource->mime_type,
$disk,
[],
true
);
}
} | php | public function handle(): void
{
$start = $this->argument('start');
$end = $this->argument('end');
$disk = $this->argument('disk');
$resources = $this->resourceService->getRepository()->makeQuery()
->select('id', 'path', 'mime_type')
->setEagerLoads([])
->skip($start)
->take($end)
->get();
foreach ($resources as $resource) {
$this->resourceService->createPreviewThumb(
$resource->id,
$resource->path,
$resource->mime_type,
$disk,
[],
true
);
}
} | [
"public",
"function",
"handle",
"(",
")",
":",
"void",
"{",
"$",
"start",
"=",
"$",
"this",
"->",
"argument",
"(",
"'start'",
")",
";",
"$",
"end",
"=",
"$",
"this",
"->",
"argument",
"(",
"'end'",
")",
";",
"$",
"disk",
"=",
"$",
"this",
"->",
"argument",
"(",
"'disk'",
")",
";",
"$",
"resources",
"=",
"$",
"this",
"->",
"resourceService",
"->",
"getRepository",
"(",
")",
"->",
"makeQuery",
"(",
")",
"->",
"select",
"(",
"'id'",
",",
"'path'",
",",
"'mime_type'",
")",
"->",
"setEagerLoads",
"(",
"[",
"]",
")",
"->",
"skip",
"(",
"$",
"start",
")",
"->",
"take",
"(",
"$",
"end",
")",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"resources",
"as",
"$",
"resource",
")",
"{",
"$",
"this",
"->",
"resourceService",
"->",
"createPreviewThumb",
"(",
"$",
"resource",
"->",
"id",
",",
"$",
"resource",
"->",
"path",
",",
"$",
"resource",
"->",
"mime_type",
",",
"$",
"disk",
",",
"[",
"]",
",",
"true",
")",
";",
"}",
"}"
] | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/honey-comb/resources/blob/9b82eb2fd99be99edfdc4e76803d95caf981e14b/src/Console/HCGenerateDefaultPreviewThumbnails.php#L73-L96 |
matteosister/CypressConsoleDefaultsBundle | Console/CommandDefault.php | CommandDefault.match | public function match(Command $command)
{
if ($this->isEmpty()) {
return false;
}
if ($this->isRegExp()) {
return 1 === preg_match($this->getName(), $command->getName());
}
return $command->getName() === $this->getName();
} | php | public function match(Command $command)
{
if ($this->isEmpty()) {
return false;
}
if ($this->isRegExp()) {
return 1 === preg_match($this->getName(), $command->getName());
}
return $command->getName() === $this->getName();
} | [
"public",
"function",
"match",
"(",
"Command",
"$",
"command",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isRegExp",
"(",
")",
")",
"{",
"return",
"1",
"===",
"preg_match",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"command",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"$",
"command",
"->",
"getName",
"(",
")",
"===",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"}"
] | @param \Symfony\Component\Console\Command\Command $command
@return bool | [
"@param",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Console",
"\\",
"Command",
"\\",
"Command",
"$command"
] | train | https://github.com/matteosister/CypressConsoleDefaultsBundle/blob/8f90f36327482f3ed9fba68ecf006e5249c3db6a/Console/CommandDefault.php#L50-L59 |
Dhii/factory-base | src/AbstractBaseCallbackFactory.php | AbstractBaseCallbackFactory.make | public function make($config = null)
{
try {
return $this->_invokeCallable($this->_getFactoryCallback($config), [$config]);
} catch (InvocationExceptionInterface $invocationException) {
throw $this->_createCouldNotMakeException(
$this->__('Could not make subject instance'),
null,
$invocationException,
$this,
$config
);
} catch (RootException $exception) {
throw $this->_createFactoryException(
$this->__('An error occurred while trying to make the subject instance'),
null,
$exception,
$this
);
}
} | php | public function make($config = null)
{
try {
return $this->_invokeCallable($this->_getFactoryCallback($config), [$config]);
} catch (InvocationExceptionInterface $invocationException) {
throw $this->_createCouldNotMakeException(
$this->__('Could not make subject instance'),
null,
$invocationException,
$this,
$config
);
} catch (RootException $exception) {
throw $this->_createFactoryException(
$this->__('An error occurred while trying to make the subject instance'),
null,
$exception,
$this
);
}
} | [
"public",
"function",
"make",
"(",
"$",
"config",
"=",
"null",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"_invokeCallable",
"(",
"$",
"this",
"->",
"_getFactoryCallback",
"(",
"$",
"config",
")",
",",
"[",
"$",
"config",
"]",
")",
";",
"}",
"catch",
"(",
"InvocationExceptionInterface",
"$",
"invocationException",
")",
"{",
"throw",
"$",
"this",
"->",
"_createCouldNotMakeException",
"(",
"$",
"this",
"->",
"__",
"(",
"'Could not make subject instance'",
")",
",",
"null",
",",
"$",
"invocationException",
",",
"$",
"this",
",",
"$",
"config",
")",
";",
"}",
"catch",
"(",
"RootException",
"$",
"exception",
")",
"{",
"throw",
"$",
"this",
"->",
"_createFactoryException",
"(",
"$",
"this",
"->",
"__",
"(",
"'An error occurred while trying to make the subject instance'",
")",
",",
"null",
",",
"$",
"exception",
",",
"$",
"this",
")",
";",
"}",
"}"
] | {@inheritdoc}
@since [*next-version*] | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/Dhii/factory-base/blob/eb6694178068ec58e0f2de9243f0eb98844511de/src/AbstractBaseCallbackFactory.php#L193-L213 |
Fenzland/php-http-client | libs/Request.php | Request.url | public function url( string$url ):self
{
$url= parse_url($url);
if( !is_array($url) )
throw new \Exception("Url '$url' is invalid.");
foreach( $url as $key=>$value )
{
$this->$key= $value;
}
return $this;
} | php | public function url( string$url ):self
{
$url= parse_url($url);
if( !is_array($url) )
throw new \Exception("Url '$url' is invalid.");
foreach( $url as $key=>$value )
{
$this->$key= $value;
}
return $this;
} | [
"public",
"function",
"url",
"(",
"string",
"$",
"url",
")",
":",
"self",
"{",
"$",
"url",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"url",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Url '$url' is invalid.\"",
")",
";",
"foreach",
"(",
"$",
"url",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Method url
@access public
@param string $url
@return self | [
"Method",
"url"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Request.php#L173-L186 |
Fenzland/php-http-client | libs/Request.php | Request.header | public function header( string$key, string$value ):self
{
$this->headers[ucwords( strtolower($key), '-' )]= $value;
return $this;
} | php | public function header( string$key, string$value ):self
{
$this->headers[ucwords( strtolower($key), '-' )]= $value;
return $this;
} | [
"public",
"function",
"header",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"headers",
"[",
"ucwords",
"(",
"strtolower",
"(",
"$",
"key",
")",
",",
"'-'",
")",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Method header
@access public
@param string $key
@param string $value
@return self | [
"Method",
"header"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Request.php#L233-L238 |
Fenzland/php-http-client | libs/Request.php | Request.send | public function send( string$body=null ):Response
{
$this->justSend($body);
return new Response( $this, $this->handle );
} | php | public function send( string$body=null ):Response
{
$this->justSend($body);
return new Response( $this, $this->handle );
} | [
"public",
"function",
"send",
"(",
"string",
"$",
"body",
"=",
"null",
")",
":",
"Response",
"{",
"$",
"this",
"->",
"justSend",
"(",
"$",
"body",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"handle",
")",
";",
"}"
] | Method send
@access public
@param string $body
@return Response | [
"Method",
"send"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Request.php#L249-L254 |
Fenzland/php-http-client | libs/Request.php | Request.sendFormData | public function sendFormData( FormData$body ):Response
{
if(!( in_array( $this->method, [ 'POST', 'PUT', 'PATCH', ] ) )){
throw new \Exception('FormData must be send with method POST, PUT or PATCH');
}
$body->setRequest( $this );
return $this->send("$body");
} | php | public function sendFormData( FormData$body ):Response
{
if(!( in_array( $this->method, [ 'POST', 'PUT', 'PATCH', ] ) )){
throw new \Exception('FormData must be send with method POST, PUT or PATCH');
}
$body->setRequest( $this );
return $this->send("$body");
} | [
"public",
"function",
"sendFormData",
"(",
"FormData",
"$",
"body",
")",
":",
"Response",
"{",
"if",
"(",
"!",
"(",
"in_array",
"(",
"$",
"this",
"->",
"method",
",",
"[",
"'POST'",
",",
"'PUT'",
",",
"'PATCH'",
",",
"]",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'FormData must be send with method POST, PUT or PATCH'",
")",
";",
"}",
"$",
"body",
"->",
"setRequest",
"(",
"$",
"this",
")",
";",
"return",
"$",
"this",
"->",
"send",
"(",
"\"$body\"",
")",
";",
"}"
] | Method sendFile
@access public
@param FormData $body
@return Response | [
"Method",
"sendFile"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Request.php#L265-L274 |
Fenzland/php-http-client | libs/Request.php | Request.justSend | protected function justSend( string$body=null )
{
$this->body= $body;
if( $length= strlen($body) )
{
$this->header( 'Content-Length', $length );
}
$this->header( 'Connection', 'close' );
$this->sendHeader();
$this->sendBody($body);
} | php | protected function justSend( string$body=null )
{
$this->body= $body;
if( $length= strlen($body) )
{
$this->header( 'Content-Length', $length );
}
$this->header( 'Connection', 'close' );
$this->sendHeader();
$this->sendBody($body);
} | [
"protected",
"function",
"justSend",
"(",
"string",
"$",
"body",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"body",
"=",
"$",
"body",
";",
"if",
"(",
"$",
"length",
"=",
"strlen",
"(",
"$",
"body",
")",
")",
"{",
"$",
"this",
"->",
"header",
"(",
"'Content-Length'",
",",
"$",
"length",
")",
";",
"}",
"$",
"this",
"->",
"header",
"(",
"'Connection'",
",",
"'close'",
")",
";",
"$",
"this",
"->",
"sendHeader",
"(",
")",
";",
"$",
"this",
"->",
"sendBody",
"(",
"$",
"body",
")",
";",
"}"
] | Method justSend
@access protected
@param string $body
@return void | [
"Method",
"justSend"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Request.php#L470-L484 |
Fenzland/php-http-client | libs/Request.php | Request.sendHeader | protected function sendHeader()
{
$this->openHandle();
$target= $this->path.($this->query? '?'.$this->query : '' ).($this->fragment? '#'.$this->fragment : '' );
$this->writeLine("{$this->method} {$target} HTTP/{$this->version}");
$this->writeLine("Host: {$this->host}");
foreach( $this->headers as $key=>$value ){
$this->writeLine("$key: $value");
}
$this->writeLine('');
} | php | protected function sendHeader()
{
$this->openHandle();
$target= $this->path.($this->query? '?'.$this->query : '' ).($this->fragment? '#'.$this->fragment : '' );
$this->writeLine("{$this->method} {$target} HTTP/{$this->version}");
$this->writeLine("Host: {$this->host}");
foreach( $this->headers as $key=>$value ){
$this->writeLine("$key: $value");
}
$this->writeLine('');
} | [
"protected",
"function",
"sendHeader",
"(",
")",
"{",
"$",
"this",
"->",
"openHandle",
"(",
")",
";",
"$",
"target",
"=",
"$",
"this",
"->",
"path",
".",
"(",
"$",
"this",
"->",
"query",
"?",
"'?'",
".",
"$",
"this",
"->",
"query",
":",
"''",
")",
".",
"(",
"$",
"this",
"->",
"fragment",
"?",
"'#'",
".",
"$",
"this",
"->",
"fragment",
":",
"''",
")",
";",
"$",
"this",
"->",
"writeLine",
"(",
"\"{$this->method} {$target} HTTP/{$this->version}\"",
")",
";",
"$",
"this",
"->",
"writeLine",
"(",
"\"Host: {$this->host}\"",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"writeLine",
"(",
"\"$key: $value\"",
")",
";",
"}",
"$",
"this",
"->",
"writeLine",
"(",
"''",
")",
";",
"}"
] | Method sendHeader
@access protected
@return void | [
"Method",
"sendHeader"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Request.php#L493-L506 |
Fenzland/php-http-client | libs/Request.php | Request.openHandle | private function openHandle()
{
if( !$this->host )
throw new \Exception('Host is not defined.');
$this->handle= ($this->scheme==='https'?
fsockopen( 'ssl://'.$this->host, $this->port?:443 )
:
fsockopen( $this->host, $this->port?:80 )
);
} | php | private function openHandle()
{
if( !$this->host )
throw new \Exception('Host is not defined.');
$this->handle= ($this->scheme==='https'?
fsockopen( 'ssl://'.$this->host, $this->port?:443 )
:
fsockopen( $this->host, $this->port?:80 )
);
} | [
"private",
"function",
"openHandle",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"host",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"'Host is not defined.'",
")",
";",
"$",
"this",
"->",
"handle",
"=",
"(",
"$",
"this",
"->",
"scheme",
"===",
"'https'",
"?",
"fsockopen",
"(",
"'ssl://'",
".",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
"?",
":",
"443",
")",
":",
"fsockopen",
"(",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
"?",
":",
"80",
")",
")",
";",
"}"
] | Method openHandle
@access private
@return void | [
"Method",
"openHandle"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Request.php#L515-L525 |
Fenzland/php-http-client | libs/Request.php | Request.write | private function write( string$content )
{
$this->raw.= $content;
fwrite( $this->handle, $content );
} | php | private function write( string$content )
{
$this->raw.= $content;
fwrite( $this->handle, $content );
} | [
"private",
"function",
"write",
"(",
"string",
"$",
"content",
")",
"{",
"$",
"this",
"->",
"raw",
".=",
"$",
"content",
";",
"fwrite",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"content",
")",
";",
"}"
] | Method write
@access private
@param string $content
@return void | [
"Method",
"write"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Request.php#L592-L597 |
MetaModels/phpunit-contao-database | src/Contao/Database/FakeResult.php | FakeResult.addRow | public function addRow($data, $rowId = null)
{
if (($rowId === null) && isset($data['id'])) {
$rowId = $data['id'];
}
if ($rowId === null) {
$rowId = count($this->rows);
}
$this->rows[$rowId] = $data;
return $this;
} | php | public function addRow($data, $rowId = null)
{
if (($rowId === null) && isset($data['id'])) {
$rowId = $data['id'];
}
if ($rowId === null) {
$rowId = count($this->rows);
}
$this->rows[$rowId] = $data;
return $this;
} | [
"public",
"function",
"addRow",
"(",
"$",
"data",
",",
"$",
"rowId",
"=",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"rowId",
"===",
"null",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"rowId",
"=",
"$",
"data",
"[",
"'id'",
"]",
";",
"}",
"if",
"(",
"$",
"rowId",
"===",
"null",
")",
"{",
"$",
"rowId",
"=",
"count",
"(",
"$",
"this",
"->",
"rows",
")",
";",
"}",
"$",
"this",
"->",
"rows",
"[",
"$",
"rowId",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}"
] | Add a row.
@param array $data The row data.
@param null|int $rowId The id for the row.
@return FakeResult | [
"Add",
"a",
"row",
"."
] | train | https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/FakeResult.php#L44-L57 |
MetaModels/phpunit-contao-database | src/Contao/Database/FakeResult.php | FakeResult.addRows | public function addRows($data)
{
foreach ($data as $key => $row) {
$this->addRow($row, isset($row['id']) ? $row['id'] : $key);
}
return $this;
} | php | public function addRows($data)
{
foreach ($data as $key => $row) {
$this->addRow($row, isset($row['id']) ? $row['id'] : $key);
}
return $this;
} | [
"public",
"function",
"addRows",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"addRow",
"(",
"$",
"row",
",",
"isset",
"(",
"$",
"row",
"[",
"'id'",
"]",
")",
"?",
"$",
"row",
"[",
"'id'",
"]",
":",
"$",
"key",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add rows.
@param array $data The row data.
@return FakeResult | [
"Add",
"rows",
"."
] | train | https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/FakeResult.php#L66-L73 |
MetaModels/phpunit-contao-database | src/Contao/Database/FakeResult.php | FakeResult.getRow | public function getRow($index)
{
$keys = array_keys($this->rows);
return isset($keys[$index]) ? $this->rows[$keys[$index]] : null;
} | php | public function getRow($index)
{
$keys = array_keys($this->rows);
return isset($keys[$index]) ? $this->rows[$keys[$index]] : null;
} | [
"public",
"function",
"getRow",
"(",
"$",
"index",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"rows",
")",
";",
"return",
"isset",
"(",
"$",
"keys",
"[",
"$",
"index",
"]",
")",
"?",
"$",
"this",
"->",
"rows",
"[",
"$",
"keys",
"[",
"$",
"index",
"]",
"]",
":",
"null",
";",
"}"
] | Retrieve the row with the given index.
@param int $index The index.
@return array | [
"Retrieve",
"the",
"row",
"with",
"the",
"given",
"index",
"."
] | train | https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/FakeResult.php#L84-L89 |
perryflynn/PerrysLambda | src/PerrysLambda/ArrayList.php | ArrayList.asType | public static function asType($type, array $data)
{
$converter = new TypeStringListConverter($type);
$converter->setArraySource($data);
return new static($converter);
} | php | public static function asType($type, array $data)
{
$converter = new TypeStringListConverter($type);
$converter->setArraySource($data);
return new static($converter);
} | [
"public",
"static",
"function",
"asType",
"(",
"$",
"type",
",",
"array",
"$",
"data",
")",
"{",
"$",
"converter",
"=",
"new",
"TypeStringListConverter",
"(",
"$",
"type",
")",
";",
"$",
"converter",
"->",
"setArraySource",
"(",
"$",
"data",
")",
";",
"return",
"new",
"static",
"(",
"$",
"converter",
")",
";",
"}"
] | Create arraylist of class
@param string $type
@param mixed[] $data
@return \PerrysLambda\ArrayList | [
"Create",
"arraylist",
"of",
"class"
] | train | https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayList.php#L32-L37 |
perryflynn/PerrysLambda | src/PerrysLambda/ArrayList.php | ArrayList.serialize | public function serialize()
{
if($this->__converter instanceof IListConverter)
{
return $this->__converter->toArray($this);
}
else
{
return $this->toArray();
}
} | php | public function serialize()
{
if($this->__converter instanceof IListConverter)
{
return $this->__converter->toArray($this);
}
else
{
return $this->toArray();
}
} | [
"public",
"function",
"serialize",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"__converter",
"instanceof",
"IListConverter",
")",
"{",
"return",
"$",
"this",
"->",
"__converter",
"->",
"toArray",
"(",
"$",
"this",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"toArray",
"(",
")",
";",
"}",
"}"
] | Serialize via converter
@return mixed[] | [
"Serialize",
"via",
"converter"
] | train | https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayList.php#L63-L73 |
perryflynn/PerrysLambda | src/PerrysLambda/ArrayList.php | ArrayList.serializeGenerator | public function serializeGenerator()
{
if($this->__converter instanceof IListConverter)
{
foreach($this->__converter->toGenerator($this) as $index => $row)
{
yield $index => $row;
}
}
else
{
foreach($this->toArray() as $index => $row)
{
yield $index => $row;
}
}
} | php | public function serializeGenerator()
{
if($this->__converter instanceof IListConverter)
{
foreach($this->__converter->toGenerator($this) as $index => $row)
{
yield $index => $row;
}
}
else
{
foreach($this->toArray() as $index => $row)
{
yield $index => $row;
}
}
} | [
"public",
"function",
"serializeGenerator",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"__converter",
"instanceof",
"IListConverter",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"__converter",
"->",
"toGenerator",
"(",
"$",
"this",
")",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"yield",
"$",
"index",
"=>",
"$",
"row",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"toArray",
"(",
")",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"yield",
"$",
"index",
"=>",
"$",
"row",
";",
"}",
"}",
"}"
] | Serialize via converter as generator
@return mixed[] | [
"Serialize",
"via",
"converter",
"as",
"generator"
] | train | https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayList.php#L79-L95 |
locomotivemtl/charcoal-translator | src/Charcoal/Translator/TranslatorConfig.php | TranslatorConfig.setTranslations | public function setTranslations(array $translations)
{
$this->translations = [];
foreach ($translations as $domain => $data) {
if (!is_array($data)) {
throw new InvalidArgumentException(
'Translator translations must be a 3-level array'
);
}
foreach ($data as $locale => $messages) {
if (!is_array($messages)) {
throw new InvalidArgumentException(
'Translator translations must be a 3-level array'
);
}
}
}
$this->translations = $translations;
return $this;
} | php | public function setTranslations(array $translations)
{
$this->translations = [];
foreach ($translations as $domain => $data) {
if (!is_array($data)) {
throw new InvalidArgumentException(
'Translator translations must be a 3-level array'
);
}
foreach ($data as $locale => $messages) {
if (!is_array($messages)) {
throw new InvalidArgumentException(
'Translator translations must be a 3-level array'
);
}
}
}
$this->translations = $translations;
return $this;
} | [
"public",
"function",
"setTranslations",
"(",
"array",
"$",
"translations",
")",
"{",
"$",
"this",
"->",
"translations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"domain",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Translator translations must be a 3-level array'",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"locale",
"=>",
"$",
"messages",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"messages",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Translator translations must be a 3-level array'",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"translations",
"=",
"$",
"translations",
";",
"return",
"$",
"this",
";",
"}"
] | Set mapping of additional translations.
Expects:
```json
{
"<domain>": {
"<locale>": {
"<translation-key>": "translation"
}
}
}
```
@param array $translations Mapping of domains/locales/messages.
@throws InvalidArgumentException If the path is not a string.
@return TranslatorConfig Chainable | [
"Set",
"mapping",
"of",
"additional",
"translations",
"."
] | train | https://github.com/locomotivemtl/charcoal-translator/blob/0a64432baef223dcccbfecf057015440dfa76e49/src/Charcoal/Translator/TranslatorConfig.php#L144-L166 |
ZFrapid/zf2rapid-domain | src/ZF2rapidDomain/Entity/AbstractEntity.php | AbstractEntity.exchangeArray | public function exchangeArray(array $array)
{
foreach ($array as $key => $value) {
$setMethod = 'set' . StaticFilter::execute(
$key, 'WordUnderscoreToCamelCase'
);
if (method_exists($this, $setMethod)) {
$this->$setMethod($value);
}
}
} | php | public function exchangeArray(array $array)
{
foreach ($array as $key => $value) {
$setMethod = 'set' . StaticFilter::execute(
$key, 'WordUnderscoreToCamelCase'
);
if (method_exists($this, $setMethod)) {
$this->$setMethod($value);
}
}
} | [
"public",
"function",
"exchangeArray",
"(",
"array",
"$",
"array",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"setMethod",
"=",
"'set'",
".",
"StaticFilter",
"::",
"execute",
"(",
"$",
"key",
",",
"'WordUnderscoreToCamelCase'",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"setMethod",
")",
")",
"{",
"$",
"this",
"->",
"$",
"setMethod",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}"
] | Exchange properties with values from array
@param array $array | [
"Exchange",
"properties",
"with",
"values",
"from",
"array"
] | train | https://github.com/ZFrapid/zf2rapid-domain/blob/9455689cac06b42025c144878604d27c28b4bb04/src/ZF2rapidDomain/Entity/AbstractEntity.php#L32-L43 |
ZFrapid/zf2rapid-domain | src/ZF2rapidDomain/Entity/AbstractEntity.php | AbstractEntity.getArrayCopy | public function getArrayCopy()
{
$data = [];
foreach (get_object_vars($this) as $key => $value) {
$getMethod = 'get' . ucfirst($key);
$arrayKey = StaticFilter::execute($key, 'WordCamelCaseToUnderscore');
$arrayKey = StaticFilter::execute($arrayKey, 'StringToLower');
if (method_exists($this, $getMethod)) {
$data[$arrayKey] = $this->$getMethod();
}
}
return $data;
} | php | public function getArrayCopy()
{
$data = [];
foreach (get_object_vars($this) as $key => $value) {
$getMethod = 'get' . ucfirst($key);
$arrayKey = StaticFilter::execute($key, 'WordCamelCaseToUnderscore');
$arrayKey = StaticFilter::execute($arrayKey, 'StringToLower');
if (method_exists($this, $getMethod)) {
$data[$arrayKey] = $this->$getMethod();
}
}
return $data;
} | [
"public",
"function",
"getArrayCopy",
"(",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"get_object_vars",
"(",
"$",
"this",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"getMethod",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"key",
")",
";",
"$",
"arrayKey",
"=",
"StaticFilter",
"::",
"execute",
"(",
"$",
"key",
",",
"'WordCamelCaseToUnderscore'",
")",
";",
"$",
"arrayKey",
"=",
"StaticFilter",
"::",
"execute",
"(",
"$",
"arrayKey",
",",
"'StringToLower'",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"getMethod",
")",
")",
"{",
"$",
"data",
"[",
"$",
"arrayKey",
"]",
"=",
"$",
"this",
"->",
"$",
"getMethod",
"(",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Generate an array copy from property values | [
"Generate",
"an",
"array",
"copy",
"from",
"property",
"values"
] | train | https://github.com/ZFrapid/zf2rapid-domain/blob/9455689cac06b42025c144878604d27c28b4bb04/src/ZF2rapidDomain/Entity/AbstractEntity.php#L48-L65 |
Fenzland/http-api-gluer | src/Gluer/THoldsSerializers_.php | THoldsSerializers_.registerSerializer_ | static public function registerSerializer_( string$mime, $serializer ):string
{
static::checkSerializerNotRegistered_( $mime );
static::checkSerializer_( $serializer );
static::$serializers_[$mime]= $serializer;
return self::class;
} | php | static public function registerSerializer_( string$mime, $serializer ):string
{
static::checkSerializerNotRegistered_( $mime );
static::checkSerializer_( $serializer );
static::$serializers_[$mime]= $serializer;
return self::class;
} | [
"static",
"public",
"function",
"registerSerializer_",
"(",
"string",
"$",
"mime",
",",
"$",
"serializer",
")",
":",
"string",
"{",
"static",
"::",
"checkSerializerNotRegistered_",
"(",
"$",
"mime",
")",
";",
"static",
"::",
"checkSerializer_",
"(",
"$",
"serializer",
")",
";",
"static",
"::",
"$",
"serializers_",
"[",
"$",
"mime",
"]",
"=",
"$",
"serializer",
";",
"return",
"self",
"::",
"class",
";",
"}"
] | Static method registerSerializer_
@static
@access public
@param string $mime
@param class|S\ASerializer $serializer
@return class | [
"Static",
"method",
"registerSerializer_"
] | train | https://github.com/Fenzland/http-api-gluer/blob/3488de28b7f54fb444ec47f84034473a7d86e17e/src/Gluer/THoldsSerializers_.php#L26-L35 |
Fenzland/http-api-gluer | src/Gluer/THoldsSerializers_.php | THoldsSerializers_.checkSerializer_ | static protected function checkSerializer_( $serializer ):void
{
if(!(
(
is_object( $serializer )
&&
$serializer instanceof S\ASerializer
)
or
(
is_string( $serializer )
&&
class_exists( $serializer )
&&
isset( class_parents( $serializer )[S\ASerializer::class] )
)
)){
$caller= debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 )[1];
throw new \TypeError(
"Argument 2 passed to {$caller['class']}{$caller['type']}{$caller['function']}() must be an class extends ".S\ASerializer::class.' or it\'s instance'
);
}
} | php | static protected function checkSerializer_( $serializer ):void
{
if(!(
(
is_object( $serializer )
&&
$serializer instanceof S\ASerializer
)
or
(
is_string( $serializer )
&&
class_exists( $serializer )
&&
isset( class_parents( $serializer )[S\ASerializer::class] )
)
)){
$caller= debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 )[1];
throw new \TypeError(
"Argument 2 passed to {$caller['class']}{$caller['type']}{$caller['function']}() must be an class extends ".S\ASerializer::class.' or it\'s instance'
);
}
} | [
"static",
"protected",
"function",
"checkSerializer_",
"(",
"$",
"serializer",
")",
":",
"void",
"{",
"if",
"(",
"!",
"(",
"(",
"is_object",
"(",
"$",
"serializer",
")",
"&&",
"$",
"serializer",
"instanceof",
"S",
"\\",
"ASerializer",
")",
"or",
"(",
"is_string",
"(",
"$",
"serializer",
")",
"&&",
"class_exists",
"(",
"$",
"serializer",
")",
"&&",
"isset",
"(",
"class_parents",
"(",
"$",
"serializer",
")",
"[",
"S",
"\\",
"ASerializer",
"::",
"class",
"]",
")",
")",
")",
")",
"{",
"$",
"caller",
"=",
"debug_backtrace",
"(",
"DEBUG_BACKTRACE_IGNORE_ARGS",
",",
"2",
")",
"[",
"1",
"]",
";",
"throw",
"new",
"\\",
"TypeError",
"(",
"\"Argument 2 passed to {$caller['class']}{$caller['type']}{$caller['function']}() must be an class extends \"",
".",
"S",
"\\",
"ASerializer",
"::",
"class",
".",
"' or it\\'s instance'",
")",
";",
"}",
"}"
] | Static method checkSerializer_
@static
@access protected
@param mixed $serializer
@return void | [
"Static",
"method",
"checkSerializer_"
] | train | https://github.com/Fenzland/http-api-gluer/blob/3488de28b7f54fb444ec47f84034473a7d86e17e/src/Gluer/THoldsSerializers_.php#L93-L116 |
Fenzland/http-api-gluer | src/Gluer/THoldsSerializers_.php | THoldsSerializers_.achieveSerializer_ | static protected function achieveSerializer_( string$mime ):S\ASerializer
{
static::checkSerializerSupported_( $mime );
$serializer= static::getSerializer_( $mime );
return static::instantiateSerializer_( $serializer );
} | php | static protected function achieveSerializer_( string$mime ):S\ASerializer
{
static::checkSerializerSupported_( $mime );
$serializer= static::getSerializer_( $mime );
return static::instantiateSerializer_( $serializer );
} | [
"static",
"protected",
"function",
"achieveSerializer_",
"(",
"string",
"$",
"mime",
")",
":",
"S",
"\\",
"ASerializer",
"{",
"static",
"::",
"checkSerializerSupported_",
"(",
"$",
"mime",
")",
";",
"$",
"serializer",
"=",
"static",
"::",
"getSerializer_",
"(",
"$",
"mime",
")",
";",
"return",
"static",
"::",
"instantiateSerializer_",
"(",
"$",
"serializer",
")",
";",
"}"
] | Static method achieveSerializer_
@static
@access protected
@param string $mime
@return S\ASerializer | [
"Static",
"method",
"achieveSerializer_"
] | train | https://github.com/Fenzland/http-api-gluer/blob/3488de28b7f54fb444ec47f84034473a7d86e17e/src/Gluer/THoldsSerializers_.php#L171-L178 |
varunsridharan/wp-post | src/Post.php | Post.set_post | protected function set_post( $post ) {
$this->post = $post;
$this->id = ( isset( $post->ID ) ) ? $post->ID : false;
if ( ! empty( $this->taxonomies() ) ) {
foreach ( $this->taxonomies() as $taxonomy ) {
$this->{$taxonomy} = $this->get_terms( $taxonomy, array( 'fields' => 'all' ) );
}
}
} | php | protected function set_post( $post ) {
$this->post = $post;
$this->id = ( isset( $post->ID ) ) ? $post->ID : false;
if ( ! empty( $this->taxonomies() ) ) {
foreach ( $this->taxonomies() as $taxonomy ) {
$this->{$taxonomy} = $this->get_terms( $taxonomy, array( 'fields' => 'all' ) );
}
}
} | [
"protected",
"function",
"set_post",
"(",
"$",
"post",
")",
"{",
"$",
"this",
"->",
"post",
"=",
"$",
"post",
";",
"$",
"this",
"->",
"id",
"=",
"(",
"isset",
"(",
"$",
"post",
"->",
"ID",
")",
")",
"?",
"$",
"post",
"->",
"ID",
":",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"taxonomies",
"(",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"taxonomies",
"(",
")",
"as",
"$",
"taxonomy",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"taxonomy",
"}",
"=",
"$",
"this",
"->",
"get_terms",
"(",
"$",
"taxonomy",
",",
"array",
"(",
"'fields'",
"=>",
"'all'",
")",
")",
";",
"}",
"}",
"}"
] | Sets Post Data.
@param $post | [
"Sets",
"Post",
"Data",
"."
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L70-L79 |
varunsridharan/wp-post | src/Post.php | Post.featured_image_id | public function featured_image_id() {
if ( isset( $this->featured_image_id ) ) {
return $this->featured_image_id;
}
$this->featured_image_id = \get_post_thumbnail_id( $this->post );
return $this->featured_image_id;
} | php | public function featured_image_id() {
if ( isset( $this->featured_image_id ) ) {
return $this->featured_image_id;
}
$this->featured_image_id = \get_post_thumbnail_id( $this->post );
return $this->featured_image_id;
} | [
"public",
"function",
"featured_image_id",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"featured_image_id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"featured_image_id",
";",
"}",
"$",
"this",
"->",
"featured_image_id",
"=",
"\\",
"get_post_thumbnail_id",
"(",
"$",
"this",
"->",
"post",
")",
";",
"return",
"$",
"this",
"->",
"featured_image_id",
";",
"}"
] | Returns Featured Image ID.
@return bool|int|mixed|string | [
"Returns",
"Featured",
"Image",
"ID",
"."
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L137-L143 |
varunsridharan/wp-post | src/Post.php | Post.featured_image_url | public function featured_image_url( $size = 'thumbnail', $default = '' ) {
$featured_image = \get_the_post_thumbnail_url( $this->id(), $size );
return ( false !== $featured_image ) ? $featured_image : $default;
} | php | public function featured_image_url( $size = 'thumbnail', $default = '' ) {
$featured_image = \get_the_post_thumbnail_url( $this->id(), $size );
return ( false !== $featured_image ) ? $featured_image : $default;
} | [
"public",
"function",
"featured_image_url",
"(",
"$",
"size",
"=",
"'thumbnail'",
",",
"$",
"default",
"=",
"''",
")",
"{",
"$",
"featured_image",
"=",
"\\",
"get_the_post_thumbnail_url",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"size",
")",
";",
"return",
"(",
"false",
"!==",
"$",
"featured_image",
")",
"?",
"$",
"featured_image",
":",
"$",
"default",
";",
"}"
] | Returns Featured Image URL.
@param string $size
@param string $default
@return false|string | [
"Returns",
"Featured",
"Image",
"URL",
"."
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L153-L156 |
varunsridharan/wp-post | src/Post.php | Post.parent | public function parent( $only_id = true ) {
if ( $only_id ) {
return $this->post->post_parent;
}
$class = get_called_class();
return new $class( $this->post->post_parent );
} | php | public function parent( $only_id = true ) {
if ( $only_id ) {
return $this->post->post_parent;
}
$class = get_called_class();
return new $class( $this->post->post_parent );
} | [
"public",
"function",
"parent",
"(",
"$",
"only_id",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"only_id",
")",
"{",
"return",
"$",
"this",
"->",
"post",
"->",
"post_parent",
";",
"}",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"post",
"->",
"post_parent",
")",
";",
"}"
] | Returns Post Parent.
@param boolean $only_id
@return int | [
"Returns",
"Post",
"Parent",
"."
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L224-L230 |
varunsridharan/wp-post | src/Post.php | Post.update_meta | public function update_meta( $meta_key = '', $values = '', $prev_values = '' ) {
return \update_post_meta( $this->id(), $meta_key, $values, $prev_values );
} | php | public function update_meta( $meta_key = '', $values = '', $prev_values = '' ) {
return \update_post_meta( $this->id(), $meta_key, $values, $prev_values );
} | [
"public",
"function",
"update_meta",
"(",
"$",
"meta_key",
"=",
"''",
",",
"$",
"values",
"=",
"''",
",",
"$",
"prev_values",
"=",
"''",
")",
"{",
"return",
"\\",
"update_post_meta",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"meta_key",
",",
"$",
"values",
",",
"$",
"prev_values",
")",
";",
"}"
] | Updates Post Meta.
@param string $meta_key
@param string $values
@param string $prev_values
@return bool|int | [
"Updates",
"Post",
"Meta",
"."
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L313-L315 |
varunsridharan/wp-post | src/Post.php | Post.add_meta | public function add_meta( $meta_key = '', $values = '', $unique = false ) {
return \add_post_meta( $this->id(), $meta_key, $values, $unique );
} | php | public function add_meta( $meta_key = '', $values = '', $unique = false ) {
return \add_post_meta( $this->id(), $meta_key, $values, $unique );
} | [
"public",
"function",
"add_meta",
"(",
"$",
"meta_key",
"=",
"''",
",",
"$",
"values",
"=",
"''",
",",
"$",
"unique",
"=",
"false",
")",
"{",
"return",
"\\",
"add_post_meta",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"meta_key",
",",
"$",
"values",
",",
"$",
"unique",
")",
";",
"}"
] | Adds Post Meta.
@param string $meta_key
@param string $values
@param boolean|bool $unique
@return bool|int | [
"Adds",
"Post",
"Meta",
"."
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L326-L328 |
varunsridharan/wp-post | src/Post.php | Post.taxonomies | public function taxonomies() {
if ( ! empty( $this->taxes ) ) {
return $this->taxes;
}
$taxes = \get_post_taxonomies( $this->post );
$this->taxes = $taxes;
return $this->taxes;
} | php | public function taxonomies() {
if ( ! empty( $this->taxes ) ) {
return $this->taxes;
}
$taxes = \get_post_taxonomies( $this->post );
$this->taxes = $taxes;
return $this->taxes;
} | [
"public",
"function",
"taxonomies",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"taxes",
")",
")",
"{",
"return",
"$",
"this",
"->",
"taxes",
";",
"}",
"$",
"taxes",
"=",
"\\",
"get_post_taxonomies",
"(",
"$",
"this",
"->",
"post",
")",
";",
"$",
"this",
"->",
"taxes",
"=",
"$",
"taxes",
";",
"return",
"$",
"this",
"->",
"taxes",
";",
"}"
] | Returns All Post Taxonomies.
@return array | [
"Returns",
"All",
"Post",
"Taxonomies",
"."
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L351-L358 |
varunsridharan/wp-post | src/Post.php | Post.get_terms | public function get_terms( $taxonomy = '', $args = array() ) {
if ( isset( $this->{$taxonomy} ) && empty( $args ) ) {
return $this->{$taxonomy};
} else {
$name = $taxonomy . '_' . md5( json_encode( $args ) );
if ( isset( $this->{$name} ) ) {
return $this->{$name};
}
$data = \wp_get_post_terms( $this->id(), $taxonomy, $args );
$this->{$name} = $data;
return $data;
}
} | php | public function get_terms( $taxonomy = '', $args = array() ) {
if ( isset( $this->{$taxonomy} ) && empty( $args ) ) {
return $this->{$taxonomy};
} else {
$name = $taxonomy . '_' . md5( json_encode( $args ) );
if ( isset( $this->{$name} ) ) {
return $this->{$name};
}
$data = \wp_get_post_terms( $this->id(), $taxonomy, $args );
$this->{$name} = $data;
return $data;
}
} | [
"public",
"function",
"get_terms",
"(",
"$",
"taxonomy",
"=",
"''",
",",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"taxonomy",
"}",
")",
"&&",
"empty",
"(",
"$",
"args",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"taxonomy",
"}",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"taxonomy",
".",
"'_'",
".",
"md5",
"(",
"json_encode",
"(",
"$",
"args",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"name",
"}",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"name",
"}",
";",
"}",
"$",
"data",
"=",
"\\",
"wp_get_post_terms",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"taxonomy",
",",
"$",
"args",
")",
";",
"$",
"this",
"->",
"{",
"$",
"name",
"}",
"=",
"$",
"data",
";",
"return",
"$",
"data",
";",
"}",
"}"
] | Returns All Terms From Post.
@param string $taxonomy
@param array $args
@return array|\WP_Error | [
"Returns",
"All",
"Terms",
"From",
"Post",
"."
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L368-L380 |
varunsridharan/wp-post | src/Post.php | Post.set_terms | public function set_terms( $terms = array(), $taxonomy = '', $append = false ) {
return \wp_set_post_terms( $this->id(), $terms, $taxonomy, $append );
} | php | public function set_terms( $terms = array(), $taxonomy = '', $append = false ) {
return \wp_set_post_terms( $this->id(), $terms, $taxonomy, $append );
} | [
"public",
"function",
"set_terms",
"(",
"$",
"terms",
"=",
"array",
"(",
")",
",",
"$",
"taxonomy",
"=",
"''",
",",
"$",
"append",
"=",
"false",
")",
"{",
"return",
"\\",
"wp_set_post_terms",
"(",
"$",
"this",
"->",
"id",
"(",
")",
",",
"$",
"terms",
",",
"$",
"taxonomy",
",",
"$",
"append",
")",
";",
"}"
] | Sets Given Terms With Tax To The Current Post.
@param array $terms
@param string $taxonomy
@param bool $append
@return array|false|\WP_Error | [
"Sets",
"Given",
"Terms",
"With",
"Tax",
"To",
"The",
"Current",
"Post",
"."
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L391-L393 |
varunsridharan/wp-post | src/Post.php | Post.in | public function in( $key = '', $data = '', $default = false ) {
if ( is_array( $data ) ) {
return ( in_array( $key, $data ) ) ? $key : $default;
}
if ( isset( $this->{$data} ) ) {
return ( in_array( $key, $this->{$data} ) ) ? $key : $default;
}
return $default;
} | php | public function in( $key = '', $data = '', $default = false ) {
if ( is_array( $data ) ) {
return ( in_array( $key, $data ) ) ? $key : $default;
}
if ( isset( $this->{$data} ) ) {
return ( in_array( $key, $this->{$data} ) ) ? $key : $default;
}
return $default;
} | [
"public",
"function",
"in",
"(",
"$",
"key",
"=",
"''",
",",
"$",
"data",
"=",
"''",
",",
"$",
"default",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"data",
")",
")",
"?",
"$",
"key",
":",
"$",
"default",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"data",
"}",
")",
")",
"{",
"return",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"{",
"$",
"data",
"}",
")",
")",
"?",
"$",
"key",
":",
"$",
"default",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Checks if given key is in array
@uses \in_array()
@uses \VS_WP_Post
@example in('somekey','post_category','no') post_category will be taken from post data.
@example in('somekey',array('somekey' => 'somekey'), will be used the given array.
@param string $key
@param string $data
@param bool $default
@return bool|string | [
"Checks",
"if",
"given",
"key",
"is",
"in",
"array"
] | train | https://github.com/varunsridharan/wp-post/blob/064bdc55c945b08480c841c1b99502eb8df148e1/src/Post.php#L415-L423 |
nattreid/mailing | src/BaseMailer.php | BaseMailer.createMail | protected function createMail(string $template): Mail
{
$mail = $this->mailFactory->create($template, $this->basePath);
$mail->setFrom($this->sender);
return $mail;
} | php | protected function createMail(string $template): Mail
{
$mail = $this->mailFactory->create($template, $this->basePath);
$mail->setFrom($this->sender);
return $mail;
} | [
"protected",
"function",
"createMail",
"(",
"string",
"$",
"template",
")",
":",
"Mail",
"{",
"$",
"mail",
"=",
"$",
"this",
"->",
"mailFactory",
"->",
"create",
"(",
"$",
"template",
",",
"$",
"this",
"->",
"basePath",
")",
";",
"$",
"mail",
"->",
"setFrom",
"(",
"$",
"this",
"->",
"sender",
")",
";",
"return",
"$",
"mail",
";",
"}"
] | Vytvori instanci mailu
@param string $template
@return Mail | [
"Vytvori",
"instanci",
"mailu"
] | train | https://github.com/nattreid/mailing/blob/d61750a47c38d7533294d74d6601ca99a25f1b7c/src/BaseMailer.php#L46-L51 |
nattreid/mailing | src/BaseMailer.php | BaseMailer.createMailFromString | protected function createMailFromString(string $latte): Mail
{
$mail = $this->createMail($latte);
$mail->setStringLoader();
return $mail;
} | php | protected function createMailFromString(string $latte): Mail
{
$mail = $this->createMail($latte);
$mail->setStringLoader();
return $mail;
} | [
"protected",
"function",
"createMailFromString",
"(",
"string",
"$",
"latte",
")",
":",
"Mail",
"{",
"$",
"mail",
"=",
"$",
"this",
"->",
"createMail",
"(",
"$",
"latte",
")",
";",
"$",
"mail",
"->",
"setStringLoader",
"(",
")",
";",
"return",
"$",
"mail",
";",
"}"
] | Vytvori instanci mailu
@param string $latte
@return Mail | [
"Vytvori",
"instanci",
"mailu"
] | train | https://github.com/nattreid/mailing/blob/d61750a47c38d7533294d74d6601ca99a25f1b7c/src/BaseMailer.php#L58-L63 |
nattreid/mailing | src/BaseMailer.php | BaseMailer.link | protected function link(string $destination, array $args = []): string
{
return $this->linkGenerator->link($destination, $args);
} | php | protected function link(string $destination, array $args = []): string
{
return $this->linkGenerator->link($destination, $args);
} | [
"protected",
"function",
"link",
"(",
"string",
"$",
"destination",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"linkGenerator",
"->",
"link",
"(",
"$",
"destination",
",",
"$",
"args",
")",
";",
"}"
] | Generuje link
@param string $destination destination in format "[[module:]presenter:]action" or "signal!" or "this"
@param array $args
@return string
@throws InvalidLinkException | [
"Generuje",
"link"
] | train | https://github.com/nattreid/mailing/blob/d61750a47c38d7533294d74d6601ca99a25f1b7c/src/BaseMailer.php#L72-L75 |
fuelphp-storage/security | src/Providers/FuelServiceProvider.php | FuelServiceProvider.register | public function register()
{
$this->container->add('security', function (array $config = [])
{
$configInstance = $this->container->get('configInstance');
$config = \Arr::merge($configInstance->load('security', true), $config);
return new Security\Manager($config);
});
$this->container->add('security.filter.htmlentities', function (Manager $manager)
{
return new Security\Filter\HtmlEntities($manager);
});
$this->container->add('security.csrf', function (array $config = [], $session = null)
{
return new Security\Csrf($config, $session);
});
} | php | public function register()
{
$this->container->add('security', function (array $config = [])
{
$configInstance = $this->container->get('configInstance');
$config = \Arr::merge($configInstance->load('security', true), $config);
return new Security\Manager($config);
});
$this->container->add('security.filter.htmlentities', function (Manager $manager)
{
return new Security\Filter\HtmlEntities($manager);
});
$this->container->add('security.csrf', function (array $config = [], $session = null)
{
return new Security\Csrf($config, $session);
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"container",
"->",
"add",
"(",
"'security'",
",",
"function",
"(",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"configInstance",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'configInstance'",
")",
";",
"$",
"config",
"=",
"\\",
"Arr",
"::",
"merge",
"(",
"$",
"configInstance",
"->",
"load",
"(",
"'security'",
",",
"true",
")",
",",
"$",
"config",
")",
";",
"return",
"new",
"Security",
"\\",
"Manager",
"(",
"$",
"config",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"container",
"->",
"add",
"(",
"'security.filter.htmlentities'",
",",
"function",
"(",
"Manager",
"$",
"manager",
")",
"{",
"return",
"new",
"Security",
"\\",
"Filter",
"\\",
"HtmlEntities",
"(",
"$",
"manager",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"container",
"->",
"add",
"(",
"'security.csrf'",
",",
"function",
"(",
"array",
"$",
"config",
"=",
"[",
"]",
",",
"$",
"session",
"=",
"null",
")",
"{",
"return",
"new",
"Security",
"\\",
"Csrf",
"(",
"$",
"config",
",",
"$",
"session",
")",
";",
"}",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/fuelphp-storage/security/blob/2cad42a8432bc9c9de46486623b71e105ff84b1b/src/Providers/FuelServiceProvider.php#L33-L53 |
linpax/microphp-framework | src/cli/CliApplication.php | CliApplication.doException | protected function doException(\Exception $e)
{
$command = new DefaultConsoleCommand();
$command->data = '"Error #' . $e->getCode() . ' - ' . $e->getMessage() . '"';
$command->execute();
$response = (new ResponseInjector)->build();
$response = $response->withHeader('status', (string)(int)$command->result); // TODO: hack for select cli stream
$stream = $response->getBody();
$stream->write($command->message);
return $response->withBody($stream);
} | php | protected function doException(\Exception $e)
{
$command = new DefaultConsoleCommand();
$command->data = '"Error #' . $e->getCode() . ' - ' . $e->getMessage() . '"';
$command->execute();
$response = (new ResponseInjector)->build();
$response = $response->withHeader('status', (string)(int)$command->result); // TODO: hack for select cli stream
$stream = $response->getBody();
$stream->write($command->message);
return $response->withBody($stream);
} | [
"protected",
"function",
"doException",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"command",
"=",
"new",
"DefaultConsoleCommand",
"(",
")",
";",
"$",
"command",
"->",
"data",
"=",
"'\"Error #'",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"' - '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'\"'",
";",
"$",
"command",
"->",
"execute",
"(",
")",
";",
"$",
"response",
"=",
"(",
"new",
"ResponseInjector",
")",
"->",
"build",
"(",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"'status'",
",",
"(",
"string",
")",
"(",
"int",
")",
"$",
"command",
"->",
"result",
")",
";",
"// TODO: hack for select cli stream",
"$",
"stream",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"$",
"stream",
"->",
"write",
"(",
"$",
"command",
"->",
"message",
")",
";",
"return",
"$",
"response",
"->",
"withBody",
"(",
"$",
"stream",
")",
";",
"}"
] | Run application with error
@param \Exception $e
@return ResponseInterface
@throws \InvalidArgumentException|\RuntimeException|Exception | [
"Run",
"application",
"with",
"error"
] | train | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/cli/CliApplication.php#L30-L43 |
sil-project/StockBundle | src/Domain/Factory/StockUnitFactory.php | StockUnitFactory.createNew | public function createNew(StockItemInterface $item, UomQty $qty, Location $location,
?BatchInterface $batch = null): StockUnit
{
$code = $this->codeGenerator->generate($item, $qty, $location, $batch);
return StockUnit::createDefault($code, $item, $qty, $location, $batch);
} | php | public function createNew(StockItemInterface $item, UomQty $qty, Location $location,
?BatchInterface $batch = null): StockUnit
{
$code = $this->codeGenerator->generate($item, $qty, $location, $batch);
return StockUnit::createDefault($code, $item, $qty, $location, $batch);
} | [
"public",
"function",
"createNew",
"(",
"StockItemInterface",
"$",
"item",
",",
"UomQty",
"$",
"qty",
",",
"Location",
"$",
"location",
",",
"?",
"BatchInterface",
"$",
"batch",
"=",
"null",
")",
":",
"StockUnit",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"codeGenerator",
"->",
"generate",
"(",
"$",
"item",
",",
"$",
"qty",
",",
"$",
"location",
",",
"$",
"batch",
")",
";",
"return",
"StockUnit",
"::",
"createDefault",
"(",
"$",
"code",
",",
"$",
"item",
",",
"$",
"qty",
",",
"$",
"location",
",",
"$",
"batch",
")",
";",
"}"
] | @param StockItemInterface $item
@param UomQty $qty
@param Location $location
@param BatchInterface|null $batch
@return StockUnit | [
"@param",
"StockItemInterface",
"$item",
"@param",
"UomQty",
"$qty",
"@param",
"Location",
"$location",
"@param",
"BatchInterface|null",
"$batch"
] | train | https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Factory/StockUnitFactory.php#L50-L56 |
sil-project/StockBundle | src/Domain/Factory/StockUnitFactory.php | StockUnitFactory.createFrom | public function createFrom(StockUnit $srcUnit, Location $location): StockUnit
{
$code = $this->codeGenerator->generate($srcUnit->getStockItem(),
$srcUnit->getQty(), $location, $srcUnit->getBatch());
return StockUnit::createDefault($code, $srcUnit->getStockItem(),
$srcUnit->getQty(), $location, $srcUnit->getBatch());
} | php | public function createFrom(StockUnit $srcUnit, Location $location): StockUnit
{
$code = $this->codeGenerator->generate($srcUnit->getStockItem(),
$srcUnit->getQty(), $location, $srcUnit->getBatch());
return StockUnit::createDefault($code, $srcUnit->getStockItem(),
$srcUnit->getQty(), $location, $srcUnit->getBatch());
} | [
"public",
"function",
"createFrom",
"(",
"StockUnit",
"$",
"srcUnit",
",",
"Location",
"$",
"location",
")",
":",
"StockUnit",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"codeGenerator",
"->",
"generate",
"(",
"$",
"srcUnit",
"->",
"getStockItem",
"(",
")",
",",
"$",
"srcUnit",
"->",
"getQty",
"(",
")",
",",
"$",
"location",
",",
"$",
"srcUnit",
"->",
"getBatch",
"(",
")",
")",
";",
"return",
"StockUnit",
"::",
"createDefault",
"(",
"$",
"code",
",",
"$",
"srcUnit",
"->",
"getStockItem",
"(",
")",
",",
"$",
"srcUnit",
"->",
"getQty",
"(",
")",
",",
"$",
"location",
",",
"$",
"srcUnit",
"->",
"getBatch",
"(",
")",
")",
";",
"}"
] | @param StockUnit $srcUnit
@param Location $location
@return StockUnit | [
"@param",
"StockUnit",
"$srcUnit",
"@param",
"Location",
"$location"
] | train | https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Factory/StockUnitFactory.php#L64-L71 |
Wedeto/Util | src/DI/DI.php | DI.startNewContext | public static function startNewContext(string $name, bool $inherit = true)
{
if ($inherit)
{
$current = static::getInjector();
$new_injector = new Injector($current);
}
else
$new_injector = new Injector();
return static::$injectors[$name] = $new_injector;
} | php | public static function startNewContext(string $name, bool $inherit = true)
{
if ($inherit)
{
$current = static::getInjector();
$new_injector = new Injector($current);
}
else
$new_injector = new Injector();
return static::$injectors[$name] = $new_injector;
} | [
"public",
"static",
"function",
"startNewContext",
"(",
"string",
"$",
"name",
",",
"bool",
"$",
"inherit",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"inherit",
")",
"{",
"$",
"current",
"=",
"static",
"::",
"getInjector",
"(",
")",
";",
"$",
"new_injector",
"=",
"new",
"Injector",
"(",
"$",
"current",
")",
";",
"}",
"else",
"$",
"new_injector",
"=",
"new",
"Injector",
"(",
")",
";",
"return",
"static",
"::",
"$",
"injectors",
"[",
"$",
"name",
"]",
"=",
"$",
"new_injector",
";",
"}"
] | Start a new injection context. Useful to be able to release
all static context to a certain run of the software, for example
in testing.
@param string $name A name for the injection context
@param bool $inherit True to inherit instances from the current injector,
false to start with an empty set. | [
"Start",
"a",
"new",
"injection",
"context",
".",
"Useful",
"to",
"be",
"able",
"to",
"release",
"all",
"static",
"context",
"to",
"a",
"certain",
"run",
"of",
"the",
"software",
"for",
"example",
"in",
"testing",
"."
] | train | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DI/DI.php#L63-L74 |
Wedeto/Util | src/DI/DI.php | DI.destroyContext | public static function destroyContext(string $name)
{
end(static::$injectors);
if ($name !== key(static::$injectors))
throw new DIException("Injection context $name is not at top of the stack");
$injector = array_pop(static::$injectors);
} | php | public static function destroyContext(string $name)
{
end(static::$injectors);
if ($name !== key(static::$injectors))
throw new DIException("Injection context $name is not at top of the stack");
$injector = array_pop(static::$injectors);
} | [
"public",
"static",
"function",
"destroyContext",
"(",
"string",
"$",
"name",
")",
"{",
"end",
"(",
"static",
"::",
"$",
"injectors",
")",
";",
"if",
"(",
"$",
"name",
"!==",
"key",
"(",
"static",
"::",
"$",
"injectors",
")",
")",
"throw",
"new",
"DIException",
"(",
"\"Injection context $name is not at top of the stack\"",
")",
";",
"$",
"injector",
"=",
"array_pop",
"(",
"static",
"::",
"$",
"injectors",
")",
";",
"}"
] | Destroy a context - the injector at the top of the stack
is released.
@param string $name The name of the injection context
@throws DIException When the injection context is not at the top of the stack | [
"Destroy",
"a",
"context",
"-",
"the",
"injector",
"at",
"the",
"top",
"of",
"the",
"stack",
"is",
"released",
"."
] | train | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DI/DI.php#L83-L90 |
wasinger/adaptimage | src/ThumbnailGenerator.php | ThumbnailGenerator.thumbnail | public function thumbnail($really_do_it, ImageFileInfo $image)
{
return $this->resizer->resize($this->ird, $image, $really_do_it);
} | php | public function thumbnail($really_do_it, ImageFileInfo $image)
{
return $this->resizer->resize($this->ird, $image, $really_do_it);
} | [
"public",
"function",
"thumbnail",
"(",
"$",
"really_do_it",
",",
"ImageFileInfo",
"$",
"image",
")",
"{",
"return",
"$",
"this",
"->",
"resizer",
"->",
"resize",
"(",
"$",
"this",
"->",
"ird",
",",
"$",
"image",
",",
"$",
"really_do_it",
")",
";",
"}"
] | Get a thumbnail for an image
If the thumbnail is already generated and cached, return the cached thumbnail. If the thumbnail is not yet
in the cache, the thumbnail will be generated and cached, but only if the first param $really_do_it
is TRUE. If it is FALSE, an ImageFileInfo is returned that contains the resulting size, pathname, and type of
the thumbnail, though this file does not exist (yet).
@param bool $really_do_it If false, don't really create thumbnail if it isn't in cache yet
but only calculate the resulting ImageFileInfo (size, type, and pathname)
@param ImageFileInfo $image The image for which the thumbnail is to be generated
@return ImageFileInfo Information about the thumbnail such as pathname, type, and size
@throws \Exception If the thumbnail can not be generated | [
"Get",
"a",
"thumbnail",
"for",
"an",
"image"
] | train | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ThumbnailGenerator.php#L65-L68 |
g4code/utility | src/Cleaner.php | Cleaner.get | public function get($variable, $default = '', $allowed = '', $escape = true)
{
// if this is an array or object, don't destroy it, just return
if(isset($variable) && (is_array($variable) || is_object($variable))) {
return $variable;
}
// now check if is set?
$variable = isset($variable) ? trim($variable) : $default;
// is in allowed range?
if(!empty($allowed) && is_array($allowed)) {
if(!in_array($variable, $allowed)) {
$variable = reset($allowed);
}
}
return $escape ? addslashes($variable) : $variable;
} | php | public function get($variable, $default = '', $allowed = '', $escape = true)
{
// if this is an array or object, don't destroy it, just return
if(isset($variable) && (is_array($variable) || is_object($variable))) {
return $variable;
}
// now check if is set?
$variable = isset($variable) ? trim($variable) : $default;
// is in allowed range?
if(!empty($allowed) && is_array($allowed)) {
if(!in_array($variable, $allowed)) {
$variable = reset($allowed);
}
}
return $escape ? addslashes($variable) : $variable;
} | [
"public",
"function",
"get",
"(",
"$",
"variable",
",",
"$",
"default",
"=",
"''",
",",
"$",
"allowed",
"=",
"''",
",",
"$",
"escape",
"=",
"true",
")",
"{",
"// if this is an array or object, don't destroy it, just return",
"if",
"(",
"isset",
"(",
"$",
"variable",
")",
"&&",
"(",
"is_array",
"(",
"$",
"variable",
")",
"||",
"is_object",
"(",
"$",
"variable",
")",
")",
")",
"{",
"return",
"$",
"variable",
";",
"}",
"// now check if is set?",
"$",
"variable",
"=",
"isset",
"(",
"$",
"variable",
")",
"?",
"trim",
"(",
"$",
"variable",
")",
":",
"$",
"default",
";",
"// is in allowed range?",
"if",
"(",
"!",
"empty",
"(",
"$",
"allowed",
")",
"&&",
"is_array",
"(",
"$",
"allowed",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"variable",
",",
"$",
"allowed",
")",
")",
"{",
"$",
"variable",
"=",
"reset",
"(",
"$",
"allowed",
")",
";",
"}",
"}",
"return",
"$",
"escape",
"?",
"addslashes",
"(",
"$",
"variable",
")",
":",
"$",
"variable",
";",
"}"
] | Takes variable and returns the same if is set otherwise returns $default
@param mixed $variable - variable
@param mixed $default - default value if variable not set
@param mixed $allowed - array of allowed values
@param bool $escape - escape quotes
@return mixed | [
"Takes",
"variable",
"and",
"returns",
"the",
"same",
"if",
"is",
"set",
"otherwise",
"returns",
"$default"
] | train | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L33-L51 |
g4code/utility | src/Cleaner.php | Cleaner.getHtml | public function getHtml($variable, $default = '', $allowed = "", $escape = true)
{
return (string) rawurldecode($this->get($variable, $default, $allowed, $escape));
} | php | public function getHtml($variable, $default = '', $allowed = "", $escape = true)
{
return (string) rawurldecode($this->get($variable, $default, $allowed, $escape));
} | [
"public",
"function",
"getHtml",
"(",
"$",
"variable",
",",
"$",
"default",
"=",
"''",
",",
"$",
"allowed",
"=",
"\"\"",
",",
"$",
"escape",
"=",
"true",
")",
"{",
"return",
"(",
"string",
")",
"rawurldecode",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"$",
"allowed",
",",
"$",
"escape",
")",
")",
";",
"}"
] | Same as _get, but it rawurldecodes the string
@param mixed $variable - variable
@param mixed $default - default value if variable not set
@param mixed $allowed - array of allowed values
@param bool $escape - escape quotes
@return string | [
"Same",
"as",
"_get",
"but",
"it",
"rawurldecodes",
"the",
"string"
] | train | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L62-L65 |
g4code/utility | src/Cleaner.php | Cleaner.getString | public function getString($variable, $default = '', $allowed = "", $escape = true)
{
return (string) strip_tags($this->getHtml($variable, $default, $allowed, $escape));
} | php | public function getString($variable, $default = '', $allowed = "", $escape = true)
{
return (string) strip_tags($this->getHtml($variable, $default, $allowed, $escape));
} | [
"public",
"function",
"getString",
"(",
"$",
"variable",
",",
"$",
"default",
"=",
"''",
",",
"$",
"allowed",
"=",
"\"\"",
",",
"$",
"escape",
"=",
"true",
")",
"{",
"return",
"(",
"string",
")",
"strip_tags",
"(",
"$",
"this",
"->",
"getHtml",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"$",
"allowed",
",",
"$",
"escape",
")",
")",
";",
"}"
] | Same as _getHtml, but it also strips tags
@param mixed $variable - variable
@param mixed $default - default value if variable not set
@param mixed $allowed - array of allowed values
@param bool $escape - escape quotes
@return string | [
"Same",
"as",
"_getHtml",
"but",
"it",
"also",
"strips",
"tags"
] | train | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L76-L79 |
g4code/utility | src/Cleaner.php | Cleaner.getBool | public function getBool($variable, $default = false)
{
return (bool) $this->get($variable, $default, array(false, true), false);
} | php | public function getBool($variable, $default = false)
{
return (bool) $this->get($variable, $default, array(false, true), false);
} | [
"public",
"function",
"getBool",
"(",
"$",
"variable",
",",
"$",
"default",
"=",
"false",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"get",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"array",
"(",
"false",
",",
"true",
")",
",",
"false",
")",
";",
"}"
] | Same as _get but casts return value to bollean
@access public
@param mixed $variable - variable
@return bool | [
"Same",
"as",
"_get",
"but",
"casts",
"return",
"value",
"to",
"bollean"
] | train | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L116-L119 |
g4code/utility | src/Cleaner.php | Cleaner.escape | public function escape($variable, $default = "", $allowed = "", $paranoid = true)
{
$variable = $paranoid
? $this->getString($variable, $default, $allowed, false)
: $this->get($variable, $default, $allowed, false);
if(!DI::has('db')) {
throw new \Exception('DB object not set');
}
$db = DI::get('db');
// @todo: should be something like this for mysql
// return $db->getConnection()->real_escape_string($variable);
return $db->realEscape($variable);
} | php | public function escape($variable, $default = "", $allowed = "", $paranoid = true)
{
$variable = $paranoid
? $this->getString($variable, $default, $allowed, false)
: $this->get($variable, $default, $allowed, false);
if(!DI::has('db')) {
throw new \Exception('DB object not set');
}
$db = DI::get('db');
// @todo: should be something like this for mysql
// return $db->getConnection()->real_escape_string($variable);
return $db->realEscape($variable);
} | [
"public",
"function",
"escape",
"(",
"$",
"variable",
",",
"$",
"default",
"=",
"\"\"",
",",
"$",
"allowed",
"=",
"\"\"",
",",
"$",
"paranoid",
"=",
"true",
")",
"{",
"$",
"variable",
"=",
"$",
"paranoid",
"?",
"$",
"this",
"->",
"getString",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"$",
"allowed",
",",
"false",
")",
":",
"$",
"this",
"->",
"get",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"$",
"allowed",
",",
"false",
")",
";",
"if",
"(",
"!",
"DI",
"::",
"has",
"(",
"'db'",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'DB object not set'",
")",
";",
"}",
"$",
"db",
"=",
"DI",
"::",
"get",
"(",
"'db'",
")",
";",
"// @todo: should be something like this for mysql",
"// return $db->getConnection()->real_escape_string($variable);",
"return",
"$",
"db",
"->",
"realEscape",
"(",
"$",
"variable",
")",
";",
"}"
] | Takes variable and returns the same if is set otherwise returns $default
escapes it to use with mysql
@access public
@param mixed $variable - variable
@param mixed $default - default value if variable not set
@param mixed $allowed - array of allowed values
@param bool $paranoid - if paranoid, strip tags
@return mixed | [
"Takes",
"variable",
"and",
"returns",
"the",
"same",
"if",
"is",
"set",
"otherwise",
"returns",
"$default",
"escapes",
"it",
"to",
"use",
"with",
"mysql"
] | train | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L132-L146 |
g4code/utility | src/Cleaner.php | Cleaner.escapeHTML | public function escapeHTML($variable, $default = "", $allowed = "", $paranoid = true)
{
$variable = $paranoid
? $this->htmlEncode(rawurldecode($this->get($variable, $default, $allowed, false)), ENT_NOQUOTES, 'UTF-8', false)
: $this->get($variable, $default, $allowed, false);
if(!DI::has('db')) {
throw new \Exception('DB object not set');
}
$db = DI::get('db');
// @todo: should be something like this for mysql
// return $db->getConnection()->real_escape_string($variable);
return $db->realEscape($variable);
} | php | public function escapeHTML($variable, $default = "", $allowed = "", $paranoid = true)
{
$variable = $paranoid
? $this->htmlEncode(rawurldecode($this->get($variable, $default, $allowed, false)), ENT_NOQUOTES, 'UTF-8', false)
: $this->get($variable, $default, $allowed, false);
if(!DI::has('db')) {
throw new \Exception('DB object not set');
}
$db = DI::get('db');
// @todo: should be something like this for mysql
// return $db->getConnection()->real_escape_string($variable);
return $db->realEscape($variable);
} | [
"public",
"function",
"escapeHTML",
"(",
"$",
"variable",
",",
"$",
"default",
"=",
"\"\"",
",",
"$",
"allowed",
"=",
"\"\"",
",",
"$",
"paranoid",
"=",
"true",
")",
"{",
"$",
"variable",
"=",
"$",
"paranoid",
"?",
"$",
"this",
"->",
"htmlEncode",
"(",
"rawurldecode",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"$",
"allowed",
",",
"false",
")",
")",
",",
"ENT_NOQUOTES",
",",
"'UTF-8'",
",",
"false",
")",
":",
"$",
"this",
"->",
"get",
"(",
"$",
"variable",
",",
"$",
"default",
",",
"$",
"allowed",
",",
"false",
")",
";",
"if",
"(",
"!",
"DI",
"::",
"has",
"(",
"'db'",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'DB object not set'",
")",
";",
"}",
"$",
"db",
"=",
"DI",
"::",
"get",
"(",
"'db'",
")",
";",
"// @todo: should be something like this for mysql",
"// return $db->getConnection()->real_escape_string($variable);",
"return",
"$",
"db",
"->",
"realEscape",
"(",
"$",
"variable",
")",
";",
"}"
] | Takes variable and returns the same if is set otherwise returns $default
escapes it to use with mysql
@access public
@param mixed $variable - variable
@param mixed $default - default value if variable not set
@param mixed $allowed - array of allowed values
@param bool $paranoid - if paranoid, strip tags
@return mixed | [
"Takes",
"variable",
"and",
"returns",
"the",
"same",
"if",
"is",
"set",
"otherwise",
"returns",
"$default",
"escapes",
"it",
"to",
"use",
"with",
"mysql"
] | train | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L159-L173 |
g4code/utility | src/Cleaner.php | Cleaner.htmlEncode | public function htmlEncode($string, $quoteStyle = ENT_QUOTES, $charset = 'UTF-8', $doubleEncode = false)
{
return htmlspecialchars((string) $string, $quoteStyle, $charset, $doubleEncode);
} | php | public function htmlEncode($string, $quoteStyle = ENT_QUOTES, $charset = 'UTF-8', $doubleEncode = false)
{
return htmlspecialchars((string) $string, $quoteStyle, $charset, $doubleEncode);
} | [
"public",
"function",
"htmlEncode",
"(",
"$",
"string",
",",
"$",
"quoteStyle",
"=",
"ENT_QUOTES",
",",
"$",
"charset",
"=",
"'UTF-8'",
",",
"$",
"doubleEncode",
"=",
"false",
")",
"{",
"return",
"htmlspecialchars",
"(",
"(",
"string",
")",
"$",
"string",
",",
"$",
"quoteStyle",
",",
"$",
"charset",
",",
"$",
"doubleEncode",
")",
";",
"}"
] | Replacement for htmlspecialchars
@param string $string
@param int $quoteStyle default ENT_QUOTES
@param string $charset default UTF-8
@param bool $doubleEncode - when double_encode is turned off PHP will not encode existing html entities
@return string | [
"Replacement",
"for",
"htmlspecialchars"
] | train | https://github.com/g4code/utility/blob/e0c9138aab61a53d88f32bb66201b075f3f44f1d/src/Cleaner.php#L184-L187 |
stubbles/stubbles-dbal | src/main/php/Database.php | Database.query | public function query(string $sql, array $values = []): int
{
return $this->dbConnection->prepare($sql)
->execute($values)
->count();
} | php | public function query(string $sql, array $values = []): int
{
return $this->dbConnection->prepare($sql)
->execute($values)
->count();
} | [
"public",
"function",
"query",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
")",
":",
"int",
"{",
"return",
"$",
"this",
"->",
"dbConnection",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"values",
")",
"->",
"count",
"(",
")",
";",
"}"
] | sends a query to the database and returns amount of affected records
@param string $sql
@param array $values
@return int
@since 3.1.0 | [
"sends",
"a",
"query",
"to",
"the",
"database",
"and",
"returns",
"amount",
"of",
"affected",
"records"
] | train | https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L57-L62 |
stubbles/stubbles-dbal | src/main/php/Database.php | Database.fetchOne | public function fetchOne(string $sql, array $values = [], int $columnNumber = 0): string
{
return $this->dbConnection->prepare($sql)
->execute($values)
->fetchOne($columnNumber);
} | php | public function fetchOne(string $sql, array $values = [], int $columnNumber = 0): string
{
return $this->dbConnection->prepare($sql)
->execute($values)
->fetchOne($columnNumber);
} | [
"public",
"function",
"fetchOne",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"int",
"$",
"columnNumber",
"=",
"0",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"dbConnection",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"values",
")",
"->",
"fetchOne",
"(",
"$",
"columnNumber",
")",
";",
"}"
] | fetch single value from a result set
@param string $sql sql query to fetch data with
@param array $values map of values in case $sql contains a prepared statement
@param int $columnNumber optional the column number to fetch, default is first column
@return string
@throws \stubbles\db\DatabaseException
@since 3.1.0 | [
"fetch",
"single",
"value",
"from",
"a",
"result",
"set"
] | train | https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L74-L79 |
stubbles/stubbles-dbal | src/main/php/Database.php | Database.fetchAll | public function fetchAll(
string $sql,
array $values = [],
int $fetchMode = null,
array $driverOptions = []
): Sequence {
return Sequence::of(new QueryResultIterator(
$this->dbConnection->prepare($sql)->execute($values),
$fetchMode,
$driverOptions
));
} | php | public function fetchAll(
string $sql,
array $values = [],
int $fetchMode = null,
array $driverOptions = []
): Sequence {
return Sequence::of(new QueryResultIterator(
$this->dbConnection->prepare($sql)->execute($values),
$fetchMode,
$driverOptions
));
} | [
"public",
"function",
"fetchAll",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"int",
"$",
"fetchMode",
"=",
"null",
",",
"array",
"$",
"driverOptions",
"=",
"[",
"]",
")",
":",
"Sequence",
"{",
"return",
"Sequence",
"::",
"of",
"(",
"new",
"QueryResultIterator",
"(",
"$",
"this",
"->",
"dbConnection",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"values",
")",
",",
"$",
"fetchMode",
",",
"$",
"driverOptions",
")",
")",
";",
"}"
] | return all result rows for given sql query
Allows to fetch all results for a query at once.
<code>
$blockedUsers = $database->fetchAll('SELECT * FROM users WHERE status = "blocked"');
</code>
Now $blockedUsers contains all rows from the query.
@param string $sql sql query to fetch data with
@param array $values map of values in case $sql contains a prepared statement
@param int $fetchMode optional the mode to use for fetching the data
@param array $driverOptions optional driver specific arguments
@return \stubbles\sequence\Sequence | [
"return",
"all",
"result",
"rows",
"for",
"given",
"sql",
"query"
] | train | https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L96-L107 |
stubbles/stubbles-dbal | src/main/php/Database.php | Database.fetchRow | public function fetchRow(
string $sql,
array $values = [],
int $fetchMode = null,
array $driverOptions = []
): array {
return $this->dbConnection->prepare($sql)
->execute($values)
->fetch($fetchMode, $driverOptions);
} | php | public function fetchRow(
string $sql,
array $values = [],
int $fetchMode = null,
array $driverOptions = []
): array {
return $this->dbConnection->prepare($sql)
->execute($values)
->fetch($fetchMode, $driverOptions);
} | [
"public",
"function",
"fetchRow",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"int",
"$",
"fetchMode",
"=",
"null",
",",
"array",
"$",
"driverOptions",
"=",
"[",
"]",
")",
":",
"array",
"{",
"return",
"$",
"this",
"->",
"dbConnection",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"values",
")",
"->",
"fetch",
"(",
"$",
"fetchMode",
",",
"$",
"driverOptions",
")",
";",
"}"
] | returns first result row for given sql query
@param string $sql sql query to fetch data with
@param array $values map of values in case $sql contains a prepared statement
@param int $fetchMode optional the mode to use for fetching the data
@param array $driverOptions optional driver specific arguments
@return array
@since 2.4.0 | [
"returns",
"first",
"result",
"row",
"for",
"given",
"sql",
"query"
] | train | https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L119-L128 |
stubbles/stubbles-dbal | src/main/php/Database.php | Database.fetchColumn | public function fetchColumn(
string $sql,
array $values = [],
int $columnIndex = 0
): Sequence {
return $this->fetchAll(
$sql,
$values,
\PDO::FETCH_COLUMN,
['columnIndex' => $columnIndex]
);
} | php | public function fetchColumn(
string $sql,
array $values = [],
int $columnIndex = 0
): Sequence {
return $this->fetchAll(
$sql,
$values,
\PDO::FETCH_COLUMN,
['columnIndex' => $columnIndex]
);
} | [
"public",
"function",
"fetchColumn",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"int",
"$",
"columnIndex",
"=",
"0",
")",
":",
"Sequence",
"{",
"return",
"$",
"this",
"->",
"fetchAll",
"(",
"$",
"sql",
",",
"$",
"values",
",",
"\\",
"PDO",
"::",
"FETCH_COLUMN",
",",
"[",
"'columnIndex'",
"=>",
"$",
"columnIndex",
"]",
")",
";",
"}"
] | return a list with all rows from given result
Allows to map the result into a list of values from one single column:
<code>
$userNames = $database->fetchColumn('SELECT username FROM users WHERE status = "blocked"');
</code>
@param string $sql sql query to fetch data with
@param array $values map of values in case $sql contains a prepared statement
@param int $columnIndex number of column to fetch
@return \stubbles\sequence\Sequence | [
"return",
"a",
"list",
"with",
"all",
"rows",
"from",
"given",
"result"
] | train | https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Database.php#L143-L154 |
Innmind/Math | src/Regression/LinearRegression.php | LinearRegression.compute | private function compute(Dataset $data): array
{
$dimension = $data->dimension()->rows();
$elements = $dimension->value();
$x = $data->abscissas()->toArray();
$y = $data->ordinates()->toArray();
$xSum = $data->abscissas()->sum();
$ySum = $data->ordinates()->sum();
$xxSum = new Integer(0);
$xySum = new Integer(0);
for ($i = 0; $i < $elements; $i++) {
$xySum = add($xySum, multiply($x[$i], $y[$i]));
$xxSum = add($xxSum, multiply($x[$i], $x[$i]));
}
$slope = divide(
subtract(
$dimension->multiplyBy($xySum),
$xSum->multiplyBy($ySum)
),
subtract(
$dimension->multiplyBy($xxSum),
$xSum->power(new Integer(2))
)
);
$intercept = divide(
subtract(
$ySum,
$slope->multiplyBy($xSum)
),
$dimension
);
return [$slope, $intercept];
} | php | private function compute(Dataset $data): array
{
$dimension = $data->dimension()->rows();
$elements = $dimension->value();
$x = $data->abscissas()->toArray();
$y = $data->ordinates()->toArray();
$xSum = $data->abscissas()->sum();
$ySum = $data->ordinates()->sum();
$xxSum = new Integer(0);
$xySum = new Integer(0);
for ($i = 0; $i < $elements; $i++) {
$xySum = add($xySum, multiply($x[$i], $y[$i]));
$xxSum = add($xxSum, multiply($x[$i], $x[$i]));
}
$slope = divide(
subtract(
$dimension->multiplyBy($xySum),
$xSum->multiplyBy($ySum)
),
subtract(
$dimension->multiplyBy($xxSum),
$xSum->power(new Integer(2))
)
);
$intercept = divide(
subtract(
$ySum,
$slope->multiplyBy($xSum)
),
$dimension
);
return [$slope, $intercept];
} | [
"private",
"function",
"compute",
"(",
"Dataset",
"$",
"data",
")",
":",
"array",
"{",
"$",
"dimension",
"=",
"$",
"data",
"->",
"dimension",
"(",
")",
"->",
"rows",
"(",
")",
";",
"$",
"elements",
"=",
"$",
"dimension",
"->",
"value",
"(",
")",
";",
"$",
"x",
"=",
"$",
"data",
"->",
"abscissas",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"y",
"=",
"$",
"data",
"->",
"ordinates",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"xSum",
"=",
"$",
"data",
"->",
"abscissas",
"(",
")",
"->",
"sum",
"(",
")",
";",
"$",
"ySum",
"=",
"$",
"data",
"->",
"ordinates",
"(",
")",
"->",
"sum",
"(",
")",
";",
"$",
"xxSum",
"=",
"new",
"Integer",
"(",
"0",
")",
";",
"$",
"xySum",
"=",
"new",
"Integer",
"(",
"0",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"elements",
";",
"$",
"i",
"++",
")",
"{",
"$",
"xySum",
"=",
"add",
"(",
"$",
"xySum",
",",
"multiply",
"(",
"$",
"x",
"[",
"$",
"i",
"]",
",",
"$",
"y",
"[",
"$",
"i",
"]",
")",
")",
";",
"$",
"xxSum",
"=",
"add",
"(",
"$",
"xxSum",
",",
"multiply",
"(",
"$",
"x",
"[",
"$",
"i",
"]",
",",
"$",
"x",
"[",
"$",
"i",
"]",
")",
")",
";",
"}",
"$",
"slope",
"=",
"divide",
"(",
"subtract",
"(",
"$",
"dimension",
"->",
"multiplyBy",
"(",
"$",
"xySum",
")",
",",
"$",
"xSum",
"->",
"multiplyBy",
"(",
"$",
"ySum",
")",
")",
",",
"subtract",
"(",
"$",
"dimension",
"->",
"multiplyBy",
"(",
"$",
"xxSum",
")",
",",
"$",
"xSum",
"->",
"power",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
")",
")",
";",
"$",
"intercept",
"=",
"divide",
"(",
"subtract",
"(",
"$",
"ySum",
",",
"$",
"slope",
"->",
"multiplyBy",
"(",
"$",
"xSum",
")",
")",
",",
"$",
"dimension",
")",
";",
"return",
"[",
"$",
"slope",
",",
"$",
"intercept",
"]",
";",
"}"
] | Determine the slope and intercept for the given dataset
@see https://richardathome.wordpress.com/2006/01/25/a-php-linear-regression-function/
@param Dataset $data
@return array | [
"Determine",
"the",
"slope",
"and",
"intercept",
"for",
"the",
"given",
"dataset"
] | train | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Regression/LinearRegression.php#L80-L116 |
drdplusinfo/drdplus-skills | DrdPlus/Skills/Skills.php | Skills.getMalusToFightNumberWithWeaponlike | public function getMalusToFightNumberWithWeaponlike(
WeaponlikeCode $weaponOrShieldForAttack,
Tables $tables,
$usesTwoWeapons
): int
{
if ($weaponOrShieldForAttack->isProjectile()) {
return 0;
}
if ($weaponOrShieldForAttack->isMelee() || $weaponOrShieldForAttack->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToFightNumberWithWeaponlike($weaponOrShieldForAttack, $tables, $usesTwoWeapons);
}
if ($weaponOrShieldForAttack->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToFightNumberWithShootingWeapon(
$weaponOrShieldForAttack->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
throw new Exceptions\UnknownTypeOfWeapon($weaponOrShieldForAttack);
} | php | public function getMalusToFightNumberWithWeaponlike(
WeaponlikeCode $weaponOrShieldForAttack,
Tables $tables,
$usesTwoWeapons
): int
{
if ($weaponOrShieldForAttack->isProjectile()) {
return 0;
}
if ($weaponOrShieldForAttack->isMelee() || $weaponOrShieldForAttack->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToFightNumberWithWeaponlike($weaponOrShieldForAttack, $tables, $usesTwoWeapons);
}
if ($weaponOrShieldForAttack->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToFightNumberWithShootingWeapon(
$weaponOrShieldForAttack->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
throw new Exceptions\UnknownTypeOfWeapon($weaponOrShieldForAttack);
} | [
"public",
"function",
"getMalusToFightNumberWithWeaponlike",
"(",
"WeaponlikeCode",
"$",
"weaponOrShieldForAttack",
",",
"Tables",
"$",
"tables",
",",
"$",
"usesTwoWeapons",
")",
":",
"int",
"{",
"if",
"(",
"$",
"weaponOrShieldForAttack",
"->",
"isProjectile",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"weaponOrShieldForAttack",
"->",
"isMelee",
"(",
")",
"||",
"$",
"weaponOrShieldForAttack",
"->",
"isThrowingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getPhysicalSkills",
"(",
")",
"->",
"getMalusToFightNumberWithWeaponlike",
"(",
"$",
"weaponOrShieldForAttack",
",",
"$",
"tables",
",",
"$",
"usesTwoWeapons",
")",
";",
"}",
"if",
"(",
"$",
"weaponOrShieldForAttack",
"->",
"isShootingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getCombinedSkills",
"(",
")",
"->",
"getMalusToFightNumberWithShootingWeapon",
"(",
"$",
"weaponOrShieldForAttack",
"->",
"convertToRangedWeaponCodeEquivalent",
"(",
")",
",",
"$",
"tables",
")",
";",
"}",
"throw",
"new",
"Exceptions",
"\\",
"UnknownTypeOfWeapon",
"(",
"$",
"weaponOrShieldForAttack",
")",
";",
"}"
] | Note about SHIELD: shield is considered as a weapon and therefore zero skill is used for it (rare
FightWithShield respectively). If you want fight number for shield as a PROTECTIVE item, use @see
getMalusToFightNumberWithProtective instead. If yu are using two weapons, you will be punished for imperfect
fight-with-two-weapons skill as well.
@param WeaponlikeCode $weaponOrShieldForAttack
@param Tables $tables
@param bool $usesTwoWeapons
@return int
@throws \DrdPlus\Skills\Exceptions\UnknownTypeOfWeapon | [
"Note",
"about",
"SHIELD",
":",
"shield",
"is",
"considered",
"as",
"a",
"weapon",
"and",
"therefore",
"zero",
"skill",
"is",
"used",
"for",
"it",
"(",
"rare",
"FightWithShield",
"respectively",
")",
".",
"If",
"you",
"want",
"fight",
"number",
"for",
"shield",
"as",
"a",
"PROTECTIVE",
"item",
"use",
"@see",
"getMalusToFightNumberWithProtective",
"instead",
".",
"If",
"yu",
"are",
"using",
"two",
"weapons",
"you",
"will",
"be",
"punished",
"for",
"imperfect",
"fight",
"-",
"with",
"-",
"two",
"-",
"weapons",
"skill",
"as",
"well",
"."
] | train | https://github.com/drdplusinfo/drdplus-skills/blob/9ae6ecdbaadf594d6572ec0c190fc13572c0a53f/DrdPlus/Skills/Skills.php#L571-L590 |
drdplusinfo/drdplus-skills | DrdPlus/Skills/Skills.php | Skills.getMalusToAttackNumberWithWeaponlike | public function getMalusToAttackNumberWithWeaponlike(
WeaponlikeCode $weaponlikeCode,
Tables $tables,
$fightsWithTwoWeapons
): int
{
if ($weaponlikeCode->isProjectile()) {
return 0;
}
if ($weaponlikeCode->isMelee() || $weaponlikeCode->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToAttackNumberWithWeaponlike($weaponlikeCode, $tables, $fightsWithTwoWeapons);
}
if ($weaponlikeCode->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToAttackNumberWithShootingWeapon(
$weaponlikeCode->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
throw new Exceptions\UnknownTypeOfWeapon($weaponlikeCode);
} | php | public function getMalusToAttackNumberWithWeaponlike(
WeaponlikeCode $weaponlikeCode,
Tables $tables,
$fightsWithTwoWeapons
): int
{
if ($weaponlikeCode->isProjectile()) {
return 0;
}
if ($weaponlikeCode->isMelee() || $weaponlikeCode->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToAttackNumberWithWeaponlike($weaponlikeCode, $tables, $fightsWithTwoWeapons);
}
if ($weaponlikeCode->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToAttackNumberWithShootingWeapon(
$weaponlikeCode->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
throw new Exceptions\UnknownTypeOfWeapon($weaponlikeCode);
} | [
"public",
"function",
"getMalusToAttackNumberWithWeaponlike",
"(",
"WeaponlikeCode",
"$",
"weaponlikeCode",
",",
"Tables",
"$",
"tables",
",",
"$",
"fightsWithTwoWeapons",
")",
":",
"int",
"{",
"if",
"(",
"$",
"weaponlikeCode",
"->",
"isProjectile",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"weaponlikeCode",
"->",
"isMelee",
"(",
")",
"||",
"$",
"weaponlikeCode",
"->",
"isThrowingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getPhysicalSkills",
"(",
")",
"->",
"getMalusToAttackNumberWithWeaponlike",
"(",
"$",
"weaponlikeCode",
",",
"$",
"tables",
",",
"$",
"fightsWithTwoWeapons",
")",
";",
"}",
"if",
"(",
"$",
"weaponlikeCode",
"->",
"isShootingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getCombinedSkills",
"(",
")",
"->",
"getMalusToAttackNumberWithShootingWeapon",
"(",
"$",
"weaponlikeCode",
"->",
"convertToRangedWeaponCodeEquivalent",
"(",
")",
",",
"$",
"tables",
")",
";",
"}",
"throw",
"new",
"Exceptions",
"\\",
"UnknownTypeOfWeapon",
"(",
"$",
"weaponlikeCode",
")",
";",
"}"
] | Note about SHIELD: shield is considered as a weapon and therefore zero skill is used for it (rare
FightWithShield respectively). If you want to use shield as a PROTECTIVE item, there is no attack number malus
from that.
@param WeaponlikeCode $weaponlikeCode
@param Tables $tables
@param bool $fightsWithTwoWeapons
@return int
@throws \DrdPlus\Skills\Physical\Exceptions\PhysicalSkillsDoNotKnowHowToUseThatWeapon
@throws \DrdPlus\Skills\Combined\Exceptions\CombinedSkillsDoNotHowToUseThatWeapon
@throws \DrdPlus\Skills\Exceptions\UnknownTypeOfWeapon | [
"Note",
"about",
"SHIELD",
":",
"shield",
"is",
"considered",
"as",
"a",
"weapon",
"and",
"therefore",
"zero",
"skill",
"is",
"used",
"for",
"it",
"(",
"rare",
"FightWithShield",
"respectively",
")",
".",
"If",
"you",
"want",
"to",
"use",
"shield",
"as",
"a",
"PROTECTIVE",
"item",
"there",
"is",
"no",
"attack",
"number",
"malus",
"from",
"that",
"."
] | train | https://github.com/drdplusinfo/drdplus-skills/blob/9ae6ecdbaadf594d6572ec0c190fc13572c0a53f/DrdPlus/Skills/Skills.php#L619-L638 |
drdplusinfo/drdplus-skills | DrdPlus/Skills/Skills.php | Skills.getMalusToCoverWithWeapon | public function getMalusToCoverWithWeapon(WeaponCode $weaponCode, Tables $tables, $fightsWithTwoWeapons): int
{
if ($weaponCode->isProjectile()) {
return 0;
}
if ($weaponCode->isMelee() || $weaponCode->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToCoverWithWeapon($weaponCode, $tables, $fightsWithTwoWeapons);
}
if ($weaponCode->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToCoverWithShootingWeapon(
$weaponCode->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
throw new Exceptions\UnknownTypeOfWeapon($weaponCode);
} | php | public function getMalusToCoverWithWeapon(WeaponCode $weaponCode, Tables $tables, $fightsWithTwoWeapons): int
{
if ($weaponCode->isProjectile()) {
return 0;
}
if ($weaponCode->isMelee() || $weaponCode->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToCoverWithWeapon($weaponCode, $tables, $fightsWithTwoWeapons);
}
if ($weaponCode->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToCoverWithShootingWeapon(
$weaponCode->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
throw new Exceptions\UnknownTypeOfWeapon($weaponCode);
} | [
"public",
"function",
"getMalusToCoverWithWeapon",
"(",
"WeaponCode",
"$",
"weaponCode",
",",
"Tables",
"$",
"tables",
",",
"$",
"fightsWithTwoWeapons",
")",
":",
"int",
"{",
"if",
"(",
"$",
"weaponCode",
"->",
"isProjectile",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"weaponCode",
"->",
"isMelee",
"(",
")",
"||",
"$",
"weaponCode",
"->",
"isThrowingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getPhysicalSkills",
"(",
")",
"->",
"getMalusToCoverWithWeapon",
"(",
"$",
"weaponCode",
",",
"$",
"tables",
",",
"$",
"fightsWithTwoWeapons",
")",
";",
"}",
"if",
"(",
"$",
"weaponCode",
"->",
"isShootingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getCombinedSkills",
"(",
")",
"->",
"getMalusToCoverWithShootingWeapon",
"(",
"$",
"weaponCode",
"->",
"convertToRangedWeaponCodeEquivalent",
"(",
")",
",",
"$",
"tables",
")",
";",
"}",
"throw",
"new",
"Exceptions",
"\\",
"UnknownTypeOfWeapon",
"(",
"$",
"weaponCode",
")",
";",
"}"
] | Usable both for weapons and shields, but SHIELD as "weaponlike" means for attacking - for shield standard usage
as a protective armament @see getMalusToCoverWithShield
@param WeaponCode $weaponCode
@param Tables $tables
@param bool $fightsWithTwoWeapons
@return int
@throws Exceptions\UnknownTypeOfWeapon | [
"Usable",
"both",
"for",
"weapons",
"and",
"shields",
"but",
"SHIELD",
"as",
"weaponlike",
"means",
"for",
"attacking",
"-",
"for",
"shield",
"standard",
"usage",
"as",
"a",
"protective",
"armament",
"@see",
"getMalusToCoverWithShield"
] | train | https://github.com/drdplusinfo/drdplus-skills/blob/9ae6ecdbaadf594d6572ec0c190fc13572c0a53f/DrdPlus/Skills/Skills.php#L650-L665 |
drdplusinfo/drdplus-skills | DrdPlus/Skills/Skills.php | Skills.getMalusToBaseOfWoundsWithWeaponlike | public function getMalusToBaseOfWoundsWithWeaponlike(
WeaponlikeCode $weaponlikeCode,
Tables $tables,
bool $fightsWithTwoWeapons
): int
{
if ($weaponlikeCode->isMelee() || $weaponlikeCode->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToBaseOfWoundsWithWeaponlike($weaponlikeCode, $tables, $fightsWithTwoWeapons);
}
if ($weaponlikeCode->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToBaseOfWoundsWithShootingWeapon(
$weaponlikeCode->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
if ($weaponlikeCode->isProjectile()) {
return 0;
}
throw new Exceptions\UnknownTypeOfWeapon($weaponlikeCode);
} | php | public function getMalusToBaseOfWoundsWithWeaponlike(
WeaponlikeCode $weaponlikeCode,
Tables $tables,
bool $fightsWithTwoWeapons
): int
{
if ($weaponlikeCode->isMelee() || $weaponlikeCode->isThrowingWeapon()) {
return $this->getPhysicalSkills()->getMalusToBaseOfWoundsWithWeaponlike($weaponlikeCode, $tables, $fightsWithTwoWeapons);
}
if ($weaponlikeCode->isShootingWeapon()) {
return $this->getCombinedSkills()->getMalusToBaseOfWoundsWithShootingWeapon(
$weaponlikeCode->convertToRangedWeaponCodeEquivalent(),
$tables
);
}
if ($weaponlikeCode->isProjectile()) {
return 0;
}
throw new Exceptions\UnknownTypeOfWeapon($weaponlikeCode);
} | [
"public",
"function",
"getMalusToBaseOfWoundsWithWeaponlike",
"(",
"WeaponlikeCode",
"$",
"weaponlikeCode",
",",
"Tables",
"$",
"tables",
",",
"bool",
"$",
"fightsWithTwoWeapons",
")",
":",
"int",
"{",
"if",
"(",
"$",
"weaponlikeCode",
"->",
"isMelee",
"(",
")",
"||",
"$",
"weaponlikeCode",
"->",
"isThrowingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getPhysicalSkills",
"(",
")",
"->",
"getMalusToBaseOfWoundsWithWeaponlike",
"(",
"$",
"weaponlikeCode",
",",
"$",
"tables",
",",
"$",
"fightsWithTwoWeapons",
")",
";",
"}",
"if",
"(",
"$",
"weaponlikeCode",
"->",
"isShootingWeapon",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getCombinedSkills",
"(",
")",
"->",
"getMalusToBaseOfWoundsWithShootingWeapon",
"(",
"$",
"weaponlikeCode",
"->",
"convertToRangedWeaponCodeEquivalent",
"(",
")",
",",
"$",
"tables",
")",
";",
"}",
"if",
"(",
"$",
"weaponlikeCode",
"->",
"isProjectile",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"throw",
"new",
"Exceptions",
"\\",
"UnknownTypeOfWeapon",
"(",
"$",
"weaponlikeCode",
")",
";",
"}"
] | If you want to use shield as a PROTECTIVE item, there is no base of wounds malus from that.
@param WeaponlikeCode $weaponlikeCode
@param Tables $tables
@param bool $fightsWithTwoWeapons
@return int
@throws Exceptions\UnknownTypeOfWeapon | [
"If",
"you",
"want",
"to",
"use",
"shield",
"as",
"a",
"PROTECTIVE",
"item",
"there",
"is",
"no",
"base",
"of",
"wounds",
"malus",
"from",
"that",
"."
] | train | https://github.com/drdplusinfo/drdplus-skills/blob/9ae6ecdbaadf594d6572ec0c190fc13572c0a53f/DrdPlus/Skills/Skills.php#L685-L704 |
thomasez/BisonLabSakonninBundle | EventListener/SakonninFileListener.php | SakonninFileListener.preRemove | public function preRemove(EventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof SakonninFile) {
// VichUploader removes this property when it removes the file,
// alas I need to store it somehow.
$this->removes[] = $entity->getStoredAs();
}
} | php | public function preRemove(EventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof SakonninFile) {
// VichUploader removes this property when it removes the file,
// alas I need to store it somehow.
$this->removes[] = $entity->getStoredAs();
}
} | [
"public",
"function",
"preRemove",
"(",
"EventArgs",
"$",
"args",
")",
"{",
"$",
"entity",
"=",
"$",
"args",
"->",
"getEntity",
"(",
")",
";",
"if",
"(",
"$",
"entity",
"instanceof",
"SakonninFile",
")",
"{",
"// VichUploader removes this property when it removes the file,",
"// alas I need to store it somehow.",
"$",
"this",
"->",
"removes",
"[",
"]",
"=",
"$",
"entity",
"->",
"getStoredAs",
"(",
")",
";",
"}",
"}"
] | Ensures a proxy will be usable in the postRemove.
@param EventArgs $event The event. | [
"Ensures",
"a",
"proxy",
"will",
"be",
"usable",
"in",
"the",
"postRemove",
"."
] | train | https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/EventListener/SakonninFileListener.php#L45-L53 |
NukaCode/Front-End-Bootstrap | src/NukaCode/Bootstrap/Filesystem/Less/Variables.php | Variables.updateEntry | public function updateEntry($package)
{
$this->verifyCommand($package);
$lines = file($this->less);
// Set the new colors
$lines[0] = '@bg: ' . $package['bg'] . ";\n";
$lines[1] = '@gray: ' . $package['gray'] . ";\n";
$lines[2] = '@brand-primary: ' . $package['primary'] . ";\n";
$lines[3] = '@brand-info: ' . $package['info'] . ";\n";
$lines[4] = '@brand-success: ' . $package['success'] . ";\n";
$lines[5] = '@brand-warning: ' . $package['warning'] . ";\n";
$lines[6] = '@brand-danger: ' . $package['danger'] . ";\n";
$lines[7] = '@menuColor: ' . $package['menu'] . ";\n";
$this->file->delete($this->less);
$this->file->put($this->less, implode($lines));
} | php | public function updateEntry($package)
{
$this->verifyCommand($package);
$lines = file($this->less);
// Set the new colors
$lines[0] = '@bg: ' . $package['bg'] . ";\n";
$lines[1] = '@gray: ' . $package['gray'] . ";\n";
$lines[2] = '@brand-primary: ' . $package['primary'] . ";\n";
$lines[3] = '@brand-info: ' . $package['info'] . ";\n";
$lines[4] = '@brand-success: ' . $package['success'] . ";\n";
$lines[5] = '@brand-warning: ' . $package['warning'] . ";\n";
$lines[6] = '@brand-danger: ' . $package['danger'] . ";\n";
$lines[7] = '@menuColor: ' . $package['menu'] . ";\n";
$this->file->delete($this->less);
$this->file->put($this->less, implode($lines));
} | [
"public",
"function",
"updateEntry",
"(",
"$",
"package",
")",
"{",
"$",
"this",
"->",
"verifyCommand",
"(",
"$",
"package",
")",
";",
"$",
"lines",
"=",
"file",
"(",
"$",
"this",
"->",
"less",
")",
";",
"// Set the new colors",
"$",
"lines",
"[",
"0",
"]",
"=",
"'@bg: '",
".",
"$",
"package",
"[",
"'bg'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"1",
"]",
"=",
"'@gray: '",
".",
"$",
"package",
"[",
"'gray'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"2",
"]",
"=",
"'@brand-primary: '",
".",
"$",
"package",
"[",
"'primary'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"3",
"]",
"=",
"'@brand-info: '",
".",
"$",
"package",
"[",
"'info'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"4",
"]",
"=",
"'@brand-success: '",
".",
"$",
"package",
"[",
"'success'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"5",
"]",
"=",
"'@brand-warning: '",
".",
"$",
"package",
"[",
"'warning'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"6",
"]",
"=",
"'@brand-danger: '",
".",
"$",
"package",
"[",
"'danger'",
"]",
".",
"\";\\n\"",
";",
"$",
"lines",
"[",
"7",
"]",
"=",
"'@menuColor: '",
".",
"$",
"package",
"[",
"'menu'",
"]",
".",
"\";\\n\"",
";",
"$",
"this",
"->",
"file",
"->",
"delete",
"(",
"$",
"this",
"->",
"less",
")",
";",
"$",
"this",
"->",
"file",
"->",
"put",
"(",
"$",
"this",
"->",
"less",
",",
"implode",
"(",
"$",
"lines",
")",
")",
";",
"}"
] | Update the colors.less file to persist the changes
@param $package | [
"Update",
"the",
"colors",
".",
"less",
"file",
"to",
"persist",
"the",
"changes"
] | train | https://github.com/NukaCode/Front-End-Bootstrap/blob/46c30fba4c77afb74ec4a4d70c43c9cffd464d6e/src/NukaCode/Bootstrap/Filesystem/Less/Variables.php#L36-L54 |
NukaCode/Front-End-Bootstrap | src/NukaCode/Bootstrap/Filesystem/Less/Variables.php | Variables.getEntry | public function getEntry()
{
$lines = file($this->colors);
foreach ($lines as $key => $line) {
if (trim($line) == '') {
unset($lines[$key]);
}
}
//ppd($lines);
$colorLocations = [
'bg' => [
'variable' => '@bg',
'title' => 'Background Color',
'line' => 0
],
'gray' => [
'variable' => '@gray',
'title' => 'Main Gray',
'line' => 1
],
'primary' => [
'variable' => '@brand-primary',
'title' => 'Primary Color',
'line' => 2
],
'info' => [
'variable' => '@brand-info',
'title' => 'Information Color',
'line' => 3
],
'success' => [
'variable' => '@brand-success',
'title' => 'Success Color',
'line' => 4
],
'warning' => [
'variable' => '@brand-warning',
'title' => 'Warning Color',
'line' => 5
],
'danger' => [
'variable' => '@brand-danger',
'title' => 'Error Color',
'line' => 6
],
'menu' => [
'variable' => '@menuColor',
'title' => 'Active Menu Link Color',
'line' => 7
],
];
foreach ($colorLocations as $key => $colorLocation) {
$colorLocations[$key]['hex'] = $this->findHex($lines, $colorLocation['variable'], $colorLocation['line']);
}
ppd($colorLocations);
$colors['bg'] = ['title' => 'Background Color', 'hex' => trim(substr(explode('@bg: ', $lines[0])[1], 0, -2))];
$colors['gray'] = ['title' => 'Main Gray', 'hex' => trim(substr(explode('@gray: ', $lines[1])[1], 0, -2))];
$colors['primary'] = ['title' => 'Primary Color', 'hex' => trim(substr(explode('@brand-primary: ', $lines[2])[1], 0, -2))];
$colors['info'] = ['title' => 'Information Color', 'hex' => trim(substr(explode('@brand-info: ', $lines[3])[1], 0, -2))];
$colors['success'] = ['title' => 'Success Color', 'hex' => trim(substr(explode('@brand-success: ', $lines[4])[1], 0, -2))];
$colors['warning'] = ['title' => 'Warning Color', 'hex' => trim(substr(explode('@brand-warning: ', $lines[5])[1], 0, -2))];
$colors['danger'] = ['title' => 'Error Color', 'hex' => trim(substr(explode('@brand-danger: ', $lines[6])[1], 0, -2))];
$colors['menu'] = ['title' => 'Active Menu Link Color', 'hex' => trim(substr(explode('@menuColor: ', $lines[7])[1], 0, -2))];
return $colors;
} | php | public function getEntry()
{
$lines = file($this->colors);
foreach ($lines as $key => $line) {
if (trim($line) == '') {
unset($lines[$key]);
}
}
//ppd($lines);
$colorLocations = [
'bg' => [
'variable' => '@bg',
'title' => 'Background Color',
'line' => 0
],
'gray' => [
'variable' => '@gray',
'title' => 'Main Gray',
'line' => 1
],
'primary' => [
'variable' => '@brand-primary',
'title' => 'Primary Color',
'line' => 2
],
'info' => [
'variable' => '@brand-info',
'title' => 'Information Color',
'line' => 3
],
'success' => [
'variable' => '@brand-success',
'title' => 'Success Color',
'line' => 4
],
'warning' => [
'variable' => '@brand-warning',
'title' => 'Warning Color',
'line' => 5
],
'danger' => [
'variable' => '@brand-danger',
'title' => 'Error Color',
'line' => 6
],
'menu' => [
'variable' => '@menuColor',
'title' => 'Active Menu Link Color',
'line' => 7
],
];
foreach ($colorLocations as $key => $colorLocation) {
$colorLocations[$key]['hex'] = $this->findHex($lines, $colorLocation['variable'], $colorLocation['line']);
}
ppd($colorLocations);
$colors['bg'] = ['title' => 'Background Color', 'hex' => trim(substr(explode('@bg: ', $lines[0])[1], 0, -2))];
$colors['gray'] = ['title' => 'Main Gray', 'hex' => trim(substr(explode('@gray: ', $lines[1])[1], 0, -2))];
$colors['primary'] = ['title' => 'Primary Color', 'hex' => trim(substr(explode('@brand-primary: ', $lines[2])[1], 0, -2))];
$colors['info'] = ['title' => 'Information Color', 'hex' => trim(substr(explode('@brand-info: ', $lines[3])[1], 0, -2))];
$colors['success'] = ['title' => 'Success Color', 'hex' => trim(substr(explode('@brand-success: ', $lines[4])[1], 0, -2))];
$colors['warning'] = ['title' => 'Warning Color', 'hex' => trim(substr(explode('@brand-warning: ', $lines[5])[1], 0, -2))];
$colors['danger'] = ['title' => 'Error Color', 'hex' => trim(substr(explode('@brand-danger: ', $lines[6])[1], 0, -2))];
$colors['menu'] = ['title' => 'Active Menu Link Color', 'hex' => trim(substr(explode('@menuColor: ', $lines[7])[1], 0, -2))];
return $colors;
} | [
"public",
"function",
"getEntry",
"(",
")",
"{",
"$",
"lines",
"=",
"file",
"(",
"$",
"this",
"->",
"colors",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"key",
"=>",
"$",
"line",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"line",
")",
"==",
"''",
")",
"{",
"unset",
"(",
"$",
"lines",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"//ppd($lines);",
"$",
"colorLocations",
"=",
"[",
"'bg'",
"=>",
"[",
"'variable'",
"=>",
"'@bg'",
",",
"'title'",
"=>",
"'Background Color'",
",",
"'line'",
"=>",
"0",
"]",
",",
"'gray'",
"=>",
"[",
"'variable'",
"=>",
"'@gray'",
",",
"'title'",
"=>",
"'Main Gray'",
",",
"'line'",
"=>",
"1",
"]",
",",
"'primary'",
"=>",
"[",
"'variable'",
"=>",
"'@brand-primary'",
",",
"'title'",
"=>",
"'Primary Color'",
",",
"'line'",
"=>",
"2",
"]",
",",
"'info'",
"=>",
"[",
"'variable'",
"=>",
"'@brand-info'",
",",
"'title'",
"=>",
"'Information Color'",
",",
"'line'",
"=>",
"3",
"]",
",",
"'success'",
"=>",
"[",
"'variable'",
"=>",
"'@brand-success'",
",",
"'title'",
"=>",
"'Success Color'",
",",
"'line'",
"=>",
"4",
"]",
",",
"'warning'",
"=>",
"[",
"'variable'",
"=>",
"'@brand-warning'",
",",
"'title'",
"=>",
"'Warning Color'",
",",
"'line'",
"=>",
"5",
"]",
",",
"'danger'",
"=>",
"[",
"'variable'",
"=>",
"'@brand-danger'",
",",
"'title'",
"=>",
"'Error Color'",
",",
"'line'",
"=>",
"6",
"]",
",",
"'menu'",
"=>",
"[",
"'variable'",
"=>",
"'@menuColor'",
",",
"'title'",
"=>",
"'Active Menu Link Color'",
",",
"'line'",
"=>",
"7",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"colorLocations",
"as",
"$",
"key",
"=>",
"$",
"colorLocation",
")",
"{",
"$",
"colorLocations",
"[",
"$",
"key",
"]",
"[",
"'hex'",
"]",
"=",
"$",
"this",
"->",
"findHex",
"(",
"$",
"lines",
",",
"$",
"colorLocation",
"[",
"'variable'",
"]",
",",
"$",
"colorLocation",
"[",
"'line'",
"]",
")",
";",
"}",
"ppd",
"(",
"$",
"colorLocations",
")",
";",
"$",
"colors",
"[",
"'bg'",
"]",
"=",
"[",
"'title'",
"=>",
"'Background Color'",
",",
"'hex'",
"=>",
"trim",
"(",
"substr",
"(",
"explode",
"(",
"'@bg: '",
",",
"$",
"lines",
"[",
"0",
"]",
")",
"[",
"1",
"]",
",",
"0",
",",
"-",
"2",
")",
")",
"]",
";",
"$",
"colors",
"[",
"'gray'",
"]",
"=",
"[",
"'title'",
"=>",
"'Main Gray'",
",",
"'hex'",
"=>",
"trim",
"(",
"substr",
"(",
"explode",
"(",
"'@gray: '",
",",
"$",
"lines",
"[",
"1",
"]",
")",
"[",
"1",
"]",
",",
"0",
",",
"-",
"2",
")",
")",
"]",
";",
"$",
"colors",
"[",
"'primary'",
"]",
"=",
"[",
"'title'",
"=>",
"'Primary Color'",
",",
"'hex'",
"=>",
"trim",
"(",
"substr",
"(",
"explode",
"(",
"'@brand-primary: '",
",",
"$",
"lines",
"[",
"2",
"]",
")",
"[",
"1",
"]",
",",
"0",
",",
"-",
"2",
")",
")",
"]",
";",
"$",
"colors",
"[",
"'info'",
"]",
"=",
"[",
"'title'",
"=>",
"'Information Color'",
",",
"'hex'",
"=>",
"trim",
"(",
"substr",
"(",
"explode",
"(",
"'@brand-info: '",
",",
"$",
"lines",
"[",
"3",
"]",
")",
"[",
"1",
"]",
",",
"0",
",",
"-",
"2",
")",
")",
"]",
";",
"$",
"colors",
"[",
"'success'",
"]",
"=",
"[",
"'title'",
"=>",
"'Success Color'",
",",
"'hex'",
"=>",
"trim",
"(",
"substr",
"(",
"explode",
"(",
"'@brand-success: '",
",",
"$",
"lines",
"[",
"4",
"]",
")",
"[",
"1",
"]",
",",
"0",
",",
"-",
"2",
")",
")",
"]",
";",
"$",
"colors",
"[",
"'warning'",
"]",
"=",
"[",
"'title'",
"=>",
"'Warning Color'",
",",
"'hex'",
"=>",
"trim",
"(",
"substr",
"(",
"explode",
"(",
"'@brand-warning: '",
",",
"$",
"lines",
"[",
"5",
"]",
")",
"[",
"1",
"]",
",",
"0",
",",
"-",
"2",
")",
")",
"]",
";",
"$",
"colors",
"[",
"'danger'",
"]",
"=",
"[",
"'title'",
"=>",
"'Error Color'",
",",
"'hex'",
"=>",
"trim",
"(",
"substr",
"(",
"explode",
"(",
"'@brand-danger: '",
",",
"$",
"lines",
"[",
"6",
"]",
")",
"[",
"1",
"]",
",",
"0",
",",
"-",
"2",
")",
")",
"]",
";",
"$",
"colors",
"[",
"'menu'",
"]",
"=",
"[",
"'title'",
"=>",
"'Active Menu Link Color'",
",",
"'hex'",
"=>",
"trim",
"(",
"substr",
"(",
"explode",
"(",
"'@menuColor: '",
",",
"$",
"lines",
"[",
"7",
"]",
")",
"[",
"1",
"]",
",",
"0",
",",
"-",
"2",
")",
")",
"]",
";",
"return",
"$",
"colors",
";",
"}"
] | Return the current color values for the site
@return array | [
"Return",
"the",
"current",
"color",
"values",
"for",
"the",
"site"
] | train | https://github.com/NukaCode/Front-End-Bootstrap/blob/46c30fba4c77afb74ec4a4d70c43c9cffd464d6e/src/NukaCode/Bootstrap/Filesystem/Less/Variables.php#L61-L132 |
hschletz/NADA | src/Link/Pdo.php | Pdo.query | public function query($statement, $params)
{
$statement = $this->_link->prepare($statement);
if ($statement === false) {
$this->_throw($this->_link);
}
if ($statement->execute($params) === false) {
$this->_throw($statement);
}
// Don't use fetchAll() because keys must be turned lowercase
$rowset = array();
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
foreach ($row as $column => $value) {
$output[strtolower($column)] = $value;
}
$rowset[] = $output;
}
return $rowset;
} | php | public function query($statement, $params)
{
$statement = $this->_link->prepare($statement);
if ($statement === false) {
$this->_throw($this->_link);
}
if ($statement->execute($params) === false) {
$this->_throw($statement);
}
// Don't use fetchAll() because keys must be turned lowercase
$rowset = array();
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
foreach ($row as $column => $value) {
$output[strtolower($column)] = $value;
}
$rowset[] = $output;
}
return $rowset;
} | [
"public",
"function",
"query",
"(",
"$",
"statement",
",",
"$",
"params",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"_link",
"->",
"prepare",
"(",
"$",
"statement",
")",
";",
"if",
"(",
"$",
"statement",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"_throw",
"(",
"$",
"this",
"->",
"_link",
")",
";",
"}",
"if",
"(",
"$",
"statement",
"->",
"execute",
"(",
"$",
"params",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"_throw",
"(",
"$",
"statement",
")",
";",
"}",
"// Don't use fetchAll() because keys must be turned lowercase",
"$",
"rowset",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"statement",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"foreach",
"(",
"$",
"row",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"output",
"[",
"strtolower",
"(",
"$",
"column",
")",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"rowset",
"[",
"]",
"=",
"$",
"output",
";",
"}",
"return",
"$",
"rowset",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Link/Pdo.php#L56-L76 |
hschletz/NADA | src/Link/Pdo.php | Pdo.exec | public function exec($statement, $params)
{
$statement = $this->_link->prepare($statement);
if ($statement === false) {
$this->_throw($this->_link);
}
if ($statement->execute($params) === false) {
$this->_throw($statement);
}
return $statement->rowCount();
} | php | public function exec($statement, $params)
{
$statement = $this->_link->prepare($statement);
if ($statement === false) {
$this->_throw($this->_link);
}
if ($statement->execute($params) === false) {
$this->_throw($statement);
}
return $statement->rowCount();
} | [
"public",
"function",
"exec",
"(",
"$",
"statement",
",",
"$",
"params",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"_link",
"->",
"prepare",
"(",
"$",
"statement",
")",
";",
"if",
"(",
"$",
"statement",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"_throw",
"(",
"$",
"this",
"->",
"_link",
")",
";",
"}",
"if",
"(",
"$",
"statement",
"->",
"execute",
"(",
"$",
"params",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"_throw",
"(",
"$",
"statement",
")",
";",
"}",
"return",
"$",
"statement",
"->",
"rowCount",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Link/Pdo.php#L79-L91 |
hschletz/NADA | src/Link/Pdo.php | Pdo.quoteValue | public function quoteValue($value, $datatype)
{
return $this->_link->quote((string)$value, \PDO::PARAM_STR);
} | php | public function quoteValue($value, $datatype)
{
return $this->_link->quote((string)$value, \PDO::PARAM_STR);
} | [
"public",
"function",
"quoteValue",
"(",
"$",
"value",
",",
"$",
"datatype",
")",
"{",
"return",
"$",
"this",
"->",
"_link",
"->",
"quote",
"(",
"(",
"string",
")",
"$",
"value",
",",
"\\",
"PDO",
"::",
"PARAM_STR",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Link/Pdo.php#L94-L97 |
hschletz/NADA | src/Link/Pdo.php | Pdo._throw | protected function _throw($object)
{
$error = $object->errorInfo();
throw new \RuntimeException(
sprintf(
'PDO operation returned SQLSTATE %s: Error %s (%s)',
$error[0],
$error[1],
$error[2]
)
);
} | php | protected function _throw($object)
{
$error = $object->errorInfo();
throw new \RuntimeException(
sprintf(
'PDO operation returned SQLSTATE %s: Error %s (%s)',
$error[0],
$error[1],
$error[2]
)
);
} | [
"protected",
"function",
"_throw",
"(",
"$",
"object",
")",
"{",
"$",
"error",
"=",
"$",
"object",
"->",
"errorInfo",
"(",
")",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'PDO operation returned SQLSTATE %s: Error %s (%s)'",
",",
"$",
"error",
"[",
"0",
"]",
",",
"$",
"error",
"[",
"1",
"]",
",",
"$",
"error",
"[",
"2",
"]",
")",
")",
";",
"}"
] | Throw exception with information from PDO's errorInfo()
@param object $object PDO object that caused the error
@throws \RuntimeException | [
"Throw",
"exception",
"with",
"information",
"from",
"PDO",
"s",
"errorInfo",
"()"
] | train | https://github.com/hschletz/NADA/blob/4ead798354089fd360f917ce64dd1432d5650df0/src/Link/Pdo.php#L104-L115 |
zhaoxianfang/tools | src/Symfony/Component/DependencyInjection/Compiler/Compiler.php | Compiler.getLoggingFormatter | public function getLoggingFormatter()
{
if (null === $this->loggingFormatter) {
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', __METHOD__), E_USER_DEPRECATED);
$this->loggingFormatter = new LoggingFormatter();
}
return $this->loggingFormatter;
} | php | public function getLoggingFormatter()
{
if (null === $this->loggingFormatter) {
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', __METHOD__), E_USER_DEPRECATED);
$this->loggingFormatter = new LoggingFormatter();
}
return $this->loggingFormatter;
} | [
"public",
"function",
"getLoggingFormatter",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"loggingFormatter",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.'",
",",
"__METHOD__",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"this",
"->",
"loggingFormatter",
"=",
"new",
"LoggingFormatter",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"loggingFormatter",
";",
"}"
] | Returns the logging formatter which can be used by compilation passes.
@return LoggingFormatter
@deprecated since version 3.3, to be removed in 4.0. Use the ContainerBuilder::log() method instead. | [
"Returns",
"the",
"logging",
"formatter",
"which",
"can",
"be",
"used",
"by",
"compilation",
"passes",
"."
] | train | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php#L62-L71 |
miaoxing/wechat | src/Controller/Admin/WechatQrcode.php | WechatQrcode.showDetailAction | public function showDetailAction($req)
{
$startTime = $req['startTime'] ?: date('Y-m-d', time() - 7 * 86400);
$endTime = $req['endTime'] ?: date('Y-m-d', time());
$daysLen = (int) ((strtotime($endTime) - strtotime($startTime)) / 86400);
// 1. 获取统计和每天的数据
$qrcode = wei()->weChatQrcode()->findOne(['sceneId' => $req['sceneId']]);
$sql1 = ', (select count(*) from wechatQrcodeLogs where appId=' . wei()->app->getId() .
' and wechatQrcodeId=' . $qrcode['id'] . ' and type=logType and createTime <= date_add(dateDay, interval 1 day)) as allCount';
$sql2 = ', (select count(distinct(userId)) from wechatQrcodeLogs where appId=' . wei()->app->getId() .
' and wechatQrcodeId=' . $qrcode['id'] . ' and type=logType and createTime <= date_add(dateDay, interval 1 day)) as allHeadCount';
$qrcodeLogs = wei()->wechatQrcodeLog()
->select('DATE_FORMAT(createTime,"%Y-%m-%d") as dateDay, type as logType, count(*) as addCount, count(distinct(userId)) as addHeadCount' . $sql1 . $sql2)
->curApp()
->andWhere(['wechatQrcodeId' => $qrcode['id']])
->andWhere('createTime >= ? and createTime < ?', [$startTime, $endTime])
->groupBy('dateDay,logType')
->desc('id')
->fetchAll();
// 2. 初始化数据
$details = [];
for ($i = 1; $i <= $daysLen; ++$i) {
$day = date('Y-m-d', strtotime($endTime) - $i * 86400);
$details[$day] = [
'statDate' => $day,
'addValidCount' => 0,
'allValidCount' => 0,
'addTotalHeadCount' => 0,
'allTotalHeadCount' => 0,
'addCancelHeadCount' => 0,
'allCancelHeadCount' => 0,
'addTotalCount' => 0,
'allTotalCount' => 0,
'addCancelCount' => 0,
'allCancelCount' => 0,
];
}
// 3. 统计数据
foreach ($qrcodeLogs as $qrcodeLog) {
if ($qrcodeLog['logType'] == 1) { // 关注
$details[$qrcodeLog['dateDay']]['addTotalCount'] = $qrcodeLog['addCount'];
$details[$qrcodeLog['dateDay']]['allTotalCount'] = $qrcodeLog['allCount'];
$details[$qrcodeLog['dateDay']]['addTotalHeadCount'] = $qrcodeLog['addHeadCount'];
$details[$qrcodeLog['dateDay']]['allTotalHeadCount'] = $qrcodeLog['allHeadCount'];
$details[$qrcodeLog['dateDay']]['addValidCount'] += $qrcodeLog['addCount'];
$details[$qrcodeLog['dateDay']]['allValidCount'] += $qrcodeLog['allCount'];
} else {
if ($qrcodeLog['logType'] == 0) { // 取关
$details[$qrcodeLog['dateDay']]['addCancelCount'] = $qrcodeLog['addCount'];
$details[$qrcodeLog['dateDay']]['allCancelCount'] = $qrcodeLog['allCount'];
$details[$qrcodeLog['dateDay']]['addCancelHeadCount'] = $qrcodeLog['addHeadCount'];
$details[$qrcodeLog['dateDay']]['allCancelHeadCount'] = $qrcodeLog['allHeadCount'];
$details[$qrcodeLog['dateDay']]['addValidCount'] -= $qrcodeLog['addCount'];
$details[$qrcodeLog['dateDay']]['allValidCount'] -= $qrcodeLog['allCount'];
}
}
}
// 4. 检验数据
$newTotalData = wei()->wechatQrcodeLog()
->curApp()
->select('count(*) as allCount, count(distinct(userId)) as allHeadCount')
->andWhere(['wechatQrcodeId' => $qrcode['id']])
->andWhere(['type' => 1])
->andWhere('createTime < ?', [$endTime])
->fetch();
$newCancelData = wei()->wechatQrcodeLog()
->curApp()
->select('count(*) as allCount, count(distinct(userId)) as allHeadCount')
->andWhere(['wechatQrcodeId' => $qrcode['id']])
->andWhere(['type' => 0])
->andWhere('createTime < ?', [$endTime])
->fetch();
$lastTotalCount = $newTotalData['allCount'];
$lastCancelCount = $newCancelData['allCount'];
$lastTotalHeadCount = $newTotalData['allHeadCount'];
$lastCancelHeadCount = $newCancelData['allHeadCount'];
$afterCheckDetails = [];
foreach ($details as $detail) {
// 次数
$detail['allTotalCount'] = $detail['allTotalCount'] ?: $lastTotalCount;
$detail['allCancelCount'] = $detail['allCancelCount'] ?: $lastCancelCount;
//人数
$detail['allTotalHeadCount'] = $detail['allTotalHeadCount'] ?: $lastTotalHeadCount;
$detail['allCancelHeadCount'] = $detail['allCancelHeadCount'] ?: $lastCancelHeadCount;
//积累数
$detail['allValidCount'] = $detail['allTotalCount'] - $detail['allCancelCount'];
$lastTotalCount = $detail['allTotalCount'] - $detail['addTotalCount'];
$lastCancelCount = $detail['allCancelCount'] - $detail['addCancelCount'];
$lastTotalHeadCount = $detail['allTotalHeadCount'] - $detail['addTotalHeadCount'];
$lastCancelHeadCount = $detail['allCancelHeadCount'] - $detail['addCancelHeadCount'];
$afterCheckDetails[] = $detail;
}
$details = array_reverse($afterCheckDetails);
// 5. 计算趋势图
$statDates = wei()->coll->column($details, 'statDate');
$columns = [
'addValidCount',
'allValidCount',
'addTotalHeadCount',
'allTotalHeadCount',
'addCancelHeadCount',
'allCancelHeadCount',
'addTotalCount',
'allTotalCount',
'addCancelCount',
'allCancelCount',
];
$chart = wei()->chart;
$charts = [];
foreach ($columns as $column) {
$charts[$column] = $chart->getColumnValues($details, $column);
}
return get_defined_vars();
} | php | public function showDetailAction($req)
{
$startTime = $req['startTime'] ?: date('Y-m-d', time() - 7 * 86400);
$endTime = $req['endTime'] ?: date('Y-m-d', time());
$daysLen = (int) ((strtotime($endTime) - strtotime($startTime)) / 86400);
// 1. 获取统计和每天的数据
$qrcode = wei()->weChatQrcode()->findOne(['sceneId' => $req['sceneId']]);
$sql1 = ', (select count(*) from wechatQrcodeLogs where appId=' . wei()->app->getId() .
' and wechatQrcodeId=' . $qrcode['id'] . ' and type=logType and createTime <= date_add(dateDay, interval 1 day)) as allCount';
$sql2 = ', (select count(distinct(userId)) from wechatQrcodeLogs where appId=' . wei()->app->getId() .
' and wechatQrcodeId=' . $qrcode['id'] . ' and type=logType and createTime <= date_add(dateDay, interval 1 day)) as allHeadCount';
$qrcodeLogs = wei()->wechatQrcodeLog()
->select('DATE_FORMAT(createTime,"%Y-%m-%d") as dateDay, type as logType, count(*) as addCount, count(distinct(userId)) as addHeadCount' . $sql1 . $sql2)
->curApp()
->andWhere(['wechatQrcodeId' => $qrcode['id']])
->andWhere('createTime >= ? and createTime < ?', [$startTime, $endTime])
->groupBy('dateDay,logType')
->desc('id')
->fetchAll();
// 2. 初始化数据
$details = [];
for ($i = 1; $i <= $daysLen; ++$i) {
$day = date('Y-m-d', strtotime($endTime) - $i * 86400);
$details[$day] = [
'statDate' => $day,
'addValidCount' => 0,
'allValidCount' => 0,
'addTotalHeadCount' => 0,
'allTotalHeadCount' => 0,
'addCancelHeadCount' => 0,
'allCancelHeadCount' => 0,
'addTotalCount' => 0,
'allTotalCount' => 0,
'addCancelCount' => 0,
'allCancelCount' => 0,
];
}
// 3. 统计数据
foreach ($qrcodeLogs as $qrcodeLog) {
if ($qrcodeLog['logType'] == 1) { // 关注
$details[$qrcodeLog['dateDay']]['addTotalCount'] = $qrcodeLog['addCount'];
$details[$qrcodeLog['dateDay']]['allTotalCount'] = $qrcodeLog['allCount'];
$details[$qrcodeLog['dateDay']]['addTotalHeadCount'] = $qrcodeLog['addHeadCount'];
$details[$qrcodeLog['dateDay']]['allTotalHeadCount'] = $qrcodeLog['allHeadCount'];
$details[$qrcodeLog['dateDay']]['addValidCount'] += $qrcodeLog['addCount'];
$details[$qrcodeLog['dateDay']]['allValidCount'] += $qrcodeLog['allCount'];
} else {
if ($qrcodeLog['logType'] == 0) { // 取关
$details[$qrcodeLog['dateDay']]['addCancelCount'] = $qrcodeLog['addCount'];
$details[$qrcodeLog['dateDay']]['allCancelCount'] = $qrcodeLog['allCount'];
$details[$qrcodeLog['dateDay']]['addCancelHeadCount'] = $qrcodeLog['addHeadCount'];
$details[$qrcodeLog['dateDay']]['allCancelHeadCount'] = $qrcodeLog['allHeadCount'];
$details[$qrcodeLog['dateDay']]['addValidCount'] -= $qrcodeLog['addCount'];
$details[$qrcodeLog['dateDay']]['allValidCount'] -= $qrcodeLog['allCount'];
}
}
}
// 4. 检验数据
$newTotalData = wei()->wechatQrcodeLog()
->curApp()
->select('count(*) as allCount, count(distinct(userId)) as allHeadCount')
->andWhere(['wechatQrcodeId' => $qrcode['id']])
->andWhere(['type' => 1])
->andWhere('createTime < ?', [$endTime])
->fetch();
$newCancelData = wei()->wechatQrcodeLog()
->curApp()
->select('count(*) as allCount, count(distinct(userId)) as allHeadCount')
->andWhere(['wechatQrcodeId' => $qrcode['id']])
->andWhere(['type' => 0])
->andWhere('createTime < ?', [$endTime])
->fetch();
$lastTotalCount = $newTotalData['allCount'];
$lastCancelCount = $newCancelData['allCount'];
$lastTotalHeadCount = $newTotalData['allHeadCount'];
$lastCancelHeadCount = $newCancelData['allHeadCount'];
$afterCheckDetails = [];
foreach ($details as $detail) {
// 次数
$detail['allTotalCount'] = $detail['allTotalCount'] ?: $lastTotalCount;
$detail['allCancelCount'] = $detail['allCancelCount'] ?: $lastCancelCount;
//人数
$detail['allTotalHeadCount'] = $detail['allTotalHeadCount'] ?: $lastTotalHeadCount;
$detail['allCancelHeadCount'] = $detail['allCancelHeadCount'] ?: $lastCancelHeadCount;
//积累数
$detail['allValidCount'] = $detail['allTotalCount'] - $detail['allCancelCount'];
$lastTotalCount = $detail['allTotalCount'] - $detail['addTotalCount'];
$lastCancelCount = $detail['allCancelCount'] - $detail['addCancelCount'];
$lastTotalHeadCount = $detail['allTotalHeadCount'] - $detail['addTotalHeadCount'];
$lastCancelHeadCount = $detail['allCancelHeadCount'] - $detail['addCancelHeadCount'];
$afterCheckDetails[] = $detail;
}
$details = array_reverse($afterCheckDetails);
// 5. 计算趋势图
$statDates = wei()->coll->column($details, 'statDate');
$columns = [
'addValidCount',
'allValidCount',
'addTotalHeadCount',
'allTotalHeadCount',
'addCancelHeadCount',
'allCancelHeadCount',
'addTotalCount',
'allTotalCount',
'addCancelCount',
'allCancelCount',
];
$chart = wei()->chart;
$charts = [];
foreach ($columns as $column) {
$charts[$column] = $chart->getColumnValues($details, $column);
}
return get_defined_vars();
} | [
"public",
"function",
"showDetailAction",
"(",
"$",
"req",
")",
"{",
"$",
"startTime",
"=",
"$",
"req",
"[",
"'startTime'",
"]",
"?",
":",
"date",
"(",
"'Y-m-d'",
",",
"time",
"(",
")",
"-",
"7",
"*",
"86400",
")",
";",
"$",
"endTime",
"=",
"$",
"req",
"[",
"'endTime'",
"]",
"?",
":",
"date",
"(",
"'Y-m-d'",
",",
"time",
"(",
")",
")",
";",
"$",
"daysLen",
"=",
"(",
"int",
")",
"(",
"(",
"strtotime",
"(",
"$",
"endTime",
")",
"-",
"strtotime",
"(",
"$",
"startTime",
")",
")",
"/",
"86400",
")",
";",
"// 1. 获取统计和每天的数据",
"$",
"qrcode",
"=",
"wei",
"(",
")",
"->",
"weChatQrcode",
"(",
")",
"->",
"findOne",
"(",
"[",
"'sceneId'",
"=>",
"$",
"req",
"[",
"'sceneId'",
"]",
"]",
")",
";",
"$",
"sql1",
"=",
"', (select count(*) from wechatQrcodeLogs where appId='",
".",
"wei",
"(",
")",
"->",
"app",
"->",
"getId",
"(",
")",
".",
"' and wechatQrcodeId='",
".",
"$",
"qrcode",
"[",
"'id'",
"]",
".",
"' and type=logType and createTime <= date_add(dateDay, interval 1 day)) as allCount'",
";",
"$",
"sql2",
"=",
"', (select count(distinct(userId)) from wechatQrcodeLogs where appId='",
".",
"wei",
"(",
")",
"->",
"app",
"->",
"getId",
"(",
")",
".",
"' and wechatQrcodeId='",
".",
"$",
"qrcode",
"[",
"'id'",
"]",
".",
"' and type=logType and createTime <= date_add(dateDay, interval 1 day)) as allHeadCount'",
";",
"$",
"qrcodeLogs",
"=",
"wei",
"(",
")",
"->",
"wechatQrcodeLog",
"(",
")",
"->",
"select",
"(",
"'DATE_FORMAT(createTime,\"%Y-%m-%d\") as dateDay, type as logType, count(*) as addCount, count(distinct(userId)) as addHeadCount'",
".",
"$",
"sql1",
".",
"$",
"sql2",
")",
"->",
"curApp",
"(",
")",
"->",
"andWhere",
"(",
"[",
"'wechatQrcodeId'",
"=>",
"$",
"qrcode",
"[",
"'id'",
"]",
"]",
")",
"->",
"andWhere",
"(",
"'createTime >= ? and createTime < ?'",
",",
"[",
"$",
"startTime",
",",
"$",
"endTime",
"]",
")",
"->",
"groupBy",
"(",
"'dateDay,logType'",
")",
"->",
"desc",
"(",
"'id'",
")",
"->",
"fetchAll",
"(",
")",
";",
"// 2. 初始化数据",
"$",
"details",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"daysLen",
";",
"++",
"$",
"i",
")",
"{",
"$",
"day",
"=",
"date",
"(",
"'Y-m-d'",
",",
"strtotime",
"(",
"$",
"endTime",
")",
"-",
"$",
"i",
"*",
"86400",
")",
";",
"$",
"details",
"[",
"$",
"day",
"]",
"=",
"[",
"'statDate'",
"=>",
"$",
"day",
",",
"'addValidCount'",
"=>",
"0",
",",
"'allValidCount'",
"=>",
"0",
",",
"'addTotalHeadCount'",
"=>",
"0",
",",
"'allTotalHeadCount'",
"=>",
"0",
",",
"'addCancelHeadCount'",
"=>",
"0",
",",
"'allCancelHeadCount'",
"=>",
"0",
",",
"'addTotalCount'",
"=>",
"0",
",",
"'allTotalCount'",
"=>",
"0",
",",
"'addCancelCount'",
"=>",
"0",
",",
"'allCancelCount'",
"=>",
"0",
",",
"]",
";",
"}",
"// 3. 统计数据",
"foreach",
"(",
"$",
"qrcodeLogs",
"as",
"$",
"qrcodeLog",
")",
"{",
"if",
"(",
"$",
"qrcodeLog",
"[",
"'logType'",
"]",
"==",
"1",
")",
"{",
"// 关注",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'addTotalCount'",
"]",
"=",
"$",
"qrcodeLog",
"[",
"'addCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'allTotalCount'",
"]",
"=",
"$",
"qrcodeLog",
"[",
"'allCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'addTotalHeadCount'",
"]",
"=",
"$",
"qrcodeLog",
"[",
"'addHeadCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'allTotalHeadCount'",
"]",
"=",
"$",
"qrcodeLog",
"[",
"'allHeadCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'addValidCount'",
"]",
"+=",
"$",
"qrcodeLog",
"[",
"'addCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'allValidCount'",
"]",
"+=",
"$",
"qrcodeLog",
"[",
"'allCount'",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"qrcodeLog",
"[",
"'logType'",
"]",
"==",
"0",
")",
"{",
"// 取关",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'addCancelCount'",
"]",
"=",
"$",
"qrcodeLog",
"[",
"'addCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'allCancelCount'",
"]",
"=",
"$",
"qrcodeLog",
"[",
"'allCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'addCancelHeadCount'",
"]",
"=",
"$",
"qrcodeLog",
"[",
"'addHeadCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'allCancelHeadCount'",
"]",
"=",
"$",
"qrcodeLog",
"[",
"'allHeadCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'addValidCount'",
"]",
"-=",
"$",
"qrcodeLog",
"[",
"'addCount'",
"]",
";",
"$",
"details",
"[",
"$",
"qrcodeLog",
"[",
"'dateDay'",
"]",
"]",
"[",
"'allValidCount'",
"]",
"-=",
"$",
"qrcodeLog",
"[",
"'allCount'",
"]",
";",
"}",
"}",
"}",
"// 4. 检验数据",
"$",
"newTotalData",
"=",
"wei",
"(",
")",
"->",
"wechatQrcodeLog",
"(",
")",
"->",
"curApp",
"(",
")",
"->",
"select",
"(",
"'count(*) as allCount, count(distinct(userId)) as allHeadCount'",
")",
"->",
"andWhere",
"(",
"[",
"'wechatQrcodeId'",
"=>",
"$",
"qrcode",
"[",
"'id'",
"]",
"]",
")",
"->",
"andWhere",
"(",
"[",
"'type'",
"=>",
"1",
"]",
")",
"->",
"andWhere",
"(",
"'createTime < ?'",
",",
"[",
"$",
"endTime",
"]",
")",
"->",
"fetch",
"(",
")",
";",
"$",
"newCancelData",
"=",
"wei",
"(",
")",
"->",
"wechatQrcodeLog",
"(",
")",
"->",
"curApp",
"(",
")",
"->",
"select",
"(",
"'count(*) as allCount, count(distinct(userId)) as allHeadCount'",
")",
"->",
"andWhere",
"(",
"[",
"'wechatQrcodeId'",
"=>",
"$",
"qrcode",
"[",
"'id'",
"]",
"]",
")",
"->",
"andWhere",
"(",
"[",
"'type'",
"=>",
"0",
"]",
")",
"->",
"andWhere",
"(",
"'createTime < ?'",
",",
"[",
"$",
"endTime",
"]",
")",
"->",
"fetch",
"(",
")",
";",
"$",
"lastTotalCount",
"=",
"$",
"newTotalData",
"[",
"'allCount'",
"]",
";",
"$",
"lastCancelCount",
"=",
"$",
"newCancelData",
"[",
"'allCount'",
"]",
";",
"$",
"lastTotalHeadCount",
"=",
"$",
"newTotalData",
"[",
"'allHeadCount'",
"]",
";",
"$",
"lastCancelHeadCount",
"=",
"$",
"newCancelData",
"[",
"'allHeadCount'",
"]",
";",
"$",
"afterCheckDetails",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"details",
"as",
"$",
"detail",
")",
"{",
"// 次数",
"$",
"detail",
"[",
"'allTotalCount'",
"]",
"=",
"$",
"detail",
"[",
"'allTotalCount'",
"]",
"?",
":",
"$",
"lastTotalCount",
";",
"$",
"detail",
"[",
"'allCancelCount'",
"]",
"=",
"$",
"detail",
"[",
"'allCancelCount'",
"]",
"?",
":",
"$",
"lastCancelCount",
";",
"//人数",
"$",
"detail",
"[",
"'allTotalHeadCount'",
"]",
"=",
"$",
"detail",
"[",
"'allTotalHeadCount'",
"]",
"?",
":",
"$",
"lastTotalHeadCount",
";",
"$",
"detail",
"[",
"'allCancelHeadCount'",
"]",
"=",
"$",
"detail",
"[",
"'allCancelHeadCount'",
"]",
"?",
":",
"$",
"lastCancelHeadCount",
";",
"//积累数",
"$",
"detail",
"[",
"'allValidCount'",
"]",
"=",
"$",
"detail",
"[",
"'allTotalCount'",
"]",
"-",
"$",
"detail",
"[",
"'allCancelCount'",
"]",
";",
"$",
"lastTotalCount",
"=",
"$",
"detail",
"[",
"'allTotalCount'",
"]",
"-",
"$",
"detail",
"[",
"'addTotalCount'",
"]",
";",
"$",
"lastCancelCount",
"=",
"$",
"detail",
"[",
"'allCancelCount'",
"]",
"-",
"$",
"detail",
"[",
"'addCancelCount'",
"]",
";",
"$",
"lastTotalHeadCount",
"=",
"$",
"detail",
"[",
"'allTotalHeadCount'",
"]",
"-",
"$",
"detail",
"[",
"'addTotalHeadCount'",
"]",
";",
"$",
"lastCancelHeadCount",
"=",
"$",
"detail",
"[",
"'allCancelHeadCount'",
"]",
"-",
"$",
"detail",
"[",
"'addCancelHeadCount'",
"]",
";",
"$",
"afterCheckDetails",
"[",
"]",
"=",
"$",
"detail",
";",
"}",
"$",
"details",
"=",
"array_reverse",
"(",
"$",
"afterCheckDetails",
")",
";",
"// 5. 计算趋势图",
"$",
"statDates",
"=",
"wei",
"(",
")",
"->",
"coll",
"->",
"column",
"(",
"$",
"details",
",",
"'statDate'",
")",
";",
"$",
"columns",
"=",
"[",
"'addValidCount'",
",",
"'allValidCount'",
",",
"'addTotalHeadCount'",
",",
"'allTotalHeadCount'",
",",
"'addCancelHeadCount'",
",",
"'allCancelHeadCount'",
",",
"'addTotalCount'",
",",
"'allTotalCount'",
",",
"'addCancelCount'",
",",
"'allCancelCount'",
",",
"]",
";",
"$",
"chart",
"=",
"wei",
"(",
")",
"->",
"chart",
";",
"$",
"charts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"$",
"charts",
"[",
"$",
"column",
"]",
"=",
"$",
"chart",
"->",
"getColumnValues",
"(",
"$",
"details",
",",
"$",
"column",
")",
";",
"}",
"return",
"get_defined_vars",
"(",
")",
";",
"}"
] | 二维码数据统计
@param $req
@return array|\Wei\Response | [
"二维码数据统计"
] | train | https://github.com/miaoxing/wechat/blob/8620f7788cd0b6b9d20d436cede1f9f2fd24925f/src/Controller/Admin/WechatQrcode.php#L178-L306 |
kambalabs/KmbZendDbInfrastructure | src/KmbZendDbInfrastructure/Hydrator/GroupHydrator.php | GroupHydrator.extract | public function extract($object)
{
$data = [
'revision_id' => $object->getRevision()->getId(),
'name' => $object->getName(),
'type' => $object->getType(),
'ordering' => $object->getOrdering(),
'include_pattern' => $object->getIncludePattern(),
'exclude_pattern' => $object->getExcludePattern(),
];
if ($object->getId()) {
$data['id'] = $object->getId();
}
return $data;
} | php | public function extract($object)
{
$data = [
'revision_id' => $object->getRevision()->getId(),
'name' => $object->getName(),
'type' => $object->getType(),
'ordering' => $object->getOrdering(),
'include_pattern' => $object->getIncludePattern(),
'exclude_pattern' => $object->getExcludePattern(),
];
if ($object->getId()) {
$data['id'] = $object->getId();
}
return $data;
} | [
"public",
"function",
"extract",
"(",
"$",
"object",
")",
"{",
"$",
"data",
"=",
"[",
"'revision_id'",
"=>",
"$",
"object",
"->",
"getRevision",
"(",
")",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"object",
"->",
"getName",
"(",
")",
",",
"'type'",
"=>",
"$",
"object",
"->",
"getType",
"(",
")",
",",
"'ordering'",
"=>",
"$",
"object",
"->",
"getOrdering",
"(",
")",
",",
"'include_pattern'",
"=>",
"$",
"object",
"->",
"getIncludePattern",
"(",
")",
",",
"'exclude_pattern'",
"=>",
"$",
"object",
"->",
"getExcludePattern",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"object",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"data",
"[",
"'id'",
"]",
"=",
"$",
"object",
"->",
"getId",
"(",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Extract values from an object
@param GroupInterface $object
@return array | [
"Extract",
"values",
"from",
"an",
"object"
] | train | https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Hydrator/GroupHydrator.php#L34-L48 |
kambalabs/KmbZendDbInfrastructure | src/KmbZendDbInfrastructure/Hydrator/GroupHydrator.php | GroupHydrator.hydrate | public function hydrate(array $data, $object)
{
$object->setId($this->getData('id', $data));
$object->setName($this->getData('name', $data));
$object->setType($this->getData('type', $data));
$object->setOrdering($this->getData('ordering', $data));
$object->setIncludePattern($this->getData('include_pattern', $data));
$object->setExcludePattern($this->getData('exclude_pattern', $data));
return $object;
} | php | public function hydrate(array $data, $object)
{
$object->setId($this->getData('id', $data));
$object->setName($this->getData('name', $data));
$object->setType($this->getData('type', $data));
$object->setOrdering($this->getData('ordering', $data));
$object->setIncludePattern($this->getData('include_pattern', $data));
$object->setExcludePattern($this->getData('exclude_pattern', $data));
return $object;
} | [
"public",
"function",
"hydrate",
"(",
"array",
"$",
"data",
",",
"$",
"object",
")",
"{",
"$",
"object",
"->",
"setId",
"(",
"$",
"this",
"->",
"getData",
"(",
"'id'",
",",
"$",
"data",
")",
")",
";",
"$",
"object",
"->",
"setName",
"(",
"$",
"this",
"->",
"getData",
"(",
"'name'",
",",
"$",
"data",
")",
")",
";",
"$",
"object",
"->",
"setType",
"(",
"$",
"this",
"->",
"getData",
"(",
"'type'",
",",
"$",
"data",
")",
")",
";",
"$",
"object",
"->",
"setOrdering",
"(",
"$",
"this",
"->",
"getData",
"(",
"'ordering'",
",",
"$",
"data",
")",
")",
";",
"$",
"object",
"->",
"setIncludePattern",
"(",
"$",
"this",
"->",
"getData",
"(",
"'include_pattern'",
",",
"$",
"data",
")",
")",
";",
"$",
"object",
"->",
"setExcludePattern",
"(",
"$",
"this",
"->",
"getData",
"(",
"'exclude_pattern'",
",",
"$",
"data",
")",
")",
";",
"return",
"$",
"object",
";",
"}"
] | Hydrate $object with the provided $data.
@param array $data
@param GroupInterface $object
@return GroupInterface | [
"Hydrate",
"$object",
"with",
"the",
"provided",
"$data",
"."
] | train | https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Hydrator/GroupHydrator.php#L57-L66 |
bound1ess/essence | src/Essence/Matchers/ThrowMatcher.php | ThrowMatcher.run | public function run()
{
parent::run();
$arguments = array_slice(array_merge($this->arguments, [null, null]), 0, 3);
list ($class, $message, $context) = $arguments;
try
{
$callback = $this->value;
if ( ! is_null($context)) {
$callback = $callback->bindTo($context);
}
$callback();
}
catch (\Exception $exception)
{
if (get_class($exception) == $class) {
if ( ! is_null($message) and $exception->getMessage() != $message) {
$this->setMessage("expected error message %s is not equal to %s", [
$message,
$exception->getMessage(),
]);
return false;
}
$this->setMessage("got %s, just as expected", [$class]);
return true;
} else {
$this->setMessage(
"%s was expected, but got %s",
[$class, get_class($exception)]
);
return false;
}
}
$this->setMessage("nothing was thrown");
return false;
} | php | public function run()
{
parent::run();
$arguments = array_slice(array_merge($this->arguments, [null, null]), 0, 3);
list ($class, $message, $context) = $arguments;
try
{
$callback = $this->value;
if ( ! is_null($context)) {
$callback = $callback->bindTo($context);
}
$callback();
}
catch (\Exception $exception)
{
if (get_class($exception) == $class) {
if ( ! is_null($message) and $exception->getMessage() != $message) {
$this->setMessage("expected error message %s is not equal to %s", [
$message,
$exception->getMessage(),
]);
return false;
}
$this->setMessage("got %s, just as expected", [$class]);
return true;
} else {
$this->setMessage(
"%s was expected, but got %s",
[$class, get_class($exception)]
);
return false;
}
}
$this->setMessage("nothing was thrown");
return false;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"parent",
"::",
"run",
"(",
")",
";",
"$",
"arguments",
"=",
"array_slice",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"arguments",
",",
"[",
"null",
",",
"null",
"]",
")",
",",
"0",
",",
"3",
")",
";",
"list",
"(",
"$",
"class",
",",
"$",
"message",
",",
"$",
"context",
")",
"=",
"$",
"arguments",
";",
"try",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"value",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"context",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"callback",
"->",
"bindTo",
"(",
"$",
"context",
")",
";",
"}",
"$",
"callback",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"if",
"(",
"get_class",
"(",
"$",
"exception",
")",
"==",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"message",
")",
"and",
"$",
"exception",
"->",
"getMessage",
"(",
")",
"!=",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"\"expected error message %s is not equal to %s\"",
",",
"[",
"$",
"message",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"]",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"setMessage",
"(",
"\"got %s, just as expected\"",
",",
"[",
"$",
"class",
"]",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"\"%s was expected, but got %s\"",
",",
"[",
"$",
"class",
",",
"get_class",
"(",
"$",
"exception",
")",
"]",
")",
";",
"return",
"false",
";",
"}",
"}",
"$",
"this",
"->",
"setMessage",
"(",
"\"nothing was thrown\"",
")",
";",
"return",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bound1ess/essence/blob/b773d3f17e192d7c7184ffd3640c668e7d74f69b/src/Essence/Matchers/ThrowMatcher.php#L17-L63 |
creios/creiwork-framework | src/Util/JsonValidator.php | JsonValidator.dataValidation | public
function dataValidation($data,
$schema,
int $max_errors = 1,
ISchemaLoader $loader = null): ValidationResult
{
return $this->validator->dataValidation($data, $schema, $max_errors, $loader);
} | php | public
function dataValidation($data,
$schema,
int $max_errors = 1,
ISchemaLoader $loader = null): ValidationResult
{
return $this->validator->dataValidation($data, $schema, $max_errors, $loader);
} | [
"public",
"function",
"dataValidation",
"(",
"$",
"data",
",",
"$",
"schema",
",",
"int",
"$",
"max_errors",
"=",
"1",
",",
"ISchemaLoader",
"$",
"loader",
"=",
"null",
")",
":",
"ValidationResult",
"{",
"return",
"$",
"this",
"->",
"validator",
"->",
"dataValidation",
"(",
"$",
"data",
",",
"$",
"schema",
",",
"$",
"max_errors",
",",
"$",
"loader",
")",
";",
"}"
] | Wrapper method for Opis\JsonSchema\ConfigValidator::dataValidation()
@see Validator::dataValidation()
@param string|object|array $data
@param object|string $schema
@param int $max_errors
@param ISchemaLoader|null $loader
@return \Opis\JsonSchema\ValidationResult | [
"Wrapper",
"method",
"for",
"Opis",
"\\",
"JsonSchema",
"\\",
"ConfigValidator",
"::",
"dataValidation",
"()"
] | train | https://github.com/creios/creiwork-framework/blob/5089578b44ef6af725ab0c8a2dfe691bfe07ffb6/src/Util/JsonValidator.php#L70-L76 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.