repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
webdevvie/pheanstalk-task-queue-bundle | Command/WorkerTenderCommand.php | WorkerTenderCommand.countWorkers | public function countWorkers()
{
$total = count($this->family);
$busy = 0;
$available = 0;
foreach ($this->family as &$child) {
switch ($child->status) {
case ChildProcessContainer::STATUS_ALIVE:
case ChildProcessContainer::STATUS_READY:
$available++;
break;
case ChildProcessContainer::STATUS_BUSY:
case ChildProcessContainer::STATUS_BUSY_BUT_SLEEPY:
$busy++;
break;
}
}
return array($total, $available);
} | php | public function countWorkers()
{
$total = count($this->family);
$busy = 0;
$available = 0;
foreach ($this->family as &$child) {
switch ($child->status) {
case ChildProcessContainer::STATUS_ALIVE:
case ChildProcessContainer::STATUS_READY:
$available++;
break;
case ChildProcessContainer::STATUS_BUSY:
case ChildProcessContainer::STATUS_BUSY_BUT_SLEEPY:
$busy++;
break;
}
}
return array($total, $available);
} | [
"public",
"function",
"countWorkers",
"(",
")",
"{",
"$",
"total",
"=",
"count",
"(",
"$",
"this",
"->",
"family",
")",
";",
"$",
"busy",
"=",
"0",
";",
"$",
"available",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"family",
"as",
"&",
"$",
"child",
")",
"{",
"switch",
"(",
"$",
"child",
"->",
"status",
")",
"{",
"case",
"ChildProcessContainer",
"::",
"STATUS_ALIVE",
":",
"case",
"ChildProcessContainer",
"::",
"STATUS_READY",
":",
"$",
"available",
"++",
";",
"break",
";",
"case",
"ChildProcessContainer",
"::",
"STATUS_BUSY",
":",
"case",
"ChildProcessContainer",
"::",
"STATUS_BUSY_BUT_SLEEPY",
":",
"$",
"busy",
"++",
";",
"break",
";",
"}",
"}",
"return",
"array",
"(",
"$",
"total",
",",
"$",
"available",
")",
";",
"}"
] | Returns an array with the worker counts
@return array | [
"Returns",
"an",
"array",
"with",
"the",
"worker",
"counts"
] | train | https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L178-L196 |
webdevvie/pheanstalk-task-queue-bundle | Command/WorkerTenderCommand.php | WorkerTenderCommand.moreOrLess | public function moreOrLess($total, $available)
{
$shouldHaveMoreWorkers = false;
$shouldHaveLessWorkers = false;
$minWorkers = $this->input->getOption('min-workers');
$maxWorkers = $this->input->getOption('max-workers');
$spareWorkers = $this->input->getOption('spare-workers');
if ($total < $minWorkers) {
//too little workers,spawn more please
$shouldHaveMoreWorkers = true;
$this->verboseOutput("<info>Too little workers</info>: $total / $minWorkers");
} elseif (($available < $spareWorkers) && ($total <= $maxWorkers)) {
//we have not enough spare workers we should spawn some more... unless we have reached the max workers limit
$shouldHaveMoreWorkers = true;
$this->verboseOutput("<info>Too little spare workers</info>: $available / $spareWorkers");
} elseif ($total >= $maxWorkers) {
//we should have less workers because we somehow ended up over the limit
$shouldHaveLessWorkers = true;
} elseif ($available >= $minWorkers + $spareWorkers && !$shouldHaveMoreWorkers) {
//we have more than enough workers for the amount of work we should probably kill one off.
$shouldHaveLessWorkers = true;
}
return array($shouldHaveLessWorkers, $shouldHaveMoreWorkers);
} | php | public function moreOrLess($total, $available)
{
$shouldHaveMoreWorkers = false;
$shouldHaveLessWorkers = false;
$minWorkers = $this->input->getOption('min-workers');
$maxWorkers = $this->input->getOption('max-workers');
$spareWorkers = $this->input->getOption('spare-workers');
if ($total < $minWorkers) {
//too little workers,spawn more please
$shouldHaveMoreWorkers = true;
$this->verboseOutput("<info>Too little workers</info>: $total / $minWorkers");
} elseif (($available < $spareWorkers) && ($total <= $maxWorkers)) {
//we have not enough spare workers we should spawn some more... unless we have reached the max workers limit
$shouldHaveMoreWorkers = true;
$this->verboseOutput("<info>Too little spare workers</info>: $available / $spareWorkers");
} elseif ($total >= $maxWorkers) {
//we should have less workers because we somehow ended up over the limit
$shouldHaveLessWorkers = true;
} elseif ($available >= $minWorkers + $spareWorkers && !$shouldHaveMoreWorkers) {
//we have more than enough workers for the amount of work we should probably kill one off.
$shouldHaveLessWorkers = true;
}
return array($shouldHaveLessWorkers, $shouldHaveMoreWorkers);
} | [
"public",
"function",
"moreOrLess",
"(",
"$",
"total",
",",
"$",
"available",
")",
"{",
"$",
"shouldHaveMoreWorkers",
"=",
"false",
";",
"$",
"shouldHaveLessWorkers",
"=",
"false",
";",
"$",
"minWorkers",
"=",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'min-workers'",
")",
";",
"$",
"maxWorkers",
"=",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'max-workers'",
")",
";",
"$",
"spareWorkers",
"=",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'spare-workers'",
")",
";",
"if",
"(",
"$",
"total",
"<",
"$",
"minWorkers",
")",
"{",
"//too little workers,spawn more please",
"$",
"shouldHaveMoreWorkers",
"=",
"true",
";",
"$",
"this",
"->",
"verboseOutput",
"(",
"\"<info>Too little workers</info>: $total / $minWorkers\"",
")",
";",
"}",
"elseif",
"(",
"(",
"$",
"available",
"<",
"$",
"spareWorkers",
")",
"&&",
"(",
"$",
"total",
"<=",
"$",
"maxWorkers",
")",
")",
"{",
"//we have not enough spare workers we should spawn some more... unless we have reached the max workers limit",
"$",
"shouldHaveMoreWorkers",
"=",
"true",
";",
"$",
"this",
"->",
"verboseOutput",
"(",
"\"<info>Too little spare workers</info>: $available / $spareWorkers\"",
")",
";",
"}",
"elseif",
"(",
"$",
"total",
">=",
"$",
"maxWorkers",
")",
"{",
"//we should have less workers because we somehow ended up over the limit",
"$",
"shouldHaveLessWorkers",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"available",
">=",
"$",
"minWorkers",
"+",
"$",
"spareWorkers",
"&&",
"!",
"$",
"shouldHaveMoreWorkers",
")",
"{",
"//we have more than enough workers for the amount of work we should probably kill one off.",
"$",
"shouldHaveLessWorkers",
"=",
"true",
";",
"}",
"return",
"array",
"(",
"$",
"shouldHaveLessWorkers",
",",
"$",
"shouldHaveMoreWorkers",
")",
";",
"}"
] | Returns two booleans if there should be more or less workers
@param integer $total
@param integer $busy
@param integer $available
@return array | [
"Returns",
"two",
"booleans",
"if",
"there",
"should",
"be",
"more",
"or",
"less",
"workers"
] | train | https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L206-L229 |
webdevvie/pheanstalk-task-queue-bundle | Command/WorkerTenderCommand.php | WorkerTenderCommand.findDisposableWorkers | private function findDisposableWorkers()
{
$disposableStatusses = array(ChildProcessContainer::STATUS_READY, ChildProcessContainer::STATUS_ALIVE);
foreach ($this->family as &$child) {
if (in_array($child->status, $disposableStatusses)) {
if ($child->getAge() < 10) {
//less than ten seconds old keep it alive a bit to let its do its job
continue;
}
$child->bedTime();
return true;
}
}
return false;
} | php | private function findDisposableWorkers()
{
$disposableStatusses = array(ChildProcessContainer::STATUS_READY, ChildProcessContainer::STATUS_ALIVE);
foreach ($this->family as &$child) {
if (in_array($child->status, $disposableStatusses)) {
if ($child->getAge() < 10) {
//less than ten seconds old keep it alive a bit to let its do its job
continue;
}
$child->bedTime();
return true;
}
}
return false;
} | [
"private",
"function",
"findDisposableWorkers",
"(",
")",
"{",
"$",
"disposableStatusses",
"=",
"array",
"(",
"ChildProcessContainer",
"::",
"STATUS_READY",
",",
"ChildProcessContainer",
"::",
"STATUS_ALIVE",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"family",
"as",
"&",
"$",
"child",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"child",
"->",
"status",
",",
"$",
"disposableStatusses",
")",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"getAge",
"(",
")",
"<",
"10",
")",
"{",
"//less than ten seconds old keep it alive a bit to let its do its job",
"continue",
";",
"}",
"$",
"child",
"->",
"bedTime",
"(",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Finds disposable workers, if it finds them it returns true
@return boolean | [
"Finds",
"disposable",
"workers",
"if",
"it",
"finds",
"them",
"it",
"returns",
"true"
] | train | https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L236-L251 |
webdevvie/pheanstalk-task-queue-bundle | Command/WorkerTenderCommand.php | WorkerTenderCommand.spawnChild | private function spawnChild()
{
$child = new ChildProcessContainer(
$this->consolePath,
$this->input->getOption('worker-command'),
$this->tube,
$this
);
$child->start();
return $child;
} | php | private function spawnChild()
{
$child = new ChildProcessContainer(
$this->consolePath,
$this->input->getOption('worker-command'),
$this->tube,
$this
);
$child->start();
return $child;
} | [
"private",
"function",
"spawnChild",
"(",
")",
"{",
"$",
"child",
"=",
"new",
"ChildProcessContainer",
"(",
"$",
"this",
"->",
"consolePath",
",",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'worker-command'",
")",
",",
"$",
"this",
"->",
"tube",
",",
"$",
"this",
")",
";",
"$",
"child",
"->",
"start",
"(",
")",
";",
"return",
"$",
"child",
";",
"}"
] | Spawns a new child
@return Child | [
"Spawns",
"a",
"new",
"child"
] | train | https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L271-L281 |
ronaldborla/chikka | src/Borla/Chikka/Receiver.php | Receiver.message | public function message($callback) {
// If there's a message
if ($this->hasMessage()) {
// Execute callback passing the message
$this->success = Utilities::executeCallback($callback, [
// First parameter is the message
$this->message,
// Second optional parameter is instance of Sender
Loader::sender($this->config),
]);
}
// Return self
return $this;
} | php | public function message($callback) {
// If there's a message
if ($this->hasMessage()) {
// Execute callback passing the message
$this->success = Utilities::executeCallback($callback, [
// First parameter is the message
$this->message,
// Second optional parameter is instance of Sender
Loader::sender($this->config),
]);
}
// Return self
return $this;
} | [
"public",
"function",
"message",
"(",
"$",
"callback",
")",
"{",
"// If there's a message",
"if",
"(",
"$",
"this",
"->",
"hasMessage",
"(",
")",
")",
"{",
"// Execute callback passing the message",
"$",
"this",
"->",
"success",
"=",
"Utilities",
"::",
"executeCallback",
"(",
"$",
"callback",
",",
"[",
"// First parameter is the message",
"$",
"this",
"->",
"message",
",",
"// Second optional parameter is instance of Sender",
"Loader",
"::",
"sender",
"(",
"$",
"this",
"->",
"config",
")",
",",
"]",
")",
";",
"}",
"// Return self",
"return",
"$",
"this",
";",
"}"
] | Handle message | [
"Handle",
"message"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Receiver.php#L78-L91 |
ronaldborla/chikka | src/Borla/Chikka/Receiver.php | Receiver.notification | public function notification($callback) {
// If there's a notification
if ($this->hasNotification()) {
// Execute callback passing the notification
$this->success = Utilities::executeCallback($callback, [$this->notification]);
}
// Return self
return $this;
} | php | public function notification($callback) {
// If there's a notification
if ($this->hasNotification()) {
// Execute callback passing the notification
$this->success = Utilities::executeCallback($callback, [$this->notification]);
}
// Return self
return $this;
} | [
"public",
"function",
"notification",
"(",
"$",
"callback",
")",
"{",
"// If there's a notification",
"if",
"(",
"$",
"this",
"->",
"hasNotification",
"(",
")",
")",
"{",
"// Execute callback passing the notification",
"$",
"this",
"->",
"success",
"=",
"Utilities",
"::",
"executeCallback",
"(",
"$",
"callback",
",",
"[",
"$",
"this",
"->",
"notification",
"]",
")",
";",
"}",
"// Return self",
"return",
"$",
"this",
";",
"}"
] | Handle notification | [
"Handle",
"notification"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Receiver.php#L96-L104 |
gruzilla/hydra | src/Hydra/Mappers/ArrayMapper.php | ArrayMapper.evalueateArrayQuery | public static function evalueateArrayQuery($data, $query)
{
// return direct hits
if (isset($data[$query])) {
return $data[$query];
}
$path = explode('.', $query);
$ref = $data;
$found = false;
while (count($path) > 0) {
$index = array_shift($path);
$oldref = $ref;
if ($index === 'count()') {
$ref = count($ref);
$found = true;
break;
}
if (is_array($ref) && isset($ref[$index])) {
$ref = $ref[$index];
} else if (is_object($ref) && isset($ref->$index)) {
$ref = $ref->$index;
}
if ($ref === $oldref) {
break;
}
if (count($path) === 0) {
$found = true;
break;
}
}
return $found ? $ref : null;
} | php | public static function evalueateArrayQuery($data, $query)
{
// return direct hits
if (isset($data[$query])) {
return $data[$query];
}
$path = explode('.', $query);
$ref = $data;
$found = false;
while (count($path) > 0) {
$index = array_shift($path);
$oldref = $ref;
if ($index === 'count()') {
$ref = count($ref);
$found = true;
break;
}
if (is_array($ref) && isset($ref[$index])) {
$ref = $ref[$index];
} else if (is_object($ref) && isset($ref->$index)) {
$ref = $ref->$index;
}
if ($ref === $oldref) {
break;
}
if (count($path) === 0) {
$found = true;
break;
}
}
return $found ? $ref : null;
} | [
"public",
"static",
"function",
"evalueateArrayQuery",
"(",
"$",
"data",
",",
"$",
"query",
")",
"{",
"// return direct hits",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"query",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"$",
"query",
"]",
";",
"}",
"$",
"path",
"=",
"explode",
"(",
"'.'",
",",
"$",
"query",
")",
";",
"$",
"ref",
"=",
"$",
"data",
";",
"$",
"found",
"=",
"false",
";",
"while",
"(",
"count",
"(",
"$",
"path",
")",
">",
"0",
")",
"{",
"$",
"index",
"=",
"array_shift",
"(",
"$",
"path",
")",
";",
"$",
"oldref",
"=",
"$",
"ref",
";",
"if",
"(",
"$",
"index",
"===",
"'count()'",
")",
"{",
"$",
"ref",
"=",
"count",
"(",
"$",
"ref",
")",
";",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"ref",
")",
"&&",
"isset",
"(",
"$",
"ref",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"ref",
"=",
"$",
"ref",
"[",
"$",
"index",
"]",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"ref",
")",
"&&",
"isset",
"(",
"$",
"ref",
"->",
"$",
"index",
")",
")",
"{",
"$",
"ref",
"=",
"$",
"ref",
"->",
"$",
"index",
";",
"}",
"if",
"(",
"$",
"ref",
"===",
"$",
"oldref",
")",
"{",
"break",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"path",
")",
"===",
"0",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"$",
"found",
"?",
"$",
"ref",
":",
"null",
";",
"}"
] | allows to query php-arrays
valid queries are:
Example | Result
4 | returns the 4th index of the array
key | returns the index named 'key'
key.subkey | returns the index named 'subkey' on the index
| named 'key'. this structure is allowed to go deep
key.0 | returns the index 0 of the array on the index 'key'
key.count() | returns the amount of children the index 'key' has
@param array $data the array that should be searched
@param string $query the query
@return mixed | [
"allows",
"to",
"query",
"php",
"-",
"arrays",
"valid",
"queries",
"are",
":"
] | train | https://github.com/gruzilla/hydra/blob/47f381cc48e1a26bfe2e211d8dcb54c787ea0478/src/Hydra/Mappers/ArrayMapper.php#L137-L177 |
bluetree-service/event | src/Event/Base/EventDispatcher.php | EventDispatcher.createEventObject | protected function createEventObject($eventName, array $data)
{
if (!array_key_exists($eventName, $this->options['events'])) {
throw new \InvalidArgumentException('Event is not defined.');
}
$namespace = $this->options['events'][$eventName]['object'];
$instance = new $namespace($eventName, $data);
if (!($instance instanceof EventInterface)) {
throw new \LogicException('Invalid interface of event object');
}
return $instance;
} | php | protected function createEventObject($eventName, array $data)
{
if (!array_key_exists($eventName, $this->options['events'])) {
throw new \InvalidArgumentException('Event is not defined.');
}
$namespace = $this->options['events'][$eventName]['object'];
$instance = new $namespace($eventName, $data);
if (!($instance instanceof EventInterface)) {
throw new \LogicException('Invalid interface of event object');
}
return $instance;
} | [
"protected",
"function",
"createEventObject",
"(",
"$",
"eventName",
",",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Event is not defined.'",
")",
";",
"}",
"$",
"namespace",
"=",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"eventName",
"]",
"[",
"'object'",
"]",
";",
"$",
"instance",
"=",
"new",
"$",
"namespace",
"(",
"$",
"eventName",
",",
"$",
"data",
")",
";",
"if",
"(",
"!",
"(",
"$",
"instance",
"instanceof",
"EventInterface",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Invalid interface of event object'",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | return event object or create it if not exist
@param string $eventName
@param array $data
@return EventInterface
@throws \LogicException
@throws \InvalidArgumentException | [
"return",
"event",
"object",
"or",
"create",
"it",
"if",
"not",
"exist"
] | train | https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L89-L103 |
bluetree-service/event | src/Event/Base/EventDispatcher.php | EventDispatcher.triggerEvent | public function triggerEvent($name, array $data = [])
{
try {
/** @var EventInterface $event */
$event = $this->createEventObject($name, $data);
} catch (\InvalidArgumentException $exception) {
return $this;
}
foreach ($this->options['events'][$name]['listeners'] as $eventListener) {
if ($event->isPropagationStopped()) {
$this->loggerInstance->makeLogEvent($name, $eventListener, self::EVENT_STATUS_BREAK);
break;
}
$this->executeListener($eventListener, $event, $name);
}
return $this;
} | php | public function triggerEvent($name, array $data = [])
{
try {
/** @var EventInterface $event */
$event = $this->createEventObject($name, $data);
} catch (\InvalidArgumentException $exception) {
return $this;
}
foreach ($this->options['events'][$name]['listeners'] as $eventListener) {
if ($event->isPropagationStopped()) {
$this->loggerInstance->makeLogEvent($name, $eventListener, self::EVENT_STATUS_BREAK);
break;
}
$this->executeListener($eventListener, $event, $name);
}
return $this;
} | [
"public",
"function",
"triggerEvent",
"(",
"$",
"name",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"/** @var EventInterface $event */",
"$",
"event",
"=",
"$",
"this",
"->",
"createEventObject",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"exception",
")",
"{",
"return",
"$",
"this",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"name",
"]",
"[",
"'listeners'",
"]",
"as",
"$",
"eventListener",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"isPropagationStopped",
"(",
")",
")",
"{",
"$",
"this",
"->",
"loggerInstance",
"->",
"makeLogEvent",
"(",
"$",
"name",
",",
"$",
"eventListener",
",",
"self",
"::",
"EVENT_STATUS_BREAK",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"executeListener",
"(",
"$",
"eventListener",
",",
"$",
"event",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | trigger new event with automatic call all subscribed listeners
@param string $name
@param array $data
@return $this
@throws \LogicException | [
"trigger",
"new",
"event",
"with",
"automatic",
"call",
"all",
"subscribed",
"listeners"
] | train | https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L129-L148 |
bluetree-service/event | src/Event/Base/EventDispatcher.php | EventDispatcher.addEventListener | public function addEventListener($eventName, array $listeners)
{
if (!array_key_exists($eventName, $this->options['events'])) {
$this->options['events'][$eventName] = [
'object' =>BaseEvent::class,
'listeners' => $listeners,
];
}
$this->options['events'][$eventName]['listeners'] = array_merge(
$this->options['events'][$eventName]['listeners'],
$listeners
);
return $this;
} | php | public function addEventListener($eventName, array $listeners)
{
if (!array_key_exists($eventName, $this->options['events'])) {
$this->options['events'][$eventName] = [
'object' =>BaseEvent::class,
'listeners' => $listeners,
];
}
$this->options['events'][$eventName]['listeners'] = array_merge(
$this->options['events'][$eventName]['listeners'],
$listeners
);
return $this;
} | [
"public",
"function",
"addEventListener",
"(",
"$",
"eventName",
",",
"array",
"$",
"listeners",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"eventName",
"]",
"=",
"[",
"'object'",
"=>",
"BaseEvent",
"::",
"class",
",",
"'listeners'",
"=>",
"$",
"listeners",
",",
"]",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"eventName",
"]",
"[",
"'listeners'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"eventName",
"]",
"[",
"'listeners'",
"]",
",",
"$",
"listeners",
")",
";",
"return",
"$",
"this",
";",
"}"
] | dynamically add new listener or listeners for given event name
listeners are added at end of the list
@param string $eventName
@param array $listeners
@return $this | [
"dynamically",
"add",
"new",
"listener",
"or",
"listeners",
"for",
"given",
"event",
"name",
"listeners",
"are",
"added",
"at",
"end",
"of",
"the",
"list"
] | train | https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L179-L194 |
bluetree-service/event | src/Event/Base/EventDispatcher.php | EventDispatcher.readEventConfiguration | public function readEventConfiguration($path, $type)
{
if (!file_exists($path)) {
throw new \InvalidArgumentException('File ' . $path . 'don\'t exists.');
}
$name = '\BlueEvent\Event\Config\\' . ucfirst($type) . 'Config';
if (!class_exists($name)) {
throw new \InvalidArgumentException('Incorrect configuration type: ' . $type);
}
/** @var \BlueEvent\Event\Config\ConfigReader $reader */
$reader = new $name;
return $this->setEventConfiguration($reader->readConfig($path));
} | php | public function readEventConfiguration($path, $type)
{
if (!file_exists($path)) {
throw new \InvalidArgumentException('File ' . $path . 'don\'t exists.');
}
$name = '\BlueEvent\Event\Config\\' . ucfirst($type) . 'Config';
if (!class_exists($name)) {
throw new \InvalidArgumentException('Incorrect configuration type: ' . $type);
}
/** @var \BlueEvent\Event\Config\ConfigReader $reader */
$reader = new $name;
return $this->setEventConfiguration($reader->readConfig($path));
} | [
"public",
"function",
"readEventConfiguration",
"(",
"$",
"path",
",",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'File '",
".",
"$",
"path",
".",
"'don\\'t exists.'",
")",
";",
"}",
"$",
"name",
"=",
"'\\BlueEvent\\Event\\Config\\\\'",
".",
"ucfirst",
"(",
"$",
"type",
")",
".",
"'Config'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Incorrect configuration type: '",
".",
"$",
"type",
")",
";",
"}",
"/** @var \\BlueEvent\\Event\\Config\\ConfigReader $reader */",
"$",
"reader",
"=",
"new",
"$",
"name",
";",
"return",
"$",
"this",
"->",
"setEventConfiguration",
"(",
"$",
"reader",
"->",
"readConfig",
"(",
"$",
"path",
")",
")",
";",
"}"
] | read configuration from file
@param mixed $path
@param string $type
@return $this
@throws \InvalidArgumentException | [
"read",
"configuration",
"from",
"file"
] | train | https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L217-L233 |
bluetree-service/event | src/Event/Base/EventDispatcher.php | EventDispatcher.logEvent | public function logEvent(array $events = [])
{
foreach ($events as $event) {
if (!in_array($event, $this->loggerInstance->logEvents, true)) {
$this->loggerInstance->logEvents[] = $event;
}
}
return $this;
} | php | public function logEvent(array $events = [])
{
foreach ($events as $event) {
if (!in_array($event, $this->loggerInstance->logEvents, true)) {
$this->loggerInstance->logEvents[] = $event;
}
}
return $this;
} | [
"public",
"function",
"logEvent",
"(",
"array",
"$",
"events",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"events",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"event",
",",
"$",
"this",
"->",
"loggerInstance",
"->",
"logEvents",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"loggerInstance",
"->",
"logEvents",
"[",
"]",
"=",
"$",
"event",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | log given events by given name
@param array $events
@return $this | [
"log",
"given",
"events",
"by",
"given",
"name"
] | train | https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L253-L262 |
bluetree-service/event | src/Event/Base/EventDispatcher.php | EventDispatcher.getConfiguration | public function getConfiguration($option = null)
{
if (!is_null($option)) {
return $this->options[$option];
}
return $this->options;
} | php | public function getConfiguration($option = null)
{
if (!is_null($option)) {
return $this->options[$option];
}
return $this->options;
} | [
"public",
"function",
"getConfiguration",
"(",
"$",
"option",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"option",
")",
")",
"{",
"return",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"options",
";",
"}"
] | get complete object configuration or value of single option
@param $option string|null
@return mixed | [
"get",
"complete",
"object",
"configuration",
"or",
"value",
"of",
"single",
"option"
] | train | https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L282-L289 |
bluetree-service/event | src/Event/Base/EventDispatcher.php | EventDispatcher.addError | protected function addError(\Exception $exception)
{
$this->errorList[$exception->getCode()] = [
'message' => $exception->getMessage(),
'line' => $exception->getLine(),
'file' => $exception->getFile(),
'trace' => $exception->getTraceAsString(),
];
$this->hasErrors = true;
return $this;
} | php | protected function addError(\Exception $exception)
{
$this->errorList[$exception->getCode()] = [
'message' => $exception->getMessage(),
'line' => $exception->getLine(),
'file' => $exception->getFile(),
'trace' => $exception->getTraceAsString(),
];
$this->hasErrors = true;
return $this;
} | [
"protected",
"function",
"addError",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"errorList",
"[",
"$",
"exception",
"->",
"getCode",
"(",
")",
"]",
"=",
"[",
"'message'",
"=>",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"'line'",
"=>",
"$",
"exception",
"->",
"getLine",
"(",
")",
",",
"'file'",
"=>",
"$",
"exception",
"->",
"getFile",
"(",
")",
",",
"'trace'",
"=>",
"$",
"exception",
"->",
"getTraceAsString",
"(",
")",
",",
"]",
";",
"$",
"this",
"->",
"hasErrors",
"=",
"true",
";",
"return",
"$",
"this",
";",
"}"
] | add new error to list
@param \Exception $exception
@return $this | [
"add",
"new",
"error",
"to",
"list"
] | train | https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L350-L361 |
GreenCape/joomla-cli | src/GreenCape/JoomlaCLI/Application.php | Application.run | public function run(InputInterface $input = null, OutputInterface $output = null)
{
try
{
parent::run($input, $output);
}
catch (\Exception $e)
{
if (null === $output) {
$output = new ConsoleOutput();
}
$message = array(
$this->getLongVersion(),
'',
$e->getMessage(),
''
);
$output->writeln($message);
}
} | php | public function run(InputInterface $input = null, OutputInterface $output = null)
{
try
{
parent::run($input, $output);
}
catch (\Exception $e)
{
if (null === $output) {
$output = new ConsoleOutput();
}
$message = array(
$this->getLongVersion(),
'',
$e->getMessage(),
''
);
$output->writeln($message);
}
} | [
"public",
"function",
"run",
"(",
"InputInterface",
"$",
"input",
"=",
"null",
",",
"OutputInterface",
"$",
"output",
"=",
"null",
")",
"{",
"try",
"{",
"parent",
"::",
"run",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"output",
")",
"{",
"$",
"output",
"=",
"new",
"ConsoleOutput",
"(",
")",
";",
"}",
"$",
"message",
"=",
"array",
"(",
"$",
"this",
"->",
"getLongVersion",
"(",
")",
",",
"''",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"''",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"$",
"message",
")",
";",
"}",
"}"
] | Runs the current application.
@param InputInterface $input An InputInterface instance
@param OutputInterface $output An OutputInterface instance
@return integer 0 if everything went fine, or an error code
@throws \Exception on problems | [
"Runs",
"the",
"current",
"application",
"."
] | train | https://github.com/GreenCape/joomla-cli/blob/74a6940f27b1f66c99330d4f9e2c5ac314cdd369/src/GreenCape/JoomlaCLI/Application.php#L68-L87 |
GreenCape/joomla-cli | src/GreenCape/JoomlaCLI/Application.php | Application.addPlugins | private function addPlugins($path)
{
foreach (glob($path . '/*.php') as $filename)
{
$commandClass = __NAMESPACE__ . '\\' . basename($filename, '.php') . 'Command';
$command = new $commandClass;
$this->add($command);
}
} | php | private function addPlugins($path)
{
foreach (glob($path . '/*.php') as $filename)
{
$commandClass = __NAMESPACE__ . '\\' . basename($filename, '.php') . 'Command';
$command = new $commandClass;
$this->add($command);
}
} | [
"private",
"function",
"addPlugins",
"(",
"$",
"path",
")",
"{",
"foreach",
"(",
"glob",
"(",
"$",
"path",
".",
"'/*.php'",
")",
"as",
"$",
"filename",
")",
"{",
"$",
"commandClass",
"=",
"__NAMESPACE__",
".",
"'\\\\'",
".",
"basename",
"(",
"$",
"filename",
",",
"'.php'",
")",
".",
"'Command'",
";",
"$",
"command",
"=",
"new",
"$",
"commandClass",
";",
"$",
"this",
"->",
"add",
"(",
"$",
"command",
")",
";",
"}",
"}"
] | Dynamically add all commands from a path
@param string $path The directory with the plugins
@return void | [
"Dynamically",
"add",
"all",
"commands",
"from",
"a",
"path"
] | train | https://github.com/GreenCape/joomla-cli/blob/74a6940f27b1f66c99330d4f9e2c5ac314cdd369/src/GreenCape/JoomlaCLI/Application.php#L96-L104 |
unclecheese/silverstripe-blubber | code/Sampler.php | Sampler.execute | public function execute() {
$results = ArrayList::create();
foreach($this->classes as $c) {
if($this->isOmitted($c)) continue;
$list = DataList::create($c)
->filter('ClassName', $c)
->limit($this->getLimitFor($c))
->sort("RAND()");
foreach($list as $record) {
$results->push($record);
}
}
return $results;
} | php | public function execute() {
$results = ArrayList::create();
foreach($this->classes as $c) {
if($this->isOmitted($c)) continue;
$list = DataList::create($c)
->filter('ClassName', $c)
->limit($this->getLimitFor($c))
->sort("RAND()");
foreach($list as $record) {
$results->push($record);
}
}
return $results;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"results",
"=",
"ArrayList",
"::",
"create",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"classes",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isOmitted",
"(",
"$",
"c",
")",
")",
"continue",
";",
"$",
"list",
"=",
"DataList",
"::",
"create",
"(",
"$",
"c",
")",
"->",
"filter",
"(",
"'ClassName'",
",",
"$",
"c",
")",
"->",
"limit",
"(",
"$",
"this",
"->",
"getLimitFor",
"(",
"$",
"c",
")",
")",
"->",
"sort",
"(",
"\"RAND()\"",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"record",
")",
"{",
"$",
"results",
"->",
"push",
"(",
"$",
"record",
")",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] | Executes the query, gets the samples
@return ArrayList | [
"Executes",
"the",
"query",
"gets",
"the",
"samples"
] | train | https://github.com/unclecheese/silverstripe-blubber/blob/f2549bd5eddeb0ca0303a3c09be4a8136fcc6661/code/Sampler.php#L56-L73 |
unclecheese/silverstripe-blubber | code/Sampler.php | Sampler.isOmitted | protected function isOmitted($c) {
foreach($this->omissions as $o) {
if($c == $o || is_subclass_of($c, $o)) {
return true;
}
}
return false;
} | php | protected function isOmitted($c) {
foreach($this->omissions as $o) {
if($c == $o || is_subclass_of($c, $o)) {
return true;
}
}
return false;
} | [
"protected",
"function",
"isOmitted",
"(",
"$",
"c",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"omissions",
"as",
"$",
"o",
")",
"{",
"if",
"(",
"$",
"c",
"==",
"$",
"o",
"||",
"is_subclass_of",
"(",
"$",
"c",
",",
"$",
"o",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if a class is omitted
@param string $c The class name
@return boolean | [
"Returns",
"true",
"if",
"a",
"class",
"is",
"omitted"
] | train | https://github.com/unclecheese/silverstripe-blubber/blob/f2549bd5eddeb0ca0303a3c09be4a8136fcc6661/code/Sampler.php#L81-L89 |
songshenzong/log | src/Bridge/Twig/TraceableTwigTemplate.php | TraceableTwigTemplate.renderBlock | public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true)
{
return $this->template->renderBlock($name, $context, $blocks, $useBlocks);
} | php | public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true)
{
return $this->template->renderBlock($name, $context, $blocks, $useBlocks);
} | [
"public",
"function",
"renderBlock",
"(",
"$",
"name",
",",
"array",
"$",
"context",
",",
"array",
"$",
"blocks",
"=",
"[",
"]",
",",
"$",
"useBlocks",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"template",
"->",
"renderBlock",
"(",
"$",
"name",
",",
"$",
"context",
",",
"$",
"blocks",
",",
"$",
"useBlocks",
")",
";",
"}"
] | @param $name
@param array $context
@param array $blocks
@param bool $useBlocks
@return mixed | [
"@param",
"$name",
"@param",
"array",
"$context",
"@param",
"array",
"$blocks",
"@param",
"bool",
"$useBlocks"
] | train | https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/Bridge/Twig/TraceableTwigTemplate.php#L122-L125 |
kiwi-suite/frontend42 | src/PageType/Service/PageTypeAbstractFactory.php | PageTypeAbstractFactory.canCreate | public function canCreate(ContainerInterface $container, $requestedName)
{
/** @var PageTypePluginManager $pageTypePluginManager */
$pageTypePluginManager = $container->get(PageTypePluginManager::class);
$pageTypes = $pageTypePluginManager->getAvailablePageTypes();
return in_array($requestedName, $pageTypes);
} | php | public function canCreate(ContainerInterface $container, $requestedName)
{
/** @var PageTypePluginManager $pageTypePluginManager */
$pageTypePluginManager = $container->get(PageTypePluginManager::class);
$pageTypes = $pageTypePluginManager->getAvailablePageTypes();
return in_array($requestedName, $pageTypes);
} | [
"public",
"function",
"canCreate",
"(",
"ContainerInterface",
"$",
"container",
",",
"$",
"requestedName",
")",
"{",
"/** @var PageTypePluginManager $pageTypePluginManager */",
"$",
"pageTypePluginManager",
"=",
"$",
"container",
"->",
"get",
"(",
"PageTypePluginManager",
"::",
"class",
")",
";",
"$",
"pageTypes",
"=",
"$",
"pageTypePluginManager",
"->",
"getAvailablePageTypes",
"(",
")",
";",
"return",
"in_array",
"(",
"$",
"requestedName",
",",
"$",
"pageTypes",
")",
";",
"}"
] | Can the factory create an instance for the service?
@param ContainerInterface $container
@param string $requestedName
@return bool | [
"Can",
"the",
"factory",
"create",
"an",
"instance",
"for",
"the",
"service?"
] | train | https://github.com/kiwi-suite/frontend42/blob/67e5208387957823ac84f7833eba83d4a8dab8cd/src/PageType/Service/PageTypeAbstractFactory.php#L21-L28 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/DOMTreeBuilder.php | HTML5_Parser_DOMTreeBuilder.startTag | public function startTag($name, $attributes = array(), $selfClosing = false) {
// fprintf(STDOUT, $name);
$lname = $this->normalizeTagName($name);
// Make sure we have an html element.
if (!$this->doc->documentElement && $name !== 'html' && !$this->frag) {
$this->startTag('html');
}
// Set quirks mode if we're at IM_INITIAL with no doctype.
if ($this->insertMode == static::IM_INITIAL) {
$this->quirks = true;
$this->parseError("No DOCTYPE specified.");
}
// SPECIAL TAG HANDLING:
// Spec says do this, and "don't ask."
if ($name == 'image') {
$name = 'img';
}
// Autoclose p tags where appropriate.
if ($this->insertMode >= static::IM_IN_BODY && HTML5_Elements::isA($name, HTML5_Elements::AUTOCLOSE_P)) {
$this->autoclose('p');
}
// Set insert mode:
switch ($name) {
case 'html':
$this->insertMode = static::IM_BEFORE_HEAD;
break;
case 'head':
if ($this->insertMode > static::IM_BEFORE_HEAD) {
$this->parseError("Unexpected head tag outside of head context.");
} else {
$this->insertMode = static::IM_IN_HEAD;
}
break;
case 'body':
$this->insertMode = static::IM_IN_BODY;
break;
case 'svg':
$this->insertMode = static::IM_IN_SVG;
break;
case 'math':
$this->insertMode = static::IM_IN_MATHML;
break;
case 'noscript':
if ($this->insertMode == static::IM_IN_HEAD) {
$this->insertMode = static::IM_IN_HEAD_NOSCRIPT;
}
break;
}
// Special case handling for SVG.
if ($this->insertMode == static::IM_IN_SVG) {
$lname = HTML5_Elements::normalizeSvgElement($lname);
}
$pushes = 0;
// when we found a tag thats appears inside $nsRoots, we have to switch the defalut namespace
if (isset($this->nsRoots[$lname]) && $this->nsStack[0][''] !== $this->nsRoots[$lname]) {
array_unshift($this->nsStack, array(
'' => $this->nsRoots[$lname]
) + $this->nsStack[0]);
$pushes ++;
}
$needsWorkaround = false;
if (isset($this->options["xmlNamespaces"]) && $this->options["xmlNamespaces"]) {
// when xmlNamespaces is true a and we found a 'xmlns' or 'xmlns:*' attribute, we should add a new item to the $nsStack
foreach ($attributes as $aName => $aVal) {
if ($aName === 'xmlns') {
$needsWorkaround = $aVal;
array_unshift($this->nsStack, array(
'' => $aVal
) + $this->nsStack[0]);
$pushes ++;
} elseif ((($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : '') === 'xmlns') {
array_unshift($this->nsStack, array(
substr($aName, $pos + 1) => $aVal
) + $this->nsStack[0]);
$pushes ++;
}
}
}
try {
$prefix = ($pos = strpos($lname, ':')) ? substr($lname, 0, $pos) : '';
if ($needsWorkaround !== false) {
$xml = "<$lname xmlns=\"$needsWorkaround\" " . (strlen($prefix) && isset($this->nsStack[0][$prefix]) ? ("xmlns:$prefix=\"" . $this->nsStack[0][$prefix] . "\"") : "") . "/>";
$frag = new \DOMDocument('1.0', 'UTF-8');
$frag->loadXML($xml);
$ele = $this->doc->importNode($frag->documentElement, true);
} else {
if (!isset($this->nsStack[0][$prefix]) || ($prefix === "" && isset($this->options['disableHtmlNsInDom']) && $this->options['disableHtmlNsInDom'])) {
$ele = $this->doc->createElement($lname);
} else {
$ele = $this->doc->createElementNS($this->nsStack[0][$prefix], $lname);
}
}
} catch (\DOMException $e) {
$this->parseError("Illegal tag name: <$lname>. Replaced with <invalid>.");
$ele = $this->doc->createElement('invalid');
}
// When we add some namespacess, we have to track them. Later, when "endElement" is invoked, we have to remove them.
// When we are on a void tag, we do not need to care about namesapce nesting.
if ($pushes > 0 && !HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
// PHP tends to free the memory used by DOM,
// to avoid spl_object_hash collisions whe have to avoid garbage collection of $ele storing it into $pushes
// see https://bugs.php.net/bug.php?id=67459
$this->pushes[spl_object_hash($ele)] = array($pushes, $ele);
// SEE https://github.com/facebook/hhvm/issues/2962
if (defined('HHVM_VERSION')) {
$ele->setAttribute('html5-php-fake-id-attribute', spl_object_hash($ele));
}
}
foreach ($attributes as $aName => $aVal) {
// xmlns attributes can't be set
if ($aName === 'xmlns') {
continue;
}
if ($this->insertMode == static::IM_IN_SVG) {
$aName = HTML5_Elements::normalizeSvgAttribute($aName);
} elseif ($this->insertMode == static::IM_IN_MATHML) {
$aName = HTML5_Elements::normalizeMathMlAttribute($aName);
}
try {
$prefix = ($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : false;
if ($prefix === 'xmlns') {
$ele->setAttributeNs(self::NAMESPACE_XMLNS, $aName, $aVal);
} elseif ($prefix !== false && isset($this->nsStack[0][$prefix])) {
$ele->setAttributeNs($this->nsStack[0][$prefix], $aName, $aVal);
} else {
$ele->setAttribute($aName, $aVal);
}
} catch (\DOMException $e) {
$this->parseError("Illegal attribute name for tag $name. Ignoring: $aName");
continue;
}
// This is necessary on a non-DTD schema, like HTML5.
if ($aName == 'id') {
$ele->setIdAttribute('id', true);
}
}
// Some elements have special processing rules. Handle those separately.
if ($this->rules->hasRules($name) && $this->frag !== $this->current) {
$this->current = $this->rules->evaluate($ele, $this->current);
} // Otherwise, it's a standard element.
else {
$this->current->appendChild($ele);
// XXX: Need to handle self-closing tags and unary tags.
if (!HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
$this->current = $ele;
}
}
// This is sort of a last-ditch attempt to correct for cases where no head/body
// elements are provided.
if ($this->insertMode <= static::IM_BEFORE_HEAD && $name != 'head' && $name != 'html') {
$this->insertMode = static::IM_IN_BODY;
}
// When we are on a void tag, we do not need to care about namesapce nesting,
// but we have to remove the namespaces pushed to $nsStack.
if ($pushes > 0 && HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
// remove the namespaced definded by current node
for ($i = 0; $i < $pushes; $i ++) {
array_shift($this->nsStack);
}
}
// Return the element mask, which the tokenizer can then use to set
// various processing rules.
return HTML5_Elements::element($name);
} | php | public function startTag($name, $attributes = array(), $selfClosing = false) {
// fprintf(STDOUT, $name);
$lname = $this->normalizeTagName($name);
// Make sure we have an html element.
if (!$this->doc->documentElement && $name !== 'html' && !$this->frag) {
$this->startTag('html');
}
// Set quirks mode if we're at IM_INITIAL with no doctype.
if ($this->insertMode == static::IM_INITIAL) {
$this->quirks = true;
$this->parseError("No DOCTYPE specified.");
}
// SPECIAL TAG HANDLING:
// Spec says do this, and "don't ask."
if ($name == 'image') {
$name = 'img';
}
// Autoclose p tags where appropriate.
if ($this->insertMode >= static::IM_IN_BODY && HTML5_Elements::isA($name, HTML5_Elements::AUTOCLOSE_P)) {
$this->autoclose('p');
}
// Set insert mode:
switch ($name) {
case 'html':
$this->insertMode = static::IM_BEFORE_HEAD;
break;
case 'head':
if ($this->insertMode > static::IM_BEFORE_HEAD) {
$this->parseError("Unexpected head tag outside of head context.");
} else {
$this->insertMode = static::IM_IN_HEAD;
}
break;
case 'body':
$this->insertMode = static::IM_IN_BODY;
break;
case 'svg':
$this->insertMode = static::IM_IN_SVG;
break;
case 'math':
$this->insertMode = static::IM_IN_MATHML;
break;
case 'noscript':
if ($this->insertMode == static::IM_IN_HEAD) {
$this->insertMode = static::IM_IN_HEAD_NOSCRIPT;
}
break;
}
// Special case handling for SVG.
if ($this->insertMode == static::IM_IN_SVG) {
$lname = HTML5_Elements::normalizeSvgElement($lname);
}
$pushes = 0;
// when we found a tag thats appears inside $nsRoots, we have to switch the defalut namespace
if (isset($this->nsRoots[$lname]) && $this->nsStack[0][''] !== $this->nsRoots[$lname]) {
array_unshift($this->nsStack, array(
'' => $this->nsRoots[$lname]
) + $this->nsStack[0]);
$pushes ++;
}
$needsWorkaround = false;
if (isset($this->options["xmlNamespaces"]) && $this->options["xmlNamespaces"]) {
// when xmlNamespaces is true a and we found a 'xmlns' or 'xmlns:*' attribute, we should add a new item to the $nsStack
foreach ($attributes as $aName => $aVal) {
if ($aName === 'xmlns') {
$needsWorkaround = $aVal;
array_unshift($this->nsStack, array(
'' => $aVal
) + $this->nsStack[0]);
$pushes ++;
} elseif ((($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : '') === 'xmlns') {
array_unshift($this->nsStack, array(
substr($aName, $pos + 1) => $aVal
) + $this->nsStack[0]);
$pushes ++;
}
}
}
try {
$prefix = ($pos = strpos($lname, ':')) ? substr($lname, 0, $pos) : '';
if ($needsWorkaround !== false) {
$xml = "<$lname xmlns=\"$needsWorkaround\" " . (strlen($prefix) && isset($this->nsStack[0][$prefix]) ? ("xmlns:$prefix=\"" . $this->nsStack[0][$prefix] . "\"") : "") . "/>";
$frag = new \DOMDocument('1.0', 'UTF-8');
$frag->loadXML($xml);
$ele = $this->doc->importNode($frag->documentElement, true);
} else {
if (!isset($this->nsStack[0][$prefix]) || ($prefix === "" && isset($this->options['disableHtmlNsInDom']) && $this->options['disableHtmlNsInDom'])) {
$ele = $this->doc->createElement($lname);
} else {
$ele = $this->doc->createElementNS($this->nsStack[0][$prefix], $lname);
}
}
} catch (\DOMException $e) {
$this->parseError("Illegal tag name: <$lname>. Replaced with <invalid>.");
$ele = $this->doc->createElement('invalid');
}
// When we add some namespacess, we have to track them. Later, when "endElement" is invoked, we have to remove them.
// When we are on a void tag, we do not need to care about namesapce nesting.
if ($pushes > 0 && !HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
// PHP tends to free the memory used by DOM,
// to avoid spl_object_hash collisions whe have to avoid garbage collection of $ele storing it into $pushes
// see https://bugs.php.net/bug.php?id=67459
$this->pushes[spl_object_hash($ele)] = array($pushes, $ele);
// SEE https://github.com/facebook/hhvm/issues/2962
if (defined('HHVM_VERSION')) {
$ele->setAttribute('html5-php-fake-id-attribute', spl_object_hash($ele));
}
}
foreach ($attributes as $aName => $aVal) {
// xmlns attributes can't be set
if ($aName === 'xmlns') {
continue;
}
if ($this->insertMode == static::IM_IN_SVG) {
$aName = HTML5_Elements::normalizeSvgAttribute($aName);
} elseif ($this->insertMode == static::IM_IN_MATHML) {
$aName = HTML5_Elements::normalizeMathMlAttribute($aName);
}
try {
$prefix = ($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : false;
if ($prefix === 'xmlns') {
$ele->setAttributeNs(self::NAMESPACE_XMLNS, $aName, $aVal);
} elseif ($prefix !== false && isset($this->nsStack[0][$prefix])) {
$ele->setAttributeNs($this->nsStack[0][$prefix], $aName, $aVal);
} else {
$ele->setAttribute($aName, $aVal);
}
} catch (\DOMException $e) {
$this->parseError("Illegal attribute name for tag $name. Ignoring: $aName");
continue;
}
// This is necessary on a non-DTD schema, like HTML5.
if ($aName == 'id') {
$ele->setIdAttribute('id', true);
}
}
// Some elements have special processing rules. Handle those separately.
if ($this->rules->hasRules($name) && $this->frag !== $this->current) {
$this->current = $this->rules->evaluate($ele, $this->current);
} // Otherwise, it's a standard element.
else {
$this->current->appendChild($ele);
// XXX: Need to handle self-closing tags and unary tags.
if (!HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
$this->current = $ele;
}
}
// This is sort of a last-ditch attempt to correct for cases where no head/body
// elements are provided.
if ($this->insertMode <= static::IM_BEFORE_HEAD && $name != 'head' && $name != 'html') {
$this->insertMode = static::IM_IN_BODY;
}
// When we are on a void tag, we do not need to care about namesapce nesting,
// but we have to remove the namespaces pushed to $nsStack.
if ($pushes > 0 && HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
// remove the namespaced definded by current node
for ($i = 0; $i < $pushes; $i ++) {
array_shift($this->nsStack);
}
}
// Return the element mask, which the tokenizer can then use to set
// various processing rules.
return HTML5_Elements::element($name);
} | [
"public",
"function",
"startTag",
"(",
"$",
"name",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"selfClosing",
"=",
"false",
")",
"{",
"// fprintf(STDOUT, $name);",
"$",
"lname",
"=",
"$",
"this",
"->",
"normalizeTagName",
"(",
"$",
"name",
")",
";",
"// Make sure we have an html element.",
"if",
"(",
"!",
"$",
"this",
"->",
"doc",
"->",
"documentElement",
"&&",
"$",
"name",
"!==",
"'html'",
"&&",
"!",
"$",
"this",
"->",
"frag",
")",
"{",
"$",
"this",
"->",
"startTag",
"(",
"'html'",
")",
";",
"}",
"// Set quirks mode if we're at IM_INITIAL with no doctype.",
"if",
"(",
"$",
"this",
"->",
"insertMode",
"==",
"static",
"::",
"IM_INITIAL",
")",
"{",
"$",
"this",
"->",
"quirks",
"=",
"true",
";",
"$",
"this",
"->",
"parseError",
"(",
"\"No DOCTYPE specified.\"",
")",
";",
"}",
"// SPECIAL TAG HANDLING:",
"// Spec says do this, and \"don't ask.\"",
"if",
"(",
"$",
"name",
"==",
"'image'",
")",
"{",
"$",
"name",
"=",
"'img'",
";",
"}",
"// Autoclose p tags where appropriate.",
"if",
"(",
"$",
"this",
"->",
"insertMode",
">=",
"static",
"::",
"IM_IN_BODY",
"&&",
"HTML5_Elements",
"::",
"isA",
"(",
"$",
"name",
",",
"HTML5_Elements",
"::",
"AUTOCLOSE_P",
")",
")",
"{",
"$",
"this",
"->",
"autoclose",
"(",
"'p'",
")",
";",
"}",
"// Set insert mode:",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'html'",
":",
"$",
"this",
"->",
"insertMode",
"=",
"static",
"::",
"IM_BEFORE_HEAD",
";",
"break",
";",
"case",
"'head'",
":",
"if",
"(",
"$",
"this",
"->",
"insertMode",
">",
"static",
"::",
"IM_BEFORE_HEAD",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Unexpected head tag outside of head context.\"",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"insertMode",
"=",
"static",
"::",
"IM_IN_HEAD",
";",
"}",
"break",
";",
"case",
"'body'",
":",
"$",
"this",
"->",
"insertMode",
"=",
"static",
"::",
"IM_IN_BODY",
";",
"break",
";",
"case",
"'svg'",
":",
"$",
"this",
"->",
"insertMode",
"=",
"static",
"::",
"IM_IN_SVG",
";",
"break",
";",
"case",
"'math'",
":",
"$",
"this",
"->",
"insertMode",
"=",
"static",
"::",
"IM_IN_MATHML",
";",
"break",
";",
"case",
"'noscript'",
":",
"if",
"(",
"$",
"this",
"->",
"insertMode",
"==",
"static",
"::",
"IM_IN_HEAD",
")",
"{",
"$",
"this",
"->",
"insertMode",
"=",
"static",
"::",
"IM_IN_HEAD_NOSCRIPT",
";",
"}",
"break",
";",
"}",
"// Special case handling for SVG.",
"if",
"(",
"$",
"this",
"->",
"insertMode",
"==",
"static",
"::",
"IM_IN_SVG",
")",
"{",
"$",
"lname",
"=",
"HTML5_Elements",
"::",
"normalizeSvgElement",
"(",
"$",
"lname",
")",
";",
"}",
"$",
"pushes",
"=",
"0",
";",
"// when we found a tag thats appears inside $nsRoots, we have to switch the defalut namespace",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"nsRoots",
"[",
"$",
"lname",
"]",
")",
"&&",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
"[",
"''",
"]",
"!==",
"$",
"this",
"->",
"nsRoots",
"[",
"$",
"lname",
"]",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"nsStack",
",",
"array",
"(",
"''",
"=>",
"$",
"this",
"->",
"nsRoots",
"[",
"$",
"lname",
"]",
")",
"+",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
")",
";",
"$",
"pushes",
"++",
";",
"}",
"$",
"needsWorkaround",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"\"xmlNamespaces\"",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"\"xmlNamespaces\"",
"]",
")",
"{",
"// when xmlNamespaces is true a and we found a 'xmlns' or 'xmlns:*' attribute, we should add a new item to the $nsStack",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"aName",
"=>",
"$",
"aVal",
")",
"{",
"if",
"(",
"$",
"aName",
"===",
"'xmlns'",
")",
"{",
"$",
"needsWorkaround",
"=",
"$",
"aVal",
";",
"array_unshift",
"(",
"$",
"this",
"->",
"nsStack",
",",
"array",
"(",
"''",
"=>",
"$",
"aVal",
")",
"+",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
")",
";",
"$",
"pushes",
"++",
";",
"}",
"elseif",
"(",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"aName",
",",
"':'",
")",
")",
"?",
"substr",
"(",
"$",
"aName",
",",
"0",
",",
"$",
"pos",
")",
":",
"''",
")",
"===",
"'xmlns'",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"nsStack",
",",
"array",
"(",
"substr",
"(",
"$",
"aName",
",",
"$",
"pos",
"+",
"1",
")",
"=>",
"$",
"aVal",
")",
"+",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
")",
";",
"$",
"pushes",
"++",
";",
"}",
"}",
"}",
"try",
"{",
"$",
"prefix",
"=",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"lname",
",",
"':'",
")",
")",
"?",
"substr",
"(",
"$",
"lname",
",",
"0",
",",
"$",
"pos",
")",
":",
"''",
";",
"if",
"(",
"$",
"needsWorkaround",
"!==",
"false",
")",
"{",
"$",
"xml",
"=",
"\"<$lname xmlns=\\\"$needsWorkaround\\\" \"",
".",
"(",
"strlen",
"(",
"$",
"prefix",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
"[",
"$",
"prefix",
"]",
")",
"?",
"(",
"\"xmlns:$prefix=\\\"\"",
".",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
"[",
"$",
"prefix",
"]",
".",
"\"\\\"\"",
")",
":",
"\"\"",
")",
".",
"\"/>\"",
";",
"$",
"frag",
"=",
"new",
"\\",
"DOMDocument",
"(",
"'1.0'",
",",
"'UTF-8'",
")",
";",
"$",
"frag",
"->",
"loadXML",
"(",
"$",
"xml",
")",
";",
"$",
"ele",
"=",
"$",
"this",
"->",
"doc",
"->",
"importNode",
"(",
"$",
"frag",
"->",
"documentElement",
",",
"true",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
"[",
"$",
"prefix",
"]",
")",
"||",
"(",
"$",
"prefix",
"===",
"\"\"",
"&&",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'disableHtmlNsInDom'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'disableHtmlNsInDom'",
"]",
")",
")",
"{",
"$",
"ele",
"=",
"$",
"this",
"->",
"doc",
"->",
"createElement",
"(",
"$",
"lname",
")",
";",
"}",
"else",
"{",
"$",
"ele",
"=",
"$",
"this",
"->",
"doc",
"->",
"createElementNS",
"(",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
"[",
"$",
"prefix",
"]",
",",
"$",
"lname",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"DOMException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Illegal tag name: <$lname>. Replaced with <invalid>.\"",
")",
";",
"$",
"ele",
"=",
"$",
"this",
"->",
"doc",
"->",
"createElement",
"(",
"'invalid'",
")",
";",
"}",
"// When we add some namespacess, we have to track them. Later, when \"endElement\" is invoked, we have to remove them.",
"// When we are on a void tag, we do not need to care about namesapce nesting.",
"if",
"(",
"$",
"pushes",
">",
"0",
"&&",
"!",
"HTML5_Elements",
"::",
"isA",
"(",
"$",
"name",
",",
"HTML5_Elements",
"::",
"VOID_TAG",
")",
")",
"{",
"// PHP tends to free the memory used by DOM,",
"// to avoid spl_object_hash collisions whe have to avoid garbage collection of $ele storing it into $pushes",
"// see https://bugs.php.net/bug.php?id=67459",
"$",
"this",
"->",
"pushes",
"[",
"spl_object_hash",
"(",
"$",
"ele",
")",
"]",
"=",
"array",
"(",
"$",
"pushes",
",",
"$",
"ele",
")",
";",
"// SEE https://github.com/facebook/hhvm/issues/2962",
"if",
"(",
"defined",
"(",
"'HHVM_VERSION'",
")",
")",
"{",
"$",
"ele",
"->",
"setAttribute",
"(",
"'html5-php-fake-id-attribute'",
",",
"spl_object_hash",
"(",
"$",
"ele",
")",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"aName",
"=>",
"$",
"aVal",
")",
"{",
"// xmlns attributes can't be set",
"if",
"(",
"$",
"aName",
"===",
"'xmlns'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"insertMode",
"==",
"static",
"::",
"IM_IN_SVG",
")",
"{",
"$",
"aName",
"=",
"HTML5_Elements",
"::",
"normalizeSvgAttribute",
"(",
"$",
"aName",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"insertMode",
"==",
"static",
"::",
"IM_IN_MATHML",
")",
"{",
"$",
"aName",
"=",
"HTML5_Elements",
"::",
"normalizeMathMlAttribute",
"(",
"$",
"aName",
")",
";",
"}",
"try",
"{",
"$",
"prefix",
"=",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"aName",
",",
"':'",
")",
")",
"?",
"substr",
"(",
"$",
"aName",
",",
"0",
",",
"$",
"pos",
")",
":",
"false",
";",
"if",
"(",
"$",
"prefix",
"===",
"'xmlns'",
")",
"{",
"$",
"ele",
"->",
"setAttributeNs",
"(",
"self",
"::",
"NAMESPACE_XMLNS",
",",
"$",
"aName",
",",
"$",
"aVal",
")",
";",
"}",
"elseif",
"(",
"$",
"prefix",
"!==",
"false",
"&&",
"isset",
"(",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
"[",
"$",
"prefix",
"]",
")",
")",
"{",
"$",
"ele",
"->",
"setAttributeNs",
"(",
"$",
"this",
"->",
"nsStack",
"[",
"0",
"]",
"[",
"$",
"prefix",
"]",
",",
"$",
"aName",
",",
"$",
"aVal",
")",
";",
"}",
"else",
"{",
"$",
"ele",
"->",
"setAttribute",
"(",
"$",
"aName",
",",
"$",
"aVal",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"DOMException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"parseError",
"(",
"\"Illegal attribute name for tag $name. Ignoring: $aName\"",
")",
";",
"continue",
";",
"}",
"// This is necessary on a non-DTD schema, like HTML5.",
"if",
"(",
"$",
"aName",
"==",
"'id'",
")",
"{",
"$",
"ele",
"->",
"setIdAttribute",
"(",
"'id'",
",",
"true",
")",
";",
"}",
"}",
"// Some elements have special processing rules. Handle those separately.",
"if",
"(",
"$",
"this",
"->",
"rules",
"->",
"hasRules",
"(",
"$",
"name",
")",
"&&",
"$",
"this",
"->",
"frag",
"!==",
"$",
"this",
"->",
"current",
")",
"{",
"$",
"this",
"->",
"current",
"=",
"$",
"this",
"->",
"rules",
"->",
"evaluate",
"(",
"$",
"ele",
",",
"$",
"this",
"->",
"current",
")",
";",
"}",
"// Otherwise, it's a standard element.",
"else",
"{",
"$",
"this",
"->",
"current",
"->",
"appendChild",
"(",
"$",
"ele",
")",
";",
"// XXX: Need to handle self-closing tags and unary tags.",
"if",
"(",
"!",
"HTML5_Elements",
"::",
"isA",
"(",
"$",
"name",
",",
"HTML5_Elements",
"::",
"VOID_TAG",
")",
")",
"{",
"$",
"this",
"->",
"current",
"=",
"$",
"ele",
";",
"}",
"}",
"// This is sort of a last-ditch attempt to correct for cases where no head/body",
"// elements are provided.",
"if",
"(",
"$",
"this",
"->",
"insertMode",
"<=",
"static",
"::",
"IM_BEFORE_HEAD",
"&&",
"$",
"name",
"!=",
"'head'",
"&&",
"$",
"name",
"!=",
"'html'",
")",
"{",
"$",
"this",
"->",
"insertMode",
"=",
"static",
"::",
"IM_IN_BODY",
";",
"}",
"// When we are on a void tag, we do not need to care about namesapce nesting,",
"// but we have to remove the namespaces pushed to $nsStack.",
"if",
"(",
"$",
"pushes",
">",
"0",
"&&",
"HTML5_Elements",
"::",
"isA",
"(",
"$",
"name",
",",
"HTML5_Elements",
"::",
"VOID_TAG",
")",
")",
"{",
"// remove the namespaced definded by current node",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"pushes",
";",
"$",
"i",
"++",
")",
"{",
"array_shift",
"(",
"$",
"this",
"->",
"nsStack",
")",
";",
"}",
"}",
"// Return the element mask, which the tokenizer can then use to set",
"// various processing rules.",
"return",
"HTML5_Elements",
"::",
"element",
"(",
"$",
"name",
")",
";",
"}"
] | Process the start tag.
@todo - XMLNS namespace handling (we need to parse, even if it's not valid)
- XLink, MathML and SVG namespace handling
- Omission rules: 8.1.2.4 Optional tags | [
"Process",
"the",
"start",
"tag",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/DOMTreeBuilder.php#L282-L469 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/DOMTreeBuilder.php | HTML5_Parser_DOMTreeBuilder.autoclose | protected function autoclose($tag) {
$working = $this->current;
do {
if ($working->nodeType != XML_ELEMENT_NODE) {
return false;
}
if ($working->tagName == $tag) {
$this->current = $working->parentNode;
return true;
}
} while ($working = $working->parentNode);
return false;
} | php | protected function autoclose($tag) {
$working = $this->current;
do {
if ($working->nodeType != XML_ELEMENT_NODE) {
return false;
}
if ($working->tagName == $tag) {
$this->current = $working->parentNode;
return true;
}
} while ($working = $working->parentNode);
return false;
} | [
"protected",
"function",
"autoclose",
"(",
"$",
"tag",
")",
"{",
"$",
"working",
"=",
"$",
"this",
"->",
"current",
";",
"do",
"{",
"if",
"(",
"$",
"working",
"->",
"nodeType",
"!=",
"XML_ELEMENT_NODE",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"working",
"->",
"tagName",
"==",
"$",
"tag",
")",
"{",
"$",
"this",
"->",
"current",
"=",
"$",
"working",
"->",
"parentNode",
";",
"return",
"true",
";",
"}",
"}",
"while",
"(",
"$",
"working",
"=",
"$",
"working",
"->",
"parentNode",
")",
";",
"return",
"false",
";",
"}"
] | Automatically climb the tree and close the closest node with the matching $tag. | [
"Automatically",
"climb",
"the",
"tree",
"and",
"close",
"the",
"closest",
"node",
"with",
"the",
"matching",
"$tag",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/DOMTreeBuilder.php#L642-L655 |
PHPPowertools/HTML5 | src/PowerTools/HTML5/Parser/DOMTreeBuilder.php | HTML5_Parser_DOMTreeBuilder.isAncestor | protected function isAncestor($tagname) {
$candidate = $this->current;
while ($candidate->nodeType === XML_ELEMENT_NODE) {
if ($candidate->tagName == $tagname) {
return true;
}
$candidate = $candidate->parentNode;
}
return false;
} | php | protected function isAncestor($tagname) {
$candidate = $this->current;
while ($candidate->nodeType === XML_ELEMENT_NODE) {
if ($candidate->tagName == $tagname) {
return true;
}
$candidate = $candidate->parentNode;
}
return false;
} | [
"protected",
"function",
"isAncestor",
"(",
"$",
"tagname",
")",
"{",
"$",
"candidate",
"=",
"$",
"this",
"->",
"current",
";",
"while",
"(",
"$",
"candidate",
"->",
"nodeType",
"===",
"XML_ELEMENT_NODE",
")",
"{",
"if",
"(",
"$",
"candidate",
"->",
"tagName",
"==",
"$",
"tagname",
")",
"{",
"return",
"true",
";",
"}",
"$",
"candidate",
"=",
"$",
"candidate",
"->",
"parentNode",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if the given tagname is an ancestor of the present candidate.
If $this->current or anything above $this->current matches the given tag
name, this returns true. | [
"Checks",
"if",
"the",
"given",
"tagname",
"is",
"an",
"ancestor",
"of",
"the",
"present",
"candidate",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/DOMTreeBuilder.php#L663-L673 |
php-lug/lug | src/Component/Resource/Form/Type/ResourceType.php | ResourceType.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setRequired(['resource', 'factory'])
->setAllowedTypes('resource', ResourceInterface::class)
->setAllowedTypes('factory', FactoryInterface::class)
->setDefaults([
'data_class' => function (Options $options) {
return $options['resource']->getModel();
},
'label_prefix' => function (Options $options) {
return 'lug.'.$options['resource']->getName();
},
'validation_groups' => function (Options $options) {
return [Constraint::DEFAULT_GROUP, 'lug.'.$options['resource']->getName()];
},
'empty_data' => function (FormInterface $form) {
return $form->isRequired() || !$form->isEmpty()
? $form->getConfig()->getOption('factory')->create()
: null;
},
]);
} | php | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setRequired(['resource', 'factory'])
->setAllowedTypes('resource', ResourceInterface::class)
->setAllowedTypes('factory', FactoryInterface::class)
->setDefaults([
'data_class' => function (Options $options) {
return $options['resource']->getModel();
},
'label_prefix' => function (Options $options) {
return 'lug.'.$options['resource']->getName();
},
'validation_groups' => function (Options $options) {
return [Constraint::DEFAULT_GROUP, 'lug.'.$options['resource']->getName()];
},
'empty_data' => function (FormInterface $form) {
return $form->isRequired() || !$form->isEmpty()
? $form->getConfig()->getOption('factory')->create()
: null;
},
]);
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setRequired",
"(",
"[",
"'resource'",
",",
"'factory'",
"]",
")",
"->",
"setAllowedTypes",
"(",
"'resource'",
",",
"ResourceInterface",
"::",
"class",
")",
"->",
"setAllowedTypes",
"(",
"'factory'",
",",
"FactoryInterface",
"::",
"class",
")",
"->",
"setDefaults",
"(",
"[",
"'data_class'",
"=>",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"options",
"[",
"'resource'",
"]",
"->",
"getModel",
"(",
")",
";",
"}",
",",
"'label_prefix'",
"=>",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"'lug.'",
".",
"$",
"options",
"[",
"'resource'",
"]",
"->",
"getName",
"(",
")",
";",
"}",
",",
"'validation_groups'",
"=>",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"[",
"Constraint",
"::",
"DEFAULT_GROUP",
",",
"'lug.'",
".",
"$",
"options",
"[",
"'resource'",
"]",
"->",
"getName",
"(",
")",
"]",
";",
"}",
",",
"'empty_data'",
"=>",
"function",
"(",
"FormInterface",
"$",
"form",
")",
"{",
"return",
"$",
"form",
"->",
"isRequired",
"(",
")",
"||",
"!",
"$",
"form",
"->",
"isEmpty",
"(",
")",
"?",
"$",
"form",
"->",
"getConfig",
"(",
")",
"->",
"getOption",
"(",
"'factory'",
")",
"->",
"create",
"(",
")",
":",
"null",
";",
"}",
",",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Resource/Form/Type/ResourceType.php#L30-L52 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.setPointColor | public function setPointColor($r, $g, $b)
{
$this->ink['point'] = imagecolorallocate($this->im, $r, $g, $b);
} | php | public function setPointColor($r, $g, $b)
{
$this->ink['point'] = imagecolorallocate($this->im, $r, $g, $b);
} | [
"public",
"function",
"setPointColor",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'point'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] | Sets the point color in rgb format
@param integer $r The red value 0-255
@param integer $g The green value 0-255
@param integer $b The blue value 0-255 | [
"Sets",
"the",
"point",
"color",
"in",
"rgb",
"format"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L143-L147 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.setLineColor | public function setLineColor($r, $g, $b)
{
$this->ink['line'] = imagecolorallocate($this->im, $r, $g, $b);
} | php | public function setLineColor($r, $g, $b)
{
$this->ink['line'] = imagecolorallocate($this->im, $r, $g, $b);
} | [
"public",
"function",
"setLineColor",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'line'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] | Sets the line color in rgb format
@param integer $r The red value 0-255
@param integer $g The green value 0-255
@param integer $b The blue value 0-255 | [
"Sets",
"the",
"line",
"color",
"in",
"rgb",
"format"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L156-L160 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.setTextColor | public function setTextColor($r, $g, $b)
{
$this->ink['text'] = imagecolorallocate($this->im, $r, $g, $b);
} | php | public function setTextColor($r, $g, $b)
{
$this->ink['text'] = imagecolorallocate($this->im, $r, $g, $b);
} | [
"public",
"function",
"setTextColor",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'text'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] | Sets the text color in rgb format - labels
@param integer $r The red value 0-255
@param integer $g The green value 0-255
@param integer $b The blue value 0-255 | [
"Sets",
"the",
"text",
"color",
"in",
"rgb",
"format",
"-",
"labels"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L169-L172 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.setAxisColor | public function setAxisColor($r, $g, $b)
{
$this->ink['axis'] = imagecolorallocate($this->im, $r, $g, $b);
} | php | public function setAxisColor($r, $g, $b)
{
$this->ink['axis'] = imagecolorallocate($this->im, $r, $g, $b);
} | [
"public",
"function",
"setAxisColor",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'axis'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] | Sets the axis color in rgb format - axis
@param integer $r The red value 0-255
@param integer $g The green value 0-255
@param integer $b The blue value 0-255 | [
"Sets",
"the",
"axis",
"color",
"in",
"rgb",
"format",
"-",
"axis"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L181-L184 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.createBackground | private function createBackground()
{
imagefilledrectangle($this->im, 0, 0, $this->width, $this->height,
$this->ink['black']);
} | php | private function createBackground()
{
imagefilledrectangle($this->im, 0, 0, $this->width, $this->height,
$this->ink['black']);
} | [
"private",
"function",
"createBackground",
"(",
")",
"{",
"imagefilledrectangle",
"(",
"$",
"this",
"->",
"im",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"width",
",",
"$",
"this",
"->",
"height",
",",
"$",
"this",
"->",
"ink",
"[",
"'black'",
"]",
")",
";",
"}"
] | Create the backgrround image | [
"Create",
"the",
"backgrround",
"image"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L198-L203 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.allocateColors | private function allocateColors()
{
$this->ink['red'] = imagecolorallocate($this->im, 0xff, 0x00, 0x00);
$this->ink['orange'] = imagecolorallocate($this->im, 0xd2, 0x8a, 0x00);
$this->ink['yellow'] = imagecolorallocate($this->im, 0xff, 0xff, 0x00);
$this->ink['green'] = imagecolorallocate($this->im, 0x00, 0xff, 0x00);
$this->ink['blue'] = imagecolorallocate($this->im, 0x00, 0x00, 0xff);
$this->ink['purple'] = imagecolorallocate($this->im, 0x70, 0x70, 0xf9);
$this->ink['white'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
$this->ink['black'] = imagecolorallocate($this->im, 0x00, 0x00, 0x00);
$this->ink['gray'] = imagecolorallocate($this->im, 0xaf, 0xaf, 0xaf);
$this->ink['axis'] = imagecolorallocate($this->im, 95, 95, 95);
$this->ink['line'] = imagecolorallocate($this->im, 0xff, 0xff, 0x00);
$this->ink['background'] = imagecolorallocate($this->im, 0x00, 0x00,
0x00);
$this->ink['text'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
$this->ink['point'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
} | php | private function allocateColors()
{
$this->ink['red'] = imagecolorallocate($this->im, 0xff, 0x00, 0x00);
$this->ink['orange'] = imagecolorallocate($this->im, 0xd2, 0x8a, 0x00);
$this->ink['yellow'] = imagecolorallocate($this->im, 0xff, 0xff, 0x00);
$this->ink['green'] = imagecolorallocate($this->im, 0x00, 0xff, 0x00);
$this->ink['blue'] = imagecolorallocate($this->im, 0x00, 0x00, 0xff);
$this->ink['purple'] = imagecolorallocate($this->im, 0x70, 0x70, 0xf9);
$this->ink['white'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
$this->ink['black'] = imagecolorallocate($this->im, 0x00, 0x00, 0x00);
$this->ink['gray'] = imagecolorallocate($this->im, 0xaf, 0xaf, 0xaf);
$this->ink['axis'] = imagecolorallocate($this->im, 95, 95, 95);
$this->ink['line'] = imagecolorallocate($this->im, 0xff, 0xff, 0x00);
$this->ink['background'] = imagecolorallocate($this->im, 0x00, 0x00,
0x00);
$this->ink['text'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
$this->ink['point'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
} | [
"private",
"function",
"allocateColors",
"(",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'red'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0x00",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'orange'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xd2",
",",
"0x8a",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'yellow'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'green'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x00",
",",
"0xff",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'blue'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x00",
",",
"0x00",
",",
"0xff",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'purple'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x70",
",",
"0x70",
",",
"0xf9",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'white'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0xff",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'black'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x00",
",",
"0x00",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'gray'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xaf",
",",
"0xaf",
",",
"0xaf",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'axis'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"95",
",",
"95",
",",
"95",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'line'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'background'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x00",
",",
"0x00",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'text'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0xff",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'point'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0xff",
")",
";",
"}"
] | Allocates the default color used | [
"Allocates",
"the",
"default",
"color",
"used"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L209-L230 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.mapYvalue | private function mapYvalue($value)
{
$rangeMapper = new \sb\Math\RangeMapper(Array(30, $this->graph_height), Array($this->min, $this->max));
return $rangeMapper->convert($value);
} | php | private function mapYvalue($value)
{
$rangeMapper = new \sb\Math\RangeMapper(Array(30, $this->graph_height), Array($this->min, $this->max));
return $rangeMapper->convert($value);
} | [
"private",
"function",
"mapYvalue",
"(",
"$",
"value",
")",
"{",
"$",
"rangeMapper",
"=",
"new",
"\\",
"sb",
"\\",
"Math",
"\\",
"RangeMapper",
"(",
"Array",
"(",
"30",
",",
"$",
"this",
"->",
"graph_height",
")",
",",
"Array",
"(",
"$",
"this",
"->",
"min",
",",
"$",
"this",
"->",
"max",
")",
")",
";",
"return",
"$",
"rangeMapper",
"->",
"convert",
"(",
"$",
"value",
")",
";",
"}"
] | Converts the range from point to pixel value
@param integer $value The value to convert
@return integer The number as converted into the pixel range on the graph | [
"Converts",
"the",
"range",
"from",
"point",
"to",
"pixel",
"value"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L238-L243 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.setValues | private function setValues($values)
{
$numbers = Array();
foreach ($values as $key => $val) {
$value = new \stdClass();
$value->label = trim($key);
if (!is_numeric($val)) {
$val = null;
}
$value->value = $val;
$this->values[] = $value;
$numbers[] = $val;
}
$min_max = Array();
foreach ($numbers as $number) {
if (!is_null($number)) {
array_push($min_max, $number);
}
}
$this->min = min($min_max);
$this->max = max($min_max);
$this->total_values = count($numbers);
$separation_dist = (($this->graph_width - 40) / $this->total_values);
$i = 0;
$this->points = Array();
foreach ($this->values as $value) {
$point = new \stdClass();
$point->x = ($i * $separation_dist) + $this->axis_offset + 40;
$point->y = $this->plotValue($value->value);
$point->label = $value->label;
$point->value = $value->value;
$this->points[] = $point;
$i++;
}
return $this->points;
} | php | private function setValues($values)
{
$numbers = Array();
foreach ($values as $key => $val) {
$value = new \stdClass();
$value->label = trim($key);
if (!is_numeric($val)) {
$val = null;
}
$value->value = $val;
$this->values[] = $value;
$numbers[] = $val;
}
$min_max = Array();
foreach ($numbers as $number) {
if (!is_null($number)) {
array_push($min_max, $number);
}
}
$this->min = min($min_max);
$this->max = max($min_max);
$this->total_values = count($numbers);
$separation_dist = (($this->graph_width - 40) / $this->total_values);
$i = 0;
$this->points = Array();
foreach ($this->values as $value) {
$point = new \stdClass();
$point->x = ($i * $separation_dist) + $this->axis_offset + 40;
$point->y = $this->plotValue($value->value);
$point->label = $value->label;
$point->value = $value->value;
$this->points[] = $point;
$i++;
}
return $this->points;
} | [
"private",
"function",
"setValues",
"(",
"$",
"values",
")",
"{",
"$",
"numbers",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"value",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"value",
"->",
"label",
"=",
"trim",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"val",
")",
")",
"{",
"$",
"val",
"=",
"null",
";",
"}",
"$",
"value",
"->",
"value",
"=",
"$",
"val",
";",
"$",
"this",
"->",
"values",
"[",
"]",
"=",
"$",
"value",
";",
"$",
"numbers",
"[",
"]",
"=",
"$",
"val",
";",
"}",
"$",
"min_max",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"numbers",
"as",
"$",
"number",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"number",
")",
")",
"{",
"array_push",
"(",
"$",
"min_max",
",",
"$",
"number",
")",
";",
"}",
"}",
"$",
"this",
"->",
"min",
"=",
"min",
"(",
"$",
"min_max",
")",
";",
"$",
"this",
"->",
"max",
"=",
"max",
"(",
"$",
"min_max",
")",
";",
"$",
"this",
"->",
"total_values",
"=",
"count",
"(",
"$",
"numbers",
")",
";",
"$",
"separation_dist",
"=",
"(",
"(",
"$",
"this",
"->",
"graph_width",
"-",
"40",
")",
"/",
"$",
"this",
"->",
"total_values",
")",
";",
"$",
"i",
"=",
"0",
";",
"$",
"this",
"->",
"points",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"point",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"point",
"->",
"x",
"=",
"(",
"$",
"i",
"*",
"$",
"separation_dist",
")",
"+",
"$",
"this",
"->",
"axis_offset",
"+",
"40",
";",
"$",
"point",
"->",
"y",
"=",
"$",
"this",
"->",
"plotValue",
"(",
"$",
"value",
"->",
"value",
")",
";",
"$",
"point",
"->",
"label",
"=",
"$",
"value",
"->",
"label",
";",
"$",
"point",
"->",
"value",
"=",
"$",
"value",
"->",
"value",
";",
"$",
"this",
"->",
"points",
"[",
"]",
"=",
"$",
"point",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"this",
"->",
"points",
";",
"}"
] | Converts the values into usable data for the drawing of the graph
@param array $values | [
"Converts",
"the",
"values",
"into",
"usable",
"data",
"for",
"the",
"drawing",
"of",
"the",
"graph"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L250-L294 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.drawYaxis | private function drawYaxis()
{
$min =
round($this->min, $this->precision);
$max =
round($this->max, $this->precision);
if (!isset($this->y_axis_legend_increment)) {
$increment =
round(($max - $min) / $this->total_values, $this->precision);
} else {
$increment = $this->y_axis_legend_increment;
}
if ($increment == 0) {
$increment = 1;
}
//$spacing = \round($spacing, 10);
for ($label = $min; $label <= $max + $increment; $label+=$increment) {
$px_position = $this->plotValue($label);
if ($this->x_axis_hints == 1) {
\imageline($this->im, 0, $px_position, $this->width,
$px_position, $this->ink['axis']);
}
imagestring($this->im, 1, 10, $px_position - 4, $label,
$this->ink['text']);
}
} | php | private function drawYaxis()
{
$min =
round($this->min, $this->precision);
$max =
round($this->max, $this->precision);
if (!isset($this->y_axis_legend_increment)) {
$increment =
round(($max - $min) / $this->total_values, $this->precision);
} else {
$increment = $this->y_axis_legend_increment;
}
if ($increment == 0) {
$increment = 1;
}
//$spacing = \round($spacing, 10);
for ($label = $min; $label <= $max + $increment; $label+=$increment) {
$px_position = $this->plotValue($label);
if ($this->x_axis_hints == 1) {
\imageline($this->im, 0, $px_position, $this->width,
$px_position, $this->ink['axis']);
}
imagestring($this->im, 1, 10, $px_position - 4, $label,
$this->ink['text']);
}
} | [
"private",
"function",
"drawYaxis",
"(",
")",
"{",
"$",
"min",
"=",
"round",
"(",
"$",
"this",
"->",
"min",
",",
"$",
"this",
"->",
"precision",
")",
";",
"$",
"max",
"=",
"round",
"(",
"$",
"this",
"->",
"max",
",",
"$",
"this",
"->",
"precision",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"y_axis_legend_increment",
")",
")",
"{",
"$",
"increment",
"=",
"round",
"(",
"(",
"$",
"max",
"-",
"$",
"min",
")",
"/",
"$",
"this",
"->",
"total_values",
",",
"$",
"this",
"->",
"precision",
")",
";",
"}",
"else",
"{",
"$",
"increment",
"=",
"$",
"this",
"->",
"y_axis_legend_increment",
";",
"}",
"if",
"(",
"$",
"increment",
"==",
"0",
")",
"{",
"$",
"increment",
"=",
"1",
";",
"}",
"//$spacing = \\round($spacing, 10);",
"for",
"(",
"$",
"label",
"=",
"$",
"min",
";",
"$",
"label",
"<=",
"$",
"max",
"+",
"$",
"increment",
";",
"$",
"label",
"+=",
"$",
"increment",
")",
"{",
"$",
"px_position",
"=",
"$",
"this",
"->",
"plotValue",
"(",
"$",
"label",
")",
";",
"if",
"(",
"$",
"this",
"->",
"x_axis_hints",
"==",
"1",
")",
"{",
"\\",
"imageline",
"(",
"$",
"this",
"->",
"im",
",",
"0",
",",
"$",
"px_position",
",",
"$",
"this",
"->",
"width",
",",
"$",
"px_position",
",",
"$",
"this",
"->",
"ink",
"[",
"'axis'",
"]",
")",
";",
"}",
"imagestring",
"(",
"$",
"this",
"->",
"im",
",",
"1",
",",
"10",
",",
"$",
"px_position",
"-",
"4",
",",
"$",
"label",
",",
"$",
"this",
"->",
"ink",
"[",
"'text'",
"]",
")",
";",
"}",
"}"
] | Draws the y axis on the graph at each point in a dashed line
fashion. This is totally optional and only happens if
$this->draw_y_axis ==1 | [
"Draws",
"the",
"y",
"axis",
"on",
"the",
"graph",
"at",
"each",
"point",
"in",
"a",
"dashed",
"line",
"fashion",
".",
"This",
"is",
"totally",
"optional",
"and",
"only",
"happens",
"if",
"$this",
"-",
">",
"draw_y_axis",
"==",
"1"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L302-L333 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.plotValue | private function plotValue($y)
{
$rangeMapper = new \sb\Math\RangeMapper(Array(
$this->axis_offset,
$this->graph_height - $this->axis_offset
), Array($this->max, $this->min));
return $rangeMapper->convert($y);
} | php | private function plotValue($y)
{
$rangeMapper = new \sb\Math\RangeMapper(Array(
$this->axis_offset,
$this->graph_height - $this->axis_offset
), Array($this->max, $this->min));
return $rangeMapper->convert($y);
} | [
"private",
"function",
"plotValue",
"(",
"$",
"y",
")",
"{",
"$",
"rangeMapper",
"=",
"new",
"\\",
"sb",
"\\",
"Math",
"\\",
"RangeMapper",
"(",
"Array",
"(",
"$",
"this",
"->",
"axis_offset",
",",
"$",
"this",
"->",
"graph_height",
"-",
"$",
"this",
"->",
"axis_offset",
")",
",",
"Array",
"(",
"$",
"this",
"->",
"max",
",",
"$",
"this",
"->",
"min",
")",
")",
";",
"return",
"$",
"rangeMapper",
"->",
"convert",
"(",
"$",
"y",
")",
";",
"}"
] | Converts points on the graph to pixels
@param integer $y
@return integer The value in pixels | [
"Converts",
"points",
"on",
"the",
"graph",
"to",
"pixels"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L341-L348 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.connectPoints | private function connectPoints()
{
foreach ($this->points as $point) {
if (is_null($point->value)) {
$last_x = $point->x;
$last_y = $point->y;
$last_val = $point->value;
continue;
}
if (isset($last_x) && (isset($last_val) && !is_null($last_val))) {
imageline($this->im, $last_x, $last_y, $point->x, $point->y,
$this->ink['line']);
}
$last_val = $point->value;
$last_x = $point->x;
$last_y = $point->y;
}
} | php | private function connectPoints()
{
foreach ($this->points as $point) {
if (is_null($point->value)) {
$last_x = $point->x;
$last_y = $point->y;
$last_val = $point->value;
continue;
}
if (isset($last_x) && (isset($last_val) && !is_null($last_val))) {
imageline($this->im, $last_x, $last_y, $point->x, $point->y,
$this->ink['line']);
}
$last_val = $point->value;
$last_x = $point->x;
$last_y = $point->y;
}
} | [
"private",
"function",
"connectPoints",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"points",
"as",
"$",
"point",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"point",
"->",
"value",
")",
")",
"{",
"$",
"last_x",
"=",
"$",
"point",
"->",
"x",
";",
"$",
"last_y",
"=",
"$",
"point",
"->",
"y",
";",
"$",
"last_val",
"=",
"$",
"point",
"->",
"value",
";",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"last_x",
")",
"&&",
"(",
"isset",
"(",
"$",
"last_val",
")",
"&&",
"!",
"is_null",
"(",
"$",
"last_val",
")",
")",
")",
"{",
"imageline",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"last_x",
",",
"$",
"last_y",
",",
"$",
"point",
"->",
"x",
",",
"$",
"point",
"->",
"y",
",",
"$",
"this",
"->",
"ink",
"[",
"'line'",
"]",
")",
";",
"}",
"$",
"last_val",
"=",
"$",
"point",
"->",
"value",
";",
"$",
"last_x",
"=",
"$",
"point",
"->",
"x",
";",
"$",
"last_y",
"=",
"$",
"point",
"->",
"y",
";",
"}",
"}"
] | Connect the points on a graph | [
"Connect",
"the",
"points",
"on",
"a",
"graph"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L354-L373 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.draw | public function draw()
{
$this->drawYaxis();
if ($this->connect_points == 1) {
$this->connectPoints();
}
foreach ($this->points as $point) {
if ($this->y_axis_hints == 1) {
imagedashedline($this->im, $point->x, $this->height, $point->x,
0, $this->ink['axis']);
} else {
//add axis line
imageline($this->im, $point->x, $this->graph_height, $point->x,
$this->graph_height + 10, $this->ink['axis']);
}
//add axis label
imagestring($this->im, 1, $point->x + 5, $this->graph_height + 10,
$point->label, $this->ink['text']);
//don't plot actual point if it is null
if (is_null($point->value)) {
continue;
}
//plot point
imagefilledellipse($this->im, $point->x, $point->y, 7, 7,
$this->ink['point']);
//add point label
if ($point->y <= 5) {
$posy = $point->y + 5;
} elseif ($point->y >= $this->graph_height - 5) {
$posy = $point->y - 20;
} else {
$posy = $point->y - 15;
}
imagestring($this->im, 3, $point->x + 10, $posy, $point->value,
$this->ink['point']);
}
} | php | public function draw()
{
$this->drawYaxis();
if ($this->connect_points == 1) {
$this->connectPoints();
}
foreach ($this->points as $point) {
if ($this->y_axis_hints == 1) {
imagedashedline($this->im, $point->x, $this->height, $point->x,
0, $this->ink['axis']);
} else {
//add axis line
imageline($this->im, $point->x, $this->graph_height, $point->x,
$this->graph_height + 10, $this->ink['axis']);
}
//add axis label
imagestring($this->im, 1, $point->x + 5, $this->graph_height + 10,
$point->label, $this->ink['text']);
//don't plot actual point if it is null
if (is_null($point->value)) {
continue;
}
//plot point
imagefilledellipse($this->im, $point->x, $point->y, 7, 7,
$this->ink['point']);
//add point label
if ($point->y <= 5) {
$posy = $point->y + 5;
} elseif ($point->y >= $this->graph_height - 5) {
$posy = $point->y - 20;
} else {
$posy = $point->y - 15;
}
imagestring($this->im, 3, $point->x + 10, $posy, $point->value,
$this->ink['point']);
}
} | [
"public",
"function",
"draw",
"(",
")",
"{",
"$",
"this",
"->",
"drawYaxis",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"connect_points",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"connectPoints",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"points",
"as",
"$",
"point",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"y_axis_hints",
"==",
"1",
")",
"{",
"imagedashedline",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"point",
"->",
"x",
",",
"$",
"this",
"->",
"height",
",",
"$",
"point",
"->",
"x",
",",
"0",
",",
"$",
"this",
"->",
"ink",
"[",
"'axis'",
"]",
")",
";",
"}",
"else",
"{",
"//add axis line",
"imageline",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"point",
"->",
"x",
",",
"$",
"this",
"->",
"graph_height",
",",
"$",
"point",
"->",
"x",
",",
"$",
"this",
"->",
"graph_height",
"+",
"10",
",",
"$",
"this",
"->",
"ink",
"[",
"'axis'",
"]",
")",
";",
"}",
"//add axis label",
"imagestring",
"(",
"$",
"this",
"->",
"im",
",",
"1",
",",
"$",
"point",
"->",
"x",
"+",
"5",
",",
"$",
"this",
"->",
"graph_height",
"+",
"10",
",",
"$",
"point",
"->",
"label",
",",
"$",
"this",
"->",
"ink",
"[",
"'text'",
"]",
")",
";",
"//don't plot actual point if it is null",
"if",
"(",
"is_null",
"(",
"$",
"point",
"->",
"value",
")",
")",
"{",
"continue",
";",
"}",
"//plot point",
"imagefilledellipse",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"point",
"->",
"x",
",",
"$",
"point",
"->",
"y",
",",
"7",
",",
"7",
",",
"$",
"this",
"->",
"ink",
"[",
"'point'",
"]",
")",
";",
"//add point label",
"if",
"(",
"$",
"point",
"->",
"y",
"<=",
"5",
")",
"{",
"$",
"posy",
"=",
"$",
"point",
"->",
"y",
"+",
"5",
";",
"}",
"elseif",
"(",
"$",
"point",
"->",
"y",
">=",
"$",
"this",
"->",
"graph_height",
"-",
"5",
")",
"{",
"$",
"posy",
"=",
"$",
"point",
"->",
"y",
"-",
"20",
";",
"}",
"else",
"{",
"$",
"posy",
"=",
"$",
"point",
"->",
"y",
"-",
"15",
";",
"}",
"imagestring",
"(",
"$",
"this",
"->",
"im",
",",
"3",
",",
"$",
"point",
"->",
"x",
"+",
"10",
",",
"$",
"posy",
",",
"$",
"point",
"->",
"value",
",",
"$",
"this",
"->",
"ink",
"[",
"'point'",
"]",
")",
";",
"}",
"}"
] | Draw the basic graph and plot the points | [
"Draw",
"the",
"basic",
"graph",
"and",
"plot",
"the",
"points"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L379-L425 |
surebert/surebert-framework | src/sb/Graph/Point.php | Point.addHorizontalLine | public function addHorizontalLine($y, $color = 'red', $label = '')
{
if (!array_key_exists($color, $this->ink)) {
throw(new \Exception("Ink color must be in " . implode(",",
\array_keys($this->ink))));
}
$y = $this->plotValue($y);
imageline($this->im, 0, $y, $this->width, $y, $this->ink[$color]);
imagestring($this->im, 2, $this->graph_width / 2 + $this->axis_offset,
$y, $label, $this->ink[$color]);
} | php | public function addHorizontalLine($y, $color = 'red', $label = '')
{
if (!array_key_exists($color, $this->ink)) {
throw(new \Exception("Ink color must be in " . implode(",",
\array_keys($this->ink))));
}
$y = $this->plotValue($y);
imageline($this->im, 0, $y, $this->width, $y, $this->ink[$color]);
imagestring($this->im, 2, $this->graph_width / 2 + $this->axis_offset,
$y, $label, $this->ink[$color]);
} | [
"public",
"function",
"addHorizontalLine",
"(",
"$",
"y",
",",
"$",
"color",
"=",
"'red'",
",",
"$",
"label",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"color",
",",
"$",
"this",
"->",
"ink",
")",
")",
"{",
"throw",
"(",
"new",
"\\",
"Exception",
"(",
"\"Ink color must be in \"",
".",
"implode",
"(",
"\",\"",
",",
"\\",
"array_keys",
"(",
"$",
"this",
"->",
"ink",
")",
")",
")",
")",
";",
"}",
"$",
"y",
"=",
"$",
"this",
"->",
"plotValue",
"(",
"$",
"y",
")",
";",
"imageline",
"(",
"$",
"this",
"->",
"im",
",",
"0",
",",
"$",
"y",
",",
"$",
"this",
"->",
"width",
",",
"$",
"y",
",",
"$",
"this",
"->",
"ink",
"[",
"$",
"color",
"]",
")",
";",
"imagestring",
"(",
"$",
"this",
"->",
"im",
",",
"2",
",",
"$",
"this",
"->",
"graph_width",
"/",
"2",
"+",
"$",
"this",
"->",
"axis_offset",
",",
"$",
"y",
",",
"$",
"label",
",",
"$",
"this",
"->",
"ink",
"[",
"$",
"color",
"]",
")",
";",
"}"
] | Add a horizontal line
@param integer $y The y value
@param string $color red, orange, yellow, green, blue, purple
@param string $label The line label | [
"Add",
"a",
"horizontal",
"line"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L434-L447 |
spiral-modules/listing | source/Listing/Prototypes/DependedModificator.php | DependedModificator.loadDependencies | protected function loadDependencies(RecordSelector $selector)
{
if (empty($this->dependencies)) {
return $selector;
}
foreach ($this->dependencies as $dependency) {
$selector = $selector->with(
$dependency->getRelation(),
$dependency->getOptions()
);
}
return $selector;
} | php | protected function loadDependencies(RecordSelector $selector)
{
if (empty($this->dependencies)) {
return $selector;
}
foreach ($this->dependencies as $dependency) {
$selector = $selector->with(
$dependency->getRelation(),
$dependency->getOptions()
);
}
return $selector;
} | [
"protected",
"function",
"loadDependencies",
"(",
"RecordSelector",
"$",
"selector",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"dependencies",
")",
")",
"{",
"return",
"$",
"selector",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"dependencies",
"as",
"$",
"dependency",
")",
"{",
"$",
"selector",
"=",
"$",
"selector",
"->",
"with",
"(",
"$",
"dependency",
"->",
"getRelation",
"(",
")",
",",
"$",
"dependency",
"->",
"getOptions",
"(",
")",
")",
";",
"}",
"return",
"$",
"selector",
";",
"}"
] | Apply dependencies for RecordSelector
@param RecordSelector $selector
@return RecordSelector | [
"Apply",
"dependencies",
"for",
"RecordSelector"
] | train | https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/Prototypes/DependedModificator.php#L72-L86 |
interactivesolutions/honeycomb-core | src/models/HCUuidModel.php | HCUuidModel.boot | protected static function boot ()
{
parent::boot ();
/**
* Attach to the 'creating' Model Event to provide a UUID
* for the `id` field (provided by $model->getKeyName())
*/
static::creating (function ($model)
{
if (!isset($model->attributes['id']))
$model->attributes['id'] = uuid4 ();
$model->{$model->getKeyName ()} = $model->attributes['id'];
});
} | php | protected static function boot ()
{
parent::boot ();
/**
* Attach to the 'creating' Model Event to provide a UUID
* for the `id` field (provided by $model->getKeyName())
*/
static::creating (function ($model)
{
if (!isset($model->attributes['id']))
$model->attributes['id'] = uuid4 ();
$model->{$model->getKeyName ()} = $model->attributes['id'];
});
} | [
"protected",
"static",
"function",
"boot",
"(",
")",
"{",
"parent",
"::",
"boot",
"(",
")",
";",
"/**\n * Attach to the 'creating' Model Event to provide a UUID\n * for the `id` field (provided by $model->getKeyName())\n */",
"static",
"::",
"creating",
"(",
"function",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"model",
"->",
"attributes",
"[",
"'id'",
"]",
")",
")",
"$",
"model",
"->",
"attributes",
"[",
"'id'",
"]",
"=",
"uuid4",
"(",
")",
";",
"$",
"model",
"->",
"{",
"$",
"model",
"->",
"getKeyName",
"(",
")",
"}",
"=",
"$",
"model",
"->",
"attributes",
"[",
"'id'",
"]",
";",
"}",
")",
";",
"}"
] | The "booting" method of the model.
@return void | [
"The",
"booting",
"method",
"of",
"the",
"model",
"."
] | train | https://github.com/interactivesolutions/honeycomb-core/blob/06b8d88bb285e73a1a286e60411ca5f41863f39f/src/models/HCUuidModel.php#L23-L38 |
LeaseCloud/leasecloud-php-sdk | src/Webook.php | Webook.validateSignature | public static function validateSignature($signature, $payload)
{
$parts = explode(',', $signature);
$parameters = [];
$t = 0;
// Find the timestamp
foreach ($parts as $part) {
parse_str($part, $parsed);
if (key($parsed) === 't') {
$t = $parsed['t'];
break;
}
}
if ($t === 0) {
return false;
}
$wanted = hash_hmac('sha256', $t . '.' . $payload, self::$secret);
// Find v1 hashes
foreach ($parts as $part) {
parse_str($part, $parsed);
if (key($parsed) === 'v1') {
if ($wanted === $parsed['v1']) {
return true;
}
}
}
return false;
} | php | public static function validateSignature($signature, $payload)
{
$parts = explode(',', $signature);
$parameters = [];
$t = 0;
// Find the timestamp
foreach ($parts as $part) {
parse_str($part, $parsed);
if (key($parsed) === 't') {
$t = $parsed['t'];
break;
}
}
if ($t === 0) {
return false;
}
$wanted = hash_hmac('sha256', $t . '.' . $payload, self::$secret);
// Find v1 hashes
foreach ($parts as $part) {
parse_str($part, $parsed);
if (key($parsed) === 'v1') {
if ($wanted === $parsed['v1']) {
return true;
}
}
}
return false;
} | [
"public",
"static",
"function",
"validateSignature",
"(",
"$",
"signature",
",",
"$",
"payload",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"','",
",",
"$",
"signature",
")",
";",
"$",
"parameters",
"=",
"[",
"]",
";",
"$",
"t",
"=",
"0",
";",
"// Find the timestamp",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"parse_str",
"(",
"$",
"part",
",",
"$",
"parsed",
")",
";",
"if",
"(",
"key",
"(",
"$",
"parsed",
")",
"===",
"'t'",
")",
"{",
"$",
"t",
"=",
"$",
"parsed",
"[",
"'t'",
"]",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"t",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"wanted",
"=",
"hash_hmac",
"(",
"'sha256'",
",",
"$",
"t",
".",
"'.'",
".",
"$",
"payload",
",",
"self",
"::",
"$",
"secret",
")",
";",
"// Find v1 hashes",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"parse_str",
"(",
"$",
"part",
",",
"$",
"parsed",
")",
";",
"if",
"(",
"key",
"(",
"$",
"parsed",
")",
"===",
"'v1'",
")",
"{",
"if",
"(",
"$",
"wanted",
"===",
"$",
"parsed",
"[",
"'v1'",
"]",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Validate the webhook signature
@param string $signature The string passed in header LeaseCloud-Signature
@param string $payload The raw payload
@return bool True if the signature is valid, otherwise false | [
"Validate",
"the",
"webhook",
"signature"
] | train | https://github.com/LeaseCloud/leasecloud-php-sdk/blob/091b073dd4f79ba915a68c0ed151bd9bfa61e7ca/src/Webook.php#L35-L66 |
NuclearCMS/Hierarchy | src/Tags/Taggable.php | Taggable.attachTag | public function attachTag($id)
{
if ( ! $this->tags->contains($id))
{
return $this->tags()->attach($id);
}
} | php | public function attachTag($id)
{
if ( ! $this->tags->contains($id))
{
return $this->tags()->attach($id);
}
} | [
"public",
"function",
"attachTag",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tags",
"->",
"contains",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"tags",
"(",
")",
"->",
"attach",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Links a tag to the node
@param int $id | [
"Links",
"a",
"tag",
"to",
"the",
"node"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Tags/Taggable.php#L36-L42 |
bpolaszek/simple-dbal | src/Model/Adapter/Mysqli/MysqliAdapter.php | MysqliAdapter.executeParallel | private function executeParallel($stmt, array $values = null): PromiseInterface
{
if (is_string($stmt)) {
$stmt = $this->emulatePrepare((string) $stmt, $values);
} else {
if (!$stmt instanceof Statement) {
throw new \InvalidArgumentException(sprintf('Expected %s object, got %s', Statement::class, get_class($stmt)));
}
if (!$stmt instanceof EmulatedStatement) {
$stmt = $this->emulatePrepare((string) $stmt, $values ?? $stmt->getValues());
} elseif (null !== $values) {
$stmt = $stmt->withValues($values);
}
}
try {
// Clone connection (Mysqli Asynchronous queries require a different connection to work properly)
$credentials = $this->getCredentials();
$cnx = self::createLink($credentials);
if ($this->hasOption('charset')) {
$cnx->set_charset($this->getOption('charset'));
}
} catch (mysqli_sql_exception $e) {
throw new AccessDeniedException($e->getMessage(), (int) $e->getCode(), $e);
}
$stmt->bind();
$promise = MysqliAsync::query($stmt->getRunnableQuery(), $cnx)->then(function ($result) use ($cnx, $stmt) {
if (!$result instanceof mysqli_result) {
$result = null;
}
return new Result($cnx, $result);
});
return $promise;
} | php | private function executeParallel($stmt, array $values = null): PromiseInterface
{
if (is_string($stmt)) {
$stmt = $this->emulatePrepare((string) $stmt, $values);
} else {
if (!$stmt instanceof Statement) {
throw new \InvalidArgumentException(sprintf('Expected %s object, got %s', Statement::class, get_class($stmt)));
}
if (!$stmt instanceof EmulatedStatement) {
$stmt = $this->emulatePrepare((string) $stmt, $values ?? $stmt->getValues());
} elseif (null !== $values) {
$stmt = $stmt->withValues($values);
}
}
try {
// Clone connection (Mysqli Asynchronous queries require a different connection to work properly)
$credentials = $this->getCredentials();
$cnx = self::createLink($credentials);
if ($this->hasOption('charset')) {
$cnx->set_charset($this->getOption('charset'));
}
} catch (mysqli_sql_exception $e) {
throw new AccessDeniedException($e->getMessage(), (int) $e->getCode(), $e);
}
$stmt->bind();
$promise = MysqliAsync::query($stmt->getRunnableQuery(), $cnx)->then(function ($result) use ($cnx, $stmt) {
if (!$result instanceof mysqli_result) {
$result = null;
}
return new Result($cnx, $result);
});
return $promise;
} | [
"private",
"function",
"executeParallel",
"(",
"$",
"stmt",
",",
"array",
"$",
"values",
"=",
"null",
")",
":",
"PromiseInterface",
"{",
"if",
"(",
"is_string",
"(",
"$",
"stmt",
")",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"emulatePrepare",
"(",
"(",
"string",
")",
"$",
"stmt",
",",
"$",
"values",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"stmt",
"instanceof",
"Statement",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Expected %s object, got %s'",
",",
"Statement",
"::",
"class",
",",
"get_class",
"(",
"$",
"stmt",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"stmt",
"instanceof",
"EmulatedStatement",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"emulatePrepare",
"(",
"(",
"string",
")",
"$",
"stmt",
",",
"$",
"values",
"??",
"$",
"stmt",
"->",
"getValues",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"values",
")",
"{",
"$",
"stmt",
"=",
"$",
"stmt",
"->",
"withValues",
"(",
"$",
"values",
")",
";",
"}",
"}",
"try",
"{",
"// Clone connection (Mysqli Asynchronous queries require a different connection to work properly)",
"$",
"credentials",
"=",
"$",
"this",
"->",
"getCredentials",
"(",
")",
";",
"$",
"cnx",
"=",
"self",
"::",
"createLink",
"(",
"$",
"credentials",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasOption",
"(",
"'charset'",
")",
")",
"{",
"$",
"cnx",
"->",
"set_charset",
"(",
"$",
"this",
"->",
"getOption",
"(",
"'charset'",
")",
")",
";",
"}",
"}",
"catch",
"(",
"mysqli_sql_exception",
"$",
"e",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"(",
"int",
")",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"$",
"stmt",
"->",
"bind",
"(",
")",
";",
"$",
"promise",
"=",
"MysqliAsync",
"::",
"query",
"(",
"$",
"stmt",
"->",
"getRunnableQuery",
"(",
")",
",",
"$",
"cnx",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"result",
")",
"use",
"(",
"$",
"cnx",
",",
"$",
"stmt",
")",
"{",
"if",
"(",
"!",
"$",
"result",
"instanceof",
"mysqli_result",
")",
"{",
"$",
"result",
"=",
"null",
";",
"}",
"return",
"new",
"Result",
"(",
"$",
"cnx",
",",
"$",
"result",
")",
";",
"}",
")",
";",
"return",
"$",
"promise",
";",
"}"
] | EXPERIMENTAL ! Executes a statement asynchronously.
The promise will return a Result object.
@param $stmt
@param array|null $values
@return PromiseInterface | [
"EXPERIMENTAL",
"!",
"Executes",
"a",
"statement",
"asynchronously",
".",
"The",
"promise",
"will",
"return",
"a",
"Result",
"object",
"."
] | train | https://github.com/bpolaszek/simple-dbal/blob/52cb50d326ba5854191814b470f5e84950ebb6e6/src/Model/Adapter/Mysqli/MysqliAdapter.php#L232-L266 |
watoki/curir | src/protocol/MimeTypes.php | MimeTypes.getType | public static function getType($extension) {
foreach (self::$map as $mime => $exts) {
if (in_array(strtolower($extension), $exts)) {
return $mime;
}
}
return null;
} | php | public static function getType($extension) {
foreach (self::$map as $mime => $exts) {
if (in_array(strtolower($extension), $exts)) {
return $mime;
}
}
return null;
} | [
"public",
"static",
"function",
"getType",
"(",
"$",
"extension",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"map",
"as",
"$",
"mime",
"=>",
"$",
"exts",
")",
"{",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"extension",
")",
",",
"$",
"exts",
")",
")",
"{",
"return",
"$",
"mime",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Retruns MIME type belonging to given file extension or null if not found.
@static
@param $extension
@return null|string | [
"Retruns",
"MIME",
"type",
"belonging",
"to",
"given",
"file",
"extension",
"or",
"null",
"if",
"not",
"found",
"."
] | train | https://github.com/watoki/curir/blob/20a44e1d1980f472369991e19ef8d3bafda79a64/src/protocol/MimeTypes.php#L137-L144 |
zicht/z | src/Zicht/Tool/PropertyPath/PropertyAccessor.php | PropertyAccessor.getByPath | public static function getByPath($subject, array $path, $notFoundIsError = true)
{
$ptr = & $subject;
foreach ($path as $key) {
if (is_object($ptr) && property_exists($ptr, $key)) {
$ptr = & $ptr->$key;
} elseif (is_array($ptr) && array_key_exists($key, $ptr)) {
$ptr = & $ptr[$key];
} else {
if ($notFoundIsError === true) {
throw new \OutOfBoundsException("Path not found: " . implode('.', $path) . ", key {$key} did not resolve");
}
return null;
}
}
return $ptr;
} | php | public static function getByPath($subject, array $path, $notFoundIsError = true)
{
$ptr = & $subject;
foreach ($path as $key) {
if (is_object($ptr) && property_exists($ptr, $key)) {
$ptr = & $ptr->$key;
} elseif (is_array($ptr) && array_key_exists($key, $ptr)) {
$ptr = & $ptr[$key];
} else {
if ($notFoundIsError === true) {
throw new \OutOfBoundsException("Path not found: " . implode('.', $path) . ", key {$key} did not resolve");
}
return null;
}
}
return $ptr;
} | [
"public",
"static",
"function",
"getByPath",
"(",
"$",
"subject",
",",
"array",
"$",
"path",
",",
"$",
"notFoundIsError",
"=",
"true",
")",
"{",
"$",
"ptr",
"=",
"&",
"$",
"subject",
";",
"foreach",
"(",
"$",
"path",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"ptr",
")",
"&&",
"property_exists",
"(",
"$",
"ptr",
",",
"$",
"key",
")",
")",
"{",
"$",
"ptr",
"=",
"&",
"$",
"ptr",
"->",
"$",
"key",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"ptr",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"ptr",
")",
")",
"{",
"$",
"ptr",
"=",
"&",
"$",
"ptr",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"notFoundIsError",
"===",
"true",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"\"Path not found: \"",
".",
"implode",
"(",
"'.'",
",",
"$",
"path",
")",
".",
"\", key {$key} did not resolve\"",
")",
";",
"}",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"ptr",
";",
"}"
] | Get a property value by a path of property names or key names.
@param mixed $subject
@param array $path
@param bool $notFoundIsError
@return null
@throws \InvalidArgumentException | [
"Get",
"a",
"property",
"value",
"by",
"a",
"path",
"of",
"property",
"names",
"or",
"key",
"names",
"."
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/PropertyPath/PropertyAccessor.php#L25-L41 |
zicht/z | src/Zicht/Tool/PropertyPath/PropertyAccessor.php | PropertyAccessor.setByPath | public static function setByPath(&$subject, array $path, $value)
{
$ptr = & $subject;
foreach ($path as $key) {
if (is_object($ptr)) {
if (!isset($ptr->$key)) {
$ptr->$key = array();
}
$ptr = & $ptr->$key;
} elseif (is_array($ptr)) {
if (!isset($ptr[$key])) {
$ptr[$key] = array();
}
$ptr = & $ptr[$key];
}
}
$ptr = $value;
return $subject;
} | php | public static function setByPath(&$subject, array $path, $value)
{
$ptr = & $subject;
foreach ($path as $key) {
if (is_object($ptr)) {
if (!isset($ptr->$key)) {
$ptr->$key = array();
}
$ptr = & $ptr->$key;
} elseif (is_array($ptr)) {
if (!isset($ptr[$key])) {
$ptr[$key] = array();
}
$ptr = & $ptr[$key];
}
}
$ptr = $value;
return $subject;
} | [
"public",
"static",
"function",
"setByPath",
"(",
"&",
"$",
"subject",
",",
"array",
"$",
"path",
",",
"$",
"value",
")",
"{",
"$",
"ptr",
"=",
"&",
"$",
"subject",
";",
"foreach",
"(",
"$",
"path",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"ptr",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ptr",
"->",
"$",
"key",
")",
")",
"{",
"$",
"ptr",
"->",
"$",
"key",
"=",
"array",
"(",
")",
";",
"}",
"$",
"ptr",
"=",
"&",
"$",
"ptr",
"->",
"$",
"key",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"ptr",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ptr",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"ptr",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"ptr",
"=",
"&",
"$",
"ptr",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"$",
"ptr",
"=",
"$",
"value",
";",
"return",
"$",
"subject",
";",
"}"
] | Set a property value by a path of property or key names.
@param mixed &$subject
@param array $path
@param mixed $value
@return mixed | [
"Set",
"a",
"property",
"value",
"by",
"a",
"path",
"of",
"property",
"or",
"key",
"names",
"."
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/PropertyPath/PropertyAccessor.php#L52-L70 |
netvlies/NetvliesFormBundle | Service/FormService.php | FormService.get | public function get($id)
{
if (!isset($this->forms[$id])) {
$contentRepository = $this->container->get('doctrine')->getRepository('NetvliesFormBundle:Form');
$form = $contentRepository->findOneById($id);
$formBuilder = $this->container->get('form.factory')->createBuilder();
$formBuilder->add('form_id', 'hidden', array('data' => $id));
foreach ($form->getFields() as $field) {
$type = $field->getType();
$options = array(
'label' => $field->getLabel(),
'constraints' => array(),
);
if ($field->getRequired()) {
$options['constraints'][] = new NotBlank();
} else {
$options['required'] = false;
}
if ($field->getDefault()) {
$options['data'] = $field->getDefault();
}
switch ($field->getType()) {
case 'select':
$type = 'choice';
$options['expanded'] = ($field->getSelectType() != 'dropdown');
$options['multiple'] = $field->getSelectMultiple();
$options['choices'] = array();
foreach ($field->getOptions() as $option) {
$options['choices'][$option->getLabel()] = $option->getLabel();
}
if ($field->getDefault()) {
$options['data'] = $field->getDefault();
if ($options['multiple']) {
$options['data'] = explode(',', $options['data']);
}
}
break;
case 'email':
$options['constraints'][] = new Email();
break;
case 'date':
$options['widget'] = 'single_text';
$options['attr']['class'] = 'datepicker';
$options['attr']['placeholder'] = 'dd-mm-yyyy';
$options['input'] = 'string';
$options['format'] = 'd-M-y';
break;
}
$formBuilder->add('field_'.$field->getId(), $type, $options);
}
if ($form->getAddCaptcha()) {
$formBuilder->add('captcha', 'captcha');
}
$form->setSf2Form($formBuilder->getForm());
$this->forms[$id] = $form;
}
return $this->forms[$id];
} | php | public function get($id)
{
if (!isset($this->forms[$id])) {
$contentRepository = $this->container->get('doctrine')->getRepository('NetvliesFormBundle:Form');
$form = $contentRepository->findOneById($id);
$formBuilder = $this->container->get('form.factory')->createBuilder();
$formBuilder->add('form_id', 'hidden', array('data' => $id));
foreach ($form->getFields() as $field) {
$type = $field->getType();
$options = array(
'label' => $field->getLabel(),
'constraints' => array(),
);
if ($field->getRequired()) {
$options['constraints'][] = new NotBlank();
} else {
$options['required'] = false;
}
if ($field->getDefault()) {
$options['data'] = $field->getDefault();
}
switch ($field->getType()) {
case 'select':
$type = 'choice';
$options['expanded'] = ($field->getSelectType() != 'dropdown');
$options['multiple'] = $field->getSelectMultiple();
$options['choices'] = array();
foreach ($field->getOptions() as $option) {
$options['choices'][$option->getLabel()] = $option->getLabel();
}
if ($field->getDefault()) {
$options['data'] = $field->getDefault();
if ($options['multiple']) {
$options['data'] = explode(',', $options['data']);
}
}
break;
case 'email':
$options['constraints'][] = new Email();
break;
case 'date':
$options['widget'] = 'single_text';
$options['attr']['class'] = 'datepicker';
$options['attr']['placeholder'] = 'dd-mm-yyyy';
$options['input'] = 'string';
$options['format'] = 'd-M-y';
break;
}
$formBuilder->add('field_'.$field->getId(), $type, $options);
}
if ($form->getAddCaptcha()) {
$formBuilder->add('captcha', 'captcha');
}
$form->setSf2Form($formBuilder->getForm());
$this->forms[$id] = $form;
}
return $this->forms[$id];
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"forms",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"contentRepository",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'doctrine'",
")",
"->",
"getRepository",
"(",
"'NetvliesFormBundle:Form'",
")",
";",
"$",
"form",
"=",
"$",
"contentRepository",
"->",
"findOneById",
"(",
"$",
"id",
")",
";",
"$",
"formBuilder",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"createBuilder",
"(",
")",
";",
"$",
"formBuilder",
"->",
"add",
"(",
"'form_id'",
",",
"'hidden'",
",",
"array",
"(",
"'data'",
"=>",
"$",
"id",
")",
")",
";",
"foreach",
"(",
"$",
"form",
"->",
"getFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"type",
"=",
"$",
"field",
"->",
"getType",
"(",
")",
";",
"$",
"options",
"=",
"array",
"(",
"'label'",
"=>",
"$",
"field",
"->",
"getLabel",
"(",
")",
",",
"'constraints'",
"=>",
"array",
"(",
")",
",",
")",
";",
"if",
"(",
"$",
"field",
"->",
"getRequired",
"(",
")",
")",
"{",
"$",
"options",
"[",
"'constraints'",
"]",
"[",
"]",
"=",
"new",
"NotBlank",
"(",
")",
";",
"}",
"else",
"{",
"$",
"options",
"[",
"'required'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"field",
"->",
"getDefault",
"(",
")",
")",
"{",
"$",
"options",
"[",
"'data'",
"]",
"=",
"$",
"field",
"->",
"getDefault",
"(",
")",
";",
"}",
"switch",
"(",
"$",
"field",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'select'",
":",
"$",
"type",
"=",
"'choice'",
";",
"$",
"options",
"[",
"'expanded'",
"]",
"=",
"(",
"$",
"field",
"->",
"getSelectType",
"(",
")",
"!=",
"'dropdown'",
")",
";",
"$",
"options",
"[",
"'multiple'",
"]",
"=",
"$",
"field",
"->",
"getSelectMultiple",
"(",
")",
";",
"$",
"options",
"[",
"'choices'",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"field",
"->",
"getOptions",
"(",
")",
"as",
"$",
"option",
")",
"{",
"$",
"options",
"[",
"'choices'",
"]",
"[",
"$",
"option",
"->",
"getLabel",
"(",
")",
"]",
"=",
"$",
"option",
"->",
"getLabel",
"(",
")",
";",
"}",
"if",
"(",
"$",
"field",
"->",
"getDefault",
"(",
")",
")",
"{",
"$",
"options",
"[",
"'data'",
"]",
"=",
"$",
"field",
"->",
"getDefault",
"(",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'multiple'",
"]",
")",
"{",
"$",
"options",
"[",
"'data'",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"options",
"[",
"'data'",
"]",
")",
";",
"}",
"}",
"break",
";",
"case",
"'email'",
":",
"$",
"options",
"[",
"'constraints'",
"]",
"[",
"]",
"=",
"new",
"Email",
"(",
")",
";",
"break",
";",
"case",
"'date'",
":",
"$",
"options",
"[",
"'widget'",
"]",
"=",
"'single_text'",
";",
"$",
"options",
"[",
"'attr'",
"]",
"[",
"'class'",
"]",
"=",
"'datepicker'",
";",
"$",
"options",
"[",
"'attr'",
"]",
"[",
"'placeholder'",
"]",
"=",
"'dd-mm-yyyy'",
";",
"$",
"options",
"[",
"'input'",
"]",
"=",
"'string'",
";",
"$",
"options",
"[",
"'format'",
"]",
"=",
"'d-M-y'",
";",
"break",
";",
"}",
"$",
"formBuilder",
"->",
"add",
"(",
"'field_'",
".",
"$",
"field",
"->",
"getId",
"(",
")",
",",
"$",
"type",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"form",
"->",
"getAddCaptcha",
"(",
")",
")",
"{",
"$",
"formBuilder",
"->",
"add",
"(",
"'captcha'",
",",
"'captcha'",
")",
";",
"}",
"$",
"form",
"->",
"setSf2Form",
"(",
"$",
"formBuilder",
"->",
"getForm",
"(",
")",
")",
";",
"$",
"this",
"->",
"forms",
"[",
"$",
"id",
"]",
"=",
"$",
"form",
";",
"}",
"return",
"$",
"this",
"->",
"forms",
"[",
"$",
"id",
"]",
";",
"}"
] | Builds the form with the requested ID. When a form is requested for the
second time, the instance created earlier is returned to ensure only one
form instance is used and form properties can be set and retrieved from
all locations where the form is used.
@param $id
@return mixed | [
"Builds",
"the",
"form",
"with",
"the",
"requested",
"ID",
".",
"When",
"a",
"form",
"is",
"requested",
"for",
"the",
"second",
"time",
"the",
"instance",
"created",
"earlier",
"is",
"returned",
"to",
"ensure",
"only",
"one",
"form",
"instance",
"is",
"used",
"and",
"form",
"properties",
"can",
"be",
"set",
"and",
"retrieved",
"from",
"all",
"locations",
"where",
"the",
"form",
"is",
"used",
"."
] | train | https://github.com/netvlies/NetvliesFormBundle/blob/93f9a3321d9925040111374e7c1014a6400a2d08/Service/FormService.php#L32-L99 |
PHPPowertools/HTML5 | src/PowerTools/HTML5.php | HTML5.load | public function load($file) {
// Handle the case where file is a resource.
if (is_resource($file)) {
// FIXME: We need a StreamInputStream class.
return $this->loadHTML(stream_get_contents($file));
}
$input = new HTML5_Inputstream_File($file);
return $this->parse($input);
} | php | public function load($file) {
// Handle the case where file is a resource.
if (is_resource($file)) {
// FIXME: We need a StreamInputStream class.
return $this->loadHTML(stream_get_contents($file));
}
$input = new HTML5_Inputstream_File($file);
return $this->parse($input);
} | [
"public",
"function",
"load",
"(",
"$",
"file",
")",
"{",
"// Handle the case where file is a resource.",
"if",
"(",
"is_resource",
"(",
"$",
"file",
")",
")",
"{",
"// FIXME: We need a StreamInputStream class.",
"return",
"$",
"this",
"->",
"loadHTML",
"(",
"stream_get_contents",
"(",
"$",
"file",
")",
")",
";",
"}",
"$",
"input",
"=",
"new",
"HTML5_Inputstream_File",
"(",
"$",
"file",
")",
";",
"return",
"$",
"this",
"->",
"parse",
"(",
"$",
"input",
")",
";",
"}"
] | Load and parse an HTML file.
This will apply the HTML5 parser, which is tolerant of many
varieties of HTML, including XHTML 1, HTML 4, and well-formed HTML
3. Note that in these cases, not all of the old data will be
preserved. For example, XHTML's XML declaration will be removed.
The rules governing parsing are set out in the HTML 5 spec.
@param string $file
The path to the file to parse. If this is a resource, it is
assumed to be an open stream whose pointer is set to the first
byte of input.
@return \DOMDocument A DOM document. These object type is defined by the libxml
library, and should have been included with your version of PHP. | [
"Load",
"and",
"parse",
"an",
"HTML",
"file",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L139-L149 |
PHPPowertools/HTML5 | src/PowerTools/HTML5.php | HTML5.parse | public function parse(HTML5_Inputstream_Interface $input) {
$this->errors = array();
$events = new HTML5_Parser_DOMTreeBuilder(false, $this->options);
$scanner = new HTML5_Parser_Scanner($input);
$parser = new HTML5_Parser_Tokenizer($scanner, $events);
$parser->parse();
$this->errors = $events->getErrors();
return $events->document();
} | php | public function parse(HTML5_Inputstream_Interface $input) {
$this->errors = array();
$events = new HTML5_Parser_DOMTreeBuilder(false, $this->options);
$scanner = new HTML5_Parser_Scanner($input);
$parser = new HTML5_Parser_Tokenizer($scanner, $events);
$parser->parse();
$this->errors = $events->getErrors();
return $events->document();
} | [
"public",
"function",
"parse",
"(",
"HTML5_Inputstream_Interface",
"$",
"input",
")",
"{",
"$",
"this",
"->",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"events",
"=",
"new",
"HTML5_Parser_DOMTreeBuilder",
"(",
"false",
",",
"$",
"this",
"->",
"options",
")",
";",
"$",
"scanner",
"=",
"new",
"HTML5_Parser_Scanner",
"(",
"$",
"input",
")",
";",
"$",
"parser",
"=",
"new",
"HTML5_Parser_Tokenizer",
"(",
"$",
"scanner",
",",
"$",
"events",
")",
";",
"$",
"parser",
"->",
"parse",
"(",
")",
";",
"$",
"this",
"->",
"errors",
"=",
"$",
"events",
"->",
"getErrors",
"(",
")",
";",
"return",
"$",
"events",
"->",
"document",
"(",
")",
";",
"}"
] | Parse an input stream.
Lower-level loading function. This requires an input stream instead
of a string, file, or resource. | [
"Parse",
"an",
"input",
"stream",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L225-L235 |
PHPPowertools/HTML5 | src/PowerTools/HTML5.php | HTML5.parseFragment | public function parseFragment(HTML5_Inputstream_Interface $input) {
$events = new HTML5_Parser_DOMTreeBuilder(true, $this->options);
$scanner = new HTML5_Parser_Scanner($input);
$parser = new HTML5_Parser_Tokenizer($scanner, $events);
$parser->parse();
$this->errors = $events->getErrors();
return $events->fragment();
} | php | public function parseFragment(HTML5_Inputstream_Interface $input) {
$events = new HTML5_Parser_DOMTreeBuilder(true, $this->options);
$scanner = new HTML5_Parser_Scanner($input);
$parser = new HTML5_Parser_Tokenizer($scanner, $events);
$parser->parse();
$this->errors = $events->getErrors();
return $events->fragment();
} | [
"public",
"function",
"parseFragment",
"(",
"HTML5_Inputstream_Interface",
"$",
"input",
")",
"{",
"$",
"events",
"=",
"new",
"HTML5_Parser_DOMTreeBuilder",
"(",
"true",
",",
"$",
"this",
"->",
"options",
")",
";",
"$",
"scanner",
"=",
"new",
"HTML5_Parser_Scanner",
"(",
"$",
"input",
")",
";",
"$",
"parser",
"=",
"new",
"HTML5_Parser_Tokenizer",
"(",
"$",
"scanner",
",",
"$",
"events",
")",
";",
"$",
"parser",
"->",
"parse",
"(",
")",
";",
"$",
"this",
"->",
"errors",
"=",
"$",
"events",
"->",
"getErrors",
"(",
")",
";",
"return",
"$",
"events",
"->",
"fragment",
"(",
")",
";",
"}"
] | Parse an input stream where the stream is a fragment.
Lower-level loading function. This requires an input stream instead
of a string, file, or resource. | [
"Parse",
"an",
"input",
"stream",
"where",
"the",
"stream",
"is",
"a",
"fragment",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L243-L252 |
PHPPowertools/HTML5 | src/PowerTools/HTML5.php | HTML5.save | public function save($dom, $file, $options = array()) {
$close = true;
if (is_resource($file)) {
$stream = $file;
$close = false;
} else {
$stream = fopen($file, 'w');
}
$options = array_merge($this->getOptions(), $options);
$rules = new HTML5_Serializer_OutputRules($stream, $options);
$trav = new HTML5_Serializer_Traverser($dom, $stream, $rules, $options);
$trav->walk();
if ($close) {
fclose($stream);
}
} | php | public function save($dom, $file, $options = array()) {
$close = true;
if (is_resource($file)) {
$stream = $file;
$close = false;
} else {
$stream = fopen($file, 'w');
}
$options = array_merge($this->getOptions(), $options);
$rules = new HTML5_Serializer_OutputRules($stream, $options);
$trav = new HTML5_Serializer_Traverser($dom, $stream, $rules, $options);
$trav->walk();
if ($close) {
fclose($stream);
}
} | [
"public",
"function",
"save",
"(",
"$",
"dom",
",",
"$",
"file",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"close",
"=",
"true",
";",
"if",
"(",
"is_resource",
"(",
"$",
"file",
")",
")",
"{",
"$",
"stream",
"=",
"$",
"file",
";",
"$",
"close",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"stream",
"=",
"fopen",
"(",
"$",
"file",
",",
"'w'",
")",
";",
"}",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
",",
"$",
"options",
")",
";",
"$",
"rules",
"=",
"new",
"HTML5_Serializer_OutputRules",
"(",
"$",
"stream",
",",
"$",
"options",
")",
";",
"$",
"trav",
"=",
"new",
"HTML5_Serializer_Traverser",
"(",
"$",
"dom",
",",
"$",
"stream",
",",
"$",
"rules",
",",
"$",
"options",
")",
";",
"$",
"trav",
"->",
"walk",
"(",
")",
";",
"if",
"(",
"$",
"close",
")",
"{",
"fclose",
"(",
"$",
"stream",
")",
";",
"}",
"}"
] | Save a DOM into a given file as HTML5.
@param mixed $dom
The DOM to be serialized.
@param string $file
The filename to be written.
@param array $options
Configuration options when serializing the DOM. These include:
- encode_entities: Text written to the output is escaped by default and not all
entities are encoded. If this is set to true all entities will be encoded.
Defaults to false. | [
"Save",
"a",
"DOM",
"into",
"a",
"given",
"file",
"as",
"HTML5",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L267-L284 |
PHPPowertools/HTML5 | src/PowerTools/HTML5.php | HTML5.saveHTML | public function saveHTML($dom, $options = array()) {
$stream = fopen('php://temp', 'w');
$this->save($dom, $stream, array_merge($this->getOptions(), $options));
return stream_get_contents($stream, - 1, 0);
} | php | public function saveHTML($dom, $options = array()) {
$stream = fopen('php://temp', 'w');
$this->save($dom, $stream, array_merge($this->getOptions(), $options));
return stream_get_contents($stream, - 1, 0);
} | [
"public",
"function",
"saveHTML",
"(",
"$",
"dom",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"stream",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'w'",
")",
";",
"$",
"this",
"->",
"save",
"(",
"$",
"dom",
",",
"$",
"stream",
",",
"array_merge",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
",",
"$",
"options",
")",
")",
";",
"return",
"stream_get_contents",
"(",
"$",
"stream",
",",
"-",
"1",
",",
"0",
")",
";",
"}"
] | Convert a DOM into an HTML5 string.
@param mixed $dom
The DOM to be serialized.
@param array $options
Configuration options when serializing the DOM. These include:
- encode_entities: Text written to the output is escaped by default and not all
entities are encoded. If this is set to true all entities will be encoded.
Defaults to false.
@return string A HTML5 documented generated from the DOM. | [
"Convert",
"a",
"DOM",
"into",
"an",
"HTML5",
"string",
"."
] | train | https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L299-L304 |
Erdiko/core | src/Logger.php | Logger.addRecord | public function addRecord($level, $message, array $context = array())
{
$message = (string) $message;
$logString=date('Y-m-d H:i:s')." ".$level.": ".$this->interpolate($message, $context).PHP_EOL;
$logFileName=$this->_logFiles["default"]; // If log key is null use the default log file
return $this->write($logString, $logFileName, null, "a");
} | php | public function addRecord($level, $message, array $context = array())
{
$message = (string) $message;
$logString=date('Y-m-d H:i:s')." ".$level.": ".$this->interpolate($message, $context).PHP_EOL;
$logFileName=$this->_logFiles["default"]; // If log key is null use the default log file
return $this->write($logString, $logFileName, null, "a");
} | [
"public",
"function",
"addRecord",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"message",
"=",
"(",
"string",
")",
"$",
"message",
";",
"$",
"logString",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
")",
".",
"\" \"",
".",
"$",
"level",
".",
"\": \"",
".",
"$",
"this",
"->",
"interpolate",
"(",
"$",
"message",
",",
"$",
"context",
")",
".",
"PHP_EOL",
";",
"$",
"logFileName",
"=",
"$",
"this",
"->",
"_logFiles",
"[",
"\"default\"",
"]",
";",
"// If log key is null use the default log file",
"return",
"$",
"this",
"->",
"write",
"(",
"$",
"logString",
",",
"$",
"logFileName",
",",
"null",
",",
"\"a\"",
")",
";",
"}"
] | Add Record
@param string $level
@param string or an object with a __toString() method$ message
@param array $context
@return bool | [
"Add",
"Record"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L97-L104 |
Erdiko/core | src/Logger.php | Logger.interpolate | function interpolate($message, array $context = array())
{
// build a replacement array with braces around the context keys
$replace = array();
foreach ($context as $key => $val) {
if ($key == "exception" && $val instanceof \Exception) {
$replace['{' . $key . '}'] = $val->getMessage();
} else {
$replace['{' . $key . '}'] = $val;
}
}
// interpolate replacement values into the message and return
return strtr($message, $replace);
} | php | function interpolate($message, array $context = array())
{
// build a replacement array with braces around the context keys
$replace = array();
foreach ($context as $key => $val) {
if ($key == "exception" && $val instanceof \Exception) {
$replace['{' . $key . '}'] = $val->getMessage();
} else {
$replace['{' . $key . '}'] = $val;
}
}
// interpolate replacement values into the message and return
return strtr($message, $replace);
} | [
"function",
"interpolate",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"// build a replacement array with braces around the context keys",
"$",
"replace",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"context",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"\"exception\"",
"&&",
"$",
"val",
"instanceof",
"\\",
"Exception",
")",
"{",
"$",
"replace",
"[",
"'{'",
".",
"$",
"key",
".",
"'}'",
"]",
"=",
"$",
"val",
"->",
"getMessage",
"(",
")",
";",
"}",
"else",
"{",
"$",
"replace",
"[",
"'{'",
".",
"$",
"key",
".",
"'}'",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"// interpolate replacement values into the message and return",
"return",
"strtr",
"(",
"$",
"message",
",",
"$",
"replace",
")",
";",
"}"
] | Implementation of Placeholder Interpolation
The message MAY contain placeholders which implementors MAY replace with values from the context array.
Placeholder names MUST correspond to keys in the context array.
@param string $message or an object with a __toString() method
@param array $context replacement values for placeholders
@return bool | [
"Implementation",
"of",
"Placeholder",
"Interpolation",
"The",
"message",
"MAY",
"contain",
"placeholders",
"which",
"implementors",
"MAY",
"replace",
"with",
"values",
"from",
"the",
"context",
"array",
".",
"Placeholder",
"names",
"MUST",
"correspond",
"to",
"keys",
"in",
"the",
"context",
"array",
"."
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L115-L129 |
Erdiko/core | src/Logger.php | Logger.addLogFile | public function addLogFile($key, $logFileName)
{
$arrayKey=strtolower($key);
return $this->_logFiles[$arrayKey] = $logFileName;
} | php | public function addLogFile($key, $logFileName)
{
$arrayKey=strtolower($key);
return $this->_logFiles[$arrayKey] = $logFileName;
} | [
"public",
"function",
"addLogFile",
"(",
"$",
"key",
",",
"$",
"logFileName",
")",
"{",
"$",
"arrayKey",
"=",
"strtolower",
"(",
"$",
"key",
")",
";",
"return",
"$",
"this",
"->",
"_logFiles",
"[",
"$",
"arrayKey",
"]",
"=",
"$",
"logFileName",
";",
"}"
] | Add log file
Valid if multiple log files exist
@param mixed $key
@param string $logFileName
@return bool | [
"Add",
"log",
"file",
"Valid",
"if",
"multiple",
"log",
"files",
"exist"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L139-L143 |
Erdiko/core | src/Logger.php | Logger.clearLog | public function clearLog($logKey = null)
{
$ret=true;
if ($logKey==null) {
foreach ($this->_logFiles as $key => $logFile) {
$ret = $ret && $this->write("", $logFile);
}
return $ret;
} else {
$arrayKey=strtolower($logKey);
if (isset($this->_logFiles[$arrayKey])) {
return $this->write("", $this->_logFiles[$arrayKey]);
} else {
return 0;
}
}
} | php | public function clearLog($logKey = null)
{
$ret=true;
if ($logKey==null) {
foreach ($this->_logFiles as $key => $logFile) {
$ret = $ret && $this->write("", $logFile);
}
return $ret;
} else {
$arrayKey=strtolower($logKey);
if (isset($this->_logFiles[$arrayKey])) {
return $this->write("", $this->_logFiles[$arrayKey]);
} else {
return 0;
}
}
} | [
"public",
"function",
"clearLog",
"(",
"$",
"logKey",
"=",
"null",
")",
"{",
"$",
"ret",
"=",
"true",
";",
"if",
"(",
"$",
"logKey",
"==",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_logFiles",
"as",
"$",
"key",
"=>",
"$",
"logFile",
")",
"{",
"$",
"ret",
"=",
"$",
"ret",
"&&",
"$",
"this",
"->",
"write",
"(",
"\"\"",
",",
"$",
"logFile",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}",
"else",
"{",
"$",
"arrayKey",
"=",
"strtolower",
"(",
"$",
"logKey",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_logFiles",
"[",
"$",
"arrayKey",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"write",
"(",
"\"\"",
",",
"$",
"this",
"->",
"_logFiles",
"[",
"$",
"arrayKey",
"]",
")",
";",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"}",
"}"
] | Clear Log
@param string $logKey
@return bool | [
"Clear",
"Log"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L164-L180 |
Erdiko/core | src/Logger.php | Logger.emergency | public function emergency($message, array $context = array())
{
// TODO: Implement emergency() method.
return $this->addRecord(\Psr\Log\LogLevel::EMERGENCY, $message, $context);
} | php | public function emergency($message, array $context = array())
{
// TODO: Implement emergency() method.
return $this->addRecord(\Psr\Log\LogLevel::EMERGENCY, $message, $context);
} | [
"public",
"function",
"emergency",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"// TODO: Implement emergency() method.",
"return",
"$",
"this",
"->",
"addRecord",
"(",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"EMERGENCY",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | System is unusable.
@param string $message
@param array $context
@return null | [
"System",
"is",
"unusable",
"."
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L195-L199 |
Erdiko/core | src/Logger.php | Logger.alert | public function alert($message, array $context = array())
{
// TODO: Implement alert() method.
return $this->addRecord(\Psr\Log\LogLevel::ALERT, $message, $context);
} | php | public function alert($message, array $context = array())
{
// TODO: Implement alert() method.
return $this->addRecord(\Psr\Log\LogLevel::ALERT, $message, $context);
} | [
"public",
"function",
"alert",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"// TODO: Implement alert() method.",
"return",
"$",
"this",
"->",
"addRecord",
"(",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"ALERT",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Action must be taken immediately.
Example: Entire website down, database unavailable, etc. This should
trigger the SMS alerts and wake you up.
@param string $message
@param array $context
@return null | [
"Action",
"must",
"be",
"taken",
"immediately",
"."
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L212-L216 |
Erdiko/core | src/Logger.php | Logger.critical | public function critical($message, array $context = array())
{
// TODO: Implement critical() method.
return $this->addRecord(\Psr\Log\LogLevel::CRITICAL, $message, $context);
} | php | public function critical($message, array $context = array())
{
// TODO: Implement critical() method.
return $this->addRecord(\Psr\Log\LogLevel::CRITICAL, $message, $context);
} | [
"public",
"function",
"critical",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"// TODO: Implement critical() method.",
"return",
"$",
"this",
"->",
"addRecord",
"(",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"CRITICAL",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Critical conditions.
Example: Application component unavailable, unexpected exception.
@param string $message
@param array $context
@return null | [
"Critical",
"conditions",
"."
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L228-L232 |
Erdiko/core | src/Logger.php | Logger.notice | public function notice($message, array $context = array())
{
// TODO: Implement notice() method.
return $this->addRecord(\Psr\Log\LogLevel::NOTICE, $message, $context);
} | php | public function notice($message, array $context = array())
{
// TODO: Implement notice() method.
return $this->addRecord(\Psr\Log\LogLevel::NOTICE, $message, $context);
} | [
"public",
"function",
"notice",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"// TODO: Implement notice() method.",
"return",
"$",
"this",
"->",
"addRecord",
"(",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"NOTICE",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Normal but significant events.
@param string $message
@param array $context
@return null | [
"Normal",
"but",
"significant",
"events",
"."
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L274-L278 |
Erdiko/core | src/Logger.php | Logger.info | public function info($message, array $context = array())
{
// TODO: Implement info() method.
return $this->addRecord(\Psr\Log\LogLevel::INFO, $message, $context);
} | php | public function info($message, array $context = array())
{
// TODO: Implement info() method.
return $this->addRecord(\Psr\Log\LogLevel::INFO, $message, $context);
} | [
"public",
"function",
"info",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"// TODO: Implement info() method.",
"return",
"$",
"this",
"->",
"addRecord",
"(",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"INFO",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Interesting events.
Example: User logs in, SQL logs.
@param string $message
@param array $context
@return null | [
"Interesting",
"events",
"."
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L290-L294 |
Erdiko/core | src/Logger.php | Logger.debug | public function debug($message, array $context = array())
{
// TODO: Implement debug() method.
return $this->addRecord(\Psr\Log\LogLevel::DEBUG, $message, $context);
} | php | public function debug($message, array $context = array())
{
// TODO: Implement debug() method.
return $this->addRecord(\Psr\Log\LogLevel::DEBUG, $message, $context);
} | [
"public",
"function",
"debug",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"// TODO: Implement debug() method.",
"return",
"$",
"this",
"->",
"addRecord",
"(",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"DEBUG",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Detailed debug information.
@param string $message
@param array $context
@return null | [
"Detailed",
"debug",
"information",
"."
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L304-L308 |
zhouyl/mellivora | Mellivora/Application/App.php | App.registerFacades | protected function registerFacades()
{
$container = $this->getContainer();
if ($container->has('facades')) {
foreach ($container->get('facades') as $alias => $abstract) {
class_alias($abstract, $alias);
}
}
} | php | protected function registerFacades()
{
$container = $this->getContainer();
if ($container->has('facades')) {
foreach ($container->get('facades') as $alias => $abstract) {
class_alias($abstract, $alias);
}
}
} | [
"protected",
"function",
"registerFacades",
"(",
")",
"{",
"$",
"container",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
";",
"if",
"(",
"$",
"container",
"->",
"has",
"(",
"'facades'",
")",
")",
"{",
"foreach",
"(",
"$",
"container",
"->",
"get",
"(",
"'facades'",
")",
"as",
"$",
"alias",
"=>",
"$",
"abstract",
")",
"{",
"class_alias",
"(",
"$",
"abstract",
",",
"$",
"alias",
")",
";",
"}",
"}",
"}"
] | 注册类别名 | [
"注册类别名"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Application/App.php#L52-L61 |
zhouyl/mellivora | Mellivora/Application/App.php | App.registerProviders | protected function registerProviders()
{
$container = $this->getContainer();
if ($container->has('providers')) {
foreach ($container->get('providers') as $class) {
if (!is_subclass_of($class, ServiceProvider::class)) {
throw new UnexpectedValueException(
$class . ' must return instance of ' . ServiceProvider::class
);
}
(new $class($this))->register();
}
}
} | php | protected function registerProviders()
{
$container = $this->getContainer();
if ($container->has('providers')) {
foreach ($container->get('providers') as $class) {
if (!is_subclass_of($class, ServiceProvider::class)) {
throw new UnexpectedValueException(
$class . ' must return instance of ' . ServiceProvider::class
);
}
(new $class($this))->register();
}
}
} | [
"protected",
"function",
"registerProviders",
"(",
")",
"{",
"$",
"container",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
";",
"if",
"(",
"$",
"container",
"->",
"has",
"(",
"'providers'",
")",
")",
"{",
"foreach",
"(",
"$",
"container",
"->",
"get",
"(",
"'providers'",
")",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"class",
",",
"ServiceProvider",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"$",
"class",
".",
"' must return instance of '",
".",
"ServiceProvider",
"::",
"class",
")",
";",
"}",
"(",
"new",
"$",
"class",
"(",
"$",
"this",
")",
")",
"->",
"register",
"(",
")",
";",
"}",
"}",
"}"
] | 注册 Service Providers | [
"注册",
"Service",
"Providers"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Application/App.php#L66-L81 |
zhouyl/mellivora | Mellivora/Application/App.php | App.refreshContainer | protected function refreshContainer()
{
$container = $this->getContainer();
$this->add(function ($request, $response, $next) use ($container) {
$container['request'] = $request;
$container['response'] = $response;
return $next($request, $response);
});
} | php | protected function refreshContainer()
{
$container = $this->getContainer();
$this->add(function ($request, $response, $next) use ($container) {
$container['request'] = $request;
$container['response'] = $response;
return $next($request, $response);
});
} | [
"protected",
"function",
"refreshContainer",
"(",
")",
"{",
"$",
"container",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
";",
"$",
"this",
"->",
"add",
"(",
"function",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"next",
")",
"use",
"(",
"$",
"container",
")",
"{",
"$",
"container",
"[",
"'request'",
"]",
"=",
"$",
"request",
";",
"$",
"container",
"[",
"'response'",
"]",
"=",
"$",
"response",
";",
"return",
"$",
"next",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
")",
";",
"}"
] | 刷新 container 中注册的 request/response 组件 | [
"刷新",
"container",
"中注册的",
"request",
"/",
"response",
"组件"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Application/App.php#L86-L96 |
zhouyl/mellivora | Mellivora/Application/App.php | App.registerDefaultArguments | protected function registerDefaultArguments()
{
$container = $this->getContainer();
$this->add(function ($request, $response, $next) use ($container) {
$route = $request->getAttribute('route');
$route
->setArgument(
'namespace',
$route->getArgument('namespace', 'App\Controllers')
)
->setArgument(
'module',
Str::camel($route->getArgument('module', ''))
)
->setArgument(
'controller',
Str::camel($route->getArgument('controller', 'index'))
)
->setArgument(
'action',
Str::camel($route->getArgument('action', 'index'))
);
return $next($request, $response);
});
} | php | protected function registerDefaultArguments()
{
$container = $this->getContainer();
$this->add(function ($request, $response, $next) use ($container) {
$route = $request->getAttribute('route');
$route
->setArgument(
'namespace',
$route->getArgument('namespace', 'App\Controllers')
)
->setArgument(
'module',
Str::camel($route->getArgument('module', ''))
)
->setArgument(
'controller',
Str::camel($route->getArgument('controller', 'index'))
)
->setArgument(
'action',
Str::camel($route->getArgument('action', 'index'))
);
return $next($request, $response);
});
} | [
"protected",
"function",
"registerDefaultArguments",
"(",
")",
"{",
"$",
"container",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
";",
"$",
"this",
"->",
"add",
"(",
"function",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"next",
")",
"use",
"(",
"$",
"container",
")",
"{",
"$",
"route",
"=",
"$",
"request",
"->",
"getAttribute",
"(",
"'route'",
")",
";",
"$",
"route",
"->",
"setArgument",
"(",
"'namespace'",
",",
"$",
"route",
"->",
"getArgument",
"(",
"'namespace'",
",",
"'App\\Controllers'",
")",
")",
"->",
"setArgument",
"(",
"'module'",
",",
"Str",
"::",
"camel",
"(",
"$",
"route",
"->",
"getArgument",
"(",
"'module'",
",",
"''",
")",
")",
")",
"->",
"setArgument",
"(",
"'controller'",
",",
"Str",
"::",
"camel",
"(",
"$",
"route",
"->",
"getArgument",
"(",
"'controller'",
",",
"'index'",
")",
")",
")",
"->",
"setArgument",
"(",
"'action'",
",",
"Str",
"::",
"camel",
"(",
"$",
"route",
"->",
"getArgument",
"(",
"'action'",
",",
"'index'",
")",
")",
")",
";",
"return",
"$",
"next",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
")",
";",
"}"
] | 注册默认路由参数 | [
"注册默认路由参数"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Application/App.php#L101-L128 |
zhouyl/mellivora | Mellivora/Translation/Translator.php | Translator.addPath | public function addPath($basepath)
{
foreach (new DirectoryIterator($basepath) as $dir) {
if ($dir->isDir() && !$dir->isDot()) {
$lang = $dir->getBasename();
$path = $dir->getPathname();
if (!isset($this->paths[$lang])) {
$this->paths[$lang] = [];
}
if (!in_array($path, $this->paths[$lang])) {
$this->paths[$lang] = $path;
}
// 新增加的目录,需要重新扫描已加载的语言包
$this->load($lang, $path, [$lang] + $this->packages);
}
}
return $this;
} | php | public function addPath($basepath)
{
foreach (new DirectoryIterator($basepath) as $dir) {
if ($dir->isDir() && !$dir->isDot()) {
$lang = $dir->getBasename();
$path = $dir->getPathname();
if (!isset($this->paths[$lang])) {
$this->paths[$lang] = [];
}
if (!in_array($path, $this->paths[$lang])) {
$this->paths[$lang] = $path;
}
// 新增加的目录,需要重新扫描已加载的语言包
$this->load($lang, $path, [$lang] + $this->packages);
}
}
return $this;
} | [
"public",
"function",
"addPath",
"(",
"$",
"basepath",
")",
"{",
"foreach",
"(",
"new",
"DirectoryIterator",
"(",
"$",
"basepath",
")",
"as",
"$",
"dir",
")",
"{",
"if",
"(",
"$",
"dir",
"->",
"isDir",
"(",
")",
"&&",
"!",
"$",
"dir",
"->",
"isDot",
"(",
")",
")",
"{",
"$",
"lang",
"=",
"$",
"dir",
"->",
"getBasename",
"(",
")",
";",
"$",
"path",
"=",
"$",
"dir",
"->",
"getPathname",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"paths",
"[",
"$",
"lang",
"]",
")",
")",
"{",
"$",
"this",
"->",
"paths",
"[",
"$",
"lang",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"paths",
"[",
"$",
"lang",
"]",
")",
")",
"{",
"$",
"this",
"->",
"paths",
"[",
"$",
"lang",
"]",
"=",
"$",
"path",
";",
"}",
"// 新增加的目录,需要重新扫描已加载的语言包",
"$",
"this",
"->",
"load",
"(",
"$",
"lang",
",",
"$",
"path",
",",
"[",
"$",
"lang",
"]",
"+",
"$",
"this",
"->",
"packages",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | 新增语言包加载路径
@param string $basepath
@return \Mellivora\Translation\Translator | [
"新增语言包加载路径"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Translation/Translator.php#L68-L89 |
zhouyl/mellivora | Mellivora/Translation/Translator.php | Translator.alias | public function alias($lang, $aliases)
{
$lang = strtolower($lang);
if (!is_array($aliases)) {
$aliases = [$aliases];
}
$aliases = array_map('strtolower', $aliases);
$this->aliases[$lang] = array_unique(
array_merge(Arr::get($this->aliases, $lang, []), $aliases)
);
return $this;
} | php | public function alias($lang, $aliases)
{
$lang = strtolower($lang);
if (!is_array($aliases)) {
$aliases = [$aliases];
}
$aliases = array_map('strtolower', $aliases);
$this->aliases[$lang] = array_unique(
array_merge(Arr::get($this->aliases, $lang, []), $aliases)
);
return $this;
} | [
"public",
"function",
"alias",
"(",
"$",
"lang",
",",
"$",
"aliases",
")",
"{",
"$",
"lang",
"=",
"strtolower",
"(",
"$",
"lang",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"aliases",
")",
")",
"{",
"$",
"aliases",
"=",
"[",
"$",
"aliases",
"]",
";",
"}",
"$",
"aliases",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"aliases",
")",
";",
"$",
"this",
"->",
"aliases",
"[",
"$",
"lang",
"]",
"=",
"array_unique",
"(",
"array_merge",
"(",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"aliases",
",",
"$",
"lang",
",",
"[",
"]",
")",
",",
"$",
"aliases",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | 设定语言包别名
@param string $lang
@param array|string $aliases
@return \Mellivora\Translation\Translator | [
"设定语言包别名"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Translation/Translator.php#L99-L114 |
zhouyl/mellivora | Mellivora/Translation/Translator.php | Translator.lang | public function lang($alias)
{
$alias = Str::slug($alias);
foreach ($this->aliases as $lang => $aliases) {
if (in_array($alias, $aliases)) {
return $lang;
}
}
return $alias;
} | php | public function lang($alias)
{
$alias = Str::slug($alias);
foreach ($this->aliases as $lang => $aliases) {
if (in_array($alias, $aliases)) {
return $lang;
}
}
return $alias;
} | [
"public",
"function",
"lang",
"(",
"$",
"alias",
")",
"{",
"$",
"alias",
"=",
"Str",
"::",
"slug",
"(",
"$",
"alias",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"aliases",
"as",
"$",
"lang",
"=>",
"$",
"aliases",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"alias",
",",
"$",
"aliases",
")",
")",
"{",
"return",
"$",
"lang",
";",
"}",
"}",
"return",
"$",
"alias",
";",
"}"
] | 将别名转换为语言包名
@param string $alias
@return string | [
"将别名转换为语言包名"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Translation/Translator.php#L139-L150 |
zhouyl/mellivora | Mellivora/Translation/Translator.php | Translator.import | public function import($packages)
{
if (!is_array($packages)) {
$packages = func_get_args();
}
// 新增的语言包
$diff = array_diff($packages, $this->packages);
// 合并到已加载的语言包中
$this->packages = array_merge($this->packages, $diff);
// 载入新增的语言包
foreach ($this->paths as $lang => $path) {
$this->load($lang, $path, $diff);
}
return $this;
} | php | public function import($packages)
{
if (!is_array($packages)) {
$packages = func_get_args();
}
// 新增的语言包
$diff = array_diff($packages, $this->packages);
// 合并到已加载的语言包中
$this->packages = array_merge($this->packages, $diff);
// 载入新增的语言包
foreach ($this->paths as $lang => $path) {
$this->load($lang, $path, $diff);
}
return $this;
} | [
"public",
"function",
"import",
"(",
"$",
"packages",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"packages",
")",
")",
"{",
"$",
"packages",
"=",
"func_get_args",
"(",
")",
";",
"}",
"// 新增的语言包",
"$",
"diff",
"=",
"array_diff",
"(",
"$",
"packages",
",",
"$",
"this",
"->",
"packages",
")",
";",
"// 合并到已加载的语言包中",
"$",
"this",
"->",
"packages",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"packages",
",",
"$",
"diff",
")",
";",
"// 载入新增的语言包",
"foreach",
"(",
"$",
"this",
"->",
"paths",
"as",
"$",
"lang",
"=>",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"lang",
",",
"$",
"path",
",",
"$",
"diff",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | 加载语言包
@param array|string $packages
@return \Mellivora\Translation\Translator | [
"加载语言包"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Translation/Translator.php#L159-L177 |
zhouyl/mellivora | Mellivora/Translation/Translator.php | Translator.export | public function export($lang = null)
{
$lang = $lang ? $this->lang($lang) : $this->default;
if (!isset($this->imported[$lang])) {
return [];
}
return $this->imported[$lang];
} | php | public function export($lang = null)
{
$lang = $lang ? $this->lang($lang) : $this->default;
if (!isset($this->imported[$lang])) {
return [];
}
return $this->imported[$lang];
} | [
"public",
"function",
"export",
"(",
"$",
"lang",
"=",
"null",
")",
"{",
"$",
"lang",
"=",
"$",
"lang",
"?",
"$",
"this",
"->",
"lang",
"(",
"$",
"lang",
")",
":",
"$",
"this",
"->",
"default",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"imported",
"[",
"$",
"lang",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"imported",
"[",
"$",
"lang",
"]",
";",
"}"
] | 导出已加载的语言包数据
@param string $lang
@return array | [
"导出已加载的语言包数据"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Translation/Translator.php#L186-L195 |
zhouyl/mellivora | Mellivora/Translation/Translator.php | Translator.trans | public function trans($text, array $replace = null, $lang = null)
{
$lang = $lang ? $this->lang($lang) : $this->default;
if (isset($this->imported[$lang])) {
$text = Arr::get($this->imported[$lang], $text, $text);
}
return $replace ? strtr($text, $replace) : $text;
} | php | public function trans($text, array $replace = null, $lang = null)
{
$lang = $lang ? $this->lang($lang) : $this->default;
if (isset($this->imported[$lang])) {
$text = Arr::get($this->imported[$lang], $text, $text);
}
return $replace ? strtr($text, $replace) : $text;
} | [
"public",
"function",
"trans",
"(",
"$",
"text",
",",
"array",
"$",
"replace",
"=",
"null",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"$",
"lang",
"=",
"$",
"lang",
"?",
"$",
"this",
"->",
"lang",
"(",
"$",
"lang",
")",
":",
"$",
"this",
"->",
"default",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"imported",
"[",
"$",
"lang",
"]",
")",
")",
"{",
"$",
"text",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"imported",
"[",
"$",
"lang",
"]",
",",
"$",
"text",
",",
"$",
"text",
")",
";",
"}",
"return",
"$",
"replace",
"?",
"strtr",
"(",
"$",
"text",
",",
"$",
"replace",
")",
":",
"$",
"text",
";",
"}"
] | 执行翻译
@param string $text
@param array $replace
@param string $lang
@return string | [
"执行翻译"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Translation/Translator.php#L206-L215 |
zhouyl/mellivora | Mellivora/Translation/Translator.php | Translator.reverse | public function reverse($text, $from = null, $to = null)
{
$from = $from ? $this->lang($from) : $this->default;
$to = $to ? $this->lang($to) : null;
if ($from === $to) {
return $text;
}
if (isset($this->imported[$from])) {
$text = Arr::get(array_flip($this->imported[$from]), $text, $text);
}
if ($to === null || $to = 'en-us') {
return $text;
}
return $this->trans($text, null, $to);
} | php | public function reverse($text, $from = null, $to = null)
{
$from = $from ? $this->lang($from) : $this->default;
$to = $to ? $this->lang($to) : null;
if ($from === $to) {
return $text;
}
if (isset($this->imported[$from])) {
$text = Arr::get(array_flip($this->imported[$from]), $text, $text);
}
if ($to === null || $to = 'en-us') {
return $text;
}
return $this->trans($text, null, $to);
} | [
"public",
"function",
"reverse",
"(",
"$",
"text",
",",
"$",
"from",
"=",
"null",
",",
"$",
"to",
"=",
"null",
")",
"{",
"$",
"from",
"=",
"$",
"from",
"?",
"$",
"this",
"->",
"lang",
"(",
"$",
"from",
")",
":",
"$",
"this",
"->",
"default",
";",
"$",
"to",
"=",
"$",
"to",
"?",
"$",
"this",
"->",
"lang",
"(",
"$",
"to",
")",
":",
"null",
";",
"if",
"(",
"$",
"from",
"===",
"$",
"to",
")",
"{",
"return",
"$",
"text",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"imported",
"[",
"$",
"from",
"]",
")",
")",
"{",
"$",
"text",
"=",
"Arr",
"::",
"get",
"(",
"array_flip",
"(",
"$",
"this",
"->",
"imported",
"[",
"$",
"from",
"]",
")",
",",
"$",
"text",
",",
"$",
"text",
")",
";",
"}",
"if",
"(",
"$",
"to",
"===",
"null",
"||",
"$",
"to",
"=",
"'en-us'",
")",
"{",
"return",
"$",
"text",
";",
"}",
"return",
"$",
"this",
"->",
"trans",
"(",
"$",
"text",
",",
"null",
",",
"$",
"to",
")",
";",
"}"
] | 反向翻译
@param string $text
@param string $from
@param string $to
@return string | [
"反向翻译"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Translation/Translator.php#L226-L244 |
zhouyl/mellivora | Mellivora/Translation/Translator.php | Translator.load | protected function load($lang, $path, array $packages)
{
// 扫描目录并加载语言包
foreach ($packages as $package) {
$file = sprintf('%s/%s.php', $path, str_replace('.', '/', $package));
// 语言文件不存在
if (!is_file($file)) {
continue;
}
// 无效语言包
$return = include $file;
if (!is_array($return)) {
continue;
}
foreach ($return as $key => $value) {
$this->imported[$lang][$key] = $value;
}
}
} | php | protected function load($lang, $path, array $packages)
{
// 扫描目录并加载语言包
foreach ($packages as $package) {
$file = sprintf('%s/%s.php', $path, str_replace('.', '/', $package));
// 语言文件不存在
if (!is_file($file)) {
continue;
}
// 无效语言包
$return = include $file;
if (!is_array($return)) {
continue;
}
foreach ($return as $key => $value) {
$this->imported[$lang][$key] = $value;
}
}
} | [
"protected",
"function",
"load",
"(",
"$",
"lang",
",",
"$",
"path",
",",
"array",
"$",
"packages",
")",
"{",
"// 扫描目录并加载语言包",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"package",
")",
"{",
"$",
"file",
"=",
"sprintf",
"(",
"'%s/%s.php'",
",",
"$",
"path",
",",
"str_replace",
"(",
"'.'",
",",
"'/'",
",",
"$",
"package",
")",
")",
";",
"// 语言文件不存在",
"if",
"(",
"!",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"continue",
";",
"}",
"// 无效语言包",
"$",
"return",
"=",
"include",
"$",
"file",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"return",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"return",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"imported",
"[",
"$",
"lang",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | 加载语言包
@param string $lang
@param string $path
@param array $packages | [
"加载语言包"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Translation/Translator.php#L253-L274 |
zhengb302/LumengPHP-Db | src/LumengPHP/Db/Misc/FieldHelper.php | FieldHelper.quoteField | public static function quoteField($field) {
$trimmedField = trim($field);
if ($trimmedField == '*') {
return $trimmedField;
}
if (strpos($trimmedField, ' ') !== false) {
return $trimmedField;
}
return strpos($trimmedField, '.') !== false ?
$trimmedField : "`{$trimmedField}`";
} | php | public static function quoteField($field) {
$trimmedField = trim($field);
if ($trimmedField == '*') {
return $trimmedField;
}
if (strpos($trimmedField, ' ') !== false) {
return $trimmedField;
}
return strpos($trimmedField, '.') !== false ?
$trimmedField : "`{$trimmedField}`";
} | [
"public",
"static",
"function",
"quoteField",
"(",
"$",
"field",
")",
"{",
"$",
"trimmedField",
"=",
"trim",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"trimmedField",
"==",
"'*'",
")",
"{",
"return",
"$",
"trimmedField",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"trimmedField",
",",
"' '",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"trimmedField",
";",
"}",
"return",
"strpos",
"(",
"$",
"trimmedField",
",",
"'.'",
")",
"!==",
"false",
"?",
"$",
"trimmedField",
":",
"\"`{$trimmedField}`\"",
";",
"}"
] | 给单个字段打引号
@param string $field 字段名
@return string 如果字段带英文句点,则不打引号直接返回原值,
否则返回打引号之后的字段名 | [
"给单个字段打引号"
] | train | https://github.com/zhengb302/LumengPHP-Db/blob/47384aa37bc26352efb7ecda3c139cf8cb03db83/src/LumengPHP/Db/Misc/FieldHelper.php#L18-L30 |
zhengb302/LumengPHP-Db | src/LumengPHP/Db/Misc/FieldHelper.php | FieldHelper.quoteFields | public static function quoteFields($fields) {
$fieldArr = is_array($fields) ? $fields : explode(',', $fields);
$resultFieldArr = array();
foreach ($fieldArr as $field) {
$resultFieldArr[] = self::quoteField($field);
}
return implode(', ', $resultFieldArr);
} | php | public static function quoteFields($fields) {
$fieldArr = is_array($fields) ? $fields : explode(',', $fields);
$resultFieldArr = array();
foreach ($fieldArr as $field) {
$resultFieldArr[] = self::quoteField($field);
}
return implode(', ', $resultFieldArr);
} | [
"public",
"static",
"function",
"quoteFields",
"(",
"$",
"fields",
")",
"{",
"$",
"fieldArr",
"=",
"is_array",
"(",
"$",
"fields",
")",
"?",
"$",
"fields",
":",
"explode",
"(",
"','",
",",
"$",
"fields",
")",
";",
"$",
"resultFieldArr",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fieldArr",
"as",
"$",
"field",
")",
"{",
"$",
"resultFieldArr",
"[",
"]",
"=",
"self",
"::",
"quoteField",
"(",
"$",
"field",
")",
";",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"resultFieldArr",
")",
";",
"}"
] | 给多个字段打引号
@param string|array $fields 以英文逗号分隔的字段列表或字段数组
@return string 以英文逗号分割的已打过引号的字段列表 | [
"给多个字段打引号"
] | train | https://github.com/zhengb302/LumengPHP-Db/blob/47384aa37bc26352efb7ecda3c139cf8cb03db83/src/LumengPHP/Db/Misc/FieldHelper.php#L37-L45 |
grozzzny/catalog | models/Base.php | Base.beforeSave | public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if(!$insert){
foreach ($this->getAttributes() as $attribute => $value){
if($this->hasValidator(['image', 'file'], $attribute)) {
if($this->$attribute !== $this->oldAttributes[$attribute]){
@unlink(Yii::getAlias('@webroot') . $this->oldAttributes[$attribute]);
}
}
}
}
return true;
} else {
return false;
}
} | php | public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if(!$insert){
foreach ($this->getAttributes() as $attribute => $value){
if($this->hasValidator(['image', 'file'], $attribute)) {
if($this->$attribute !== $this->oldAttributes[$attribute]){
@unlink(Yii::getAlias('@webroot') . $this->oldAttributes[$attribute]);
}
}
}
}
return true;
} else {
return false;
}
} | [
"public",
"function",
"beforeSave",
"(",
"$",
"insert",
")",
"{",
"if",
"(",
"parent",
"::",
"beforeSave",
"(",
"$",
"insert",
")",
")",
"{",
"if",
"(",
"!",
"$",
"insert",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasValidator",
"(",
"[",
"'image'",
",",
"'file'",
"]",
",",
"$",
"attribute",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"$",
"attribute",
"!==",
"$",
"this",
"->",
"oldAttributes",
"[",
"$",
"attribute",
"]",
")",
"{",
"@",
"unlink",
"(",
"Yii",
"::",
"getAlias",
"(",
"'@webroot'",
")",
".",
"$",
"this",
"->",
"oldAttributes",
"[",
"$",
"attribute",
"]",
")",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Используется при отчистке ранее загруженных файлов
@param bool $insert
@return bool | [
"Используется",
"при",
"отчистке",
"ранее",
"загруженных",
"файлов"
] | train | https://github.com/grozzzny/catalog/blob/ff1cac10a5f3a89f3ef2767f9ede6b2d74e1849a/models/Base.php#L88-L104 |
grozzzny/catalog | models/Base.php | Base.afterDelete | public function afterDelete()
{
parent::afterDelete();
foreach ($this->getAttributes() as $attribute => $value){
if($this->hasValidator(['image', 'file'], $attribute)) {
@unlink(Yii::getAlias('@webroot').$this->$attribute);
}
}
} | php | public function afterDelete()
{
parent::afterDelete();
foreach ($this->getAttributes() as $attribute => $value){
if($this->hasValidator(['image', 'file'], $attribute)) {
@unlink(Yii::getAlias('@webroot').$this->$attribute);
}
}
} | [
"public",
"function",
"afterDelete",
"(",
")",
"{",
"parent",
"::",
"afterDelete",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasValidator",
"(",
"[",
"'image'",
",",
"'file'",
"]",
",",
"$",
"attribute",
")",
")",
"{",
"@",
"unlink",
"(",
"Yii",
"::",
"getAlias",
"(",
"'@webroot'",
")",
".",
"$",
"this",
"->",
"$",
"attribute",
")",
";",
"}",
"}",
"}"
] | Используется при отчистке файлов | [
"Используется",
"при",
"отчистке",
"файлов"
] | train | https://github.com/grozzzny/catalog/blob/ff1cac10a5f3a89f3ef2767f9ede6b2d74e1849a/models/Base.php#L109-L118 |
mothership-ec/composer | src/Composer/Command/HomeCommand.php | HomeCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$repos = $this->initializeRepos();
$return = 0;
foreach ($input->getArgument('packages') as $packageName) {
foreach ($repos as $repo) {
$package = $this->getPackage($repo, $packageName);
if ($package instanceof CompletePackageInterface) {
break;
}
}
$package = $this->getPackage($repo, $packageName);
if (!$package instanceof CompletePackageInterface) {
$return = 1;
$this->getIO()->writeError('<warning>Package '.$packageName.' not found</warning>');
continue;
}
$support = $package->getSupport();
$url = isset($support['source']) ? $support['source'] : $package->getSourceUrl();
if (!$url || $input->getOption('homepage')) {
$url = $package->getHomepage();
}
if (!filter_var($url, FILTER_VALIDATE_URL)) {
$return = 1;
$this->getIO()->writeError('<warning>'.($input->getOption('homepage') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL').' for '.$packageName.'</warning>');
continue;
}
if ($input->getOption('show')) {
$this->getIO()->write(sprintf('<info>%s</info>', $url));
} else {
$this->openBrowser($url);
}
}
return $return;
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$repos = $this->initializeRepos();
$return = 0;
foreach ($input->getArgument('packages') as $packageName) {
foreach ($repos as $repo) {
$package = $this->getPackage($repo, $packageName);
if ($package instanceof CompletePackageInterface) {
break;
}
}
$package = $this->getPackage($repo, $packageName);
if (!$package instanceof CompletePackageInterface) {
$return = 1;
$this->getIO()->writeError('<warning>Package '.$packageName.' not found</warning>');
continue;
}
$support = $package->getSupport();
$url = isset($support['source']) ? $support['source'] : $package->getSourceUrl();
if (!$url || $input->getOption('homepage')) {
$url = $package->getHomepage();
}
if (!filter_var($url, FILTER_VALIDATE_URL)) {
$return = 1;
$this->getIO()->writeError('<warning>'.($input->getOption('homepage') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL').' for '.$packageName.'</warning>');
continue;
}
if ($input->getOption('show')) {
$this->getIO()->write(sprintf('<info>%s</info>', $url));
} else {
$this->openBrowser($url);
}
}
return $return;
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"repos",
"=",
"$",
"this",
"->",
"initializeRepos",
"(",
")",
";",
"$",
"return",
"=",
"0",
";",
"foreach",
"(",
"$",
"input",
"->",
"getArgument",
"(",
"'packages'",
")",
"as",
"$",
"packageName",
")",
"{",
"foreach",
"(",
"$",
"repos",
"as",
"$",
"repo",
")",
"{",
"$",
"package",
"=",
"$",
"this",
"->",
"getPackage",
"(",
"$",
"repo",
",",
"$",
"packageName",
")",
";",
"if",
"(",
"$",
"package",
"instanceof",
"CompletePackageInterface",
")",
"{",
"break",
";",
"}",
"}",
"$",
"package",
"=",
"$",
"this",
"->",
"getPackage",
"(",
"$",
"repo",
",",
"$",
"packageName",
")",
";",
"if",
"(",
"!",
"$",
"package",
"instanceof",
"CompletePackageInterface",
")",
"{",
"$",
"return",
"=",
"1",
";",
"$",
"this",
"->",
"getIO",
"(",
")",
"->",
"writeError",
"(",
"'<warning>Package '",
".",
"$",
"packageName",
".",
"' not found</warning>'",
")",
";",
"continue",
";",
"}",
"$",
"support",
"=",
"$",
"package",
"->",
"getSupport",
"(",
")",
";",
"$",
"url",
"=",
"isset",
"(",
"$",
"support",
"[",
"'source'",
"]",
")",
"?",
"$",
"support",
"[",
"'source'",
"]",
":",
"$",
"package",
"->",
"getSourceUrl",
"(",
")",
";",
"if",
"(",
"!",
"$",
"url",
"||",
"$",
"input",
"->",
"getOption",
"(",
"'homepage'",
")",
")",
"{",
"$",
"url",
"=",
"$",
"package",
"->",
"getHomepage",
"(",
")",
";",
"}",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"url",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"$",
"return",
"=",
"1",
";",
"$",
"this",
"->",
"getIO",
"(",
")",
"->",
"writeError",
"(",
"'<warning>'",
".",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'homepage'",
")",
"?",
"'Invalid or missing homepage'",
":",
"'Invalid or missing repository URL'",
")",
".",
"' for '",
".",
"$",
"packageName",
".",
"'</warning>'",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'show'",
")",
")",
"{",
"$",
"this",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"sprintf",
"(",
"'<info>%s</info>'",
",",
"$",
"url",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"openBrowser",
"(",
"$",
"url",
")",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Command/HomeCommand.php#L58-L100 |
mothership-ec/composer | src/Composer/Command/HomeCommand.php | HomeCommand.getPackage | protected function getPackage(RepositoryInterface $repos, $name)
{
$name = strtolower($name);
$pool = new Pool('dev');
$pool->addRepository($repos);
$matches = $pool->whatProvides($name);
foreach ($matches as $index => $package) {
// skip providers/replacers
if ($package->getName() !== $name) {
unset($matches[$index]);
continue;
}
return $package;
}
} | php | protected function getPackage(RepositoryInterface $repos, $name)
{
$name = strtolower($name);
$pool = new Pool('dev');
$pool->addRepository($repos);
$matches = $pool->whatProvides($name);
foreach ($matches as $index => $package) {
// skip providers/replacers
if ($package->getName() !== $name) {
unset($matches[$index]);
continue;
}
return $package;
}
} | [
"protected",
"function",
"getPackage",
"(",
"RepositoryInterface",
"$",
"repos",
",",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"$",
"pool",
"=",
"new",
"Pool",
"(",
"'dev'",
")",
";",
"$",
"pool",
"->",
"addRepository",
"(",
"$",
"repos",
")",
";",
"$",
"matches",
"=",
"$",
"pool",
"->",
"whatProvides",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"index",
"=>",
"$",
"package",
")",
"{",
"// skip providers/replacers",
"if",
"(",
"$",
"package",
"->",
"getName",
"(",
")",
"!==",
"$",
"name",
")",
"{",
"unset",
"(",
"$",
"matches",
"[",
"$",
"index",
"]",
")",
";",
"continue",
";",
"}",
"return",
"$",
"package",
";",
"}",
"}"
] | finds a package by name
@param RepositoryInterface $repos
@param string $name
@return CompletePackageInterface | [
"finds",
"a",
"package",
"by",
"name"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Command/HomeCommand.php#L109-L125 |
mothership-ec/composer | src/Composer/Command/HomeCommand.php | HomeCommand.openBrowser | private function openBrowser($url)
{
$url = ProcessExecutor::escape($url);
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
return passthru('start "web" explorer "' . $url . '"');
}
passthru('which xdg-open', $linux);
passthru('which open', $osx);
if (0 === $linux) {
passthru('xdg-open ' . $url);
} elseif (0 === $osx) {
passthru('open ' . $url);
} else {
$this->getIO()->writeError('no suitable browser opening command found, open yourself: ' . $url);
}
} | php | private function openBrowser($url)
{
$url = ProcessExecutor::escape($url);
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
return passthru('start "web" explorer "' . $url . '"');
}
passthru('which xdg-open', $linux);
passthru('which open', $osx);
if (0 === $linux) {
passthru('xdg-open ' . $url);
} elseif (0 === $osx) {
passthru('open ' . $url);
} else {
$this->getIO()->writeError('no suitable browser opening command found, open yourself: ' . $url);
}
} | [
"private",
"function",
"openBrowser",
"(",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"ProcessExecutor",
"::",
"escape",
"(",
"$",
"url",
")",
";",
"if",
"(",
"defined",
"(",
"'PHP_WINDOWS_VERSION_MAJOR'",
")",
")",
"{",
"return",
"passthru",
"(",
"'start \"web\" explorer \"'",
".",
"$",
"url",
".",
"'\"'",
")",
";",
"}",
"passthru",
"(",
"'which xdg-open'",
",",
"$",
"linux",
")",
";",
"passthru",
"(",
"'which open'",
",",
"$",
"osx",
")",
";",
"if",
"(",
"0",
"===",
"$",
"linux",
")",
"{",
"passthru",
"(",
"'xdg-open '",
".",
"$",
"url",
")",
";",
"}",
"elseif",
"(",
"0",
"===",
"$",
"osx",
")",
"{",
"passthru",
"(",
"'open '",
".",
"$",
"url",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getIO",
"(",
")",
"->",
"writeError",
"(",
"'no suitable browser opening command found, open yourself: '",
".",
"$",
"url",
")",
";",
"}",
"}"
] | opens a url in your system default browser
@param string $url | [
"opens",
"a",
"url",
"in",
"your",
"system",
"default",
"browser"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Command/HomeCommand.php#L132-L150 |
mothership-ec/composer | src/Composer/Command/HomeCommand.php | HomeCommand.initializeRepos | private function initializeRepos()
{
$composer = $this->getComposer(false);
if ($composer) {
return array(
$composer->getRepositoryManager()->getLocalRepository(),
new CompositeRepository($composer->getRepositoryManager()->getRepositories())
);
}
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
return array(new CompositeRepository($defaultRepos));
} | php | private function initializeRepos()
{
$composer = $this->getComposer(false);
if ($composer) {
return array(
$composer->getRepositoryManager()->getLocalRepository(),
new CompositeRepository($composer->getRepositoryManager()->getRepositories())
);
}
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
return array(new CompositeRepository($defaultRepos));
} | [
"private",
"function",
"initializeRepos",
"(",
")",
"{",
"$",
"composer",
"=",
"$",
"this",
"->",
"getComposer",
"(",
"false",
")",
";",
"if",
"(",
"$",
"composer",
")",
"{",
"return",
"array",
"(",
"$",
"composer",
"->",
"getRepositoryManager",
"(",
")",
"->",
"getLocalRepository",
"(",
")",
",",
"new",
"CompositeRepository",
"(",
"$",
"composer",
"->",
"getRepositoryManager",
"(",
")",
"->",
"getRepositories",
"(",
")",
")",
")",
";",
"}",
"$",
"defaultRepos",
"=",
"Factory",
"::",
"createDefaultRepositories",
"(",
"$",
"this",
"->",
"getIO",
"(",
")",
")",
";",
"return",
"array",
"(",
"new",
"CompositeRepository",
"(",
"$",
"defaultRepos",
")",
")",
";",
"}"
] | Initializes repositories
Returns an array of repos in order they should be checked in
@return RepositoryInterface[] | [
"Initializes",
"repositories"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Command/HomeCommand.php#L159-L173 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.when | public function when($value, $callback, $default = null)
{
$builder = $this;
if ($value) {
$builder = $callback($builder);
} elseif ($default) {
$builder = $default($builder);
}
return $builder;
} | php | public function when($value, $callback, $default = null)
{
$builder = $this;
if ($value) {
$builder = $callback($builder);
} elseif ($default) {
$builder = $default($builder);
}
return $builder;
} | [
"public",
"function",
"when",
"(",
"$",
"value",
",",
"$",
"callback",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"builder",
"=",
"$",
"this",
";",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"builder",
"=",
"$",
"callback",
"(",
"$",
"builder",
")",
";",
"}",
"elseif",
"(",
"$",
"default",
")",
"{",
"$",
"builder",
"=",
"$",
"default",
"(",
"$",
"builder",
")",
";",
"}",
"return",
"$",
"builder",
";",
"}"
] | Apply the callback's query changes if the given "value" is true.
@param bool $value
@param \Closure $callback
@param \Closure $default
@return $this | [
"Apply",
"the",
"callback",
"s",
"query",
"changes",
"if",
"the",
"given",
"value",
"is",
"true",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L170-L181 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.hydrate | public function hydrate(array $items)
{
$instance = $this->model->newInstance();
return $instance->newCollection(array_map(function ($item) use ($instance) {
return $instance->newFromBuilder($item);
}, $items));
} | php | public function hydrate(array $items)
{
$instance = $this->model->newInstance();
return $instance->newCollection(array_map(function ($item) use ($instance) {
return $instance->newFromBuilder($item);
}, $items));
} | [
"public",
"function",
"hydrate",
"(",
"array",
"$",
"items",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"model",
"->",
"newInstance",
"(",
")",
";",
"return",
"$",
"instance",
"->",
"newCollection",
"(",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"instance",
")",
"{",
"return",
"$",
"instance",
"->",
"newFromBuilder",
"(",
"$",
"item",
")",
";",
"}",
",",
"$",
"items",
")",
")",
";",
"}"
] | Create a collection of models from plain arrays.
@param array $items
@return \Mellivora\Database\Eloquent\Collection | [
"Create",
"a",
"collection",
"of",
"models",
"from",
"plain",
"arrays",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L247-L254 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.fromQuery | public function fromQuery($query, $bindings = [])
{
$instance = $this->model->newInstance();
return $this->hydrate(
$instance->getConnection()->select($query, $bindings)
);
} | php | public function fromQuery($query, $bindings = [])
{
$instance = $this->model->newInstance();
return $this->hydrate(
$instance->getConnection()->select($query, $bindings)
);
} | [
"public",
"function",
"fromQuery",
"(",
"$",
"query",
",",
"$",
"bindings",
"=",
"[",
"]",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"model",
"->",
"newInstance",
"(",
")",
";",
"return",
"$",
"this",
"->",
"hydrate",
"(",
"$",
"instance",
"->",
"getConnection",
"(",
")",
"->",
"select",
"(",
"$",
"query",
",",
"$",
"bindings",
")",
")",
";",
"}"
] | Create a collection of models from a raw query.
@param string $query
@param array $bindings
@return \Mellivora\Database\Eloquent\Collection | [
"Create",
"a",
"collection",
"of",
"models",
"from",
"a",
"raw",
"query",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L264-L271 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.findOrNew | public function findOrNew($id, $columns = ['*'])
{
if (!is_null($model = $this->find($id, $columns))) {
return $model;
}
return $this->model->newInstance()->setConnection(
$this->query->getConnection()->getName()
);
} | php | public function findOrNew($id, $columns = ['*'])
{
if (!is_null($model = $this->find($id, $columns))) {
return $model;
}
return $this->model->newInstance()->setConnection(
$this->query->getConnection()->getName()
);
} | [
"public",
"function",
"findOrNew",
"(",
"$",
"id",
",",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"id",
",",
"$",
"columns",
")",
")",
")",
"{",
"return",
"$",
"model",
";",
"}",
"return",
"$",
"this",
"->",
"model",
"->",
"newInstance",
"(",
")",
"->",
"setConnection",
"(",
"$",
"this",
"->",
"query",
"->",
"getConnection",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"}"
] | Find a model by its primary key or return fresh model instance.
@param mixed $id
@param array $columns
@return \Mellivora\Database\Eloquent\Model | [
"Find",
"a",
"model",
"by",
"its",
"primary",
"key",
"or",
"return",
"fresh",
"model",
"instance",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L343-L352 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.firstOrNew | public function firstOrNew(array $attributes, array $values = [])
{
if (!is_null($instance = $this->where($attributes)->first())) {
return $instance;
}
return $this->model->newInstance($attributes + $values)->setConnection(
$this->query->getConnection()->getName()
);
} | php | public function firstOrNew(array $attributes, array $values = [])
{
if (!is_null($instance = $this->where($attributes)->first())) {
return $instance;
}
return $this->model->newInstance($attributes + $values)->setConnection(
$this->query->getConnection()->getName()
);
} | [
"public",
"function",
"firstOrNew",
"(",
"array",
"$",
"attributes",
",",
"array",
"$",
"values",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"instance",
"=",
"$",
"this",
"->",
"where",
"(",
"$",
"attributes",
")",
"->",
"first",
"(",
")",
")",
")",
"{",
"return",
"$",
"instance",
";",
"}",
"return",
"$",
"this",
"->",
"model",
"->",
"newInstance",
"(",
"$",
"attributes",
"+",
"$",
"values",
")",
"->",
"setConnection",
"(",
"$",
"this",
"->",
"query",
"->",
"getConnection",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"}"
] | Get the first record matching the attributes or instantiate it.
@param array $attributes
@param array $values
@return \Mellivora\Database\Eloquent\Model | [
"Get",
"the",
"first",
"record",
"matching",
"the",
"attributes",
"or",
"instantiate",
"it",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L362-L371 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.getModels | public function getModels($columns = ['*'])
{
return $this->model->hydrate(
$this->query->get($columns)->all(),
$this->model->getConnectionName()
)->all();
} | php | public function getModels($columns = ['*'])
{
return $this->model->hydrate(
$this->query->get($columns)->all(),
$this->model->getConnectionName()
)->all();
} | [
"public",
"function",
"getModels",
"(",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"hydrate",
"(",
"$",
"this",
"->",
"query",
"->",
"get",
"(",
"$",
"columns",
")",
"->",
"all",
"(",
")",
",",
"$",
"this",
"->",
"model",
"->",
"getConnectionName",
"(",
")",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Get the hydrated models without eager loading.
@param array $columns
@return \Mellivora\Database\Eloquent\Model[] | [
"Get",
"the",
"hydrated",
"models",
"without",
"eager",
"loading",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L506-L512 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.chunkById | public function chunkById($count, callable $callback, $column = null, $alias = null)
{
$column = is_null($column) ? $this->getModel()->getKeyName() : $column;
$alias = is_null($alias) ? $column : $alias;
$lastId = 0;
do {
$clone = clone $this;
// We'll execute the query for the given page and get the results. If there are
// no results we can just break and return from here. When there are results
// we will call the callback with the current chunk of these results here.
$results = $clone->forPageAfterId($count, $lastId, $column)->get();
$countResults = $results->count();
if ($countResults === 0) {
break;
}
// On each chunk result set, we will pass them to the callback and then let the
// developer take care of everything within the callback, which allows us to
// keep the memory low for spinning through large result sets for working.
if ($callback($results) === false) {
return false;
}
$lastId = $results->last()->{$alias};
} while ($countResults === $count);
return true;
} | php | public function chunkById($count, callable $callback, $column = null, $alias = null)
{
$column = is_null($column) ? $this->getModel()->getKeyName() : $column;
$alias = is_null($alias) ? $column : $alias;
$lastId = 0;
do {
$clone = clone $this;
// We'll execute the query for the given page and get the results. If there are
// no results we can just break and return from here. When there are results
// we will call the callback with the current chunk of these results here.
$results = $clone->forPageAfterId($count, $lastId, $column)->get();
$countResults = $results->count();
if ($countResults === 0) {
break;
}
// On each chunk result set, we will pass them to the callback and then let the
// developer take care of everything within the callback, which allows us to
// keep the memory low for spinning through large result sets for working.
if ($callback($results) === false) {
return false;
}
$lastId = $results->last()->{$alias};
} while ($countResults === $count);
return true;
} | [
"public",
"function",
"chunkById",
"(",
"$",
"count",
",",
"callable",
"$",
"callback",
",",
"$",
"column",
"=",
"null",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"column",
"=",
"is_null",
"(",
"$",
"column",
")",
"?",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"getKeyName",
"(",
")",
":",
"$",
"column",
";",
"$",
"alias",
"=",
"is_null",
"(",
"$",
"alias",
")",
"?",
"$",
"column",
":",
"$",
"alias",
";",
"$",
"lastId",
"=",
"0",
";",
"do",
"{",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"// We'll execute the query for the given page and get the results. If there are",
"// no results we can just break and return from here. When there are results",
"// we will call the callback with the current chunk of these results here.",
"$",
"results",
"=",
"$",
"clone",
"->",
"forPageAfterId",
"(",
"$",
"count",
",",
"$",
"lastId",
",",
"$",
"column",
")",
"->",
"get",
"(",
")",
";",
"$",
"countResults",
"=",
"$",
"results",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"countResults",
"===",
"0",
")",
"{",
"break",
";",
"}",
"// On each chunk result set, we will pass them to the callback and then let the",
"// developer take care of everything within the callback, which allows us to",
"// keep the memory low for spinning through large result sets for working.",
"if",
"(",
"$",
"callback",
"(",
"$",
"results",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"lastId",
"=",
"$",
"results",
"->",
"last",
"(",
")",
"->",
"{",
"$",
"alias",
"}",
";",
"}",
"while",
"(",
"$",
"countResults",
"===",
"$",
"count",
")",
";",
"return",
"true",
";",
"}"
] | Chunk the results of a query by comparing numeric IDs.
@param int $count
@param callable $callback
@param string $column
@param null|string $alias
@return bool | [
"Chunk",
"the",
"results",
"of",
"a",
"query",
"by",
"comparing",
"numeric",
"IDs",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L694-L727 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.create | public function create(array $attributes = [])
{
$instance = $this->model->newInstance($attributes)->setConnection(
$this->query->getConnection()->getName()
);
$instance->save();
return $instance;
} | php | public function create(array $attributes = [])
{
$instance = $this->model->newInstance($attributes)->setConnection(
$this->query->getConnection()->getName()
);
$instance->save();
return $instance;
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"model",
"->",
"newInstance",
"(",
"$",
"attributes",
")",
"->",
"setConnection",
"(",
"$",
"this",
"->",
"query",
"->",
"getConnection",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"$",
"instance",
"->",
"save",
"(",
")",
";",
"return",
"$",
"instance",
";",
"}"
] | Save a new model and return the instance.
@param array $attributes
@return \Mellivora\Database\Eloquent\Model | [
"Save",
"a",
"new",
"model",
"and",
"return",
"the",
"instance",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L848-L857 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.forceCreate | public function forceCreate(array $attributes)
{
$instance = $this->model->newInstance()->setConnection(
$this->query->getConnection()->getName()
);
return $this->model->unguarded(function () use ($attributes, $instance) {
return $instance->create($attributes);
});
} | php | public function forceCreate(array $attributes)
{
$instance = $this->model->newInstance()->setConnection(
$this->query->getConnection()->getName()
);
return $this->model->unguarded(function () use ($attributes, $instance) {
return $instance->create($attributes);
});
} | [
"public",
"function",
"forceCreate",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"model",
"->",
"newInstance",
"(",
")",
"->",
"setConnection",
"(",
"$",
"this",
"->",
"query",
"->",
"getConnection",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"model",
"->",
"unguarded",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"attributes",
",",
"$",
"instance",
")",
"{",
"return",
"$",
"instance",
"->",
"create",
"(",
"$",
"attributes",
")",
";",
"}",
")",
";",
"}"
] | Save a new model and return the instance. Allow mass-assignment.
@param array $attributes
@return \Mellivora\Database\Eloquent\Model | [
"Save",
"a",
"new",
"model",
"and",
"return",
"the",
"instance",
".",
"Allow",
"mass",
"-",
"assignment",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L866-L875 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.addUpdatedAtColumn | protected function addUpdatedAtColumn(array $values)
{
if (!$this->model->usesTimestamps()) {
return $values;
}
return Arr::add(
$values,
$this->model->getUpdatedAtColumn(),
$this->model->freshTimestampString()
);
} | php | protected function addUpdatedAtColumn(array $values)
{
if (!$this->model->usesTimestamps()) {
return $values;
}
return Arr::add(
$values,
$this->model->getUpdatedAtColumn(),
$this->model->freshTimestampString()
);
} | [
"protected",
"function",
"addUpdatedAtColumn",
"(",
"array",
"$",
"values",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"model",
"->",
"usesTimestamps",
"(",
")",
")",
"{",
"return",
"$",
"values",
";",
"}",
"return",
"Arr",
"::",
"add",
"(",
"$",
"values",
",",
"$",
"this",
"->",
"model",
"->",
"getUpdatedAtColumn",
"(",
")",
",",
"$",
"this",
"->",
"model",
"->",
"freshTimestampString",
"(",
")",
")",
";",
"}"
] | Add the "updated at" column to an array of values.
@param array $values
@return array | [
"Add",
"the",
"updated",
"at",
"column",
"to",
"an",
"array",
"of",
"values",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L932-L943 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.callScope | protected function callScope(callable $scope, $parameters = [])
{
array_unshift($parameters, $this);
$query = $this->getQuery();
// We will keep track of how many wheres are on the query before running the
// scope so that we can properly group the added scope constraints in the
// query as their own isolated nested where statement and avoid issues.
$originalWhereCount = count($query->wheres);
$result = $scope(...array_values($parameters)) ?: $this;
if (count($query->wheres) > $originalWhereCount) {
$this->addNewWheresWithinGroup($query, $originalWhereCount);
}
return $result;
} | php | protected function callScope(callable $scope, $parameters = [])
{
array_unshift($parameters, $this);
$query = $this->getQuery();
// We will keep track of how many wheres are on the query before running the
// scope so that we can properly group the added scope constraints in the
// query as their own isolated nested where statement and avoid issues.
$originalWhereCount = count($query->wheres);
$result = $scope(...array_values($parameters)) ?: $this;
if (count($query->wheres) > $originalWhereCount) {
$this->addNewWheresWithinGroup($query, $originalWhereCount);
}
return $result;
} | [
"protected",
"function",
"callScope",
"(",
"callable",
"$",
"scope",
",",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"array_unshift",
"(",
"$",
"parameters",
",",
"$",
"this",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getQuery",
"(",
")",
";",
"// We will keep track of how many wheres are on the query before running the",
"// scope so that we can properly group the added scope constraints in the",
"// query as their own isolated nested where statement and avoid issues.",
"$",
"originalWhereCount",
"=",
"count",
"(",
"$",
"query",
"->",
"wheres",
")",
";",
"$",
"result",
"=",
"$",
"scope",
"(",
"...",
"array_values",
"(",
"$",
"parameters",
")",
")",
"?",
":",
"$",
"this",
";",
"if",
"(",
"count",
"(",
"$",
"query",
"->",
"wheres",
")",
">",
"$",
"originalWhereCount",
")",
"{",
"$",
"this",
"->",
"addNewWheresWithinGroup",
"(",
"$",
"query",
",",
"$",
"originalWhereCount",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Apply the given scope on the current builder instance.
@param callable $scope
@param array $parameters
@return mixed | [
"Apply",
"the",
"given",
"scope",
"on",
"the",
"current",
"builder",
"instance",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L1056-L1074 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Builder.php | Builder.parseWithRelations | protected function parseWithRelations(array $relations)
{
$results = [];
foreach ($relations as $name => $constraints) {
// If the "relation" value is actually a numeric key, we can assume that no
// constraints have been specified for the eager load and we'll just put
// an empty Closure with the loader so that we can treat all the same.
if (is_numeric($name)) {
$name = $constraints;
list($name, $constraints) = Str::contains($name, ':')
? $this->createSelectWithConstraint($name)
: [$name, function () {
//
}];
}
// We need to separate out any nested includes. Which allows the developers
// to load deep relationships using "dots" without stating each level of
// the relationship with its own key in the array of eager load names.
$results = $this->addNestedWiths($name, $results);
$results[$name] = $constraints;
}
return $results;
} | php | protected function parseWithRelations(array $relations)
{
$results = [];
foreach ($relations as $name => $constraints) {
// If the "relation" value is actually a numeric key, we can assume that no
// constraints have been specified for the eager load and we'll just put
// an empty Closure with the loader so that we can treat all the same.
if (is_numeric($name)) {
$name = $constraints;
list($name, $constraints) = Str::contains($name, ':')
? $this->createSelectWithConstraint($name)
: [$name, function () {
//
}];
}
// We need to separate out any nested includes. Which allows the developers
// to load deep relationships using "dots" without stating each level of
// the relationship with its own key in the array of eager load names.
$results = $this->addNestedWiths($name, $results);
$results[$name] = $constraints;
}
return $results;
} | [
"protected",
"function",
"parseWithRelations",
"(",
"array",
"$",
"relations",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"name",
"=>",
"$",
"constraints",
")",
"{",
"// If the \"relation\" value is actually a numeric key, we can assume that no",
"// constraints have been specified for the eager load and we'll just put",
"// an empty Closure with the loader so that we can treat all the same.",
"if",
"(",
"is_numeric",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"constraints",
";",
"list",
"(",
"$",
"name",
",",
"$",
"constraints",
")",
"=",
"Str",
"::",
"contains",
"(",
"$",
"name",
",",
"':'",
")",
"?",
"$",
"this",
"->",
"createSelectWithConstraint",
"(",
"$",
"name",
")",
":",
"[",
"$",
"name",
",",
"function",
"(",
")",
"{",
"//",
"}",
"]",
";",
"}",
"// We need to separate out any nested includes. Which allows the developers",
"// to load deep relationships using \"dots\" without stating each level of",
"// the relationship with its own key in the array of eager load names.",
"$",
"results",
"=",
"$",
"this",
"->",
"addNestedWiths",
"(",
"$",
"name",
",",
"$",
"results",
")",
";",
"$",
"results",
"[",
"$",
"name",
"]",
"=",
"$",
"constraints",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Parse a list of relations into individuals.
@param array $relations
@return array | [
"Parse",
"a",
"list",
"of",
"relations",
"into",
"individuals",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Builder.php#L1185-L1212 |
Baachi/CouchDB | src/CouchDB/DesignDocument/Result.php | Result.getFirstRow | public function getFirstRow()
{
$rows = $this->data['rows'];
if (empty($rows)) {
return false;
}
$row = array_slice($rows, 0, 1);
return current($row);
} | php | public function getFirstRow()
{
$rows = $this->data['rows'];
if (empty($rows)) {
return false;
}
$row = array_slice($rows, 0, 1);
return current($row);
} | [
"public",
"function",
"getFirstRow",
"(",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"data",
"[",
"'rows'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"rows",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"row",
"=",
"array_slice",
"(",
"$",
"rows",
",",
"0",
",",
"1",
")",
";",
"return",
"current",
"(",
"$",
"row",
")",
";",
"}"
] | Return the first row.
@return bool|array | [
"Return",
"the",
"first",
"row",
"."
] | train | https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/DesignDocument/Result.php#L60-L70 |
Baachi/CouchDB | src/CouchDB/DesignDocument/Result.php | Result.getLastRow | public function getLastRow()
{
$rows = $this->data['rows'];
if (empty($rows)) {
return false;
}
$row = array_slice($rows, count($rows) - 1);
return current($row);
} | php | public function getLastRow()
{
$rows = $this->data['rows'];
if (empty($rows)) {
return false;
}
$row = array_slice($rows, count($rows) - 1);
return current($row);
} | [
"public",
"function",
"getLastRow",
"(",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"data",
"[",
"'rows'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"rows",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"row",
"=",
"array_slice",
"(",
"$",
"rows",
",",
"count",
"(",
"$",
"rows",
")",
"-",
"1",
")",
";",
"return",
"current",
"(",
"$",
"row",
")",
";",
"}"
] | Return the last row.
@return bool|array | [
"Return",
"the",
"last",
"row",
"."
] | train | https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/DesignDocument/Result.php#L77-L87 |
artincms/laravel_tagable | src/LTSServiceProvider.php | LTSServiceProvider.boot | public function boot()
{
// the main router
$this->loadRoutesFrom( __DIR__.'/Routes/backend_lts_route.php');
$this->loadRoutesFrom( __DIR__.'/Routes/frontend_lts_route.php');
// the main views folder
$this->loadViewsFrom(__DIR__ . '/Views', 'laravel_tagable');
// the main migration folder for create sms_ir tables
// for publish the views into main app
$this->publishes([
__DIR__ . '/Views' => resource_path('views/vendor/laravel_tagable'),
]);
$this->publishes([
__DIR__ . '/Database/Migrations/' => database_path('migrations')
], 'migrations');
// for publish the assets files into main app
$this->publishes([
__DIR__.'/assets' => public_path('vendor/laravel_tagable'),
], 'public');
// for publish the sms_ir config file to the main app config folder
$this->publishes([
__DIR__ . '/Config/LTS.php' => config_path('laravel_tagable.php'),
]);
$this->publishes([
__DIR__ . '/Traits/LaraveTagablesSystem.php' => app_path('Traits/LaraveTagablesSystem.php'),
]);
$this->publishes([
__DIR__ . '/Components' => resource_path('assets/js/components/laravel_tagable'),
]);
} | php | public function boot()
{
// the main router
$this->loadRoutesFrom( __DIR__.'/Routes/backend_lts_route.php');
$this->loadRoutesFrom( __DIR__.'/Routes/frontend_lts_route.php');
// the main views folder
$this->loadViewsFrom(__DIR__ . '/Views', 'laravel_tagable');
// the main migration folder for create sms_ir tables
// for publish the views into main app
$this->publishes([
__DIR__ . '/Views' => resource_path('views/vendor/laravel_tagable'),
]);
$this->publishes([
__DIR__ . '/Database/Migrations/' => database_path('migrations')
], 'migrations');
// for publish the assets files into main app
$this->publishes([
__DIR__.'/assets' => public_path('vendor/laravel_tagable'),
], 'public');
// for publish the sms_ir config file to the main app config folder
$this->publishes([
__DIR__ . '/Config/LTS.php' => config_path('laravel_tagable.php'),
]);
$this->publishes([
__DIR__ . '/Traits/LaraveTagablesSystem.php' => app_path('Traits/LaraveTagablesSystem.php'),
]);
$this->publishes([
__DIR__ . '/Components' => resource_path('assets/js/components/laravel_tagable'),
]);
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"// the main router",
"$",
"this",
"->",
"loadRoutesFrom",
"(",
"__DIR__",
".",
"'/Routes/backend_lts_route.php'",
")",
";",
"$",
"this",
"->",
"loadRoutesFrom",
"(",
"__DIR__",
".",
"'/Routes/frontend_lts_route.php'",
")",
";",
"// the main views folder",
"$",
"this",
"->",
"loadViewsFrom",
"(",
"__DIR__",
".",
"'/Views'",
",",
"'laravel_tagable'",
")",
";",
"// the main migration folder for create sms_ir tables",
"// for publish the views into main app",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/Views'",
"=>",
"resource_path",
"(",
"'views/vendor/laravel_tagable'",
")",
",",
"]",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/Database/Migrations/'",
"=>",
"database_path",
"(",
"'migrations'",
")",
"]",
",",
"'migrations'",
")",
";",
"// for publish the assets files into main app",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/assets'",
"=>",
"public_path",
"(",
"'vendor/laravel_tagable'",
")",
",",
"]",
",",
"'public'",
")",
";",
"// for publish the sms_ir config file to the main app config folder",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/Config/LTS.php'",
"=>",
"config_path",
"(",
"'laravel_tagable.php'",
")",
",",
"]",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/Traits/LaraveTagablesSystem.php'",
"=>",
"app_path",
"(",
"'Traits/LaraveTagablesSystem.php'",
")",
",",
"]",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/Components'",
"=>",
"resource_path",
"(",
"'assets/js/components/laravel_tagable'",
")",
",",
"]",
")",
";",
"}"
] | Bootstrap the application services.
@return void | [
"Bootstrap",
"the",
"application",
"services",
"."
] | train | https://github.com/artincms/laravel_tagable/blob/175b299f496bdeda7bd91cae27d30a9aa3533328/src/LTSServiceProvider.php#L15-L48 |
kiwi-suite/frontend42 | src/Module.php | Module.init | public function init(ModuleManagerInterface $manager)
{
$events = $manager->getEventManager();
$events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'addPageTypes'));
$events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'addBlocks'));
} | php | public function init(ModuleManagerInterface $manager)
{
$events = $manager->getEventManager();
$events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'addPageTypes'));
$events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'addBlocks'));
} | [
"public",
"function",
"init",
"(",
"ModuleManagerInterface",
"$",
"manager",
")",
"{",
"$",
"events",
"=",
"$",
"manager",
"->",
"getEventManager",
"(",
")",
";",
"$",
"events",
"->",
"attach",
"(",
"ModuleEvent",
"::",
"EVENT_MERGE_CONFIG",
",",
"array",
"(",
"$",
"this",
",",
"'addPageTypes'",
")",
")",
";",
"$",
"events",
"->",
"attach",
"(",
"ModuleEvent",
"::",
"EVENT_MERGE_CONFIG",
",",
"array",
"(",
"$",
"this",
",",
"'addBlocks'",
")",
")",
";",
"}"
] | Initialize workflow
@param ModuleManagerInterface $manager
@return void | [
"Initialize",
"workflow"
] | train | https://github.com/kiwi-suite/frontend42/blob/67e5208387957823ac84f7833eba83d4a8dab8cd/src/Module.php#L55-L60 |
kiwi-suite/frontend42 | src/Module.php | Module.onBootstrap | public function onBootstrap(EventInterface $e)
{
/** @var ServiceManager $serviceManager */
$serviceManager = $e->getApplication()->getServiceManager();
/** @var Environment $environment */
$environment = $serviceManager->get(Environment::class);
if ($environment->is(\Admin42\Module::ENVIRONMENT_ADMIN)) {
$serviceManager
->get(PageEventListener::class)
->attach($e->getApplication()->getServiceManager()->get('Frontend42\Page\EventManager'));
}
if (!$environment->is(\Admin42\Module::ENVIRONMENT_ADMIN)) {
$e->getApplication()
->getEventManager()
->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($serviceManager){
/** @var Localization $localization */
$localization = $serviceManager->get(Localization::class);
$localization->acceptLocale($localization->getDefaultLocale());
$serviceManager->get(TranslatorInterface::class)->setLocale($localization->getActiveLocale());
}, 100);
}
} | php | public function onBootstrap(EventInterface $e)
{
/** @var ServiceManager $serviceManager */
$serviceManager = $e->getApplication()->getServiceManager();
/** @var Environment $environment */
$environment = $serviceManager->get(Environment::class);
if ($environment->is(\Admin42\Module::ENVIRONMENT_ADMIN)) {
$serviceManager
->get(PageEventListener::class)
->attach($e->getApplication()->getServiceManager()->get('Frontend42\Page\EventManager'));
}
if (!$environment->is(\Admin42\Module::ENVIRONMENT_ADMIN)) {
$e->getApplication()
->getEventManager()
->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($serviceManager){
/** @var Localization $localization */
$localization = $serviceManager->get(Localization::class);
$localization->acceptLocale($localization->getDefaultLocale());
$serviceManager->get(TranslatorInterface::class)->setLocale($localization->getActiveLocale());
}, 100);
}
} | [
"public",
"function",
"onBootstrap",
"(",
"EventInterface",
"$",
"e",
")",
"{",
"/** @var ServiceManager $serviceManager */",
"$",
"serviceManager",
"=",
"$",
"e",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
";",
"/** @var Environment $environment */",
"$",
"environment",
"=",
"$",
"serviceManager",
"->",
"get",
"(",
"Environment",
"::",
"class",
")",
";",
"if",
"(",
"$",
"environment",
"->",
"is",
"(",
"\\",
"Admin42",
"\\",
"Module",
"::",
"ENVIRONMENT_ADMIN",
")",
")",
"{",
"$",
"serviceManager",
"->",
"get",
"(",
"PageEventListener",
"::",
"class",
")",
"->",
"attach",
"(",
"$",
"e",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
"->",
"get",
"(",
"'Frontend42\\Page\\EventManager'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"environment",
"->",
"is",
"(",
"\\",
"Admin42",
"\\",
"Module",
"::",
"ENVIRONMENT_ADMIN",
")",
")",
"{",
"$",
"e",
"->",
"getApplication",
"(",
")",
"->",
"getEventManager",
"(",
")",
"->",
"attach",
"(",
"MvcEvent",
"::",
"EVENT_DISPATCH_ERROR",
",",
"function",
"(",
"$",
"e",
")",
"use",
"(",
"$",
"serviceManager",
")",
"{",
"/** @var Localization $localization */",
"$",
"localization",
"=",
"$",
"serviceManager",
"->",
"get",
"(",
"Localization",
"::",
"class",
")",
";",
"$",
"localization",
"->",
"acceptLocale",
"(",
"$",
"localization",
"->",
"getDefaultLocale",
"(",
")",
")",
";",
"$",
"serviceManager",
"->",
"get",
"(",
"TranslatorInterface",
"::",
"class",
")",
"->",
"setLocale",
"(",
"$",
"localization",
"->",
"getActiveLocale",
"(",
")",
")",
";",
"}",
",",
"100",
")",
";",
"}",
"}"
] | Listen to the bootstrap event
@param EventInterface $e
@return array | [
"Listen",
"to",
"the",
"bootstrap",
"event"
] | train | https://github.com/kiwi-suite/frontend42/blob/67e5208387957823ac84f7833eba83d4a8dab8cd/src/Module.php#L124-L148 |
inhere/php-librarys | src/Traits/FixedEventTrait.php | FixedEventTrait.on | public function on(string $event, callable $cb, bool $replace = false)
{
if (false === ($key = array_search($event, $this->getSupportedEvents(), true))) {
$sup = implode(',', $this->getSupportedEvents());
throw new \InvalidArgumentException("The want registered event [$event] is not supported. Supported: $sup");
}
// init property
if ($this->eventHandlers === null) {
$this->eventHandlers = new \SplFixedArray(\count($this->getSupportedEvents()));
}
if (!$replace && isset($this->eventHandlers[$key])) {
throw new \InvalidArgumentException("The want registered event [$event] have been registered! don't allow replace.");
}
$this->eventHandlers[$key] = $cb;
} | php | public function on(string $event, callable $cb, bool $replace = false)
{
if (false === ($key = array_search($event, $this->getSupportedEvents(), true))) {
$sup = implode(',', $this->getSupportedEvents());
throw new \InvalidArgumentException("The want registered event [$event] is not supported. Supported: $sup");
}
// init property
if ($this->eventHandlers === null) {
$this->eventHandlers = new \SplFixedArray(\count($this->getSupportedEvents()));
}
if (!$replace && isset($this->eventHandlers[$key])) {
throw new \InvalidArgumentException("The want registered event [$event] have been registered! don't allow replace.");
}
$this->eventHandlers[$key] = $cb;
} | [
"public",
"function",
"on",
"(",
"string",
"$",
"event",
",",
"callable",
"$",
"cb",
",",
"bool",
"$",
"replace",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"event",
",",
"$",
"this",
"->",
"getSupportedEvents",
"(",
")",
",",
"true",
")",
")",
")",
"{",
"$",
"sup",
"=",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"getSupportedEvents",
"(",
")",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The want registered event [$event] is not supported. Supported: $sup\"",
")",
";",
"}",
"// init property",
"if",
"(",
"$",
"this",
"->",
"eventHandlers",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"eventHandlers",
"=",
"new",
"\\",
"SplFixedArray",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"getSupportedEvents",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"replace",
"&&",
"isset",
"(",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The want registered event [$event] have been registered! don't allow replace.\"",
")",
";",
"}",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"key",
"]",
"=",
"$",
"cb",
";",
"}"
] | register a event callback
@param string $event event name
@param callable $cb event callback
@param bool $replace replace exists's event cb
@throws \InvalidArgumentException | [
"register",
"a",
"event",
"callback"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/FixedEventTrait.php#L99-L117 |
inhere/php-librarys | src/Traits/FixedEventTrait.php | FixedEventTrait.off | public function off(string $event)
{
if (false === ($key = array_search($event, $this->getSupportedEvents(), true))) {
return null;
}
if (!isset($this->eventHandlers[$key]) || !($cb = $this->eventHandlers[$key])) {
return null;
}
$this->eventHandlers[$key] = null;
return $cb;
} | php | public function off(string $event)
{
if (false === ($key = array_search($event, $this->getSupportedEvents(), true))) {
return null;
}
if (!isset($this->eventHandlers[$key]) || !($cb = $this->eventHandlers[$key])) {
return null;
}
$this->eventHandlers[$key] = null;
return $cb;
} | [
"public",
"function",
"off",
"(",
"string",
"$",
"event",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"event",
",",
"$",
"this",
"->",
"getSupportedEvents",
"(",
")",
",",
"true",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"key",
"]",
")",
"||",
"!",
"(",
"$",
"cb",
"=",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"eventHandlers",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"return",
"$",
"cb",
";",
"}"
] | remove event handler
@param string $event
@return bool | [
"remove",
"event",
"handler"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/FixedEventTrait.php#L124-L137 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.