repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
vworldat/MenuBundle | Menu/Menu.php | Menu.createItem | public function createItem($itemRouteName, array $itemOptions)
{
if (isset($itemOptions['item_class']))
{
$class = $itemOptions['item_class'];
}
else
{
$class = $this->getDefaultItemClass();
}
if (isset($this->itemClassAliases[$class]))
{
$class = $this->itemClassAliases[$class];
}
if (!$this->isValidMenuItemClass($class))
{
throw new NoMenuItemClassException(sprintf('Item class %s does not extend \C33s\MenuBundle\Item\MenuItem', $itemOptions['item_class']));
}
$item = new $class($itemRouteName, $itemOptions, $this);
return $item;
} | php | public function createItem($itemRouteName, array $itemOptions)
{
if (isset($itemOptions['item_class']))
{
$class = $itemOptions['item_class'];
}
else
{
$class = $this->getDefaultItemClass();
}
if (isset($this->itemClassAliases[$class]))
{
$class = $this->itemClassAliases[$class];
}
if (!$this->isValidMenuItemClass($class))
{
throw new NoMenuItemClassException(sprintf('Item class %s does not extend \C33s\MenuBundle\Item\MenuItem', $itemOptions['item_class']));
}
$item = new $class($itemRouteName, $itemOptions, $this);
return $item;
} | [
"public",
"function",
"createItem",
"(",
"$",
"itemRouteName",
",",
"array",
"$",
"itemOptions",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"itemOptions",
"[",
"'item_class'",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"itemOptions",
"[",
"'item_class'",
"... | MenuItem factory method.
@param string $itemRouteName
@param array $itemOptions
@throws NoMenuItemClassException
@return MenuItem | [
"MenuItem",
"factory",
"method",
"."
] | 136e5ee859c3be95a199a7207fa5aacc5ccb26ec | https://github.com/vworldat/MenuBundle/blob/136e5ee859c3be95a199a7207fa5aacc5ccb26ec/Menu/Menu.php#L124-L148 | train |
vworldat/MenuBundle | Menu/Menu.php | Menu.getBreadcrumbItems | public function getBreadcrumbItems()
{
$item = $this->getBaseItem();
$items = array();
while ($current = $item->getCurrentChild())
{
$items[] = $current;
$item = $current;
}
return $items;
} | php | public function getBreadcrumbItems()
{
$item = $this->getBaseItem();
$items = array();
while ($current = $item->getCurrentChild())
{
$items[] = $current;
$item = $current;
}
return $items;
} | [
"public",
"function",
"getBreadcrumbItems",
"(",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"getBaseItem",
"(",
")",
";",
"$",
"items",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"current",
"=",
"$",
"item",
"->",
"getCurrentChild",
"(",
")"... | Get all items on the current item's path, starting with the lowest. Useful for breadcrumb rendering.
@return array | [
"Get",
"all",
"items",
"on",
"the",
"current",
"item",
"s",
"path",
"starting",
"with",
"the",
"lowest",
".",
"Useful",
"for",
"breadcrumb",
"rendering",
"."
] | 136e5ee859c3be95a199a7207fa5aacc5ccb26ec | https://github.com/vworldat/MenuBundle/blob/136e5ee859c3be95a199a7207fa5aacc5ccb26ec/Menu/Menu.php#L181-L194 | train |
vworldat/MenuBundle | Menu/Menu.php | Menu.isValidMenuItemClass | protected function isValidMenuItemClass($className)
{
if (!isset($this->checkedClasses[$className]))
{
$this->checkedClasses[$className] = $this->hasParentClass($className, 'C33s\\MenuBundle\\Item\\MenuItem');
}
return $this->checkedClasses[$className];
} | php | protected function isValidMenuItemClass($className)
{
if (!isset($this->checkedClasses[$className]))
{
$this->checkedClasses[$className] = $this->hasParentClass($className, 'C33s\\MenuBundle\\Item\\MenuItem');
}
return $this->checkedClasses[$className];
} | [
"protected",
"function",
"isValidMenuItemClass",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"checkedClasses",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"this",
"->",
"checkedClasses",
"[",
"$",
"className",
"]... | Check if the given class is a valid MenuItem class.
@param string $className
@return boolean | [
"Check",
"if",
"the",
"given",
"class",
"is",
"a",
"valid",
"MenuItem",
"class",
"."
] | 136e5ee859c3be95a199a7207fa5aacc5ccb26ec | https://github.com/vworldat/MenuBundle/blob/136e5ee859c3be95a199a7207fa5aacc5ccb26ec/Menu/Menu.php#L228-L236 | train |
teamelf/core | src/Application/Server.php | Server.boot | protected function boot(): void
{
// boot extensions
foreach ($this->extensionManager->getExtensions() as $extension) {
if ($extension->isActivated()) {
$extension->boot();
}
}
// boot app
$this->dispatch(new RoutesWillBeLoaded($this->router));
$this->dispatch(new RoutesHaveBeenLoaded($this->router));
// send back responses
try {
$response = $this->router->getResponse();
$response->send();
} catch (RouteNotFoundException $exception) {
throw new HttpNotFoundException();
} catch (ResourceNotFoundException $exception) {
throw new HttpNotFoundException();
} catch (MethodNotAllowedException $exception) {
throw new HttpMethodNotAllowedException();
}
} | php | protected function boot(): void
{
// boot extensions
foreach ($this->extensionManager->getExtensions() as $extension) {
if ($extension->isActivated()) {
$extension->boot();
}
}
// boot app
$this->dispatch(new RoutesWillBeLoaded($this->router));
$this->dispatch(new RoutesHaveBeenLoaded($this->router));
// send back responses
try {
$response = $this->router->getResponse();
$response->send();
} catch (RouteNotFoundException $exception) {
throw new HttpNotFoundException();
} catch (ResourceNotFoundException $exception) {
throw new HttpNotFoundException();
} catch (MethodNotAllowedException $exception) {
throw new HttpMethodNotAllowedException();
}
} | [
"protected",
"function",
"boot",
"(",
")",
":",
"void",
"{",
"// boot extensions",
"foreach",
"(",
"$",
"this",
"->",
"extensionManager",
"->",
"getExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"if",
"(",
"$",
"extension",
"->",
"isActivated",
"... | boot all services
@throws HttpMethodNotAllowedException
@throws HttpNotFoundException | [
"boot",
"all",
"services"
] | 653fc6e27f42239c2a8998a5fea325480e9dd39e | https://github.com/teamelf/core/blob/653fc6e27f42239c2a8998a5fea325480e9dd39e/src/Application/Server.php#L66-L90 | train |
rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Action.php | PHP_ParserGenerator_Action.actioncmp | static function actioncmp(PHP_ParserGenerator_Action $ap1, PHP_ParserGenerator_Action $ap2)
{
$rc = $ap1->sp->index - $ap2->sp->index;
if ($rc === 0) {
$rc = $ap1->type - $ap2->type;
}
if ($rc === 0) {
if ($ap1->type == self::SHIFT) {
if ($ap1->x->statenum != $ap2->x->statenum) {
throw new Exception('Shift conflict: ' . $ap1->sp->name .
' shifts both to state ' . $ap1->x->statenum . ' (rule ' .
$ap1->x->cfp->rp->lhs->name . ' on line ' .
$ap1->x->cfp->rp->ruleline . ') and to state ' .
$ap2->x->statenum . ' (rule ' .
$ap2->x->cfp->rp->lhs->name . ' on line ' .
$ap2->x->cfp->rp->ruleline . ')');
}
}
if ($ap1->type != self::REDUCE
&& $ap1->type != self::RD_RESOLVED
&& $ap1->type != self::CONFLICT
) {
throw new Exception('action has not been processed: ' .
$ap1->sp->name . ' on line ' . $ap1->x->cfp->rp->ruleline .
', rule ' . $ap1->x->cfp->rp->lhs->name);
}
if ($ap2->type != self::REDUCE
&& $ap2->type != self::RD_RESOLVED
&& $ap2->type != self::CONFLICT
) {
throw new Exception('action has not been processed: ' .
$ap2->sp->name . ' on line ' . $ap2->x->cfp->rp->ruleline .
', rule ' . $ap2->x->cfp->rp->lhs->name);
}
$rc = $ap1->x->index - $ap2->x->index;
}
return $rc;
} | php | static function actioncmp(PHP_ParserGenerator_Action $ap1, PHP_ParserGenerator_Action $ap2)
{
$rc = $ap1->sp->index - $ap2->sp->index;
if ($rc === 0) {
$rc = $ap1->type - $ap2->type;
}
if ($rc === 0) {
if ($ap1->type == self::SHIFT) {
if ($ap1->x->statenum != $ap2->x->statenum) {
throw new Exception('Shift conflict: ' . $ap1->sp->name .
' shifts both to state ' . $ap1->x->statenum . ' (rule ' .
$ap1->x->cfp->rp->lhs->name . ' on line ' .
$ap1->x->cfp->rp->ruleline . ') and to state ' .
$ap2->x->statenum . ' (rule ' .
$ap2->x->cfp->rp->lhs->name . ' on line ' .
$ap2->x->cfp->rp->ruleline . ')');
}
}
if ($ap1->type != self::REDUCE
&& $ap1->type != self::RD_RESOLVED
&& $ap1->type != self::CONFLICT
) {
throw new Exception('action has not been processed: ' .
$ap1->sp->name . ' on line ' . $ap1->x->cfp->rp->ruleline .
', rule ' . $ap1->x->cfp->rp->lhs->name);
}
if ($ap2->type != self::REDUCE
&& $ap2->type != self::RD_RESOLVED
&& $ap2->type != self::CONFLICT
) {
throw new Exception('action has not been processed: ' .
$ap2->sp->name . ' on line ' . $ap2->x->cfp->rp->ruleline .
', rule ' . $ap2->x->cfp->rp->lhs->name);
}
$rc = $ap1->x->index - $ap2->x->index;
}
return $rc;
} | [
"static",
"function",
"actioncmp",
"(",
"PHP_ParserGenerator_Action",
"$",
"ap1",
",",
"PHP_ParserGenerator_Action",
"$",
"ap2",
")",
"{",
"$",
"rc",
"=",
"$",
"ap1",
"->",
"sp",
"->",
"index",
"-",
"$",
"ap2",
"->",
"sp",
"->",
"index",
";",
"if",
"(",
... | Compare two actions
This is used by {@link Action_sort()} to compare actions | [
"Compare",
"two",
"actions"
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Action.php#L122-L159 | train |
rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Action.php | PHP_ParserGenerator_Action.Action_add | static function Action_add(&$app, $type, PHP_ParserGenerator_Symbol $sp, $arg)
{
$new = new PHP_ParserGenerator_Action;
$new->next = $app;
$app = $new;
$new->type = $type;
$new->sp = $sp;
$new->x = $arg;
echo ' Adding ';
$new->display();
} | php | static function Action_add(&$app, $type, PHP_ParserGenerator_Symbol $sp, $arg)
{
$new = new PHP_ParserGenerator_Action;
$new->next = $app;
$app = $new;
$new->type = $type;
$new->sp = $sp;
$new->x = $arg;
echo ' Adding ';
$new->display();
} | [
"static",
"function",
"Action_add",
"(",
"&",
"$",
"app",
",",
"$",
"type",
",",
"PHP_ParserGenerator_Symbol",
"$",
"sp",
",",
"$",
"arg",
")",
"{",
"$",
"new",
"=",
"new",
"PHP_ParserGenerator_Action",
";",
"$",
"new",
"->",
"next",
"=",
"$",
"app",
"... | create linked list of PHP_ParserGenerator_Actions
@param PHP_ParserGenerator_Action|null $app
@param int $type one of the class constants from PHP_ParserGenerator_Action
@param PHP_ParserGenerator_Symbol $sp
@param PHP_ParserGenerator_State|PHP_ParserGenerator_Rule $arg | [
"create",
"linked",
"list",
"of",
"PHP_ParserGenerator_Actions"
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Action.php#L187-L197 | train |
rodchyn/elephant-lang | lib/ParserGenerator/PHP/ParserGenerator/Action.php | PHP_ParserGenerator_Action.PrintAction | function PrintAction($fp, $indent)
{
if (!$fp) {
$fp = STDOUT;
}
$result = 1;
switch ($this->type)
{
case self::SHIFT:
fprintf($fp, "%${indent}s shift %d", $this->sp->name, $this->x->statenum);
break;
case self::REDUCE:
fprintf($fp, "%${indent}s reduce %d", $this->sp->name, $this->x->index);
break;
case self::ACCEPT:
fprintf($fp, "%${indent}s accept", $this->sp->name);
break;
case self::ERROR:
fprintf($fp, "%${indent}s error", $this->sp->name);
break;
case self::CONFLICT:
fprintf($fp, "%${indent}s reduce %-3d ** Parsing conflict **", $this->sp->name, $this->x->index);
break;
case self::SH_RESOLVED:
case self::RD_RESOLVED:
case self::NOT_USED:
$result = 0;
break;
}
return $result;
} | php | function PrintAction($fp, $indent)
{
if (!$fp) {
$fp = STDOUT;
}
$result = 1;
switch ($this->type)
{
case self::SHIFT:
fprintf($fp, "%${indent}s shift %d", $this->sp->name, $this->x->statenum);
break;
case self::REDUCE:
fprintf($fp, "%${indent}s reduce %d", $this->sp->name, $this->x->index);
break;
case self::ACCEPT:
fprintf($fp, "%${indent}s accept", $this->sp->name);
break;
case self::ERROR:
fprintf($fp, "%${indent}s error", $this->sp->name);
break;
case self::CONFLICT:
fprintf($fp, "%${indent}s reduce %-3d ** Parsing conflict **", $this->sp->name, $this->x->index);
break;
case self::SH_RESOLVED:
case self::RD_RESOLVED:
case self::NOT_USED:
$result = 0;
break;
}
return $result;
} | [
"function",
"PrintAction",
"(",
"$",
"fp",
",",
"$",
"indent",
")",
"{",
"if",
"(",
"!",
"$",
"fp",
")",
"{",
"$",
"fp",
"=",
"STDOUT",
";",
"}",
"$",
"result",
"=",
"1",
";",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self"... | Print an action to the given file descriptor. Return FALSE if
nothing was actually printed.
@param resource $fp File descriptor to print on
@param integer $indent Number of indents
@see PHP_ParserGenerator_Data::ReportOutput()
@return int|false | [
"Print",
"an",
"action",
"to",
"the",
"given",
"file",
"descriptor",
".",
"Return",
"FALSE",
"if",
"nothing",
"was",
"actually",
"printed",
"."
] | e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf | https://github.com/rodchyn/elephant-lang/blob/e0acc26eec1ab4dbfcc90ad79efc23318eaba5cf/lib/ParserGenerator/PHP/ParserGenerator/Action.php#L225-L255 | train |
m-jch/ZagrosCore | src/models/Project.php | Project.removeElementFromArray | public static function removeElementFromArray($elements, $array)
{
if (is_array($elements) && is_array($array))
{
foreach ($elements as $element)
{
if (in_array($element, $array))
{
$key = array_search($element, $array);
unset($array[$key]);
}
}
}
return $array;
} | php | public static function removeElementFromArray($elements, $array)
{
if (is_array($elements) && is_array($array))
{
foreach ($elements as $element)
{
if (in_array($element, $array))
{
$key = array_search($element, $array);
unset($array[$key]);
}
}
}
return $array;
} | [
"public",
"static",
"function",
"removeElementFromArray",
"(",
"$",
"elements",
",",
"$",
"array",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"elements",
")",
"&&",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"foreach",
"(",
"$",
"elements",
"as",
"$... | For example remove admins from writers array
@param $elements array
@param $array array
@return array | [
"For",
"example",
"remove",
"admins",
"from",
"writers",
"array"
] | 06771fe13e77f7663ea5cc561c6078be08b0f557 | https://github.com/m-jch/ZagrosCore/blob/06771fe13e77f7663ea5cc561c6078be08b0f557/src/models/Project.php#L70-L84 | train |
benkle-libs/feed-parser | src/Utilities/PriorityList.php | PriorityList.add | public function add($entry, $priority = self::DEFAULT_PRIORITY)
{
if (isset($this->entryClass) && !($entry instanceof $this->entryClass)) {
throw new InvalidObjectClassException($this->entryClass, get_class($entry));
}
$this->entries[] = ['data' => $entry, 'priority' => $priority];
$this->sorted = false;
return $this;
} | php | public function add($entry, $priority = self::DEFAULT_PRIORITY)
{
if (isset($this->entryClass) && !($entry instanceof $this->entryClass)) {
throw new InvalidObjectClassException($this->entryClass, get_class($entry));
}
$this->entries[] = ['data' => $entry, 'priority' => $priority];
$this->sorted = false;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"entry",
",",
"$",
"priority",
"=",
"self",
"::",
"DEFAULT_PRIORITY",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entryClass",
")",
"&&",
"!",
"(",
"$",
"entry",
"instanceof",
"$",
"this",
"->",
"entr... | Add an entry to the list.
@param mixed $entry
@param int $priority
@return $this
@throws InvalidObjectClassException | [
"Add",
"an",
"entry",
"to",
"the",
"list",
"."
] | 8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f | https://github.com/benkle-libs/feed-parser/blob/8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f/src/Utilities/PriorityList.php#L55-L63 | train |
benkle-libs/feed-parser | src/Utilities/PriorityList.php | PriorityList.remove | public function remove($entry, $priority = false)
{
$unsetAnything = false;
foreach ($this->entries as $i => $entryData) {
if ($entry === $entryData['data'] && ($priority === false || $entryData['priority'] == $priority)) {
unset($this->entries[$i]);
$unsetAnything = true;
}
}
if ($unsetAnything) {
$this->sorted = false;
}
return $this;
} | php | public function remove($entry, $priority = false)
{
$unsetAnything = false;
foreach ($this->entries as $i => $entryData) {
if ($entry === $entryData['data'] && ($priority === false || $entryData['priority'] == $priority)) {
unset($this->entries[$i]);
$unsetAnything = true;
}
}
if ($unsetAnything) {
$this->sorted = false;
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"entry",
",",
"$",
"priority",
"=",
"false",
")",
"{",
"$",
"unsetAnything",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"i",
"=>",
"$",
"entryData",
")",
"{",
"if",
"(",
"$"... | Removes an entry from the list.
@param mixed $entry
@param bool|int $priority When false, remove all instances of $entry from the list, otherwise only those with matching priority
@return $this | [
"Removes",
"an",
"entry",
"from",
"the",
"list",
"."
] | 8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f | https://github.com/benkle-libs/feed-parser/blob/8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f/src/Utilities/PriorityList.php#L71-L84 | train |
benkle-libs/feed-parser | src/Utilities/PriorityList.php | PriorityList.reprioritise | public function reprioritise($entry, $newPriority, $oldPriority = false)
{
$changedAnything = false;
foreach ($this->entries as $i => &$entryData) {
if ($entry === $entryData['data'] && ($oldPriority === false || $entryData['priority'] == $oldPriority)) {
$entryData['priority'] = $newPriority;
$changedAnything = true;
}
}
if ($changedAnything) {
$this->sorted = false;
}
return $this;
} | php | public function reprioritise($entry, $newPriority, $oldPriority = false)
{
$changedAnything = false;
foreach ($this->entries as $i => &$entryData) {
if ($entry === $entryData['data'] && ($oldPriority === false || $entryData['priority'] == $oldPriority)) {
$entryData['priority'] = $newPriority;
$changedAnything = true;
}
}
if ($changedAnything) {
$this->sorted = false;
}
return $this;
} | [
"public",
"function",
"reprioritise",
"(",
"$",
"entry",
",",
"$",
"newPriority",
",",
"$",
"oldPriority",
"=",
"false",
")",
"{",
"$",
"changedAnything",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"i",
"=>",
"&",
"$",
... | change the priority for an entry.
@param mixed $entry
@param int $newPriority
@param bool|int $oldPriority If falsechange remove all instances of $entry from the list, otherwise only those with matching priority
@return $this | [
"change",
"the",
"priority",
"for",
"an",
"entry",
"."
] | 8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f | https://github.com/benkle-libs/feed-parser/blob/8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f/src/Utilities/PriorityList.php#L93-L106 | train |
benkle-libs/feed-parser | src/Utilities/PriorityList.php | PriorityList.toArray | public function toArray()
{
if (!$this->sorted) {
$this->rewind();
}
return array_map(
function ($entry) {
return $entry['data'];
}, $this->entries
);
} | php | public function toArray()
{
if (!$this->sorted) {
$this->rewind();
}
return array_map(
function ($entry) {
return $entry['data'];
}, $this->entries
);
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"sorted",
")",
"{",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"}",
"return",
"array_map",
"(",
"function",
"(",
"$",
"entry",
")",
"{",
"return",
"$",
"entry",
"... | Returns all items, ordered by priority.
@return array | [
"Returns",
"all",
"items",
"ordered",
"by",
"priority",
"."
] | 8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f | https://github.com/benkle-libs/feed-parser/blob/8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f/src/Utilities/PriorityList.php#L189-L199 | train |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Support/Arr.php | Arr.dotGet | public static function dotGet(array $array, $key, $default = null)
{
if (is_null($key)) {
return $array;
}
if (isset($array[$key])) {
return $array[$key];
}
foreach (explode('.', $key) as $segment) {
if (!is_array($array) || !array_key_exists($segment, $array)) {
return Std::thunk($default);
}
$array = $array[$segment];
}
return $array;
} | php | public static function dotGet(array $array, $key, $default = null)
{
if (is_null($key)) {
return $array;
}
if (isset($array[$key])) {
return $array[$key];
}
foreach (explode('.', $key) as $segment) {
if (!is_array($array) || !array_key_exists($segment, $array)) {
return Std::thunk($default);
}
$array = $array[$segment];
}
return $array;
} | [
"public",
"static",
"function",
"dotGet",
"(",
"array",
"$",
"array",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"array",
";",
"}",
"if",
"(",
"isset",
"(",
... | Get the resulting value of an attempt to traverse a key path.
Each key in the path is separated with a dot.
For example, the following snippet should return `true`:
```php
Arr::dotGet([
'hello' => [
'world' => true,
],
], 'hello.world');
```
Additionally, a default value may be provided, which will be returned if
the path does not yield to a value.
@param array $array
@param string $key
@param null|mixed $default
@return mixed | [
"Get",
"the",
"resulting",
"value",
"of",
"an",
"attempt",
"to",
"traverse",
"a",
"key",
"path",
"."
] | c05d9c23d424a6bd5ab2e29140805cc6e37e4623 | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Support/Arr.php#L53-L72 | train |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Support/Arr.php | Arr.dotSet | public static function dotSet(array $array, $key, $value)
{
$path = explode('.', $key);
$total = count($path);
$current = &$array;
for ($ii = 0; $ii < $total; $ii++) {
if ($ii === $total - 1) {
$current[$path[$ii]] = $value;
} else {
if (!is_array($current)) {
throw new LackOfCoffeeException(
'Part of the path is not an array.'
);
}
if (!array_key_exists($path[$ii], $current)) {
$current[$path[$ii]] = [];
}
$current = &$current[$path[$ii]];
}
}
} | php | public static function dotSet(array $array, $key, $value)
{
$path = explode('.', $key);
$total = count($path);
$current = &$array;
for ($ii = 0; $ii < $total; $ii++) {
if ($ii === $total - 1) {
$current[$path[$ii]] = $value;
} else {
if (!is_array($current)) {
throw new LackOfCoffeeException(
'Part of the path is not an array.'
);
}
if (!array_key_exists($path[$ii], $current)) {
$current[$path[$ii]] = [];
}
$current = &$current[$path[$ii]];
}
}
} | [
"public",
"static",
"function",
"dotSet",
"(",
"array",
"$",
"array",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"path",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"total",
"=",
"count",
"(",
"$",
"path",
")",
";",
"$",... | Set an array element using dot notation.
Same as `Arr::dotGet()`, but the value is replaced instead of fetched.
@param array $array
@param string $key
@param mixed $value
@throws LackOfCoffeeException | [
"Set",
"an",
"array",
"element",
"using",
"dot",
"notation",
"."
] | c05d9c23d424a6bd5ab2e29140805cc6e37e4623 | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Support/Arr.php#L85-L109 | train |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Support/Arr.php | Arr.walk | public static function walk(
array &$array,
callable $callback,
$recurse = false,
$path = '',
$considerLeaves = true
) {
$path = trim($path, '.');
foreach ($array as $key => $value) {
if (is_array($value) && $recurse) {
if ($considerLeaves === false && !static::hasNested($value)) {
$callback($key, $value, $array, $path);
continue;
}
$deeperPath = $key;
if ($path !== '') {
$deeperPath = vsprintf('%s.%s', [$path, $key]);
}
static::walk(
$array[$key],
$callback,
true,
$deeperPath,
$considerLeaves
);
continue;
}
$callback($key, $value, $array, $path);
}
return $array;
} | php | public static function walk(
array &$array,
callable $callback,
$recurse = false,
$path = '',
$considerLeaves = true
) {
$path = trim($path, '.');
foreach ($array as $key => $value) {
if (is_array($value) && $recurse) {
if ($considerLeaves === false && !static::hasNested($value)) {
$callback($key, $value, $array, $path);
continue;
}
$deeperPath = $key;
if ($path !== '') {
$deeperPath = vsprintf('%s.%s', [$path, $key]);
}
static::walk(
$array[$key],
$callback,
true,
$deeperPath,
$considerLeaves
);
continue;
}
$callback($key, $value, $array, $path);
}
return $array;
} | [
"public",
"static",
"function",
"walk",
"(",
"array",
"&",
"$",
"array",
",",
"callable",
"$",
"callback",
",",
"$",
"recurse",
"=",
"false",
",",
"$",
"path",
"=",
"''",
",",
"$",
"considerLeaves",
"=",
"true",
")",
"{",
"$",
"path",
"=",
"trim",
... | A more complicated, but flexible, version of `array_walk`.
This modified version is useful for flattening arrays without losing
important structure data (how the array is arranged and nested).
Possible applications: flattening complex validation responses or a
configuration file.
Additional features:
- The current path in dot notation is provided to the callback.
- Leaf arrays (no nested arrays) can be optionally ignored.
Callback signature:
```php
$callback($key, $value, $array, $path);
```
@param array $array
@param callable $callback
@param bool $recurse
@param string $path - The current path prefix.
@param bool $considerLeaves
@return array | [
"A",
"more",
"complicated",
"but",
"flexible",
"version",
"of",
"array_walk",
"."
] | c05d9c23d424a6bd5ab2e29140805cc6e37e4623 | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Support/Arr.php#L164-L200 | train |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Support/Arr.php | Arr.filterNullValues | public static function filterNullValues($properties, array $allowed = null)
{
// If provided, only use allowed properties
$properties = static::only($properties, $allowed);
return array_filter(
$properties,
function ($value) {
return !is_null($value);
}
);
} | php | public static function filterNullValues($properties, array $allowed = null)
{
// If provided, only use allowed properties
$properties = static::only($properties, $allowed);
return array_filter(
$properties,
function ($value) {
return !is_null($value);
}
);
} | [
"public",
"static",
"function",
"filterNullValues",
"(",
"$",
"properties",
",",
"array",
"$",
"allowed",
"=",
"null",
")",
"{",
"// If provided, only use allowed properties",
"$",
"properties",
"=",
"static",
"::",
"only",
"(",
"$",
"properties",
",",
"$",
"all... | Get array elements that are not null.
@param array $properties
@param array|null $allowed
@return array | [
"Get",
"array",
"elements",
"that",
"are",
"not",
"null",
"."
] | c05d9c23d424a6bd5ab2e29140805cc6e37e4623 | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Support/Arr.php#L241-L252 | train |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Support/Arr.php | Arr.filterKeys | public static function filterKeys(array $input, $included = [])
{
if (is_null($included) || count($included) == 0) {
return $input;
}
return array_intersect_key($input, array_flip($included));
} | php | public static function filterKeys(array $input, $included = [])
{
if (is_null($included) || count($included) == 0) {
return $input;
}
return array_intersect_key($input, array_flip($included));
} | [
"public",
"static",
"function",
"filterKeys",
"(",
"array",
"$",
"input",
",",
"$",
"included",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"included",
")",
"||",
"count",
"(",
"$",
"included",
")",
"==",
"0",
")",
"{",
"return",
"$",
... | Filter the keys of an array to only the allowed set.
@param array $input
@param array $included
@throws InvalidArgumentException
@return array
@deprecated | [
"Filter",
"the",
"keys",
"of",
"an",
"array",
"to",
"only",
"the",
"allowed",
"set",
"."
] | c05d9c23d424a6bd5ab2e29140805cc6e37e4623 | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Support/Arr.php#L295-L302 | train |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Support/Arr.php | Arr.except | public static function except(array $input, $excluded = [])
{
Arguments::define(Boa::arrOf(Boa::either(
Boa::string(),
Boa::integer()
)))->check($excluded);
return Std::filter(function ($_, $key) use ($excluded) {
return !in_array($key, $excluded);
},
$input);
} | php | public static function except(array $input, $excluded = [])
{
Arguments::define(Boa::arrOf(Boa::either(
Boa::string(),
Boa::integer()
)))->check($excluded);
return Std::filter(function ($_, $key) use ($excluded) {
return !in_array($key, $excluded);
},
$input);
} | [
"public",
"static",
"function",
"except",
"(",
"array",
"$",
"input",
",",
"$",
"excluded",
"=",
"[",
"]",
")",
"{",
"Arguments",
"::",
"define",
"(",
"Boa",
"::",
"arrOf",
"(",
"Boa",
"::",
"either",
"(",
"Boa",
"::",
"string",
"(",
")",
",",
"Boa... | Get a copy of the provided array excluding the specified keys.
@param array $input
@param array $excluded
@throws InvalidArgumentException
@return array | [
"Get",
"a",
"copy",
"of",
"the",
"provided",
"array",
"excluding",
"the",
"specified",
"keys",
"."
] | c05d9c23d424a6bd5ab2e29140805cc6e37e4623 | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Support/Arr.php#L313-L324 | train |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Support/Arr.php | Arr.exchange | public static function exchange(array &$elements, $indexA, $indexB)
{
$count = count($elements);
if (($indexA < 0 || $indexA > ($count - 1))
|| $indexB < 0
|| $indexB > ($count - 1)
) {
throw new IndexOutOfBoundsException();
}
$temp = $elements[$indexA];
$elements[$indexA] = $elements[$indexB];
$elements[$indexB] = $temp;
} | php | public static function exchange(array &$elements, $indexA, $indexB)
{
$count = count($elements);
if (($indexA < 0 || $indexA > ($count - 1))
|| $indexB < 0
|| $indexB > ($count - 1)
) {
throw new IndexOutOfBoundsException();
}
$temp = $elements[$indexA];
$elements[$indexA] = $elements[$indexB];
$elements[$indexB] = $temp;
} | [
"public",
"static",
"function",
"exchange",
"(",
"array",
"&",
"$",
"elements",
",",
"$",
"indexA",
",",
"$",
"indexB",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"elements",
")",
";",
"if",
"(",
"(",
"$",
"indexA",
"<",
"0",
"||",
"$",
"ind... | Exchange two elements in an array.
@param array $elements
@param int $indexA
@param int $indexB
@throws IndexOutOfBoundsException | [
"Exchange",
"two",
"elements",
"in",
"an",
"array",
"."
] | c05d9c23d424a6bd5ab2e29140805cc6e37e4623 | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Support/Arr.php#L357-L373 | train |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Support/Arr.php | Arr.indexOf | public static function indexOf(array $input, $value)
{
foreach ($input as $key => $inputValue) {
if ($inputValue === $value) {
return $key;
}
}
return false;
} | php | public static function indexOf(array $input, $value)
{
foreach ($input as $key => $inputValue) {
if ($inputValue === $value) {
return $key;
}
}
return false;
} | [
"public",
"static",
"function",
"indexOf",
"(",
"array",
"$",
"input",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"input",
"as",
"$",
"key",
"=>",
"$",
"inputValue",
")",
"{",
"if",
"(",
"$",
"inputValue",
"===",
"$",
"value",
")",
"{",
"ret... | Returns the index of the first occurrence of a value in the provided
array.
If the value is not found, false is returned.
@param array $input
@param mixed $value
@return int|string|bool | [
"Returns",
"the",
"index",
"of",
"the",
"first",
"occurrence",
"of",
"a",
"value",
"in",
"the",
"provided",
"array",
"."
] | c05d9c23d424a6bd5ab2e29140805cc6e37e4623 | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Support/Arr.php#L541-L550 | train |
pletfix/core | src/Services/CacheFactory.php | CacheFactory.store | public function store($name = null)
{
if (is_null($name)) {
$name = $this->defaultStore;
}
if (isset($this->caches[$name])) {
return $this->caches[$name];
}
$config = config('cache.stores.' . $name);
if ($config === null) {
throw new InvalidArgumentException('Cache store "' . $name . '" is not defined.');
}
if (!isset($config['driver'])) {
throw new InvalidArgumentException('Cache driver for store "' . $name . '" is not specified.');
}
switch ($config['driver']) {
case 'APCu':
$provider = new ApcuCache;
break;
case 'Array':
$provider = new ArrayCache;
break;
case 'File':
$provider = new FilesystemCache($config['path']);
break;
case 'Memcached':
$memcached = new Memcached();
$memcached->addServer($config['host'], $config['port'], $config['weight']);
$provider = new MemcachedCache();
$provider->setMemcached($memcached);
break;
case 'Redis':
$redis = new Redis;
$redis->connect($config['host'], $config['port'], $config['timeout']);
$provider = new RedisCache;
$provider->setRedis($redis);
break;
default:
throw new InvalidArgumentException('Cache driver "' . $config['driver'] . '" is not supported.');
}
return $this->caches[$name] = new Cache($provider);
} | php | public function store($name = null)
{
if (is_null($name)) {
$name = $this->defaultStore;
}
if (isset($this->caches[$name])) {
return $this->caches[$name];
}
$config = config('cache.stores.' . $name);
if ($config === null) {
throw new InvalidArgumentException('Cache store "' . $name . '" is not defined.');
}
if (!isset($config['driver'])) {
throw new InvalidArgumentException('Cache driver for store "' . $name . '" is not specified.');
}
switch ($config['driver']) {
case 'APCu':
$provider = new ApcuCache;
break;
case 'Array':
$provider = new ArrayCache;
break;
case 'File':
$provider = new FilesystemCache($config['path']);
break;
case 'Memcached':
$memcached = new Memcached();
$memcached->addServer($config['host'], $config['port'], $config['weight']);
$provider = new MemcachedCache();
$provider->setMemcached($memcached);
break;
case 'Redis':
$redis = new Redis;
$redis->connect($config['host'], $config['port'], $config['timeout']);
$provider = new RedisCache;
$provider->setRedis($redis);
break;
default:
throw new InvalidArgumentException('Cache driver "' . $config['driver'] . '" is not supported.');
}
return $this->caches[$name] = new Cache($provider);
} | [
"public",
"function",
"store",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"defaultStore",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"caches",
... | Get a Cache instance by given store name.
@param string|null $name
@return \Core\Services\Contracts\Cache
@throws \InvalidArgumentException | [
"Get",
"a",
"Cache",
"instance",
"by",
"given",
"store",
"name",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Services/CacheFactory.php#L58-L104 | train |
dflydev/dflydev-github-gist-twig-extension | src/Dflydev/Twig/Extension/GitHubGist/Cache/FilesystemCache.php | FilesystemCache.generatePathname | protected function generatePathname($id)
{
if (!file_exists($this->basePath)) {
mkdir($this->basePath, 0777, true);
}
return $this->basePath.'/'.$id;
} | php | protected function generatePathname($id)
{
if (!file_exists($this->basePath)) {
mkdir($this->basePath, 0777, true);
}
return $this->basePath.'/'.$id;
} | [
"protected",
"function",
"generatePathname",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"basePath",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"basePath",
",",
"0777",
",",
"true",
")",
";",
"}",
"return",
... | Generate a pathname for an ID
@param string $id ID
@return string | [
"Generate",
"a",
"pathname",
"for",
"an",
"ID"
] | c324152707397472bed8548ca98cee6c12f215f0 | https://github.com/dflydev/dflydev-github-gist-twig-extension/blob/c324152707397472bed8548ca98cee6c12f215f0/src/Dflydev/Twig/Extension/GitHubGist/Cache/FilesystemCache.php#L77-L84 | train |
mvccore/ext-form | src/MvcCore/Ext/Forms/Field/Props/GroupCssClasses.php | GroupLabelCssClasses.& | public function & SetGroupLabelCssClasses ($groupLabelCssClasses) {
/** @var $this \MvcCore\Ext\Forms\IField */
if (gettype($groupLabelCssClasses) == 'array') {
$this->groupLabelCssClasses = $groupLabelCssClasses;
} else {
$this->groupLabelCssClasses = explode(' ', (string) $groupLabelCssClasses);
}
return $this;
} | php | public function & SetGroupLabelCssClasses ($groupLabelCssClasses) {
/** @var $this \MvcCore\Ext\Forms\IField */
if (gettype($groupLabelCssClasses) == 'array') {
$this->groupLabelCssClasses = $groupLabelCssClasses;
} else {
$this->groupLabelCssClasses = explode(' ', (string) $groupLabelCssClasses);
}
return $this;
} | [
"public",
"function",
"&",
"SetGroupLabelCssClasses",
"(",
"$",
"groupLabelCssClasses",
")",
"{",
"/** @var $this \\MvcCore\\Ext\\Forms\\IField */",
"if",
"(",
"gettype",
"(",
"$",
"groupLabelCssClasses",
")",
"==",
"'array'",
")",
"{",
"$",
"this",
"->",
"groupLabelC... | Set css class or classes for group label,
as array of strings or string with classes
separated by space. Any previously defined
group css classes will be replaced.
@param string|\string[] $groupLabelCssClasses
@return \MvcCore\Ext\Forms\Field|\MvcCore\Ext\Forms\IField | [
"Set",
"css",
"class",
"or",
"classes",
"for",
"group",
"label",
"as",
"array",
"of",
"strings",
"or",
"string",
"with",
"classes",
"separated",
"by",
"space",
".",
"Any",
"previously",
"defined",
"group",
"css",
"classes",
"will",
"be",
"replaced",
"."
] | 8d81a3c7326236702f37dc4b9d968907b3230b9f | https://github.com/mvccore/ext-form/blob/8d81a3c7326236702f37dc4b9d968907b3230b9f/src/MvcCore/Ext/Forms/Field/Props/GroupCssClasses.php#L46-L54 | train |
mvccore/ext-form | src/MvcCore/Ext/Forms/Field/Props/GroupCssClasses.php | GroupLabelCssClasses.AddGroupLabelCssClasses | public function AddGroupLabelCssClasses ($groupLabelCssClasses) {
/** @var $this \MvcCore\Ext\Forms\IField */
if (gettype($groupLabelCssClasses) == 'array') {
$groupCssClasses = $groupLabelCssClasses;
} else {
$groupCssClasses = explode(' ', (string) $groupLabelCssClasses);
}
$this->groupLabelCssClasses = array_merge($this->groupLabelCssClasses, $groupCssClasses);
return $this;
} | php | public function AddGroupLabelCssClasses ($groupLabelCssClasses) {
/** @var $this \MvcCore\Ext\Forms\IField */
if (gettype($groupLabelCssClasses) == 'array') {
$groupCssClasses = $groupLabelCssClasses;
} else {
$groupCssClasses = explode(' ', (string) $groupLabelCssClasses);
}
$this->groupLabelCssClasses = array_merge($this->groupLabelCssClasses, $groupCssClasses);
return $this;
} | [
"public",
"function",
"AddGroupLabelCssClasses",
"(",
"$",
"groupLabelCssClasses",
")",
"{",
"/** @var $this \\MvcCore\\Ext\\Forms\\IField */",
"if",
"(",
"gettype",
"(",
"$",
"groupLabelCssClasses",
")",
"==",
"'array'",
")",
"{",
"$",
"groupCssClasses",
"=",
"$",
"g... | Add css class or classes for group label as array of
strings or string with classes separated by space.
@param string|\string[] $groupLabelCssClasses
@return \MvcCore\Ext\Forms\Field|\MvcCore\Ext\Forms\IField | [
"Add",
"css",
"class",
"or",
"classes",
"for",
"group",
"label",
"as",
"array",
"of",
"strings",
"or",
"string",
"with",
"classes",
"separated",
"by",
"space",
"."
] | 8d81a3c7326236702f37dc4b9d968907b3230b9f | https://github.com/mvccore/ext-form/blob/8d81a3c7326236702f37dc4b9d968907b3230b9f/src/MvcCore/Ext/Forms/Field/Props/GroupCssClasses.php#L62-L71 | train |
phergie/phergie-irc-plugin-react-usermode | src/Plugin.php | Plugin.changeUserMode | public function changeUserMode(EventInterface $event, EventQueueInterface $queue)
{
$logger = $this->getLogger();
$params = $event->getParams();
$logger->debug('Changing user mode', array('params' => $params));
// Disregard mode changes without both an associated channel and user
if (!isset($params['channel']) || !isset($params['user'])) {
$logger->debug('Missing channel or user, skipping');
return;
}
$connectionMask = $this->getConnectionMask($event->getConnection());
$channel = $params['channel'];
$nick = $params['user'];
$modes = str_split($params['mode']);
$operation = array_shift($modes);
$logger->debug('Extracted event data', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
'nick' => $nick,
'operation' => $operation,
'modes' => $modes,
));
foreach ($modes as $mode) {
switch ($operation) {
case '+':
if (!isset($this->modes[$connectionMask])) {
$this->modes[$connectionMask] = array();
}
if (!isset($this->modes[$connectionMask][$channel])) {
$this->modes[$connectionMask][$channel] = array();
}
if (!isset($this->modes[$connectionMask][$channel][$nick])) {
$this->modes[$connectionMask][$channel][$nick] = array();
}
$this->modes[$connectionMask][$channel][$nick][$mode] = true;
break;
case '-':
unset($this->modes[$connectionMask][$channel][$nick][$mode]);
break;
default:
$logger->warning('Encountered unknown operation', array(
'operation' => $operation,
));
break;
}
}
} | php | public function changeUserMode(EventInterface $event, EventQueueInterface $queue)
{
$logger = $this->getLogger();
$params = $event->getParams();
$logger->debug('Changing user mode', array('params' => $params));
// Disregard mode changes without both an associated channel and user
if (!isset($params['channel']) || !isset($params['user'])) {
$logger->debug('Missing channel or user, skipping');
return;
}
$connectionMask = $this->getConnectionMask($event->getConnection());
$channel = $params['channel'];
$nick = $params['user'];
$modes = str_split($params['mode']);
$operation = array_shift($modes);
$logger->debug('Extracted event data', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
'nick' => $nick,
'operation' => $operation,
'modes' => $modes,
));
foreach ($modes as $mode) {
switch ($operation) {
case '+':
if (!isset($this->modes[$connectionMask])) {
$this->modes[$connectionMask] = array();
}
if (!isset($this->modes[$connectionMask][$channel])) {
$this->modes[$connectionMask][$channel] = array();
}
if (!isset($this->modes[$connectionMask][$channel][$nick])) {
$this->modes[$connectionMask][$channel][$nick] = array();
}
$this->modes[$connectionMask][$channel][$nick][$mode] = true;
break;
case '-':
unset($this->modes[$connectionMask][$channel][$nick][$mode]);
break;
default:
$logger->warning('Encountered unknown operation', array(
'operation' => $operation,
));
break;
}
}
} | [
"public",
"function",
"changeUserMode",
"(",
"EventInterface",
"$",
"event",
",",
"EventQueueInterface",
"$",
"queue",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"getLogger",
"(",
")",
";",
"$",
"params",
"=",
"$",
"event",
"->",
"getParams",
"(",
... | Monitors use mode changes.
@param \Phergie\Irc\Event\EventInterface $event
@param \Phergie\Irc\Bot\React\EventQueueInterface $queue | [
"Monitors",
"use",
"mode",
"changes",
"."
] | 4bf3b75cda6f4dd66513ee4d62b0a436e24645e5 | https://github.com/phergie/phergie-irc-plugin-react-usermode/blob/4bf3b75cda6f4dd66513ee4d62b0a436e24645e5/src/Plugin.php#L89-L140 | train |
phergie/phergie-irc-plugin-react-usermode | src/Plugin.php | Plugin.removeUserData | protected function removeUserData($connectionMask, array $channels, $nick)
{
$logger = $this->getLogger();
foreach ($channels as $channel) {
$logger->debug('Removing user mode data', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
'nick' => $nick,
));
unset($this->modes[$connectionMask][$channel][$nick]);
}
} | php | protected function removeUserData($connectionMask, array $channels, $nick)
{
$logger = $this->getLogger();
foreach ($channels as $channel) {
$logger->debug('Removing user mode data', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
'nick' => $nick,
));
unset($this->modes[$connectionMask][$channel][$nick]);
}
} | [
"protected",
"function",
"removeUserData",
"(",
"$",
"connectionMask",
",",
"array",
"$",
"channels",
",",
"$",
"nick",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"getLogger",
"(",
")",
";",
"foreach",
"(",
"$",
"channels",
"as",
"$",
"channel",
... | Removes mode data for a user and list of channels.
@param string $connectionMask
@param array $channels
@param string $nick | [
"Removes",
"mode",
"data",
"for",
"a",
"user",
"and",
"list",
"of",
"channels",
"."
] | 4bf3b75cda6f4dd66513ee4d62b0a436e24645e5 | https://github.com/phergie/phergie-irc-plugin-react-usermode/blob/4bf3b75cda6f4dd66513ee4d62b0a436e24645e5/src/Plugin.php#L188-L199 | train |
phergie/phergie-irc-plugin-react-usermode | src/Plugin.php | Plugin.changeUserNick | public function changeUserNick(UserEventInterface $event, EventQueueInterface $queue)
{
$logger = $this->getLogger();
$connectionMask = $this->getConnectionMask($event->getConnection());
$old = $event->getNick();
$params = $event->getParams();
$new = $params['nickname'];
$logger->debug('Changing user nick', array(
'connectionMask' => $connectionMask,
'oldNick' => $old,
'newNick' => $new,
));
foreach (array_keys($this->modes[$connectionMask]) as $channel) {
if (!isset($this->modes[$connectionMask][$channel][$old])) {
continue;
}
$logger->debug('Moving user mode data', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
'oldNick' => $old,
'newNick' => $new,
));
$this->modes[$connectionMask][$channel][$new] = $this->modes[$connectionMask][$channel][$old];
unset($this->modes[$connectionMask][$channel][$old]);
}
} | php | public function changeUserNick(UserEventInterface $event, EventQueueInterface $queue)
{
$logger = $this->getLogger();
$connectionMask = $this->getConnectionMask($event->getConnection());
$old = $event->getNick();
$params = $event->getParams();
$new = $params['nickname'];
$logger->debug('Changing user nick', array(
'connectionMask' => $connectionMask,
'oldNick' => $old,
'newNick' => $new,
));
foreach (array_keys($this->modes[$connectionMask]) as $channel) {
if (!isset($this->modes[$connectionMask][$channel][$old])) {
continue;
}
$logger->debug('Moving user mode data', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
'oldNick' => $old,
'newNick' => $new,
));
$this->modes[$connectionMask][$channel][$new] = $this->modes[$connectionMask][$channel][$old];
unset($this->modes[$connectionMask][$channel][$old]);
}
} | [
"public",
"function",
"changeUserNick",
"(",
"UserEventInterface",
"$",
"event",
",",
"EventQueueInterface",
"$",
"queue",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"getLogger",
"(",
")",
";",
"$",
"connectionMask",
"=",
"$",
"this",
"->",
"getConnect... | Accounts for user nick changes in stored data.
@param \Phergie\Irc\Event\EventInterface $event
@param \Phergie\Irc\Bot\React\EventQueueInterface $queue | [
"Accounts",
"for",
"user",
"nick",
"changes",
"in",
"stored",
"data",
"."
] | 4bf3b75cda6f4dd66513ee4d62b0a436e24645e5 | https://github.com/phergie/phergie-irc-plugin-react-usermode/blob/4bf3b75cda6f4dd66513ee4d62b0a436e24645e5/src/Plugin.php#L207-L234 | train |
phergie/phergie-irc-plugin-react-usermode | src/Plugin.php | Plugin.loadUserModes | public function loadUserModes(EventInterface $event, EventQueueInterface $queue)
{
$logger = $this->getLogger();
$connectionMask = $this->getConnectionMask($event->getConnection());
$params = $event->getParams();
$channel = $params[1];
$validPrefixes = implode('', array_keys($this->prefixes));
$pattern = '/^([' . preg_quote($validPrefixes) . ']+)(.+)$/';
$logger->debug('Gathering initial user mode data', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
));
foreach ($params['iterable'] as $fullNick) {
if (!preg_match($pattern, $fullNick, $match)) {
continue;
}
$nickPrefixes = str_split($match[1]);
$nick = $match[2];
foreach ($nickPrefixes as $prefix) {
$mode = $this->prefixes[$prefix];
$logger->debug('Recording user mode', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
'nick' => $nick,
'mode' => $mode,
));
$this->modes[$connectionMask][$channel][$nick][$mode] = true;
}
}
} | php | public function loadUserModes(EventInterface $event, EventQueueInterface $queue)
{
$logger = $this->getLogger();
$connectionMask = $this->getConnectionMask($event->getConnection());
$params = $event->getParams();
$channel = $params[1];
$validPrefixes = implode('', array_keys($this->prefixes));
$pattern = '/^([' . preg_quote($validPrefixes) . ']+)(.+)$/';
$logger->debug('Gathering initial user mode data', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
));
foreach ($params['iterable'] as $fullNick) {
if (!preg_match($pattern, $fullNick, $match)) {
continue;
}
$nickPrefixes = str_split($match[1]);
$nick = $match[2];
foreach ($nickPrefixes as $prefix) {
$mode = $this->prefixes[$prefix];
$logger->debug('Recording user mode', array(
'connectionMask' => $connectionMask,
'channel' => $channel,
'nick' => $nick,
'mode' => $mode,
));
$this->modes[$connectionMask][$channel][$nick][$mode] = true;
}
}
} | [
"public",
"function",
"loadUserModes",
"(",
"EventInterface",
"$",
"event",
",",
"EventQueueInterface",
"$",
"queue",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"getLogger",
"(",
")",
";",
"$",
"connectionMask",
"=",
"$",
"this",
"->",
"getConnectionMa... | Loads initial user mode data when the bot joins a channel.
@param \Phergie\Irc\Event\EventInterface $event
@param \Phergie\Irc\Bot\React\EventQueueInterface $queue | [
"Loads",
"initial",
"user",
"mode",
"data",
"when",
"the",
"bot",
"joins",
"a",
"channel",
"."
] | 4bf3b75cda6f4dd66513ee4d62b0a436e24645e5 | https://github.com/phergie/phergie-irc-plugin-react-usermode/blob/4bf3b75cda6f4dd66513ee4d62b0a436e24645e5/src/Plugin.php#L242-L273 | train |
phergie/phergie-irc-plugin-react-usermode | src/Plugin.php | Plugin.userHasMode | public function userHasMode(ConnectionInterface $connection, $channel, $nick, $mode)
{
$connectionMask = $this->getConnectionMask($connection);
return isset($this->modes[$connectionMask][$channel][$nick][$mode]);
} | php | public function userHasMode(ConnectionInterface $connection, $channel, $nick, $mode)
{
$connectionMask = $this->getConnectionMask($connection);
return isset($this->modes[$connectionMask][$channel][$nick][$mode]);
} | [
"public",
"function",
"userHasMode",
"(",
"ConnectionInterface",
"$",
"connection",
",",
"$",
"channel",
",",
"$",
"nick",
",",
"$",
"mode",
")",
"{",
"$",
"connectionMask",
"=",
"$",
"this",
"->",
"getConnectionMask",
"(",
"$",
"connection",
")",
";",
"re... | Returns whether a user has a particular mode in a particular channel.
@param \Phergie\Irc\ConnectionInterface $connection
@param string $channel
@param string $nick
@param string $mode
@return boolean | [
"Returns",
"whether",
"a",
"user",
"has",
"a",
"particular",
"mode",
"in",
"a",
"particular",
"channel",
"."
] | 4bf3b75cda6f4dd66513ee4d62b0a436e24645e5 | https://github.com/phergie/phergie-irc-plugin-react-usermode/blob/4bf3b75cda6f4dd66513ee4d62b0a436e24645e5/src/Plugin.php#L284-L288 | train |
phergie/phergie-irc-plugin-react-usermode | src/Plugin.php | Plugin.getUserModes | public function getUserModes(ConnectionInterface $connection, $channel, $nick)
{
$connectionMask = $this->getConnectionMask($connection);
if (isset($this->modes[$connectionMask][$channel][$nick])) {
return array_keys($this->modes[$connectionMask][$channel][$nick]);
}
return array();
} | php | public function getUserModes(ConnectionInterface $connection, $channel, $nick)
{
$connectionMask = $this->getConnectionMask($connection);
if (isset($this->modes[$connectionMask][$channel][$nick])) {
return array_keys($this->modes[$connectionMask][$channel][$nick]);
}
return array();
} | [
"public",
"function",
"getUserModes",
"(",
"ConnectionInterface",
"$",
"connection",
",",
"$",
"channel",
",",
"$",
"nick",
")",
"{",
"$",
"connectionMask",
"=",
"$",
"this",
"->",
"getConnectionMask",
"(",
"$",
"connection",
")",
";",
"if",
"(",
"isset",
... | Returns a list of modes for a user in a particular channel.
@param \Phergie\Irc\ConnectionInterface $connection
@param string $channel
@param string $nick
@return array Enumerated array of mode letters or an empty array if the
user has no modes in the specified channel | [
"Returns",
"a",
"list",
"of",
"modes",
"for",
"a",
"user",
"in",
"a",
"particular",
"channel",
"."
] | 4bf3b75cda6f4dd66513ee4d62b0a436e24645e5 | https://github.com/phergie/phergie-irc-plugin-react-usermode/blob/4bf3b75cda6f4dd66513ee4d62b0a436e24645e5/src/Plugin.php#L299-L306 | train |
phergie/phergie-irc-plugin-react-usermode | src/Plugin.php | Plugin.getConnectionMask | protected function getConnectionMask(ConnectionInterface $connection)
{
return strtolower(sprintf(
'%s!%s@%s',
$connection->getNickname(),
$connection->getUsername(),
$connection->getServerHostname()
));
} | php | protected function getConnectionMask(ConnectionInterface $connection)
{
return strtolower(sprintf(
'%s!%s@%s',
$connection->getNickname(),
$connection->getUsername(),
$connection->getServerHostname()
));
} | [
"protected",
"function",
"getConnectionMask",
"(",
"ConnectionInterface",
"$",
"connection",
")",
"{",
"return",
"strtolower",
"(",
"sprintf",
"(",
"'%s!%s@%s'",
",",
"$",
"connection",
"->",
"getNickname",
"(",
")",
",",
"$",
"connection",
"->",
"getUsername",
... | Returns the mask string for a given connection.
@param \Phergie\Irc\ConnectionInterface $connection
@return string | [
"Returns",
"the",
"mask",
"string",
"for",
"a",
"given",
"connection",
"."
] | 4bf3b75cda6f4dd66513ee4d62b0a436e24645e5 | https://github.com/phergie/phergie-irc-plugin-react-usermode/blob/4bf3b75cda6f4dd66513ee4d62b0a436e24645e5/src/Plugin.php#L314-L322 | train |
twister-php/twister | src/Container.php | Container.make | public function make(string $name, array $params = null)
{
if (isset($this->bindings[$name]))
return $this->bindings[$name];
// cached constructor lists
static $constructors = null;
if (isset($constructors[$name])) {
$constructor = $constructors[$name];
}
else {
$constructors[$name] = $constructor = method_exists($name, '__construct') ? new \ReflectionMethod($name, '__construct') : null;
}
return $constructor ?
(new \ReflectionClass($name))->newInstanceArgs($this->_buildArgList($constructor, $params)) :
(new \ReflectionClass($name))->newInstance();
} | php | public function make(string $name, array $params = null)
{
if (isset($this->bindings[$name]))
return $this->bindings[$name];
// cached constructor lists
static $constructors = null;
if (isset($constructors[$name])) {
$constructor = $constructors[$name];
}
else {
$constructors[$name] = $constructor = method_exists($name, '__construct') ? new \ReflectionMethod($name, '__construct') : null;
}
return $constructor ?
(new \ReflectionClass($name))->newInstanceArgs($this->_buildArgList($constructor, $params)) :
(new \ReflectionClass($name))->newInstance();
} | [
"public",
"function",
"make",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"params",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"bindings",
"[",
"$",
"name",
"]",
")",
")",
"return",
"$",
"this",
"->",
"bindings",
"[",
"... | Build an object by its name.
This method behaves like get() except resolves the entry again every time.
For example if the entry is a class then a new instance will be created each time.
This method makes the container behave like a factory.
@param string $name Entry name or a class name.
@param array $parameters Optional parameters to use to build the entry.
Use this to force specific parameters to specific values.
Parameters not defined in this array will be resolved using the container.
@throws InvalidArgumentException The name parameter must be of type string.
@throws DependencyException Error while resolving the entry.
@throws NotFoundException No entry found for the given name.
@return mixed | [
"Build",
"an",
"object",
"by",
"its",
"name",
"."
] | c06ea2650331faf11590c017c850dc5f0bbc5c13 | https://github.com/twister-php/twister/blob/c06ea2650331faf11590c017c850dc5f0bbc5c13/src/Container.php#L176-L194 | train |
FuturaSoft/Pabana | src/Core/Configuration.php | Configuration.base | public static function base()
{
// Charset by default
self::write('application.encoding', 'UTF8');
// Application environnement
self::write('application.env', 'dev');
// Application name
self::write('application.name', 'Awesome Application');
// Namespace for application
self::write('application.namespace', '\App');
// Absolute path to application
self::write('application.path', 'auto');
// Defined if bootstrap is use by application
self::write('bootstrap.enable', true);
// Set config file for route collection
self::write('database.config.enable', true);
// Set config file for route collection
self::write('database.config.file', 'databases.php');
// Set debug level to all
self::write('debug.level', E_ALL);
// Define if script file existence is tested
self::write('html.script.test_file_existance', true);
// Define if css file existence is tested
self::write('html.css.test_file_existance', true);
// Set autoloading of shared var between componant
self::write('mvc.autoload_shared_var', true);
// Set namespace for controller
self::write('mvc.controller.namespace', '\App\Controller');
// Set namespace for layout
self::write('mvc.layout.namespace', '\App\Layout');
// Set path for Layout
self::write('mvc.layout.path', '/src/Layout');
// Set default layout
self::write('mvc.layout.default', 'Application');
// Set extension for layout
self::write('mvc.layout.extension', 'php');
// Set auto render for layout
self::write('mvc.layout.auto_render', true);
// Set namespace for model
self::write('mvc.model.namespace', '\App\Model');
// Set auto render for view
self::write('mvc.view.auto_render', true);
// Set extension for view
self::write('mvc.view.extension', 'php');
// Set path for view
self::write('mvc.view.path', '/src/View');
// Set auto routing
self::write('routing.auto', true);
// Set config file for route collection
self::write('routing.config.enable', true);
// Set config file for route collection
self::write('routing.config.file', 'routes.php');
// Set error action (if not route is avaiable)
self::write('routing.fallback.action', 'index');
// Set error controller (if not route is avaiable)
self::write('routing.fallback.controller', 'Error');
// Set config file for route collection
self::write('routing.default_separator', '/');
} | php | public static function base()
{
// Charset by default
self::write('application.encoding', 'UTF8');
// Application environnement
self::write('application.env', 'dev');
// Application name
self::write('application.name', 'Awesome Application');
// Namespace for application
self::write('application.namespace', '\App');
// Absolute path to application
self::write('application.path', 'auto');
// Defined if bootstrap is use by application
self::write('bootstrap.enable', true);
// Set config file for route collection
self::write('database.config.enable', true);
// Set config file for route collection
self::write('database.config.file', 'databases.php');
// Set debug level to all
self::write('debug.level', E_ALL);
// Define if script file existence is tested
self::write('html.script.test_file_existance', true);
// Define if css file existence is tested
self::write('html.css.test_file_existance', true);
// Set autoloading of shared var between componant
self::write('mvc.autoload_shared_var', true);
// Set namespace for controller
self::write('mvc.controller.namespace', '\App\Controller');
// Set namespace for layout
self::write('mvc.layout.namespace', '\App\Layout');
// Set path for Layout
self::write('mvc.layout.path', '/src/Layout');
// Set default layout
self::write('mvc.layout.default', 'Application');
// Set extension for layout
self::write('mvc.layout.extension', 'php');
// Set auto render for layout
self::write('mvc.layout.auto_render', true);
// Set namespace for model
self::write('mvc.model.namespace', '\App\Model');
// Set auto render for view
self::write('mvc.view.auto_render', true);
// Set extension for view
self::write('mvc.view.extension', 'php');
// Set path for view
self::write('mvc.view.path', '/src/View');
// Set auto routing
self::write('routing.auto', true);
// Set config file for route collection
self::write('routing.config.enable', true);
// Set config file for route collection
self::write('routing.config.file', 'routes.php');
// Set error action (if not route is avaiable)
self::write('routing.fallback.action', 'index');
// Set error controller (if not route is avaiable)
self::write('routing.fallback.controller', 'Error');
// Set config file for route collection
self::write('routing.default_separator', '/');
} | [
"public",
"static",
"function",
"base",
"(",
")",
"{",
"// Charset by default",
"self",
"::",
"write",
"(",
"'application.encoding'",
",",
"'UTF8'",
")",
";",
"// Application environnement",
"self",
"::",
"write",
"(",
"'application.env'",
",",
"'dev'",
")",
";",
... | Get base configuration of Pabana
This method defined default key and value for using Pabana
@since 1.0
@return void | [
"Get",
"base",
"configuration",
"of",
"Pabana"
] | b3a95eeb976042ac2a393cc10755a7adbc164c24 | https://github.com/FuturaSoft/Pabana/blob/b3a95eeb976042ac2a393cc10755a7adbc164c24/src/Core/Configuration.php#L40-L98 | train |
FuturaSoft/Pabana | src/Core/Configuration.php | Configuration.prepare | public static function prepare($key, $value)
{
if ($value == 'true') {
return true;
} elseif ($value == 'false') {
return false;
} elseif ($key == 'debug.level' && substr($value, 0, 2) == "E_") {
return eval('return ' . $value . ';');
} elseif ($key == 'application.path' && ($value === false || $value === 'false' || $value === 'auto')) {
$sLibraryPath = DS . 'vendor' . DS . 'pabana' . DS . 'pabana' . DS . 'src' . DS . 'Core';
return str_replace($sLibraryPath, '', __DIR__);
}
return $value;
} | php | public static function prepare($key, $value)
{
if ($value == 'true') {
return true;
} elseif ($value == 'false') {
return false;
} elseif ($key == 'debug.level' && substr($value, 0, 2) == "E_") {
return eval('return ' . $value . ';');
} elseif ($key == 'application.path' && ($value === false || $value === 'false' || $value === 'auto')) {
$sLibraryPath = DS . 'vendor' . DS . 'pabana' . DS . 'pabana' . DS . 'src' . DS . 'Core';
return str_replace($sLibraryPath, '', __DIR__);
}
return $value;
} | [
"public",
"static",
"function",
"prepare",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"'true'",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"$",
"value",
"==",
"'false'",
")",
"{",
"return",
"false",
";",
... | Prepare a configuration value
This method is used to modify a configuration value
For exemple change 'true' string to true boolean
@since 1.0
@param string $key Key to prepare
@param mixed $value Value to prepare.
@return mixed Value prepared | [
"Prepare",
"a",
"configuration",
"value"
] | b3a95eeb976042ac2a393cc10755a7adbc164c24 | https://github.com/FuturaSoft/Pabana/blob/b3a95eeb976042ac2a393cc10755a7adbc164c24/src/Core/Configuration.php#L216-L229 | train |
FuturaSoft/Pabana | src/Core/Configuration.php | Configuration.prepareArray | public static function prepareArray($configList)
{
$preparedConfigList = array();
foreach ($configList as $key => $value) {
$preparedConfigList[$key] = self::prepare($key, $value);
}
return $preparedConfigList;
} | php | public static function prepareArray($configList)
{
$preparedConfigList = array();
foreach ($configList as $key => $value) {
$preparedConfigList[$key] = self::prepare($key, $value);
}
return $preparedConfigList;
} | [
"public",
"static",
"function",
"prepareArray",
"(",
"$",
"configList",
")",
"{",
"$",
"preparedConfigList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"configList",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"preparedConfigList",
"[",
"... | Prepare a configuration array
Parse array and prepare all of their value
@since 1.0
@param array $configList Array of key and value to prepare
@return array Array of key and value prepared | [
"Prepare",
"a",
"configuration",
"array"
] | b3a95eeb976042ac2a393cc10755a7adbc164c24 | https://github.com/FuturaSoft/Pabana/blob/b3a95eeb976042ac2a393cc10755a7adbc164c24/src/Core/Configuration.php#L240-L247 | train |
FuturaSoft/Pabana | src/Core/Configuration.php | Configuration.read | public static function read($key)
{
// Check key existence
if (!self::check($key)) {
throw new \Exception('Configuration key "' . $key . '" doesn\'t exists');
return false;
}
// Get value of key
return self::$configList[$key];
} | php | public static function read($key)
{
// Check key existence
if (!self::check($key)) {
throw new \Exception('Configuration key "' . $key . '" doesn\'t exists');
return false;
}
// Get value of key
return self::$configList[$key];
} | [
"public",
"static",
"function",
"read",
"(",
"$",
"key",
")",
"{",
"// Check key existence",
"if",
"(",
"!",
"self",
"::",
"check",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Configuration key \"'",
".",
"$",
"key",
".",
... | Read a configuration key
This method is used to read a key from Configuration
Key existance is checked first
@since 1.0
@param string $key Key to read.
@return mixed|bool Value of Configuration parameter or false if configuration key doesn't exist | [
"Read",
"a",
"configuration",
"key"
] | b3a95eeb976042ac2a393cc10755a7adbc164c24 | https://github.com/FuturaSoft/Pabana/blob/b3a95eeb976042ac2a393cc10755a7adbc164c24/src/Core/Configuration.php#L259-L268 | train |
FuturaSoft/Pabana | src/Core/Configuration.php | Configuration.write | public static function write($key, $value, $force = true)
{
// Check key existence
if (self::check($key) && $force === false) {
throw new \Exception('Configuration key "' . $key . '" already exist (use force argument to modify an already defined key).');
return false;
}
// Prepare value (transform 'true' to true, etc...)
$preparedValue = self::prepare($key, $value);
// Write value content
self::$configList[$key] = $preparedValue;
return true;
} | php | public static function write($key, $value, $force = true)
{
// Check key existence
if (self::check($key) && $force === false) {
throw new \Exception('Configuration key "' . $key . '" already exist (use force argument to modify an already defined key).');
return false;
}
// Prepare value (transform 'true' to true, etc...)
$preparedValue = self::prepare($key, $value);
// Write value content
self::$configList[$key] = $preparedValue;
return true;
} | [
"public",
"static",
"function",
"write",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"force",
"=",
"true",
")",
"{",
"// Check key existence",
"if",
"(",
"self",
"::",
"check",
"(",
"$",
"key",
")",
"&&",
"$",
"force",
"===",
"false",
")",
"{",
"... | Write a configuration key
This method is used to write a key and a value
First value is prepare by prepare method
@since 1.0
@param string $key Key to read.
@param string $value Value of key.
@param bool $force Force writing of key even is already defined.
@return bool Return true if success else return false;. | [
"Write",
"a",
"configuration",
"key"
] | b3a95eeb976042ac2a393cc10755a7adbc164c24 | https://github.com/FuturaSoft/Pabana/blob/b3a95eeb976042ac2a393cc10755a7adbc164c24/src/Core/Configuration.php#L334-L346 | train |
undefined-exception-coders/UECMediaBundle | Path/MediaPathGenerator.php | MediaPathGenerator.generate | public function generate(MediaProviderInterface $mediaProvider)
{
$path = rtrim($this->basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR .
$mediaProvider->getMedia()->getContext() . DIRECTORY_SEPARATOR .
date('Y') . DIRECTORY_SEPARATOR .
date('m') . DIRECTORY_SEPARATOR .
date('d')
;
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
return $path;
} | php | public function generate(MediaProviderInterface $mediaProvider)
{
$path = rtrim($this->basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR .
$mediaProvider->getMedia()->getContext() . DIRECTORY_SEPARATOR .
date('Y') . DIRECTORY_SEPARATOR .
date('m') . DIRECTORY_SEPARATOR .
date('d')
;
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
return $path;
} | [
"public",
"function",
"generate",
"(",
"MediaProviderInterface",
"$",
"mediaProvider",
")",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"basePath",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"mediaProvider",
"->",
"getMedi... | Generate path for Media
@param MediaProviderInterface $mediaProvider
@return string | [
"Generate",
"path",
"for",
"Media"
] | 93c7bd6b3e1185ef716c26368677c08f95200f0b | https://github.com/undefined-exception-coders/UECMediaBundle/blob/93c7bd6b3e1185ef716c26368677c08f95200f0b/Path/MediaPathGenerator.php#L15-L29 | train |
meliorframework/melior | Classes/Helper/GUIDGenerator.php | GUIDGenerator.generate | public function generate(string $content = null): string
{
if (empty($content)) {
$guid = Uuid::uuid4();
} else {
$guid = Uuid::uuid5(Uuid::NAMESPACE_DNS, $content);
}
return $guid->toString();
} | php | public function generate(string $content = null): string
{
if (empty($content)) {
$guid = Uuid::uuid4();
} else {
$guid = Uuid::uuid5(Uuid::NAMESPACE_DNS, $content);
}
return $guid->toString();
} | [
"public",
"function",
"generate",
"(",
"string",
"$",
"content",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"content",
")",
")",
"{",
"$",
"guid",
"=",
"Uuid",
"::",
"uuid4",
"(",
")",
";",
"}",
"else",
"{",
"$",
"guid",
... | Generates a GUID, optionally from specified Content.
@param string|null $content
@return string | [
"Generates",
"a",
"GUID",
"optionally",
"from",
"specified",
"Content",
"."
] | f6469fa6e85f66a0507ae13603d19d78f2774e0b | https://github.com/meliorframework/melior/blob/f6469fa6e85f66a0507ae13603d19d78f2774e0b/Classes/Helper/GUIDGenerator.php#L35-L44 | train |
aloframework/handlers | src/class/Output/Dump.php | Dump.html | public static function html() {
$fargs = func_get_args();
$mode = self::enabled();
self::enabled(self::MODE_RICH);
$ret = self::dump(empty($fargs) ? null : $fargs[0]);
self::enabled($mode);
return $ret;
} | php | public static function html() {
$fargs = func_get_args();
$mode = self::enabled();
self::enabled(self::MODE_RICH);
$ret = self::dump(empty($fargs) ? null : $fargs[0]);
self::enabled($mode);
return $ret;
} | [
"public",
"static",
"function",
"html",
"(",
")",
"{",
"$",
"fargs",
"=",
"func_get_args",
"(",
")",
";",
"$",
"mode",
"=",
"self",
"::",
"enabled",
"(",
")",
";",
"self",
"::",
"enabled",
"(",
"self",
"::",
"MODE_RICH",
")",
";",
"$",
"ret",
"=",
... | Dumps in HTML mode
@author Art <a.molcanovas@gmail.com>
@return string The output | [
"Dumps",
"in",
"HTML",
"mode"
] | 3f17510c5e9221855d39c332710d0e512ec8b42d | https://github.com/aloframework/handlers/blob/3f17510c5e9221855d39c332710d0e512ec8b42d/src/class/Output/Dump.php#L37-L45 | train |
iJos/iForms | src/iForm.php | iForm.addFormField | public function addFormField($type, $params = array()) {
$namespace = "\\iJos\\iForms\\Fields\\" . ucfirst($type);
$field = new $namespace( $params );
array_push($this -> form_fields, $field);
} | php | public function addFormField($type, $params = array()) {
$namespace = "\\iJos\\iForms\\Fields\\" . ucfirst($type);
$field = new $namespace( $params );
array_push($this -> form_fields, $field);
} | [
"public",
"function",
"addFormField",
"(",
"$",
"type",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"namespace",
"=",
"\"\\\\iJos\\\\iForms\\\\Fields\\\\\"",
".",
"ucfirst",
"(",
"$",
"type",
")",
";",
"$",
"field",
"=",
"new",
"$",
"names... | Add a Field to the curent form
@param string $type
@param array $params | [
"Add",
"a",
"Field",
"to",
"the",
"curent",
"form"
] | 9ccae9bc624a749f18cddcac59bb41cec3ed22b8 | https://github.com/iJos/iForms/blob/9ccae9bc624a749f18cddcac59bb41cec3ed22b8/src/iForm.php#L46-L50 | train |
railsphp/framework | src/Rails/ActionView/Helper/Methods/FormTagTrait.php | FormTagTrait.normalizeFormFieldTagParams | public function normalizeFormFieldTagParams($name, $value, array $attributes, $fieldType = null)
{
if (!isset($attributes['id'])) {
$attributes['id'] = trim(
str_replace(['[', ']', '()', '__'], ['_', '_', '', '_'], $name),
'_'
);
}
if ($name) {
$attributes['name'] = $name;
}
return [$name, (string)$value, $attributes];
} | php | public function normalizeFormFieldTagParams($name, $value, array $attributes, $fieldType = null)
{
if (!isset($attributes['id'])) {
$attributes['id'] = trim(
str_replace(['[', ']', '()', '__'], ['_', '_', '', '_'], $name),
'_'
);
}
if ($name) {
$attributes['name'] = $name;
}
return [$name, (string)$value, $attributes];
} | [
"public",
"function",
"normalizeFormFieldTagParams",
"(",
"$",
"name",
",",
"$",
"value",
",",
"array",
"$",
"attributes",
",",
"$",
"fieldType",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributes",
"[",
"'id'",
"]",
")",
")",
"{",
... | This method can be "extended" to edit attributes for form-related tags. | [
"This",
"method",
"can",
"be",
"extended",
"to",
"edit",
"attributes",
"for",
"form",
"-",
"related",
"tags",
"."
] | 2ac9d3e493035dcc68f3c3812423327127327cd5 | https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActionView/Helper/Methods/FormTagTrait.php#L392-L404 | train |
railsphp/framework | src/Rails/ActionView/Helper/Methods/FormTagTrait.php | FormTagTrait.normalizeFormTagOptions | public function normalizeFormTagOptions($urlOptions, $options, $block)
{
if (!$urlOptions || !$options || !$block) {
if ($urlOptions instanceof Closure) {
$block = $urlOptions;
$urlOptions = null;
$options = [];
} elseif (is_array($urlOptions) && is_string(key($urlOptions))) {
$block = $options;
$options = $urlOptions;
$urlOptions = null;
} elseif ($options instanceof Closure) {
$block = $options;
$options = [];
}
}
if (!$block instanceof Closure) {
throw new Exception\BadMethodCallException(
"One of the arguments for formTag must be a Closure"
);
}
if (empty($options['method'])) {
$options['method'] = 'post';
}
if (!empty($options['multipart'])) {
$options['enctype'] = 'multipart/form-data';
unset($options['multipart']);
}
if ($urlOptions) {
if (!$this->isUrl($urlOptions)) {
$options['action'] = $this->urlFor($urlOptions);
} else {
$options['action'] = $urlOptions;
}
}
return [$urlOptions, $options, $block];
} | php | public function normalizeFormTagOptions($urlOptions, $options, $block)
{
if (!$urlOptions || !$options || !$block) {
if ($urlOptions instanceof Closure) {
$block = $urlOptions;
$urlOptions = null;
$options = [];
} elseif (is_array($urlOptions) && is_string(key($urlOptions))) {
$block = $options;
$options = $urlOptions;
$urlOptions = null;
} elseif ($options instanceof Closure) {
$block = $options;
$options = [];
}
}
if (!$block instanceof Closure) {
throw new Exception\BadMethodCallException(
"One of the arguments for formTag must be a Closure"
);
}
if (empty($options['method'])) {
$options['method'] = 'post';
}
if (!empty($options['multipart'])) {
$options['enctype'] = 'multipart/form-data';
unset($options['multipart']);
}
if ($urlOptions) {
if (!$this->isUrl($urlOptions)) {
$options['action'] = $this->urlFor($urlOptions);
} else {
$options['action'] = $urlOptions;
}
}
return [$urlOptions, $options, $block];
} | [
"public",
"function",
"normalizeFormTagOptions",
"(",
"$",
"urlOptions",
",",
"$",
"options",
",",
"$",
"block",
")",
"{",
"if",
"(",
"!",
"$",
"urlOptions",
"||",
"!",
"$",
"options",
"||",
"!",
"$",
"block",
")",
"{",
"if",
"(",
"$",
"urlOptions",
... | This method may be "extended" to customize form options such as HTML attributes. | [
"This",
"method",
"may",
"be",
"extended",
"to",
"customize",
"form",
"options",
"such",
"as",
"HTML",
"attributes",
"."
] | 2ac9d3e493035dcc68f3c3812423327127327cd5 | https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActionView/Helper/Methods/FormTagTrait.php#L443-L484 | train |
railsphp/framework | src/Rails/ActionView/Helper/Methods/FormTagTrait.php | FormTagTrait.runContentBlock | protected function runContentBlock(Closure $block)
{
ob_start();
$result = $block();
$contents = ob_get_clean();
return $result ?: $contents;
} | php | protected function runContentBlock(Closure $block)
{
ob_start();
$result = $block();
$contents = ob_get_clean();
return $result ?: $contents;
} | [
"protected",
"function",
"runContentBlock",
"(",
"Closure",
"$",
"block",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"result",
"=",
"$",
"block",
"(",
")",
";",
"$",
"contents",
"=",
"ob_get_clean",
"(",
")",
";",
"return",
"$",
"result",
"?",
":",
"$... | Runs a Closure that can either output content itself or
return the content as a string.
@param Closure $block
@return string | [
"Runs",
"a",
"Closure",
"that",
"can",
"either",
"output",
"content",
"itself",
"or",
"return",
"the",
"content",
"as",
"a",
"string",
"."
] | 2ac9d3e493035dcc68f3c3812423327127327cd5 | https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActionView/Helper/Methods/FormTagTrait.php#L566-L572 | train |
railsphp/framework | src/Rails/ActionView/Helper/Methods/FormTagTrait.php | FormTagTrait.normalizeSizeOption | protected function normalizeSizeOption(array &$options)
{
if (isset($options['size'])) {
$size = explode('x', $options['size']);
if (
isset($size[0]) &&
isset($size[1])
) {
list($options['cols'], $options['rows']) = $size;
}
unset($options['size']);
}
} | php | protected function normalizeSizeOption(array &$options)
{
if (isset($options['size'])) {
$size = explode('x', $options['size']);
if (
isset($size[0]) &&
isset($size[1])
) {
list($options['cols'], $options['rows']) = $size;
}
unset($options['size']);
}
} | [
"protected",
"function",
"normalizeSizeOption",
"(",
"array",
"&",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'size'",
"]",
")",
")",
"{",
"$",
"size",
"=",
"explode",
"(",
"'x'",
",",
"$",
"options",
"[",
"'size'",
"]",... | Checks for the "size" option, which is expected to be something like
`50x20`, and is splitted into "cols" and "rows".
@return void | [
"Checks",
"for",
"the",
"size",
"option",
"which",
"is",
"expected",
"to",
"be",
"something",
"like",
"50x20",
"and",
"is",
"splitted",
"into",
"cols",
"and",
"rows",
"."
] | 2ac9d3e493035dcc68f3c3812423327127327cd5 | https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActionView/Helper/Methods/FormTagTrait.php#L600-L612 | train |
tekkla/core-asset | Core/Asset/Javascript/JavascriptHandler.php | JavascriptHandler.& | public function &createScript($content, $defer = true, $combine = true, $minify = true): JavascriptObjectInterface
{
$obj = new JavascriptObject();
$obj->setType($obj::TYPE_SCRIPT);
$obj->setContent($content);
$obj->setDefer($defer);
$obj->setCombine($combine);
$obj->setMinify($minify);
$this->addObject($obj);
return $obj;
} | php | public function &createScript($content, $defer = true, $combine = true, $minify = true): JavascriptObjectInterface
{
$obj = new JavascriptObject();
$obj->setType($obj::TYPE_SCRIPT);
$obj->setContent($content);
$obj->setDefer($defer);
$obj->setCombine($combine);
$obj->setMinify($minify);
$this->addObject($obj);
return $obj;
} | [
"public",
"function",
"&",
"createScript",
"(",
"$",
"content",
",",
"$",
"defer",
"=",
"true",
",",
"$",
"combine",
"=",
"true",
",",
"$",
"minify",
"=",
"true",
")",
":",
"JavascriptObjectInterface",
"{",
"$",
"obj",
"=",
"new",
"JavascriptObject",
"("... | Adds an script javascript object to the output queue
@param string $content
Objects content
@param boolean $defer
Optional flag to put objects output right before the closing body tag. (Default: true)
@param boolean $combine
Optional flag to switch combining for this object on or off. (Default: true)
@param boolean $minify
Optional flag to switch minifying for this object on or off. (Default: true)
Applies only when $combine argument is set to true.
@return JavascriptObjectInterface | [
"Adds",
"an",
"script",
"javascript",
"object",
"to",
"the",
"output",
"queue"
] | 7dec00b51627dd8201a7e1cbc349d85abed84063 | https://github.com/tekkla/core-asset/blob/7dec00b51627dd8201a7e1cbc349d85abed84063/Core/Asset/Javascript/JavascriptHandler.php#L169-L182 | train |
tekkla/core-asset | Core/Asset/Javascript/JavascriptHandler.php | JavascriptHandler.& | public function &createBlock($content, $defer = true, $combine = true, $minify = true): JavascriptObjectInterface
{
$obj = new JavascriptObject();
$obj->setType($obj::TYPE_BLOCK);
$obj->setContent($content);
$obj->setDefer($defer);
$obj->setCombine($combine);
$obj->setMinify($minify);
$this->addObject($obj);
return $obj;
} | php | public function &createBlock($content, $defer = true, $combine = true, $minify = true): JavascriptObjectInterface
{
$obj = new JavascriptObject();
$obj->setType($obj::TYPE_BLOCK);
$obj->setContent($content);
$obj->setDefer($defer);
$obj->setCombine($combine);
$obj->setMinify($minify);
$this->addObject($obj);
return $obj;
} | [
"public",
"function",
"&",
"createBlock",
"(",
"$",
"content",
",",
"$",
"defer",
"=",
"true",
",",
"$",
"combine",
"=",
"true",
",",
"$",
"minify",
"=",
"true",
")",
":",
"JavascriptObjectInterface",
"{",
"$",
"obj",
"=",
"new",
"JavascriptObject",
"(",... | Blocks with complete code
Use this for conditional scripts!
@param string $content
Objects content
@param boolean $defer
Optional flag to put objects output right before the closing body tag. (Default: true)
@param boolean $combine
Optional flag to switch combining for this object on or off. (Default: true)
@param boolean $minify
Optional flag to switch minifying for this object on or off. (Default: true)
Applies only when $combine argument is set to true.g.
@return JavascriptObjectInterface | [
"Blocks",
"with",
"complete",
"code"
] | 7dec00b51627dd8201a7e1cbc349d85abed84063 | https://github.com/tekkla/core-asset/blob/7dec00b51627dd8201a7e1cbc349d85abed84063/Core/Asset/Javascript/JavascriptHandler.php#L229-L242 | train |
Webiny/Hrc | src/Webiny/Hrc/Request.php | Request.matchUrl | public function matchUrl($pattern)
{
if ($this->matchValue($this->getUrl(), $pattern)) {
return $this->getUrl();
}
return false;
} | php | public function matchUrl($pattern)
{
if ($this->matchValue($this->getUrl(), $pattern)) {
return $this->getUrl();
}
return false;
} | [
"public",
"function",
"matchUrl",
"(",
"$",
"pattern",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"matchValue",
"(",
"$",
"this",
"->",
"getUrl",
"(",
")",
",",
"$",
"pattern",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getUrl",
"(",
")",
";",
"}"... | Check if the url matches the given pattern.
@param string $pattern Pattern to match.
@return bool|null|string Url value if pattern matches, otherwise false. | [
"Check",
"if",
"the",
"url",
"matches",
"the",
"given",
"pattern",
"."
] | 2594d645dd79a579916d90ec93ce815bd413558f | https://github.com/Webiny/Hrc/blob/2594d645dd79a579916d90ec93ce815bd413558f/src/Webiny/Hrc/Request.php#L144-L151 | train |
Webiny/Hrc | src/Webiny/Hrc/Request.php | Request.matchHeader | public function matchHeader($name, $pattern = null)
{
if (isset($this->getHeaders()[$name])) {
if (!empty($pattern)) {
if ($this->matchValue($this->getHeaders()[$name], $pattern)) {
return $this->getHeaders()[$name];
}
} else {
if (empty($this->getHeaders()[$name])) {
return true;
} else {
return $this->getHeaders()[$name];
}
}
} elseif ($pattern == '?') {
// in case of optional pattern we just return true
return true;
}
return false;
} | php | public function matchHeader($name, $pattern = null)
{
if (isset($this->getHeaders()[$name])) {
if (!empty($pattern)) {
if ($this->matchValue($this->getHeaders()[$name], $pattern)) {
return $this->getHeaders()[$name];
}
} else {
if (empty($this->getHeaders()[$name])) {
return true;
} else {
return $this->getHeaders()[$name];
}
}
} elseif ($pattern == '?') {
// in case of optional pattern we just return true
return true;
}
return false;
} | [
"public",
"function",
"matchHeader",
"(",
"$",
"name",
",",
"$",
"pattern",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"pat... | Check if the given header exists, and optionally if the pattern matches the header value.
@param string $name Header name to match.
@param string|null $pattern Optional pattern that needs to match the header value.
@return bool|string False if the header doesn't exist, or the pattern doesn't match.
If the header exists and pattern matched, the header value is returned. | [
"Check",
"if",
"the",
"given",
"header",
"exists",
"and",
"optionally",
"if",
"the",
"pattern",
"matches",
"the",
"header",
"value",
"."
] | 2594d645dd79a579916d90ec93ce815bd413558f | https://github.com/Webiny/Hrc/blob/2594d645dd79a579916d90ec93ce815bd413558f/src/Webiny/Hrc/Request.php#L162-L182 | train |
Webiny/Hrc | src/Webiny/Hrc/Request.php | Request.matchCookie | public function matchCookie($name, $pattern = null)
{
if (isset($this->getCookies()[$name])) {
if (!empty($pattern)) {
if ($this->matchValue($this->getCookies()[$name], $pattern)) {
return $this->getCookies()[$name];
}
} else {
if (empty($this->getCookies()[$name])) {
return true;
} else {
return $this->getCookies()[$name];
}
}
} elseif ($pattern == '?') {
// in case of optional pattern we just return true
return true;
}
return false;
} | php | public function matchCookie($name, $pattern = null)
{
if (isset($this->getCookies()[$name])) {
if (!empty($pattern)) {
if ($this->matchValue($this->getCookies()[$name], $pattern)) {
return $this->getCookies()[$name];
}
} else {
if (empty($this->getCookies()[$name])) {
return true;
} else {
return $this->getCookies()[$name];
}
}
} elseif ($pattern == '?') {
// in case of optional pattern we just return true
return true;
}
return false;
} | [
"public",
"function",
"matchCookie",
"(",
"$",
"name",
",",
"$",
"pattern",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"getCookies",
"(",
")",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"pat... | Check if the given cookie exists, and optionally if the pattern matches the cookie value.
@param string $name Cookie name to match.
@param string|null $pattern Optional pattern that needs to match the cookie value.
@return bool|string False if the cookie doesn't exist, or the pattern doesn't match.
If the cookie exists and pattern matched, the cookie value is returned. | [
"Check",
"if",
"the",
"given",
"cookie",
"exists",
"and",
"optionally",
"if",
"the",
"pattern",
"matches",
"the",
"cookie",
"value",
"."
] | 2594d645dd79a579916d90ec93ce815bd413558f | https://github.com/Webiny/Hrc/blob/2594d645dd79a579916d90ec93ce815bd413558f/src/Webiny/Hrc/Request.php#L193-L213 | train |
Webiny/Hrc | src/Webiny/Hrc/Request.php | Request.matchQueryParam | public function matchQueryParam($name, $pattern = null)
{
if (isset($this->getQueryParams()[$name])) {
if (!empty($pattern)) {
if ($this->matchValue($this->getQueryParams()[$name], $pattern)) {
return $this->getQueryParams()[$name];
}
} else {
if (empty($this->getQueryParams()[$name])) {
return true;
} else {
return $this->getQueryParams()[$name];
}
}
} elseif ($pattern == '?') {
// in case of optional pattern we just return true
return true;
}
return false;
} | php | public function matchQueryParam($name, $pattern = null)
{
if (isset($this->getQueryParams()[$name])) {
if (!empty($pattern)) {
if ($this->matchValue($this->getQueryParams()[$name], $pattern)) {
return $this->getQueryParams()[$name];
}
} else {
if (empty($this->getQueryParams()[$name])) {
return true;
} else {
return $this->getQueryParams()[$name];
}
}
} elseif ($pattern == '?') {
// in case of optional pattern we just return true
return true;
}
return false;
} | [
"public",
"function",
"matchQueryParam",
"(",
"$",
"name",
",",
"$",
"pattern",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"getQueryParams",
"(",
")",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$"... | Check if the given query param exists, and optionally if the pattern matches the query param value.
@param string $name Query param name to match.
@param string|null $pattern Optional pattern that needs to match the query param value.
@return bool|string False if the query param doesn't exist, or the pattern doesn't match.
If the query param exists and pattern matched, the query param value is returned. | [
"Check",
"if",
"the",
"given",
"query",
"param",
"exists",
"and",
"optionally",
"if",
"the",
"pattern",
"matches",
"the",
"query",
"param",
"value",
"."
] | 2594d645dd79a579916d90ec93ce815bd413558f | https://github.com/Webiny/Hrc/blob/2594d645dd79a579916d90ec93ce815bd413558f/src/Webiny/Hrc/Request.php#L224-L244 | train |
Webiny/Hrc | src/Webiny/Hrc/Request.php | Request.matchValue | private function matchValue($value, $pattern)
{
// basic check
if ($value == $pattern) {
return true;
}
// simple check in case of optional param
if ($pattern == '?') {
return true;
}
// simple match in case pattern is just "*"
if ($pattern == '*' && $value != '') {
return true;
}
// more complex match in case when wildcard is part of a larger match
$pattern = str_replace('*', '(.+)', $pattern);
// regex match
if (strpos($pattern, '(') !== false || strpos($pattern, '[') !== false || strpos($pattern, '\\') !== false) {
return preg_match('#^' . $pattern . '$#', $value);
}
return false;
} | php | private function matchValue($value, $pattern)
{
// basic check
if ($value == $pattern) {
return true;
}
// simple check in case of optional param
if ($pattern == '?') {
return true;
}
// simple match in case pattern is just "*"
if ($pattern == '*' && $value != '') {
return true;
}
// more complex match in case when wildcard is part of a larger match
$pattern = str_replace('*', '(.+)', $pattern);
// regex match
if (strpos($pattern, '(') !== false || strpos($pattern, '[') !== false || strpos($pattern, '\\') !== false) {
return preg_match('#^' . $pattern . '$#', $value);
}
return false;
} | [
"private",
"function",
"matchValue",
"(",
"$",
"value",
",",
"$",
"pattern",
")",
"{",
"// basic check",
"if",
"(",
"$",
"value",
"==",
"$",
"pattern",
")",
"{",
"return",
"true",
";",
"}",
"// simple check in case of optional param",
"if",
"(",
"$",
"patter... | Method that tries to match the given pattern to the given value.
@param string $value Value where the pattern match will be performed.
@param string $pattern Pattern to match.
@return bool True if pattern matched the value, otherwise false. | [
"Method",
"that",
"tries",
"to",
"match",
"the",
"given",
"pattern",
"to",
"the",
"given",
"value",
"."
] | 2594d645dd79a579916d90ec93ce815bd413558f | https://github.com/Webiny/Hrc/blob/2594d645dd79a579916d90ec93ce815bd413558f/src/Webiny/Hrc/Request.php#L281-L307 | train |
xaamin/encoding | src/Encode.php | Encode.strlen | protected static function strlen($text)
{
$exits = (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload')) & 2);
return $exits ? mb_strlen($text,'8bit') : strlen($text);
} | php | protected static function strlen($text)
{
$exits = (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload')) & 2);
return $exits ? mb_strlen($text,'8bit') : strlen($text);
} | [
"protected",
"static",
"function",
"strlen",
"(",
"$",
"text",
")",
"{",
"$",
"exits",
"=",
"(",
"function_exists",
"(",
"'mb_strlen'",
")",
"&&",
"(",
"(",
"int",
")",
"ini_get",
"(",
"'mbstring.func_overload'",
")",
")",
"&",
"2",
")",
";",
"return",
... | Calculates the length from given string
@param string $text
@return int | [
"Calculates",
"the",
"length",
"from",
"given",
"string"
] | b2572676fb9f0a8cb81b3f2dbf2d63801bfe3be4 | https://github.com/xaamin/encoding/blob/b2572676fb9f0a8cb81b3f2dbf2d63801bfe3be4/src/Encode.php#L319-L324 | train |
xaamin/encoding | src/Encode.php | Encode.normalizeEncoding | protected static function normalizeEncoding($encodingLabel)
{
$encoding = strtoupper($encodingLabel);
$encoding = preg_replace('/[^a-zA-Z0-9\s]/', '', $encoding);
$equivalences = [
'ISO88591' => 'ISO-8859-1',
'ISO8859' => 'ISO-8859-1',
'ISO' => 'ISO-8859-1',
'LATIN1' => 'ISO-8859-1',
'LATIN' => 'ISO-8859-1',
'UTF8' => 'UTF-8',
'UTF' => 'UTF-8',
'WIN1252' => 'ISO-8859-1',
'WINDOWS1252' => 'ISO-8859-1'
];
if (empty($equivalences[$encoding])) {
return 'UTF-8';
}
return $equivalences[$encoding];
} | php | protected static function normalizeEncoding($encodingLabel)
{
$encoding = strtoupper($encodingLabel);
$encoding = preg_replace('/[^a-zA-Z0-9\s]/', '', $encoding);
$equivalences = [
'ISO88591' => 'ISO-8859-1',
'ISO8859' => 'ISO-8859-1',
'ISO' => 'ISO-8859-1',
'LATIN1' => 'ISO-8859-1',
'LATIN' => 'ISO-8859-1',
'UTF8' => 'UTF-8',
'UTF' => 'UTF-8',
'WIN1252' => 'ISO-8859-1',
'WINDOWS1252' => 'ISO-8859-1'
];
if (empty($equivalences[$encoding])) {
return 'UTF-8';
}
return $equivalences[$encoding];
} | [
"protected",
"static",
"function",
"normalizeEncoding",
"(",
"$",
"encodingLabel",
")",
"{",
"$",
"encoding",
"=",
"strtoupper",
"(",
"$",
"encodingLabel",
")",
";",
"$",
"encoding",
"=",
"preg_replace",
"(",
"'/[^a-zA-Z0-9\\s]/'",
",",
"''",
",",
"$",
"encodi... | Returns normalized encoding name from common aliases
@param string $encodingLabel
@return string | [
"Returns",
"normalized",
"encoding",
"name",
"from",
"common",
"aliases"
] | b2572676fb9f0a8cb81b3f2dbf2d63801bfe3be4 | https://github.com/xaamin/encoding/blob/b2572676fb9f0a8cb81b3f2dbf2d63801bfe3be4/src/Encode.php#L332-L354 | train |
xaamin/encoding | src/Encode.php | Encode.to | public static function to($encodingLabel, $text)
{
$encodingLabel = static::normalizeEncoding($encodingLabel);
if ($encodingLabel == 'ISO-8859-1') {
return static::toLatin1($text);
}
return static::toUTF8($text);
} | php | public static function to($encodingLabel, $text)
{
$encodingLabel = static::normalizeEncoding($encodingLabel);
if ($encodingLabel == 'ISO-8859-1') {
return static::toLatin1($text);
}
return static::toUTF8($text);
} | [
"public",
"static",
"function",
"to",
"(",
"$",
"encodingLabel",
",",
"$",
"text",
")",
"{",
"$",
"encodingLabel",
"=",
"static",
"::",
"normalizeEncoding",
"(",
"$",
"encodingLabel",
")",
";",
"if",
"(",
"$",
"encodingLabel",
"==",
"'ISO-8859-1'",
")",
"{... | Encode to supported encoding types aliases
ISO88591
ISO8859
ISO
LATIN1
LATIN
UTF8
UTF
WIN1252
WINDOWS1252
@param string $encodingLabel Encoding name
@param string|array $text
@return string|array | [
"Encode",
"to",
"supported",
"encoding",
"types",
"aliases",
"ISO88591",
"ISO8859",
"ISO",
"LATIN1",
"LATIN",
"UTF8",
"UTF",
"WIN1252",
"WINDOWS1252"
] | b2572676fb9f0a8cb81b3f2dbf2d63801bfe3be4 | https://github.com/xaamin/encoding/blob/b2572676fb9f0a8cb81b3f2dbf2d63801bfe3be4/src/Encode.php#L372-L381 | train |
xaamin/encoding | src/Encode.php | Encode.utf8Decode | protected static function utf8Decode($text, $option)
{
if ($option == self::WITHOUT_ICONV || !function_exists('iconv')) {
$decoded = utf8_decode(
str_replace(array_keys(static::$utf8ToWin1252), array_values(static::$utf8ToWin1252), static::toUTF8($text))
);
} else {
$decoded = iconv("UTF-8", "Windows-1252" . ($option == self::ICONV_TRANSLIT ? '//TRANSLIT' : ($option == self::ICONV_IGNORE ? '//IGNORE' : '')), $text);
}
return $decoded;
} | php | protected static function utf8Decode($text, $option)
{
if ($option == self::WITHOUT_ICONV || !function_exists('iconv')) {
$decoded = utf8_decode(
str_replace(array_keys(static::$utf8ToWin1252), array_values(static::$utf8ToWin1252), static::toUTF8($text))
);
} else {
$decoded = iconv("UTF-8", "Windows-1252" . ($option == self::ICONV_TRANSLIT ? '//TRANSLIT' : ($option == self::ICONV_IGNORE ? '//IGNORE' : '')), $text);
}
return $decoded;
} | [
"protected",
"static",
"function",
"utf8Decode",
"(",
"$",
"text",
",",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"option",
"==",
"self",
"::",
"WITHOUT_ICONV",
"||",
"!",
"function_exists",
"(",
"'iconv'",
")",
")",
"{",
"$",
"decoded",
"=",
"utf8_decode... | Converts a string with ISO-8859-1 characters encoded with UTF-8 to single-byte Windows-1252
@param string $text
@param string $option How to convert if use iconv function (TRANSLIT or IGNORE)
@return string | [
"Converts",
"a",
"string",
"with",
"ISO",
"-",
"8859",
"-",
"1",
"characters",
"encoded",
"with",
"UTF",
"-",
"8",
"to",
"single",
"-",
"byte",
"Windows",
"-",
"1252"
] | b2572676fb9f0a8cb81b3f2dbf2d63801bfe3be4 | https://github.com/xaamin/encoding/blob/b2572676fb9f0a8cb81b3f2dbf2d63801bfe3be4/src/Encode.php#L390-L401 | train |
rseyferth/chickenwire | src/ChickenWire/Core/Configuration.php | Configuration.allFor | public function allFor($name) {
// Loop through environments
$result = array();
foreach ($this->_envSettings as $env => $settings) {
$result[$env] = $settings[$name];
}
return $result;
} | php | public function allFor($name) {
// Loop through environments
$result = array();
foreach ($this->_envSettings as $env => $settings) {
$result[$env] = $settings[$name];
}
return $result;
} | [
"public",
"function",
"allFor",
"(",
"$",
"name",
")",
"{",
"// Loop through environments",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_envSettings",
"as",
"$",
"env",
"=>",
"$",
"settings",
")",
"{",
"$",
"result",
... | Get the values of the given setting for each environment
@param string $name The settings to retrieve
@return array | [
"Get",
"the",
"values",
"of",
"the",
"given",
"setting",
"for",
"each",
"environment"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Core/Configuration.php#L99-L108 | train |
SergioMadness/framework | framework/components/datamapper/traits/ErrorTrait.php | ErrorTrait.getError | public function getError($attribute)
{
$result = null;
if ($this->isErrorExists($attribute)) {
$result = $this->errors[$attribute];
}
return $result;
} | php | public function getError($attribute)
{
$result = null;
if ($this->isErrorExists($attribute)) {
$result = $this->errors[$attribute];
}
return $result;
} | [
"public",
"function",
"getError",
"(",
"$",
"attribute",
")",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"isErrorExists",
"(",
"$",
"attribute",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"errors",
"[",
"$",
"att... | Get error by attribute name
@param string $attribute
@return string | [
"Get",
"error",
"by",
"attribute",
"name"
] | a5038eb926a5038b9a331d0cb6a68d7fc3cf1f1e | https://github.com/SergioMadness/framework/blob/a5038eb926a5038b9a331d0cb6a68d7fc3cf1f1e/framework/components/datamapper/traits/ErrorTrait.php#L28-L37 | train |
osflab/view | Helper/AbstractViewHelper.php | AbstractViewHelper.html | protected function html($newLine, $condition = true)
{
if ($condition) {
$this->lines[] = ltrim($newLine);
}
return $this;
} | php | protected function html($newLine, $condition = true)
{
if ($condition) {
$this->lines[] = ltrim($newLine);
}
return $this;
} | [
"protected",
"function",
"html",
"(",
"$",
"newLine",
",",
"$",
"condition",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"condition",
")",
"{",
"$",
"this",
"->",
"lines",
"[",
"]",
"=",
"ltrim",
"(",
"$",
"newLine",
")",
";",
"}",
"return",
"$",
"thi... | Cumulate HTML code in order to restitute it
@param string $newLine
@param bool $condition ignored if false
@return $this | [
"Cumulate",
"HTML",
"code",
"in",
"order",
"to",
"restitute",
"it"
] | e06601013e8ec86dc2055e000e58dffd963c78e2 | https://github.com/osflab/view/blob/e06601013e8ec86dc2055e000e58dffd963c78e2/Helper/AbstractViewHelper.php#L58-L64 | train |
jamesmcfadden/gen | src/Publisher.php | Publisher.getPageUrl | public function getPageUrl(Page $page)
{
return $this->config['base_url'].'/'.
($page->getSubFolder() === null ? '' : $page->getSubFolder().'/').
$this->getPagePublishFilename($page);
} | php | public function getPageUrl(Page $page)
{
return $this->config['base_url'].'/'.
($page->getSubFolder() === null ? '' : $page->getSubFolder().'/').
$this->getPagePublishFilename($page);
} | [
"public",
"function",
"getPageUrl",
"(",
"Page",
"$",
"page",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"[",
"'base_url'",
"]",
".",
"'/'",
".",
"(",
"$",
"page",
"->",
"getSubFolder",
"(",
")",
"===",
"null",
"?",
"''",
":",
"$",
"page",
"-... | Return the page URL.
@return string | [
"Return",
"the",
"page",
"URL",
"."
] | 2c7a7da1c3a04e10463c956722f85f5da13dc179 | https://github.com/jamesmcfadden/gen/blob/2c7a7da1c3a04e10463c956722f85f5da13dc179/src/Publisher.php#L225-L230 | train |
jamesmcfadden/gen | src/Publisher.php | Publisher.getPagePublishDirectory | public function getPagePublishDirectory(Page $page)
{
return $this->getPublishDirectory().
rtrim(DIRECTORY_SEPARATOR.$page->getSubFolder(), DIRECTORY_SEPARATOR);
} | php | public function getPagePublishDirectory(Page $page)
{
return $this->getPublishDirectory().
rtrim(DIRECTORY_SEPARATOR.$page->getSubFolder(), DIRECTORY_SEPARATOR);
} | [
"public",
"function",
"getPagePublishDirectory",
"(",
"Page",
"$",
"page",
")",
"{",
"return",
"$",
"this",
"->",
"getPublishDirectory",
"(",
")",
".",
"rtrim",
"(",
"DIRECTORY_SEPARATOR",
".",
"$",
"page",
"->",
"getSubFolder",
"(",
")",
",",
"DIRECTORY_SEPAR... | Return the directory to which the page should be published.
@return string | [
"Return",
"the",
"directory",
"to",
"which",
"the",
"page",
"should",
"be",
"published",
"."
] | 2c7a7da1c3a04e10463c956722f85f5da13dc179 | https://github.com/jamesmcfadden/gen/blob/2c7a7da1c3a04e10463c956722f85f5da13dc179/src/Publisher.php#L237-L241 | train |
jamesmcfadden/gen | src/Publisher.php | Publisher.getPagePublishPath | public function getPagePublishPath(Page $page)
{
return $this->getPagePublishDirectory($page).
DIRECTORY_SEPARATOR.
$this->getPagePublishFilename($page);
} | php | public function getPagePublishPath(Page $page)
{
return $this->getPagePublishDirectory($page).
DIRECTORY_SEPARATOR.
$this->getPagePublishFilename($page);
} | [
"public",
"function",
"getPagePublishPath",
"(",
"Page",
"$",
"page",
")",
"{",
"return",
"$",
"this",
"->",
"getPagePublishDirectory",
"(",
"$",
"page",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"getPagePublishFilename",
"(",
"$",
"page",
")",
... | Return the full page publish path.
@return string | [
"Return",
"the",
"full",
"page",
"publish",
"path",
"."
] | 2c7a7da1c3a04e10463c956722f85f5da13dc179 | https://github.com/jamesmcfadden/gen/blob/2c7a7da1c3a04e10463c956722f85f5da13dc179/src/Publisher.php#L248-L253 | train |
morrelinko/simple-photo | src/Toolbox/PhotoCollection.php | PhotoCollection.transform | public function transform(\Closure $callback)
{
$this->photos = array_map($callback, $this->photos);
return $this;
} | php | public function transform(\Closure $callback)
{
$this->photos = array_map($callback, $this->photos);
return $this;
} | [
"public",
"function",
"transform",
"(",
"\\",
"Closure",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"photos",
"=",
"array_map",
"(",
"$",
"callback",
",",
"$",
"this",
"->",
"photos",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Executes a callback on each photo in the collection
Setting each item to the result from the callback.
@param callable $callback
@return PhotoCollection | [
"Executes",
"a",
"callback",
"on",
"each",
"photo",
"in",
"the",
"collection",
"Setting",
"each",
"item",
"to",
"the",
"result",
"from",
"the",
"callback",
"."
] | be1fbe3139d32eb39e88cff93f847154bb6a8cb2 | https://github.com/morrelinko/simple-photo/blob/be1fbe3139d32eb39e88cff93f847154bb6a8cb2/src/Toolbox/PhotoCollection.php#L89-L94 | train |
veridu/idos-sdk-php | src/idOS/Endpoint/Company/Settings.php | Settings.createNew | public function createNew(
string $section,
string $property,
string $value,
bool $protected
) : array {
return $this->sendPost(
sprintf('/companies/%s/settings', $this->companySlug),
[],
[
'section' => $section,
'property' => $property,
'value' => $value,
'protected' => $protected
]
);
} | php | public function createNew(
string $section,
string $property,
string $value,
bool $protected
) : array {
return $this->sendPost(
sprintf('/companies/%s/settings', $this->companySlug),
[],
[
'section' => $section,
'property' => $property,
'value' => $value,
'protected' => $protected
]
);
} | [
"public",
"function",
"createNew",
"(",
"string",
"$",
"section",
",",
"string",
"$",
"property",
",",
"string",
"$",
"value",
",",
"bool",
"$",
"protected",
")",
":",
"array",
"{",
"return",
"$",
"this",
"->",
"sendPost",
"(",
"sprintf",
"(",
"'/compani... | Creates a new setting for the given company.
@param string $section
@param string $property
@param string $value
@param bool $protected
@return array Response | [
"Creates",
"a",
"new",
"setting",
"for",
"the",
"given",
"company",
"."
] | e56757bed10404756f2f0485a4b7f55794192008 | https://github.com/veridu/idos-sdk-php/blob/e56757bed10404756f2f0485a4b7f55794192008/src/idOS/Endpoint/Company/Settings.php#L35-L52 | train |
phPoirot/Module-Authorization | src/Authorization/Guard/GuardRoute.php | GuardRoute._verifyIsBannedRoute | function _verifyIsBannedRoute($currentRoute)
{
$r = false;
$currentRoute = rtrim($currentRoute, '/');
foreach ($this->routesDenied as $deniedRoute) {
$deniedRoute = rtrim($deniedRoute, '/');
$allowLeft = false;
if (substr($deniedRoute, -1) == '*') {
// remove star
$allowLeft = true;
$deniedRoute = substr($deniedRoute, 0, strlen($deniedRoute) -1 );
}
if ( ($left = str_replace($deniedRoute, '', $currentRoute)) !== $currentRoute ) {
if ($allowLeft || $left == '')
return true;
}
}
return $r;
} | php | function _verifyIsBannedRoute($currentRoute)
{
$r = false;
$currentRoute = rtrim($currentRoute, '/');
foreach ($this->routesDenied as $deniedRoute) {
$deniedRoute = rtrim($deniedRoute, '/');
$allowLeft = false;
if (substr($deniedRoute, -1) == '*') {
// remove star
$allowLeft = true;
$deniedRoute = substr($deniedRoute, 0, strlen($deniedRoute) -1 );
}
if ( ($left = str_replace($deniedRoute, '', $currentRoute)) !== $currentRoute ) {
if ($allowLeft || $left == '')
return true;
}
}
return $r;
} | [
"function",
"_verifyIsBannedRoute",
"(",
"$",
"currentRoute",
")",
"{",
"$",
"r",
"=",
"false",
";",
"$",
"currentRoute",
"=",
"rtrim",
"(",
"$",
"currentRoute",
",",
"'/'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"routesDenied",
"as",
"$",
"deniedR... | Check given route name is in banned list
@param string $currentRoute
@return bool | [
"Check",
"given",
"route",
"name",
"is",
"in",
"banned",
"list"
] | 1adcb85d01bb7cfaa6cc6b0cbcb9907ef4778e06 | https://github.com/phPoirot/Module-Authorization/blob/1adcb85d01bb7cfaa6cc6b0cbcb9907ef4778e06/src/Authorization/Guard/GuardRoute.php#L162-L183 | train |
judus/minimal-minimal | src/ArrayLoader.php | ArrayLoader.minimal | public static function minimal(string $filePath = null)
{
if (is_file($filePath)) {
/** @noinspection PhpIncludeInspection */
$configItems = require_once $filePath;
!is_array($configItems) || Config::items($configItems);
ini_set('error_reporting',
Config::exists('errors.error_reporting', 0));
ini_set('display_errors',
Config::exists('errors.display_errors', 0));
Event::dispatch('minimal.loaded.minimal', [
$filePath,
is_array($configItems) ? $configItems : []
]);
}
} | php | public static function minimal(string $filePath = null)
{
if (is_file($filePath)) {
/** @noinspection PhpIncludeInspection */
$configItems = require_once $filePath;
!is_array($configItems) || Config::items($configItems);
ini_set('error_reporting',
Config::exists('errors.error_reporting', 0));
ini_set('display_errors',
Config::exists('errors.display_errors', 0));
Event::dispatch('minimal.loaded.minimal', [
$filePath,
is_array($configItems) ? $configItems : []
]);
}
} | [
"public",
"static",
"function",
"minimal",
"(",
"string",
"$",
"filePath",
"=",
"null",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"filePath",
")",
")",
"{",
"/** @noinspection PhpIncludeInspection */",
"$",
"configItems",
"=",
"require_once",
"$",
"filePath",
... | Registers the minimal config file.
It stores the array items from the minimal config file in the Config
object and eventually sets the php.ini error_reporting and display_errors.
@param string|null $filePath | [
"Registers",
"the",
"minimal",
"config",
"file",
".",
"It",
"stores",
"the",
"array",
"items",
"from",
"the",
"minimal",
"config",
"file",
"in",
"the",
"Config",
"object",
"and",
"eventually",
"sets",
"the",
"php",
".",
"ini",
"error_reporting",
"and",
"disp... | 36db55c537175cead2ab412f166bf2574d0f9597 | https://github.com/judus/minimal-minimal/blob/36db55c537175cead2ab412f166bf2574d0f9597/src/ArrayLoader.php#L18-L36 | train |
jonneyless/yii2-helper-extend | helpers/Zip.php | Zip.dir | public static function dir($sourcePath, $outZipPath)
{
$sourcePath = rtrim($sourcePath, "/");
$zip = new ZipArchive();
$zip->open($outZipPath, ZipArchive::CREATE);
self::folderToZip($sourcePath, $zip, strlen($sourcePath . "/"));
$zip->close();
} | php | public static function dir($sourcePath, $outZipPath)
{
$sourcePath = rtrim($sourcePath, "/");
$zip = new ZipArchive();
$zip->open($outZipPath, ZipArchive::CREATE);
self::folderToZip($sourcePath, $zip, strlen($sourcePath . "/"));
$zip->close();
} | [
"public",
"static",
"function",
"dir",
"(",
"$",
"sourcePath",
",",
"$",
"outZipPath",
")",
"{",
"$",
"sourcePath",
"=",
"rtrim",
"(",
"$",
"sourcePath",
",",
"\"/\"",
")",
";",
"$",
"zip",
"=",
"new",
"ZipArchive",
"(",
")",
";",
"$",
"zip",
"->",
... | Zip a folder
@param string $sourcePath Path of directory to be zip.
@param string $outZipPath Path of output zip file. | [
"Zip",
"a",
"folder"
] | 1c1afa051e219865f52d40c728c0a95f1ae54106 | https://github.com/jonneyless/yii2-helper-extend/blob/1c1afa051e219865f52d40c728c0a95f1ae54106/helpers/Zip.php#L20-L27 | train |
dshovchko/debulog | src/Logger.php | Logger.add | public function add($message)
{
$this->_messages[] = $this->log_timestamp() . $message . PHP_EOL;
$this->debug($message);
} | php | public function add($message)
{
$this->_messages[] = $this->log_timestamp() . $message . PHP_EOL;
$this->debug($message);
} | [
"public",
"function",
"add",
"(",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"_messages",
"[",
"]",
"=",
"$",
"this",
"->",
"log_timestamp",
"(",
")",
".",
"$",
"message",
".",
"PHP_EOL",
";",
"$",
"this",
"->",
"debug",
"(",
"$",
"message",
")",... | Add message to logger buffer
@param string $message Message text | [
"Add",
"message",
"to",
"logger",
"buffer"
] | eb48c5c409b2ff2b023f6c65c46af3364ae98e7e | https://github.com/dshovchko/debulog/blob/eb48c5c409b2ff2b023f6c65c46af3364ae98e7e/src/Logger.php#L70-L74 | train |
dshovchko/debulog | src/Logger.php | Logger.error | public function error($message)
{
$this->_errors[] = $this->log_timestamp() . $message . PHP_EOL;
$this->debug('ERROR: '.$message);
} | php | public function error($message)
{
$this->_errors[] = $this->log_timestamp() . $message . PHP_EOL;
$this->debug('ERROR: '.$message);
} | [
"public",
"function",
"error",
"(",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"$",
"this",
"->",
"log_timestamp",
"(",
")",
".",
"$",
"message",
".",
"PHP_EOL",
";",
"$",
"this",
"->",
"debug",
"(",
"'ERROR: '",
".",
"$... | Add error message to logger buffer
@param string $message Message text | [
"Add",
"error",
"message",
"to",
"logger",
"buffer"
] | eb48c5c409b2ff2b023f6c65c46af3364ae98e7e | https://github.com/dshovchko/debulog/blob/eb48c5c409b2ff2b023f6c65c46af3364ae98e7e/src/Logger.php#L82-L86 | train |
dshovchko/debulog | src/Logger.php | Logger.shutdown | public function shutdown()
{
if ($this->ondebug === TRUE)
{
$this->_debugs[] = $this->log_debug_event('end') . PHP_EOL;
}
$this->sync();
} | php | public function shutdown()
{
if ($this->ondebug === TRUE)
{
$this->_debugs[] = $this->log_debug_event('end') . PHP_EOL;
}
$this->sync();
} | [
"public",
"function",
"shutdown",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ondebug",
"===",
"TRUE",
")",
"{",
"$",
"this",
"->",
"_debugs",
"[",
"]",
"=",
"$",
"this",
"->",
"log_debug_event",
"(",
"'end'",
")",
".",
"PHP_EOL",
";",
"}",
"$",
... | Finish and sync all buffers to files | [
"Finish",
"and",
"sync",
"all",
"buffers",
"to",
"files"
] | eb48c5c409b2ff2b023f6c65c46af3364ae98e7e | https://github.com/dshovchko/debulog/blob/eb48c5c409b2ff2b023f6c65c46af3364ae98e7e/src/Logger.php#L106-L113 | train |
dshovchko/debulog | src/Logger.php | Logger.sync | public function sync()
{
$this->sync_single_log($this->_messages, '');
$this->sync_single_log($this->_debugs, '_debug');
$this->sync_single_log($this->_errors, '_error');
} | php | public function sync()
{
$this->sync_single_log($this->_messages, '');
$this->sync_single_log($this->_debugs, '_debug');
$this->sync_single_log($this->_errors, '_error');
} | [
"public",
"function",
"sync",
"(",
")",
"{",
"$",
"this",
"->",
"sync_single_log",
"(",
"$",
"this",
"->",
"_messages",
",",
"''",
")",
";",
"$",
"this",
"->",
"sync_single_log",
"(",
"$",
"this",
"->",
"_debugs",
",",
"'_debug'",
")",
";",
"$",
"thi... | Sync all buffers to files | [
"Sync",
"all",
"buffers",
"to",
"files"
] | eb48c5c409b2ff2b023f6c65c46af3364ae98e7e | https://github.com/dshovchko/debulog/blob/eb48c5c409b2ff2b023f6c65c46af3364ae98e7e/src/Logger.php#L118-L123 | train |
dshovchko/debulog | src/Logger.php | Logger.sync_single_log | protected function sync_single_log(&$buffer, $suffix)
{
if ( ! empty($buffer))
{
$this->write($buffer, $this->dir . $this->prefix . $suffix . '.log');
$buffer = array();
}
} | php | protected function sync_single_log(&$buffer, $suffix)
{
if ( ! empty($buffer))
{
$this->write($buffer, $this->dir . $this->prefix . $suffix . '.log');
$buffer = array();
}
} | [
"protected",
"function",
"sync_single_log",
"(",
"&",
"$",
"buffer",
",",
"$",
"suffix",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"buffer",
")",
")",
"{",
"$",
"this",
"->",
"write",
"(",
"$",
"buffer",
",",
"$",
"this",
"->",
"dir",
".",
"$"... | Sync specific buffer to file
@param array $buffer
@param string $suffix log filename suffix | [
"Sync",
"specific",
"buffer",
"to",
"file"
] | eb48c5c409b2ff2b023f6c65c46af3364ae98e7e | https://github.com/dshovchko/debulog/blob/eb48c5c409b2ff2b023f6c65c46af3364ae98e7e/src/Logger.php#L131-L138 | train |
dshovchko/debulog | src/Logger.php | Logger.write | protected function write($messages, $file)
{
$f = @fopen($file, 'a');
if ($f === false)
{
throw new \Exception("Logfile $file is not writeable!");
}
foreach($messages as $msg)
{
fwrite($f, $msg);
}
fclose($f);
} | php | protected function write($messages, $file)
{
$f = @fopen($file, 'a');
if ($f === false)
{
throw new \Exception("Logfile $file is not writeable!");
}
foreach($messages as $msg)
{
fwrite($f, $msg);
}
fclose($f);
} | [
"protected",
"function",
"write",
"(",
"$",
"messages",
",",
"$",
"file",
")",
"{",
"$",
"f",
"=",
"@",
"fopen",
"(",
"$",
"file",
",",
"'a'",
")",
";",
"if",
"(",
"$",
"f",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"L... | Write text to file
@param array $messages
@param string $file
@throws Exception | [
"Write",
"text",
"to",
"file"
] | eb48c5c409b2ff2b023f6c65c46af3364ae98e7e | https://github.com/dshovchko/debulog/blob/eb48c5c409b2ff2b023f6c65c46af3364ae98e7e/src/Logger.php#L170-L184 | train |
cundd/test-flight | src/Configuration/ConfigurationProvider.php | ConfigurationProvider.setConfiguration | public function setConfiguration(array $configuration): ConfigurationProviderInterface
{
if (isset($configuration['configuration']) && $configuration['configuration']) {
$configuration = array_merge(
$configuration,
$this->load($configuration['configuration']),
array_filter($configuration)
);
}
$this->configuration = $configuration;
return $this;
} | php | public function setConfiguration(array $configuration): ConfigurationProviderInterface
{
if (isset($configuration['configuration']) && $configuration['configuration']) {
$configuration = array_merge(
$configuration,
$this->load($configuration['configuration']),
array_filter($configuration)
);
}
$this->configuration = $configuration;
return $this;
} | [
"public",
"function",
"setConfiguration",
"(",
"array",
"$",
"configuration",
")",
":",
"ConfigurationProviderInterface",
"{",
"if",
"(",
"isset",
"(",
"$",
"configuration",
"[",
"'configuration'",
"]",
")",
"&&",
"$",
"configuration",
"[",
"'configuration'",
"]",... | Sets the underlying configuration
@param array $configuration
@return ConfigurationProviderInterface | [
"Sets",
"the",
"underlying",
"configuration"
] | 9d8424dfb586f823f9dad2dcb81ff3986e255d56 | https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/Configuration/ConfigurationProvider.php#L40-L53 | train |
droid-php/droid-mysql | src/Db/Config.php | Config.initConnectionData | protected function initConnectionData()
{
if ($this->connectionData) {
return;
}
if (!$this->connectionUrl) {
throw new \UnexpectedValueException(
'Expected a connectionUrl, got nowt.'
);
}
$parsed = parse_url($this->connectionUrl);
if ($parsed === false) {
throw new UnexpectedValueException(
'Expected a sensible connectionUrl, got nowt but rubbish.'
);
}
$this->connectionData = $parsed;
} | php | protected function initConnectionData()
{
if ($this->connectionData) {
return;
}
if (!$this->connectionUrl) {
throw new \UnexpectedValueException(
'Expected a connectionUrl, got nowt.'
);
}
$parsed = parse_url($this->connectionUrl);
if ($parsed === false) {
throw new UnexpectedValueException(
'Expected a sensible connectionUrl, got nowt but rubbish.'
);
}
$this->connectionData = $parsed;
} | [
"protected",
"function",
"initConnectionData",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connectionData",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"connectionUrl",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",... | Parse a connection url and populate connectionData with the result.
@throws \UnexpectedValueException | [
"Parse",
"a",
"connection",
"url",
"and",
"populate",
"connectionData",
"with",
"the",
"result",
"."
] | d363ec067495073469a25b48b97d460b6fba938a | https://github.com/droid-php/droid-mysql/blob/d363ec067495073469a25b48b97d460b6fba938a/src/Db/Config.php#L102-L121 | train |
PHPComponent/AtomicFile | src/AtomicFileReader.php | AtomicFileReader.readFileLine | public function readFileLine($length = null)
{
$this->openFile();
//gets warning "fgets(): Length parameter must be greater than 0" when parameter is null and is passed to function
if($length === null)
{
$line = fgets($this->getFile());
}
else
{
$line = fgets($this->getFile(), $length);
}
return $line;
} | php | public function readFileLine($length = null)
{
$this->openFile();
//gets warning "fgets(): Length parameter must be greater than 0" when parameter is null and is passed to function
if($length === null)
{
$line = fgets($this->getFile());
}
else
{
$line = fgets($this->getFile(), $length);
}
return $line;
} | [
"public",
"function",
"readFileLine",
"(",
"$",
"length",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"openFile",
"(",
")",
";",
"//gets warning \"fgets(): Length parameter must be greater than 0\" when parameter is null and is passed to function",
"if",
"(",
"$",
"length",
... | Read line from file
@param null|int $length
@return bool|string | [
"Read",
"line",
"from",
"file"
] | 9ca88297bdbdeb3bcbecdcbe884e4f412bb2cfe8 | https://github.com/PHPComponent/AtomicFile/blob/9ca88297bdbdeb3bcbecdcbe884e4f412bb2cfe8/src/AtomicFileReader.php#L86-L100 | train |
slickframework/orm | src/Mapper/Relation/RelationsUtilityMethods.php | RelationsUtilityMethods.getParentRepository | public function getParentRepository()
{
if (null == $this->parentRepository) {
$this->setParentRepository(
Orm::getRepository($this->getParentEntity())
);
}
return $this->parentRepository;
} | php | public function getParentRepository()
{
if (null == $this->parentRepository) {
$this->setParentRepository(
Orm::getRepository($this->getParentEntity())
);
}
return $this->parentRepository;
} | [
"public",
"function",
"getParentRepository",
"(",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"this",
"->",
"parentRepository",
")",
"{",
"$",
"this",
"->",
"setParentRepository",
"(",
"Orm",
"::",
"getRepository",
"(",
"$",
"this",
"->",
"getParentEntity",
"(",... | Gets parent entity repository
@return \Slick\Orm\Repository\EntityRepository | [
"Gets",
"parent",
"entity",
"repository"
] | c5c782f5e3a46cdc6c934eda4411cb9edc48f969 | https://github.com/slickframework/orm/blob/c5c782f5e3a46cdc6c934eda4411cb9edc48f969/src/Mapper/Relation/RelationsUtilityMethods.php#L63-L71 | train |
calgamo/collection | src/Queue.php | Queue.dequeue | public function dequeue(&$item) : Queue
{
$values = $this->_shift($item);
$this->setValues($values);
return $this;
} | php | public function dequeue(&$item) : Queue
{
$values = $this->_shift($item);
$this->setValues($values);
return $this;
} | [
"public",
"function",
"dequeue",
"(",
"&",
"$",
"item",
")",
":",
"Queue",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"_shift",
"(",
"$",
"item",
")",
";",
"$",
"this",
"->",
"setValues",
"(",
"$",
"values",
")",
";",
"return",
"$",
"this",
";",... | Take item from the queue
@param mixed &$item
@return Queue | [
"Take",
"item",
"from",
"the",
"queue"
] | 65b2efa612bc8250cbe0e1749c7d77176bd0c3c5 | https://github.com/calgamo/collection/blob/65b2efa612bc8250cbe0e1749c7d77176bd0c3c5/src/Queue.php#L28-L33 | train |
calgamo/collection | src/Queue.php | Queue.enqueue | public function enqueue(... $items) : Queue
{
$values = $this->_pushAll($items);
$this->setValues($values);
return $this;
} | php | public function enqueue(... $items) : Queue
{
$values = $this->_pushAll($items);
$this->setValues($values);
return $this;
} | [
"public",
"function",
"enqueue",
"(",
"...",
"$",
"items",
")",
":",
"Queue",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"_pushAll",
"(",
"$",
"items",
")",
";",
"$",
"this",
"->",
"setValues",
"(",
"$",
"values",
")",
";",
"return",
"$",
"this",
... | Add item to the queue
@param mixed $items
@return Queue | [
"Add",
"item",
"to",
"the",
"queue"
] | 65b2efa612bc8250cbe0e1749c7d77176bd0c3c5 | https://github.com/calgamo/collection/blob/65b2efa612bc8250cbe0e1749c7d77176bd0c3c5/src/Queue.php#L42-L47 | train |
kambo-1st/HttpMessage | src/Message.php | Message.normalizeBody | private function normalizeBody($body = null)
{
$body = $body ? $body : new Stream(fopen('php://temp', 'r+'));
if (is_string($body)) {
$memoryStream = fopen('php://temp', 'r+');
fwrite($memoryStream, $body);
rewind($memoryStream);
$body = new Stream($memoryStream);
} elseif (!($body instanceof StreamInterface)) {
throw new InvalidArgumentException(
'Body must be a string, null or implement Psr\Http\Message\StreamInterface'
);
}
return $body;
} | php | private function normalizeBody($body = null)
{
$body = $body ? $body : new Stream(fopen('php://temp', 'r+'));
if (is_string($body)) {
$memoryStream = fopen('php://temp', 'r+');
fwrite($memoryStream, $body);
rewind($memoryStream);
$body = new Stream($memoryStream);
} elseif (!($body instanceof StreamInterface)) {
throw new InvalidArgumentException(
'Body must be a string, null or implement Psr\Http\Message\StreamInterface'
);
}
return $body;
} | [
"private",
"function",
"normalizeBody",
"(",
"$",
"body",
"=",
"null",
")",
"{",
"$",
"body",
"=",
"$",
"body",
"?",
"$",
"body",
":",
"new",
"Stream",
"(",
"fopen",
"(",
"'php://temp'",
",",
"'r+'",
")",
")",
";",
"if",
"(",
"is_string",
"(",
"$",... | Normalize provided body and ensure that the result object is Stream.
@param StreamInterface|string|null $body The request body object
@return Stream Normalized body
@throws \InvalidArgumentException If an unsupported argument type is provided. | [
"Normalize",
"provided",
"body",
"and",
"ensure",
"that",
"the",
"result",
"object",
"is",
"Stream",
"."
] | 38877b9d895f279fdd5bdf957d8f23f9808a940a | https://github.com/kambo-1st/HttpMessage/blob/38877b9d895f279fdd5bdf957d8f23f9808a940a/src/Message.php#L325-L340 | train |
kambo-1st/HttpMessage | src/Message.php | Message.normalizeHeaders | private function normalizeHeaders($headers)
{
if (is_array($headers)) {
$headers = new Headers($headers);
} elseif (!($headers instanceof Headers)) {
throw new InvalidArgumentException(
'Headers must be an array or instance of Headers'
);
}
return $headers;
} | php | private function normalizeHeaders($headers)
{
if (is_array($headers)) {
$headers = new Headers($headers);
} elseif (!($headers instanceof Headers)) {
throw new InvalidArgumentException(
'Headers must be an array or instance of Headers'
);
}
return $headers;
} | [
"private",
"function",
"normalizeHeaders",
"(",
"$",
"headers",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"headers",
")",
")",
"{",
"$",
"headers",
"=",
"new",
"Headers",
"(",
"$",
"headers",
")",
";",
"}",
"elseif",
"(",
"!",
"(",
"$",
"headers",
... | Normalize provided headers and ensure that the result object is Headers.
@param Headers|array $headers The request body object
@return Headers Normalized headers
@throws \InvalidArgumentException If an unsupported argument type is provided. | [
"Normalize",
"provided",
"headers",
"and",
"ensure",
"that",
"the",
"result",
"object",
"is",
"Headers",
"."
] | 38877b9d895f279fdd5bdf957d8f23f9808a940a | https://github.com/kambo-1st/HttpMessage/blob/38877b9d895f279fdd5bdf957d8f23f9808a940a/src/Message.php#L351-L362 | train |
kambo-1st/HttpMessage | src/Message.php | Message.validateProtocol | private function validateProtocol($version)
{
$valid = [
'1.0' => true,
'1.1' => true,
'2.0' => true,
];
if (!isset($valid[$version])) {
throw new InvalidArgumentException('Invalid HTTP version. Must be one of: 1.0, 1.1, 2.0');
}
} | php | private function validateProtocol($version)
{
$valid = [
'1.0' => true,
'1.1' => true,
'2.0' => true,
];
if (!isset($valid[$version])) {
throw new InvalidArgumentException('Invalid HTTP version. Must be one of: 1.0, 1.1, 2.0');
}
} | [
"private",
"function",
"validateProtocol",
"(",
"$",
"version",
")",
"{",
"$",
"valid",
"=",
"[",
"'1.0'",
"=>",
"true",
",",
"'1.1'",
"=>",
"true",
",",
"'2.0'",
"=>",
"true",
",",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"valid",
"[",
"$",
... | Validate version of the HTTP protocol.
@param string $version Version of the HTTP protocol.
@throws \InvalidArgumentException When the protocol version is not valid. | [
"Validate",
"version",
"of",
"the",
"HTTP",
"protocol",
"."
] | 38877b9d895f279fdd5bdf957d8f23f9808a940a | https://github.com/kambo-1st/HttpMessage/blob/38877b9d895f279fdd5bdf957d8f23f9808a940a/src/Message.php#L385-L396 | train |
teamelf/core | src/Extension/ExtensionManager.php | ExtensionManager.getPackages | public function getPackages()
{
$filename = $this->vendorPath . '/composer/installed.json';
if (!file_exists($filename)) {
throw new Exception($filename . ' not exists!');
}
$packages = [];
foreach (json_decode(file_get_contents($filename), true) as $package) {
if ($package['type'] === 'teamelf-extension') {
$packages[] = $package;
}
}
return $packages;
} | php | public function getPackages()
{
$filename = $this->vendorPath . '/composer/installed.json';
if (!file_exists($filename)) {
throw new Exception($filename . ' not exists!');
}
$packages = [];
foreach (json_decode(file_get_contents($filename), true) as $package) {
if ($package['type'] === 'teamelf-extension') {
$packages[] = $package;
}
}
return $packages;
} | [
"public",
"function",
"getPackages",
"(",
")",
"{",
"$",
"filename",
"=",
"$",
"this",
"->",
"vendorPath",
".",
"'/composer/installed.json'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
... | get install packages
@return array
@throws Exception | [
"get",
"install",
"packages"
] | 653fc6e27f42239c2a8998a5fea325480e9dd39e | https://github.com/teamelf/core/blob/653fc6e27f42239c2a8998a5fea325480e9dd39e/src/Extension/ExtensionManager.php#L50-L63 | train |
teamelf/core | src/Extension/ExtensionManager.php | ExtensionManager.load | public function load()
{
$this->extensions = [];
foreach ($this->getPackages() as $package) {
[$v, $p] = explode('/', $package['name']);
$extension = Extension::findBy([
'vendor' => $v,
'package' => $p
]);
if (!$extension) {
$extension = (new Extension())
->vendor($v)
->package($p);
}
$extension
->version($package['version'] ?? '')
->description($package['description'] ?? '')
->save();
$this->extensions[] = $extension;
}
return $this;
} | php | public function load()
{
$this->extensions = [];
foreach ($this->getPackages() as $package) {
[$v, $p] = explode('/', $package['name']);
$extension = Extension::findBy([
'vendor' => $v,
'package' => $p
]);
if (!$extension) {
$extension = (new Extension())
->vendor($v)
->package($p);
}
$extension
->version($package['version'] ?? '')
->description($package['description'] ?? '')
->save();
$this->extensions[] = $extension;
}
return $this;
} | [
"public",
"function",
"load",
"(",
")",
"{",
"$",
"this",
"->",
"extensions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getPackages",
"(",
")",
"as",
"$",
"package",
")",
"{",
"[",
"$",
"v",
",",
"$",
"p",
"]",
"=",
"explode",
"("... | sync install packages with extension repository
@return $this | [
"sync",
"install",
"packages",
"with",
"extension",
"repository"
] | 653fc6e27f42239c2a8998a5fea325480e9dd39e | https://github.com/teamelf/core/blob/653fc6e27f42239c2a8998a5fea325480e9dd39e/src/Extension/ExtensionManager.php#L70-L91 | train |
gossi/trixionary | src/model/Base/Group.php | Group.countSkillGroups | public function countSkillGroups(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collSkillGroupsPartial && !$this->isNew();
if (null === $this->collSkillGroups || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collSkillGroups) {
return 0;
}
if ($partial && !$criteria) {
return count($this->getSkillGroups());
}
$query = ChildSkillGroupQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterByGroup($this)
->count($con);
}
return count($this->collSkillGroups);
} | php | public function countSkillGroups(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collSkillGroupsPartial && !$this->isNew();
if (null === $this->collSkillGroups || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collSkillGroups) {
return 0;
}
if ($partial && !$criteria) {
return count($this->getSkillGroups());
}
$query = ChildSkillGroupQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterByGroup($this)
->count($con);
}
return count($this->collSkillGroups);
} | [
"public",
"function",
"countSkillGroups",
"(",
"Criteria",
"$",
"criteria",
"=",
"null",
",",
"$",
"distinct",
"=",
"false",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"$",
"partial",
"=",
"$",
"this",
"->",
"collSkillGroupsPartial",
"&&"... | Returns the number of related SkillGroup objects.
@param Criteria $criteria
@param boolean $distinct
@param ConnectionInterface $con
@return int Count of related SkillGroup objects.
@throws PropelException | [
"Returns",
"the",
"number",
"of",
"related",
"SkillGroup",
"objects",
"."
] | 221a6c5322473d7d7f8e322958a3ee46d87da150 | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Base/Group.php#L1572-L1595 | train |
gossi/trixionary | src/model/Base/Group.php | Group.initSkills | public function initSkills()
{
$this->collSkills = new ObjectCollection();
$this->collSkillsPartial = true;
$this->collSkills->setModel('\gossi\trixionary\model\Skill');
} | php | public function initSkills()
{
$this->collSkills = new ObjectCollection();
$this->collSkillsPartial = true;
$this->collSkills->setModel('\gossi\trixionary\model\Skill');
} | [
"public",
"function",
"initSkills",
"(",
")",
"{",
"$",
"this",
"->",
"collSkills",
"=",
"new",
"ObjectCollection",
"(",
")",
";",
"$",
"this",
"->",
"collSkillsPartial",
"=",
"true",
";",
"$",
"this",
"->",
"collSkills",
"->",
"setModel",
"(",
"'\\gossi\\... | Initializes the collSkills crossRef collection.
By default this just sets the collSkills collection to an empty collection (like clearSkills());
however, you may wish to override this method in your stub class to provide setting appropriate
to your application -- for example, setting the initial array to the values stored in database.
@return void | [
"Initializes",
"the",
"collSkills",
"crossRef",
"collection",
"."
] | 221a6c5322473d7d7f8e322958a3ee46d87da150 | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Base/Group.php#L1695-L1701 | train |
gossi/trixionary | src/model/Base/Group.php | Group.countSkills | public function countSkills(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collSkillsPartial && !$this->isNew();
if (null === $this->collSkills || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collSkills) {
return 0;
} else {
if ($partial && !$criteria) {
return count($this->getSkills());
}
$query = ChildSkillQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterByGroup($this)
->count($con);
}
} else {
return count($this->collSkills);
}
} | php | public function countSkills(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
{
$partial = $this->collSkillsPartial && !$this->isNew();
if (null === $this->collSkills || null !== $criteria || $partial) {
if ($this->isNew() && null === $this->collSkills) {
return 0;
} else {
if ($partial && !$criteria) {
return count($this->getSkills());
}
$query = ChildSkillQuery::create(null, $criteria);
if ($distinct) {
$query->distinct();
}
return $query
->filterByGroup($this)
->count($con);
}
} else {
return count($this->collSkills);
}
} | [
"public",
"function",
"countSkills",
"(",
"Criteria",
"$",
"criteria",
"=",
"null",
",",
"$",
"distinct",
"=",
"false",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"$",
"partial",
"=",
"$",
"this",
"->",
"collSkillsPartial",
"&&",
"!",
... | Gets the number of Skill objects related by a many-to-many relationship
to the current object by way of the kk_trixionary_skill_group cross-reference table.
@param Criteria $criteria Optional query object to filter the query
@param boolean $distinct Set to true to force count distinct
@param ConnectionInterface $con Optional connection object
@return int the number of related Skill objects | [
"Gets",
"the",
"number",
"of",
"Skill",
"objects",
"related",
"by",
"a",
"many",
"-",
"to",
"-",
"many",
"relationship",
"to",
"the",
"current",
"object",
"by",
"way",
"of",
"the",
"kk_trixionary_skill_group",
"cross",
"-",
"reference",
"table",
"."
] | 221a6c5322473d7d7f8e322958a3ee46d87da150 | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Base/Group.php#L1806-L1830 | train |
gossi/trixionary | src/model/Base/Group.php | Group.addSkill | public function addSkill(ChildSkill $skill)
{
if ($this->collSkills === null) {
$this->initSkills();
}
if (!$this->getSkills()->contains($skill)) {
// only add it if the **same** object is not already associated
$this->collSkills->push($skill);
$this->doAddSkill($skill);
}
return $this;
} | php | public function addSkill(ChildSkill $skill)
{
if ($this->collSkills === null) {
$this->initSkills();
}
if (!$this->getSkills()->contains($skill)) {
// only add it if the **same** object is not already associated
$this->collSkills->push($skill);
$this->doAddSkill($skill);
}
return $this;
} | [
"public",
"function",
"addSkill",
"(",
"ChildSkill",
"$",
"skill",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collSkills",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"initSkills",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getSkills",
"... | Associate a ChildSkill to this object
through the kk_trixionary_skill_group cross reference table.
@param ChildSkill $skill
@return ChildGroup The current object (for fluent API support) | [
"Associate",
"a",
"ChildSkill",
"to",
"this",
"object",
"through",
"the",
"kk_trixionary_skill_group",
"cross",
"reference",
"table",
"."
] | 221a6c5322473d7d7f8e322958a3ee46d87da150 | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Base/Group.php#L1839-L1852 | train |
gossi/trixionary | src/model/Base/Group.php | Group.removeSkill | public function removeSkill(ChildSkill $skill)
{
if ($this->getSkills()->contains($skill)) { $skillGroup = new ChildSkillGroup();
$skillGroup->setSkill($skill);
if ($skill->isGroupsLoaded()) {
//remove the back reference if available
$skill->getGroups()->removeObject($this);
}
$skillGroup->setGroup($this);
$this->removeSkillGroup(clone $skillGroup);
$skillGroup->clear();
$this->collSkills->remove($this->collSkills->search($skill));
if (null === $this->skillsScheduledForDeletion) {
$this->skillsScheduledForDeletion = clone $this->collSkills;
$this->skillsScheduledForDeletion->clear();
}
$this->skillsScheduledForDeletion->push($skill);
}
return $this;
} | php | public function removeSkill(ChildSkill $skill)
{
if ($this->getSkills()->contains($skill)) { $skillGroup = new ChildSkillGroup();
$skillGroup->setSkill($skill);
if ($skill->isGroupsLoaded()) {
//remove the back reference if available
$skill->getGroups()->removeObject($this);
}
$skillGroup->setGroup($this);
$this->removeSkillGroup(clone $skillGroup);
$skillGroup->clear();
$this->collSkills->remove($this->collSkills->search($skill));
if (null === $this->skillsScheduledForDeletion) {
$this->skillsScheduledForDeletion = clone $this->collSkills;
$this->skillsScheduledForDeletion->clear();
}
$this->skillsScheduledForDeletion->push($skill);
}
return $this;
} | [
"public",
"function",
"removeSkill",
"(",
"ChildSkill",
"$",
"skill",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getSkills",
"(",
")",
"->",
"contains",
"(",
"$",
"skill",
")",
")",
"{",
"$",
"skillGroup",
"=",
"new",
"ChildSkillGroup",
"(",
")",
";",
... | Remove skill of this object
through the kk_trixionary_skill_group cross reference table.
@param ChildSkill $skill
@return ChildGroup The current object (for fluent API support) | [
"Remove",
"skill",
"of",
"this",
"object",
"through",
"the",
"kk_trixionary_skill_group",
"cross",
"reference",
"table",
"."
] | 221a6c5322473d7d7f8e322958a3ee46d87da150 | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Base/Group.php#L1886-L1912 | train |
WellCommerce/DataGrid | Configuration/EventHandlers.php | EventHandlers.get | public function get(string $name) : EventHandlerInterface
{
if (!isset($this->eventHandlers[$name])) {
throw new \InvalidArgumentException(sprintf('DataGrid event handler %s not found', $name));
}
return $this->eventHandlers[$name];
} | php | public function get(string $name) : EventHandlerInterface
{
if (!isset($this->eventHandlers[$name])) {
throw new \InvalidArgumentException(sprintf('DataGrid event handler %s not found', $name));
}
return $this->eventHandlers[$name];
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"name",
")",
":",
"EventHandlerInterface",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"("... | Returns chosen event handler by its function name
@param $name
@return EventHandlerInterface
@throws \InvalidArgumentException | [
"Returns",
"chosen",
"event",
"handler",
"by",
"its",
"function",
"name"
] | 5ce3cd47c7902aaeb07c343a76574399286f56ff | https://github.com/WellCommerce/DataGrid/blob/5ce3cd47c7902aaeb07c343a76574399286f56ff/Configuration/EventHandlers.php#L77-L84 | train |
aruberutochan/repository | src/Http/Controllers/AbstractController.php | AbstractController.makeRequest | protected function makeRequest($type) {
if(isset($this->{$type . 'Request'}) && $this->{$type . 'Request'}) {
$request = app()->make($this->{$type . 'Request'});
if (!$request instanceof Request) {
throw new \Exception("Class {$this->{$type . 'Request'}} must be an instance of Illuminate\\Http\\Request");
}
return $request;
}
} | php | protected function makeRequest($type) {
if(isset($this->{$type . 'Request'}) && $this->{$type . 'Request'}) {
$request = app()->make($this->{$type . 'Request'});
if (!$request instanceof Request) {
throw new \Exception("Class {$this->{$type . 'Request'}} must be an instance of Illuminate\\Http\\Request");
}
return $request;
}
} | [
"protected",
"function",
"makeRequest",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"type",
".",
"'Request'",
"}",
")",
"&&",
"$",
"this",
"->",
"{",
"$",
"type",
".",
"'Request'",
"}",
")",
"{",
"$",
"reques... | Create a FormRequest declared in property type
@param string $type
@return Illuminate\Http\Request | void | [
"Create",
"a",
"FormRequest",
"declared",
"in",
"property",
"type"
] | 4ecc5eb37377af8f000af76c886c217479dcf454 | https://github.com/aruberutochan/repository/blob/4ecc5eb37377af8f000af76c886c217479dcf454/src/Http/Controllers/AbstractController.php#L15-L25 | train |
aruberutochan/repository | src/Http/Controllers/AbstractController.php | AbstractController.maybeMakeResource | protected function maybeMakeResource($type, $data, $status = 200) {
$resourceName = $type . 'Resource';
if(isset($this->$resourceName) && $this->$resourceName) {
$class = $this->$resourceName;
return (new $class($data))->response()
->setStatusCode($status);
} elseif(is_bool($data)){
return strval($data);
} else {
return $data;
}
} | php | protected function maybeMakeResource($type, $data, $status = 200) {
$resourceName = $type . 'Resource';
if(isset($this->$resourceName) && $this->$resourceName) {
$class = $this->$resourceName;
return (new $class($data))->response()
->setStatusCode($status);
} elseif(is_bool($data)){
return strval($data);
} else {
return $data;
}
} | [
"protected",
"function",
"maybeMakeResource",
"(",
"$",
"type",
",",
"$",
"data",
",",
"$",
"status",
"=",
"200",
")",
"{",
"$",
"resourceName",
"=",
"$",
"type",
".",
"'Resource'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"$",
"resourceName",
... | If is defined return a Api Resource object
@param string $type
@param collection $data
@return Resource | Model | [
"If",
"is",
"defined",
"return",
"a",
"Api",
"Resource",
"object"
] | 4ecc5eb37377af8f000af76c886c217479dcf454 | https://github.com/aruberutochan/repository/blob/4ecc5eb37377af8f000af76c886c217479dcf454/src/Http/Controllers/AbstractController.php#L34-L45 | train |
smeeckaert/di | src/DI/AutoBuild.php | AutoBuild.getDefaultParameters | public static function getDefaultParameters($className)
{
if (!isset(static::$registeredClasses[$className])) {
return null;
}
$params = static::$registeredClasses[$className];
if (is_callable($params)) {
$params = $params();
}
return $params;
} | php | public static function getDefaultParameters($className)
{
if (!isset(static::$registeredClasses[$className])) {
return null;
}
$params = static::$registeredClasses[$className];
if (is_callable($params)) {
$params = $params();
}
return $params;
} | [
"public",
"static",
"function",
"getDefaultParameters",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"registeredClasses",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"params",
"=",
... | Get the registered parameters for a given class
@param $className
@return mixed|null | [
"Get",
"the",
"registered",
"parameters",
"for",
"a",
"given",
"class"
] | 3d5e3ed20038bed9a42fcd2821970f77112b8d3c | https://github.com/smeeckaert/di/blob/3d5e3ed20038bed9a42fcd2821970f77112b8d3c/src/DI/AutoBuild.php#L42-L52 | train |
smeeckaert/di | src/DI/AutoBuild.php | AutoBuild.getInstance | public static function getInstance($className)
{
if (!isset(static::$registeredClasses[$className])) {
return null;
}
/** @var DI $object */
$object = $className::build()->auto();
return $object;
} | php | public static function getInstance($className)
{
if (!isset(static::$registeredClasses[$className])) {
return null;
}
/** @var DI $object */
$object = $className::build()->auto();
return $object;
} | [
"public",
"static",
"function",
"getInstance",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"registeredClasses",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"/** @var DI $object */",
"$",
... | Get a new instance of a registered class, returns null if the class is not registered
@param $className
@return DI | [
"Get",
"a",
"new",
"instance",
"of",
"a",
"registered",
"class",
"returns",
"null",
"if",
"the",
"class",
"is",
"not",
"registered"
] | 3d5e3ed20038bed9a42fcd2821970f77112b8d3c | https://github.com/smeeckaert/di/blob/3d5e3ed20038bed9a42fcd2821970f77112b8d3c/src/DI/AutoBuild.php#L60-L68 | train |
Xannn94/support | src/Providers/AuthorizationServiceProvider.php | AuthorizationServiceProvider.defineMany | protected function defineMany($gate, $class, array $policies)
{
foreach ($policies as $method => $ability) {
$gate->define($ability, "$class@$method");
}
} | php | protected function defineMany($gate, $class, array $policies)
{
foreach ($policies as $method => $ability) {
$gate->define($ability, "$class@$method");
}
} | [
"protected",
"function",
"defineMany",
"(",
"$",
"gate",
",",
"$",
"class",
",",
"array",
"$",
"policies",
")",
"{",
"foreach",
"(",
"$",
"policies",
"as",
"$",
"method",
"=>",
"$",
"ability",
")",
"{",
"$",
"gate",
"->",
"define",
"(",
"$",
"ability... | Define policies.
@param \Illuminate\Contracts\Auth\Access\Gate $gate
@param string $class
@param array $policies | [
"Define",
"policies",
"."
] | 92f4da1b0d47b769af3c65cd1d672b68809262c8 | https://github.com/Xannn94/support/blob/92f4da1b0d47b769af3c65cd1d672b68809262c8/src/Providers/AuthorizationServiceProvider.php#L24-L29 | train |
gliverphp/helpers | src/StringHelper/StringHelper.php | StringHelper.normalize | public static function normalize($pattern)
{
//normalize the string pattern and return safe pattern for use
return self::$delimiter.trim($pattern, self::$delimiter).self::$delimiter;
} | php | public static function normalize($pattern)
{
//normalize the string pattern and return safe pattern for use
return self::$delimiter.trim($pattern, self::$delimiter).self::$delimiter;
} | [
"public",
"static",
"function",
"normalize",
"(",
"$",
"pattern",
")",
"{",
"//normalize the string pattern and return safe pattern for use",
"return",
"self",
"::",
"$",
"delimiter",
".",
"trim",
"(",
"$",
"pattern",
",",
"self",
"::",
"$",
"delimiter",
")",
".",... | This method normalizes the regular expression pattern before we use it
@param string $pattern The regular expression string to be used
@return string Normalized/Sanitized regular expression string
@throws This method does not throw an error | [
"This",
"method",
"normalizes",
"the",
"regular",
"expression",
"pattern",
"before",
"we",
"use",
"it"
] | c5204df8169fad55f5b273422e45f56164373ab8 | https://github.com/gliverphp/helpers/blob/c5204df8169fad55f5b273422e45f56164373ab8/src/StringHelper/StringHelper.php#L58-L63 | train |
gliverphp/helpers | src/StringHelper/StringHelper.php | StringHelper.sanitize | public static function sanitize($string, $mask)
{
//check if the input mask is an array
if( is_array($mask))
{
//assign value to parts
$parts = $mask;
}
//check if $mask is a string
else if( is_string($mask))
{
//divide string into substrings
$parts = str_split($mask);
}
//not any of the above, return the string
else
{
//return string
return $string;
}
//loop through the parts array normalizing each part
foreach ($parts as $part)
{
//normalize the part
$normalized = self::normalize("\\{$part}");
//search string and replace normalized string in place of original string from input $string
$string = preg_replace("{$normalized}m", "\\{$part}", $string);
}
//return the string after sanitizing is complete
return $string;
} | php | public static function sanitize($string, $mask)
{
//check if the input mask is an array
if( is_array($mask))
{
//assign value to parts
$parts = $mask;
}
//check if $mask is a string
else if( is_string($mask))
{
//divide string into substrings
$parts = str_split($mask);
}
//not any of the above, return the string
else
{
//return string
return $string;
}
//loop through the parts array normalizing each part
foreach ($parts as $part)
{
//normalize the part
$normalized = self::normalize("\\{$part}");
//search string and replace normalized string in place of original string from input $string
$string = preg_replace("{$normalized}m", "\\{$part}", $string);
}
//return the string after sanitizing is complete
return $string;
} | [
"public",
"static",
"function",
"sanitize",
"(",
"$",
"string",
",",
"$",
"mask",
")",
"{",
"//check if the input mask is an array",
"if",
"(",
"is_array",
"(",
"$",
"mask",
")",
")",
"{",
"//assign value to parts",
"$",
"parts",
"=",
"$",
"mask",
";",
"}",
... | This method loops through the characters of a string, replacing them with regualar expression friendly
character representations.
@param string $string The string to be converted
@param string $mask
@return string The string after it has been sanitized | [
"This",
"method",
"loops",
"through",
"the",
"characters",
"of",
"a",
"string",
"replacing",
"them",
"with",
"regualar",
"expression",
"friendly",
"character",
"representations",
"."
] | c5204df8169fad55f5b273422e45f56164373ab8 | https://github.com/gliverphp/helpers/blob/c5204df8169fad55f5b273422e45f56164373ab8/src/StringHelper/StringHelper.php#L168-L208 | train |
gliverphp/helpers | src/StringHelper/StringHelper.php | StringHelper.unique | public static function unique($string)
{
//set intitial unique var sting as empty
$unique = '';
//split the string into substrings
$parts = str_split($string);
//loop through the sting parts array removing duplicated characters
foreach ($parts as $part)
{
//add this character if it doesnt exist yet
if( ! strstr($unique, $part) )
{
//add this character to the main unique array
$unique .= $part;
}
}
//return the unique string
return $unique;
} | php | public static function unique($string)
{
//set intitial unique var sting as empty
$unique = '';
//split the string into substrings
$parts = str_split($string);
//loop through the sting parts array removing duplicated characters
foreach ($parts as $part)
{
//add this character if it doesnt exist yet
if( ! strstr($unique, $part) )
{
//add this character to the main unique array
$unique .= $part;
}
}
//return the unique string
return $unique;
} | [
"public",
"static",
"function",
"unique",
"(",
"$",
"string",
")",
"{",
"//set intitial unique var sting as empty",
"$",
"unique",
"=",
"''",
";",
"//split the string into substrings",
"$",
"parts",
"=",
"str_split",
"(",
"$",
"string",
")",
";",
"//loop through the... | This method removes duplicates from a string
@param string $string The string for which duplicates are to be removed
@return string String with only unique values | [
"This",
"method",
"removes",
"duplicates",
"from",
"a",
"string"
] | c5204df8169fad55f5b273422e45f56164373ab8 | https://github.com/gliverphp/helpers/blob/c5204df8169fad55f5b273422e45f56164373ab8/src/StringHelper/StringHelper.php#L216-L240 | train |
gliverphp/helpers | src/StringHelper/StringHelper.php | StringHelper.indexOf | public static function indexOf($string, $substring, $offset = null)
{
//get the position of this string in the main string
$position = strpos($string, $substring, $offset);
//return -1 of the substring was not found
if( ! is_int($position) )
{
//return string position as -1
return -1;
}
//return actual string position if found
return $position;
} | php | public static function indexOf($string, $substring, $offset = null)
{
//get the position of this string in the main string
$position = strpos($string, $substring, $offset);
//return -1 of the substring was not found
if( ! is_int($position) )
{
//return string position as -1
return -1;
}
//return actual string position if found
return $position;
} | [
"public",
"static",
"function",
"indexOf",
"(",
"$",
"string",
",",
"$",
"substring",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"//get the position of this string in the main string",
"$",
"position",
"=",
"strpos",
"(",
"$",
"string",
",",
"$",
"substring",
... | This method determines substrings within larger strings
@param string $string The main sting against which to check for substring
@param string $substring The substring to check for
@param int $offset The offset value to start from
@return int The position of the substring in the main string | [
"This",
"method",
"determines",
"substrings",
"within",
"larger",
"strings"
] | c5204df8169fad55f5b273422e45f56164373ab8 | https://github.com/gliverphp/helpers/blob/c5204df8169fad55f5b273422e45f56164373ab8/src/StringHelper/StringHelper.php#L250-L265 | train |
gliverphp/helpers | src/StringHelper/StringHelper.php | StringHelper.singular | public static function singular($string)
{
//assing the input string to a result variable
$result = $string;
//loop through the array of singular patterns, getting the regular exppression patters
foreach ($self::$singulars as $rule => $replacement)
{
//get the regular expression friendly pattern
$rule = self::normalize($rule);
//check if there is a matching pattern in the input string
if ( preg_match($rule, $string) )
{
//replace with the appropriate string and return
$result = preg_replace($rule, $replacement, $string);
//once a replacement is found, break out of the loop
break;
}
}
//return the result that was found
return $result;
} | php | public static function singular($string)
{
//assing the input string to a result variable
$result = $string;
//loop through the array of singular patterns, getting the regular exppression patters
foreach ($self::$singulars as $rule => $replacement)
{
//get the regular expression friendly pattern
$rule = self::normalize($rule);
//check if there is a matching pattern in the input string
if ( preg_match($rule, $string) )
{
//replace with the appropriate string and return
$result = preg_replace($rule, $replacement, $string);
//once a replacement is found, break out of the loop
break;
}
}
//return the result that was found
return $result;
} | [
"public",
"static",
"function",
"singular",
"(",
"$",
"string",
")",
"{",
"//assing the input string to a result variable",
"$",
"result",
"=",
"$",
"string",
";",
"//loop through the array of singular patterns, getting the regular exppression patters",
"foreach",
"(",
"$",
"... | This method gets the singular form of an input string
@param string $string The input string for which an singular term is to be found.
@return string The output string after appropriate replacement has been done. | [
"This",
"method",
"gets",
"the",
"singular",
"form",
"of",
"an",
"input",
"string"
] | c5204df8169fad55f5b273422e45f56164373ab8 | https://github.com/gliverphp/helpers/blob/c5204df8169fad55f5b273422e45f56164373ab8/src/StringHelper/StringHelper.php#L328-L355 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.