repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
phossa/phossa-event | src/Phossa/Event/Interfaces/EventManagerTrait.php | EventManagerTrait.getListenerEvents | protected function getListenerEvents(
$listener,
/*# string */ $eventName = ''
)/*# : array */ {
// check listener
if (!$this->isListener($listener)) {
throw new Exception\InvalidArgumentException(
Message::get(
Message::INVALID_EVENT_LISTENER,
is_object($listener) ?
get_class($listener) :
$listener
),
Message::INVALID_EVENT_LISTENER
);
}
// get listener's listening event definition array
if (is_object($listener)) {
/* @var $listener EventListenerInterface */
$evts = $listener->getEventsListening();
} else {
/* @var $listener EventListenerStaticInterface */
$evts = $listener::getEventsListeningStatically();
}
if ($eventName != '') {
foreach (array_keys($evts) as $name) {
if ($name !== $eventName) {
unset($evts[$name]);
}
}
}
return $evts;
} | php | protected function getListenerEvents(
$listener,
/*# string */ $eventName = ''
)/*# : array */ {
// check listener
if (!$this->isListener($listener)) {
throw new Exception\InvalidArgumentException(
Message::get(
Message::INVALID_EVENT_LISTENER,
is_object($listener) ?
get_class($listener) :
$listener
),
Message::INVALID_EVENT_LISTENER
);
}
// get listener's listening event definition array
if (is_object($listener)) {
/* @var $listener EventListenerInterface */
$evts = $listener->getEventsListening();
} else {
/* @var $listener EventListenerStaticInterface */
$evts = $listener::getEventsListeningStatically();
}
if ($eventName != '') {
foreach (array_keys($evts) as $name) {
if ($name !== $eventName) {
unset($evts[$name]);
}
}
}
return $evts;
} | [
"protected",
"function",
"getListenerEvents",
"(",
"$",
"listener",
",",
"/*# string */",
"$",
"eventName",
"=",
"''",
")",
"/*# : array */",
"{",
"// check listener",
"if",
"(",
"!",
"$",
"this",
"->",
"isListener",
"(",
"$",
"listener",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"INVALID_EVENT_LISTENER",
",",
"is_object",
"(",
"$",
"listener",
")",
"?",
"get_class",
"(",
"$",
"listener",
")",
":",
"$",
"listener",
")",
",",
"Message",
"::",
"INVALID_EVENT_LISTENER",
")",
";",
"}",
"// get listener's listening event definition array",
"if",
"(",
"is_object",
"(",
"$",
"listener",
")",
")",
"{",
"/* @var $listener EventListenerInterface */",
"$",
"evts",
"=",
"$",
"listener",
"->",
"getEventsListening",
"(",
")",
";",
"}",
"else",
"{",
"/* @var $listener EventListenerStaticInterface */",
"$",
"evts",
"=",
"$",
"listener",
"::",
"getEventsListeningStatically",
"(",
")",
";",
"}",
"if",
"(",
"$",
"eventName",
"!=",
"''",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"evts",
")",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"name",
"!==",
"$",
"eventName",
")",
"{",
"unset",
"(",
"$",
"evts",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"evts",
";",
"}"
] | Get listener events array
@param EventListenerInterface|string $listener object/static class name
@param string $eventName event name or '' for all events
@return array
@throws Exception\InvalidArgumentException
if $listener not a valid listener
@access protected | [
"Get",
"listener",
"events",
"array"
] | 0044888fcc9b21584233c73cf20fc160e1b1f295 | https://github.com/phossa/phossa-event/blob/0044888fcc9b21584233c73cf20fc160e1b1f295/src/Phossa/Event/Interfaces/EventManagerTrait.php#L277-L312 | train |
phossa/phossa-event | src/Phossa/Event/Interfaces/EventManagerTrait.php | EventManagerTrait.makeCallables | protected function makeCallables(
$listener,
$callable,
/*# int */ $priority
)/*# : array */ {
$result = [];
if (is_array($callable)) {
if (isset($callable[1]) && is_int($callable[1])) {
$priority = $callable[1];
$xc = $callable[0];
} else {
foreach ($callable as $cc) {
$result = array_merge(
$result,
$this->makeCallables($listener, $cc, $priority)
);
}
return $result;
}
} elseif (is_string($callable)) {
$xc = $callable;
}
if (isset($xc)) {
if (!is_callable($xc)) {
$xc = array($listener, $xc);
}
if (is_callable($xc)) {
$result[] = [ $xc, $priority ];
}
}
return $result;
} | php | protected function makeCallables(
$listener,
$callable,
/*# int */ $priority
)/*# : array */ {
$result = [];
if (is_array($callable)) {
if (isset($callable[1]) && is_int($callable[1])) {
$priority = $callable[1];
$xc = $callable[0];
} else {
foreach ($callable as $cc) {
$result = array_merge(
$result,
$this->makeCallables($listener, $cc, $priority)
);
}
return $result;
}
} elseif (is_string($callable)) {
$xc = $callable;
}
if (isset($xc)) {
if (!is_callable($xc)) {
$xc = array($listener, $xc);
}
if (is_callable($xc)) {
$result[] = [ $xc, $priority ];
}
}
return $result;
} | [
"protected",
"function",
"makeCallables",
"(",
"$",
"listener",
",",
"$",
"callable",
",",
"/*# int */",
"$",
"priority",
")",
"/*# : array */",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"callable",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"callable",
"[",
"1",
"]",
")",
"&&",
"is_int",
"(",
"$",
"callable",
"[",
"1",
"]",
")",
")",
"{",
"$",
"priority",
"=",
"$",
"callable",
"[",
"1",
"]",
";",
"$",
"xc",
"=",
"$",
"callable",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"callable",
"as",
"$",
"cc",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"makeCallables",
"(",
"$",
"listener",
",",
"$",
"cc",
",",
"$",
"priority",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"callable",
")",
")",
"{",
"$",
"xc",
"=",
"$",
"callable",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xc",
")",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"xc",
")",
")",
"{",
"$",
"xc",
"=",
"array",
"(",
"$",
"listener",
",",
"$",
"xc",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"xc",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"[",
"$",
"xc",
",",
"$",
"priority",
"]",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns an array of callables
@param EventListenerInterface|string $listener object/static class name
@param mixed $callable user defined callables
@param int $priority priority
@return array
@access protected | [
"Returns",
"an",
"array",
"of",
"callables"
] | 0044888fcc9b21584233c73cf20fc160e1b1f295 | https://github.com/phossa/phossa-event/blob/0044888fcc9b21584233c73cf20fc160e1b1f295/src/Phossa/Event/Interfaces/EventManagerTrait.php#L323-L355 | train |
phossa/phossa-event | src/Phossa/Event/Interfaces/EventManagerTrait.php | EventManagerTrait.attachIt | protected function attachIt(
/*# string */ $eventName,
$listener,
$callable,
/*# int */ $priority
) {
// get named event queue
if ($this->hasEventQueue($eventName)) {
$q = $this->getEventQueue($eventName);
} else {
$q = new EventQueue();
$this->events[$eventName] = $q;
}
// attach callable directory
if (is_null($listener)) {
// need $eventName
if (empty($eventName)) {
throw new Exception\InvalidArgumentException(
Message::get(Message::INVALID_EVENT_NAME, 'EMPTY'),
Message::INVALID_EVENT_NAME
);
}
$xc = [
[ $callable, (int) $priority ]
];
// get callables from listener object or static listener class
} else {
$xc = $this->makeCallables($listener, $callable, (int) $priority);
}
if (empty($xc)) {
throw new Exception\InvalidArgumentException(
Message::get(Message::INVALID_EVENT_CALLABLE, $eventName),
Message::INVALID_EVENT_CALLABLE
);
} else {
foreach ($xc as $c) {
$q->insert($c[0], $c[1]);
}
}
} | php | protected function attachIt(
/*# string */ $eventName,
$listener,
$callable,
/*# int */ $priority
) {
// get named event queue
if ($this->hasEventQueue($eventName)) {
$q = $this->getEventQueue($eventName);
} else {
$q = new EventQueue();
$this->events[$eventName] = $q;
}
// attach callable directory
if (is_null($listener)) {
// need $eventName
if (empty($eventName)) {
throw new Exception\InvalidArgumentException(
Message::get(Message::INVALID_EVENT_NAME, 'EMPTY'),
Message::INVALID_EVENT_NAME
);
}
$xc = [
[ $callable, (int) $priority ]
];
// get callables from listener object or static listener class
} else {
$xc = $this->makeCallables($listener, $callable, (int) $priority);
}
if (empty($xc)) {
throw new Exception\InvalidArgumentException(
Message::get(Message::INVALID_EVENT_CALLABLE, $eventName),
Message::INVALID_EVENT_CALLABLE
);
} else {
foreach ($xc as $c) {
$q->insert($c[0], $c[1]);
}
}
} | [
"protected",
"function",
"attachIt",
"(",
"/*# string */",
"$",
"eventName",
",",
"$",
"listener",
",",
"$",
"callable",
",",
"/*# int */",
"$",
"priority",
")",
"{",
"// get named event queue",
"if",
"(",
"$",
"this",
"->",
"hasEventQueue",
"(",
"$",
"eventName",
")",
")",
"{",
"$",
"q",
"=",
"$",
"this",
"->",
"getEventQueue",
"(",
"$",
"eventName",
")",
";",
"}",
"else",
"{",
"$",
"q",
"=",
"new",
"EventQueue",
"(",
")",
";",
"$",
"this",
"->",
"events",
"[",
"$",
"eventName",
"]",
"=",
"$",
"q",
";",
"}",
"// attach callable directory",
"if",
"(",
"is_null",
"(",
"$",
"listener",
")",
")",
"{",
"// need $eventName",
"if",
"(",
"empty",
"(",
"$",
"eventName",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"INVALID_EVENT_NAME",
",",
"'EMPTY'",
")",
",",
"Message",
"::",
"INVALID_EVENT_NAME",
")",
";",
"}",
"$",
"xc",
"=",
"[",
"[",
"$",
"callable",
",",
"(",
"int",
")",
"$",
"priority",
"]",
"]",
";",
"// get callables from listener object or static listener class",
"}",
"else",
"{",
"$",
"xc",
"=",
"$",
"this",
"->",
"makeCallables",
"(",
"$",
"listener",
",",
"$",
"callable",
",",
"(",
"int",
")",
"$",
"priority",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"xc",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"INVALID_EVENT_CALLABLE",
",",
"$",
"eventName",
")",
",",
"Message",
"::",
"INVALID_EVENT_CALLABLE",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"xc",
"as",
"$",
"c",
")",
"{",
"$",
"q",
"->",
"insert",
"(",
"$",
"c",
"[",
"0",
"]",
",",
"$",
"c",
"[",
"1",
"]",
")",
";",
"}",
"}",
"}"
] | Attach callable to event queque
@param string $eventName event name
@param EventListenerInterface|string|null $listener
object/static class name or a callable
@param mixed $callable string | array
@param int $priority priority integer
@return void
@throws Exception\InvalidArgumentException
if callable is the wrong format
@access protected | [
"Attach",
"callable",
"to",
"event",
"queque"
] | 0044888fcc9b21584233c73cf20fc160e1b1f295 | https://github.com/phossa/phossa-event/blob/0044888fcc9b21584233c73cf20fc160e1b1f295/src/Phossa/Event/Interfaces/EventManagerTrait.php#L370-L411 | train |
phossa/phossa-event | src/Phossa/Event/Interfaces/EventManagerTrait.php | EventManagerTrait.detachIt | protected function detachIt(
/*# string */ $eventName,
$listener,
$callable
) {
// queue not found
if ($eventName != '' && !$this->hasEventQueue($eventName)) {
return;
}
// detach callable directly
if (is_null($listener)) {
$xc = [
[ $callable, 50 ]
];
} else {
// get callables from listener object or static listener class
$xc = $this->makeCallables($listener, $callable, 50);
}
if (empty($xc)) {
throw new Exception\InvalidArgumentException(
Message::get(Message::INVALID_EVENT_CALLABLE, $eventName),
Message::INVALID_EVENT_CALLABLE
);
} else {
if ($eventName != '') {
$q = $this->getEventQueue($eventName);
foreach ($xc as $c) {
$q->remove($c[0]);
}
if ($q->count() === 0) {
unset($this->events[$eventName]);
}
} else {
$names = $this->getEventNames();
foreach ($names as $n) {
$q = $this->getEventQueue($n);
foreach ($xc as $c) {
$q->remove($c[0]);
}
if ($q->count() === 0) {
unset($this->events[$n]);
}
}
}
}
} | php | protected function detachIt(
/*# string */ $eventName,
$listener,
$callable
) {
// queue not found
if ($eventName != '' && !$this->hasEventQueue($eventName)) {
return;
}
// detach callable directly
if (is_null($listener)) {
$xc = [
[ $callable, 50 ]
];
} else {
// get callables from listener object or static listener class
$xc = $this->makeCallables($listener, $callable, 50);
}
if (empty($xc)) {
throw new Exception\InvalidArgumentException(
Message::get(Message::INVALID_EVENT_CALLABLE, $eventName),
Message::INVALID_EVENT_CALLABLE
);
} else {
if ($eventName != '') {
$q = $this->getEventQueue($eventName);
foreach ($xc as $c) {
$q->remove($c[0]);
}
if ($q->count() === 0) {
unset($this->events[$eventName]);
}
} else {
$names = $this->getEventNames();
foreach ($names as $n) {
$q = $this->getEventQueue($n);
foreach ($xc as $c) {
$q->remove($c[0]);
}
if ($q->count() === 0) {
unset($this->events[$n]);
}
}
}
}
} | [
"protected",
"function",
"detachIt",
"(",
"/*# string */",
"$",
"eventName",
",",
"$",
"listener",
",",
"$",
"callable",
")",
"{",
"// queue not found",
"if",
"(",
"$",
"eventName",
"!=",
"''",
"&&",
"!",
"$",
"this",
"->",
"hasEventQueue",
"(",
"$",
"eventName",
")",
")",
"{",
"return",
";",
"}",
"// detach callable directly",
"if",
"(",
"is_null",
"(",
"$",
"listener",
")",
")",
"{",
"$",
"xc",
"=",
"[",
"[",
"$",
"callable",
",",
"50",
"]",
"]",
";",
"}",
"else",
"{",
"// get callables from listener object or static listener class",
"$",
"xc",
"=",
"$",
"this",
"->",
"makeCallables",
"(",
"$",
"listener",
",",
"$",
"callable",
",",
"50",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"xc",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"INVALID_EVENT_CALLABLE",
",",
"$",
"eventName",
")",
",",
"Message",
"::",
"INVALID_EVENT_CALLABLE",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"eventName",
"!=",
"''",
")",
"{",
"$",
"q",
"=",
"$",
"this",
"->",
"getEventQueue",
"(",
"$",
"eventName",
")",
";",
"foreach",
"(",
"$",
"xc",
"as",
"$",
"c",
")",
"{",
"$",
"q",
"->",
"remove",
"(",
"$",
"c",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"$",
"q",
"->",
"count",
"(",
")",
"===",
"0",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"eventName",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"names",
"=",
"$",
"this",
"->",
"getEventNames",
"(",
")",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"n",
")",
"{",
"$",
"q",
"=",
"$",
"this",
"->",
"getEventQueue",
"(",
"$",
"n",
")",
";",
"foreach",
"(",
"$",
"xc",
"as",
"$",
"c",
")",
"{",
"$",
"q",
"->",
"remove",
"(",
"$",
"c",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"$",
"q",
"->",
"count",
"(",
")",
"===",
"0",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"n",
"]",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Detach callable to event queque
@param string $eventName event name
@param EventListenerInterface|string|null $listener
object/static class name or a callable
@param mixed $callable string | array
@return void
@throws Exception\InvalidArgumentException
if callable is the wrong format
@access protected | [
"Detach",
"callable",
"to",
"event",
"queque"
] | 0044888fcc9b21584233c73cf20fc160e1b1f295 | https://github.com/phossa/phossa-event/blob/0044888fcc9b21584233c73cf20fc160e1b1f295/src/Phossa/Event/Interfaces/EventManagerTrait.php#L425-L472 | train |
phossa/phossa-event | src/Phossa/Event/Interfaces/EventManagerTrait.php | EventManagerTrait.matchEventQueue | protected function matchEventQueue(
/*# string */ $eventName,
EventManagerInterface $manager
)/*# : EventQueueInterface */ {
$names = $this->globNames($eventName, $manager->getEventNames());
// combine all globbing queue
$queue = new EventQueue();
foreach ($names as $n) {
if ($manager->hasEventQueue($n)) {
$queue = $queue->combine($manager->getEventQueue($n));
}
}
return $queue;
} | php | protected function matchEventQueue(
/*# string */ $eventName,
EventManagerInterface $manager
)/*# : EventQueueInterface */ {
$names = $this->globNames($eventName, $manager->getEventNames());
// combine all globbing queue
$queue = new EventQueue();
foreach ($names as $n) {
if ($manager->hasEventQueue($n)) {
$queue = $queue->combine($manager->getEventQueue($n));
}
}
return $queue;
} | [
"protected",
"function",
"matchEventQueue",
"(",
"/*# string */",
"$",
"eventName",
",",
"EventManagerInterface",
"$",
"manager",
")",
"/*# : EventQueueInterface */",
"{",
"$",
"names",
"=",
"$",
"this",
"->",
"globNames",
"(",
"$",
"eventName",
",",
"$",
"manager",
"->",
"getEventNames",
"(",
")",
")",
";",
"// combine all globbing queue",
"$",
"queue",
"=",
"new",
"EventQueue",
"(",
")",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"n",
")",
"{",
"if",
"(",
"$",
"manager",
"->",
"hasEventQueue",
"(",
"$",
"n",
")",
")",
"{",
"$",
"queue",
"=",
"$",
"queue",
"->",
"combine",
"(",
"$",
"manager",
"->",
"getEventQueue",
"(",
"$",
"n",
")",
")",
";",
"}",
"}",
"return",
"$",
"queue",
";",
"}"
] | Match proper event queue with globbing support
Including queues with globbing event names
@param string $eventName event name to match
@param EventManagerInterface $manager which manager to look at
@return EventQueueInterface
@access protected | [
"Match",
"proper",
"event",
"queue",
"with",
"globbing",
"support"
] | 0044888fcc9b21584233c73cf20fc160e1b1f295 | https://github.com/phossa/phossa-event/blob/0044888fcc9b21584233c73cf20fc160e1b1f295/src/Phossa/Event/Interfaces/EventManagerTrait.php#L484-L499 | train |
phossa/phossa-event | src/Phossa/Event/Interfaces/EventManagerTrait.php | EventManagerTrait.globNames | protected function globNames(
/*# string */ $eventName,
array $names
)/*# : array */ {
$result = [];
foreach ($names as $n) {
if ($n === '*' || $n === $eventName || $eventName === '') {
$result[] = $n;
} elseif (strpos($n, '*') !== false) {
$regex = str_replace(array('.', '*'), array('[.]', '.*?'), $n);
if (preg_match('/^'.$regex.'$/', $eventName)) {
$result[] = $n;
}
}
}
return $result;
} | php | protected function globNames(
/*# string */ $eventName,
array $names
)/*# : array */ {
$result = [];
foreach ($names as $n) {
if ($n === '*' || $n === $eventName || $eventName === '') {
$result[] = $n;
} elseif (strpos($n, '*') !== false) {
$regex = str_replace(array('.', '*'), array('[.]', '.*?'), $n);
if (preg_match('/^'.$regex.'$/', $eventName)) {
$result[] = $n;
}
}
}
return $result;
} | [
"protected",
"function",
"globNames",
"(",
"/*# string */",
"$",
"eventName",
",",
"array",
"$",
"names",
")",
"/*# : array */",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"n",
")",
"{",
"if",
"(",
"$",
"n",
"===",
"'*'",
"||",
"$",
"n",
"===",
"$",
"eventName",
"||",
"$",
"eventName",
"===",
"''",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"n",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"n",
",",
"'*'",
")",
"!==",
"false",
")",
"{",
"$",
"regex",
"=",
"str_replace",
"(",
"array",
"(",
"'.'",
",",
"'*'",
")",
",",
"array",
"(",
"'[.]'",
",",
"'.*?'",
")",
",",
"$",
"n",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^'",
".",
"$",
"regex",
".",
"'$/'",
",",
"$",
"eventName",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"n",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Return those globbing event names based on the given one
e.g.
Matching specific name 'login.MobileFail' with those '*',
'login.*', 'login.*Fail'
@param string $eventName specific event name
@param string[] $names name array to search thru
@return string[]
@access protected | [
"Return",
"those",
"globbing",
"event",
"names",
"based",
"on",
"the",
"given",
"one"
] | 0044888fcc9b21584233c73cf20fc160e1b1f295 | https://github.com/phossa/phossa-event/blob/0044888fcc9b21584233c73cf20fc160e1b1f295/src/Phossa/Event/Interfaces/EventManagerTrait.php#L513-L529 | train |
Finesse/QueryScribe | src/QueryBricks/SelectTrait.php | SelectTrait.from | public function from($table, string $alias = null): self
{
return $this->table($table, $alias);
} | php | public function from($table, string $alias = null): self
{
return $this->table($table, $alias);
} | [
"public",
"function",
"from",
"(",
"$",
"table",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"table",
"(",
"$",
"table",
",",
"$",
"alias",
")",
";",
"}"
] | Table method alias
@see Query::table For reference
@param string|\Closure|Query|StatementInterface $table
@param string|null $alias
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Table",
"method",
"alias"
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/SelectTrait.php#L34-L37 | train |
Finesse/QueryScribe | src/QueryBricks/SelectTrait.php | SelectTrait.addSelect | public function addSelect($columns, string $alias = null): self
{
if (!is_array($columns)) {
if ($alias === null) {
$columns = [$columns];
} else {
$columns = [$alias => $columns];
}
}
foreach ($columns as $alias => $column) {
$column = $this->checkStringValue('Argument $columns['.$alias.']', $column);
if (is_string($alias)) {
$this->select[$alias] = $column;
} else {
$this->select[] = $column;
}
}
return $this;
} | php | public function addSelect($columns, string $alias = null): self
{
if (!is_array($columns)) {
if ($alias === null) {
$columns = [$columns];
} else {
$columns = [$alias => $columns];
}
}
foreach ($columns as $alias => $column) {
$column = $this->checkStringValue('Argument $columns['.$alias.']', $column);
if (is_string($alias)) {
$this->select[$alias] = $column;
} else {
$this->select[] = $column;
}
}
return $this;
} | [
"public",
"function",
"addSelect",
"(",
"$",
"columns",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"columns",
")",
")",
"{",
"if",
"(",
"$",
"alias",
"===",
"null",
")",
"{",
"$",
"columns",
"=",
"[",
"$",
"columns",
"]",
";",
"}",
"else",
"{",
"$",
"columns",
"=",
"[",
"$",
"alias",
"=>",
"$",
"columns",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"alias",
"=>",
"$",
"column",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $columns['",
".",
"$",
"alias",
".",
"']'",
",",
"$",
"column",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"alias",
")",
")",
"{",
"$",
"this",
"->",
"select",
"[",
"$",
"alias",
"]",
"=",
"$",
"column",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"select",
"[",
"]",
"=",
"$",
"column",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds column or columns to the SELECT section.
@param string|\Closure|Query|StatementInterface|string[]|\Closure[]|Query[]|StatementInterface[] $columns Columns
to add. If string or raw, one column is added. If array, many columns are added and string indexes are
treated as aliases.
@param string|null $alias Column alias name. Used only if the first argument is not an array.
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"column",
"or",
"columns",
"to",
"the",
"SELECT",
"section",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/SelectTrait.php#L50-L71 | train |
Finesse/QueryScribe | src/QueryBricks/SelectTrait.php | SelectTrait.addCount | public function addCount($column = '*', string $alias = null): self
{
return $this->addAggregate('COUNT', $column, $alias);
} | php | public function addCount($column = '*', string $alias = null): self
{
return $this->addAggregate('COUNT', $column, $alias);
} | [
"public",
"function",
"addCount",
"(",
"$",
"column",
"=",
"'*'",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addAggregate",
"(",
"'COUNT'",
",",
"$",
"column",
",",
"$",
"alias",
")",
";",
"}"
] | Adds a COUNT aggregate to the SELECT section.
@param string|\Closure|Query|StatementInterface $column Column to count
@param string|null $alias Aggregate alias name
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"a",
"COUNT",
"aggregate",
"to",
"the",
"SELECT",
"section",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/SelectTrait.php#L82-L85 | train |
Finesse/QueryScribe | src/QueryBricks/SelectTrait.php | SelectTrait.addAvg | public function addAvg($column, string $alias = null): self
{
return $this->addAggregate('AVG', $column, $alias);
} | php | public function addAvg($column, string $alias = null): self
{
return $this->addAggregate('AVG', $column, $alias);
} | [
"public",
"function",
"addAvg",
"(",
"$",
"column",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addAggregate",
"(",
"'AVG'",
",",
"$",
"column",
",",
"$",
"alias",
")",
";",
"}"
] | Adds a AVG aggregate to the SELECT section.
@param string|\Closure|Query|StatementInterface $column Column to get average
@param string|null $alias Aggregate alias name
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"a",
"AVG",
"aggregate",
"to",
"the",
"SELECT",
"section",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/SelectTrait.php#L96-L99 | train |
Finesse/QueryScribe | src/QueryBricks/SelectTrait.php | SelectTrait.addSum | public function addSum($column, string $alias = null): self
{
return $this->addAggregate('SUM', $column, $alias);
} | php | public function addSum($column, string $alias = null): self
{
return $this->addAggregate('SUM', $column, $alias);
} | [
"public",
"function",
"addSum",
"(",
"$",
"column",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addAggregate",
"(",
"'SUM'",
",",
"$",
"column",
",",
"$",
"alias",
")",
";",
"}"
] | Adds a SUM aggregate to the SELECT section.
@param string|\Closure|Query|StatementInterface $column Column to get sum
@param string|null $alias Aggregate alias name
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"a",
"SUM",
"aggregate",
"to",
"the",
"SELECT",
"section",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/SelectTrait.php#L110-L113 | train |
Finesse/QueryScribe | src/QueryBricks/SelectTrait.php | SelectTrait.addMin | public function addMin($column, string $alias = null): self
{
return $this->addAggregate('MIN', $column, $alias);
} | php | public function addMin($column, string $alias = null): self
{
return $this->addAggregate('MIN', $column, $alias);
} | [
"public",
"function",
"addMin",
"(",
"$",
"column",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addAggregate",
"(",
"'MIN'",
",",
"$",
"column",
",",
"$",
"alias",
")",
";",
"}"
] | Adds a MIN aggregate to the SELECT section.
@param string|\Closure|Query|StatementInterface $column Column to get min
@param string|null $alias Aggregate alias name
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"a",
"MIN",
"aggregate",
"to",
"the",
"SELECT",
"section",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/SelectTrait.php#L124-L127 | train |
Finesse/QueryScribe | src/QueryBricks/SelectTrait.php | SelectTrait.addMax | public function addMax($column, string $alias = null): self
{
return $this->addAggregate('MAX', $column, $alias);
} | php | public function addMax($column, string $alias = null): self
{
return $this->addAggregate('MAX', $column, $alias);
} | [
"public",
"function",
"addMax",
"(",
"$",
"column",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addAggregate",
"(",
"'MAX'",
",",
"$",
"column",
",",
"$",
"alias",
")",
";",
"}"
] | Adds a MAX aggregate to the SELECT section.
@param string|\Closure|Query|StatementInterface $column Column to get max
@param string|null $alias Aggregate alias name
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"a",
"MAX",
"aggregate",
"to",
"the",
"SELECT",
"section",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/SelectTrait.php#L138-L141 | train |
Finesse/QueryScribe | src/QueryBricks/SelectTrait.php | SelectTrait.addAggregate | protected function addAggregate(string $function, $column, string $alias = null): self
{
$column = $this->checkStringValue('Argument $column', $column);
$aggregate = new Aggregate($function, $column);
if ($alias === null) {
$this->select[] = $aggregate;
} else {
$this->select[$alias] = $aggregate;
}
return $this;
} | php | protected function addAggregate(string $function, $column, string $alias = null): self
{
$column = $this->checkStringValue('Argument $column', $column);
$aggregate = new Aggregate($function, $column);
if ($alias === null) {
$this->select[] = $aggregate;
} else {
$this->select[$alias] = $aggregate;
}
return $this;
} | [
"protected",
"function",
"addAggregate",
"(",
"string",
"$",
"function",
",",
"$",
"column",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $column'",
",",
"$",
"column",
")",
";",
"$",
"aggregate",
"=",
"new",
"Aggregate",
"(",
"$",
"function",
",",
"$",
"column",
")",
";",
"if",
"(",
"$",
"alias",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"select",
"[",
"]",
"=",
"$",
"aggregate",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"select",
"[",
"$",
"alias",
"]",
"=",
"$",
"aggregate",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds an arbitrary aggregate to the SELECT section.
@param string $function Aggregate function name
@param string|\Closure|Query|StatementInterface $column Column to count (not prefixed)
@param string|null $alias Aggregate alias name
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException | [
"Adds",
"an",
"arbitrary",
"aggregate",
"to",
"the",
"SELECT",
"section",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/SelectTrait.php#L153-L165 | train |
itkg/core | src/Itkg/Core/Command/DatabaseUpdate/Runner.php | Runner.run | public function run(Migration $migration, $executeQueries = false, $forcedRollback = false)
{
$this->migration = $migration;
try {
$this->playQueries($executeQueries);
if ($forcedRollback) {
$this->playRollbackQueries($executeQueries);
}
} catch (Exception $e) {
$this->playRollbackQueries($executeQueries);
throw $e;
}
} | php | public function run(Migration $migration, $executeQueries = false, $forcedRollback = false)
{
$this->migration = $migration;
try {
$this->playQueries($executeQueries);
if ($forcedRollback) {
$this->playRollbackQueries($executeQueries);
}
} catch (Exception $e) {
$this->playRollbackQueries($executeQueries);
throw $e;
}
} | [
"public",
"function",
"run",
"(",
"Migration",
"$",
"migration",
",",
"$",
"executeQueries",
"=",
"false",
",",
"$",
"forcedRollback",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"migration",
"=",
"$",
"migration",
";",
"try",
"{",
"$",
"this",
"->",
"playQueries",
"(",
"$",
"executeQueries",
")",
";",
"if",
"(",
"$",
"forcedRollback",
")",
"{",
"$",
"this",
"->",
"playRollbackQueries",
"(",
"$",
"executeQueries",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"playRollbackQueries",
"(",
"$",
"executeQueries",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] | Run a migration
@param Migration $migration
@param bool $executeQueries
@param bool $forcedRollback
@throws \Exception
@throws Migration\Exception
@return void | [
"Run",
"a",
"migration"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Command/DatabaseUpdate/Runner.php#L65-L79 | train |
itkg/core | src/Itkg/Core/Command/DatabaseUpdate/Runner.php | Runner.playQueries | private function playQueries($executeQueries = false)
{
foreach ($this->migration->getQueries() as $idx => $query) {
try {
$this->runQuery($query, $executeQueries);
} catch (\Exception $e) {
// Only throw if more than one query is played
if ($idx >= 1) {
throw new Exception($e->getMessage());
}
throw $e;
}
}
} | php | private function playQueries($executeQueries = false)
{
foreach ($this->migration->getQueries() as $idx => $query) {
try {
$this->runQuery($query, $executeQueries);
} catch (\Exception $e) {
// Only throw if more than one query is played
if ($idx >= 1) {
throw new Exception($e->getMessage());
}
throw $e;
}
}
} | [
"private",
"function",
"playQueries",
"(",
"$",
"executeQueries",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"migration",
"->",
"getQueries",
"(",
")",
"as",
"$",
"idx",
"=>",
"$",
"query",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"runQuery",
"(",
"$",
"query",
",",
"$",
"executeQueries",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// Only throw if more than one query is played",
"if",
"(",
"$",
"idx",
">=",
"1",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"}",
"}"
] | Play Script queries
@param bool $executeQueries
@throws Migration\Exception
@throws \Exception
@return void | [
"Play",
"Script",
"queries"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Command/DatabaseUpdate/Runner.php#L89-L103 | train |
itkg/core | src/Itkg/Core/Command/DatabaseUpdate/Runner.php | Runner.playRollbackQueries | private function playRollbackQueries($executeQueries = false)
{
foreach ($this->migration->getRollbackQueries() as $query) {
$this->runQuery($query, $executeQueries);
}
} | php | private function playRollbackQueries($executeQueries = false)
{
foreach ($this->migration->getRollbackQueries() as $query) {
$this->runQuery($query, $executeQueries);
}
} | [
"private",
"function",
"playRollbackQueries",
"(",
"$",
"executeQueries",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"migration",
"->",
"getRollbackQueries",
"(",
")",
"as",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"runQuery",
"(",
"$",
"query",
",",
"$",
"executeQueries",
")",
";",
"}",
"}"
] | Play rollback queries
@param bool $executeQueries
@return void | [
"Play",
"rollback",
"queries"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Command/DatabaseUpdate/Runner.php#L111-L116 | train |
itkg/core | src/Itkg/Core/Command/DatabaseUpdate/Runner.php | Runner.runQuery | private function runQuery(Query $query, $executeQueries = false)
{
$this->playedQueries[] = $query;
if ($executeQueries) {
$this->connection->executeQuery((string)$query);
}
} | php | private function runQuery(Query $query, $executeQueries = false)
{
$this->playedQueries[] = $query;
if ($executeQueries) {
$this->connection->executeQuery((string)$query);
}
} | [
"private",
"function",
"runQuery",
"(",
"Query",
"$",
"query",
",",
"$",
"executeQueries",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"playedQueries",
"[",
"]",
"=",
"$",
"query",
";",
"if",
"(",
"$",
"executeQueries",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"executeQuery",
"(",
"(",
"string",
")",
"$",
"query",
")",
";",
"}",
"}"
] | Run a query if execute query is true
else simply add query to played queries stack
@param Query $query
@param bool $executeQueries | [
"Run",
"a",
"query",
"if",
"execute",
"query",
"is",
"true",
"else",
"simply",
"add",
"query",
"to",
"played",
"queries",
"stack"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Command/DatabaseUpdate/Runner.php#L125-L131 | train |
Wedeto/IO | src/DirReader.php | DirReader.rewind | public function rewind()
{
$this->dir->rewind();
$this->iter = 0;
$this->hasNext();
$this->cur_entry = $this->next_entry;
$this->next_entry = null;
} | php | public function rewind()
{
$this->dir->rewind();
$this->iter = 0;
$this->hasNext();
$this->cur_entry = $this->next_entry;
$this->next_entry = null;
} | [
"public",
"function",
"rewind",
"(",
")",
"{",
"$",
"this",
"->",
"dir",
"->",
"rewind",
"(",
")",
";",
"$",
"this",
"->",
"iter",
"=",
"0",
";",
"$",
"this",
"->",
"hasNext",
"(",
")",
";",
"$",
"this",
"->",
"cur_entry",
"=",
"$",
"this",
"->",
"next_entry",
";",
"$",
"this",
"->",
"next_entry",
"=",
"null",
";",
"}"
] | Rewind the directory reader to the start | [
"Rewind",
"the",
"directory",
"reader",
"to",
"the",
"start"
] | 4cfeaedd1bd9bda3097d18cb12233a4afecb2e85 | https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/DirReader.php#L106-L113 | train |
ZhukV/AppleModel | src/Apple/Model/Software.php | Software.setPlatform | public function setPlatform($platform)
{
if (!in_array($platform, array(Software::PLATFORM_MAC, Software::PLATFORM_IOS), true)) {
throw new \InvalidArgumentException(sprintf('Undefined software platform "%s".', $platform));
}
$this->platform = $platform;
return $this;
} | php | public function setPlatform($platform)
{
if (!in_array($platform, array(Software::PLATFORM_MAC, Software::PLATFORM_IOS), true)) {
throw new \InvalidArgumentException(sprintf('Undefined software platform "%s".', $platform));
}
$this->platform = $platform;
return $this;
} | [
"public",
"function",
"setPlatform",
"(",
"$",
"platform",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"platform",
",",
"array",
"(",
"Software",
"::",
"PLATFORM_MAC",
",",
"Software",
"::",
"PLATFORM_IOS",
")",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Undefined software platform \"%s\".'",
",",
"$",
"platform",
")",
")",
";",
"}",
"$",
"this",
"->",
"platform",
"=",
"$",
"platform",
";",
"return",
"$",
"this",
";",
"}"
] | Set software platform
@param integer $platform
@return Software
@throws \InvalidArgumentException | [
"Set",
"software",
"platform"
] | 3ab06d560b7c442b8ebafdd95d1d2523b40ef903 | https://github.com/ZhukV/AppleModel/blob/3ab06d560b7c442b8ebafdd95d1d2523b40ef903/src/Apple/Model/Software.php#L235-L244 | train |
ZhukV/AppleModel | src/Apple/Model/Software.php | Software.setUserRatingCount | public function setUserRatingCount($userRatingCount)
{
$userRatingCount = (int) $userRatingCount;
if ($userRatingCount < 0) {
throw new \InvalidArgumentException(sprintf(
'User rating can\'t be less than "0", "%s" given.',
$userRatingCount
));
}
$this->userRatingCount = (int) $userRatingCount;
return $this;
} | php | public function setUserRatingCount($userRatingCount)
{
$userRatingCount = (int) $userRatingCount;
if ($userRatingCount < 0) {
throw new \InvalidArgumentException(sprintf(
'User rating can\'t be less than "0", "%s" given.',
$userRatingCount
));
}
$this->userRatingCount = (int) $userRatingCount;
return $this;
} | [
"public",
"function",
"setUserRatingCount",
"(",
"$",
"userRatingCount",
")",
"{",
"$",
"userRatingCount",
"=",
"(",
"int",
")",
"$",
"userRatingCount",
";",
"if",
"(",
"$",
"userRatingCount",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'User rating can\\'t be less than \"0\", \"%s\" given.'",
",",
"$",
"userRatingCount",
")",
")",
";",
"}",
"$",
"this",
"->",
"userRatingCount",
"=",
"(",
"int",
")",
"$",
"userRatingCount",
";",
"return",
"$",
"this",
";",
"}"
] | Set user rating count
@param integer $userRatingCount
@return Software
@throws \InvalidArgumentException | [
"Set",
"user",
"rating",
"count"
] | 3ab06d560b7c442b8ebafdd95d1d2523b40ef903 | https://github.com/ZhukV/AppleModel/blob/3ab06d560b7c442b8ebafdd95d1d2523b40ef903/src/Apple/Model/Software.php#L712-L726 | train |
ZhukV/AppleModel | src/Apple/Model/Software.php | Software.setAverageUserRating | public function setAverageUserRating($averageUserRating)
{
$averageUserRating = (float) $averageUserRating;
if ($averageUserRating < 0 || $averageUserRating > 5) {
throw new \InvalidArgumentException(sprintf(
'Average user rating must be between 0 and 5, "%s" given.',
$averageUserRating
));
}
if ($averageUserRating && fmod($averageUserRating, 0.5)) {
throw new \InvalidArgumentException(sprintf(
'Rating must be division by 0.5, "%s" given.',
$averageUserRating
));
}
$this->averageUserRating = $averageUserRating;
return $this;
} | php | public function setAverageUserRating($averageUserRating)
{
$averageUserRating = (float) $averageUserRating;
if ($averageUserRating < 0 || $averageUserRating > 5) {
throw new \InvalidArgumentException(sprintf(
'Average user rating must be between 0 and 5, "%s" given.',
$averageUserRating
));
}
if ($averageUserRating && fmod($averageUserRating, 0.5)) {
throw new \InvalidArgumentException(sprintf(
'Rating must be division by 0.5, "%s" given.',
$averageUserRating
));
}
$this->averageUserRating = $averageUserRating;
return $this;
} | [
"public",
"function",
"setAverageUserRating",
"(",
"$",
"averageUserRating",
")",
"{",
"$",
"averageUserRating",
"=",
"(",
"float",
")",
"$",
"averageUserRating",
";",
"if",
"(",
"$",
"averageUserRating",
"<",
"0",
"||",
"$",
"averageUserRating",
">",
"5",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Average user rating must be between 0 and 5, \"%s\" given.'",
",",
"$",
"averageUserRating",
")",
")",
";",
"}",
"if",
"(",
"$",
"averageUserRating",
"&&",
"fmod",
"(",
"$",
"averageUserRating",
",",
"0.5",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Rating must be division by 0.5, \"%s\" given.'",
",",
"$",
"averageUserRating",
")",
")",
";",
"}",
"$",
"this",
"->",
"averageUserRating",
"=",
"$",
"averageUserRating",
";",
"return",
"$",
"this",
";",
"}"
] | Set user average rating
@param float $averageUserRating
@return Software
@throws \InvalidArgumentException | [
"Set",
"user",
"average",
"rating"
] | 3ab06d560b7c442b8ebafdd95d1d2523b40ef903 | https://github.com/ZhukV/AppleModel/blob/3ab06d560b7c442b8ebafdd95d1d2523b40ef903/src/Apple/Model/Software.php#L747-L768 | train |
ZhukV/AppleModel | src/Apple/Model/Software.php | Software.setUserRatingCountCurrent | public function setUserRatingCountCurrent($userRatingCountCurrent)
{
$userRatingCountCurrent = (int) $userRatingCountCurrent;
if ($userRatingCountCurrent < 0) {
throw new \InvalidArgumentException(sprintf(
'User rating can\'t be less than "0", "%s" given.',
$userRatingCountCurrent
));
}
$this->userRatingCountCurrent = (int) $userRatingCountCurrent;
return $this;
} | php | public function setUserRatingCountCurrent($userRatingCountCurrent)
{
$userRatingCountCurrent = (int) $userRatingCountCurrent;
if ($userRatingCountCurrent < 0) {
throw new \InvalidArgumentException(sprintf(
'User rating can\'t be less than "0", "%s" given.',
$userRatingCountCurrent
));
}
$this->userRatingCountCurrent = (int) $userRatingCountCurrent;
return $this;
} | [
"public",
"function",
"setUserRatingCountCurrent",
"(",
"$",
"userRatingCountCurrent",
")",
"{",
"$",
"userRatingCountCurrent",
"=",
"(",
"int",
")",
"$",
"userRatingCountCurrent",
";",
"if",
"(",
"$",
"userRatingCountCurrent",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'User rating can\\'t be less than \"0\", \"%s\" given.'",
",",
"$",
"userRatingCountCurrent",
")",
")",
";",
"}",
"$",
"this",
"->",
"userRatingCountCurrent",
"=",
"(",
"int",
")",
"$",
"userRatingCountCurrent",
";",
"return",
"$",
"this",
";",
"}"
] | Set user rating count for current version
@param integer $userRatingCountCurrent
@return Software
@throws \InvalidArgumentException | [
"Set",
"user",
"rating",
"count",
"for",
"current",
"version"
] | 3ab06d560b7c442b8ebafdd95d1d2523b40ef903 | https://github.com/ZhukV/AppleModel/blob/3ab06d560b7c442b8ebafdd95d1d2523b40ef903/src/Apple/Model/Software.php#L789-L803 | train |
ZhukV/AppleModel | src/Apple/Model/Software.php | Software.setAverageUserRatingCurrent | public function setAverageUserRatingCurrent($averageUserRatingCurrent)
{
$averageUserRatingCurrent = (float) $averageUserRatingCurrent;
if ($averageUserRatingCurrent < 0 || $averageUserRatingCurrent > 5) {
throw new \InvalidArgumentException(sprintf(
'Average user rating must be between 0 and 5, "%s" given.',
$averageUserRatingCurrent
));
}
if ($averageUserRatingCurrent && fmod($averageUserRatingCurrent, 0.5)) {
throw new \InvalidArgumentException(sprintf(
'Rating must be division by 0.5, "%s" given.',
$averageUserRatingCurrent
));
}
$this->averageUserRatingCurrent = $averageUserRatingCurrent;
return $this;
} | php | public function setAverageUserRatingCurrent($averageUserRatingCurrent)
{
$averageUserRatingCurrent = (float) $averageUserRatingCurrent;
if ($averageUserRatingCurrent < 0 || $averageUserRatingCurrent > 5) {
throw new \InvalidArgumentException(sprintf(
'Average user rating must be between 0 and 5, "%s" given.',
$averageUserRatingCurrent
));
}
if ($averageUserRatingCurrent && fmod($averageUserRatingCurrent, 0.5)) {
throw new \InvalidArgumentException(sprintf(
'Rating must be division by 0.5, "%s" given.',
$averageUserRatingCurrent
));
}
$this->averageUserRatingCurrent = $averageUserRatingCurrent;
return $this;
} | [
"public",
"function",
"setAverageUserRatingCurrent",
"(",
"$",
"averageUserRatingCurrent",
")",
"{",
"$",
"averageUserRatingCurrent",
"=",
"(",
"float",
")",
"$",
"averageUserRatingCurrent",
";",
"if",
"(",
"$",
"averageUserRatingCurrent",
"<",
"0",
"||",
"$",
"averageUserRatingCurrent",
">",
"5",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Average user rating must be between 0 and 5, \"%s\" given.'",
",",
"$",
"averageUserRatingCurrent",
")",
")",
";",
"}",
"if",
"(",
"$",
"averageUserRatingCurrent",
"&&",
"fmod",
"(",
"$",
"averageUserRatingCurrent",
",",
"0.5",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Rating must be division by 0.5, \"%s\" given.'",
",",
"$",
"averageUserRatingCurrent",
")",
")",
";",
"}",
"$",
"this",
"->",
"averageUserRatingCurrent",
"=",
"$",
"averageUserRatingCurrent",
";",
"return",
"$",
"this",
";",
"}"
] | Set average user rating for current version
@param float $averageUserRatingCurrent
@return Software
@throws \InvalidArgumentException | [
"Set",
"average",
"user",
"rating",
"for",
"current",
"version"
] | 3ab06d560b7c442b8ebafdd95d1d2523b40ef903 | https://github.com/ZhukV/AppleModel/blob/3ab06d560b7c442b8ebafdd95d1d2523b40ef903/src/Apple/Model/Software.php#L824-L845 | train |
ciims/ciims-modules-api | controllers/EventController.php | EventController.actionIndex | public function actionIndex()
{
$model = new Events('search');
$model->unsetAttributes();
if (isset($_GET['Event']))
$model->attributes = $_GET['Event'];
$dataProvider = $model->search();
$dataProvider->pagination = array(
'pageVar' => 'page'
);
// Throw a 404 if we exceed the number of available results
if ($dataProvider->totalItemCount == 0 || ($dataProvider->totalItemCount / ($dataProvider->itemCount * Cii::get($_GET, 'page', 1))) < 1)
throw new CHttpException(404, Yii::t('Api.events', 'No results found'));
$response = array();
foreach ($dataProvider->getData() as $content)
$response[] = $content->getAPIAttributes();
return array(
'count' => $model->count(), // This to the TOTAL count (as if pagination DNE)
'data' => $response // This is JUST the paginated response
);
} | php | public function actionIndex()
{
$model = new Events('search');
$model->unsetAttributes();
if (isset($_GET['Event']))
$model->attributes = $_GET['Event'];
$dataProvider = $model->search();
$dataProvider->pagination = array(
'pageVar' => 'page'
);
// Throw a 404 if we exceed the number of available results
if ($dataProvider->totalItemCount == 0 || ($dataProvider->totalItemCount / ($dataProvider->itemCount * Cii::get($_GET, 'page', 1))) < 1)
throw new CHttpException(404, Yii::t('Api.events', 'No results found'));
$response = array();
foreach ($dataProvider->getData() as $content)
$response[] = $content->getAPIAttributes();
return array(
'count' => $model->count(), // This to the TOTAL count (as if pagination DNE)
'data' => $response // This is JUST the paginated response
);
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"Events",
"(",
"'search'",
")",
";",
"$",
"model",
"->",
"unsetAttributes",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'Event'",
"]",
")",
")",
"$",
"model",
"->",
"attributes",
"=",
"$",
"_GET",
"[",
"'Event'",
"]",
";",
"$",
"dataProvider",
"=",
"$",
"model",
"->",
"search",
"(",
")",
";",
"$",
"dataProvider",
"->",
"pagination",
"=",
"array",
"(",
"'pageVar'",
"=>",
"'page'",
")",
";",
"// Throw a 404 if we exceed the number of available results\r",
"if",
"(",
"$",
"dataProvider",
"->",
"totalItemCount",
"==",
"0",
"||",
"(",
"$",
"dataProvider",
"->",
"totalItemCount",
"/",
"(",
"$",
"dataProvider",
"->",
"itemCount",
"*",
"Cii",
"::",
"get",
"(",
"$",
"_GET",
",",
"'page'",
",",
"1",
")",
")",
")",
"<",
"1",
")",
"throw",
"new",
"CHttpException",
"(",
"404",
",",
"Yii",
"::",
"t",
"(",
"'Api.events'",
",",
"'No results found'",
")",
")",
";",
"$",
"response",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"dataProvider",
"->",
"getData",
"(",
")",
"as",
"$",
"content",
")",
"$",
"response",
"[",
"]",
"=",
"$",
"content",
"->",
"getAPIAttributes",
"(",
")",
";",
"return",
"array",
"(",
"'count'",
"=>",
"$",
"model",
"->",
"count",
"(",
")",
",",
"// This to the TOTAL count (as if pagination DNE)\r",
"'data'",
"=>",
"$",
"response",
"// This is JUST the paginated response\r",
")",
";",
"}"
] | Provides functionality to search through events | [
"Provides",
"functionality",
"to",
"search",
"through",
"events"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/EventController.php#L25-L51 | train |
ciims/ciims-modules-api | controllers/EventController.php | EventController.actionPageviews | public function actionPageviews()
{
$models = Events::model()->groupByUrl()->findAll();
$response = array();
foreach ($models as $model)
$response[] = array(
'uri' => $model->uri,
'count' => $model->id
);
return $response;
} | php | public function actionPageviews()
{
$models = Events::model()->groupByUrl()->findAll();
$response = array();
foreach ($models as $model)
$response[] = array(
'uri' => $model->uri,
'count' => $model->id
);
return $response;
} | [
"public",
"function",
"actionPageviews",
"(",
")",
"{",
"$",
"models",
"=",
"Events",
"::",
"model",
"(",
")",
"->",
"groupByUrl",
"(",
")",
"->",
"findAll",
"(",
")",
";",
"$",
"response",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"$",
"response",
"[",
"]",
"=",
"array",
"(",
"'uri'",
"=>",
"$",
"model",
"->",
"uri",
",",
"'count'",
"=>",
"$",
"model",
"->",
"id",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Shows pageview results
@return array | [
"Shows",
"pageview",
"results"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/EventController.php#L57-L69 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/PrimaryKey.php | PrimaryKey.setColumnNames | public function setColumnNames(array $columnNames)
{
$this->columnNames = array();
foreach ($columnNames as $columnName) {
$this->addColumnName($columnName);
}
} | php | public function setColumnNames(array $columnNames)
{
$this->columnNames = array();
foreach ($columnNames as $columnName) {
$this->addColumnName($columnName);
}
} | [
"public",
"function",
"setColumnNames",
"(",
"array",
"$",
"columnNames",
")",
"{",
"$",
"this",
"->",
"columnNames",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"columnNames",
"as",
"$",
"columnName",
")",
"{",
"$",
"this",
"->",
"addColumnName",
"(",
"$",
"columnName",
")",
";",
"}",
"}"
] | Sets the column names.
@param array $columnNames The column names. | [
"Sets",
"the",
"column",
"names",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/PrimaryKey.php#L56-L63 | train |
black-lamp/blcms-cart | frontend/controllers/OrderController.php | OrderController.actionShowOrderList | public function actionShowOrderList() {
if (!\Yii::$app->user->isGuest) {
$userOrders = \Yii::$app->cart->getAllUserOrders();
$filterModel = new OrderSearch();
$dataProvider = $filterModel->search(Yii::$app->request->get());
return $this->render('order-list', [
'userOrders' => $userOrders,
'filterModel' => $filterModel,
'dataProvider' => $dataProvider,
]);
}
else throw new NotFoundHttpException();
} | php | public function actionShowOrderList() {
if (!\Yii::$app->user->isGuest) {
$userOrders = \Yii::$app->cart->getAllUserOrders();
$filterModel = new OrderSearch();
$dataProvider = $filterModel->search(Yii::$app->request->get());
return $this->render('order-list', [
'userOrders' => $userOrders,
'filterModel' => $filterModel,
'dataProvider' => $dataProvider,
]);
}
else throw new NotFoundHttpException();
} | [
"public",
"function",
"actionShowOrderList",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"userOrders",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"cart",
"->",
"getAllUserOrders",
"(",
")",
";",
"$",
"filterModel",
"=",
"new",
"OrderSearch",
"(",
")",
";",
"$",
"dataProvider",
"=",
"$",
"filterModel",
"->",
"search",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"get",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'order-list'",
",",
"[",
"'userOrders'",
"=>",
"$",
"userOrders",
",",
"'filterModel'",
"=>",
"$",
"filterModel",
",",
"'dataProvider'",
"=>",
"$",
"dataProvider",
",",
"]",
")",
";",
"}",
"else",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}"
] | Return list of user orders.
@return array Order
@throws NotFoundHttpException | [
"Return",
"list",
"of",
"user",
"orders",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/frontend/controllers/OrderController.php#L24-L37 | train |
wobblecode/WobbleCodeUserBundle | Manager/RoleManager.php | RoleManager.switchOrganization | public function switchOrganization(User $user, OrganizationInterface $organization)
{
$role = $this->getOrganizationRole($user, $organization);
if ($role == false && !$this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
throw new NotFoundHttpException('Roles in organization not found');
}
$userRoles = $this->removeOrganizationRoles($user->getRoles());
$user->setRoles(array_merge($userRoles, $role->getroles()));
$user->setActiveOrganization($organization);
$user->setActiveRole($role);
$this->dm->persist($user);
$this->dm->flush();
$token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken(
$user,
null,
'main',
$user->getRoles()
);
$this->tokenStorage->setToken($token);
$this->userProvider->refreshUser($user);
} | php | public function switchOrganization(User $user, OrganizationInterface $organization)
{
$role = $this->getOrganizationRole($user, $organization);
if ($role == false && !$this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
throw new NotFoundHttpException('Roles in organization not found');
}
$userRoles = $this->removeOrganizationRoles($user->getRoles());
$user->setRoles(array_merge($userRoles, $role->getroles()));
$user->setActiveOrganization($organization);
$user->setActiveRole($role);
$this->dm->persist($user);
$this->dm->flush();
$token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken(
$user,
null,
'main',
$user->getRoles()
);
$this->tokenStorage->setToken($token);
$this->userProvider->refreshUser($user);
} | [
"public",
"function",
"switchOrganization",
"(",
"User",
"$",
"user",
",",
"OrganizationInterface",
"$",
"organization",
")",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"getOrganizationRole",
"(",
"$",
"user",
",",
"$",
"organization",
")",
";",
"if",
"(",
"$",
"role",
"==",
"false",
"&&",
"!",
"$",
"this",
"->",
"authorizationChecker",
"->",
"isGranted",
"(",
"'ROLE_SUPER_ADMIN'",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'Roles in organization not found'",
")",
";",
"}",
"$",
"userRoles",
"=",
"$",
"this",
"->",
"removeOrganizationRoles",
"(",
"$",
"user",
"->",
"getRoles",
"(",
")",
")",
";",
"$",
"user",
"->",
"setRoles",
"(",
"array_merge",
"(",
"$",
"userRoles",
",",
"$",
"role",
"->",
"getroles",
"(",
")",
")",
")",
";",
"$",
"user",
"->",
"setActiveOrganization",
"(",
"$",
"organization",
")",
";",
"$",
"user",
"->",
"setActiveRole",
"(",
"$",
"role",
")",
";",
"$",
"this",
"->",
"dm",
"->",
"persist",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"dm",
"->",
"flush",
"(",
")",
";",
"$",
"token",
"=",
"new",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Security",
"\\",
"Core",
"\\",
"Authentication",
"\\",
"Token",
"\\",
"UsernamePasswordToken",
"(",
"$",
"user",
",",
"null",
",",
"'main'",
",",
"$",
"user",
"->",
"getRoles",
"(",
")",
")",
";",
"$",
"this",
"->",
"tokenStorage",
"->",
"setToken",
"(",
"$",
"token",
")",
";",
"$",
"this",
"->",
"userProvider",
"->",
"refreshUser",
"(",
"$",
"user",
")",
";",
"}"
] | Switch the working organization of logged user
@todo update security context calls. Deprecated since version 2.6, to be
removed in 3.0. Use AuthorizationCheckerInterface::isGranted() instead.
http://symfony.com/blog/new-in-symfony-2-6-security-component-improvements
@param User $user
@param OrganizationInterface $organization
@return void | [
"Switch",
"the",
"working",
"organization",
"of",
"logged",
"user"
] | 7b8206f8b4a50fbc61f7bfe4f83eb466cad96440 | https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/Manager/RoleManager.php#L89-L115 | train |
wobblecode/WobbleCodeUserBundle | Manager/RoleManager.php | RoleManager.getOrganizationRole | public function getOrganizationRole($user, $organization)
{
return $this->dm->getRepository('WobbleCodeUserBundle:Role')->findOneBy(
[
'organization.$id' => new \MongoId($organization->getId()),
'user.$id' => new \MongoId($user->getId())
]
);
} | php | public function getOrganizationRole($user, $organization)
{
return $this->dm->getRepository('WobbleCodeUserBundle:Role')->findOneBy(
[
'organization.$id' => new \MongoId($organization->getId()),
'user.$id' => new \MongoId($user->getId())
]
);
} | [
"public",
"function",
"getOrganizationRole",
"(",
"$",
"user",
",",
"$",
"organization",
")",
"{",
"return",
"$",
"this",
"->",
"dm",
"->",
"getRepository",
"(",
"'WobbleCodeUserBundle:Role'",
")",
"->",
"findOneBy",
"(",
"[",
"'organization.$id'",
"=>",
"new",
"\\",
"MongoId",
"(",
"$",
"organization",
"->",
"getId",
"(",
")",
")",
",",
"'user.$id'",
"=>",
"new",
"\\",
"MongoId",
"(",
"$",
"user",
"->",
"getId",
"(",
")",
")",
"]",
")",
";",
"}"
] | Get user role definition within an organization
@param User $user
@param OrganizationInterface $organizatgion
@return (Role|false) | [
"Get",
"user",
"role",
"definition",
"within",
"an",
"organization"
] | 7b8206f8b4a50fbc61f7bfe4f83eb466cad96440 | https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/Manager/RoleManager.php#L141-L149 | train |
Dhii/config | src/DereferencingConfigMapFactory.php | DereferencingConfigMapFactory._createProduct | protected function _createProduct($config, $data)
{
$className = static::PRODUCT_CLASS_NAME;
$referenceContainer = $this->_getReferenceContainer($config);
return new $className($data, $referenceContainer);
} | php | protected function _createProduct($config, $data)
{
$className = static::PRODUCT_CLASS_NAME;
$referenceContainer = $this->_getReferenceContainer($config);
return new $className($data, $referenceContainer);
} | [
"protected",
"function",
"_createProduct",
"(",
"$",
"config",
",",
"$",
"data",
")",
"{",
"$",
"className",
"=",
"static",
"::",
"PRODUCT_CLASS_NAME",
";",
"$",
"referenceContainer",
"=",
"$",
"this",
"->",
"_getReferenceContainer",
"(",
"$",
"config",
")",
";",
"return",
"new",
"$",
"className",
"(",
"$",
"data",
",",
"$",
"referenceContainer",
")",
";",
"}"
] | Creates a new factory product.
@since [*next-version*]
@param array|ArrayAccess|BaseContainerInterface|stdClass|null $config The data for the new product instance.
@param array|stdClass|ArrayObject $data The data for the new product instance.
@throws InvalidArgumentException If the data or the config is invalid.
@throws RuntimeException If the product could not be created.
@return mixed The new factory product. | [
"Creates",
"a",
"new",
"factory",
"product",
"."
] | 1ab9a7ccf9c0ebd7c6fcbce600b4c00b52b2fdcf | https://github.com/Dhii/config/blob/1ab9a7ccf9c0ebd7c6fcbce600b4c00b52b2fdcf/src/DereferencingConfigMapFactory.php#L124-L130 | train |
Dhii/config | src/DereferencingConfigMapFactory.php | DereferencingConfigMapFactory._getReferenceContainer | protected function _getReferenceContainer($config)
{
try {
$container = $this->_containerHas($config, static::K_REFERENCE_CONTAINER)
? $this->_containerGet($config, static::K_REFERENCE_CONTAINER)
: $this->_getContainer();
} catch (RootException $e) {
throw $this->_createRuntimeException('Could not retrieve a valid referencing container');
}
return $container;
} | php | protected function _getReferenceContainer($config)
{
try {
$container = $this->_containerHas($config, static::K_REFERENCE_CONTAINER)
? $this->_containerGet($config, static::K_REFERENCE_CONTAINER)
: $this->_getContainer();
} catch (RootException $e) {
throw $this->_createRuntimeException('Could not retrieve a valid referencing container');
}
return $container;
} | [
"protected",
"function",
"_getReferenceContainer",
"(",
"$",
"config",
")",
"{",
"try",
"{",
"$",
"container",
"=",
"$",
"this",
"->",
"_containerHas",
"(",
"$",
"config",
",",
"static",
"::",
"K_REFERENCE_CONTAINER",
")",
"?",
"$",
"this",
"->",
"_containerGet",
"(",
"$",
"config",
",",
"static",
"::",
"K_REFERENCE_CONTAINER",
")",
":",
"$",
"this",
"->",
"_getContainer",
"(",
")",
";",
"}",
"catch",
"(",
"RootException",
"$",
"e",
")",
"{",
"throw",
"$",
"this",
"->",
"_createRuntimeException",
"(",
"'Could not retrieve a valid referencing container'",
")",
";",
"}",
"return",
"$",
"container",
";",
"}"
] | Retrieves the reference container to create the child with.
@since [*next-version*]
@param array|ArrayAccess|BaseContainerInterface|stdClass|null $config The config of the product, the child of which to get the container for.
@throws RuntimeException If the reference container could not be retrieved.
@return BaseContainerInterface|null The reference container, if any. | [
"Retrieves",
"the",
"reference",
"container",
"to",
"create",
"the",
"child",
"with",
"."
] | 1ab9a7ccf9c0ebd7c6fcbce600b4c00b52b2fdcf | https://github.com/Dhii/config/blob/1ab9a7ccf9c0ebd7c6fcbce600b4c00b52b2fdcf/src/DereferencingConfigMapFactory.php#L153-L164 | train |
bytic/orm | src/Traits/ActiveRecord/ActiveRecordsTrait.php | ActiveRecordsTrait.insert | public function insert($model, $onDuplicate = false)
{
$query = $this->insertQuery($model, $onDuplicate);
$query->execute();
return $this->getDB()->lastInsertID();
} | php | public function insert($model, $onDuplicate = false)
{
$query = $this->insertQuery($model, $onDuplicate);
$query->execute();
return $this->getDB()->lastInsertID();
} | [
"public",
"function",
"insert",
"(",
"$",
"model",
",",
"$",
"onDuplicate",
"=",
"false",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"insertQuery",
"(",
"$",
"model",
",",
"$",
"onDuplicate",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getDB",
"(",
")",
"->",
"lastInsertID",
"(",
")",
";",
"}"
] | Inserts a Record into the database
@param Record $model
@param array|bool $onDuplicate
@return integer | [
"Inserts",
"a",
"Record",
"into",
"the",
"database"
] | 8d9a79b47761af0bfd9b8d1d28c83221dcac0de0 | https://github.com/bytic/orm/blob/8d9a79b47761af0bfd9b8d1d28c83221dcac0de0/src/Traits/ActiveRecord/ActiveRecordsTrait.php#L110-L116 | train |
bytic/orm | src/Traits/ActiveRecord/ActiveRecordsTrait.php | ActiveRecordsTrait.update | public function update(Record $model)
{
$query = $this->updateQuery($model);
if ($query) {
return $query->execute();
}
return false;
} | php | public function update(Record $model)
{
$query = $this->updateQuery($model);
if ($query) {
return $query->execute();
}
return false;
} | [
"public",
"function",
"update",
"(",
"Record",
"$",
"model",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"updateQuery",
"(",
"$",
"model",
")",
";",
"if",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Updates a Record's database entry
@param Record $model
@return bool|Result | [
"Updates",
"a",
"Record",
"s",
"database",
"entry"
] | 8d9a79b47761af0bfd9b8d1d28c83221dcac0de0 | https://github.com/bytic/orm/blob/8d9a79b47761af0bfd9b8d1d28c83221dcac0de0/src/Traits/ActiveRecord/ActiveRecordsTrait.php#L150-L159 | train |
bytic/orm | src/Traits/ActiveRecord/ActiveRecordsTrait.php | ActiveRecordsTrait.save | public function save(Record $model)
{
$pk = $this->getPrimaryKey();
if (isset($model->{$pk})) {
$model->update();
return $model->{$pk};
} else {
/** @var Record $previous */
$previous = $model->exists();
if ($previous) {
$data = $model->toArray();
if ($data) {
$previous->writeData($model->toArray());
}
$previous->update();
$model->writeData($previous->toArray());
return $model->getPrimaryKey();
}
}
$model->insert();
return $model->getPrimaryKey();
} | php | public function save(Record $model)
{
$pk = $this->getPrimaryKey();
if (isset($model->{$pk})) {
$model->update();
return $model->{$pk};
} else {
/** @var Record $previous */
$previous = $model->exists();
if ($previous) {
$data = $model->toArray();
if ($data) {
$previous->writeData($model->toArray());
}
$previous->update();
$model->writeData($previous->toArray());
return $model->getPrimaryKey();
}
}
$model->insert();
return $model->getPrimaryKey();
} | [
"public",
"function",
"save",
"(",
"Record",
"$",
"model",
")",
"{",
"$",
"pk",
"=",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"model",
"->",
"{",
"$",
"pk",
"}",
")",
")",
"{",
"$",
"model",
"->",
"update",
"(",
")",
";",
"return",
"$",
"model",
"->",
"{",
"$",
"pk",
"}",
";",
"}",
"else",
"{",
"/** @var Record $previous */",
"$",
"previous",
"=",
"$",
"model",
"->",
"exists",
"(",
")",
";",
"if",
"(",
"$",
"previous",
")",
"{",
"$",
"data",
"=",
"$",
"model",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"previous",
"->",
"writeData",
"(",
"$",
"model",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"$",
"previous",
"->",
"update",
"(",
")",
";",
"$",
"model",
"->",
"writeData",
"(",
"$",
"previous",
"->",
"toArray",
"(",
")",
")",
";",
"return",
"$",
"model",
"->",
"getPrimaryKey",
"(",
")",
";",
"}",
"}",
"$",
"model",
"->",
"insert",
"(",
")",
";",
"return",
"$",
"model",
"->",
"getPrimaryKey",
"(",
")",
";",
"}"
] | Saves a Record's database entry
@param Record $model
@return mixed | [
"Saves",
"a",
"Record",
"s",
"database",
"entry"
] | 8d9a79b47761af0bfd9b8d1d28c83221dcac0de0 | https://github.com/bytic/orm/blob/8d9a79b47761af0bfd9b8d1d28c83221dcac0de0/src/Traits/ActiveRecord/ActiveRecordsTrait.php#L203-L232 | train |
sil-project/SeedBatchBundle | src/Entity/OuterExtension/HasSeedBatches.php | HasSeedBatches.addSeedBatch | public function addSeedBatch($seedBatch)
{
$this->seedBatches[] = $seedBatch;
if (method_exists(get_class($this), 'setProducer')) {
$seedBatch->setProducer($this);
}
return $this;
} | php | public function addSeedBatch($seedBatch)
{
$this->seedBatches[] = $seedBatch;
if (method_exists(get_class($this), 'setProducer')) {
$seedBatch->setProducer($this);
}
return $this;
} | [
"public",
"function",
"addSeedBatch",
"(",
"$",
"seedBatch",
")",
"{",
"$",
"this",
"->",
"seedBatches",
"[",
"]",
"=",
"$",
"seedBatch",
";",
"if",
"(",
"method_exists",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"'setProducer'",
")",
")",
"{",
"$",
"seedBatch",
"->",
"setProducer",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add seed batch.
@param SeedBatch $seedBatch
@return self | [
"Add",
"seed",
"batch",
"."
] | a2640b5359fe31d3bdb9c9fa2f72141ac841729c | https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/Entity/OuterExtension/HasSeedBatches.php#L32-L41 | train |
itkg/core | src/Itkg/Core/Cache/Listener/CacheListener.php | CacheListener.fetchEntityFromCache | public function fetchEntityFromCache(EntityLoadEvent $event)
{
$entity = $event->getEntity();
// Check cache
if (false !== $data = $this->cache->get($entity)) {
// Set data from cache to entity object
$entity->setDataFromCache($data);
$entity->setIsLoaded(true);
$this->dispatcher->dispatch('cache.load', new CacheEvent($entity));
}
} | php | public function fetchEntityFromCache(EntityLoadEvent $event)
{
$entity = $event->getEntity();
// Check cache
if (false !== $data = $this->cache->get($entity)) {
// Set data from cache to entity object
$entity->setDataFromCache($data);
$entity->setIsLoaded(true);
$this->dispatcher->dispatch('cache.load', new CacheEvent($entity));
}
} | [
"public",
"function",
"fetchEntityFromCache",
"(",
"EntityLoadEvent",
"$",
"event",
")",
"{",
"$",
"entity",
"=",
"$",
"event",
"->",
"getEntity",
"(",
")",
";",
"// Check cache",
"if",
"(",
"false",
"!==",
"$",
"data",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"entity",
")",
")",
"{",
"// Set data from cache to entity object",
"$",
"entity",
"->",
"setDataFromCache",
"(",
"$",
"data",
")",
";",
"$",
"entity",
"->",
"setIsLoaded",
"(",
"true",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"'cache.load'",
",",
"new",
"CacheEvent",
"(",
"$",
"entity",
")",
")",
";",
"}",
"}"
] | Load data from cache
@param EntityLoadEvent $event
@return void | [
"Load",
"data",
"from",
"cache"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Cache/Listener/CacheListener.php#L52-L64 | train |
guni12/comment | src/Comments/HTMLForm/UpdateCommForm.php | UpdateCommForm.decode | public function decode($fromjson)
{
$textfilter = $this->di->get("textfilter");
$toparse = json_decode($fromjson);
$comt = $textfilter->parse($toparse->text, ["yamlfrontmatter", "shortcode", "markdown", "titlefromheader"]);
$comt = strip_tags($comt->text);
return $comt;
} | php | public function decode($fromjson)
{
$textfilter = $this->di->get("textfilter");
$toparse = json_decode($fromjson);
$comt = $textfilter->parse($toparse->text, ["yamlfrontmatter", "shortcode", "markdown", "titlefromheader"]);
$comt = strip_tags($comt->text);
return $comt;
} | [
"public",
"function",
"decode",
"(",
"$",
"fromjson",
")",
"{",
"$",
"textfilter",
"=",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"\"textfilter\"",
")",
";",
"$",
"toparse",
"=",
"json_decode",
"(",
"$",
"fromjson",
")",
";",
"$",
"comt",
"=",
"$",
"textfilter",
"->",
"parse",
"(",
"$",
"toparse",
"->",
"text",
",",
"[",
"\"yamlfrontmatter\"",
",",
"\"shortcode\"",
",",
"\"markdown\"",
",",
"\"titlefromheader\"",
"]",
")",
";",
"$",
"comt",
"=",
"strip_tags",
"(",
"$",
"comt",
"->",
"text",
")",
";",
"return",
"$",
"comt",
";",
"}"
] | Converts json-string back to variables
@param string $fromjson the jsoncode
@return the extracted comment-text | [
"Converts",
"json",
"-",
"string",
"back",
"to",
"variables"
] | f9c2f3e2093fea414867f548c5f5e07f96c55bfd | https://github.com/guni12/comment/blob/f9c2f3e2093fea414867f548c5f5e07f96c55bfd/src/Comments/HTMLForm/UpdateCommForm.php#L36-L43 | train |
Wedeto/HTTP | src/Forms/Form.php | Form.isSubmitted | public function isSubmitted(Request $request)
{
$arguments = $this->method === "GET" ? $request->get : $request->post;
// Check if the form has been submitted at all
return $this->method === $request->method && $arguments['_form_name'] === $this->name;
} | php | public function isSubmitted(Request $request)
{
$arguments = $this->method === "GET" ? $request->get : $request->post;
// Check if the form has been submitted at all
return $this->method === $request->method && $arguments['_form_name'] === $this->name;
} | [
"public",
"function",
"isSubmitted",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"method",
"===",
"\"GET\"",
"?",
"$",
"request",
"->",
"get",
":",
"$",
"request",
"->",
"post",
";",
"// Check if the form has been submitted at all",
"return",
"$",
"this",
"->",
"method",
"===",
"$",
"request",
"->",
"method",
"&&",
"$",
"arguments",
"[",
"'_form_name'",
"]",
"===",
"$",
"this",
"->",
"name",
";",
"}"
] | Check if the form has been submitted
@return bool True if the form was submitted, false if not | [
"Check",
"if",
"the",
"form",
"has",
"been",
"submitted"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Form.php#L203-L209 | train |
Wedeto/HTTP | src/Forms/Form.php | Form.isValid | public function isValid(Request $request)
{
$arguments = $this->method === "GET" ? $request->get : $request->post;
$files = $request->files;
if (!$this->validate($arguments, $files))
return false;
$params = ['form' => $this, 'request' => $request, 'valid' => true, 'arguments' => $arguments];
$params = TypedDictionary::wrap($params);
$params->setType('errors', Type::ARRAY);
$result = Hook::execute('Wedeto.HTTP.Forms.Form.isValid', $params);
if (!$result['valid'])
{
foreach ($result['errors'] as $field => $errors)
{
if ($errors instanceof Dictionary)
$this->errors[$field] = $errors->toArray();
}
return false;
}
unset($this->form_elements[Nonce::getParameterName()]);
unset($this->form_elements['_form_name']);
return true;
} | php | public function isValid(Request $request)
{
$arguments = $this->method === "GET" ? $request->get : $request->post;
$files = $request->files;
if (!$this->validate($arguments, $files))
return false;
$params = ['form' => $this, 'request' => $request, 'valid' => true, 'arguments' => $arguments];
$params = TypedDictionary::wrap($params);
$params->setType('errors', Type::ARRAY);
$result = Hook::execute('Wedeto.HTTP.Forms.Form.isValid', $params);
if (!$result['valid'])
{
foreach ($result['errors'] as $field => $errors)
{
if ($errors instanceof Dictionary)
$this->errors[$field] = $errors->toArray();
}
return false;
}
unset($this->form_elements[Nonce::getParameterName()]);
unset($this->form_elements['_form_name']);
return true;
} | [
"public",
"function",
"isValid",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"method",
"===",
"\"GET\"",
"?",
"$",
"request",
"->",
"get",
":",
"$",
"request",
"->",
"post",
";",
"$",
"files",
"=",
"$",
"request",
"->",
"files",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"validate",
"(",
"$",
"arguments",
",",
"$",
"files",
")",
")",
"return",
"false",
";",
"$",
"params",
"=",
"[",
"'form'",
"=>",
"$",
"this",
",",
"'request'",
"=>",
"$",
"request",
",",
"'valid'",
"=>",
"true",
",",
"'arguments'",
"=>",
"$",
"arguments",
"]",
";",
"$",
"params",
"=",
"TypedDictionary",
"::",
"wrap",
"(",
"$",
"params",
")",
";",
"$",
"params",
"->",
"setType",
"(",
"'errors'",
",",
"Type",
"::",
"ARRAY",
")",
";",
"$",
"result",
"=",
"Hook",
"::",
"execute",
"(",
"'Wedeto.HTTP.Forms.Form.isValid'",
",",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"result",
"[",
"'valid'",
"]",
")",
"{",
"foreach",
"(",
"$",
"result",
"[",
"'errors'",
"]",
"as",
"$",
"field",
"=>",
"$",
"errors",
")",
"{",
"if",
"(",
"$",
"errors",
"instanceof",
"Dictionary",
")",
"$",
"this",
"->",
"errors",
"[",
"$",
"field",
"]",
"=",
"$",
"errors",
"->",
"toArray",
"(",
")",
";",
"}",
"return",
"false",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"form_elements",
"[",
"Nonce",
"::",
"getParameterName",
"(",
")",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"form_elements",
"[",
"'_form_name'",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Check if the form submission is valid
@param Request $request The request containing the submitted data
@return bool True when the submission is valid, false otherwise | [
"Check",
"if",
"the",
"form",
"submission",
"is",
"valid"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Form.php#L216-L243 | train |
Wedeto/HTTP | src/Forms/Form.php | Form.validate | public function validate(Dictionary $arguments, Dictionary $files)
{
// Check all submitted values
$complete = true;
$this->errors = [];
$this->value = [];
foreach ($this->form_elements as $name => $element)
{
if ($element instanceof Form)
{
// Subforms are validated as sub form to unwrap nested structures
if (!$element->validateAsSubForm($arguments, $files))
{
$this->errors[$name] = $element->getErrors();
$complete = false;
}
}
elseif (!$element->validate($arguments, $files))
{
// Delegate validation to the form field
$this->errors[$name] = $element->getErrors();
$complete = false;
}
$this->value[$name] = $element->getValue();
}
foreach ($this->form_validators as $validator)
{
if (!$validator->validate($this))
{
$complete = false;
$error = $validator->getErrorMessage($this);
$this->errors[''][] = $error;
}
}
return $complete;
} | php | public function validate(Dictionary $arguments, Dictionary $files)
{
// Check all submitted values
$complete = true;
$this->errors = [];
$this->value = [];
foreach ($this->form_elements as $name => $element)
{
if ($element instanceof Form)
{
// Subforms are validated as sub form to unwrap nested structures
if (!$element->validateAsSubForm($arguments, $files))
{
$this->errors[$name] = $element->getErrors();
$complete = false;
}
}
elseif (!$element->validate($arguments, $files))
{
// Delegate validation to the form field
$this->errors[$name] = $element->getErrors();
$complete = false;
}
$this->value[$name] = $element->getValue();
}
foreach ($this->form_validators as $validator)
{
if (!$validator->validate($this))
{
$complete = false;
$error = $validator->getErrorMessage($this);
$this->errors[''][] = $error;
}
}
return $complete;
} | [
"public",
"function",
"validate",
"(",
"Dictionary",
"$",
"arguments",
",",
"Dictionary",
"$",
"files",
")",
"{",
"// Check all submitted values",
"$",
"complete",
"=",
"true",
";",
"$",
"this",
"->",
"errors",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"value",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"form_elements",
"as",
"$",
"name",
"=>",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"Form",
")",
"{",
"// Subforms are validated as sub form to unwrap nested structures",
"if",
"(",
"!",
"$",
"element",
"->",
"validateAsSubForm",
"(",
"$",
"arguments",
",",
"$",
"files",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"name",
"]",
"=",
"$",
"element",
"->",
"getErrors",
"(",
")",
";",
"$",
"complete",
"=",
"false",
";",
"}",
"}",
"elseif",
"(",
"!",
"$",
"element",
"->",
"validate",
"(",
"$",
"arguments",
",",
"$",
"files",
")",
")",
"{",
"// Delegate validation to the form field",
"$",
"this",
"->",
"errors",
"[",
"$",
"name",
"]",
"=",
"$",
"element",
"->",
"getErrors",
"(",
")",
";",
"$",
"complete",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"value",
"[",
"$",
"name",
"]",
"=",
"$",
"element",
"->",
"getValue",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"form_validators",
"as",
"$",
"validator",
")",
"{",
"if",
"(",
"!",
"$",
"validator",
"->",
"validate",
"(",
"$",
"this",
")",
")",
"{",
"$",
"complete",
"=",
"false",
";",
"$",
"error",
"=",
"$",
"validator",
"->",
"getErrorMessage",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"errors",
"[",
"''",
"]",
"[",
"]",
"=",
"$",
"error",
";",
"}",
"}",
"return",
"$",
"complete",
";",
"}"
] | Make sure the form was submitted correctly. When errors occur,
these can be obtained using getErrors.
@param Dictionary $arguments The submitted arguments
@param Dictionary $files The submitted files
@return bool True if all fields validate, false if not. | [
"Make",
"sure",
"the",
"form",
"was",
"submitted",
"correctly",
".",
"When",
"errors",
"occur",
"these",
"can",
"be",
"obtained",
"using",
"getErrors",
"."
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Form.php#L291-L328 | train |
Wedeto/HTTP | src/Forms/Form.php | Form.validateAsSubForm | public function validateAsSubForm(Dictionary $arguments, Dictionary $files)
{
$name = $this->name;
if (!$arguments->has($name, Type::ARRAY))
{
$this->errors = [];
if ($this->isRequired())
{
$this->errors = ['' => ['msg' => "{name} is required", 'context' => ['name' => $name]]];
$this->complete = false;
}
return $this->complete;
}
$sub = $arguments->get($name);
$subfiles = $files->has($name, Type::ARRAY) ? $files[$name] : new Dictionary;
if (!$this->repeatable)
return $this->validate($sub, $subfiles);
// Repeatable forms should be an array of arrays - each containing
// their own set of the values for the form elements. We need to
// collect them all here.
$value = [];
$errors = [];
// Only numeric keys are allowed for repeatable forms.
if (!WF::is_numeric_array($sub))
{
$this->errors = ['' => ['msg' => "{name} should be an array", 'context' => ['name' => $name]]];
$this->complete = false;
return $this->complete;
}
// Validate each set of submitted data
$valid = true;
foreach ($sub as $idx => $subsub)
{
$subsubfiles = $subfiles->has($idx, Type::ARRAY) ? $subfiles[$idx] : new Dictionary;
$valid = $valid && $this->validate($subsub, $subsubfiles);
$subvalue = $this->getValue();
$value[$idx] = $subvalue;
if (count($this->errors))
$errors[$idx] = $this->errors;
}
// Store the value and the errors for the form as a whole.
$this->value = $value;
$this->errors = $errors;
return $valid;
} | php | public function validateAsSubForm(Dictionary $arguments, Dictionary $files)
{
$name = $this->name;
if (!$arguments->has($name, Type::ARRAY))
{
$this->errors = [];
if ($this->isRequired())
{
$this->errors = ['' => ['msg' => "{name} is required", 'context' => ['name' => $name]]];
$this->complete = false;
}
return $this->complete;
}
$sub = $arguments->get($name);
$subfiles = $files->has($name, Type::ARRAY) ? $files[$name] : new Dictionary;
if (!$this->repeatable)
return $this->validate($sub, $subfiles);
// Repeatable forms should be an array of arrays - each containing
// their own set of the values for the form elements. We need to
// collect them all here.
$value = [];
$errors = [];
// Only numeric keys are allowed for repeatable forms.
if (!WF::is_numeric_array($sub))
{
$this->errors = ['' => ['msg' => "{name} should be an array", 'context' => ['name' => $name]]];
$this->complete = false;
return $this->complete;
}
// Validate each set of submitted data
$valid = true;
foreach ($sub as $idx => $subsub)
{
$subsubfiles = $subfiles->has($idx, Type::ARRAY) ? $subfiles[$idx] : new Dictionary;
$valid = $valid && $this->validate($subsub, $subsubfiles);
$subvalue = $this->getValue();
$value[$idx] = $subvalue;
if (count($this->errors))
$errors[$idx] = $this->errors;
}
// Store the value and the errors for the form as a whole.
$this->value = $value;
$this->errors = $errors;
return $valid;
} | [
"public",
"function",
"validateAsSubForm",
"(",
"Dictionary",
"$",
"arguments",
",",
"Dictionary",
"$",
"files",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"name",
";",
"if",
"(",
"!",
"$",
"arguments",
"->",
"has",
"(",
"$",
"name",
",",
"Type",
"::",
"ARRAY",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isRequired",
"(",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"=",
"[",
"''",
"=>",
"[",
"'msg'",
"=>",
"\"{name} is required\"",
",",
"'context'",
"=>",
"[",
"'name'",
"=>",
"$",
"name",
"]",
"]",
"]",
";",
"$",
"this",
"->",
"complete",
"=",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"complete",
";",
"}",
"$",
"sub",
"=",
"$",
"arguments",
"->",
"get",
"(",
"$",
"name",
")",
";",
"$",
"subfiles",
"=",
"$",
"files",
"->",
"has",
"(",
"$",
"name",
",",
"Type",
"::",
"ARRAY",
")",
"?",
"$",
"files",
"[",
"$",
"name",
"]",
":",
"new",
"Dictionary",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"repeatable",
")",
"return",
"$",
"this",
"->",
"validate",
"(",
"$",
"sub",
",",
"$",
"subfiles",
")",
";",
"// Repeatable forms should be an array of arrays - each containing",
"// their own set of the values for the form elements. We need to",
"// collect them all here.",
"$",
"value",
"=",
"[",
"]",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"// Only numeric keys are allowed for repeatable forms.",
"if",
"(",
"!",
"WF",
"::",
"is_numeric_array",
"(",
"$",
"sub",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"=",
"[",
"''",
"=>",
"[",
"'msg'",
"=>",
"\"{name} should be an array\"",
",",
"'context'",
"=>",
"[",
"'name'",
"=>",
"$",
"name",
"]",
"]",
"]",
";",
"$",
"this",
"->",
"complete",
"=",
"false",
";",
"return",
"$",
"this",
"->",
"complete",
";",
"}",
"// Validate each set of submitted data",
"$",
"valid",
"=",
"true",
";",
"foreach",
"(",
"$",
"sub",
"as",
"$",
"idx",
"=>",
"$",
"subsub",
")",
"{",
"$",
"subsubfiles",
"=",
"$",
"subfiles",
"->",
"has",
"(",
"$",
"idx",
",",
"Type",
"::",
"ARRAY",
")",
"?",
"$",
"subfiles",
"[",
"$",
"idx",
"]",
":",
"new",
"Dictionary",
";",
"$",
"valid",
"=",
"$",
"valid",
"&&",
"$",
"this",
"->",
"validate",
"(",
"$",
"subsub",
",",
"$",
"subsubfiles",
")",
";",
"$",
"subvalue",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"$",
"value",
"[",
"$",
"idx",
"]",
"=",
"$",
"subvalue",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"errors",
")",
")",
"$",
"errors",
"[",
"$",
"idx",
"]",
"=",
"$",
"this",
"->",
"errors",
";",
"}",
"// Store the value and the errors for the form as a whole.",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"errors",
"=",
"$",
"errors",
";",
"return",
"$",
"valid",
";",
"}"
] | Validate the form as a sub form
@param Dictionary $arguments The submitted data
@param Dictionary $files The submitted files
@return True if the form valides, false if not. | [
"Validate",
"the",
"form",
"as",
"a",
"sub",
"form"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Form.php#L345-L396 | train |
Wedeto/HTTP | src/Forms/Form.php | Form.prepare | public function prepare(Session $session = null, bool $is_root_form = true)
{
foreach ($this->form_elements as $field)
{
if ($field instanceof Form)
$field->prepare(null, false);
}
$params = ['form' => $this, 'session' => $session, 'is_root_form' => $is_root_form];
$params = TypedDictionary::wrap($params);
Hook::execute('Wedeto.HTTP.Forms.Form.prepare', $params);
if ($is_root_form)
$this->form_elements['_form_name'] = new FormField('_form_name', Type::STRING, "hidden", $this->name);
return $this;
} | php | public function prepare(Session $session = null, bool $is_root_form = true)
{
foreach ($this->form_elements as $field)
{
if ($field instanceof Form)
$field->prepare(null, false);
}
$params = ['form' => $this, 'session' => $session, 'is_root_form' => $is_root_form];
$params = TypedDictionary::wrap($params);
Hook::execute('Wedeto.HTTP.Forms.Form.prepare', $params);
if ($is_root_form)
$this->form_elements['_form_name'] = new FormField('_form_name', Type::STRING, "hidden", $this->name);
return $this;
} | [
"public",
"function",
"prepare",
"(",
"Session",
"$",
"session",
"=",
"null",
",",
"bool",
"$",
"is_root_form",
"=",
"true",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"form_elements",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"Form",
")",
"$",
"field",
"->",
"prepare",
"(",
"null",
",",
"false",
")",
";",
"}",
"$",
"params",
"=",
"[",
"'form'",
"=>",
"$",
"this",
",",
"'session'",
"=>",
"$",
"session",
",",
"'is_root_form'",
"=>",
"$",
"is_root_form",
"]",
";",
"$",
"params",
"=",
"TypedDictionary",
"::",
"wrap",
"(",
"$",
"params",
")",
";",
"Hook",
"::",
"execute",
"(",
"'Wedeto.HTTP.Forms.Form.prepare'",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"is_root_form",
")",
"$",
"this",
"->",
"form_elements",
"[",
"'_form_name'",
"]",
"=",
"new",
"FormField",
"(",
"'_form_name'",
",",
"Type",
"::",
"STRING",
",",
"\"hidden\"",
",",
"$",
"this",
"->",
"name",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Prepare the form for rendering. This will generate the nonce and add the form name
@param Session $session The session used to generate the nonce. Omit to skip adding a nonce
@param bool $is_root_form Whether this is the root form or not. When
false, the _form_name element is not added
@return Form Provides fluent interface | [
"Prepare",
"the",
"form",
"for",
"rendering",
".",
"This",
"will",
"generate",
"the",
"nonce",
"and",
"add",
"the",
"form",
"name"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Form.php#L405-L421 | train |
Wedeto/HTTP | src/Forms/Form.php | Form.offsetSet | public function offsetSet($offset, $value)
{
if (!($value instanceof FormField))
throw new InvalidArgumentException("Value must be a FormField");
$this->form_elements[$offset] = $value;
} | php | public function offsetSet($offset, $value)
{
if (!($value instanceof FormField))
throw new InvalidArgumentException("Value must be a FormField");
$this->form_elements[$offset] = $value;
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"value",
"instanceof",
"FormField",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Value must be a FormField\"",
")",
";",
"$",
"this",
"->",
"form_elements",
"[",
"$",
"offset",
"]",
"=",
"$",
"value",
";",
"}"
] | Add or replace a form element
@param string $offset The name of the element
@param FormElement $element The element to set | [
"Add",
"or",
"replace",
"a",
"form",
"element"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Forms/Form.php#L493-L499 | train |
shrink0r/php-schema | src/Factory.php | Factory.verifyClassMap | protected function verifyClassMap(array $classMap)
{
foreach ($classMap as $type => $class) {
if (!class_exists($class)) {
throw new Exception("Class '$class' that has been registered for type '$type' does not exist");
}
if (!in_array(PropertyInterface::class, class_implements($class))) {
throw new Exception("Class '$class' does not implement: " . PropertyInterface::class);
}
}
return $classMap;
} | php | protected function verifyClassMap(array $classMap)
{
foreach ($classMap as $type => $class) {
if (!class_exists($class)) {
throw new Exception("Class '$class' that has been registered for type '$type' does not exist");
}
if (!in_array(PropertyInterface::class, class_implements($class))) {
throw new Exception("Class '$class' does not implement: " . PropertyInterface::class);
}
}
return $classMap;
} | [
"protected",
"function",
"verifyClassMap",
"(",
"array",
"$",
"classMap",
")",
"{",
"foreach",
"(",
"$",
"classMap",
"as",
"$",
"type",
"=>",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Class '$class' that has been registered for type '$type' does not exist\"",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"PropertyInterface",
"::",
"class",
",",
"class_implements",
"(",
"$",
"class",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Class '$class' does not implement: \"",
".",
"PropertyInterface",
"::",
"class",
")",
";",
"}",
"}",
"return",
"$",
"classMap",
";",
"}"
] | Ensures that the given class map contains valid values.
@param string[] $classMap
@return string[] Returns the verified class map. | [
"Ensures",
"that",
"the",
"given",
"class",
"map",
"contains",
"valid",
"values",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Factory.php#L99-L111 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/BaseNodeController.php | BaseNodeController.setRelation | protected function setRelation($request)
{
$this->changeRelationModel();
$relation = [];
if ($request->has('group-thumbnail')) {
$this->relations['thumbnails']['datas'] = collect($request->get('group-thumbnail'))->reject(function($item)
{
return ! $item['thumbnail_slug'] || ! $item['thumbnail_width'] || ! $item['thumbnail_height'];
})->map(function($item,$key)
{
$item['slug'] = $item['thumbnail_slug'];
unsetReturn($item,'thumbnail_slug');
$item['photo_width'] = $item['thumbnail_width'];
unsetReturn($item,'thumbnail_width');
$item['photo_height'] = $item['thumbnail_height'];
unsetReturn($item,'thumbnail_height');
return $item;
});
if ($this->relations['thumbnails']['datas']->count() > 0) $relation[] = $this->relations['thumbnails'];
}
if ($request->has('group-extra')) {
$this->relations['extras']['datas'] = collect($request->get('group-extra'))->reject(function($item)
{
return ! $item['extra_name'] || ! $item['extra_type'];
})->map(function($item,$key)
{
$item['name'] = $item['extra_name'];
unsetReturn($item,'extra_name');
$item['type'] = $item['extra_type'];
unsetReturn($item,'extra_type');
return $item;
});
if ($this->relations['extras']['datas']->count() > 0) $relation[] = $this->relations['extras'];
}
$this->setOperationRelation($relation);
} | php | protected function setRelation($request)
{
$this->changeRelationModel();
$relation = [];
if ($request->has('group-thumbnail')) {
$this->relations['thumbnails']['datas'] = collect($request->get('group-thumbnail'))->reject(function($item)
{
return ! $item['thumbnail_slug'] || ! $item['thumbnail_width'] || ! $item['thumbnail_height'];
})->map(function($item,$key)
{
$item['slug'] = $item['thumbnail_slug'];
unsetReturn($item,'thumbnail_slug');
$item['photo_width'] = $item['thumbnail_width'];
unsetReturn($item,'thumbnail_width');
$item['photo_height'] = $item['thumbnail_height'];
unsetReturn($item,'thumbnail_height');
return $item;
});
if ($this->relations['thumbnails']['datas']->count() > 0) $relation[] = $this->relations['thumbnails'];
}
if ($request->has('group-extra')) {
$this->relations['extras']['datas'] = collect($request->get('group-extra'))->reject(function($item)
{
return ! $item['extra_name'] || ! $item['extra_type'];
})->map(function($item,$key)
{
$item['name'] = $item['extra_name'];
unsetReturn($item,'extra_name');
$item['type'] = $item['extra_type'];
unsetReturn($item,'extra_type');
return $item;
});
if ($this->relations['extras']['datas']->count() > 0) $relation[] = $this->relations['extras'];
}
$this->setOperationRelation($relation);
} | [
"protected",
"function",
"setRelation",
"(",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"changeRelationModel",
"(",
")",
";",
"$",
"relation",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"request",
"->",
"has",
"(",
"'group-thumbnail'",
")",
")",
"{",
"$",
"this",
"->",
"relations",
"[",
"'thumbnails'",
"]",
"[",
"'datas'",
"]",
"=",
"collect",
"(",
"$",
"request",
"->",
"get",
"(",
"'group-thumbnail'",
")",
")",
"->",
"reject",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"!",
"$",
"item",
"[",
"'thumbnail_slug'",
"]",
"||",
"!",
"$",
"item",
"[",
"'thumbnail_width'",
"]",
"||",
"!",
"$",
"item",
"[",
"'thumbnail_height'",
"]",
";",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
",",
"$",
"key",
")",
"{",
"$",
"item",
"[",
"'slug'",
"]",
"=",
"$",
"item",
"[",
"'thumbnail_slug'",
"]",
";",
"unsetReturn",
"(",
"$",
"item",
",",
"'thumbnail_slug'",
")",
";",
"$",
"item",
"[",
"'photo_width'",
"]",
"=",
"$",
"item",
"[",
"'thumbnail_width'",
"]",
";",
"unsetReturn",
"(",
"$",
"item",
",",
"'thumbnail_width'",
")",
";",
"$",
"item",
"[",
"'photo_height'",
"]",
"=",
"$",
"item",
"[",
"'thumbnail_height'",
"]",
";",
"unsetReturn",
"(",
"$",
"item",
",",
"'thumbnail_height'",
")",
";",
"return",
"$",
"item",
";",
"}",
")",
";",
"if",
"(",
"$",
"this",
"->",
"relations",
"[",
"'thumbnails'",
"]",
"[",
"'datas'",
"]",
"->",
"count",
"(",
")",
">",
"0",
")",
"$",
"relation",
"[",
"]",
"=",
"$",
"this",
"->",
"relations",
"[",
"'thumbnails'",
"]",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"has",
"(",
"'group-extra'",
")",
")",
"{",
"$",
"this",
"->",
"relations",
"[",
"'extras'",
"]",
"[",
"'datas'",
"]",
"=",
"collect",
"(",
"$",
"request",
"->",
"get",
"(",
"'group-extra'",
")",
")",
"->",
"reject",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"!",
"$",
"item",
"[",
"'extra_name'",
"]",
"||",
"!",
"$",
"item",
"[",
"'extra_type'",
"]",
";",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
",",
"$",
"key",
")",
"{",
"$",
"item",
"[",
"'name'",
"]",
"=",
"$",
"item",
"[",
"'extra_name'",
"]",
";",
"unsetReturn",
"(",
"$",
"item",
",",
"'extra_name'",
")",
";",
"$",
"item",
"[",
"'type'",
"]",
"=",
"$",
"item",
"[",
"'extra_type'",
"]",
";",
"unsetReturn",
"(",
"$",
"item",
",",
"'extra_type'",
")",
";",
"return",
"$",
"item",
";",
"}",
")",
";",
"if",
"(",
"$",
"this",
"->",
"relations",
"[",
"'extras'",
"]",
"[",
"'datas'",
"]",
"->",
"count",
"(",
")",
">",
"0",
")",
"$",
"relation",
"[",
"]",
"=",
"$",
"this",
"->",
"relations",
"[",
"'extras'",
"]",
";",
"}",
"$",
"this",
"->",
"setOperationRelation",
"(",
"$",
"relation",
")",
";",
"}"
] | set the relations
@param $request
@return void | [
"set",
"the",
"relations"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/BaseNodeController.php#L37-L72 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/BaseNodeController.php | BaseNodeController.setRelationDefine | protected function setRelationDefine($parent)
{
$this->changeRelationModel();
$this->setDefineValues($this->defineValues);
$this->relations['thumbnails']['datas'] = $parent->thumbnails()->get(['slug','photo_width','photo_height'])->toArray();
$this->relations['extras']['datas'] = $parent->extras()->get(['name','type'])->toArray();
$this->setOperationRelation($this->relations);
} | php | protected function setRelationDefine($parent)
{
$this->changeRelationModel();
$this->setDefineValues($this->defineValues);
$this->relations['thumbnails']['datas'] = $parent->thumbnails()->get(['slug','photo_width','photo_height'])->toArray();
$this->relations['extras']['datas'] = $parent->extras()->get(['name','type'])->toArray();
$this->setOperationRelation($this->relations);
} | [
"protected",
"function",
"setRelationDefine",
"(",
"$",
"parent",
")",
"{",
"$",
"this",
"->",
"changeRelationModel",
"(",
")",
";",
"$",
"this",
"->",
"setDefineValues",
"(",
"$",
"this",
"->",
"defineValues",
")",
";",
"$",
"this",
"->",
"relations",
"[",
"'thumbnails'",
"]",
"[",
"'datas'",
"]",
"=",
"$",
"parent",
"->",
"thumbnails",
"(",
")",
"->",
"get",
"(",
"[",
"'slug'",
",",
"'photo_width'",
",",
"'photo_height'",
"]",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"this",
"->",
"relations",
"[",
"'extras'",
"]",
"[",
"'datas'",
"]",
"=",
"$",
"parent",
"->",
"extras",
"(",
")",
"->",
"get",
"(",
"[",
"'name'",
",",
"'type'",
"]",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"this",
"->",
"setOperationRelation",
"(",
"$",
"this",
"->",
"relations",
")",
";",
"}"
] | set relation define datas
@param $parent
@return void | [
"set",
"relation",
"define",
"datas"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/BaseNodeController.php#L80-L87 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/BaseNodeController.php | BaseNodeController.changeRelationModel | protected function changeRelationModel()
{
$module = getModule(get_called_class());
$module = explode('-',$module);
$module = ucfirst_tr($module[1]);
$this->relations['thumbnails']['relation_model'] = "\\App\\{$module}Thumbnail";
$this->relations['extras']['relation_model'] = "\\App\\{$module}Extra";
} | php | protected function changeRelationModel()
{
$module = getModule(get_called_class());
$module = explode('-',$module);
$module = ucfirst_tr($module[1]);
$this->relations['thumbnails']['relation_model'] = "\\App\\{$module}Thumbnail";
$this->relations['extras']['relation_model'] = "\\App\\{$module}Extra";
} | [
"protected",
"function",
"changeRelationModel",
"(",
")",
"{",
"$",
"module",
"=",
"getModule",
"(",
"get_called_class",
"(",
")",
")",
";",
"$",
"module",
"=",
"explode",
"(",
"'-'",
",",
"$",
"module",
")",
";",
"$",
"module",
"=",
"ucfirst_tr",
"(",
"$",
"module",
"[",
"1",
"]",
")",
";",
"$",
"this",
"->",
"relations",
"[",
"'thumbnails'",
"]",
"[",
"'relation_model'",
"]",
"=",
"\"\\\\App\\\\{$module}Thumbnail\"",
";",
"$",
"this",
"->",
"relations",
"[",
"'extras'",
"]",
"[",
"'relation_model'",
"]",
"=",
"\"\\\\App\\\\{$module}Extra\"",
";",
"}"
] | change relation model | [
"change",
"relation",
"model"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/BaseNodeController.php#L92-L99 | train |
XetaIO/Xetaravel-IpTraceable | src/Traits/IpTraceable.php | IpTraceable.updateFields | public function updateFields(Guard $auth, $ip = null): bool
{
$ip = $this->setIpValue($ip);
$user = $auth->user();
if (!$user instanceof Model) {
return false;
}
$user->last_login_ip = $ip;
$lastLoginDate = config('iptraceable.fields.last_login_date');
if (!is_null($lastLoginDate)) {
$user->{$lastLoginDate} = Carbon::now();
}
return $user->save();
} | php | public function updateFields(Guard $auth, $ip = null): bool
{
$ip = $this->setIpValue($ip);
$user = $auth->user();
if (!$user instanceof Model) {
return false;
}
$user->last_login_ip = $ip;
$lastLoginDate = config('iptraceable.fields.last_login_date');
if (!is_null($lastLoginDate)) {
$user->{$lastLoginDate} = Carbon::now();
}
return $user->save();
} | [
"public",
"function",
"updateFields",
"(",
"Guard",
"$",
"auth",
",",
"$",
"ip",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"ip",
"=",
"$",
"this",
"->",
"setIpValue",
"(",
"$",
"ip",
")",
";",
"$",
"user",
"=",
"$",
"auth",
"->",
"user",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"instanceof",
"Model",
")",
"{",
"return",
"false",
";",
"}",
"$",
"user",
"->",
"last_login_ip",
"=",
"$",
"ip",
";",
"$",
"lastLoginDate",
"=",
"config",
"(",
"'iptraceable.fields.last_login_date'",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"lastLoginDate",
")",
")",
"{",
"$",
"user",
"->",
"{",
"$",
"lastLoginDate",
"}",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"}",
"return",
"$",
"user",
"->",
"save",
"(",
")",
";",
"}"
] | Update the fields for the user.
@param \Illuminate\Contracts\Auth\Guard $auth
@param null|string $ip The IP to set.
@return bool | [
"Update",
"the",
"fields",
"for",
"the",
"user",
"."
] | e1c57592d45f240c55e827fd6b756e5143c892b5 | https://github.com/XetaIO/Xetaravel-IpTraceable/blob/e1c57592d45f240c55e827fd6b756e5143c892b5/src/Traits/IpTraceable.php#L19-L37 | train |
squareproton/Bond | src/Bond/Entity/Types/DateRange.php | DateRange.contains | public function contains( DateTime $datetime )
{
$lower = $this->lower->toUnixTimestamp();
$upper = $this->upper->toUnixTimestamp();
$working = $datetime->toUnixTimestamp();
$lowerCompare = bccomp( $lower, $working );
$upperCompare = bccomp( $upper, $working );
// echo "\n{$lower} {$upper} {$working} {$lowerCompare} {$upperCompare}";
// fucking hell, this was much more annoying than it should be
if( $lowerCompare === 1 || ( $this->bounds & self::LOWER_CONTAIN_NOT and $lowerCompare === 0 ) ) {
return false;
}
if( $upperCompare === -1 || ( $this->bounds & self::UPPER_CONTAIN_NOT and $upperCompare === 0 ) ) {
return false;
}
return true;
} | php | public function contains( DateTime $datetime )
{
$lower = $this->lower->toUnixTimestamp();
$upper = $this->upper->toUnixTimestamp();
$working = $datetime->toUnixTimestamp();
$lowerCompare = bccomp( $lower, $working );
$upperCompare = bccomp( $upper, $working );
// echo "\n{$lower} {$upper} {$working} {$lowerCompare} {$upperCompare}";
// fucking hell, this was much more annoying than it should be
if( $lowerCompare === 1 || ( $this->bounds & self::LOWER_CONTAIN_NOT and $lowerCompare === 0 ) ) {
return false;
}
if( $upperCompare === -1 || ( $this->bounds & self::UPPER_CONTAIN_NOT and $upperCompare === 0 ) ) {
return false;
}
return true;
} | [
"public",
"function",
"contains",
"(",
"DateTime",
"$",
"datetime",
")",
"{",
"$",
"lower",
"=",
"$",
"this",
"->",
"lower",
"->",
"toUnixTimestamp",
"(",
")",
";",
"$",
"upper",
"=",
"$",
"this",
"->",
"upper",
"->",
"toUnixTimestamp",
"(",
")",
";",
"$",
"working",
"=",
"$",
"datetime",
"->",
"toUnixTimestamp",
"(",
")",
";",
"$",
"lowerCompare",
"=",
"bccomp",
"(",
"$",
"lower",
",",
"$",
"working",
")",
";",
"$",
"upperCompare",
"=",
"bccomp",
"(",
"$",
"upper",
",",
"$",
"working",
")",
";",
"// echo \"\\n{$lower} {$upper} {$working} {$lowerCompare} {$upperCompare}\";",
"// fucking hell, this was much more annoying than it should be",
"if",
"(",
"$",
"lowerCompare",
"===",
"1",
"||",
"(",
"$",
"this",
"->",
"bounds",
"&",
"self",
"::",
"LOWER_CONTAIN_NOT",
"and",
"$",
"lowerCompare",
"===",
"0",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"upperCompare",
"===",
"-",
"1",
"||",
"(",
"$",
"this",
"->",
"bounds",
"&",
"self",
"::",
"UPPER_CONTAIN_NOT",
"and",
"$",
"upperCompare",
"===",
"0",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Does this interval contain our time
@return Bond\Entity\T | [
"Does",
"this",
"interval",
"contain",
"our",
"time"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/DateRange.php#L87-L110 | train |
danielgp/common-lib | source/MySQLiAdvancedOutput.php | MySQLiAdvancedOutput.getFieldOutputEnumSet | private function getFieldOutputEnumSet($tblSrc, $fldType, $val, $iar = [])
{
$adnlThings = $this->establishDefaultEnumSet($fldType);
if (array_key_exists('readonly', $val)) {
return $this->getFieldOutputEnumSetReadOnly($val, $adnlThings);
}
$inAdtnl = $adnlThings['additional'];
if ($iar !== []) {
$inAdtnl = array_merge($inAdtnl, $iar);
}
$vlSlct = explode(',', $this->getFieldValue($val));
$slctOptns = $this->getSetOrEnum2Array($tblSrc, $val['COLUMN_NAME']);
return $this->setArrayToSelect($slctOptns, $vlSlct, $val['COLUMN_NAME'] . $adnlThings['suffix'], $inAdtnl);
} | php | private function getFieldOutputEnumSet($tblSrc, $fldType, $val, $iar = [])
{
$adnlThings = $this->establishDefaultEnumSet($fldType);
if (array_key_exists('readonly', $val)) {
return $this->getFieldOutputEnumSetReadOnly($val, $adnlThings);
}
$inAdtnl = $adnlThings['additional'];
if ($iar !== []) {
$inAdtnl = array_merge($inAdtnl, $iar);
}
$vlSlct = explode(',', $this->getFieldValue($val));
$slctOptns = $this->getSetOrEnum2Array($tblSrc, $val['COLUMN_NAME']);
return $this->setArrayToSelect($slctOptns, $vlSlct, $val['COLUMN_NAME'] . $adnlThings['suffix'], $inAdtnl);
} | [
"private",
"function",
"getFieldOutputEnumSet",
"(",
"$",
"tblSrc",
",",
"$",
"fldType",
",",
"$",
"val",
",",
"$",
"iar",
"=",
"[",
"]",
")",
"{",
"$",
"adnlThings",
"=",
"$",
"this",
"->",
"establishDefaultEnumSet",
"(",
"$",
"fldType",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'readonly'",
",",
"$",
"val",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getFieldOutputEnumSetReadOnly",
"(",
"$",
"val",
",",
"$",
"adnlThings",
")",
";",
"}",
"$",
"inAdtnl",
"=",
"$",
"adnlThings",
"[",
"'additional'",
"]",
";",
"if",
"(",
"$",
"iar",
"!==",
"[",
"]",
")",
"{",
"$",
"inAdtnl",
"=",
"array_merge",
"(",
"$",
"inAdtnl",
",",
"$",
"iar",
")",
";",
"}",
"$",
"vlSlct",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"getFieldValue",
"(",
"$",
"val",
")",
")",
";",
"$",
"slctOptns",
"=",
"$",
"this",
"->",
"getSetOrEnum2Array",
"(",
"$",
"tblSrc",
",",
"$",
"val",
"[",
"'COLUMN_NAME'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"setArrayToSelect",
"(",
"$",
"slctOptns",
",",
"$",
"vlSlct",
",",
"$",
"val",
"[",
"'COLUMN_NAME'",
"]",
".",
"$",
"adnlThings",
"[",
"'suffix'",
"]",
",",
"$",
"inAdtnl",
")",
";",
"}"
] | Returns a Enum or Set field to use in form
@param string $tblSrc
@param string $fldType
@param array $val
@param array $iar
@return string | [
"Returns",
"a",
"Enum",
"or",
"Set",
"field",
"to",
"use",
"in",
"form"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiAdvancedOutput.php#L50-L63 | train |
danielgp/common-lib | source/MySQLiAdvancedOutput.php | MySQLiAdvancedOutput.getFieldOutputText | private function getFieldOutputText($tbl, $fieldType, $value, $iar = [])
{
if (!in_array($fieldType, ['char', 'tinytext', 'varchar'])) {
return '';
}
$foreignKeysArray = $this->getFieldOutputTextPrerequisites($tbl, $value);
if ($foreignKeysArray !== []) {
return $this->getFieldOutputTextFK($foreignKeysArray, $value, $iar);
}
return $this->getFieldOutputTextNonFK($value, $iar);
} | php | private function getFieldOutputText($tbl, $fieldType, $value, $iar = [])
{
if (!in_array($fieldType, ['char', 'tinytext', 'varchar'])) {
return '';
}
$foreignKeysArray = $this->getFieldOutputTextPrerequisites($tbl, $value);
if ($foreignKeysArray !== []) {
return $this->getFieldOutputTextFK($foreignKeysArray, $value, $iar);
}
return $this->getFieldOutputTextNonFK($value, $iar);
} | [
"private",
"function",
"getFieldOutputText",
"(",
"$",
"tbl",
",",
"$",
"fieldType",
",",
"$",
"value",
",",
"$",
"iar",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"fieldType",
",",
"[",
"'char'",
",",
"'tinytext'",
",",
"'varchar'",
"]",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"foreignKeysArray",
"=",
"$",
"this",
"->",
"getFieldOutputTextPrerequisites",
"(",
"$",
"tbl",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"foreignKeysArray",
"!==",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"getFieldOutputTextFK",
"(",
"$",
"foreignKeysArray",
",",
"$",
"value",
",",
"$",
"iar",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getFieldOutputTextNonFK",
"(",
"$",
"value",
",",
"$",
"iar",
")",
";",
"}"
] | Returns a Char field 2 use in a form
@param string $tbl
@param string $fieldType
@param array $value
@param array $iar
@return string | [
"Returns",
"a",
"Char",
"field",
"2",
"use",
"in",
"a",
"form"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiAdvancedOutput.php#L74-L84 | train |
danielgp/common-lib | source/MySQLiAdvancedOutput.php | MySQLiAdvancedOutput.getFieldOutputTextLarge | protected function getFieldOutputTextLarge($fieldType, $value, $iar = [])
{
if (!in_array($fieldType, ['blob', 'text'])) {
return '';
}
$inAdtnl = [
'name' => $value['COLUMN_NAME'],
'id' => $value['COLUMN_NAME'],
'rows' => 4,
'cols' => 55,
];
if ($iar !== []) {
$inAdtnl = array_merge($inAdtnl, $iar);
}
return $this->setStringIntoTag($this->getFieldValue($value), 'textarea', $inAdtnl);
} | php | protected function getFieldOutputTextLarge($fieldType, $value, $iar = [])
{
if (!in_array($fieldType, ['blob', 'text'])) {
return '';
}
$inAdtnl = [
'name' => $value['COLUMN_NAME'],
'id' => $value['COLUMN_NAME'],
'rows' => 4,
'cols' => 55,
];
if ($iar !== []) {
$inAdtnl = array_merge($inAdtnl, $iar);
}
return $this->setStringIntoTag($this->getFieldValue($value), 'textarea', $inAdtnl);
} | [
"protected",
"function",
"getFieldOutputTextLarge",
"(",
"$",
"fieldType",
",",
"$",
"value",
",",
"$",
"iar",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"fieldType",
",",
"[",
"'blob'",
",",
"'text'",
"]",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"inAdtnl",
"=",
"[",
"'name'",
"=>",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
",",
"'id'",
"=>",
"$",
"value",
"[",
"'COLUMN_NAME'",
"]",
",",
"'rows'",
"=>",
"4",
",",
"'cols'",
"=>",
"55",
",",
"]",
";",
"if",
"(",
"$",
"iar",
"!==",
"[",
"]",
")",
"{",
"$",
"inAdtnl",
"=",
"array_merge",
"(",
"$",
"inAdtnl",
",",
"$",
"iar",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setStringIntoTag",
"(",
"$",
"this",
"->",
"getFieldValue",
"(",
"$",
"value",
")",
",",
"'textarea'",
",",
"$",
"inAdtnl",
")",
";",
"}"
] | Returns a Text field 2 use in a form
@param string $fieldType
@param array $value
@param array $iar
@return string | [
"Returns",
"a",
"Text",
"field",
"2",
"use",
"in",
"a",
"form"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiAdvancedOutput.php#L94-L109 | train |
danielgp/common-lib | source/MySQLiAdvancedOutput.php | MySQLiAdvancedOutput.getFieldOutputTimestamp | private function getFieldOutputTimestamp($dtl, $iar = [])
{
if (($dtl['COLUMN_DEFAULT'] == 'CURRENT_TIMESTAMP') || ($dtl['EXTRA'] == 'on update CURRENT_TIMESTAMP')) {
return $this->getTimestamping($dtl)['input'];
}
$input = $this->getFieldOutputTT($dtl, 19, $iar);
if (!array_key_exists('readonly', $iar)) {
$input .= $this->setCalendarControlWithTime($dtl['COLUMN_NAME']);
}
return $input;
} | php | private function getFieldOutputTimestamp($dtl, $iar = [])
{
if (($dtl['COLUMN_DEFAULT'] == 'CURRENT_TIMESTAMP') || ($dtl['EXTRA'] == 'on update CURRENT_TIMESTAMP')) {
return $this->getTimestamping($dtl)['input'];
}
$input = $this->getFieldOutputTT($dtl, 19, $iar);
if (!array_key_exists('readonly', $iar)) {
$input .= $this->setCalendarControlWithTime($dtl['COLUMN_NAME']);
}
return $input;
} | [
"private",
"function",
"getFieldOutputTimestamp",
"(",
"$",
"dtl",
",",
"$",
"iar",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"(",
"$",
"dtl",
"[",
"'COLUMN_DEFAULT'",
"]",
"==",
"'CURRENT_TIMESTAMP'",
")",
"||",
"(",
"$",
"dtl",
"[",
"'EXTRA'",
"]",
"==",
"'on update CURRENT_TIMESTAMP'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getTimestamping",
"(",
"$",
"dtl",
")",
"[",
"'input'",
"]",
";",
"}",
"$",
"input",
"=",
"$",
"this",
"->",
"getFieldOutputTT",
"(",
"$",
"dtl",
",",
"19",
",",
"$",
"iar",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'readonly'",
",",
"$",
"iar",
")",
")",
"{",
"$",
"input",
".=",
"$",
"this",
"->",
"setCalendarControlWithTime",
"(",
"$",
"dtl",
"[",
"'COLUMN_NAME'",
"]",
")",
";",
"}",
"return",
"$",
"input",
";",
"}"
] | Returns a Timestamp field 2 use in a form
@param array $dtl
@param array $iar
@return string | [
"Returns",
"a",
"Timestamp",
"field",
"2",
"use",
"in",
"a",
"form"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiAdvancedOutput.php#L118-L128 | train |
danielgp/common-lib | source/MySQLiAdvancedOutput.php | MySQLiAdvancedOutput.getFieldOutputYear | private function getFieldOutputYear($tblName, $details, $iar)
{
$listOfValues = [];
for ($cntr = 1901; $cntr <= 2155; $cntr++) {
$listOfValues[$cntr] = $cntr;
}
if ($iar == []) {
$slDflt = $this->getFieldValue($details);
return $this->setArrayToSelect($listOfValues, $slDflt, $details['COLUMN_NAME'], ['size' => 1]);
}
return $this->getFieldOutputText($tblName, 'varchar', $details, $iar);
} | php | private function getFieldOutputYear($tblName, $details, $iar)
{
$listOfValues = [];
for ($cntr = 1901; $cntr <= 2155; $cntr++) {
$listOfValues[$cntr] = $cntr;
}
if ($iar == []) {
$slDflt = $this->getFieldValue($details);
return $this->setArrayToSelect($listOfValues, $slDflt, $details['COLUMN_NAME'], ['size' => 1]);
}
return $this->getFieldOutputText($tblName, 'varchar', $details, $iar);
} | [
"private",
"function",
"getFieldOutputYear",
"(",
"$",
"tblName",
",",
"$",
"details",
",",
"$",
"iar",
")",
"{",
"$",
"listOfValues",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"cntr",
"=",
"1901",
";",
"$",
"cntr",
"<=",
"2155",
";",
"$",
"cntr",
"++",
")",
"{",
"$",
"listOfValues",
"[",
"$",
"cntr",
"]",
"=",
"$",
"cntr",
";",
"}",
"if",
"(",
"$",
"iar",
"==",
"[",
"]",
")",
"{",
"$",
"slDflt",
"=",
"$",
"this",
"->",
"getFieldValue",
"(",
"$",
"details",
")",
";",
"return",
"$",
"this",
"->",
"setArrayToSelect",
"(",
"$",
"listOfValues",
",",
"$",
"slDflt",
",",
"$",
"details",
"[",
"'COLUMN_NAME'",
"]",
",",
"[",
"'size'",
"=>",
"1",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getFieldOutputText",
"(",
"$",
"tblName",
",",
"'varchar'",
",",
"$",
"details",
",",
"$",
"iar",
")",
";",
"}"
] | Returns a Year field 2 use in a form
@param array $details
@param array $iar
@return string | [
"Returns",
"a",
"Year",
"field",
"2",
"use",
"in",
"a",
"form"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiAdvancedOutput.php#L137-L148 | train |
danielgp/common-lib | source/MySQLiAdvancedOutput.php | MySQLiAdvancedOutput.getSetOrEnum2Array | protected function getSetOrEnum2Array($refTbl, $refCol)
{
$dat = $this->establishDatabaseAndTable($refTbl);
foreach ($this->advCache['tableStructureCache'][$dat[0]][$dat[1]] as $vle) {
if ($vle['COLUMN_NAME'] == $refCol) {
$kVl = explode('\',\'', substr($vle['COLUMN_TYPE'], strlen($vle['DATA_TYPE']) + 2, -2));
$fVl = array_combine($kVl, $kVl);
if ($vle['IS_NULLABLE'] === 'YES') {
$fVl['NULL'] = '';
}
}
}
ksort($fVl);
return $fVl;
} | php | protected function getSetOrEnum2Array($refTbl, $refCol)
{
$dat = $this->establishDatabaseAndTable($refTbl);
foreach ($this->advCache['tableStructureCache'][$dat[0]][$dat[1]] as $vle) {
if ($vle['COLUMN_NAME'] == $refCol) {
$kVl = explode('\',\'', substr($vle['COLUMN_TYPE'], strlen($vle['DATA_TYPE']) + 2, -2));
$fVl = array_combine($kVl, $kVl);
if ($vle['IS_NULLABLE'] === 'YES') {
$fVl['NULL'] = '';
}
}
}
ksort($fVl);
return $fVl;
} | [
"protected",
"function",
"getSetOrEnum2Array",
"(",
"$",
"refTbl",
",",
"$",
"refCol",
")",
"{",
"$",
"dat",
"=",
"$",
"this",
"->",
"establishDatabaseAndTable",
"(",
"$",
"refTbl",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"advCache",
"[",
"'tableStructureCache'",
"]",
"[",
"$",
"dat",
"[",
"0",
"]",
"]",
"[",
"$",
"dat",
"[",
"1",
"]",
"]",
"as",
"$",
"vle",
")",
"{",
"if",
"(",
"$",
"vle",
"[",
"'COLUMN_NAME'",
"]",
"==",
"$",
"refCol",
")",
"{",
"$",
"kVl",
"=",
"explode",
"(",
"'\\',\\''",
",",
"substr",
"(",
"$",
"vle",
"[",
"'COLUMN_TYPE'",
"]",
",",
"strlen",
"(",
"$",
"vle",
"[",
"'DATA_TYPE'",
"]",
")",
"+",
"2",
",",
"-",
"2",
")",
")",
";",
"$",
"fVl",
"=",
"array_combine",
"(",
"$",
"kVl",
",",
"$",
"kVl",
")",
";",
"if",
"(",
"$",
"vle",
"[",
"'IS_NULLABLE'",
"]",
"===",
"'YES'",
")",
"{",
"$",
"fVl",
"[",
"'NULL'",
"]",
"=",
"''",
";",
"}",
"}",
"}",
"ksort",
"(",
"$",
"fVl",
")",
";",
"return",
"$",
"fVl",
";",
"}"
] | Returns an array with possible values of a SET or ENUM column
@param string $refTbl
@param string $refCol
@return array | [
"Returns",
"an",
"array",
"with",
"possible",
"values",
"of",
"a",
"SET",
"or",
"ENUM",
"column"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiAdvancedOutput.php#L157-L171 | train |
danielgp/common-lib | source/MySQLiAdvancedOutput.php | MySQLiAdvancedOutput.getTimestamping | private function getTimestamping($dtl)
{
$fieldValue = $this->getFieldValue($dtl);
$inM = $this->setStringIntoTag($fieldValue, 'span');
if (in_array($fieldValue, ['', 'CURRENT_TIMESTAMP', 'NULL'])) {
$mCN = [
'InsertDateTime' => 'data/timpul ad. informatiei',
'ModificationDateTime' => 'data/timpul modificarii inf.',
'modification_datetime' => 'data/timpul modificarii inf.',
];
if (array_key_exists($dtl['COLUMN_NAME'], $mCN)) {
$inM = $this->setStringIntoTag($mCN[$dtl['COLUMN_NAME']], 'span', ['style' => 'font-style:italic;']);
}
}
$lbl = '<span class="fake_label">' . $this->getFieldNameForDisplay($dtl) . '</span>';
return ['label' => $lbl, 'input' => $inM];
} | php | private function getTimestamping($dtl)
{
$fieldValue = $this->getFieldValue($dtl);
$inM = $this->setStringIntoTag($fieldValue, 'span');
if (in_array($fieldValue, ['', 'CURRENT_TIMESTAMP', 'NULL'])) {
$mCN = [
'InsertDateTime' => 'data/timpul ad. informatiei',
'ModificationDateTime' => 'data/timpul modificarii inf.',
'modification_datetime' => 'data/timpul modificarii inf.',
];
if (array_key_exists($dtl['COLUMN_NAME'], $mCN)) {
$inM = $this->setStringIntoTag($mCN[$dtl['COLUMN_NAME']], 'span', ['style' => 'font-style:italic;']);
}
}
$lbl = '<span class="fake_label">' . $this->getFieldNameForDisplay($dtl) . '</span>';
return ['label' => $lbl, 'input' => $inM];
} | [
"private",
"function",
"getTimestamping",
"(",
"$",
"dtl",
")",
"{",
"$",
"fieldValue",
"=",
"$",
"this",
"->",
"getFieldValue",
"(",
"$",
"dtl",
")",
";",
"$",
"inM",
"=",
"$",
"this",
"->",
"setStringIntoTag",
"(",
"$",
"fieldValue",
",",
"'span'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"fieldValue",
",",
"[",
"''",
",",
"'CURRENT_TIMESTAMP'",
",",
"'NULL'",
"]",
")",
")",
"{",
"$",
"mCN",
"=",
"[",
"'InsertDateTime'",
"=>",
"'data/timpul ad. informatiei'",
",",
"'ModificationDateTime'",
"=>",
"'data/timpul modificarii inf.'",
",",
"'modification_datetime'",
"=>",
"'data/timpul modificarii inf.'",
",",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"dtl",
"[",
"'COLUMN_NAME'",
"]",
",",
"$",
"mCN",
")",
")",
"{",
"$",
"inM",
"=",
"$",
"this",
"->",
"setStringIntoTag",
"(",
"$",
"mCN",
"[",
"$",
"dtl",
"[",
"'COLUMN_NAME'",
"]",
"]",
",",
"'span'",
",",
"[",
"'style'",
"=>",
"'font-style:italic;'",
"]",
")",
";",
"}",
"}",
"$",
"lbl",
"=",
"'<span class=\"fake_label\">'",
".",
"$",
"this",
"->",
"getFieldNameForDisplay",
"(",
"$",
"dtl",
")",
".",
"'</span>'",
";",
"return",
"[",
"'label'",
"=>",
"$",
"lbl",
",",
"'input'",
"=>",
"$",
"inM",
"]",
";",
"}"
] | Returns a timestamp field value
@param array $dtl
@return array | [
"Returns",
"a",
"timestamp",
"field",
"value"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiAdvancedOutput.php#L179-L195 | train |
anime-db/catalog-bundle | src/Controller/NoticeController.php | NoticeController.indexAction | public function indexAction(Request $request)
{
$response = $this->getCacheTimeKeeper()->getResponse('AnimeDbAppBundle:Notice');
// response was not modified for this request
if ($response->isNotModified($request)) {
return $response;
}
$rep = $this->getRepository();
$change_form = $this->createForm(new ChangeNotice())->handleRequest($request);
if ($change_form->isValid() && ($notices = $change_form->getData()['notices'])) {
switch ($change_form->getData()['action']) {
case ChangeNotice::ACTION_SET_STATUS_SHOWN:
$rep->setStatus($notices->toArray(), Notice::STATUS_SHOWN);
break;
case ChangeNotice::ACTION_SET_STATUS_CLOSED:
$rep->setStatus($notices->toArray(), Notice::STATUS_CLOSED);
break;
case ChangeNotice::ACTION_REMOVE:
$rep->remove($notices->toArray());
}
return $this->redirect($this->generateUrl('notice_list'));
}
return $this->render('AnimeDbCatalogBundle:Notice:index.html.twig', [
'has_notices' => $rep->count(),
], $response);
} | php | public function indexAction(Request $request)
{
$response = $this->getCacheTimeKeeper()->getResponse('AnimeDbAppBundle:Notice');
// response was not modified for this request
if ($response->isNotModified($request)) {
return $response;
}
$rep = $this->getRepository();
$change_form = $this->createForm(new ChangeNotice())->handleRequest($request);
if ($change_form->isValid() && ($notices = $change_form->getData()['notices'])) {
switch ($change_form->getData()['action']) {
case ChangeNotice::ACTION_SET_STATUS_SHOWN:
$rep->setStatus($notices->toArray(), Notice::STATUS_SHOWN);
break;
case ChangeNotice::ACTION_SET_STATUS_CLOSED:
$rep->setStatus($notices->toArray(), Notice::STATUS_CLOSED);
break;
case ChangeNotice::ACTION_REMOVE:
$rep->remove($notices->toArray());
}
return $this->redirect($this->generateUrl('notice_list'));
}
return $this->render('AnimeDbCatalogBundle:Notice:index.html.twig', [
'has_notices' => $rep->count(),
], $response);
} | [
"public",
"function",
"indexAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getCacheTimeKeeper",
"(",
")",
"->",
"getResponse",
"(",
"'AnimeDbAppBundle:Notice'",
")",
";",
"// response was not modified for this request",
"if",
"(",
"$",
"response",
"->",
"isNotModified",
"(",
"$",
"request",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"$",
"rep",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
";",
"$",
"change_form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ChangeNotice",
"(",
")",
")",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"change_form",
"->",
"isValid",
"(",
")",
"&&",
"(",
"$",
"notices",
"=",
"$",
"change_form",
"->",
"getData",
"(",
")",
"[",
"'notices'",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"change_form",
"->",
"getData",
"(",
")",
"[",
"'action'",
"]",
")",
"{",
"case",
"ChangeNotice",
"::",
"ACTION_SET_STATUS_SHOWN",
":",
"$",
"rep",
"->",
"setStatus",
"(",
"$",
"notices",
"->",
"toArray",
"(",
")",
",",
"Notice",
"::",
"STATUS_SHOWN",
")",
";",
"break",
";",
"case",
"ChangeNotice",
"::",
"ACTION_SET_STATUS_CLOSED",
":",
"$",
"rep",
"->",
"setStatus",
"(",
"$",
"notices",
"->",
"toArray",
"(",
")",
",",
"Notice",
"::",
"STATUS_CLOSED",
")",
";",
"break",
";",
"case",
"ChangeNotice",
"::",
"ACTION_REMOVE",
":",
"$",
"rep",
"->",
"remove",
"(",
"$",
"notices",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'notice_list'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'AnimeDbCatalogBundle:Notice:index.html.twig'",
",",
"[",
"'has_notices'",
"=>",
"$",
"rep",
"->",
"count",
"(",
")",
",",
"]",
",",
"$",
"response",
")",
";",
"}"
] | Edit list notices.
@param Request $request
@return Response | [
"Edit",
"list",
"notices",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Controller/NoticeController.php#L39-L67 | train |
anime-db/catalog-bundle | src/Controller/NoticeController.php | NoticeController.listAction | public function listAction(Request $request)
{
$current_page = $request->get('page', 1);
$current_page = $current_page > 1 ? $current_page : 1;
$rep = $this->getRepository();
// filter list notice
$filter = $this->createForm('notices_filter')->handleRequest($request);
if ($filter->isValid()) {
$query = $rep->getFilteredQuery($filter->getData()['status'], $filter->getData()['type']);
} else {
$query = $rep->createQueryBuilder('n');
}
$query
->orderBy('n.date_created', 'DESC')
->setFirstResult(($current_page - 1) * self::NOTICE_PER_PAGE)
->setMaxResults(self::NOTICE_PER_PAGE);
$list = $query->getQuery()->getResult();
// get count all items
$count = $query
->select('COUNT(n)')
->getQuery()
->getSingleScalarResult();
// pagination
$that = $this;
$request_query = $request->query->all();
unset($request_query['page']);
$pagination = $this->get('anime_db.pagination')
->create(ceil($count / self::NOTICE_PER_PAGE), $current_page)
->setPageLink(function ($page) use ($that, $request_query) {
return $that->generateUrl('notice_list', array_merge($request_query, ['page' => $page]));
})
->setFirstPageLink($this->generateUrl('notice_list', $request_query))
->getView();
return $this->render('AnimeDbCatalogBundle:Notice:list.html.twig', [
'list' => $list,
'pagination' => $pagination,
'change_form' => $this->createForm(new ChangeNotice())->createView(),
'filter' => $filter->createView(),
'action_remove' => ChangeNotice::ACTION_REMOVE,
]);
} | php | public function listAction(Request $request)
{
$current_page = $request->get('page', 1);
$current_page = $current_page > 1 ? $current_page : 1;
$rep = $this->getRepository();
// filter list notice
$filter = $this->createForm('notices_filter')->handleRequest($request);
if ($filter->isValid()) {
$query = $rep->getFilteredQuery($filter->getData()['status'], $filter->getData()['type']);
} else {
$query = $rep->createQueryBuilder('n');
}
$query
->orderBy('n.date_created', 'DESC')
->setFirstResult(($current_page - 1) * self::NOTICE_PER_PAGE)
->setMaxResults(self::NOTICE_PER_PAGE);
$list = $query->getQuery()->getResult();
// get count all items
$count = $query
->select('COUNT(n)')
->getQuery()
->getSingleScalarResult();
// pagination
$that = $this;
$request_query = $request->query->all();
unset($request_query['page']);
$pagination = $this->get('anime_db.pagination')
->create(ceil($count / self::NOTICE_PER_PAGE), $current_page)
->setPageLink(function ($page) use ($that, $request_query) {
return $that->generateUrl('notice_list', array_merge($request_query, ['page' => $page]));
})
->setFirstPageLink($this->generateUrl('notice_list', $request_query))
->getView();
return $this->render('AnimeDbCatalogBundle:Notice:list.html.twig', [
'list' => $list,
'pagination' => $pagination,
'change_form' => $this->createForm(new ChangeNotice())->createView(),
'filter' => $filter->createView(),
'action_remove' => ChangeNotice::ACTION_REMOVE,
]);
} | [
"public",
"function",
"listAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"current_page",
"=",
"$",
"request",
"->",
"get",
"(",
"'page'",
",",
"1",
")",
";",
"$",
"current_page",
"=",
"$",
"current_page",
">",
"1",
"?",
"$",
"current_page",
":",
"1",
";",
"$",
"rep",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
";",
"// filter list notice",
"$",
"filter",
"=",
"$",
"this",
"->",
"createForm",
"(",
"'notices_filter'",
")",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"filter",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"query",
"=",
"$",
"rep",
"->",
"getFilteredQuery",
"(",
"$",
"filter",
"->",
"getData",
"(",
")",
"[",
"'status'",
"]",
",",
"$",
"filter",
"->",
"getData",
"(",
")",
"[",
"'type'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"$",
"rep",
"->",
"createQueryBuilder",
"(",
"'n'",
")",
";",
"}",
"$",
"query",
"->",
"orderBy",
"(",
"'n.date_created'",
",",
"'DESC'",
")",
"->",
"setFirstResult",
"(",
"(",
"$",
"current_page",
"-",
"1",
")",
"*",
"self",
"::",
"NOTICE_PER_PAGE",
")",
"->",
"setMaxResults",
"(",
"self",
"::",
"NOTICE_PER_PAGE",
")",
";",
"$",
"list",
"=",
"$",
"query",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"// get count all items",
"$",
"count",
"=",
"$",
"query",
"->",
"select",
"(",
"'COUNT(n)'",
")",
"->",
"getQuery",
"(",
")",
"->",
"getSingleScalarResult",
"(",
")",
";",
"// pagination",
"$",
"that",
"=",
"$",
"this",
";",
"$",
"request_query",
"=",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
";",
"unset",
"(",
"$",
"request_query",
"[",
"'page'",
"]",
")",
";",
"$",
"pagination",
"=",
"$",
"this",
"->",
"get",
"(",
"'anime_db.pagination'",
")",
"->",
"create",
"(",
"ceil",
"(",
"$",
"count",
"/",
"self",
"::",
"NOTICE_PER_PAGE",
")",
",",
"$",
"current_page",
")",
"->",
"setPageLink",
"(",
"function",
"(",
"$",
"page",
")",
"use",
"(",
"$",
"that",
",",
"$",
"request_query",
")",
"{",
"return",
"$",
"that",
"->",
"generateUrl",
"(",
"'notice_list'",
",",
"array_merge",
"(",
"$",
"request_query",
",",
"[",
"'page'",
"=>",
"$",
"page",
"]",
")",
")",
";",
"}",
")",
"->",
"setFirstPageLink",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'notice_list'",
",",
"$",
"request_query",
")",
")",
"->",
"getView",
"(",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'AnimeDbCatalogBundle:Notice:list.html.twig'",
",",
"[",
"'list'",
"=>",
"$",
"list",
",",
"'pagination'",
"=>",
"$",
"pagination",
",",
"'change_form'",
"=>",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ChangeNotice",
"(",
")",
")",
"->",
"createView",
"(",
")",
",",
"'filter'",
"=>",
"$",
"filter",
"->",
"createView",
"(",
")",
",",
"'action_remove'",
"=>",
"ChangeNotice",
"::",
"ACTION_REMOVE",
",",
"]",
")",
";",
"}"
] | Get notice list.
@param Request $request
@return Response | [
"Get",
"notice",
"list",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Controller/NoticeController.php#L76-L120 | train |
WellBloud/sovacore-core | src/model/CoreFacade.php | CoreFacade.getAllPublished | public function getAllPublished(
$orderBy = null,
$limit = null
)
{
return $this->repository->findAllPublished($orderBy, $limit);
} | php | public function getAllPublished(
$orderBy = null,
$limit = null
)
{
return $this->repository->findAllPublished($orderBy, $limit);
} | [
"public",
"function",
"getAllPublished",
"(",
"$",
"orderBy",
"=",
"null",
",",
"$",
"limit",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"repository",
"->",
"findAllPublished",
"(",
"$",
"orderBy",
",",
"$",
"limit",
")",
";",
"}"
] | Method which finds all published items in the repository
@param array $orderBy
@param int $limit
@return array | [
"Method",
"which",
"finds",
"all",
"published",
"items",
"in",
"the",
"repository"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/CoreFacade.php#L35-L41 | train |
WellBloud/sovacore-core | src/model/CoreFacade.php | CoreFacade.getById | public function getById($id = null)
{
if ($id === null) {
throw new ItemNotSelectedException;
}
$entity = $this->repository->findById($id);
if (!$entity) {
throw new NonexistingItemException;
}
return $entity;
} | php | public function getById($id = null)
{
if ($id === null) {
throw new ItemNotSelectedException;
}
$entity = $this->repository->findById($id);
if (!$entity) {
throw new NonexistingItemException;
}
return $entity;
} | [
"public",
"function",
"getById",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"id",
"===",
"null",
")",
"{",
"throw",
"new",
"ItemNotSelectedException",
";",
"}",
"$",
"entity",
"=",
"$",
"this",
"->",
"repository",
"->",
"findById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"new",
"NonexistingItemException",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Method which finds one item in the repository
@param type $id
@return type entity
@throws ItemNotSelectedException | [
"Method",
"which",
"finds",
"one",
"item",
"in",
"the",
"repository"
] | 1816a0d7cd3ec4a90d64e301fc2469d171ad217f | https://github.com/WellBloud/sovacore-core/blob/1816a0d7cd3ec4a90d64e301fc2469d171ad217f/src/model/CoreFacade.php#L68-L78 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Message/AbstractMessage.php | AbstractMessage.parseHeader | public static function parseHeader(MessageInterface $message, $header)
{
static $trimmed = "\"' \n\t\r";
$params = $matches = [];
foreach (self::normalizeHeader($message, $header) as $val) {
$part = [];
foreach (preg_split('/;(?=([^"]*"[^"]*")*[^"]*$)/', $val) as $kvp) {
if (preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches)) {
$m = $matches[0];
if (isset($m[1])) {
$part[trim($m[0], $trimmed)] = trim($m[1], $trimmed);
} else {
$part[] = trim($m[0], $trimmed);
}
}
}
if ($part) {
$params[] = $part;
}
}
return $params;
} | php | public static function parseHeader(MessageInterface $message, $header)
{
static $trimmed = "\"' \n\t\r";
$params = $matches = [];
foreach (self::normalizeHeader($message, $header) as $val) {
$part = [];
foreach (preg_split('/;(?=([^"]*"[^"]*")*[^"]*$)/', $val) as $kvp) {
if (preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches)) {
$m = $matches[0];
if (isset($m[1])) {
$part[trim($m[0], $trimmed)] = trim($m[1], $trimmed);
} else {
$part[] = trim($m[0], $trimmed);
}
}
}
if ($part) {
$params[] = $part;
}
}
return $params;
} | [
"public",
"static",
"function",
"parseHeader",
"(",
"MessageInterface",
"$",
"message",
",",
"$",
"header",
")",
"{",
"static",
"$",
"trimmed",
"=",
"\"\\\"' \\n\\t\\r\"",
";",
"$",
"params",
"=",
"$",
"matches",
"=",
"[",
"]",
";",
"foreach",
"(",
"self",
"::",
"normalizeHeader",
"(",
"$",
"message",
",",
"$",
"header",
")",
"as",
"$",
"val",
")",
"{",
"$",
"part",
"=",
"[",
"]",
";",
"foreach",
"(",
"preg_split",
"(",
"'/;(?=([^\"]*\"[^\"]*\")*[^\"]*$)/'",
",",
"$",
"val",
")",
"as",
"$",
"kvp",
")",
"{",
"if",
"(",
"preg_match_all",
"(",
"'/<[^>]+>|[^=]+/'",
",",
"$",
"kvp",
",",
"$",
"matches",
")",
")",
"{",
"$",
"m",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"m",
"[",
"1",
"]",
")",
")",
"{",
"$",
"part",
"[",
"trim",
"(",
"$",
"m",
"[",
"0",
"]",
",",
"$",
"trimmed",
")",
"]",
"=",
"trim",
"(",
"$",
"m",
"[",
"1",
"]",
",",
"$",
"trimmed",
")",
";",
"}",
"else",
"{",
"$",
"part",
"[",
"]",
"=",
"trim",
"(",
"$",
"m",
"[",
"0",
"]",
",",
"$",
"trimmed",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"part",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"part",
";",
"}",
"}",
"return",
"$",
"params",
";",
"}"
] | Parse an array of header values containing ";" separated data into an
array of associative arrays representing the header key value pair
data of the header. When a parameter does not contain a value, but just
contains a key, this function will inject a key with a '' string value.
@param MessageInterface $message That contains the header
@param string $header Header to retrieve from the message
@return array Returns the parsed header values. | [
"Parse",
"an",
"array",
"of",
"header",
"values",
"containing",
";",
"separated",
"data",
"into",
"an",
"array",
"of",
"associative",
"arrays",
"representing",
"the",
"header",
"key",
"value",
"pair",
"data",
"of",
"the",
"header",
".",
"When",
"a",
"parameter",
"does",
"not",
"contain",
"a",
"value",
"but",
"just",
"contains",
"a",
"key",
"this",
"function",
"will",
"inject",
"a",
"key",
"with",
"a",
"string",
"value",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Message/AbstractMessage.php#L161-L184 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Message/AbstractMessage.php | AbstractMessage.getHeadersAsString | public static function getHeadersAsString(MessageInterface $message)
{
$result = '';
foreach ($message->getHeaders() as $name => $values) {
$result .= "\r\n{$name}: " . implode(', ', $values);
}
return $result;
} | php | public static function getHeadersAsString(MessageInterface $message)
{
$result = '';
foreach ($message->getHeaders() as $name => $values) {
$result .= "\r\n{$name}: " . implode(', ', $values);
}
return $result;
} | [
"public",
"static",
"function",
"getHeadersAsString",
"(",
"MessageInterface",
"$",
"message",
")",
"{",
"$",
"result",
"=",
"''",
";",
"foreach",
"(",
"$",
"message",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"values",
")",
"{",
"$",
"result",
".=",
"\"\\r\\n{$name}: \"",
".",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Gets the headers of a message as a string
@param MessageInterface $message
@return string | [
"Gets",
"the",
"headers",
"of",
"a",
"message",
"as",
"a",
"string"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Message/AbstractMessage.php#L231-L239 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Message/AbstractMessage.php | AbstractMessage.getStartLine | public static function getStartLine(MessageInterface $message)
{
if ($message instanceof RequestInterface) {
return trim($message->getMethod() . ' '
. $message->getResource())
. ' HTTP/' . $message->getProtocolVersion();
} elseif ($message instanceof ResponseInterface) {
return 'HTTP/' . $message->getProtocolVersion() . ' '
. $message->getStatusCode() . ' '
. $message->getReasonPhrase();
} else {
throw new \InvalidArgumentException('Unknown message type');
}
} | php | public static function getStartLine(MessageInterface $message)
{
if ($message instanceof RequestInterface) {
return trim($message->getMethod() . ' '
. $message->getResource())
. ' HTTP/' . $message->getProtocolVersion();
} elseif ($message instanceof ResponseInterface) {
return 'HTTP/' . $message->getProtocolVersion() . ' '
. $message->getStatusCode() . ' '
. $message->getReasonPhrase();
} else {
throw new \InvalidArgumentException('Unknown message type');
}
} | [
"public",
"static",
"function",
"getStartLine",
"(",
"MessageInterface",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"message",
"instanceof",
"RequestInterface",
")",
"{",
"return",
"trim",
"(",
"$",
"message",
"->",
"getMethod",
"(",
")",
".",
"' '",
".",
"$",
"message",
"->",
"getResource",
"(",
")",
")",
".",
"' HTTP/'",
".",
"$",
"message",
"->",
"getProtocolVersion",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"message",
"instanceof",
"ResponseInterface",
")",
"{",
"return",
"'HTTP/'",
".",
"$",
"message",
"->",
"getProtocolVersion",
"(",
")",
".",
"' '",
".",
"$",
"message",
"->",
"getStatusCode",
"(",
")",
".",
"' '",
".",
"$",
"message",
"->",
"getReasonPhrase",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unknown message type'",
")",
";",
"}",
"}"
] | Gets the start line of a message
@param MessageInterface $message
@return string
@throws \InvalidArgumentException | [
"Gets",
"the",
"start",
"line",
"of",
"a",
"message"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Message/AbstractMessage.php#L249-L262 | train |
DeimosProject/Request | src/Request/URL.php | URL.url | public function url($withParams = false)
{
$url = $this->scheme() . '://';
$url .= $this->domain();
return $url . $this->urlPath($withParams);
} | php | public function url($withParams = false)
{
$url = $this->scheme() . '://';
$url .= $this->domain();
return $url . $this->urlPath($withParams);
} | [
"public",
"function",
"url",
"(",
"$",
"withParams",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"scheme",
"(",
")",
".",
"'://'",
";",
"$",
"url",
".=",
"$",
"this",
"->",
"domain",
"(",
")",
";",
"return",
"$",
"url",
".",
"$",
"this",
"->",
"urlPath",
"(",
"$",
"withParams",
")",
";",
"}"
] | Gets request URL
@param bool $withParams Whether to preserve URL parameters
@return string URL of this request | [
"Gets",
"request",
"URL"
] | 3e45af0fdbfc3c47c27de27a98e8980ba42c3737 | https://github.com/DeimosProject/Request/blob/3e45af0fdbfc3c47c27de27a98e8980ba42c3737/src/Request/URL.php#L74-L80 | train |
DeimosProject/Request | src/Request/URL.php | URL.urlPath | public function urlPath($withParams = false)
{
$path = $this->server('request_uri');
if (!$withParams)
{
$position = mb_strpos($path, '?');
if ($position !== false)
{
$path = mb_substr($path, 0, $position);
}
}
return $path;
} | php | public function urlPath($withParams = false)
{
$path = $this->server('request_uri');
if (!$withParams)
{
$position = mb_strpos($path, '?');
if ($position !== false)
{
$path = mb_substr($path, 0, $position);
}
}
return $path;
} | [
"public",
"function",
"urlPath",
"(",
"$",
"withParams",
"=",
"false",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"server",
"(",
"'request_uri'",
")",
";",
"if",
"(",
"!",
"$",
"withParams",
")",
"{",
"$",
"position",
"=",
"mb_strpos",
"(",
"$",
"path",
",",
"'?'",
")",
";",
"if",
"(",
"$",
"position",
"!==",
"false",
")",
"{",
"$",
"path",
"=",
"mb_substr",
"(",
"$",
"path",
",",
"0",
",",
"$",
"position",
")",
";",
"}",
"}",
"return",
"$",
"path",
";",
"}"
] | without host & schema
@param bool $withParams
@return string | [
"without",
"host",
"&",
"schema"
] | 3e45af0fdbfc3c47c27de27a98e8980ba42c3737 | https://github.com/DeimosProject/Request/blob/3e45af0fdbfc3c47c27de27a98e8980ba42c3737/src/Request/URL.php#L89-L103 | train |
offworks/laraquent | src/Blueprint.php | Blueprint.addColumn | public function addColumn($type, $column, array $parameters = array())
{
// check against existing
if(!$this->builder->hasColumn($this->table, $column))
return parent::addColumn($type, $column, $parameters);
// else probably compare and do some alteration
} | php | public function addColumn($type, $column, array $parameters = array())
{
// check against existing
if(!$this->builder->hasColumn($this->table, $column))
return parent::addColumn($type, $column, $parameters);
// else probably compare and do some alteration
} | [
"public",
"function",
"addColumn",
"(",
"$",
"type",
",",
"$",
"column",
",",
"array",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"// check against existing",
"if",
"(",
"!",
"$",
"this",
"->",
"builder",
"->",
"hasColumn",
"(",
"$",
"this",
"->",
"table",
",",
"$",
"column",
")",
")",
"return",
"parent",
"::",
"addColumn",
"(",
"$",
"type",
",",
"$",
"column",
",",
"$",
"parameters",
")",
";",
"// else probably compare and do some alteration",
"}"
] | Add column only if there isn't one.
So it will not throw if there already exists. | [
"Add",
"column",
"only",
"if",
"there",
"isn",
"t",
"one",
".",
"So",
"it",
"will",
"not",
"throw",
"if",
"there",
"already",
"exists",
"."
] | 74cbc6258acfda8f7213c701887a7b223aff954f | https://github.com/offworks/laraquent/blob/74cbc6258acfda8f7213c701887a7b223aff954f/src/Blueprint.php#L19-L26 | train |
ARCANESOFT/Auth | src/Providers/PackagesServiceProvider.php | PackagesServiceProvider.configLaravelAuthPackage | private function configLaravelAuthPackage()
{
$config = $this->config();
$config->set(
'laravel-auth',
Arr::only($config->get('arcanesoft.auth'), [
'database', 'users', 'roles', 'role-user', 'permissions-groups', 'permissions', 'permission-role',
'password-resets', 'events', 'user-confirmation', 'track-activity', 'socialite', 'throttles', 'seeds'
])
);
if (SocialAuthenticator::isEnabled()) {
$this->registerProvider(\Laravel\Socialite\SocialiteServiceProvider::class);
}
} | php | private function configLaravelAuthPackage()
{
$config = $this->config();
$config->set(
'laravel-auth',
Arr::only($config->get('arcanesoft.auth'), [
'database', 'users', 'roles', 'role-user', 'permissions-groups', 'permissions', 'permission-role',
'password-resets', 'events', 'user-confirmation', 'track-activity', 'socialite', 'throttles', 'seeds'
])
);
if (SocialAuthenticator::isEnabled()) {
$this->registerProvider(\Laravel\Socialite\SocialiteServiceProvider::class);
}
} | [
"private",
"function",
"configLaravelAuthPackage",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"(",
")",
";",
"$",
"config",
"->",
"set",
"(",
"'laravel-auth'",
",",
"Arr",
"::",
"only",
"(",
"$",
"config",
"->",
"get",
"(",
"'arcanesoft.auth'",
")",
",",
"[",
"'database'",
",",
"'users'",
",",
"'roles'",
",",
"'role-user'",
",",
"'permissions-groups'",
",",
"'permissions'",
",",
"'permission-role'",
",",
"'password-resets'",
",",
"'events'",
",",
"'user-confirmation'",
",",
"'track-activity'",
",",
"'socialite'",
",",
"'throttles'",
",",
"'seeds'",
"]",
")",
")",
";",
"if",
"(",
"SocialAuthenticator",
"::",
"isEnabled",
"(",
")",
")",
"{",
"$",
"this",
"->",
"registerProvider",
"(",
"\\",
"Laravel",
"\\",
"Socialite",
"\\",
"SocialiteServiceProvider",
"::",
"class",
")",
";",
"}",
"}"
] | Config the Laravel Auth package. | [
"Config",
"the",
"Laravel",
"Auth",
"package",
"."
] | b33ca82597a76b1e395071f71ae3e51f1ec67e62 | https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Providers/PackagesServiceProvider.php#L86-L100 | train |
ARCANESOFT/Auth | src/Providers/PackagesServiceProvider.php | PackagesServiceProvider.rebindModels | private function rebindModels()
{
$config = $this->config();
$bindings = [
[
'abstract' => \Arcanesoft\Contracts\Auth\Models\User::class,
'concrete' => $config->get('arcanesoft.auth.users.model'),
],[
'abstract' => \Arcanesoft\Contracts\Auth\Models\Role::class,
'concrete' => $config->get('arcanesoft.auth.roles.model'),
],[
'abstract' => \Arcanesoft\Contracts\Auth\Models\Permission::class,
'concrete' => $config->get('arcanesoft.auth.permissions.model'),
],[
'abstract' => \Arcanesoft\Contracts\Auth\Models\PermissionsGroup::class,
'concrete' => $config->get('arcanesoft.auth.permissions-groups.model'),
],
];
foreach ($bindings as $binding) {
$this->bind($binding['abstract'], $binding['concrete']);
}
} | php | private function rebindModels()
{
$config = $this->config();
$bindings = [
[
'abstract' => \Arcanesoft\Contracts\Auth\Models\User::class,
'concrete' => $config->get('arcanesoft.auth.users.model'),
],[
'abstract' => \Arcanesoft\Contracts\Auth\Models\Role::class,
'concrete' => $config->get('arcanesoft.auth.roles.model'),
],[
'abstract' => \Arcanesoft\Contracts\Auth\Models\Permission::class,
'concrete' => $config->get('arcanesoft.auth.permissions.model'),
],[
'abstract' => \Arcanesoft\Contracts\Auth\Models\PermissionsGroup::class,
'concrete' => $config->get('arcanesoft.auth.permissions-groups.model'),
],
];
foreach ($bindings as $binding) {
$this->bind($binding['abstract'], $binding['concrete']);
}
} | [
"private",
"function",
"rebindModels",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"(",
")",
";",
"$",
"bindings",
"=",
"[",
"[",
"'abstract'",
"=>",
"\\",
"Arcanesoft",
"\\",
"Contracts",
"\\",
"Auth",
"\\",
"Models",
"\\",
"User",
"::",
"class",
",",
"'concrete'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'arcanesoft.auth.users.model'",
")",
",",
"]",
",",
"[",
"'abstract'",
"=>",
"\\",
"Arcanesoft",
"\\",
"Contracts",
"\\",
"Auth",
"\\",
"Models",
"\\",
"Role",
"::",
"class",
",",
"'concrete'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'arcanesoft.auth.roles.model'",
")",
",",
"]",
",",
"[",
"'abstract'",
"=>",
"\\",
"Arcanesoft",
"\\",
"Contracts",
"\\",
"Auth",
"\\",
"Models",
"\\",
"Permission",
"::",
"class",
",",
"'concrete'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'arcanesoft.auth.permissions.model'",
")",
",",
"]",
",",
"[",
"'abstract'",
"=>",
"\\",
"Arcanesoft",
"\\",
"Contracts",
"\\",
"Auth",
"\\",
"Models",
"\\",
"PermissionsGroup",
"::",
"class",
",",
"'concrete'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'arcanesoft.auth.permissions-groups.model'",
")",
",",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"bindings",
"as",
"$",
"binding",
")",
"{",
"$",
"this",
"->",
"bind",
"(",
"$",
"binding",
"[",
"'abstract'",
"]",
",",
"$",
"binding",
"[",
"'concrete'",
"]",
")",
";",
"}",
"}"
] | Rebind the auth models. | [
"Rebind",
"the",
"auth",
"models",
"."
] | b33ca82597a76b1e395071f71ae3e51f1ec67e62 | https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Providers/PackagesServiceProvider.php#L115-L137 | train |
hiqdev/hidev-phpunit | src/console/PhpunitController.php | PhpunitController.actionGenfake | public function actionGenfake($file)
{
$path = $this->buildFakePath($file);
if (!$this->force && file_exists($path)) {
Yii::warning("already exists: $path");
return 1;
}
return $this->genFake($file, $path);
} | php | public function actionGenfake($file)
{
$path = $this->buildFakePath($file);
if (!$this->force && file_exists($path)) {
Yii::warning("already exists: $path");
return 1;
}
return $this->genFake($file, $path);
} | [
"public",
"function",
"actionGenfake",
"(",
"$",
"file",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"buildFakePath",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"force",
"&&",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"Yii",
"::",
"warning",
"(",
"\"already exists: $path\"",
")",
";",
"return",
"1",
";",
"}",
"return",
"$",
"this",
"->",
"genFake",
"(",
"$",
"file",
",",
"$",
"path",
")",
";",
"}"
] | Generates skeleton class for fake. | [
"Generates",
"skeleton",
"class",
"for",
"fake",
"."
] | 53f3567490b20c720b911e4486a010585db13d28 | https://github.com/hiqdev/hidev-phpunit/blob/53f3567490b20c720b911e4486a010585db13d28/src/console/PhpunitController.php#L50-L60 | train |
Wedeto/DB | src/Query/GetClause.php | GetClause.toSQL | public function toSQL(Parameters $params, bool $inner_clause)
{
$alias = $this->alias;
$drv = $params->getDriver();
$sql = $drv->toSQL($params, $this->expression, true);
if (empty($this->alias))
$this->alias = $params->generateAlias($this->expression);
if (!empty($this->alias))
return $sql . ' AS ' . $drv->identQuote($this->alias);
return $sql;
} | php | public function toSQL(Parameters $params, bool $inner_clause)
{
$alias = $this->alias;
$drv = $params->getDriver();
$sql = $drv->toSQL($params, $this->expression, true);
if (empty($this->alias))
$this->alias = $params->generateAlias($this->expression);
if (!empty($this->alias))
return $sql . ' AS ' . $drv->identQuote($this->alias);
return $sql;
} | [
"public",
"function",
"toSQL",
"(",
"Parameters",
"$",
"params",
",",
"bool",
"$",
"inner_clause",
")",
"{",
"$",
"alias",
"=",
"$",
"this",
"->",
"alias",
";",
"$",
"drv",
"=",
"$",
"params",
"->",
"getDriver",
"(",
")",
";",
"$",
"sql",
"=",
"$",
"drv",
"->",
"toSQL",
"(",
"$",
"params",
",",
"$",
"this",
"->",
"expression",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"alias",
")",
")",
"$",
"this",
"->",
"alias",
"=",
"$",
"params",
"->",
"generateAlias",
"(",
"$",
"this",
"->",
"expression",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"alias",
")",
")",
"return",
"$",
"sql",
".",
"' AS '",
".",
"$",
"drv",
"->",
"identQuote",
"(",
"$",
"this",
"->",
"alias",
")",
";",
"return",
"$",
"sql",
";",
"}"
] | Write a select return clause as SQL query syntax
@param Parameters $params The query parameters: tables and placeholder values
@return string The generated SQL | [
"Write",
"a",
"select",
"return",
"clause",
"as",
"SQL",
"query",
"syntax"
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/GetClause.php#L56-L70 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/xml/SimpleXMLParser.php | SimpleXMLParser.parseXMLString | public function parseXMLString($xmlString, $simpleXMLClass = 'SimpleXMLExtended')
{
libxml_use_internal_errors(true);
$doc = simplexml_load_string($xmlString, $simpleXMLClass);
if (false === $doc) {
$xml = explode("\n", $xmlString);
$errors = libxml_get_errors();
$errorString = '';
foreach ($errors as $error) {
$errorString .= $this->displayXmlError($error, $xml);
}
libxml_clear_errors();
throw new SimpleXMLParserException("Unable to parse xml string:\n\n".$errorString);
}
return $doc;
} | php | public function parseXMLString($xmlString, $simpleXMLClass = 'SimpleXMLExtended')
{
libxml_use_internal_errors(true);
$doc = simplexml_load_string($xmlString, $simpleXMLClass);
if (false === $doc) {
$xml = explode("\n", $xmlString);
$errors = libxml_get_errors();
$errorString = '';
foreach ($errors as $error) {
$errorString .= $this->displayXmlError($error, $xml);
}
libxml_clear_errors();
throw new SimpleXMLParserException("Unable to parse xml string:\n\n".$errorString);
}
return $doc;
} | [
"public",
"function",
"parseXMLString",
"(",
"$",
"xmlString",
",",
"$",
"simpleXMLClass",
"=",
"'SimpleXMLExtended'",
")",
"{",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"doc",
"=",
"simplexml_load_string",
"(",
"$",
"xmlString",
",",
"$",
"simpleXMLClass",
")",
";",
"if",
"(",
"false",
"===",
"$",
"doc",
")",
"{",
"$",
"xml",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"xmlString",
")",
";",
"$",
"errors",
"=",
"libxml_get_errors",
"(",
")",
";",
"$",
"errorString",
"=",
"''",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"error",
")",
"{",
"$",
"errorString",
".=",
"$",
"this",
"->",
"displayXmlError",
"(",
"$",
"error",
",",
"$",
"xml",
")",
";",
"}",
"libxml_clear_errors",
"(",
")",
";",
"throw",
"new",
"SimpleXMLParserException",
"(",
"\"Unable to parse xml string:\\n\\n\"",
".",
"$",
"errorString",
")",
";",
"}",
"return",
"$",
"doc",
";",
"}"
] | Converts an XML string into a SimpleXMLElement object
@param string $xmlString String of well-formed XML
@param string $simpleXMLClass Optional parameter to specify classname of
the return object. That class should extend the SimpleXMLElement class.
@return SimpleXMLElement Object of specified class
@throws SimpleXMLParserException upon parse error, or class
not found for {@link $simpleXMLClass} | [
"Converts",
"an",
"XML",
"string",
"into",
"a",
"SimpleXMLElement",
"object"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/xml/SimpleXMLParser.php#L46-L68 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/xml/SimpleXMLParser.php | SimpleXMLParser.loadIncludes | protected function loadIncludes($xmlPath, $xmlString)
{
$m = null;
if (preg_match_all("/\<include\s*href\=\"([^\"]+)\".*?\/\>/si", $xmlString, $m, PREG_SET_ORDER) !== false) {
foreach ($m as $match) {
$includeFile = rtrim($xmlPath, '/').'/'.$match[1];
if (file_exists($includeFile)) {
$includeString = file_get_contents($includeFile);
$includeString = $this->loadIncludes(dirname($includeFile), $includeString);
$xmlString = str_replace($match[0], $includeString, $xmlString);
} else {
throw new Exception("XML include file not found: {$includeFile}");
}
}
}
return $xmlString;
} | php | protected function loadIncludes($xmlPath, $xmlString)
{
$m = null;
if (preg_match_all("/\<include\s*href\=\"([^\"]+)\".*?\/\>/si", $xmlString, $m, PREG_SET_ORDER) !== false) {
foreach ($m as $match) {
$includeFile = rtrim($xmlPath, '/').'/'.$match[1];
if (file_exists($includeFile)) {
$includeString = file_get_contents($includeFile);
$includeString = $this->loadIncludes(dirname($includeFile), $includeString);
$xmlString = str_replace($match[0], $includeString, $xmlString);
} else {
throw new Exception("XML include file not found: {$includeFile}");
}
}
}
return $xmlString;
} | [
"protected",
"function",
"loadIncludes",
"(",
"$",
"xmlPath",
",",
"$",
"xmlString",
")",
"{",
"$",
"m",
"=",
"null",
";",
"if",
"(",
"preg_match_all",
"(",
"\"/\\<include\\s*href\\=\\\"([^\\\"]+)\\\".*?\\/\\>/si\"",
",",
"$",
"xmlString",
",",
"$",
"m",
",",
"PREG_SET_ORDER",
")",
"!==",
"false",
")",
"{",
"foreach",
"(",
"$",
"m",
"as",
"$",
"match",
")",
"{",
"$",
"includeFile",
"=",
"rtrim",
"(",
"$",
"xmlPath",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"match",
"[",
"1",
"]",
";",
"if",
"(",
"file_exists",
"(",
"$",
"includeFile",
")",
")",
"{",
"$",
"includeString",
"=",
"file_get_contents",
"(",
"$",
"includeFile",
")",
";",
"$",
"includeString",
"=",
"$",
"this",
"->",
"loadIncludes",
"(",
"dirname",
"(",
"$",
"includeFile",
")",
",",
"$",
"includeString",
")",
";",
"$",
"xmlString",
"=",
"str_replace",
"(",
"$",
"match",
"[",
"0",
"]",
",",
"$",
"includeString",
",",
"$",
"xmlString",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"XML include file not found: {$includeFile}\"",
")",
";",
"}",
"}",
"}",
"return",
"$",
"xmlString",
";",
"}"
] | Loads all the includes into the xml string.
@param string $xmlPath The absolute path to the directory where the include files are located
@param string $xmlString The full XML string (usually file contents from an xml doc)
@return string the full xml string with any includes replaced by the included content | [
"Loads",
"all",
"the",
"includes",
"into",
"the",
"xml",
"string",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/xml/SimpleXMLParser.php#L177-L194 | train |
liip/DataAggregator | src/Liip/DataAggregator/Subjects/SubjectDispatcher.php | SubjectDispatcher.attachSubject | public function attachSubject($event, \SplSubject $subject)
{
$key = $this->getUniqueKey($event);
if (!array_key_exists($event, $this->subjects)) {
$this->subjects[$event] = array();
}
$this->subjects[$event][$key] = $subject;
return $key;
} | php | public function attachSubject($event, \SplSubject $subject)
{
$key = $this->getUniqueKey($event);
if (!array_key_exists($event, $this->subjects)) {
$this->subjects[$event] = array();
}
$this->subjects[$event][$key] = $subject;
return $key;
} | [
"public",
"function",
"attachSubject",
"(",
"$",
"event",
",",
"\\",
"SplSubject",
"$",
"subject",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getUniqueKey",
"(",
"$",
"event",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"event",
",",
"$",
"this",
"->",
"subjects",
")",
")",
"{",
"$",
"this",
"->",
"subjects",
"[",
"$",
"event",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"subjects",
"[",
"$",
"event",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"subject",
";",
"return",
"$",
"key",
";",
"}"
] | Registers a subject to be called an a specific event.
@param string $event
@param \SplSubject $subject
@return string | [
"Registers",
"a",
"subject",
"to",
"be",
"called",
"an",
"a",
"specific",
"event",
"."
] | 53da08ed3f5f24597be9f40ecf8ec44da7765e47 | https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/Subjects/SubjectDispatcher.php#L23-L34 | train |
liip/DataAggregator | src/Liip/DataAggregator/Subjects/SubjectDispatcher.php | SubjectDispatcher.detachSubject | public function detachSubject($event, $key)
{
Assertion::notEmptyKey($this->subjects, $event, 'Provided event does not exist.');
Assertion::notEmptyKey($this->subjects[$event], $key, 'Subject to be detached does not exist.');
unset($this->subjects[$event][$key]);
} | php | public function detachSubject($event, $key)
{
Assertion::notEmptyKey($this->subjects, $event, 'Provided event does not exist.');
Assertion::notEmptyKey($this->subjects[$event], $key, 'Subject to be detached does not exist.');
unset($this->subjects[$event][$key]);
} | [
"public",
"function",
"detachSubject",
"(",
"$",
"event",
",",
"$",
"key",
")",
"{",
"Assertion",
"::",
"notEmptyKey",
"(",
"$",
"this",
"->",
"subjects",
",",
"$",
"event",
",",
"'Provided event does not exist.'",
")",
";",
"Assertion",
"::",
"notEmptyKey",
"(",
"$",
"this",
"->",
"subjects",
"[",
"$",
"event",
"]",
",",
"$",
"key",
",",
"'Subject to be detached does not exist.'",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"subjects",
"[",
"$",
"event",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}"
] | Unregisters a subject from a specific event.
@param string $event
@param string $key | [
"Unregisters",
"a",
"subject",
"from",
"a",
"specific",
"event",
"."
] | 53da08ed3f5f24597be9f40ecf8ec44da7765e47 | https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/Subjects/SubjectDispatcher.php#L42-L48 | train |
liip/DataAggregator | src/Liip/DataAggregator/Subjects/SubjectDispatcher.php | SubjectDispatcher.emit | public function emit($event)
{
if (!empty($this->subjects[$event])) {
/** @var \SplSubject $subject */
foreach($this->subjects[$event] as $subject) {
$subject->notify();
}
}
} | php | public function emit($event)
{
if (!empty($this->subjects[$event])) {
/** @var \SplSubject $subject */
foreach($this->subjects[$event] as $subject) {
$subject->notify();
}
}
} | [
"public",
"function",
"emit",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"subjects",
"[",
"$",
"event",
"]",
")",
")",
"{",
"/** @var \\SplSubject $subject */",
"foreach",
"(",
"$",
"this",
"->",
"subjects",
"[",
"$",
"event",
"]",
"as",
"$",
"subject",
")",
"{",
"$",
"subject",
"->",
"notify",
"(",
")",
";",
"}",
"}",
"}"
] | Triggers every subject attached to an event.
@param string $event | [
"Triggers",
"every",
"subject",
"attached",
"to",
"an",
"event",
"."
] | 53da08ed3f5f24597be9f40ecf8ec44da7765e47 | https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/Subjects/SubjectDispatcher.php#L56-L65 | train |
koolkode/stream | src/ErrorHandlerTrait.php | ErrorHandlerTrait.handleError | protected static function handleError()
{
if(self::$errorHandler === NULL)
{
self::$errorHandler = function ($type, $message, $file, $line) {
throw new \RuntimeException($message);
};
}
return self::$errorHandler;
} | php | protected static function handleError()
{
if(self::$errorHandler === NULL)
{
self::$errorHandler = function ($type, $message, $file, $line) {
throw new \RuntimeException($message);
};
}
return self::$errorHandler;
} | [
"protected",
"static",
"function",
"handleError",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"errorHandler",
"===",
"NULL",
")",
"{",
"self",
"::",
"$",
"errorHandler",
"=",
"function",
"(",
"$",
"type",
",",
"$",
"message",
",",
"$",
"file",
",",
"$",
"line",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
";",
"}",
"return",
"self",
"::",
"$",
"errorHandler",
";",
"}"
] | Initialize and return the error handler callback.
@return callable | [
"Initialize",
"and",
"return",
"the",
"error",
"handler",
"callback",
"."
] | 05e83efd76e1cb9e40a972711986b4a7e38bc141 | https://github.com/koolkode/stream/blob/05e83efd76e1cb9e40a972711986b4a7e38bc141/src/ErrorHandlerTrait.php#L33-L43 | train |
Facebook-Anonymous-Publisher/firewall | src/Firewall.php | Firewall.isAllowCountry | public function isAllowCountry(array $codes = ['*'])
{
try {
return in_array('*', $codes, true)
|| in_array(Utility::isoCode($this->ip()), $codes, true);
} catch (\Exception $e) {
return true;
}
} | php | public function isAllowCountry(array $codes = ['*'])
{
try {
return in_array('*', $codes, true)
|| in_array(Utility::isoCode($this->ip()), $codes, true);
} catch (\Exception $e) {
return true;
}
} | [
"public",
"function",
"isAllowCountry",
"(",
"array",
"$",
"codes",
"=",
"[",
"'*'",
"]",
")",
"{",
"try",
"{",
"return",
"in_array",
"(",
"'*'",
",",
"$",
"codes",
",",
"true",
")",
"||",
"in_array",
"(",
"Utility",
"::",
"isoCode",
"(",
"$",
"this",
"->",
"ip",
"(",
")",
")",
",",
"$",
"codes",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"true",
";",
"}",
"}"
] | Determine the request ip address is in allow countries.
@param array $codes
@return bool | [
"Determine",
"the",
"request",
"ip",
"address",
"is",
"in",
"allow",
"countries",
"."
] | 3d78855cc828a1ebda37ac73c41fd64dc8dd0583 | https://github.com/Facebook-Anonymous-Publisher/firewall/blob/3d78855cc828a1ebda37ac73c41fd64dc8dd0583/src/Firewall.php#L79-L87 | train |
Facebook-Anonymous-Publisher/firewall | src/Firewall.php | Firewall.ban | public function ban($ip = null, $type = 'regular')
{
$this->validateType($type);
if (! is_null($ip)) {
if ('segment' === $type) {
$ip = Utility::cidr($ip);
}
} else {
$ip = $this->ip();
session(['isBan' => $type]);
}
return $this->model->firstOrCreate(compact('ip'), compact('type'));
} | php | public function ban($ip = null, $type = 'regular')
{
$this->validateType($type);
if (! is_null($ip)) {
if ('segment' === $type) {
$ip = Utility::cidr($ip);
}
} else {
$ip = $this->ip();
session(['isBan' => $type]);
}
return $this->model->firstOrCreate(compact('ip'), compact('type'));
} | [
"public",
"function",
"ban",
"(",
"$",
"ip",
"=",
"null",
",",
"$",
"type",
"=",
"'regular'",
")",
"{",
"$",
"this",
"->",
"validateType",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"ip",
")",
")",
"{",
"if",
"(",
"'segment'",
"===",
"$",
"type",
")",
"{",
"$",
"ip",
"=",
"Utility",
"::",
"cidr",
"(",
"$",
"ip",
")",
";",
"}",
"}",
"else",
"{",
"$",
"ip",
"=",
"$",
"this",
"->",
"ip",
"(",
")",
";",
"session",
"(",
"[",
"'isBan'",
"=>",
"$",
"type",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"model",
"->",
"firstOrCreate",
"(",
"compact",
"(",
"'ip'",
")",
",",
"compact",
"(",
"'type'",
")",
")",
";",
"}"
] | Ban ip address.
@param string|null $ip
@param string $type
@return Models\Firewall | [
"Ban",
"ip",
"address",
"."
] | 3d78855cc828a1ebda37ac73c41fd64dc8dd0583 | https://github.com/Facebook-Anonymous-Publisher/firewall/blob/3d78855cc828a1ebda37ac73c41fd64dc8dd0583/src/Firewall.php#L97-L112 | train |
Facebook-Anonymous-Publisher/firewall | src/Firewall.php | Firewall.unban | public function unban($ip = null)
{
if (is_null($ip)) {
$ip = $this->ip();
session()->forget('isBan');
}
return $this->model->destroy($ip);
} | php | public function unban($ip = null)
{
if (is_null($ip)) {
$ip = $this->ip();
session()->forget('isBan');
}
return $this->model->destroy($ip);
} | [
"public",
"function",
"unban",
"(",
"$",
"ip",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"ip",
")",
")",
"{",
"$",
"ip",
"=",
"$",
"this",
"->",
"ip",
"(",
")",
";",
"session",
"(",
")",
"->",
"forget",
"(",
"'isBan'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"model",
"->",
"destroy",
"(",
"$",
"ip",
")",
";",
"}"
] | Unban ip address.
@param string|null $ip
@return int | [
"Unban",
"ip",
"address",
"."
] | 3d78855cc828a1ebda37ac73c41fd64dc8dd0583 | https://github.com/Facebook-Anonymous-Publisher/firewall/blob/3d78855cc828a1ebda37ac73c41fd64dc8dd0583/src/Firewall.php#L133-L142 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/storagefacility/LocalStorageFacility.php | LocalStorageFacility.fileExists | public function fileExists(StorageFacilityParams $params, $fileid)
{
$this->validateFileID($fileid);
return file_exists($this->generateStoragePath($params, $fileid));
} | php | public function fileExists(StorageFacilityParams $params, $fileid)
{
$this->validateFileID($fileid);
return file_exists($this->generateStoragePath($params, $fileid));
} | [
"public",
"function",
"fileExists",
"(",
"StorageFacilityParams",
"$",
"params",
",",
"$",
"fileid",
")",
"{",
"$",
"this",
"->",
"validateFileID",
"(",
"$",
"fileid",
")",
";",
"return",
"file_exists",
"(",
"$",
"this",
"->",
"generateStoragePath",
"(",
"$",
"params",
",",
"$",
"fileid",
")",
")",
";",
"}"
] | Returns true if the file exists in the storage facility or
false if it doesn't exist. Throws an exception is the operation failed.
@param Site $site Site used to determine storage location
@param string $fileid File identifier of stored file, ex. /path/to/file.jpg
@return boolean
@throws StorageFacilityException if operation fails | [
"Returns",
"true",
"if",
"the",
"file",
"exists",
"in",
"the",
"storage",
"facility",
"or",
"false",
"if",
"it",
"doesn",
"t",
"exist",
".",
"Throws",
"an",
"exception",
"is",
"the",
"operation",
"failed",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/storagefacility/LocalStorageFacility.php#L124-L128 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/storagefacility/LocalStorageFacility.php | LocalStorageFacility.deleteFile | public function deleteFile(StorageFacilityParams $params, $fileid)
{
$this->validateFileID($fileid);
$storagePath = $this->generateStoragePath($params, $fileid);
if (is_file($storagePath)) {
if (!@unlink($storagePath)) {
throw new StorageFacilityException("Cannot delete file '".$storagePath."'");
} else {
return true;
}
}
} | php | public function deleteFile(StorageFacilityParams $params, $fileid)
{
$this->validateFileID($fileid);
$storagePath = $this->generateStoragePath($params, $fileid);
if (is_file($storagePath)) {
if (!@unlink($storagePath)) {
throw new StorageFacilityException("Cannot delete file '".$storagePath."'");
} else {
return true;
}
}
} | [
"public",
"function",
"deleteFile",
"(",
"StorageFacilityParams",
"$",
"params",
",",
"$",
"fileid",
")",
"{",
"$",
"this",
"->",
"validateFileID",
"(",
"$",
"fileid",
")",
";",
"$",
"storagePath",
"=",
"$",
"this",
"->",
"generateStoragePath",
"(",
"$",
"params",
",",
"$",
"fileid",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"storagePath",
")",
")",
"{",
"if",
"(",
"!",
"@",
"unlink",
"(",
"$",
"storagePath",
")",
")",
"{",
"throw",
"new",
"StorageFacilityException",
"(",
"\"Cannot delete file '\"",
".",
"$",
"storagePath",
".",
"\"'\"",
")",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}",
"}"
] | Deletes a file in the storage facility.
@param Site $site Site used to determine storage location
@param string $fileid File identifier of stored file, ex. /path/to/file.jpg
@return boolean True upon success
@throws StorageFacilityException if operation fails | [
"Deletes",
"a",
"file",
"in",
"the",
"storage",
"facility",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/storagefacility/LocalStorageFacility.php#L139-L152 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/storagefacility/LocalStorageFacility.php | LocalStorageFacility.renameFile | public function renameFile(StorageFacilityParams $params, StorageFacilityFile &$file, $newfileid)
{
$this->validateFileID($newfileid);
if ($file->getId() == null)
throw new StorageFacilityException("Invalid fileid '".$file->getId()."'");
if ($this->fileExists($params, $newfileid))
throw new StorageFacilityException("New file already exists '".$newfileid."'");
if (!$this->fileExists($params, $file->getId()))
throw new StorageFacilityException("File does not exist '".$file->getId()."'");
if (!@rename($this->generateStoragePath($params, $file->getId()),
$this->generateStoragePath($params, $newfileid)))
throw new StorageFacilityException("Could not rename file '".$file->getId()."'");
$file->setId($newfileid);
$file->setUrl($this->generateUrl($params, $newfileid));
} | php | public function renameFile(StorageFacilityParams $params, StorageFacilityFile &$file, $newfileid)
{
$this->validateFileID($newfileid);
if ($file->getId() == null)
throw new StorageFacilityException("Invalid fileid '".$file->getId()."'");
if ($this->fileExists($params, $newfileid))
throw new StorageFacilityException("New file already exists '".$newfileid."'");
if (!$this->fileExists($params, $file->getId()))
throw new StorageFacilityException("File does not exist '".$file->getId()."'");
if (!@rename($this->generateStoragePath($params, $file->getId()),
$this->generateStoragePath($params, $newfileid)))
throw new StorageFacilityException("Could not rename file '".$file->getId()."'");
$file->setId($newfileid);
$file->setUrl($this->generateUrl($params, $newfileid));
} | [
"public",
"function",
"renameFile",
"(",
"StorageFacilityParams",
"$",
"params",
",",
"StorageFacilityFile",
"&",
"$",
"file",
",",
"$",
"newfileid",
")",
"{",
"$",
"this",
"->",
"validateFileID",
"(",
"$",
"newfileid",
")",
";",
"if",
"(",
"$",
"file",
"->",
"getId",
"(",
")",
"==",
"null",
")",
"throw",
"new",
"StorageFacilityException",
"(",
"\"Invalid fileid '\"",
".",
"$",
"file",
"->",
"getId",
"(",
")",
".",
"\"'\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fileExists",
"(",
"$",
"params",
",",
"$",
"newfileid",
")",
")",
"throw",
"new",
"StorageFacilityException",
"(",
"\"New file already exists '\"",
".",
"$",
"newfileid",
".",
"\"'\"",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"fileExists",
"(",
"$",
"params",
",",
"$",
"file",
"->",
"getId",
"(",
")",
")",
")",
"throw",
"new",
"StorageFacilityException",
"(",
"\"File does not exist '\"",
".",
"$",
"file",
"->",
"getId",
"(",
")",
".",
"\"'\"",
")",
";",
"if",
"(",
"!",
"@",
"rename",
"(",
"$",
"this",
"->",
"generateStoragePath",
"(",
"$",
"params",
",",
"$",
"file",
"->",
"getId",
"(",
")",
")",
",",
"$",
"this",
"->",
"generateStoragePath",
"(",
"$",
"params",
",",
"$",
"newfileid",
")",
")",
")",
"throw",
"new",
"StorageFacilityException",
"(",
"\"Could not rename file '\"",
".",
"$",
"file",
"->",
"getId",
"(",
")",
".",
"\"'\"",
")",
";",
"$",
"file",
"->",
"setId",
"(",
"$",
"newfileid",
")",
";",
"$",
"file",
"->",
"setUrl",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"$",
"params",
",",
"$",
"newfileid",
")",
")",
";",
"}"
] | Renames a StorageFacilityFile in the storage facility.
@param Site $site Site used to determine storage location
@param string &$file File identifier of stored file, ex. /path/to/file.ext
@param string $newfileid File identifier to rename to
@return StorageFacilityFile Fully-resolved and stored file, has URL and id
set appropriately to reference the stored file later
@throws StorageFacilityException if operation fails | [
"Renames",
"a",
"StorageFacilityFile",
"in",
"the",
"storage",
"facility",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/storagefacility/LocalStorageFacility.php#L165-L184 | train |
gplcart/cli | controllers/commands/Country.php | Country.cmdGetCountry | public function cmdGetCountry()
{
$result = $this->getListCountry();
$this->outputFormat($result);
$this->outputFormatTableCountry($result);
$this->output();
} | php | public function cmdGetCountry()
{
$result = $this->getListCountry();
$this->outputFormat($result);
$this->outputFormatTableCountry($result);
$this->output();
} | [
"public",
"function",
"cmdGetCountry",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListCountry",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableCountry",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "country-get" command | [
"Callback",
"for",
"country",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Country.php#L40-L46 | train |
gplcart/cli | controllers/commands/Country.php | Country.cmdUpdateCountry | public function cmdUpdateCountry()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->setSubmittedJson('format');
$this->validateComponent('country');
$this->updateCountry($params[0]);
$this->output();
} | php | public function cmdUpdateCountry()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->setSubmittedJson('format');
$this->validateComponent('country');
$this->updateCountry($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateCountry",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"setSubmittedJson",
"(",
"'format'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'country'",
")",
";",
"$",
"this",
"->",
"updateCountry",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "country-update" command | [
"Callback",
"for",
"country",
"-",
"update",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Country.php#L65-L80 | train |
gplcart/cli | controllers/commands/Country.php | Country.cmdDeleteCountry | public function cmdDeleteCountry()
{
$code = $this->getParam(0);
$all = $this->getParam('all');
if (empty($code) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = null;
if (!empty($code)) {
$result = $this->country->delete($code);
} else if (!empty($all)) {
$deleted = $count = 0;
foreach ($this->country->getList() as $item) {
$count++;
$deleted += (int) $this->country->delete($item['code']);
}
$result = $count && $count == $deleted;
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | php | public function cmdDeleteCountry()
{
$code = $this->getParam(0);
$all = $this->getParam('all');
if (empty($code) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = null;
if (!empty($code)) {
$result = $this->country->delete($code);
} else if (!empty($all)) {
$deleted = $count = 0;
foreach ($this->country->getList() as $item) {
$count++;
$deleted += (int) $this->country->delete($item['code']);
}
$result = $count && $count == $deleted;
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | [
"public",
"function",
"cmdDeleteCountry",
"(",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"$",
"all",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'all'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"code",
")",
"&&",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"code",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"country",
"->",
"delete",
"(",
"$",
"code",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"deleted",
"=",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"country",
"->",
"getList",
"(",
")",
"as",
"$",
"item",
")",
"{",
"$",
"count",
"++",
";",
"$",
"deleted",
"+=",
"(",
"int",
")",
"$",
"this",
"->",
"country",
"->",
"delete",
"(",
"$",
"item",
"[",
"'code'",
"]",
")",
";",
"}",
"$",
"result",
"=",
"$",
"count",
"&&",
"$",
"count",
"==",
"$",
"deleted",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "country-delete" command | [
"Callback",
"for",
"country",
"-",
"delete",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Country.php#L85-L114 | train |
gplcart/cli | controllers/commands/Country.php | Country.addCountry | protected function addCountry()
{
if (!$this->isError() && !$this->country->add($this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | php | protected function addCountry()
{
if (!$this->isError() && !$this->country->add($this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | [
"protected",
"function",
"addCountry",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"country",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"}"
] | Add a new country | [
"Add",
"a",
"new",
"country"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Country.php#L169-L174 | train |
gplcart/cli | controllers/commands/Country.php | Country.updateCountry | protected function updateCountry($code)
{
if (!$this->isError() && !$this->country->update($code, $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | php | protected function updateCountry($code)
{
if (!$this->isError() && !$this->country->update($code, $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | [
"protected",
"function",
"updateCountry",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"country",
"->",
"update",
"(",
"$",
"code",
",",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"}"
] | Updates an country
@param string $code | [
"Updates",
"an",
"country"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Country.php#L180-L185 | train |
gplcart/cli | controllers/commands/Country.php | Country.submitAddCountry | protected function submitAddCountry()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmittedJson('format');
$this->validateComponent('country');
$this->addCountry();
} | php | protected function submitAddCountry()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmittedJson('format');
$this->validateComponent('country');
$this->addCountry();
} | [
"protected",
"function",
"submitAddCountry",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"setSubmittedJson",
"(",
"'format'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'country'",
")",
";",
"$",
"this",
"->",
"addCountry",
"(",
")",
";",
"}"
] | Add a new country at once | [
"Add",
"a",
"new",
"country",
"at",
"once"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Country.php#L190-L196 | train |
gplcart/cli | controllers/commands/Country.php | Country.wizardAddCountry | protected function wizardAddCountry()
{
$this->validatePrompt('code', $this->text('Code'), 'country');
$this->validatePrompt('name', $this->text('Name'), 'country', '');
$this->validatePrompt('native_name', $this->text('Native name'), 'country', '');
$this->validatePrompt('zone_id', $this->text('Zone'), 'country', 0);
$this->validatePrompt('status', $this->text('Status'), 'country', 0);
$this->validatePrompt('weight', $this->text('Weight'), 'country', 0);
$this->validateComponent('country');
$this->addCountry();
} | php | protected function wizardAddCountry()
{
$this->validatePrompt('code', $this->text('Code'), 'country');
$this->validatePrompt('name', $this->text('Name'), 'country', '');
$this->validatePrompt('native_name', $this->text('Native name'), 'country', '');
$this->validatePrompt('zone_id', $this->text('Zone'), 'country', 0);
$this->validatePrompt('status', $this->text('Status'), 'country', 0);
$this->validatePrompt('weight', $this->text('Weight'), 'country', 0);
$this->validateComponent('country');
$this->addCountry();
} | [
"protected",
"function",
"wizardAddCountry",
"(",
")",
"{",
"$",
"this",
"->",
"validatePrompt",
"(",
"'code'",
",",
"$",
"this",
"->",
"text",
"(",
"'Code'",
")",
",",
"'country'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'name'",
",",
"$",
"this",
"->",
"text",
"(",
"'Name'",
")",
",",
"'country'",
",",
"''",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'native_name'",
",",
"$",
"this",
"->",
"text",
"(",
"'Native name'",
")",
",",
"'country'",
",",
"''",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'zone_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Zone'",
")",
",",
"'country'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'country'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'weight'",
",",
"$",
"this",
"->",
"text",
"(",
"'Weight'",
")",
",",
"'country'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'country'",
")",
";",
"$",
"this",
"->",
"addCountry",
"(",
")",
";",
"}"
] | Add a new country step by step | [
"Add",
"a",
"new",
"country",
"step",
"by",
"step"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Country.php#L201-L212 | train |
DaGhostman/codewave | src/Application/Router.php | Router.get | public function get($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('get', $pattern, $callback, $middleware, $name);
return $this;
} | php | public function get($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('get', $pattern, $callback, $middleware, $name);
return $this;
} | [
"public",
"function",
"get",
"(",
"$",
"pattern",
",",
"$",
"callback",
",",
"array",
"$",
"middleware",
"=",
"null",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"addRoute",
"(",
"'get'",
",",
"$",
"pattern",
",",
"$",
"callback",
",",
"$",
"middleware",
",",
"$",
"name",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a route which will respond to GET and HEAD requests
@param string $pattern The route pattern for the URL
@param callable $callback The callback which should be handle the response
@param callable[] $middleware List of the middleware for the route
@param string $name (Optional) Route name. Used for reverse routing.
@return $this | [
"Defines",
"a",
"route",
"which",
"will",
"respond",
"to",
"GET",
"and",
"HEAD",
"requests"
] | f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Application/Router.php#L147-L152 | train |
DaGhostman/codewave | src/Application/Router.php | Router.addRoute | protected function addRoute($method, $pattern, $callback, array $middleware = null, $name = null)
{
$concatenatedPattern = (!is_null($this->prefix) ? '/' . $this->prefix : '') .
$pattern;
$this->collector->addRoute(strtoupper($method), $concatenatedPattern, new Route($callback, $middleware));
if ($name !== null) {
$this->namedRoutes[$name] = $concatenatedPattern;
}
} | php | protected function addRoute($method, $pattern, $callback, array $middleware = null, $name = null)
{
$concatenatedPattern = (!is_null($this->prefix) ? '/' . $this->prefix : '') .
$pattern;
$this->collector->addRoute(strtoupper($method), $concatenatedPattern, new Route($callback, $middleware));
if ($name !== null) {
$this->namedRoutes[$name] = $concatenatedPattern;
}
} | [
"protected",
"function",
"addRoute",
"(",
"$",
"method",
",",
"$",
"pattern",
",",
"$",
"callback",
",",
"array",
"$",
"middleware",
"=",
"null",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"concatenatedPattern",
"=",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"prefix",
")",
"?",
"'/'",
".",
"$",
"this",
"->",
"prefix",
":",
"''",
")",
".",
"$",
"pattern",
";",
"$",
"this",
"->",
"collector",
"->",
"addRoute",
"(",
"strtoupper",
"(",
"$",
"method",
")",
",",
"$",
"concatenatedPattern",
",",
"new",
"Route",
"(",
"$",
"callback",
",",
"$",
"middleware",
")",
")",
";",
"if",
"(",
"$",
"name",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"namedRoutes",
"[",
"$",
"name",
"]",
"=",
"$",
"concatenatedPattern",
";",
"}",
"}"
] | Proxies the route definition with the backend routing library
@param string $method
@param string $pattern
@param callable $callback
@param array $middleware
@param null $name | [
"Proxies",
"the",
"route",
"definition",
"with",
"the",
"backend",
"routing",
"library"
] | f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Application/Router.php#L163-L173 | train |
DaGhostman/codewave | src/Application/Router.php | Router.post | public function post($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('post', $pattern, $callback, $middleware, $name);
return $this;
} | php | public function post($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('post', $pattern, $callback, $middleware, $name);
return $this;
} | [
"public",
"function",
"post",
"(",
"$",
"pattern",
",",
"$",
"callback",
",",
"array",
"$",
"middleware",
"=",
"null",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"addRoute",
"(",
"'post'",
",",
"$",
"pattern",
",",
"$",
"callback",
",",
"$",
"middleware",
",",
"$",
"name",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a route which will respond to POST requests
@param string $pattern The route pattern for the URL
@param callable $callback The callback which should be handle the response
@param callable[] $middleware List of the middleware for the route
@param string $name (Optional) Route name. Used for reverse routing.
@return $this | [
"Defines",
"a",
"route",
"which",
"will",
"respond",
"to",
"POST",
"requests"
] | f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Application/Router.php#L185-L190 | train |
DaGhostman/codewave | src/Application/Router.php | Router.put | public function put($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('put', $pattern, $callback, $middleware, $name);
return $this;
} | php | public function put($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('put', $pattern, $callback, $middleware, $name);
return $this;
} | [
"public",
"function",
"put",
"(",
"$",
"pattern",
",",
"$",
"callback",
",",
"array",
"$",
"middleware",
"=",
"null",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"addRoute",
"(",
"'put'",
",",
"$",
"pattern",
",",
"$",
"callback",
",",
"$",
"middleware",
",",
"$",
"name",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a route which will respond to PUT requests
@param string $pattern The route pattern for the URL
@param callable $callback The callback which should be handle the response
@param callable[] $middleware List of the middleware for the route
@param string $name (Optional) Route name. Used for reverse routing.
@return $this | [
"Defines",
"a",
"route",
"which",
"will",
"respond",
"to",
"PUT",
"requests"
] | f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Application/Router.php#L202-L207 | train |
DaGhostman/codewave | src/Application/Router.php | Router.patch | public function patch($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('patch', $pattern, $callback, $middleware, $name);
return $this;
} | php | public function patch($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('patch', $pattern, $callback, $middleware, $name);
return $this;
} | [
"public",
"function",
"patch",
"(",
"$",
"pattern",
",",
"$",
"callback",
",",
"array",
"$",
"middleware",
"=",
"null",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"addRoute",
"(",
"'patch'",
",",
"$",
"pattern",
",",
"$",
"callback",
",",
"$",
"middleware",
",",
"$",
"name",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a route which will respond to PATCH requests
@param string $pattern The route pattern for the URL
@param callable $callback The callback which should be handle the response
@param callable[] $middleware List of the middleware for the route
@param string $name (Optional) Route name. Used for reverse routing.
@return $this | [
"Defines",
"a",
"route",
"which",
"will",
"respond",
"to",
"PATCH",
"requests"
] | f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Application/Router.php#L219-L224 | train |
DaGhostman/codewave | src/Application/Router.php | Router.delete | public function delete($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('delete', $pattern, $callback, $middleware, $name);
return $this;
} | php | public function delete($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('delete', $pattern, $callback, $middleware, $name);
return $this;
} | [
"public",
"function",
"delete",
"(",
"$",
"pattern",
",",
"$",
"callback",
",",
"array",
"$",
"middleware",
"=",
"null",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"addRoute",
"(",
"'delete'",
",",
"$",
"pattern",
",",
"$",
"callback",
",",
"$",
"middleware",
",",
"$",
"name",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a route which will respond to DELETE requests
@param string $pattern The route pattern for the URL
@param callable $callback The callback which should be handle the response
@param callable[] $middleware List of the middleware for the route
@param string $name (Optional) Route name. Used for reverse routing.
@return $this | [
"Defines",
"a",
"route",
"which",
"will",
"respond",
"to",
"DELETE",
"requests"
] | f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Application/Router.php#L236-L241 | train |
DaGhostman/codewave | src/Application/Router.php | Router.options | public function options($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('options', $pattern, $callback, $middleware, $name);
return $this;
} | php | public function options($pattern, $callback, array $middleware = null, $name = null)
{
$this->addRoute('options', $pattern, $callback, $middleware, $name);
return $this;
} | [
"public",
"function",
"options",
"(",
"$",
"pattern",
",",
"$",
"callback",
",",
"array",
"$",
"middleware",
"=",
"null",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"addRoute",
"(",
"'options'",
",",
"$",
"pattern",
",",
"$",
"callback",
",",
"$",
"middleware",
",",
"$",
"name",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a route which will respond to OPTIONS requests
@param string $pattern The route pattern for the URL
@param callable $callback The callback which should be handle the response
@param callable[] $middleware List of the middleware for the route
@param string $name (Optional) Route name. Used for reverse routing.
@return $this | [
"Defines",
"a",
"route",
"which",
"will",
"respond",
"to",
"OPTIONS",
"requests"
] | f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Application/Router.php#L253-L258 | train |
DaGhostman/codewave | src/Application/Router.php | Router.dispatch | public function dispatch(ServerRequestInterface $request, ResponseInterface $response)
{
$method = $request->getMethod();
$uri = $request->getUri()->getPath();
$d = new \FastRoute\Dispatcher\GroupCountBased($this->collector->getData());
$r = $d->dispatch(
($method === 'HEAD' ? 'GET' : $method),
$uri
);
switch ($r[0]) {
case 0:
throw new NotFoundException('Route not found');
break;
case 1:
return call_user_func($r[1], $request, $response, $r[2]);
break;
case 2:
throw new MethodNotAllowedException('Method not allowed', 0, null, $r[1]);
break;
}
return $response;
} | php | public function dispatch(ServerRequestInterface $request, ResponseInterface $response)
{
$method = $request->getMethod();
$uri = $request->getUri()->getPath();
$d = new \FastRoute\Dispatcher\GroupCountBased($this->collector->getData());
$r = $d->dispatch(
($method === 'HEAD' ? 'GET' : $method),
$uri
);
switch ($r[0]) {
case 0:
throw new NotFoundException('Route not found');
break;
case 1:
return call_user_func($r[1], $request, $response, $r[2]);
break;
case 2:
throw new MethodNotAllowedException('Method not allowed', 0, null, $r[1]);
break;
}
return $response;
} | [
"public",
"function",
"dispatch",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"method",
"=",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"$",
"uri",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"$",
"d",
"=",
"new",
"\\",
"FastRoute",
"\\",
"Dispatcher",
"\\",
"GroupCountBased",
"(",
"$",
"this",
"->",
"collector",
"->",
"getData",
"(",
")",
")",
";",
"$",
"r",
"=",
"$",
"d",
"->",
"dispatch",
"(",
"(",
"$",
"method",
"===",
"'HEAD'",
"?",
"'GET'",
":",
"$",
"method",
")",
",",
"$",
"uri",
")",
";",
"switch",
"(",
"$",
"r",
"[",
"0",
"]",
")",
"{",
"case",
"0",
":",
"throw",
"new",
"NotFoundException",
"(",
"'Route not found'",
")",
";",
"break",
";",
"case",
"1",
":",
"return",
"call_user_func",
"(",
"$",
"r",
"[",
"1",
"]",
",",
"$",
"request",
",",
"$",
"response",
",",
"$",
"r",
"[",
"2",
"]",
")",
";",
"break",
";",
"case",
"2",
":",
"throw",
"new",
"MethodNotAllowedException",
"(",
"'Method not allowed'",
",",
"0",
",",
"null",
",",
"$",
"r",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Performs the route matching and invokes the handler for the route, if
there is an error it throws exception.
@param ServerRequestInterface $request
@param ResponseInterface $response
@throws MethodNotAllowedException
@throws NotFoundException
@return ResponseInterface | [
"Performs",
"the",
"route",
"matching",
"and",
"invokes",
"the",
"handler",
"for",
"the",
"route",
"if",
"there",
"is",
"an",
"error",
"it",
"throws",
"exception",
"."
] | f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Application/Router.php#L387-L412 | train |
OxfordInfoLabs/kinikit-core | src/Util/XMLUtils.php | XMLUtils.prettyPrint | public static function prettyPrint($xmlString, $htmlDisplay = false) {
// Create a nicely formatted version
$doc = new \DOMDocument();
$doc->loadXML($xmlString);
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$prettyXML = $doc->saveXML();
if ($htmlDisplay) $prettyXML = str_replace(array("<", ">", "\n", " "), array("<", ">", "<br>", " "), $prettyXML);
return $prettyXML;
} | php | public static function prettyPrint($xmlString, $htmlDisplay = false) {
// Create a nicely formatted version
$doc = new \DOMDocument();
$doc->loadXML($xmlString);
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$prettyXML = $doc->saveXML();
if ($htmlDisplay) $prettyXML = str_replace(array("<", ">", "\n", " "), array("<", ">", "<br>", " "), $prettyXML);
return $prettyXML;
} | [
"public",
"static",
"function",
"prettyPrint",
"(",
"$",
"xmlString",
",",
"$",
"htmlDisplay",
"=",
"false",
")",
"{",
"// Create a nicely formatted version",
"$",
"doc",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"doc",
"->",
"loadXML",
"(",
"$",
"xmlString",
")",
";",
"$",
"doc",
"->",
"preserveWhiteSpace",
"=",
"false",
";",
"$",
"doc",
"->",
"formatOutput",
"=",
"true",
";",
"$",
"prettyXML",
"=",
"$",
"doc",
"->",
"saveXML",
"(",
")",
";",
"if",
"(",
"$",
"htmlDisplay",
")",
"$",
"prettyXML",
"=",
"str_replace",
"(",
"array",
"(",
"\"<\"",
",",
"\">\"",
",",
"\"\\n\"",
",",
"\" \"",
")",
",",
"array",
"(",
"\"<\"",
",",
"\">\"",
",",
"\"<br>\"",
",",
"\" \"",
")",
",",
"$",
"prettyXML",
")",
";",
"return",
"$",
"prettyXML",
";",
"}"
] | Pretty print an XML string - if the HTML Display flag is passed it will be formatted for display on a web page
with special characters escaped.
@param string $xmlString
@param boolean $htmlDisplay
@return string | [
"Pretty",
"print",
"an",
"XML",
"string",
"-",
"if",
"the",
"HTML",
"Display",
"flag",
"is",
"passed",
"it",
"will",
"be",
"formatted",
"for",
"display",
"on",
"a",
"web",
"page",
"with",
"special",
"characters",
"escaped",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/XMLUtils.php#L19-L32 | train |
gplcart/cli | controllers/commands/Language.php | Language.cmdUpdateLanguage | public function cmdUpdateLanguage()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('language');
$this->updateLanguage($params[0]);
$this->output();
} | php | public function cmdUpdateLanguage()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('language');
$this->updateLanguage($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateLanguage",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'language'",
")",
";",
"$",
"this",
"->",
"updateLanguage",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "language-update" | [
"Callback",
"for",
"language",
"-",
"update"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Language.php#L31-L45 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.